From c22ddc4368650550845f862fc07cb35b998fbb23 Mon Sep 17 00:00:00 2001 From: Gavin Shan Date: Wed, 9 Sep 2026 19:58:37 +1000 Subject: [PATCH] plat/qemu: add plat_rmmd_reserve_memory() for VIRT platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gavin Shan --- plat/qemu/qemu/include/platform_def.h | 3 +++ plat/qemu/qemu/plat_rmm_mem_carveout.c | 28 ++++++++++++++++++++++++++ plat/qemu/qemu/platform.mk | 4 ++++ 3 files changed, 35 insertions(+) create mode 100644 plat/qemu/qemu/plat_rmm_mem_carveout.c diff --git a/plat/qemu/qemu/include/platform_def.h b/plat/qemu/qemu/include/platform_def.h index 06018e7b2..c3ed986cf 100644 --- a/plat/qemu/qemu/include/platform_def.h +++ b/plat/qemu/qemu/include/platform_def.h @@ -368,6 +368,9 @@ CASSERT((PLAT_QEMU_L0_GPT_BASE & (PLAT_QEMU_L0_GPT_SIZE - 1)) == 0, #define RMM_SHARED_BASE (RMM_LIMIT) #define RMM_SHARED_SIZE PLAT_QEMU_RMM_SHARED_SIZE +#define PLAT_ARM_RMM_PAYLOAD_SIZE UL(0x600000) /* 2 * 3MB */ +#define RMM_PAYLOAD_LIMIT (RMM_BASE + PLAT_ARM_RMM_PAYLOAD_SIZE) + /* * We add the RMM_SHARED size to RMM mapping to map the region as a block. * Else we end up requiring more pagetables in BL2 for ROMLIB build. diff --git a/plat/qemu/qemu/plat_rmm_mem_carveout.c b/plat/qemu/qemu/plat_rmm_mem_carveout.c new file mode 100644 index 000000000..c68ca243d --- /dev/null +++ b/plat/qemu/qemu/plat_rmm_mem_carveout.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2026, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +static spinlock_t mem_reserve_lock; +static uintptr_t top_mem = RMM_LIMIT; + +uintptr_t plat_rmmd_reserve_memory(size_t size, unsigned long alignment) +{ + uint64_t align_mask = alignment - 1; + uintptr_t addr; + + spin_lock(&mem_reserve_lock); + addr = (top_mem - size) & ~align_mask; + if (addr >= RMM_PAYLOAD_LIMIT) { + top_mem = addr; + } else { + addr = 0; + } + spin_unlock(&mem_reserve_lock); + + return addr; +} diff --git a/plat/qemu/qemu/platform.mk b/plat/qemu/qemu/platform.mk index 2e12f6bca..655cc683a 100644 --- a/plat/qemu/qemu/platform.mk +++ b/plat/qemu/qemu/platform.mk @@ -175,6 +175,10 @@ BL31_SOURCES += plat/common/plat_spmd_manifest.c \ ${FDT_WRAPPERS_SOURCES} endif +ifeq (${ENABLE_RMM},1) +BL31_SOURCES += ${PLAT_QEMU_PATH}/plat_rmm_mem_carveout.c +endif + ifneq (${ENABLE_FEAT_RNG_TRAP},0) BL31_SOURCES += plat/qemu/qemu/qemu_sync_traps.c endif -- 2.55.0