24 #include <linux/slab.h>
27 #include <asm/msidef.h>
54 inline static bool kvm_is_dm_lowest_prio(
struct kvm_lapic_irq *irq)
71 kvm_is_dm_lowest_prio(irq)) {
87 if (!kvm_is_dm_lowest_prio(irq)) {
113 trace_kvm_msi_set_irq(e->
msi.address_lo, e->
msi.data);
133 if (!irqchip_in_kernel(kvm) || msi->
flags != 0)
156 trace_kvm_set_irq(irq, level, irq_source_id);
164 if (irq < irq_rt->nr_rt_entries)
171 r = irq_set[
i].
set(&irq_set[
i], kvm, irq_source_id, level);
175 ret = r + ((ret < 0) ? 0 : ret);
187 trace_kvm_ack_irq(irqchip, pin);
192 hlist_for_each_entry_rcu(kian, n, &kvm->irq_ack_notifier_list,
194 if (kian->
gsi == gsi)
203 hlist_add_head_rcu(&kian->
link, &kvm->irq_ack_notifier_list);
211 hlist_del_init_rcu(&kian->
link);
218 unsigned long *
bitmap = &kvm->
arch.irq_sources_bitmap;
234 set_bit(irq_source_id, bitmap);
238 return irq_source_id;
249 if (irq_source_id < 0 ||
255 if (!irqchip_in_kernel(kvm))
271 hlist_add_head_rcu(&kimn->
link, &kvm->mask_notifier_list);
279 hlist_del_rcu(&kimn->
link);
294 hlist_for_each_entry_rcu(kimn, n, &kvm->mask_notifier_list,
link)
295 if (kimn->
irq == gsi)
296 kimn->
func(kimn, mask);
304 kfree(kvm->irq_routing);
309 const struct kvm_irq_routing_entry *ue)
322 if (ei->
type == KVM_IRQ_ROUTING_MSI ||
323 ue->
type == KVM_IRQ_ROUTING_MSI ||
324 ue->
u.irqchip.irqchip == ei->irqchip.irqchip)
330 case KVM_IRQ_ROUTING_IRQCHIP:
332 switch (ue->u.irqchip.irqchip) {
334 e->
set = kvm_set_pic_irq;
338 e->
set = kvm_set_pic_irq;
344 e->
set = kvm_set_ioapic_irq;
349 e->
irqchip.irqchip = ue->u.irqchip.irqchip;
353 rt->chip[ue->u.irqchip.irqchip][e->
irqchip.pin] = ue->gsi;
355 case KVM_IRQ_ROUTING_MSI:
357 e->
msi.address_lo = ue->u.msi.address_lo;
358 e->
msi.address_hi = ue->u.msi.address_hi;
359 e->
msi.data = ue->u.msi.data;
365 hlist_add_head(&e->
link, &rt->map[e->
gsi]);
373 const struct kvm_irq_routing_entry *ue,
378 u32 i,
j, nr_rt_entries = 0;
381 for (i = 0; i <
nr; ++
i) {
382 if (ue[i].gsi >= KVM_MAX_IRQ_ROUTES)
384 nr_rt_entries =
max(nr_rt_entries, ue[i].gsi);
389 new = kzalloc(
sizeof(*
new) + (nr_rt_entries *
sizeof(
struct hlist_head))
396 new->rt_entries = (
void *)&new->map[nr_rt_entries];
398 new->nr_rt_entries = nr_rt_entries;
399 for (i = 0; i < 3; i++)
401 new->chip[i][j] = -1;
403 for (i = 0; i <
nr; ++
i) {
407 r = setup_routing_entry(
new, &new->rt_entries[i], ue);
414 old = kvm->irq_routing;
428 #define IOAPIC_ROUTING_ENTRY(irq) \
429 { .gsi = irq, .type = KVM_IRQ_ROUTING_IRQCHIP, \
430 .u.irqchip.irqchip = KVM_IRQCHIP_IOAPIC, .u.irqchip.pin = (irq) }
431 #define ROUTING_ENTRY1(irq) IOAPIC_ROUTING_ENTRY(irq)
434 # define PIC_ROUTING_ENTRY(irq) \
435 { .gsi = irq, .type = KVM_IRQ_ROUTING_IRQCHIP, \
436 .u.irqchip.irqchip = SELECT_PIC(irq), .u.irqchip.pin = (irq) % 8 }
437 # define ROUTING_ENTRY2(irq) \
438 IOAPIC_ROUTING_ENTRY(irq), PIC_ROUTING_ENTRY(irq)
440 # define ROUTING_ENTRY2(irq) \
441 IOAPIC_ROUTING_ENTRY(irq)
444 static const struct kvm_irq_routing_entry default_routing[] = {