From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.80]) by mx.groups.io with SMTP id smtpd.web12.5583.1601673274255340087 for ; Fri, 02 Oct 2020 14:14:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=Ajhu+L5A; spf=pass (domain: arm.com, ip: 40.107.20.80, 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=EfcV1P3dWHIJUTVppSkzpGIIxiobeB1jvJvI6xxfnSo=; b=Ajhu+L5A8kau/F24cWznWOAOIz9NvR9B+Z7U7TDIW6QgivYvS4A9OsnYnKF1V455pAB0g23D491reiutdniq1QtNd1jjbzB3I4SzKzO+ROX6FKHv4yfUqT03e6cer5jmn2EmjnrqAckBSV05bCdlnK/cXRxQdzU82u3btlWwuKg= Received: from AM7PR04CA0027.eurprd04.prod.outlook.com (2603:10a6:20b:110::37) by VI1PR08MB2848.eurprd08.prod.outlook.com (2603:10a6:802:23::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20; Fri, 2 Oct 2020 21:14:26 +0000 Received: from VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:110:cafe::8f) by AM7PR04CA0027.outlook.office365.com (2603:10a6:20b:110::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.36 via Frontend Transport; Fri, 2 Oct 2020 21:14:26 +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=pass 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 VE1EUR03FT031.mail.protection.outlook.com (10.152.18.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.34 via Frontend Transport; Fri, 2 Oct 2020 21:14:25 +0000 Received: ("Tessian outbound bac899b43a54:v64"); Fri, 02 Oct 2020 21:14:24 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 28d30adc3747670e X-CR-MTA-TID: 64aa7808 Received: from e93ae44121dc.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4D3916D4-CFAB-47B0-8D4D-A2B453E6CDB0.1; Fri, 02 Oct 2020 21:14:18 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e93ae44121dc.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 02 Oct 2020 21:14:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UR1sc9yIbjUs/9do943UK5zoCFB+5lfH85N1Kxj7jpU23PkBMj6Aixyy3tj9CBUaDcLvSXPMcFfISmE6Ly3PA5u5/tNZ7R8XXErSZN5mQukoQXcRb8k3EsRvIY859VhzM5SI3K4WJwjm0kMyoU5drzhZf9ePKCZlcdi/dbLdQdWrequA3l2nZQ9ykYvC5M1r1OGnYNbyQwrGUrvpHQqOnav3dgCJfCftUEA+WL+lWwOlLk6tI8lzkslgOezwks4PxFcQoNZtPtgCgRinGSf2ue8CednpbpKcJj3IrLav2bfmYrvc/T7eYVlqHF58EO2n+wXQ62TSBZ2DD6G7E98/xw== 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=EfcV1P3dWHIJUTVppSkzpGIIxiobeB1jvJvI6xxfnSo=; b=ka839vEHTyjNxEZkVb0z0cdGsuFvKkVvixDAfl+C+5o783VH15wy6sd9ItX1Q86vyzQIFEsBffZ4YoCqDIwI50hhMOICXzu05IYpnU6ojH9Z/sUEI5zZuOZzlLUa9cKWRTS1CaX8cI4TX9de/iaHOrSH9BLLM+DB9CiAR9o7tPOyCcB65iCXmq/RAlrMHBTI5KTyOAyu30FyPNi0s/6ogdbIZvoPrvPVHLleHvTeOTFfBlqT04SNh58C37bEHCyxb12E4bkXyOIkLeU+9Z3F3BjL2rFUt43rcOT4RF1iIvOgqcm7oDB5ghTbW552Z8MrBvpNnkTaheAHxkL7Ik6/TQ== 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=pass (p=none sp=none pct=100) 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=EfcV1P3dWHIJUTVppSkzpGIIxiobeB1jvJvI6xxfnSo=; b=Ajhu+L5A8kau/F24cWznWOAOIz9NvR9B+Z7U7TDIW6QgivYvS4A9OsnYnKF1V455pAB0g23D491reiutdniq1QtNd1jjbzB3I4SzKzO+ROX6FKHv4yfUqT03e6cer5jmn2EmjnrqAckBSV05bCdlnK/cXRxQdzU82u3btlWwuKg= Received: from AM6P194CA0038.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::15) by AM6PR08MB4738.eurprd08.prod.outlook.com (2603:10a6:20b:cf::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.37; Fri, 2 Oct 2020 21:14:17 +0000 Received: from AM5EUR03FT037.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:84:cafe::14) by AM6P194CA0038.outlook.office365.com (2603:10a6:209:84::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.32 via Frontend Transport; Fri, 2 Oct 2020 21:14:17 +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=pass 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 AM5EUR03FT037.mail.protection.outlook.com (10.152.17.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3433.34 via Frontend Transport; Fri, 2 Oct 2020 21:14:17 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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.2044.4; Fri, 2 Oct 2020 21:14:15 +0000 Received: from E107187.Arm.com (10.57.53.44) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2044.4 via Frontend Transport; Fri, 2 Oct 2020 21:14:14 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v5 05/15] ArmVirtPkg: kvmtool platform memory map Date: Fri, 2 Oct 2020 22:13:59 +0100 Message-ID: <20201002211409.43888-6-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20201002211409.43888-1-sami.mujawar@arm.com> References: <20201002211409.43888-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22323522-fecd-424a-b98c-08d867182436 X-MS-TrafficTypeDiagnostic: AM6PR08MB4738:|VI1PR08MB2848: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 1hJDoc9NlkRHRunJ/JDZP7z82vO9Sx40QkR6L6m8SVqOeL6Mj8+d6PpqIglOMtULcmqtQ1C2rET06nBx0pJR9k7q90fndMb9nKbfwwb6nHnlEVJUY819nYI3KrXjeuswz/YyD/HXETJ9lTfQt0bt9leQE4DFQnr6VG7GW8eXUiWF8OdivwwxLCzJbYfBqLaMs+hc4THWNe64DVgOlAgSFmR4GY7X25Q/TKic2BHbZ/OQPPJ54bJB7svTnqpRjcBeLlLQBa2XM3SwXCjvzT+rhZ5N9tNBx/WWKLvznI/j6BnZCtjOXG+ngJQDEOlzU3p69X11VD4F5qouCXUmUkxpZ6xOm9964bifUv9gHT2674wqkzq6cDfepjoKCQuMEHV9CtrNy51NtIhXt877xNrVF8/wkAVGLvExRndWQVEMKZqQRPnYjJCwhQPKAK3k4/nWcptzZKVziTgd96FTlTfK1UVUkh5749YQNgSOVm7oTQs= 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;SFS:(4636009)(39850400004)(396003)(136003)(346002)(376002)(46966005)(47076004)(7696005)(44832011)(8676002)(5660300002)(356005)(82740400003)(966005)(8936002)(36756003)(81166007)(83080400001)(478600001)(186003)(336012)(4326008)(6916009)(426003)(6666004)(70206006)(26005)(86362001)(2906002)(83380400001)(82310400003)(1076003)(54906003)(2616005)(316002)(70586007);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4738 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ce1ceada-4d01-4001-d1d3-08d867181f2d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fL0sV9CFMN7xSkwbmE03R10Eagd0YrGFDj9Qo6TK1Z4nDHX2kH3dYDzdV/UBkJ2D+NW4bnxqaO7AgmRInIDfC0zyzuXuJmM1nJljKyCQ8WMX89kdNK8PJgubAIHnggnILgI3gL8Z0La/vslhNqUp4NdjdaSfrx/2fY56qSMdfgKnIi2Nbwn8x7OPBcU+VnRL9QMHzxBkGpdwAeCrhDebWhL01hGXoc+Os1x5dpkVPT5VQD8Egv+0pQG7cJjCcA/bplMq/DfsLMRtYnzima4UYyMNzgwY0d345Y5N47A9rSCQ/5M51glf0VhEgKB2Fmzw+TZwDDuoNeEIBIWDd5SO/danvKKXmkBilnmEzIrT/t60Vzq2STd2TfeJWM9LbNqfo14AbGCtnFug/VE+NT3YTCztWOlGbJYrC11JwPTul22PHtU4Xj7HsJs45I3RqQfoDjL/tXwYhyf5Efd/pFHOWMdDBPRyK1NqYX0ob/YunvjqPWw0VLXcgJcD19eX8xXOkqOop9La3e/0EcG3mqQnSQ== 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;SFS:(4636009)(396003)(376002)(39860400002)(346002)(136003)(46966005)(5660300002)(54906003)(83380400001)(7696005)(81166007)(82310400003)(426003)(186003)(26005)(2906002)(4326008)(47076004)(966005)(478600001)(82740400003)(8676002)(86362001)(36756003)(70586007)(36906005)(70206006)(1076003)(44832011)(6666004)(2616005)(6916009)(8936002)(336012)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2020 21:14:25.6169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22323522-fecd-424a-b98c-08d867182436 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: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB2848 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: v5: - Fixed minor ECC reported issues in file header and [Sami] also a minor fix for ECC error "5007: There should be no initialization of a variable as part of its declaration". Ref: https://edk2.groups.io/g/devel/message/62145 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 | 98 ++++++++++++++++++++ ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf | 43 +++++++++ 2 files changed, 141 insertions(+) diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c new file mode 100644 index 0000000000000000000000000000000000000000..63bb81ef91ce0d16b604f5606a6a340647b706ad --- /dev/null +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c @@ -0,0 +1,98 @@ +/** @file + Kvmtool virtual memory map library. + + 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; + 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; + } + + Idx = 0; + // 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..4b0cf06e1e6950d57c397502a77abd8aa738254d --- /dev/null +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf @@ -0,0 +1,43 @@ +## @file +# Kvmtool virtual memory map library. +# +# 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)'