Skip to content

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

Open
@polarvid

Description

@polarvid

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 (第一次的初始映射)中。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions