xref: /qemu/include/hw/cxl/cxl_cdat.h (revision b2a3cbb8)
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 
15 /*
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
19  */
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)
23 
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
27 
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;
36 
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;
45 
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;
55 
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;
65 
66 typedef struct CDATSubHeader {
67     uint8_t type;
68     uint8_t reserved;
69     uint16_t length;
70 } CDATSubHeader;
71 
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;
85 
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;
98 
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;
107 
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;
115 
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;
125 
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;
133 
134 #define CDAT_PORT_ID_USP 0x100
135 /* Switch Scoped Latency and Bandwidth Entry - CDAT Table 10 */
136 typedef struct CDATSslbe {
137     uint16_t port_x_id;
138     uint16_t port_y_id;
139     uint16_t latency_bandwidth;
140     uint16_t reserved;
141 } QEMU_PACKED CDATSslbe;
142 
143 typedef struct CDATSslbis {
144     CDATSslbisHeader sslbis_header;
145     CDATSslbe sslbe[];
146 } QEMU_PACKED CDATSslbis;
147 
148 typedef struct CDATEntry {
149     void *base;
150     uint32_t length;
151 } CDATEntry;
152 
153 typedef struct CDATObject {
154     CDATEntry *entry;
155     int entry_len;
156 
157     int (*build_cdat_table)(CDATSubHeader ***cdat_table, void *priv);
158     void (*free_cdat_table)(CDATSubHeader **cdat_table, int num, void *priv);
159     bool to_update;
160     void *private;
161     char *filename;
162     uint8_t *buf;
163     struct CDATSubHeader **built_buf;
164     int built_buf_len;
165 } CDATObject;
166 #endif /* CXL_CDAT_H */
167