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