Skip to content

Commit c2ecae8

Browse files
committed
[MM] Support page MPR dynamic size
For RISC-V or dynamic address space arch in the future. Signed-off-by: GuEe-GUI <2991707448@qq.com>
1 parent bd2f06e commit c2ecae8

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

components/mm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
menu "Memory management"
22

3+
config RT_PAGE_MPR_SIZE_DYNAMIC
4+
bool "Page MPR size is dynamic"
5+
default n
6+
help
7+
Some platforms' virtual address width is not a compile-time constant
8+
and must be determined dynamically at runtime.
9+
310
config RT_PAGE_AFFINITY_BLOCK_SIZE
411
hex "Affinity block size in bytes for page management"
512
default 0x1000

components/mm/mm_page.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,26 @@ static inline rt_page_t addr_to_page(rt_page_t pg_start, void *addr)
417417
const rt_size_t shadow_mask =
418418
((1ul << (RT_PAGE_MAX_ORDER + ARCH_PAGE_SHIFT - 1)) - 1);
419419

420-
const rt_size_t rt_mpr_size = CEIL(
421-
((1ul << (ARCH_VADDR_WIDTH - ARCH_PAGE_SHIFT))) * sizeof(struct rt_page),
422-
ARCH_PAGE_SIZE);
420+
#define MPR_SIZE CEIL( \
421+
((1ul << (ARCH_VADDR_WIDTH - ARCH_PAGE_SHIFT))) * sizeof(struct rt_page), \
422+
ARCH_PAGE_SIZE)
423+
424+
#ifdef RT_PAGE_MPR_SIZE_DYNAMIC
425+
/**
426+
* @brief Get the size of Memory Page Region (MPR)
427+
*
428+
* When RT_PAGE_MPR_SIZE_DYNAMIC is enabled, MPR size is calculated at runtime
429+
* for platforms where virtual address width is not a compile-time constant.
430+
*
431+
* @return MPR size in bytes
432+
*/
433+
const rt_size_t rt_mpr_size_dynamic(void)
434+
{
435+
return MPR_SIZE;
436+
}
437+
#else
438+
const rt_size_t rt_mpr_size = MPR_SIZE;
439+
#endif
423440

424441
void *rt_mpr_start;
425442

components/mm/mm_page.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ typedef struct tag_region
7070
const char *name;
7171
} rt_region_t;
7272

73+
#ifdef RT_PAGE_MPR_SIZE_DYNAMIC
74+
const rt_size_t rt_mpr_size_dynamic(void);
75+
#define rt_mpr_size rt_mpr_size_dynamic()
76+
#else
7377
extern const rt_size_t rt_mpr_size;
78+
#endif
7479
extern void *rt_mpr_start;
7580

7681
void rt_page_init(rt_region_t reg);

0 commit comments

Comments
 (0)