From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.120]) by mx.groups.io with SMTP id smtpd.web10.10900.1589458556567498284 for ; Thu, 14 May 2020 05:15:56 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G7bN1Sid; spf=pass (domain: redhat.com, ip: 205.139.110.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589458554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i2PZ7D7EBfQjnoLci5uv/QxLXmcF9EgpCvV4JuPuw1Q=; b=G7bN1SidwyU9rnZN34mIZNlIi3faft/kT9pVdSqxuLZTE/2O1u0VzZO65NM/Z3jxtzkkUg AbKakbLosfS42VCjVwg6sXDzpCJQDTHzbuTzjd8Y/RNc9ize6aGa/sOyFTD0O4viqRdtmv yXnotpavspGW+D1PdrRvuAlYU5YflVk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-26SlIthsOFCwuUjLoLuJrg-1; Thu, 14 May 2020 08:15:53 -0400 X-MC-Unique: 26SlIthsOFCwuUjLoLuJrg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9AADA0BD8; Thu, 14 May 2020 12:15:50 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-179.ams2.redhat.com [10.36.113.179]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A9A6619BC; Thu, 14 May 2020 12:15:48 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v1 07/11] ArmVirtPkg: kvmtool platform memory map To: devel@edk2.groups.io, sami.mujawar@arm.com Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, Alexandru.Elisei@arm.com, Andre.Przywara@arm.com, Matteo.Carlini@arm.com, Laura.Moretta@arm.com, nd@arm.com References: <20200514084019.71368-1-sami.mujawar@arm.com> <20200514084019.71368-8-sami.mujawar@arm.com> From: "Laszlo Ersek" Message-ID: <8b09d7ff-a573-1deb-5b1d-5bb51daf9657@redhat.com> Date: Thu, 14 May 2020 14:15:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200514084019.71368-8-sami.mujawar@arm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 05/14/20 10:40, Sami Mujawar wrote: > Kvmtool is a virtual machine manager that enables > hosting KVM guests. Kvmtool allows to vary the > hardware configuration of the emulated platform > it provides to the guest partition. It provides > the current hardware configuration to the firmware > by handing off a device tree containing the hardware > information. > > This library parses the kvmtool provided device > tree and populates the system memory map for the > kvmtool emulated platform. > > Signed-off-by: Sami Mujawar > --- > ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c | 114 ++++++++++++++++++++ > ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf | 42 ++++++++ > 2 files changed, 156 insertions(+) > > diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c > new file mode 100644 > index 0000000000000000000000000000000000000000..0d353733478b2d097d160246007022990a9cbacb > --- /dev/null > +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c > @@ -0,0 +1,114 @@ > +/** @file > + > + Copyright (c) 2018, ARM Limited. All rights reserved. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +// Number of Virtual Memory Map Descriptors > +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5 > + > +#define LOG_VM_MAP(txt) \ (1) Please use "Txt" at least. There are some other mild coding style discrepancies in this patch, but I don't want to obsess about those. With (1) fixed: Acked-by: Laszlo Ersek Thanks Laszlo > + DEBUG (( \ > + DEBUG_ERROR, \ > + "%a: " #txt "\n" \ > + "\tPhysicalBase: 0x%lX\n" \ > + "\tVirtualBase: 0x%lX\n" \ > + "\tLength: 0x%lX\n", \ > + __FUNCTION__, \ > + VirtualMemoryTable[Idx].PhysicalBase, \ > + VirtualMemoryTable[Idx].VirtualBase, \ > + VirtualMemoryTable[Idx].Length \ > + )); > + > +/** > + Return the Virtual Memory Map of your platform > + > + This Virtual Memory Map is used by MemoryInitPei Module to initialize the 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; > + UINTN Idx = 0; > + EFI_PHYSICAL_ADDRESS TopOfAddressSpace; > + > + ASSERT (VirtualMemoryMap != NULL); > + > + TopOfAddressSpace = LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()); > + > + VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*) > + AllocatePages ( > + EFI_SIZE_TO_PAGES ( > + sizeof (ARM_MEMORY_REGION_DESCRIPTOR) * > + MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS > + ) > + ); > + > + if (VirtualMemoryTable == NULL) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Error: Failed to Allocate Pages\n", > + __FUNCTION__ > + )); > + return; > + } > + > + // System DRAM > + VirtualMemoryTable[Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase); > + VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase; > + VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemorySize); > + VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK; > + LOG_VM_MAP ("System DRAM Memory Map"); > + > + // Peripheral space before DRAM > + VirtualMemoryTable[++Idx].PhysicalBase = 0x0; > + VirtualMemoryTable[Idx].VirtualBase = 0x0; > + VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemoryBase); > + VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; > + LOG_VM_MAP ("Peripheral space before DRAM"); > + > + // Peripheral space after DRAM > + VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase) + > + PcdGet64 (PcdSystemMemorySize); > + VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase; > + VirtualMemoryTable[Idx].Length = TopOfAddressSpace - > + VirtualMemoryTable[Idx].PhysicalBase; > + VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; > + LOG_VM_MAP ("Peripheral space after DRAM"); > + > + // Map the FV region as normal executable memory > + VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdFvBaseAddress); > + VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase; > + VirtualMemoryTable[Idx].Length = FixedPcdGet32 (PcdFvSize); > + VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK; > + LOG_VM_MAP ("FV region"); > + > + // End of Table > + VirtualMemoryTable[++Idx].PhysicalBase = 0; > + VirtualMemoryTable[Idx].VirtualBase = 0; > + VirtualMemoryTable[Idx].Length = 0; > + VirtualMemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0; > + > + ASSERT((Idx + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS); > + > + *VirtualMemoryMap = VirtualMemoryTable; > +} > diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf > new file mode 100644 > index 0000000000000000000000000000000000000000..dbf4ceabe3ae0db5e743e1d9a575542dca32ed0a > --- /dev/null > +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf > @@ -0,0 +1,42 @@ > +#/* @file > +# > +# Copyright (c) 2018, ARM Limited. All rights reserved. > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#*/ > + > +[Defines] > + INF_VERSION = 0x0001001B > + BASE_NAME = KvmtoolVirtMemInfoLib > + FILE_GUID = B752E953-394F-462C-811C-F8BE35C8C071 > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = ArmVirtMemInfoLib > + > +[Sources] > + KvmtoolVirtMemInfoLib.c > + > +[Packages] > + ArmPkg/ArmPkg.dec > + ArmVirtPkg/ArmVirtPkg.dec > + EmbeddedPkg/EmbeddedPkg.dec > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + > +[LibraryClasses] > + ArmLib > + BaseLib > + BaseMemoryLib > + DebugLib > + MemoryAllocationLib > + PcdLib > + > +[Pcd] > + gArmTokenSpaceGuid.PcdFvBaseAddress > + gArmTokenSpaceGuid.PcdSystemMemoryBase > + gArmTokenSpaceGuid.PcdSystemMemorySize > + > +[FixedPcd] > + gArmTokenSpaceGuid.PcdFvSize > + >