1 /* 2 * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <lib/spinlock.h> 8 #include <plat/common/platform.h> 9 10 static spinlock_t mem_reserve_lock; 11 static uintptr_t top_mem = RMM_LIMIT; 12 13 uintptr_t plat_rmmd_reserve_memory(size_t size, unsigned long alignment) 14 { 15 uint64_t align_mask = alignment - 1; 16 uintptr_t addr; 17 18 spin_lock(&mem_reserve_lock); 19 addr = (top_mem - size) & ~align_mask; 20 if (addr >= RMM_PAYLOAD_LIMIT) { 21 top_mem = addr; 22 } else { 23 addr = 0; 24 } 25 spin_unlock(&mem_reserve_lock); 26 27 return addr; 28 } 29