1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * irq.h: in kernel interrupt controller related definitions 4 * Copyright (c) 2007, Intel Corporation. 5 * 6 * Authors: 7 * Yaozu (Eddie) Dong <Eddie.dong@intel.com> 8 */ 9 10 #ifndef __IRQ_H 11 #define __IRQ_H 12 13 #include <linux/mm_types.h> 14 #include <linux/hrtimer.h> 15 #include <linux/kvm_host.h> 16 #include <linux/spinlock.h> 17 18 #include <kvm/iodev.h> 19 #include "lapic.h" 20 21 #define PIC_NUM_PINS 16 22 #define SELECT_PIC(irq) \ 23 ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE) 24 25 struct kvm; 26 struct kvm_vcpu; 27 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 */ 34 u8 irq_base; 35 u8 read_reg_select; 36 u8 poll; 37 u8 special_mask; 38 u8 init_state; 39 u8 auto_eoi; 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 */ 44 u8 elcr_mask; 45 u8 isr_ack; /* interrupt ack detection */ 46 struct kvm_pic *pics_state; 47 }; 48 49 struct kvm_pic { 50 spinlock_t lock; 51 bool wakeup_needed; 52 unsigned pending_acks; 53 struct kvm *kvm; 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_eclr; 59 void (*ack_notifier)(void *opaque, int irq); 60 unsigned long irq_states[PIC_NUM_PINS]; 61 }; 62 63 int kvm_pic_init(struct kvm *kvm); 64 void kvm_pic_destroy(struct kvm *kvm); 65 int kvm_pic_read_irq(struct kvm *kvm); 66 void kvm_pic_update_irq(struct kvm_pic *s); 67 irqchip_split(struct kvm * kvm)68static inline int irqchip_split(struct kvm *kvm) 69 { 70 int mode = kvm->arch.irqchip_mode; 71 72 /* Matches smp_wmb() when setting irqchip_mode */ 73 smp_rmb(); 74 return mode == KVM_IRQCHIP_SPLIT; 75 } 76 irqchip_kernel(struct kvm * kvm)77static inline int irqchip_kernel(struct kvm *kvm) 78 { 79 int mode = kvm->arch.irqchip_mode; 80 81 /* Matches smp_wmb() when setting irqchip_mode */ 82 smp_rmb(); 83 return mode == KVM_IRQCHIP_KERNEL; 84 } 85 pic_in_kernel(struct kvm * kvm)86static inline int pic_in_kernel(struct kvm *kvm) 87 { 88 return irqchip_kernel(kvm); 89 } 90 irqchip_in_kernel(struct kvm * kvm)91static inline int irqchip_in_kernel(struct kvm *kvm) 92 { 93 int mode = kvm->arch.irqchip_mode; 94 95 /* Matches smp_wmb() when setting irqchip_mode */ 96 smp_rmb(); 97 return mode != KVM_IRQCHIP_NONE; 98 } 99 100 void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu); 101 void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu); 102 void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu); 103 void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu); 104 void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu); 105 void __kvm_migrate_timers(struct kvm_vcpu *vcpu); 106 107 int apic_has_pending_timer(struct kvm_vcpu *vcpu); 108 109 int kvm_setup_default_irq_routing(struct kvm *kvm); 110 int kvm_setup_empty_irq_routing(struct kvm *kvm); 111 int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, 112 struct kvm_lapic_irq *irq, 113 struct dest_map *dest_map); 114 115 #endif 116