]> 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 c93c7c99b552986b4a87a18a82e6c45bdd48e79a..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
@@ -92,33 +59,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \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
 \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
@@ -129,7 +79,6 @@ PrepareLpcBridgeDevicePath (
 {\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
@@ -141,26 +90,11 @@ PrepareLpcBridgeDevicePath (
     return Status;\r
   }\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
@@ -291,49 +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
   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
@@ -341,9 +237,8 @@ PreparePciSerialDevicePath (
 EFI_STATUS\r
 EFIAPI\r
 VisitAllInstancesOfProtocol (\r
-  IN EFI_GUID                    *Id,\r
-  IN PROTOCOL_INSTANCE_CALLBACK  CallBackFunction,\r
-  IN VOID                        *Context\r
+  IN EFI_GUID                           *Id,\r
+  IN SIMPLE_PROTOCOL_INSTANCE_CALLBACK  CallBackFunction\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -376,8 +271,7 @@ VisitAllInstancesOfProtocol (
 \r
     Status = (*CallBackFunction)(\r
   HandleBuffer[Index],\r
-  Instance,\r
-  Context\r
+  Instance\r
   );\r
   }\r
 \r
@@ -387,21 +281,21 @@ VisitAllInstancesOfProtocol (
 }\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
+  IN VOID        *Instance\r
   )\r
 {\r
   EFI_STATUS           Status;\r
@@ -424,56 +318,6 @@ VisitingAPciInstance (
     return Status;\r
   }\r
 \r
-  return (*(VISIT_PCI_INSTANCE_CALLBACK)(UINTN)Context)(\r
-  Handle,\r
-  PciIo,\r
-  &Pci\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
-  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
@@ -482,13 +326,13 @@ DetectAndPreparePlatformPciDevicePath (
                     );\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
@@ -500,39 +344,60 @@ DetectAndPreparePlatformPciDevicePath (
       PrepareLpcBridgeDevicePath (Handle);\r
       return EFI_SUCCESS;\r
     }\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,10 +405,12 @@ DetectAndPreparePlatformPciDevicePath (
 **/\r
 EFI_STATUS\r
 DetectAndPreparePlatformPciDevicePaths (\r
-  BOOLEAN  DetectVgaOnly\r
+  BOOLEAN  DetectDisplayOnly\r
   )\r
 {\r
-  mDetectVgaOnly = DetectVgaOnly;\r
+  EFI_STATUS  Status;\r
+\r
+  mDetectDisplayOnly = DetectDisplayOnly;\r
 \r
   EfiBootManagerUpdateConsoleVariable (\r
     ConIn,\r
@@ -551,36 +418,37 @@ DetectAndPreparePlatformPciDevicePaths (
     NULL\r
     );\r
 \r
-  return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath);\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
+EFIAPI\r
+ConnectOneRootBridge (\r
+  IN EFI_HANDLE  Handle,\r
+  IN VOID        *Instance\r
   )\r
 {\r
   EFI_STATUS  Status;\r
-  EFI_HANDLE  RootHandle;\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
@@ -599,12 +467,10 @@ PlatformConsoleInit (
   VOID\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