diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/ia64/kvm/kvm-ia64.c | 33 | ||||
-rw-r--r-- | arch/ia64/kvm/lapic.h | 4 | ||||
-rw-r--r-- | arch/x86/kvm/lapic.c | 59 | ||||
-rw-r--r-- | arch/x86/kvm/lapic.h | 3 |
4 files changed, 38 insertions, 61 deletions
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index 1887a93a2bd5..acf43ec42704 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c | |||
@@ -283,6 +283,18 @@ static int handle_sal_call(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
283 | 283 | ||
284 | } | 284 | } |
285 | 285 | ||
286 | static int __apic_accept_irq(struct kvm_vcpu *vcpu, uint64_t vector) | ||
287 | { | ||
288 | struct vpd *vpd = to_host(vcpu->kvm, vcpu->arch.vpd); | ||
289 | |||
290 | if (!test_and_set_bit(vector, &vpd->irr[0])) { | ||
291 | vcpu->arch.irq_new_pending = 1; | ||
292 | kvm_vcpu_kick(vcpu); | ||
293 | return 1; | ||
294 | } | ||
295 | return 0; | ||
296 | } | ||
297 | |||
286 | /* | 298 | /* |
287 | * offset: address offset to IPI space. | 299 | * offset: address offset to IPI space. |
288 | * value: deliver value. | 300 | * value: deliver value. |
@@ -292,20 +304,20 @@ static void vcpu_deliver_ipi(struct kvm_vcpu *vcpu, uint64_t dm, | |||
292 | { | 304 | { |
293 | switch (dm) { | 305 | switch (dm) { |
294 | case SAPIC_FIXED: | 306 | case SAPIC_FIXED: |
295 | kvm_apic_set_irq(vcpu, vector, dm, 0); | ||
296 | break; | 307 | break; |
297 | case SAPIC_NMI: | 308 | case SAPIC_NMI: |
298 | kvm_apic_set_irq(vcpu, 2, dm, 0); | 309 | vector = 2; |
299 | break; | 310 | break; |
300 | case SAPIC_EXTINT: | 311 | case SAPIC_EXTINT: |
301 | kvm_apic_set_irq(vcpu, 0, dm, 0); | 312 | vector = 0; |
302 | break; | 313 | break; |
303 | case SAPIC_INIT: | 314 | case SAPIC_INIT: |
304 | case SAPIC_PMI: | 315 | case SAPIC_PMI: |
305 | default: | 316 | default: |
306 | printk(KERN_ERR"kvm: Unimplemented Deliver reserved IPI!\n"); | 317 | printk(KERN_ERR"kvm: Unimplemented Deliver reserved IPI!\n"); |
307 | break; | 318 | return; |
308 | } | 319 | } |
320 | __apic_accept_irq(vcpu, vector); | ||
309 | } | 321 | } |
310 | 322 | ||
311 | static struct kvm_vcpu *lid_to_vcpu(struct kvm *kvm, unsigned long id, | 323 | static struct kvm_vcpu *lid_to_vcpu(struct kvm *kvm, unsigned long id, |
@@ -1813,17 +1825,9 @@ void kvm_vcpu_kick(struct kvm_vcpu *vcpu) | |||
1813 | put_cpu(); | 1825 | put_cpu(); |
1814 | } | 1826 | } |
1815 | 1827 | ||
1816 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 dmode, u8 trig) | 1828 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq) |
1817 | { | 1829 | { |
1818 | 1830 | return __apic_accept_irq(vcpu, irq->vector); | |
1819 | struct vpd *vpd = to_host(vcpu->kvm, vcpu->arch.vpd); | ||
1820 | |||
1821 | if (!test_and_set_bit(vec, &vpd->irr[0])) { | ||
1822 | vcpu->arch.irq_new_pending = 1; | ||
1823 | kvm_vcpu_kick(vcpu); | ||
1824 | return 1; | ||
1825 | } | ||
1826 | return 0; | ||
1827 | } | 1831 | } |
1828 | 1832 | ||
1829 | int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest) | 1833 | int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest) |
@@ -1844,6 +1848,7 @@ int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2) | |||
1844 | int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, | 1848 | int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, |
1845 | int short_hand, int dest, int dest_mode) | 1849 | int short_hand, int dest, int dest_mode) |
1846 | { | 1850 | { |
1851 | struct kvm_lapic *target = vcpu->arch.apic; | ||
1847 | return (dest_mode == 0) ? | 1852 | return (dest_mode == 0) ? |
1848 | kvm_apic_match_physical_addr(target, dest) : | 1853 | kvm_apic_match_physical_addr(target, dest) : |
1849 | kvm_apic_match_logical_addr(target, dest); | 1854 | kvm_apic_match_logical_addr(target, dest); |
diff --git a/arch/ia64/kvm/lapic.h b/arch/ia64/kvm/lapic.h index e42109e6ca47..ee541cebcd78 100644 --- a/arch/ia64/kvm/lapic.h +++ b/arch/ia64/kvm/lapic.h | |||
@@ -23,7 +23,7 @@ int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); | |||
23 | int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, | 23 | int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, |
24 | int short_hand, int dest, int dest_mode); | 24 | int short_hand, int dest, int dest_mode); |
25 | int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2); | 25 | int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2); |
26 | bool kvm_apic_present(struct kvm_vcpu *vcpu); | 26 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq); |
27 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 dmode, u8 trig); | 27 | #define kvm_apic_present(x) (true) |
28 | 28 | ||
29 | #endif | 29 | #endif |
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 814466f455d9..dd934d27040f 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c | |||
@@ -199,27 +199,12 @@ EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr); | |||
199 | static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, | 199 | static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, |
200 | int vector, int level, int trig_mode); | 200 | int vector, int level, int trig_mode); |
201 | 201 | ||
202 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 dmode, u8 trig) | 202 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq) |
203 | { | 203 | { |
204 | struct kvm_lapic *apic = vcpu->arch.apic; | 204 | struct kvm_lapic *apic = vcpu->arch.apic; |
205 | int lapic_dmode; | ||
206 | 205 | ||
207 | switch (dmode) { | 206 | return __apic_accept_irq(apic, irq->delivery_mode, irq->vector, |
208 | case IOAPIC_LOWEST_PRIORITY: | 207 | irq->level, irq->trig_mode); |
209 | lapic_dmode = APIC_DM_LOWEST; | ||
210 | break; | ||
211 | case IOAPIC_FIXED: | ||
212 | lapic_dmode = APIC_DM_FIXED; | ||
213 | break; | ||
214 | case IOAPIC_NMI: | ||
215 | lapic_dmode = APIC_DM_NMI; | ||
216 | break; | ||
217 | default: | ||
218 | printk(KERN_DEBUG"Ignoring delivery mode %d\n", dmode); | ||
219 | return 0; | ||
220 | break; | ||
221 | } | ||
222 | return __apic_accept_irq(apic, lapic_dmode, vec, 1, trig); | ||
223 | } | 208 | } |
224 | 209 | ||
225 | static inline int apic_find_highest_isr(struct kvm_lapic *apic) | 210 | static inline int apic_find_highest_isr(struct kvm_lapic *apic) |
@@ -447,36 +432,24 @@ static void apic_send_ipi(struct kvm_lapic *apic) | |||
447 | { | 432 | { |
448 | u32 icr_low = apic_get_reg(apic, APIC_ICR); | 433 | u32 icr_low = apic_get_reg(apic, APIC_ICR); |
449 | u32 icr_high = apic_get_reg(apic, APIC_ICR2); | 434 | u32 icr_high = apic_get_reg(apic, APIC_ICR2); |
435 | struct kvm_lapic_irq irq; | ||
450 | 436 | ||
451 | unsigned int dest = GET_APIC_DEST_FIELD(icr_high); | 437 | irq.vector = icr_low & APIC_VECTOR_MASK; |
452 | unsigned int short_hand = icr_low & APIC_SHORT_MASK; | 438 | irq.delivery_mode = icr_low & APIC_MODE_MASK; |
453 | unsigned int trig_mode = icr_low & APIC_INT_LEVELTRIG; | 439 | irq.dest_mode = icr_low & APIC_DEST_MASK; |
454 | unsigned int level = icr_low & APIC_INT_ASSERT; | 440 | irq.level = icr_low & APIC_INT_ASSERT; |
455 | unsigned int dest_mode = icr_low & APIC_DEST_MASK; | 441 | irq.trig_mode = icr_low & APIC_INT_LEVELTRIG; |
456 | unsigned int delivery_mode = icr_low & APIC_MODE_MASK; | 442 | irq.shorthand = icr_low & APIC_SHORT_MASK; |
457 | unsigned int vector = icr_low & APIC_VECTOR_MASK; | 443 | irq.dest_id = GET_APIC_DEST_FIELD(icr_high); |
458 | |||
459 | DECLARE_BITMAP(deliver_bitmask, KVM_MAX_VCPUS); | ||
460 | int i; | ||
461 | 444 | ||
462 | apic_debug("icr_high 0x%x, icr_low 0x%x, " | 445 | apic_debug("icr_high 0x%x, icr_low 0x%x, " |
463 | "short_hand 0x%x, dest 0x%x, trig_mode 0x%x, level 0x%x, " | 446 | "short_hand 0x%x, dest 0x%x, trig_mode 0x%x, level 0x%x, " |
464 | "dest_mode 0x%x, delivery_mode 0x%x, vector 0x%x\n", | 447 | "dest_mode 0x%x, delivery_mode 0x%x, vector 0x%x\n", |
465 | icr_high, icr_low, short_hand, dest, | 448 | icr_high, icr_low, irq.shorthand, irq.dest, |
466 | trig_mode, level, dest_mode, delivery_mode, vector); | 449 | irq.trig_mode, irq.level, irq.dest_mode, irq.delivery_mode, |
467 | 450 | irq.vector); | |
468 | kvm_get_intr_delivery_bitmask(apic->vcpu->kvm, apic, dest, dest_mode, | 451 | |
469 | delivery_mode == APIC_DM_LOWEST, short_hand, | 452 | kvm_irq_delivery_to_apic(apic->vcpu->kvm, apic, &irq); |
470 | deliver_bitmask); | ||
471 | |||
472 | while ((i = find_first_bit(deliver_bitmask, KVM_MAX_VCPUS)) | ||
473 | < KVM_MAX_VCPUS) { | ||
474 | struct kvm_vcpu *vcpu = apic->vcpu->kvm->vcpus[i]; | ||
475 | __clear_bit(i, deliver_bitmask); | ||
476 | if (vcpu) | ||
477 | __apic_accept_irq(vcpu->arch.apic, delivery_mode, | ||
478 | vector, level, trig_mode); | ||
479 | } | ||
480 | } | 453 | } |
481 | 454 | ||
482 | static u32 apic_get_tmcct(struct kvm_lapic *apic) | 455 | static u32 apic_get_tmcct(struct kvm_lapic *apic) |
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index b66dc14a9698..a587f8349c46 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h | |||
@@ -31,14 +31,13 @@ u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu); | |||
31 | 31 | ||
32 | int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); | 32 | int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); |
33 | int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); | 33 | int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); |
34 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 dmode, u8 trig); | 34 | int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq); |
35 | 35 | ||
36 | u64 kvm_get_apic_base(struct kvm_vcpu *vcpu); | 36 | u64 kvm_get_apic_base(struct kvm_vcpu *vcpu); |
37 | void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data); | 37 | void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data); |
38 | void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu); | 38 | void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu); |
39 | int kvm_lapic_enabled(struct kvm_vcpu *vcpu); | 39 | int kvm_lapic_enabled(struct kvm_vcpu *vcpu); |
40 | bool kvm_apic_present(struct kvm_vcpu *vcpu); | 40 | bool kvm_apic_present(struct kvm_vcpu *vcpu); |
41 | bool kvm_lapic_present(struct kvm_vcpu *vcpu); | ||
42 | int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu); | 41 | int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu); |
43 | 42 | ||
44 | void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr); | 43 | void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr); |