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