Repository navigation
[libcpu][riscv] fix MMU and user fault handling for Smart #11892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BernardXiong
wants to merge
2
commits into
RT-Thread:master
Choose a base branch
from
BernardXiong:pr/riscv-smart-mmu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−8
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| */ | ||
|
|
||
| #include <rtthread.h> | ||
| #include <rthw.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
|
|
@@ -85,6 +86,20 @@ void rt_hw_aspace_switch(rt_aspace_t aspace) | |
| uint32_t hartid = rt_hw_cpu_id(); | ||
| uintptr_t ptr = (uintptr_t)aspace->page_table + (uintptr_t)(hartid * ARCH_PAGE_SIZE); | ||
| uintptr_t page_table = (uintptr_t)rt_kmem_v2p((void *)ptr); | ||
|
|
||
| if (page_table == (uintptr_t)ARCH_MAP_FAILED) | ||
| { | ||
| /* | ||
| * During early K230 bring-up the kernel still runs with low physical | ||
| * pointers after relocation, including MMUTable. The formal kernel | ||
| * aspace does not translate that low pointer yet, but SATP needs the | ||
| * physical page-table address, so use the low address directly. | ||
| */ | ||
| if (ptr < KERNEL_VADDR_START) | ||
| { | ||
| page_table = ptr; | ||
| } | ||
| } | ||
| #ifndef RT_USING_SMP | ||
| current_mmu_table = aspace->page_table; | ||
| #else | ||
|
|
@@ -632,14 +647,14 @@ static inline void _init_region(void *vaddr, size_t size) | |
| { | ||
| rt_ioremap_start = vaddr; | ||
| rt_ioremap_size = size; | ||
| rt_mpr_start = rt_ioremap_start - rt_mpr_size; | ||
| rt_mpr_start = (void *)((rt_ubase_t)rt_ioremap_start - rt_mpr_size); | ||
| LOG_D("rt_ioremap_start: %p, rt_mpr_start: %p", rt_ioremap_start, | ||
| rt_mpr_start); | ||
| } | ||
| #else | ||
| static inline void _init_region(void *vaddr, size_t size) | ||
| { | ||
| rt_mpr_start = vaddr - rt_mpr_size; | ||
| rt_mpr_start = (void *)((rt_ubase_t)vaddr - rt_mpr_size); | ||
| } | ||
| #endif | ||
|
|
||
|
|
@@ -1057,6 +1072,9 @@ void rt_hw_mem_setup_early(void *pgtbl, rt_uint64_t hartid) | |
| vs += EARLY_MAP_PAGE_SIZE_2M; | ||
| } | ||
| #endif | ||
| /* flush page table entries from data cache before enabling MMU */ | ||
| rt_hw_cpu_dcache_clean(early_pgtbl, ARCH_PAGE_SIZE); | ||
|
|
||
| /* apply new mapping */ | ||
| asm volatile("sfence.vma x0, x0"); | ||
| write_csr(satp, SATP_BASE | ((size_t)early_pgtbl >> PAGE_OFFSET_BIT)); | ||
|
|
@@ -1121,6 +1139,19 @@ void *rt_hw_mmu_pgtbl_create(void) | |
| return RT_NULL; | ||
| } | ||
| rt_memcpy(mmu_table, rt_kernel_space.page_table, ARCH_PAGE_SIZE); | ||
|
|
||
| #ifdef RT_USING_SMART | ||
| { | ||
| int i; | ||
| int start_idx = USER_VADDR_START >> VPN2_SHIFT; | ||
| int end_idx = USER_VADDR_TOP >> VPN2_SHIFT; | ||
| for (i = start_idx; i <= end_idx; i++) | ||
| { | ||
| mmu_table[i] = 0; | ||
|
Comment on lines
+1146
to
+1150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 熊老师好呀!这段清零好像只在非 SMP 分支,SMP 下每个 hart 的 table 是不是也要清一下?另外 |
||
| } | ||
| } | ||
| #endif | ||
|
|
||
| rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, mmu_table, ARCH_PAGE_SIZE); | ||
| #endif | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
熊老师好呀!
sys_exit_group(-1)后面的csr_write按理走不到,IE 会一直开着。是不是先恢复再调更稳?如有误解请指正,谢谢!