]> git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiPayloadPkg / Library / SblParseLib / SblParseLib.c
1 /** @file
2 This library will parse the Slim Bootloader to get required information.
3
4 Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/PcdLib.h>
14 #include <Library/IoLib.h>
15 #include <Library/HobLib.h>
16 #include <Library/BlParseLib.h>
17 #include <IndustryStandard/Acpi.h>
18 #include <UniversalPayload/PciRootBridges.h>
19
20 /**
21 This function retrieves the parameter base address from boot loader.
22
23 This function will get bootloader specific parameter address for UEFI payload.
24 e.g. HobList pointer for Slim Bootloader, and coreboot table header for Coreboot.
25
26 @retval NULL Failed to find the GUID HOB.
27 @retval others GUIDed HOB data pointer.
28
29 **/
30 VOID *
31 EFIAPI
32 GetParameterBase (
33 VOID
34 )
35 {
36 EFI_HOB_HANDOFF_INFO_TABLE *HandoffTable;
37
38 HandoffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)(UINTN)GET_BOOTLOADER_PARAMETER ();
39 if ((HandoffTable->Header.HobType == EFI_HOB_TYPE_HANDOFF) &&
40 (HandoffTable->Header.HobLength == sizeof (EFI_HOB_HANDOFF_INFO_TABLE)) &&
41 (HandoffTable->Header.Reserved == 0))
42 {
43 return (VOID *)HandoffTable;
44 }
45
46 return NULL;
47 }
48
49 /**
50 This function retrieves a GUIDed HOB data from Slim Bootloader.
51
52 This function will search SBL HOB list to find the first GUIDed HOB that
53 its GUID matches Guid.
54
55 @param[in] Guid A pointer to HOB GUID to search.
56
57 @retval NULL Failed to find the GUID HOB.
58 @retval others GUIDed HOB data pointer.
59
60 **/
61 VOID *
62 GetGuidHobDataFromSbl (
63 IN EFI_GUID *Guid
64 )
65 {
66 UINT8 *GuidHob;
67 CONST VOID *HobList;
68
69 HobList = GetParameterBase ();
70 ASSERT (HobList != NULL);
71 GuidHob = GetNextGuidHob (Guid, HobList);
72 if (GuidHob != NULL) {
73 return GET_GUID_HOB_DATA (GuidHob);
74 }
75
76 return NULL;
77 }
78
79 /**
80 Acquire the memory map information.
81
82 @param MemInfoCallback The callback routine
83 @param Params Pointer to the callback routine parameter
84
85 @retval RETURN_SUCCESS Successfully find out the memory information.
86 @retval RETURN_NOT_FOUND Failed to find the memory information.
87
88 **/
89 RETURN_STATUS
90 EFIAPI
91 ParseMemoryInfo (
92 IN BL_MEM_INFO_CALLBACK MemInfoCallback,
93 IN VOID *Params
94 )
95 {
96 MEMORY_MAP_INFO *MemoryMapInfo;
97 UINTN Idx;
98
99 MemoryMapInfo = (MEMORY_MAP_INFO *)GetGuidHobDataFromSbl (&gLoaderMemoryMapInfoGuid);
100 if (MemoryMapInfo == NULL) {
101 ASSERT (FALSE);
102 return RETURN_NOT_FOUND;
103 }
104
105 for (Idx = 0; Idx < MemoryMapInfo->Count; Idx++) {
106 MemInfoCallback (&MemoryMapInfo->Entry[Idx], Params);
107 }
108
109 return RETURN_SUCCESS;
110 }
111
112 /**
113 Acquire SMBIOS table from slim bootloader.
114
115 @param SmbiosTable Pointer to the SMBIOS table info.
116
117 @retval RETURN_SUCCESS Successfully find out the tables.
118 @retval RETURN_NOT_FOUND Failed to find the tables.
119
120 **/
121 RETURN_STATUS
122 EFIAPI
123 ParseSmbiosTable (
124 OUT UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmbiosTable
125 )
126 {
127 UNIVERSAL_PAYLOAD_SMBIOS_TABLE *TableInfo;
128
129 TableInfo = (UNIVERSAL_PAYLOAD_SMBIOS_TABLE *)GetGuidHobDataFromSbl (&gUniversalPayloadSmbiosTableGuid);
130 if (TableInfo == NULL) {
131 ASSERT (FALSE);
132 return RETURN_NOT_FOUND;
133 }
134
135 SmbiosTable->SmBiosEntryPoint = TableInfo->SmBiosEntryPoint;
136
137 return RETURN_SUCCESS;
138 }
139
140 /**
141 Acquire ACPI table from slim bootloader.
142
143 @param AcpiTableHob Pointer to the ACPI table info.
144
145 @retval RETURN_SUCCESS Successfully find out the tables.
146 @retval RETURN_NOT_FOUND Failed to find the tables.
147
148 **/
149 RETURN_STATUS
150 EFIAPI
151 ParseAcpiTableInfo (
152 OUT UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableHob
153 )
154 {
155 UNIVERSAL_PAYLOAD_ACPI_TABLE *TableInfo;
156
157 TableInfo = (UNIVERSAL_PAYLOAD_ACPI_TABLE *)GetGuidHobDataFromSbl (&gUniversalPayloadAcpiTableGuid);
158 if (TableInfo == NULL) {
159 ASSERT (FALSE);
160 return RETURN_NOT_FOUND;
161 }
162
163 AcpiTableHob->Rsdp = TableInfo->Rsdp;
164
165 return RETURN_SUCCESS;
166 }
167
168 /**
169 Find the serial port information
170
171 @param[out] SerialPortInfo Pointer to serial port info structure
172
173 @retval RETURN_SUCCESS Successfully find the serial port information.
174 @retval RETURN_NOT_FOUND Failed to find the serial port information .
175
176 **/
177 RETURN_STATUS
178 EFIAPI
179 ParseSerialInfo (
180 OUT SERIAL_PORT_INFO *SerialPortInfo
181 )
182 {
183 SERIAL_PORT_INFO *BlSerialInfo;
184
185 BlSerialInfo = (SERIAL_PORT_INFO *)GetGuidHobDataFromSbl (&gUefiSerialPortInfoGuid);
186 if (BlSerialInfo == NULL) {
187 ASSERT (FALSE);
188 return RETURN_NOT_FOUND;
189 }
190
191 CopyMem (SerialPortInfo, BlSerialInfo, sizeof (SERIAL_PORT_INFO));
192
193 return RETURN_SUCCESS;
194 }
195
196 /**
197 Find the video frame buffer information
198
199 @param GfxInfo Pointer to the EFI_PEI_GRAPHICS_INFO_HOB structure
200
201 @retval RETURN_SUCCESS Successfully find the video frame buffer information.
202 @retval RETURN_NOT_FOUND Failed to find the video frame buffer information .
203
204 **/
205 RETURN_STATUS
206 EFIAPI
207 ParseGfxInfo (
208 OUT EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo
209 )
210 {
211 EFI_PEI_GRAPHICS_INFO_HOB *BlGfxInfo;
212
213 BlGfxInfo = (EFI_PEI_GRAPHICS_INFO_HOB *)GetGuidHobDataFromSbl (&gEfiGraphicsInfoHobGuid);
214 if (BlGfxInfo == NULL) {
215 return RETURN_NOT_FOUND;
216 }
217
218 CopyMem (GfxInfo, BlGfxInfo, sizeof (EFI_PEI_GRAPHICS_INFO_HOB));
219
220 return RETURN_SUCCESS;
221 }
222
223 /**
224 Find the video frame buffer device information
225
226 @param GfxDeviceInfo Pointer to the EFI_PEI_GRAPHICS_DEVICE_INFO_HOB structure
227
228 @retval RETURN_SUCCESS Successfully find the video frame buffer information.
229 @retval RETURN_NOT_FOUND Failed to find the video frame buffer information.
230
231 **/
232 RETURN_STATUS
233 EFIAPI
234 ParseGfxDeviceInfo (
235 OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *GfxDeviceInfo
236 )
237 {
238 EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *BlGfxDeviceInfo;
239
240 BlGfxDeviceInfo = (EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *)GetGuidHobDataFromSbl (&gEfiGraphicsDeviceInfoHobGuid);
241 if (BlGfxDeviceInfo == NULL) {
242 return RETURN_NOT_FOUND;
243 }
244
245 CopyMem (GfxDeviceInfo, BlGfxDeviceInfo, sizeof (EFI_PEI_GRAPHICS_DEVICE_INFO_HOB));
246
247 return RETURN_SUCCESS;
248 }
249
250 /**
251 Parse and handle the misc info provided by bootloader
252
253 @retval RETURN_SUCCESS The misc information was parsed successfully.
254 @retval RETURN_NOT_FOUND Could not find required misc info.
255 @retval RETURN_OUT_OF_RESOURCES Insufficant memory space.
256
257 **/
258 RETURN_STATUS
259 EFIAPI
260 ParseMiscInfo (
261 VOID
262 )
263 {
264 RETURN_STATUS Status;
265 UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *BlRootBridgesHob;
266 UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *PldRootBridgesHob;
267
268 Status = RETURN_NOT_FOUND;
269 BlRootBridgesHob = (UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *)GetGuidHobDataFromSbl (
270 &gUniversalPayloadPciRootBridgeInfoGuid
271 );
272 if (BlRootBridgesHob != NULL) {
273 //
274 // Migrate bootloader root bridge info hob from bootloader to payload.
275 //
276 PldRootBridgesHob = BuildGuidHob (
277 &gUniversalPayloadPciRootBridgeInfoGuid,
278 BlRootBridgesHob->Header.Length
279 );
280 ASSERT (PldRootBridgesHob != NULL);
281 if (PldRootBridgesHob != NULL) {
282 CopyMem (PldRootBridgesHob, BlRootBridgesHob, BlRootBridgesHob->Header.Length);
283 DEBUG ((DEBUG_INFO, "Create PCI root bridge info guid hob\n"));
284 Status = RETURN_SUCCESS;
285 } else {
286 Status = RETURN_OUT_OF_RESOURCES;
287 }
288 }
289
290 return Status;
291 }