2 Platform BDS customizations.
4 Copyright (c) 2004 - 2009, Intel Corporation. <BR>
5 All rights reserved. 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
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.
15 #include "BdsPlatform.h"
22 VOID
*mEfiDevPathNotifyReg
;
23 EFI_EVENT mEfiDevPathEvent
;
24 VOID
*mEmuVariableEventReg
;
25 EFI_EVENT mEmuVariableEvent
;
26 BOOLEAN mDetectVgaOnly
;
35 (EFIAPI
*PROTOCOL_INSTANCE_CALLBACK
)(
42 @param[in] Handle - Handle of PCI device instance
43 @param[in] PciIo - PCI IO protocol instance
44 @param[in] Pci - PCI Header register block
48 (EFIAPI
*VISIT_PCI_INSTANCE_CALLBACK
)(
50 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
56 // Function prototypes
60 VisitAllInstancesOfProtocol (
62 IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction
,
67 VisitAllPciInstancesOfProtocol (
68 IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction
72 InstallDevicePathCallback (
84 PciRomLoadEfiDriversFromRomImage (
85 IN EFI_PHYSICAL_ADDRESS Rom
,
90 // BDS Platform Functions
101 Platform Bds init. Incude the platform firmware vendor, revision
112 DEBUG ((EFI_D_INFO
, "PlatformBdsInit\n"));
113 InstallDevicePathCallback ();
134 EFI_SUCCESS - Connect RootBridge successfully.
135 EFI_STATUS - Connect RootBridge fail.
140 EFI_HANDLE RootHandle
;
143 // Make all the PCI_IO protocols on PCI Seg 0 show up
145 BdsLibConnectDevicePath (gPlatformRootBridges
[0]);
147 Status
= gBS
->LocateDevicePath (
148 &gEfiDevicePathProtocolGuid
,
149 &gPlatformRootBridges
[0],
152 if (EFI_ERROR (Status
)) {
156 Status
= gBS
->ConnectController (RootHandle
, NULL
, NULL
, FALSE
);
157 if (EFI_ERROR (Status
)) {
166 PrepareLpcBridgeDevicePath (
167 IN EFI_HANDLE DeviceHandle
173 Add IsaKeyboard to ConIn,
174 add IsaSerial to ConOut, ConIn, ErrOut.
179 DeviceHandle - Handle of PCIIO protocol.
183 EFI_SUCCESS - LPC bridge is added to ConOut, ConIn, and ErrOut.
184 EFI_STATUS - No LPC bridge is added.
189 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
190 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
194 Status
= gBS
->HandleProtocol (
196 &gEfiDevicePathProtocolGuid
,
199 if (EFI_ERROR (Status
)) {
202 TempDevicePath
= DevicePath
;
207 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnpPs2KeyboardDeviceNode
);
209 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
214 DevicePath
= TempDevicePath
;
215 gPnp16550ComPortDeviceNode
.UID
= 0;
217 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnp16550ComPortDeviceNode
);
218 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gUartDeviceNode
);
219 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
224 DevPathStr
= DevicePathToStr(DevicePath
);
227 "BdsPlatform.c+%d: COM%d DevPath: %s\n",
229 gPnp16550ComPortDeviceNode
.UID
+ 1,
232 FreePool(DevPathStr
);
234 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
235 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
236 BdsLibUpdateConsoleVariable (VarErrorOut
, DevicePath
, NULL
);
241 DevicePath
= TempDevicePath
;
242 gPnp16550ComPortDeviceNode
.UID
= 1;
244 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnp16550ComPortDeviceNode
);
245 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gUartDeviceNode
);
246 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
251 DevPathStr
= DevicePathToStr(DevicePath
);
254 "BdsPlatform.c+%d: COM%d DevPath: %s\n",
256 gPnp16550ComPortDeviceNode
.UID
+ 1,
259 FreePool(DevPathStr
);
261 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
262 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
263 BdsLibUpdateConsoleVariable (VarErrorOut
, DevicePath
, NULL
);
270 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
271 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
276 EFI_HANDLE PciDeviceHandle
;
277 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
278 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
279 UINTN GopHandleCount
;
280 EFI_HANDLE
*GopHandleBuffer
;
282 if (PciDevicePath
== NULL
|| GopDevicePath
== NULL
) {
283 return EFI_INVALID_PARAMETER
;
287 // Initialize the GopDevicePath to be PciDevicePath
289 *GopDevicePath
= PciDevicePath
;
290 TempPciDevicePath
= PciDevicePath
;
292 Status
= gBS
->LocateDevicePath (
293 &gEfiDevicePathProtocolGuid
,
297 if (EFI_ERROR (Status
)) {
302 // Try to connect this handle, so that GOP dirver could start on this
303 // device and create child handles with GraphicsOutput Protocol installed
304 // on them, then we get device paths of these child handles and select
305 // them as possible console device.
307 gBS
->ConnectController (PciDeviceHandle
, NULL
, NULL
, FALSE
);
309 Status
= gBS
->LocateHandleBuffer (
311 &gEfiGraphicsOutputProtocolGuid
,
316 if (!EFI_ERROR (Status
)) {
318 // Add all the child handles as possible Console Device
320 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
321 Status
= gBS
->HandleProtocol (GopHandleBuffer
[Index
], &gEfiDevicePathProtocolGuid
, (VOID
*)&TempDevicePath
);
322 if (EFI_ERROR (Status
)) {
328 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
331 // In current implementation, we only enable one of the child handles
332 // as console device, i.e. sotre one of the child handle's device
333 // path to variable "ConOut"
334 // In futhure, we could select all child handles to be console device
337 *GopDevicePath
= TempDevicePath
;
340 // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()
341 // Add the integrity GOP device path.
343 BdsLibUpdateConsoleVariable (VarConsoleOutDev
, NULL
, PciDevicePath
);
344 BdsLibUpdateConsoleVariable (VarConsoleOutDev
, TempDevicePath
, NULL
);
347 gBS
->FreePool (GopHandleBuffer
);
354 PreparePciVgaDevicePath (
355 IN EFI_HANDLE DeviceHandle
361 Add PCI VGA to ConOut.
366 DeviceHandle - Handle of PCIIO protocol.
370 EFI_SUCCESS - PCI VGA is added to ConOut.
371 EFI_STATUS - No PCI VGA device is added.
376 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
377 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
380 Status
= gBS
->HandleProtocol (
382 &gEfiDevicePathProtocolGuid
,
385 if (EFI_ERROR (Status
)) {
389 GetGopDevicePath (DevicePath
, &GopDevicePath
);
390 DevicePath
= GopDevicePath
;
392 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
398 PreparePciSerialDevicePath (
399 IN EFI_HANDLE DeviceHandle
405 Add PCI Serial to ConOut, ConIn, ErrOut.
410 DeviceHandle - Handle of PCIIO protocol.
414 EFI_SUCCESS - PCI Serial is added to ConOut, ConIn, and ErrOut.
415 EFI_STATUS - No PCI Serial device is added.
420 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
423 Status
= gBS
->HandleProtocol (
425 &gEfiDevicePathProtocolGuid
,
428 if (EFI_ERROR (Status
)) {
432 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gUartDeviceNode
);
433 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
435 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
436 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
437 BdsLibUpdateConsoleVariable (VarErrorOut
, DevicePath
, NULL
);
443 VisitAllInstancesOfProtocol (
445 IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction
,
451 EFI_HANDLE
*HandleBuffer
;
456 // Start to check all the PciIo to find all possible device
460 Status
= gBS
->LocateHandleBuffer (
467 if (EFI_ERROR (Status
)) {
471 for (Index
= 0; Index
< HandleCount
; Index
++) {
472 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], Id
, &Instance
);
473 if (EFI_ERROR (Status
)) {
477 Status
= (*CallBackFunction
) (
484 gBS
->FreePool (HandleBuffer
);
492 VisitingAPciInstance (
493 IN EFI_HANDLE Handle
,
499 EFI_PCI_IO_PROTOCOL
*PciIo
;
502 PciIo
= (EFI_PCI_IO_PROTOCOL
*) Instance
;
505 // Check for all PCI device
507 Status
= PciIo
->Pci
.Read (
511 sizeof (Pci
) / sizeof (UINT32
),
514 if (EFI_ERROR (Status
)) {
518 return (*(VISIT_PCI_INSTANCE_CALLBACK
)(UINTN
) Context
) (
529 VisitAllPciInstances (
530 IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction
533 return VisitAllInstancesOfProtocol (
534 &gEfiPciIoProtocolGuid
,
535 VisitingAPciInstance
,
536 (VOID
*)(UINTN
) CallBackFunction
542 Do platform specific PCI Device check and add them to
543 ConOut, ConIn, ErrOut.
545 @param[in] Handle - Handle of PCI device instance
546 @param[in] PciIo - PCI IO protocol instance
547 @param[in] Pci - PCI Header register block
549 @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
550 @retval EFI_STATUS - PCI Device check or Console variable update fail.
555 DetectAndPreparePlatformPciDevicePath (
556 IN EFI_HANDLE Handle
,
557 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
563 Status
= PciIo
->Attributes (
565 EfiPciIoAttributeOperationEnable
,
566 EFI_PCI_DEVICE_ENABLE
,
569 ASSERT_EFI_ERROR (Status
);
571 if (!mDetectVgaOnly
) {
573 // Here we decide whether it is LPC Bridge
575 if ((IS_PCI_LPC (Pci
)) ||
576 ((IS_PCI_ISA_PDECODE (Pci
)) &&
577 (Pci
->Hdr
.VendorId
== 0x8086) &&
578 (Pci
->Hdr
.DeviceId
== 0x7000)
582 // Add IsaKeyboard to ConIn,
583 // add IsaSerial to ConOut, ConIn, ErrOut
585 DEBUG ((EFI_D_INFO
, "Found LPC Bridge device\n"));
586 PrepareLpcBridgeDevicePath (Handle
);
590 // Here we decide which Serial device to enable in PCI bus
592 if (IS_PCI_16550SERIAL (Pci
)) {
594 // Add them to ConOut, ConIn, ErrOut.
596 DEBUG ((EFI_D_INFO
, "Found PCI 16550 SERIAL device\n"));
597 PreparePciSerialDevicePath (Handle
);
603 // Here we decide which VGA device to enable in PCI bus
605 if (IS_PCI_VGA (Pci
)) {
607 // Add them to ConOut.
609 DEBUG ((EFI_D_INFO
, "Found PCI VGA device\n"));
610 PreparePciVgaDevicePath (Handle
);
619 Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
621 @param[in] DetectVgaOnly - Only detect VGA device if it's TRUE.
623 @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
624 @retval EFI_STATUS - PCI Device check or Console variable update fail.
628 DetectAndPreparePlatformPciDevicePaths (
629 BOOLEAN DetectVgaOnly
632 mDetectVgaOnly
= DetectVgaOnly
;
633 return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath
);
638 PlatformBdsConnectConsole (
639 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
645 Connect the predefined platform default console device. Always try to find
646 and enable the vga device if have.
650 PlatformConsole - Predfined platform default console device array.
654 EFI_SUCCESS - Success connect at least one ConIn and ConOut
655 device, there must have one ConOut device is
658 EFI_STATUS - Return the status of
659 BdsLibConnectAllDefaultConsoles ()
665 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
666 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
667 UINTN DevicePathSize
;
670 // Connect RootBridge
672 VarConout
= BdsLibGetVariableAndSize (
674 &gEfiGlobalVariableGuid
,
677 VarConin
= BdsLibGetVariableAndSize (
679 &gEfiGlobalVariableGuid
,
683 if (VarConout
== NULL
|| VarConin
== NULL
) {
685 // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
687 DetectAndPreparePlatformPciDevicePaths (FALSE
);
690 // Have chance to connect the platform default console,
691 // the platform default console is the minimue device group
692 // the platform should support
694 for (Index
= 0; PlatformConsole
[Index
].DevicePath
!= NULL
; ++Index
) {
696 // Update the console variable with the connect type
698 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
699 BdsLibUpdateConsoleVariable (VarConsoleInp
, PlatformConsole
[Index
].DevicePath
, NULL
);
701 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
702 BdsLibUpdateConsoleVariable (VarConsoleOut
, PlatformConsole
[Index
].DevicePath
, NULL
);
704 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
705 BdsLibUpdateConsoleVariable (VarErrorOut
, PlatformConsole
[Index
].DevicePath
, NULL
);
710 // Only detect VGA device and add them to ConOut
712 DetectAndPreparePlatformPciDevicePaths (TRUE
);
716 // Connect the all the default console with current cosole variable
718 Status
= BdsLibConnectAllDefaultConsoles ();
719 if (EFI_ERROR (Status
)) {
732 // Bus 0, Device 0, Function 0 - Host to PCI Bridge
734 PciWrite8 (PCI_LIB_ADDRESS (0, 0, 0, 0x3c), 0x00);
737 // Bus 0, Device 1, Function 0 - PCI to ISA Bridge
739 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x3c), 0x00);
740 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x60), 0x0b);
741 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x61), 0x09);
742 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x62), 0x0b);
743 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x63), 0x09);
746 // Bus 0, Device 1, Function 1 - IDE Controller
748 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 1, 0x3c), 0x00);
749 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 1, 0x0d), 0x40);
752 // Bus 0, Device 1, Function 3 - Power Managment Controller
754 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3c), 0x0b);
755 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3d), 0x01);
758 // Bus 0, Device 2, Function 0 - Video Controller
760 PciWrite8 (PCI_LIB_ADDRESS (0, 2, 0, 0x3c), 0x00);
763 // Bus 0, Device 3, Function 0 - Network Controller
765 PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3c), 0x0b);
766 PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3d), 0x01);
769 // Bus 0, Device 4, Function 0 - RAM Memory
771 PciWrite8 (PCI_LIB_ADDRESS (0, 4, 0, 0x3c), 0x09);
772 PciWrite8 (PCI_LIB_ADDRESS (0, 4, 0, 0x3d), 0x01);
778 ConnectRecursivelyIfPciMassStorage (
779 IN EFI_HANDLE Handle
,
780 IN EFI_PCI_IO_PROTOCOL
*Instance
,
781 IN PCI_TYPE00
*PciHeader
785 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
788 if (IS_CLASS1 (PciHeader
, PCI_CLASS_MASS_STORAGE
)) {
790 Status
= gBS
->HandleProtocol (
792 &gEfiDevicePathProtocolGuid
,
795 if (EFI_ERROR (Status
)) {
802 DevPathStr
= DevicePathToStr (DevicePath
);
805 "Found Mass Storage device: %s\n",
808 FreePool(DevPathStr
);
810 Status
= gBS
->ConnectController (Handle
, NULL
, NULL
, TRUE
);
811 if (EFI_ERROR (Status
)) {
822 This notification function is invoked when the
823 EMU Variable FVB has been changed.
825 @param Event The event that occured
826 @param Context For EFI compatiblity. Not used.
831 EmuVariablesUpdatedCallback (
836 DEBUG ((EFI_D_INFO
, "EmuVariablesUpdatedCallback\n"));
837 UpdateNvVarsOnFileSystem ();
843 VisitingFileSystemInstance (
844 IN EFI_HANDLE Handle
,
850 STATIC BOOLEAN ConnectedToFileSystem
= FALSE
;
852 if (ConnectedToFileSystem
) {
853 return EFI_ALREADY_STARTED
;
856 Status
= ConnectNvVarsToFileSystem (Handle
);
857 if (EFI_ERROR (Status
)) {
861 ConnectedToFileSystem
= TRUE
;
863 EfiCreateProtocolNotifyEvent (
864 &gEfiDevicePathProtocolGuid
,
866 EmuVariablesUpdatedCallback
,
868 &mEmuVariableEventReg
870 PcdSet64 (PcdEmuVariableEvent
, (UINT64
)(UINTN
) mEmuVariableEvent
);
877 PlatformBdsRestoreNvVarsFromHardDisk (
880 VisitAllPciInstances (ConnectRecursivelyIfPciMassStorage
);
881 VisitAllInstancesOfProtocol (
882 &gEfiSimpleFileSystemProtocolGuid
,
883 VisitingFileSystemInstance
,
891 PlatformBdsConnectSequence (
898 Connect with predeined platform connect sequence,
899 the OEM/IBV can customize with their own connect sequence.
913 DEBUG ((EFI_D_INFO
, "PlatformBdsConnectSequence\n"));
918 // Here we can get the customized platform connect sequence
919 // Notes: we can connect with new variable which record the
920 // last time boots connect device path sequence
922 while (gPlatformConnectSequence
[Index
] != NULL
) {
924 // Build the platform boot option
926 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
931 // Just use the simple policy to connect all devices
935 PciInitialization ();
938 // Clear the logo after all devices are connected.
940 gST
->ConOut
->ClearScreen (gST
->ConOut
);
944 PlatformBdsGetDriverOption (
945 IN OUT LIST_ENTRY
*BdsDriverLists
951 Load the predefined driver option, OEM/IBV can customize this
952 to load their own drivers
956 BdsDriverLists - The header of the driver option link list.
964 DEBUG ((EFI_D_INFO
, "PlatformBdsGetDriverOption\n"));
969 PlatformBdsDiagnostics (
970 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
971 IN BOOLEAN QuietBoot
,
972 IN BASEM_MEMORY_TEST BaseMemoryTest
978 Perform the platform diagnostic, such like test memory. OEM/IBV also
979 can customize this fuction to support specific platform diagnostic.
983 MemoryTestLevel - The memory test intensive level
985 QuietBoot - Indicate if need to enable the quiet boot
987 BaseMemoryTest - A pointer to BaseMemoryTest()
997 DEBUG ((EFI_D_INFO
, "PlatformBdsDiagnostics\n"));
1000 // Here we can decide if we need to show
1001 // the diagnostics screen
1002 // Notes: this quiet boot code should be remove
1003 // from the graphic lib
1006 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1008 // Perform system diagnostic
1010 Status
= BaseMemoryTest (MemoryTestLevel
);
1011 if (EFI_ERROR (Status
)) {
1012 DisableQuietBoot ();
1018 // Perform system diagnostic
1020 Status
= BaseMemoryTest (MemoryTestLevel
);
1026 PlatformBdsPolicyBehavior (
1027 IN OUT LIST_ENTRY
*DriverOptionList
,
1028 IN OUT LIST_ENTRY
*BootOptionList
,
1029 IN PROCESS_CAPSULES ProcessCapsules
,
1030 IN BASEM_MEMORY_TEST BaseMemoryTest
1034 Routine Description:
1036 The function will excute with as the platform policy, current policy
1037 is driven by boot mode. IBV/OEM can customize this code for their specific
1042 DriverOptionList - The header of the driver option link list
1044 BootOptionList - The header of the boot option link list
1046 ProcessCapsules - A pointer to ProcessCapsules()
1048 BaseMemoryTest - A pointer to BaseMemoryTest()
1058 EFI_EVENT UserInputDurationTime
;
1060 BDS_COMMON_OPTION
*BootOption
;
1064 EFI_BOOT_MODE BootMode
;
1066 DEBUG ((EFI_D_INFO
, "PlatformBdsPolicyBehavior\n"));
1068 ConnectRootBridge ();
1071 // Try to restore variables from the hard disk early so
1072 // they can be used for the other BDS connect operations.
1074 PlatformBdsRestoreNvVarsFromHardDisk ();
1077 // Init the time out value
1079 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
1082 // Load the driver option as the driver option list
1084 PlatformBdsGetDriverOption (DriverOptionList
);
1087 // Get current Boot Mode
1089 Status
= BdsLibGetBootMode (&BootMode
);
1090 DEBUG ((EFI_D_ERROR
, "Boot Mode:%x\n", BootMode
));
1093 // Go the different platform policy with different boot mode
1094 // Notes: this part code can be change with the table policy
1096 ASSERT (BootMode
== BOOT_WITH_FULL_CONFIGURATION
);
1098 // Connect platform console
1100 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1101 if (EFI_ERROR (Status
)) {
1103 // Here OEM/IBV can customize with defined action
1105 PlatformBdsNoConsoleAction ();
1108 // Create a 300ms duration event to ensure user has enough input time to enter Setup
1110 Status
= gBS
->CreateEvent (
1115 &UserInputDurationTime
1117 ASSERT (Status
== EFI_SUCCESS
);
1118 Status
= gBS
->SetTimer (UserInputDurationTime
, TimerRelative
, 3000000);
1119 ASSERT (Status
== EFI_SUCCESS
);
1121 // Memory test and Logo show
1123 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1126 // Perform some platform specific connect sequence
1128 PlatformBdsConnectSequence ();
1131 // Give one chance to enter the setup if we
1132 // have the time out
1135 //PlatformBdsEnterFrontPage (Timeout, FALSE);
1138 DEBUG ((EFI_D_INFO
, "BdsLibConnectAll\n"));
1139 BdsLibConnectAll ();
1140 BdsLibEnumerateAllBootOption (BootOptionList
);
1143 // Please uncomment above ConnectAll and EnumerateAll code and remove following first boot
1144 // checking code in real production tip.
1146 // In BOOT_WITH_FULL_CONFIGURATION boot mode, should always connect every device
1147 // and do enumerate all the default boot options. But in development system board, the boot mode
1148 // cannot be BOOT_ASSUMING_NO_CONFIGURATION_CHANGES because the machine box
1149 // is always open. So the following code only do the ConnectAll and EnumerateAll at first boot.
1151 Status
= BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1152 if (EFI_ERROR(Status
)) {
1154 // If cannot find "BootOrder" variable, it may be first boot.
1155 // Try to connect all devices and enumerate all boot options here.
1157 BdsLibConnectAll ();
1158 BdsLibEnumerateAllBootOption (BootOptionList
);
1162 // To give the User a chance to enter Setup here, if user set TimeOut is 0.
1163 // BDS should still give user a chance to enter Setup
1165 // Connect first boot option, and then check user input before exit
1167 for (Link
= BootOptionList
->ForwardLink
; Link
!= BootOptionList
;Link
= Link
->ForwardLink
) {
1168 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
1169 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
1171 // skip the header of the link list, becuase it has no boot option
1176 // Make sure the boot option device path connected, but ignore the BBS device path
1178 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
1179 BdsLibConnectDevicePath (BootOption
->DevicePath
);
1186 // Check whether the user input after the duration time has expired
1188 OldTpl
= EfiGetCurrentTpl();
1189 gBS
->RestoreTPL (TPL_APPLICATION
);
1190 gBS
->WaitForEvent (1, &UserInputDurationTime
, &Index
);
1191 gBS
->CloseEvent (UserInputDurationTime
);
1192 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
1193 gBS
->RaiseTPL (OldTpl
);
1195 if (!EFI_ERROR (Status
)) {
1197 // Enter Setup if user input
1200 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
1208 PlatformBdsBootSuccess (
1209 IN BDS_COMMON_OPTION
*Option
1213 Routine Description:
1215 Hook point after a boot attempt succeeds. We don't expect a boot option to
1216 return, so the EFI 1.0 specification defines that you will default to an
1217 interactive mode and stop processing the BootOrder list in this case. This
1218 is alos a platform implementation and can be customized by IBV/OEM.
1222 Option - Pointer to Boot Option that succeeded to boot.
1232 DEBUG ((EFI_D_INFO
, "PlatformBdsBootSuccess\n"));
1234 // If Boot returned with EFI_SUCCESS and there is not in the boot device
1235 // select loop then we need to pop up a UI and wait for user input.
1237 TmpStr
= Option
->StatusString
;
1238 if (TmpStr
!= NULL
) {
1239 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
1246 PlatformBdsBootFail (
1247 IN BDS_COMMON_OPTION
*Option
,
1248 IN EFI_STATUS Status
,
1249 IN CHAR16
*ExitData
,
1250 IN UINTN ExitDataSize
1254 Routine Description:
1256 Hook point after a boot attempt fails.
1260 Option - Pointer to Boot Option that failed to boot.
1262 Status - Status returned from failed boot.
1264 ExitData - Exit data returned from failed boot.
1266 ExitDataSize - Exit data size returned from failed boot.
1276 DEBUG ((EFI_D_INFO
, "PlatformBdsBootFail\n"));
1279 // If Boot returned with failed status then we need to pop up a UI and wait
1282 TmpStr
= Option
->StatusString
;
1283 if (TmpStr
!= NULL
) {
1284 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
1290 PlatformBdsNoConsoleAction (
1295 Routine Description:
1297 This function is remained for IBV/OEM to do some platform action,
1298 if there no console device can be connected.
1306 EFI_SUCCESS - Direct return success now.
1310 DEBUG ((EFI_D_INFO
, "PlatformBdsNoConsoleAction\n"));
1316 PlatformBdsLockNonUpdatableFlash (
1320 DEBUG ((EFI_D_INFO
, "PlatformBdsLockNonUpdatableFlash\n"));
1326 This notification function is invoked when an instance of the
1327 EFI_DEVICE_PATH_PROTOCOL is produced.
1329 @param Event The event that occured
1330 @param Context For EFI compatiblity. Not used.
1343 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
1344 ATAPI_DEVICE_PATH
*Atapi
;
1347 // Examine all new handles
1351 // Get the next handle
1353 BufferSize
= sizeof (Handle
);
1354 Status
= gBS
->LocateHandle (
1357 mEfiDevPathNotifyReg
,
1363 // If not found, we're done
1365 if (EFI_NOT_FOUND
== Status
) {
1369 if (EFI_ERROR (Status
)) {
1374 // Get the DevicePath protocol on that handle
1376 Status
= gBS
->HandleProtocol (Handle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPathNode
);
1377 ASSERT_EFI_ERROR (Status
);
1379 while (!IsDevicePathEnd (DevPathNode
)) {
1381 // Find the handler to dump this device path node
1384 (DevicePathType(DevPathNode
) == MESSAGING_DEVICE_PATH
) &&
1385 (DevicePathSubType(DevPathNode
) == MSG_ATAPI_DP
)
1387 Atapi
= (ATAPI_DEVICE_PATH
*) DevPathNode
;
1393 (Atapi
->PrimarySecondary
== 1) ? 0x42: 0x40
1400 // Next device path node
1402 DevPathNode
= NextDevicePathNode (DevPathNode
);
1411 InstallDevicePathCallback (
1415 DEBUG ((EFI_D_INFO
, "Registered NotifyDevPath Event\n"));
1416 mEfiDevPathEvent
= EfiCreateProtocolNotifyEvent (
1417 &gEfiDevicePathProtocolGuid
,
1421 &mEfiDevPathNotifyReg
1426 Lock the ConsoleIn device in system table. All key
1427 presses will be ignored until the Password is typed in. The only way to
1428 disable the password is to type it in to a ConIn device.
1430 @param Password Password used to lock ConIn device.
1432 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
1433 @retval EFI_UNSUPPORTED Password not found
1442 return EFI_UNSUPPORTED
;
1452 PCI_DATA_STRUCTURE
*Pcir
;
1456 // The virtual machines sometimes load the video rom image
1457 // directly at the legacy video BIOS location of C000:0000,
1458 // and do not implement the PCI expansion ROM feature.
1460 Pcir
= (PCI_DATA_STRUCTURE
*) (UINTN
) 0xc0000;
1461 RomSize
= Pcir
->ImageLength
* 512;
1462 PciRomLoadEfiDriversFromRomImage (0xc0000, RomSize
);
1468 PciRomLoadEfiDriversFromRomImage (
1469 IN EFI_PHYSICAL_ADDRESS Rom
,
1474 EFI_PCI_EXPANSION_ROM_HEADER
*EfiRomHeader
;
1475 PCI_DATA_STRUCTURE
*Pcir
;
1480 EFI_HANDLE ImageHandle
;
1482 EFI_STATUS retStatus
;
1483 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
1485 UINT32 DestinationSize
;
1489 VOID
*DecompressedImageBuffer
;
1491 EFI_DECOMPRESS_PROTOCOL
*Decompress
;
1493 FileName
= L
"PciRomInMemory";
1495 //FileName = L"PciRom Addr=0000000000000000";
1496 //HexToString (&FileName[12], Rom, 16);
1499 retStatus
= EFI_NOT_FOUND
;
1500 RomOffset
= (UINTN
) Rom
;
1504 EfiRomHeader
= (EFI_PCI_EXPANSION_ROM_HEADER
*) (UINTN
) RomOffset
;
1506 if (EfiRomHeader
->Signature
!= 0xaa55) {
1510 Pcir
= (PCI_DATA_STRUCTURE
*) (UINTN
) (RomOffset
+ EfiRomHeader
->PcirOffset
);
1511 ImageSize
= Pcir
->ImageLength
* 512;
1513 if ((Pcir
->CodeType
== PCI_CODE_TYPE_EFI_IMAGE
) &&
1514 (EfiRomHeader
->EfiSignature
== EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE
) ) {
1516 if ((EfiRomHeader
->EfiSubsystem
== EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
) ||
1517 (EfiRomHeader
->EfiSubsystem
== EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
) ) {
1519 ImageOffset
= EfiRomHeader
->EfiImageHeaderOffset
;
1520 ImageSize
= EfiRomHeader
->InitializationSize
* 512;
1522 ImageBuffer
= (VOID
*) (UINTN
) (RomOffset
+ ImageOffset
);
1523 ImageLength
= ImageSize
- ImageOffset
;
1524 DecompressedImageBuffer
= NULL
;
1527 // decompress here if needed
1530 if (EfiRomHeader
->CompressionType
> EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED
) {
1534 if (EfiRomHeader
->CompressionType
== EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED
) {
1535 Status
= gBS
->LocateProtocol (&gEfiDecompressProtocolGuid
, NULL
, (VOID
**) &Decompress
);
1536 if (EFI_ERROR (Status
)) {
1540 Status
= Decompress
->GetInfo (
1547 if (!EFI_ERROR (Status
)) {
1548 DecompressedImageBuffer
= NULL
;
1549 DecompressedImageBuffer
= AllocatePool (DestinationSize
);
1550 if (DecompressedImageBuffer
!= NULL
) {
1551 Scratch
= AllocatePool (ScratchSize
);
1552 if (Scratch
!= NULL
) {
1553 Status
= Decompress
->Decompress (
1557 DecompressedImageBuffer
,
1562 if (!EFI_ERROR (Status
)) {
1563 ImageBuffer
= DecompressedImageBuffer
;
1564 ImageLength
= DestinationSize
;
1568 gBS
->FreePool (Scratch
);
1578 // load image and start image
1581 FilePath
= FileDevicePath (NULL
, FileName
);
1583 Status
= gBS
->LoadImage (
1591 if (!EFI_ERROR (Status
)) {
1592 Status
= gBS
->StartImage (ImageHandle
, NULL
, NULL
);
1593 if (!EFI_ERROR (Status
)) {
1597 if (FilePath
!= NULL
) {
1598 gBS
->FreePool (FilePath
);
1602 if (DecompressedImageBuffer
!= NULL
) {
1603 gBS
->FreePool (DecompressedImageBuffer
);
1609 RomOffset
= RomOffset
+ ImageSize
;
1611 } while (((Pcir
->Indicator
& 0x80) == 0x00) && ((RomOffset
- (UINTN
) Rom
) < RomSize
));