arm64: Create common mmu and mpu interfaces
Include the new introduced include/arch/arm64/mm.h instead of the arm_mmu.h or arm_mpu.h. Unify function names z_arm64_thread_pt_init/z_arm64_swap_ptables with z_arm64_thread_mem_domains_init/z_arm64_swap_mem_domains for mmu and mpu, because: 1. mmu and mpu have almost the same logic. 2. mpu doesn't have ptables. 3. using the function names help reducing "#if define" macros. Similarly, change z_arm64_ptable_ipi to z_arm64_domain_sync_ipi And fix a log bug in arm_mmu.c. Signed-off-by: Jaxson Han <jaxson.han@arm.com>
This commit is contained in:
parent
9c1115c655
commit
d282d86d7e
7 changed files with 27 additions and 24 deletions
|
@ -9,12 +9,11 @@
|
|||
#include <init.h>
|
||||
#include <kernel.h>
|
||||
#include <soc.h>
|
||||
#include <arch/arm64/cortex_r/arm_mpu.h>
|
||||
#include <arch/arm64/mm.h>
|
||||
#include <linker/linker-defs.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_MPU_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(mpu);
|
||||
|
||||
LOG_MODULE_REGISTER(mpu, CONFIG_MPU_LOG_LEVEL);
|
||||
|
||||
/*
|
||||
* AArch64 Memory Model Feature Register 0
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <logging/log.h>
|
||||
#include <arch/arm64/cpu.h>
|
||||
#include <arch/arm64/lib_helpers.h>
|
||||
#include <arch/arm64/arm_mmu.h>
|
||||
#include <arch/arm64/mm.h>
|
||||
#include <linker/linker-defs.h>
|
||||
#include <spinlock.h>
|
||||
#include <sys/util.h>
|
||||
|
@ -931,6 +931,8 @@ int arch_page_phys_get(void *virt, uintptr_t *phys)
|
|||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
|
||||
static void z_arm64_swap_ptables(struct k_thread *incoming);
|
||||
|
||||
static inline bool is_ptable_active(struct arm_mmu_ptables *ptables)
|
||||
{
|
||||
return read_sysreg(ttbr0_el1) == (uintptr_t)ptables->base_xlat_table;
|
||||
|
@ -1037,7 +1039,7 @@ void arch_mem_domain_thread_add(struct k_thread *thread)
|
|||
} else {
|
||||
#ifdef CONFIG_SMP
|
||||
/* the thread could be running on another CPU right now */
|
||||
z_arm64_ptable_ipi();
|
||||
z_arm64_mem_cfg_ipi();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1067,7 +1069,7 @@ void arch_mem_domain_thread_remove(struct k_thread *thread)
|
|||
thread->stack_info.size);
|
||||
}
|
||||
|
||||
void z_arm64_swap_ptables(struct k_thread *incoming)
|
||||
static void z_arm64_swap_ptables(struct k_thread *incoming)
|
||||
{
|
||||
struct arm_mmu_ptables *ptables = incoming->arch.ptables;
|
||||
|
||||
|
@ -1076,7 +1078,7 @@ void z_arm64_swap_ptables(struct k_thread *incoming)
|
|||
}
|
||||
}
|
||||
|
||||
void z_arm64_thread_pt_init(struct k_thread *incoming)
|
||||
void z_arm64_thread_mem_domains_init(struct k_thread *incoming)
|
||||
{
|
||||
struct arm_mmu_ptables *ptables;
|
||||
|
||||
|
@ -1091,4 +1093,9 @@ void z_arm64_thread_pt_init(struct k_thread *incoming)
|
|||
z_arm64_swap_ptables(incoming);
|
||||
}
|
||||
|
||||
void z_arm64_swap_mem_domains(struct k_thread *incoming)
|
||||
{
|
||||
z_arm64_swap_ptables(incoming);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <ksched.h>
|
||||
#include <soc.h>
|
||||
#include <init.h>
|
||||
#include <arch/arm64/arm_mmu.h>
|
||||
#include <arch/arm64/mm.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <drivers/interrupt_controller/gic.h>
|
||||
#include <drivers/pm_cpu_ops.h>
|
||||
|
@ -26,7 +26,7 @@
|
|||
#include "boot.h"
|
||||
|
||||
#define SGI_SCHED_IPI 0
|
||||
#define SGI_PTABLE_IPI 1
|
||||
#define SGI_MMCFG_IPI 1
|
||||
#define SGI_FPU_IPI 2
|
||||
|
||||
struct boot_params {
|
||||
|
@ -130,7 +130,7 @@ void z_arm64_secondary_start(void)
|
|||
|
||||
irq_enable(SGI_SCHED_IPI);
|
||||
#ifdef CONFIG_USERSPACE
|
||||
irq_enable(SGI_PTABLE_IPI);
|
||||
irq_enable(SGI_MMCFG_IPI);
|
||||
#endif
|
||||
#ifdef CONFIG_FPU_SHARING
|
||||
irq_enable(SGI_FPU_IPI);
|
||||
|
@ -180,7 +180,7 @@ void arch_sched_ipi(void)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
void ptable_ipi_handler(const void *unused)
|
||||
void mem_cfg_ipi_handler(const void *unused)
|
||||
{
|
||||
ARG_UNUSED(unused);
|
||||
|
||||
|
@ -188,12 +188,12 @@ void ptable_ipi_handler(const void *unused)
|
|||
* Make sure a domain switch by another CPU is effective on this CPU.
|
||||
* This is a no-op if the page table is already the right one.
|
||||
*/
|
||||
z_arm64_swap_ptables(_current);
|
||||
z_arm64_swap_mem_domains(_current);
|
||||
}
|
||||
|
||||
void z_arm64_ptable_ipi(void)
|
||||
void z_arm64_mem_cfg_ipi(void)
|
||||
{
|
||||
broadcast_ipi(SGI_PTABLE_IPI);
|
||||
broadcast_ipi(SGI_MMCFG_IPI);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -227,8 +227,9 @@ static int arm64_smp_init(const struct device *dev)
|
|||
irq_enable(SGI_SCHED_IPI);
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
IRQ_CONNECT(SGI_PTABLE_IPI, IRQ_DEFAULT_PRIORITY, ptable_ipi_handler, NULL, 0);
|
||||
irq_enable(SGI_PTABLE_IPI);
|
||||
IRQ_CONNECT(SGI_MMCFG_IPI, IRQ_DEFAULT_PRIORITY,
|
||||
mem_cfg_ipi_handler, NULL, 0);
|
||||
irq_enable(SGI_MMCFG_IPI);
|
||||
#endif
|
||||
#ifdef CONFIG_FPU_SHARING
|
||||
IRQ_CONNECT(SGI_FPU_IPI, IRQ_DEFAULT_PRIORITY, flush_fpu_ipi_handler, NULL, 0);
|
||||
|
|
|
@ -89,7 +89,7 @@ SECTION_FUNC(TEXT, z_arm64_context_switch)
|
|||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
stp xzr, x30, [sp, #-16]!
|
||||
bl z_arm64_swap_ptables
|
||||
bl z_arm64_swap_mem_domains
|
||||
ldp xzr, x30, [sp], #16
|
||||
#endif
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
|
|||
uintptr_t stack_ptr;
|
||||
|
||||
/* Map the thread stack */
|
||||
z_arm64_thread_pt_init(_current);
|
||||
z_arm64_thread_mem_domains_init(_current);
|
||||
|
||||
/*
|
||||
* Reset the SP_EL0 stack pointer to the stack top discarding any old
|
||||
|
|
|
@ -42,7 +42,7 @@ static inline void arch_switch(void *switch_to, void **switched_from)
|
|||
extern void z_arm64_fatal_error(z_arch_esf_t *esf, unsigned int reason);
|
||||
extern void z_arm64_userspace_enter(z_arch_esf_t *esf, uintptr_t sp_el0);
|
||||
extern void z_arm64_set_ttbr0(uintptr_t ttbr0);
|
||||
extern void z_arm64_ptable_ipi(void);
|
||||
extern void z_arm64_mem_cfg_ipi(void);
|
||||
|
||||
#ifdef CONFIG_FPU_SHARING
|
||||
void z_arm64_flush_local_fpu(void);
|
||||
|
|
|
@ -218,10 +218,6 @@ typedef struct { uint32_t attrs; } k_mem_partition_attr_t;
|
|||
*/
|
||||
extern const struct arm_mmu_config mmu_config;
|
||||
|
||||
struct k_thread;
|
||||
void z_arm64_thread_pt_init(struct k_thread *thread);
|
||||
void z_arm64_swap_ptables(struct k_thread *thread);
|
||||
|
||||
#endif /* _ASMLANGUAGE */
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_ARM_MMU_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue