]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/Library/DuetBdsLib/BdsPlatform.c
DuetPkg: Remove DuetPkg
[mirror_edk2.git] / DuetPkg / Library / DuetBdsLib / BdsPlatform.c
diff --git a/DuetPkg/Library/DuetBdsLib/BdsPlatform.c b/DuetPkg/Library/DuetBdsLib/BdsPlatform.c
deleted file mode 100644 (file)
index c0dc493..0000000
+++ /dev/null
@@ -1,1731 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-Module Name:\r
-\r
-  BdsPlatform.c\r
-\r
-Abstract:\r
-\r
-  This file include all platform action which can be customized\r
-  by IBV/OEM.\r
-\r
---*/\r
-\r
-#include "BdsPlatform.h"\r
-\r
-#define IS_PCI_ISA_PDECODE(_p)        IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_ISA_PDECODE, 0)\r
-\r
-extern BOOLEAN  gConnectAllHappened;\r
-extern USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath;\r
-\r
-EFI_GUID                    *gTableGuidArray[] = {\r
-    &gEfiAcpi20TableGuid, &gEfiAcpiTableGuid, &gEfiSmbiosTableGuid, &gEfiMpsTableGuid\r
-  };\r
-\r
-//\r
-// BDS Platform Functions\r
-//\r
-\r
-VOID\r
-GetSystemTablesFromHob (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Find GUID'ed HOBs that contain EFI_PHYSICAL_ADDRESS of ACPI, SMBIOS, MPs tables\r
-\r
-Arguments:\r
-  None\r
-\r
-Returns:\r
-  None.\r
-\r
---*/\r
-{\r
-  EFI_PEI_HOB_POINTERS        GuidHob;\r
-  EFI_PEI_HOB_POINTERS        HobStart;\r
-  EFI_PHYSICAL_ADDRESS        *Table;\r
-  UINTN                       Index;\r
-\r
-  //\r
-  // Get Hob List\r
-  //\r
-  HobStart.Raw = GetHobList ();\r
-  //\r
-  // Iteratively add ACPI Table, SMBIOS Table, MPS Table to EFI System Table\r
-  //\r
-  for (Index = 0; Index < ARRAY_SIZE (gTableGuidArray); ++Index) {\r
-    GuidHob.Raw = GetNextGuidHob (gTableGuidArray[Index], HobStart.Raw);\r
-    if (GuidHob.Raw != NULL) {\r
-      Table = GET_GUID_HOB_DATA (GuidHob.Guid);\r
-      if (Table != NULL) {\r
-        //\r
-        // Check if Mps Table/Smbios Table/Acpi Table exists in E/F seg,\r
-        // According to UEFI Spec, we should make sure Smbios table, \r
-        // ACPI table and Mps tables kept in memory of specified type\r
-        //\r
-        ConvertSystemTable(gTableGuidArray[Index], (VOID**)&Table);\r
-        gBS->InstallConfigurationTable (gTableGuidArray[Index], (VOID *)Table);\r
-      }\r
-    }\r
-  }\r
-\r
-  return ;\r
-}\r
-\r
-#if 0\r
-VOID\r
-PrintMemoryMap (\r
-  VOID\r
-  )\r
-{\r
-  EFI_MEMORY_DESCRIPTOR       *MemMap;\r
-  EFI_MEMORY_DESCRIPTOR       *MemMapPtr;\r
-  UINTN                       MemMapSize;\r
-  UINTN                       MapKey, DescriptorSize;\r
-  UINTN                       Index;\r
-  UINT32                      DescriptorVersion;\r
-  UINT64                      Bytes;\r
-  EFI_STATUS                  Status;\r
-\r
-  MemMapSize = 0;\r
-  MemMap     = NULL;\r
-  Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);\r
-  ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-  MemMapSize += EFI_PAGE_SIZE;\r
-  Status = gBS->AllocatePool (EfiBootServicesData, MemMapSize, &MemMap);\r
-  ASSERT (Status == EFI_SUCCESS);\r
-  Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);\r
-  ASSERT (Status == EFI_SUCCESS);\r
-  MemMapPtr = MemMap;\r
-\r
-  ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);\r
-\r
-  for (Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {\r
-    Bytes = LShiftU64 (MemMap->NumberOfPages, 12);\r
-    DEBUG ((EFI_D_ERROR, "%lX-%lX  %lX %lX %X\n",\r
-          MemMap->PhysicalStart, \r
-          MemMap->PhysicalStart + Bytes - 1,\r
-          MemMap->NumberOfPages, \r
-          MemMap->Attribute,\r
-          (UINTN)MemMap->Type));\r
-    MemMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMap + DescriptorSize);\r
-  }\r
-\r
-  gBS->FreePool (MemMapPtr);\r
-}\r
-#endif\r
-\r
-VOID\r
-UpdateMemoryMap (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS                      Status;\r
-  EFI_PEI_HOB_POINTERS            GuidHob;\r
-  VOID                            *Table;\r
-  MEMORY_DESC_HOB                 MemoryDescHob;\r
-  UINTN                           Index;\r
-  EFI_PHYSICAL_ADDRESS            Memory;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
-  \r
-  GuidHob.Raw = GetFirstGuidHob (&gLdrMemoryDescriptorGuid);\r
-  if (GuidHob.Raw == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "Fail to get gEfiLdrMemoryDescriptorGuid from GUID HOB LIST!\n"));\r
-    return;\r
-  }\r
-  Table = GET_GUID_HOB_DATA (GuidHob.Guid);\r
-  if (Table == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "Fail to get gEfiLdrMemoryDescriptorGuid from GUID HOB LIST!\n"));\r
-    return;\r
-  }\r
-  MemoryDescHob.MemDescCount = *(UINTN *)Table;\r
-  MemoryDescHob.MemDesc      = *(EFI_MEMORY_DESCRIPTOR **)((UINTN)Table + sizeof(UINTN));\r
-\r
-  //\r
-  // Add ACPINVS, ACPIReclaim, and Reserved memory to MemoryMap\r
-  //\r
-  for (Index = 0; Index < MemoryDescHob.MemDescCount; Index++) {\r
-    if (MemoryDescHob.MemDesc[Index].PhysicalStart < 0x100000) {\r
-      continue;\r
-    }\r
-    if (MemoryDescHob.MemDesc[Index].PhysicalStart >= 0x100000000ULL) {\r
-      continue;\r
-    }\r
-    if ((MemoryDescHob.MemDesc[Index].Type == EfiReservedMemoryType) ||\r
-        (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) ||\r
-        (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode) ||\r
-        (MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||\r
-        (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {\r
-      DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%016lx, ", MemoryDescHob.MemDesc[Index].PhysicalStart));\r
-      DEBUG ((EFI_D_ERROR, "PageNumber    - 0x%016lx, ", MemoryDescHob.MemDesc[Index].NumberOfPages));\r
-      DEBUG ((EFI_D_ERROR, "Attribute     - 0x%016lx, ", MemoryDescHob.MemDesc[Index].Attribute));\r
-      DEBUG ((EFI_D_ERROR, "Type          - 0x%08x\n", MemoryDescHob.MemDesc[Index].Type));\r
-      if ((MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) ||\r
-          (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode)) {\r
-        //\r
-        // For RuntimeSevicesData and RuntimeServicesCode, they are BFV or DxeCore.\r
-        // The memory type is assigned in EfiLdr\r
-        //\r
-        Status = gDS->GetMemorySpaceDescriptor (MemoryDescHob.MemDesc[Index].PhysicalStart, &Descriptor);\r
-        if (EFI_ERROR (Status)) {\r
-          continue;\r
-        }\r
-        if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeReserved) {\r
-          //\r
-          // BFV or tested DXE core\r
-          //\r
-          continue;\r
-        }\r
-        //\r
-        // Untested DXE Core region, free and remove\r
-        //\r
-        Status = gDS->FreeMemorySpace (\r
-                        MemoryDescHob.MemDesc[Index].PhysicalStart,\r
-                        LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)\r
-                        );\r
-        if (EFI_ERROR (Status)) {\r
-          DEBUG ((EFI_D_ERROR, "FreeMemorySpace fail - %r!\n", Status));\r
-          continue;\r
-        }\r
-        Status = gDS->RemoveMemorySpace (\r
-                        MemoryDescHob.MemDesc[Index].PhysicalStart,\r
-                        LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)\r
-                        );\r
-        if (EFI_ERROR (Status)) {\r
-          DEBUG ((EFI_D_ERROR, "RemoveMemorySpace fail - %r!\n", Status));\r
-          continue;\r
-        }\r
-\r
-        //\r
-        // Convert Runtime type to BootTime type\r
-        //\r
-        if (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) {\r
-          MemoryDescHob.MemDesc[Index].Type = EfiBootServicesData;\r
-        } else {\r
-          MemoryDescHob.MemDesc[Index].Type = EfiBootServicesCode;\r
-        }\r
-\r
-        //\r
-        // PassThrough, let below code add and alloate.\r
-        //\r
-      }\r
-      //\r
-      // ACPI or reserved memory\r
-      //\r
-      Status = gDS->AddMemorySpace (\r
-                      EfiGcdMemoryTypeSystemMemory,\r
-                      MemoryDescHob.MemDesc[Index].PhysicalStart,\r
-                      LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT),\r
-                      MemoryDescHob.MemDesc[Index].Attribute\r
-                      );\r
-      if (EFI_ERROR (Status)) {\r
-        DEBUG ((EFI_D_ERROR, "AddMemorySpace fail - %r!\n", Status));\r
-        if ((MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||\r
-            (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {\r
-          //\r
-          // For EfiACPIReclaimMemory and EfiACPIMemoryNVS, it must success.\r
-          // For EfiReservedMemoryType, there maybe overlap. So skip check here.\r
-          //\r
-//          ASSERT_EFI_ERROR (Status);\r
-        }\r
-        continue;\r
-      }\r
-\r
-      Memory = MemoryDescHob.MemDesc[Index].PhysicalStart;\r
-      Status = gBS->AllocatePages (\r
-                      AllocateAddress,\r
-                      (EFI_MEMORY_TYPE)MemoryDescHob.MemDesc[Index].Type,\r
-                      (UINTN)MemoryDescHob.MemDesc[Index].NumberOfPages,\r
-                      &Memory\r
-                      );\r
-      if (EFI_ERROR (Status)) {\r
-        DEBUG ((EFI_D_ERROR, "AllocatePages fail - %r!\n", Status));\r
-        //\r
-        // For the page added, it must be allocated.\r
-        //\r
-//        ASSERT_EFI_ERROR (Status);\r
-        continue;\r
-      }\r
-    }\r
-  }\r
-  \r
-}\r
-\r
-EFI_STATUS\r
-DisableUsbLegacySupport(\r
-  void\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Disabble the USB legacy Support in all Ehci and Uhci.\r
-  This function assume all PciIo handles have been created in system.\r
-  \r
-Arguments:\r
-  None\r
-  \r
-Returns:\r
-  EFI_SUCCESS\r
-  EFI_NOT_FOUND\r
---*/\r
-{\r
-  EFI_STATUS                            Status;\r
-  EFI_HANDLE                            *HandleArray;\r
-  UINTN                                 HandleArrayCount;\r
-  UINTN                                 Index;\r
-  EFI_PCI_IO_PROTOCOL                   *PciIo;\r
-  UINT8                                 Class[3];\r
-  UINT16                                Command;\r
-  UINT32                                HcCapParams;\r
-  UINT32                                ExtendCap;\r
-  UINT32                                Value;\r
-  UINT32                                TimeOut;\r
-  \r
-  //\r
-  // Find the usb host controller \r
-  //   \r
-  Status = gBS->LocateHandleBuffer (\r
-                  ByProtocol,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  NULL,\r
-                  &HandleArrayCount,\r
-                  &HandleArray\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    for (Index = 0; Index < HandleArrayCount; Index++) {\r
-      Status = gBS->HandleProtocol (\r
-                      HandleArray[Index],\r
-                      &gEfiPciIoProtocolGuid,\r
-                      (VOID **)&PciIo\r
-                      );\r
-      if (!EFI_ERROR (Status)) {\r
-        //\r
-        // Find the USB host controller controller\r
-        //\r
-        Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);\r
-        if (!EFI_ERROR (Status)) {\r
-          if ((PCI_CLASS_SERIAL == Class[2]) &&\r
-              (PCI_CLASS_SERIAL_USB == Class[1])) {\r
-            if (PCI_IF_UHCI == Class[0]) {\r
-              //\r
-              // Found the UHCI, then disable the legacy support\r
-              //\r
-              Command = 0;\r
-              Status = PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, 0xC0, 1, &Command);\r
-            } else if (PCI_IF_EHCI == Class[0]) {\r
-              //\r
-              // Found the EHCI, then disable the legacy support\r
-              //\r
-              Status = PciIo->Mem.Read (\r
-                                   PciIo,\r
-                                   EfiPciIoWidthUint32,\r
-                                   0,                   //EHC_BAR_INDEX\r
-                                   (UINT64) 0x08,       //EHC_HCCPARAMS_OFFSET\r
-                                   1,\r
-                                   &HcCapParams\r
-                                   );\r
-              \r
-              ExtendCap = (HcCapParams >> 8) & 0xFF;\r
-              //\r
-              // Disable the SMI in USBLEGCTLSTS firstly\r
-              //\r
-              PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap + 0x4, 1, &Value);\r
-              Value &= 0xFFFF0000;\r
-              PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, ExtendCap + 0x4, 1, &Value);\r
-              \r
-              //\r
-              // Get EHCI Ownership from legacy bios\r
-              //\r
-              PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap, 1, &Value);\r
-              Value |= (0x1 << 24);\r
-              PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, ExtendCap, 1, &Value);\r
-\r
-              TimeOut = 40;\r
-              while (TimeOut--) {\r
-                gBS->Stall (500);\r
-\r
-                PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap, 1, &Value);\r
-\r
-                if ((Value & 0x01010000) == 0x01000000) {\r
-                  break;\r
-                }\r
-              }\r
-            }\r
-          } \r
-        }\r
-      }\r
-    }\r
-  } else {\r
-    return Status;\r
-  }\r
-  gBS->FreePool (HandleArray);\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-VOID\r
-EFIAPI\r
-PlatformBdsInit (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Platform Bds init. Include the platform firmware vendor, revision\r
-  and so crc check.\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None.\r
-\r
---*/\r
-{\r
-  GetSystemTablesFromHob ();\r
-\r
-  UpdateMemoryMap ();\r
-  \r
-  //\r
-  // Append Usb Keyboard short form DevicePath into "ConInDev" \r
-  //\r
-  BdsLibUpdateConsoleVariable (\r
-    VarConsoleInpDev,\r
-    (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath,\r
-    NULL\r
-    );\r
-}\r
-\r
-UINT64\r
-GetPciExpressBaseAddressForRootBridge (\r
-  IN UINTN    HostBridgeNumber,\r
-  IN UINTN    RootBridgeNumber\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  This routine is to get PciExpress Base Address for this RootBridge\r
-\r
-Arguments:\r
-  HostBridgeNumber - The number of HostBridge\r
-  RootBridgeNumber - The number of RootBridge\r
-    \r
-Returns:\r
-  UINT64 - PciExpressBaseAddress for this HostBridge and RootBridge\r
-\r
---*/\r
-{\r
-  EFI_PCI_EXPRESS_BASE_ADDRESS_INFORMATION *PciExpressBaseAddressInfo;\r
-  UINTN                                    BufferSize;\r
-  UINT32                                   Index;\r
-  UINT32                                   Number;\r
-  EFI_PEI_HOB_POINTERS                     GuidHob;\r
-\r
-  //\r
-  // Get PciExpressAddressInfo Hob\r
-  //\r
-  PciExpressBaseAddressInfo = NULL;\r
-  BufferSize                = 0;\r
-  GuidHob.Raw = GetFirstGuidHob (&gEfiPciExpressBaseAddressGuid);\r
-  if (GuidHob.Raw != NULL) {\r
-    PciExpressBaseAddressInfo = GET_GUID_HOB_DATA (GuidHob.Guid);\r
-    BufferSize                = GET_GUID_HOB_DATA_SIZE (GuidHob.Guid);\r
-  } else {\r
-    return 0;\r
-  }\r
-\r
-  //\r
-  // Search the PciExpress Base Address in the Hob for current RootBridge\r
-  //\r
-  Number = (UINT32)(BufferSize / sizeof(EFI_PCI_EXPRESS_BASE_ADDRESS_INFORMATION));\r
-  for (Index = 0; Index < Number; Index++) {\r
-    if ((PciExpressBaseAddressInfo[Index].HostBridgeNumber == HostBridgeNumber) &&\r
-        (PciExpressBaseAddressInfo[Index].RootBridgeNumber == RootBridgeNumber)) {\r
-      return PciExpressBaseAddressInfo[Index].PciExpressBaseAddress;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Do not find the PciExpress Base Address in the Hob\r
-  //\r
-  return 0;  \r
-}\r
-\r
-VOID\r
-PatchPciRootBridgeDevicePath (\r
-  IN UINTN    HostBridgeNumber,\r
-  IN UINTN    RootBridgeNumber,\r
-  IN PLATFORM_ROOT_BRIDGE_DEVICE_PATH  *RootBridge\r
-  )\r
-{\r
-  UINT64  PciExpressBase;\r
-\r
-  PciExpressBase = GetPciExpressBaseAddressForRootBridge (HostBridgeNumber, RootBridgeNumber);\r
-  \r
-  DEBUG ((EFI_D_INFO, "Get PciExpress Address from Hob: 0x%X\n", PciExpressBase));\r
-  \r
-  if (PciExpressBase != 0) {\r
-    RootBridge->PciRootBridge.HID = EISA_PNP_ID(0x0A08);\r
-  }\r
-}\r
-\r
-EFI_STATUS\r
-ConnectRootBridge (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Connect RootBridge\r
-\r
-Arguments:\r
-\r
-  None.\r
\r
-Returns:\r
-\r
-  EFI_SUCCESS             - Connect RootBridge successfully.\r
-  EFI_STATUS              - Connect RootBridge fail.\r
-\r
---*/\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_HANDLE                RootHandle;\r
-\r
-  //\r
-  // Patch Pci Root Bridge Device Path\r
-  //\r
-  PatchPciRootBridgeDevicePath (0, 0, &gPlatformRootBridge0);\r
-\r
-  //\r
-  // Make all the PCI_IO protocols on PCI Seg 0 show up\r
-  //\r
-  BdsLibConnectDevicePath (gPlatformRootBridges[0]);\r
-\r
-  Status = gBS->LocateDevicePath (\r
-                  &gEfiDevicePathProtocolGuid, \r
-                  &gPlatformRootBridges[0], \r
-                  &RootHandle\r
-                  );\r
-  DEBUG ((EFI_D_INFO, "Pci Root bridge handle is 0x%X\n", RootHandle));\r
-  \r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->ConnectController (RootHandle, NULL, NULL, FALSE);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PrepareLpcBridgeDevicePath (\r
-  IN EFI_HANDLE                DeviceHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Add IsaKeyboard to ConIn,\r
-  add IsaSerial to ConOut, ConIn, ErrOut.\r
-  LPC Bridge: 06 01 00\r
-\r
-Arguments:\r
-\r
-  DeviceHandle            - Handle of PCIIO protocol.\r
\r
-Returns:\r
-\r
-  EFI_SUCCESS             - LPC bridge is added to ConOut, ConIn, and ErrOut.\r
-  EFI_STATUS              - No LPC bridge is added.\r
-\r
---*/\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
-\r
-  DevicePath = NULL;\r
-  Status = gBS->HandleProtocol (\r
-                  DeviceHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID*)&DevicePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  TempDevicePath = DevicePath;\r
-\r
-  //\r
-  // Register Keyboard\r
-  //\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnpPs2KeyboardDeviceNode);\r
-\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-\r
-  //\r
-  // Register COM1\r
-  //\r
-  DevicePath = TempDevicePath;\r
-  gPnp16550ComPortDeviceNode.UID = 0;\r
-\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
-\r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
-\r
-  //\r
-  // Register COM2\r
-  //\r
-  DevicePath = TempDevicePath;\r
-  gPnp16550ComPortDeviceNode.UID = 1;\r
-\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
-\r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetGopDevicePath (\r
-   IN  EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,\r
-   OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath\r
-   )\r
-{\r
-  UINTN                           Index;\r
-  EFI_STATUS                      Status;\r
-  EFI_HANDLE                      PciDeviceHandle;\r
-  EFI_DEVICE_PATH_PROTOCOL        *TempDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL        *TempPciDevicePath;\r
-  UINTN                           GopHandleCount;\r
-  EFI_HANDLE                      *GopHandleBuffer;\r
-\r
-  if (PciDevicePath == NULL || GopDevicePath == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // Initialize the GopDevicePath to be PciDevicePath\r
-  //\r
-  *GopDevicePath    = PciDevicePath;\r
-  TempPciDevicePath = PciDevicePath;\r
-\r
-  Status = gBS->LocateDevicePath (\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  &TempPciDevicePath,\r
-                  &PciDeviceHandle\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Try to connect this handle, so that GOP driver could start on this \r
-  // device and create child handles with GraphicsOutput Protocol installed\r
-  // on them, then we get device paths of these child handles and select \r
-  // them as possible console device.\r
-  //\r
-  gBS->ConnectController (PciDeviceHandle, NULL, NULL, FALSE);\r
-\r
-  Status = gBS->LocateHandleBuffer (\r
-                  ByProtocol,\r
-                  &gEfiGraphicsOutputProtocolGuid,\r
-                  NULL,\r
-                  &GopHandleCount,\r
-                  &GopHandleBuffer\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Add all the child handles as possible Console Device\r
-    //\r
-    for (Index = 0; Index < GopHandleCount; Index++) {\r
-      Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID*)&TempDevicePath);\r
-      if (EFI_ERROR (Status)) {\r
-        continue;\r
-      }\r
-      if (CompareMem (\r
-            PciDevicePath,\r
-            TempDevicePath,\r
-            GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH\r
-            ) == 0) {\r
-        //\r
-        // In current implementation, we only enable one of the child handles\r
-        // as console device, i.e. sotre one of the child handle's device\r
-        // path to variable "ConOut"\r
-        // In future, we could select all child handles to be console device\r
-        //       \r
-\r
-        *GopDevicePath = TempDevicePath;\r
-\r
-        //\r
-        // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()\r
-        // Add the integrity GOP device path.\r
-        //\r
-        BdsLibUpdateConsoleVariable (VarConsoleOutDev, NULL, PciDevicePath);\r
-        BdsLibUpdateConsoleVariable (VarConsoleOutDev, TempDevicePath, NULL);\r
-      }\r
-    }\r
-    gBS->FreePool (GopHandleBuffer);\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PreparePciVgaDevicePath (\r
-  IN EFI_HANDLE                DeviceHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Add PCI VGA to ConOut.\r
-  PCI VGA: 03 00 00\r
-\r
-Arguments:\r
-\r
-  DeviceHandle            - Handle of PCIIO protocol.\r
\r
-Returns:\r
-\r
-  EFI_SUCCESS             - PCI VGA is added to ConOut.\r
-  EFI_STATUS              - No PCI VGA device is added.\r
-\r
---*/\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *GopDevicePath;\r
-\r
-  DevicePath    = NULL;\r
-  GopDevicePath = NULL;\r
-  Status = gBS->HandleProtocol (\r
-                  DeviceHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID*)&DevicePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  \r
-  GetGopDevicePath (DevicePath, &GopDevicePath);\r
-  DevicePath = GopDevicePath;\r
-\r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PreparePciSerialDevicePath (\r
-  IN EFI_HANDLE                DeviceHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Add PCI Serial to ConOut, ConIn, ErrOut.\r
-  PCI Serial: 07 00 02\r
-\r
-Arguments:\r
-\r
-  DeviceHandle            - Handle of PCIIO protocol.\r
\r
-Returns:\r
-\r
-  EFI_SUCCESS             - PCI Serial is added to ConOut, ConIn, and ErrOut.\r
-  EFI_STATUS              - No PCI Serial device is added.\r
-\r
---*/\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  \r
-  DevicePath = NULL;\r
-  Status = gBS->HandleProtocol (\r
-                  DeviceHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID*)&DevicePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
-\r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
-  \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-DetectAndPreparePlatformPciDevicePath (\r
-  BOOLEAN DetectVgaOnly\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
-\r
-Arguments:\r
-\r
-  DetectVgaOnly           - Only detect VGA device if it's TRUE.\r
\r
-Returns:\r
-\r
-  EFI_SUCCESS             - PCI Device check and Console variable update successfully.\r
-  EFI_STATUS              - PCI Device check or Console variable update fail.\r
-\r
---*/\r
-{\r
-  EFI_STATUS                Status;\r
-  UINTN                     HandleCount;\r
-  EFI_HANDLE                *HandleBuffer;\r
-  UINTN                     Index;\r
-  EFI_PCI_IO_PROTOCOL       *PciIo;\r
-  PCI_TYPE00                Pci;\r
-\r
-  //\r
-  // Start to check all the PciIo to find all possible device\r
-  //\r
-  HandleCount = 0;\r
-  HandleBuffer = NULL;\r
-  Status = gBS->LocateHandleBuffer (\r
-                  ByProtocol,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  NULL,\r
-                  &HandleCount,\r
-                  &HandleBuffer\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  for (Index = 0; Index < HandleCount; Index++) {\r
-    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID*)&PciIo);\r
-    if (EFI_ERROR (Status)) {\r
-      continue;\r
-    }\r
-\r
-    //\r
-    // Check for all PCI device\r
-    //\r
-    Status = PciIo->Pci.Read (\r
-                      PciIo,\r
-                      EfiPciIoWidthUint32,\r
-                      0,\r
-                      sizeof (Pci) / sizeof (UINT32),\r
-                      &Pci\r
-                      );\r
-    if (EFI_ERROR (Status)) {\r
-      continue;\r
-    }\r
-\r
-    if (!DetectVgaOnly) {\r
-      //\r
-      // Here we decide whether it is LPC Bridge\r
-      //\r
-      if ((IS_PCI_LPC (&Pci)) ||\r
-          ((IS_PCI_ISA_PDECODE (&Pci)) && (Pci.Hdr.VendorId == 0x8086) && (Pci.Hdr.DeviceId == 0x7110))) {\r
-        //\r
-        // Add IsaKeyboard to ConIn,\r
-        // add IsaSerial to ConOut, ConIn, ErrOut\r
-        //\r
-        DEBUG ((EFI_D_INFO, "Find the LPC Bridge device\n"));\r
-        PrepareLpcBridgeDevicePath (HandleBuffer[Index]);\r
-        continue;\r
-      }\r
-      //\r
-      // Here we decide which Serial device to enable in PCI bus \r
-      //\r
-      if (IS_PCI_16550SERIAL (&Pci)) {\r
-        //\r
-        // Add them to ConOut, ConIn, ErrOut.\r
-        //\r
-        DEBUG ((EFI_D_INFO, "Find the 16550 SERIAL device\n"));\r
-        PreparePciSerialDevicePath (HandleBuffer[Index]);\r
-        continue;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Here we decide which VGA device to enable in PCI bus \r
-    //\r
-    if (IS_PCI_VGA (&Pci)) {\r
-      //\r
-      // Add them to ConOut.\r
-      //\r
-      DEBUG ((EFI_D_INFO, "Find the VGA device\n"));\r
-      PreparePciVgaDevicePath (HandleBuffer[Index]);\r
-      continue;\r
-    }\r
-  }\r
-  \r
-  gBS->FreePool (HandleBuffer);\r
-  \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-PlatformBdsConnectConsole (\r
-  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Connect the predefined platform default console device. Always try to find\r
-  and enable the vga device if have.\r
-\r
-Arguments:\r
-\r
-  PlatformConsole         - Predefined platform default console device array.\r
\r
-Returns:\r
-\r
-  EFI_SUCCESS             - Success connect at least one ConIn and ConOut \r
-                            device, there must have one ConOut device is \r
-                            active vga device.\r
-  \r
-  EFI_STATUS              - Return the status of \r
-                            BdsLibConnectAllDefaultConsoles ()\r
-\r
---*/\r
-{\r
-  EFI_STATUS                         Status;\r
-  UINTN                              Index;\r
-  EFI_DEVICE_PATH_PROTOCOL           *VarConout;\r
-  EFI_DEVICE_PATH_PROTOCOL           *VarConin;\r
-  UINTN                              DevicePathSize;\r
-\r
-  //\r
-  // Connect RootBridge\r
-  //\r
-  ConnectRootBridge ();\r
-\r
-  VarConout = BdsLibGetVariableAndSize (\r
-                VarConsoleOut,\r
-                &gEfiGlobalVariableGuid,\r
-                &DevicePathSize\r
-                );\r
-  VarConin = BdsLibGetVariableAndSize (\r
-               VarConsoleInp,\r
-               &gEfiGlobalVariableGuid,\r
-               &DevicePathSize\r
-               );\r
-  \r
-  if (VarConout == NULL || VarConin == NULL) {\r
-    //\r
-    // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
-    //\r
-    DetectAndPreparePlatformPciDevicePath (FALSE);\r
-\r
-    //\r
-    // Have chance to connect the platform default console,\r
-    // the platform default console is the minimum device group\r
-    // the platform should support\r
-    //\r
-    for (Index = 0; PlatformConsole[Index].DevicePath != NULL; ++Index) {\r
-      //\r
-      // Update the console variable with the connect type\r
-      //\r
-      if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
-        BdsLibUpdateConsoleVariable (VarConsoleInp, PlatformConsole[Index].DevicePath, NULL);\r
-      }\r
-      if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
-        BdsLibUpdateConsoleVariable (VarConsoleOut, PlatformConsole[Index].DevicePath, NULL);\r
-      }\r
-      if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
-        BdsLibUpdateConsoleVariable (VarErrorOut, PlatformConsole[Index].DevicePath, NULL);\r
-      }\r
-    }\r
-  } else {\r
-    //\r
-    // Only detect VGA device and add them to ConOut\r
-    //\r
-    DetectAndPreparePlatformPciDevicePath (TRUE);\r
-  }\r
-  \r
-  //\r
-  // The ConIn devices connection will start the USB bus, should disable all\r
-  // Usb legacy support firstly.\r
-  // Caution: Must ensure the PCI bus driver has been started. Since the \r
-  // ConnectRootBridge() will create all the PciIo protocol, it's safe here now\r
-  //\r
-  Status = DisableUsbLegacySupport();\r
-  \r
-  //\r
-  // Connect the all the default console with current cosole variable\r
-  //\r
-  Status = BdsLibConnectAllDefaultConsoles ();\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-PlatformBdsConnectSequence (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Connect with predefined platform connect sequence,\r
-  the OEM/IBV can customize with their own connect sequence.\r
-  \r
-Arguments:\r
-\r
-  None.\r
\r
-Returns:\r
-\r
-  None.\r
-  \r
---*/\r
-{\r
-  UINTN Index;\r
-\r
-  Index = 0;\r
-\r
-  //\r
-  // Here we can get the customized platform connect sequence\r
-  // Notes: we can connect with new variable which record the\r
-  // last time boots connect device path sequence\r
-  //\r
-  while (gPlatformConnectSequence[Index] != NULL) {\r
-    //\r
-    // Build the platform boot option\r
-    //\r
-    BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
-    Index++;\r
-  }\r
-\r
-}\r
-\r
-VOID\r
-PlatformBdsGetDriverOption (\r
-  IN OUT LIST_ENTRY              *BdsDriverLists\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Load the predefined driver option, OEM/IBV can customize this\r
-  to load their own drivers\r
-  \r
-Arguments:\r
-\r
-  BdsDriverLists  - The header of the driver option link list.\r
\r
-Returns:\r
-\r
-  None.\r
-  \r
---*/\r
-{\r
-  UINTN Index;\r
-\r
-  Index = 0;\r
-\r
-  //\r
-  // Here we can get the customized platform driver option\r
-  //\r
-  while (gPlatformDriverOption[Index] != NULL) {\r
-    //\r
-    // Build the platform boot option\r
-    //\r
-    BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
-    Index++;\r
-  }\r
-\r
-}\r
-\r
-VOID\r
-PlatformBdsDiagnostics (\r
-  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
-  IN BOOLEAN                     QuietBoot,\r
-  IN BASEM_MEMORY_TEST           BaseMemoryTest\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
-  can customize this fuction to support specific platform diagnostic.\r
-  \r
-Arguments:\r
-\r
-  MemoryTestLevel  - The memory test intensive level\r
-  \r
-  QuietBoot        - Indicate if need to enable the quiet boot\r
-\r
-  BaseMemoryTest   - A pointer to BdsMemoryTest()\r
\r
-Returns:\r
-\r
-  None.\r
-  \r
---*/\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  //\r
-  // Here we can decide if we need to show\r
-  // the diagnostics screen\r
-  // Notes: this quiet boot code should be remove\r
-  // from the graphic lib\r
-  //\r
-  if (QuietBoot) {\r
-    Status = EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
-    if (EFI_ERROR (Status)) {\r
-      DisableQuietBoot ();\r
-      return;\r
-    }\r
-\r
-    //\r
-    // Perform system diagnostic\r
-    //\r
-    Status = BaseMemoryTest (MemoryTestLevel);\r
-    if (EFI_ERROR (Status)) {\r
-      DisableQuietBoot ();\r
-    }\r
-\r
-    return ;\r
-  }\r
-  //\r
-  // Perform system diagnostic\r
-  //\r
-  Status = BaseMemoryTest (MemoryTestLevel);\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-PlatformBdsPolicyBehavior (\r
-  IN OUT LIST_ENTRY              *DriverOptionList,\r
-  IN OUT LIST_ENTRY              *BootOptionList,\r
-  IN PROCESS_CAPSULES            ProcessCapsules,\r
-  IN BASEM_MEMORY_TEST           BaseMemoryTest\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  The function will execute with as the platform policy, current policy\r
-  is driven by boot mode. IBV/OEM can customize this code for their specific\r
-  policy action.\r
-  \r
-Arguments:\r
-\r
-  DriverOptionList - The header of the driver option link list\r
-  \r
-  BootOptionList   - The header of the boot option link list\r
\r
-Returns:\r
-\r
-  None.\r
-  \r
---*/\r
-{\r
-  EFI_STATUS                         Status;\r
-  UINT16                             Timeout;\r
-  EFI_EVENT                          UserInputDurationTime;\r
-  UINTN                              Index;\r
-  EFI_INPUT_KEY                      Key;\r
-  EFI_BOOT_MODE                      BootMode;\r
-\r
-  //\r
-  // Init the time out value\r
-  //\r
-  Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
-\r
-  //\r
-  // Load the driver option as the driver option list\r
-  //\r
-  PlatformBdsGetDriverOption (DriverOptionList);\r
-\r
-  //\r
-  // Get current Boot Mode\r
-  //\r
-  Status = BdsLibGetBootMode (&BootMode);\r
-  DEBUG ((EFI_D_ERROR, "Boot Mode:%x\n", BootMode));\r
-\r
-  //\r
-  // Go the different platform policy with different boot mode\r
-  // Notes: this part code can be change with the table policy\r
-  //\r
-  ASSERT (BootMode == BOOT_WITH_FULL_CONFIGURATION);\r
-  //\r
-  // Connect platform console\r
-  //\r
-  Status = PlatformBdsConnectConsole (gPlatformConsole);\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // Here OEM/IBV can customize with defined action\r
-    //\r
-    PlatformBdsNoConsoleAction ();\r
-  }\r
-  //\r
-  // Create a 300ms duration event to ensure user has enough input time to enter Setup\r
-  //\r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER,\r
-                  0,\r
-                  NULL,\r
-                  NULL,\r
-                  &UserInputDurationTime\r
-                  );\r
-  ASSERT (Status == EFI_SUCCESS);\r
-  Status = gBS->SetTimer (UserInputDurationTime, TimerRelative, 3000000);\r
-  ASSERT (Status == EFI_SUCCESS);\r
-  //\r
-  // Memory test and Logo show\r
-  //\r
-  PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);\r
-\r
-  //\r
-  // Perform some platform specific connect sequence\r
-  //\r
-  PlatformBdsConnectSequence ();\r
-\r
-  //\r
-  // Give one chance to enter the setup if we\r
-  // have the time out\r
-  //\r
-  // BUGBUG: hard code timeout to 5 second to show logo in graphic mode.\r
-  Timeout = 5;  \r
-  if (Timeout != 0) {\r
-    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
-  }\r
-\r
-  //\r
-  //BdsLibConnectAll ();\r
-  //BdsLibEnumerateAllBootOption (BootOptionList);  \r
-  \r
-  //\r
-  // Please uncomment above ConnectAll and EnumerateAll code and remove following first boot\r
-  // checking code in real production tip.\r
-  //          \r
-  // In BOOT_WITH_FULL_CONFIGURATION boot mode, should always connect every device \r
-  // and do enumerate all the default boot options. But in development system board, the boot mode \r
-  // cannot be BOOT_ASSUMING_NO_CONFIGURATION_CHANGES because the machine box\r
-  // is always open. So the following code only do the ConnectAll and EnumerateAll at first boot.\r
-  //\r
-  Status = BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
-  if (EFI_ERROR(Status)) {\r
-    //\r
-    // If cannot find "BootOrder" variable,  it may be first boot. \r
-    // Try to connect all devices and enumerate all boot options here.\r
-    //\r
-    BdsLibConnectAll ();\r
-    BdsLibEnumerateAllBootOption (BootOptionList);\r
-  } \r
-\r
-  //\r
-  // To give the User a chance to enter Setup here, if user set TimeOut is 0.\r
-  // BDS should still give user a chance to enter Setup\r
-  // Check whether the user input after the duration time has expired \r
-  //\r
-  gBS->WaitForEvent (1, &UserInputDurationTime, &Index);\r
-  gBS->CloseEvent (UserInputDurationTime);\r
-  Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-  \r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Enter Setup if user input \r
-    //\r
-    Timeout = 0xffff;\r
-    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
-  }\r
-  \r
-  return ;\r
-\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-PlatformBdsBootSuccess (\r
-  IN  BDS_COMMON_OPTION *Option\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  \r
-  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
-  return, so the EFI 1.0 specification defines that you will default to an\r
-  interactive mode and stop processing the BootOrder list in this case. This\r
-  is alos a platform implementation and can be customized by IBV/OEM.\r
-\r
-Arguments:\r
-\r
-  Option - Pointer to Boot Option that succeeded to boot.\r
-\r
-Returns:\r
-  \r
-  None.\r
-\r
---*/\r
-{\r
-  CHAR16  *TmpStr;\r
-\r
-  //\r
-  // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
-  // select loop then we need to pop up a UI and wait for user input.\r
-  //\r
-  TmpStr = Option->StatusString;\r
-  if (TmpStr != NULL) {\r
-    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
-    gBS->FreePool (TmpStr);\r
-  }\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-PlatformBdsBootFail (\r
-  IN  BDS_COMMON_OPTION  *Option,\r
-  IN  EFI_STATUS         Status,\r
-  IN  CHAR16             *ExitData,\r
-  IN  UINTN              ExitDataSize\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  \r
-  Hook point after a boot attempt fails.\r
-\r
-Arguments:\r
-  \r
-  Option - Pointer to Boot Option that failed to boot.\r
-\r
-  Status - Status returned from failed boot.\r
-\r
-  ExitData - Exit data returned from failed boot.\r
-\r
-  ExitDataSize - Exit data size returned from failed boot.\r
-\r
-Returns:\r
-  \r
-  None.\r
-\r
---*/\r
-{\r
-  CHAR16  *TmpStr;\r
-\r
-  //\r
-  // If Boot returned with failed status then we need to pop up a UI and wait\r
-  // for user input.\r
-  //\r
-  TmpStr = Option->StatusString;\r
-  if (TmpStr != NULL) {\r
-    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
-    gBS->FreePool (TmpStr);\r
-  }\r
-\r
-}\r
-\r
-EFI_STATUS\r
-PlatformBdsNoConsoleAction (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  \r
-  This function is remained for IBV/OEM to do some platform action,\r
-  if there no console device can be connected.\r
-\r
-Arguments:\r
-  \r
-  None.\r
-  \r
-Returns:\r
-  \r
-  EFI_SUCCESS      - Direct return success now.\r
-\r
---*/\r
-{\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-ConvertSystemTable (\r
-  IN     EFI_GUID        *TableGuid,\r
-  IN OUT VOID            **Table\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Convert ACPI Table /Smbios Table /MP Table if its location is lower than Address:0x100000\r
-  Assumption here:\r
-   As in legacy Bios, ACPI/Smbios/MP table is required to place in E/F Seg, \r
-   So here we just check if the range is E/F seg, \r
-   and if Not, assume the Memory type is EfiACPIReclaimMemory/EfiACPIMemoryNVS\r
-\r
-Arguments:\r
-  TableGuid - Guid of the table\r
-  Table     - pointer to the table  \r
-\r
-Returns:\r
-  EFI_SUCEESS - Convert Table successfully\r
-  Other       - Failed\r
-\r
---*/\r
-{\r
-  EFI_STATUS      Status;\r
-  VOID            *AcpiHeader;\r
-  UINTN           AcpiTableLen;\r
-  \r
-  //\r
-  // If match acpi guid (1.0, 2.0, or later), Convert ACPI table according to version. \r
-  //\r
-  AcpiHeader = (VOID*)(UINTN)(*(UINT64 *)(*Table));\r
-  \r
-  if (CompareGuid(TableGuid, &gEfiAcpiTableGuid) || CompareGuid(TableGuid, &gEfiAcpi20TableGuid)){\r
-    if (((EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiHeader)->Reserved == 0x00){\r
-      //\r
-      // If Acpi 1.0 Table, then RSDP structure doesn't contain Length field, use structure size\r
-      //\r
-      AcpiTableLen = sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);\r
-    } else if (((EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiHeader)->Reserved >= 0x02){\r
-      //\r
-      // If Acpi 2.0 or later, use RSDP Length fied.\r
-      //\r
-      AcpiTableLen = ((EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiHeader)->Length;\r
-    } else {\r
-      //\r
-      // Invalid Acpi Version, return\r
-      //\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-    Status = ConvertAcpiTable (AcpiTableLen, Table);\r
-    return Status; \r
-  }\r
-  \r
-  //\r
-  // If matches smbios guid, convert Smbios table.\r
-  //\r
-  if (CompareGuid(TableGuid, &gEfiSmbiosTableGuid)){\r
-    Status = ConvertSmbiosTable (Table);\r
-    return Status;\r
-  }\r
-  \r
-  //\r
-  // If the table is MP table?\r
-  //\r
-  if (CompareGuid(TableGuid, &gEfiMpsTableGuid)){\r
-    Status = ConvertMpsTable (Table);\r
-    return Status;\r
-  }\r
-  \r
-  return EFI_UNSUPPORTED;\r
-}  \r
-\r
-\r
-EFI_STATUS\r
-ConvertAcpiTable (\r
-  IN     UINTN                       TableLen,\r
-  IN OUT VOID                        **Table\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Convert RSDP of ACPI Table if its location is lower than Address:0x100000\r
-  Assumption here:\r
-   As in legacy Bios, ACPI table is required to place in E/F Seg, \r
-   So here we just check if the range is E/F seg, \r
-   and if Not, assume the Memory type is EfiACPIReclaimMemory/EfiACPIMemoryNVS\r
-\r
-Arguments:\r
-  TableLen  - Acpi RSDP length\r
-  Table     - pointer to the table  \r
-\r
-Returns:\r
-  EFI_SUCEESS - Convert Table successfully\r
-  Other       - Failed\r
-\r
---*/\r
-{\r
-  VOID                  *AcpiTableOri;\r
-  VOID                  *AcpiTableNew;\r
-  EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  BufferPtr;\r
-\r
-  \r
-  AcpiTableOri    =  (VOID *)(UINTN)(*(UINT64*)(*Table));\r
-  if (((UINTN)AcpiTableOri < 0x100000) && ((UINTN)AcpiTableOri > 0xE0000)) {\r
-    BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;\r
-    Status = gBS->AllocatePages (\r
-                    AllocateMaxAddress,\r
-                    EfiACPIMemoryNVS,\r
-                    EFI_SIZE_TO_PAGES(TableLen),\r
-                    &BufferPtr\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-    AcpiTableNew = (VOID *)(UINTN)BufferPtr;\r
-    CopyMem (AcpiTableNew, AcpiTableOri, TableLen);\r
-  } else {\r
-    AcpiTableNew = AcpiTableOri;\r
-  }\r
-  //\r
-  // Change configuration table Pointer\r
-  //\r
-  *Table = AcpiTableNew;\r
-  \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-ConvertSmbiosTable (\r
-  IN OUT VOID        **Table\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Convert Smbios Table if the Location of the SMBios Table is lower than Addres 0x100000\r
-  Assumption here:\r
-   As in legacy Bios, Smbios table is required to place in E/F Seg, \r
-   So here we just check if the range is F seg, \r
-   and if Not, assume the Memory type is EfiACPIMemoryNVS/EfiRuntimeServicesData\r
-Arguments:\r
-  Table     - pointer to the table\r
-\r
-Returns:\r
-  EFI_SUCEESS - Convert Table successfully\r
-  Other       - Failed\r
-\r
---*/\r
-{\r
-  SMBIOS_TABLE_ENTRY_POINT *SmbiosTableNew;\r
-  SMBIOS_TABLE_ENTRY_POINT *SmbiosTableOri;\r
-  EFI_STATUS               Status;\r
-  UINT32                   SmbiosEntryLen;\r
-  UINT32                   BufferLen;\r
-  EFI_PHYSICAL_ADDRESS     BufferPtr;\r
-  \r
-  SmbiosTableNew  = NULL;\r
-  SmbiosTableOri  = NULL;\r
-  \r
-  //\r
-  // Get Smibos configuration Table \r
-  //\r
-  SmbiosTableOri =  (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)(*(UINT64*)(*Table));\r
-  \r
-  if ((SmbiosTableOri == NULL) ||\r
-      ((UINTN)SmbiosTableOri > 0x100000) ||\r
-      ((UINTN)SmbiosTableOri < 0xF0000)){\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Relocate the Smibos memory\r
-  //\r
-  BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;\r
-  if (SmbiosTableOri->SmbiosBcdRevision != 0x21) {\r
-    SmbiosEntryLen  = SmbiosTableOri->EntryPointLength;\r
-  } else {\r
-    //\r
-    // According to Smbios Spec 2.4, we should set entry point length as 0x1F if version is 2.1\r
-    //\r
-    SmbiosEntryLen = 0x1F;\r
-  }\r
-  BufferLen = SmbiosEntryLen + SYS_TABLE_PAD(SmbiosEntryLen) + SmbiosTableOri->TableLength;\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiACPIMemoryNVS,\r
-                  EFI_SIZE_TO_PAGES(BufferLen),\r
-                  &BufferPtr\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  SmbiosTableNew = (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)BufferPtr;\r
-  CopyMem (\r
-    SmbiosTableNew, \r
-    SmbiosTableOri,\r
-    SmbiosEntryLen\r
-    );\r
-  // \r
-  // Get Smbios Structure table address, and make sure the start address is 32-bit align\r
-  //\r
-  BufferPtr += SmbiosEntryLen + SYS_TABLE_PAD(SmbiosEntryLen);\r
-  CopyMem (\r
-    (VOID *)(UINTN)BufferPtr, \r
-    (VOID *)(UINTN)(SmbiosTableOri->TableAddress),\r
-    SmbiosTableOri->TableLength\r
-    );\r
-  SmbiosTableNew->TableAddress = (UINT32)BufferPtr;\r
-  SmbiosTableNew->IntermediateChecksum = 0;\r
-  SmbiosTableNew->IntermediateChecksum = \r
-          CalculateCheckSum8 ((UINT8*)SmbiosTableNew + 0x10, SmbiosEntryLen -0x10);\r
-  //\r
-  // Change the SMBIOS pointer\r
-  //\r
-  *Table = SmbiosTableNew;\r
-  \r
-  return EFI_SUCCESS;  \r
-} \r
-\r
-EFI_STATUS\r
-ConvertMpsTable (\r
-  IN OUT VOID          **Table\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Convert MP Table if the Location of the SMBios Table is lower than Addres 0x100000\r
-  Assumption here:\r
-   As in legacy Bios, MP table is required to place in E/F Seg, \r
-   So here we just check if the range is E/F seg, \r
-   and if Not, assume the Memory type is EfiACPIMemoryNVS/EfiRuntimeServicesData\r
-Arguments:\r
-  Table     - pointer to the table\r
-\r
-Returns:\r
-  EFI_SUCEESS - Convert Table successfully\r
-  Other       - Failed\r
-\r
---*/\r
-{\r
-  UINT32                                       Data32;\r
-  UINT32                                       FPLength;\r
-  EFI_LEGACY_MP_TABLE_FLOATING_POINTER         *MpsFloatingPointerOri;\r
-  EFI_LEGACY_MP_TABLE_FLOATING_POINTER         *MpsFloatingPointerNew;\r
-  EFI_LEGACY_MP_TABLE_HEADER                   *MpsTableOri;\r
-  EFI_LEGACY_MP_TABLE_HEADER                   *MpsTableNew;\r
-  VOID                                         *OemTableOri;\r
-  VOID                                         *OemTableNew;\r
-  EFI_STATUS                                   Status;\r
-  EFI_PHYSICAL_ADDRESS                         BufferPtr;\r
-  \r
-  //\r
-  // Get MP configuration Table \r
-  //\r
-  MpsFloatingPointerOri = (EFI_LEGACY_MP_TABLE_FLOATING_POINTER *)(UINTN)(*(UINT64*)(*Table));\r
-  if (!(((UINTN)MpsFloatingPointerOri <= 0x100000) && \r
-        ((UINTN)MpsFloatingPointerOri >= 0xF0000))){\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Get Floating pointer structure length\r
-  //\r
-  FPLength = MpsFloatingPointerOri->Length * 16;\r
-  Data32   = FPLength + SYS_TABLE_PAD (FPLength);\r
-  MpsTableOri = (EFI_LEGACY_MP_TABLE_HEADER *)(UINTN)(MpsFloatingPointerOri->PhysicalAddress);\r
-  if (MpsTableOri != NULL) {\r
-    Data32 += MpsTableOri->BaseTableLength;\r
-    Data32 += MpsTableOri->ExtendedTableLength;\r
-    if (MpsTableOri->OemTablePointer != 0x00) {\r
-      Data32 += SYS_TABLE_PAD (Data32);\r
-      Data32 += MpsTableOri->OemTableSize;\r
-    }\r
-  } else {\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Relocate memory\r
-  //\r
-  BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiACPIMemoryNVS,\r
-                  EFI_SIZE_TO_PAGES(Data32),\r
-                  &BufferPtr\r
-                  );\r
-  ASSERT_EFI_ERROR (Status); \r
-  MpsFloatingPointerNew = (EFI_LEGACY_MP_TABLE_FLOATING_POINTER *)(UINTN)BufferPtr;\r
-  CopyMem (MpsFloatingPointerNew, MpsFloatingPointerOri, FPLength);\r
-  //\r
-  // If Mp Table exists\r
-  //\r
-  if (MpsTableOri != NULL) {\r
-    //\r
-    // Get Mps table length, including Ext table\r
-    //\r
-    BufferPtr = BufferPtr + FPLength + SYS_TABLE_PAD (FPLength);\r
-    MpsTableNew = (EFI_LEGACY_MP_TABLE_HEADER *)(UINTN)BufferPtr;\r
-    CopyMem (MpsTableNew, MpsTableOri, MpsTableOri->BaseTableLength + MpsTableOri->ExtendedTableLength);\r
-    \r
-    if ((MpsTableOri->OemTableSize != 0x0000) && (MpsTableOri->OemTablePointer != 0x0000)){\r
-        BufferPtr += MpsTableOri->BaseTableLength + MpsTableOri->ExtendedTableLength;\r
-        BufferPtr += SYS_TABLE_PAD (BufferPtr);\r
-        OemTableNew = (VOID *)(UINTN)BufferPtr;\r
-        OemTableOri = (VOID *)(UINTN)MpsTableOri->OemTablePointer;\r
-        CopyMem (OemTableNew, OemTableOri, MpsTableOri->OemTableSize);\r
-        MpsTableNew->OemTablePointer = (UINT32)(UINTN)OemTableNew;\r
-    }\r
-    MpsTableNew->Checksum = 0;\r
-    MpsTableNew->Checksum = CalculateCheckSum8 ((UINT8*)MpsTableNew, MpsTableOri->BaseTableLength);\r
-    MpsFloatingPointerNew->PhysicalAddress = (UINT32)(UINTN)MpsTableNew;\r
-    MpsFloatingPointerNew->Checksum = 0;\r
-    MpsFloatingPointerNew->Checksum = CalculateCheckSum8 ((UINT8*)MpsFloatingPointerNew, FPLength);\r
-  }\r
-  //\r
-  // Change the pointer\r
-  //\r
-  *Table = MpsFloatingPointerNew;\r
-  \r
-  return EFI_SUCCESS;  \r
-} \r
-  \r
-/**\r
-  Lock the ConsoleIn device in system table. All key\r
-  presses will be ignored until the Password is typed in. The only way to\r
-  disable the password is to type it in to a ConIn device.\r
-\r
-  @param  Password        Password used to lock ConIn device.\r
-\r
-  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.\r
-  @retval EFI_UNSUPPORTED Password not found\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-LockKeyboards (\r
-  IN  CHAR16    *Password\r
-  )\r
-{\r
-    return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
-  This function locks platform flash that is not allowed to be updated during normal boot path.\r
-  The flash layout is platform specific.\r
-\r
-  **/\r
-VOID\r
-EFIAPI\r
-PlatformBdsLockNonUpdatableFlash (\r
-  VOID\r
-  )\r
-{\r
-  return;\r
-}\r