Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
在你之后
rt-thread
提交
9db73a47
R
rt-thread
项目概览
在你之后
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9db73a47
编写于
1月 29, 2023
作者:
C
chenhy0106
提交者:
GitHub
1月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
为c906添加asid支持 (#6870)
* [rt-smart] asid for c906
上级
af143ee3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
3 deletion
+65
-3
components/mm/mm_aspace.h
components/mm/mm_aspace.h
+2
-0
libcpu/risc-v/t-head/c906/mmu.c
libcpu/risc-v/t-head/c906/mmu.c
+59
-1
libcpu/risc-v/t-head/c906/riscv_mmu.h
libcpu/risc-v/t-head/c906/riscv_mmu.h
+4
-2
未找到文件。
components/mm/mm_aspace.h
浏览文件 @
9db73a47
...
...
@@ -53,6 +53,8 @@ typedef struct rt_aspace
struct
_aspace_tree
tree
;
struct
rt_mutex
bst_lock
;
rt_uint64_t
asid
;
}
*
rt_aspace_t
;
typedef
struct
rt_varea
...
...
libcpu/risc-v/t-head/c906/mmu.c
浏览文件 @
9db73a47
...
...
@@ -41,14 +41,70 @@ static void *current_mmu_table = RT_NULL;
volatile
__attribute__
((
aligned
(
4
*
1024
)))
rt_ubase_t
MMUTable
[
__SIZE
(
VPN2_BIT
)];
static
rt_uint8_t
ASID_BITS
=
0
;
static
rt_uint16_t
next_asid
;
static
rt_uint64_t
global_asid_generation
;
#define ASID_MASK ((1 << ASID_BITS) - 1)
#define ASID_FIRST_GENERATION (1 << ASID_BITS)
#define MAX_ASID ASID_FIRST_GENERATION
static
void
_asid_init
()
{
unsigned
int
satp_reg
=
read_csr
(
satp
);
satp_reg
|=
(((
rt_uint64_t
)
0xffff
)
<<
PPN_BITS
);
write_csr
(
satp
,
satp_reg
);
unsigned
short
valid_asid_bit
=
((
read_csr
(
satp
)
>>
PPN_BITS
)
&
0xffff
);
// The maximal value of ASIDLEN, is 9 for Sv32 or 16 for Sv39, Sv48, and Sv57
for
(
unsigned
i
=
0
;
i
<
16
;
i
++
)
{
if
(
!
(
valid_asid_bit
&
0x1
))
{
break
;
}
valid_asid_bit
>>=
1
;
ASID_BITS
++
;
}
global_asid_generation
=
ASID_FIRST_GENERATION
;
next_asid
=
1
;
}
static
rt_uint64_t
_asid_check_switch
(
rt_aspace_t
aspace
)
{
if
((
aspace
->
asid
^
global_asid_generation
)
>>
ASID_BITS
)
// not same generation
{
if
(
next_asid
!=
MAX_ASID
)
{
aspace
->
asid
=
global_asid_generation
|
next_asid
;
next_asid
++
;
}
else
{
// scroll to next generation
global_asid_generation
+=
ASID_FIRST_GENERATION
;
next_asid
=
1
;
rt_hw_tlb_invalidate_all_local
();
aspace
->
asid
=
global_asid_generation
|
next_asid
;
next_asid
++
;
}
}
return
aspace
->
asid
&
ASID_MASK
;
}
void
rt_hw_aspace_switch
(
rt_aspace_t
aspace
)
{
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
);
write_csr
(
satp
,
(((
size_t
)
SATP_MODE
)
<<
SATP_MODE_OFFSET
)
|
(
asid
<<
PPN_BITS
)
|
((
rt_ubase_t
)
page_table
>>
PAGE_OFFSET_BIT
));
rt_hw_tlb_invalidate_all_local
(
);
asm
volatile
(
"sfence.vma x0,%0"
::
"r"
(
asid
)
:
"memory"
);
}
void
*
rt_hw_mmu_tbl_get
()
...
...
@@ -482,6 +538,8 @@ void rt_hw_mmu_setup(rt_aspace_t aspace, struct mem_desc *mdesc, int desc_nr)
mdesc
++
;
}
_asid_init
();
rt_hw_aspace_switch
(
&
rt_kernel_space
);
rt_page_cleanup
();
}
...
...
libcpu/risc-v/t-head/c906/riscv_mmu.h
浏览文件 @
9db73a47
...
...
@@ -63,8 +63,8 @@
#define PAGE_ATTR_CB (PTE_BUF | PTE_CACHE)
#define PAGE_ATTR_DEV (PTE_SO)
#define PAGE_DEFAULT_ATTR_LEAF (PTE_SHARE | PTE_BUF | PTE_CACHE | PTE_A | PTE_D | PTE_
G | PTE_
U | PAGE_ATTR_RWX | PTE_V)
#define PAGE_DEFAULT_ATTR_NEXT (PTE_SHARE | PTE_BUF | PTE_CACHE | PTE_A | PTE_D | PTE_
G | PTE_
V)
#define PAGE_DEFAULT_ATTR_LEAF (PTE_SHARE | PTE_BUF | PTE_CACHE | PTE_A | PTE_D | PTE_U | PAGE_ATTR_RWX | PTE_V)
#define PAGE_DEFAULT_ATTR_NEXT (PTE_SHARE | PTE_BUF | PTE_CACHE | PTE_A | PTE_D | PTE_V)
#define PAGE_IS_LEAF(pte) __MASKVALUE(pte, PAGE_ATTR_RWX)
...
...
@@ -81,6 +81,8 @@
#define SATP_MODE_SV57 10
#define SATP_MODE_SV64 11
#define PPN_BITS 44
#define ARCH_VADDR_WIDTH 39
#define SATP_MODE SATP_MODE_SV39
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录