From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.16100.1594128164021639629 for ; Tue, 07 Jul 2020 06:22:44 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BA145C0A; Tue, 7 Jul 2020 06:22:43 -0700 (PDT) Received: from [192.168.1.205] (unknown [10.37.8.187]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 063793F71E; Tue, 7 Jul 2020 06:22:39 -0700 (PDT) Subject: Re: [PATCH v4 04/15] ArmVirtPkg: Add kvmtool platform driver To: Sami Mujawar , devel@edk2.groups.io Cc: leif@nuviainc.com, lersek@redhat.com, Alexandru.Elisei@arm.com, Andre.Przywara@arm.com, Matteo.Carlini@arm.com, Laura.Moretta@arm.com, nd@arm.com References: <20200707124810.50668-1-sami.mujawar@arm.com> <20200707124810.50668-5-sami.mujawar@arm.com> From: "Ard Biesheuvel" Message-ID: Date: Tue, 7 Jul 2020 16:22:36 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200707124810.50668-5-sami.mujawar@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 7/7/20 3:47 PM, Sami Mujawar wrote: > 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 > Acked-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel > --- > > Notes: > v4: > - Cleaned up include file and LibraryClasses list. [Sami] > - Missing MemoryAllocationLib here - either add it [Ard] > here, or remove it from LibraryClasses. > Ref: https://edk2.groups.io/g/devel/message/61714 > > v3: > - Don't use CpuDeadLoop()s in your drivers. [Ard] > - Returned error code instead of dead loop. [Sami] > - Installing a protocol on an image handle should not [Ard] > ever fail. So just use ASSERT_EFI_ERROR(). > - Added assert and returned status code. [Sami] > Ref: https://edk2.groups.io/g/devel/topic/74200911#59650 > > v2: > - Updated according to review comments. [Sami] > > v1: > - Add kvmtool platform driver to support loading platform [Sami] > specific information. > - Keep code to initialise the variable storage PCDs in the [Laszlo] > platform-specific FVB driver. > - Document code derived from [Laszlo] > "ArmVirtPkg/PlatformHasAcpiDtDxe" > Ref: https://edk2.groups.io/g/devel/topic/30915278#30757 > > ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c | 82 ++++++++++++++++++++ > ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf | 44 +++++++++++ > 2 files changed, 126 insertions(+) > > diff --git a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c > new file mode 100644 > index 0000000000000000000000000000000000000000..a42b64d1061dcdf8163775f66b6d2f550e481315 > --- /dev/null > +++ b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.c > @@ -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 > +#include > +#include > +#include > +#include > + > +/** 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; > +} > diff --git a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf > new file mode 100644 > index 0000000000000000000000000000000000000000..05087178cc0fa3f7b414336861b39cedec48b68a > --- /dev/null > +++ b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf > @@ -0,0 +1,44 @@ > +#/** @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 >