xref: /openbmc/linux/arch/x86/kvm/irq.h (revision 93b6547e2219784b2df790353e083e0bdbebd2c2)
1edf88417SAvi Kivity /*
2edf88417SAvi Kivity  * irq.h: in kernel interrupt controller related definitions
3edf88417SAvi Kivity  * Copyright (c) 2007, Intel Corporation.
4edf88417SAvi Kivity  *
5edf88417SAvi Kivity  * This program is free software; you can redistribute it and/or modify it
6edf88417SAvi Kivity  * under the terms and conditions of the GNU General Public License,
7edf88417SAvi Kivity  * version 2, as published by the Free Software Foundation.
8edf88417SAvi Kivity  *
9edf88417SAvi Kivity  * This program is distributed in the hope it will be useful, but WITHOUT
10edf88417SAvi Kivity  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11edf88417SAvi Kivity  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12edf88417SAvi Kivity  * more details.
13edf88417SAvi Kivity  *
14edf88417SAvi Kivity  * You should have received a copy of the GNU General Public License along with
15edf88417SAvi Kivity  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16edf88417SAvi Kivity  * Place - Suite 330, Boston, MA 02111-1307 USA.
17edf88417SAvi Kivity  * Authors:
18edf88417SAvi Kivity  *   Yaozu (Eddie) Dong <Eddie.dong@intel.com>
19edf88417SAvi Kivity  *
20edf88417SAvi Kivity  */
21edf88417SAvi Kivity 
22edf88417SAvi Kivity #ifndef __IRQ_H
23edf88417SAvi Kivity #define __IRQ_H
24edf88417SAvi Kivity 
25edf88417SAvi Kivity #include <linux/mm_types.h>
26edf88417SAvi Kivity #include <linux/hrtimer.h>
27edf88417SAvi Kivity #include <linux/kvm_host.h>
283f353858SAvi Kivity #include <linux/spinlock.h>
2982470196SZhang Xiantao 
30edf88417SAvi Kivity #include "iodev.h"
3182470196SZhang Xiantao #include "ioapic.h"
3282470196SZhang Xiantao #include "lapic.h"
33edf88417SAvi Kivity 
34c65bbfa1SBen-Ami Yassour #define PIC_NUM_PINS 16
3544882eedSMarcelo Tosatti #define SELECT_PIC(irq) \
3644882eedSMarcelo Tosatti 	((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)
37c65bbfa1SBen-Ami Yassour 
38edf88417SAvi Kivity struct kvm;
39edf88417SAvi Kivity struct kvm_vcpu;
40edf88417SAvi Kivity 
41edf88417SAvi Kivity struct kvm_kpic_state {
42edf88417SAvi Kivity 	u8 last_irr;	/* edge detection */
43edf88417SAvi Kivity 	u8 irr;		/* interrupt request register */
44edf88417SAvi Kivity 	u8 imr;		/* interrupt mask register */
45edf88417SAvi Kivity 	u8 isr;		/* interrupt service register */
46edf88417SAvi Kivity 	u8 priority_add;	/* highest irq priority */
47edf88417SAvi Kivity 	u8 irq_base;
48edf88417SAvi Kivity 	u8 read_reg_select;
49edf88417SAvi Kivity 	u8 poll;
50edf88417SAvi Kivity 	u8 special_mask;
51edf88417SAvi Kivity 	u8 init_state;
52edf88417SAvi Kivity 	u8 auto_eoi;
53edf88417SAvi Kivity 	u8 rotate_on_auto_eoi;
54edf88417SAvi Kivity 	u8 special_fully_nested_mode;
55edf88417SAvi Kivity 	u8 init4;		/* true if 4 byte init */
56edf88417SAvi Kivity 	u8 elcr;		/* PIIX edge/trigger selection */
57edf88417SAvi Kivity 	u8 elcr_mask;
58eebb5f31SGleb Natapov 	u8 isr_ack;	/* interrupt ack detection */
59edf88417SAvi Kivity 	struct kvm_pic *pics_state;
60edf88417SAvi Kivity };
61edf88417SAvi Kivity 
62edf88417SAvi Kivity struct kvm_pic {
63f4f51050SAvi Kivity 	spinlock_t lock;
6450a085bdSJan Kiszka 	bool wakeup_needed;
653f353858SAvi Kivity 	unsigned pending_acks;
663f353858SAvi Kivity 	struct kvm *kvm;
67edf88417SAvi Kivity 	struct kvm_kpic_state pics[2]; /* 0 is master pic, 1 is slave pic */
68edf88417SAvi Kivity 	int output;		/* intr from master PIC */
69743eeb0bSSasha Levin 	struct kvm_io_device dev_master;
70743eeb0bSSasha Levin 	struct kvm_io_device dev_slave;
71743eeb0bSSasha Levin 	struct kvm_io_device dev_eclr;
72f5244726SMarcelo Tosatti 	void (*ack_notifier)(void *opaque, int irq);
73*93b6547eSMichael S. Tsirkin 	unsigned long irq_states[PIC_NUM_PINS];
74edf88417SAvi Kivity };
75edf88417SAvi Kivity 
76edf88417SAvi Kivity struct kvm_pic *kvm_create_pic(struct kvm *kvm);
7772bb2fcdSWei Yongjun void kvm_destroy_pic(struct kvm *kvm);
78f5244726SMarcelo Tosatti int kvm_pic_read_irq(struct kvm *kvm);
79edf88417SAvi Kivity void kvm_pic_update_irq(struct kvm_pic *s);
80edf88417SAvi Kivity 
81edf88417SAvi Kivity static inline struct kvm_pic *pic_irqchip(struct kvm *kvm)
82edf88417SAvi Kivity {
83edf88417SAvi Kivity 	return kvm->arch.vpic;
84edf88417SAvi Kivity }
85edf88417SAvi Kivity 
86edf88417SAvi Kivity static inline int irqchip_in_kernel(struct kvm *kvm)
87edf88417SAvi Kivity {
883ddea128SMarcelo Tosatti 	int ret;
893ddea128SMarcelo Tosatti 
903ddea128SMarcelo Tosatti 	ret = (pic_irqchip(kvm) != NULL);
913ddea128SMarcelo Tosatti 	smp_rmb();
923ddea128SMarcelo Tosatti 	return ret;
93edf88417SAvi Kivity }
94edf88417SAvi Kivity 
95edf88417SAvi Kivity void kvm_pic_reset(struct kvm_kpic_state *s);
96edf88417SAvi Kivity 
97edf88417SAvi Kivity void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu);
98edf88417SAvi Kivity void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu);
998fdb2351SJan Kiszka void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu);
1002f52d58cSAvi Kivity void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu);
1012f599714SMarcelo Tosatti void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu);
1022f599714SMarcelo Tosatti void __kvm_migrate_timers(struct kvm_vcpu *vcpu);
103edf88417SAvi Kivity 
1043d80840dSMarcelo Tosatti int apic_has_pending_timer(struct kvm_vcpu *vcpu);
1053d80840dSMarcelo Tosatti 
106edf88417SAvi Kivity #endif
107