Skip to content

Commit 57152d0

Browse files
lifeixjren1
authored andcommitted
hv: lapic: export write_lapic_reg32
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent 471082c commit 57152d0

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

hypervisor/arch/x86/intr_lapic.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ struct lapic_info {
166166

167167
static struct lapic_info lapic_info;
168168

169-
static uint32_t read_lapic_reg32(uint32_t offset)
169+
static inline uint32_t read_lapic_reg32(uint32_t offset)
170170
{
171-
ASSERT((offset >= 0x020) && (offset <= 0x3FF), "");
171+
if (offset < 0x20 || offset > 0x3ff)
172+
return 0;
173+
172174
return mmio_read_long(lapic_info.xapic.vaddr + offset);
173175
}
174176

175-
static void write_lapic_reg32(uint32_t offset, uint32_t value)
177+
inline void write_lapic_reg32(uint32_t offset, uint32_t value)
176178
{
177-
ASSERT((offset >= 0x020) && (offset <= 0x3FF), "");
179+
if (offset < 0x20 || offset > 0x3ff)
180+
return;
181+
178182
mmio_write_long(value, lapic_info.xapic.vaddr + offset);
179183
}
180184

hypervisor/arch/x86/timer.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,17 @@ _search_nearest_timer(struct per_cpu_timers *cpu_timer)
174174
static struct timer*
175175
_search_timer_by_handle(struct per_cpu_timers *cpu_timer, long handle)
176176
{
177-
struct timer *timer;
177+
struct timer *timer = NULL, *tmp;
178178
struct list_head *pos;
179179

180180
list_for_each(pos, &cpu_timer->timer_list) {
181-
timer = list_entry(pos, struct timer, node);
182-
if (timer->handle == handle)
183-
goto FOUND;
181+
tmp = list_entry(pos, struct timer, node);
182+
if (tmp->handle == handle) {
183+
timer = tmp;
184+
break;
185+
}
184186
}
185-
timer = NULL;
186-
FOUND:
187+
187188
return timer;
188189
}
189190

@@ -296,9 +297,10 @@ static void init_tsc_deadline_timer(void)
296297
uint32_t val;
297298

298299
val = VECTOR_TIMER;
299-
val |= 0x40000; /* TSC deadline and unmask */
300-
mmio_write_long(val, LAPIC_BASE + LAPIC_LVT_TIMER_REGISTER);
300+
val |= APIC_LVTT_TM_TSCDLT; /* TSC deadline and unmask */
301+
write_lapic_reg32(LAPIC_LVT_TIMER_REGISTER, val);
301302
asm volatile("mfence" : : : "memory");
303+
302304
/* disarm timer */
303305
msr_write(MSR_IA32_TSC_DEADLINE, 0UL);
304306
}

hypervisor/include/arch/x86/lapic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct lapic_regs {
179179
uint32_t tdcr;
180180
};
181181

182+
void write_lapic_reg32(uint32_t offset, uint32_t value);
182183
void save_lapic(struct lapic_regs *regs);
183184
int early_init_lapic(void);
184185
int init_lapic(uint32_t cpu_id);

0 commit comments

Comments
 (0)