]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
ArmPlatformPkg: Use EfiEventGroupSignal from UefiLib
[mirror_edk2.git] / ArmPlatformPkg / Library / PlatformIntelBdsLib / IntelBdsPlatform.c
CommitLineData
43ac100e
OM
1/** @file\r
2\r
9c8fe63c 3Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
43ac100e
OM
4Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "IntelBdsPlatform.h"\r
17\r
18///\r
19/// Predefined platform default time out value\r
20///\r
21UINT16 gPlatformBootTimeOutDefault;\r
22\r
23EFI_STATUS\r
24EFIAPI\r
25PlatformIntelBdsConstructor (\r
26 IN EFI_HANDLE ImageHandle,\r
27 IN EFI_SYSTEM_TABLE *SystemTable\r
28 )\r
29{\r
30 gPlatformBootTimeOutDefault = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);\r
31 return EFI_SUCCESS;\r
32}\r
33\r
34//\r
35// BDS Platform Functions\r
36//\r
37/**\r
38 Platform Bds init. Include the platform firmware vendor, revision\r
39 and so crc check.\r
40\r
41**/\r
42VOID\r
43EFIAPI\r
44PlatformBdsInit (\r
45 VOID\r
46 )\r
47{\r
0f060e34
AB
48 //\r
49 // Signal EndOfDxe PI Event\r
50 //\r
9c8fe63c 51 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
43ac100e
OM
52}\r
53\r
54STATIC\r
55EFI_STATUS\r
56GetConsoleDevicePathFromVariable (\r
57 IN CHAR16* ConsoleVarName,\r
58 IN CHAR16* DefaultConsolePaths,\r
59 OUT EFI_DEVICE_PATH** DevicePaths\r
60 )\r
61{\r
62 EFI_STATUS Status;\r
63 UINTN Size;\r
64 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;\r
65 EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;\r
66 CHAR16* DevicePathStr;\r
67 CHAR16* NextDevicePathStr;\r
68 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;\r
69\r
3baf5c9f
AB
70 Status = EFI_SUCCESS;\r
71 Size = 0;\r
72\r
73 DevicePathInstances = BdsLibGetVariableAndSize (ConsoleVarName, &gEfiGlobalVariableGuid, &Size);\r
74 if (DevicePathInstances == NULL) {\r
43ac100e
OM
75 // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)\r
76 if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {\r
77 *DevicePaths = NULL;\r
78 return EFI_SUCCESS;\r
79 }\r
80\r
81 Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
82 ASSERT_EFI_ERROR(Status);\r
83\r
43ac100e
OM
84 // Extract the Device Path instances from the multi-device path string\r
85 while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {\r
86 NextDevicePathStr = StrStr (DefaultConsolePaths, L";");\r
87 if (NextDevicePathStr == NULL) {\r
88 DevicePathStr = DefaultConsolePaths;\r
89 DefaultConsolePaths = NULL;\r
90 } else {\r
91 DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);\r
92 *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';\r
93 DefaultConsolePaths = NextDevicePathStr;\r
94 if (DefaultConsolePaths[0] == L';') {\r
95 DefaultConsolePaths++;\r
96 }\r
97 }\r
98\r
99 DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);\r
100 ASSERT(DevicePathInstance != NULL);\r
101 DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);\r
102\r
103 if (NextDevicePathStr != NULL) {\r
104 FreePool (DevicePathStr);\r
105 }\r
106 FreePool (DevicePathInstance);\r
107 }\r
108\r
109 // Set the environment variable with this device path multi-instances\r
110 Size = GetDevicePathSize (DevicePathInstances);\r
111 if (Size > 0) {\r
112 gRT->SetVariable (\r
113 ConsoleVarName,\r
114 &gEfiGlobalVariableGuid,\r
115 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
116 Size,\r
117 DevicePathInstances\r
118 );\r
119 } else {\r
120 Status = EFI_INVALID_PARAMETER;\r
121 }\r
122 }\r
123\r
124 if (!EFI_ERROR(Status)) {\r
125 *DevicePaths = DevicePathInstances;\r
126 }\r
127 return Status;\r
128}\r
129\r
130STATIC\r
131EFI_STATUS\r
132InitializeConsolePipe (\r
133 IN EFI_DEVICE_PATH *ConsoleDevicePaths,\r
134 IN EFI_GUID *Protocol,\r
135 OUT EFI_HANDLE *Handle,\r
136 OUT VOID* *Interface\r
137 )\r
138{\r
139 EFI_STATUS Status;\r
140 UINTN Size;\r
141 UINTN NoHandles;\r
142 EFI_HANDLE *Buffer;\r
143 EFI_DEVICE_PATH_PROTOCOL* DevicePath;\r
144\r
145 // Connect all the Device Path Consoles\r
146 while (ConsoleDevicePaths != NULL) {\r
147 DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);\r
148\r
3baf5c9f
AB
149 Status = BdsLibConnectDevicePath (DevicePath);\r
150 if (!EFI_ERROR (Status)) {\r
151 //\r
152 // If BdsLibConnectDevicePath () succeeded, *Handle must have a non-NULL\r
153 // value. So ASSERT that this is the case.\r
154 //\r
155 gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, Handle);\r
156 ASSERT (*Handle != NULL);\r
157 }\r
43ac100e
OM
158 DEBUG_CODE_BEGIN();\r
159 if (EFI_ERROR(Status)) {\r
160 // We convert back to the text representation of the device Path\r
3d175bcb
AB
161 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToTextProtocol;\r
162 CHAR16 *DevicePathTxt;\r
43ac100e 163\r
3d175bcb
AB
164 DevicePathToTextProtocol = NULL;\r
165 gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **) &DevicePathToTextProtocol);\r
166 if (DevicePathToTextProtocol != NULL) {\r
43ac100e
OM
167 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);\r
168\r
169 DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));\r
170\r
171 FreePool (DevicePathTxt);\r
172 }\r
173 }\r
174 DEBUG_CODE_END();\r
175\r
176 // If the console splitter driver is not supported by the platform then use the first Device Path\r
177 // instance for the console interface.\r
178 if (!EFI_ERROR(Status) && (*Interface == NULL)) {\r
179 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
180 }\r
181 }\r
182\r
183 // No Device Path has been defined for this console interface. We take the first protocol implementation\r
184 if (*Interface == NULL) {\r
185 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
186 if (EFI_ERROR (Status)) {\r
3baf5c9f 187 BdsLibConnectAll ();\r
43ac100e
OM
188 Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
189 }\r
190\r
191 if (!EFI_ERROR(Status)) {\r
192 *Handle = Buffer[0];\r
193 Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
194 ASSERT_EFI_ERROR (Status);\r
3a2b37f0 195 FreePool (Buffer);\r
43ac100e 196 }\r
43ac100e
OM
197 } else {\r
198 Status = EFI_SUCCESS;\r
199 }\r
200\r
201 return Status;\r
202}\r
203\r
204/**\r
205 Connect the predefined platform default console device. Always try to find\r
206 and enable the vga device if have.\r
207\r
208 @param PlatformConsole Predefined platform default console device array.\r
209\r
210 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut\r
211 device, there must have one ConOut device is\r
212 active vga device.\r
213 @return Return the status of BdsLibConnectAllDefaultConsoles ()\r
214\r
215**/\r
216EFI_STATUS\r
217PlatformBdsConnectConsole (\r
218 VOID\r
219 )\r
220{\r
221 EFI_STATUS Status;\r
222 EFI_DEVICE_PATH* ConOutDevicePaths;\r
223 EFI_DEVICE_PATH* ConInDevicePaths;\r
224 EFI_DEVICE_PATH* ConErrDevicePaths;\r
225\r
226 // By getting the Console Device Paths from the environment variables before initializing the console pipe, we\r
227 // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface\r
228 // of newly installed console drivers\r
229 Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);\r
230 ASSERT_EFI_ERROR (Status);\r
231 Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);\r
232 ASSERT_EFI_ERROR (Status);\r
233 Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);\r
234 ASSERT_EFI_ERROR (Status);\r
235\r
236 // Initialize the Consoles\r
237 Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);\r
238 ASSERT_EFI_ERROR (Status);\r
239 Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);\r
240 ASSERT_EFI_ERROR (Status);\r
241 Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);\r
242 if (EFI_ERROR(Status)) {\r
243 // In case of error, we reuse the console output for the error output\r
244 gST->StandardErrorHandle = gST->ConsoleOutHandle;\r
245 gST->StdErr = gST->ConOut;\r
246 }\r
247\r
248 return Status;\r
249}\r
250\r
251/**\r
252 Connect with predefined platform connect sequence,\r
253 the OEM/IBV can customize with their own connect sequence.\r
254**/\r
255VOID\r
256PlatformBdsConnectSequence (\r
257 VOID\r
258 )\r
259{\r
260}\r
261\r
262/**\r
263 Load the predefined driver option, OEM/IBV can customize this\r
264 to load their own drivers\r
265\r
266 @param BdsDriverLists - The header of the driver option link list.\r
267\r
268**/\r
269VOID\r
270PlatformBdsGetDriverOption (\r
271 IN OUT LIST_ENTRY *BdsDriverLists\r
272 )\r
273{\r
274}\r
275\r
276/**\r
277 Perform the platform diagnostic, such like test memory. OEM/IBV also\r
278 can customize this function to support specific platform diagnostic.\r
279\r
280 @param MemoryTestLevel The memory test intensive level\r
281 @param QuietBoot Indicate if need to enable the quiet boot\r
282 @param BaseMemoryTest A pointer to BdsMemoryTest()\r
283\r
284**/\r
285VOID\r
286PlatformBdsDiagnostics (\r
287 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,\r
288 IN BOOLEAN QuietBoot,\r
289 IN BASEM_MEMORY_TEST BaseMemoryTest\r
290 )\r
291{\r
292}\r
293\r
294/**\r
295 The function will execute with as the platform policy, current policy\r
296 is driven by boot mode. IBV/OEM can customize this code for their specific\r
297 policy action.\r
298\r
299 @param DriverOptionList The header of the driver option link list\r
300 @param BootOptionList The header of the boot option link list\r
301 @param ProcessCapsules A pointer to ProcessCapsules()\r
302 @param BaseMemoryTest A pointer to BaseMemoryTest()\r
303\r
304**/\r
305VOID\r
306EFIAPI\r
307PlatformBdsPolicyBehavior (\r
308 IN LIST_ENTRY *DriverOptionList,\r
309 IN LIST_ENTRY *BootOptionList,\r
310 IN PROCESS_CAPSULES ProcessCapsules,\r
311 IN BASEM_MEMORY_TEST BaseMemoryTest\r
312 )\r
313{\r
314 EFI_STATUS Status;\r
315\r
316 Status = PlatformBdsConnectConsole ();\r
317 ASSERT_EFI_ERROR (Status);\r
a680d52f
AB
318\r
319 //\r
320 // Show the splash screen.\r
321 //\r
322 EnableQuietBoot (PcdGetPtr (PcdLogoFile));\r
50e8d393
LL
323\r
324 //\r
325 // Connect _all_ devices, to pick up plug-in and removable devices\r
326 // TODO: do this more cleanly, permitting faster boot times when boot config\r
327 // is known\r
328 //\r
329 BdsLibConnectAll ();\r
43ac100e
OM
330}\r
331\r
332/**\r
333 Hook point after a boot attempt succeeds. We don't expect a boot option to\r
334 return, so the UEFI 2.0 specification defines that you will default to an\r
335 interactive mode and stop processing the BootOrder list in this case. This\r
336 is also a platform implementation and can be customized by IBV/OEM.\r
337\r
338 @param Option Pointer to Boot Option that succeeded to boot.\r
339\r
340**/\r
341VOID\r
342EFIAPI\r
343PlatformBdsBootSuccess (\r
344 IN BDS_COMMON_OPTION *Option\r
345 )\r
346{\r
347}\r
348\r
349/**\r
350 Hook point after a boot attempt fails.\r
351\r
352 @param Option Pointer to Boot Option that failed to boot.\r
353 @param Status Status returned from failed boot.\r
354 @param ExitData Exit data returned from failed boot.\r
355 @param ExitDataSize Exit data size returned from failed boot.\r
356\r
357**/\r
358VOID\r
359EFIAPI\r
360PlatformBdsBootFail (\r
361 IN BDS_COMMON_OPTION *Option,\r
362 IN EFI_STATUS Status,\r
363 IN CHAR16 *ExitData,\r
364 IN UINTN ExitDataSize\r
365 )\r
366{\r
367}\r
368\r
369/**\r
370 This function locks platform flash that is not allowed to be updated during normal boot path.\r
371 The flash layout is platform specific.\r
372**/\r
373VOID\r
374EFIAPI\r
375PlatformBdsLockNonUpdatableFlash (\r
376 VOID\r
377 )\r
378{\r
379 return;\r
380}\r
381\r
382\r
383/**\r
384 Lock the ConsoleIn device in system table. All key\r
385 presses will be ignored until the Password is typed in. The only way to\r
386 disable the password is to type it in to a ConIn device.\r
387\r
388 @param Password Password used to lock ConIn device.\r
389\r
390 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.\r
391 @retval EFI_UNSUPPORTED Password not found\r
392\r
393**/\r
394EFI_STATUS\r
395EFIAPI\r
396LockKeyboards (\r
397 IN CHAR16 *Password\r
398 )\r
399{\r
400 return EFI_UNSUPPORTED;\r
401}\r