From patchwork Fri Apr 8 09:44:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65368 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp569136lbl; Fri, 8 Apr 2016 02:45:31 -0700 (PDT) X-Received: by 10.98.86.157 with SMTP id h29mr11386350pfj.105.1460108727871; Fri, 08 Apr 2016 02:45: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 tr1si10346pab.135.2016.04.08.02.45.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 02:45: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; 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 2CEAE1A1F42; Fri, 8 Apr 2016 02:45:27 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com [IPv6:2a00:1450:400c:c09::22b]) (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 52F811A1F42 for ; Fri, 8 Apr 2016 02:45:25 -0700 (PDT) Received: by mail-wm0-x22b.google.com with SMTP id u206so15470634wme.1 for ; Fri, 08 Apr 2016 02:45:25 -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=ZXZE+BfFqDv2ED5yORfx9kTV5oDfI4e3nGSemaRvtXw=; b=cKSRkYLodgYsCJ3yKxISDUigGGea4DqtqCA4rnXYGTXylxYeZKPJ+6wLMh//K/f2iB Sc86f8sW6fQ9uWzFTFtqtfkT4dCBWp88FBWoVv9nVXIkUS8svvQjZPKRWljswIxUm/7c 4CVNRgsPDoS6sXJESS5PrX/o8/scp8vWcxZ1g= 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=ZXZE+BfFqDv2ED5yORfx9kTV5oDfI4e3nGSemaRvtXw=; b=OzN5CMWtq4LDrrS2cH4HpekCou8nqydIS52vRu+9+0xNdKCM4GzGY28UMk9Kh7qJ72 i1CHHt2uqtVtwzmSfqAhtncVbQdGi284XzmQyBVlemQrJp2nqxQpNLARlReg703dRFEP o16N1GH44Df8NiOtMGLTiZ5AEHmpFjpLxNbuwqf+s0vqaTiqg4t7FXqU9ImzgN0KicBx Qf+l5h1qslfVtGCDeVEsW+JDi4gbA3Zn5OW/EI3Vm+epv5z01JhwNHsRm/de7C17+7X8 l6sce3IBCQ6QuR1uj2RULk3547114n1yVknEu96DAljudguMzrODNUDT6cWnQtKp14V5 WKjQ== X-Gm-Message-State: AD7BkJIsykBdEvtjm6t/4UodJYJmK39pRLu5uJNqAivYDJ/uUF0UPntVPAZ3lL503UwtTAKH X-Received: by 10.28.107.13 with SMTP id g13mr2755706wmc.62.1460108723993; Fri, 08 Apr 2016 02:45:23 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id s10sm9710681wjp.3.2016.04.08.02.45.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Apr 2016 02:45:23 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Fri, 8 Apr 2016 11:44:51 +0200 Message-Id: <1460108711-12122-5-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 04/24] ArmVirtPkg/ArmGicArchLib: move to FdtClient 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" Instead of relying on VirtFdtDxe to populate the GIC related PCDs, move this handling to our implementation of ArmGicArchLib, and retrieve the required DT info using the new FDT client protocol. This removes one of the reasons we need to load VirtFdtDxe first using an 'A PRIORI' declaration in the platform FDF. As Laszlo kindly confirms: So, ultimately, the only user of this library instance is "ArmPkg/Drivers/ArmGic/ArmGicDxe.inf". ... Indeed, checking the build report file for ArmVirtQemu (AARCH64), I find ArmVirtGicArchLib (and ArmGicLib too) only under "ArmPkg/Drivers/ArmGic/ArmGicDxe.inf". which means that the constructor is only invoked once, and so the dynamic PCDs are set in time for ArmGicDxe to consume them, and never afterwards. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c | 75 ++++++++++++++++++-- ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf | 18 +++-- 2 files changed, 85 insertions(+), 8 deletions(-) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c index 732860cadfe6..7ef829ff2d26 100644 --- a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c +++ b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c @@ -1,7 +1,7 @@ /** @file ArmGicArchLib library class implementation for DT based virt platforms - Copyright (c) 2015, Linaro Ltd. All rights reserved.
+ Copyright (c) 2015 - 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 @@ -14,11 +14,16 @@ **/ #include +#include #include #include -#include +#include #include +#include +#include + +#include STATIC ARM_GIC_ARCH_REVISION mGicArchRevision; @@ -28,12 +33,62 @@ ArmVirtGicArchLibConstructor ( VOID ) { - UINT32 IccSre; + UINT32 IccSre; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST UINT64 *Reg; + UINT32 RegElemSize, RegSize; + UINTN GicRevision; + EFI_STATUS Status; + UINT64 DistBase, CpuBase, RedistBase; - switch (PcdGet32 (PcdArmGicRevision)) { + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + GicRevision = 2; + Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,cortex-a15-gic", + (CONST VOID **)&Reg, &RegElemSize, &RegSize); + if (Status == EFI_NOT_FOUND) { + GicRevision = 3; + Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,gic-v3", + (CONST VOID **)&Reg, &RegElemSize, &RegSize); + } + if (EFI_ERROR (Status)) { + return Status; + } + + switch (GicRevision) { case 3: // + // The GIC v3 DT binding describes a series of at least 3 physical (base + // addresses, size) pairs: the distributor interface (GICD), at least one + // redistributor region (GICR) containing dedicated redistributor + // interfaces for all individual CPUs, and the CPU interface (GICC). + // Under virtualization, we assume that the first redistributor region + // listed covers the boot CPU. Also, our GICv3 driver only supports the + // system register CPU interface, so we can safely ignore the MMIO version + // which is listed after the sequence of redistributor interfaces. + // This means we are only interested in the first two memory regions + // supplied, and ignore everything else. + // + ASSERT (RegSize >= 32); + + // RegProp[0..1] == { GICD base, GICD size } + DistBase = SwapBytes64 (Reg[0]); + ASSERT (DistBase < MAX_UINT32); + + // RegProp[2..3] == { GICR base, GICR size } + RedistBase = SwapBytes64 (Reg[2]); + ASSERT (RedistBase < MAX_UINT32); + + PcdSet32 (PcdGicDistributorBase, (UINT32)DistBase); + PcdSet32 (PcdGicRedistributorsBase, (UINT32)RedistBase); + + DEBUG ((EFI_D_INFO, "Found GIC v3 (re)distributor @ 0x%Lx (0x%Lx)\n", + DistBase, RedistBase)); + + // // The default implementation of ArmGicArchLib is responsible for enabling // the system register interface on the GICv3 if one is found. So let's do // the same here. @@ -55,6 +110,18 @@ ArmVirtGicArchLibConstructor ( break; case 2: + ASSERT (RegSize == 32); + + DistBase = SwapBytes64 (Reg[0]); + CpuBase = SwapBytes64 (Reg[2]); + ASSERT (DistBase < MAX_UINT32); + ASSERT (CpuBase < MAX_UINT32); + + PcdSet32 (PcdGicDistributorBase, (UINT32)DistBase); + PcdSet32 (PcdGicInterruptInterfaceBase, (UINT32)CpuBase); + + DEBUG ((EFI_D_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase)); + mGicArchRevision = ARM_GIC_ARCH_REVISION_2; break; diff --git a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf index c85b2d44d856..a25c191bc97d 100644 --- a/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf +++ b/ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf @@ -27,14 +27,24 @@ [Sources] ArmVirtGicArchLib.c [LibraryClasses] - PcdLib - DebugLib ArmGicLib + BaseLib + DebugLib + PcdLib + UefiBootServicesTableLib [Packages] - MdePkg/MdePkg.dec ArmPkg/ArmPkg.dec ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES [Pcd] - gArmVirtTokenSpaceGuid.PcdArmGicRevision + gArmTokenSpaceGuid.PcdGicDistributorBase + gArmTokenSpaceGuid.PcdGicRedistributorsBase + gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase + +[Depex] + gFdtClientProtocolGuid