From patchwork Wed Apr 6 16:15:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65202 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1147230lbc; Wed, 6 Apr 2016 09:16:11 -0700 (PDT) X-Received: by 10.98.66.155 with SMTP id h27mr39625144pfd.91.1459959371662; Wed, 06 Apr 2016 09:16:11 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id my7si5468037pab.146.2016.04.06.09.16.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Apr 2016 09:16:11 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 07E281A1FDA; Wed, 6 Apr 2016 09:15:53 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 34D501A1FDA for ; Wed, 6 Apr 2016 09:15:51 -0700 (PDT) Received: by mail-wm0-x22d.google.com with SMTP id n3so70221504wmn.0 for ; Wed, 06 Apr 2016 09:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6iuqtjzNfwpRCHxuWYXXc0X3AnI2vPQdzKYTGRMvdcM=; b=dWKqPMR8AMeWCIyqj7K1fHdliS7WaHRB02dHs+BLTKDjpUTfSsJWBQBybBvfFRmyjr Pd7r/jrfMKAdK7GN3pd6G90qw9P2DZLCHkqmshdvsFBRKREVaL71ZOtTet6A6dnZxuyK onOY+l+FpbsDU8iYINduynKk1yIqe89nCQu5E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6iuqtjzNfwpRCHxuWYXXc0X3AnI2vPQdzKYTGRMvdcM=; b=YhJ6tNSY07oQbOv4tnRTt4x5T50LQOHv+mnjCyfIg71PBi0wkkyya/BJgH6z3dmIbb vxpFRoO0ecWJR0PS2/F3Xoe1f1T7hnf6WgpH1aJAxjNiqPCPqg2W1FrYx7hLPzCJcbOw T+MnVxNn+C0feqVqGmtfsQs6fsCYFAInolZoOe9S8sFIcCMCEhA0dcrdNGiSfWXkikHu Yu7a1hHiguQ1UI15UoUUSllnDcGJ0apEXzIAUKaGww/HPqbU+Tjf/pDsBozmR0PQnEtA k9jGFcgxa49TIrMnAPJsLXLhX38q3HebNQtxxm1aPFnfU4IpYHvP9s90ZMIqIt7+4S/X gGcA== X-Gm-Message-State: AD7BkJK1JvP1llOLAckfeJxQX7K/yMaC2RBm4BlX+jpdSGKJieRu2WdrLZIMhs7QrAuXUoWv X-Received: by 10.194.134.134 with SMTP id pk6mr31315399wjb.176.1459959349883; Wed, 06 Apr 2016 09:15:49 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id om6sm3961219wjc.40.2016.04.06.09.15.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Apr 2016 09:15:49 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Wed, 6 Apr 2016 18:15:11 +0200 Message-Id: <1459959319-19293-14-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459959319-19293-1-git-send-email-ard.biesheuvel@linaro.org> References: <1459959319-19293-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 13/21] ArmVirtPkg/QemuFwCfgLib: move to FDT client protocol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Make this library depend on the FDT client protocol to access the host supplied device tree directly rather than depending on VirtFdtDxe to set them using dynamic PCDs. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 73 ++++++++++++++++++-- ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf | 12 ++-- 2 files changed, 72 insertions(+), 13 deletions(-) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c index 303dc520c6eb..1cb372562b62 100644 --- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c @@ -20,6 +20,10 @@ #include #include #include +#include +#include + +#include STATIC UINTN mFwCfgSelectorAddress; STATIC UINTN mFwCfgDataAddress; @@ -109,14 +113,70 @@ QemuFwCfgIsAvailable ( } -RETURN_STATUS +EFI_STATUS EFIAPI QemuFwCfgInitialize ( - VOID + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable ) { - mFwCfgSelectorAddress = (UINTN)PcdGet64 (PcdFwCfgSelectorAddress); - mFwCfgDataAddress = (UINTN)PcdGet64 (PcdFwCfgDataAddress); + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST VOID *Reg; + UINTN RegElemSize, RegSize; + UINT64 FwCfgSelectorSize; + UINT64 FwCfgDataSize; + UINT64 FwCfgDmaSize; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, (VOID **)&FdtClient); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = FdtClient->FindCompatibleNodeReg (FdtClient, + "qemu,fw-cfg-mmio", + &Reg, + &RegElemSize, + &RegSize); + if (EFI_ERROR (Status)) { + return Status; + } + + ASSERT (RegElemSize == sizeof (UINT64)); + ASSERT (RegSize == 2 * sizeof (UINT64)); + + mFwCfgDataAddress = fdt64_to_cpu (((UINT64 *)Reg)[0]); + FwCfgDataSize = 8; + mFwCfgSelectorAddress = mFwCfgDataAddress + FwCfgDataSize; + FwCfgSelectorSize = 2; + + // + // The following ASSERT()s express + // + // Address + Size - 1 <= MAX_UINTN + // + // for both registers, that is, that the last byte in each MMIO range is + // expressible as a MAX_UINTN. The form below is mathematically + // equivalent, and it also prevents any unsigned overflow before the + // comparison. + // + ASSERT (mFwCfgSelectorAddress <= MAX_UINTN - FwCfgSelectorSize + 1); + ASSERT (mFwCfgDataAddress <= MAX_UINTN - FwCfgDataSize + 1); + + DEBUG ((EFI_D_INFO, "Found FwCfg @ 0x%Lx/0x%Lx\n", mFwCfgSelectorAddress, + mFwCfgDataAddress)); + + if (fdt64_to_cpu (((UINT64 *)Reg)[1]) >= 0x18) { + mFwCfgDmaAddress = mFwCfgDataAddress + 0x10; + FwCfgDmaSize = 0x08; + + // + // See explanation above. + // + ASSERT (mFwCfgDmaAddress <= MAX_UINTN - FwCfgDmaSize + 1); + + DEBUG ((EFI_D_INFO, "Found FwCfg DMA @ 0x%Lx\n", mFwCfgDmaAddress)); + } if (InternalQemuFwCfgIsAvailable ()) { UINT32 Signature; @@ -128,13 +188,12 @@ QemuFwCfgInitialize ( // For DMA support, we require the DTB to advertise the register, and the // feature bitmap (which we read without DMA) to confirm the feature. // - if (PcdGet64 (PcdFwCfgDmaAddress) != 0) { + if (mFwCfgDmaAddress != 0) { UINT32 Features; QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion); Features = QemuFwCfgRead32 (); if ((Features & BIT1) != 0) { - mFwCfgDmaAddress = PcdGet64 (PcdFwCfgDmaAddress); InternalQemuFwCfgReadBytes = DmaReadBytes; } } @@ -143,7 +202,7 @@ QemuFwCfgInitialize ( mFwCfgDataAddress = 0; } } - return RETURN_SUCCESS; + return EFI_SUCCESS; } diff --git a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf index 298aa6edfb26..a4ae2a3f9d22 100644 --- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf +++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf @@ -20,7 +20,7 @@ [Defines] INF_VERSION = 0x00010005 BASE_NAME = QemuFwCfgLib FILE_GUID = B271F41F-B841-48A9-BA8D-545B4BC2E2BF - MODULE_TYPE = BASE + MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 LIBRARY_CLASS = QemuFwCfgLib|DXE_DRIVER @@ -46,9 +46,9 @@ [LibraryClasses] BaseMemoryLib DebugLib IoLib - PcdLib -[Pcd] - gArmVirtTokenSpaceGuid.PcdFwCfgSelectorAddress - gArmVirtTokenSpaceGuid.PcdFwCfgDataAddress - gArmVirtTokenSpaceGuid.PcdFwCfgDmaAddress +[Protocols] + gFdtClientProtocolGuid + +[Depex] + gFdtClientProtocolGuid