fix(drtm): sort the address-map in ascending order
As per the specification the address map region in the
DLME data must be sorted.
Change-Id: Ibf39dad33ef7ce739d6ec8632198df55a4e8a1c3
Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
diff --git a/services/std_svc/drtm/drtm_res_address_map.c b/services/std_svc/drtm/drtm_res_address_map.c
index 8636706..52e6eab 100644
--- a/services/std_svc/drtm/drtm_res_address_map.c
+++ b/services/std_svc/drtm/drtm_res_address_map.c
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
+ * Copyright (c) 2022-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdint.h>
+#include <stdlib.h>
#include <plat/common/platform.h>
#include <services/drtm_svc.h>
@@ -23,6 +24,20 @@
static uint64_t drtm_address_map_size;
+static int compare_regions(const void *a, const void *b)
+{
+ const drtm_mem_region_t *region_a = (const drtm_mem_region_t *)a;
+ const drtm_mem_region_t *region_b = (const drtm_mem_region_t *)b;
+
+ if (region_a->region_address < region_b->region_address) {
+ return -1;
+ } else if (region_a->region_address > region_b->region_address) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
drtm_memory_region_descriptor_table_t *drtm_build_address_map(void)
{
/* Set up pointer to DRTM memory map. */
@@ -75,6 +90,9 @@
map->num_regions = i;
+ qsort(map->region, map->num_regions, sizeof(drtm_mem_region_t),
+ compare_regions);
+
/* Store total size of address map. */
drtm_address_map_size = sizeof(drtm_memory_region_descriptor_table_t);
drtm_address_map_size += (i * sizeof(drtm_mem_region_t));