From patchwork Tue Feb 24 18:02:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 44980 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73C502029F for ; Tue, 24 Feb 2015 18:06:50 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf18348657lab.2 for ; Tue, 24 Feb 2015 10:06:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=ERDQEGQqT5XxO6ls58bcp9tspegbc0mXypfltGmPB8I=; b=dKqCRBxin9xv36LbPnktsf513P0JNVFrv0jKKVwlJW5opx5ITZIBZd0l3G4T6dqD1S DLOuDQDyp5+S+0FM8WoBClTIbDOnxrZ/x6Nst/Y6zRbDeopXuocY8aFpRwwwe1dVRne1 By1qiXVNXqriCR01fErMhmxSmGnwlNJOJlji1uFlz4CjSruwhSsDtCcdJPoZNPdvYesF nZQ33zAqzHJVicuyrb+xKyMW1NhcY5LslZHxGTNMz3O+olY5PdwoBB8NR7qKTX5wUG0a 25W7i0g9gGDklbyqfN2/MBa1i5FjFbdGgSDMNh+TAVk6qRDeoQKVOFU1mPrdQE5rSthe 9KWw== X-Gm-Message-State: ALoCoQkiS4G8sYh89Dsw3yStqvT3t4cr9vJroJk/9iXcOgkHIj3ejFlhNrXXy+cpicVhOscPKSvi X-Received: by 10.180.101.101 with SMTP id ff5mr2303533wib.5.1424801209446; Tue, 24 Feb 2015 10:06:49 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.137 with SMTP id s9ls650282las.15.gmail; Tue, 24 Feb 2015 10:06:49 -0800 (PST) X-Received: by 10.112.46.201 with SMTP id x9mr275034lbm.65.1424801209290; Tue, 24 Feb 2015 10:06:49 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id zq10si1836245lbb.106.2015.02.24.10.06.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Feb 2015 10:06:49 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by labgd6 with SMTP id gd6so4906836lab.8 for ; Tue, 24 Feb 2015 10:06:49 -0800 (PST) X-Received: by 10.152.179.172 with SMTP id dh12mr15063830lac.76.1424801209147; Tue, 24 Feb 2015 10:06:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp2079467lbj; Tue, 24 Feb 2015 10:06:47 -0800 (PST) X-Received: by 10.140.94.236 with SMTP id g99mr8742691qge.70.1424801207226; Tue, 24 Feb 2015 10:06:47 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id s20si25806418qge.73.2015.02.24.10.06.45 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Feb 2015 10:06:47 -0800 (PST) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQJqe-00020V-Gl; Tue, 24 Feb 2015 18:04:44 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQJqc-0001y9-TF for xen-devel@lists.xen.org; Tue, 24 Feb 2015 18:04:43 +0000 Received: from [193.109.254.147] by server-3.bemta-14.messagelabs.com id 1A/0C-10964-A3DBCE45; Tue, 24 Feb 2015 18:04:42 +0000 X-Env-Sender: ard.biesheuvel@linaro.org X-Msg-Ref: server-5.tower-27.messagelabs.com!1424801081!7939418!1 X-Originating-IP: [74.125.82.181] X-SpamReason: No, hits=0.0 required=7.0 tests=UPPERCASE_25_50 X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27128 invoked from network); 24 Feb 2015 18:04:41 -0000 Received: from mail-we0-f181.google.com (HELO mail-we0-f181.google.com) (74.125.82.181) by server-5.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 24 Feb 2015 18:04:41 -0000 Received: by wesu56 with SMTP id u56so26840448wes.10 for ; Tue, 24 Feb 2015 10:04:41 -0800 (PST) X-Received: by 10.195.12.35 with SMTP id en3mr33632454wjd.129.1424801081125; Tue, 24 Feb 2015 10:04:41 -0800 (PST) Received: from ards-macbook-pro.lan (bl11-65-113.dsl.telepac.pt. [85.244.65.113]) by mx.google.com with ESMTPSA id w8sm12792521wja.4.2015.02.24.10.04.37 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Feb 2015 10:04:39 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, olivier.martin@arm.com, lersek@redhat.com, roy.franz@linaro.org, leif.lindholm@linaro.org, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, anthony.perard@citrix.com, xen-devel@lists.xen.org, julien.grall@linaro.org, jordan.l.justen@intel.com, michael.d.kinney@intel.com Date: Tue, 24 Feb 2015 18:02:51 +0000 Message-Id: <1424800990-15777-11-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1424800990-15777-1-git-send-email-ard.biesheuvel@linaro.org> References: <1424800990-15777-1-git-send-email-ard.biesheuvel@linaro.org> Cc: wei.liu2@citrix.com, Ard Biesheuvel Subject: [Xen-devel] [PATCH v5 10/29] ArmVirtualizationPkg: implement custom MemoryInitPeiLib X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This implements a MemoryInitPeiLib instance that differs from the stock ArmPlatformPkg version only in the fact that it does not remove the memory used by the flash device (FD). The reason is that, when using PrePi, the DXE core is started immediately and never returns so there is no reason to preserve any of the memory that the flash device occupied originally, and it is preferable to release is so that the OS loader can reuse it. This is especially important for the relocatable PrePi configuration, which is aimed at being launched from a boot loader that itself adheres to the Linux arm64 boot protocol. Contributed-under: TianoCore Contribution Agreement 1.0 Acked-by: Laszlo Ersek Reviewed-By: Olivier Martin Signed-off-by: Ard Biesheuvel --- .../ArmVirtualizationMemoryInitPeiLib.c | 91 ++++++++++++++++++++++ .../ArmVirtualizationMemoryInitPeiLib.inf | 66 ++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c new file mode 100644 index 000000000000..5f6cd059c47f --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c @@ -0,0 +1,91 @@ +/** @file +* +* Copyright (c) 2011-2014, ARM Limited. All rights reserved. +* Copyright (c) 2014, Linaro Limited. 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 + +VOID +BuildMemoryTypeInformationHob ( + VOID + ); + +VOID +InitMmu ( + VOID + ) +{ + ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; + VOID *TranslationTableBase; + UINTN TranslationTableSize; + RETURN_STATUS Status; + + // Get Virtual Memory Map from the Platform Library + ArmPlatformGetVirtualMemoryMap (&MemoryTable); + + //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in + // DRAM (even at the top of DRAM as it is the first permanent memory allocation) + Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n")); + } +} + +EFI_STATUS +EFIAPI +MemoryPeim ( + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, + IN UINT64 UefiMemorySize + ) +{ + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; + + // Ensure PcdSystemMemorySize has been set + ASSERT (PcdGet64 (PcdSystemMemorySize) != 0); + + // + // Now, the permanent memory has been installed, we can call AllocatePages() + // + ResourceAttributes = ( + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_TESTED + ); + + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + PcdGet64 (PcdSystemMemoryBase), + PcdGet64 (PcdSystemMemorySize) + ); + + // Build Memory Allocation Hob + InitMmu (); + + if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) { + // Optional feature that helps prevent EFI memory map fragmentation. + BuildMemoryTypeInformationHob (); + } + + return EFI_SUCCESS; +} diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf new file mode 100644 index 000000000000..fcdae06de7c2 --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.inf @@ -0,0 +1,66 @@ +#/** @file +# +# Copyright (c) 2011-2014, ARM Ltd. All rights reserved.
+# Copyright (c) 2014, 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 = 0x00010005 + BASE_NAME = ArmVirtMemoryInitPeiLib + FILE_GUID = 021b6156-3cc8-4e99-85ee-13d8a871edf2 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + LIBRARY_CLASS = MemoryInitPeiLib + +[Sources] + ArmVirtualizationMemoryInitPeiLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + +[LibraryClasses] + DebugLib + HobLib + ArmLib + ArmPlatformLib + +[Guids] + gEfiMemoryTypeInformationGuid + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob + +[FixedPcd] + gArmTokenSpaceGuid.PcdFdSize + + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData + +[Pcd] + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + gArmTokenSpaceGuid.PcdFdBaseAddress + +[Depex] + TRUE