]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiPayloadPkg / Library / PlatformBootManagerLib / PlatformConsole.c
index a27cc552ab8bab6959d8ef9a56278a7de791e831..e92d12e991ca305b89c20aae64ed8dbf4b0fb2f7 100644 (file)
@@ -38,45 +38,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
     0 \\r
   }\r
 \r
-#define gPciRootBridge \\r
-  PNPID_DEVICE_PATH_NODE(0x0A03)\r
-\r
 #define gPnp16550ComPort \\r
   PNPID_DEVICE_PATH_NODE(0x0501)\r
 \r
 #define gPnpPs2Keyboard \\r
   PNPID_DEVICE_PATH_NODE(0x0303)\r
 \r
-#define gUartVendor \\r
-  { \\r
-    { \\r
-      HARDWARE_DEVICE_PATH, \\r
-      HW_VENDOR_DP, \\r
-      { \\r
-        (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \\r
-        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \\r
-      } \\r
-    }, \\r
-    EDKII_SERIAL_PORT_LIB_VENDOR_GUID \\r
-  }\r
-\r
-#define gUart \\r
-  { \\r
-    { \\r
-      MESSAGING_DEVICE_PATH, \\r
-      MSG_UART_DP, \\r
-      { \\r
-        (UINT8) (sizeof (UART_DEVICE_PATH)), \\r
-        (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \\r
-      } \\r
-    }, \\r
-    0, \\r
-    115200, \\r
-    8, \\r
-    1, \\r
-    1 \\r
-  }\r
-\r
 #define gPcAnsiTerminal \\r
   { \\r
     { \\r
@@ -90,76 +57,44 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
     DEVICE_PATH_MESSAGING_PC_ANSI \\r
   }\r
 \r
-ACPI_HID_DEVICE_PATH       gPnpPs2KeyboardDeviceNode  = gPnpPs2Keyboard;\r
-ACPI_HID_DEVICE_PATH       gPnp16550ComPortDeviceNode = gPnp16550ComPort;\r
-UART_DEVICE_PATH           gUartDeviceNode            = gUart;\r
-VENDOR_DEVICE_PATH         gTerminalTypeDeviceNode    = gPcAnsiTerminal;\r
-VENDOR_DEVICE_PATH         gUartDeviceVendorNode      = gUartVendor;\r
-\r
-//\r
-// Predefined platform root bridge\r
-//\r
-PLATFORM_ROOT_BRIDGE_DEVICE_PATH  gPlatformRootBridge0 = {\r
-  gPciRootBridge,\r
-  gEndEntire\r
-};\r
+ACPI_HID_DEVICE_PATH  gPnpPs2KeyboardDeviceNode  = gPnpPs2Keyboard;\r
+ACPI_HID_DEVICE_PATH  gPnp16550ComPortDeviceNode = gPnp16550ComPort;\r
+VENDOR_DEVICE_PATH    gTerminalTypeDeviceNode    = gPcAnsiTerminal;\r
 \r
-EFI_DEVICE_PATH_PROTOCOL          *gPlatformRootBridges[] = {\r
-  (EFI_DEVICE_PATH_PROTOCOL *) &gPlatformRootBridge0,\r
-  NULL\r
-};\r
-\r
-BOOLEAN       mDetectVgaOnly;\r
+BOOLEAN  mDetectDisplayOnly;\r
 \r
 /**\r
-  Add IsaKeyboard to ConIn; add IsaSerial to ConOut, ConIn, ErrOut.\r
+  Add IsaKeyboard to ConIn.\r
 \r
   @param[in] DeviceHandle  Handle of the LPC Bridge device.\r
 \r
-  @retval EFI_SUCCESS  Console devices on the LPC bridge have been added to\r
-                       ConOut, ConIn, and ErrOut.\r
-\r
+  @retval EFI_SUCCESS  IsaKeyboard on the LPC bridge have been added to ConIn.\r
   @return              Error codes, due to EFI_DEVICE_PATH_PROTOCOL missing\r
                        from DeviceHandle.\r
 **/\r
 EFI_STATUS\r
 PrepareLpcBridgeDevicePath (\r
-  IN EFI_HANDLE                DeviceHandle\r
-)\r
+  IN EFI_HANDLE  DeviceHandle\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
+  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
   EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
-\r
-  //\r
-  // Register COM1\r
-  //\r
-  DevicePath = TempDevicePath;\r
-  DevicePath = AppendDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *)NULL, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceVendorNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
-\r
-  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
-  EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
-  EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -175,19 +110,19 @@ PrepareLpcBridgeDevicePath (
 **/\r
 EFI_STATUS\r
 GetGopDevicePath (\r
-  IN  EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath\r
-)\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
+  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
@@ -198,10 +133,10 @@ GetGopDevicePath (
   TempPciDevicePath = PciDevicePath;\r
 \r
   Status = gBS->LocateDevicePath (\r
-             &gEfiDevicePathProtocolGuid,\r
-             &TempPciDevicePath,\r
-             &PciDeviceHandle\r
-           );\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &TempPciDevicePath,\r
+                  &PciDeviceHandle\r
+                  );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -209,26 +144,28 @@ GetGopDevicePath (
   gBS->ConnectController (PciDeviceHandle, NULL, NULL, FALSE);\r
 \r
   Status = gBS->LocateHandleBuffer (\r
-             ByProtocol,\r
-             &gEfiGraphicsOutputProtocolGuid,\r
-             NULL,\r
-             &GopHandleCount,\r
-             &GopHandleBuffer\r
-           );\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
+      Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *)&TempDevicePath);\r
       if (EFI_ERROR (Status)) {\r
         continue;\r
       }\r
+\r
       if (CompareMem (\r
             PciDevicePath,\r
             TempDevicePath,\r
             GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH\r
-          ) == 0) {\r
+            ) == 0)\r
+      {\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
@@ -245,6 +182,7 @@ GetGopDevicePath (
         EfiBootManagerUpdateConsoleVariable (ConOut, TempDevicePath, NULL);\r
       }\r
     }\r
+\r
     gBS->FreePool (GopHandleBuffer);\r
   }\r
 \r
@@ -262,19 +200,19 @@ GetGopDevicePath (
 **/\r
 EFI_STATUS\r
 PreparePciVgaDevicePath (\r
-  IN EFI_HANDLE                DeviceHandle\r
-)\r
+  IN EFI_HANDLE  DeviceHandle\r
+  )\r
 {\r
   EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *GopDevicePath;\r
 \r
   DevicePath = NULL;\r
-  Status = gBS->HandleProtocol (\r
-             DeviceHandle,\r
-             &gEfiDevicePathProtocolGuid,\r
-             (VOID*)&DevicePath\r
-           );\r
+  Status     = gBS->HandleProtocol (\r
+                      DeviceHandle,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      (VOID *)&DevicePath\r
+                      );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -287,50 +225,11 @@ PreparePciVgaDevicePath (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Add PCI Serial to ConOut, ConIn, ErrOut.\r
-\r
-  @param[in]  DeviceHandle - Handle of PciIo protocol.\r
-\r
-  @retval EFI_SUCCESS  - PCI Serial is added to ConOut, ConIn, and ErrOut.\r
-  @retval EFI_STATUS   - No PCI Serial device is added.\r
-\r
-**/\r
-EFI_STATUS\r
-PreparePciSerialDevicePath (\r
-  IN EFI_HANDLE                DeviceHandle\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
-  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
-  EfiBootManagerUpdateConsoleVariable (ConIn,  DevicePath, NULL);\r
-  EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   For every PCI instance execute a callback function.\r
 \r
   @param[in]  Id                 - The protocol GUID for callback\r
   @param[in]  CallBackFunction   - The callback function\r
-  @param[in]  Context    - The context of the callback\r
 \r
   @retval EFI_STATUS - Callback function failed.\r
 \r
@@ -338,29 +237,28 @@ PreparePciSerialDevicePath (
 EFI_STATUS\r
 EFIAPI\r
 VisitAllInstancesOfProtocol (\r
-  IN EFI_GUID                    *Id,\r
-  IN PROTOCOL_INSTANCE_CALLBACK  CallBackFunction,\r
-  IN VOID                        *Context\r
-)\r
+  IN EFI_GUID                           *Id,\r
+  IN SIMPLE_PROTOCOL_INSTANCE_CALLBACK  CallBackFunction\r
+  )\r
 {\r
-  EFI_STATUS                Status;\r
-  UINTN                     HandleCount;\r
-  EFI_HANDLE                *HandleBuffer;\r
-  UINTN                     Index;\r
-  VOID                      *Instance;\r
+  EFI_STATUS  Status;\r
+  UINTN       HandleCount;\r
+  EFI_HANDLE  *HandleBuffer;\r
+  UINTN       Index;\r
+  VOID        *Instance;\r
 \r
   //\r
   // Start to check all the PciIo to find all possible device\r
   //\r
-  HandleCount = 0;\r
+  HandleCount  = 0;\r
   HandleBuffer = NULL;\r
-  Status = gBS->LocateHandleBuffer (\r
-             ByProtocol,\r
-             Id,\r
-             NULL,\r
-             &HandleCount,\r
-             &HandleBuffer\r
-           );\r
+  Status       = gBS->LocateHandleBuffer (\r
+                        ByProtocol,\r
+                        Id,\r
+                        NULL,\r
+                        &HandleCount,\r
+                        &HandleBuffer\r
+                        );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -371,11 +269,10 @@ VisitAllInstancesOfProtocol (
       continue;\r
     }\r
 \r
-    Status = (*CallBackFunction) (\r
-               HandleBuffer[Index],\r
-               Instance,\r
-               Context\r
-             );\r
+    Status = (*CallBackFunction)(\r
+  HandleBuffer[Index],\r
+  Instance\r
+  );\r
   }\r
 \r
   gBS->FreePool (HandleBuffer);\r
@@ -383,115 +280,62 @@ VisitAllInstancesOfProtocol (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  For every PCI instance execute a callback function.\r
+  Do platform specific PCI Device check and add them to\r
+  ConOut, ConIn, ErrOut.\r
 \r
-  @param[in]  Handle     - The PCI device handle\r
-  @param[in]  Instance   - The instance of the PciIo protocol\r
-  @param[in]  Context    - The context of the callback\r
+  @param[in]  Handle    - Handle of PCI device instance\r
+  @param[in]  Instance  - The instance of PCI device\r
 \r
-  @retval EFI_STATUS - Callback function failed.\r
+  @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r
+  @retval EFI_STATUS - PCI Device check or Console variable update fail.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-VisitingAPciInstance (\r
+DetectAndPreparePlatformPciDevicePath (\r
   IN EFI_HANDLE  Handle,\r
-  IN VOID        *Instance,\r
-  IN VOID        *Context\r
-)\r
+  IN VOID        *Instance\r
+  )\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_PCI_IO_PROTOCOL       *PciIo;\r
-  PCI_TYPE00                Pci;\r
+  EFI_STATUS           Status;\r
+  EFI_PCI_IO_PROTOCOL  *PciIo;\r
+  PCI_TYPE00           Pci;\r
 \r
-  PciIo = (EFI_PCI_IO_PROTOCOL*) Instance;\r
+  PciIo = (EFI_PCI_IO_PROTOCOL *)Instance;\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
+                        PciIo,\r
+                        EfiPciIoWidthUint32,\r
+                        0,\r
+                        sizeof (Pci) / sizeof (UINT32),\r
+                        &Pci\r
+                        );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN) Context) (\r
-           Handle,\r
-           PciIo,\r
-           &Pci\r
-         );\r
-\r
-}\r
-\r
-\r
-/**\r
-  For every PCI instance execute a callback function.\r
-\r
-  @param[in]  CallBackFunction - Callback function pointer\r
-\r
-  @retval EFI_STATUS - Callback function failed.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VisitAllPciInstances (\r
-  IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction\r
-)\r
-{\r
-  return VisitAllInstancesOfProtocol (\r
-           &gEfiPciIoProtocolGuid,\r
-           VisitingAPciInstance,\r
-           (VOID*)(UINTN) CallBackFunction\r
-         );\r
-}\r
-\r
-\r
-/**\r
-  Do platform specific PCI Device check and add them to\r
-  ConOut, ConIn, ErrOut.\r
-\r
-  @param[in]  Handle - Handle of PCI device instance\r
-  @param[in]  PciIo - PCI IO protocol instance\r
-  @param[in]  Pci - PCI Header register block\r
-\r
-  @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r
-  @retval EFI_STATUS - PCI Device check or Console variable update fail.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DetectAndPreparePlatformPciDevicePath (\r
-  IN EFI_HANDLE           Handle,\r
-  IN EFI_PCI_IO_PROTOCOL  *PciIo,\r
-  IN PCI_TYPE00           *Pci\r
-)\r
-{\r
-  EFI_STATUS                Status;\r
-\r
   Status = PciIo->Attributes (\r
-             PciIo,\r
-             EfiPciIoAttributeOperationEnable,\r
-             EFI_PCI_DEVICE_ENABLE,\r
-             NULL\r
-           );\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationEnable,\r
+                    EFI_PCI_DEVICE_ENABLE,\r
+                    NULL\r
+                    );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  if (!mDetectVgaOnly) {\r
+  if (!mDetectDisplayOnly) {\r
     //\r
     // Here we decide whether it is LPC Bridge\r
     //\r
-    if ((IS_PCI_LPC (Pci)) ||\r
-        ((IS_PCI_ISA_PDECODE (Pci)) &&\r
-         (Pci->Hdr.VendorId == 0x8086)\r
+    if ((IS_PCI_LPC (&Pci)) ||\r
+        ((IS_PCI_ISA_PDECODE (&Pci)) &&\r
+         (Pci.Hdr.VendorId == 0x8086)\r
+        )\r
         )\r
-       ) {\r
+    {\r
       //\r
       // Add IsaKeyboard to ConIn,\r
       // add IsaSerial to ConOut, ConIn, ErrOut\r
@@ -500,39 +344,60 @@ DetectAndPreparePlatformPciDevicePath (
       PrepareLpcBridgeDevicePath (Handle);\r
       return EFI_SUCCESS;\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 ((DEBUG_INFO, "Found PCI 16550 SERIAL device\n"));\r
-      PreparePciSerialDevicePath (Handle);\r
-      return EFI_SUCCESS;\r
-    }\r
   }\r
 \r
   //\r
-  // Here we decide which VGA device to enable in PCI bus\r
+  // Enable all display devices\r
   //\r
-  if (IS_PCI_VGA (Pci)) {\r
+  if (IS_PCI_DISPLAY (&Pci)) {\r
     //\r
     // Add them to ConOut.\r
     //\r
-    DEBUG ((DEBUG_INFO, "Found PCI VGA device\n"));\r
-    PreparePciVgaDevicePath (Handle);\r
+    DEBUG ((DEBUG_INFO, "Found PCI Display device\n"));\r
+    EfiBootManagerConnectVideoController (Handle);\r
     return EFI_SUCCESS;\r
   }\r
 \r
   return Status;\r
 }\r
 \r
+/**\r
+  For every Serial Io instance, add it to ConOut, ConIn, ErrOut.\r
+\r
+  @param[in]  Handle     - The Serial Io device handle\r
+  @param[in]  Instance   - The instance of the SerialIo protocol\r
+\r
+  @retval EFI_STATUS - Callback function failed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AddDevicePathForOneSerialIoInstance (\r
+  IN EFI_HANDLE  Handle,\r
+  IN VOID        *Instance\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  DevicePath = NULL;\r
+  Status     = gBS->HandleProtocol (\r
+                      Handle,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      (VOID *)&DevicePath\r
+                      );\r
+  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
+\r
+  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
+  return Status;\r
+}\r
 \r
 /**\r
   Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
 \r
-  @param[in]  DetectVgaOnly - Only detect VGA device if it's TRUE.\r
+  @param[in]  DetectDisplayOnly - Only detect display device if it's TRUE.\r
 \r
   @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.\r
   @retval EFI_STATUS - PCI Device check or Console variable update fail.\r
@@ -540,48 +405,50 @@ DetectAndPreparePlatformPciDevicePath (
 **/\r
 EFI_STATUS\r
 DetectAndPreparePlatformPciDevicePaths (\r
-  BOOLEAN DetectVgaOnly\r
-)\r
+  BOOLEAN  DetectDisplayOnly\r
+  )\r
 {\r
-  mDetectVgaOnly = DetectVgaOnly;\r
+  EFI_STATUS  Status;\r
+\r
+  mDetectDisplayOnly = DetectDisplayOnly;\r
 \r
   EfiBootManagerUpdateConsoleVariable (\r
     ConIn,\r
-    (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath,\r
+    (EFI_DEVICE_PATH_PROTOCOL *)&gUsbClassKeyboardDevicePath,\r
     NULL\r
     );\r
 \r
-  return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath);\r
-}\r
+  VisitAllInstancesOfProtocol (\r
+    &gEfiSerialIoProtocolGuid,\r
+    AddDevicePathForOneSerialIoInstance\r
+    );\r
 \r
+  Status = VisitAllInstancesOfProtocol (\r
+             &gEfiPciIoProtocolGuid,\r
+             DetectAndPreparePlatformPciDevicePath\r
+             );\r
+  return Status;\r
+}\r
 \r
 /**\r
-  The function will connect root bridge\r
+  The function will connect one root bridge\r
+\r
+  @param[in]  Handle     - The root bridge handle\r
+  @param[in]  Instance   - The instance of the root bridge\r
 \r
-   @return EFI_SUCCESS      Connect RootBridge successfully.\r
+  @return EFI_SUCCESS      Connect RootBridge successfully.\r
 \r
 **/\r
 EFI_STATUS\r
-ConnectRootBridge (\r
-  VOID\r
-)\r
+EFIAPI\r
+ConnectOneRootBridge (\r
+  IN EFI_HANDLE  Handle,\r
+  IN VOID        *Instance\r
+  )\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_HANDLE                RootHandle;\r
+  EFI_STATUS  Status;\r
 \r
-  //\r
-  // Make all the PCI_IO protocols on PCI Seg 0 show up\r
-  //\r
-  Status = gBS->LocateDevicePath (\r
-             &gEfiDevicePathProtocolGuid,\r
-             &gPlatformRootBridges[0],\r
-             &RootHandle\r
-           );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->ConnectController (RootHandle, NULL, NULL, FALSE);\r
+  Status = gBS->ConnectController (Handle, NULL, NULL, FALSE);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -598,18 +465,15 @@ VOID
 EFIAPI\r
 PlatformConsoleInit (\r
   VOID\r
-)\r
+  )\r
 {\r
-  gUartDeviceNode.BaudRate = PcdGet64 (PcdUartDefaultBaudRate);\r
-  gUartDeviceNode.DataBits = PcdGet8 (PcdUartDefaultDataBits);\r
-  gUartDeviceNode.Parity   = PcdGet8 (PcdUartDefaultParity);\r
-  gUartDeviceNode.StopBits = PcdGet8 (PcdUartDefaultStopBits);\r
-\r
-  ConnectRootBridge ();\r
+  VisitAllInstancesOfProtocol (\r
+    &gEfiPciRootBridgeIoProtocolGuid,\r
+    ConnectOneRootBridge\r
+    );\r
 \r
   //\r
   // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
   //\r
   DetectAndPreparePlatformPciDevicePaths (FALSE);\r
-\r
 }\r