Lines Matching +full:guest +full:- +full:index +full:- +full:bits

7  *    75002 Paris - France
8 * http://www.linux-mandrake.com/
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
62 switch (ioapic->ioregsel) { in ioapic_read_indirect()
64 result = ((((IOAPIC_NUM_PINS - 1) & 0xff) << 16) in ioapic_read_indirect()
70 result = ((ioapic->id & 0xf) << 24); in ioapic_read_indirect()
75 u32 redir_index = (ioapic->ioregsel - 0x10) >> 1; in ioapic_read_indirect()
79 u32 index = array_index_nospec( in ioapic_read_indirect() local
82 redir_content = ioapic->redirtbl[index].bits; in ioapic_read_indirect()
85 result = (ioapic->ioregsel & 0x1) ? in ioapic_read_indirect()
97 ioapic->rtc_status.pending_eoi = 0; in rtc_irq_eoi_tracking_reset()
98 bitmap_zero(ioapic->rtc_status.dest_map.map, KVM_MAX_VCPU_IDS); in rtc_irq_eoi_tracking_reset()
105 if (WARN_ON(ioapic->rtc_status.pending_eoi < 0)) in rtc_status_pending_eoi_check_valid()
112 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in __rtc_irq_eoi_tracking_restore_one()
113 struct dest_map *dest_map = &ioapic->rtc_status.dest_map; in __rtc_irq_eoi_tracking_restore_one()
116 e = &ioapic->redirtbl[RTC_GSI]; in __rtc_irq_eoi_tracking_restore_one()
118 e->fields.dest_id, in __rtc_irq_eoi_tracking_restore_one()
119 kvm_lapic_irq_dest_mode(!!e->fields.dest_mode))) in __rtc_irq_eoi_tracking_restore_one()
122 new_val = kvm_apic_pending_eoi(vcpu, e->fields.vector); in __rtc_irq_eoi_tracking_restore_one()
123 old_val = test_bit(vcpu->vcpu_id, dest_map->map); in __rtc_irq_eoi_tracking_restore_one()
129 __set_bit(vcpu->vcpu_id, dest_map->map); in __rtc_irq_eoi_tracking_restore_one()
130 dest_map->vectors[vcpu->vcpu_id] = e->fields.vector; in __rtc_irq_eoi_tracking_restore_one()
131 ioapic->rtc_status.pending_eoi++; in __rtc_irq_eoi_tracking_restore_one()
133 __clear_bit(vcpu->vcpu_id, dest_map->map); in __rtc_irq_eoi_tracking_restore_one()
134 ioapic->rtc_status.pending_eoi--; in __rtc_irq_eoi_tracking_restore_one()
141 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in kvm_rtc_eoi_tracking_restore_one()
143 spin_lock(&ioapic->lock); in kvm_rtc_eoi_tracking_restore_one()
145 spin_unlock(&ioapic->lock); in kvm_rtc_eoi_tracking_restore_one()
157 kvm_for_each_vcpu(i, vcpu, ioapic->kvm) in kvm_rtc_eoi_tracking_restore_all()
164 struct dest_map *dest_map = &ioapic->rtc_status.dest_map; in rtc_irq_eoi()
167 if (test_bit(vcpu->vcpu_id, dest_map->map) && in rtc_irq_eoi()
168 (vector == dest_map->vectors[vcpu->vcpu_id]) && in rtc_irq_eoi()
169 (test_and_clear_bit(vcpu->vcpu_id, in rtc_irq_eoi()
170 ioapic->rtc_status.dest_map.map))) { in rtc_irq_eoi()
171 --ioapic->rtc_status.pending_eoi; in rtc_irq_eoi()
178 if (ioapic->rtc_status.pending_eoi > 0) in rtc_irq_check_coalesced()
188 union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq]; in ioapic_lazy_update_eoi()
190 kvm_for_each_vcpu(i, vcpu, ioapic->kvm) { in ioapic_lazy_update_eoi()
192 entry->fields.dest_id, in ioapic_lazy_update_eoi()
193 entry->fields.dest_mode) || in ioapic_lazy_update_eoi()
194 kvm_apic_pending_eoi(vcpu, entry->fields.vector)) in ioapic_lazy_update_eoi()
201 rtc_irq_eoi(ioapic, vcpu, entry->fields.vector); in ioapic_lazy_update_eoi()
214 entry = ioapic->redirtbl[irq]; in ioapic_set_irq()
218 ioapic->irr &= ~mask; in ioapic_set_irq()
225 * triggered, in which case the in-kernel IOAPIC will not be able in ioapic_set_irq()
229 if (edge && kvm_apicv_activated(ioapic->kvm)) in ioapic_set_irq()
233 * Return 0 for coalesced interrupts; for edge-triggered interrupts, in ioapic_set_irq()
238 * RTC is special: it is edge-triggered, but userspace likes to know in ioapic_set_irq()
239 * if it has been already ack-ed via EOI because coalesced RTC in ioapic_set_irq()
249 old_irr = ioapic->irr; in ioapic_set_irq()
250 ioapic->irr |= mask; in ioapic_set_irq()
252 ioapic->irr_delivered &= ~mask; in ioapic_set_irq()
253 if (old_irr == ioapic->irr) { in ioapic_set_irq()
262 trace_kvm_ioapic_set_irq(entry.bits, irq, ret == 0); in ioapic_set_irq()
280 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in kvm_ioapic_scan_entry()
281 struct dest_map *dest_map = &ioapic->rtc_status.dest_map; in kvm_ioapic_scan_entry()
283 int index; in kvm_ioapic_scan_entry() local
285 spin_lock(&ioapic->lock); in kvm_ioapic_scan_entry()
288 if (test_bit(vcpu->vcpu_id, dest_map->map)) in kvm_ioapic_scan_entry()
289 __set_bit(dest_map->vectors[vcpu->vcpu_id], in kvm_ioapic_scan_entry()
292 for (index = 0; index < IOAPIC_NUM_PINS; index++) { in kvm_ioapic_scan_entry()
293 e = &ioapic->redirtbl[index]; in kvm_ioapic_scan_entry()
294 if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG || in kvm_ioapic_scan_entry()
295 kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || in kvm_ioapic_scan_entry()
296 index == RTC_GSI) { in kvm_ioapic_scan_entry()
297 u16 dm = kvm_lapic_irq_dest_mode(!!e->fields.dest_mode); in kvm_ioapic_scan_entry()
300 e->fields.dest_id, dm) || in kvm_ioapic_scan_entry()
301 kvm_apic_pending_eoi(vcpu, e->fields.vector)) in kvm_ioapic_scan_entry()
302 __set_bit(e->fields.vector, in kvm_ioapic_scan_entry()
306 spin_unlock(&ioapic->lock); in kvm_ioapic_scan_entry()
318 unsigned index; in ioapic_write_indirect() local
324 switch (ioapic->ioregsel) { in ioapic_write_indirect()
330 ioapic->id = (val >> 24) & 0xf; in ioapic_write_indirect()
337 index = (ioapic->ioregsel - 0x10) >> 1; in ioapic_write_indirect()
339 if (index >= IOAPIC_NUM_PINS) in ioapic_write_indirect()
341 index = array_index_nospec(index, IOAPIC_NUM_PINS); in ioapic_write_indirect()
342 e = &ioapic->redirtbl[index]; in ioapic_write_indirect()
343 mask_before = e->fields.mask; in ioapic_write_indirect()
344 /* Preserve read-only fields */ in ioapic_write_indirect()
345 old_remote_irr = e->fields.remote_irr; in ioapic_write_indirect()
346 old_delivery_status = e->fields.delivery_status; in ioapic_write_indirect()
347 old_dest_id = e->fields.dest_id; in ioapic_write_indirect()
348 old_dest_mode = e->fields.dest_mode; in ioapic_write_indirect()
349 if (ioapic->ioregsel & 1) { in ioapic_write_indirect()
350 e->bits &= 0xffffffff; in ioapic_write_indirect()
351 e->bits |= (u64) val << 32; in ioapic_write_indirect()
353 e->bits &= ~0xffffffffULL; in ioapic_write_indirect()
354 e->bits |= (u32) val; in ioapic_write_indirect()
356 e->fields.remote_irr = old_remote_irr; in ioapic_write_indirect()
357 e->fields.delivery_status = old_delivery_status; in ioapic_write_indirect()
362 * as edge-triggered. This behavior is used to simulate an in ioapic_write_indirect()
365 if (e->fields.trig_mode == IOAPIC_EDGE_TRIG) in ioapic_write_indirect()
366 e->fields.remote_irr = 0; in ioapic_write_indirect()
368 mask_after = e->fields.mask; in ioapic_write_indirect()
370 kvm_fire_mask_notifiers(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index, mask_after); in ioapic_write_indirect()
371 if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG && in ioapic_write_indirect()
372 ioapic->irr & (1 << index) && !e->fields.mask && !e->fields.remote_irr) { in ioapic_write_indirect()
377 * Linux guest as a oneshot interrupt (IRQF_ONESHOT). In this in ioapic_write_indirect()
378 * case the guest acknowledges the interrupt to the device in in ioapic_write_indirect()
382 * cases, injecting this pending interrupt to the guest is in ioapic_write_indirect()
383 * buggy: the guest will receive an extra unwanted interrupt. in ioapic_write_indirect()
389 * is done, without actually injecting it into the guest. If the in ioapic_write_indirect()
392 * through irqfd and injected into the guest. in ioapic_write_indirect()
396 * pending interrupt into the guest, so the guest will not miss in ioapic_write_indirect()
399 if (kvm_notify_irqfd_resampler(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index)) in ioapic_write_indirect()
400 ioapic->irr &= ~(1 << index); in ioapic_write_indirect()
402 ioapic_service(ioapic, index, false); in ioapic_write_indirect()
404 if (e->fields.delivery_mode == APIC_DM_FIXED) { in ioapic_write_indirect()
407 irq.vector = e->fields.vector; in ioapic_write_indirect()
408 irq.delivery_mode = e->fields.delivery_mode << 8; in ioapic_write_indirect()
410 kvm_lapic_irq_dest_mode(!!e->fields.dest_mode); in ioapic_write_indirect()
412 irq.trig_mode = e->fields.trig_mode; in ioapic_write_indirect()
414 irq.dest_id = e->fields.dest_id; in ioapic_write_indirect()
417 kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq, in ioapic_write_indirect()
419 if (old_dest_mode != e->fields.dest_mode || in ioapic_write_indirect()
420 old_dest_id != e->fields.dest_id) { in ioapic_write_indirect()
429 !!e->fields.dest_mode); in ioapic_write_indirect()
430 kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq, in ioapic_write_indirect()
433 kvm_make_scan_ioapic_request_mask(ioapic->kvm, in ioapic_write_indirect()
436 kvm_make_scan_ioapic_request(ioapic->kvm); in ioapic_write_indirect()
444 union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq]; in ioapic_service()
448 if (entry->fields.mask || in ioapic_service()
449 (entry->fields.trig_mode == IOAPIC_LEVEL_TRIG && in ioapic_service()
450 entry->fields.remote_irr)) in ioapic_service()
451 return -1; in ioapic_service()
453 irqe.dest_id = entry->fields.dest_id; in ioapic_service()
454 irqe.vector = entry->fields.vector; in ioapic_service()
455 irqe.dest_mode = kvm_lapic_irq_dest_mode(!!entry->fields.dest_mode); in ioapic_service()
456 irqe.trig_mode = entry->fields.trig_mode; in ioapic_service()
457 irqe.delivery_mode = entry->fields.delivery_mode << 8; in ioapic_service()
463 ioapic->irr_delivered |= 1 << irq; in ioapic_service()
472 BUG_ON(ioapic->rtc_status.pending_eoi != 0); in ioapic_service()
473 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, in ioapic_service()
474 &ioapic->rtc_status.dest_map); in ioapic_service()
475 ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret); in ioapic_service()
477 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL); in ioapic_service()
480 entry->fields.remote_irr = 1; in ioapic_service()
492 spin_lock(&ioapic->lock); in kvm_ioapic_set_irq()
493 irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq], in kvm_ioapic_set_irq()
497 spin_unlock(&ioapic->lock); in kvm_ioapic_set_irq()
506 spin_lock(&ioapic->lock); in kvm_ioapic_clear_all()
508 __clear_bit(irq_source_id, &ioapic->irq_states[i]); in kvm_ioapic_clear_all()
509 spin_unlock(&ioapic->lock); in kvm_ioapic_clear_all()
517 spin_lock(&ioapic->lock); in kvm_ioapic_eoi_inject_work()
519 union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[i]; in kvm_ioapic_eoi_inject_work()
521 if (ent->fields.trig_mode != IOAPIC_LEVEL_TRIG) in kvm_ioapic_eoi_inject_work()
524 if (ioapic->irr & (1 << i) && !ent->fields.remote_irr) in kvm_ioapic_eoi_inject_work()
527 spin_unlock(&ioapic->lock); in kvm_ioapic_eoi_inject_work()
536 struct kvm_lapic *apic = vcpu->arch.apic; in kvm_ioapic_update_eoi_one()
537 union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[pin]; in kvm_ioapic_update_eoi_one()
547 spin_unlock(&ioapic->lock); in kvm_ioapic_update_eoi_one()
548 kvm_notify_acked_irq(ioapic->kvm, KVM_IRQCHIP_IOAPIC, pin); in kvm_ioapic_update_eoi_one()
549 spin_lock(&ioapic->lock); in kvm_ioapic_update_eoi_one()
555 ASSERT(ent->fields.trig_mode == IOAPIC_LEVEL_TRIG); in kvm_ioapic_update_eoi_one()
556 ent->fields.remote_irr = 0; in kvm_ioapic_update_eoi_one()
557 if (!ent->fields.mask && (ioapic->irr & (1 << pin))) { in kvm_ioapic_update_eoi_one()
558 ++ioapic->irq_eoi[pin]; in kvm_ioapic_update_eoi_one()
559 if (ioapic->irq_eoi[pin] == IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT) { in kvm_ioapic_update_eoi_one()
563 * lets a buggy guest make slow progress in kvm_ioapic_update_eoi_one()
565 * level-triggered interrupt. Emulate this in kvm_ioapic_update_eoi_one()
568 schedule_delayed_work(&ioapic->eoi_inject, HZ / 100); in kvm_ioapic_update_eoi_one()
569 ioapic->irq_eoi[pin] = 0; in kvm_ioapic_update_eoi_one()
570 trace_kvm_ioapic_delayed_eoi_inj(ent->bits); in kvm_ioapic_update_eoi_one()
575 ioapic->irq_eoi[pin] = 0; in kvm_ioapic_update_eoi_one()
582 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in kvm_ioapic_update_eoi()
584 spin_lock(&ioapic->lock); in kvm_ioapic_update_eoi()
587 union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[i]; in kvm_ioapic_update_eoi()
589 if (ent->fields.vector != vector) in kvm_ioapic_update_eoi()
593 spin_unlock(&ioapic->lock); in kvm_ioapic_update_eoi()
603 return ((addr >= ioapic->base_address && in ioapic_in_range()
604 (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); in ioapic_in_range()
613 return -EOPNOTSUPP; in ioapic_mmio_read()
618 spin_lock(&ioapic->lock); in ioapic_mmio_read()
621 result = ioapic->ioregsel; in ioapic_mmio_read()
632 spin_unlock(&ioapic->lock); in ioapic_mmio_read()
655 return -EOPNOTSUPP; in ioapic_mmio_write()
676 spin_lock(&ioapic->lock); in ioapic_mmio_write()
679 ioapic->ioregsel = data & 0xFF; /* 8-bit register */ in ioapic_mmio_write()
689 spin_unlock(&ioapic->lock); in ioapic_mmio_write()
697 cancel_delayed_work_sync(&ioapic->eoi_inject); in kvm_ioapic_reset()
699 ioapic->redirtbl[i].fields.mask = 1; in kvm_ioapic_reset()
700 ioapic->base_address = IOAPIC_DEFAULT_BASE_ADDRESS; in kvm_ioapic_reset()
701 ioapic->ioregsel = 0; in kvm_ioapic_reset()
702 ioapic->irr = 0; in kvm_ioapic_reset()
703 ioapic->irr_delivered = 0; in kvm_ioapic_reset()
704 ioapic->id = 0; in kvm_ioapic_reset()
705 memset(ioapic->irq_eoi, 0x00, sizeof(ioapic->irq_eoi)); in kvm_ioapic_reset()
721 return -ENOMEM; in kvm_ioapic_init()
722 spin_lock_init(&ioapic->lock); in kvm_ioapic_init()
723 INIT_DELAYED_WORK(&ioapic->eoi_inject, kvm_ioapic_eoi_inject_work); in kvm_ioapic_init()
724 kvm->arch.vioapic = ioapic; in kvm_ioapic_init()
726 kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); in kvm_ioapic_init()
727 ioapic->kvm = kvm; in kvm_ioapic_init()
728 mutex_lock(&kvm->slots_lock); in kvm_ioapic_init()
729 ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, ioapic->base_address, in kvm_ioapic_init()
730 IOAPIC_MEM_LENGTH, &ioapic->dev); in kvm_ioapic_init()
731 mutex_unlock(&kvm->slots_lock); in kvm_ioapic_init()
733 kvm->arch.vioapic = NULL; in kvm_ioapic_init()
742 struct kvm_ioapic *ioapic = kvm->arch.vioapic; in kvm_ioapic_destroy()
747 cancel_delayed_work_sync(&ioapic->eoi_inject); in kvm_ioapic_destroy()
748 mutex_lock(&kvm->slots_lock); in kvm_ioapic_destroy()
749 kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &ioapic->dev); in kvm_ioapic_destroy()
750 mutex_unlock(&kvm->slots_lock); in kvm_ioapic_destroy()
751 kvm->arch.vioapic = NULL; in kvm_ioapic_destroy()
757 struct kvm_ioapic *ioapic = kvm->arch.vioapic; in kvm_get_ioapic()
759 spin_lock(&ioapic->lock); in kvm_get_ioapic()
761 state->irr &= ~ioapic->irr_delivered; in kvm_get_ioapic()
762 spin_unlock(&ioapic->lock); in kvm_get_ioapic()
767 struct kvm_ioapic *ioapic = kvm->arch.vioapic; in kvm_set_ioapic()
769 spin_lock(&ioapic->lock); in kvm_set_ioapic()
771 ioapic->irr = 0; in kvm_set_ioapic()
772 ioapic->irr_delivered = 0; in kvm_set_ioapic()
774 kvm_ioapic_inject_all(ioapic, state->irr); in kvm_set_ioapic()
775 spin_unlock(&ioapic->lock); in kvm_set_ioapic()