hw/pci-bridge/cxl_upstream: Fix problem with g_steal_pointer()
[qemu/kevin.git] / include / hw / cxl / cxl_cdat.h
blobb44cefaad684590c96d2545d6ff3c78fdf7ee50f
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"
14 #include "hw/pci/pcie_doe.h"
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
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)
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
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;
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;
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;
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;
67 typedef struct CDATSubHeader {
68 uint8_t type;
69 uint8_t reserved;
70 uint16_t length;
71 } CDATSubHeader;
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;
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;
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;
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;
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;
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 } CDATSslbisHeader;
134 QEMU_BUILD_BUG_ON(sizeof(CDATSslbisHeader) != 16);
136 #define CDAT_PORT_ID_USP 0x100
137 /* Switch Scoped Latency and Bandwidth Entry - CDAT Table 10 */
138 typedef struct CDATSslbe {
139 uint16_t port_x_id;
140 uint16_t port_y_id;
141 uint16_t latency_bandwidth;
142 uint16_t reserved;
143 } CDATSslbe;
144 QEMU_BUILD_BUG_ON(sizeof(CDATSslbe) != 8);
146 typedef struct CDATSslbis {
147 CDATSslbisHeader sslbis_header;
148 CDATSslbe sslbe[];
149 } CDATSslbis;
151 typedef struct CDATEntry {
152 void *base;
153 uint32_t length;
154 } CDATEntry;
156 typedef struct CDATObject {
157 CDATEntry *entry;
158 int entry_len;
160 int (*build_cdat_table)(CDATSubHeader ***cdat_table, void *priv);
161 void (*free_cdat_table)(CDATSubHeader **cdat_table, int num, void *priv);
162 bool to_update;
163 void *private;
164 char *filename;
165 uint8_t *buf;
166 struct CDATSubHeader **built_buf;
167 int built_buf_len;
168 } CDATObject;
169 #endif /* CXL_CDAT_H */