2
0

cxl_cdat.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * CXL CDAT Structure
  3. *
  4. * Copyright (C) 2021 Avery Design Systems, Inc.
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #ifndef CXL_CDAT_H
  10. #define CXL_CDAT_H
  11. #include "hw/cxl/cxl_pci.h"
  12. #include "hw/pci/pcie_doe.h"
  13. /*
  14. * Reference:
  15. * Coherent Device Attribute Table (CDAT) Specification, Rev. 1.03, July. 2022
  16. * Compute Express Link (CXL) Specification, Rev. 3.1, Aug. 2023
  17. */
  18. /* Table Access DOE - CXL r3.1 8.1.11 */
  19. #define CXL_DOE_TABLE_ACCESS 2
  20. #define CXL_DOE_PROTOCOL_CDAT ((CXL_DOE_TABLE_ACCESS << 16) | CXL_VENDOR_ID)
  21. /* Read Entry - CXL r3.1 8.1.11.1 */
  22. #define CXL_DOE_TAB_TYPE_CDAT 0
  23. #define CXL_DOE_TAB_ENT_MAX 0xFFFF
  24. /* Read Entry Request - CXL r3.1 8.1.11.1 Table 8-13 */
  25. #define CXL_DOE_TAB_REQ 0
  26. typedef struct CDATReq {
  27. DOEHeader header;
  28. uint8_t req_code;
  29. uint8_t table_type;
  30. uint16_t entry_handle;
  31. } QEMU_PACKED CDATReq;
  32. /* Read Entry Response - CXL r3.1 8.1.11.1 Table 8-14 */
  33. #define CXL_DOE_TAB_RSP 0
  34. typedef struct CDATRsp {
  35. DOEHeader header;
  36. uint8_t rsp_code;
  37. uint8_t table_type;
  38. uint16_t entry_handle;
  39. } QEMU_PACKED CDATRsp;
  40. /* CDAT Table Format - CDAT Table 1 */
  41. #define CXL_CDAT_REV 2
  42. typedef struct CDATTableHeader {
  43. uint32_t length;
  44. uint8_t revision;
  45. uint8_t checksum;
  46. uint8_t reserved[6];
  47. uint32_t sequence;
  48. } QEMU_PACKED CDATTableHeader;
  49. /* CDAT Structure Types - CDAT Table 2 */
  50. typedef enum {
  51. CDAT_TYPE_DSMAS = 0,
  52. CDAT_TYPE_DSLBIS = 1,
  53. CDAT_TYPE_DSMSCIS = 2,
  54. CDAT_TYPE_DSIS = 3,
  55. CDAT_TYPE_DSEMTS = 4,
  56. CDAT_TYPE_SSLBIS = 5,
  57. } CDATType;
  58. typedef struct CDATSubHeader {
  59. uint8_t type;
  60. uint8_t reserved;
  61. uint16_t length;
  62. } CDATSubHeader;
  63. /* Device Scoped Memory Affinity Structure - CDAT Table 3 */
  64. typedef struct CDATDsmas {
  65. CDATSubHeader header;
  66. uint8_t DSMADhandle;
  67. uint8_t flags;
  68. #define CDAT_DSMAS_FLAG_NV (1 << 2)
  69. #define CDAT_DSMAS_FLAG_SHAREABLE (1 << 3)
  70. #define CDAT_DSMAS_FLAG_HW_COHERENT (1 << 4)
  71. #define CDAT_DSMAS_FLAG_DYNAMIC_CAP (1 << 5)
  72. uint16_t reserved;
  73. uint64_t DPA_base;
  74. uint64_t DPA_length;
  75. } CDATDsmas;
  76. QEMU_BUILD_BUG_ON(sizeof(CDATDsmas) != 24);
  77. /* Device Scoped Latency and Bandwidth Information Structure - CDAT Table 5 */
  78. typedef struct CDATDslbis {
  79. CDATSubHeader header;
  80. uint8_t handle;
  81. /* Definitions of these fields refer directly to HMAT fields */
  82. uint8_t flags;
  83. uint8_t data_type;
  84. uint8_t reserved;
  85. uint64_t entry_base_unit;
  86. uint16_t entry[3];
  87. uint16_t reserved2;
  88. } CDATDslbis;
  89. QEMU_BUILD_BUG_ON(sizeof(CDATDslbis) != 24);
  90. /* Device Scoped Memory Side Cache Information Structure - CDAT Table 6 */
  91. typedef struct CDATDsmscis {
  92. CDATSubHeader header;
  93. uint8_t DSMAS_handle;
  94. uint8_t reserved[3];
  95. uint64_t memory_side_cache_size;
  96. uint32_t cache_attributes;
  97. } QEMU_PACKED CDATDsmscis;
  98. /* Device Scoped Initiator Structure - CDAT Table 7 */
  99. typedef struct CDATDsis {
  100. CDATSubHeader header;
  101. uint8_t flags;
  102. uint8_t handle;
  103. uint16_t reserved;
  104. } QEMU_PACKED CDATDsis;
  105. /* Device Scoped EFI Memory Type Structure - CDAT Table 8 */
  106. typedef struct CDATDsemts {
  107. CDATSubHeader header;
  108. uint8_t DSMAS_handle;
  109. uint8_t EFI_memory_type_attr;
  110. uint16_t reserved;
  111. uint64_t DPA_offset;
  112. uint64_t DPA_length;
  113. } CDATDsemts;
  114. QEMU_BUILD_BUG_ON(sizeof(CDATDsemts) != 24);
  115. /* Switch Scoped Latency and Bandwidth Information Structure - CDAT Table 9 */
  116. typedef struct CDATSslbisHeader {
  117. CDATSubHeader header;
  118. uint8_t data_type;
  119. uint8_t reserved[3];
  120. uint64_t entry_base_unit;
  121. } CDATSslbisHeader;
  122. QEMU_BUILD_BUG_ON(sizeof(CDATSslbisHeader) != 16);
  123. #define CDAT_PORT_ID_USP 0x100
  124. /* Switch Scoped Latency and Bandwidth Entry - CDAT Table 10 */
  125. typedef struct CDATSslbe {
  126. uint16_t port_x_id;
  127. uint16_t port_y_id;
  128. uint16_t latency_bandwidth;
  129. uint16_t reserved;
  130. } CDATSslbe;
  131. QEMU_BUILD_BUG_ON(sizeof(CDATSslbe) != 8);
  132. typedef struct CDATSslbis {
  133. CDATSslbisHeader sslbis_header;
  134. CDATSslbe sslbe[];
  135. } CDATSslbis;
  136. typedef struct CDATEntry {
  137. void *base;
  138. uint32_t length;
  139. } CDATEntry;
  140. typedef struct CDATObject {
  141. CDATEntry *entry;
  142. int entry_len;
  143. int (*build_cdat_table)(CDATSubHeader ***cdat_table, void *priv);
  144. void (*free_cdat_table)(CDATSubHeader **cdat_table, int num, void *priv);
  145. bool to_update;
  146. void *private;
  147. char *filename;
  148. uint8_t *buf;
  149. struct CDATSubHeader **built_buf;
  150. int built_buf_len;
  151. } CDATObject;
  152. #endif /* CXL_CDAT_H */