]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/HardwareInfoLib/HardwareInfoPciHostBridgeLib.h
OvmfPkg/Library: Create base HardwareInfoLib for PCI Host Bridges
[mirror_edk2.git] / OvmfPkg / Library / HardwareInfoLib / HardwareInfoPciHostBridgeLib.h
CommitLineData
6c9f218b
NOL
1/**@file\r
2 Hardware info library with types and accessors to parse information about\r
3 PCI host bridges.\r
4\r
5 Copyright 2021 - 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9\r
10#ifndef __HARDWARE_INFO_PCI_HOST_BRIDGE_LIB_H__\r
11#define __HARDWARE_INFO_PCI_HOST_BRIDGE_LIB_H__\r
12\r
13#include <Uefi/UefiBaseType.h>\r
14#include <Uefi/UefiSpec.h>\r
15#include <Library/PciHostBridgeLib.h>\r
16\r
17//\r
18// Host Bridge resources information\r
19//\r
20#pragma pack(1)\r
21typedef struct {\r
22 //\r
23 // Feature tracking, initially 0\r
24 //\r
25 UINT64 Version;\r
26\r
27 //\r
28 // Host bridge enabled attributes (EFI_PCI_ATTRIBUTE_*)\r
29 //\r
30 UINT64 Attributes;\r
31\r
32 union {\r
33 UINT32 Uint32;\r
34 struct {\r
35 UINT32 DmaAbove4G : 1;\r
36 UINT32 NoExtendedConfigSpace : 1;\r
37 UINT32 CombineMemPMem : 1;\r
38 UINT32 Reserved : 29;\r
39 } Bits;\r
40 } Flags;\r
41\r
42 //\r
43 // Bus number range\r
44 //\r
45 UINT8 BusNrStart;\r
46 UINT8 BusNrLast;\r
47\r
48 UINT8 Padding[2];\r
49\r
50 //\r
51 // IO aperture\r
52 //\r
53 UINT64 IoStart;\r
54 UINT64 IoSize;\r
55\r
56 //\r
57 // 32-bit MMIO aperture\r
58 //\r
59 UINT64 MemStart;\r
60 UINT64 MemSize;\r
61\r
62 //\r
63 // 32-bit prefetchable MMIO aperture\r
64 //\r
65 UINT64 PMemStart;\r
66 UINT64 PMemSize;\r
67\r
68 //\r
69 // 64-bit MMIO aperture\r
70 //\r
71 UINT64 MemAbove4GStart;\r
72 UINT64 MemAbove4GSize;\r
73\r
74 //\r
75 // 64-bit prefetchable MMIO aperture\r
76 //\r
77 UINT64 PMemAbove4GStart;\r
78 UINT64 PMemAbove4GSize;\r
79\r
80 //\r
81 // MMIO accessible PCIe config space (ECAM)\r
82 //\r
83 UINT64 PcieConfigStart;\r
84 UINT64 PcieConfigSize;\r
85} HOST_BRIDGE_INFO;\r
86#pragma pack()\r
87\r
88/**\r
89 Extract the last MMIO address, either from high (64-bit) or low (32-bit)\r
90 memory used by the HostBridge's apertures.\r
91\r
92 @param[in] HostBridge Root bridge's resources specification\r
93 @param[in] DataSize Size in bytes of the actually filled\r
94 data available in the HostBridge object\r
95 @param[in] HighMem 64-bit (true) or 32-bit (false) MMIO\r
96 address\r
97 @param[out] LastMmioAddress Pointer to last MMIO address\r
98\r
99 @retval EFI_SUCCESS Operation succeeded\r
100 @retval EFI_INVALID_PARAMETER One or more pointer parameters are\r
101 invalid\r
102 @retval EFI_INCOMPATIBLE_VERSION HostBridge information belongs to\r
103 an unsupported version\r
104**/\r
105EFI_STATUS\r
106HardwareInfoPciHostBridgeLastMmioAddress (\r
107 IN CONST HOST_BRIDGE_INFO *HostBridge,\r
108 IN UINTN DataSize,\r
109 IN BOOLEAN HighMem,\r
110 OUT UINT64 *LastMmioAddress\r
111 );\r
112\r
113/**\r
114 Interpret the HostBridge resources and extact the bus number\r
115 range.\r
116\r
117 @param[in] HostBridge Root bridge's resources specification\r
118 @param[in] DataSize Size in bytes of the actually filled\r
119 data available in the HostBridge object\r
120 @param[out] BusNrStart Pointer to the Bus Number range start\r
121 @param[out] BusNrLast Pointer to the Bus Number range end\r
122\r
123 @retval EFI_SUCCESS Retrieved the bus number range\r
124 without any issues.\r
125 @retval EFI_INVALID_PARAMETER One of the parameters is invalid,\r
126 either NULL pointer or size 0\r
127 @retval EFI_INCOMPATIBLE_VERSION HostBridge data of unsupported\r
128 version\r
129**/\r
130EFI_STATUS\r
131HardwareInfoPciHostBridgeGetBusNrRange (\r
132 IN CONST HOST_BRIDGE_INFO *HostBridge,\r
133 IN UINTN DataSize,\r
134 OUT UINTN *BusNrStart,\r
135 OUT UINTN *BusNrLast\r
136 );\r
137\r
138/**\r
139 Interpret the MMIO resources in HostBridge and set the apertures\r
140 in 32-bit space (Mem), 64-bit space (MemAbove4G), PIO (IO) and\r
141 ECAM (PcieConfig) accordingly.\r
142\r
143 The 2 types of apertures in each MMIO space (prefetchable and\r
144 non-prefetchable) may be merged into a single window, hence if both\r
145 types of apertures are defined while the CombineMemPMem flag is set,\r
146 the ranges must be contiguous.\r
147\r
148 @param[in] HostBridge Root bridge's resources specification\r
149 @param[in] DataSize Size in bytes of the actually filled\r
150 data available in the HostBridge object\r
151 @param[out] Mem Pointer to 32-bit MMIO aperture\r
152 @param[out] MemAbove4G Pointer to 64-bit MMIO aperture\r
153 @param[out] PMem Pointer to the 32-bit prefetchable MMIO aperture\r
154 @param[out] PMemAbove4G Pointer to the 64-bit prefetchable MMIO aperture\r
155 @param[out] PcieConfig Pointer to MMIO mapped PCIe config aperture (ECAM)\r
156\r
157 @retval EFI_INVALID_PARAMETER HostBridge object is invalid\r
158 @retval EFI_INCOMPATIBLE_VERSION HostBridge information belongs to\r
159 an unsupported version\r
160 @retval EFI_WARN_STALE_DATA One or more valid aperture in the\r
161 HostBridge's resources were ignored\r
162 because corresponding aperture pointer\r
163 is NULL.\r
164 @retval EFI_SUCCESS Operation executed cleanly, all valid\r
165 ranges were parsed into the corresponding\r
166 aperture object.\r
167**/\r
168EFI_STATUS\r
169HardwareInfoPciHostBridgeGetApertures (\r
170 IN CONST HOST_BRIDGE_INFO *HostBridge,\r
171 IN UINTN DataSize,\r
172 OUT PCI_ROOT_BRIDGE_APERTURE *Io,\r
173 OUT PCI_ROOT_BRIDGE_APERTURE *Mem,\r
174 OUT PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
175 OUT PCI_ROOT_BRIDGE_APERTURE *PMem,\r
176 OUT PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,\r
177 OUT PCI_ROOT_BRIDGE_APERTURE *PcieConfig\r
178 );\r
179\r
180/**\r
181 Retrieve all flags and attributes of a host bridge describing the\r
182 resources and capabilities.\r
183\r
184 @param[in] HostBridge Host bridge information object\r
185 @param[in] DataSize Size in bytes of the actually filled\r
186 data available in the HostBridge object\r
187 @param[out] Attributes Pointer to the host bridge's attributes\r
188 @param[out] DmaAbove4G Pointer to the DMA Above 4G flag\r
189 @param[out] NoExtendedConfigSpace Pointer to the Extended Config Space flag\r
190 @param[out] CombineMemPMem Pointer to the Combine Mem and PMem flag\r
191\r
192 @retval EFI_INVALID_PARAMETER HostBridge object is invalid\r
193 @retval EFI_INCOMPATIBLE_VERSION HostBridge information belongs to\r
194 an unsupported version\r
195 @retval EFI_SUCCESS Operation executed cleanly\r
196**/\r
197EFI_STATUS\r
198HardwareInfoPciHostBridgeGetFlags (\r
199 IN CONST HOST_BRIDGE_INFO *HostBridge,\r
200 IN UINTN DataSize,\r
201 OUT UINT64 *Attributes OPTIONAL,\r
202 OUT BOOLEAN *DmaAbove4G OPTIONAL,\r
203 OUT BOOLEAN *NoExtendedConfigSpace OPTIONAL,\r
204 OUT BOOLEAN *CombineMemPMem OPTIONAL\r
205 );\r
206\r
207/**\r
208 Getter that parses information from a HOST_BRIDGE_INFO object\r
209 into smaller chunks of types handled by the PciHostBridgeLib.\r
210\r
211 @param[in] HostBridge Host bridge information object\r
212 @param[in] DataSize Size in bytes of the actually filled\r
213 data available in the HostBridge object\r
214 @param[out] BusNrStart Pointer to the Bus Number range start\r
215 @param[out] BusNrLast Pointer to the Bus Number range end\r
216 @param[out] Attributes Pointer to the host bridge's attributes\r
217 @param[out] DmaAbove4G Pointer to the DMA Above 4G flag\r
218 @param[out] NoExtendedConfigSpace Pointer to the Extended Config Space flag\r
219 @param[out] CombineMemPMem Pointer to the Combine Mem and PMem flag\r
220 @param[out] Io Pointer to the PIO aperture object\r
221 @param[out] Mem Pointer to the 32-bit MMIO aperture object\r
222 @param[out] MemAbove4G Pointer to the 64-bit MMIO aperture object\r
223 @param[out] PMem Pointer to the 32-bit prefetchable MMIO\r
224 aperture object\r
225 @param[out] PMemAbove4G Pointer to the 64-bit prefetchable MMIO\r
226 aperture object\r
227 @param[out] PcieConfig MMIO mapped PCIe config aperture (ECAM)\r
228\r
229 @retval EFI_SUCCESS Whole operation succeeded\r
230 @retval EFI_INVALID_PARAMETER HostBridge object and/or non-optional\r
231 output parameters are invalid\r
232 @retval EFI_INCOMPATIBLE_VERSION HostBridge information provided belongs to\r
233 and unsupported version\r
234 @retval EFI_WARN_STALE_DATA One or more apertures having valid ranges\r
235 in the HostBridge info were ignored because\r
236 the correspnding aperture pointer is NULL\r
237**/\r
238EFI_STATUS\r
239HardwareInfoPciHostBridgeGet (\r
240 IN CONST HOST_BRIDGE_INFO *HostBridge,\r
241 IN UINTN DataSize,\r
242 OUT UINTN *BusNrStart,\r
243 OUT UINTN *BusNrLast,\r
244 OUT UINT64 *Attributes OPTIONAL,\r
245 OUT BOOLEAN *DmaAbove4G OPTIONAL,\r
246 OUT BOOLEAN *NoExtendedConfigSpace OPTIONAL,\r
247 OUT BOOLEAN *CombineMemPMem OPTIONAL,\r
248 OUT PCI_ROOT_BRIDGE_APERTURE *Io OPTIONAL,\r
249 OUT PCI_ROOT_BRIDGE_APERTURE *Mem OPTIONAL,\r
250 OUT PCI_ROOT_BRIDGE_APERTURE *MemAbove4G OPTIONAL,\r
251 OUT PCI_ROOT_BRIDGE_APERTURE *PMem OPTIONAL,\r
252 OUT PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G OPTIONAL,\r
253 OUT PCI_ROOT_BRIDGE_APERTURE *PcieConfig OPTIONAL\r
254 );\r
255\r
256#endif // __HARDWARE_INFO_PCI_HOST_BRIDGE_LIB_H__\r