13b20eb23SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2edf88417SAvi Kivity /* 3edf88417SAvi Kivity * irq.h: in kernel interrupt controller related definitions 4edf88417SAvi Kivity * Copyright (c) 2007, Intel Corporation. 5edf88417SAvi Kivity * 6edf88417SAvi Kivity * Authors: 7edf88417SAvi Kivity * Yaozu (Eddie) Dong <Eddie.dong@intel.com> 8edf88417SAvi Kivity */ 9edf88417SAvi Kivity 10edf88417SAvi Kivity #ifndef __IRQ_H 11edf88417SAvi Kivity #define __IRQ_H 12edf88417SAvi Kivity 13edf88417SAvi Kivity #include <linux/mm_types.h> 14edf88417SAvi Kivity #include <linux/hrtimer.h> 15edf88417SAvi Kivity #include <linux/kvm_host.h> 163f353858SAvi Kivity #include <linux/spinlock.h> 1782470196SZhang Xiantao 18af669ac6SAndre Przywara #include <kvm/iodev.h> 1982470196SZhang Xiantao #include "lapic.h" 20edf88417SAvi Kivity 21c65bbfa1SBen-Ami Yassour #define PIC_NUM_PINS 16 2244882eedSMarcelo Tosatti #define SELECT_PIC(irq) \ 2344882eedSMarcelo Tosatti ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE) 24c65bbfa1SBen-Ami Yassour 25edf88417SAvi Kivity struct kvm; 26edf88417SAvi Kivity struct kvm_vcpu; 27edf88417SAvi Kivity 28edf88417SAvi Kivity struct kvm_kpic_state { 29edf88417SAvi Kivity u8 last_irr; /* edge detection */ 30edf88417SAvi Kivity u8 irr; /* interrupt request register */ 31edf88417SAvi Kivity u8 imr; /* interrupt mask register */ 32edf88417SAvi Kivity u8 isr; /* interrupt service register */ 33edf88417SAvi Kivity u8 priority_add; /* highest irq priority */ 34edf88417SAvi Kivity u8 irq_base; 35edf88417SAvi Kivity u8 read_reg_select; 36edf88417SAvi Kivity u8 poll; 37edf88417SAvi Kivity u8 special_mask; 38edf88417SAvi Kivity u8 init_state; 39edf88417SAvi Kivity u8 auto_eoi; 40edf88417SAvi Kivity u8 rotate_on_auto_eoi; 41edf88417SAvi Kivity u8 special_fully_nested_mode; 42edf88417SAvi Kivity u8 init4; /* true if 4 byte init */ 43edf88417SAvi Kivity u8 elcr; /* PIIX edge/trigger selection */ 44edf88417SAvi Kivity u8 elcr_mask; 45eebb5f31SGleb Natapov u8 isr_ack; /* interrupt ack detection */ 46edf88417SAvi Kivity struct kvm_pic *pics_state; 47edf88417SAvi Kivity }; 48edf88417SAvi Kivity 49edf88417SAvi Kivity struct kvm_pic { 50f4f51050SAvi Kivity spinlock_t lock; 5150a085bdSJan Kiszka bool wakeup_needed; 523f353858SAvi Kivity unsigned pending_acks; 533f353858SAvi Kivity struct kvm *kvm; 54edf88417SAvi Kivity struct kvm_kpic_state pics[2]; /* 0 is master pic, 1 is slave pic */ 55edf88417SAvi Kivity int output; /* intr from master PIC */ 56743eeb0bSSasha Levin struct kvm_io_device dev_master; 57743eeb0bSSasha Levin struct kvm_io_device dev_slave; 58*34739a28SMaciej W. Rozycki struct kvm_io_device dev_elcr; 5993b6547eSMichael S. Tsirkin unsigned long irq_states[PIC_NUM_PINS]; 60edf88417SAvi Kivity }; 61edf88417SAvi Kivity 6209941366SRadim Krčmář int kvm_pic_init(struct kvm *kvm); 6309941366SRadim Krčmář void kvm_pic_destroy(struct kvm *kvm); 64f5244726SMarcelo Tosatti int kvm_pic_read_irq(struct kvm *kvm); 65edf88417SAvi Kivity void kvm_pic_update_irq(struct kvm_pic *s); 66edf88417SAvi Kivity irqchip_split(struct kvm * kvm)6749df6397SSteve Rutherfordstatic inline int irqchip_split(struct kvm *kvm) 6849df6397SSteve Rutherford { 69637e3f86SDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 70637e3f86SDavid Hildenbrand 71637e3f86SDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 72637e3f86SDavid Hildenbrand smp_rmb(); 73637e3f86SDavid Hildenbrand return mode == KVM_IRQCHIP_SPLIT; 7449776fafSRadim Krčmář } 7549776fafSRadim Krčmář irqchip_kernel(struct kvm * kvm)7649776fafSRadim Krčmářstatic inline int irqchip_kernel(struct kvm *kvm) 7749776fafSRadim Krčmář { 78637e3f86SDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 79637e3f86SDavid Hildenbrand 80637e3f86SDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 81637e3f86SDavid Hildenbrand smp_rmb(); 82637e3f86SDavid Hildenbrand return mode == KVM_IRQCHIP_KERNEL; 8349df6397SSteve Rutherford } 8449df6397SSteve Rutherford pic_in_kernel(struct kvm * kvm)8588197e6aS彭浩(Richard)static inline int pic_in_kernel(struct kvm *kvm) 8688197e6aS彭浩(Richard) { 8788197e6aS彭浩(Richard) return irqchip_kernel(kvm); 8888197e6aS彭浩(Richard) } 8988197e6aS彭浩(Richard) irqchip_in_kernel(struct kvm * kvm)90edf88417SAvi Kivitystatic inline int irqchip_in_kernel(struct kvm *kvm) 91edf88417SAvi Kivity { 92637e3f86SDavid Hildenbrand int mode = kvm->arch.irqchip_mode; 9349df6397SSteve Rutherford 94637e3f86SDavid Hildenbrand /* Matches smp_wmb() when setting irqchip_mode */ 953ddea128SMarcelo Tosatti smp_rmb(); 965c0aea0eSDavid Hildenbrand return mode != KVM_IRQCHIP_NONE; 97edf88417SAvi Kivity } 98edf88417SAvi Kivity 99edf88417SAvi Kivity void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu); 100edf88417SAvi Kivity void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu); 1018fdb2351SJan Kiszka void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu); 1022f52d58cSAvi Kivity void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu); 1032f599714SMarcelo Tosatti void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu); 1042f599714SMarcelo Tosatti void __kvm_migrate_timers(struct kvm_vcpu *vcpu); 105edf88417SAvi Kivity 1063d80840dSMarcelo Tosatti int apic_has_pending_timer(struct kvm_vcpu *vcpu); 1073d80840dSMarcelo Tosatti 108d9565a73SEric Auger int kvm_setup_default_irq_routing(struct kvm *kvm); 109d9565a73SEric Auger int kvm_setup_empty_irq_routing(struct kvm *kvm); 11059508b30SPeter Xu int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, 11159508b30SPeter Xu struct kvm_lapic_irq *irq, 11259508b30SPeter Xu struct dest_map *dest_map); 113d9565a73SEric Auger 114edf88417SAvi Kivity #endif 115