Skip to content
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

[Feature] riscv: common64: ASID 的初始化过程优化 | Merge asid init into setup of early page table #9521

Open
polarvid opened this issue Oct 11, 2024 · 2 comments
Labels
Arch: RISC-V BSP related with risc-v

Comments

@polarvid
Copy link
Contributor

polarvid commented Oct 11, 2024

Describe problem solved by the proposed feature

关联 #9511 (comment)

void rt_hw_asid_init(void)
{
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;
}

这里的 write_csr(satp, satp_reg); 重置 satp 怪怪的。因为正常是两个启动阶段,做两次 satp 设置。第一次是初始映射,使用大粒度 pte,为了给初始化过程配置最基础的虚存属性(比如 cache 属性),并进入线性地址空间。第二次是按照虚存配置的映射(可能从静态/动态配置中读取运行时虚存布局),按照应用、驱动的需求配置内核地址空间。

这里在中间又重置了一次 satp,并不是特别必要。或许是可以把 ASID 初始化操作合并到 rt_hw_mem_setup_early (第一次的初始映射)中。

@polarvid polarvid added the Arch: RISC-V BSP related with risc-v label Oct 11, 2024
@zhangjing0303
Copy link
Contributor

目前rt_hw_asid_init中通过向satp寄存器的bit[59:44]写1以确定ASIDLEN的值,此函数最好在MMU页表未使能前调用,所以把 ASID 初始化操作合并到 rt_hw_mem_setup_early的开始处比较合理些。

@zhangjing0303
Copy link
Contributor

再就是commn64中通过ARCH_USING_ASID来决定是否使用ASID,是否可以通过rt_hw_asid_init中的ASID_BITS值确定当前cpu是否支持ASID,如果支持,则默认在rt_hw_aspace_switch中使用asid功能。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: RISC-V BSP related with risc-v
Projects
None yet
Development

No branches or pull requests

2 participants