blob: 9b64abf9b3f145b25e858845e12563490857f1eb [file] [log] [blame]
Thomas Gleixner3b20eb22019-05-29 16:57:35 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Eddie Dong85f455f2007-07-06 12:20:49 +03002/*
3 * irq.h: in kernel interrupt controller related definitions
4 * Copyright (c) 2007, Intel Corporation.
5 *
Eddie Dong85f455f2007-07-06 12:20:49 +03006 * Authors:
7 * Yaozu (Eddie) Dong <Eddie.dong@intel.com>
Eddie Dong85f455f2007-07-06 12:20:49 +03008 */
9
10#ifndef __IRQ_H
11#define __IRQ_H
12
Hollis Blancharde01a1b52007-12-03 15:30:25 -060013#include <linux/mm_types.h>
14#include <linux/hrtimer.h>
Avi Kivityedf88412007-12-16 11:02:48 +020015#include <linux/kvm_host.h>
Avi Kivity3f353852008-12-21 22:48:32 +020016#include <linux/spinlock.h>
Zhang Xiantao82470192007-12-17 13:59:56 +080017
Andre Przywaraaf669ac2015-03-26 14:39:29 +000018#include <kvm/iodev.h>
Zhang Xiantao82470192007-12-17 13:59:56 +080019#include "lapic.h"
Eddie Dong85f455f2007-07-06 12:20:49 +030020
Ben-Ami Yassourc65bbfa2008-07-06 17:15:07 +030021#define PIC_NUM_PINS 16
Marcelo Tosatti44882ee2009-01-27 15:12:38 -020022#define SELECT_PIC(irq) \
23 ((irq) < 8 ? KVM_IRQCHIP_PIC_MASTER : KVM_IRQCHIP_PIC_SLAVE)
Ben-Ami Yassourc65bbfa2008-07-06 17:15:07 +030024
Hollis Blancharde01a1b52007-12-03 15:30:25 -060025struct kvm;
26struct kvm_vcpu;
27
Eddie Dong85f455f2007-07-06 12:20:49 +030028struct 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 Natapoveebb5f32010-08-30 12:49:13 +030045 u8 isr_ack; /* interrupt ack detection */
Eddie Dong85f455f2007-07-06 12:20:49 +030046 struct kvm_pic *pics_state;
47};
48
49struct kvm_pic {
Avi Kivityf4f51052010-09-19 18:44:07 +020050 spinlock_t lock;
Jan Kiszka50a085b2010-02-24 10:41:58 +010051 bool wakeup_needed;
Avi Kivity3f353852008-12-21 22:48:32 +020052 unsigned pending_acks;
53 struct kvm *kvm;
Eddie Dong85f455f2007-07-06 12:20:49 +030054 struct kvm_kpic_state pics[2]; /* 0 is master pic, 1 is slave pic */
Eddie Dong85f455f2007-07-06 12:20:49 +030055 int output; /* intr from master PIC */
Sasha Levin743eeb02011-07-27 16:00:48 +030056 struct kvm_io_device dev_master;
57 struct kvm_io_device dev_slave;
58 struct kvm_io_device dev_eclr;
Marcelo Tosattif5244722008-07-26 17:01:00 -030059 void (*ack_notifier)(void *opaque, int irq);
Michael S. Tsirkin93b65472012-07-19 13:55:53 +030060 unsigned long irq_states[PIC_NUM_PINS];
Eddie Dong85f455f2007-07-06 12:20:49 +030061};
62
Radim Krčmář09941362016-12-16 16:10:03 +010063int kvm_pic_init(struct kvm *kvm);
64void kvm_pic_destroy(struct kvm *kvm);
Marcelo Tosattif5244722008-07-26 17:01:00 -030065int kvm_pic_read_irq(struct kvm *kvm);
He, Qing6ceb9d72007-07-26 11:05:18 +030066void kvm_pic_update_irq(struct kvm_pic *s);
Eddie Dong85f455f2007-07-06 12:20:49 +030067
Steve Rutherford49df6392015-07-29 23:21:40 -070068static inline int irqchip_split(struct kvm *kvm)
69{
David Hildenbrand637e3f82017-04-07 10:50:19 +020070 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ář49776fa2016-12-16 16:10:02 +010075}
76
77static inline int irqchip_kernel(struct kvm *kvm)
78{
David Hildenbrand637e3f82017-04-07 10:50:19 +020079 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 Rutherford49df6392015-07-29 23:21:40 -070084}
85
彭浩(Richard)88197e62020-05-21 05:57:49 +000086static inline int pic_in_kernel(struct kvm *kvm)
87{
88 return irqchip_kernel(kvm);
89}
90
Zhang Xiantao682c59a2007-12-11 20:36:00 +080091static inline int irqchip_in_kernel(struct kvm *kvm)
92{
David Hildenbrand637e3f82017-04-07 10:50:19 +020093 int mode = kvm->arch.irqchip_mode;
Steve Rutherford49df6392015-07-29 23:21:40 -070094
David Hildenbrand637e3f82017-04-07 10:50:19 +020095 /* Matches smp_wmb() when setting irqchip_mode */
Marcelo Tosatti3ddea122009-10-29 13:44:15 -020096 smp_rmb();
David Hildenbrand5c0aea02017-04-28 17:06:20 +020097 return mode != KVM_IRQCHIP_NONE;
Zhang Xiantao682c59a2007-12-11 20:36:00 +080098}
99
Eddie Dong1b9778d2007-09-03 16:56:58 +0300100void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu);
101void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu);
Jan Kiszka8fdb2352008-10-20 10:20:02 +0200102void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu);
Avi Kivity2f52d582008-01-16 12:49:30 +0200103void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu);
Marcelo Tosatti2f599712008-05-27 12:10:20 -0300104void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu);
105void __kvm_migrate_timers(struct kvm_vcpu *vcpu);
Eddie Dong97222cc2007-09-12 10:58:04 +0300106
Marcelo Tosatti3d808402008-04-11 14:53:26 -0300107int apic_has_pending_timer(struct kvm_vcpu *vcpu);
108
Eric Augerd9565a72016-07-22 16:20:40 +0000109int kvm_setup_default_irq_routing(struct kvm *kvm);
110int kvm_setup_empty_irq_routing(struct kvm *kvm);
Peter Xu59508b32019-12-04 20:07:17 +0100111int 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 Augerd9565a72016-07-22 16:20:40 +0000114
Eddie Dong85f455f2007-07-06 12:20:49 +0300115#endif