KVM
ioapic.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KVM_IO_APIC_H
3 #define __KVM_IO_APIC_H
4 
5 #include <linux/kvm_host.h>
6 #include <kvm/iodev.h>
7 #include "irq.h"
8 
9 struct kvm;
10 struct kvm_vcpu;
11 
12 #define IOAPIC_NUM_PINS KVM_IOAPIC_NUM_PINS
13 #define MAX_NR_RESERVED_IOAPIC_PINS KVM_MAX_IRQ_ROUTES
14 #define IOAPIC_VERSION_ID 0x11 /* IOAPIC version */
15 #define IOAPIC_EDGE_TRIG 0
16 #define IOAPIC_LEVEL_TRIG 1
17 
18 #define IOAPIC_DEFAULT_BASE_ADDRESS 0xfec00000
19 #define IOAPIC_MEM_LENGTH 0x100
20 
21 /* Direct registers. */
22 #define IOAPIC_REG_SELECT 0x00
23 #define IOAPIC_REG_WINDOW 0x10
24 
25 /* Indirect registers. */
26 #define IOAPIC_REG_APIC_ID 0x00 /* x86 IOAPIC only */
27 #define IOAPIC_REG_VERSION 0x01
28 #define IOAPIC_REG_ARB_ID 0x02 /* x86 IOAPIC only */
29 
30 /*ioapic delivery mode*/
31 #define IOAPIC_FIXED 0x0
32 #define IOAPIC_LOWEST_PRIORITY 0x1
33 #define IOAPIC_PMI 0x2
34 #define IOAPIC_NMI 0x4
35 #define IOAPIC_INIT 0x5
36 #define IOAPIC_EXTINT 0x7
37 
38 #define RTC_GSI 8
39 
40 struct dest_map {
41  /* vcpu bitmap where IRQ has been sent */
42  DECLARE_BITMAP(map, KVM_MAX_VCPU_IDS);
43 
44  /*
45  * Vector sent to a given vcpu, only valid when
46  * the vcpu's bit in map is set
47  */
48  u8 vectors[KVM_MAX_VCPU_IDS];
49 };
50 
51 
52 struct rtc_status {
54  struct dest_map dest_map;
55 };
56 
58  u64 bits;
59  struct {
60  u8 vector;
62  u8 dest_mode:1;
64  u8 polarity:1;
65  u8 remote_irr:1;
66  u8 trig_mode:1;
67  u8 mask:1;
68  u8 reserve:7;
69  u8 reserved[4];
70  u8 dest_id;
71  } fields;
72 };
73 
74 struct kvm_ioapic {
76  u32 ioregsel;
77  u32 id;
78  u32 irr;
79  u32 pad;
81  unsigned long irq_states[IOAPIC_NUM_PINS];
82  struct kvm_io_device dev;
83  struct kvm *kvm;
84  spinlock_t lock;
85  struct rtc_status rtc_status;
86  struct delayed_work eoi_inject;
89 };
90 
91 #ifdef DEBUG
92 #define ASSERT(x) \
93 do { \
94  if (!(x)) { \
95  printk(KERN_EMERG "assertion failed %s: %d: %s\n", \
96  __FILE__, __LINE__, #x); \
97  BUG(); \
98  } \
99 } while (0)
100 #else
101 #define ASSERT(x) do { } while (0)
102 #endif
103 
104 static inline int ioapic_in_kernel(struct kvm *kvm)
105 {
106  return irqchip_kernel(kvm);
107 }
108 
109 void kvm_rtc_eoi_tracking_restore_one(struct kvm_vcpu *vcpu);
110 void kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector,
111  int trigger_mode);
112 int kvm_ioapic_init(struct kvm *kvm);
113 void kvm_ioapic_destroy(struct kvm *kvm);
114 int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,
115  int level, bool line_status);
116 void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id);
117 void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
118 void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
119 void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,
120  ulong *ioapic_handled_vectors);
121 void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
122  ulong *ioapic_handled_vectors);
123 #endif
void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors)
Definition: irq_comm.c:412
#define IOAPIC_NUM_PINS
Definition: ioapic.h:12
void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)
Definition: ioapic.c:755
int kvm_ioapic_init(struct kvm *kvm)
Definition: ioapic.c:714
void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)
Definition: ioapic.c:765
int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id, int level, bool line_status)
Definition: ioapic.c:485
static int ioapic_in_kernel(struct kvm *kvm)
Definition: ioapic.h:104
void kvm_rtc_eoi_tracking_restore_one(struct kvm_vcpu *vcpu)
Definition: ioapic.c:139
void kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode)
Definition: ioapic.c:579
void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors)
Definition: ioapic.c:278
void kvm_ioapic_destroy(struct kvm *kvm)
Definition: ioapic.c:740
void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id)
Definition: ioapic.c:502
static int irqchip_kernel(struct kvm *kvm)
Definition: irq.h:76
u8 vectors[KVM_MAX_VCPU_IDS]
Definition: ioapic.h:48
DECLARE_BITMAP(map, KVM_MAX_VCPU_IDS)
u32 pad
Definition: ioapic.h:79
u32 id
Definition: ioapic.h:77
struct delayed_work eoi_inject
Definition: ioapic.h:86
u32 ioregsel
Definition: ioapic.h:76
u64 base_address
Definition: ioapic.h:75
struct kvm * kvm
Definition: ioapic.h:83
u32 irr
Definition: ioapic.h:78
struct kvm_io_device dev
Definition: ioapic.h:82
spinlock_t lock
Definition: ioapic.h:84
union kvm_ioapic_redirect_entry redirtbl[IOAPIC_NUM_PINS]
Definition: ioapic.h:80
unsigned long irq_states[IOAPIC_NUM_PINS]
Definition: ioapic.h:81
u32 irq_eoi[IOAPIC_NUM_PINS]
Definition: ioapic.h:87
u32 irr_delivered
Definition: ioapic.h:88
int pending_eoi
Definition: ioapic.h:53
Definition: ioapic.h:57
u64 bits
Definition: ioapic.h:58
u8 polarity
Definition: ioapic.h:64
u8 trig_mode
Definition: ioapic.h:66
u8 dest_mode
Definition: ioapic.h:62
u8 delivery_status
Definition: ioapic.h:63
u8 delivery_mode
Definition: ioapic.h:61
u8 vector
Definition: ioapic.h:60
u8 reserve
Definition: ioapic.h:68
u8 mask
Definition: ioapic.h:67
struct kvm_ioapic_redirect_entry::@1 fields
u8 reserved[4]
Definition: ioapic.h:69
u8 dest_id
Definition: ioapic.h:70
u8 remote_irr
Definition: ioapic.h:65
int state
Definition: xen.h:0