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 35*44882eedSMarcelo Tosatti #define SELECT_PIC(irq) \ 36*44882eedSMarcelo 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 typedef void irq_request_func(void *opaque, int level); 42edf88417SAvi Kivity 43edf88417SAvi Kivity struct kvm_kpic_state { 44edf88417SAvi Kivity u8 last_irr; /* edge detection */ 45edf88417SAvi Kivity u8 irr; /* interrupt request register */ 46edf88417SAvi Kivity u8 imr; /* interrupt mask register */ 47edf88417SAvi Kivity u8 isr; /* interrupt service register */ 48e4825800SMarcelo Tosatti u8 isr_ack; /* interrupt ack detection */ 49edf88417SAvi Kivity u8 priority_add; /* highest irq priority */ 50edf88417SAvi Kivity u8 irq_base; 51edf88417SAvi Kivity u8 read_reg_select; 52edf88417SAvi Kivity u8 poll; 53edf88417SAvi Kivity u8 special_mask; 54edf88417SAvi Kivity u8 init_state; 55edf88417SAvi Kivity u8 auto_eoi; 56edf88417SAvi Kivity u8 rotate_on_auto_eoi; 57edf88417SAvi Kivity u8 special_fully_nested_mode; 58edf88417SAvi Kivity u8 init4; /* true if 4 byte init */ 59edf88417SAvi Kivity u8 elcr; /* PIIX edge/trigger selection */ 60edf88417SAvi Kivity u8 elcr_mask; 61edf88417SAvi Kivity struct kvm_pic *pics_state; 62edf88417SAvi Kivity }; 63edf88417SAvi Kivity 64edf88417SAvi Kivity struct kvm_pic { 653f353858SAvi Kivity spinlock_t lock; 663f353858SAvi Kivity bool wakeup_needed; 673f353858SAvi Kivity unsigned pending_acks; 683f353858SAvi Kivity struct kvm *kvm; 69edf88417SAvi Kivity struct kvm_kpic_state pics[2]; /* 0 is master pic, 1 is slave pic */ 70edf88417SAvi Kivity irq_request_func *irq_request; 71edf88417SAvi Kivity void *irq_request_opaque; 72edf88417SAvi Kivity int output; /* intr from master PIC */ 73edf88417SAvi Kivity struct kvm_io_device dev; 74f5244726SMarcelo Tosatti void (*ack_notifier)(void *opaque, int irq); 75edf88417SAvi Kivity }; 76edf88417SAvi Kivity 77edf88417SAvi Kivity struct kvm_pic *kvm_create_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); 80e4825800SMarcelo Tosatti void kvm_pic_clear_isr_ack(struct kvm *kvm); 81edf88417SAvi Kivity 82edf88417SAvi Kivity static inline struct kvm_pic *pic_irqchip(struct kvm *kvm) 83edf88417SAvi Kivity { 84edf88417SAvi Kivity return kvm->arch.vpic; 85edf88417SAvi Kivity } 86edf88417SAvi Kivity 87edf88417SAvi Kivity static inline int irqchip_in_kernel(struct kvm *kvm) 88edf88417SAvi Kivity { 89edf88417SAvi Kivity return pic_irqchip(kvm) != NULL; 90edf88417SAvi Kivity } 91edf88417SAvi Kivity 92edf88417SAvi Kivity void kvm_pic_reset(struct kvm_kpic_state *s); 93edf88417SAvi Kivity 94edf88417SAvi Kivity void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu); 95edf88417SAvi Kivity void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu); 968fdb2351SJan Kiszka void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu); 972f52d58cSAvi Kivity void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu); 982f599714SMarcelo Tosatti void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu); 992f599714SMarcelo Tosatti void __kvm_migrate_timers(struct kvm_vcpu *vcpu); 100edf88417SAvi Kivity 1013d80840dSMarcelo Tosatti int pit_has_pending_timer(struct kvm_vcpu *vcpu); 1023d80840dSMarcelo Tosatti int apic_has_pending_timer(struct kvm_vcpu *vcpu); 1033d80840dSMarcelo Tosatti 104edf88417SAvi Kivity #endif 105