xref: /kvm-unit-tests/lib/pci-edu.h (revision 7f2a26cd2172069c3873ce0cee3c7f7a39e6eb6a)
1 /*
2  * Edu PCI device header.
3  *
4  * Copyright (C) 2016 Red Hat, Inc.
5  *
6  * Authors:
7  *   Peter Xu <peterx@redhat.com>,
8  *
9  * This work is licensed under the terms of the GNU LGPL, version 2 or
10  * later.
11  *
12  * Edu device is a virtualized device in QEMU. Please refer to
13  * docs/specs/edu.txt in QEMU repository for EDU device manual.
14  */
15 #ifndef __PCI_EDU_H__
16 #define __PCI_EDU_H__
17 
18 #include "pci.h"
19 #include "asm/io.h"
20 
21 #define  PCI_VENDOR_ID_QEMU              0x1234
22 #define  PCI_DEVICE_ID_EDU               0x11e8
23 
24 /* The only bar used by EDU device */
25 #define EDU_BAR                     0
26 #define EDU_MAGIC                   0xed
27 #define EDU_VERSION                 0x100
28 #define EDU_DMA_BUF_SIZE            (1 << 20)
29 #define EDU_INPUT_BUF_SIZE          256
30 
31 #define EDU_REG_ID                  0x0
32 #define EDU_REG_ALIVE               0x4
33 #define EDU_REG_FACTORIAL           0x8
34 #define EDU_REG_STATUS              0x20
35 #define EDU_REG_DMA_SRC             0x80
36 #define EDU_REG_DMA_DST             0x88
37 #define EDU_REG_DMA_COUNT           0x90
38 #define EDU_REG_DMA_CMD             0x98
39 
40 #define EDU_CMD_DMA_START           0x01
41 #define EDU_CMD_DMA_FROM            0x02
42 #define EDU_CMD_DMA_TO              0x00
43 
44 #define EDU_STATUS_FACTORIAL        0x1
45 #define EDU_STATUS_INT_ENABLE       0x80
46 
47 #define EDU_DMA_START               0x40000
48 #define EDU_DMA_SIZE_MAX            4096
49 
50 struct pci_edu_dev {
51 	struct pci_dev pci_dev;
52 	volatile void *reg_base;
53 };
54 
55 #define edu_reg(d, r) (volatile void *)((d)->reg_base + (r))
56 
57 static inline uint64_t edu_reg_readq(struct pci_edu_dev *dev, int reg)
58 {
59 	return __raw_readq(edu_reg(dev, reg));
60 }
61 
62 static inline uint32_t edu_reg_readl(struct pci_edu_dev *dev, int reg)
63 {
64 	return __raw_readl(edu_reg(dev, reg));
65 }
66 
67 static inline void edu_reg_writeq(struct pci_edu_dev *dev, int reg,
68 				  uint64_t val)
69 {
70 	__raw_writeq(val, edu_reg(dev, reg));
71 }
72 
73 static inline void edu_reg_writel(struct pci_edu_dev *dev, int reg,
74 				  uint32_t val)
75 {
76 	__raw_writel(val, edu_reg(dev, reg));
77 }
78 
79 bool edu_init(struct pci_edu_dev *dev);
80 void edu_dma(struct pci_edu_dev *dev, iova_t iova,
81 	     size_t size, unsigned int dev_offset, bool from_device);
82 
83 #endif
84