Thomas Gleixner | 3b20eb2 | 2019-05-29 16:57:35 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 2 | /* |
| 3 | * irq.h: in kernel interrupt controller related definitions |
| 4 | * Copyright (c) 2007, Intel Corporation. |
| 5 | * |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 6 | * Authors: |
| 7 | * Yaozu (Eddie) Dong <Eddie.dong@intel.com> |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef __IRQ_H |
| 11 | #define __IRQ_H |
| 12 | |
Hollis Blanchard | e01a1b5 | 2007-12-03 15:30:25 -0600 | [diff] [blame] | 13 | #include <linux/mm_types.h> |
| 14 | #include <linux/hrtimer.h> |
Avi Kivity | edf8841 | 2007-12-16 11:02:48 +0200 | [diff] [blame] | 15 | #include <linux/kvm_host.h> |
Avi Kivity | 3f35385 | 2008-12-21 22:48:32 +0200 | [diff] [blame] | 16 | #include <linux/spinlock.h> |
Zhang Xiantao | 8247019 | 2007-12-17 13:59:56 +0800 | [diff] [blame] | 17 | |
Andre Przywara | af669ac | 2015-03-26 14:39:29 +0000 | [diff] [blame] | 18 | #include <kvm/iodev.h> |
Zhang Xiantao | 8247019 | 2007-12-17 13:59:56 +0800 | [diff] [blame] | 19 | #include "lapic.h" |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 20 | |
Ben-Ami Yassour | c65bbfa | 2008-07-06 17:15:07 +0300 | [diff] [blame] | 21 | #define PIC_NUM_PINS 16 |
Marcelo Tosatti | 44882ee | 2009-01-27 15:12:38 -0200 | [diff] [blame] | 22 | #define SELECT_PIC(irq) \ |
| 23 | ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE) |
Ben-Ami Yassour | c65bbfa | 2008-07-06 17:15:07 +0300 | [diff] [blame] | 24 | |
Hollis Blanchard | e01a1b5 | 2007-12-03 15:30:25 -0600 | [diff] [blame] | 25 | struct kvm; |
| 26 | struct kvm_vcpu; |
| 27 | |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 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; |
Gleb Natapov | eebb5f3 | 2010-08-30 12:49:13 +0300 | [diff] [blame] | 45 | u8 isr_ack; /* interrupt ack detection */ |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 46 | struct kvm_pic *pics_state; |
| 47 | }; |
| 48 | |
| 49 | struct kvm_pic { |
Avi Kivity | f4f5105 | 2010-09-19 18:44:07 +0200 | [diff] [blame] | 50 | spinlock_t lock; |
Jan Kiszka | 50a085b | 2010-02-24 10:41:58 +0100 | [diff] [blame] | 51 | bool wakeup_needed; |
Avi Kivity | 3f35385 | 2008-12-21 22:48:32 +0200 | [diff] [blame] | 52 | unsigned pending_acks; |
| 53 | struct kvm *kvm; |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 54 | struct kvm_kpic_state pics[2]; /* 0 is master pic, 1 is slave pic */ |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 55 | int output; /* intr from master PIC */ |
Sasha Levin | 743eeb0 | 2011-07-27 16:00:48 +0300 | [diff] [blame] | 56 | struct kvm_io_device dev_master; |
| 57 | struct kvm_io_device dev_slave; |
| 58 | struct kvm_io_device dev_eclr; |
Marcelo Tosatti | f524472 | 2008-07-26 17:01:00 -0300 | [diff] [blame] | 59 | void (*ack_notifier)(void *opaque, int irq); |
Michael S. Tsirkin | 93b6547 | 2012-07-19 13:55:53 +0300 | [diff] [blame] | 60 | unsigned long irq_states[PIC_NUM_PINS]; |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 61 | }; |
| 62 | |
Radim Krčmář | 0994136 | 2016-12-16 16:10:03 +0100 | [diff] [blame] | 63 | int kvm_pic_init(struct kvm *kvm); |
| 64 | void kvm_pic_destroy(struct kvm *kvm); |
Marcelo Tosatti | f524472 | 2008-07-26 17:01:00 -0300 | [diff] [blame] | 65 | int kvm_pic_read_irq(struct kvm *kvm); |
He, Qing | 6ceb9d7 | 2007-07-26 11:05:18 +0300 | [diff] [blame] | 66 | void kvm_pic_update_irq(struct kvm_pic *s); |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 67 | |
Steve Rutherford | 49df639 | 2015-07-29 23:21:40 -0700 | [diff] [blame] | 68 | static inline int irqchip_split(struct kvm *kvm) |
| 69 | { |
David Hildenbrand | 637e3f8 | 2017-04-07 10:50:19 +0200 | [diff] [blame] | 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; |
Radim Krčmář | 49776fa | 2016-12-16 16:10:02 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static inline int irqchip_kernel(struct kvm *kvm) |
| 78 | { |
David Hildenbrand | 637e3f8 | 2017-04-07 10:50:19 +0200 | [diff] [blame] | 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; |
Steve Rutherford | 49df639 | 2015-07-29 23:21:40 -0700 | [diff] [blame] | 84 | } |
| 85 | |
彭浩(Richard) | 88197e6 | 2020-05-21 05:57:49 +0000 | [diff] [blame] | 86 | static inline int pic_in_kernel(struct kvm *kvm) |
| 87 | { |
| 88 | return irqchip_kernel(kvm); |
| 89 | } |
| 90 | |
Zhang Xiantao | 682c59a | 2007-12-11 20:36:00 +0800 | [diff] [blame] | 91 | static inline int irqchip_in_kernel(struct kvm *kvm) |
| 92 | { |
David Hildenbrand | 637e3f8 | 2017-04-07 10:50:19 +0200 | [diff] [blame] | 93 | int mode = kvm->arch.irqchip_mode; |
Steve Rutherford | 49df639 | 2015-07-29 23:21:40 -0700 | [diff] [blame] | 94 | |
David Hildenbrand | 637e3f8 | 2017-04-07 10:50:19 +0200 | [diff] [blame] | 95 | /* Matches smp_wmb() when setting irqchip_mode */ |
Marcelo Tosatti | 3ddea12 | 2009-10-29 13:44:15 -0200 | [diff] [blame] | 96 | smp_rmb(); |
David Hildenbrand | 5c0aea0 | 2017-04-28 17:06:20 +0200 | [diff] [blame] | 97 | return mode != KVM_IRQCHIP_NONE; |
Zhang Xiantao | 682c59a | 2007-12-11 20:36:00 +0800 | [diff] [blame] | 98 | } |
| 99 | |
Eddie Dong | 1b9778d | 2007-09-03 16:56:58 +0300 | [diff] [blame] | 100 | void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu); |
| 101 | void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu); |
Jan Kiszka | 8fdb235 | 2008-10-20 10:20:02 +0200 | [diff] [blame] | 102 | void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu); |
Avi Kivity | 2f52d58 | 2008-01-16 12:49:30 +0200 | [diff] [blame] | 103 | void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu); |
Marcelo Tosatti | 2f59971 | 2008-05-27 12:10:20 -0300 | [diff] [blame] | 104 | void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu); |
| 105 | void __kvm_migrate_timers(struct kvm_vcpu *vcpu); |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 106 | |
Marcelo Tosatti | 3d80840 | 2008-04-11 14:53:26 -0300 | [diff] [blame] | 107 | int apic_has_pending_timer(struct kvm_vcpu *vcpu); |
| 108 | |
Eric Auger | d9565a7 | 2016-07-22 16:20:40 +0000 | [diff] [blame] | 109 | int kvm_setup_default_irq_routing(struct kvm *kvm); |
| 110 | int kvm_setup_empty_irq_routing(struct kvm *kvm); |
Peter Xu | 59508b3 | 2019-12-04 20:07:17 +0100 | [diff] [blame] | 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); |
Eric Auger | d9565a7 | 2016-07-22 16:20:40 +0000 | [diff] [blame] | 114 | |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 115 | #endif |