drivers/clocksource/mmio.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/mmio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/mmio.c- Extension
.c- Size
- 1980 bytes
- Lines
- 76
- Domain
- Driver Families
- Bucket
- drivers/clocksource
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clocksource.hlinux/errno.hlinux/init.hlinux/slab.h
Detected Declarations
struct clocksource_mmiofunction clocksource_mmio_readl_upfunction clocksource_mmio_readl_downfunction clocksource_mmio_readw_upfunction clocksource_mmio_readw_downfunction clocksource_mmio_initexport clocksource_mmio_readl_upexport clocksource_mmio_readl_downexport clocksource_mmio_readw_upexport clocksource_mmio_readw_downexport clocksource_mmio_init
Annotated Snippet
struct clocksource_mmio {
void __iomem *reg;
struct clocksource clksrc;
};
static inline struct clocksource_mmio *to_mmio_clksrc(struct clocksource *c)
{
return container_of(c, struct clocksource_mmio, clksrc);
}
u64 clocksource_mmio_readl_up(struct clocksource *c)
{
return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
}
EXPORT_SYMBOL_GPL(clocksource_mmio_readl_up);
u64 clocksource_mmio_readl_down(struct clocksource *c)
{
return ~(u64)readl_relaxed(to_mmio_clksrc(c)->reg) & c->mask;
}
EXPORT_SYMBOL_GPL(clocksource_mmio_readl_down);
u64 clocksource_mmio_readw_up(struct clocksource *c)
{
return (u64)readw_relaxed(to_mmio_clksrc(c)->reg);
}
EXPORT_SYMBOL_GPL(clocksource_mmio_readw_up);
u64 clocksource_mmio_readw_down(struct clocksource *c)
{
return ~(u64)readw_relaxed(to_mmio_clksrc(c)->reg) & c->mask;
}
EXPORT_SYMBOL_GPL(clocksource_mmio_readw_down);
/**
* clocksource_mmio_init - Initialize a simple mmio based clocksource
* @base: Virtual address of the clock readout register
* @name: Name of the clocksource
* @hz: Frequency of the clocksource in Hz
* @rating: Rating of the clocksource
* @bits: Number of valid bits
* @read: One of clocksource_mmio_read*() above
*/
int clocksource_mmio_init(void __iomem *base, const char *name,
unsigned long hz, int rating, unsigned bits,
u64 (*read)(struct clocksource *))
{
struct clocksource_mmio *cs;
if (bits > 64 || bits < 16)
return -EINVAL;
cs = kzalloc_obj(struct clocksource_mmio);
if (!cs)
return -ENOMEM;
cs->reg = base;
cs->clksrc.name = name;
cs->clksrc.rating = rating;
cs->clksrc.read = read;
cs->clksrc.mask = CLOCKSOURCE_MASK(bits);
cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
return clocksource_register_hz(&cs->clksrc, hz);
}
EXPORT_SYMBOL_GPL(clocksource_mmio_init);
Annotation
- Immediate include surface: `linux/clocksource.h`, `linux/errno.h`, `linux/init.h`, `linux/slab.h`.
- Detected declarations: `struct clocksource_mmio`, `function clocksource_mmio_readl_up`, `function clocksource_mmio_readl_down`, `function clocksource_mmio_readw_up`, `function clocksource_mmio_readw_down`, `function clocksource_mmio_init`, `export clocksource_mmio_readl_up`, `export clocksource_mmio_readl_down`, `export clocksource_mmio_readw_up`, `export clocksource_mmio_readw_down`.
- Atlas domain: Driver Families / drivers/clocksource.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.