diff --git a/kernel/include/mmu.h b/kernel/include/mmu.h index ba39ec5bbc4..38f9c9c6704 100644 --- a/kernel/include/mmu.h +++ b/kernel/include/mmu.h @@ -25,10 +25,17 @@ * anonymous mappings. We don't currently maintain an ontology of these in the * core kernel. */ -#define Z_PHYS_RAM_START ((uintptr_t)CONFIG_SRAM_BASE_ADDRESS) -#define Z_PHYS_RAM_SIZE (KB(CONFIG_SRAM_SIZE)) -#define Z_PHYS_RAM_END (Z_PHYS_RAM_START + Z_PHYS_RAM_SIZE) -#define Z_NUM_PAGE_FRAMES (Z_PHYS_RAM_SIZE / (size_t)CONFIG_MMU_PAGE_SIZE) + +/** Start address of physical memory. */ +#define K_MEM_PHYS_RAM_START ((uintptr_t)CONFIG_SRAM_BASE_ADDRESS) + +/** Size of physical memory. */ +#define K_MEM_PHYS_RAM_SIZE (KB(CONFIG_SRAM_SIZE)) + +/** End address (exclusive) of physical memory. */ +#define K_MEM_PHYS_RAM_END (K_MEM_PHYS_RAM_START + K_MEM_PHYS_RAM_SIZE) + +#define Z_NUM_PAGE_FRAMES (K_MEM_PHYS_RAM_SIZE / (size_t)CONFIG_MMU_PAGE_SIZE) /** End virtual address of virtual address space */ #define Z_VIRT_RAM_START ((uint8_t *)CONFIG_KERNEL_VM_BASE) @@ -76,7 +83,7 @@ #define K_MEM_BOOT_PHYS_TO_VIRT(phys) ((uint8_t *)(((uintptr_t)(phys)) + K_MEM_VM_OFFSET)) #ifdef CONFIG_ARCH_MAPS_ALL_RAM -#define Z_FREE_VM_START K_MEM_BOOT_PHYS_TO_VIRT(Z_PHYS_RAM_END) +#define Z_FREE_VM_START K_MEM_BOOT_PHYS_TO_VIRT(K_MEM_PHYS_RAM_END) #else #define Z_FREE_VM_START Z_KERNEL_VIRT_END #endif /* CONFIG_ARCH_MAPS_ALL_RAM */ @@ -227,7 +234,7 @@ extern struct z_page_frame z_page_frames[Z_NUM_PAGE_FRAMES]; static inline uintptr_t z_page_frame_to_phys(struct z_page_frame *pf) { return (uintptr_t)((pf - z_page_frames) * CONFIG_MMU_PAGE_SIZE) + - Z_PHYS_RAM_START; + K_MEM_PHYS_RAM_START; } /* Presumes there is but one mapping in the virtual address space */ @@ -241,8 +248,8 @@ static inline void *z_page_frame_to_virt(struct z_page_frame *pf) static inline bool z_is_page_frame(uintptr_t phys) { z_assert_phys_aligned(phys); - return IN_RANGE(phys, (uintptr_t)Z_PHYS_RAM_START, - (uintptr_t)(Z_PHYS_RAM_END - 1)); + return IN_RANGE(phys, (uintptr_t)K_MEM_PHYS_RAM_START, + (uintptr_t)(K_MEM_PHYS_RAM_END - 1)); } static inline struct z_page_frame *z_phys_to_page_frame(uintptr_t phys) @@ -250,7 +257,7 @@ static inline struct z_page_frame *z_phys_to_page_frame(uintptr_t phys) __ASSERT(z_is_page_frame(phys), "0x%lx not an SRAM physical address", phys); - return &z_page_frames[(phys - Z_PHYS_RAM_START) / + return &z_page_frames[(phys - K_MEM_PHYS_RAM_START) / CONFIG_MMU_PAGE_SIZE]; } @@ -278,8 +285,8 @@ void z_page_frames_dump(void); /* Convenience macro for iterating over all page frames */ #define Z_PAGE_FRAME_FOREACH(_phys, _pageframe) \ - for ((_phys) = Z_PHYS_RAM_START, (_pageframe) = z_page_frames; \ - (_phys) < Z_PHYS_RAM_END; \ + for ((_phys) = K_MEM_PHYS_RAM_START, (_pageframe) = z_page_frames; \ + (_phys) < K_MEM_PHYS_RAM_END; \ (_phys) += CONFIG_MMU_PAGE_SIZE, (_pageframe)++) #ifdef CONFIG_DEMAND_PAGING diff --git a/kernel/mmu.c b/kernel/mmu.c index 391c74b2145..9fe6ce85a31 100644 --- a/kernel/mmu.c +++ b/kernel/mmu.c @@ -111,7 +111,7 @@ void z_page_frames_dump(void) __ASSERT(page_frames_initialized, "%s called too early", __func__); printk("Physical memory from 0x%lx to 0x%lx\n", - Z_PHYS_RAM_START, Z_PHYS_RAM_END); + K_MEM_PHYS_RAM_START, K_MEM_PHYS_RAM_END); for (int i = 0; i < Z_NUM_PAGE_FRAMES; i++) { struct z_page_frame *pf = &z_page_frames[i]; diff --git a/tests/arch/x86/pagetables/src/main.c b/tests/arch/x86/pagetables/src/main.c index e42c4e3494e..c9025bd0ead 100644 --- a/tests/arch/x86/pagetables/src/main.c +++ b/tests/arch/x86/pagetables/src/main.c @@ -197,7 +197,8 @@ ZTEST(x86_pagetables, test_ram_perms) /* All RAM page frame entries aside from 0x0 must have a mapping. * We currently identity-map on x86, no conversion necessary other than a cast */ - for (pos = (uint8_t *)Z_PHYS_RAM_START; pos < (uint8_t *)Z_PHYS_RAM_END; + for (pos = (uint8_t *)K_MEM_PHYS_RAM_START; + pos < (uint8_t *)K_MEM_PHYS_RAM_END; pos += CONFIG_MMU_PAGE_SIZE) { if (pos == NULL) { continue;