kernel: mm: rename Z_PHYS_RAM_* to K_MEM_PHYS_*

Renames:
  Z_PHYS_RAM_START to K_MEM_PHYS_RAM_START
  Z_PHYS_RAM_SIZE to K_MEM_PHYS_RAM_SIZE
  Z_PHYS_RAM_END to K_MEM_PHYS_RAM_END

This is part of a series to move memory management related
stuff from Z_ namespace into its own namespace.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2024-06-07 09:31:46 -07:00 committed by Anas Nashif
commit 3fd66de508
3 changed files with 21 additions and 13 deletions

View file

@ -25,10 +25,17 @@
* anonymous mappings. We don't currently maintain an ontology of these in the * anonymous mappings. We don't currently maintain an ontology of these in the
* core kernel. * core kernel.
*/ */
#define Z_PHYS_RAM_START ((uintptr_t)CONFIG_SRAM_BASE_ADDRESS)
#define Z_PHYS_RAM_SIZE (KB(CONFIG_SRAM_SIZE)) /** Start address of physical memory. */
#define Z_PHYS_RAM_END (Z_PHYS_RAM_START + Z_PHYS_RAM_SIZE) #define K_MEM_PHYS_RAM_START ((uintptr_t)CONFIG_SRAM_BASE_ADDRESS)
#define Z_NUM_PAGE_FRAMES (Z_PHYS_RAM_SIZE / (size_t)CONFIG_MMU_PAGE_SIZE)
/** 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 */ /** End virtual address of virtual address space */
#define Z_VIRT_RAM_START ((uint8_t *)CONFIG_KERNEL_VM_BASE) #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)) #define K_MEM_BOOT_PHYS_TO_VIRT(phys) ((uint8_t *)(((uintptr_t)(phys)) + K_MEM_VM_OFFSET))
#ifdef CONFIG_ARCH_MAPS_ALL_RAM #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 #else
#define Z_FREE_VM_START Z_KERNEL_VIRT_END #define Z_FREE_VM_START Z_KERNEL_VIRT_END
#endif /* CONFIG_ARCH_MAPS_ALL_RAM */ #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) 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) + 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 */ /* 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) static inline bool z_is_page_frame(uintptr_t phys)
{ {
z_assert_phys_aligned(phys); z_assert_phys_aligned(phys);
return IN_RANGE(phys, (uintptr_t)Z_PHYS_RAM_START, return IN_RANGE(phys, (uintptr_t)K_MEM_PHYS_RAM_START,
(uintptr_t)(Z_PHYS_RAM_END - 1)); (uintptr_t)(K_MEM_PHYS_RAM_END - 1));
} }
static inline struct z_page_frame *z_phys_to_page_frame(uintptr_t phys) 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), __ASSERT(z_is_page_frame(phys),
"0x%lx not an SRAM physical address", 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]; CONFIG_MMU_PAGE_SIZE];
} }
@ -278,8 +285,8 @@ void z_page_frames_dump(void);
/* Convenience macro for iterating over all page frames */ /* Convenience macro for iterating over all page frames */
#define Z_PAGE_FRAME_FOREACH(_phys, _pageframe) \ #define Z_PAGE_FRAME_FOREACH(_phys, _pageframe) \
for ((_phys) = Z_PHYS_RAM_START, (_pageframe) = z_page_frames; \ for ((_phys) = K_MEM_PHYS_RAM_START, (_pageframe) = z_page_frames; \
(_phys) < Z_PHYS_RAM_END; \ (_phys) < K_MEM_PHYS_RAM_END; \
(_phys) += CONFIG_MMU_PAGE_SIZE, (_pageframe)++) (_phys) += CONFIG_MMU_PAGE_SIZE, (_pageframe)++)
#ifdef CONFIG_DEMAND_PAGING #ifdef CONFIG_DEMAND_PAGING

View file

@ -111,7 +111,7 @@ void z_page_frames_dump(void)
__ASSERT(page_frames_initialized, "%s called too early", __func__); __ASSERT(page_frames_initialized, "%s called too early", __func__);
printk("Physical memory from 0x%lx to 0x%lx\n", 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++) { for (int i = 0; i < Z_NUM_PAGE_FRAMES; i++) {
struct z_page_frame *pf = &z_page_frames[i]; struct z_page_frame *pf = &z_page_frames[i];

View file

@ -197,7 +197,8 @@ ZTEST(x86_pagetables, test_ram_perms)
/* All RAM page frame entries aside from 0x0 must have a mapping. /* 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 * 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) { pos += CONFIG_MMU_PAGE_SIZE) {
if (pos == NULL) { if (pos == NULL) {
continue; continue;