pci_bridge.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * QEMU PCI bridge
  3. *
  4. * Copyright (c) 2004 Fabrice Bellard
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. *
  20. * split out pci bus specific stuff from pci.[hc] to pci_bridge.[hc]
  21. * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
  22. * VA Linux Systems Japan K.K.
  23. *
  24. */
  25. #ifndef QEMU_PCI_BRIDGE_H
  26. #define QEMU_PCI_BRIDGE_H
  27. #include "hw/pci/pci_device.h"
  28. #include "hw/pci/pci_bus.h"
  29. #include "hw/cxl/cxl.h"
  30. #include "qom/object.h"
  31. typedef struct PCIBridgeWindows PCIBridgeWindows;
  32. /*
  33. * Aliases for each of the address space windows that the bridge
  34. * can forward. Mapped into the bridge's parent's address space,
  35. * as subregions.
  36. */
  37. struct PCIBridgeWindows {
  38. MemoryRegion alias_pref_mem;
  39. MemoryRegion alias_mem;
  40. MemoryRegion alias_io;
  41. /*
  42. * When bridge control VGA forwarding is enabled, bridges will
  43. * provide positive decode on the PCI VGA defined I/O port and
  44. * MMIO ranges. When enabled forwarding is only qualified on the
  45. * I/O and memory enable bits in the bridge command register.
  46. */
  47. MemoryRegion alias_vga[QEMU_PCI_VGA_NUM_REGIONS];
  48. };
  49. #define TYPE_PCI_BRIDGE "base-pci-bridge"
  50. OBJECT_DECLARE_SIMPLE_TYPE(PCIBridge, PCI_BRIDGE)
  51. #define IS_PCI_BRIDGE(dev) object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)
  52. struct PCIBridge {
  53. /*< private >*/
  54. PCIDevice parent_obj;
  55. /*< public >*/
  56. /* private member */
  57. PCIBus sec_bus;
  58. /*
  59. * Memory regions for the bridge's address spaces. These regions are not
  60. * directly added to system_memory/system_io or its descendants.
  61. * Bridge's secondary bus points to these, so that devices
  62. * under the bridge see these regions as its address spaces.
  63. * The regions are as large as the entire address space -
  64. * they don't take into account any windows.
  65. */
  66. MemoryRegion address_space_mem;
  67. MemoryRegion address_space_io;
  68. PCIBridgeWindows *windows;
  69. pci_map_irq_fn map_irq;
  70. const char *bus_name;
  71. };
  72. #define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr"
  73. #define PCI_BRIDGE_DEV_PROP_MSI "msi"
  74. #define PCI_BRIDGE_DEV_PROP_SHPC "shpc"
  75. typedef struct CXLHost CXLHost;
  76. struct PXBDev {
  77. /*< private >*/
  78. PCIDevice parent_obj;
  79. /*< public >*/
  80. uint8_t bus_nr;
  81. uint16_t numa_node;
  82. bool bypass_iommu;
  83. struct cxl_dev {
  84. CXLHost *cxl_host_bridge; /* Pointer to a CXLHost */
  85. } cxl;
  86. };
  87. #define TYPE_PXB_CXL_DEVICE "pxb-cxl"
  88. DECLARE_INSTANCE_CHECKER(PXBDev, PXB_CXL_DEV,
  89. TYPE_PXB_CXL_DEVICE)
  90. int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
  91. uint16_t svid, uint16_t ssid,
  92. Error **errp);
  93. PCIDevice *pci_bridge_get_device(PCIBus *bus);
  94. PCIBus *pci_bridge_get_sec_bus(PCIBridge *br);
  95. pcibus_t pci_bridge_get_base(const PCIDevice *bridge, uint8_t type);
  96. pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
  97. void pci_bridge_update_mappings(PCIBridge *br);
  98. void pci_bridge_write_config(PCIDevice *d,
  99. uint32_t address, uint32_t val, int len);
  100. void pci_bridge_disable_base_limit(PCIDevice *dev);
  101. void pci_bridge_reset(DeviceState *qdev);
  102. void pci_bridge_initfn(PCIDevice *pci_dev, const char *typename);
  103. void pci_bridge_exitfn(PCIDevice *pci_dev);
  104. void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
  105. Error **errp);
  106. void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
  107. Error **errp);
  108. void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
  109. DeviceState *dev, Error **errp);
  110. /*
  111. * before qdev initialization(qdev_init()), this function sets bus_name and
  112. * map_irq callback which are necessary for pci_bridge_initfn() to
  113. * initialize bus.
  114. */
  115. void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,
  116. pci_map_irq_fn map_irq);
  117. /* TODO: add this define to pci_regs.h in linux and then in qemu. */
  118. #define PCI_BRIDGE_CTL_VGA_16BIT 0x10 /* VGA 16-bit decode */
  119. #define PCI_BRIDGE_CTL_DISCARD 0x100 /* Primary discard timer */
  120. #define PCI_BRIDGE_CTL_SEC_DISCARD 0x200 /* Secondary discard timer */
  121. #define PCI_BRIDGE_CTL_DISCARD_STATUS 0x400 /* Discard timer status */
  122. #define PCI_BRIDGE_CTL_DISCARD_SERR 0x800 /* Discard timer SERR# enable */
  123. typedef struct PCIBridgeQemuCap {
  124. uint8_t id; /* Standard PCI capability header field */
  125. uint8_t next; /* Standard PCI capability header field */
  126. uint8_t len; /* Standard PCI vendor-specific capability header field */
  127. uint8_t type; /* Red Hat vendor-specific capability type.
  128. Types are defined with REDHAT_PCI_CAP_ prefix */
  129. uint32_t bus_res; /* Minimum number of buses to reserve */
  130. uint64_t io; /* IO space to reserve */
  131. uint32_t mem; /* Non-prefetchable memory to reserve */
  132. /* At most one of the following two fields may be set to a value
  133. * different from -1 */
  134. uint32_t mem_pref_32; /* Prefetchable memory to reserve (32-bit MMIO) */
  135. uint64_t mem_pref_64; /* Prefetchable memory to reserve (64-bit MMIO) */
  136. } PCIBridgeQemuCap;
  137. #define REDHAT_PCI_CAP_TYPE_OFFSET 3
  138. #define REDHAT_PCI_CAP_RESOURCE_RESERVE 1
  139. /*
  140. * PCI BUS/IO/MEM/PREFMEM additional resources recorded as a
  141. * capability in PCI configuration space to reserve on firmware init.
  142. */
  143. typedef struct PCIResReserve {
  144. uint32_t bus;
  145. uint64_t io;
  146. uint64_t mem_non_pref;
  147. uint64_t mem_pref_32;
  148. uint64_t mem_pref_64;
  149. } PCIResReserve;
  150. #define REDHAT_PCI_CAP_RES_RESERVE_BUS_RES 4
  151. #define REDHAT_PCI_CAP_RES_RESERVE_IO 8
  152. #define REDHAT_PCI_CAP_RES_RESERVE_MEM 16
  153. #define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_32 20
  154. #define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_64 24
  155. #define REDHAT_PCI_CAP_RES_RESERVE_CAP_SIZE 32
  156. int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,
  157. PCIResReserve res_reserve, Error **errp);
  158. #endif /* QEMU_PCI_BRIDGE_H */