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