From patchwork Thu Jun 23 11:31:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 70758 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp383184qgy; Thu, 23 Jun 2016 04:35:36 -0700 (PDT) X-Received: by 10.66.144.97 with SMTP id sl1mr14258902pab.47.1466681731202; Thu, 23 Jun 2016 04:35:31 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id k9si6493655pfj.91.2016.06.23.04.35.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jun 2016 04:35:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 83A851A1E0E; Thu, 23 Jun 2016 04:36:01 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [119.145.14.66]) (using TLSv1 with cipher DES-CBC3-SHA (112/168 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 898A71A1E04 for ; Thu, 23 Jun 2016 04:35:59 -0700 (PDT) Received: from 172.24.1.137 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CDT69881; Thu, 23 Jun 2016 19:31:38 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 23 Jun 2016 19:31:31 +0800 From: Shannon Zhao To: , , Date: Thu, 23 Jun 2016 19:31:20 +0800 Message-ID: <1466681480-14500-1-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.576BC89E.006F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1ab0490298f9d1d8e91d2131a0144704 Subject: [edk2] [PATCH v2] ArmVirtPkg/ArmVirtXen: Add ACPI support for Virt Xen ARM X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: peter.huangpeng@huawei.com, shannon.zhao@linaro.org, xen-devel@lists.xen.org Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" From: Shannon Zhao Add ACPI support for Virt Xen ARM and only for aarch64. It gets the ACPI tables through Xen ARM multiboot protocol. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Shannon Zhao --- Changes since v1: * move the codes into ArmVirtPkg * use FdtClient * don't rely on OvmfPkg/AcpiPlatformDxe/EntryPoint.c while implement own entry point since it's minor * use compatible string to find the DT node instead of node path If you want to test, the corresponding Xen patches can be fetched from: https://git.linaro.org/people/shannon.zhao/xen.git domu_acpi_v2 --- ArmVirtPkg/ArmVirtXen.dsc | 8 + ArmVirtPkg/ArmVirtXen.fdf | 8 + ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.c | 241 +++++++++++++++++++++ .../XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf | 49 +++++ 4 files changed, 306 insertions(+) create mode 100644 ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.c create mode 100644 ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf -- 2.0.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index 594ca64..a869986 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -216,3 +216,11 @@ OvmfPkg/XenBusDxe/XenBusDxe.inf OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf + + # + # ACPI support + # +!if $(ARCH) == AARCH64 + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf +!endif diff --git a/ArmVirtPkg/ArmVirtXen.fdf b/ArmVirtPkg/ArmVirtXen.fdf index 13412f9..b1e00e5 100644 --- a/ArmVirtPkg/ArmVirtXen.fdf +++ b/ArmVirtPkg/ArmVirtXen.fdf @@ -179,6 +179,14 @@ READ_LOCK_STATUS = TRUE INF OvmfPkg/XenBusDxe/XenBusDxe.inf INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf + # + # ACPI support + # +!if $(ARCH) == AARCH64 + INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + INF ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf +!endif + [FV.FVMAIN_COMPACT] FvAlignment = 16 ERASE_POLARITY = 1 diff --git a/ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.c b/ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.c new file mode 100644 index 0000000..9258be8 --- /dev/null +++ b/ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.c @@ -0,0 +1,241 @@ +/** @file + Xen ARM ACPI Platform Driver using Xen ARM multiboot protocol + + Copyright (C) 2016, Linaro Ltd. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include + +#include +#include + +#include + +EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *XenAcpiRsdpStructurePtr = NULL; + +/** + Get the address of Xen ACPI Root System Description Pointer (RSDP) + structure. + + @param RsdpStructurePtr Return pointer to RSDP structure + + @return EFI_SUCCESS Find Xen RSDP structure successfully. + @return EFI_NOT_FOUND Don't find Xen RSDP structure. + @return EFI_ABORTED Find Xen RSDP structure, but it's not integrated. + +**/ +EFI_STATUS +EFIAPI +GetXenArmAcpiRsdp ( + OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr + ) +{ + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *RsdpStructurePtr; + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST UINT64 *Reg; + UINT32 RegElemSize, RegSize; + UINT64 RegBase; + UINT8 Sum; + + RsdpStructurePtr = NULL; + // + // Get the RSDP structure address from DeviceTree + // + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + Status = FdtClient->FindCompatibleNodeReg (FdtClient, "xen,guest-acpi", + (CONST VOID **)&Reg, &RegElemSize, &RegSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_WARN, "%a: No 'xen,guest-acpi' compatible DT node found\n", + __FUNCTION__)); + return EFI_NOT_FOUND; + } + + ASSERT (RegSize == 2 * sizeof (UINT64)); + + RegBase = SwapBytes64(Reg[0]); + RsdpStructurePtr = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)RegBase; + + if (RsdpStructurePtr && RsdpStructurePtr->Revision >= 2) { + Sum = CalculateSum8 ((CONST UINT8 *)RsdpStructurePtr, + sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER)); + if (Sum != 0) { + return EFI_ABORTED; + } + } + + *RsdpPtr = RsdpStructurePtr; + return EFI_SUCCESS; +} + +/** + Get Xen Acpi tables from the RSDP structure. And installs Xen ACPI tables + into the RSDT/XSDT using InstallAcpiTable. Some signature of the installed + ACPI tables are: FACP, APIC, GTDT, DSDT. + + @param AcpiProtocol Protocol instance pointer. + + @return EFI_SUCCESS The table was successfully inserted. + @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableHandle is + NULL, or AcpiTableBufferSize and the size + field embedded in the ACPI table pointed to + by AcpiTableBuffer are not in sync. + @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request. + +**/ +EFI_STATUS +EFIAPI +InstallXenArmTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ) +{ + EFI_STATUS Status; + UINTN TableHandle; + + EFI_ACPI_DESCRIPTION_HEADER *Xsdt; + VOID *CurrentTableEntry; + UINTN CurrentTablePointer; + EFI_ACPI_DESCRIPTION_HEADER *CurrentTable; + UINTN Index; + UINTN NumberOfTableEntries; + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *FadtTable; + EFI_ACPI_DESCRIPTION_HEADER *DsdtTable; + + FadtTable = NULL; + DsdtTable = NULL; + TableHandle = 0; + NumberOfTableEntries = 0; + + // + // Try to find Xen ARM ACPI tables + // + Status = GetXenArmAcpiRsdp (&XenAcpiRsdpStructurePtr); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_INFO, "%a: No RSDP table found\n", __FUNCTION__)); + return Status; + } + + // + // If XSDT table is find, just install its tables. + // + if (XenAcpiRsdpStructurePtr->XsdtAddress) { + // + // Retrieve the addresses of XSDT and + // calculate the number of its table entries. + // + Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) + XenAcpiRsdpStructurePtr->XsdtAddress; + NumberOfTableEntries = (Xsdt->Length - + sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / + sizeof (UINT64); + // + // Install ACPI tables found in XSDT. + // + for (Index = 0; Index < NumberOfTableEntries; Index++) { + // + // Get the table entry from XSDT + // + CurrentTableEntry = (VOID *) ((UINT8 *) Xsdt + + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + + Index * sizeof (UINT64)); + CurrentTablePointer = (UINTN) *(UINT64 *)CurrentTableEntry; + CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTablePointer; + + // + // Install the XSDT tables + // + Status = AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + CurrentTable, + CurrentTable->Length, + &TableHandle + ); + + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Get the FACS and DSDT table address from the table FADT + // + if (!AsciiStrnCmp ((CHAR8 *) &CurrentTable->Signature, "FACP", 4)) { + FadtTable = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) + (UINTN) CurrentTablePointer; + DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) FadtTable->Dsdt; + } + } + } + + // + // Install DSDT table. + // + Status = AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + DsdtTable, + DsdtTable->Length, + &TableHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return EFI_SUCCESS; +} + +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; +} + +/** + Entrypoint of Xen ARM Acpi Platform driver. + + @param ImageHandle + @param SystemTable + + @return EFI_SUCCESS + @return EFI_LOAD_ERROR + @return EFI_OUT_OF_RESOURCES + +**/ + +EFI_STATUS +EFIAPI +XenAcpiPlatformEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = InstallXenArmTables (FindAcpiTableProtocol ()); + return Status; +} diff --git a/ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf b/ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf new file mode 100644 index 0000000..0c31b7c --- /dev/null +++ b/ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf @@ -0,0 +1,49 @@ +## @file +# Xen ARM ACPI Platform Driver using Xen ARM multiboot protocol +# +# Copyright (C) 2016, Linaro Ltd. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = XenAcpiPlatformDxe + FILE_GUID = 0efc6282-f1e5-469a-8a70-194a8761f9aa + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = XenAcpiPlatformEntryPoint + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = AARCH64 +# + +[Sources] + XenAcpiPlatformDxe.c + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiAcpiTableProtocolGuid ## PROTOCOL ALWAYS_CONSUMED + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gEfiAcpiTableProtocolGuid