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