5.2 TCR_ELx and TCR2_ELx
TCR_ELx sets the shape of a regime’s translation: how large each VA range is, which granule each range uses, how large the output addresses may be, and with what memory attributes the walker reads descriptors. TCR2_ELx (FEAT_TCR2) is the extension register that newer translation features are enabled from. The descriptors themselves are in 5.3.
Layouts
TCR_EL1 and the VHE form of TCR_EL2 (E2H == 1) have two sets of fields, one per VA range. TCR_EL3 and the non-VHE TCR_EL2 have one set and a different layout:
| Field | TCR_EL1 bits | TCR_EL3 / TCR_EL2 (E2H=0) bits | Meaning |
|---|---|---|---|
T0SZ | [5:0] | [5:0] | Size offset of the low (TTBR0) range: VA size = 64 − T0SZ |
EPD0 | [7] | – | Disable walks for TTBR0 on a TLB miss |
IRGN0/ORGN0/SH0 | [9:8]/[11:10]/[13:12] | same | Walk attributes for TTBR0 walks |
TG0 | [15:14] | [15:14] | TTBR0 granule: 00=4K, 01=64K, 10=16K |
T1SZ | [21:16] | – | Size offset of the high (TTBR1) range |
A1 | [22] | – | ASID comes from TTBR1_EL1 (1) or TTBR0_EL1 (0) |
EPD1 | [23] | RES1 at [23] | Disable walks for TTBR1 |
IRGN1/ORGN1/SH1 | [25:24]/[27:26]/[29:28] | – | Walk attributes for TTBR1 walks |
TG1 | [31:30] | RES1 at [31] | TTBR1 granule: 01=16K, 10=4K, 11=64K (different encoding!) |
IPS / PS | IPS [34:32] | PS [18:16] | Output address size |
AS | [36] | – | 16-bit ASIDs (if ID_AA64MMFR0_EL1.ASIDBits allows) |
TBI0/TBI1 | [37]/[38] | TBI [20] | Top byte ignored (13.3) |
HA/HD | [39]/[40] | [21]/[22] | Hardware AF/dirty update (5.6) |
HPD0/HPD1 | [41]/[42] | HPD [24] | Disable hierarchical permissions (FEAT_HPDS, v8.1) |
HWU* | [50:43] | [28:25] | Descriptor bits 59–62 usable by hardware, IMPLEMENTATION DEFINED (FEAT_HPDS2) |
TBID0/TBID1 | [51]/[52] | TBID [29] | TBI for data accesses only (FEAT_PAuth) |
NFD0/NFD1 | [53]/[54] | – | SVE non-fault accesses fault without a walk |
E0PD0/E0PD1 | [55]/[56] | – | EL0 access to the range faults without a walk (FEAT_E0PD, v8.5) |
TCMA0/TCMA1 | [57]/[58] | TCMA [30] | MTE match-all tag (13.5) |
DS | [59] | [32] | 52-bit with 4K/16K (FEAT_LPA2, 5.7) |
Note the RES1 bits. TCR_EL3 and non-VHE TCR_EL2 have bits [31] and [23] RES1, and TF-A defines TCR_EL3_RES1 for them. Note also that TG0 and TG1 use different encodings for the same granule. Copying a TG0 value into TG1 gives the wrong granule or a reserved value (4K 00 becomes reserved, 64K 01 becomes 16K, 16K 10 becomes 4K). This is a classic bring-up bug: TG1 = 00 is reserved, and a reserved value is treated as an IMPLEMENTATION DEFINED choice among the implemented granules, so the behaviour differs between a model and silicon.
T0SZ, T1SZ: the input address size
The low range covers VAs 0 to 2^(64−T0SZ) − 1. The high range covers 2^64 − 2^(64−T1SZ) to 2^64 − 1. T0SZ = 16 gives the familiar 48-bit range. The size, together with the granule, fixes the starting level of the walk and the size of the first table (5.3). Programming T0SZ and the table layout from different assumptions is the commonest root cause of a level-0 Translation fault right after SCTLR_ELx.M is set.
Limits:
- The minimum
TxSZis 16 (48-bit), or 12 (52-bit) with FEAT_LVA for 64K, or withDS == 1(FEAT_LPA2) for 4K/16K (5.7). - The maximum is 39, or up to 48 (47 for 64K) with FEAT_TTST (v8.4, small translation tables).
- Values outside the supported range are CONSTRAINED UNPREDICTABLE in their effect. Do not rely on any behaviour.
The TTBR covering a range must point to a table aligned to that table’s size, with a 64-byte minimum. A 48-bit 64K configuration, for example, starts at level 1 with only 64 entries (512 bytes).
TG0/TG1: granules
The granule is the page size and the size of every translation table at that granule (4KB, 16KB or 64KB). It also sets the bits resolved per level (9, 11 and 13 respectively) and the available block sizes. Support is discoverable, and the fields have different signedness:
ID_AA64MMFR0_EL1 field | Bits | Encoding |
|---|---|---|
TGran4 | [31:28] | 0000 supported, 0001 supported with 52-bit, 1111 not supported (signed) |
TGran64 | [27:24] | 0000 supported, 1111 not supported (signed) |
TGran16 | [23:20] | 0000 not supported, 0001 supported, 0010 with 52-bit (unsigned) |
TGran4_2/TGran64_2/TGran16_2 | [43:40]/[39:36]/[35:32] | Stage 2 support; 0000 means “as the stage 1 field” |
The two ranges of one regime may use different granules, and stage 1 and stage 2 may differ too.
IPS and PS: output address size
| Value | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
|---|---|---|---|---|---|---|---|---|
| Bits | 32 | 36 | 40 | 42 | 44 | 48 | 52 (FEAT_LPA/LPA2) | 56 (FEAT_D128) |
If IPS or PS is larger than ID_AA64MMFR0_EL1.PARange, the implemented size is used instead. An output address above the configured size is an Address size fault. This covers the TTBR base address, a next-level table address and the final output address. If IPS is too small for your DRAM, the walk faults with an Address size fault, not a Translation fault. That difference tells you which of the two is misprogrammed. In the EL1&0 regime with stage 2 active, IPS bounds the IPA. The PA bound is VTCR_EL2.PS.
EPD0/EPD1
EPDn = 1 makes a TLB miss in that range a Translation fault instead of a walk. It does not disable TLB hits, so cached entries for that range keep working until they are invalidated. Typical uses:
- an EL1 environment that has no user half (
EPD0=1) or no kernel half (EPD1=1, as in many bare-metal or RTOS ports that use TTBR0 only); - a temporary state during a TTBR switch.
Keep TG1 a valid encoding and T1SZ in range anyway: the fields still exist, some behaviour still depends on them (the TTBR0/TTBR1 range split, TLBI range operations), and a later clear of EPD1 uses them immediately. Point TTBR1_EL1 at something harmless for the same reason.
HPD0/HPD1
With FEAT_HPDS (v8.1), HPDn = 1 makes the walk ignore the hierarchical permission bits in table descriptors (APTable, UXNTable/XNTable, PXNTable). With FEAT_HPDS2 (v8.2), those freed bits, together with the HWU enables, can carry IMPLEMENTATION DEFINED hardware attributes (PBHA). NSTable is not affected by HPD. Permissions are in 5.5.
Walk attributes: IRGN, ORGN, SH
IRGNn/ORGNn give the inner/outer cacheability of the walker’s descriptor reads (00 Non-cacheable, 01 WB read/write-allocate, 10 WT read-allocate, 11 WB read-allocate no write-allocate), and SHn their shareability (00 Non-shareable, 10 Outer, 11 Inner). They must agree with how software writes the tables, or the walker can read stale data: see Part 6 (6.3, 6.6).
TCR2_ELx (FEAT_TCR2)
TCR_EL1 was nearly full, so FEAT_TCR2 (an Armv8.9/v9.4 extension; for the permitted-from version, see DDI0487 A2) adds TCR2_EL1 and TCR2_EL2 as the enable registers for newer translation features. TCR2_EL1 fields:
| Bit | Field | Feature | Enables |
|---|---|---|---|
| 0 | PnCH | FEAT_THE | Protected attribute in descriptor bit 52 (13.2) |
| 1 | PIE | FEAT_S1PIE | Indirect permission scheme (5.5) |
| 2 | E0POE | FEAT_S1POE | Permission overlays for EL0 accesses (POR_EL0) |
| 3 | POE | FEAT_S1POE | Permission overlays for EL1 accesses (POR_EL1) |
| 4 | AIE | FEAT_AIE | Attribute index extension (MAIR2_EL1) |
| 5 | D128 | FEAT_D128 | 128-bit descriptor format (5.7) |
| 10 | PTTWI | FEAT_THE | Permitted translation table write inhibit |
| 11 | HAFT | FEAT_HAFT | Hardware Access flag in table descriptors (5.6) |
| 14/15 | DisCH0/DisCH1 | FEAT_D128 | Disable the contiguous hint per range |
| 16–18 | A2, FNG0, FNG1 | FEAT_ASID2 | Two concurrent ASIDs |
TCR2_EL1 is gated twice. If SCR_EL3.TCR2En == 0, EL1 and EL2 accesses to it trap to EL3 or are UNDEFINED. If EL2 is enabled and HCRX_EL2.TCR2En == 0, EL1 accesses trap to EL2. In either case, all TCR2_EL1 fields are treated as 0. A kernel that enables PIE while firmware leaves SCR_EL3.TCR2En clear does not get partial PIE: it takes an exception on the MSR. EL3 has no TCR2_EL3. The equivalent EL3 enables are fields of TCR_EL3 itself (for example TCR_EL3.PIE and TCR_EL3.POE). The enable sequencing is in 17.3.
Write ordering
All of these fields may be cached in TLBs. Change them only when no walk can use the old values (normally with the MMU off, or with a TLB invalidate afterwards), and follow the write with an ISB before relying on it (7.8). The enable sequence is in 9.3.
// EL1, TTBR0 only: 48-bit VA, 4K, 40-bit IPS, inner-shareable WBWA walks
// T0SZ=16, IRGN0=ORGN0=WBWA, SH0=Inner, TG0=4K, T1SZ=16 and TG1=4K (valid, unused), EPD1=1, IPS=40-bit
.equ TCR_VAL, (16 << 0) | (1 << 8) | (1 << 10) | (3 << 12) | (0 << 14) | (16 << 16) | (1 << 23) | (2 << 30) | (2 << 32)
ldr x0, =TCR_VAL // = 0x2_8090_3510
msr tcr_el1, x0
isb
Checkpoint
Q5.2.1 A port copies TCR_EL1.TG0 = 0b00 (4K) into TG1 and sets T1SZ = 16 for a kernel in the high range. The tables are built for 4K. What is the most likely outcome?
- A. It works, because
00means 4K in both fields - B.
TG1 = 00is reserved, so the walk uses an IMPLEMENTATION DEFINED implemented granule and may not match the tables, which can make it work on one platform and fault on another - C. The
MSRtoTCR_EL1is UNDEFINED - D. The TTBR1 range is disabled as if
EPD1were set
Answer
B. TG1 encodes 16K/4K/64K as 01/10/11, and 00 is reserved. Reserved granule values are treated as an IMPLEMENTATION DEFINED implemented granule, so the result depends on the implementation, which is the worst kind of bug to find late. Option A is the assumption that causes the bug.
Read more: Arm ARM (DDI0487), TCR_EL1.TG1
Q5.2.2 DRAM sits at PA 0x80_0000_0000 (bit 39 set). With TCR_EL1.IPS = 0b001 (36 bits), the first access after enabling the MMU faults. Which DFSC class do you expect, and why?
- A. Translation fault level 0, because the VA is out of range
- B. Permission fault, because the walk was Non-cacheable
- C. Translation fault at the level of the first invalid descriptor
- D. Address size fault, because the TTBR base or a descriptor’s output address exceeds the 36-bit output size
Answer
D. Output addresses (including TTBR and table addresses) are checked against IPS. Bits above it that are non-zero give an Address size fault. Option A is tempting because “level 0” is common at MMU enable, but it concerns the input range (T0SZ), not the output range.
Read more: Arm ARM (DDI0487), “Address size configuration”, TCR_EL1.IPS
Q5.2.3 Linux enables FEAT_S1PIE on a platform whose EL3 firmware does not set SCR_EL3.TCR2En. What happens when the kernel executes MSR TCR2_EL1, x0?
- A. The access traps to EL3 (or is UNDEFINED), and the
TCR2_EL1fields are treated as 0 regardless - B. The write succeeds, and PIE is enabled at EL1 but not at EL0
- C. The write is ignored silently, so
MRSreads back 0 - D. PIE is enabled, but POE is not
Answer
A. With SCR_EL3.TCR2En == 0, lower-EL accesses to TCR2_EL1 trap to EL3 or are UNDEFINED, and the register’s fields are treated as zero for all purposes. Option C describes a write-ignore, which is not what the architecture specifies. It is the “silent failure” that people expect from RAZ/WI controls.
Read more: Arm ARM (DDI0487), TCR2_EL1, SCR_EL3.TCR2En, HCRX_EL2.TCR2En