TianoCore EDK2 master
Loading...
Searching...
No Matches
DtPlatformDxe.c
Go to the documentation of this file.
1
9#include <Library/BaseLib.h>
10#include <Library/DebugLib.h>
13#include <Library/HiiLib.h>
18
19#include "DtPlatformDxe.h"
20
21extern UINT8 DtPlatformHiiBin[];
22extern UINT8 DtPlatformDxeStrings[];
23
24typedef struct {
25 VENDOR_DEVICE_PATH VendorDevicePath;
28
29STATIC HII_VENDOR_DEVICE_PATH mDtPlatformDxeVendorDevicePath = {
30 {
31 {
34 {
35 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
36 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
37 }
38 },
39 DT_PLATFORM_FORMSET_GUID
40 },
41 {
42 END_DEVICE_PATH_TYPE,
43 END_ENTIRE_DEVICE_PATH_SUBTYPE,
44 {
45 (UINT8)(END_DEVICE_PATH_LENGTH),
46 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
47 }
48 }
49};
50
53InstallHiiPages (
54 VOID
55 )
56{
57 EFI_STATUS Status;
58 EFI_HII_HANDLE HiiHandle;
59 EFI_HANDLE DriverHandle;
60
61 DriverHandle = NULL;
62 Status = gBS->InstallMultipleProtocolInterfaces (
63 &DriverHandle,
64 &gEfiDevicePathProtocolGuid,
65 &mDtPlatformDxeVendorDevicePath,
66 NULL
67 );
68 if (EFI_ERROR (Status)) {
69 return Status;
70 }
71
72 HiiHandle = HiiAddPackages (
73 &gDtPlatformFormSetGuid,
74 DriverHandle,
75 DtPlatformDxeStrings,
76 DtPlatformHiiBin,
77 NULL
78 );
79
80 if (HiiHandle == NULL) {
81 gBS->UninstallMultipleProtocolInterfaces (
82 DriverHandle,
83 &gEfiDevicePathProtocolGuid,
84 &mDtPlatformDxeVendorDevicePath,
85 NULL
86 );
87 return EFI_OUT_OF_RESOURCES;
88 }
89
90 return EFI_SUCCESS;
91}
92
107EFIAPI
109 IN EFI_HANDLE ImageHandle,
110 IN EFI_SYSTEM_TABLE *SystemTable
111 )
112{
113 EFI_STATUS Status;
114 DT_ACPI_VARSTORE_DATA DtAcpiPref;
115 UINTN BufferSize;
116 VOID *Dtb;
117 UINTN DtbSize;
118
119 Dtb = NULL;
120 Status = DtPlatformLoadDtb (&Dtb, &DtbSize);
121 if (EFI_ERROR (Status)) {
122 DEBUG ((
123 DEBUG_WARN,
124 "%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n",
125 __func__,
126 Status
127 ));
128 DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;
129 } else {
130 //
131 // Get the current DT/ACPI preference from the DtAcpiPref variable.
132 //
133 BufferSize = sizeof (DtAcpiPref);
134 Status = gRT->GetVariable (
135 DT_ACPI_VARIABLE_NAME,
136 &gDtPlatformFormSetGuid,
137 NULL,
138 &BufferSize,
139 &DtAcpiPref
140 );
141 if (EFI_ERROR (Status)) {
142 DEBUG ((
143 DEBUG_WARN,
144 "%a: no DT/ACPI preference found, defaulting to %a\n",
145 __func__,
146 PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"
147 ));
148 DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT
149 : DT_ACPI_SELECT_ACPI;
150 }
151 }
152
153 if (!EFI_ERROR (Status) &&
154 (DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI) &&
155 (DtAcpiPref.Pref != DT_ACPI_SELECT_DT))
156 {
157 DEBUG ((
158 DEBUG_WARN,
159 "%a: invalid value for %s, defaulting to %a\n",
160 __func__,
161 DT_ACPI_VARIABLE_NAME,
162 PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"
163 ));
164 DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT
165 : DT_ACPI_SELECT_ACPI;
166 Status = EFI_INVALID_PARAMETER; // trigger setvar below
167 }
168
169 //
170 // Write the newly selected default value back to the variable store.
171 //
172 if (EFI_ERROR (Status)) {
173 Status = gRT->SetVariable (
174 DT_ACPI_VARIABLE_NAME,
175 &gDtPlatformFormSetGuid,
176 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
177 sizeof (DtAcpiPref),
178 &DtAcpiPref
179 );
180 if (EFI_ERROR (Status)) {
181 goto FreeDtb;
182 }
183 }
184
185 if (DtAcpiPref.Pref == DT_ACPI_SELECT_ACPI) {
186 //
187 // ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a
188 // NULL protocol to unlock dispatch of ACPI related drivers.
189 //
190 Status = gBS->InstallMultipleProtocolInterfaces (
191 &ImageHandle,
192 &gEdkiiPlatformHasAcpiGuid,
193 NULL,
194 NULL
195 );
196 if (EFI_ERROR (Status)) {
197 DEBUG ((
198 DEBUG_ERROR,
199 "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",
200 __func__
201 ));
202 goto FreeDtb;
203 }
204 } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {
205 //
206 // DT was selected: copy the blob into newly allocated memory and install
207 // a reference to it as the FDT configuration table.
208 //
209 Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb);
210 if (EFI_ERROR (Status)) {
211 DEBUG ((
212 DEBUG_ERROR,
213 "%a: failed to install FDT configuration table\n",
214 __func__
215 ));
216 goto FreeDtb;
217 }
218 } else {
219 ASSERT (FALSE);
220 }
221
222 //
223 // No point in installing the HII pages if ACPI is the only description
224 // we have
225 //
226 if (Dtb == NULL) {
227 return EFI_SUCCESS;
228 }
229
230 //
231 // Note that we don't uninstall the gEdkiiPlatformHasAcpiGuid protocol nor
232 // the FDT configuration table if the following call fails. While that will
233 // cause loading of this driver to fail, proceeding with ACPI and DT both
234 // disabled will guarantee a failed boot, and so it is better to leave them
235 // installed in that case.
236 //
237 return InstallHiiPages ();
238
239FreeDtb:
240 if (Dtb != NULL) {
241 FreePool (Dtb);
242 }
243
244 return Status;
245}
UINT64 UINTN
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_VENDOR_DP
Definition: DevicePath.h:133
EFI_STATUS EFIAPI DtPlatformLoadDtb(OUT VOID **Dtb, OUT UINTN *DtbSize)
EFI_STATUS EFIAPI DtPlatformDxeEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
VOID * EFI_HII_HANDLE
#define EFI_VARIABLE_NON_VOLATILE