Skip to content

Commit

Permalink
arm64: Move setting TCR_HD to C code
Browse files Browse the repository at this point in the history
To allow for it to be more selective when we enable it, e.g. if the
CPU has an erratum that prevents us from doing so, move the check for
setting TCR_HD to C.

Reviewed by:	alc
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47808
  • Loading branch information
zxombie committed Dec 11, 2024
1 parent fcdce73 commit fc25f06
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
17 changes: 7 additions & 10 deletions sys/arm64/arm64/locore.S
Original file line number Diff line number Diff line change
Expand Up @@ -940,20 +940,17 @@ LENTRY(start_mmu)
bfi x2, x3, #(TCR_ASID_SHIFT), #(TCR_ASID_WIDTH)

/*
* Check if the HW supports access flag and dirty state updates,
* and set TCR_EL1.HA and TCR_EL1.HD accordingly.
* Check if the HW supports access flag updates, and set
* TCR_EL1.HA accordingly. The TCR_EL1.HD flag to enable
* HW management of dirty state is set in C code as it may
* need to be disabled because of CPU errata.
*/
mrs x3, id_aa64mmfr1_el1
and x3, x3, #(ID_AA64MMFR1_HAFDBS_MASK)
cmp x3, #1
b.ne 1f
orr x2, x2, #(TCR_HA)
b 2f
cbz x3, 1f
orr x2, x2, #(TCR_HA)
1:
cmp x3, #2
b.ne 2f
orr x2, x2, #(TCR_HA | TCR_HD)
2:

msr tcr_el1, x2

/*
Expand Down
1 change: 1 addition & 0 deletions sys/arm64/arm64/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ init_secondary(uint64_t cpu)
pcpup = cpuid_to_pcpu[cpu];
pcpup->pc_midr = get_midr();
identify_cpu(cpu);
pmap_cpu_init();

/* Ensure the stores in identify_cpu have completed */
atomic_thread_fence_acq_rel();
Expand Down
21 changes: 21 additions & 0 deletions sys/arm64/arm64/pmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,8 @@ pmap_bootstrap(vm_size_t kernlen)
vm_paddr_t start_pa, pa;
uint64_t tcr;

pmap_cpu_init();

tcr = READ_SPECIALREG(tcr_el1);

/* Verify that the ASID is set through TTBR0. */
Expand Down Expand Up @@ -1623,6 +1625,25 @@ pmap_init_pv_table(void)
}
}

void
pmap_cpu_init(void)
{
uint64_t id_aa64mmfr1, tcr;

/* Enable HAFDBS if supported */
id_aa64mmfr1 = READ_SPECIALREG(id_aa64mmfr1_el1);
if (ID_AA64MMFR1_HAFDBS_VAL(id_aa64mmfr1) >=ID_AA64MMFR1_HAFDBS_AF_DBS){
tcr = READ_SPECIALREG(tcr_el1) | TCR_HD;
WRITE_SPECIALREG(tcr_el1, tcr);
isb();
/* Flush the local TLB for the TCR_HD flag change */
dsb(nshst);
__asm __volatile("tlbi vmalle1");
dsb(nsh);
isb();
}
}

/*
* Initialize the pmap module.
*
Expand Down
1 change: 1 addition & 0 deletions sys/arm64/include/pmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ extern pt_entry_t pmap_sh_attr;

void pmap_activate_vm(pmap_t);
void pmap_bootstrap(vm_size_t);
void pmap_cpu_init(void);
int pmap_change_attr(vm_offset_t va, vm_size_t size, int mode);
int pmap_change_prot(vm_offset_t va, vm_size_t size, vm_prot_t prot);
void pmap_kenter(vm_offset_t sva, vm_size_t size, vm_paddr_t pa, int mode);
Expand Down

0 comments on commit fc25f06

Please sign in to comment.