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 30af669ac6SAndre Przywara #include <kvm/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); 7393b6547eSMichael S. Tsirkin unsigned long irq_states[PIC_NUM_PINS]; 74edf88417SAvi Kivity }; 75edf88417SAvi Kivity 7609941366SRadim Krčmář int kvm_pic_init(struct kvm *kvm); 7709941366SRadim Krčmář void kvm_pic_destroy(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 811c1a9ce9SSteve Rutherford static inline int pic_in_kernel(struct kvm *kvm) 821c1a9ce9SSteve Rutherford { 8319d25a0eSDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 841c1a9ce9SSteve Rutherford 8519d25a0eSDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 8619d25a0eSDavid Hildenbrand smp_rmb(); 8719d25a0eSDavid Hildenbrand return mode == KVM_IRQCHIP_KERNEL; 881c1a9ce9SSteve Rutherford } 891c1a9ce9SSteve Rutherford 9049df6397SSteve Rutherford static inline int irqchip_split(struct kvm *kvm) 9149df6397SSteve Rutherford { 92637e3f86SDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 93637e3f86SDavid Hildenbrand 94637e3f86SDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 95637e3f86SDavid Hildenbrand smp_rmb(); 96637e3f86SDavid Hildenbrand return mode == KVM_IRQCHIP_SPLIT; 9749776fafSRadim Krčmář } 9849776fafSRadim Krčmář 9949776fafSRadim Krčmář static inline int irqchip_kernel(struct kvm *kvm) 10049776fafSRadim Krčmář { 101637e3f86SDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 102637e3f86SDavid Hildenbrand 103637e3f86SDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 104637e3f86SDavid Hildenbrand smp_rmb(); 105637e3f86SDavid Hildenbrand return mode == KVM_IRQCHIP_KERNEL; 10649df6397SSteve Rutherford } 10749df6397SSteve Rutherford 108edf88417SAvi Kivity static inline int irqchip_in_kernel(struct kvm *kvm) 109edf88417SAvi Kivity { 110637e3f86SDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 11149df6397SSteve Rutherford 112637e3f86SDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 1133ddea128SMarcelo Tosatti smp_rmb(); 114*5c0aea0eSDavid Hildenbrand return mode != KVM_IRQCHIP_NONE; 115edf88417SAvi Kivity } 116edf88417SAvi Kivity 117edf88417SAvi Kivity void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu); 118edf88417SAvi Kivity void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu); 1198fdb2351SJan Kiszka void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu); 1202f52d58cSAvi Kivity void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu); 1212f599714SMarcelo Tosatti void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu); 1222f599714SMarcelo Tosatti void __kvm_migrate_timers(struct kvm_vcpu *vcpu); 123edf88417SAvi Kivity 1243d80840dSMarcelo Tosatti int apic_has_pending_timer(struct kvm_vcpu *vcpu); 1253d80840dSMarcelo Tosatti 126d9565a73SEric Auger int kvm_setup_default_irq_routing(struct kvm *kvm); 127d9565a73SEric Auger int kvm_setup_empty_irq_routing(struct kvm *kvm); 128d9565a73SEric Auger 129edf88417SAvi Kivity #endif 130