6.5 MAIR_ELx and AttrIndx
Stage 1 descriptors do not encode the memory type directly. A block or page descriptor carries a 3-bit AttrIndx in bits[4:2]. That index selects one of eight 8-bit Attr fields in MAIR_ELx (Memory Attribute Indirection Register) of the translation regime. There are three of these registers:
MAIR_EL1for EL1&0;MAIR_EL2for EL2, or for EL2&0 with VHE;MAIR_EL3.
Shareability is not in MAIR. It comes from the descriptor’s SH field (6.4). Stage 2 does not use indirection: its descriptors carry MemAttr[3:0] directly, and the combination rules (including FEAT_S2FWB) are in 11.3.
The Attr encoding
Each Attr field (8 bits, written Attr<n> in DDI0487) is decoded as follows.
| Attr[7:4] | Attr[3:0] | Meaning |
|---|---|---|
0000 | dd00 | Device memory. dd: 00 nGnRnE, 01 nGnRE, 10 nGRE, 11 GRE |
0000 | dd01 | With FEAT_XS: Device memory with XS=0. Otherwise UNPREDICTABLE |
0000 | dd1x | UNPREDICTABLE |
oooo ≠ 0000 | iiii ≠ 0000 | Normal memory. oooo = Outer, iiii = Inner, per the table below |
0100 | 0000 | With FEAT_XS: Normal Inner/Outer Non-cacheable, XS=0 |
1010 | 0000 | With FEAT_XS: Normal Inner/Outer WT RA nWA Non-transient, XS=0 |
1111 | 0000 | With FEAT_MTE2: Tagged Normal, Inner/Outer WB RA WA Non-transient |
| other | 0000 | UNPREDICTABLE |
The Inner and Outer nibbles of a Normal type use the same encoding:
| Nibble | Meaning |
|---|---|
00RW (RW ≠ 00) | Write-Through Transient |
0100 | Non-cacheable |
01RW (RW ≠ 00) | Write-Back Transient |
10RW | Write-Through Non-transient |
11RW | Write-Back Non-transient |
Here R and W are the read-allocate and write-allocate hints (1 = allocate) (6.3).
The working set of values is small:
| Value | Type | TF-A index | Linux index |
|---|---|---|---|
0xFF | Normal WB RAWA Non-transient (Inner and Outer) | 0 (ATTR_IWBWA_OWBWA_NTR) | 0 (MT_NORMAL) |
0xF0 | Tagged Normal (MTE) | n/a | 1 (MT_NORMAL_TAGGED) |
0x44 | Normal Non-cacheable | 2 (ATTR_NON_CACHEABLE) | 2 (MT_NORMAL_NC) |
0x00 | Device-nGnRnE | 1 (ATTR_DEVICE) | 3 (MT_DEVICE_nGnRnE) |
0x04 | Device-nGnRE | n/a | 4 (MT_DEVICE_nGnRE) |
// MAIR_EL3: idx0 = Normal WB, idx1 = Device-nGnRnE, idx2 = Normal NC
mov x0, #0xff // Attr0
mov x1, #0x440000 // Attr1 = 0x00 (bits[15:8]), Attr2 = 0x44 (bits[23:16])
orr x0, x0, x1
msr mair_el3, x0
isb // before any walk that uses the new values
Tagged Normal (0xF0)
0xF0 is the only Tagged type, and it must be Inner and Outer WB RAWA Non-transient.
- Tag checking and tag accesses take place only for Tagged memory. Instructions such as
LDGandSTGoperate on allocation tags only there; on Untagged memory their tag accesses are RAZ/WI (13.4). - Without FEAT_MTE2,
0xF0is UNPREDICTABLE. It is not “plain WB”. - Linux defers the switch. Linux boots with
MAIR_EL1.Attr1=0xFFand switches it to0xF0only once MTE support has been detected.mte_cpu_setup()writesMAIR_EL1and then callslocal_flush_tlb_all(), because TLB entries may hold attributes derived from the old MAIR value.
That last step generalises. Changing an Attr field that live mappings use changes the attributes of every one of those mappings, and TLBs may cache the old attributes. Treat it like a change to the descriptors: change the field only when no mapping uses it, or follow the write with ISB and TLB invalidation, and deal with any aliasing it creates (6.6).
FEAT_AIE (brief)
FEAT_AIE is a 2022 extension; for its permitted-from version, see DDI0487 A2. It extends the indirection to 16 entries:
TCR2_ELx.AIE=1 enables an extraAttrIndxbit in the descriptor.- Indices 8–15 select fields in
MAIR2_ELx. - When 128-bit descriptors are enabled (
TCR2_ELx.D128=1, FEAT_D128),TCR2_ELx.AIEis RES1 (5.7).
Memory types when the MMU or the D-cache is off
When stage 1 translation of a regime is disabled (SCTLR_ELx.M=0), the PE does not consult MAIR at all. The VA is used directly as the PA, and fixed attributes apply.
| Access | Attributes with SCTLR_ELx.M=0 |
|---|---|
| Data | Device-nGnRnE, whatever SCTLR_ELx.C says |
Instruction fetch, SCTLR_ELx.I=1 | Normal, Outer Shareable, Inner/Outer Write-Through RA nWA |
Instruction fetch, SCTLR_ELx.I=0 | Normal, Outer Shareable, Inner/Outer Non-cacheable |
Special cases:
- EL1&0 under a hypervisor. For the EL1&0 regime,
HCR_EL2.DC=1 overrides the data default to Normal Non-shareable, Inner/Outer Write-Back RAWA, and the PE behaves as ifHCR_EL2.VMwere 1, so stage 2 translation applies (11.3). - MMU on, D-cache off. With
M=1 andC=0, MAIR is used, but every Normal data access is treated as Non-cacheable. Device mappings stay Device.
The asymmetry between data and instruction fetch is deliberate. Data stays safe for MMIO, and instruction fetch stays fast. The fetch side is still speculative. With all stages of translation disabled, DDI0487 limits speculative instruction fetches to locations near the code being executed (roughly the same or the next translation-granule-sized block; see “Behavior of instruction fetches when all associated stages of translation are disabled”). Within that window nothing is execute-never, so an unmapped hole or a read-sensitive peripheral placed directly after the boot image can be fetched. With stage 2 enabled (EL1 with its MMU off under a hypervisor), this limit does not apply, because not all stages are disabled (14.2).
The consequences of running with data as Device-nGnRnE
Early boot code (BL1, BL31’s cold-boot entry, and the PSCI warm-boot paths before the MMU is enabled) runs with all data in Device-nGnRnE memory, including its stack. Four consequences follow.
- Every unaligned data access faults, whatever
SCTLR_ELx.Asays (DFSC0b100001). Compilers generate unaligned accesses freely on AArch64: for packed structs, for inlinedmemcpy, and for merged adjacent stores. TF-A therefore builds all AArch64 code with-mstrict-align(make_helpers/cflags.mk), so the compiler never emits an access it does not know to be aligned. TF-A also setsSCTLR_EL3.A=1 at entry, so alignment checking stays on after the MMU is enabled. The flag is therefore needed in both phases. It does not cover hand-written assembly or prebuilt libraries. DC ZVAfaults.DC ZVAto Device memory generates an Alignment fault, so an optimisedmemsetcannot be used before the MMU is on. TF-A has two helpers:zeromemuses plain stores and is safe with the MMU off, whilezero_normalmemusesDC ZVAand requires Normal memory.- Exclusives and atomics are not guaranteed. Load-Exclusive/Store-Exclusive and LSE atomics are architecturally guaranteed only on Normal shareable WB memory. On Device memory, support is IMPLEMENTATION DEFINED: a
STXRmight never succeed, or the access might fault with “Unsupported Exclusive or Atomic access” (DFSC0b110101). This is why TF-A uses bakery locks, which need only ordinary loads and stores, on paths where participating PEs may have their data caches off. Spinlocks built on exclusives are used only where every participant is coherent (10.4). - Everything is slow and nothing is speculative. Every load waits for a non-gathered, non-reordered round trip. On emulation, that can make the pre-MMU phase dominate boot time. That is a reason to enable the MMU early, not to “optimise” pre-MMU code.
Bring-up note: “Works on FVP, Alignment fault on silicon or emulation right after reset” is almost always consequence 1 or 2. Look for a new C file built without
-mstrict-align, a vendor library linked into BL1 or BL2, or amemsetthat resolves to an optimised libc version. ESR shows EC0x25(Data Abort, same EL) with DFSC0b100001, andFAR_ELxgives an address that is not naturally aligned, or that is the target of aDC ZVA(5.8).
Validation note: To check that every MAIR index your firmware uses produces the attributes you meant, use
AT S1E3R(orS1E1R) on one address per index, thenISB, then readPAR_EL1.PAR_EL1.ATTR(bits[63:56]) returns the resulting attributes in MAIR format, andPAR_EL1.SHreturns the shareability (5.9). In RTL or emulation, also check the bus attributes of one real access per index. A mismatch betweenPAR_EL1.ATTRand the bus means an integration problem, not a table problem.
Checkpoint
Q6.5.1 BL31 code that runs before the MMU is enabled calls a C helper that zeroes a struct with memset, and takes an Alignment fault at a 64-byte-aligned address. What is the most likely cause?
- A. The struct is not aligned to 16 bytes
- B.
SCTLR_EL3.Ais 1; clearing it would fix the fault - C. The
memsetusesDC ZVA, which faults on Device memory, and with the MMU off all data accesses are Device-nGnRnE - D.
DC ZVAis UNDEFINED at EL3
Answer
C. With stage 1 disabled, data accesses are Device-nGnRnE, and DC ZVA to Device memory generates an Alignment fault, even at an aligned address. B is the tempting fix, but Device-memory alignment faults do not depend on SCTLR_ELx.A. The fix is a plain-store zeroing routine (TF-A’s zeromem) until the MMU is on.
Read more: Arm ARM (DDI0487), DC ZVA; “Behavior when stage 1 address translation is disabled”
Q6.5.2 With SCTLR_EL3.M=0 and SCTLR_EL3.I=1, which statement about instruction fetch is correct?
- A. Fetches are Normal, Write-Through cacheable and Outer Shareable, so the PE may speculatively fetch beyond the executed code, within an architecturally limited window, and nothing in that window is execute-never
- B. Fetches are Device-nGnRnE like data accesses, so no speculative fetch occurs
- C. Fetches are Normal Write-Back, so
IC IALLUis not needed after loading code - D. Instruction fetch is disabled until the MMU is enabled
Answer
A. With stage 1 off, instruction fetches are Normal, Outer Shareable, and WT-cacheable when I=1. Nothing marks any region execute-never. DDI0487 limits speculative fetches in this state to locations near the code being executed, but MMIO or a hole directly after the boot image is inside that window, which is how early-boot SErrors from speculative fetches arise. B is the common assumption that “MMU off means everything is Device”, which holds only for data. C is wrong because the I-cache can still hold stale lines.
Read more: Arm ARM (DDI0487), “Behavior when stage 1 address translation is disabled”; SCTLR_EL3.I
Q6.5.3 Why does TF-A build with -mstrict-align even though most of BL31 runs with the MMU and caches enabled?
- A. Because
-mstrict-alignmakes generated code faster on Normal memory - B. Because code runs with data as Device-nGnRnE before the MMU is on, and because TF-A sets
SCTLR_EL3.A=1 so alignment checking also applies after the MMU is enabled - C. Because Normal memory forbids unaligned accesses at EL3
- D. Because exclusives require aligned addresses, and
-mstrict-alignalso aligns all exclusive accesses
Answer
B. Both phases fault on unaligned accesses: Device memory always, and Normal memory once SCTLR_EL3.A=1. The flag stops the compiler from introducing such accesses. C is false, because Normal memory permits unaligned accesses unless SCTLR_ELx.A is set. D misstates the flag: it affects the compiler’s choice of ordinary loads and stores, while exclusive alignment is an architectural rule that the code must meet anyway.
Read more: Arm ARM (DDI0487), “Alignment support”; TF-A make_helpers/cflags.mk, el3_common_macros.S