From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.85]) by mx.groups.io with SMTP id smtpd.web11.15382.1594126120807950686 for ; Tue, 07 Jul 2020 05:48:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=bJ9GOQIm; spf=pass (domain: arm.com, ip: 40.107.8.85, 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=ISuUmMsefX5IsgSOtlJ4XTZT/QuX/hhcTvmCvZEEtgQ=; b=bJ9GOQImBOzj0Ck3GEinFmrKuPTVyGynn5OuMbeWy/Zq+EMKEQ/8uCC5zCyKqY0sYpuREfCdKanmdy+2Ef6DhXWUkFSJCwR2JgUQpzPUxhjLTKQKU0S4Q2HmF0vRE6GJpG09PT+4g1iN5ps3KGnXkeDYG4HV6oMPQXrc/IJekio= Received: from FR2P281CA0009.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::19) by VI1PR0801MB2077.eurprd08.prod.outlook.com (2603:10a6:800:8b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.29; Tue, 7 Jul 2020 12:48:36 +0000 Received: from VE1EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:a:cafe::34) by FR2P281CA0009.outlook.office365.com (2603:10a6:d10:a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.8 via Frontend Transport; Tue, 7 Jul 2020 12:48:36 +0000 X-MS-Exchange-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 VE1EUR03FT007.mail.protection.outlook.com (10.152.18.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.24 via Frontend Transport; Tue, 7 Jul 2020 12:48:36 +0000 Received: ("Tessian outbound 2dd9eeca983c:v62"); Tue, 07 Jul 2020 12:48:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 13fa135319de1c00 X-CR-MTA-TID: 64aa7808 Received: from 5d1836d1b25c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id AC1AD02E-0C6E-436D-82FB-E2C603F20E7C.1; Tue, 07 Jul 2020 12:48:30 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5d1836d1b25c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 07 Jul 2020 12:48:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JWLE0XMu2K+DwSEfcn/3aPz2QXKVkcNapdlNk1m4sBVUjLT28HdpZI4mAQlCZW84bsEplAvZYKmA8znXVFFs9XqcAYKm2YJ8Uns6o06kVGWb2RUS9IzlW/HGsHF9UtJ72+sIfL/ns+rTmGaXRmzVTg9c9tKMGP8dKUctaNXSL4Bn7xF9A++LUlCa9HNpP8kvCp7gl37HfedBzWUQfu5ytlDejApeu0oDWHdmz/SaiR9k2IFtbaVoRQjmzkLxEklHyHmqBG9ccHv0MtSvf50MsfxHkEgCVHTiymm1miKvKp+3NBf1dUNvN7TwqQtC3E2QVgk521BsD1b+61WMJm1xiQ== 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=ISuUmMsefX5IsgSOtlJ4XTZT/QuX/hhcTvmCvZEEtgQ=; b=diErLUFMmSZcgHMtEQVFicu/9lU/Y0TeRwzaTKmoRgykJQ2oN2CFaluD8xPkUfPKvDEi7dE5IHZ7AgUAEO933VFDo5QyK95NBVGkh5BHOFap4FsqAc3U2h6ex1vgHLChPliroSx74qMas0Ar81xJhFJGg126at6YBB4HyfcG26DnOj0UMpr10Qis4IEfD5vXniBJeXsz3VQZJLBRF5Qf1Ri1PNB+6DeMpANwW6nVvNN1igZu0wf/gZeVmzgGWnjSucJv4Nc3Eky78OKIWhpm5Ber3qaiWDEIiW4abEuqWF2giArsG7+3GGiiWlCEOns0n+KbZtVRDPYTBgf0FIIR8A== 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=ISuUmMsefX5IsgSOtlJ4XTZT/QuX/hhcTvmCvZEEtgQ=; b=bJ9GOQImBOzj0Ck3GEinFmrKuPTVyGynn5OuMbeWy/Zq+EMKEQ/8uCC5zCyKqY0sYpuREfCdKanmdy+2Ef6DhXWUkFSJCwR2JgUQpzPUxhjLTKQKU0S4Q2HmF0vRE6GJpG09PT+4g1iN5ps3KGnXkeDYG4HV6oMPQXrc/IJekio= Received: from AM6P194CA0096.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:8f::37) by AM0PR08MB3377.eurprd08.prod.outlook.com (2603:10a6:208:d4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.23; Tue, 7 Jul 2020 12:48:29 +0000 Received: from VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8f:cafe::9f) by AM6P194CA0096.outlook.office365.com (2603:10a6:209:8f::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.23 via Frontend Transport; Tue, 7 Jul 2020 12:48:29 +0000 X-MS-Exchange-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; 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 VE1EUR03FT053.mail.protection.outlook.com (10.152.19.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3153.24 via Frontend Transport; Tue, 7 Jul 2020 12:48:29 +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; Tue, 7 Jul 2020 12:48:17 +0000 Received: from E107187.Arm.com (10.57.21.15) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Tue, 7 Jul 2020 12:48:16 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v4 05/15] ArmVirtPkg: kvmtool platform memory map Date: Tue, 7 Jul 2020 13:47:59 +0100 Message-ID: <20200707124810.50668-6-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200707124810.50668-1-sami.mujawar@arm.com> References: <20200707124810.50668-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)(396003)(39860400002)(376002)(346002)(136003)(46966005)(6916009)(336012)(7696005)(82740400003)(47076004)(186003)(6666004)(316002)(356005)(86362001)(26005)(4326008)(8936002)(54906003)(81166007)(82310400002)(8676002)(966005)(478600001)(70206006)(70586007)(44832011)(426003)(1076003)(2616005)(2906002)(5660300002)(36756003)(83380400001);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 397902f2-75c2-4fc0-84e6-08d82274108c X-MS-TrafficTypeDiagnostic: AM0PR08MB3377:|VI1PR0801MB2077: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-Forefront-PRVS: 0457F11EAF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: bu/nhoW3dWvskjrybU9lh7OFosl8dr/abb/X3mecC+KgEWYsP3IS62CtUOHbq+q6lLwoVMf1JFnwoQdGELBu6w3YbBqRXyzIJ1s3kyRPBHjJ3c3KpmZqezTZcXT341wFCllnHvCiDwMRr5mgZIvP9134s/WyYkDrw2xhmDm4h9IjRbFK7q0vHlOvjOd3DK/V8se19k3ijFFrAjMvMGVbaWPRupfjlireGQKNgyebDk0PF14cKP9q2u1nIgYrVZ34Vtm7l2sx7VqUlNnkpuzARNJdo0FudLwaaAIk9LZ+h5gFkh8bEYcngy3eBzjEFycF5FrBSPt1T8XbHUxE+IDZkw0bVTnSJBgihhHPS+WVrY7BuqxEo+5QJzDcS+wjRB6mS5xl1lzqaPFmbfdQPT3WuCLOiutVoMuq9ZM+SrnuqLjES/V0LBrA9WVw7tV03ZxAA0hMwpRlSyzBz6F3qpHEsSOKDD1BBneoeQdS5DFUUek= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3377 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT007.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)(136003)(39860400002)(376002)(396003)(346002)(46966005)(186003)(70206006)(82740400003)(70586007)(83380400001)(8676002)(81166007)(44832011)(82310400002)(4326008)(8936002)(6916009)(47076004)(336012)(1076003)(36756003)(426003)(2616005)(26005)(966005)(478600001)(36906005)(6666004)(54906003)(316002)(7696005)(2906002)(86362001)(5660300002);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: bd3326b1-fce4-4138-b5b6-08d822740c59 X-Forefront-PRVS: 0457F11EAF X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p9k3X6XmnqWViirLyBQxl2d6WEu76B+d7AdkT0XomBA209JZdFjfy2XRtPb4bL1LJLPCwcZQbzfy9y3QPqwQjZshUPFY0Q2iiXLSxtSSQChf34g5LQqxcOCCIkFHhJZX58tj8XFg9bVBOGY+w/v9lckS+DVnWAURo0ImLtY/mnxVMhWEyU+7iL7QPvU69bnWFfTFqb0qTrw9LvIGZYRMia28S3umjP9WIv50ZZbVEsgOnS3mw8FNE2qkI8McTNFLZWXkcIEN2jO4BzajorixqsDnNtnDdCZmHNzg2YGB/EAuTiuJuZZTTZNr1yfRmKQJGXpMtKR7p9tGaujlMIP5Y4MQcfOw9SXgmt/ZUazvIaPGIlxb/hdapPLb7+bDKefK5jKXfTbVPDLXVnm/vrcsFCxUpB/TTGxdgyitHh0Hf9+KWppQ9eeKUKt20mTJiCmRMj8JogZszipgvwCag5JjXkZGRWCN07EEwMU1WF8e/qg= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2020 12:48:36.0980 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 397902f2-75c2-4fc0-84e6-08d82274108c 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-AuthSource: VE1EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2077 Content-Type: text/plain Kvmtool is a virtual machine manager that enables hosting KVM guests. Kvmtool allows to vary the hardware configuration of the virtual 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 virtual platform. Signed-off-by: Sami Mujawar Reviewed-by: Ard Biesheuvel Acked-by: Laszlo Ersek --- Notes: v4: - Remove logging code as this requires support for Early [Sami] serial port initialisation which is dropped in this series as it would not work with Xen. Ref: https://edk2.groups.io/g/devel/message/61669 https://edk2.groups.io/g/devel/topic/75081479 v3: - Fix coding style, use "Txt" in LOG_VM_MAP(txt). [Laszlo] - Fixed coding style and also formatted log output. [Sami] Ref: https://edk2.groups.io/g/devel/topic/74200913#59548 v2: - Library to populate Kvmtool system memory map. [Sami] ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c | 96 ++++++++++++++++++++ ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf | 42 +++++++++ 2 files changed, 138 insertions(+) diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c new file mode 100644 index 0000000000000000000000000000000000000000..50e805b252d7564ac4770162eb68eddfc1153d4b --- /dev/null +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c @@ -0,0 +1,96 @@ +/** @file + + Copyright (c) 2018 - 2020, 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 + +/** + 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; + + // 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; + + // 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; + + // 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; + + // 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)'