Commit 8be5453f authored by Zhang Xiantao's avatar Zhang Xiantao Committed by Avi Kivity

KVM: Replace kvm_lapic with kvm_vcpu in ioapic/lapic interface

This patch replaces lapic structure with kvm_vcpu in ioapic.c, making ioapic
independent of the local apic, as required by ia64.
Signed-off-by: default avatarZhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 2b5203ee
...@@ -136,7 +136,7 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) ...@@ -136,7 +136,7 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
} }
static void ioapic_inj_irq(struct kvm_ioapic *ioapic, static void ioapic_inj_irq(struct kvm_ioapic *ioapic,
struct kvm_lapic *target, struct kvm_vcpu *vcpu,
u8 vector, u8 trig_mode, u8 delivery_mode) u8 vector, u8 trig_mode, u8 delivery_mode)
{ {
ioapic_debug("irq %d trig %d deliv %d\n", vector, trig_mode, ioapic_debug("irq %d trig %d deliv %d\n", vector, trig_mode,
...@@ -145,7 +145,7 @@ static void ioapic_inj_irq(struct kvm_ioapic *ioapic, ...@@ -145,7 +145,7 @@ static void ioapic_inj_irq(struct kvm_ioapic *ioapic,
ASSERT((delivery_mode == dest_Fixed) || ASSERT((delivery_mode == dest_Fixed) ||
(delivery_mode == dest_LowestPrio)); (delivery_mode == dest_LowestPrio));
kvm_apic_set_irq(target, vector, trig_mode); kvm_apic_set_irq(vcpu, vector, trig_mode);
} }
static u32 ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest, static u32 ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,
...@@ -196,7 +196,6 @@ static void ioapic_deliver(struct kvm_ioapic *ioapic, int irq) ...@@ -196,7 +196,6 @@ static void ioapic_deliver(struct kvm_ioapic *ioapic, int irq)
u8 vector = ioapic->redirtbl[irq].fields.vector; u8 vector = ioapic->redirtbl[irq].fields.vector;
u8 trig_mode = ioapic->redirtbl[irq].fields.trig_mode; u8 trig_mode = ioapic->redirtbl[irq].fields.trig_mode;
u32 deliver_bitmask; u32 deliver_bitmask;
struct kvm_lapic *target;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
int vcpu_id; int vcpu_id;
...@@ -212,13 +211,13 @@ static void ioapic_deliver(struct kvm_ioapic *ioapic, int irq) ...@@ -212,13 +211,13 @@ static void ioapic_deliver(struct kvm_ioapic *ioapic, int irq)
switch (delivery_mode) { switch (delivery_mode) {
case dest_LowestPrio: case dest_LowestPrio:
target = vcpu = kvm_get_lowest_prio_vcpu(ioapic->kvm, vector,
kvm_apic_round_robin(ioapic->kvm, vector, deliver_bitmask); deliver_bitmask);
if (target != NULL) if (vcpu != NULL)
ioapic_inj_irq(ioapic, target, vector, ioapic_inj_irq(ioapic, vcpu, vector,
trig_mode, delivery_mode); trig_mode, delivery_mode);
else else
ioapic_debug("null round robin: " ioapic_debug("null lowest prio vcpu: "
"mask=%x vector=%x delivery_mode=%x\n", "mask=%x vector=%x delivery_mode=%x\n",
deliver_bitmask, vector, dest_LowestPrio); deliver_bitmask, vector, dest_LowestPrio);
break; break;
...@@ -229,8 +228,7 @@ static void ioapic_deliver(struct kvm_ioapic *ioapic, int irq) ...@@ -229,8 +228,7 @@ static void ioapic_deliver(struct kvm_ioapic *ioapic, int irq)
deliver_bitmask &= ~(1 << vcpu_id); deliver_bitmask &= ~(1 << vcpu_id);
vcpu = ioapic->kvm->vcpus[vcpu_id]; vcpu = ioapic->kvm->vcpus[vcpu_id];
if (vcpu) { if (vcpu) {
target = vcpu->apic; ioapic_inj_irq(ioapic, vcpu, vector,
ioapic_inj_irq(ioapic, target, vector,
trig_mode, delivery_mode); trig_mode, delivery_mode);
} }
} }
......
...@@ -145,14 +145,15 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu); ...@@ -145,14 +145,15 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu);
u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu); u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu);
void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8); void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8);
void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value); void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector,
struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector,
unsigned long bitmap); unsigned long bitmap);
u64 kvm_get_apic_base(struct kvm_vcpu *vcpu); u64 kvm_get_apic_base(struct kvm_vcpu *vcpu);
void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data); void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data);
int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
void kvm_ioapic_update_eoi(struct kvm *kvm, int vector); void kvm_ioapic_update_eoi(struct kvm *kvm, int vector);
int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda);
int kvm_apic_set_irq(struct kvm_lapic *apic, u8 vec, u8 trig); int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig);
void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu); void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu);
int kvm_ioapic_init(struct kvm *kvm); int kvm_ioapic_init(struct kvm *kvm);
void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level); void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level);
......
...@@ -185,8 +185,10 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu) ...@@ -185,8 +185,10 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)
} }
EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr); EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr);
int kvm_apic_set_irq(struct kvm_lapic *apic, u8 vec, u8 trig) int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig)
{ {
struct kvm_lapic *apic = vcpu->apic;
if (!apic_test_and_set_irr(vec, apic)) { if (!apic_test_and_set_irr(vec, apic)) {
/* a new pending irq is set in IRR */ /* a new pending irq is set in IRR */
if (trig) if (trig)
...@@ -394,7 +396,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, ...@@ -394,7 +396,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
return result; return result;
} }
struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector, static struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector,
unsigned long bitmap) unsigned long bitmap)
{ {
int last; int last;
...@@ -422,6 +424,17 @@ struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector, ...@@ -422,6 +424,17 @@ struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector,
return apic; return apic;
} }
struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector,
unsigned long bitmap)
{
struct kvm_lapic *apic;
apic = kvm_apic_round_robin(kvm, vector, bitmap);
if (apic)
return apic->vcpu;
return NULL;
}
static void apic_set_eoi(struct kvm_lapic *apic) static void apic_set_eoi(struct kvm_lapic *apic)
{ {
int vector = apic_find_highest_isr(apic); int vector = apic_find_highest_isr(apic);
...@@ -453,7 +466,7 @@ static void apic_send_ipi(struct kvm_lapic *apic) ...@@ -453,7 +466,7 @@ static void apic_send_ipi(struct kvm_lapic *apic)
unsigned int delivery_mode = icr_low & APIC_MODE_MASK; unsigned int delivery_mode = icr_low & APIC_MODE_MASK;
unsigned int vector = icr_low & APIC_VECTOR_MASK; unsigned int vector = icr_low & APIC_VECTOR_MASK;
struct kvm_lapic *target; struct kvm_vcpu *target;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
unsigned long lpr_map = 0; unsigned long lpr_map = 0;
int i; int i;
...@@ -480,9 +493,9 @@ static void apic_send_ipi(struct kvm_lapic *apic) ...@@ -480,9 +493,9 @@ static void apic_send_ipi(struct kvm_lapic *apic)
} }
if (delivery_mode == APIC_DM_LOWEST) { if (delivery_mode == APIC_DM_LOWEST) {
target = kvm_apic_round_robin(vcpu->kvm, vector, lpr_map); target = kvm_get_lowest_prio_vcpu(vcpu->kvm, vector, lpr_map);
if (target != NULL) if (target != NULL)
__apic_accept_irq(target, delivery_mode, __apic_accept_irq(target->apic, delivery_mode,
vector, level, trig_mode); vector, level, trig_mode);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment