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