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