xref: /openbmc/qemu/include/hw/cxl/cxl_pci.h (revision ecd6f6a8)
1 /*
2  * QEMU CXL PCI interfaces
3  *
4  * Copyright (c) 2020 Intel
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2. See the
7  * COPYING file in the top-level directory.
8  */
9 
10 #ifndef CXL_PCI_H
11 #define CXL_PCI_H
12 
13 
14 #define CXL_VENDOR_ID 0x1e98
15 
16 #define PCIE_DVSEC_HEADER1_OFFSET 0x4 /* Offset from start of extend cap */
17 #define PCIE_DVSEC_ID_OFFSET 0x8
18 
19 #define PCIE_CXL_DEVICE_DVSEC_LENGTH 0x3C
20 #define PCIE_CXL31_DEVICE_DVSEC_REVID 3
21 
22 #define EXTENSIONS_PORT_DVSEC_LENGTH 0x28
23 #define EXTENSIONS_PORT_DVSEC_REVID 0
24 
25 #define GPF_PORT_DVSEC_LENGTH 0x10
26 #define GPF_PORT_DVSEC_REVID  0
27 
28 #define GPF_DEVICE_DVSEC_LENGTH 0x10
29 #define GPF_DEVICE_DVSEC_REVID 0
30 
31 #define PCIE_CXL3_FLEXBUS_PORT_DVSEC_LENGTH 0x20
32 #define PCIE_CXL3_FLEXBUS_PORT_DVSEC_REVID  2
33 
34 #define REG_LOC_DVSEC_LENGTH 0x24
35 #define REG_LOC_DVSEC_REVID  0
36 
37 enum {
38     PCIE_CXL_DEVICE_DVSEC      = 0,
39     NON_CXL_FUNCTION_MAP_DVSEC = 2,
40     EXTENSIONS_PORT_DVSEC      = 3,
41     GPF_PORT_DVSEC             = 4,
42     GPF_DEVICE_DVSEC           = 5,
43     PCIE_FLEXBUS_PORT_DVSEC    = 7,
44     REG_LOC_DVSEC              = 8,
45     MLD_DVSEC                  = 9,
46     CXL20_MAX_DVSEC
47 };
48 
49 typedef struct DVSECHeader {
50     uint32_t cap_hdr;
51     uint32_t dv_hdr1;
52     uint16_t dv_hdr2;
53 } QEMU_PACKED DVSECHeader;
54 QEMU_BUILD_BUG_ON(sizeof(DVSECHeader) != 10);
55 
56 /*
57  * CXL r3.1 Table 8-2: CXL DVSEC ID Assignment
58  * Devices must implement certain DVSEC IDs, and can [optionally]
59  * implement others.
60  * (x) - IDs in Table 8-2.
61  *
62  * CXL RCD (D1):         0, [2], [5], 7, [8], A  - Not emulated yet
63  * CXL RCD USP (UP1):    7, [8]                  - Not emulated yet
64  * CXL RCH DSP (DP1):    7, [8]
65  * CXL SLD (D2):         0, [2], 5, 7, 8, [A]
66  * CXL LD (LD):          0, [2], 5, 7, 8
67  * CXL RP (R):           3, 4, 7, 8
68  * CXL Switch USP (USP): [2], 7, 8
69  * CXL Switch DSP (DSP): 3, 4, 7, 8
70  * FM-Owned LD (FMLD):   0, [2], 7, 8, 9
71  */
72 
73 /*
74  * CXL r3.1 Section 8.1.3: PCIe DVSEC for Devices
75  * DVSEC ID: 0, Revision: 3
76  */
77 typedef struct CXLDVSECDevice {
78     DVSECHeader hdr;
79     uint16_t cap;
80     uint16_t ctrl;
81     uint16_t status;
82     uint16_t ctrl2;
83     uint16_t status2;
84     uint16_t lock;
85     uint16_t cap2;
86     uint32_t range1_size_hi;
87     uint32_t range1_size_lo;
88     uint32_t range1_base_hi;
89     uint32_t range1_base_lo;
90     uint32_t range2_size_hi;
91     uint32_t range2_size_lo;
92     uint32_t range2_base_hi;
93     uint32_t range2_base_lo;
94     uint16_t cap3;
95 } QEMU_PACKED CXLDVSECDevice;
96 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDevice) != 0x3A);
97 
98 /*
99  * CXL r3.1 Section 8.1.5: CXL Extensions DVSEC for Ports
100  * DVSEC ID: 3, Revision: 0
101  */
102 typedef struct CXLDVSECPortExt {
103     DVSECHeader hdr;
104     uint16_t status;
105     uint16_t control;
106     uint8_t alt_bus_base;
107     uint8_t alt_bus_limit;
108     uint16_t alt_memory_base;
109     uint16_t alt_memory_limit;
110     uint16_t alt_prefetch_base;
111     uint16_t alt_prefetch_limit;
112     uint32_t alt_prefetch_base_high;
113     uint32_t alt_prefetch_limit_high;
114     uint32_t rcrb_base;
115     uint32_t rcrb_base_high;
116 } CXLDVSECPortExt;
117 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECPortExt) != 0x28);
118 
119 #define PORT_CONTROL_OFFSET          0xc
120 #define PORT_CONTROL_UNMASK_SBR      1
121 #define PORT_CONTROL_ALT_MEMID_EN    4
122 
123 /*
124  * CXL r3.1 Section 8.1.6: GPF DVSEC for CXL Port
125  * DVSEC ID: 4, Revision: 0
126  */
127 typedef struct CXLDVSECPortGPF {
128     DVSECHeader hdr;
129     uint16_t rsvd;
130     uint16_t phase1_ctrl;
131     uint16_t phase2_ctrl;
132 } CXLDVSECPortGPF;
133 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECPortGPF) != 0x10);
134 
135 /*
136  * CXL r3.1 Section 8.1.7: GPF DVSEC for CXL Device
137  * DVSEC ID: 5, Revision 0
138  */
139 typedef struct CXLDVSECDeviceGPF {
140     DVSECHeader hdr;
141     uint16_t phase2_duration;
142     uint32_t phase2_power;
143 } CXLDVSECDeviceGPF;
144 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDeviceGPF) != 0x10);
145 
146 /*
147  * CXL r3.1 Section 8.1.8: PCIe DVSEC for Flex Bus Port
148  * CXL r3.1 Section 8.2.1.3: Flex Bus Port DVSEC
149  * DVSEC ID: 7, Revision 2
150  */
151 typedef struct CXLDVSECPortFlexBus {
152     DVSECHeader hdr;
153     uint16_t cap;
154     uint16_t ctrl;
155     uint16_t status;
156     uint32_t rcvd_mod_ts_data_phase1;
157     uint32_t cap2;
158     uint32_t ctrl2;
159     uint32_t status2;
160 } CXLDVSECPortFlexBus;
161 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECPortFlexBus) != 0x20);
162 
163 /*
164  * CXL r3.1 Section 8.1.9: Register Locator DVSEC
165  * DVSEC ID: 8, Revision 0
166  */
167 typedef struct CXLDVSECRegisterLocator {
168     DVSECHeader hdr;
169     uint16_t rsvd;
170     uint32_t reg0_base_lo;
171     uint32_t reg0_base_hi;
172     uint32_t reg1_base_lo;
173     uint32_t reg1_base_hi;
174     uint32_t reg2_base_lo;
175     uint32_t reg2_base_hi;
176 } CXLDVSECRegisterLocator;
177 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECRegisterLocator) != 0x24);
178 
179 /* BAR Equivalence Indicator */
180 #define BEI_BAR_10H 0
181 #define BEI_BAR_14H 1
182 #define BEI_BAR_18H 2
183 #define BEI_BAR_1cH 3
184 #define BEI_BAR_20H 4
185 #define BEI_BAR_24H 5
186 
187 /* Register Block Identifier */
188 #define RBI_EMPTY          0
189 #define RBI_COMPONENT_REG  (1 << 8)
190 #define RBI_BAR_VIRT_ACL   (2 << 8)
191 #define RBI_CXL_DEVICE_REG (3 << 8)
192 
193 #endif
194