cxl_pci.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * QEMU CXL PCI interfaces
  3. *
  4. * Copyright (c) 2020 Intel
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2. See the
  7. * COPYING file in the top-level directory.
  8. */
  9. #ifndef CXL_PCI_H
  10. #define CXL_PCI_H
  11. #define CXL_VENDOR_ID 0x1e98
  12. #define PCIE_DVSEC_HEADER1_OFFSET 0x4 /* Offset from start of extend cap */
  13. #define PCIE_DVSEC_ID_OFFSET 0x8
  14. #define PCIE_CXL_DEVICE_DVSEC_LENGTH 0x3C
  15. #define PCIE_CXL31_DEVICE_DVSEC_REVID 3
  16. #define EXTENSIONS_PORT_DVSEC_LENGTH 0x28
  17. #define EXTENSIONS_PORT_DVSEC_REVID 0
  18. #define GPF_PORT_DVSEC_LENGTH 0x10
  19. #define GPF_PORT_DVSEC_REVID 0
  20. #define GPF_DEVICE_DVSEC_LENGTH 0x10
  21. #define GPF_DEVICE_DVSEC_REVID 0
  22. #define PCIE_CXL3_FLEXBUS_PORT_DVSEC_LENGTH 0x20
  23. #define PCIE_CXL3_FLEXBUS_PORT_DVSEC_REVID 2
  24. #define REG_LOC_DVSEC_LENGTH 0x24
  25. #define REG_LOC_DVSEC_REVID 0
  26. enum {
  27. PCIE_CXL_DEVICE_DVSEC = 0,
  28. NON_CXL_FUNCTION_MAP_DVSEC = 2,
  29. EXTENSIONS_PORT_DVSEC = 3,
  30. GPF_PORT_DVSEC = 4,
  31. GPF_DEVICE_DVSEC = 5,
  32. PCIE_FLEXBUS_PORT_DVSEC = 7,
  33. REG_LOC_DVSEC = 8,
  34. MLD_DVSEC = 9,
  35. CXL20_MAX_DVSEC
  36. };
  37. typedef struct DVSECHeader {
  38. uint32_t cap_hdr;
  39. uint32_t dv_hdr1;
  40. uint16_t dv_hdr2;
  41. } QEMU_PACKED DVSECHeader;
  42. QEMU_BUILD_BUG_ON(sizeof(DVSECHeader) != 10);
  43. /*
  44. * CXL r3.1 Table 8-2: CXL DVSEC ID Assignment
  45. * Devices must implement certain DVSEC IDs, and can [optionally]
  46. * implement others.
  47. * (x) - IDs in Table 8-2.
  48. *
  49. * CXL RCD (D1): 0, [2], [5], 7, [8], A - Not emulated yet
  50. * CXL RCD USP (UP1): 7, [8] - Not emulated yet
  51. * CXL RCH DSP (DP1): 7, [8]
  52. * CXL SLD (D2): 0, [2], 5, 7, 8, [A]
  53. * CXL LD (LD): 0, [2], 5, 7, 8
  54. * CXL RP (R): 3, 4, 7, 8
  55. * CXL Switch USP (USP): [2], 7, 8
  56. * CXL Switch DSP (DSP): 3, 4, 7, 8
  57. * FM-Owned LD (FMLD): 0, [2], 7, 8, 9
  58. */
  59. /*
  60. * CXL r3.1 Section 8.1.3: PCIe DVSEC for Devices
  61. * DVSEC ID: 0, Revision: 3
  62. */
  63. typedef struct CXLDVSECDevice {
  64. DVSECHeader hdr;
  65. uint16_t cap;
  66. uint16_t ctrl;
  67. uint16_t status;
  68. uint16_t ctrl2;
  69. uint16_t status2;
  70. uint16_t lock;
  71. uint16_t cap2;
  72. uint32_t range1_size_hi;
  73. uint32_t range1_size_lo;
  74. uint32_t range1_base_hi;
  75. uint32_t range1_base_lo;
  76. uint32_t range2_size_hi;
  77. uint32_t range2_size_lo;
  78. uint32_t range2_base_hi;
  79. uint32_t range2_base_lo;
  80. uint16_t cap3;
  81. uint16_t resv;
  82. } QEMU_PACKED CXLDVSECDevice;
  83. QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDevice) != PCIE_CXL_DEVICE_DVSEC_LENGTH);
  84. /*
  85. * CXL r3.1 Section 8.1.5: CXL Extensions DVSEC for Ports
  86. * DVSEC ID: 3, Revision: 0
  87. */
  88. typedef struct CXLDVSECPortExt {
  89. DVSECHeader hdr;
  90. uint16_t status;
  91. uint16_t control;
  92. uint8_t alt_bus_base;
  93. uint8_t alt_bus_limit;
  94. uint16_t alt_memory_base;
  95. uint16_t alt_memory_limit;
  96. uint16_t alt_prefetch_base;
  97. uint16_t alt_prefetch_limit;
  98. uint32_t alt_prefetch_base_high;
  99. uint32_t alt_prefetch_limit_high;
  100. uint32_t rcrb_base;
  101. uint32_t rcrb_base_high;
  102. } CXLDVSECPortExt;
  103. QEMU_BUILD_BUG_ON(sizeof(CXLDVSECPortExt) != 0x28);
  104. #define PORT_CONTROL_OFFSET 0xc
  105. #define PORT_CONTROL_UNMASK_SBR 1
  106. #define PORT_CONTROL_ALT_MEMID_EN 4
  107. /*
  108. * CXL r3.1 Section 8.1.6: GPF DVSEC for CXL Port
  109. * DVSEC ID: 4, Revision: 0
  110. */
  111. typedef struct CXLDVSECPortGPF {
  112. DVSECHeader hdr;
  113. uint16_t rsvd;
  114. uint16_t phase1_ctrl;
  115. uint16_t phase2_ctrl;
  116. } CXLDVSECPortGPF;
  117. QEMU_BUILD_BUG_ON(sizeof(CXLDVSECPortGPF) != 0x10);
  118. /*
  119. * CXL r3.1 Section 8.1.7: GPF DVSEC for CXL Device
  120. * DVSEC ID: 5, Revision 0
  121. */
  122. typedef struct CXLDVSECDeviceGPF {
  123. DVSECHeader hdr;
  124. uint16_t phase2_duration;
  125. uint32_t phase2_power;
  126. } CXLDVSECDeviceGPF;
  127. QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDeviceGPF) != 0x10);
  128. /*
  129. * CXL r3.1 Section 8.1.8: PCIe DVSEC for Flex Bus Port
  130. * CXL r3.1 Section 8.2.1.3: Flex Bus Port DVSEC
  131. * DVSEC ID: 7, Revision 2
  132. */
  133. typedef struct CXLDVSECPortFlexBus {
  134. DVSECHeader hdr;
  135. uint16_t cap;
  136. uint16_t ctrl;
  137. uint16_t status;
  138. uint32_t rcvd_mod_ts_data_phase1;
  139. uint32_t cap2;
  140. uint32_t ctrl2;
  141. uint32_t status2;
  142. } CXLDVSECPortFlexBus;
  143. QEMU_BUILD_BUG_ON(sizeof(CXLDVSECPortFlexBus) != 0x20);
  144. /*
  145. * CXL r3.1 Section 8.1.9: Register Locator DVSEC
  146. * DVSEC ID: 8, Revision 0
  147. */
  148. typedef struct CXLDVSECRegisterLocator {
  149. DVSECHeader hdr;
  150. uint16_t rsvd;
  151. uint32_t reg0_base_lo;
  152. uint32_t reg0_base_hi;
  153. uint32_t reg1_base_lo;
  154. uint32_t reg1_base_hi;
  155. uint32_t reg2_base_lo;
  156. uint32_t reg2_base_hi;
  157. } CXLDVSECRegisterLocator;
  158. QEMU_BUILD_BUG_ON(sizeof(CXLDVSECRegisterLocator) != 0x24);
  159. /* BAR Equivalence Indicator */
  160. #define BEI_BAR_10H 0
  161. #define BEI_BAR_14H 1
  162. #define BEI_BAR_18H 2
  163. #define BEI_BAR_1cH 3
  164. #define BEI_BAR_20H 4
  165. #define BEI_BAR_24H 5
  166. /* Register Block Identifier */
  167. #define RBI_EMPTY 0
  168. #define RBI_COMPONENT_REG (1 << 8)
  169. #define RBI_BAR_VIRT_ACL (2 << 8)
  170. #define RBI_CXL_DEVICE_REG (3 << 8)
  171. #endif