@@ -39,8 +39,28 @@ DECLARE_GLOBAL_DATA_PTR;
3939 * off: FFF
4040 */
4141
42- u64 get_tcr ( int el , u64 * pips , u64 * pva_bits )
42+ static int get_effective_el ( void )
4343{
44+ int el = current_el ();
45+
46+ if (el == 2 ) {
47+ u64 hcr_el2 ;
48+
49+ /*
50+ * If we are using the EL2&0 translation regime, the TCR_EL2
51+ * looks like the EL1 version, even though we are in EL2.
52+ */
53+ __asm__ ("mrs %0, HCR_EL2\n" : "=r" (hcr_el2 ));
54+ if (hcr_el2 & BIT (HCR_EL2_E2H_BIT ))
55+ return 1 ;
56+ }
57+
58+ return el ;
59+ }
60+
61+ u64 get_tcr (u64 * pips , u64 * pva_bits )
62+ {
63+ int el = get_effective_el ();
4464 u64 max_addr = 0 ;
4565 u64 ips , va_bits ;
4666 u64 tcr ;
@@ -115,7 +135,7 @@ static u64 *find_pte(u64 addr, int level)
115135
116136 debug ("addr=%llx level=%d\n" , addr , level );
117137
118- get_tcr (0 , NULL , & va_bits );
138+ get_tcr (NULL , & va_bits );
119139 if (va_bits < 39 )
120140 start_level = 1 ;
121141
@@ -343,7 +363,7 @@ __weak u64 get_page_table_size(void)
343363 u64 va_bits ;
344364 int start_level = 0 ;
345365
346- get_tcr (0 , NULL , & va_bits );
366+ get_tcr (NULL , & va_bits );
347367 if (va_bits < 39 )
348368 start_level = 1 ;
349369
@@ -415,7 +435,7 @@ __weak void mmu_setup(void)
415435 setup_all_pgtables ();
416436
417437 el = current_el ();
418- set_ttbr_tcr_mair (el , gd -> arch .tlb_addr , get_tcr (el , NULL , NULL ),
438+ set_ttbr_tcr_mair (el , gd -> arch .tlb_addr , get_tcr (NULL , NULL ),
419439 MEMORY_ATTRIBUTES );
420440
421441 /* enable the mmu */
0 commit comments