root / hw / pci.h @ bf3bc4c4
History | View | Annotate | Download (20.6 kB)
1 | 87ecb68b | pbrook | #ifndef QEMU_PCI_H
|
---|---|---|---|
2 | 87ecb68b | pbrook | #define QEMU_PCI_H
|
3 | 87ecb68b | pbrook | |
4 | 376253ec | aliguori | #include "qemu-common.h" |
5 | 376253ec | aliguori | |
6 | 6b1b92d3 | Paul Brook | #include "qdev.h" |
7 | 1e39101c | Avi Kivity | #include "memory.h" |
8 | ec174575 | David Gibson | #include "dma.h" |
9 | 6b1b92d3 | Paul Brook | |
10 | 87ecb68b | pbrook | /* PCI includes legacy ISA access. */
|
11 | 87ecb68b | pbrook | #include "isa.h" |
12 | 87ecb68b | pbrook | |
13 | 0428527c | Isaku Yamahata | #include "pcie.h" |
14 | 0428527c | Isaku Yamahata | |
15 | 87ecb68b | pbrook | /* PCI bus */
|
16 | 87ecb68b | pbrook | |
17 | 3ae80618 | aliguori | #define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) |
18 | 3ae80618 | aliguori | #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) |
19 | 3ae80618 | aliguori | #define PCI_FUNC(devfn) ((devfn) & 0x07) |
20 | 90a20dbb | Isaku Yamahata | #define PCI_SLOT_MAX 32 |
21 | 6fa84913 | Isaku Yamahata | #define PCI_FUNC_MAX 8 |
22 | 3ae80618 | aliguori | |
23 | a770dc7e | aliguori | /* Class, Vendor and Device IDs from Linux's pci_ids.h */
|
24 | a770dc7e | aliguori | #include "pci_ids.h" |
25 | 173a543b | blueswir1 | |
26 | a770dc7e | aliguori | /* QEMU-specific Vendor and Device ID definitions */
|
27 | 6f338c34 | aliguori | |
28 | a770dc7e | aliguori | /* IBM (0x1014) */
|
29 | a770dc7e | aliguori | #define PCI_DEVICE_ID_IBM_440GX 0x027f |
30 | 4ebcf884 | blueswir1 | #define PCI_DEVICE_ID_IBM_OPENPIC2 0xffff |
31 | deb54399 | aliguori | |
32 | a770dc7e | aliguori | /* Hitachi (0x1054) */
|
33 | deb54399 | aliguori | #define PCI_VENDOR_ID_HITACHI 0x1054 |
34 | a770dc7e | aliguori | #define PCI_DEVICE_ID_HITACHI_SH7751R 0x350e |
35 | deb54399 | aliguori | |
36 | a770dc7e | aliguori | /* Apple (0x106b) */
|
37 | 4ebcf884 | blueswir1 | #define PCI_DEVICE_ID_APPLE_343S1201 0x0010 |
38 | 4ebcf884 | blueswir1 | #define PCI_DEVICE_ID_APPLE_UNI_N_I_PCI 0x001e |
39 | 4ebcf884 | blueswir1 | #define PCI_DEVICE_ID_APPLE_UNI_N_PCI 0x001f |
40 | 4ebcf884 | blueswir1 | #define PCI_DEVICE_ID_APPLE_UNI_N_KEYL 0x0022 |
41 | a770dc7e | aliguori | #define PCI_DEVICE_ID_APPLE_IPID_USB 0x003f |
42 | deb54399 | aliguori | |
43 | a770dc7e | aliguori | /* Realtek (0x10ec) */
|
44 | a770dc7e | aliguori | #define PCI_DEVICE_ID_REALTEK_8029 0x8029 |
45 | deb54399 | aliguori | |
46 | a770dc7e | aliguori | /* Xilinx (0x10ee) */
|
47 | a770dc7e | aliguori | #define PCI_DEVICE_ID_XILINX_XC2VP30 0x0300 |
48 | deb54399 | aliguori | |
49 | a770dc7e | aliguori | /* Marvell (0x11ab) */
|
50 | a770dc7e | aliguori | #define PCI_DEVICE_ID_MARVELL_GT6412X 0x4620 |
51 | deb54399 | aliguori | |
52 | a770dc7e | aliguori | /* QEMU/Bochs VGA (0x1234) */
|
53 | 4ebcf884 | blueswir1 | #define PCI_VENDOR_ID_QEMU 0x1234 |
54 | 4ebcf884 | blueswir1 | #define PCI_DEVICE_ID_QEMU_VGA 0x1111 |
55 | 4ebcf884 | blueswir1 | |
56 | a770dc7e | aliguori | /* VMWare (0x15ad) */
|
57 | deb54399 | aliguori | #define PCI_VENDOR_ID_VMWARE 0x15ad |
58 | deb54399 | aliguori | #define PCI_DEVICE_ID_VMWARE_SVGA2 0x0405 |
59 | deb54399 | aliguori | #define PCI_DEVICE_ID_VMWARE_SVGA 0x0710 |
60 | deb54399 | aliguori | #define PCI_DEVICE_ID_VMWARE_NET 0x0720 |
61 | deb54399 | aliguori | #define PCI_DEVICE_ID_VMWARE_SCSI 0x0730 |
62 | deb54399 | aliguori | #define PCI_DEVICE_ID_VMWARE_IDE 0x1729 |
63 | deb54399 | aliguori | |
64 | cef3017c | aliguori | /* Intel (0x8086) */
|
65 | a770dc7e | aliguori | #define PCI_DEVICE_ID_INTEL_82551IT 0x1209 |
66 | d6fd1e66 | Stefan Weil | #define PCI_DEVICE_ID_INTEL_82557 0x1229 |
67 | 1a5a86fb | Alexander Graf | #define PCI_DEVICE_ID_INTEL_82801IR 0x2922 |
68 | 74c62ba8 | aurel32 | |
69 | deb54399 | aliguori | /* Red Hat / Qumranet (for QEMU) -- see pci-ids.txt */
|
70 | d350d97d | aliguori | #define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 |
71 | d350d97d | aliguori | #define PCI_SUBVENDOR_ID_REDHAT_QUMRANET 0x1af4 |
72 | d350d97d | aliguori | #define PCI_SUBDEVICE_ID_QEMU 0x1100 |
73 | d350d97d | aliguori | |
74 | d350d97d | aliguori | #define PCI_DEVICE_ID_VIRTIO_NET 0x1000 |
75 | d350d97d | aliguori | #define PCI_DEVICE_ID_VIRTIO_BLOCK 0x1001 |
76 | d350d97d | aliguori | #define PCI_DEVICE_ID_VIRTIO_BALLOON 0x1002 |
77 | 14d50bef | aliguori | #define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003 |
78 | 973abc7f | Stefan Hajnoczi | #define PCI_DEVICE_ID_VIRTIO_SCSI 0x1004 |
79 | 16c915ba | Amit Shah | #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005 |
80 | d350d97d | aliguori | |
81 | 4f8589e1 | Isaku Yamahata | #define FMT_PCIBUS PRIx64
|
82 | 6e355d90 | Isaku Yamahata | |
83 | 87ecb68b | pbrook | typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, |
84 | 87ecb68b | pbrook | uint32_t address, uint32_t data, int len);
|
85 | 87ecb68b | pbrook | typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
|
86 | 87ecb68b | pbrook | uint32_t address, int len);
|
87 | 87ecb68b | pbrook | typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, |
88 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type);
|
89 | f90c2bcd | Alex Williamson | typedef void PCIUnregisterFunc(PCIDevice *pci_dev); |
90 | 87ecb68b | pbrook | |
91 | 87ecb68b | pbrook | typedef struct PCIIORegion { |
92 | 6e355d90 | Isaku Yamahata | pcibus_t addr; /* current PCI mapping address. -1 means not mapped */
|
93 | 6e355d90 | Isaku Yamahata | #define PCI_BAR_UNMAPPED (~(pcibus_t)0) |
94 | 6e355d90 | Isaku Yamahata | pcibus_t size; |
95 | 87ecb68b | pbrook | uint8_t type; |
96 | 79ff8cb0 | Avi Kivity | MemoryRegion *memory; |
97 | 5968eca3 | Avi Kivity | MemoryRegion *address_space; |
98 | 87ecb68b | pbrook | } PCIIORegion; |
99 | 87ecb68b | pbrook | |
100 | 87ecb68b | pbrook | #define PCI_ROM_SLOT 6 |
101 | 87ecb68b | pbrook | #define PCI_NUM_REGIONS 7 |
102 | 87ecb68b | pbrook | |
103 | fb58a897 | Isaku Yamahata | #include "pci_regs.h" |
104 | fb58a897 | Isaku Yamahata | |
105 | fb58a897 | Isaku Yamahata | /* PCI HEADER_TYPE */
|
106 | 6407f373 | Isaku Yamahata | #define PCI_HEADER_TYPE_MULTI_FUNCTION 0x80 |
107 | 8098ed41 | aurel32 | |
108 | b7ee1603 | Michael S. Tsirkin | /* Size of the standard PCI config header */
|
109 | b7ee1603 | Michael S. Tsirkin | #define PCI_CONFIG_HEADER_SIZE 0x40 |
110 | b7ee1603 | Michael S. Tsirkin | /* Size of the standard PCI config space */
|
111 | b7ee1603 | Michael S. Tsirkin | #define PCI_CONFIG_SPACE_SIZE 0x100 |
112 | a9f49946 | Isaku Yamahata | /* Size of the standart PCIe config space: 4KB */
|
113 | a9f49946 | Isaku Yamahata | #define PCIE_CONFIG_SPACE_SIZE 0x1000 |
114 | b7ee1603 | Michael S. Tsirkin | |
115 | e369cad7 | Isaku Yamahata | #define PCI_NUM_PINS 4 /* A-D */ |
116 | e369cad7 | Isaku Yamahata | |
117 | 02eb84d0 | Michael S. Tsirkin | /* Bits in cap_present field. */
|
118 | 02eb84d0 | Michael S. Tsirkin | enum {
|
119 | e4c7d2ae | Isaku Yamahata | QEMU_PCI_CAP_MSI = 0x1,
|
120 | e4c7d2ae | Isaku Yamahata | QEMU_PCI_CAP_MSIX = 0x2,
|
121 | e4c7d2ae | Isaku Yamahata | QEMU_PCI_CAP_EXPRESS = 0x4,
|
122 | 49823868 | Isaku Yamahata | |
123 | 49823868 | Isaku Yamahata | /* multifunction capable device */
|
124 | e4c7d2ae | Isaku Yamahata | #define QEMU_PCI_CAP_MULTIFUNCTION_BITNR 3 |
125 | 49823868 | Isaku Yamahata | QEMU_PCI_CAP_MULTIFUNCTION = (1 << QEMU_PCI_CAP_MULTIFUNCTION_BITNR),
|
126 | b1aeb926 | Isaku Yamahata | |
127 | b1aeb926 | Isaku Yamahata | /* command register SERR bit enabled */
|
128 | b1aeb926 | Isaku Yamahata | #define QEMU_PCI_CAP_SERR_BITNR 4 |
129 | b1aeb926 | Isaku Yamahata | QEMU_PCI_CAP_SERR = (1 << QEMU_PCI_CAP_SERR_BITNR),
|
130 | 1dc324d2 | Michael S. Tsirkin | /* Standard hot plug controller. */
|
131 | 1dc324d2 | Michael S. Tsirkin | #define QEMU_PCI_SHPC_BITNR 5 |
132 | 1dc324d2 | Michael S. Tsirkin | QEMU_PCI_CAP_SHPC = (1 << QEMU_PCI_SHPC_BITNR),
|
133 | 762833b3 | Michael S. Tsirkin | #define QEMU_PCI_SLOTID_BITNR 6 |
134 | 762833b3 | Michael S. Tsirkin | QEMU_PCI_CAP_SLOTID = (1 << QEMU_PCI_SLOTID_BITNR),
|
135 | 02eb84d0 | Michael S. Tsirkin | }; |
136 | 02eb84d0 | Michael S. Tsirkin | |
137 | 40021f08 | Anthony Liguori | #define TYPE_PCI_DEVICE "pci-device" |
138 | 40021f08 | Anthony Liguori | #define PCI_DEVICE(obj) \
|
139 | 40021f08 | Anthony Liguori | OBJECT_CHECK(PCIDevice, (obj), TYPE_PCI_DEVICE) |
140 | 40021f08 | Anthony Liguori | #define PCI_DEVICE_CLASS(klass) \
|
141 | 40021f08 | Anthony Liguori | OBJECT_CLASS_CHECK(PCIDeviceClass, (klass), TYPE_PCI_DEVICE) |
142 | 40021f08 | Anthony Liguori | #define PCI_DEVICE_GET_CLASS(obj) \
|
143 | 40021f08 | Anthony Liguori | OBJECT_GET_CLASS(PCIDeviceClass, (obj), TYPE_PCI_DEVICE) |
144 | 40021f08 | Anthony Liguori | |
145 | 3afa9bb4 | Michael S. Tsirkin | typedef struct PCIINTxRoute { |
146 | 3afa9bb4 | Michael S. Tsirkin | enum {
|
147 | 3afa9bb4 | Michael S. Tsirkin | PCI_INTX_ENABLED, |
148 | 3afa9bb4 | Michael S. Tsirkin | PCI_INTX_INVERTED, |
149 | 3afa9bb4 | Michael S. Tsirkin | PCI_INTX_DISABLED, |
150 | 3afa9bb4 | Michael S. Tsirkin | } mode; |
151 | 3afa9bb4 | Michael S. Tsirkin | int irq;
|
152 | 3afa9bb4 | Michael S. Tsirkin | } PCIINTxRoute; |
153 | 3afa9bb4 | Michael S. Tsirkin | |
154 | 40021f08 | Anthony Liguori | typedef struct PCIDeviceClass { |
155 | 40021f08 | Anthony Liguori | DeviceClass parent_class; |
156 | 40021f08 | Anthony Liguori | |
157 | 40021f08 | Anthony Liguori | int (*init)(PCIDevice *dev);
|
158 | 40021f08 | Anthony Liguori | PCIUnregisterFunc *exit; |
159 | 40021f08 | Anthony Liguori | PCIConfigReadFunc *config_read; |
160 | 40021f08 | Anthony Liguori | PCIConfigWriteFunc *config_write; |
161 | 40021f08 | Anthony Liguori | |
162 | 40021f08 | Anthony Liguori | uint16_t vendor_id; |
163 | 40021f08 | Anthony Liguori | uint16_t device_id; |
164 | 40021f08 | Anthony Liguori | uint8_t revision; |
165 | 40021f08 | Anthony Liguori | uint16_t class_id; |
166 | 40021f08 | Anthony Liguori | uint16_t subsystem_vendor_id; /* only for header type = 0 */
|
167 | 40021f08 | Anthony Liguori | uint16_t subsystem_id; /* only for header type = 0 */
|
168 | 40021f08 | Anthony Liguori | |
169 | 40021f08 | Anthony Liguori | /*
|
170 | 40021f08 | Anthony Liguori | * pci-to-pci bridge or normal device.
|
171 | 40021f08 | Anthony Liguori | * This doesn't mean pci host switch.
|
172 | 40021f08 | Anthony Liguori | * When card bus bridge is supported, this would be enhanced.
|
173 | 40021f08 | Anthony Liguori | */
|
174 | 40021f08 | Anthony Liguori | int is_bridge;
|
175 | 40021f08 | Anthony Liguori | |
176 | 40021f08 | Anthony Liguori | /* pcie stuff */
|
177 | 40021f08 | Anthony Liguori | int is_express; /* is this device pci express? */ |
178 | 40021f08 | Anthony Liguori | |
179 | 40021f08 | Anthony Liguori | /* device isn't hot-pluggable */
|
180 | 40021f08 | Anthony Liguori | int no_hotplug;
|
181 | 40021f08 | Anthony Liguori | |
182 | 40021f08 | Anthony Liguori | /* rom bar */
|
183 | 40021f08 | Anthony Liguori | const char *romfile; |
184 | 40021f08 | Anthony Liguori | } PCIDeviceClass; |
185 | 40021f08 | Anthony Liguori | |
186 | 0ae16251 | Jan Kiszka | typedef void (*PCIINTxRoutingNotifier)(PCIDevice *dev); |
187 | 2cdfe53c | Jan Kiszka | typedef int (*MSIVectorUseNotifier)(PCIDevice *dev, unsigned int vector, |
188 | 2cdfe53c | Jan Kiszka | MSIMessage msg); |
189 | 2cdfe53c | Jan Kiszka | typedef void (*MSIVectorReleaseNotifier)(PCIDevice *dev, unsigned int vector); |
190 | 2cdfe53c | Jan Kiszka | |
191 | 87ecb68b | pbrook | struct PCIDevice {
|
192 | 6b1b92d3 | Paul Brook | DeviceState qdev; |
193 | 5fa45de5 | David Gibson | |
194 | 87ecb68b | pbrook | /* PCI config space */
|
195 | a9f49946 | Isaku Yamahata | uint8_t *config; |
196 | b7ee1603 | Michael S. Tsirkin | |
197 | ebabb67a | Stefan Weil | /* Used to enable config checks on load. Note that writable bits are
|
198 | bd4b65ee | Michael S. Tsirkin | * never checked even if set in cmask. */
|
199 | a9f49946 | Isaku Yamahata | uint8_t *cmask; |
200 | bd4b65ee | Michael S. Tsirkin | |
201 | b7ee1603 | Michael S. Tsirkin | /* Used to implement R/W bytes */
|
202 | a9f49946 | Isaku Yamahata | uint8_t *wmask; |
203 | 87ecb68b | pbrook | |
204 | 92ba5f51 | Isaku Yamahata | /* Used to implement RW1C(Write 1 to Clear) bytes */
|
205 | 92ba5f51 | Isaku Yamahata | uint8_t *w1cmask; |
206 | 92ba5f51 | Isaku Yamahata | |
207 | 6f4cbd39 | Michael S. Tsirkin | /* Used to allocate config space for capabilities. */
|
208 | a9f49946 | Isaku Yamahata | uint8_t *used; |
209 | 6f4cbd39 | Michael S. Tsirkin | |
210 | 87ecb68b | pbrook | /* the following fields are read only */
|
211 | 87ecb68b | pbrook | PCIBus *bus; |
212 | 09f1bbcd | Michael Roth | int32_t devfn; |
213 | 87ecb68b | pbrook | char name[64]; |
214 | 87ecb68b | pbrook | PCIIORegion io_regions[PCI_NUM_REGIONS]; |
215 | 817dcc53 | Avi Kivity | AddressSpace bus_master_as; |
216 | 1c380f94 | Avi Kivity | MemoryRegion bus_master_enable_region; |
217 | 5fa45de5 | David Gibson | DMAContext *dma; |
218 | 87ecb68b | pbrook | |
219 | 87ecb68b | pbrook | /* do not access the following fields */
|
220 | 87ecb68b | pbrook | PCIConfigReadFunc *config_read; |
221 | 87ecb68b | pbrook | PCIConfigWriteFunc *config_write; |
222 | 87ecb68b | pbrook | |
223 | 87ecb68b | pbrook | /* IRQ objects for the INTA-INTD pins. */
|
224 | 87ecb68b | pbrook | qemu_irq *irq; |
225 | 87ecb68b | pbrook | |
226 | 87ecb68b | pbrook | /* Current IRQ levels. Used internally by the generic PCI code. */
|
227 | d036bb21 | Michael S. Tsirkin | uint8_t irq_state; |
228 | 02eb84d0 | Michael S. Tsirkin | |
229 | 02eb84d0 | Michael S. Tsirkin | /* Capability bits */
|
230 | 02eb84d0 | Michael S. Tsirkin | uint32_t cap_present; |
231 | 02eb84d0 | Michael S. Tsirkin | |
232 | 02eb84d0 | Michael S. Tsirkin | /* Offset of MSI-X capability in config space */
|
233 | 02eb84d0 | Michael S. Tsirkin | uint8_t msix_cap; |
234 | 02eb84d0 | Michael S. Tsirkin | |
235 | 02eb84d0 | Michael S. Tsirkin | /* MSI-X entries */
|
236 | 02eb84d0 | Michael S. Tsirkin | int msix_entries_nr;
|
237 | 02eb84d0 | Michael S. Tsirkin | |
238 | d35e428c | Alex Williamson | /* Space to store MSIX table & pending bit array */
|
239 | d35e428c | Alex Williamson | uint8_t *msix_table; |
240 | d35e428c | Alex Williamson | uint8_t *msix_pba; |
241 | 53f94925 | Alex Williamson | /* MemoryRegion container for msix exclusive BAR setup */
|
242 | 53f94925 | Alex Williamson | MemoryRegion msix_exclusive_bar; |
243 | d35e428c | Alex Williamson | /* Memory Regions for MSIX table and pending bit entries. */
|
244 | d35e428c | Alex Williamson | MemoryRegion msix_table_mmio; |
245 | d35e428c | Alex Williamson | MemoryRegion msix_pba_mmio; |
246 | 02eb84d0 | Michael S. Tsirkin | /* Reference-count for entries actually in use by driver. */
|
247 | 02eb84d0 | Michael S. Tsirkin | unsigned *msix_entry_used;
|
248 | 50322249 | Michael S. Tsirkin | /* MSIX function mask set or MSIX disabled */
|
249 | 50322249 | Michael S. Tsirkin | bool msix_function_masked;
|
250 | f16c4abf | Juan Quintela | /* Version id needed for VMState */
|
251 | f16c4abf | Juan Quintela | int32_t version_id; |
252 | c2039bd0 | Anthony Liguori | |
253 | e4c7d2ae | Isaku Yamahata | /* Offset of MSI capability in config space */
|
254 | e4c7d2ae | Isaku Yamahata | uint8_t msi_cap; |
255 | e4c7d2ae | Isaku Yamahata | |
256 | 0428527c | Isaku Yamahata | /* PCI Express */
|
257 | 0428527c | Isaku Yamahata | PCIExpressDevice exp; |
258 | 0428527c | Isaku Yamahata | |
259 | 1dc324d2 | Michael S. Tsirkin | /* SHPC */
|
260 | 1dc324d2 | Michael S. Tsirkin | SHPCDevice *shpc; |
261 | 1dc324d2 | Michael S. Tsirkin | |
262 | c2039bd0 | Anthony Liguori | /* Location of option rom */
|
263 | 8c52c8f3 | Gerd Hoffmann | char *romfile;
|
264 | 14caaf7f | Avi Kivity | bool has_rom;
|
265 | 14caaf7f | Avi Kivity | MemoryRegion rom; |
266 | 88169ddf | Gerd Hoffmann | uint32_t rom_bar; |
267 | 2cdfe53c | Jan Kiszka | |
268 | 0ae16251 | Jan Kiszka | /* INTx routing notifier */
|
269 | 0ae16251 | Jan Kiszka | PCIINTxRoutingNotifier intx_routing_notifier; |
270 | 0ae16251 | Jan Kiszka | |
271 | 2cdfe53c | Jan Kiszka | /* MSI-X notifiers */
|
272 | 2cdfe53c | Jan Kiszka | MSIVectorUseNotifier msix_vector_use_notifier; |
273 | 2cdfe53c | Jan Kiszka | MSIVectorReleaseNotifier msix_vector_release_notifier; |
274 | 87ecb68b | pbrook | }; |
275 | 87ecb68b | pbrook | |
276 | e824b2cc | Avi Kivity | void pci_register_bar(PCIDevice *pci_dev, int region_num, |
277 | e824b2cc | Avi Kivity | uint8_t attr, MemoryRegion *memory); |
278 | 16a96f28 | Avi Kivity | pcibus_t pci_get_bar_addr(PCIDevice *pci_dev, int region_num);
|
279 | 87ecb68b | pbrook | |
280 | ca77089d | Isaku Yamahata | int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
|
281 | ca77089d | Isaku Yamahata | uint8_t offset, uint8_t size); |
282 | 6f4cbd39 | Michael S. Tsirkin | |
283 | 6f4cbd39 | Michael S. Tsirkin | void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
|
284 | 6f4cbd39 | Michael S. Tsirkin | |
285 | 6f4cbd39 | Michael S. Tsirkin | uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id); |
286 | 6f4cbd39 | Michael S. Tsirkin | |
287 | 6f4cbd39 | Michael S. Tsirkin | |
288 | 87ecb68b | pbrook | uint32_t pci_default_read_config(PCIDevice *d, |
289 | 87ecb68b | pbrook | uint32_t address, int len);
|
290 | 87ecb68b | pbrook | void pci_default_write_config(PCIDevice *d,
|
291 | 87ecb68b | pbrook | uint32_t address, uint32_t val, int len);
|
292 | 87ecb68b | pbrook | void pci_device_save(PCIDevice *s, QEMUFile *f);
|
293 | 87ecb68b | pbrook | int pci_device_load(PCIDevice *s, QEMUFile *f);
|
294 | f5e6fed8 | Avi Kivity | MemoryRegion *pci_address_space(PCIDevice *dev); |
295 | e11d6439 | Richard Henderson | MemoryRegion *pci_address_space_io(PCIDevice *dev); |
296 | 87ecb68b | pbrook | |
297 | 5d4e84c8 | Juan Quintela | typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level); |
298 | 87ecb68b | pbrook | typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num); |
299 | 3afa9bb4 | Michael S. Tsirkin | typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin); |
300 | e927d487 | Michael S. Tsirkin | |
301 | e927d487 | Michael S. Tsirkin | typedef enum { |
302 | e927d487 | Michael S. Tsirkin | PCI_HOTPLUG_DISABLED, |
303 | e927d487 | Michael S. Tsirkin | PCI_HOTPLUG_ENABLED, |
304 | e927d487 | Michael S. Tsirkin | PCI_COLDPLUG_ENABLED, |
305 | e927d487 | Michael S. Tsirkin | } PCIHotplugState; |
306 | e927d487 | Michael S. Tsirkin | |
307 | e927d487 | Michael S. Tsirkin | typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev, |
308 | e927d487 | Michael S. Tsirkin | PCIHotplugState state); |
309 | 21eea4b3 | Gerd Hoffmann | void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
|
310 | 1e39101c | Avi Kivity | const char *name, |
311 | aee97b84 | Avi Kivity | MemoryRegion *address_space_mem, |
312 | aee97b84 | Avi Kivity | MemoryRegion *address_space_io, |
313 | 1e39101c | Avi Kivity | uint8_t devfn_min); |
314 | 1e39101c | Avi Kivity | PCIBus *pci_bus_new(DeviceState *parent, const char *name, |
315 | aee97b84 | Avi Kivity | MemoryRegion *address_space_mem, |
316 | aee97b84 | Avi Kivity | MemoryRegion *address_space_io, |
317 | aee97b84 | Avi Kivity | uint8_t devfn_min); |
318 | 21eea4b3 | Gerd Hoffmann | void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
319 | 21eea4b3 | Gerd Hoffmann | void *irq_opaque, int nirq); |
320 | 9ddf8437 | Isaku Yamahata | int pci_bus_get_irq_level(PCIBus *bus, int irq_num); |
321 | 87c30546 | Isaku Yamahata | void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);
|
322 | 91e56159 | Isaku Yamahata | /* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
|
323 | 91e56159 | Isaku Yamahata | int pci_swizzle_map_irq_fn(PCIDevice *pci_dev, int pin); |
324 | 02e2da45 | Paul Brook | PCIBus *pci_register_bus(DeviceState *parent, const char *name, |
325 | 02e2da45 | Paul Brook | pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, |
326 | 1e39101c | Avi Kivity | void *irq_opaque,
|
327 | aee97b84 | Avi Kivity | MemoryRegion *address_space_mem, |
328 | aee97b84 | Avi Kivity | MemoryRegion *address_space_io, |
329 | 1e39101c | Avi Kivity | uint8_t devfn_min, int nirq);
|
330 | 3afa9bb4 | Michael S. Tsirkin | void pci_bus_set_route_irq_fn(PCIBus *, pci_route_irq_fn);
|
331 | 3afa9bb4 | Michael S. Tsirkin | PCIINTxRoute pci_device_route_intx_to_irq(PCIDevice *dev, int pin);
|
332 | d6e65d54 | Alex Williamson | bool pci_intx_route_changed(PCIINTxRoute *old, PCIINTxRoute *new);
|
333 | 0ae16251 | Jan Kiszka | void pci_bus_fire_intx_routing_notifier(PCIBus *bus);
|
334 | 0ae16251 | Jan Kiszka | void pci_device_set_intx_routing_notifier(PCIDevice *dev,
|
335 | 0ae16251 | Jan Kiszka | PCIINTxRoutingNotifier notifier); |
336 | 0ead87c8 | Isaku Yamahata | void pci_device_reset(PCIDevice *dev);
|
337 | 9bb33586 | Isaku Yamahata | void pci_bus_reset(PCIBus *bus);
|
338 | 87ecb68b | pbrook | |
339 | 5607c388 | Markus Armbruster | PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, |
340 | 5607c388 | Markus Armbruster | const char *default_devaddr); |
341 | 07caea31 | Markus Armbruster | PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model, |
342 | 07caea31 | Markus Armbruster | const char *default_devaddr); |
343 | 129d42fb | Aurelien Jarno | |
344 | 129d42fb | Aurelien Jarno | PCIDevice *pci_vga_init(PCIBus *bus); |
345 | 129d42fb | Aurelien Jarno | |
346 | 87ecb68b | pbrook | int pci_bus_num(PCIBus *s);
|
347 | 7aa8cbb9 | Anthony PERARD | void pci_for_each_device(PCIBus *bus, int bus_num, |
348 | 7aa8cbb9 | Anthony PERARD | void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque), |
349 | 7aa8cbb9 | Anthony PERARD | void *opaque);
|
350 | c469e1dd | Isaku Yamahata | PCIBus *pci_find_root_bus(int domain);
|
351 | e075e788 | Isaku Yamahata | int pci_find_domain(const PCIBus *bus); |
352 | 5256d8bf | Isaku Yamahata | PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
|
353 | f3006dd1 | Isaku Yamahata | int pci_qdev_find_device(const char *id, PCIDevice **pdev); |
354 | 49bd1458 | Markus Armbruster | PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr); |
355 | 87ecb68b | pbrook | |
356 | e9283f8b | Jan Kiszka | int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp, |
357 | e9283f8b | Jan Kiszka | unsigned *slotp);
|
358 | 880345c4 | aliguori | |
359 | 4c92325b | Isaku Yamahata | void pci_device_deassert_intx(PCIDevice *dev);
|
360 | 4c92325b | Isaku Yamahata | |
361 | 5fa45de5 | David Gibson | typedef DMAContext *(*PCIDMAContextFunc)(PCIBus *, void *, int); |
362 | 5fa45de5 | David Gibson | |
363 | 5fa45de5 | David Gibson | void pci_setup_iommu(PCIBus *bus, PCIDMAContextFunc fn, void *opaque); |
364 | 5fa45de5 | David Gibson | |
365 | deb54399 | aliguori | static inline void |
366 | 64d50b8b | Michael S. Tsirkin | pci_set_byte(uint8_t *config, uint8_t val) |
367 | 64d50b8b | Michael S. Tsirkin | { |
368 | 64d50b8b | Michael S. Tsirkin | *config = val; |
369 | 64d50b8b | Michael S. Tsirkin | } |
370 | 64d50b8b | Michael S. Tsirkin | |
371 | 64d50b8b | Michael S. Tsirkin | static inline uint8_t |
372 | cb95c2e4 | Stefan Weil | pci_get_byte(const uint8_t *config)
|
373 | 64d50b8b | Michael S. Tsirkin | { |
374 | 64d50b8b | Michael S. Tsirkin | return *config;
|
375 | 64d50b8b | Michael S. Tsirkin | } |
376 | 64d50b8b | Michael S. Tsirkin | |
377 | 64d50b8b | Michael S. Tsirkin | static inline void |
378 | 14e12559 | Michael S. Tsirkin | pci_set_word(uint8_t *config, uint16_t val) |
379 | 14e12559 | Michael S. Tsirkin | { |
380 | 14e12559 | Michael S. Tsirkin | cpu_to_le16wu((uint16_t *)config, val); |
381 | 14e12559 | Michael S. Tsirkin | } |
382 | 14e12559 | Michael S. Tsirkin | |
383 | 14e12559 | Michael S. Tsirkin | static inline uint16_t |
384 | cb95c2e4 | Stefan Weil | pci_get_word(const uint8_t *config)
|
385 | 14e12559 | Michael S. Tsirkin | { |
386 | cb95c2e4 | Stefan Weil | return le16_to_cpupu((const uint16_t *)config); |
387 | 14e12559 | Michael S. Tsirkin | } |
388 | 14e12559 | Michael S. Tsirkin | |
389 | 14e12559 | Michael S. Tsirkin | static inline void |
390 | 14e12559 | Michael S. Tsirkin | pci_set_long(uint8_t *config, uint32_t val) |
391 | 14e12559 | Michael S. Tsirkin | { |
392 | 14e12559 | Michael S. Tsirkin | cpu_to_le32wu((uint32_t *)config, val); |
393 | 14e12559 | Michael S. Tsirkin | } |
394 | 14e12559 | Michael S. Tsirkin | |
395 | 14e12559 | Michael S. Tsirkin | static inline uint32_t |
396 | cb95c2e4 | Stefan Weil | pci_get_long(const uint8_t *config)
|
397 | 14e12559 | Michael S. Tsirkin | { |
398 | cb95c2e4 | Stefan Weil | return le32_to_cpupu((const uint32_t *)config); |
399 | 14e12559 | Michael S. Tsirkin | } |
400 | 14e12559 | Michael S. Tsirkin | |
401 | 14e12559 | Michael S. Tsirkin | static inline void |
402 | fb5ce7d2 | Isaku Yamahata | pci_set_quad(uint8_t *config, uint64_t val) |
403 | fb5ce7d2 | Isaku Yamahata | { |
404 | fb5ce7d2 | Isaku Yamahata | cpu_to_le64w((uint64_t *)config, val); |
405 | fb5ce7d2 | Isaku Yamahata | } |
406 | fb5ce7d2 | Isaku Yamahata | |
407 | fb5ce7d2 | Isaku Yamahata | static inline uint64_t |
408 | cb95c2e4 | Stefan Weil | pci_get_quad(const uint8_t *config)
|
409 | fb5ce7d2 | Isaku Yamahata | { |
410 | cb95c2e4 | Stefan Weil | return le64_to_cpup((const uint64_t *)config); |
411 | fb5ce7d2 | Isaku Yamahata | } |
412 | fb5ce7d2 | Isaku Yamahata | |
413 | fb5ce7d2 | Isaku Yamahata | static inline void |
414 | deb54399 | aliguori | pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val) |
415 | deb54399 | aliguori | { |
416 | 14e12559 | Michael S. Tsirkin | pci_set_word(&pci_config[PCI_VENDOR_ID], val); |
417 | deb54399 | aliguori | } |
418 | deb54399 | aliguori | |
419 | deb54399 | aliguori | static inline void |
420 | deb54399 | aliguori | pci_config_set_device_id(uint8_t *pci_config, uint16_t val) |
421 | deb54399 | aliguori | { |
422 | 14e12559 | Michael S. Tsirkin | pci_set_word(&pci_config[PCI_DEVICE_ID], val); |
423 | deb54399 | aliguori | } |
424 | deb54399 | aliguori | |
425 | 173a543b | blueswir1 | static inline void |
426 | cf602c7b | Izik Eidus | pci_config_set_revision(uint8_t *pci_config, uint8_t val) |
427 | cf602c7b | Izik Eidus | { |
428 | cf602c7b | Izik Eidus | pci_set_byte(&pci_config[PCI_REVISION_ID], val); |
429 | cf602c7b | Izik Eidus | } |
430 | cf602c7b | Izik Eidus | |
431 | cf602c7b | Izik Eidus | static inline void |
432 | 173a543b | blueswir1 | pci_config_set_class(uint8_t *pci_config, uint16_t val) |
433 | 173a543b | blueswir1 | { |
434 | 14e12559 | Michael S. Tsirkin | pci_set_word(&pci_config[PCI_CLASS_DEVICE], val); |
435 | 173a543b | blueswir1 | } |
436 | 173a543b | blueswir1 | |
437 | cf602c7b | Izik Eidus | static inline void |
438 | cf602c7b | Izik Eidus | pci_config_set_prog_interface(uint8_t *pci_config, uint8_t val) |
439 | cf602c7b | Izik Eidus | { |
440 | cf602c7b | Izik Eidus | pci_set_byte(&pci_config[PCI_CLASS_PROG], val); |
441 | cf602c7b | Izik Eidus | } |
442 | cf602c7b | Izik Eidus | |
443 | cf602c7b | Izik Eidus | static inline void |
444 | cf602c7b | Izik Eidus | pci_config_set_interrupt_pin(uint8_t *pci_config, uint8_t val) |
445 | cf602c7b | Izik Eidus | { |
446 | cf602c7b | Izik Eidus | pci_set_byte(&pci_config[PCI_INTERRUPT_PIN], val); |
447 | cf602c7b | Izik Eidus | } |
448 | cf602c7b | Izik Eidus | |
449 | aabcf526 | Isaku Yamahata | /*
|
450 | aabcf526 | Isaku Yamahata | * helper functions to do bit mask operation on configuration space.
|
451 | aabcf526 | Isaku Yamahata | * Just to set bit, use test-and-set and discard returned value.
|
452 | aabcf526 | Isaku Yamahata | * Just to clear bit, use test-and-clear and discard returned value.
|
453 | aabcf526 | Isaku Yamahata | * NOTE: They aren't atomic.
|
454 | aabcf526 | Isaku Yamahata | */
|
455 | aabcf526 | Isaku Yamahata | static inline uint8_t |
456 | aabcf526 | Isaku Yamahata | pci_byte_test_and_clear_mask(uint8_t *config, uint8_t mask) |
457 | aabcf526 | Isaku Yamahata | { |
458 | aabcf526 | Isaku Yamahata | uint8_t val = pci_get_byte(config); |
459 | aabcf526 | Isaku Yamahata | pci_set_byte(config, val & ~mask); |
460 | aabcf526 | Isaku Yamahata | return val & mask;
|
461 | aabcf526 | Isaku Yamahata | } |
462 | aabcf526 | Isaku Yamahata | |
463 | aabcf526 | Isaku Yamahata | static inline uint8_t |
464 | aabcf526 | Isaku Yamahata | pci_byte_test_and_set_mask(uint8_t *config, uint8_t mask) |
465 | aabcf526 | Isaku Yamahata | { |
466 | aabcf526 | Isaku Yamahata | uint8_t val = pci_get_byte(config); |
467 | aabcf526 | Isaku Yamahata | pci_set_byte(config, val | mask); |
468 | aabcf526 | Isaku Yamahata | return val & mask;
|
469 | aabcf526 | Isaku Yamahata | } |
470 | aabcf526 | Isaku Yamahata | |
471 | aabcf526 | Isaku Yamahata | static inline uint16_t |
472 | aabcf526 | Isaku Yamahata | pci_word_test_and_clear_mask(uint8_t *config, uint16_t mask) |
473 | aabcf526 | Isaku Yamahata | { |
474 | aabcf526 | Isaku Yamahata | uint16_t val = pci_get_word(config); |
475 | aabcf526 | Isaku Yamahata | pci_set_word(config, val & ~mask); |
476 | aabcf526 | Isaku Yamahata | return val & mask;
|
477 | aabcf526 | Isaku Yamahata | } |
478 | aabcf526 | Isaku Yamahata | |
479 | aabcf526 | Isaku Yamahata | static inline uint16_t |
480 | aabcf526 | Isaku Yamahata | pci_word_test_and_set_mask(uint8_t *config, uint16_t mask) |
481 | aabcf526 | Isaku Yamahata | { |
482 | aabcf526 | Isaku Yamahata | uint16_t val = pci_get_word(config); |
483 | aabcf526 | Isaku Yamahata | pci_set_word(config, val | mask); |
484 | aabcf526 | Isaku Yamahata | return val & mask;
|
485 | aabcf526 | Isaku Yamahata | } |
486 | aabcf526 | Isaku Yamahata | |
487 | aabcf526 | Isaku Yamahata | static inline uint32_t |
488 | aabcf526 | Isaku Yamahata | pci_long_test_and_clear_mask(uint8_t *config, uint32_t mask) |
489 | aabcf526 | Isaku Yamahata | { |
490 | aabcf526 | Isaku Yamahata | uint32_t val = pci_get_long(config); |
491 | aabcf526 | Isaku Yamahata | pci_set_long(config, val & ~mask); |
492 | aabcf526 | Isaku Yamahata | return val & mask;
|
493 | aabcf526 | Isaku Yamahata | } |
494 | aabcf526 | Isaku Yamahata | |
495 | aabcf526 | Isaku Yamahata | static inline uint32_t |
496 | aabcf526 | Isaku Yamahata | pci_long_test_and_set_mask(uint8_t *config, uint32_t mask) |
497 | aabcf526 | Isaku Yamahata | { |
498 | aabcf526 | Isaku Yamahata | uint32_t val = pci_get_long(config); |
499 | aabcf526 | Isaku Yamahata | pci_set_long(config, val | mask); |
500 | aabcf526 | Isaku Yamahata | return val & mask;
|
501 | aabcf526 | Isaku Yamahata | } |
502 | aabcf526 | Isaku Yamahata | |
503 | aabcf526 | Isaku Yamahata | static inline uint64_t |
504 | aabcf526 | Isaku Yamahata | pci_quad_test_and_clear_mask(uint8_t *config, uint64_t mask) |
505 | aabcf526 | Isaku Yamahata | { |
506 | aabcf526 | Isaku Yamahata | uint64_t val = pci_get_quad(config); |
507 | aabcf526 | Isaku Yamahata | pci_set_quad(config, val & ~mask); |
508 | aabcf526 | Isaku Yamahata | return val & mask;
|
509 | aabcf526 | Isaku Yamahata | } |
510 | aabcf526 | Isaku Yamahata | |
511 | aabcf526 | Isaku Yamahata | static inline uint64_t |
512 | aabcf526 | Isaku Yamahata | pci_quad_test_and_set_mask(uint8_t *config, uint64_t mask) |
513 | aabcf526 | Isaku Yamahata | { |
514 | aabcf526 | Isaku Yamahata | uint64_t val = pci_get_quad(config); |
515 | aabcf526 | Isaku Yamahata | pci_set_quad(config, val | mask); |
516 | aabcf526 | Isaku Yamahata | return val & mask;
|
517 | aabcf526 | Isaku Yamahata | } |
518 | aabcf526 | Isaku Yamahata | |
519 | c9f50cea | Michael S. Tsirkin | /* Access a register specified by a mask */
|
520 | c9f50cea | Michael S. Tsirkin | static inline void |
521 | c9f50cea | Michael S. Tsirkin | pci_set_byte_by_mask(uint8_t *config, uint8_t mask, uint8_t reg) |
522 | c9f50cea | Michael S. Tsirkin | { |
523 | c9f50cea | Michael S. Tsirkin | uint8_t val = pci_get_byte(config); |
524 | c9f50cea | Michael S. Tsirkin | uint8_t rval = reg << (ffs(mask) - 1);
|
525 | c9f50cea | Michael S. Tsirkin | pci_set_byte(config, (~mask & val) | (mask & rval)); |
526 | c9f50cea | Michael S. Tsirkin | } |
527 | c9f50cea | Michael S. Tsirkin | |
528 | c9f50cea | Michael S. Tsirkin | static inline uint8_t |
529 | c9f50cea | Michael S. Tsirkin | pci_get_byte_by_mask(uint8_t *config, uint8_t mask) |
530 | c9f50cea | Michael S. Tsirkin | { |
531 | c9f50cea | Michael S. Tsirkin | uint8_t val = pci_get_byte(config); |
532 | c9f50cea | Michael S. Tsirkin | return (val & mask) >> (ffs(mask) - 1); |
533 | c9f50cea | Michael S. Tsirkin | } |
534 | c9f50cea | Michael S. Tsirkin | |
535 | c9f50cea | Michael S. Tsirkin | static inline void |
536 | c9f50cea | Michael S. Tsirkin | pci_set_word_by_mask(uint8_t *config, uint16_t mask, uint16_t reg) |
537 | c9f50cea | Michael S. Tsirkin | { |
538 | c9f50cea | Michael S. Tsirkin | uint16_t val = pci_get_word(config); |
539 | c9f50cea | Michael S. Tsirkin | uint16_t rval = reg << (ffs(mask) - 1);
|
540 | c9f50cea | Michael S. Tsirkin | pci_set_word(config, (~mask & val) | (mask & rval)); |
541 | c9f50cea | Michael S. Tsirkin | } |
542 | c9f50cea | Michael S. Tsirkin | |
543 | c9f50cea | Michael S. Tsirkin | static inline uint16_t |
544 | c9f50cea | Michael S. Tsirkin | pci_get_word_by_mask(uint8_t *config, uint16_t mask) |
545 | c9f50cea | Michael S. Tsirkin | { |
546 | c9f50cea | Michael S. Tsirkin | uint16_t val = pci_get_word(config); |
547 | c9f50cea | Michael S. Tsirkin | return (val & mask) >> (ffs(mask) - 1); |
548 | c9f50cea | Michael S. Tsirkin | } |
549 | c9f50cea | Michael S. Tsirkin | |
550 | c9f50cea | Michael S. Tsirkin | static inline void |
551 | c9f50cea | Michael S. Tsirkin | pci_set_long_by_mask(uint8_t *config, uint32_t mask, uint32_t reg) |
552 | c9f50cea | Michael S. Tsirkin | { |
553 | c9f50cea | Michael S. Tsirkin | uint32_t val = pci_get_long(config); |
554 | c9f50cea | Michael S. Tsirkin | uint32_t rval = reg << (ffs(mask) - 1);
|
555 | c9f50cea | Michael S. Tsirkin | pci_set_long(config, (~mask & val) | (mask & rval)); |
556 | c9f50cea | Michael S. Tsirkin | } |
557 | c9f50cea | Michael S. Tsirkin | |
558 | c9f50cea | Michael S. Tsirkin | static inline uint32_t |
559 | c9f50cea | Michael S. Tsirkin | pci_get_long_by_mask(uint8_t *config, uint32_t mask) |
560 | c9f50cea | Michael S. Tsirkin | { |
561 | c9f50cea | Michael S. Tsirkin | uint32_t val = pci_get_long(config); |
562 | c9f50cea | Michael S. Tsirkin | return (val & mask) >> (ffs(mask) - 1); |
563 | c9f50cea | Michael S. Tsirkin | } |
564 | c9f50cea | Michael S. Tsirkin | |
565 | c9f50cea | Michael S. Tsirkin | static inline void |
566 | c9f50cea | Michael S. Tsirkin | pci_set_quad_by_mask(uint8_t *config, uint64_t mask, uint64_t reg) |
567 | c9f50cea | Michael S. Tsirkin | { |
568 | c9f50cea | Michael S. Tsirkin | uint64_t val = pci_get_quad(config); |
569 | c9f50cea | Michael S. Tsirkin | uint64_t rval = reg << (ffs(mask) - 1);
|
570 | c9f50cea | Michael S. Tsirkin | pci_set_quad(config, (~mask & val) | (mask & rval)); |
571 | c9f50cea | Michael S. Tsirkin | } |
572 | c9f50cea | Michael S. Tsirkin | |
573 | c9f50cea | Michael S. Tsirkin | static inline uint64_t |
574 | c9f50cea | Michael S. Tsirkin | pci_get_quad_by_mask(uint8_t *config, uint64_t mask) |
575 | c9f50cea | Michael S. Tsirkin | { |
576 | c9f50cea | Michael S. Tsirkin | uint64_t val = pci_get_quad(config); |
577 | c9f50cea | Michael S. Tsirkin | return (val & mask) >> (ffs(mask) - 1); |
578 | c9f50cea | Michael S. Tsirkin | } |
579 | c9f50cea | Michael S. Tsirkin | |
580 | 49823868 | Isaku Yamahata | PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction, |
581 | 49823868 | Isaku Yamahata | const char *name); |
582 | 49823868 | Isaku Yamahata | PCIDevice *pci_create_simple_multifunction(PCIBus *bus, int devfn,
|
583 | 49823868 | Isaku Yamahata | bool multifunction,
|
584 | 49823868 | Isaku Yamahata | const char *name); |
585 | 499cf102 | Markus Armbruster | PCIDevice *pci_create(PCIBus *bus, int devfn, const char *name); |
586 | 6b1b92d3 | Paul Brook | PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name); |
587 | 6b1b92d3 | Paul Brook | |
588 | 3c18685f | Isaku Yamahata | static inline int pci_is_express(const PCIDevice *d) |
589 | a9f49946 | Isaku Yamahata | { |
590 | a9f49946 | Isaku Yamahata | return d->cap_present & QEMU_PCI_CAP_EXPRESS;
|
591 | a9f49946 | Isaku Yamahata | } |
592 | a9f49946 | Isaku Yamahata | |
593 | 3c18685f | Isaku Yamahata | static inline uint32_t pci_config_size(const PCIDevice *d) |
594 | a9f49946 | Isaku Yamahata | { |
595 | a9f49946 | Isaku Yamahata | return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : PCI_CONFIG_SPACE_SIZE;
|
596 | a9f49946 | Isaku Yamahata | } |
597 | a9f49946 | Isaku Yamahata | |
598 | ec174575 | David Gibson | /* DMA access functions */
|
599 | d86a77f8 | David Gibson | static inline DMAContext *pci_dma_context(PCIDevice *dev) |
600 | d86a77f8 | David Gibson | { |
601 | 5fa45de5 | David Gibson | return dev->dma;
|
602 | d86a77f8 | David Gibson | } |
603 | d86a77f8 | David Gibson | |
604 | ec174575 | David Gibson | static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr, |
605 | ec174575 | David Gibson | void *buf, dma_addr_t len, DMADirection dir)
|
606 | ec174575 | David Gibson | { |
607 | d86a77f8 | David Gibson | dma_memory_rw(pci_dma_context(dev), addr, buf, len, dir); |
608 | ec174575 | David Gibson | return 0; |
609 | ec174575 | David Gibson | } |
610 | ec174575 | David Gibson | |
611 | ec174575 | David Gibson | static inline int pci_dma_read(PCIDevice *dev, dma_addr_t addr, |
612 | ec174575 | David Gibson | void *buf, dma_addr_t len)
|
613 | ec174575 | David Gibson | { |
614 | ec174575 | David Gibson | return pci_dma_rw(dev, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
|
615 | ec174575 | David Gibson | } |
616 | ec174575 | David Gibson | |
617 | ec174575 | David Gibson | static inline int pci_dma_write(PCIDevice *dev, dma_addr_t addr, |
618 | ec174575 | David Gibson | const void *buf, dma_addr_t len) |
619 | ec174575 | David Gibson | { |
620 | ec174575 | David Gibson | return pci_dma_rw(dev, addr, (void *) buf, len, DMA_DIRECTION_FROM_DEVICE); |
621 | ec174575 | David Gibson | } |
622 | ec174575 | David Gibson | |
623 | ec174575 | David Gibson | #define PCI_DMA_DEFINE_LDST(_l, _s, _bits) \
|
624 | ec174575 | David Gibson | static inline uint##_bits##_t ld##_l##_pci_dma(PCIDevice *dev, \ |
625 | ec174575 | David Gibson | dma_addr_t addr) \ |
626 | ec174575 | David Gibson | { \ |
627 | d86a77f8 | David Gibson | return ld##_l##_dma(pci_dma_context(dev), addr); \ |
628 | ec174575 | David Gibson | } \ |
629 | ec174575 | David Gibson | static inline void st##_s##_pci_dma(PCIDevice *dev, \ |
630 | d86a77f8 | David Gibson | dma_addr_t addr, uint##_bits##_t val) \ |
631 | ec174575 | David Gibson | { \ |
632 | d86a77f8 | David Gibson | st##_s##_dma(pci_dma_context(dev), addr, val); \ |
633 | ec174575 | David Gibson | } |
634 | ec174575 | David Gibson | |
635 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(ub, b, 8);
|
636 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(uw_le, w_le, 16)
|
637 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(l_le, l_le, 32);
|
638 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(q_le, q_le, 64);
|
639 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(uw_be, w_be, 16)
|
640 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(l_be, l_be, 32);
|
641 | ec174575 | David Gibson | PCI_DMA_DEFINE_LDST(q_be, q_be, 64);
|
642 | ec174575 | David Gibson | |
643 | ec174575 | David Gibson | #undef PCI_DMA_DEFINE_LDST
|
644 | ec174575 | David Gibson | |
645 | ec174575 | David Gibson | static inline void *pci_dma_map(PCIDevice *dev, dma_addr_t addr, |
646 | ec174575 | David Gibson | dma_addr_t *plen, DMADirection dir) |
647 | ec174575 | David Gibson | { |
648 | ec174575 | David Gibson | void *buf;
|
649 | ec174575 | David Gibson | |
650 | d86a77f8 | David Gibson | buf = dma_memory_map(pci_dma_context(dev), addr, plen, dir); |
651 | ec174575 | David Gibson | return buf;
|
652 | ec174575 | David Gibson | } |
653 | ec174575 | David Gibson | |
654 | ec174575 | David Gibson | static inline void pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len, |
655 | ec174575 | David Gibson | DMADirection dir, dma_addr_t access_len) |
656 | ec174575 | David Gibson | { |
657 | d86a77f8 | David Gibson | dma_memory_unmap(pci_dma_context(dev), buffer, len, dir, access_len); |
658 | ec174575 | David Gibson | } |
659 | ec174575 | David Gibson | |
660 | ec174575 | David Gibson | static inline void pci_dma_sglist_init(QEMUSGList *qsg, PCIDevice *dev, |
661 | ec174575 | David Gibson | int alloc_hint)
|
662 | ec174575 | David Gibson | { |
663 | c65bcef3 | David Gibson | qemu_sglist_init(qsg, alloc_hint, pci_dma_context(dev)); |
664 | ec174575 | David Gibson | } |
665 | ec174575 | David Gibson | |
666 | 701a8f76 | Paolo Bonzini | extern const VMStateDescription vmstate_pci_device; |
667 | 701a8f76 | Paolo Bonzini | |
668 | 701a8f76 | Paolo Bonzini | #define VMSTATE_PCI_DEVICE(_field, _state) { \
|
669 | 701a8f76 | Paolo Bonzini | .name = (stringify(_field)), \ |
670 | 701a8f76 | Paolo Bonzini | .size = sizeof(PCIDevice), \
|
671 | 701a8f76 | Paolo Bonzini | .vmsd = &vmstate_pci_device, \ |
672 | 701a8f76 | Paolo Bonzini | .flags = VMS_STRUCT, \ |
673 | 701a8f76 | Paolo Bonzini | .offset = vmstate_offset_value(_state, _field, PCIDevice), \ |
674 | 701a8f76 | Paolo Bonzini | } |
675 | 701a8f76 | Paolo Bonzini | |
676 | 701a8f76 | Paolo Bonzini | #define VMSTATE_PCI_DEVICE_POINTER(_field, _state) { \
|
677 | 701a8f76 | Paolo Bonzini | .name = (stringify(_field)), \ |
678 | 701a8f76 | Paolo Bonzini | .size = sizeof(PCIDevice), \
|
679 | 701a8f76 | Paolo Bonzini | .vmsd = &vmstate_pci_device, \ |
680 | 701a8f76 | Paolo Bonzini | .flags = VMS_STRUCT|VMS_POINTER, \ |
681 | 701a8f76 | Paolo Bonzini | .offset = vmstate_offset_pointer(_state, _field, PCIDevice), \ |
682 | 701a8f76 | Paolo Bonzini | } |
683 | 701a8f76 | Paolo Bonzini | |
684 | 87ecb68b | pbrook | #endif |