From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EDC358037F for ; Wed, 8 Mar 2017 11:05:33 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 878DE4E359; Wed, 8 Mar 2017 19:05:34 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-47.phx2.redhat.com [10.3.117.47]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28J5GPP014080; Wed, 8 Mar 2017 14:05:32 -0500 From: Laszlo Ersek To: edk2-devel-01 Cc: Ard Biesheuvel Date: Wed, 8 Mar 2017 20:05:10 +0100 Message-Id: <20170308190511.31195-6-lersek@redhat.com> In-Reply-To: <20170308190511.31195-1-lersek@redhat.com> References: <20170308190511.31195-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 08 Mar 2017 19:05:34 +0000 (UTC) Subject: [PATCH 5/6] ArmVirtPkg/FdtClientDxe: don't forward DT to OS if QEMU provides ACPI X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Mar 2017 19:05:34 -0000 ArmVirtQemu can be built with -D PURE_ACPI_BOOT_ENABLE at the moment. We should replace that build-time setting with a dynamic one: forward the DT from QEMU to the guest kernel if and only if - the guest architecture is arm32, or - we run on Xen, or - ACPI payload is not available from QEMU. This will let QEMU's "-no-acpi" option exclusively expose DT vs. ACPI to the guest. Showing both is never needed (it is actually detrimental to the adoption of standards, such as SBSA / SBBR). Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- ArmVirtPkg/ArmVirtQemu.dsc | 5 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 5 +- ArmVirtPkg/ArmVirtXen.dsc | 5 +- ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf | 5 +- ArmVirtPkg/FdtClientDxe/FdtClientDxe.c | 67 ++++++++++++++++++-- 5 files changed, 75 insertions(+), 12 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 477dfdcfc764..863077f53edf 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -301,7 +301,10 @@ [Components.common] # Platform Driver # ArmVirtPkg/VirtioFdtDxe/VirtioFdtDxe.inf - ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf + ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf { + + QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLibExplicitInit.inf + } ArmVirtPkg/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc index fd39c2802a85..08a8eafd60d0 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -290,7 +290,10 @@ [Components.common] # Platform Driver # ArmVirtPkg/VirtioFdtDxe/VirtioFdtDxe.inf - ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf + ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf { + + QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLibExplicitInit.inf + } ArmVirtPkg/HighMemDxe/HighMemDxe.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf OvmfPkg/VirtioScsiDxe/VirtioScsi.inf diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index 3422d1e5d996..4442329907ae 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -197,7 +197,10 @@ [Components.common] # Platform Driver # ArmVirtPkg/XenioFdtDxe/XenioFdtDxe.inf - ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf + ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf { + + QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLibExplicitInit.inf + } # # FAT filesystem + GPT/MBR partitioning diff --git a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf index 3a0cd37040eb..832f85bacd9b 100644 --- a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf +++ b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf @@ -29,12 +29,14 @@ [Packages] EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [LibraryClasses] BaseLib DebugLib FdtLib HobLib + QemuFwCfgLib UefiBootServicesTableLib UefiDriverEntryPoint @@ -45,8 +47,5 @@ [Guids] gFdtHobGuid gFdtTableGuid -[FeaturePcd] - gArmVirtTokenSpaceGuid.PcdPureAcpiBoot - [Depex] TRUE diff --git a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c index 6082b22d35c1..8def7662a271 100644 --- a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c +++ b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,15 @@ STATIC VOID *mDeviceTreeBase; +typedef enum { + OsExposureUnavailable, + OsExposureEnabled, + OsExposureDisabled, + OsExposureMax +} OS_EXPOSURE_STATE; + +STATIC OS_EXPOSURE_STATE mOsExposure; + STATIC EFI_STATUS EFIAPI @@ -300,7 +310,11 @@ GetOsExposure ( OUT BOOLEAN *FdtExposedToOs ) { - *FdtExposedToOs = !FeaturePcdGet (PcdPureAcpiBoot); + ASSERT (mOsExposure < OsExposureMax); + if (mOsExposure == OsExposureUnavailable) { + return EFI_NOT_STARTED; + } + *FdtExposedToOs = (BOOLEAN)(mOsExposure == OsExposureEnabled); return EFI_SUCCESS; } @@ -317,6 +331,12 @@ STATIC FDT_CLIENT_PROTOCOL mFdtClientProtocol = { GetOsExposure }; +RETURN_STATUS +EFIAPI +QemuFwCfgInitialize ( + VOID + ); + EFI_STATUS EFIAPI InitializeFdtClientDxe ( @@ -327,6 +347,7 @@ InitializeFdtClientDxe ( VOID *Hob; VOID *DeviceTreeBase; EFI_STATUS Status; + EFI_TPL OldTpl; Hob = GetFirstGuidHob (&gFdtHobGuid); if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) { @@ -344,15 +365,49 @@ InitializeFdtClientDxe ( DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, mDeviceTreeBase)); - if (!FeaturePcdGet (PcdPureAcpiBoot)) { + // + // Install the protocol for our QemuFwCfgLibExplicitInit instance, but + // prevent any protocol notifies at TPL_CALLBACK from firing. + // + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); + Status = gBS->InstallProtocolInterface (&ImageHandle, + &gFdtClientProtocolGuid, EFI_NATIVE_INTERFACE, + &mFdtClientProtocol); + if (EFI_ERROR (Status)) { + goto RestoreTpl; + } + + // + // Install the FDT as a configuration table only if: + // - we're running on 32-bit ARM, or + // - we're running on Xen, or + // - QEMU doesn't provide us with ACPI payload (e.g. due to the -no-acpi + // option). + // + mOsExposure = OsExposureEnabled; + if (MAX_UINTN != MAX_UINT32) { // - // Only install the FDT as a configuration table if we want to leave it up - // to the OS to decide whether it prefers ACPI over DT. + // Call the fw_cfg library constructor explicitly. It always succeeds; + // we'll check fw_cfg availability separately. // + QemuFwCfgInitialize (); + if (QemuFwCfgIsAvailable ()) { + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + + if (!RETURN_ERROR (QemuFwCfgFindFile ("etc/table-loader", &FwCfgItem, + &FwCfgSize))) { + mOsExposure = OsExposureDisabled; + } + } + } + + if (mOsExposure == OsExposureEnabled) { Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DeviceTreeBase); ASSERT_EFI_ERROR (Status); } - return gBS->InstallProtocolInterface (&ImageHandle, &gFdtClientProtocolGuid, - EFI_NATIVE_INTERFACE, &mFdtClientProtocol); +RestoreTpl: + gBS->RestoreTPL (OldTpl); + return Status; } -- 2.9.3