Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

7.9 Device memory ordering

6.2 defines the Device types and the G/R/E attributes. This section covers what those attributes do for ordering, what they do not do, and the bring-up question that matters most: when can software assume a peripheral has acted on a write?

What Device-nR orders, and what it leaves alone

The Non-Reordering attribute gives a guarantee that Normal memory never gets: for Device-nR memory, accesses to the same peripheral arrive at that peripheral in program order. This is an arrival-order guarantee at the endpoint, which is stronger than the observability order a DMB provides. The size of “the same peripheral” (the block over which nR applies) is IMPLEMENTATION DEFINED. Do not assume it covers two different IP blocks that happen to sit in adjacent 4 KB pages.

Both types used for MMIO in practice, Device-nGnRnE and Device-nGnRE, are nR. Program-ordered STRs to one UART or one timer frame therefore arrive in order with no barrier. Everything else needs an explicit barrier:

Earlier accessLater accessOrdered without a barrier?Barrier that orders it
Device-nR, peripheral PDevice-nR, same Pyes (arrival order)n/a
Device, peripheral PDevice, peripheral QnoDMB OSH (observation); DSB if Q’s side effect depends on P’s having happened
Normal (DMA buffer, descriptor)Device (doorbell)noDMB OSHST (or STLR to the doorbell)
Device (status/index read)Normal (buffer read)noDMB OSHLD (or LDAR for the status read)
Device writesystem-register write (ICC_EOIR1_EL1, MSR to a timer)no; a DMB does not order system-register writesDSB
Device writeWFI, power-down, resetnoDSB (7.6)

The domain is OSH for a reason. Device and Normal Non-cacheable memory are always treated as Outer Shareable, whatever SH says (6.4), and a peripheral or DMA master may sit outside the Inner Shareable domain. DMB ISH architecturally orders accesses only with respect to observers in the Inner Shareable domain. On many SoCs it happens to work, which is how the bug survives until a chiplet or an IO-coherent bridge changes the topology. DMB SY is also correct. TF-A and Linux use OSH because it is the minimum that is sufficient.

Acquire/release semantics apply to Device accesses as they do to Normal ones (7.7). STLR to a doorbell is therefore a valid single-instruction replacement for DMB OSHST; STR. It also orders earlier loads, which is stronger than needed but rarely costly. Device locations are never read speculatively and accesses are never repeated or merged beyond what G permits, so the only reordering left to control is between distinct endpoints and memory types.

nGnRnE vs nGnRE in practice

The only difference is E, Early write acknowledgement. It says who may send the write response:

  • nE: the response must come from the endpoint.
  • E: any point on the path may respond, such as an interconnect write buffer or a bridge. On AMBA this roughly corresponds to the transaction being marked bufferable.

E does not change the architectural order in which observers see the writes. It changes completion, and therefore what a DSB waits for. It also changes error attribution. An early responder cannot return the endpoint’s SLVERR/DECERR on that response, so a failing write to an E location surfaces later, if at all, as an asynchronous SError (3.4), far from the faulting STR.

Typical choices:

WhoMappingAttribute (MAIR encoding)
MMU or D-side translation offall data accessesDevice-nGnRnE (6.5)
TF-A MT_DEVICEall MMIODevice-nGnRE (0x04)
Linux ioremap()ordinary MMIODevice-nGnRE
Linux ioremap_np(), PCI config spacenon-posted requirementDevice-nGnRnE (0x00)

Whether nE is honoured end to end is a platform property, not something the PE can enforce. A bridge that converts to a protocol with posted writes, such as a PCIe root port, acknowledges early regardless of the attribute. Some interconnects treat all Device writes as bufferable. On many cores the attribute also affects how many writes may be outstanding at once, which is IMPLEMENTATION DEFINED and visible only as performance.

“Does a DSB ensure the peripheral saw it?”

Answer in layers:

  1. For an nE location: the write reached the endpoint. The Arm ARM states that a DSB executed by the PE that performed a write to a No Early write acknowledgement location completes only after that write has reached its endpoint in the memory system. This assumes the platform honours nE.
  2. For an E location: no. The DSB may complete when an intermediate buffer accepts the write. The write is ordered and will arrive, but it may not have arrived yet.
  3. Even for nE, “reached the endpoint” is not “took effect”. The peripheral may synchronise the write into another clock domain. An interrupt line it deasserts takes cycles to reach the GIC. A reset or clock controller starts a sequence that finishes later. The architecture can say nothing about any of that.

So the robust idioms, in order of strength, are:

  • Read back from the same peripheral. Because of nR, the read arrives at the peripheral after the write. When its data returns, the write has arrived, whatever E says. For PCIe, a read also flushes posted writes on the same path. Then use the read value or a DSB to order anything that follows.
  • Poll the peripheral’s own completion indication, for example GICD_CTLR.RWP, GICR_CTLR.RWP, or a power controller’s status register. Only the peripheral knows when its side effect has finished.
// ISR tail: clear the source, then EOI, without a spurious re-entry
    mov   w1, #IRQ_BIT
    str   w1, [x0, #UART_ICR]       // Device-nGnRE: may be acknowledged early
    ldr   w2, [x0, #UART_RIS]       // read-back, same peripheral, arrives after the clear
    dsb   sy                        // read complete before the system-register write
    msr   icc_eoir1_el1, x3         // EOI (and deactivate, if EOImode == 0)

With only DSB SY and no read-back, the code is architecturally correct for an nE mapping on a platform that honours nE. It is still exposed to rule 3, because the line deassertion may not yet have reached the GIC. That is why drivers add the read-back even when “the DSB should be enough”.

Validation note: Two cheap checks tell you whether the platform honours nE. (1) Time a STR + DSB SY pair to a distant peripheral mapped nGnRnE and then nGnRE, using CNTVCT_EL0 with ISB before each read (4.7), or the PMU cycle counter. If the latency is identical and short for both, something on the path acknowledges early regardless. (2) Write to an unmapped hole behind the same bridge with nGnRnE. On a platform that honours nE, the error arrives close to the STR (an SError right after the DSB, with ESR_ELx.ISS.AET/DFSC per 3.4). An error that arrives much later, or never, means the response was early. In pre-silicon, confirm the bufferable bit (AWCACHE[0] on AXI, or the EWA bit of the CHI MemAttr field) on the bus trace.

Bring-up note: Configuring one block and then starting another is the classic cross-peripheral case. Examples: program a clock divider and then release a reset, or set up an SMMU stream table and then enable a DMA master. nR does not cover two peripherals, and a DMB only orders observation. Use the first block’s completion status, or a read-back followed by DSB SY, before the second write.

Checkpoint

Q7.9.1 A driver writes a DMA descriptor to Normal, Inner Shareable, Write-Back memory that a hardware-coherent DMA engine reads. It then writes the engine’s doorbell, which is mapped Device-nGnRE. Which barrier between the two stores is the minimum sufficient one architecturally?

  • A. None. Device-nR keeps the two stores in order
  • B. DMB ISHST, because the descriptor is Inner Shareable
  • C. DMB OSHST, because the doorbell is Device (treated as Outer Shareable) and the DMA engine may be outside the Inner Shareable domain
  • D. DSB SY, because only completion guarantees the engine sees the descriptor
Answer

C. The order needed is store→store observation by the DMA engine, so a DMB of the ST type is enough, and the domain must include the engine. A is wrong because nR covers only accesses to the same peripheral, not Normal→Device. B often works in practice but is not architecturally sufficient. D works but is stronger than necessary for a coherent master. For a non-coherent master the maintenance itself needs a DSB (8.7).

Read more: Arm ARM (DDI0487), Device memory and Data Memory Barrier; shareability of Device memory

Q7.9.2 A store to a peripheral mapped Device-nGnRnE is followed by DSB SY. What does the architecture guarantee when the DSB completes, assuming the platform honours nE?

  • A. The peripheral has finished acting on the write, including any interrupt line deassertion
  • B. The write has reached its endpoint, but nothing is said about when the peripheral’s side effects finish
  • C. Only that the write is ordered before later Device accesses; completion is never architected for Device memory
  • D. That every other PE has executed a CSE and sees the new peripheral state
Answer

B. For a No Early write acknowledgement location, DSB completion means the write reached the endpoint. What the peripheral then does internally is outside the architecture, which is why read-back and status polling exist. A is the tempting overstatement. C describes a DMB.

Read more: Arm ARM (DDI0487), Early Write Acknowledgement; Data Synchronization Barrier

Q7.9.3 An ISR clears a peripheral’s interrupt status with a store (Device-nGnRE) and then writes ICC_EOIR1_EL1. The interrupt is occasionally re-taken at once. Which change addresses both the architectural gap and the platform gap?

  • A. Insert DMB OSH between the store and the MSR
  • B. Remap the peripheral as Device-nGnRnE, with no other change
  • C. Insert ISB between the store and the MSR
  • D. Read back a register of the same peripheral after the store, then DSB SY, then write ICC_EOIR1_EL1
Answer

D. The read-back relies on nR arrival order to prove that the clear reached the peripheral, regardless of E. The DSB orders that against the system-register write, which a DMB cannot do (A). B on its own still has no barrier against the MSR. C synchronises context, not memory.

Read more: Arm ARM (DDI0487), Device memory attributes (nR, nE); GICv3 (IHI0069), interrupt end of interrupt