pci.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * libqos PCI bindings
  3. *
  4. * Copyright IBM, Corp. 2012-2013
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #ifndef LIBQOS_PCI_H
  13. #define LIBQOS_PCI_H
  14. #include "../libqtest.h"
  15. #include "qgraph.h"
  16. #define QPCI_PIO_LIMIT 0x10000
  17. #define QPCI_DEVFN(dev, fn) (((dev) << 3) | (fn))
  18. typedef struct QPCIDevice QPCIDevice;
  19. typedef struct QPCIBus QPCIBus;
  20. typedef struct QPCIBar QPCIBar;
  21. typedef struct QPCIAddress QPCIAddress;
  22. struct QPCIBus {
  23. uint8_t (*pio_readb)(QPCIBus *bus, uint32_t addr);
  24. uint16_t (*pio_readw)(QPCIBus *bus, uint32_t addr);
  25. uint32_t (*pio_readl)(QPCIBus *bus, uint32_t addr);
  26. uint64_t (*pio_readq)(QPCIBus *bus, uint32_t addr);
  27. void (*pio_writeb)(QPCIBus *bus, uint32_t addr, uint8_t value);
  28. void (*pio_writew)(QPCIBus *bus, uint32_t addr, uint16_t value);
  29. void (*pio_writel)(QPCIBus *bus, uint32_t addr, uint32_t value);
  30. void (*pio_writeq)(QPCIBus *bus, uint32_t addr, uint64_t value);
  31. void (*memread)(QPCIBus *bus, uint32_t addr, void *buf, size_t len);
  32. void (*memwrite)(QPCIBus *bus, uint32_t addr, const void *buf, size_t len);
  33. uint8_t (*config_readb)(QPCIBus *bus, int devfn, uint8_t offset);
  34. uint16_t (*config_readw)(QPCIBus *bus, int devfn, uint8_t offset);
  35. uint32_t (*config_readl)(QPCIBus *bus, int devfn, uint8_t offset);
  36. void (*config_writeb)(QPCIBus *bus, int devfn,
  37. uint8_t offset, uint8_t value);
  38. void (*config_writew)(QPCIBus *bus, int devfn,
  39. uint8_t offset, uint16_t value);
  40. void (*config_writel)(QPCIBus *bus, int devfn,
  41. uint8_t offset, uint32_t value);
  42. QTestState *qts;
  43. uint16_t pio_alloc_ptr;
  44. uint64_t mmio_alloc_ptr, mmio_limit;
  45. bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */
  46. };
  47. struct QPCIBar {
  48. uint64_t addr;
  49. };
  50. struct QPCIDevice
  51. {
  52. QPCIBus *bus;
  53. int devfn;
  54. bool msix_enabled;
  55. QPCIBar msix_table_bar, msix_pba_bar;
  56. uint64_t msix_table_off, msix_pba_off;
  57. };
  58. struct QPCIAddress {
  59. uint32_t devfn;
  60. uint16_t vendor_id;
  61. uint16_t device_id;
  62. };
  63. void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
  64. void (*func)(QPCIDevice *dev, int devfn, void *data),
  65. void *data);
  66. QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
  67. void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr);
  68. int qpci_secondary_buses_init(QPCIBus *bus);
  69. bool qpci_has_buggy_msi(QPCIDevice *dev);
  70. bool qpci_check_buggy_msi(QPCIDevice *dev);
  71. void qpci_device_enable(QPCIDevice *dev);
  72. uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id, uint8_t start_addr);
  73. void qpci_msix_enable(QPCIDevice *dev);
  74. void qpci_msix_disable(QPCIDevice *dev);
  75. bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry);
  76. bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry);
  77. uint16_t qpci_msix_table_size(QPCIDevice *dev);
  78. uint8_t qpci_config_readb(QPCIDevice *dev, uint8_t offset);
  79. uint16_t qpci_config_readw(QPCIDevice *dev, uint8_t offset);
  80. uint32_t qpci_config_readl(QPCIDevice *dev, uint8_t offset);
  81. void qpci_config_writeb(QPCIDevice *dev, uint8_t offset, uint8_t value);
  82. void qpci_config_writew(QPCIDevice *dev, uint8_t offset, uint16_t value);
  83. void qpci_config_writel(QPCIDevice *dev, uint8_t offset, uint32_t value);
  84. uint8_t qpci_io_readb(QPCIDevice *dev, QPCIBar token, uint64_t off);
  85. uint16_t qpci_io_readw(QPCIDevice *dev, QPCIBar token, uint64_t off);
  86. uint32_t qpci_io_readl(QPCIDevice *dev, QPCIBar token, uint64_t off);
  87. uint64_t qpci_io_readq(QPCIDevice *dev, QPCIBar token, uint64_t off);
  88. void qpci_io_writeb(QPCIDevice *dev, QPCIBar token, uint64_t off,
  89. uint8_t value);
  90. void qpci_io_writew(QPCIDevice *dev, QPCIBar token, uint64_t off,
  91. uint16_t value);
  92. void qpci_io_writel(QPCIDevice *dev, QPCIBar token, uint64_t off,
  93. uint32_t value);
  94. void qpci_io_writeq(QPCIDevice *dev, QPCIBar token, uint64_t off,
  95. uint64_t value);
  96. void qpci_memread(QPCIDevice *bus, QPCIBar token, uint64_t off,
  97. void *buf, size_t len);
  98. void qpci_memwrite(QPCIDevice *bus, QPCIBar token, uint64_t off,
  99. const void *buf, size_t len);
  100. QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
  101. void qpci_iounmap(QPCIDevice *dev, QPCIBar addr);
  102. QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
  103. void qpci_unplug_acpi_device_test(QTestState *qs, const char *id, uint8_t slot);
  104. void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr);
  105. #endif