From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 4E6F5AC064A for ; Wed, 3 Jan 2024 00:59:28 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=B1va1BQhMn06gjKyJWdZD5A93cbbnus6g4Kp5ABVgoo=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704243566; v=1; b=h0rXp3SE2OK69nDafvamHnQEj+KWxDOhuTdhIg6qBoNxJuHy4R9Q5/ynRPj/f6P1m5G6IH2F VYTYyxl8fjFXLO7Y02ulzoyRv82OpbqUnMTFAKF28H4OIfOETuukhBRUdZ5tVqOw+fw8NV1dMxC kW5VTs8/fFuPEJAOoCuIpXAw= X-Received: by 127.0.0.2 with SMTP id 88ggYY7687511xljG0bKii6r; Tue, 02 Jan 2024 16:59:26 -0800 X-Received: from zg8tmja5ljk3lje4ms43mwaa.icoremail.net (zg8tmja5ljk3lje4ms43mwaa.icoremail.net [209.97.181.73]) by mx.groups.io with SMTP id smtpd.web10.115796.1703728759131292018 for ; Wed, 27 Dec 2023 17:59:20 -0800 X-Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with SMTP id AQAAfwDHT7Z01oxlaDN6BA--.13246S2; Thu, 28 Dec 2023 09:59:16 +0800 (CST) X-Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAfwAXnQtq1oxlqEoAAA--.182S4; Thu, 28 Dec 2023 09:59:09 +0800 (CST) From: "Xiong Yining" To: devel@edk2.groups.io Cc: Xiong Yining , Chen Baozi Subject: [edk2-devel] [PATCH v2 1/1] SbsaQemu: add memory space for the high memory nodes Date: Thu, 28 Dec 2023 01:59:02 +0000 Message-Id: <20231228015902.1692317-2-xiongyining1480@phytium.com.cn> In-Reply-To: <20231228015902.1692317-1-xiongyining1480@phytium.com.cn> References: <20231228015902.1692317-1-xiongyining1480@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwAXnQtq1oxlqEoAAA--.182S4 X-CM-SenderInfo: x0lr0wp1lqx0bjrumio6sk53xlxphulrpou0/1tbiAQAHBmWMfGYBfQACsN X-Coremail-Antispam: 1Uk129KBjvJXoW3Wr17tryUJFy7AryUXr1DZFb_yoWxuw1fpF W7AFWrur48J342vw4fJa4rZFW5CF98G3y5G39rX3WxXa13JF18Zw47Zrn3J3sxXrn8Xayk WF18t34UW3Z5KaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,xiongyining1480@phytium.com.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Hkbnt6s3sz8p5QMQD4UiuNgLx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=h0rXp3SE; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io To support more memory nodes, we refer to the implement of "OvmfPkg/Fdt/HighMemDxe" to add memory space for the high memory nodes except the first one. Signed-off-by: Xiong Yining Signed-off-by: Chen Baozi --- Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 3 +- Platform/Qemu/SbsaQemu/SbsaQemu.fdf | 1 + .../SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf | 43 ++++++ .../SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.c | 133 ++++++++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf create mode 100644 Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.c diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc index 378600050df9..21acc188b75e 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc @@ -78,7 +78,7 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf - ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf + ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf @@ -675,6 +675,7 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE ArmPkg/Drivers/TimerDxe/TimerDxe.inf OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf # # FAT filesystem + GPT/MBR partitioning diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.fdf b/Platform/Qemu/SbsaQemu/SbsaQemu.fdf index 6fcfd25faaeb..b35f42e11aa4 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.fdf +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.fdf @@ -161,6 +161,7 @@ READ_LOCK_STATUS = TRUE INF MdeModulePkg/Core/Dxe/DxeMain.inf INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + INF Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf # # PI DXE Drivers producing Architectural Protocols (EFI Services) diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf new file mode 100644 index 000000000000..27a7ef649685 --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.inf @@ -0,0 +1,43 @@ +## @file +# High memory node enumeration DXE driver for SbsaQemu +# +# Copyright (c) 2023, Linaro Ltd. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SbsaQemuHighMemDxe + FILE_GUID = 9E749C5E-C282-32F8-7CC3-E5A3DDE15329 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + + ENTRY_POINT = InitializeHighMemDxe + +[Sources] + SbsaQemuHighMemDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Silicon/Qemu/SbsaQemu/SbsaQemu.dec + +[LibraryClasses] + BaseLib + DebugLib + DxeServicesTableLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + SbsaQemuSmc + +[Protocols] + gEfiCpuArchProtocolGuid ## CONSUMES + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy + +[Depex] + gEfiCpuArchProtocolGuid diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.c new file mode 100644 index 000000000000..01b74a1247cd --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuHighMemDxe/SbsaQemuHighMemDxe.c @@ -0,0 +1,133 @@ +/** @file +* High memory node enumeration DXE driver for SbsaQemu +* Virtual Machines +* +* Copyright (c) 2023, Linaro Ltd. All rights reserved. +* +* SPDX-License-Identifier: BSD-2-Clause-Patent +* +**/ + +#include +#include +#include +#include +#include +#include + +#include + +EFI_STATUS +EFIAPI +InitializeHighMemDxe ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + + UINT64 CurBase; + UINT64 CurSize; + UINT64 Attributes; + UINT32 NumMemNodes; + UINT32 index; + MemoryNode MemNode; + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; + EFI_CPU_ARCH_PROTOCOL *Cpu; + + Status = gBS->LocateProtocol ( + &gEfiCpuArchProtocolGuid, + NULL, + (VOID **)&Cpu + ); + ASSERT_EFI_ERROR (Status); + + // + // Check for memory node and add the memory spaces except the lowest one + // + NumMemNodes = SbsaQemuGetMemNodeCount(); + for (index = 0; index < NumMemNodes; index++){ + MemNode = SbsaQemuGetMemInfo(index); + CurBase = MemNode.AddressBase; + CurSize = MemNode.AddressSize; + + Status = gDS->GetMemorySpaceDescriptor (CurBase, &GcdDescriptor); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_WARN, + "%a: Region 0x%lx - 0x%lx not found in the GCD memory space map\n", + __func__, + CurBase, + CurBase + CurSize - 1 + )); + continue; + } + + if (GcdDescriptor.GcdMemoryType == EfiGcdMemoryTypeNonExistent) { + Status = gDS->AddMemorySpace ( + EfiGcdMemoryTypeSystemMemory, + CurBase, + CurSize, + EFI_MEMORY_WB | EFI_MEMORY_XP + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n", + __func__, + CurBase, + CurBase + CurSize - 1, + Status + )); + continue; + } + + Status = gDS->SetMemorySpaceAttributes ( + CurBase, + CurSize, + EFI_MEMORY_WB | EFI_MEMORY_XP + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_WARN, + "%a: gDS->SetMemorySpaceAttributes() failed on region 0x%lx - 0x%lx (%r)\n", + __func__, + CurBase, + CurBase + CurSize - 1, + Status + )); + } + + Attributes = EFI_MEMORY_WB; + if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & + (1U << (UINT32)EfiConventionalMemory)) != 0) + { + Attributes |= EFI_MEMORY_XP; + } + + Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize, Attributes); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n", + __func__, + CurBase, + CurBase + CurSize - 1, + Status + )); + } else { + DEBUG (( + DEBUG_INFO, + "%a: Add System RAM @ 0x%lx - 0x%lx\n", + __func__, + CurBase, + CurBase + CurSize - 1 + )); + } + + } + } + return EFI_SUCCESS; +} -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113048): https://edk2.groups.io/g/devel/message/113048 Mute This Topic: https://groups.io/mt/103494168/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-