]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg: Add kvmtool platform driver
authorSami Mujawar <sami.mujawar@arm.com>
Fri, 2 Oct 2020 21:13:58 +0000 (22:13 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 16 Oct 2020 17:21:04 +0000 (17:21 +0000)
Kvmtool is a virtual machine manager that enables
hosting KVM guests. It essentially provides a
virtual hardware platform for guest operating
systems.

Kvmtool hands of a device tree containing the
current hardware configuration to the firmware.

A standards-based operating system would use
ACPI to consume the platform hardware
information, while some operating systems may
prefer to use Device Tree.

The KvmtoolPlatformDxe performs the platform
actions like determining if the firmware should
expose ACPI or the Device Tree based hardware
description to the operating system.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c [new file with mode: 0644]
ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf [new file with mode: 0644]

diff --git a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c
new file mode 100644 (file)
index 0000000..a42b64d
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+\r
+  The KvmtoolPlatformDxe performs the platform specific initialization like:\r
+  - It decides if the firmware should expose ACPI or Device Tree-based\r
+    hardware description to the operating system.\r
+\r
+  Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Guid/VariableFormat.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Protocol/FdtClient.h>\r
+\r
+/** Decide if the firmware should expose ACPI tables or Device Tree and\r
+    install the appropriate protocol interface.\r
+\r
+  Note: This function is derived from "ArmVirtPkg/PlatformHasAcpiDtDxe",\r
+        by dropping the word size check, and the fw_cfg check.\r
+\r
+  @param [in]  ImageHandle  Handle for this image.\r
+\r
+  @retval EFI_SUCCESS             Success.\r
+  @retval EFI_OUT_OF_RESOURCES    There was not enough memory to install the\r
+                                  protocols.\r
+  @retval EFI_INVALID_PARAMETER   A parameter is invalid.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+PlatformHasAcpiDt (\r
+  IN EFI_HANDLE           ImageHandle\r
+  )\r
+{\r
+  if (!PcdGetBool (PcdForceNoAcpi)) {\r
+    // Expose ACPI tables\r
+    return gBS->InstallProtocolInterface (\r
+                  &ImageHandle,\r
+                  &gEdkiiPlatformHasAcpiGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  NULL\r
+                  );\r
+  }\r
+\r
+  // Expose the Device Tree.\r
+  return gBS->InstallProtocolInterface (\r
+                &ImageHandle,\r
+                &gEdkiiPlatformHasDeviceTreeGuid,\r
+                EFI_NATIVE_INTERFACE,\r
+                NULL\r
+                );\r
+}\r
+\r
+/** Entry point for Kvmtool Platform Dxe\r
+\r
+  @param [in]  ImageHandle  Handle for this image.\r
+  @param [in]  SystemTable  Pointer to the EFI system table.\r
+\r
+  @retval EFI_SUCCESS             Success.\r
+  @retval EFI_OUT_OF_RESOURCES    There was not enough memory to install the\r
+                                  protocols.\r
+  @retval EFI_INVALID_PARAMETER   A parameter is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+KvmtoolPlatformDxeEntryPoint (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                     Status;\r
+\r
+  Status = PlatformHasAcpiDt (ImageHandle);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf
new file mode 100644 (file)
index 0000000..1cf2578
--- /dev/null
@@ -0,0 +1,43 @@
+## @file\r
+#  The KvmtoolPlatformDxe performs the platform specific initialization like:\r
+#  - It decides if the firmware should expose ACPI or Device Tree-based\r
+#    hardware description to the operating system.\r
+#\r
+#  Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001001B\r
+  BASE_NAME                      = KvmtoolPlatformDxe\r
+  FILE_GUID                      = 7479CCCD-D721-442A-8C73-A72DBB886669\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = KvmtoolPlatformDxeEntryPoint\r
+\r
+[Sources]\r
+  KvmtoolPlatformDxe.c\r
+\r
+[Packages]\r
+  ArmVirtPkg/ArmVirtPkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+\r
+[Guids]\r
+  gEdkiiPlatformHasAcpiGuid       ## SOMETIMES_PRODUCES ## PROTOCOL\r
+  gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL\r
+\r
+[Pcd]\r
+  gArmVirtTokenSpaceGuid.PcdForceNoAcpi\r
+\r
+[Depex]\r
+  TRUE\r