Skip to content

Commit 7bbe9da

Browse files
kedareswararaonashif
authored andcommitted
tests: lib: shared_multi_heap: fix ARM64 MMU attributes
The qemu_cortex_a53 overlay was using ARM MPU memory attributes (DT_MEM_ARM(ATTR_MPU_RAM)) even though Cortex-A53 is an ARM64 platform with MMU, not MPU. Fix by switching the overlay to DT_MEM_ARM64_MMU_NORMAL / DT_MEM_ARM64_MMU_NORMAL_NC and updating the test source to handle both ARM MPU and ARM64 MMU attributes via #if defined(CONFIG_ARM64). The ARM64 path now checks the generic DT_MEM_CACHEABLE bit instead of switching on architecture-specific enum values, consistent with the composable-bitmask design. Use the generic DT_MEM_ARCH_ATTR_UNKNOWN for the "unknown attribute" default instead of architecture-specific aliases. Remove the runtime smh_reg_map() function and its call site since memory regions are now statically mapped at compile time via MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY_FROM_DT, making the dynamic k_mem_map_phys_bare() mapping redundant. Increase CONFIG_MAX_XLAT_TABLES to 16 for qemu_cortex_a53. Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
1 parent 94e4c83 commit 7bbe9da

3 files changed

Lines changed: 22 additions & 52 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
22
CONFIG_CUSTOM_LINKER_SCRIPT="linker_arm64_shared_pool.ld"
3+
CONFIG_MAX_XLAT_TABLES=16

tests/lib/shared_multi_heap/boards/qemu_cortex_a53.overlay

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*/
66

77
#include <zephyr/dt-bindings/memory-attr/memory-attr.h>
8-
#include <zephyr/dt-bindings/memory-attr/memory-attr-arm.h>
8+
#include <zephyr/dt-bindings/memory-attr/memory-attr-arm64.h>
99

1010
/ {
1111
soc {
1212
res0: memory@42000000 {
1313
compatible = "zephyr,memory-region", "mmio-sram";
1414
reg = <0x0 0x42000000 0x0 0x1000>;
1515
zephyr,memory-region = "RES0";
16-
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>;
16+
zephyr,memory-attr = <DT_MEM_ARM64_MMU_NORMAL>;
1717
};
1818

1919
res1: memory@43000000 {
2020
compatible = "zephyr,memory-region", "mmio-sram";
2121
reg = <0x0 0x43000000 0x0 0x2000>;
2222
zephyr,memory-region = "RES1";
23-
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM_NOCACHE)>;
23+
zephyr,memory-attr = <DT_MEM_ARM64_MMU_NORMAL_NC>;
2424
};
2525

2626
res_no_mpu: memory@45000000 {
@@ -33,7 +33,7 @@
3333
compatible = "zephyr,memory-region", "mmio-sram";
3434
reg = <0x0 0x44000000 0x0 0x3000>;
3535
zephyr,memory-region = "RES2";
36-
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>;
36+
zephyr,memory-attr = <DT_MEM_ARM64_MMU_NORMAL>;
3737
};
3838
};
3939
};

tests/lib/shared_multi_heap/src/main.c

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/ztest.h>
99
#include <zephyr/linker/linker-defs.h>
10-
#include <zephyr/kernel/mm.h>
10+
#if defined(CONFIG_ARM64)
11+
#include <zephyr/dt-bindings/memory-attr/memory-attr-arm64.h>
12+
#else
1113
#include <zephyr/dt-bindings/memory-attr/memory-attr-arm.h>
14+
#endif
1215

1316
#include <zephyr/multi_heap/shared_multi_heap.h>
1417

1518
#define DT_DRV_COMPAT zephyr_memory_region
1619

20+
#define SMH_DT_MEM_UNKNOWN_DEFAULT DT_MEM_ARCH_ATTR_UNKNOWN
21+
1722
#define RES0_CACHE_ADDR DT_REG_ADDR(DT_NODELABEL(res0))
1823
#define RES1_NOCACHE_ADDR DT_REG_ADDR(DT_NODELABEL(res1))
1924
#define RES2_CACHE_ADDR DT_REG_ADDR(DT_NODELABEL(res2))
@@ -29,29 +34,14 @@ struct region_map {
2934
.addr = (uintptr_t) DT_INST_REG_ADDR(n), \
3035
.size = DT_INST_REG_SIZE(n), \
3136
.attr = DT_INST_PROP_OR(n, zephyr_memory_attr, \
32-
DT_MEM_ARM_MPU_UNKNOWN), \
37+
SMH_DT_MEM_UNKNOWN_DEFAULT), \
3338
}, \
3439
},
3540

3641
struct region_map map[] = {
3742
DT_INST_FOREACH_STATUS_OKAY(FOREACH_REG)
3843
};
3944

40-
#if defined(CONFIG_MMU)
41-
static void smh_reg_map(struct shared_multi_heap_region *region)
42-
{
43-
uint32_t mem_attr;
44-
uint8_t *v_addr;
45-
46-
mem_attr = (region->attr == SMH_REG_ATTR_CACHEABLE) ? K_MEM_CACHE_WB : K_MEM_CACHE_NONE;
47-
mem_attr |= K_MEM_PERM_RW;
48-
49-
k_mem_map_phys_bare(&v_addr, region->addr, region->size, mem_attr);
50-
51-
region->addr = (uintptr_t) v_addr;
52-
}
53-
#endif /* CONFIG_MMU */
54-
5545
/*
5646
* Given a virtual address retrieve the original memory region that the mapping
5747
* is belonging to.
@@ -67,34 +57,25 @@ static struct region_map *get_region_map(void *v_addr)
6757
return NULL;
6858
}
6959

70-
static inline enum shared_multi_heap_attr mpu_to_reg_attr(uint32_t dt_attr)
60+
static inline enum shared_multi_heap_attr dt_to_reg_attr(uint32_t dt_attr)
7161
{
72-
/*
73-
* All the memory regions defined in the DT with the MPU property `RAM`
74-
* can be accessed and memory can be retrieved from using the attribute
75-
* `SMH_REG_ATTR_CACHEABLE`.
76-
*
77-
* All the memory regions defined in the DT with the MPU property
78-
* `RAM_NOCACHE` can be accessed and memory can be retrieved from using
79-
* the attribute `SMH_REG_ATTR_NON_CACHEABLE`.
80-
*
81-
* [MPU attr] -> [SMH attr]
82-
*
83-
* RAM -> SMH_REG_ATTR_CACHEABLE
84-
* RAM_NOCACHE -> SMH_REG_ATTR_NON_CACHEABLE
85-
*/
62+
#if defined(CONFIG_ARM64)
63+
if (DT_MEM_ATTR_GET(dt_attr) & DT_MEM_CACHEABLE) {
64+
return SMH_REG_ATTR_CACHEABLE;
65+
}
66+
return SMH_REG_ATTR_NON_CACHEABLE;
67+
#else
8668
switch (DT_MEM_ARM_GET(dt_attr)) {
8769
case DT_MEM_ARM_MPU_RAM:
8870
return SMH_REG_ATTR_CACHEABLE;
8971
case DT_MEM_ARM_MPU_RAM_NOCACHE:
9072
return SMH_REG_ATTR_NON_CACHEABLE;
9173
default:
92-
/* How ? */
9374
ztest_test_fail();
9475
}
9576

96-
/* whatever */
9777
return 0;
78+
#endif
9879
}
9980

10081
static void fill_multi_heap(void)
@@ -105,28 +86,16 @@ static void fill_multi_heap(void)
10586
reg_map = &map[idx];
10687

10788
/* zephyr,memory-attr property not found. Skip it. */
108-
if (reg_map->region.attr == DT_MEM_ARM_MPU_UNKNOWN) {
89+
if (reg_map->region.attr == SMH_DT_MEM_UNKNOWN_DEFAULT) {
10990
continue;
11091
}
11192

11293
/* Convert MPU attributes to shared-multi-heap capabilities */
113-
reg_map->region.attr = mpu_to_reg_attr(reg_map->region.attr);
94+
reg_map->region.attr = dt_to_reg_attr(reg_map->region.attr);
11495

11596
/* Assume for now that phys == virt */
11697
reg_map->p_addr = reg_map->region.addr;
11798

118-
#if defined(CONFIG_MMU)
119-
/*
120-
* For MMU-enabled platform we have to MMU-map the physical
121-
* address retrieved by DT at run-time because the SMH
122-
* framework expects virtual addresses.
123-
*
124-
* For MPU-enabled platform the code is assuming that the
125-
* region are configured at build-time, so no map is needed.
126-
*/
127-
smh_reg_map(&reg_map->region);
128-
#endif /* CONFIG_MMU */
129-
13099
shared_multi_heap_add(&reg_map->region, NULL);
131100
}
132101
}

0 commit comments

Comments
 (0)