From patchwork Fri Mar 31 14:15:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96443 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1250961obc; Fri, 31 Mar 2017 07:16:15 -0700 (PDT) X-Received: by 10.98.196.12 with SMTP id y12mr3121354pff.49.1490969775658; Fri, 31 Mar 2017 07:16:15 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id y11si5385248plg.82.2017.03.31.07.16.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Mar 2017 07:16:15 -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 sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 24C4C20080323; Fri, 31 Mar 2017 07:16:11 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-lf0-x22d.google.com (mail-lf0-x22d.google.com [IPv6:2a00:1450:4010:c07::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 8203D2008031D for ; Fri, 31 Mar 2017 07:16:08 -0700 (PDT) Received: by mail-lf0-x22d.google.com with SMTP id h125so44937717lfe.0 for ; Fri, 31 Mar 2017 07:16:08 -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=uB4xXQqqbiBiBe6qbgHf+yQehoIX3s+EnH9PLxIXb/Y=; b=X9j11V05Gyf7GrgTwt6jwYui8sp23DoiZD5J/lMiX0mley+maPDB1gJ50vcMcUd1Nn BRVI6hvLnMEZDLij1rGn0sqQEhAknpfO7OnUBca6fXF0+B+ccB/PeaTVTYMeMyDnJRZ0 Pea7NjnpSWuxbVV1ifX8254xabTyWd8W5+BGQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uB4xXQqqbiBiBe6qbgHf+yQehoIX3s+EnH9PLxIXb/Y=; b=irj/DsaLc4vaZpa9Szn39xrHnQQY5aaVyc41xBfTeOMHWHQRQvk0slcP+GUWZlSgNS fDkMCc3h072noOQ0BHP5iNpEPyWncc24qoMoSDy5PGDBE+B8X8nYlmH0eE+g3bM+7TZW qtPmcJynbEQ3XS3KfjZvdP3Syn258swYYwfzTnnlh8385hrpm8oA+vYRSjMqxtP5FmAA 4hZ55QufMshyH4H8BFmFvu9QxisrgXEkRueSBnCJIxeqVvO+4ULVHtPIjcF6Na+4JPYL sCif9ve7I17zlAaliufQq4u/MSkVN6C1Q7Erohvm6Y22tDg/I2jVE0QPvfZa+ehdxGzd FEVQ== X-Gm-Message-State: AFeK/H0AoYnHRttsODfENTvViAt9ssr42c0RntdM0xOdA5tCw0RQbJ3LHyD4XO1RoUFE1KD7 X-Received: by 10.28.105.92 with SMTP id e89mr2947497wmc.93.1490969766718; Fri, 31 Mar 2017 07:16:06 -0700 (PDT) Received: from localhost.localdomain ([160.171.180.74]) by smtp.gmail.com with ESMTPSA id h187sm3057561wma.32.2017.03.31.07.16.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Mar 2017 07:16:06 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, ryan.harkin@linaro.org Date: Fri, 31 Mar 2017 15:15:44 +0100 Message-Id: <20170331141547.20987-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170331141547.20987-1-ard.biesheuvel@linaro.org> References: <20170331141547.20987-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 06/13] Platforms/FVP: add DtPlatformDtbLoaderLib implementation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" In preparation of switching to DtPlatformDxe to supply the device tree image to the OS, add an implementation of DtPlatformDtbLoaderLib that loads the correct version from an FV. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.c | 134 ++++++++++++++++++++ Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.inf | 39 ++++++ 2 files changed, 173 insertions(+) -- 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.c b/Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.c new file mode 100644 index 000000000000..3a5613c83709 --- /dev/null +++ b/Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.c @@ -0,0 +1,134 @@ +/** @file +* +* Copyright (c) 2017, 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 + +#include +#include +#include +#include +#include +#include + +#include "ArmPlatform.h" + +typedef enum { + ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2, + ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2_LEGACY, + ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV3, + ARM_FVP_FOUNDATION_GICV2, + ARM_FVP_FOUNDATION_GICV2_LEGACY, + ARM_FVP_FOUNDATION_GICV3, + ARM_FVP_UNKNOWN, +} ARM_VEXPRESS_PLATFORM_ID; + +ARM_VEXPRESS_PLATFORM_ID +GetPlatformId ( + VOID + ) +{ + UINT32 SysId; + UINT32 FvpSysId; + UINT32 VariantSysId; + ARM_GIC_ARCH_REVISION GicRevision; + + SysId = MmioRead32 (ARM_VE_SYS_ID_REG); + + // Remove the GIC variant to identify if we are running on the FVP Base or + // Foundation models + FvpSysId = SysId & (ARM_FVP_SYS_ID_HBI_MASK | ARM_FVP_SYS_ID_PLAT_MASK ); + // Extract the variant from the SysId + VariantSysId = SysId & ARM_FVP_SYS_ID_VARIANT_MASK; + + if (FvpSysId == ARM_FVP_BASE_BOARD_SYS_ID) { + if (VariantSysId == ARM_FVP_GIC_VE_MMAP) { + // FVP Base Model with legacy GIC memory map -- no longer supported + return ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2_LEGACY; + } else { + GicRevision = ArmGicGetSupportedArchRevision (); + + if (GicRevision == ARM_GIC_ARCH_REVISION_2) { + // FVP Base Model with GICv2 support + return ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2; + } else { + // FVP Base Model with GICv3 support + return ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV3; + } + } + } else if (FvpSysId == ARM_FVP_FOUNDATION_BOARD_SYS_ID) { + if (VariantSysId == ARM_FVP_GIC_VE_MMAP) { + // FVP Foundation Model with legacy GIC memory map -- no longer supported + return ARM_FVP_FOUNDATION_GICV2_LEGACY; + } else { + GicRevision = ArmGicGetSupportedArchRevision (); + + if (GicRevision == ARM_GIC_ARCH_REVISION_2) { + // FVP Foundation Model with GICv2 + return ARM_FVP_FOUNDATION_GICV2; + } else { + // FVP Foundation Model with GICv3 + return ARM_FVP_FOUNDATION_GICV3; + } + } + } + return ARM_FVP_UNKNOWN; +} + +/** + Return a pool allocated copy of the DTB image that is appropriate for + booting the current platform via DT. + + @param[out] Dtb Pointer to the DTB copy + @param[out] DtbSize Size of the DTB copy + + @retval EFI_SUCCESS Operation completed successfully + @retval EFI_NOT_FOUND No suitable DTB image could be located + @retval EFI_OUT_OF_RESOURCES No pool memory available + +**/ +EFI_STATUS +EFIAPI +DtPlatformLoadDtb ( + OUT VOID **Dtb, + OUT UINTN *DtbSize + ) +{ + EFI_STATUS Status; + VOID *OrigDtb; + VOID *CopyDtb; + UINTN OrigDtbSize; + ARM_VEXPRESS_PLATFORM_ID PlatformId; + + PlatformId = GetPlatformId (); + ASSERT (PlatformId < ARM_FVP_UNKNOWN); + if (PlatformId >= ARM_FVP_UNKNOWN) { + return EFI_NOT_FOUND; + } + + Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid, + EFI_SECTION_RAW, (UINTN)PlatformId, &OrigDtb, &OrigDtbSize); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + CopyDtb = AllocateCopyPool (OrigDtbSize, OrigDtb); + if (CopyDtb == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *Dtb = CopyDtb; + *DtbSize = OrigDtbSize; + + return EFI_SUCCESS; +} diff --git a/Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.inf b/Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.inf new file mode 100644 index 000000000000..5012101fe8db --- /dev/null +++ b/Platforms/ARM/VExpress/Library/ArmVExpressDtPlatformDtbLoaderLib/ArmVExpressDtPlatformDtbLoaderLib.inf @@ -0,0 +1,39 @@ +/** @file +* +* Copyright (c) 2017, 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 = 0x00010019 + BASE_NAME = ArmVExpressDtPlatformDtbLoaderLib + FILE_GUID = 050d6041-1508-4ae7-a69f-250155ccb567 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = DtPlatformDtbLoaderLib|DXE_DRIVER + +[Sources] + ArmVExpressDtPlatformDtbLoaderLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + ArmGicLib + BaseLib + DxeServicesLib + IoLib + MemoryAllocationLib + +[Guids] + gDtPlatformDefaultDtbFileGuid