From nobody Wed Dec 25 02:39:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511345296105357.80476065030996; Wed, 22 Nov 2017 02:08:16 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A1D43220C162C; Wed, 22 Nov 2017 02:03:46 -0800 (PST) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (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 F33C1220C1600 for ; Wed, 22 Nov 2017 02:03:42 -0800 (PST) Received: by mail-wm0-x242.google.com with SMTP id x63so8920139wmf.4 for ; Wed, 22 Nov 2017 02:07:59 -0800 (PST) Received: from localhost.localdomain ([154.145.25.106]) by smtp.gmail.com with ESMTPSA id i192sm2761457wmf.46.2017.11.22.02.07.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 02:07:56 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::242; helo=mail-wm0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org 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=RtbtrQNGCDDtVPr+kttRw34DXIqA/CXLpnSA4VoHXRw=; b=X9Y76jUci5zi62MZWZZMWjHRrTqoNVKc0jGLrsNB53rz4rvtc9Lx5kucK4WcW65zpo TtCXb5lIB9kbcQqhP5nmTCB3lnJLvAmfOAe1wq4kJBhFoNGM9UevstLHPAeE0VwssnXn s52VF/+p/kyiZtuFvs7FcIZAa7ESpxkbThjKY= 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=RtbtrQNGCDDtVPr+kttRw34DXIqA/CXLpnSA4VoHXRw=; b=pUzk2+5RclScQYAIPwFfxew3E3hU0BgyqVwLDTMvq6iZjSe2D4fIQoreURdluTR/tx 6EdvemllFsTLwonmZ73h4a9yqGIPxffHWfbk9/5sUVJifPf9K+wjrA3pVhdUN0T6VsNs XNZuyK6b/KaFgt2kwcdb1CKlLIAO134nh4OwYIixad+85qM815jpRmo/kf1fuEBi7Krb 0cvFkoV5YvOu8tko82oi7hwYPYcPcL842f+3pCGpxZkiaXzYDKVCb/Rapk23oHsqL7Nl G4g9u2+nFmMBk0yUVK8g24QTb9vjltX3aNlmc52JFcylpPIHygBghPDGdkJ2kYepHo/z v2yQ== X-Gm-Message-State: AJaThX4ebREHcbgU/Ql4HpKJJlQlKeBh7e7fC5avHR8F2Bbk2UyvLBc/ pMqY0SIX+CnMYDF9pu6g9gbYNtEjDkY= X-Google-Smtp-Source: AGs4zMal5KCRAeAdl9jlwljm7xZ2BJszqoHdavcAWTj39fOHyTOkl3SNQ9rhyuEDm9fjNCkCt4iydA== X-Received: by 10.28.34.67 with SMTP id i64mr3675047wmi.57.1511345277487; Wed, 22 Nov 2017 02:07:57 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Wed, 22 Nov 2017 10:07:28 +0000 Message-Id: <20171122100731.24525-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171122100731.24525-1-ard.biesheuvel@linaro.org> References: <20171122100731.24525-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: add ArmVirtMemInfoLib 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 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create a new ArmVirtMemInfoLib for ArmVirtQemuKernel by cloning the existing ArmPlatformGetVirtualMemoryMap () for this platform, (ArmQemuRelocatablePlatformLib *not* ArmVirtPlatformLib), and cleaning it up: - remove support for uncached DRAM mappings - replace EFI_D_xxx with DEBUG_xxx throughout - use a temp variable to hold the top of the physical address space - use AllocatePool () instead of AllocatePages (), given that we use 160 bytes only, and the memory is never freed. In a future patch, we will add this library to the ordinary ArmVirtQemu platform as well. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 + ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S | 39 ++++++++ ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S | 24 +++++ ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c | 100 +++++++= +++++++++++++ ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf | 54 +++++++= ++++ 5 files changed, 218 insertions(+) diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index 7e5d584344b4..f50d30388cf2 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -49,6 +49,7 @@ [LibraryClasses.common] QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf =20 ArmPlatformLib|ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuR= elocatablePlatformLib.inf + ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoL= ib.inf =20 TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf NorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.i= nf diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S b/= ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S new file mode 100644 index 000000000000..a1f6a194d59b --- /dev/null +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S @@ -0,0 +1,39 @@ +# +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016-2017, Linaro Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +# + +#include + +//EFI_PHYSICAL_ADDRESS +//GetPhysAddrTop ( +// VOID +// ); +ASM_FUNC(ArmGetPhysAddrTop) + mrs x0, id_aa64mmfr0_el1 + adr x1, .LPARanges + and x0, x0, #7 + ldrb w1, [x1, x0] + mov x0, #1 + lsl x0, x0, x1 + ret + +// +// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the +// physical address space support on this CPU: +// 0 =3D=3D 32 bits, 1 =3D=3D 36 bits, etc etc +// 6 and 7 are reserved +// +.LPARanges: + .byte 32, 36, 40, 42, 44, 48, -1, -1 + +ASM_FUNCTION_REMOVE_IF_UNREFERENCED diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S b/ArmV= irtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S new file mode 100644 index 000000000000..9cd81529fb3d --- /dev/null +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S @@ -0,0 +1,24 @@ +# +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2014-2017, Linaro Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +# + +#include + +//EFI_PHYSICAL_ADDRESS +//GetPhysAddrTop ( +// VOID +// ); +ASM_FUNC(ArmGetPhysAddrTop) + mov r0, #0x00000000 + mov r1, #0x10000 + bx lr diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/A= rmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c new file mode 100644 index 000000000000..ea70f2c33b77 --- /dev/null +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c @@ -0,0 +1,100 @@ +/** @file + + Copyright (c) 2014-2017, Linaro Limited. All rights reserved. + + This program and the accompanying materials are licensed and made availa= ble + 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 IMP= LIED. + +**/ + +#include +#include +#include +#include +#include + +// Number of Virtual Memory Map Descriptors +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5 + +EFI_PHYSICAL_ADDRESS +ArmGetPhysAddrTop ( + VOID + ); + +/** + Return the Virtual Memory Map of your platform + + This Virtual Memory Map is used by MemoryInitPei Module to initialize th= e MMU + on your platform. + + @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR + describing a Physical-to-Virtual Memory + mapping. This array must be ended by a + zero-filled entry. The allocated memory + will not be freed. + +**/ +VOID +ArmVirtGetMemoryMap ( + OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap + ) +{ + ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; + UINT64 TopOfMemory; + + ASSERT (VirtualMemoryMap !=3D NULL); + + VirtualMemoryTable =3D AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTO= R) * + MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS); + + if (VirtualMemoryTable =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION= __)); + return; + } + + // System DRAM + VirtualMemoryTable[0].PhysicalBase =3D PcdGet64 (PcdSystemMemoryBase); + VirtualMemoryTable[0].VirtualBase =3D VirtualMemoryTable[0].PhysicalBas= e; + VirtualMemoryTable[0].Length =3D PcdGet64 (PcdSystemMemorySize); + VirtualMemoryTable[0].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK; + + DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + __FUNCTION__, + VirtualMemoryTable[0].PhysicalBase, + VirtualMemoryTable[0].VirtualBase, + VirtualMemoryTable[0].Length)); + + // Peripheral space before DRAM + VirtualMemoryTable[1].PhysicalBase =3D 0x0; + VirtualMemoryTable[1].VirtualBase =3D 0x0; + VirtualMemoryTable[1].Length =3D VirtualMemoryTable[0].PhysicalBas= e; + VirtualMemoryTable[1].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_DEVIC= E; + + // Peripheral space after DRAM + TopOfMemory =3D MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize), + ArmGetPhysAddrTop ()); + VirtualMemoryTable[2].PhysicalBase =3D VirtualMemoryTable[0].Length + Vi= rtualMemoryTable[1].Length; + VirtualMemoryTable[2].VirtualBase =3D VirtualMemoryTable[2].PhysicalBas= e; + VirtualMemoryTable[2].Length =3D TopOfMemory - + VirtualMemoryTable[2].PhysicalBase; + VirtualMemoryTable[2].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_DEVIC= E; + + // Remap the FD region as normal executable memory + VirtualMemoryTable[3].PhysicalBase =3D PcdGet64 (PcdFdBaseAddress); + VirtualMemoryTable[3].VirtualBase =3D VirtualMemoryTable[3].PhysicalBas= e; + VirtualMemoryTable[3].Length =3D FixedPcdGet32 (PcdFdSize); + VirtualMemoryTable[3].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK; + + // End of Table + ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR)); + + *VirtualMemoryMap =3D VirtualMemoryTable; +} diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf b= /ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf new file mode 100644 index 000000000000..c72a97f9e78a --- /dev/null +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf @@ -0,0 +1,54 @@ +#/* @file +# +# Copyright (c) 2011-2015, ARM Limited. All rights reserved. +# Copyright (c) 2014-2017, Linaro Limited. All rights reserved. +# +# This program and the accompanying materials are licensed and made avail= able +# 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 IM= PLIED. +# +#*/ + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D QemuVirtMemInfoLib + FILE_GUID =3D 9b30ca82-6746-4a82-a3e6-11ea79df3b46 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmVirtMemInfoLib + +[Sources] + QemuVirtMemInfoLib.c + +[Sources.ARM] + Arm/PhysAddrTop.S + +[Sources.AARCH64] + AArch64/PhysAddrTop.S + +[Packages] + ArmPkg/ArmPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PcdLib + +[Pcd] + gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + +[FixedPcd] + gArmTokenSpaceGuid.PcdFdSize + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel