]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
903b46d583853f157e085a77241fe9497c42e6a7
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / PlatformBdsLib / BdsPlatform.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 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 Module Name:
16
17 BdsPlatform.c
18
19 Abstract:
20
21 This file include all platform action which can be customized
22 by IBV/OEM.
23
24 --*/
25
26 #include "BdsPlatform.h"
27 #include "SetupMode.h"
28 #include <Guid/SetupVariable.h>
29 #include <Library/TcgPhysicalPresenceLib.h>
30 #include <Library/TrEEPhysicalPresenceLib.h>
31 #include <Protocol/I2cMasterMcg.h>
32 #include <TianoApi.h>
33 #include <PlatformBaseAddresses.h>
34 #include <Protocol/GlobalNvsArea.h>
35 #include <Library/DxeServicesTableLib.h>
36 #include <Protocol/BlockIo.h>
37 #include <PchRegs/PchRegsPcu.h>
38 #include <Library/S3BootScriptLib.h>
39 #include "PchAccess.h"
40 #include "PchRegs/PchRegsSata.h"
41 #include <Library/SerialPortLib.h>
42 #include <Library/DebugLib.h>
43
44 #include <Library/GenericBdsLib/InternalBdsLib.h>
45 #include <Library/GenericBdsLib/String.h>
46 #include <Library/NetLib.h>
47
48 EFI_GUID *ConnectDriverTable[] = {
49 &gEfiMmioDeviceProtocolGuid,
50 &gEfiI2cMasterProtocolGuid,
51 &gEfiI2cHostProtocolGuid
52 };
53
54 #define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \
55 { \
56 0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
57 }
58 VOID *mShellImageCallbackReg = NULL;
59
60
61
62 EFI_USER_PROFILE_HANDLE mCurrentUser = NULL;
63 EFI_EVENT mHotKeyTimerEvent = NULL;
64 EFI_EVENT mHitHotkeyEvent = NULL;
65 EFI_EVENT mUsbKeyboardConnectEvent = NULL;
66 BOOLEAN mHotKeyPressed = FALSE;
67 VOID *mHitHotkeyRegistration;
68 #define KEYBOARD_TIMER_INTERVAL 20000 // 0.02s
69
70 VOID
71 ConnectUSBController (
72 VOID
73 );
74
75 EFI_STATUS
76 PlatformBdsConnectSimpleConsole (
77 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
78 );
79
80 VOID
81 BootIntoFirmwareInterface(
82 VOID
83 );
84
85 VOID
86 EFIAPI
87 PlatformBdsInitHotKeyEvent (
88 VOID
89 );
90
91 VOID
92 EFIAPI
93 DisableAhciCtlr (
94 IN EFI_EVENT Event,
95 IN VOID *Context
96 )
97 {
98 UINT32 PmcDisableAddress;
99 UINT8 SataStorageAmount;
100 UINT32 SataBase;
101 UINT16 SataPortStatus;
102
103
104 DEBUG ((EFI_D_INFO, "Disable AHCI event is signalled\n"));
105 SataStorageAmount = 0;
106 SataBase = *(UINT32*) Context;
107
108 //
109 // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port Control and Status)
110 //
111 SataPortStatus = MmioRead16 (SataBase + R_PCH_SATA_PCS);
112
113 //
114 // Bit 8 EN: Port 0 Present
115 //
116 if ((SataPortStatus & 0x100) == 0x100) {
117 SataStorageAmount++;
118 }
119
120 //
121 // Bit 9 EN: Port 1 Present
122 //
123 if ((SataPortStatus & 0x200) == 0x200) {
124 SataStorageAmount++;
125 }
126
127 //
128 // Disable SATA controller when it sets to AHCI mode without carrying any devices
129 // in order to prevent AHCI yellow bang under Win device manager.
130 //
131 if (SataStorageAmount == 0) {
132 PmcDisableAddress = (MmioRead32 ((PCH_PCI_EXPRESS_BASE_ADDRESS + (UINT32) (31 << 15)) + R_PCH_LPC_PMC_BASE) & B_PCH_LPC_PMC_BASE_BAR) + R_PCH_PMC_FUNC_DIS;
133 MmioOr32 (PmcDisableAddress, B_PCH_PMC_FUNC_DIS_SATA);
134 S3BootScriptSaveMemWrite (
135 EfiBootScriptWidthUint32,
136 (UINTN) PmcDisableAddress,
137 1,
138 (VOID *) (UINTN) PmcDisableAddress
139 );
140 }
141 }
142
143 VOID
144 InstallReadyToLock (
145 VOID
146 )
147 {
148 EFI_STATUS Status;
149 EFI_HANDLE Handle;
150 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;
151 EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
152
153 //
154 // Install DxeSmmReadyToLock protocol prior to the processing of boot options
155 //
156 Status = gBS->LocateProtocol (
157 &gEfiSmmAccess2ProtocolGuid,
158 NULL,
159 (VOID **) &SmmAccess
160 );
161 if (!EFI_ERROR (Status)) {
162
163 //
164 // Prepare S3 information, this MUST be done before DxeSmmReadyToLock
165 //
166 Status = gBS->LocateProtocol (
167 &gEfiAcpiS3SaveProtocolGuid,
168 NULL,
169 (VOID **)&AcpiS3Save
170 );
171 if (!EFI_ERROR (Status)) {
172 AcpiS3Save->S3Save (AcpiS3Save, NULL);
173 }
174
175 Handle = NULL;
176 Status = gBS->InstallProtocolInterface (
177 &Handle,
178 &gExitPmAuthProtocolGuid,
179 EFI_NATIVE_INTERFACE,
180 NULL
181 );
182 ASSERT_EFI_ERROR (Status);
183
184 Handle = NULL;
185 Status = gBS->InstallProtocolInterface (
186 &Handle,
187 &gEfiDxeSmmReadyToLockProtocolGuid,
188 EFI_NATIVE_INTERFACE,
189 NULL
190 );
191 ASSERT_EFI_ERROR (Status);
192 }
193
194 return ;
195 }
196
197 VOID
198 EFIAPI
199 ShellImageCallback (
200 IN EFI_EVENT Event,
201 IN VOID *Context
202 )
203 {
204 BdsSetConsoleMode (TRUE);
205 DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n"));
206 }
207
208 //
209 // BDS Platform Functions
210 //
211 /**
212 Platform Bds init. Incude the platform firmware vendor, revision
213 and so crc check.
214
215 @param VOID
216
217 @retval None.
218
219 **/
220 VOID
221 EFIAPI
222 PlatformBdsInit (
223 VOID
224 )
225 {
226 EFI_STATUS Status;
227 EFI_EVENT ShellImageEvent;
228 EFI_GUID ShellEnvProtocol = SHELL_ENVIRONMENT_INTERFACE_PROTOCOL;
229
230 #ifdef __GNUC__
231 SerialPortWrite((UINT8 *)">>>>BdsEntry[GCC]\r\n", 19);
232 #else
233 SerialPortWrite((UINT8 *)">>>>BdsEntry\r\n", 14);
234 #endif
235 BdsLibSaveMemoryTypeInformation ();
236
237 //
238 // Before user authentication, the user identification devices need be connected
239 // from the platform customized device paths
240 //
241 PlatformBdsConnectAuthDevice ();
242
243 //
244 // As console is not ready, the auto logon user will be identified.
245 //
246 BdsLibUserIdentify (&mCurrentUser);
247
248 //
249 // Change Gop mode when boot into Shell
250 //
251 if (mShellImageCallbackReg == NULL) {
252 Status = gBS->CreateEvent (
253 EFI_EVENT_NOTIFY_SIGNAL,
254 EFI_TPL_CALLBACK,
255 ShellImageCallback,
256 NULL,
257 &ShellImageEvent
258 );
259 if (!EFI_ERROR (Status)) {
260 Status = gBS->RegisterProtocolNotify (
261 &ShellEnvProtocol,
262 ShellImageEvent,
263 &mShellImageCallbackReg
264 );
265
266 DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n"));
267 }
268 }
269 }
270
271 EFI_STATUS
272 GetGopDevicePath (
273 IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,
274 OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath
275 )
276 {
277 UINTN Index;
278 EFI_STATUS Status;
279 EFI_HANDLE PciDeviceHandle;
280 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
281 EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath;
282 UINTN GopHandleCount;
283 EFI_HANDLE *GopHandleBuffer;
284
285 UINTN VarSize;
286 SYSTEM_CONFIGURATION mSystemConfiguration;
287
288 if (PciDevicePath == NULL || GopDevicePath == NULL) {
289 return EFI_INVALID_PARAMETER;
290 }
291
292 //
293 // Initialize the GopDevicePath to be PciDevicePath
294 //
295 *GopDevicePath = PciDevicePath;
296 TempPciDevicePath = PciDevicePath;
297
298 Status = gBS->LocateDevicePath (
299 &gEfiDevicePathProtocolGuid,
300 &TempPciDevicePath,
301 &PciDeviceHandle
302 );
303 if (EFI_ERROR (Status)) {
304 return Status;
305 }
306
307 //
308 // Try to connect this handle, so that GOP dirver could start on this
309 // device and create child handles with GraphicsOutput Protocol installed
310 // on them, then we get device paths of these child handles and select
311 // them as possible console device.
312 //
313
314 //
315 // Select display devices
316 //
317 VarSize = sizeof(SYSTEM_CONFIGURATION);
318 Status = gRT->GetVariable(
319 L"Setup",
320 &gEfiNormalSetupGuid,
321 NULL,
322 &VarSize,
323 &mSystemConfiguration
324 );
325 ASSERT_EFI_ERROR (Status);
326
327 if(mSystemConfiguration.BootDisplayDevice != 0x0)
328 {
329 ACPI_ADR_DEVICE_PATH AcpiAdr;
330 EFI_DEVICE_PATH_PROTOCOL *MyDevicePath = NULL;
331
332 AcpiAdr.Header.Type = ACPI_DEVICE_PATH;
333 AcpiAdr.Header.SubType = ACPI_ADR_DP;
334
335 switch (mSystemConfiguration.BootDisplayDevice) {
336 case 1:
337 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, PORT_CRT, 0); //CRT Device
338 break;
339 case 2:
340 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_B_HDMI, 0); //HDMI Device Port B
341 break;
342 case 3:
343 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_B_DP, 0); //DP PortB
344 break;
345 case 4:
346 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_C_DP, 0); //DP PortC
347 break;
348 case 5:
349 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_C_DP, 0); //eDP Port C
350 break;
351 case 6:
352 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_MIPI_A, 0); //DSI Port A
353 break;
354 case 7:
355 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_MIPI_C, 0); //DSI Port C
356 break;
357 default:
358 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, PORT_CRT, 0);
359 break;
360 }
361
362 SetDevicePathNodeLength (&AcpiAdr.Header, sizeof (ACPI_ADR_DEVICE_PATH));
363
364 MyDevicePath = AppendDevicePathNode(MyDevicePath, (EFI_DEVICE_PATH_PROTOCOL*)&AcpiAdr);
365
366 gBS->ConnectController (
367 PciDeviceHandle,
368 NULL,
369 MyDevicePath,
370 FALSE
371 );
372
373 FreePool(MyDevicePath);
374 }
375 else
376 {
377 gBS->ConnectController (
378 PciDeviceHandle,
379 NULL,
380 NULL,
381 FALSE
382 );
383 }
384
385 Status = gBS->LocateHandleBuffer (
386 ByProtocol,
387 &gEfiGraphicsOutputProtocolGuid,
388 NULL,
389 &GopHandleCount,
390 &GopHandleBuffer
391 );
392 if (!EFI_ERROR (Status)) {
393 //
394 // Add all the child handles as possible Console Device
395 //
396 for (Index = 0; Index < GopHandleCount; Index++) {
397 Status = gBS->HandleProtocol (
398 GopHandleBuffer[Index],
399 &gEfiDevicePathProtocolGuid,
400 (VOID**)&TempDevicePath
401 );
402 if (EFI_ERROR (Status)) {
403 continue;
404 }
405 if (CompareMem (
406 PciDevicePath,
407 TempDevicePath,
408 GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH
409 ) == 0) {
410 //
411 // In current implementation, we only enable one of the child handles
412 // as console device, i.e. sotre one of the child handle's device
413 // path to variable "ConOut"
414 // In futhure, we could select all child handles to be console device
415 //
416 *GopDevicePath = TempDevicePath;
417 }
418 }
419 gBS->FreePool (GopHandleBuffer);
420 }
421
422 return EFI_SUCCESS;
423 }
424
425 /**
426
427 Search out all the platform pci or agp video device. The function may will
428 find multiple video device, and return all enabled device path.
429
430 @param PlugInPciVgaDevicePath Return the platform plug in pci video device
431 path if the system have plug in pci video device.
432 @param OnboardPciVgaDevicePath Return the platform active agp video device path
433 if the system have plug in agp video device or on
434 chip agp device.
435
436 @retval EFI_SUCCSS Get all platform active video device path.
437 @retval EFI_STATUS Return the status of gBS->LocateDevicePath (),
438 gBS->ConnectController (),
439 and gBS->LocateHandleBuffer ().
440
441 **/
442 EFI_STATUS
443 GetPlugInPciVgaDevicePath (
444 IN OUT EFI_DEVICE_PATH_PROTOCOL **PlugInPciVgaDevicePath,
445 IN OUT EFI_DEVICE_PATH_PROTOCOL **OnboardPciVgaDevicePath
446 )
447 {
448 EFI_STATUS Status;
449 EFI_HANDLE RootHandle;
450 UINTN HandleCount;
451 EFI_HANDLE *HandleBuffer;
452 UINTN Index;
453 UINTN Index1;
454 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
455 BOOLEAN PlugInPciVga;
456 EFI_PCI_IO_PROTOCOL *PciIo;
457 PCI_TYPE00 Pci;
458
459 DevicePath = NULL;
460 PlugInPciVga = TRUE;
461 HandleCount = 0;
462 HandleBuffer = NULL;
463
464 //
465 // Make all the PCI_IO protocols on PCI Seg 0 show up
466 //
467 BdsLibConnectDevicePath (gPlatformRootBridges[0]);
468
469 Status = gBS->LocateDevicePath (
470 &gEfiDevicePathProtocolGuid,
471 &gPlatformRootBridges[0],
472 &RootHandle
473 );
474 if (EFI_ERROR (Status)) {
475 return Status;
476 }
477
478 Status = gBS->ConnectController (
479 RootHandle,
480 NULL,
481 NULL,
482 FALSE
483 );
484 if (EFI_ERROR (Status)) {
485 return Status;
486 }
487
488 //
489 // Start to check all the pci io to find all possible VGA device
490 //
491 HandleCount = 0;
492 HandleBuffer = NULL;
493 Status = gBS->LocateHandleBuffer (
494 ByProtocol,
495 &gEfiPciIoProtocolGuid,
496 NULL,
497 &HandleCount,
498 &HandleBuffer
499 );
500 if (EFI_ERROR (Status)) {
501 return Status;
502 }
503
504 for (Index = 0; Index < HandleCount; Index++) {
505 Status = gBS->HandleProtocol (
506 HandleBuffer[Index],
507 &gEfiPciIoProtocolGuid,
508 (VOID**)&PciIo
509 );
510 if (!EFI_ERROR (Status)) {
511
512 //
513 // Check for all VGA device
514 //
515 Status = PciIo->Pci.Read (
516 PciIo,
517 EfiPciIoWidthUint32,
518 0,
519 sizeof (Pci) / sizeof (UINT32),
520 &Pci
521 );
522 if (EFI_ERROR (Status)) {
523 continue;
524 }
525
526 //
527 // Here we decide which VGA device to enable in PCI bus
528 //
529 // The first plugin PCI VGA card device will be present as PCI VGA
530 // The onchip AGP or AGP card will be present as AGP VGA
531 //
532 if (!IS_PCI_VGA (&Pci)) {
533 continue;
534 }
535
536 //
537 // Set the device as the possible console out device,
538 //
539 // Below code will make every VGA device to be one
540 // of the possibe console out device
541 //
542 PlugInPciVga = TRUE;
543 gBS->HandleProtocol (
544 HandleBuffer[Index],
545 &gEfiDevicePathProtocolGuid,
546 (VOID**)&DevicePath
547 );
548
549 Index1 = 0;
550
551 while (gPlatformAllPossiblePciVgaConsole[Index1] != NULL) {
552 if (CompareMem (
553 DevicePath,
554 gPlatformAllPossiblePciVgaConsole[Index1],
555 GetDevicePathSize (gPlatformAllPossiblePciVgaConsole[Index1])
556 ) == 0) {
557
558 //
559 // This device is an AGP device
560 //
561 *OnboardPciVgaDevicePath = DevicePath;
562 PlugInPciVga = FALSE;
563 break;
564 }
565
566 Index1 ++;
567 }
568
569 if (PlugInPciVga) {
570 *PlugInPciVgaDevicePath = DevicePath;
571 }
572 }
573 }
574
575 FreePool (HandleBuffer);
576
577 return EFI_SUCCESS;
578 }
579
580 /**
581
582 Find the platform active vga, and base on the policy to enable the vga as
583 the console out device. The policy is driven by one setup variable "VBIOS".
584
585 None.
586
587 @param EFI_UNSUPPORTED There is no active vga device
588
589 @retval EFI_STATUS Return the status of BdsLibGetVariableAndSize ()
590
591 **/
592 EFI_STATUS
593 PlatformBdsForceActiveVga (
594 VOID
595 )
596 {
597 EFI_STATUS Status;
598 EFI_DEVICE_PATH_PROTOCOL *PlugInPciVgaDevicePath;
599 EFI_DEVICE_PATH_PROTOCOL *OnboardPciVgaDevicePath;
600 EFI_DEVICE_PATH_PROTOCOL *DevicePathFirst;
601 EFI_DEVICE_PATH_PROTOCOL *DevicePathSecond;
602 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
603 UINTN VarSize;
604 SYSTEM_CONFIGURATION mSystemConfiguration;
605
606 Status = EFI_SUCCESS;
607 PlugInPciVgaDevicePath = NULL;
608 OnboardPciVgaDevicePath = NULL;
609
610 //
611 // Check the policy which is the first enabled VGA
612 //
613 GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath, &OnboardPciVgaDevicePath);
614
615 if (PlugInPciVgaDevicePath == NULL && OnboardPciVgaDevicePath == NULL) {
616 return EFI_UNSUPPORTED;
617 }
618
619 VarSize = sizeof(SYSTEM_CONFIGURATION);
620 Status = gRT->GetVariable(
621 L"Setup",
622 &gEfiNormalSetupGuid,
623 NULL,
624 &VarSize,
625 &mSystemConfiguration
626 );
627 ASSERT_EFI_ERROR (Status);
628
629
630 if ((PlugInPciVgaDevicePath == NULL && OnboardPciVgaDevicePath != NULL) ) {
631 DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA ...\n"));
632 DevicePathFirst = OnboardPciVgaDevicePath;
633 DevicePathSecond = PlugInPciVgaDevicePath;
634 goto UpdateConOut;
635 }
636 if(OnboardPciVgaDevicePath != NULL && mSystemConfiguration.PrimaryVideoAdaptor == 0) {
637 DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA When set primary!!!...\n"));
638 DevicePathFirst = OnboardPciVgaDevicePath;
639 DevicePathSecond = PlugInPciVgaDevicePath;
640 goto UpdateConOut;
641 }
642
643 DEBUG ((EFI_D_ERROR,"Update plug in PCI VGA ...\n"));
644 DevicePathFirst = PlugInPciVgaDevicePath;
645 DevicePathSecond = OnboardPciVgaDevicePath;
646
647 UpdateConOut:
648 GetGopDevicePath (DevicePathFirst, &GopDevicePath);
649 DevicePathFirst = GopDevicePath;
650
651 Status = BdsLibUpdateConsoleVariable (
652 L"ConOut",
653 DevicePathFirst,
654 DevicePathSecond
655 );
656
657 return Status;
658 }
659
660 VOID
661 UpdateConsoleResolution(
662 VOID
663 )
664 {
665 UINT32 HorizontalResolution;
666 UINT32 VerticalResolution;
667 SYSTEM_CONFIGURATION SystemConfiguration;
668 UINTN VarSize;
669 EFI_STATUS Status;
670
671
672 HorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
673 VerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
674
675 VarSize = sizeof(SYSTEM_CONFIGURATION);
676 Status = gRT->GetVariable(
677 L"Setup",
678 &gEfiNormalSetupGuid,
679 NULL,
680 &VarSize,
681 &SystemConfiguration
682 );
683 ASSERT_EFI_ERROR (Status);
684
685 switch (SystemConfiguration.IgdFlatPanel) {
686
687 case 0:
688 //
689 // Use the detault PCD values.
690 //
691 break;
692
693 case 1:
694 HorizontalResolution = 640;
695 VerticalResolution = 480;
696 break;
697
698 case 2:
699 HorizontalResolution = 800;
700 VerticalResolution = 600;
701 break;
702
703 case 3:
704 HorizontalResolution = 1024;
705 VerticalResolution = 768;
706 break;
707
708 case 4:
709 HorizontalResolution = 1280;
710 VerticalResolution = 1024;
711 break;
712
713 case 5:
714 HorizontalResolution = 1366;
715 VerticalResolution = 768;
716 break;
717
718 case 6:
719 HorizontalResolution = 1680;
720 VerticalResolution = 1050;
721 break;
722
723 case 7:
724 HorizontalResolution = 1920;
725 VerticalResolution = 1200;
726 break;
727
728 case 8:
729 HorizontalResolution = 1280;
730 VerticalResolution = 800;
731 break;
732 }
733
734 PcdSet32 (PcdSetupVideoHorizontalResolution, HorizontalResolution);
735 PcdSet32 (PcdSetupVideoVerticalResolution, VerticalResolution);
736 DEBUG ((EFI_D_ERROR, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution, VerticalResolution));
737
738 return;
739 }
740
741 /**
742 Connect the predefined platform default console device. Always try to find
743 and enable the vga device if have.
744
745 @param PlatformConsole Predfined platform default console device array.
746
747 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
748 device, there must have one ConOut device is
749 active vga device.
750
751 @retval EFI_STATUS Return the status of
752 BdsLibConnectAllDefaultConsoles ()
753
754 **/
755 EFI_STATUS
756 PlatformBdsConnectConsole (
757 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
758 )
759 {
760 EFI_STATUS Status;
761 UINTN Index;
762 EFI_DEVICE_PATH_PROTOCOL *VarConout;
763 EFI_DEVICE_PATH_PROTOCOL *VarConin;
764 UINTN DevicePathSize;
765
766 UpdateConsoleResolution();
767
768 Index = 0;
769 Status = EFI_SUCCESS;
770 DevicePathSize = 0;
771 VarConout = BdsLibGetVariableAndSize (
772 L"ConOut",
773 &gEfiGlobalVariableGuid,
774 &DevicePathSize
775 );
776 VarConin = BdsLibGetVariableAndSize (
777 L"ConIn",
778 &gEfiGlobalVariableGuid,
779 &DevicePathSize
780 );
781 if (VarConout == NULL || VarConin == NULL) {
782 //
783 // Have chance to connect the platform default console,
784 // the platform default console is the minimue device group
785 // the platform should support
786 //
787 while (PlatformConsole[Index].DevicePath != NULL) {
788
789 //
790 // Update the console variable with the connect type
791 //
792 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
793 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
794 }
795
796 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
797 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
798 }
799
800 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
801 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
802 }
803
804 Index ++;
805 }
806 }
807
808 //
809 // Make sure we have at least one active VGA, and have the right
810 // active VGA in console variable
811 //
812 Status = PlatformBdsForceActiveVga ();
813 if (EFI_ERROR (Status)) {
814 return Status;
815 }
816
817 DEBUG ((EFI_D_INFO, "DISPLAY INIT DONE\n"));
818
819 //
820 // Connect the all the default console with current console variable
821 //
822 Status = BdsLibConnectAllDefaultConsoles ();
823 if (EFI_ERROR (Status)) {
824 return Status;
825 }
826
827 return EFI_SUCCESS;
828 }
829
830 /**
831 Connect with predeined platform connect sequence,
832 the OEM/IBV can customize with their own connect sequence.
833
834 @param None.
835
836 @retval None.
837
838 **/
839 VOID
840 PlatformBdsConnectSequence (
841 VOID
842 )
843 {
844 UINTN Index;
845
846 Index = 0;
847
848 //
849 // Here we can get the customized platform connect sequence
850 // Notes: we can connect with new variable which record the
851 // last time boots connect device path sequence
852 //
853 while (gPlatformConnectSequence[Index] != NULL) {
854
855 //
856 // Build the platform boot option
857 //
858 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
859 Index ++;
860 }
861
862 //
863 // Just use the simple policy to connect all devices
864 // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.
865 //
866 // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.
867 // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.
868 //
869 // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().
870 // We may also consider to connect SataController only later if needed.
871 //
872 BdsLibConnectAll ();
873 }
874
875 /**
876
877 Load the predefined driver option, OEM/IBV can customize this
878 to load their own drivers
879
880 @param BdsDriverLists The header of the driver option link list.
881
882 @retval None.
883
884 **/
885 VOID
886 PlatformBdsGetDriverOption (
887 IN OUT LIST_ENTRY *BdsDriverLists
888 )
889 {
890 UINTN Index;
891
892 Index = 0;
893
894 //
895 // Here we can get the customized platform driver option
896 //
897 while (gPlatformDriverOption[Index] != NULL) {
898
899 //
900 // Build the platform boot option
901 //
902 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
903 Index ++;
904 }
905
906 }
907
908 /**
909 This function is used for some critical time if the the system
910 have no any boot option, and there is no time out for user to add
911 the new boot option. This can also treat as the platform default
912 boot option.
913
914 @param BdsBootOptionList The header of the boot option link list.
915
916 @retval None.
917
918 **/
919 VOID
920 PlatformBdsPredictBootOption (
921 IN OUT LIST_ENTRY *BdsBootOptionList
922 )
923 {
924 UINTN Index;
925
926 Index = 0;
927
928 //
929 // Here give chance to get platform boot option data
930 //
931 while (gPlatformBootOption[Index] != NULL) {
932
933 //
934 // Build the platform boot option
935 //
936 BdsLibRegisterNewOption (BdsBootOptionList, gPlatformBootOption[Index], NULL, L"BootOrder");
937 Index ++;
938 }
939 }
940
941 /**
942 Perform the platform diagnostic, such like test memory. OEM/IBV also
943 can customize this fuction to support specific platform diagnostic.
944
945 @param MemoryTestLevel The memory test intensive level
946 @param QuietBoot Indicate if need to enable the quiet boot
947 @param BaseMemoryTest A pointer to BdsMemoryTest()
948
949 @retval None.
950
951 **/
952 VOID
953 PlatformBdsDiagnostics (
954 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
955 IN BOOLEAN QuietBoot,
956 IN BASEM_MEMORY_TEST BaseMemoryTest
957 )
958 {
959 EFI_STATUS Status;
960
961 //
962 // Here we can decide if we need to show
963 // the diagnostics screen
964 // Notes: this quiet boot code should be remove
965 // from the graphic lib
966 //
967 if (QuietBoot) {
968 EnableQuietBoot (PcdGetPtr(PcdLogoFile));
969
970 //
971 // Perform system diagnostic
972 //
973 Status = BaseMemoryTest (MemoryTestLevel);
974 if (EFI_ERROR (Status)) {
975 DisableQuietBoot ();
976 }
977
978 return;
979 }
980
981 //
982 // Perform system diagnostic
983 //
984 Status = BaseMemoryTest (MemoryTestLevel);
985 }
986
987
988 /**
989 For EFI boot option, BDS separate them as six types:
990 1. Network - The boot option points to the SimpleNetworkProtocol device.
991 Bds will try to automatically create this type boot option when enumerate.
992 2. Shell - The boot option points to internal flash shell.
993 Bds will try to automatically create this type boot option when enumerate.
994 3. Removable BlockIo - The boot option only points to the removable media
995 device, like USB flash disk, DVD, Floppy etc.
996 These device should contain a *removable* blockIo
997 protocol in their device handle.
998 Bds will try to automatically create this type boot option
999 when enumerate.
1000 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
1001 like HardDisk.
1002 These device should contain a *fixed* blockIo
1003 protocol in their device handle.
1004 BDS will skip fixed blockIo devices, and NOT
1005 automatically create boot option for them. But BDS
1006 will help to delete those fixed blockIo boot option,
1007 whose description rule conflict with other auto-created
1008 boot options.
1009 5. Non-BlockIo Simplefile - The boot option points to a device whose handle
1010 has SimpleFileSystem Protocol, but has no blockio
1011 protocol. These devices do not offer blockIo
1012 protocol, but BDS still can get the
1013 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
1014 Protocol.
1015 6. File - The boot option points to a file. These boot options are usually
1016 created by user manually or OS loader. BDS will not delete or modify
1017 these boot options.
1018
1019 This function will enumerate all possible boot device in the system, and
1020 automatically create boot options for Network, Shell, Removable BlockIo,
1021 and Non-BlockIo Simplefile devices.
1022 It will only execute once of every boot.
1023
1024 @param BdsBootOptionList The header of the link list which indexed all
1025 current boot options
1026
1027 @retval EFI_SUCCESS Finished all the boot device enumerate and create
1028 the boot option base on that boot device
1029
1030 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list
1031 **/
1032 EFI_STATUS
1033 EFIAPI
1034 PlatformBdsLibEnumerateAllBootOption (
1035 IN OUT LIST_ENTRY *BdsBootOptionList
1036 )
1037 {
1038 EFI_STATUS Status;
1039 UINT16 FloppyNumber;
1040 UINT16 HarddriveNumber;
1041 UINT16 CdromNumber;
1042 UINT16 UsbNumber;
1043 UINT16 MiscNumber;
1044 UINT16 ScsiNumber;
1045 UINT16 NonBlockNumber;
1046 UINTN NumberBlockIoHandles;
1047 EFI_HANDLE *BlockIoHandles;
1048 EFI_BLOCK_IO_PROTOCOL *BlkIo;
1049 BOOLEAN Removable[2];
1050 UINTN RemovableIndex;
1051 UINTN Index;
1052 UINTN NumOfLoadFileHandles;
1053 EFI_HANDLE *LoadFileHandles;
1054 UINTN FvHandleCount;
1055 EFI_HANDLE *FvHandleBuffer;
1056 EFI_FV_FILETYPE Type;
1057 UINTN Size;
1058 EFI_FV_FILE_ATTRIBUTES Attributes;
1059 UINT32 AuthenticationStatus;
1060 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
1061 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1062 UINTN DevicePathType;
1063 CHAR16 Buffer[40];
1064 EFI_HANDLE *FileSystemHandles;
1065 UINTN NumberFileSystemHandles;
1066 BOOLEAN NeedDelete;
1067 EFI_IMAGE_DOS_HEADER DosHeader;
1068 CHAR8 *PlatLang;
1069 CHAR8 *LastLang;
1070 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
1071 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
1072 CHAR16 *MacStr;
1073 CHAR16 *IPverStr;
1074 EFI_HANDLE *NetworkHandles;
1075 UINTN BufferSize;
1076
1077 FloppyNumber = 0;
1078 HarddriveNumber = 0;
1079 CdromNumber = 0;
1080 UsbNumber = 0;
1081 MiscNumber = 0;
1082 ScsiNumber = 0;
1083 PlatLang = NULL;
1084 LastLang = NULL;
1085 ZeroMem (Buffer, sizeof (Buffer));
1086
1087 //
1088 // If the boot device enumerate happened, just get the boot
1089 // device from the boot order variable
1090 //
1091 if (mEnumBootDevice) {
1092 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (VOID**)&LastLang, NULL);
1093 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL);
1094 ASSERT (PlatLang != NULL);
1095 if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {
1096 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
1097 FreePool (LastLang);
1098 FreePool (PlatLang);
1099 return Status;
1100 } else {
1101 Status = gRT->SetVariable (
1102 LAST_ENUM_LANGUAGE_VARIABLE_NAME,
1103 &gLastEnumLangGuid,
1104 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1105 AsciiStrSize (PlatLang),
1106 PlatLang
1107 );
1108 //
1109 // Failure to set the variable only impacts the performance next time enumerating the boot options.
1110 //
1111
1112 if (LastLang != NULL) {
1113 FreePool (LastLang);
1114 }
1115 FreePool (PlatLang);
1116 }
1117 }
1118
1119 //
1120 // Notes: this dirty code is to get the legacy boot option from the
1121 // BBS table and create to variable as the EFI boot option, it should
1122 // be removed after the CSM can provide legacy boot option directly
1123 //
1124 REFRESH_LEGACY_BOOT_OPTIONS;
1125
1126 //
1127 // Delete invalid boot option
1128 //
1129 BdsDeleteAllInvalidEfiBootOption ();
1130
1131 //
1132 // Parse removable media followed by fixed media.
1133 // The Removable[] array is used by the for-loop below to create removable media boot options
1134 // at first, and then to create fixed media boot options.
1135 //
1136 Removable[0] = FALSE;
1137 Removable[1] = TRUE;
1138
1139 gBS->LocateHandleBuffer (
1140 ByProtocol,
1141 &gEfiBlockIoProtocolGuid,
1142 NULL,
1143 &NumberBlockIoHandles,
1144 &BlockIoHandles
1145 );
1146
1147 for (RemovableIndex = 0; RemovableIndex < 2; RemovableIndex++) {
1148 for (Index = 0; Index < NumberBlockIoHandles; Index++) {
1149 Status = gBS->HandleProtocol (
1150 BlockIoHandles[Index],
1151 &gEfiBlockIoProtocolGuid,
1152 (VOID **) &BlkIo
1153 );
1154 //
1155 // skip the logical partition
1156 //
1157 if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) {
1158 continue;
1159 }
1160
1161 //
1162 // firstly fixed block io then the removable block io
1163 //
1164 if (BlkIo->Media->RemovableMedia == Removable[RemovableIndex]) {
1165 continue;
1166 }
1167 DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);
1168 DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);
1169
1170 switch (DevicePathType) {
1171 case BDS_EFI_ACPI_FLOPPY_BOOT:
1172 if (FloppyNumber != 0) {
1173 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);
1174 } else {
1175 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));
1176 }
1177 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
1178 FloppyNumber++;
1179 break;
1180
1181 //
1182 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
1183 //
1184 case BDS_EFI_MESSAGE_ATAPI_BOOT:
1185 case BDS_EFI_MESSAGE_SATA_BOOT:
1186 if (BlkIo->Media->RemovableMedia) {
1187 if (CdromNumber != 0) {
1188 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);
1189 } else {
1190 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));
1191 }
1192 CdromNumber++;
1193 } else {
1194 if (HarddriveNumber != 0) {
1195 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber);
1196 } else {
1197 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)));
1198 }
1199 HarddriveNumber++;
1200 }
1201 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));
1202 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
1203 break;
1204
1205 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
1206 if (UsbNumber != 0) {
1207 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);
1208 } else {
1209 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));
1210 }
1211 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
1212 UsbNumber++;
1213 break;
1214
1215 case BDS_EFI_MESSAGE_SCSI_BOOT:
1216 if (ScsiNumber != 0) {
1217 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);
1218 } else {
1219 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));
1220 }
1221 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
1222 ScsiNumber++;
1223 break;
1224
1225 case BDS_EFI_MESSAGE_MISC_BOOT:
1226 default:
1227 if (MiscNumber != 0) {
1228 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);
1229 } else {
1230 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));
1231 }
1232 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
1233 MiscNumber++;
1234 break;
1235 }
1236 }
1237 }
1238
1239 if (NumberBlockIoHandles != 0) {
1240 FreePool (BlockIoHandles);
1241 }
1242
1243 //
1244 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
1245 //
1246 NonBlockNumber = 0;
1247 gBS->LocateHandleBuffer (
1248 ByProtocol,
1249 &gEfiSimpleFileSystemProtocolGuid,
1250 NULL,
1251 &NumberFileSystemHandles,
1252 &FileSystemHandles
1253 );
1254 for (Index = 0; Index < NumberFileSystemHandles; Index++) {
1255 Status = gBS->HandleProtocol (
1256 FileSystemHandles[Index],
1257 &gEfiBlockIoProtocolGuid,
1258 (VOID **) &BlkIo
1259 );
1260 if (!EFI_ERROR (Status)) {
1261 //
1262 // Skip if the file system handle supports a BlkIo protocol,
1263 //
1264 continue;
1265 }
1266
1267 //
1268 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
1269 // machinename is ia32, ia64, x64, ...
1270 //
1271 Hdr.Union = &HdrData;
1272 NeedDelete = TRUE;
1273 Status = BdsLibGetImageHeader (
1274 FileSystemHandles[Index],
1275 EFI_REMOVABLE_MEDIA_FILE_NAME,
1276 &DosHeader,
1277 Hdr
1278 );
1279 if (!EFI_ERROR (Status) &&
1280 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
1281 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
1282 NeedDelete = FALSE;
1283 }
1284
1285 if (NeedDelete) {
1286 //
1287 // No such file or the file is not a EFI application, delete this boot option
1288 //
1289 BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
1290 } else {
1291 if (NonBlockNumber != 0) {
1292 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);
1293 } else {
1294 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));
1295 }
1296 BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);
1297 NonBlockNumber++;
1298 }
1299 }
1300
1301 if (NumberFileSystemHandles != 0) {
1302 FreePool (FileSystemHandles);
1303 }
1304
1305 //
1306 // Check if we have on flash shell
1307 //
1308 gBS->LocateHandleBuffer (
1309 ByProtocol,
1310 &gEfiFirmwareVolume2ProtocolGuid,
1311 NULL,
1312 &FvHandleCount,
1313 &FvHandleBuffer
1314 );
1315 for (Index = 0; Index < FvHandleCount; Index++) {
1316 gBS->HandleProtocol (
1317 FvHandleBuffer[Index],
1318 &gEfiFirmwareVolume2ProtocolGuid,
1319 (VOID **) &Fv
1320 );
1321
1322 Status = Fv->ReadFile (
1323 Fv,
1324 PcdGetPtr(PcdShellFile),
1325 NULL,
1326 &Size,
1327 &Type,
1328 &Attributes,
1329 &AuthenticationStatus
1330 );
1331 if (EFI_ERROR (Status)) {
1332 //
1333 // Skip if no shell file in the FV
1334 //
1335 continue;
1336 }
1337 //
1338 // Build the shell boot option
1339 //
1340 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1341 }
1342
1343 if (FvHandleCount != 0) {
1344 FreePool (FvHandleBuffer);
1345 }
1346
1347 //
1348 // Parse Network Boot Device
1349 //
1350 NumOfLoadFileHandles = 0;
1351 //
1352 // Search Load File protocol for PXE boot option.
1353 //
1354 gBS->LocateHandleBuffer (
1355 ByProtocol,
1356 &gEfiLoadFileProtocolGuid,
1357 NULL,
1358 &NumOfLoadFileHandles,
1359 &LoadFileHandles
1360 );
1361
1362 for (Index = 0; Index < NumOfLoadFileHandles; Index++) {
1363
1364 //
1365 //Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
1366 //
1367
1368 Status = gBS->HandleProtocol (
1369 LoadFileHandles[Index],
1370 &gEfiDevicePathProtocolGuid,
1371 (VOID **) &DevicePath
1372 );
1373
1374 ASSERT_EFI_ERROR (Status);
1375
1376 while (!IsDevicePathEnd (DevicePath)) {
1377 if ((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
1378 (DevicePath->SubType == MSG_IPv4_DP)) {
1379
1380 //
1381 //Get handle infomation
1382 //
1383 BufferSize = 0;
1384 NetworkHandles = NULL;
1385 Status = gBS->LocateHandle (
1386 ByProtocol,
1387 &gEfiSimpleNetworkProtocolGuid,
1388 NULL,
1389 &BufferSize,
1390 NetworkHandles
1391 );
1392
1393 if (Status == EFI_BUFFER_TOO_SMALL) {
1394 NetworkHandles = AllocateZeroPool(BufferSize);
1395 if (NetworkHandles == NULL) {
1396 return (EFI_OUT_OF_RESOURCES);
1397 }
1398 Status = gBS->LocateHandle(
1399 ByProtocol,
1400 &gEfiSimpleNetworkProtocolGuid,
1401 NULL,
1402 &BufferSize,
1403 NetworkHandles
1404 );
1405 }
1406
1407 //
1408 //Get the MAC string
1409 //
1410 Status = NetLibGetMacString (
1411 *NetworkHandles,
1412 NULL,
1413 &MacStr
1414 );
1415 if (EFI_ERROR (Status)) {
1416 return Status;
1417 }
1418 IPverStr = L" IPv4";
1419 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
1420 break;
1421 }
1422 if((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
1423 (DevicePath->SubType == MSG_IPv6_DP)) {
1424
1425 //
1426 //Get handle infomation
1427 //
1428 BufferSize = 0;
1429 NetworkHandles = NULL;
1430 Status = gBS->LocateHandle (
1431 ByProtocol,
1432 &gEfiSimpleNetworkProtocolGuid,
1433 NULL,
1434 &BufferSize,
1435 NetworkHandles
1436 );
1437
1438 if (Status == EFI_BUFFER_TOO_SMALL) {
1439 NetworkHandles = AllocateZeroPool(BufferSize);
1440 if (NetworkHandles == NULL) {
1441 return (EFI_OUT_OF_RESOURCES);
1442 }
1443 Status = gBS->LocateHandle(
1444 ByProtocol,
1445 &gEfiSimpleNetworkProtocolGuid,
1446 NULL,
1447 &BufferSize,
1448 NetworkHandles
1449 );
1450 }
1451
1452 //
1453 //Get the MAC string
1454 //
1455 Status = NetLibGetMacString (
1456 *NetworkHandles,
1457 NULL,
1458 &MacStr
1459 );
1460 if (EFI_ERROR (Status)) {
1461 return Status;
1462 }
1463 IPverStr = L" IPv6";
1464 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
1465 break;
1466 }
1467 DevicePath = NextDevicePathNode (DevicePath);
1468 }
1469
1470 BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);
1471 }
1472
1473 if (NumOfLoadFileHandles != 0) {
1474 FreePool (LoadFileHandles);
1475 }
1476
1477 //
1478 // Check if we have on flash shell
1479 //
1480 /* gBS->LocateHandleBuffer (
1481 ByProtocol,
1482 &gEfiFirmwareVolume2ProtocolGuid,
1483 NULL,
1484 &FvHandleCount,
1485 &FvHandleBuffer
1486 );
1487 for (Index = 0; Index < FvHandleCount; Index++) {
1488 gBS->HandleProtocol (
1489 FvHandleBuffer[Index],
1490 &gEfiFirmwareVolume2ProtocolGuid,
1491 (VOID **) &Fv
1492 );
1493
1494 Status = Fv->ReadFile (
1495 Fv,
1496 PcdGetPtr(PcdShellFile),
1497 NULL,
1498 &Size,
1499 &Type,
1500 &Attributes,
1501 &AuthenticationStatus
1502 );
1503 if (EFI_ERROR (Status)) {
1504 //
1505 // Skip if no shell file in the FV
1506 //
1507 continue;
1508 }
1509 //
1510 // Build the shell boot option
1511 //
1512 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1513 }
1514
1515 if (FvHandleCount != 0) {
1516 FreePool (FvHandleBuffer);
1517 } */
1518
1519 //
1520 // Make sure every boot only have one time
1521 // boot device enumerate
1522 //
1523 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
1524 mEnumBootDevice = TRUE;
1525
1526 return Status;
1527 }
1528
1529
1530
1531 /**
1532
1533 The function will excute with as the platform policy, current policy
1534 is driven by boot mode. IBV/OEM can customize this code for their specific
1535 policy action.
1536
1537 @param DriverOptionList - The header of the driver option link list
1538 @param BootOptionList - The header of the boot option link list
1539 @param ProcessCapsules - A pointer to ProcessCapsules()
1540 @param BaseMemoryTest - A pointer to BaseMemoryTest()
1541
1542 @retval None.
1543
1544 **/
1545 VOID
1546 EFIAPI
1547 PlatformBdsPolicyBehavior (
1548 IN OUT LIST_ENTRY *DriverOptionList,
1549 IN OUT LIST_ENTRY *BootOptionList,
1550 IN PROCESS_CAPSULES ProcessCapsules,
1551 IN BASEM_MEMORY_TEST BaseMemoryTest
1552 )
1553 {
1554 EFI_STATUS Status;
1555 UINT16 Timeout;
1556 EFI_BOOT_MODE BootMode;
1557 BOOLEAN DeferredImageExist;
1558 UINTN Index;
1559 CHAR16 CapsuleVarName[36];
1560 CHAR16 *TempVarName;
1561 SYSTEM_CONFIGURATION SystemConfiguration;
1562 UINTN VarSize;
1563 BOOLEAN SetVariableFlag;
1564 PLATFORM_PCI_DEVICE_PATH *EmmcBootDevPath;
1565 EFI_GLOBAL_NVS_AREA_PROTOCOL *GlobalNvsArea;
1566 EFI_HANDLE FvProtocolHandle;
1567 UINTN HandleCount;
1568 EFI_HANDLE *HandleBuffer;
1569 UINTN Index1;
1570 UINTN SataPciRegBase = 0;
1571 UINT16 SataModeSelect = 0;
1572 VOID *RegistrationExitPmAuth = NULL;
1573 EFI_EVENT Event;
1574 BOOLEAN IsFirstBoot;
1575 UINT16 *BootOrder;
1576 UINTN BootOrderSize;
1577
1578 Timeout = PcdGet16 (PcdPlatformBootTimeOut);
1579 VarSize = sizeof(SYSTEM_CONFIGURATION);
1580 Status = gRT->GetVariable(
1581 NORMAL_SETUP_NAME,
1582 &gEfiNormalSetupGuid,
1583 NULL,
1584 &VarSize,
1585 &SystemConfiguration
1586 );
1587 if (EFI_ERROR (Status)) {
1588 return;
1589 }
1590
1591 //
1592 // Load the driver option as the driver option list
1593 //
1594 PlatformBdsGetDriverOption (DriverOptionList);
1595
1596 //
1597 // Get current Boot Mode
1598 //
1599 BootMode = GetBootModeHob();
1600
1601 //
1602 // Clear all the capsule variables CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
1603 // as early as possible which will avoid the next time boot after the capsule update
1604 // will still into the capsule loop
1605 //
1606 StrCpy (CapsuleVarName, EFI_CAPSULE_VARIABLE_NAME);
1607 TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
1608 Index = 0;
1609 SetVariableFlag = TRUE;
1610 while (SetVariableFlag) {
1611 if (Index > 0) {
1612 UnicodeValueToString (TempVarName, 0, Index, 0);
1613 }
1614 Status = gRT->SetVariable (
1615 CapsuleVarName,
1616 &gEfiCapsuleVendorGuid,
1617 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS |
1618 EFI_VARIABLE_BOOTSERVICE_ACCESS,
1619 0,
1620 (VOID *)NULL
1621 );
1622 if (EFI_ERROR (Status)) {
1623 //
1624 // There is no capsule variables, quit
1625 //
1626 SetVariableFlag = FALSE;
1627 continue;
1628 }
1629 Index++;
1630 }
1631
1632 //
1633 // No deferred images exist by default
1634 //
1635 DeferredImageExist = FALSE;
1636 if ((BootMode != BOOT_WITH_MINIMAL_CONFIGURATION) && (PcdGet32(PcdFlashFvShellSize) > 0)){
1637 gDS->ProcessFirmwareVolume (
1638 (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),
1639 PcdGet32(PcdFlashFvShellSize),
1640 &FvProtocolHandle
1641 );
1642 }
1643
1644 if (SystemConfiguration.FastBoot == 1) {
1645 BootOrder = BdsLibGetVariableAndSize (
1646 L"BootOrder",
1647 &gEfiGlobalVariableGuid,
1648 &BootOrderSize
1649 );
1650 if ((BootOrder != NULL) && (BootMode != BOOT_ON_FLASH_UPDATE)) {
1651 //
1652 // BootOrder exist, it means system has boot before. We can do fast boot.
1653 //
1654 BootMode = BOOT_WITH_MINIMAL_CONFIGURATION;
1655 }
1656 }
1657
1658
1659 //
1660 // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,
1661 // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.
1662 //
1663 SataPciRegBase = MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, 0, 0);
1664 SataModeSelect = MmioRead16 (SataPciRegBase + R_PCH_SATA_MAP) & B_PCH_SATA_MAP_SMS_MASK;
1665 Status = EFI_SUCCESS;
1666 if (SataModeSelect != V_PCH_SATA_MAP_SMS_IDE) {
1667 Status = gBS->CreateEvent (
1668 EVT_NOTIFY_SIGNAL,
1669 TPL_CALLBACK,
1670 DisableAhciCtlr,
1671 &SataPciRegBase,
1672 &Event
1673 );
1674 if (!EFI_ERROR (Status)) {
1675 Status = gBS->RegisterProtocolNotify (
1676 &gExitPmAuthProtocolGuid,
1677 Event,
1678 &RegistrationExitPmAuth
1679 );
1680 }
1681 }
1682
1683 switch (BootMode) {
1684
1685 case BOOT_WITH_MINIMAL_CONFIGURATION:
1686 PlatformBdsInitHotKeyEvent ();
1687 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole);
1688
1689
1690 //
1691 // Check to see if it's needed to dispatch more DXE drivers.
1692 //
1693 for (Index = 0; Index < sizeof(ConnectDriverTable)/sizeof(EFI_GUID *); Index++) {
1694 Status = gBS->LocateHandleBuffer (
1695 ByProtocol,
1696 ConnectDriverTable[Index],
1697 NULL,
1698 &HandleCount,
1699 &HandleBuffer
1700 );
1701 if (!EFI_ERROR (Status)) {
1702 for (Index1 = 0; Index1 < HandleCount; Index1++) {
1703 gBS->ConnectController (
1704 HandleBuffer[Index1],
1705 NULL,
1706 NULL,
1707 TRUE
1708 );
1709 }
1710 }
1711
1712 if (HandleBuffer != NULL) {
1713 FreePool (HandleBuffer);
1714 }
1715
1716 gDS->Dispatch ();
1717 }
1718
1719 //
1720 // Locate the Global NVS Protocol.
1721 //
1722 Status = gBS->LocateProtocol (
1723 &gEfiGlobalNvsAreaProtocolGuid,
1724 NULL,
1725 (void **)&GlobalNvsArea
1726 );
1727 if (GlobalNvsArea->Area->emmcVersion == 0){
1728 EmmcBootDevPath = (PLATFORM_PCI_DEVICE_PATH *)gPlatformSimpleBootOption[0];
1729 EmmcBootDevPath->PciDevice.Device = 0x10;
1730 }
1731
1732 //
1733 // Connect boot device here to give time to read keyboard.
1734 //
1735 BdsLibConnectDevicePath (gPlatformSimpleBootOption[0]);
1736
1737 //
1738 // This is a workround for dectecting hotkey from USB keyboard.
1739 //
1740 gBS->Stall(KEYBOARD_TIMER_INTERVAL);
1741
1742 if (mHotKeyTimerEvent != NULL) {
1743 gBS->SetTimer (
1744 mHotKeyTimerEvent,
1745 TimerCancel,
1746 0
1747 );
1748 gBS->CloseEvent (mHotKeyTimerEvent);
1749 mHotKeyTimerEvent = NULL;
1750 }
1751 if (mHotKeyPressed) {
1752 //
1753 // Skip show progress count down
1754 //
1755 Timeout = 0xFFFF;
1756 goto FULL_CONFIGURATION;
1757 }
1758
1759 if (SystemConfiguration.QuietBoot) {
1760 EnableQuietBoot (PcdGetPtr(PcdLogoFile));
1761 } else {
1762 PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);
1763 }
1764
1765
1766 #ifdef TPM_ENABLED
1767 TcgPhysicalPresenceLibProcessRequest();
1768 #endif
1769
1770 //
1771 // Close boot script and install ready to lock
1772 //
1773 InstallReadyToLock ();
1774
1775 //
1776 // Give one chance to enter the setup if we
1777 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
1778 //
1779 BootIntoFirmwareInterface();
1780 break;
1781
1782 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
1783
1784 //
1785 // In no-configuration boot mode, we can connect the
1786 // console directly.
1787 //
1788 BdsLibConnectAllDefaultConsoles ();
1789 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
1790
1791 //
1792 // Perform some platform specific connect sequence
1793 //
1794 PlatformBdsConnectSequence ();
1795
1796 //
1797 // As console is ready, perform user identification again.
1798 //
1799 if (mCurrentUser == NULL) {
1800 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
1801 if (DeferredImageExist) {
1802 //
1803 // After user authentication, the deferred drivers was loaded again.
1804 // Here, need to ensure the deferred images are connected.
1805 //
1806 BdsLibConnectAllDefaultConsoles ();
1807 PlatformBdsConnectSequence ();
1808 }
1809 }
1810
1811 //
1812 // Close boot script and install ready to lock
1813 //
1814 InstallReadyToLock ();
1815
1816 //
1817 // Notes: current time out = 0 can not enter the
1818 // front page
1819 //
1820 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);
1821
1822 //
1823 // Check the boot option with the boot option list
1824 //
1825 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
1826 break;
1827
1828 case BOOT_ON_FLASH_UPDATE:
1829
1830 //
1831 // Boot with the specific configuration
1832 //
1833 PlatformBdsConnectConsole (gPlatformConsole);
1834 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
1835 BdsLibConnectAll ();
1836
1837 //
1838 // Perform user identification
1839 //
1840 if (mCurrentUser == NULL) {
1841 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
1842 if (DeferredImageExist) {
1843 //
1844 // After user authentication, the deferred drivers was loaded again.
1845 // Here, need to ensure the deferred images are connected.
1846 //
1847 BdsLibConnectAll ();
1848 }
1849 }
1850
1851 //
1852 // Close boot script and install ready to lock
1853 //
1854 InstallReadyToLock ();
1855
1856 ProcessCapsules (BOOT_ON_FLASH_UPDATE);
1857 break;
1858
1859 case BOOT_IN_RECOVERY_MODE:
1860
1861 //
1862 // In recovery mode, just connect platform console
1863 // and show up the front page
1864 //
1865 PlatformBdsConnectConsole (gPlatformConsole);
1866 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
1867 BdsLibConnectAll ();
1868
1869 //
1870 // Perform user identification
1871 //
1872 if (mCurrentUser == NULL) {
1873 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
1874 if (DeferredImageExist) {
1875 //
1876 // After user authentication, the deferred drivers was loaded again.
1877 // Here, need to ensure the deferred drivers are connected.
1878 //
1879 BdsLibConnectAll ();
1880 }
1881 }
1882
1883 //
1884 // Close boot script and install ready to lock
1885 //
1886 InstallReadyToLock ();
1887
1888 //
1889 // In recovery boot mode, we still enter to the
1890 // frong page now
1891 //
1892 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);
1893 break;
1894
1895 FULL_CONFIGURATION:
1896 case BOOT_WITH_FULL_CONFIGURATION:
1897 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
1898 case BOOT_WITH_DEFAULT_SETTINGS:
1899 default:
1900
1901 //
1902 // Connect platform console
1903 //
1904 Status = PlatformBdsConnectConsole (gPlatformConsole);
1905 if (EFI_ERROR (Status)) {
1906
1907 //
1908 // Here OEM/IBV can customize with defined action
1909 //
1910 PlatformBdsNoConsoleAction ();
1911 }
1912
1913 //
1914 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
1915 // Need to root cause this issue.
1916 //
1917 DEBUG ((DEBUG_ERROR, "Start to reconnect all driver.\n"));
1918 BdsLibDisconnectAllEfi();
1919 BdsLibConnectAll ();
1920 DEBUG ((DEBUG_ERROR, "End to reconnect all driver.\n"));
1921
1922 //
1923 // Perform some platform specific connect sequence
1924 //
1925 PlatformBdsConnectSequence ();
1926 if (SystemConfiguration.QuietBoot) {
1927 EnableQuietBoot (PcdGetPtr(PcdLogoFile));
1928 } else {
1929 PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);
1930 }
1931
1932 //
1933 // Do a pre-delay so Hard Disk can spin up and see more logo.
1934 //
1935 gBS->Stall(SystemConfiguration.HddPredelay * 1000000);
1936
1937 //
1938 // Perform user identification
1939 //
1940 if (mCurrentUser == NULL) {
1941 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
1942 if (DeferredImageExist) {
1943 //
1944 // After user authentication, the deferred drivers was loaded again.
1945 // Here, need to ensure the deferred drivers are connected.
1946 //
1947 Status = PlatformBdsConnectConsole (gPlatformConsole);
1948 if (EFI_ERROR (Status)) {
1949 PlatformBdsNoConsoleAction ();
1950 }
1951 PlatformBdsConnectSequence ();
1952 }
1953 }
1954 #ifdef TPM_ENABLED
1955 TcgPhysicalPresenceLibProcessRequest();
1956 #endif
1957
1958 //
1959 // Close boot script and install ready to lock
1960 //
1961 InstallReadyToLock ();
1962
1963 //
1964 // Here we have enough time to do the enumeration of boot device
1965 //
1966 PlatformBdsLibEnumerateAllBootOption (BootOptionList);
1967
1968 //
1969 // Give one chance to enter the setup if we
1970 // have the time out
1971 //
1972 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);
1973
1974 //
1975 // Give one chance to enter the setup if we
1976 // select Gummiboot "Reboot Into Firmware Interface"
1977 //
1978 BootIntoFirmwareInterface();
1979
1980 //
1981 // In default boot mode, always find all boot
1982 // option and do enumerate all the default boot option
1983 //
1984 if (Timeout == 0) {
1985 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
1986 if (IsListEmpty(BootOptionList)) {
1987 PlatformBdsPredictBootOption (BootOptionList);
1988 }
1989
1990 return;
1991 }
1992
1993
1994 break;
1995 }
1996
1997
1998 IsFirstBoot = PcdGetBool(PcdBootState);
1999 if (IsFirstBoot) {
2000 PcdSetBool(PcdBootState, FALSE);
2001 }
2002 return;
2003
2004 }
2005
2006 /**
2007 Hook point after a boot attempt succeeds. We don't expect a boot option to
2008 return, so the UEFI 2.0 specification defines that you will default to an
2009 interactive mode and stop processing the BootOrder list in this case. This
2010 is alos a platform implementation and can be customized by IBV/OEM.
2011
2012 @param Option Pointer to Boot Option that succeeded to boot.
2013
2014 @retval None.
2015
2016 **/
2017 VOID
2018 EFIAPI
2019 PlatformBdsBootSuccess (
2020 IN BDS_COMMON_OPTION *Option
2021 )
2022 {
2023 CHAR16 *TmpStr;
2024
2025 //
2026 // If Boot returned with EFI_SUCCESS and there is not in the boot device
2027 // select loop then we need to pop up a UI and wait for user input.
2028 //
2029 TmpStr = Option->StatusString;
2030 if (TmpStr != NULL) {
2031 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
2032 FreePool(TmpStr);
2033 }
2034 }
2035
2036 /**
2037 Hook point after a boot attempt fails.
2038
2039 @param Option - Pointer to Boot Option that failed to boot.
2040 @param Status - Status returned from failed boot.
2041 @param ExitData - Exit data returned from failed boot.
2042 @param ExitDataSize - Exit data size returned from failed boot.
2043
2044 @retval None.
2045
2046 **/
2047 VOID
2048 EFIAPI
2049 PlatformBdsBootFail (
2050 IN BDS_COMMON_OPTION *Option,
2051 IN EFI_STATUS Status,
2052 IN CHAR16 *ExitData,
2053 IN UINTN ExitDataSize
2054 )
2055 {
2056 CHAR16 *TmpStr;
2057 EFI_HANDLE FvProtocolHandle;
2058
2059 //
2060 // If Boot returned with failed status then we need to pop up a UI and wait
2061 // for user input.
2062 //
2063 TmpStr = Option->StatusString;
2064 if (TmpStr != NULL) {
2065 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
2066 FreePool(TmpStr);
2067 }
2068 if (PcdGet32(PcdFlashFvShellSize) > 0){
2069 gDS->ProcessFirmwareVolume (
2070 (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),
2071 PcdGet32(PcdFlashFvShellSize),
2072 &FvProtocolHandle
2073 );
2074 }
2075 PlatformBdsConnectSequence ();
2076 }
2077
2078 /**
2079 This function is remained for IBV/OEM to do some platform action,
2080 if there no console device can be connected.
2081
2082 @param None.
2083
2084 @retval EFI_SUCCESS Direct return success now.
2085
2086 **/
2087 EFI_STATUS
2088 PlatformBdsNoConsoleAction (
2089 VOID
2090 )
2091 {
2092 return EFI_SUCCESS;
2093 }
2094
2095 /**
2096 This function locks the block
2097
2098 @param Base The base address flash region to be locked.
2099
2100 **/
2101 VOID
2102 BdsLockFv (
2103 IN EFI_PHYSICAL_ADDRESS Base
2104 )
2105 {
2106 EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
2107 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
2108 EFI_PHYSICAL_ADDRESS BaseAddress;
2109 UINT8 Data;
2110 UINT32 BlockLength;
2111 UINTN Index;
2112
2113 BaseAddress = Base - 0x400000 + 2;
2114 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (Base));
2115 BlockMap = &(FvHeader->BlockMap[0]);
2116
2117 while ((BlockMap->NumBlocks != 0) && (BlockMap->Length != 0)) {
2118 BlockLength = BlockMap->Length;
2119 for (Index = 0; Index < BlockMap->NumBlocks; Index++) {
2120 Data = MmioOr8 ((UINTN) BaseAddress, 0x03);
2121 BaseAddress += BlockLength;
2122 }
2123 BlockMap++;
2124 }
2125 }
2126
2127 VOID
2128 EFIAPI
2129 PlatformBdsLockNonUpdatableFlash (
2130 VOID
2131 )
2132 {
2133 EFI_PHYSICAL_ADDRESS Base;
2134
2135 Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvMainBase);
2136 if (Base > 0) {
2137 BdsLockFv (Base);
2138 }
2139
2140 Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvRecoveryBase);
2141 if (Base > 0) {
2142 BdsLockFv (Base);
2143 }
2144 }
2145
2146 /**
2147 Lock the ConsoleIn device in system table. All key
2148 presses will be ignored until the Password is typed in. The only way to
2149 disable the password is to type it in to a ConIn device.
2150
2151 @param Password Password used to lock ConIn device.
2152
2153 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
2154 @retval EFI_UNSUPPORTED Password not found
2155
2156 **/
2157 EFI_STATUS
2158 EFIAPI
2159 LockKeyboards (
2160 IN CHAR16 *Password
2161 )
2162 {
2163 return EFI_UNSUPPORTED;
2164 }
2165
2166 /**
2167 Connect the predefined platform default authentication devices.
2168
2169 This function connects the predefined device path for authentication device,
2170 and if the predefined device path has child device path, the child handle will
2171 be connected too. But the child handle of the child will not be connected.
2172
2173 **/
2174 VOID
2175 EFIAPI
2176 PlatformBdsConnectAuthDevice (
2177 VOID
2178 )
2179 {
2180 EFI_STATUS Status;
2181 UINTN Index;
2182 UINTN HandleIndex;
2183 UINTN HandleCount;
2184 EFI_HANDLE *HandleBuffer;
2185 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;
2186 EFI_USER_MANAGER_PROTOCOL *Manager;
2187
2188 Status = gBS->LocateProtocol (
2189 &gEfiUserManagerProtocolGuid,
2190 NULL,
2191 (VOID **) &Manager
2192 );
2193 if (EFI_ERROR (Status)) {
2194 //
2195 // As user manager protocol is not installed, the authentication devices
2196 // should not be connected.
2197 //
2198 return ;
2199 }
2200
2201 Index = 0;
2202 while (gUserAuthenticationDevice[Index] != NULL) {
2203 //
2204 // Connect the platform customized device paths
2205 //
2206 BdsLibConnectDevicePath (gUserAuthenticationDevice[Index]);
2207 Index++;
2208 }
2209
2210 //
2211 // Find and connect the child device paths of the platform customized device paths
2212 //
2213 HandleBuffer = NULL;
2214 for (Index = 0; gUserAuthenticationDevice[Index] != NULL; Index++) {
2215 HandleCount = 0;
2216 Status = gBS->LocateHandleBuffer (
2217 AllHandles,
2218 NULL,
2219 NULL,
2220 &HandleCount,
2221 &HandleBuffer
2222 );
2223 ASSERT (!EFI_ERROR (Status));
2224
2225 //
2226 // Find and connect the child device paths of gUserIdentificationDevice[Index]
2227 //
2228 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
2229 ChildDevicePath = NULL;
2230 Status = gBS->HandleProtocol (
2231 HandleBuffer[HandleIndex],
2232 &gEfiDevicePathProtocolGuid,
2233 (VOID **) &ChildDevicePath
2234 );
2235 if (EFI_ERROR (Status) || ChildDevicePath == NULL) {
2236 continue;
2237 }
2238
2239 if (CompareMem (
2240 ChildDevicePath,
2241 gUserAuthenticationDevice[Index],
2242 (GetDevicePathSize (gUserAuthenticationDevice[Index]) - sizeof (EFI_DEVICE_PATH_PROTOCOL))
2243 ) != 0) {
2244 continue;
2245 }
2246 gBS->ConnectController (
2247 HandleBuffer[HandleIndex],
2248 NULL,
2249 NULL,
2250 TRUE
2251 );
2252 }
2253 }
2254
2255 if (HandleBuffer != NULL) {
2256 FreePool (HandleBuffer);
2257 }
2258 }
2259
2260 /**
2261 This function is to identify a user, and return whether deferred images exist.
2262
2263 @param[out] User Point to user profile handle.
2264 @param[out] DeferredImageExist On return, points to TRUE if the deferred image
2265 exist or FALSE if it did not exist.
2266
2267 **/
2268 VOID
2269 EFIAPI
2270 PlatformBdsUserIdentify (
2271 OUT EFI_USER_PROFILE_HANDLE *User,
2272 OUT BOOLEAN *DeferredImageExist
2273 )
2274 {
2275 EFI_STATUS Status;
2276 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage;
2277 UINTN HandleCount;
2278 EFI_HANDLE *HandleBuf;
2279 UINTN Index;
2280 UINTN DriverIndex;
2281 EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;
2282 VOID *DriverImage;
2283 UINTN ImageSize;
2284 BOOLEAN BootOption;
2285
2286 //
2287 // Perform user identification
2288 //
2289 do {
2290 Status = BdsLibUserIdentify (User);
2291 } while (EFI_ERROR (Status));
2292
2293 //
2294 // After user authentication now, try to find whether deferred image exists
2295 //
2296 HandleCount = 0;
2297 HandleBuf = NULL;
2298 *DeferredImageExist = FALSE;
2299 Status = gBS->LocateHandleBuffer (
2300 ByProtocol,
2301 &gEfiDeferredImageLoadProtocolGuid,
2302 NULL,
2303 &HandleCount,
2304 &HandleBuf
2305 );
2306 if (EFI_ERROR (Status)) {
2307 return ;
2308 }
2309
2310 for (Index = 0; Index < HandleCount; Index++) {
2311 Status = gBS->HandleProtocol (
2312 HandleBuf[Index],
2313 &gEfiDeferredImageLoadProtocolGuid,
2314 (VOID **) &DeferredImage
2315 );
2316 if (!EFI_ERROR (Status)) {
2317 //
2318 // Find whether deferred image exists in this instance.
2319 //
2320 DriverIndex = 0;
2321 Status = DeferredImage->GetImageInfo(
2322 DeferredImage,
2323 DriverIndex,
2324 &ImageDevicePath,
2325 (VOID **) &DriverImage,
2326 &ImageSize,
2327 &BootOption
2328 );
2329 if (!EFI_ERROR (Status)) {
2330 //
2331 // The deferred image is found.
2332 //
2333 FreePool (HandleBuf);
2334 *DeferredImageExist = TRUE;
2335 return ;
2336 }
2337 }
2338 }
2339
2340 FreePool (HandleBuf);
2341 }
2342
2343 UINTN gHotKey = 0;
2344
2345
2346 EFI_STATUS
2347 ShowProgressHotKey (
2348 IN UINT16 TimeoutDefault
2349 )
2350 {
2351 CHAR16 *TmpStr;
2352 UINT16 TimeoutRemain;
2353 EFI_STATUS Status;
2354 EFI_INPUT_KEY Key;
2355 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
2356 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
2357 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;
2358 UINT32 GpioValue;
2359
2360 if (TimeoutDefault == 0) {
2361 return EFI_TIMEOUT;
2362 }
2363
2364 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
2365
2366 if (DebugAssertEnabled())
2367 {
2368 DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it, or press <F2> or <DEL> to enter setup page! ...Zzz....\n"));
2369 }
2370 else
2371 {
2372 #ifdef __GNUC__
2373 SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
2374 #else
2375 SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
2376 #endif
2377 }
2378 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
2379 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
2380 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
2381
2382 //
2383 // Clear the progress status bar first
2384 //
2385 TmpStr = L"Start boot option, Press <F2> or <DEL> to enter setup page.";
2386 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);
2387
2388 TimeoutRemain = TimeoutDefault;
2389 while (TimeoutRemain != 0) {
2390 if (DebugAssertEnabled())
2391 {
2392 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));
2393 }
2394 else
2395 {
2396 SerialPortWrite ((UINT8 *)".", 1);
2397 }
2398 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);
2399 if (Status != EFI_TIMEOUT) {
2400 break;
2401 }
2402 TimeoutRemain--;
2403
2404 //
2405 // Show progress
2406 //
2407 if (TmpStr != NULL) {
2408 PlatformBdsShowProgress (
2409 Foreground,
2410 Background,
2411 TmpStr,
2412 Color,
2413 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),
2414 0
2415 );
2416 }
2417 }
2418
2419 //
2420 // Timeout expired
2421 //
2422 if (TimeoutRemain == 0) {
2423 if (DebugAssertEnabled())
2424 {
2425 }
2426 else
2427 {
2428 SerialPortWrite ((UINT8 *)"\r\n", 2);
2429 }
2430 return EFI_TIMEOUT;
2431 }
2432
2433 //
2434 // User pressed some key
2435 //
2436 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2437 if (EFI_ERROR (Status)) {
2438 return Status;
2439 }
2440
2441 //
2442 // Check Volume Up Key to enter Setup
2443 //
2444 GpioValue = MmioRead32 (IO_BASE_ADDRESS + 0x0668); // The value of GPIOC_5
2445 if (((GpioValue & BIT0) == 0) && (Key.ScanCode == SCAN_UP)) {
2446 gHotKey = 0;
2447 return EFI_SUCCESS;
2448 }
2449
2450 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
2451 //
2452 // User pressed enter, equivalent to select "continue"
2453 //
2454 return EFI_TIMEOUT;
2455 }
2456
2457 //
2458 //F2 -- Front Page
2459 //F5 -- Device Manager
2460 //F7 -- Boot Manager
2461 // do not use F8. generally people assume it is windows safe mode key.
2462 //F9 -- Boot order
2463 //
2464 DEBUG ((EFI_D_INFO, "[Key Pressed]: ScanCode 0x%x\n", Key.ScanCode));
2465 switch(Key.ScanCode) {
2466 case SCAN_F2:
2467 gHotKey = 0;
2468 break;
2469
2470 case SCAN_DELETE:
2471 gHotKey = 0;
2472 break;
2473
2474 case SCAN_F5:
2475 gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
2476 break;
2477
2478 case SCAN_F7:
2479 gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;
2480 break;
2481
2482 case SCAN_F9:
2483 gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;
2484 break;
2485
2486 default:
2487 //set gHotKey to continue so that flow will not go into CallFrontPage
2488 gHotKey = FRONT_PAGE_KEY_CONTINUE;
2489 return EFI_TIMEOUT;
2490 break;
2491 }
2492
2493 return EFI_SUCCESS;
2494 }
2495
2496
2497
2498 /**
2499 This function is the main entry of the platform setup entry.
2500 The function will present the main menu of the system setup,
2501 this is the platform reference part and can be customize.
2502
2503
2504 @param TimeoutDefault The fault time out value before the system
2505 continue to boot.
2506 @param ConnectAllHappened The indicater to check if the connect all have
2507 already happened.
2508
2509 **/
2510 VOID
2511 PlatformBdsEnterFrontPageWithHotKey (
2512 IN UINT16 TimeoutDefault,
2513 IN BOOLEAN ConnectAllHappened
2514 )
2515 {
2516 EFI_STATUS Status;
2517
2518 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
2519 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
2520 UINTN BootTextColumn;
2521 UINTN BootTextRow;
2522
2523 GraphicsOutput = NULL;
2524 SimpleTextOut = NULL;
2525
2526 PERF_START (NULL, "BdsTimeOut", "BDS", 0);
2527
2528 //
2529 // Indicate if we need connect all in the platform setup
2530 //
2531 if (ConnectAllHappened) {
2532 gConnectAllHappened = TRUE;
2533 }
2534
2535 if (!mModeInitialized) {
2536 //
2537 // After the console is ready, get current video resolution
2538 // and text mode before launching setup at first time.
2539 //
2540 Status = gBS->HandleProtocol (
2541 gST->ConsoleOutHandle,
2542 &gEfiGraphicsOutputProtocolGuid,
2543 (VOID**)&GraphicsOutput
2544 );
2545 if (EFI_ERROR (Status)) {
2546 GraphicsOutput = NULL;
2547 }
2548
2549 Status = gBS->HandleProtocol (
2550 gST->ConsoleOutHandle,
2551 &gEfiSimpleTextOutProtocolGuid,
2552 (VOID**)&SimpleTextOut
2553 );
2554 if (EFI_ERROR (Status)) {
2555 SimpleTextOut = NULL;
2556 }
2557
2558 if (GraphicsOutput != NULL) {
2559 //
2560 // Get current video resolution and text mode.
2561 //
2562 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
2563 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
2564 }
2565
2566 if (SimpleTextOut != NULL) {
2567 Status = SimpleTextOut->QueryMode (
2568 SimpleTextOut,
2569 SimpleTextOut->Mode->Mode,
2570 &BootTextColumn,
2571 &BootTextRow
2572 );
2573 mBootTextModeColumn = (UINT32)BootTextColumn;
2574 mBootTextModeRow = (UINT32)BootTextRow;
2575 }
2576
2577 //
2578 // Get user defined text mode for setup.
2579 //
2580 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
2581 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
2582 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);
2583 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);
2584
2585 mModeInitialized = TRUE;
2586 }
2587
2588 if (TimeoutDefault != 0xffff) {
2589 Status = ShowProgressHotKey (TimeoutDefault);
2590
2591 //
2592 // Ensure screen is clear when switch Console from Graphics mode to Text mode
2593 //
2594 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
2595 gST->ConOut->ClearScreen (gST->ConOut);
2596
2597 if (EFI_ERROR (Status)) {
2598 //
2599 // Timeout or user press enter to continue
2600 //
2601 goto Exit;
2602 }
2603 }
2604 //
2605 // Install BM HiiPackages.
2606 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
2607 //
2608 InitBMPackage ();
2609 do {
2610
2611 BdsSetConsoleMode (TRUE);
2612
2613 InitializeFrontPage (FALSE);
2614
2615 //
2616 // Update Front Page strings
2617 //
2618 UpdateFrontPageStrings ();
2619
2620 Status = EFI_SUCCESS;
2621 gCallbackKey = 0;
2622 if (gHotKey == 0) {
2623 Status = CallFrontPage ();
2624 } else {
2625 gCallbackKey = gHotKey;
2626 gHotKey = 0;
2627 }
2628
2629 //
2630 // If gCallbackKey is greater than 1 and less or equal to 5,
2631 // it will launch configuration utilities.
2632 // 2 = set language
2633 // 3 = boot manager
2634 // 4 = device manager
2635 // 5 = boot maintenance manager
2636 //
2637 if (gCallbackKey != 0) {
2638 REPORT_STATUS_CODE (
2639 EFI_PROGRESS_CODE,
2640 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
2641 );
2642 }
2643
2644 //
2645 // Based on the key that was set, we can determine what to do
2646 //
2647 switch (gCallbackKey) {
2648 //
2649 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
2650 // describe to their customers in documentation how to find their setup information (namely
2651 // under the device manager and specific buckets)
2652 //
2653 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
2654 //
2655 case FRONT_PAGE_KEY_CONTINUE:
2656
2657 //
2658 // User hit continue
2659 //
2660 break;
2661
2662 case FRONT_PAGE_KEY_LANGUAGE:
2663
2664 //
2665 // User made a language setting change - display front page again
2666 //
2667 break;
2668
2669 case FRONT_PAGE_KEY_BOOT_MANAGER:
2670 //
2671 // Remove the installed BootMaint HiiPackages when exit.
2672 //
2673 FreeBMPackage ();
2674
2675 //
2676 // User chose to run the Boot Manager
2677 //
2678 CallBootManager ();
2679
2680 //
2681 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
2682 //
2683 InitBMPackage ();
2684 break;
2685
2686 case FRONT_PAGE_KEY_DEVICE_MANAGER:
2687
2688 //
2689 // Display the Device Manager
2690 //
2691 do {
2692 CallDeviceManager ();
2693 } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);
2694 break;
2695
2696 case FRONT_PAGE_KEY_BOOT_MAINTAIN:
2697
2698 //
2699 // Display the Boot Maintenance Manager
2700 //
2701 BdsStartBootMaint ();
2702 break;
2703 }
2704
2705 } while (((UINTN)gCallbackKey) != FRONT_PAGE_KEY_CONTINUE);
2706
2707 //
2708 //Will leave browser, check any reset required change is applied? if yes, reset system
2709 //
2710 SetupResetReminder ();
2711 //
2712 // Remove the installed BootMaint HiiPackages when exit.
2713 //
2714 FreeBMPackage ();
2715
2716 Exit:
2717 //
2718 // Automatically load current entry
2719 // Note: The following lines of code only execute when Auto boot
2720 // takes affect
2721 //
2722 PERF_END (NULL, "BdsTimeOut", "BDS", 0);
2723 }
2724
2725
2726 VOID
2727 BootIntoFirmwareInterface(
2728 VOID
2729 )
2730 {
2731 EFI_STATUS Status;
2732 UINTN DataSize;
2733 UINT16 Timeout;
2734 UINT64 OsIndication;
2735
2736
2737 OsIndication = 0;
2738 DataSize = sizeof(UINT64);
2739 Status = gRT->GetVariable (
2740 L"OsIndications",
2741 &gEfiGlobalVariableGuid,
2742 NULL,
2743 &DataSize,
2744 &OsIndication
2745 );
2746
2747 DEBUG ((EFI_D_INFO, "OSIndication Variable Value %d\n", OsIndication));
2748 //
2749 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
2750 //
2751 if (!EFI_ERROR(Status) && (OsIndication != 0)) {
2752 Timeout = 0xffff;
2753 PlatformBdsEnterFrontPage (Timeout, FALSE);
2754 }
2755 }
2756
2757
2758 EFI_STATUS
2759 PlatformBdsConnectSimpleConsole (
2760 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
2761 )
2762 {
2763 EFI_STATUS Status;
2764 UINTN Index;
2765 EFI_DEVICE_PATH_PROTOCOL *VarConout;
2766 EFI_DEVICE_PATH_PROTOCOL *VarConin;
2767 UINTN DevicePathSize;
2768
2769
2770 Index = 0;
2771 Status = EFI_SUCCESS;
2772 DevicePathSize = 0;
2773 VarConout = BdsLibGetVariableAndSize (
2774 L"ConOut",
2775 &gEfiGlobalVariableGuid,
2776 &DevicePathSize
2777 );
2778 VarConin = BdsLibGetVariableAndSize (
2779 L"ConIn",
2780 &gEfiGlobalVariableGuid,
2781 &DevicePathSize
2782 );
2783 if (VarConout == NULL || VarConin == NULL) {
2784 //
2785 // Have chance to connect the platform default console,
2786 // the platform default console is the minimue device group
2787 // the platform should support
2788 //
2789 while (PlatformConsole[Index].DevicePath != NULL) {
2790
2791 //
2792 // Update the console variable with the connect type
2793 //
2794 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
2795 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
2796 }
2797
2798 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
2799 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
2800 }
2801
2802 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
2803 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
2804 }
2805
2806 Index ++;
2807 }
2808 }
2809
2810 //
2811 // Connect ConIn first to give keyboard time to parse hot key event.
2812 //
2813 Status = BdsLibConnectConsoleVariable (L"ConIn");
2814 if (EFI_ERROR (Status)) {
2815 return Status;
2816 }
2817
2818 //
2819 // Make sure we have at least one active VGA, and have the right
2820 // active VGA in console variable
2821 //
2822 Status = PlatformBdsForceActiveVga ();
2823
2824 //
2825 // It seems impossible not to have any ConOut device on platform,
2826 // so we check the status here.
2827 //
2828 Status = BdsLibConnectConsoleVariable (L"ConOut");
2829 if (EFI_ERROR (Status)) {
2830 return Status;
2831 }
2832
2833 return EFI_SUCCESS;
2834 }
2835
2836
2837 /**
2838 Timer handler to convert the key from USB.
2839
2840 @param Event Indicates the event that invoke this function.
2841 @param Context Indicates the calling context.
2842 **/
2843 VOID
2844 EFIAPI
2845 HotKeyTimerHandler (
2846 IN EFI_EVENT Event,
2847 IN VOID *Context
2848 )
2849 {
2850 EFI_STATUS Status;
2851 EFI_INPUT_KEY Key;
2852
2853 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2854 if (EFI_ERROR (Status)) {
2855 return;
2856 }
2857
2858 switch(Key.ScanCode) {
2859 case SCAN_F2:
2860 gHotKey = 0;
2861 mHotKeyPressed = TRUE;
2862 break;
2863
2864 case SCAN_F5:
2865 gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
2866 mHotKeyPressed = TRUE;
2867 break;
2868
2869 case SCAN_F7:
2870 gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;
2871 mHotKeyPressed = TRUE;
2872 break;
2873
2874 case SCAN_F9:
2875 gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;
2876 mHotKeyPressed = TRUE;
2877 break;
2878 }
2879
2880 if (mHotKeyPressed) {
2881 gBS->SetTimer (
2882 mHotKeyTimerEvent,
2883 TimerCancel,
2884 0
2885 );
2886 gBS->CloseEvent (mHotKeyTimerEvent);
2887 mHotKeyTimerEvent = NULL;
2888 }
2889
2890 return;
2891 }
2892
2893
2894 /**
2895 Callback function for SimpleTextInEx protocol install events
2896
2897 @param Event the event that is signaled.
2898 @param Context not used here.
2899
2900 **/
2901 VOID
2902 EFIAPI
2903 HitHotkeyEvent (
2904 IN EFI_EVENT Event,
2905 IN VOID *Context
2906 )
2907 {
2908 EFI_STATUS Status;
2909
2910 Status = gBS->CloseEvent(mHitHotkeyEvent);
2911 if (EFI_ERROR (Status)) {
2912 return;
2913 }
2914 Status = gBS->CreateEvent (
2915 EVT_TIMER | EVT_NOTIFY_SIGNAL,
2916 TPL_NOTIFY,
2917 HotKeyTimerHandler,
2918 NULL,
2919 &mHotKeyTimerEvent
2920 );
2921 if (EFI_ERROR (Status)) {
2922 return;
2923 }
2924 Status = gBS->SetTimer (
2925 mHotKeyTimerEvent,
2926 TimerPeriodic,
2927 KEYBOARD_TIMER_INTERVAL
2928 );
2929 if (EFI_ERROR (Status)) {
2930 return;
2931 }
2932
2933 return;
2934 }
2935
2936
2937 VOID
2938 EFIAPI
2939 PlatformBdsInitHotKeyEvent (
2940 VOID
2941 )
2942 {
2943 EFI_STATUS Status;
2944
2945 //
2946 // Register Protocol notify for Hotkey service
2947 //
2948 Status = gBS->CreateEvent (
2949 EVT_NOTIFY_SIGNAL,
2950 TPL_CALLBACK,
2951 HitHotkeyEvent,
2952 NULL,
2953 &mHitHotkeyEvent
2954 );
2955 ASSERT_EFI_ERROR (Status);
2956
2957 //
2958 // Register for protocol notifications on this event
2959 //
2960 Status = gBS->RegisterProtocolNotify (
2961 &gEfiSimpleTextInputExProtocolGuid,
2962 mHitHotkeyEvent,
2963 &mHitHotkeyRegistration
2964 );
2965 ASSERT_EFI_ERROR (Status);
2966 }