diff --git a/hypervisor/arch/x86/intr_lapic.c b/hypervisor/arch/x86/intr_lapic.c index 3c69d3666..bfd63a6ce 100644 --- a/hypervisor/arch/x86/intr_lapic.c +++ b/hypervisor/arch/x86/intr_lapic.c @@ -166,15 +166,19 @@ struct lapic_info { static struct lapic_info lapic_info; -static uint32_t read_lapic_reg32(uint32_t offset) +static inline uint32_t read_lapic_reg32(uint32_t offset) { - ASSERT((offset >= 0x020) && (offset <= 0x3FF), ""); + if (offset < 0x20 || offset > 0x3ff) + return 0; + return mmio_read_long(lapic_info.xapic.vaddr + offset); } -static void write_lapic_reg32(uint32_t offset, uint32_t value) +inline void write_lapic_reg32(uint32_t offset, uint32_t value) { - ASSERT((offset >= 0x020) && (offset <= 0x3FF), ""); + if (offset < 0x20 || offset > 0x3ff) + return; + mmio_write_long(value, lapic_info.xapic.vaddr + offset); } diff --git a/hypervisor/arch/x86/timer.c b/hypervisor/arch/x86/timer.c index 733a82079..da06bd03f 100644 --- a/hypervisor/arch/x86/timer.c +++ b/hypervisor/arch/x86/timer.c @@ -174,16 +174,17 @@ _search_nearest_timer(struct per_cpu_timers *cpu_timer) static struct timer* _search_timer_by_handle(struct per_cpu_timers *cpu_timer, long handle) { - struct timer *timer; + struct timer *timer = NULL, *tmp; struct list_head *pos; list_for_each(pos, &cpu_timer->timer_list) { - timer = list_entry(pos, struct timer, node); - if (timer->handle == handle) - goto FOUND; + tmp = list_entry(pos, struct timer, node); + if (tmp->handle == handle) { + timer = tmp; + break; + } } - timer = NULL; -FOUND: + return timer; } @@ -296,9 +297,10 @@ static void init_tsc_deadline_timer(void) uint32_t val; val = VECTOR_TIMER; - val |= 0x40000; /* TSC deadline and unmask */ - mmio_write_long(val, LAPIC_BASE + LAPIC_LVT_TIMER_REGISTER); + val |= APIC_LVTT_TM_TSCDLT; /* TSC deadline and unmask */ + write_lapic_reg32(LAPIC_LVT_TIMER_REGISTER, val); asm volatile("mfence" : : : "memory"); + /* disarm timer */ msr_write(MSR_IA32_TSC_DEADLINE, 0UL); } diff --git a/hypervisor/include/arch/x86/lapic.h b/hypervisor/include/arch/x86/lapic.h index 9f955b5e5..f5d232489 100644 --- a/hypervisor/include/arch/x86/lapic.h +++ b/hypervisor/include/arch/x86/lapic.h @@ -179,6 +179,7 @@ struct lapic_regs { uint32_t tdcr; }; +void write_lapic_reg32(uint32_t offset, uint32_t value); void save_lapic(struct lapic_regs *regs); int early_init_lapic(void); int init_lapic(uint32_t cpu_id);