diff options
| author | wangxiaoyao <[email protected]> | 2023-02-20 13:48:00 +0800 |
|---|---|---|
| committer | guo <[email protected]> | 2023-02-21 08:48:49 +0800 |
| commit | 484a0d602e8b571a9d8186d38c8b136abc4ccfc9 (patch) | |
| tree | 399ef1a1718bffed545a7354bbf2a8f8133e9c23 /libcpu/risc-v | |
| parent | f84d89b0ca9c8982d436aa12be75554722462090 (diff) | |
[fixup] add cache maintenance ops;
fix bugs on cache maintenance when starting user app
Diffstat (limited to 'libcpu/risc-v')
| -rw-r--r-- | libcpu/risc-v/t-head/c906/backtrace.c | 4 | ||||
| -rw-r--r-- | libcpu/risc-v/t-head/c906/cache.h | 2 | ||||
| -rw-r--r-- | libcpu/risc-v/t-head/c906/mmu.c | 7 | ||||
| -rw-r--r-- | libcpu/risc-v/t-head/c906/mmu.h | 13 | ||||
| -rw-r--r-- | libcpu/risc-v/virt64/backtrace.c | 4 | ||||
| -rw-r--r-- | libcpu/risc-v/virt64/cache.h | 2 | ||||
| -rw-r--r-- | libcpu/risc-v/virt64/mmu.c | 7 | ||||
| -rw-r--r-- | libcpu/risc-v/virt64/mmu.h | 13 |
8 files changed, 18 insertions, 34 deletions
diff --git a/libcpu/risc-v/t-head/c906/backtrace.c b/libcpu/risc-v/t-head/c906/backtrace.c index ad5dd7d2d3..c10d9f3522 100644 --- a/libcpu/risc-v/t-head/c906/backtrace.c +++ b/libcpu/risc-v/t-head/c906/backtrace.c @@ -59,13 +59,13 @@ void rt_hw_backtrace(rt_uint32_t *ffp, rt_ubase_t sepc) } ra = fp - 1; - if (!_rt_kmem_v2p(ra) || *ra < vas || *ra > vae) + if (!rt_kmem_v2p(ra) || *ra < vas || *ra > vae) break; rt_kprintf(" %p", *ra - 0x04); fp = fp - 2; - if (!_rt_kmem_v2p(fp)) + if (!rt_kmem_v2p(fp)) break; fp = (rt_ubase_t *)(*fp); if (!fp) diff --git a/libcpu/risc-v/t-head/c906/cache.h b/libcpu/risc-v/t-head/c906/cache.h index c7dcac61ac..d29c5c1e44 100644 --- a/libcpu/risc-v/t-head/c906/cache.h +++ b/libcpu/risc-v/t-head/c906/cache.h @@ -63,6 +63,8 @@ ALWAYS_INLINE void rt_hw_cpu_icache_invalidate_all_local(void) rt_hw_cpu_sync_i(); } +#define rt_hw_icache_invalidate_all rt_hw_cpu_icache_invalidate_all + /** * ======================================== * Multi-core cache maintainence operations diff --git a/libcpu/risc-v/t-head/c906/mmu.c b/libcpu/risc-v/t-head/c906/mmu.c index cc696ec6cb..73481dccf0 100644 --- a/libcpu/risc-v/t-head/c906/mmu.c +++ b/libcpu/risc-v/t-head/c906/mmu.c @@ -25,6 +25,7 @@ #include <tlb.h> #ifdef RT_USING_SMART +#include <board.h> #include <ioremap.h> #include <lwp_user_mm.h> #endif @@ -96,7 +97,7 @@ static rt_uint64_t _asid_check_switch(rt_aspace_t aspace) void rt_hw_aspace_switch(rt_aspace_t aspace) { - uintptr_t page_table = (uintptr_t)_rt_kmem_v2p(aspace->page_table); + uintptr_t page_table = (uintptr_t)rt_kmem_v2p(aspace->page_table); current_mmu_table = aspace->page_table; rt_uint64_t asid = _asid_check_switch(aspace); @@ -191,7 +192,9 @@ void *rt_hw_mmu_map(struct rt_aspace *aspace, void *v_addr, void *p_addr, // TODO trying with HUGEPAGE here while (npages--) { + MM_PGTBL_LOCK(aspace); ret = _map_one_page(aspace, v_addr, p_addr, attr); + MM_PGTBL_UNLOCK(aspace); if (ret != 0) { /* error, undo map */ @@ -500,7 +503,7 @@ int rt_hw_mmu_control(struct rt_aspace *aspace, void *vaddr, size_t size, * otherwise is a failure and no report will be * returned. * - * @param mmu_info + * @param aspace * @param mdesc * @param desc_nr */ diff --git a/libcpu/risc-v/t-head/c906/mmu.h b/libcpu/risc-v/t-head/c906/mmu.h index aa05cebc8e..809e514b82 100644 --- a/libcpu/risc-v/t-head/c906/mmu.h +++ b/libcpu/risc-v/t-head/c906/mmu.h @@ -67,19 +67,6 @@ void rt_hw_mmu_unmap(rt_aspace_t aspace, void *v_addr, size_t size); void rt_hw_aspace_switch(rt_aspace_t aspace); void *rt_hw_mmu_v2p(rt_aspace_t aspace, void *vaddr); -static inline void *_rt_kmem_v2p(void *vaddr) -{ - return rt_hw_mmu_v2p(&rt_kernel_space, vaddr); -} - -static inline void *rt_kmem_v2p(void *vaddr) -{ - MM_PGTBL_LOCK(&rt_kernel_space); - void *paddr = _rt_kmem_v2p(vaddr); - MM_PGTBL_UNLOCK(&rt_kernel_space); - return paddr; -} - int rt_hw_mmu_control(struct rt_aspace *aspace, void *vaddr, size_t size, enum rt_mmu_cntl cmd); diff --git a/libcpu/risc-v/virt64/backtrace.c b/libcpu/risc-v/virt64/backtrace.c index ad5dd7d2d3..c10d9f3522 100644 --- a/libcpu/risc-v/virt64/backtrace.c +++ b/libcpu/risc-v/virt64/backtrace.c @@ -59,13 +59,13 @@ void rt_hw_backtrace(rt_uint32_t *ffp, rt_ubase_t sepc) } ra = fp - 1; - if (!_rt_kmem_v2p(ra) || *ra < vas || *ra > vae) + if (!rt_kmem_v2p(ra) || *ra < vas || *ra > vae) break; rt_kprintf(" %p", *ra - 0x04); fp = fp - 2; - if (!_rt_kmem_v2p(fp)) + if (!rt_kmem_v2p(fp)) break; fp = (rt_ubase_t *)(*fp); if (!fp) diff --git a/libcpu/risc-v/virt64/cache.h b/libcpu/risc-v/virt64/cache.h index e343d7927f..b4a041ac88 100644 --- a/libcpu/risc-v/virt64/cache.h +++ b/libcpu/risc-v/virt64/cache.h @@ -45,6 +45,8 @@ ALWAYS_INLINE void rt_hw_cpu_icache_invalidate_all_local() {} #define rt_hw_cpu_icache_invalidate rt_hw_cpu_icache_invalidate_local #define rt_hw_cpu_icache_invalidate_all rt_hw_cpu_icache_invalidate_all_local +#define rt_hw_icache_invalidate_all rt_hw_cpu_icache_invalidate_all + /** instruction barrier */ void rt_hw_cpu_sync(void); diff --git a/libcpu/risc-v/virt64/mmu.c b/libcpu/risc-v/virt64/mmu.c index 6d4cc6463e..091be5adab 100644 --- a/libcpu/risc-v/virt64/mmu.c +++ b/libcpu/risc-v/virt64/mmu.c @@ -17,6 +17,7 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> +#include <board.h> #include <cache.h> #include <mm_aspace.h> #include <mm_page.h> @@ -43,7 +44,7 @@ rt_ubase_t MMUTable[__SIZE(VPN2_BIT)]; void rt_hw_aspace_switch(rt_aspace_t aspace) { - uintptr_t page_table = (uintptr_t)_rt_kmem_v2p(aspace->page_table); + uintptr_t page_table = (uintptr_t)rt_kmem_v2p(aspace->page_table); current_mmu_table = aspace->page_table; write_csr(satp, (((size_t)SATP_MODE) << SATP_MODE_OFFSET) | @@ -136,7 +137,9 @@ void *rt_hw_mmu_map(struct rt_aspace *aspace, void *v_addr, void *p_addr, // TODO trying with HUGEPAGE here while (npages--) { + MM_PGTBL_LOCK(aspace); ret = _map_one_page(aspace, v_addr, p_addr, attr); + MM_PGTBL_UNLOCK(aspace); if (ret != 0) { /* error, undo map */ @@ -444,7 +447,7 @@ int rt_hw_mmu_control(struct rt_aspace *aspace, void *vaddr, size_t size, * otherwise is a failure and no report will be * returned. * - * @param mmu_info + * @param aspace * @param mdesc * @param desc_nr */ diff --git a/libcpu/risc-v/virt64/mmu.h b/libcpu/risc-v/virt64/mmu.h index aa05cebc8e..809e514b82 100644 --- a/libcpu/risc-v/virt64/mmu.h +++ b/libcpu/risc-v/virt64/mmu.h @@ -67,19 +67,6 @@ void rt_hw_mmu_unmap(rt_aspace_t aspace, void *v_addr, size_t size); void rt_hw_aspace_switch(rt_aspace_t aspace); void *rt_hw_mmu_v2p(rt_aspace_t aspace, void *vaddr); -static inline void *_rt_kmem_v2p(void *vaddr) -{ - return rt_hw_mmu_v2p(&rt_kernel_space, vaddr); -} - -static inline void *rt_kmem_v2p(void *vaddr) -{ - MM_PGTBL_LOCK(&rt_kernel_space); - void *paddr = _rt_kmem_v2p(vaddr); - MM_PGTBL_UNLOCK(&rt_kernel_space); - return paddr; -} - int rt_hw_mmu_control(struct rt_aspace *aspace, void *vaddr, size_t size, enum rt_mmu_cntl cmd); |
