]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
MdeModulePkg/UfsPciHcDxe: Fix EBC build error
[mirror_edk2.git] / ArmPlatformPkg / ArmVirtualizationPkg / Library / PlatformIntelBdsLib / IntelBdsPlatform.c
index 6fea2b0aebfd4634356717dae35b9d4b3fe780c4..499cce5dcde68f72fec16ff0bb3d4a389bbfe281 100644 (file)
 /** @file\r
+  Implementation for PlatformBdsLib library class interfaces.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
-Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (C) 2015, Red Hat, Inc.\r
+  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
 \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
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  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
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
+#include <IndustryStandard/Pci22.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PlatformBdsLib.h>\r
+#include <Library/QemuBootOrderLib.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+#include <Protocol/PciIo.h>\r
+#include <Protocol/PciRootBridgeIo.h>\r
+\r
 #include "IntelBdsPlatform.h"\r
 \r
-#include <Library/QemuBootOrderLib.h>\r
+#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }\r
 \r
-///\r
-/// Predefined platform default time out value\r
-///\r
-UINT16                      gPlatformBootTimeOutDefault;\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-PlatformIntelBdsConstructor (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
-  )\r
-{\r
-  gPlatformBootTimeOutDefault = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);\r
-  return EFI_SUCCESS;\r
-}\r
+#pragma pack (1)\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH         SerialDxe;\r
+  UART_DEVICE_PATH           Uart;\r
+  VENDOR_DEFINED_DEVICE_PATH Vt100;\r
+  EFI_DEVICE_PATH_PROTOCOL   End;\r
+} PLATFORM_SERIAL_CONSOLE;\r
+#pragma pack ()\r
+\r
+#define SERIAL_DXE_FILE_GUID { \\r
+          0xD3987D4B, 0x971A, 0x435F, \\r
+          { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \\r
+          }\r
+\r
+STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {\r
+  //\r
+  // VENDOR_DEVICE_PATH SerialDxe\r
+  //\r
+  {\r
+    { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },\r
+    SERIAL_DXE_FILE_GUID\r
+  },\r
+\r
+  //\r
+  // UART_DEVICE_PATH Uart\r
+  //\r
+  {\r
+    { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) },\r
+    0,                                      // Reserved\r
+    FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate\r
+    FixedPcdGet8 (PcdUartDefaultDataBits),  // DataBits\r
+    FixedPcdGet8 (PcdUartDefaultParity),    // Parity\r
+    FixedPcdGet8 (PcdUartDefaultStopBits)   // StopBits\r
+  },\r
+\r
+  //\r
+  // VENDOR_DEFINED_DEVICE_PATH Vt100\r
+  //\r
+  {\r
+    {\r
+      MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,\r
+      DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)\r
+    },\r
+    EFI_VT_100_GUID\r
+  },\r
+\r
+  //\r
+  // EFI_DEVICE_PATH_PROTOCOL End\r
+  //\r
+  {\r
+    END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)\r
+  }\r
+};\r
+\r
+\r
+#pragma pack (1)\r
+typedef struct {\r
+  USB_CLASS_DEVICE_PATH    Keyboard;\r
+  EFI_DEVICE_PATH_PROTOCOL End;\r
+} PLATFORM_USB_KEYBOARD;\r
+#pragma pack ()\r
+\r
+STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {\r
+  //\r
+  // USB_CLASS_DEVICE_PATH Keyboard\r
+  //\r
+  {\r
+    {\r
+      MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,\r
+      DP_NODE_LEN (USB_CLASS_DEVICE_PATH)\r
+    },\r
+    0xFFFF, // VendorId: any\r
+    0xFFFF, // ProductId: any\r
+    3,      // DeviceClass: HID\r
+    1,      // DeviceSubClass: boot\r
+    1       // DeviceProtocol: keyboard\r
+  },\r
+\r
+  //\r
+  // EFI_DEVICE_PATH_PROTOCOL End\r
+  //\r
+  {\r
+    END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)\r
+  }\r
+};\r
+\r
 \r
 //\r
 // BDS Platform Functions\r
@@ -49,237 +135,207 @@ PlatformBdsInit (
 {\r
 }\r
 \r
-STATIC\r
-EFI_STATUS\r
-GetConsoleDevicePathFromVariable (\r
-  IN  CHAR16*             ConsoleVarName,\r
-  IN  CHAR16*             DefaultConsolePaths,\r
-  OUT EFI_DEVICE_PATH**   DevicePaths\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-  UINTN                     Size;\r
-  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;\r
-  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;\r
-  CHAR16*                   DevicePathStr;\r
-  CHAR16*                   NextDevicePathStr;\r
-  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;\r
-\r
-  Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);\r
-  if (EFI_ERROR (Status)) {\r
-    // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)\r
-    if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {\r
-      *DevicePaths = NULL;\r
-      return EFI_SUCCESS;\r
-    }\r
 \r
-    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    DevicePathInstances = NULL;\r
-\r
-    // Extract the Device Path instances from the multi-device path string\r
-    while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {\r
-      NextDevicePathStr = StrStr (DefaultConsolePaths, L";");\r
-      if (NextDevicePathStr == NULL) {\r
-        DevicePathStr = DefaultConsolePaths;\r
-        DefaultConsolePaths = NULL;\r
-      } else {\r
-        DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof (CHAR16), DefaultConsolePaths);\r
-        *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';\r
-        DefaultConsolePaths = NextDevicePathStr;\r
-        if (DefaultConsolePaths[0] == L';') {\r
-          DefaultConsolePaths++;\r
-        }\r
-      }\r
-\r
-      DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);\r
-      ASSERT (DevicePathInstance != NULL);\r
-      DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);\r
-\r
-      if (NextDevicePathStr != NULL) {\r
-        FreePool (DevicePathStr);\r
-      }\r
-      FreePool (DevicePathInstance);\r
-    }\r
+/**\r
+  Check if the handle satisfies a particular condition.\r
 \r
-    // Set the environment variable with this device path multi-instances\r
-    Size = GetDevicePathSize (DevicePathInstances);\r
-    if (Size > 0) {\r
-      gRT->SetVariable (\r
-          ConsoleVarName,\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-          Size,\r
-          DevicePathInstances\r
-          );\r
-    } else {\r
-      Status = EFI_INVALID_PARAMETER;\r
-    }\r
-  }\r
+  @param[in] Handle      The handle to check.\r
+  @param[in] ReportText  A caller-allocated string passed in for reporting\r
+                         purposes. It must never be NULL.\r
 \r
-  if (!EFI_ERROR (Status)) {\r
-    *DevicePaths = DevicePathInstances;\r
-  }\r
-  return Status;\r
-}\r
+  @retval TRUE   The condition is satisfied.\r
+  @retval FALSE  Otherwise. This includes the case when the condition could not\r
+                 be fully evaluated due to an error.\r
+**/\r
+typedef\r
+BOOLEAN\r
+(EFIAPI *FILTER_FUNCTION) (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\r
+  );\r
+\r
+\r
+/**\r
+  Process a handle.\r
+\r
+  @param[in] Handle      The handle to process.\r
+  @param[in] ReportText  A caller-allocated string passed in for reporting\r
+                         purposes. It must never be NULL.\r
+**/\r
+typedef\r
+VOID\r
+(EFIAPI *CALLBACK_FUNCTION)  (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\r
+  );\r
+\r
+/**\r
+  Locate all handles that carry the specified protocol, filter them with a\r
+  callback function, and pass each handle that passes the filter to another\r
+  callback.\r
 \r
+  @param[in] ProtocolGuid  The protocol to look for.\r
+\r
+  @param[in] Filter        The filter function to pass each handle to. If this\r
+                           parameter is NULL, then all handles are processed.\r
+\r
+  @param[in] Process       The callback function to pass each handle to that\r
+                           clears the filter.\r
+**/\r
 STATIC\r
-EFI_STATUS\r
-InitializeConsolePipe (\r
-  IN EFI_DEVICE_PATH    *ConsoleDevicePaths,\r
-  IN EFI_GUID           *Protocol,\r
-  OUT EFI_HANDLE        *Handle,\r
-  OUT VOID*             *Interface\r
+VOID\r
+FilterAndProcess (\r
+  IN EFI_GUID          *ProtocolGuid,\r
+  IN FILTER_FUNCTION   Filter         OPTIONAL,\r
+  IN CALLBACK_FUNCTION Process\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  UINTN                     Size;\r
-  UINTN                     NoHandles;\r
-  EFI_HANDLE                *Buffer;\r
-  EFI_DEVICE_PATH_PROTOCOL* DevicePath;\r
-\r
-  // Connect all the Device Path Consoles\r
-  while (ConsoleDevicePaths != NULL) {\r
-    DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);\r
-\r
-    Status = BdsConnectDevicePath (DevicePath, Handle, NULL);\r
-    DEBUG_CODE_BEGIN ();\r
-      if (EFI_ERROR (Status)) {\r
-        // We convert back to the text representation of the device Path\r
-        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
-        CHAR16* DevicePathTxt;\r
-        EFI_STATUS Status;\r
-\r
-        Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
-        if (!EFI_ERROR (Status)) {\r
-          DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);\r
-\r
-          DEBUG ((EFI_D_ERROR, "Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));\r
-\r
-          FreePool (DevicePathTxt);\r
-        }\r
-      }\r
-    DEBUG_CODE_END ();\r
-\r
-    // If the console splitter driver is not supported by the platform then use the first Device Path\r
-    // instance for the console interface.\r
-    if (!EFI_ERROR (Status) && (*Interface == NULL)) {\r
-      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
-    }\r
+  EFI_STATUS Status;\r
+  EFI_HANDLE *Handles;\r
+  UINTN      NoHandles;\r
+  UINTN      Idx;\r
+\r
+  Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid,\r
+                  NULL /* SearchKey */, &NoHandles, &Handles);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // This is not an error, just an informative condition.\r
+    //\r
+    DEBUG ((EFI_D_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid,\r
+      Status));\r
+    return;\r
   }\r
 \r
-  // No Device Path has been defined for this console interface. We take the first protocol implementation\r
-  if (*Interface == NULL) {\r
-    Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
-    if (EFI_ERROR (Status)) {\r
-      BdsConnectAllDrivers ();\r
-      Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
+  ASSERT (NoHandles > 0);\r
+  for (Idx = 0; Idx < NoHandles; ++Idx) {\r
+    CHAR16        *DevicePathText;\r
+    STATIC CHAR16 Fallback[] = L"<device path unavailable>";\r
+\r
+    //\r
+    // The ConvertDevicePathToText() function handles NULL input transparently.\r
+    //\r
+    DevicePathText = ConvertDevicePathToText (\r
+                       DevicePathFromHandle (Handles[Idx]),\r
+                       FALSE, // DisplayOnly\r
+                       FALSE  // AllowShortcuts\r
+                       );\r
+    if (DevicePathText == NULL) {\r
+      DevicePathText = Fallback;\r
     }\r
 \r
-    if (!EFI_ERROR (Status)) {\r
-      *Handle = Buffer[0];\r
-      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
-      ASSERT_EFI_ERROR (Status);\r
+    if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) {\r
+      Process (Handles[Idx], DevicePathText);\r
     }\r
-    FreePool (Buffer);\r
-  } else {\r
-    Status = EFI_SUCCESS;\r
-  }\r
 \r
-  return Status;\r
+    if (DevicePathText != Fallback) {\r
+      FreePool (DevicePathText);\r
+    }\r
+  }\r
+  gBS->FreePool (Handles);\r
 }\r
 \r
-/**\r
-  Connect the predefined platform default console device. Always try to find\r
-  and enable the vga device if have.\r
-\r
-  @param PlatformConsole          Predefined platform default console device array.\r
-\r
-  @retval EFI_SUCCESS             Success connect at least one ConIn and ConOut\r
-                                  device, there must have one ConOut device is\r
-                                  active vga device.\r
-  @return Return the status of BdsLibConnectAllDefaultConsoles ()\r
 \r
+/**\r
+  This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.\r
 **/\r
-EFI_STATUS\r
-PlatformBdsConnectConsole (\r
-  VOID\r
+STATIC\r
+BOOLEAN\r
+EFIAPI\r
+IsPciDisplay (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH*          ConOutDevicePaths;\r
-  EFI_DEVICE_PATH*          ConInDevicePaths;\r
-  EFI_DEVICE_PATH*          ConErrDevicePaths;\r
-\r
-  // By getting the Console Device Paths from the environment variables before initializing the console pipe, we\r
-  // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface\r
-  // of newly installed console drivers\r
-  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr (PcdDefaultConOutPaths), &ConOutDevicePaths);\r
-  ASSERT_EFI_ERROR (Status);\r
-  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr (PcdDefaultConInPaths), &ConInDevicePaths);\r
-  ASSERT_EFI_ERROR (Status);\r
-  Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr (PcdDefaultConOutPaths), &ConErrDevicePaths);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  // Initialize the Consoles\r
-  Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);\r
-  ASSERT_EFI_ERROR (Status);\r
-  Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);\r
-  ASSERT_EFI_ERROR (Status);\r
-  Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);\r
+  EFI_STATUS          Status;\r
+  EFI_PCI_IO_PROTOCOL *PciIo;\r
+  PCI_TYPE00          Pci;\r
+\r
+  Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid,\r
+                  (VOID**)&PciIo);\r
   if (EFI_ERROR (Status)) {\r
-    // In case of error, we reuse the console output for the error output\r
-    gST->StandardErrorHandle = gST->ConsoleOutHandle;\r
-    gST->StdErr = gST->ConOut;\r
+    //\r
+    // This is not an error worth reporting.\r
+    //\r
+    return FALSE;\r
   }\r
 \r
-  return Status;\r
+  Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */,\r
+                        sizeof Pci / sizeof (UINT32), &Pci);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status));\r
+    return FALSE;\r
+  }\r
+\r
+  return IS_PCI_DISPLAY (&Pci);\r
 }\r
 \r
+\r
 /**\r
-  Connect with predefined platform connect sequence,\r
-  the OEM/IBV can customize with their own connect sequence.\r
+  This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking\r
+  the matching driver to produce all first-level child handles.\r
 **/\r
+STATIC\r
 VOID\r
-PlatformBdsConnectSequence (\r
-  VOID\r
+EFIAPI\r
+Connect (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\r
   )\r
 {\r
-}\r
+  EFI_STATUS Status;\r
 \r
-/**\r
-  Load the predefined driver option, OEM/IBV can customize this\r
-  to load their own drivers\r
+  Status = gBS->ConnectController (\r
+                  Handle, // ControllerHandle\r
+                  NULL,   // DriverImageHandle\r
+                  NULL,   // RemainingDevicePath -- produce all children\r
+                  FALSE   // Recursive\r
+                  );\r
+  DEBUG ((EFI_ERROR (Status) ? EFI_D_ERROR : EFI_D_VERBOSE, "%a: %s: %r\n",\r
+    __FUNCTION__, ReportText, Status));\r
+}\r
 \r
-  @param BdsDriverLists  - The header of the driver option link list.\r
 \r
+/**\r
+  This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the\r
+  handle, and adds it to ConOut and ErrOut.\r
 **/\r
+STATIC\r
 VOID\r
-PlatformBdsGetDriverOption (\r
-  IN OUT LIST_ENTRY              *BdsDriverLists\r
+EFIAPI\r
+AddOutput (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\r
   )\r
 {\r
-}\r
+  EFI_STATUS               Status;\r
+  EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+\r
+  DevicePath = DevicePathFromHandle (Handle);\r
+  if (DevicePath == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "%a: %s: handle %p: device path not found\n",\r
+      __FUNCTION__, ReportText, Handle));\r
+    return;\r
+  }\r
 \r
-/**\r
-  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
-  can customize this function to support specific platform diagnostic.\r
+  Status = BdsLibUpdateConsoleVariable (L"ConOut", DevicePath, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__,\r
+      ReportText, Status));\r
+    return;\r
+  }\r
 \r
-  @param MemoryTestLevel  The memory test intensive level\r
-  @param QuietBoot        Indicate if need to enable the quiet boot\r
-  @param BaseMemoryTest   A pointer to BdsMemoryTest()\r
+  Status = BdsLibUpdateConsoleVariable (L"ErrOut", DevicePath, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__,\r
+      ReportText, Status));\r
+    return;\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
+  DEBUG ((EFI_D_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__,\r
+    ReportText));\r
 }\r
 \r
+\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
@@ -300,19 +356,66 @@ PlatformBdsPolicyBehavior (
   IN BASEM_MEMORY_TEST               BaseMemoryTest\r
   )\r
 {\r
-  EFI_STATUS Status;\r
+  //\r
+  // Locate the PCI root bridges and make the PCI bus driver connect each,\r
+  // non-recursively. This will produce a number of child handles with PciIo on\r
+  // them.\r
+  //\r
+  FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect);\r
+\r
+  //\r
+  // Find all display class PCI devices (using the handles from the previous\r
+  // step), and connect them non-recursively. This should produce a number of\r
+  // child handles with GOPs on them.\r
+  //\r
+  FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect);\r
 \r
-  Status = PlatformBdsConnectConsole ();\r
-  ASSERT_EFI_ERROR (Status);\r
+  //\r
+  // Now add the device path of all handles with GOP on them to ConOut and\r
+  // ErrOut.\r
+  //\r
+  FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput);\r
 \r
   //\r
-  // Process QEMU's -kernel command line option\r
+  // Add the hardcoded short-form USB keyboard device path to ConIn.\r
   //\r
-  TryRunningQemuKernel ();\r
+  BdsLibUpdateConsoleVariable (L"ConIn",\r
+    (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);\r
 \r
+  //\r
+  // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.\r
+  //\r
+  BdsLibUpdateConsoleVariable (L"ConIn",\r
+    (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r
+  BdsLibUpdateConsoleVariable (L"ConOut",\r
+    (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r
+  BdsLibUpdateConsoleVariable (L"ErrOut",\r
+    (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r
+\r
+  //\r
+  // Connect the consoles based on the above variables.\r
+  //\r
+  BdsLibConnectAllDefaultConsoles ();\r
+\r
+  //\r
+  // Show the splash screen.\r
+  //\r
+  EnableQuietBoot (PcdGetPtr (PcdLogoFile));\r
+\r
+  //\r
+  // Connect the rest of the devices.\r
+  //\r
   BdsLibConnectAll ();\r
-  BdsLibEnumerateAllBootOption (BootOptionList);\r
 \r
+  //\r
+  // Process QEMU's -kernel command line option. Note that the kernel booted\r
+  // this way should receive ACPI tables, which is why we connect all devices\r
+  // first (see above) -- PCI enumeration blocks ACPI table installation, if\r
+  // there is a PCI host.\r
+  //\r
+  TryRunningQemuKernel ();\r
+\r
+  BdsLibEnumerateAllBootOption (BootOptionList);\r
   SetBootOrderFromQemu (BootOptionList);\r
   //\r
   // The BootOrder variable may have changed, reload the in-memory list with\r
@@ -320,7 +423,7 @@ PlatformBdsPolicyBehavior (
   //\r
   BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
 \r
-  PlatformBdsEnterFrontPage (gPlatformBootTimeOutDefault, TRUE);\r
+  PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE);\r
 }\r
 \r
 /**\r
@@ -372,24 +475,3 @@ PlatformBdsLockNonUpdatableFlash (
 {\r
   return;\r
 }\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