@@ -237,8 +237,8 @@ static void add_map(struct arm_mmu_ptables *ptables, const char *name,
237237 name , virt , phys , size );
238238
239239 /* check minimum alignment requirement for given mmap region */
240- __ASSERT (((virt & (PAGE_SIZE - 1 )) == 0 ) &&
241- ((size & (PAGE_SIZE - 1 )) == 0 ),
240+ __ASSERT (((virt & (CONFIG_MMU_PAGE_SIZE - 1 )) == 0 ) &&
241+ ((size & (CONFIG_MMU_PAGE_SIZE - 1 )) == 0 ),
242242 "address/size are not page aligned\n" );
243243
244244 desc = get_region_desc (attrs );
@@ -407,6 +407,9 @@ static int arm_mmu_init(const struct device *arg)
407407 /* Current MMU code supports only EL1 */
408408 __asm__ volatile ("mrs %0, CurrentEL" : "=r" (val ));
409409
410+ __ASSERT (CONFIG_MMU_PAGE_SIZE == KB (4 ),
411+ "Only 4K page size is supported\n" );
412+
410413 __ASSERT (GET_EL (val ) == MODE_EL1 ,
411414 "Exception level not EL1, MMU not enabled!\n" );
412415
@@ -429,3 +432,51 @@ SYS_INIT(arm_mmu_init, PRE_KERNEL_1,
429432 CONFIG_KERNEL_INIT_PRIORITY_DEVICE
430433#endif
431434);
435+
436+ int arch_mem_map (void * virt , uintptr_t phys , size_t size , uint32_t flags )
437+ {
438+ struct arm_mmu_ptables * ptables ;
439+ uint32_t entry_flags = MT_SECURE | MT_P_RX_U_NA ;
440+
441+ /* Always map in the kernel page tables */
442+ ptables = & kernel_ptables ;
443+
444+ /* Translate flags argument into HW-recognized entry flags. */
445+ switch (flags & K_MEM_CACHE_MASK ) {
446+ /*
447+ * K_MEM_CACHE_NONE => MT_DEVICE_nGnRnE
448+ * (Device memory nGnRnE)
449+ * K_MEM_CACHE_WB => MT_NORMAL
450+ * (Normal memory Outer WB + Inner WB)
451+ * K_MEM_CACHE_WT => MT_NORMAL_WT
452+ * (Normal memory Outer WT + Inner WT)
453+ */
454+ case K_MEM_CACHE_NONE :
455+ entry_flags |= MT_DEVICE_nGnRnE ;
456+ break ;
457+ case K_MEM_CACHE_WT :
458+ entry_flags |= MT_NORMAL_WT ;
459+ break ;
460+ case K_MEM_CACHE_WB :
461+ entry_flags |= MT_NORMAL ;
462+ break ;
463+ default :
464+ return - ENOTSUP ;
465+ }
466+
467+ if ((flags & K_MEM_PERM_RW ) != 0U ) {
468+ entry_flags |= MT_RW ;
469+ }
470+
471+ if ((flags & K_MEM_PERM_EXEC ) == 0U ) {
472+ entry_flags |= MT_P_EXECUTE_NEVER ;
473+ }
474+
475+ if ((flags & K_MEM_PERM_USER ) != 0U ) {
476+ return - ENOTSUP ;
477+ }
478+
479+ add_map (ptables , "generic" , phys , (uintptr_t )virt , size , entry_flags );
480+
481+ return 0 ;
482+ }
0 commit comments