8.1 Cache organisation
The Arm ARM does not describe a cache hierarchy. It describes the behaviour of caches as software sees it, and a small set of ID registers. Those registers give software what it needs to write correct maintenance code: line sizes for by-VA loops, the levels to walk for set/way loops, and the levels at which the PoU and PoC lie. This section covers those registers and the guarantees behind them. The points themselves are defined in 8.4.
What the architecture guarantees about cache structure
- Data and unified caches behave as PIPT. Whatever the real indexing scheme, software never sees VA aliasing in data caches: two VAs mapping the same PA with the same attributes always see the same data. Aliasing between attributes is a different problem (see 6.6).
- Instruction caches can have a different policy, reported in
CTR_EL0.L1Ip. They are not required to be coherent with data caches or with memory. That is why code modification needs explicit maintenance (8.6). - Allocation is unpredictable. Any location that is mapped with a cacheable Normal attribute and is accessible under the current translation regime can be allocated into a cache at any time, including speculatively, and without any program-order access to it. It can also be evicted at any time. Every DMA and power-down rule in 8.7 and 8.8 follows from this.
- Cache sizes and line counts are not architectural. The ID registers below say how to manage the caches, not how big they really are. Recent DDI0487 issues say explicitly that
CCSIDR_EL1is intended for set/way management and need not describe the physical cache. Some implementations report a reduced or synthetic geometry.
CTR_EL0: the by-VA maintenance parameters
CTR_EL0 is the register that by-VA CMO loops depend on. EL0 can read it when SCTLR_EL1.UCT == 1. It is trapped to EL2 by HCR_EL2.TID2, and with FEAT_FGT also by a fine-grained trap.
| Field | Bits | Meaning |
|---|---|---|
IminLine | [3:0] | log2(words) of the smallest I-cache line of all instruction caches controlled by the PE |
L1Ip | [15:14] | L1 instruction cache policy (see below) |
DminLine | [19:16] | log2(words) of the smallest data/unified cache line of all levels controlled by the PE |
ERG | [23:20] | Exclusives Reservation Granule, log2(words). 0 means “not reported”: assume 512 words (2 KB) |
CWG | [27:24] | Cache Writeback Granule, log2(words). 0 means “not reported”: assume 2 KB, or derive it from the largest CCSIDR_EL1.LineSize |
IDC | [28] | D-cache clean to PoU is not required for I/D coherence (8.6) |
DIC | [29] | I-cache invalidation to PoU is not required for I/D coherence (8.6) |
TminLine | [37:32] | FEAT_MTE2: log2(tag granules) of the smallest tag-cache line |
A “word” is 4 bytes, so the line size in bytes is 4 << DminLine. A value of 4 means 64 bytes.
mrs x1, ctr_el0
ubfx x1, x1, #16, #4 // DminLine
mov x2, #4
lsl x2, x2, x1 // x2 = D-cache line size in bytes (stride for DC by VA)
sub x3, x2, #1
bic x0, x0, x3 // align start address down to a line
DminLine is the minimum across levels because a loop with a smaller stride is always correct: it just issues some redundant operations. A stride larger than the smallest line would skip lines.
CWG is the granule of memory that a cache writeback may overwrite when one modified line is evicted. It is the number that matters for DMA buffer alignment (8.7). If a buffer the device writes shares a CWG-sized block with CPU-written data, an eviction of the CPU’s dirty data can overwrite what the device wrote. ERG bounds the region an exclusive monitor may track (10.1). Two lock words inside one ERG can clear each other’s reservations.
Bring-up note: on heterogeneous systems (big.LITTLE, DynamIQ with mixed cores)
CTR_EL0can differ between cores. Code that reads it once on the boot core and caches the stride is wrong if another core has a smaller line. Linux computes a system-wide “safe” value (the minimumDminLine/IminLine,IDC/DIConly if every core has them). If cores disagree, it clearsSCTLR_EL1.UCTand emulates EL0 reads. TF-A readsCTR_EL0on every call to its cache helpers, which avoids the problem.
L1Ip: instruction cache policy
L1Ip | Policy | Status |
|---|---|---|
0b00 | VPIPT (VMID-aware PIPT) | Added in a later Armv8 issue of DDI0487 (no FEAT_ name). Since removed from the architecture (now reserved). No implementation is known, and Linux dropped support in 2023 |
0b01 | AIVIVT (ASID-tagged VIVT) | Listed in early DDI0487 issues; now reserved, and no Armv8 implementation used it |
0b10 | VIPT | Permitted |
0b11 | PIPT | Permitted |
With PIPT, an IC IVAU by any VA that maps the PA invalidates the line. With VIPT, the index can contain VA bits above the page offset when a way is larger than the page size. The same PA can then sit in the I-cache under different index bits for different VAs, and maintenance by one VA is not a reliable way to remove entries created through another alias. This is why Linux falls back to IC IALLU/IC IALLUIS when it makes a new user page executable on a VIPT I-cache. VPIPT was PIPT with VMID-tagged entries, where IC maintenance at EL1 affected only the current VMID. Hypervisors had to invalidate on VMID reuse. Code that still checks for 0b00 should treat it as reserved.
CLIDR_EL1: which levels exist, and where the PoU and PoC lie
| Field | Bits | Meaning |
|---|---|---|
Ctype1–Ctype7 | [20:0], 3 bits each | 0b000 none, 0b001 I only, 0b010 D only, 0b011 separate I and D, 0b100 unified |
LoUIS | [23:21] | Level of Unification, Inner Shareable |
LoC | [26:24] | Level of Coherence |
LoUU | [29:27] | Level of Unification, Uniprocessor |
ICB | [32:30] | Inner cache boundary: the last level that holds Inner-cacheable attributes (0 = not disclosed) |
Ttype1–Ttype7 | [46:33] | FEAT_MTE2: tag-cache type per level |
The three “Level of” fields are counts. LoC = 3 means that levels 1 and 2 must be cleaned or invalidated to make data coherent at the PoC, and level 3 and beyond need not be. They are the bounds of a set/way loop. LoC = 0 means no cache needs maintenance to reach the PoC. On some systems that is literally true. On others the caches below the PoC are hardware-coherent with every master. A LoUU of 1 on a core whose L1 I- and D-caches are unified at L2 means DC CVAU only needs to push data out of L1D. A LoUU of 0 is possible when the L1 I-cache snoops the D-cache. CTR_EL0.IDC is the by-VA equivalent statement.
The architecture places a level of caching relative to a point, not to physical blocks. A DSU L3 or a CMN system-level cache may or may not count as a “level” in CLIDR_EL1. A system cache that lies beyond the PoC is invisible to CLIDR_EL1 (see 8.2). Do not infer the SoC topology from CLIDR_EL1.
CSSELR_EL1 and CCSIDR_EL1: per-level geometry
To read the geometry of one cache, select it with CSSELR_EL1 and read CCSIDR_EL1. The select is a system-register write whose effect on a later MRS is only guaranteed after an ISB (7.8).
// x0 = level (0-based) ; select data/unified cache at that level
lsl x1, x0, #1 // CSSELR_EL1.Level is bits [3:1]; InD [0] = 0
msr csselr_el1, x1
isb // CSSELR write must be synchronized before reading CCSIDR
mrs x2, ccsidr_el1
CSSELR_EL1 fields: InD [0] (1 = instruction cache), Level [3:1], and TnD [4] (FEAT_MTE2: separate allocation-tag cache).
CCSIDR_EL1 has two layouts, chosen by ID_AA64MMFR2_EL1.CCIDX (FEAT_CCIDX, OPTIONAL from v8.2):
| Field | Without FEAT_CCIDX (32-bit) | With FEAT_CCIDX (64-bit) |
|---|---|---|
LineSize = log2(bytes) − 4 | [2:0] | [2:0] |
Associativity = ways − 1 | [12:3] | [23:3] |
NumSets = sets − 1 | [27:13] | [55:32] |
In AArch32 the wider NumSets does not fit, so FEAT_CCIDX adds CCSIDR2 (and the AArch64 CCSIDR2_EL1), which holds NumSets separately. Code that hard-codes the 32-bit layout reads garbage on a FEAT_CCIDX core. A set/way loop that uses those values can then miss most of the cache. TF-A and Linux both check CCIDX before decoding.
LineSize here is the real line length for that level, used as the set index shift in set/way operands (8.5). It is not CTR_EL0.DminLine, which is a minimum across levels. HCR_EL2.TID2 traps CTR_EL0, CCSIDR_EL1, CCSIDR2_EL1, CLIDR_EL1 and CSSELR_EL1. With FEAT_EVT, HCR_EL2.TID4 traps the latter four without CTR_EL0. KVM uses these traps to present a fixed, migratable geometry to guests.
Putting it together
ID register answers used by
----------- ------- -------
CTR_EL0 by-VA stride (DminLine/IminLine), I-policy, DC/IC by VA loops, DMA alignment,
IDC/DIC, CWG, ERG JIT, exclusives layout
CLIDR_EL1 which levels exist; LoUU/LoUIS/LoC bounds of set/way loops
CSSELR_EL1 + sets, ways, line length of one level set/way operand encoding
CCSIDR_EL1
Validation note: silicon validation should check that the ID registers agree with the RTL configuration and with each other. Check that
CTR_EL0.DminLineis not larger than the smallestCCSIDR_EL1.LineSize, thatLoC/LoUU/LoUISmatch the documented hierarchy, and thatIDC/DICare set only when the coherence they promise is real. Test the last one by writing an instruction through the D-side, skipping the operationsIDC/DICsay are unnecessary, and executing it in a loop, as in 8.10. A wrongDIC = 1shows up as stale-instruction execution that only appears under cache pressure.
Checkpoint
Q8.1.1 A boot-time routine on a big.LITTLE system reads CTR_EL0 on the boot core (DminLine = 4) and stores the 64-byte stride in a global variable. A secondary core of the other type has a 32-byte L1D line. What is the consequence for DC CIVAC loops run on that secondary core?
- A. None, because
DC CIVACoperates on whole cache lines of whatever size the executing core has - B. None, because
DminLineis defined as the system-wide minimum - C. Every other 32-byte line of the range may be left unmaintained on that core, so dirty data can survive the “clean”
- D. The loop faults with an alignment fault because the addresses are not 32-byte aligned
Answer
C. DminLine is the minimum over the caches controlled by that PE, not over the system. A 64-byte stride on a core with 32-byte lines maintains only the line containing each address it issues, so alternate lines are skipped. A is the tempting option: each operation does maintain a whole line, but only the line that contains its address. DC by VA operations are not alignment-checked, so D is wrong.
Read more: Arm ARM (DDI0487), CTR_EL0 (DminLine); Linux arm64 read_sanitised_ftr_reg(SYS_CTR_EL0)
Q8.1.2 On a core with FEAT_CCIDX, legacy firmware decodes CCSIDR_EL1 as NumSets = bits[27:13], Associativity = bits[12:3]. What is the most likely visible result?
- A. Its set/way clean loop issues the wrong set and way counts, so dirty lines stay in the cache and the data is lost at power-down
- B. Nothing, because FEAT_CCIDX only changes the AArch32 view
- C. An UNDEFINED exception when
CCSIDR_EL1is read - D. Nothing on single-cluster systems, because
CCSIDR_EL1is only consulted for L3
Answer
A. With FEAT_CCIDX, CCSIDR_EL1 is 64-bit: Associativity is [23:3] and NumSets is [55:32]. Decoding the old layout yields nonsense counts. Usually the counts are too small, so most sets or ways are never cleaned, and the failure only shows up when a power-down drops dirty data. B is wrong: the AArch64 register layout itself changes, and CCSIDR2 exists because AArch32 cannot hold the wider field.
Read more: Arm ARM (DDI0487), CCSIDR_EL1, CCSIDR2_EL1, ID_AA64MMFR2_EL1.CCIDX
Q8.1.3 CLIDR_EL1 reports Ctype1 = 0b011, Ctype2 = 0b100, LoUU = 1, LoC = 2. The SoC also has a 16 MB system-level cache in the interconnect. What can you conclude?
- A. The system cache is a third level that
CLIDR_EL1failed to report, which is an erratum - B. To publish new code to instruction fetch on this PE, both L1 and L2 must be cleaned
- C. A set/way loop must cover levels 1, 2 and the system cache to reach the PoC
- D. Only L1 and L2 need maintenance to reach the PoC, and the system cache sits beyond the PoC or is otherwise transparent to all observers
Answer
D. LoC = 2 means levels 1 and 2 are the only ones that need maintenance to reach the PoC. A system cache beyond the PoC (or one every master goes through coherently) is architecturally invisible and needs no CPU maintenance. LoUU = 1 means only L1 needs cleaning for I/D unification, so B is wrong. A is the tempting option, but CLIDR_EL1 reports the levels that matter for maintenance, not every SRAM in the SoC.
Read more: Arm ARM (DDI0487), CLIDR_EL1 (LoC, LoUU, Ctypen)