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.web09.15543.1621234257458298569 for ; Sun, 16 May 2021 23:50:57 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jianyong.wu@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 1ED2B1042; Sun, 16 May 2021 23:50:57 -0700 (PDT) Received: from entos-thunderx2-desktop.shanghai.arm.com (entos-thunderx2-desktop.shanghai.arm.com [10.169.212.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BE8723F73B; Sun, 16 May 2021 23:50:54 -0700 (PDT) From: "Jianyong Wu" To: devel@edk2.groups.io, lersek@redhat.com, ardb+tianocore@kernel.org, sami.mujawar@arm.com Cc: hao.a.wu@intel.com, justin.he@arm.com, jianyong.wu@arm.com Subject: [PATCH v2 3/5] ArmVirtPkg: enable ACPI for cloud hypervisor Date: Mon, 17 May 2021 14:50:30 +0800 Message-Id: <20210517065032.82423-4-jianyong.wu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210517065032.82423-1-jianyong.wu@arm.com> References: <20210517065032.82423-1-jianyong.wu@arm.com> The current implementation of PlatformHasAcpiDt is not a common library and is on behalf of qemu. So give a specific version for Cloud Hypervisor here. There is no device like Fw-cfg in qemu in Cloud Hypervisor, so a specific Acpi handler is introduced here. The handler implemented here is in a very simple way: firstly, aquire the Rsdp address from the PCD varaible in the top ".dsc"; secondly, get the Xsdp address from Rsdp structure; thirdly, get the Acpi tables following the Xsdp structrue and install it one by one. Signed-off-by: Jianyong Wu --- .../CloudHvAcpiPlatformDxe.inf | 51 +++++++++++++ .../CloudHvHasAcpiDtDxe.inf | 43 +++++++++++ .../CloudHvAcpiPlatformDxe/CloudHvAcpi.c | 73 +++++++++++++++++++ .../CloudHvHasAcpiDtDxe.c | 69 ++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpiPlatformDxe.inf create mode 100644 ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf create mode 100644 ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpi.c create mode 100644 ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.c diff --git a/ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpiPlatformDxe.inf b/ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpiPlatformDxe.inf new file mode 100644 index 000000000000..63c74e84eb27 --- /dev/null +++ b/ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpiPlatformDxe.inf @@ -0,0 +1,51 @@ +## @file +# OVMF ACPI Platform Driver for Cloud Hypervisor +# +# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ClhFwCfgAcpiPlatform + FILE_GUID = 6c76e407-73f2-dc1c-938f-5d6c4691ea93 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = CloudHvAcpiPlatformEntryPoint + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 +# + +[Sources] + CloudHvAcpi.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + OrderedCollectionLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED + +[Guids] + gRootBridgesConnectedEventGroupGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiRsdpBaseAddress + +[Depex] + gEfiAcpiTableProtocolGuid diff --git a/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf new file mode 100644 index 000000000000..f511a4f5064c --- /dev/null +++ b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf @@ -0,0 +1,43 @@ +## @file +# Decide whether the firmware should expose an ACPI- and/or a Device Tree-based +# hardware description to the operating system. +# +# Copyright (c) 2017, Red Hat, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = ClhPlatformHasAcpiDtDxe + FILE_GUID = 71fe72f9-6dc1-199d-5054-13b4200ee88d + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = PlatformHasAcpiDt + +[Sources] + CloudHvHasAcpiDtDxe.c + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Guids] + gEdkiiPlatformHasAcpiGuid ## SOMETIMES_PRODUCES ## PROTOCOL + gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL + +[Pcd] + gArmVirtTokenSpaceGuid.PcdForceNoAcpi + +[Depex] + gEfiVariableArchProtocolGuid diff --git a/ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpi.c b/ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpi.c new file mode 100644 index 000000000000..c2344e7b29fa --- /dev/null +++ b/ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpi.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include + +#define ACPI_ENTRY_SIZE 8 +#define XSDT_LEN 36 + +STATIC +EFI_ACPI_TABLE_PROTOCOL * +FindAcpiTableProtocol ( + VOID + ) +{ + EFI_STATUS Status; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + + Status = gBS->LocateProtocol ( + &gEfiAcpiTableProtocolGuid, + NULL, + (VOID**)&AcpiTable + ); + ASSERT_EFI_ERROR (Status); + return AcpiTable; +} + +EFI_STATUS +EFIAPI +InstallCloudHvAcpiTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ) +{ + UINTN InstalledKey, TableSize; + UINT64 Rsdp, Xsdt, table_offset, PointerValue; + EFI_STATUS Status = 0; + int size; + + Rsdp = PcdGet64 (PcdAcpiRsdpBaseAddress); + Xsdt = ((EFI_ACPI_6_3_ROOT_SYSTEM_DESCRIPTION_POINTER *)Rsdp)->XsdtAddress; + PointerValue = Xsdt; + table_offset = Xsdt; + size = ((EFI_ACPI_COMMON_HEADER *)PointerValue)->Length - XSDT_LEN; + table_offset += XSDT_LEN; + + while(!Status && size > 0) { + PointerValue = *(UINT64 *)table_offset; + TableSize = ((EFI_ACPI_COMMON_HEADER *)PointerValue)->Length; + Status = AcpiProtocol->InstallAcpiTable (AcpiProtocol, + (VOID *)(UINT64)PointerValue, TableSize, + &InstalledKey); + table_offset += ACPI_ENTRY_SIZE; + size -= ACPI_ENTRY_SIZE; + } + + return Status; +} + +EFI_STATUS +EFIAPI +CloudHvAcpiPlatformEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = InstallCloudHvAcpiTables (FindAcpiTableProtocol ()); + return Status; +} + diff --git a/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.c b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.c new file mode 100644 index 000000000000..ae07c91f5705 --- /dev/null +++ b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.c @@ -0,0 +1,69 @@ +/** @file + Decide whether the firmware should expose an ACPI- and/or a Device Tree-based + hardware description to the operating system. + + Copyright (c) 2017, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +PlatformHasAcpiDt ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // If we fail to install any of the necessary protocols below, the OS will be + // unbootable anyway (due to lacking hardware description), so tolerate no + // errors here. + // + if (MAX_UINTN == MAX_UINT64 && + !PcdGetBool (PcdForceNoAcpi)) + { + Status = gBS->InstallProtocolInterface ( + &ImageHandle, + &gEdkiiPlatformHasAcpiGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + if (EFI_ERROR (Status)) { + goto Failed; + } + + return Status; + } + + // + // Expose the Device Tree otherwise. + // + Status = gBS->InstallProtocolInterface ( + &ImageHandle, + &gEdkiiPlatformHasDeviceTreeGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + if (EFI_ERROR (Status)) { + goto Failed; + } + + return Status; + +Failed: + ASSERT_EFI_ERROR (Status); + CpuDeadLoop (); + // + // Keep compilers happy. + // + return Status; +} -- 2.17.1