]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / Drivers / DtPlatformDxe / DtPlatformDxe.c
CommitLineData
779cc439
AB
1/** @file\r
2*\r
3* Copyright (c) 2017, Linaro, Ltd. All rights reserved.\r
4*\r
878b807a 5* SPDX-License-Identifier: BSD-2-Clause-Patent\r
779cc439
AB
6*\r
7**/\r
8\r
9#include <Library/BaseLib.h>\r
10#include <Library/DebugLib.h>\r
11#include <Library/DevicePathLib.h>\r
12c71010 12#include <Library/DtPlatformDtbLoaderLib.h>\r
779cc439
AB
13#include <Library/HiiLib.h>\r
14#include <Library/MemoryAllocationLib.h>\r
15#include <Library/UefiBootServicesTableLib.h>\r
16#include <Library/UefiDriverEntryPoint.h>\r
17#include <Library/UefiRuntimeServicesTableLib.h>\r
18\r
19#include "DtPlatformDxe.h"\r
20\r
e7108d0e
MK
21extern UINT8 DtPlatformHiiBin[];\r
22extern UINT8 DtPlatformDxeStrings[];\r
779cc439
AB
23\r
24typedef struct {\r
e7108d0e
MK
25 VENDOR_DEVICE_PATH VendorDevicePath;\r
26 EFI_DEVICE_PATH_PROTOCOL End;\r
779cc439
AB
27} HII_VENDOR_DEVICE_PATH;\r
28\r
e7108d0e 29STATIC HII_VENDOR_DEVICE_PATH mDtPlatformDxeVendorDevicePath = {\r
779cc439
AB
30 {\r
31 {\r
32 HARDWARE_DEVICE_PATH,\r
33 HW_VENDOR_DP,\r
34 {\r
e7108d0e
MK
35 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r
36 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
779cc439
AB
37 }\r
38 },\r
39 DT_PLATFORM_FORMSET_GUID\r
40 },\r
41 {\r
42 END_DEVICE_PATH_TYPE,\r
43 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
44 {\r
e7108d0e
MK
45 (UINT8)(END_DEVICE_PATH_LENGTH),\r
46 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)\r
779cc439
AB
47 }\r
48 }\r
49};\r
50\r
51STATIC\r
52EFI_STATUS\r
53InstallHiiPages (\r
54 VOID\r
55 )\r
56{\r
e7108d0e
MK
57 EFI_STATUS Status;\r
58 EFI_HII_HANDLE HiiHandle;\r
59 EFI_HANDLE DriverHandle;\r
779cc439
AB
60\r
61 DriverHandle = NULL;\r
e7108d0e
MK
62 Status = gBS->InstallMultipleProtocolInterfaces (\r
63 &DriverHandle,\r
64 &gEfiDevicePathProtocolGuid,\r
65 &mDtPlatformDxeVendorDevicePath,\r
66 NULL\r
67 );\r
779cc439
AB
68 if (EFI_ERROR (Status)) {\r
69 return Status;\r
70 }\r
71\r
e7108d0e
MK
72 HiiHandle = HiiAddPackages (\r
73 &gDtPlatformFormSetGuid,\r
74 DriverHandle,\r
75 DtPlatformDxeStrings,\r
76 DtPlatformHiiBin,\r
77 NULL\r
78 );\r
779cc439
AB
79\r
80 if (HiiHandle == NULL) {\r
e7108d0e
MK
81 gBS->UninstallMultipleProtocolInterfaces (\r
82 DriverHandle,\r
83 &gEfiDevicePathProtocolGuid,\r
84 &mDtPlatformDxeVendorDevicePath,\r
85 NULL\r
86 );\r
779cc439
AB
87 return EFI_OUT_OF_RESOURCES;\r
88 }\r
e7108d0e 89\r
779cc439
AB
90 return EFI_SUCCESS;\r
91}\r
92\r
93/**\r
94 The entry point for DtPlatformDxe driver.\r
95\r
96 @param[in] ImageHandle The image handle of the driver.\r
97 @param[in] SystemTable The system table.\r
98\r
99 @retval EFI_ALREADY_STARTED The driver already exists in system.\r
100 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of\r
101 resources.\r
c6a72cd7 102 @retval EFI_SUCCESS All the related protocols are installed on\r
779cc439
AB
103 the driver.\r
104\r
105**/\r
106EFI_STATUS\r
107EFIAPI\r
108DtPlatformDxeEntryPoint (\r
e7108d0e
MK
109 IN EFI_HANDLE ImageHandle,\r
110 IN EFI_SYSTEM_TABLE *SystemTable\r
779cc439
AB
111 )\r
112{\r
e7108d0e
MK
113 EFI_STATUS Status;\r
114 DT_ACPI_VARSTORE_DATA DtAcpiPref;\r
115 UINTN BufferSize;\r
116 VOID *Dtb;\r
117 UINTN DtbSize;\r
779cc439 118\r
e7108d0e 119 Dtb = NULL;\r
12c71010 120 Status = DtPlatformLoadDtb (&Dtb, &DtbSize);\r
779cc439 121 if (EFI_ERROR (Status)) {\r
e7108d0e
MK
122 DEBUG ((\r
123 DEBUG_WARN,\r
12c71010 124 "%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n",\r
e7108d0e
MK
125 __FUNCTION__,\r
126 Status\r
127 ));\r
779cc439
AB
128 DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;\r
129 } else {\r
130 //\r
131 // Get the current DT/ACPI preference from the DtAcpiPref variable.\r
132 //\r
133 BufferSize = sizeof (DtAcpiPref);\r
e7108d0e
MK
134 Status = gRT->GetVariable (\r
135 DT_ACPI_VARIABLE_NAME,\r
136 &gDtPlatformFormSetGuid,\r
137 NULL,\r
138 &BufferSize,\r
139 &DtAcpiPref\r
140 );\r
779cc439 141 if (EFI_ERROR (Status)) {\r
e7108d0e
MK
142 DEBUG ((\r
143 DEBUG_WARN,\r
144 "%a: no DT/ACPI preference found, defaulting to %a\n",\r
145 __FUNCTION__,\r
146 PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"\r
147 ));\r
601a18bf
AS
148 DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT\r
149 : DT_ACPI_SELECT_ACPI;\r
779cc439
AB
150 }\r
151 }\r
152\r
153 if (!EFI_ERROR (Status) &&\r
e7108d0e
MK
154 (DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI) &&\r
155 (DtAcpiPref.Pref != DT_ACPI_SELECT_DT))\r
156 {\r
157 DEBUG ((\r
158 DEBUG_WARN,\r
159 "%a: invalid value for %s, defaulting to %a\n",\r
160 __FUNCTION__,\r
161 DT_ACPI_VARIABLE_NAME,\r
162 PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"\r
163 ));\r
601a18bf
AS
164 DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT\r
165 : DT_ACPI_SELECT_ACPI;\r
779cc439
AB
166 Status = EFI_INVALID_PARAMETER; // trigger setvar below\r
167 }\r
168\r
169 //\r
170 // Write the newly selected default value back to the variable store.\r
171 //\r
172 if (EFI_ERROR (Status)) {\r
e7108d0e
MK
173 Status = gRT->SetVariable (\r
174 DT_ACPI_VARIABLE_NAME,\r
175 &gDtPlatformFormSetGuid,\r
779cc439 176 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
e7108d0e
MK
177 sizeof (DtAcpiPref),\r
178 &DtAcpiPref\r
179 );\r
779cc439 180 if (EFI_ERROR (Status)) {\r
12c71010 181 goto FreeDtb;\r
779cc439
AB
182 }\r
183 }\r
184\r
185 if (DtAcpiPref.Pref == DT_ACPI_SELECT_ACPI) {\r
186 //\r
187 // ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a\r
188 // NULL protocol to unlock dispatch of ACPI related drivers.\r
189 //\r
e7108d0e
MK
190 Status = gBS->InstallMultipleProtocolInterfaces (\r
191 &ImageHandle,\r
192 &gEdkiiPlatformHasAcpiGuid,\r
193 NULL,\r
194 NULL\r
195 );\r
779cc439 196 if (EFI_ERROR (Status)) {\r
e7108d0e
MK
197 DEBUG ((\r
198 DEBUG_ERROR,\r
779cc439 199 "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",\r
e7108d0e
MK
200 __FUNCTION__\r
201 ));\r
12c71010 202 goto FreeDtb;\r
779cc439
AB
203 }\r
204 } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {\r
205 //\r
206 // DT was selected: copy the blob into newly allocated memory and install\r
207 // a reference to it as the FDT configuration table.\r
208 //\r
12c71010 209 Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb);\r
779cc439 210 if (EFI_ERROR (Status)) {\r
e7108d0e
MK
211 DEBUG ((\r
212 DEBUG_ERROR,\r
213 "%a: failed to install FDT configuration table\n",\r
214 __FUNCTION__\r
215 ));\r
12c71010 216 goto FreeDtb;\r
779cc439
AB
217 }\r
218 } else {\r
219 ASSERT (FALSE);\r
220 }\r
221\r
222 //\r
223 // No point in installing the HII pages if ACPI is the only description\r
224 // we have\r
225 //\r
226 if (Dtb == NULL) {\r
227 return EFI_SUCCESS;\r
228 }\r
229\r
230 //\r
231 // Note that we don't uninstall the gEdkiiPlatformHasAcpiGuid protocol nor\r
232 // the FDT configuration table if the following call fails. While that will\r
233 // cause loading of this driver to fail, proceeding with ACPI and DT both\r
234 // disabled will guarantee a failed boot, and so it is better to leave them\r
235 // installed in that case.\r
236 //\r
237 return InstallHiiPages ();\r
12c71010
AB
238\r
239FreeDtb:\r
240 if (Dtb != NULL) {\r
241 FreePool (Dtb);\r
242 }\r
243\r
244 return Status;\r
779cc439 245}\r