From patchwork Tue May 31 04:59:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 68875 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1730629qge; Mon, 30 May 2016 22:00:27 -0700 (PDT) X-Received: by 10.98.89.207 with SMTP id k76mr52436150pfj.166.1464670827559; Mon, 30 May 2016 22:00:27 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id dd5si8242195pab.188.2016.05.30.22.00.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 22:00:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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 A5B0E1A1DF2; Mon, 30 May 2016 22:00:40 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [119.145.14.65]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id ED2A01A1DE8 for ; Mon, 30 May 2016 22:00:38 -0700 (PDT) Received: from 172.24.1.47 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DHY49654; Tue, 31 May 2016 13:00:03 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Tue, 31 May 2016 12:59:54 +0800 From: Shannon Zhao To: , , Date: Tue, 31 May 2016 12:59:46 +0800 Message-ID: <1464670786-10424-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.0A020202.574D1A57.0050, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 709b56b0af03e04f58b1c79fb973a7a9 Subject: [edk2] [PATCH] OvmfPkg: 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 it gets the ACPI tables through Xen ARM multiboot protocol. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Shannon Zhao --- The corresponding Xen patches can be fetched from: http://git.linaro.org/people/shannon.zhao/xen.git/shortlog/refs/heads/domu_acpi --- ArmVirtPkg/ArmVirtXen.dsc | 6 + ArmVirtPkg/ArmVirtXen.fdf | 6 + OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 6 + OvmfPkg/AcpiPlatformDxe/XenArmAcpi.c | 207 ++++++++++++++++++++++ OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatform.c | 38 ++++ OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.inf | 59 ++++++ 6 files changed, 322 insertions(+) create mode 100644 OvmfPkg/AcpiPlatformDxe/XenArmAcpi.c create mode 100644 OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatform.c create mode 100644 OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.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..a0d197f 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -216,3 +216,9 @@ OvmfPkg/XenBusDxe/XenBusDxe.inf OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf + + # + # ACPI Support + # + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.inf diff --git a/ArmVirtPkg/ArmVirtXen.fdf b/ArmVirtPkg/ArmVirtXen.fdf index 13412f9..da30e87 100644 --- a/ArmVirtPkg/ArmVirtXen.fdf +++ b/ArmVirtPkg/ArmVirtXen.fdf @@ -179,6 +179,12 @@ READ_LOCK_STATUS = TRUE INF OvmfPkg/XenBusDxe/XenBusDxe.inf INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf + # + # ACPI Support + # + INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + INF OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.inf + [FV.FVMAIN_COMPACT] FvAlignment = 16 ERASE_POLARITY = 1 diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h index 08dd7f8..325d7e6 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -69,6 +69,12 @@ InstallXenTables ( EFI_STATUS EFIAPI +InstallXenArmTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ); + +EFI_STATUS +EFIAPI InstallQemuFwCfgTables ( IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol ); diff --git a/OvmfPkg/AcpiPlatformDxe/XenArmAcpi.c b/OvmfPkg/AcpiPlatformDxe/XenArmAcpi.c new file mode 100644 index 0000000..c3a351c --- /dev/null +++ b/OvmfPkg/AcpiPlatformDxe/XenArmAcpi.c @@ -0,0 +1,207 @@ +/** @file + OVMF ACPI Xen ARM support + + 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 "AcpiPlatform.h" +#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 + ) +{ + VOID *Hob; + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *RsdpStructurePtr; + VOID *DeviceTreeBase; + INT32 Node, Depth, Len; + CONST CHAR8 *Type; + CONST VOID *RegProp; + + RsdpStructurePtr = NULL; + // + // Get the RSDP structure address from DeviceTree + // + Hob = GetFirstGuidHob(&gFdtHobGuid); + if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) { + DEBUG ((EFI_D_ERROR, "%a: Failed to get Fdt Hob\n", __FUNCTION__)); + return EFI_NOT_FOUND; + } + DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob); + + if (fdt_check_header (DeviceTreeBase) != 0) { + DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__, DeviceTreeBase)); + return EFI_NOT_FOUND; + } + + Node = fdt_path_offset(DeviceTreeBase, "/chosen/modules"); + if ( Node < 0 ) { + DEBUG ((EFI_D_ERROR, "%a: NO /chosen/modules found\n", __FUNCTION__)); + return EFI_NOT_FOUND; + } + + + for (Depth = 0; + (Node >= 0) && (Depth >= 0); + Node = fdt_next_node (DeviceTreeBase, Node, &Depth)) { + if (Depth == 1) { + Type = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len); + if (fdt_stringlist_contains (Type, Len, "xen,linux-acpi")) { + RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len); + ASSERT (Len == 2 * sizeof (UINT64)); + RsdpStructurePtr = (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) + (UINTN) fdt64_to_cpu (((UINT64 *)RegProp)[0]); + } + } + } + + if (RsdpStructurePtr && RsdpStructurePtr->Revision >= 2) { + *RsdpPtr = RsdpStructurePtr; + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + +/** + 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; +} diff --git a/OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatform.c new file mode 100644 index 0000000..7f141a9 --- /dev/null +++ b/OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatform.c @@ -0,0 +1,38 @@ +/** @file + OVMF 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 "AcpiPlatform.h" + +/** + Effective 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 +InstallAcpiTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable + ) +{ + EFI_STATUS Status; + + Status = InstallXenArmTables (AcpiTable); + return Status; +} diff --git a/OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.inf new file mode 100644 index 0000000..d96e9a1 --- /dev/null +++ b/OvmfPkg/AcpiPlatformDxe/XenArmAcpiPlatformDxe.inf @@ -0,0 +1,59 @@ +## @file +# OVMF 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 = XenArmAcpiPlatform + FILE_GUID = 0efc6282-f1e5-469a-8a70-194a8761f9aa + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = AcpiPlatformEntryPoint + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = AARCH64 +# + +[Sources] + XenArmAcpiPlatform.c + XenArmAcpi.c + EntryPoint.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + HobLib + FdtLib + UefiDriverEntryPoint + +[Protocols] + gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiPciEnumerationCompleteProtocolGuid # PROTOCOL SOMETIMES_CONSUMED + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration + +[Depex] + gEfiAcpiTableProtocolGuid + +[Guids] + gFdtHobGuid