arch/nios2/kernel/time.c
Source file repositories/reference/linux-study-clean/arch/nios2/kernel/time.c
File Facts
- System
- Linux kernel
- Corpus path
arch/nios2/kernel/time.c- Extension
.c- Size
- 8569 bytes
- Lines
- 360
- Domain
- Architecture Layer
- Bucket
- arch/nios2
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/interrupt.hlinux/clockchips.hlinux/clocksource.hlinux/delay.hlinux/of.hlinux/of_address.hlinux/of_irq.hlinux/io.hlinux/slab.h
Detected Declarations
struct nios2_timerstruct nios2_clockevent_devstruct nios2_clocksourcefunction to_nios2_clkeventfunction to_nios2_clksourcefunction timer_readwfunction timer_writewfunction read_timersnapshotfunction nios2_timer_readfunction get_cyclesfunction nios2_timer_startfunction nios2_timer_stopfunction nios2_timer_configfunction nios2_timer_set_next_eventfunction nios2_timer_shutdownfunction nios2_timer_set_periodicfunction nios2_timer_resumefunction timer_interruptfunction nios2_timer_get_base_and_freqfunction nios2_clockevent_initfunction nios2_clocksource_initfunction nios2_time_initfunction read_persistent_clock64function time_initexport get_cycles
Annotated Snippet
struct nios2_timer {
void __iomem *base;
unsigned long freq;
};
struct nios2_clockevent_dev {
struct nios2_timer timer;
struct clock_event_device ced;
};
struct nios2_clocksource {
struct nios2_timer timer;
struct clocksource cs;
};
static inline struct nios2_clockevent_dev *
to_nios2_clkevent(struct clock_event_device *evt)
{
return container_of(evt, struct nios2_clockevent_dev, ced);
}
static inline struct nios2_clocksource *
to_nios2_clksource(struct clocksource *cs)
{
return container_of(cs, struct nios2_clocksource, cs);
}
static u16 timer_readw(struct nios2_timer *timer, u32 offs)
{
return readw(timer->base + offs);
}
static void timer_writew(struct nios2_timer *timer, u16 val, u32 offs)
{
writew(val, timer->base + offs);
}
static inline unsigned long read_timersnapshot(struct nios2_timer *timer)
{
unsigned long count;
timer_writew(timer, 0, ALTERA_TIMER_SNAPL_REG);
count = timer_readw(timer, ALTERA_TIMER_SNAPH_REG) << 16 |
timer_readw(timer, ALTERA_TIMER_SNAPL_REG);
return count;
}
static u64 nios2_timer_read(struct clocksource *cs)
{
struct nios2_clocksource *nios2_cs = to_nios2_clksource(cs);
unsigned long flags;
u32 count;
local_irq_save(flags);
count = read_timersnapshot(&nios2_cs->timer);
local_irq_restore(flags);
/* Counter is counting down */
return ~count;
}
static struct nios2_clocksource nios2_cs = {
.cs = {
.name = "nios2-clksrc",
.rating = 250,
.read = nios2_timer_read,
.mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
},
};
cycles_t get_cycles(void)
{
/* Only read timer if it has been initialized */
if (nios2_cs.timer.base)
return nios2_timer_read(&nios2_cs.cs);
return 0;
}
EXPORT_SYMBOL(get_cycles);
static void nios2_timer_start(struct nios2_timer *timer)
{
u16 ctrl;
ctrl = timer_readw(timer, ALTERA_TIMER_CONTROL_REG);
ctrl |= ALTERA_TIMER_CONTROL_START_MSK;
timer_writew(timer, ctrl, ALTERA_TIMER_CONTROL_REG);
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/interrupt.h`, `linux/clockchips.h`, `linux/clocksource.h`, `linux/delay.h`, `linux/of.h`, `linux/of_address.h`, `linux/of_irq.h`.
- Detected declarations: `struct nios2_timer`, `struct nios2_clockevent_dev`, `struct nios2_clocksource`, `function to_nios2_clkevent`, `function to_nios2_clksource`, `function timer_readw`, `function timer_writew`, `function read_timersnapshot`, `function nios2_timer_read`, `function get_cycles`.
- Atlas domain: Architecture Layer / arch/nios2.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.