Commit 6563c0be authored by Antonio Nino Diaz's avatar Antonio Nino Diaz
Browse files

xlat v2: Turn MMU parameters into 64-bit values



Most registers are 64-bit wide, even in AArch32 mode:

- MAIR_ELx is equivalent to MAIR0 and MAIR1.
- TTBR is 64 bit in both AArch64 and AArch32.

The only difference is the TCR register, which is 32 bit in AArch32 and
in EL3 in AArch64. For consistency with the rest of ELs in AArch64, it
makes sense to also have it as a 64-bit value.

Change-Id: I2274d66a28876702e7085df5f8aad0e7ec139da9
Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
parent aa1d5f60
...@@ -16,12 +16,11 @@ ...@@ -16,12 +16,11 @@
#error "Do not include this header file directly. Include xlat_tables_v2.h instead." #error "Do not include this header file directly. Include xlat_tables_v2.h instead."
#endif #endif
/* Offsets into mmu_cfg_params array. All parameters are 32 bits wide. */ /* Offsets into mmu_cfg_params array. All parameters are 64 bits wide. */
#define MMU_CFG_MAIR0 0 #define MMU_CFG_MAIR 0
#define MMU_CFG_TCR 1 #define MMU_CFG_TCR 1
#define MMU_CFG_TTBR0_LO 2 #define MMU_CFG_TTBR0 2
#define MMU_CFG_TTBR0_HI 3 #define MMU_CFG_PARAM_MAX 3
#define MMU_CFG_PARAM_MAX 4
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
...@@ -32,7 +31,7 @@ ...@@ -32,7 +31,7 @@
#include <xlat_tables_defs.h> #include <xlat_tables_defs.h>
/* Parameters of register values required when enabling MMU */ /* Parameters of register values required when enabling MMU */
extern uint32_t mmu_cfg_params[MMU_CFG_PARAM_MAX]; extern uint64_t mmu_cfg_params[MMU_CFG_PARAM_MAX];
/* Forward declaration */ /* Forward declaration */
struct mmap_region; struct mmap_region;
......
...@@ -24,17 +24,17 @@ func enable_mmu_direct ...@@ -24,17 +24,17 @@ func enable_mmu_direct
mov r3, r0 mov r3, r0
ldr r0, =mmu_cfg_params ldr r0, =mmu_cfg_params
/* MAIR0 */ /* MAIR0. Only the lower 32 bits are used. */
ldr r1, [r0, #(MMU_CFG_MAIR0 << 2)] ldr r1, [r0, #(MMU_CFG_MAIR << 3)]
stcopr r1, MAIR0 stcopr r1, MAIR0
/* TTBCR */ /* TTBCR. Only the lower 32 bits are used. */
ldr r2, [r0, #(MMU_CFG_TCR << 2)] ldr r2, [r0, #(MMU_CFG_TCR << 3)]
stcopr r2, TTBCR stcopr r2, TTBCR
/* TTBR0 */ /* TTBR0 */
ldr r1, [r0, #(MMU_CFG_TTBR0_LO << 2)] ldr r1, [r0, #(MMU_CFG_TTBR0 << 3)]
ldr r2, [r0, #(MMU_CFG_TTBR0_HI << 2)] ldr r2, [r0, #((MMU_CFG_TTBR0 << 3) + 4)]
stcopr16 r1, r2, TTBR0_64 stcopr16 r1, r2, TTBR0_64
/* TTBR1 is unused right now; set it to 0. */ /* TTBR1 is unused right now; set it to 0. */
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#error ARMv7 target does not support LPAE MMU descriptors #error ARMv7 target does not support LPAE MMU descriptors
#endif #endif
uint32_t mmu_cfg_params[MMU_CFG_PARAM_MAX]; uint64_t mmu_cfg_params[MMU_CFG_PARAM_MAX];
/* /*
* Returns 1 if the provided granule size is supported, 0 otherwise. * Returns 1 if the provided granule size is supported, 0 otherwise.
...@@ -113,16 +113,16 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table, ...@@ -113,16 +113,16 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table,
unsigned long long max_pa, uintptr_t max_va, unsigned long long max_pa, uintptr_t max_va,
__unused int xlat_regime) __unused int xlat_regime)
{ {
u_register_t mair0, ttbcr; uint64_t mair, ttbr0;
uint64_t ttbr0; uint32_t ttbcr;
assert(IS_IN_SECURE()); assert(IS_IN_SECURE());
/* Set attributes in the right indices of the MAIR */ /* Set attributes in the right indices of the MAIR */
mair0 = MAIR0_ATTR_SET(ATTR_DEVICE, ATTR_DEVICE_INDEX); mair = MAIR0_ATTR_SET(ATTR_DEVICE, ATTR_DEVICE_INDEX);
mair0 |= MAIR0_ATTR_SET(ATTR_IWBWA_OWBWA_NTR, mair |= MAIR0_ATTR_SET(ATTR_IWBWA_OWBWA_NTR,
ATTR_IWBWA_OWBWA_NTR_INDEX); ATTR_IWBWA_OWBWA_NTR_INDEX);
mair0 |= MAIR0_ATTR_SET(ATTR_NON_CACHEABLE, mair |= MAIR0_ATTR_SET(ATTR_NON_CACHEABLE,
ATTR_NON_CACHEABLE_INDEX); ATTR_NON_CACHEABLE_INDEX);
/* /*
...@@ -170,17 +170,17 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table, ...@@ -170,17 +170,17 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table,
/* Set TTBR0 bits as well */ /* Set TTBR0 bits as well */
ttbr0 = (uint64_t)(uintptr_t) base_table; ttbr0 = (uint64_t)(uintptr_t) base_table;
#if ARM_ARCH_AT_LEAST(8, 2) #if ARM_ARCH_AT_LEAST(8, 2)
/* /*
* Enable CnP bit so as to share page tables with all PEs. * Enable CnP bit so as to share page tables with all PEs. This
* Mandatory for ARMv8.2 implementations. * is mandatory for ARMv8.2 implementations.
*/ */
ttbr0 |= TTBR_CNP_BIT; ttbr0 |= TTBR_CNP_BIT;
#endif #endif
/* Now populate MMU configuration */ /* Now populate MMU configuration */
mmu_cfg_params[MMU_CFG_MAIR0] = mair0; mmu_cfg_params[MMU_CFG_MAIR] = mair;
mmu_cfg_params[MMU_CFG_TCR] = ttbcr; mmu_cfg_params[MMU_CFG_TCR] = (uint64_t) ttbcr;
mmu_cfg_params[MMU_CFG_TTBR0_LO] = (uint32_t) ttbr0; mmu_cfg_params[MMU_CFG_TTBR0] = ttbr0;
mmu_cfg_params[MMU_CFG_TTBR0_HI] = ttbr0 >> 32;
} }
...@@ -43,17 +43,15 @@ ...@@ -43,17 +43,15 @@
ldr x0, =mmu_cfg_params ldr x0, =mmu_cfg_params
/* MAIR */ /* MAIR */
ldr w1, [x0, #(MMU_CFG_MAIR0 << 2)] ldr x1, [x0, #(MMU_CFG_MAIR << 3)]
_msr mair, \el, x1 _msr mair, \el, x1
/* TCR */ /* TCR */
ldr w2, [x0, #(MMU_CFG_TCR << 2)] ldr x2, [x0, #(MMU_CFG_TCR << 3)]
_msr tcr, \el, x2 _msr tcr, \el, x2
/* TTBR */ /* TTBR */
ldr w3, [x0, #(MMU_CFG_TTBR0_LO << 2)] ldr x3, [x0, #(MMU_CFG_TTBR0 << 3)]
ldr w4, [x0, #(MMU_CFG_TTBR0_HI << 2)]
orr x3, x3, x4, lsl #32
_msr ttbr0, \el, x3 _msr ttbr0, \el, x3
/* /*
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <xlat_tables_v2.h> #include <xlat_tables_v2.h>
#include "../xlat_tables_private.h" #include "../xlat_tables_private.h"
uint32_t mmu_cfg_params[MMU_CFG_PARAM_MAX]; uint64_t mmu_cfg_params[MMU_CFG_PARAM_MAX];
/* /*
* Returns 1 if the provided granule size is supported, 0 otherwise. * Returns 1 if the provided granule size is supported, 0 otherwise.
...@@ -183,7 +183,7 @@ int xlat_arch_current_el(void) ...@@ -183,7 +183,7 @@ int xlat_arch_current_el(void)
void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table, void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table,
unsigned long long max_pa, uintptr_t max_va, int xlat_regime) unsigned long long max_pa, uintptr_t max_va, int xlat_regime)
{ {
uint64_t mair, ttbr, tcr; uint64_t mair, ttbr0, tcr;
uintptr_t virtual_addr_space_size; uintptr_t virtual_addr_space_size;
/* Set attributes in the right indices of the MAIR. */ /* Set attributes in the right indices of the MAIR. */
...@@ -191,8 +191,6 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table, ...@@ -191,8 +191,6 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table,
mair |= MAIR_ATTR_SET(ATTR_IWBWA_OWBWA_NTR, ATTR_IWBWA_OWBWA_NTR_INDEX); mair |= MAIR_ATTR_SET(ATTR_IWBWA_OWBWA_NTR, ATTR_IWBWA_OWBWA_NTR_INDEX);
mair |= MAIR_ATTR_SET(ATTR_NON_CACHEABLE, ATTR_NON_CACHEABLE_INDEX); mair |= MAIR_ATTR_SET(ATTR_NON_CACHEABLE, ATTR_NON_CACHEABLE_INDEX);
ttbr = (uint64_t) base_table;
/* /*
* Limit the input address ranges and memory region sizes translated * Limit the input address ranges and memory region sizes translated
* using TTBR0 to the given virtual address space size. * using TTBR0 to the given virtual address space size.
...@@ -239,18 +237,18 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table, ...@@ -239,18 +237,18 @@ void setup_mmu_cfg(unsigned int flags, const uint64_t *base_table,
tcr |= TCR_EL3_RES1 | (tcr_ps_bits << TCR_EL3_PS_SHIFT); tcr |= TCR_EL3_RES1 | (tcr_ps_bits << TCR_EL3_PS_SHIFT);
} }
mmu_cfg_params[MMU_CFG_MAIR0] = (uint32_t) mair;
mmu_cfg_params[MMU_CFG_TCR] = (uint32_t) tcr;
/* Set TTBR bits as well */ /* Set TTBR bits as well */
if (ARM_ARCH_AT_LEAST(8, 2)) { ttbr0 = (uint64_t) base_table;
/*
* Enable CnP bit so as to share page tables with all PEs. This #if ARM_ARCH_AT_LEAST(8, 2)
* is mandatory for ARMv8.2 implementations. /*
*/ * Enable CnP bit so as to share page tables with all PEs. This
ttbr |= TTBR_CNP_BIT; * is mandatory for ARMv8.2 implementations.
} */
ttbr0 |= TTBR_CNP_BIT;
#endif
mmu_cfg_params[MMU_CFG_TTBR0_LO] = (uint32_t) ttbr; mmu_cfg_params[MMU_CFG_MAIR] = mair;
mmu_cfg_params[MMU_CFG_TTBR0_HI] = (uint32_t) (ttbr >> 32); mmu_cfg_params[MMU_CFG_TCR] = tcr;
mmu_cfg_params[MMU_CFG_TTBR0] = ttbr0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment