]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtualizationPkg: PlatformIntelBdsLib: detect consoles dynamically
authorLaszlo Ersek <lersek@redhat.com>
Wed, 25 Feb 2015 17:54:05 +0000 (17:54 +0000)
committerlersek <lersek@Edk2>
Wed, 25 Feb 2015 17:54:05 +0000 (17:54 +0000)
Detect the video displays dynamically, and add them to the console and
error output variables.

Add a short-form, "wild card" USB_CLASS_DEVICE_PATH to the console input
variable, which causes the USB keyboard to be handled automatically.

Add the fixed location serial console to all of the console input, console
output, and error output variables.

This patch enables QEMU users to drop "addr=..." PCI address
specifications from the -device options (or to use whatever addresses they
like). For example, the following works:

  -device VGA \
  \
  -device ich9-usb-ehci1,multifunction=on,id=ehci \
  -device ich9-usb-uhci1,multifunction=on,masterbus=ehci.0,firstport=0 \
  -device ich9-usb-uhci2,multifunction=on,masterbus=ehci.0,firstport=2 \
  -device ich9-usb-uhci3,multifunction=on,masterbus=ehci.0,firstport=4 \
  -device usb-kbd,bus=ehci.0

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16924 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf

index 16c1d83089eed984aa75d1113126cb22ea39de68..598b0edb2f62088fd01c79589591bc1a50832b9d 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
   Implementation for PlatformBdsLib library class interfaces.\r
 \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
 \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
+#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }\r
+\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
 //\r
@@ -35,6 +135,207 @@ PlatformBdsInit (
 {\r
 }\r
 \r
+\r
+/**\r
+  Check if the handle satisfies a particular condition.\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
+  @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
+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
+  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
+  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 (Filter == NULL || Filter (Handles[Idx], DevicePathText)) {\r
+      Process (Handles[Idx], DevicePathText);\r
+    }\r
+\r
+    if (DevicePathText != Fallback) {\r
+      FreePool (DevicePathText);\r
+    }\r
+  }\r
+  gBS->FreePool (Handles);\r
+}\r
+\r
+\r
+/**\r
+  This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.\r
+**/\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_PCI_IO_PROTOCOL *PciIo;\r
+  PCI_TYPE00          Pci;\r
+\r
+  Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid,\r
+                  (VOID**)&PciIo);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // This is not an error worth reporting.\r
+    //\r
+    return FALSE;\r
+  }\r
+\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
+  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
+EFIAPI\r
+Connect (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\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
+\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
+EFIAPI\r
+AddOutput (\r
+  IN EFI_HANDLE   Handle,\r
+  IN CONST CHAR16 *ReportText\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
+  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
+  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
+  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
@@ -55,6 +356,50 @@ PlatformBdsPolicyBehavior (
   IN BASEM_MEMORY_TEST               BaseMemoryTest\r
   )\r
 {\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
+  //\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
+  // Add the hardcoded short-form USB keyboard device path to ConIn.\r
+  //\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
+  // Connect the rest of the devices.\r
+  //\r
   BdsLibConnectAll ();\r
 \r
   //\r
index c4e5d609ab6b62ab760b2753248633b7c6616169..c9c5e6f2c784d4dcf9425b98e2ee40d3e1da18b0 100644 (file)
@@ -1,6 +1,7 @@
 ## @file\r
 #  Implementation for PlatformBdsLib library class interfaces.\r
 #\r
+#  Copyright (C) 2015, Red Hat, Inc.\r
 #  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
 #  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #\r
   UefiBootServicesTableLib\r
   UefiRuntimeServicesTableLib\r
 \r
+[FixedPcd]\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits\r
+\r
 [Guids]\r
   gEfiFileInfoGuid\r
   gEfiFileSystemInfoGuid\r
@@ -60,5 +67,7 @@
 \r
 [Protocols]\r
   gEfiDevicePathProtocolGuid\r
+  gEfiGraphicsOutputProtocolGuid\r
   gEfiLoadedImageProtocolGuid\r
+  gEfiPciRootBridgeIoProtocolGuid\r
   gEfiSimpleFileSystemProtocolGuid\r