Commit 14e12559919195d817d94bc5590a8a26c70e2298
Committed by
Anthony Liguori
1 parent
b7ee1603
qemu/pci: helper routines for pci access
Add inline routines for convenient access to pci devices with correct (little) endianness. Will be used by MSI-X support. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
27 additions
and
3 deletions
hw/pci.h
... | ... | @@ -215,21 +215,45 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, |
215 | 215 | pci_map_irq_fn map_irq, const char *name); |
216 | 216 | |
217 | 217 | static inline void |
218 | +pci_set_word(uint8_t *config, uint16_t val) | |
219 | +{ | |
220 | + cpu_to_le16wu((uint16_t *)config, val); | |
221 | +} | |
222 | + | |
223 | +static inline uint16_t | |
224 | +pci_get_word(uint8_t *config) | |
225 | +{ | |
226 | + return le16_to_cpupu((uint16_t *)config); | |
227 | +} | |
228 | + | |
229 | +static inline void | |
230 | +pci_set_long(uint8_t *config, uint32_t val) | |
231 | +{ | |
232 | + cpu_to_le32wu((uint32_t *)config, val); | |
233 | +} | |
234 | + | |
235 | +static inline uint32_t | |
236 | +pci_get_long(uint8_t *config) | |
237 | +{ | |
238 | + return le32_to_cpupu((uint32_t *)config); | |
239 | +} | |
240 | + | |
241 | +static inline void | |
218 | 242 | pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val) |
219 | 243 | { |
220 | - cpu_to_le16wu((uint16_t *)&pci_config[PCI_VENDOR_ID], val); | |
244 | + pci_set_word(&pci_config[PCI_VENDOR_ID], val); | |
221 | 245 | } |
222 | 246 | |
223 | 247 | static inline void |
224 | 248 | pci_config_set_device_id(uint8_t *pci_config, uint16_t val) |
225 | 249 | { |
226 | - cpu_to_le16wu((uint16_t *)&pci_config[PCI_DEVICE_ID], val); | |
250 | + pci_set_word(&pci_config[PCI_DEVICE_ID], val); | |
227 | 251 | } |
228 | 252 | |
229 | 253 | static inline void |
230 | 254 | pci_config_set_class(uint8_t *pci_config, uint16_t val) |
231 | 255 | { |
232 | - cpu_to_le16wu((uint16_t *)&pci_config[PCI_CLASS_DEVICE], val); | |
256 | + pci_set_word(&pci_config[PCI_CLASS_DEVICE], val); | |
233 | 257 | } |
234 | 258 | |
235 | 259 | typedef void (*pci_qdev_initfn)(PCIDevice *dev); | ... | ... |