From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (EUR02-AM5-obe.outbound.protection.outlook.com [40.107.0.88]) by mx.groups.io with SMTP id smtpd.web12.8517.1589445889326224056 for ; Thu, 14 May 2020 01:44:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=6X5zqANc; spf=pass (domain: arm.com, ip: 40.107.0.88, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9g7s2mpY9VPv9EPdnjNAjItfZYn18sUE+hPKftTj1Rg=; b=6X5zqANckSBHt1hYV6jGmmT8ZdEzt/iq0IGoVStsbkvMQfteyyfJ8i3hbXtNB6uKD6jaBPJ2F1+lX7V/iL/yJpOb2I/iw9RN8amGXujalqfPwn9uJhfkOYOfv0z/FncXsRX60srtGcbe3OH6o3ONEzymBOYzS4A0lIV69EalZuA= Received: from DB8PR06CA0011.eurprd06.prod.outlook.com (2603:10a6:10:100::24) by VE1PR08MB5245.eurprd08.prod.outlook.com (2603:10a6:803:10a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.34; Thu, 14 May 2020 08:44:45 +0000 Received: from DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:100:cafe::d0) by DB8PR06CA0011.outlook.office365.com (2603:10a6:10:100::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Thu, 14 May 2020 08:44:45 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT044.mail.protection.outlook.com (10.152.21.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Thu, 14 May 2020 08:44:45 +0000 Received: ("Tessian outbound 11763d234d54:v54"); Thu, 14 May 2020 08:44:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 45769ff3d30fde2b X-CR-MTA-TID: 64aa7808 Received: from da156ad1b19b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2A4AF84D-66B5-429E-9416-8E53A1C4BDB7.1; Thu, 14 May 2020 08:44:40 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id da156ad1b19b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 14 May 2020 08:44:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TSz3aPB08Rr8mMKglYRAh9BcFo/qSOk7DErjs/N9lNszKBguwDHwag2oJh4BkzOAy4lE2Y/roryFWo+ctYKIwl+qrwUpOdX4kT5c8d/wm/Hw1ZnZ08mfmsI8mO23SBvXIU/j3XoFAUQe5Sp2tfsNuN7RmUFwjL6SL27NhYaIduC/hIIfMNn/M+FztV0eLQB4tqpnRtU2GJEJKqyevGkcLn3xDh1KZMOXbHVJ/LqUgY6YqLKC38vCh8n301ntfxLW9faRcxq/0nhhEGV1FSG1UvwmZDWxUwadsGtFgIaAiPtJ9+7nbyvRLJKz5cOmrXR2LxC+DXmGuio1xFxVmjxZEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9g7s2mpY9VPv9EPdnjNAjItfZYn18sUE+hPKftTj1Rg=; b=e9gO6dWq3+0EsEZJAdLxcYZmcs39+HFoVMDrNfNS2XyS+qz7zcDooixBTRnQIuU7gHaGjduq5wKvpzpLMuRhMT8nYSQfMkfCZgNpdXXbQcALKwPF1zTgrNs9AJHV73OikA6opIm0vmslnwu5ZRoqViTScdU27/sdnQNpDBV+2y1MhKXls94HK1KEZVeU8oy1/Xxt2l44motDy3e7+MHALP2t9DYASkyJan83J93W3RsEbVaJg08LH59X+5Np7D7lMSNyJY5An0D4reQBSx72MEZRCQlCiw5KIBVyHBCEcbgnLZ5PIMfOK74kVqVa/Bn6+eLs4I0c4Ic7uVHotVHk1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9g7s2mpY9VPv9EPdnjNAjItfZYn18sUE+hPKftTj1Rg=; b=6X5zqANckSBHt1hYV6jGmmT8ZdEzt/iq0IGoVStsbkvMQfteyyfJ8i3hbXtNB6uKD6jaBPJ2F1+lX7V/iL/yJpOb2I/iw9RN8amGXujalqfPwn9uJhfkOYOfv0z/FncXsRX60srtGcbe3OH6o3ONEzymBOYzS4A0lIV69EalZuA= Received: from DB6PR0301CA0058.eurprd03.prod.outlook.com (2603:10a6:4:54::26) by VI1PR08MB4365.eurprd08.prod.outlook.com (2603:10a6:803:fb::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Thu, 14 May 2020 08:44:38 +0000 Received: from DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:54:cafe::f0) by DB6PR0301CA0058.outlook.office365.com (2603:10a6:4:54::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Thu, 14 May 2020 08:44:38 +0000 Authentication-Results-Original: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT021.mail.protection.outlook.com (10.152.20.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3000.19 via Frontend Transport; Thu, 14 May 2020 08:44:38 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Thu, 14 May 2020 08:40:28 +0000 Received: from E107187.Arm.com (10.57.42.179) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Thu, 14 May 2020 08:40:28 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v1 07/11] ArmVirtPkg: kvmtool platform memory map Date: Thu, 14 May 2020 09:40:15 +0100 Message-ID: <20200514084019.71368-8-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200514084019.71368-1-sami.mujawar@arm.com> References: <20200514084019.71368-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(376002)(136003)(346002)(46966005)(4326008)(47076004)(36756003)(7696005)(1076003)(8936002)(81166007)(5660300002)(356005)(86362001)(8676002)(82740400003)(82310400002)(2906002)(6666004)(6916009)(478600001)(336012)(2616005)(70586007)(70206006)(54906003)(26005)(44832011)(186003)(426003)(316002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb674625-2482-40ca-3829-08d7f7e30dc0 X-MS-TrafficTypeDiagnostic: VI1PR08MB4365:|VE1PR08MB5245: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7219;OLM:7219; X-Forefront-PRVS: 040359335D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Juq0q3v6fFlh+WjD7cTV05ScDPpuv561+ro5+Nf9UmOgtfeMWeNup1BEWeN2ymUzYgkd3SDXfFW4N4Tq0ck4Z9jJWyu24DwbUQ7o35cEKnF4ZJgY4Ia5krDbQU3Bm5UO8/TlqecJXH0aZlfqTr2NUV4BxxFdxaRKStyl2X6ut6E/rTKoQgwR2I/oNhjhHSteja+kYMniuQ7hnnQTwoskJwtW3TPq0mTpS/LO96mtyMF6k6KCdKJUQ9YoiIgv+pov0NYM9h54vF5QczrA6T4obGBRSEAQpvaHFDY3kG7MW2PtLX6bzAU28jf1OkT4qLParW247CVpe4NnCFQW0H89XPOMp9UYAU0wi53yoY/4Xv5oR2yCzEjx2x9Ufvlil7t537FOpcf2N5riRArl+dGyZtRqRlz0Rq3ipe9xXim3bppt2oqwT+2m+aamoMpaAcsZTTSdTBH6HBiMtZUw9DT7zgk6vAv5cACv3VjM5JLwE+fAhZZ2DzFBaWHtj+D+nsyQyNN7dbZz80gCt/i4JundMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4365 Original-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(396003)(376002)(346002)(39860400002)(136003)(46966005)(316002)(7696005)(8676002)(336012)(36756003)(86362001)(5660300002)(44832011)(6916009)(70586007)(1076003)(8936002)(2906002)(4326008)(26005)(2616005)(70206006)(82740400003)(426003)(47076004)(81166007)(186003)(478600001)(54906003)(6666004)(82310400002);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 3eeccd6a-7d6d-4e3e-998d-08d7f7e30982 X-Forefront-PRVS: 040359335D X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c3wlSsInqoiH/Fdgrsopmbj47BM8LpPvjgWkZs28JYn6qU5MdMVGsmCWLWyDpStlDY1CyetT5Y2QhmYYJ0tUGw7Hed/GLZ0a72i5R09pYk9wPoWG1mvcx6WUn9QUbdplxsw0gKz0jJVaiwcw4MUNeN58hWkfxI/vcqjRDhONr+ncka1+ZTk9CKwTeVeK3zTe+cgSoMcuUznn8z4pLNkQh/Io/BpUCGzK0p7qRMytDrramFRKe23zQ8vagJ1NivkXzLPd7+mafNiYpNgk7NojjkDiG0j/ts2KVBERJrtSOnFpKlARp26KGlF3PsbdzidCopqSlY2yIS0dzRNMoHrXmhX//zenWyF8fMhI+qK9Vv2KAujLdg8M7FZ7BJmL+AES/YYamQKSEFy1UjXjfCWghognhXuifOVVHx0gTcinhvF7G840GATA1xF0atnLUh6bjJaaevt1oe3QSD6rj8kHGTstbw8zuMo9Ov3YN34jv81Ls6SIv+NLRgkSGrpk6F6q+YoRA6erEBMjLhnrGe4ASg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 08:44:45.6482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb674625-2482-40ca-3829-08d7f7e30dc0 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5245 Content-Type: text/plain 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) \ + 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 + -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'