From patchwork Fri Apr 8 09:44:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65375 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp569325lbl; Fri, 8 Apr 2016 02:46:02 -0700 (PDT) X-Received: by 10.98.12.153 with SMTP id 25mr11354391pfm.27.1460108747988; Fri, 08 Apr 2016 02:45:47 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id u4si9934par.185.2016.04.08.02.45.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 02:45:47 -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; 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 2001:19d0:306:5::1 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 1D0201A1FCA; Fri, 8 Apr 2016 02:45:38 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com [IPv6:2a00:1450:400c:c09::236]) (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 D9FE11A1FCA for ; Fri, 8 Apr 2016 02:45:36 -0700 (PDT) Received: by mail-wm0-x236.google.com with SMTP id u206so15476591wme.1 for ; Fri, 08 Apr 2016 02:45:36 -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=UeUKIBuiNX1lD9lfYjLagDPIiB8wxaiTqQgNQNBK5jE=; b=LJRUd3TnHzkkmwhnk0Dxloovtu3wZbEbX7CRdHeQnV1+mf/Wsg/sXo2R5EZb3PkhM6 v5BgKfM32s3xASYpYN5TEgiWlII5qkyPe3zzcMwHzcsvTZ7kOh0LwYKr3WnZr00b0JF+ IYtfgw1gScXLbaZQh6i2sYt4iJaPB3SIESH+U= 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=UeUKIBuiNX1lD9lfYjLagDPIiB8wxaiTqQgNQNBK5jE=; b=ZApCitkfofgrrqvseHv2706+SHocC2xY3fClh5YgKkjstUxv/9ztj8db5GMD8uXBgQ CaPLGDrvj3AIZxI2mefK8xfoeOQfsVdotUwSfFQTGd/LaOzexAoFSWvZ6jrl8w3X44kk j0BVvDU44lgbdo2yWcnS+N8pOfyt/Pi/4eMQ1MlHPyfaqxQ7Drh54etnsvEIDedLVF/p 2whfrgGETHtnz/8+TJEG6XTcxOZVtp9UNz8KaDkB8Gd5YsFD3JgtVNOH9t6WE3q5XZ1r O+bKOfUjJ62b8XTw6QJAwGx1KkV1GZ68CoPH70ibN20RpCVeLD3QHiVBPf/XPmC7DDdu 9Z/g== X-Gm-Message-State: AD7BkJLqIWQCYNu59zvC5YaH5VcISjuczLQ9dafkgxrq5Sd9/dTVDlpA45ANWs6yRiDyu0cf X-Received: by 10.28.126.210 with SMTP id z201mr2615238wmc.74.1460108735589; Fri, 08 Apr 2016 02:45:35 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id s10sm9710681wjp.3.2016.04.08.02.45.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Apr 2016 02:45:34 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Fri, 8 Apr 2016 11:44:58 +0200 Message-Id: <1460108711-12122-12-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460108711-12122-1-git-send-email-ard.biesheuvel@linaro.org> References: <1460108711-12122-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 11/24] 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. Since this library is used by several drivers (BdsDxe, SmbiosDxe and QemuFwCfgAcpiPlatformDxe), we will end up parsing the device tree and the fwcfg node at least three times. However, no dynamic PCDs are involved anymore, and will even be removed completely in a subsequent patch. So the conversion is not optimal, but guaranteed to be safe. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 63 ++++++++++++++++++-- ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf | 10 ++-- 2 files changed, 64 insertions(+), 9 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..34f31517d0fa 100644 --- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c @@ -14,12 +14,17 @@ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ +#include + #include #include #include #include #include #include +#include + +#include STATIC UINTN mFwCfgSelectorAddress; STATIC UINTN mFwCfgDataAddress; @@ -115,8 +120,59 @@ QemuFwCfgInitialize ( VOID ) { - mFwCfgSelectorAddress = (UINTN)PcdGet64 (PcdFwCfgSelectorAddress); - mFwCfgDataAddress = (UINTN)PcdGet64 (PcdFwCfgDataAddress); + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST UINT64 *Reg; + UINT32 RegElemSize, RegSize; + UINT64 FwCfgSelectorSize; + UINT64 FwCfgDataSize; + UINT64 FwCfgDmaSize; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + Status = FdtClient->FindCompatibleNodeReg (FdtClient, "qemu,fw-cfg-mmio", + (CONST VOID **)&Reg, &RegElemSize, &RegSize); + if (EFI_ERROR (Status)) { + return Status; + } + + ASSERT (RegElemSize == sizeof (UINT64)); + ASSERT (RegSize == 2 * sizeof (UINT64)); + + mFwCfgDataAddress = SwapBytes64 (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 (SwapBytes64 (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 +184,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; } } diff --git a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf index 298aa6edfb26..cab42e4fd532 100644 --- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf +++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf @@ -46,9 +46,9 @@ [LibraryClasses] BaseMemoryLib DebugLib IoLib - PcdLib -[Pcd] - gArmVirtTokenSpaceGuid.PcdFwCfgSelectorAddress - gArmVirtTokenSpaceGuid.PcdFwCfgDataAddress - gArmVirtTokenSpaceGuid.PcdFwCfgDmaAddress +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid