arch/x86/kvm/i8254.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/i8254.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/i8254.c- Extension
.c- Size
- 21033 bytes
- Lines
- 817
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kvm_host.hlinux/slab.hioapic.hirq.hi8254.hx86.h
Detected Declarations
function Copyrightfunction pit_get_gatefunction __kpit_elapsedfunction kpit_elapsedfunction pit_get_countfunction pit_get_outfunction pit_latch_countfunction pit_latch_statusfunction kvm_pit_ack_irqfunction __kvm_migrate_pit_timerfunction destroy_pit_timerfunction pit_do_workfunction pit_timer_fnfunction kvm_pit_reset_reinjectfunction kvm_pit_set_reinjectfunction create_pit_timerfunction pit_load_countfunction kvm_pit_load_countfunction pit_in_rangefunction pit_ioport_writefunction pit_ioport_readfunction speaker_ioport_writefunction speaker_ioport_readfunction kvm_pit_resetfunction pit_mask_notifierfunction kvm_vm_ioctl_get_pitfunction kvm_vm_ioctl_set_pitfunction kvm_vm_ioctl_get_pit2function kvm_vm_ioctl_set_pit2function kvm_vm_ioctl_reinjectfunction kvm_free_pit
Annotated Snippet
if (ps->period < min_period) {
pr_info_ratelimited(
"requested %lld ns "
"i8254 timer period limited to %lld ns\n",
ps->period, min_period);
ps->period = min_period;
}
}
hrtimer_start(&ps->timer, ktime_add_ns(ktime_get(), interval),
HRTIMER_MODE_ABS);
}
static void pit_load_count(struct kvm_pit *pit, int channel, u32 val)
{
struct kvm_kpit_state *ps = &pit->pit_state;
pr_debug("load_count val is %u, channel is %d\n", val, channel);
/*
* The largest possible initial count is 0; this is equivalent
* to 216 for binary counting and 104 for BCD counting.
*/
if (val == 0)
val = 0x10000;
ps->channels[channel].count = val;
if (channel != 0) {
ps->channels[channel].count_load_time = ktime_get();
return;
}
/* Two types of timer
* mode 1 is one shot, mode 2 is period, otherwise del timer */
switch (ps->channels[0].mode) {
case 0:
case 1:
/* FIXME: enhance mode 4 precision */
case 4:
create_pit_timer(pit, val, 0);
break;
case 2:
case 3:
create_pit_timer(pit, val, 1);
break;
default:
destroy_pit_timer(pit);
}
}
static void kvm_pit_load_count(struct kvm_pit *pit, int channel, u32 val,
int hpet_legacy_start)
{
u8 saved_mode;
WARN_ON_ONCE(!mutex_is_locked(&pit->pit_state.lock));
if (hpet_legacy_start) {
/* save existing mode for later reenablement */
WARN_ON(channel != 0);
saved_mode = pit->pit_state.channels[0].mode;
pit->pit_state.channels[0].mode = 0xff; /* disable timer */
pit_load_count(pit, channel, val);
pit->pit_state.channels[0].mode = saved_mode;
} else {
pit_load_count(pit, channel, val);
}
}
static inline struct kvm_pit *dev_to_pit(struct kvm_io_device *dev)
{
return container_of(dev, struct kvm_pit, dev);
}
static inline struct kvm_pit *speaker_to_pit(struct kvm_io_device *dev)
{
return container_of(dev, struct kvm_pit, speaker_dev);
}
static inline int pit_in_range(gpa_t addr)
{
return ((addr >= KVM_PIT_BASE_ADDRESS) &&
(addr < KVM_PIT_BASE_ADDRESS + KVM_PIT_MEM_LENGTH));
}
static int pit_ioport_write(struct kvm_vcpu *vcpu,
struct kvm_io_device *this,
gpa_t addr, int len, const void *data)
{
Annotation
- Immediate include surface: `linux/kvm_host.h`, `linux/slab.h`, `ioapic.h`, `irq.h`, `i8254.h`, `x86.h`.
- Detected declarations: `function Copyright`, `function pit_get_gate`, `function __kpit_elapsed`, `function kpit_elapsed`, `function pit_get_count`, `function pit_get_out`, `function pit_latch_count`, `function pit_latch_status`, `function kvm_pit_ack_irq`, `function __kvm_migrate_pit_timer`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.