From patchwork Mon Apr 10 16:22:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 97183 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1426396obc; Mon, 10 Apr 2017 09:22:30 -0700 (PDT) X-Received: by 10.237.37.146 with SMTP id x18mr17730190qtc.156.1491841350249; Mon, 10 Apr 2017 09:22:30 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b11si13873889qta.25.2017.04.10.09.22.29; Mon, 10 Apr 2017 09:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=linaro-uefi-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DBE4860C2C; Mon, 10 Apr 2017 16:22:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id CC11F61E64; Mon, 10 Apr 2017 16:22:27 +0000 (UTC) X-Original-To: linaro-uefi@lists.linaro.org Delivered-To: linaro-uefi@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id F061D63DEA; Mon, 10 Apr 2017 16:22:26 +0000 (UTC) Received: from mail-wr0-f178.google.com (mail-wr0-f178.google.com [209.85.128.178]) by lists.linaro.org (Postfix) with ESMTPS id 54EA663E1C for ; Mon, 10 Apr 2017 16:22:24 +0000 (UTC) Received: by mail-wr0-f178.google.com with SMTP id l28so23022918wre.0 for ; Mon, 10 Apr 2017 09:22:24 -0700 (PDT) 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=iTGyhjdaZu1Ouca3Vz2ELlyVrFohBxA/WIKBXWkPsCO4qLOWoLkaec5boBbYKiB63M QmGgZrtN4j+g7Ih5ADj9ukB226YssMbzAQKHaVo/exxSgzKa7g82sQc/cyYrbVSRUK4f McgJ9o7/Y/5iBIXe8Iyx2XftPW+shG5UFJYg+pXCl04F/eewBs3jp7Td1s1MLcjsCSGb KIj8O6zCTRU67DRnLR980t55IzrIJA1NnI4U53DwDgprmjzcQl+3NbX32qWd4UGTh/mr AL5hn3cJbDysrZp1hZC2lUp3XTex0RVyQCy7sANWJpHH5Qm0SMAD70uT8cWqzmkw4P+T nE4w== X-Gm-Message-State: AFeK/H1UQFuPMM1cJlakg0vToYfzGco/6BY4XIDhumJGVDRvikqCHWcFFLCKzBoHiLwygXHosyc= X-Received: by 10.223.164.137 with SMTP id g9mr38319443wrb.92.1491841343169; Mon, 10 Apr 2017 09:22:23 -0700 (PDT) Received: from localhost.localdomain ([196.85.182.219]) by smtp.gmail.com with ESMTPSA id z38sm18140215wrc.36.2017.04.10.09.22.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 09:22:22 -0700 (PDT) From: Ard Biesheuvel To: linaro-uefi@lists.linaro.org Date: Mon, 10 Apr 2017 17:22:07 +0100 Message-Id: <20170410162208.20611-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170410162208.20611-1-ard.biesheuvel@linaro.org> References: <20170410162208.20611-1-ard.biesheuvel@linaro.org> Subject: [Linaro-uefi] [PATCH v3 5/6] Platforms/FVP: add DtPlatformDtbLoaderLib implementation X-BeenThere: linaro-uefi@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-uefi-bounces@lists.linaro.org Sender: "Linaro-uefi" 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(+) 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