]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Library/EmuBdsLib/BdsPlatform.c
75fba847f4c5c702086e2a10bffa1d6fc5826615
[mirror_edk2.git] / EmulatorPkg / Library / EmuBdsLib / BdsPlatform.c
1 /*++ @file
2
3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2011, Apple Inc. All rights reserved.
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "BdsPlatform.h"
16
17 EMU_SYSTEM_CONFIGURATION mSystemConfigData;
18
19 VOID
20 SetupVariableInit (
21 VOID
22 )
23 {
24 EFI_STATUS Status;
25 UINTN Size;
26
27 Size = sizeof (mSystemConfigData);
28 Status = gRT->GetVariable (
29 L"Setup",
30 &gEmuSystemConfigGuid,
31 NULL,
32 &Size,
33 (VOID *) &mSystemConfigData
34 );
35
36 if (EFI_ERROR (Status)) {
37 //
38 // SetupVariable is corrupt
39 //
40 mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);
41 mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);
42
43 Status = gRT->SetVariable (
44 L"Setup",
45 &gEmuSystemConfigGuid,
46 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
47 sizeof (mSystemConfigData),
48 (VOID *) &mSystemConfigData
49 );
50 if (EFI_ERROR (Status)) {
51 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
52 }
53 }
54 }
55
56 //
57 // BDS Platform Functions
58 //
59 VOID
60 EFIAPI
61 PlatformBdsInit (
62 VOID
63 )
64 /*++
65
66 Routine Description:
67
68 Platform Bds init. Include the platform firmware vendor, revision
69 and so crc check.
70
71 Arguments:
72
73 Returns:
74
75 None.
76
77 **/
78 {
79 SetupVariableInit ();
80
81 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
82 }
83
84 EFI_STATUS
85 PlatformBdsConnectConsole (
86 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
87 )
88 /*++
89
90 Routine Description:
91
92 Connect the predefined platform default console device. Always try to find
93 and enable the vga device if have.
94
95 Arguments:
96
97 PlatformConsole - Predefined platform default console device array.
98
99 Returns:
100
101 EFI_SUCCESS - Success connect at least one ConIn and ConOut
102 device, there must have one ConOut device is
103 active vga device.
104
105 EFI_STATUS - Return the status of
106 BdsLibConnectAllDefaultConsoles ()
107
108 **/
109 {
110 EFI_STATUS Status;
111 UINTN Index;
112
113 Index = 0;
114 Status = EFI_SUCCESS;
115
116 //
117 // Have chance to connect the platform default console,
118 // the platform default console is the minimum device group
119 // the platform should support
120 //
121 while (PlatformConsole[Index].DevicePath != NULL) {
122 //
123 // Update the console variable with the connect type
124 //
125 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
126 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
127 }
128
129 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
130 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
131 }
132
133 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
134 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
135 }
136
137 Index++;
138 }
139 //
140 // Connect the all the default console with current cosole variable
141 //
142 Status = BdsLibConnectAllDefaultConsoles ();
143 return Status;
144 }
145
146 VOID
147 PlatformBdsConnectSequence (
148 VOID
149 )
150 /*++
151
152 Routine Description:
153
154 Connect with predefined platform connect sequence,
155 the OEM/IBV can customize with their own connect sequence.
156
157 Arguments:
158
159 None.
160
161 Returns:
162
163 None.
164
165 **/
166 {
167 UINTN Index;
168
169 Index = 0;
170
171 //
172 // Here we can get the customized platform connect sequence
173 // Notes: we can connect with new variable which record the
174 // last time boots connect device path sequence
175 //
176 while (gPlatformConnectSequence[Index] != NULL) {
177 //
178 // Build the platform boot option
179 //
180 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
181 Index++;
182 }
183
184 //
185 // Just use the simple policy to connect all devices
186 //
187 BdsLibConnectAll ();
188 }
189
190 VOID
191 PlatformBdsGetDriverOption (
192 IN OUT LIST_ENTRY *BdsDriverLists
193 )
194 /*++
195
196 Routine Description:
197
198 Load the predefined driver option, OEM/IBV can customize this
199 to load their own drivers
200
201 Arguments:
202
203 BdsDriverLists - The header of the driver option link list.
204
205 Returns:
206
207 None.
208
209 **/
210 {
211 UINTN Index;
212
213 Index = 0;
214
215 //
216 // Here we can get the customized platform driver option
217 //
218 while (gPlatformDriverOption[Index] != NULL) {
219 //
220 // Build the platform boot option
221 //
222 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
223 Index++;
224 }
225
226 }
227
228 VOID
229 PlatformBdsDiagnostics (
230 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
231 IN BOOLEAN QuietBoot,
232 IN BASEM_MEMORY_TEST BaseMemoryTest
233 )
234 /*++
235
236 Routine Description:
237
238 Perform the platform diagnostic, such like test memory. OEM/IBV also
239 can customize this fuction to support specific platform diagnostic.
240
241 Arguments:
242
243 MemoryTestLevel - The memory test intensive level
244
245 QuietBoot - Indicate if need to enable the quiet boot
246
247 BaseMemoryTest - A pointer to BdsMemoryTest()
248
249 Returns:
250
251 None.
252
253 **/
254 {
255 EFI_STATUS Status;
256
257 //
258 // Here we can decide if we need to show
259 // the diagnostics screen
260 // Notes: this quiet boot code should be remove
261 // from the graphic lib
262 //
263 if (QuietBoot) {
264 EnableQuietBoot (PcdGetPtr(PcdLogoFile));
265 //
266 // Perform system diagnostic
267 //
268 Status = BaseMemoryTest (MemoryTestLevel);
269 if (EFI_ERROR (Status)) {
270 DisableQuietBoot ();
271 }
272
273 return ;
274 }
275 //
276 // Perform system diagnostic
277 //
278 Status = BaseMemoryTest (MemoryTestLevel);
279 }
280
281 VOID
282 EFIAPI
283 PlatformBdsPolicyBehavior (
284 IN OUT LIST_ENTRY *DriverOptionList,
285 IN OUT LIST_ENTRY *BootOptionList,
286 IN PROCESS_CAPSULES ProcessCapsules,
287 IN BASEM_MEMORY_TEST BaseMemoryTest
288 )
289 /*++
290
291 Routine Description:
292
293 The function will execute with as the platform policy, current policy
294 is driven by boot mode. IBV/OEM can customize this code for their specific
295 policy action.
296
297 Arguments:
298
299 DriverOptionList - The header of the driver option link list
300
301 BootOptionList - The header of the boot option link list
302
303 ProcessCapsules - A pointer to ProcessCapsules()
304
305 BaseMemoryTest - A pointer to BaseMemoryTest()
306
307 Returns:
308
309 None.
310
311 **/
312 {
313 EFI_STATUS Status;
314 UINT16 Timeout;
315 EFI_BOOT_MODE BootMode;
316
317 //
318 // Init the time out value
319 //
320 Timeout = PcdGet16 (PcdPlatformBootTimeOut);
321
322 //
323 // Load the driver option as the driver option list
324 //
325 PlatformBdsGetDriverOption (DriverOptionList);
326
327 //
328 // Get current Boot Mode
329 //
330 Status = BdsLibGetBootMode (&BootMode);
331
332 //
333 // Go the different platform policy with different boot mode
334 // Notes: this part code can be change with the table policy
335 //
336 switch (BootMode) {
337
338 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
339 case BOOT_WITH_MINIMAL_CONFIGURATION:
340 //
341 // In no-configuration boot mode, we can connect the
342 // console directly.
343 //
344 BdsLibConnectAllDefaultConsoles ();
345 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
346
347 //
348 // Perform some platform specific connect sequence
349 //
350 PlatformBdsConnectSequence ();
351
352 //
353 // Notes: current time out = 0 can not enter the
354 // front page
355 //
356 PlatformBdsEnterFrontPage (Timeout, FALSE);
357
358 //
359 // Check the boot option with the boot option list
360 //
361 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
362 break;
363
364 case BOOT_ON_FLASH_UPDATE:
365 //
366 // Boot with the specific configuration
367 //
368 PlatformBdsConnectConsole (gPlatformConsole);
369 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
370 BdsLibConnectAll ();
371 ProcessCapsules (BOOT_ON_FLASH_UPDATE);
372 break;
373
374 case BOOT_IN_RECOVERY_MODE:
375 //
376 // In recovery mode, just connect platform console
377 // and show up the front page
378 //
379 PlatformBdsConnectConsole (gPlatformConsole);
380 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
381
382 //
383 // In recovery boot mode, we still enter to the
384 // frong page now
385 //
386 PlatformBdsEnterFrontPage (Timeout, FALSE);
387 break;
388
389 case BOOT_WITH_FULL_CONFIGURATION:
390 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
391 case BOOT_WITH_DEFAULT_SETTINGS:
392 default:
393 //
394 // Connect platform console
395 //
396 Status = PlatformBdsConnectConsole (gPlatformConsole);
397 if (EFI_ERROR (Status)) {
398 //
399 // Here OEM/IBV can customize with defined action
400 //
401 PlatformBdsNoConsoleAction ();
402 }
403
404 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
405
406 //
407 // Perform some platform specific connect sequence
408 //
409 PlatformBdsConnectSequence ();
410
411 //
412 // Give one chance to enter the setup if we
413 // have the time out
414 //
415 PlatformBdsEnterFrontPage (Timeout, FALSE);
416
417 //
418 // Here we have enough time to do the enumeration of boot device
419 //
420 BdsLibEnumerateAllBootOption (BootOptionList);
421 break;
422 }
423
424 return ;
425
426 }
427
428 VOID
429 EFIAPI
430 PlatformBdsBootSuccess (
431 IN BDS_COMMON_OPTION *Option
432 )
433 /*++
434
435 Routine Description:
436
437 Hook point after a boot attempt succeeds. We don't expect a boot option to
438 return, so the EFI 1.0 specification defines that you will default to an
439 interactive mode and stop processing the BootOrder list in this case. This
440 is alos a platform implementation and can be customized by IBV/OEM.
441
442 Arguments:
443
444 Option - Pointer to Boot Option that succeeded to boot.
445
446 Returns:
447
448 None.
449
450 **/
451 {
452 CHAR16 *TmpStr;
453
454 //
455 // If Boot returned with EFI_SUCCESS and there is not in the boot device
456 // select loop then we need to pop up a UI and wait for user input.
457 //
458 TmpStr = Option->StatusString;
459 if (TmpStr != NULL) {
460 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
461 FreePool (TmpStr);
462 }
463 }
464
465 VOID
466 EFIAPI
467 PlatformBdsBootFail (
468 IN BDS_COMMON_OPTION *Option,
469 IN EFI_STATUS Status,
470 IN CHAR16 *ExitData,
471 IN UINTN ExitDataSize
472 )
473 /*++
474
475 Routine Description:
476
477 Hook point after a boot attempt fails.
478
479 Arguments:
480
481 Option - Pointer to Boot Option that failed to boot.
482
483 Status - Status returned from failed boot.
484
485 ExitData - Exit data returned from failed boot.
486
487 ExitDataSize - Exit data size returned from failed boot.
488
489 Returns:
490
491 None.
492
493 **/
494 {
495 CHAR16 *TmpStr;
496
497 //
498 // If Boot returned with failed status then we need to pop up a UI and wait
499 // for user input.
500 //
501 TmpStr = Option->StatusString;
502 if (TmpStr != NULL) {
503 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
504 FreePool (TmpStr);
505 }
506 }
507
508 EFI_STATUS
509 PlatformBdsNoConsoleAction (
510 VOID
511 )
512 /*++
513
514 Routine Description:
515
516 This function is remained for IBV/OEM to do some platform action,
517 if there no console device can be connected.
518
519 Arguments:
520
521 None.
522
523 Returns:
524
525 EFI_SUCCESS - Direct return success now.
526
527 **/
528 {
529 return EFI_SUCCESS;
530 }
531
532 VOID
533 EFIAPI
534 PlatformBdsLockNonUpdatableFlash (
535 VOID
536 )
537 {
538 return;
539 }
540
541 /**
542 Lock the ConsoleIn device in system table. All key
543 presses will be ignored until the Password is typed in. The only way to
544 disable the password is to type it in to a ConIn device.
545
546 @param Password Password used to lock ConIn device.
547
548 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
549 @retval EFI_UNSUPPORTED Password not found
550
551 **/
552 EFI_STATUS
553 EFIAPI
554 LockKeyboards (
555 IN CHAR16 *Password
556 )
557 {
558 return EFI_UNSUPPORTED;
559 }