Day74 - MMIO Access and Register Operations¶
Date: 2026-06-10
Summary¶
Today I learned how Linux platform drivers access hardware registers through Memory-Mapped I/O (MMIO).
Starting from the Device Tree reg property, I followed the complete resource path:
Device Tree
reg
↓
platform_get_resource()
↓
struct resource
↓
MMIO resource
↓
__iomem pointer
↓
readl() / writel()
I also investigated how Device Tree bus addresses are translated into CPU physical addresses through the ranges property and examined real MMIO resources on Raspberry Pi 5.
In addition, I built a simulated register block to understand register offsets, bit operations, read-modify-write patterns, and Linux register field helpers.
Topics Learned¶
- Memory-Mapped I/O (MMIO)
- Device Tree
regproperty platform_get_resource()IORESOURCE_MEMstruct resource- Device Tree
rangestranslation /proc/iomem__iomemioremap()devm_ioremap_resource()- Register offset model
readl()/writel()BIT()- Read-Modify-Write (RMW)
GENMASK()FIELD_PREP()FIELD_GET()
Experiments¶
Lab1 - MMIO Resource Inspection¶
Created a platform driver that retrieves an MMIO resource from Device Tree using:
Verified:
Lab2 - devm_ioremap_resource()¶
Attempted to map a fake MMIO resource using:
Observed:
Learned that the helper performs both resource ownership checks and MMIO mapping.
Lab3 - Real MMIO Resource Investigation¶
Inspected Raspberry Pi 5 Device Tree nodes:
Verified corresponding entries in:
Lab4 - Device Tree Address Translation¶
Examined:
Verified that Device Tree bus addresses are translated into CPU physical addresses before becoming kernel resources.
Lab5 - __iomem¶
Verified:
Learned that __iomem is an address-space annotation used by kernel tooling rather than a different pointer type.
Lab6 - Register Offset Model¶
Built a fake register map and verified:
Lab7 - Simulated readl() / writel()¶
Implemented helper functions to simulate register access:
Verified register reads and writes using offset-based addressing.
Lab8 - Bit Operations¶
Practiced:
and read-modify-write patterns:
Lab9 - Register Fields¶
Practiced:
for encoding and decoding register fields.
Key Takeaways¶
- Device Tree
regdescribes bus addresses, not necessarily CPU physical addresses. - MMIO resources are represented by
struct resource. devm_ioremap_resource()performs resource ownership checks in addition to mapping.- Linux drivers access registers using:
rather than direct pointer dereferencing.
- Register access is fundamentally:
- Most Linux drivers rely heavily on:
BIT()- Read-Modify-Write
GENMASK()FIELD_PREP()FIELD_GET()
Next Step¶
Day75 - GPIO Controller Architecture
Planned topics:
- GPIO controller structure
- GPIO register blocks
- Direction and data registers
- GPIO lines and numbering
- Relationship between GPIO subsystem and MMIO registers