* off: FFF
*/
-u64 get_tcr(int el, u64 *pips, u64 *pva_bits)
+static int get_effective_el(void)
{
+ int el = current_el();
+
+ if (el == 2) {
+ u64 hcr_el2;
+
+ /*
+ * If we are using the EL2&0 translation regime, the TCR_EL2
+ * looks like the EL1 version, even though we are in EL2.
+ */
+ __asm__ ("mrs %0, HCR_EL2\n" : "=r" (hcr_el2));
+ if (hcr_el2 & BIT(HCR_EL2_E2H_BIT))
+ return 1;
+ }
+
+ return el;
+}
+
+u64 get_tcr(u64 *pips, u64 *pva_bits)
+{
+ int el = get_effective_el();
u64 max_addr = 0;
u64 ips, va_bits;
u64 tcr;
debug("addr=%llx level=%d\n", addr, level);
- get_tcr(0, NULL, &va_bits);
+ get_tcr(NULL, &va_bits);
if (va_bits < 39)
start_level = 1;
u64 va_bits;
int start_level = 0;
- get_tcr(0, NULL, &va_bits);
+ get_tcr(NULL, &va_bits);
if (va_bits < 39)
start_level = 1;
setup_all_pgtables();
el = current_el();
- set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
+ set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(NULL, NULL),
MEMORY_ATTRIBUTES);
/* enable the mmu */
/* point TTBR to the new table */
set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
- get_tcr(el, NULL, NULL) &
+ get_tcr(NULL, NULL) &
~(TCR_ORGN_MASK | TCR_IRGN_MASK),
MEMORY_ATTRIBUTES);
invalidate_icache_all();
/* point TTBR to the new table */
- set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
+ set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(NULL, NULL),
MEMORY_ATTRIBUTES);
set_sctlr(get_sctlr() | CR_M);
msr cptr_el3, xzr /* Enable FP/SIMD */
b 0f
2: mrs x1, hcr_el2
- tbnz x1, #34, 1f /* HCR_EL2.E2H */
+ tbnz x1, #HCR_EL2_E2H_BIT, 1f /* HCR_EL2.E2H */
orr x1, x1, #HCR_EL2_AMO_EL2 /* Route SErrors to EL2 */
msr hcr_el2, x1
set_vbar vbar_el2, x0
#define TCR_EL2_RSVD (1U << 31 | 1 << 23)
#define TCR_EL3_RSVD (1U << 31 | 1 << 23)
+#define HCR_EL2_E2H_BIT 34
+
#ifndef __ASSEMBLY__
static inline void set_ttbr_tcr_mair(int el, u64 table, u64 tcr, u64 attr)
{
extern struct mm_region *mem_map;
void setup_pgtables(void);
-u64 get_tcr(int el, u64 *pips, u64 *pva_bits);
+u64 get_tcr(u64 *pips, u64 *pva_bits);
#endif
#endif /* _ASM_ARMV8_MMU_H_ */