慢慢欣赏arm64内核启动23 primary_entry之__cpu_setup代码第五部分

展示代码

#ifdef CONFIG_ARM64_HW_AFDBM
	/*
	 * Enable hardware update of the Access Flags bit.
	 * Hardware dirty bit management is enabled later,
	 * via capabilities.
	 */
	mrs	x9, ID_AA64MMFR1_EL1
	and	x9, x9, #0xf
	cbz	x9, 1f
	orr	x10, x10, #TCR_HA		// hardware Access flag update
1:
#endif	/* CONFIG_ARM64_HW_AFDBM */
	msr	tcr_el1, x10

分析代码

第1行涉及到条件编译宏定义 CONFIG_ARM64_HW_AFDBM

$ cat .config | grep CONFIG_ARM64_HW_AFDBM
CONFIG_ARM64_HW_AFDBM=y

其含义如下
The ARMv8.1 architecture extensions introduce support for  hardware updates of the access and dirty information in page  table entries.
When enabled in TCR_EL1 (HA and HD bits) on capable processors, accesses to pages with PTE_AF cleared will set this bit instead of raising an access flag fault.
Similarly, writes to read-only pages with the DBM bit set will clear the read-only bit (AP[2]) instead of raising a permission fault.
CONFIG_ARM64_HW_AFDBM 是 Linux 内核的一个配置选项,用于启用 ARMv8.1 架构扩展中的硬件功能,该功能支持硬件更新页面表项中的访问(Access)和脏(Dirty)标志位。
当在 TCR_EL1 寄存器(HA 和 HD 位)上启用此功能时,如果访问了清除了 PTE_AF 位的页面,则会设置该位,而不是触发访问标志故障。
同样,如果向设置了 DBM 位的只读页面写入,将清除只读位(AP[2]),而不是触发权限故障。即使在不具备 ARMv8.1 功能的硬件上构建了启用此配置选项的内核,其性能影响也很小。
如果在内核配置中不确定是否启用此选项,建议选择“Y”启用它

第2行到第6行为注释,含义为使能“硬件访问标记位”。后继使能“硬件脏位”

第7行涉及到寄存器 ID_AA64MMFR1_EL1, AArch64 Memory Model Feature Register 1,含义如下
Provides information about the implemented memory model and memory management support in AArch64 state.
该语句将 ID_AA64MMFR1_EL1 的内容存放到 x9


第8行的含义是提取 ID_AA64MMFR1_EL1 的bits[3:0],其含义如下
HAFDBS, bits [3:0]
Hardware updates to Access flag and Dirty state in translation tables. Defined values are:
    0b0000    Hardware update of the Access flag and dirty state are not supported.
    0b0001    Hardware update of the Access flag is supported.
    0b0010    Hardware update of both the Access flag and dirty state is supported.
从这里我们可以看出硬件是否支持 更新页面表项中的访问(Access)和脏(Dirty)

第9行的含义是判断  ID_AA64MMFR1_EL1 的bits[3:0] 是否为0, 如果为0,则跳转到第11行,否则继续执行第10行

第10行涉及到宏定义 TCR_HA,含义如下

#define TCR_HA			(UL(1) << 39)

该行的含义是按位或,将 x10 的 bit39 置为1

第13行可以看出,bit39 是 TCR_EL1 的 HA位
HA, bit [39]
When ARMv8.1-TTHM is implemented:
    Hardware Access flag update in stage 1 translations from EL0 and EL1.
    0b0    Stage 1 Access flag update disabled.
    0b1    Stage 1 Access flag update enabled.
我们从这里可以看出实现逻辑,如果解析寄存器 ID_AA64MMFR1_EL1 支持  更新页面表项中的访问(Access),那么就设置 TCR_EL1 使能 更新页面表项中的访问(Access),根据注释,脏标记的使能后续再说。
TCR_EL1, Translation Control Register (EL1) 的含义如下
The control register for stage 1 of the EL1&0 translation regime.
在ARM64架构中,TCR_EL1(Translation Control Register)是一个重要的系统寄存器,它控制着MMU(内存管理单元)的行为和属性。TCR_EL1寄存器的设置会影响地址翻译的行为,包括页表的缓存属性、页粒度大小、物理地址的大小,以及ASID(Address Space Identifier)的大小等。
x10 除了包含 bit39,还包含 bits[34:32],在 TCR_EL1 的含义如下
IPS, bits [34:32]
Intermediate Physical Address Size.
    0b000    32 bits, 4GB.
    0b001    36 bits, 64GB.
    0b010    40 bits, 1TB.
    0b011    42 bits, 4TB.
    0b100    44 bits, 16TB.
    0b101    48 bits, 256TB.
    0b110    52 bits, 4PB.
根据上上章节,是从 ID_AA64MMFR0_PARANGE_SHIFT 获取硬件的支持情况设置进去的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值