]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/i386/apic_internal.h
Clean up decorations and whitespace around header guards
[mirror_qemu.git] / include / hw / i386 / apic_internal.h
CommitLineData
dae01685
JK
1/*
2 * APIC support - internal interfaces
3 *
4 * Copyright (c) 2004-2005 Fabrice Bellard
5 * Copyright (c) 2011 Jan Kiszka, Siemens AG
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>
19 */
175de524 20
dae01685
JK
21#ifndef QEMU_APIC_INTERNAL_H
22#define QEMU_APIC_INTERNAL_H
23
20fbcfdd 24#include "cpu.h"
022c62cb 25#include "exec/memory.h"
1de7afc9 26#include "qemu/timer.h"
dae01685
JK
27
28/* APIC Local Vector Table */
29#define APIC_LVT_TIMER 0
30#define APIC_LVT_THERMAL 1
31#define APIC_LVT_PERFORM 2
32#define APIC_LVT_LINT0 3
33#define APIC_LVT_LINT1 4
34#define APIC_LVT_ERROR 5
35#define APIC_LVT_NB 6
36
37/* APIC delivery modes */
38#define APIC_DM_FIXED 0
39#define APIC_DM_LOWPRI 1
40#define APIC_DM_SMI 2
41#define APIC_DM_NMI 4
42#define APIC_DM_INIT 5
43#define APIC_DM_SIPI 6
44#define APIC_DM_EXTINT 7
45
46/* APIC destination mode */
47#define APIC_DESTMODE_FLAT 0xf
48#define APIC_DESTMODE_CLUSTER 1
49
50#define APIC_TRIGGER_EDGE 0
51#define APIC_TRIGGER_LEVEL 1
52
6519d187
PB
53#define APIC_VECTOR_MASK 0xff
54#define APIC_DCR_MASK 0xf
55
56#define APIC_LVT_TIMER_SHIFT 17
57#define APIC_LVT_MASKED_SHIFT 16
58#define APIC_LVT_LEVEL_TRIGGER_SHIFT 15
59#define APIC_LVT_REMOTE_IRR_SHIFT 14
60#define APIC_LVT_INT_POLARITY_SHIFT 13
61#define APIC_LVT_DELIV_STS_SHIFT 12
62#define APIC_LVT_DELIV_MOD_SHIFT 8
63
64#define APIC_LVT_TIMER_TSCDEADLINE (2 << APIC_LVT_TIMER_SHIFT)
b6cfc3c2
PB
65#define APIC_LVT_TIMER_PERIODIC (1 << APIC_LVT_TIMER_SHIFT)
66#define APIC_LVT_MASKED (1 << APIC_LVT_MASKED_SHIFT)
67#define APIC_LVT_LEVEL_TRIGGER (1 << APIC_LVT_LEVEL_TRIGGER_SHIFT)
68#define APIC_LVT_REMOTE_IRR (1 << APIC_LVT_REMOTE_IRR_SHIFT)
6519d187
PB
69#define APIC_LVT_INT_POLARITY (1 << APIC_LVT_INT_POLARITY_SHIFT)
70#define APIC_LVT_DELIV_STS (1 << APIC_LVT_DELIV_STS_SHIFT)
71#define APIC_LVT_DELIV_MOD (7 << APIC_LVT_DELIV_MOD_SHIFT)
72
73#define APIC_ESR_ILL_ADDRESS_SHIFT 7
74#define APIC_ESR_RECV_ILL_VECT_SHIFT 6
75#define APIC_ESR_SEND_ILL_VECT_SHIFT 5
76#define APIC_ESR_RECV_ACCEPT_SHIFT 3
77#define APIC_ESR_SEND_ACCEPT_SHIFT 2
78#define APIC_ESR_RECV_CHECK_SUM_SHIFT 1
dae01685 79
b6cfc3c2 80#define APIC_ESR_ILLEGAL_ADDRESS (1 << APIC_ESR_ILL_ADDRESS_SHIFT)
6519d187
PB
81#define APIC_ESR_RECV_ILLEGAL_VECT (1 << APIC_ESR_RECV_ILL_VECT_SHIFT)
82#define APIC_ESR_SEND_ILLEGAL_VECT (1 << APIC_ESR_SEND_ILL_VECT_SHIFT)
83#define APIC_ESR_RECV_ACCEPT (1 << APIC_ESR_RECV_ACCEPT_SHIFT)
84#define APIC_ESR_SEND_ACCEPT (1 << APIC_ESR_SEND_ACCEPT_SHIFT)
85#define APIC_ESR_RECV_CHECK_SUM (1 << APIC_ESR_RECV_CHECK_SUM_SHIFT)
86#define APIC_ESR_SEND_CHECK_SUM 1
87
88#define APIC_ICR_DEST_SHIFT 24
89#define APIC_ICR_DEST_SHORT_SHIFT 18
90#define APIC_ICR_TRIGGER_MOD_SHIFT 15
91#define APIC_ICR_LEVEL_SHIFT 14
92#define APIC_ICR_DELIV_STS_SHIFT 12
93#define APIC_ICR_DEST_MOD_SHIFT 11
94#define APIC_ICR_DELIV_MOD_SHIFT 8
95
96#define APIC_ICR_DEST_SHORT (3 << APIC_ICR_DEST_SHORT_SHIFT)
97#define APIC_ICR_TRIGGER_MOD (1 << APIC_ICR_TRIGGER_MOD_SHIFT)
98#define APIC_ICR_LEVEL (1 << APIC_ICR_LEVEL_SHIFT)
99#define APIC_ICR_DELIV_STS (1 << APIC_ICR_DELIV_STS_SHIFT)
100#define APIC_ICR_DEST_MOD (1 << APIC_ICR_DEST_MOD_SHIFT)
101#define APIC_ICR_DELIV_MOD (7 << APIC_ICR_DELIV_MOD_SHIFT)
102
103#define APIC_PR_CLASS_SHIFT 4
104#define APIC_PR_SUB_CLASS 0xf
105
106#define APIC_LOGDEST_XAPIC_SHIFT 4
107#define APIC_LOGDEST_XAPIC_ID 0xf
108
109#define APIC_LOGDEST_X2APIC_SHIFT 16
110#define APIC_LOGDEST_X2APIC_ID 0xffff
111
112#define APIC_SPURIO_FOCUS_SHIFT 9
113#define APIC_SPURIO_ENABLED_SHIFT 8
114
115#define APIC_SPURIO_FOCUS (1 << APIC_SPURIO_FOCUS_SHIFT)
116#define APIC_SPURIO_ENABLED (1 << APIC_SPURIO_ENABLED_SHIFT)
dae01685 117
b6cfc3c2
PB
118#define APIC_SV_DIRECTED_IO (1 << 12)
119#define APIC_SV_ENABLE (1 << 8)
dae01685 120
e5ad936b
JK
121#define VAPIC_ENABLE_BIT 0
122#define VAPIC_ENABLE_MASK (1 << VAPIC_ENABLE_BIT)
123
dae01685
JK
124#define MAX_APICS 255
125
dae01685
JK
126typedef struct APICCommonState APICCommonState;
127
999e12bb
AL
128#define TYPE_APIC_COMMON "apic-common"
129#define APIC_COMMON(obj) \
130 OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC_COMMON)
131#define APIC_COMMON_CLASS(klass) \
132 OBJECT_CLASS_CHECK(APICCommonClass, (klass), TYPE_APIC_COMMON)
133#define APIC_COMMON_GET_CLASS(obj) \
134 OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
135
136typedef struct APICCommonClass
137{
46232aaa 138 DeviceClass parent_class;
999e12bb 139
ff6986ce 140 DeviceRealize realize;
999e12bb
AL
141 void (*set_base)(APICCommonState *s, uint64_t val);
142 void (*set_tpr)(APICCommonState *s, uint8_t val);
e5ad936b
JK
143 uint8_t (*get_tpr)(APICCommonState *s);
144 void (*enable_tpr_reporting)(APICCommonState *s, bool enable);
145 void (*vapic_base_update)(APICCommonState *s);
999e12bb 146 void (*external_nmi)(APICCommonState *s);
e5ad936b 147 void (*pre_save)(APICCommonState *s);
999e12bb 148 void (*post_load)(APICCommonState *s);
575a6f40 149 void (*reset)(APICCommonState *s);
999e12bb
AL
150} APICCommonClass;
151
dae01685 152struct APICCommonState {
46232aaa
CF
153 /*< private >*/
154 DeviceState parent_obj;
155 /*< public >*/
60671e58 156
dae01685 157 MemoryRegion io_memory;
60671e58 158 X86CPU *cpu;
dae01685
JK
159 uint32_t apicbase;
160 uint8_t id;
aa93200b 161 uint8_t version;
dae01685
JK
162 uint8_t arb_id;
163 uint8_t tpr;
164 uint32_t spurious_vec;
165 uint8_t log_dest;
166 uint8_t dest_mode;
167 uint32_t isr[8]; /* in service register */
168 uint32_t tmr[8]; /* trigger mode register */
169 uint32_t irr[8]; /* interrupt request register */
170 uint32_t lvt[APIC_LVT_NB];
171 uint32_t esr; /* error register */
172 uint32_t icr[2];
173
174 uint32_t divide_conf;
175 int count_shift;
176 uint32_t initial_count;
177 int64_t initial_count_load_time;
178 int64_t next_time;
179 int idx;
180 QEMUTimer *timer;
7a380ca3 181 int64_t timer_expiry;
dae01685
JK
182 int sipi_vector;
183 int wait_for_sipi;
e5ad936b
JK
184
185 uint32_t vapic_control;
186 DeviceState *vapic;
a8170e5e 187 hwaddr vapic_paddr; /* note: persistence via kvmvapic */
dae01685
JK
188};
189
e5ad936b
JK
190typedef struct VAPICState {
191 uint8_t tpr;
192 uint8_t isr;
193 uint8_t zero;
194 uint8_t irr;
195 uint8_t enabled;
196} QEMU_PACKED VAPICState;
197
198extern bool apic_report_tpr_access;
199
dae01685 200void apic_report_irq_delivered(int delivered);
7a380ca3 201bool apic_next_timer(APICCommonState *s, int64_t current_time);
e5ad936b 202void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
a8170e5e 203void apic_enable_vapic(DeviceState *d, hwaddr paddr);
e5ad936b 204
d77953b9 205void vapic_report_tpr_access(DeviceState *dev, CPUState *cpu, target_ulong ip,
e5ad936b 206 TPRAccess access);
dae01685 207
82a5e042
PB
208int apic_get_ppr(APICCommonState *s);
209
210static inline void apic_set_bit(uint32_t *tab, int index)
211{
212 int i, mask;
213 i = index >> 5;
214 mask = 1 << (index & 0x1f);
215 tab[i] |= mask;
216}
217
218static inline int apic_get_bit(uint32_t *tab, int index)
219{
220 int i, mask;
221 i = index >> 5;
222 mask = 1 << (index & 0x1f);
223 return !!(tab[i] & mask);
224}
225
175de524 226#endif /* QEMU_APIC_INTERNAL_H */