ArmVirtPkg: Add kvmtool platform driver

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>
This commit is contained in:
Sami Mujawar 2020-10-02 22:13:58 +01:00 committed by mergify[bot]
parent d3095addf3
commit 39d76b2596
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,82 @@
/** @file
The KvmtoolPlatformDxe performs the platform specific initialization like:
- It decides if the firmware should expose ACPI or Device Tree-based
hardware description to the operating system.
Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Guid/VariableFormat.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/FdtClient.h>
/** Decide if the firmware should expose ACPI tables or Device Tree and
install the appropriate protocol interface.
Note: This function is derived from "ArmVirtPkg/PlatformHasAcpiDtDxe",
by dropping the word size check, and the fw_cfg check.
@param [in] ImageHandle Handle for this image.
@retval EFI_SUCCESS Success.
@retval EFI_OUT_OF_RESOURCES There was not enough memory to install the
protocols.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
PlatformHasAcpiDt (
IN EFI_HANDLE ImageHandle
)
{
if (!PcdGetBool (PcdForceNoAcpi)) {
// Expose ACPI tables
return gBS->InstallProtocolInterface (
&ImageHandle,
&gEdkiiPlatformHasAcpiGuid,
EFI_NATIVE_INTERFACE,
NULL
);
}
// Expose the Device Tree.
return gBS->InstallProtocolInterface (
&ImageHandle,
&gEdkiiPlatformHasDeviceTreeGuid,
EFI_NATIVE_INTERFACE,
NULL
);
}
/** Entry point for Kvmtool Platform Dxe
@param [in] ImageHandle Handle for this image.
@param [in] SystemTable Pointer to the EFI system table.
@retval EFI_SUCCESS Success.
@retval EFI_OUT_OF_RESOURCES There was not enough memory to install the
protocols.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
EFI_STATUS
EFIAPI
KvmtoolPlatformDxeEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
Status = PlatformHasAcpiDt (ImageHandle);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@ -0,0 +1,43 @@
## @file
# The KvmtoolPlatformDxe performs the platform specific initialization like:
# - It decides if the firmware should expose ACPI or Device Tree-based
# hardware description to the operating system.
#
# Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x0001001B
BASE_NAME = KvmtoolPlatformDxe
FILE_GUID = 7479CCCD-D721-442A-8C73-A72DBB886669
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = KvmtoolPlatformDxeEntryPoint
[Sources]
KvmtoolPlatformDxe.c
[Packages]
ArmVirtPkg/ArmVirtPkg.dec
EmbeddedPkg/EmbeddedPkg.dec
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
DebugLib
UefiBootServicesTableLib
UefiDriverEntryPoint
[Guids]
gEdkiiPlatformHasAcpiGuid ## SOMETIMES_PRODUCES ## PROTOCOL
gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL
[Pcd]
gArmVirtTokenSpaceGuid.PcdForceNoAcpi
[Depex]
TRUE