1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * irq.h: in kernel interrupt controller related definitions
4 * Copyright (c) 2007, Intel Corporation.
7 * Yaozu (Eddie) Dong <Eddie.dong@intel.com>
13 #include <linux/mm_types.h>
14 #include <linux/hrtimer.h>
15 #include <linux/kvm_host.h>
16 #include <linux/spinlock.h>
18 #include <kvm/iodev.h>
21 #define PIC_NUM_PINS 16
22 #define SELECT_PIC(irq) \
23 ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)
28 struct kvm_kpic_state
{
29 u8 last_irr
; /* edge detection */
30 u8 irr
; /* interrupt request register */
31 u8 imr
; /* interrupt mask register */
32 u8 isr
; /* interrupt service register */
33 u8 priority_add
; /* highest irq priority */
40 u8 rotate_on_auto_eoi
;
41 u8 special_fully_nested_mode
;
42 u8 init4
; /* true if 4 byte init */
43 u8 elcr
; /* PIIX edge/trigger selection */
45 u8 isr_ack
; /* interrupt ack detection */
46 struct kvm_pic
*pics_state
;
52 unsigned pending_acks
;
54 struct kvm_kpic_state pics
[2]; /* 0 is master pic, 1 is slave pic */
55 int output
; /* intr from master PIC */
56 struct kvm_io_device dev_master
;
57 struct kvm_io_device dev_slave
;
58 struct kvm_io_device dev_elcr
;
59 unsigned long irq_states
[PIC_NUM_PINS
];
62 int kvm_pic_init(struct kvm
*kvm
);
63 void kvm_pic_destroy(struct kvm
*kvm
);
64 int kvm_pic_read_irq(struct kvm
*kvm
);
65 void kvm_pic_update_irq(struct kvm_pic
*s
);
67 static inline int irqchip_split(struct kvm
*kvm
)
69 int mode
= kvm
->arch
.irqchip_mode
;
71 /* Matches smp_wmb() when setting irqchip_mode */
73 return mode
== KVM_IRQCHIP_SPLIT
;
76 static inline int irqchip_kernel(struct kvm
*kvm
)
78 int mode
= kvm
->arch
.irqchip_mode
;
80 /* Matches smp_wmb() when setting irqchip_mode */
82 return mode
== KVM_IRQCHIP_KERNEL
;
85 static inline int pic_in_kernel(struct kvm
*kvm
)
87 return irqchip_kernel(kvm
);
90 static inline int irqchip_in_kernel(struct kvm
*kvm
)
92 int mode
= kvm
->arch
.irqchip_mode
;
94 /* Matches smp_wmb() when setting irqchip_mode */
96 return mode
!= KVM_IRQCHIP_NONE
;
99 void kvm_inject_pending_timer_irqs(struct kvm_vcpu
*vcpu
);
100 void kvm_inject_apic_timer_irqs(struct kvm_vcpu
*vcpu
);
101 void kvm_apic_nmi_wd_deliver(struct kvm_vcpu
*vcpu
);
102 void __kvm_migrate_apic_timer(struct kvm_vcpu
*vcpu
);
103 void __kvm_migrate_pit_timer(struct kvm_vcpu
*vcpu
);
104 void __kvm_migrate_timers(struct kvm_vcpu
*vcpu
);
106 int apic_has_pending_timer(struct kvm_vcpu
*vcpu
);
108 int kvm_setup_default_irq_routing(struct kvm
*kvm
);
109 int kvm_irq_delivery_to_apic(struct kvm
*kvm
, struct kvm_lapic
*src
,
110 struct kvm_lapic_irq
*irq
,
111 struct dest_map
*dest_map
);