refactor: drop dynamic allocation of memory region address
Drop dynamic allocation of memory region address, for the sake of
simplifying the handling of manifest memory regions.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I09575176a71a680dc7d5598f22247ec6af0265b8
diff --git a/src/load.c b/src/load.c
index 4ed3c0c..22b4605 100644
--- a/src/load.c
+++ b/src/load.c
@@ -514,8 +514,7 @@
static bool ffa_map_memory_regions(const struct manifest_vm *manifest_vm,
const struct vm_locked vm_locked,
const struct vm_locked primary_vm_locked,
- paddr_t mem_end, bool is_el0_partition,
- struct mpool *ppool)
+ bool is_el0_partition, struct mpool *ppool)
{
#if LOG_LEVEL >= LOG_LEVEL_WARNING
const char *error_string = " region security state ignored for ";
@@ -523,9 +522,7 @@
int j = 0;
paddr_t region_begin;
paddr_t region_end;
- paddr_t alloc_base = mem_end;
size_t size;
- size_t total_alloc = 0;
uint32_t map_mode;
uint32_t attributes;
@@ -534,38 +531,12 @@
size = manifest_vm->partition.mem_regions[j].page_count *
PAGE_SIZE;
/*
- * For memory-regions without base-address, memory
- * should be allocated inside partition's page table.
- * Start allocating memory regions in partition's
- * page table, starting from the end.
- * TODO: Add mechanism to let partition know of these
- * memory regions
+ * Identity map memory region for both case,
+ * VA(S-EL0) or IPA(S-EL1).
*/
- if (manifest_vm->partition.mem_regions[j].base_address ==
- MANIFEST_INVALID_ADDRESS) {
- total_alloc += size;
- /* Don't go beyond half the VM's memory space */
- if (total_alloc >
- (manifest_vm->secondary.mem_size / 2)) {
- dlog_error(
- "Not enough space for memory-"
- "region allocation");
- return false;
- }
-
- region_end = alloc_base;
- region_begin = pa_subtract(alloc_base, size);
- alloc_base = region_begin;
- } else {
- /*
- * Identity map memory region for both case,
- * VA(S-EL0) or IPA(S-EL1).
- */
- region_begin =
- pa_init(manifest_vm->partition.mem_regions[j]
- .base_address);
- region_end = pa_add(region_begin, size);
- }
+ region_begin = pa_init(
+ manifest_vm->partition.mem_regions[j].base_address);
+ region_end = pa_add(region_begin, size);
attributes = manifest_vm->partition.mem_regions[j].attributes;
if ((attributes & MANIFEST_REGION_ATTR_SECURITY) != 0) {
@@ -763,8 +734,8 @@
if (manifest_vm->is_ffa_partition) {
if (!ffa_map_memory_regions(manifest_vm, vm_locked,
- primary_vm_locked, mem_end,
- is_el0_partition, ppool)) {
+ primary_vm_locked, is_el0_partition,
+ ppool)) {
ret = false;
goto out;
}
diff --git a/src/manifest.c b/src/manifest.c
index a1a9d64..c01da95 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -8,6 +8,8 @@
#include "hf/manifest.h"
+#include <stddef.h>
+
#include "hf/arch/types.h"
#include "hf/addr.h"
@@ -417,7 +419,8 @@
static enum manifest_return_code check_and_record_mem_regions(
uintptr_t base_address, uint32_t page_count)
{
- uintptr_t limit = base_address + (page_count * PAGE_SIZE) - 1U;
+ uintptr_t limit =
+ base_address + ((uintptr_t)page_count * PAGE_SIZE) - 1U;
if (page_count == 0U) {
dlog_error(
@@ -483,9 +486,8 @@
dlog_verbose(" Name: %s\n",
string_data(&mem_regions[i].name));
- TRY(read_optional_uint64(mem_node, "base-address",
- MANIFEST_INVALID_ADDRESS,
- &mem_regions[i].base_address));
+ TRY(read_uint64(mem_node, "base-address",
+ &mem_regions[i].base_address));
dlog_verbose(" Base address: %#x\n",
mem_regions[i].base_address);