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