Lines Matching refs:ioapic
53 struct kvm_ioapic *ioapic,
57 static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic) in ioapic_read_indirect() argument
61 switch (ioapic->ioregsel) { in ioapic_read_indirect()
69 result = ((ioapic->id & 0xf) << 24); in ioapic_read_indirect()
74 u32 redir_index = (ioapic->ioregsel - 0x10) >> 1; in ioapic_read_indirect()
81 redir_content = ioapic->redirtbl[index].bits; in ioapic_read_indirect()
84 result = (ioapic->ioregsel & 0x1) ? in ioapic_read_indirect()
94 static void rtc_irq_eoi_tracking_reset(struct kvm_ioapic *ioapic) in rtc_irq_eoi_tracking_reset() argument
96 ioapic->rtc_status.pending_eoi = 0; in rtc_irq_eoi_tracking_reset()
97 bitmap_zero(ioapic->rtc_status.dest_map.map, KVM_MAX_VCPU_IDS); in rtc_irq_eoi_tracking_reset()
100 static void kvm_rtc_eoi_tracking_restore_all(struct kvm_ioapic *ioapic);
102 static void rtc_status_pending_eoi_check_valid(struct kvm_ioapic *ioapic) in rtc_status_pending_eoi_check_valid() argument
104 if (WARN_ON(ioapic->rtc_status.pending_eoi < 0)) in rtc_status_pending_eoi_check_valid()
105 kvm_rtc_eoi_tracking_restore_all(ioapic); in rtc_status_pending_eoi_check_valid()
111 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in __rtc_irq_eoi_tracking_restore_one() local
112 struct dest_map *dest_map = &ioapic->rtc_status.dest_map; in __rtc_irq_eoi_tracking_restore_one()
115 e = &ioapic->redirtbl[RTC_GSI]; in __rtc_irq_eoi_tracking_restore_one()
130 ioapic->rtc_status.pending_eoi++; in __rtc_irq_eoi_tracking_restore_one()
133 ioapic->rtc_status.pending_eoi--; in __rtc_irq_eoi_tracking_restore_one()
134 rtc_status_pending_eoi_check_valid(ioapic); in __rtc_irq_eoi_tracking_restore_one()
140 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in kvm_rtc_eoi_tracking_restore_one() local
142 spin_lock(&ioapic->lock); in kvm_rtc_eoi_tracking_restore_one()
144 spin_unlock(&ioapic->lock); in kvm_rtc_eoi_tracking_restore_one()
147 static void kvm_rtc_eoi_tracking_restore_all(struct kvm_ioapic *ioapic) in kvm_rtc_eoi_tracking_restore_all() argument
155 rtc_irq_eoi_tracking_reset(ioapic); in kvm_rtc_eoi_tracking_restore_all()
156 kvm_for_each_vcpu(i, vcpu, ioapic->kvm) in kvm_rtc_eoi_tracking_restore_all()
160 static void rtc_irq_eoi(struct kvm_ioapic *ioapic, struct kvm_vcpu *vcpu, in rtc_irq_eoi() argument
163 struct dest_map *dest_map = &ioapic->rtc_status.dest_map; in rtc_irq_eoi()
169 ioapic->rtc_status.dest_map.map))) { in rtc_irq_eoi()
170 --ioapic->rtc_status.pending_eoi; in rtc_irq_eoi()
171 rtc_status_pending_eoi_check_valid(ioapic); in rtc_irq_eoi()
175 static bool rtc_irq_check_coalesced(struct kvm_ioapic *ioapic) in rtc_irq_check_coalesced() argument
177 if (ioapic->rtc_status.pending_eoi > 0) in rtc_irq_check_coalesced()
183 static void ioapic_lazy_update_eoi(struct kvm_ioapic *ioapic, int irq) in ioapic_lazy_update_eoi() argument
187 union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq]; in ioapic_lazy_update_eoi()
189 kvm_for_each_vcpu(i, vcpu, ioapic->kvm) { in ioapic_lazy_update_eoi()
200 rtc_irq_eoi(ioapic, vcpu, entry->fields.vector); in ioapic_lazy_update_eoi()
205 static int ioapic_set_irq(struct kvm_ioapic *ioapic, unsigned int irq, in ioapic_set_irq() argument
213 entry = ioapic->redirtbl[irq]; in ioapic_set_irq()
217 ioapic->irr &= ~mask; in ioapic_set_irq()
228 if (edge && kvm_apicv_activated(ioapic->kvm)) in ioapic_set_irq()
229 ioapic_lazy_update_eoi(ioapic, irq); in ioapic_set_irq()
243 rtc_irq_check_coalesced(ioapic)) { in ioapic_set_irq()
248 old_irr = ioapic->irr; in ioapic_set_irq()
249 ioapic->irr |= mask; in ioapic_set_irq()
251 ioapic->irr_delivered &= ~mask; in ioapic_set_irq()
252 if (old_irr == ioapic->irr) { in ioapic_set_irq()
258 ret = ioapic_service(ioapic, irq, line_status); in ioapic_set_irq()
265 static void kvm_ioapic_inject_all(struct kvm_ioapic *ioapic, unsigned long irr) in kvm_ioapic_inject_all() argument
269 rtc_irq_eoi_tracking_reset(ioapic); in kvm_ioapic_inject_all()
271 ioapic_set_irq(ioapic, idx, 1, true); in kvm_ioapic_inject_all()
273 kvm_rtc_eoi_tracking_restore_all(ioapic); in kvm_ioapic_inject_all()
279 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in kvm_ioapic_scan_entry() local
280 struct dest_map *dest_map = &ioapic->rtc_status.dest_map; in kvm_ioapic_scan_entry()
284 spin_lock(&ioapic->lock); in kvm_ioapic_scan_entry()
292 e = &ioapic->redirtbl[index]; in kvm_ioapic_scan_entry()
294 kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || in kvm_ioapic_scan_entry()
305 spin_unlock(&ioapic->lock); in kvm_ioapic_scan_entry()
315 static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) in ioapic_write_indirect() argument
323 switch (ioapic->ioregsel) { in ioapic_write_indirect()
329 ioapic->id = (val >> 24) & 0xf; in ioapic_write_indirect()
336 index = (ioapic->ioregsel - 0x10) >> 1; in ioapic_write_indirect()
341 e = &ioapic->redirtbl[index]; in ioapic_write_indirect()
348 if (ioapic->ioregsel & 1) { in ioapic_write_indirect()
369 kvm_fire_mask_notifiers(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index, mask_after); in ioapic_write_indirect()
371 && ioapic->irr & (1 << index)) in ioapic_write_indirect()
372 ioapic_service(ioapic, index, false); in ioapic_write_indirect()
386 kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq, in ioapic_write_indirect()
399 kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq, in ioapic_write_indirect()
402 kvm_make_scan_ioapic_request_mask(ioapic->kvm, in ioapic_write_indirect()
405 kvm_make_scan_ioapic_request(ioapic->kvm); in ioapic_write_indirect()
411 static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status) in ioapic_service() argument
413 union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq]; in ioapic_service()
432 ioapic->irr_delivered |= 1 << irq; in ioapic_service()
441 BUG_ON(ioapic->rtc_status.pending_eoi != 0); in ioapic_service()
442 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, in ioapic_service()
443 &ioapic->rtc_status.dest_map); in ioapic_service()
444 ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret); in ioapic_service()
446 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL); in ioapic_service()
454 int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id, in kvm_ioapic_set_irq() argument
461 spin_lock(&ioapic->lock); in kvm_ioapic_set_irq()
462 irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq], in kvm_ioapic_set_irq()
464 ret = ioapic_set_irq(ioapic, irq, irq_level, line_status); in kvm_ioapic_set_irq()
466 spin_unlock(&ioapic->lock); in kvm_ioapic_set_irq()
471 void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id) in kvm_ioapic_clear_all() argument
475 spin_lock(&ioapic->lock); in kvm_ioapic_clear_all()
477 __clear_bit(irq_source_id, &ioapic->irq_states[i]); in kvm_ioapic_clear_all()
478 spin_unlock(&ioapic->lock); in kvm_ioapic_clear_all()
484 struct kvm_ioapic *ioapic = container_of(work, struct kvm_ioapic, in kvm_ioapic_eoi_inject_work() local
486 spin_lock(&ioapic->lock); in kvm_ioapic_eoi_inject_work()
488 union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[i]; in kvm_ioapic_eoi_inject_work()
493 if (ioapic->irr & (1 << i) && !ent->fields.remote_irr) in kvm_ioapic_eoi_inject_work()
494 ioapic_service(ioapic, i, false); in kvm_ioapic_eoi_inject_work()
496 spin_unlock(&ioapic->lock); in kvm_ioapic_eoi_inject_work()
501 struct kvm_ioapic *ioapic, in kvm_ioapic_update_eoi_one() argument
506 union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[pin]; in kvm_ioapic_update_eoi_one()
516 spin_unlock(&ioapic->lock); in kvm_ioapic_update_eoi_one()
517 kvm_notify_acked_irq(ioapic->kvm, KVM_IRQCHIP_IOAPIC, pin); in kvm_ioapic_update_eoi_one()
518 spin_lock(&ioapic->lock); in kvm_ioapic_update_eoi_one()
526 if (!ent->fields.mask && (ioapic->irr & (1 << pin))) { in kvm_ioapic_update_eoi_one()
527 ++ioapic->irq_eoi[pin]; in kvm_ioapic_update_eoi_one()
528 if (ioapic->irq_eoi[pin] == IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT) { in kvm_ioapic_update_eoi_one()
537 schedule_delayed_work(&ioapic->eoi_inject, HZ / 100); in kvm_ioapic_update_eoi_one()
538 ioapic->irq_eoi[pin] = 0; in kvm_ioapic_update_eoi_one()
541 ioapic_service(ioapic, pin, false); in kvm_ioapic_update_eoi_one()
544 ioapic->irq_eoi[pin] = 0; in kvm_ioapic_update_eoi_one()
551 struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; in kvm_ioapic_update_eoi() local
553 spin_lock(&ioapic->lock); in kvm_ioapic_update_eoi()
554 rtc_irq_eoi(ioapic, vcpu, vector); in kvm_ioapic_update_eoi()
556 union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[i]; in kvm_ioapic_update_eoi()
560 kvm_ioapic_update_eoi_one(vcpu, ioapic, trigger_mode, i); in kvm_ioapic_update_eoi()
562 spin_unlock(&ioapic->lock); in kvm_ioapic_update_eoi()
570 static inline int ioapic_in_range(struct kvm_ioapic *ioapic, gpa_t addr) in ioapic_in_range() argument
572 return ((addr >= ioapic->base_address && in ioapic_in_range()
573 (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); in ioapic_in_range()
579 struct kvm_ioapic *ioapic = to_ioapic(this); in ioapic_mmio_read() local
581 if (!ioapic_in_range(ioapic, addr)) in ioapic_mmio_read()
587 spin_lock(&ioapic->lock); in ioapic_mmio_read()
590 result = ioapic->ioregsel; in ioapic_mmio_read()
594 result = ioapic_read_indirect(ioapic); in ioapic_mmio_read()
601 spin_unlock(&ioapic->lock); in ioapic_mmio_read()
621 struct kvm_ioapic *ioapic = to_ioapic(this); in ioapic_mmio_write() local
623 if (!ioapic_in_range(ioapic, addr)) in ioapic_mmio_write()
645 spin_lock(&ioapic->lock); in ioapic_mmio_write()
648 ioapic->ioregsel = data & 0xFF; /* 8-bit register */ in ioapic_mmio_write()
652 ioapic_write_indirect(ioapic, data); in ioapic_mmio_write()
658 spin_unlock(&ioapic->lock); in ioapic_mmio_write()
662 static void kvm_ioapic_reset(struct kvm_ioapic *ioapic) in kvm_ioapic_reset() argument
666 cancel_delayed_work_sync(&ioapic->eoi_inject); in kvm_ioapic_reset()
668 ioapic->redirtbl[i].fields.mask = 1; in kvm_ioapic_reset()
669 ioapic->base_address = IOAPIC_DEFAULT_BASE_ADDRESS; in kvm_ioapic_reset()
670 ioapic->ioregsel = 0; in kvm_ioapic_reset()
671 ioapic->irr = 0; in kvm_ioapic_reset()
672 ioapic->irr_delivered = 0; in kvm_ioapic_reset()
673 ioapic->id = 0; in kvm_ioapic_reset()
674 memset(ioapic->irq_eoi, 0x00, sizeof(ioapic->irq_eoi)); in kvm_ioapic_reset()
675 rtc_irq_eoi_tracking_reset(ioapic); in kvm_ioapic_reset()
685 struct kvm_ioapic *ioapic; in kvm_ioapic_init() local
688 ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL_ACCOUNT); in kvm_ioapic_init()
689 if (!ioapic) in kvm_ioapic_init()
691 spin_lock_init(&ioapic->lock); in kvm_ioapic_init()
692 INIT_DELAYED_WORK(&ioapic->eoi_inject, kvm_ioapic_eoi_inject_work); in kvm_ioapic_init()
693 kvm->arch.vioapic = ioapic; in kvm_ioapic_init()
694 kvm_ioapic_reset(ioapic); in kvm_ioapic_init()
695 kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); in kvm_ioapic_init()
696 ioapic->kvm = kvm; in kvm_ioapic_init()
698 ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, ioapic->base_address, in kvm_ioapic_init()
699 IOAPIC_MEM_LENGTH, &ioapic->dev); in kvm_ioapic_init()
703 kfree(ioapic); in kvm_ioapic_init()
711 struct kvm_ioapic *ioapic = kvm->arch.vioapic; in kvm_ioapic_destroy() local
713 if (!ioapic) in kvm_ioapic_destroy()
716 cancel_delayed_work_sync(&ioapic->eoi_inject); in kvm_ioapic_destroy()
718 kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &ioapic->dev); in kvm_ioapic_destroy()
721 kfree(ioapic); in kvm_ioapic_destroy()
726 struct kvm_ioapic *ioapic = kvm->arch.vioapic; in kvm_get_ioapic() local
728 spin_lock(&ioapic->lock); in kvm_get_ioapic()
729 memcpy(state, ioapic, sizeof(struct kvm_ioapic_state)); in kvm_get_ioapic()
730 state->irr &= ~ioapic->irr_delivered; in kvm_get_ioapic()
731 spin_unlock(&ioapic->lock); in kvm_get_ioapic()
736 struct kvm_ioapic *ioapic = kvm->arch.vioapic; in kvm_set_ioapic() local
738 spin_lock(&ioapic->lock); in kvm_set_ioapic()
739 memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); in kvm_set_ioapic()
740 ioapic->irr = 0; in kvm_set_ioapic()
741 ioapic->irr_delivered = 0; in kvm_set_ioapic()
743 kvm_ioapic_inject_all(ioapic, state->irr); in kvm_set_ioapic()
744 spin_unlock(&ioapic->lock); in kvm_set_ioapic()