blob: d66a476aac36c1028d1e5ebaea5b343661ff43e4 [file] [log] [blame]
bellard574bbf72005-01-03 23:27:31 +00001/*
2 * APIC support
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard574bbf72005-01-03 23:27:31 +00004 * Copyright (c) 2004-2005 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000017 * License along with this library; if not, see <http://www.gnu.org/licenses/>
bellard574bbf72005-01-03 23:27:31 +000018 */
Jan Kiszka5d62c432012-07-09 16:42:32 +020019#include "qemu-thread.h"
Jan Kiszkadae01682011-10-16 11:16:36 +020020#include "apic_internal.h"
Blue Swirlaa28b9b2010-03-21 19:46:26 +000021#include "apic.h"
Jan Kiszka0280b572011-02-03 22:54:11 +010022#include "ioapic.h"
Michael S. Tsirkina2cb15b2012-12-12 14:24:50 +020023#include "pci/msi.h"
aurel32bb7e7292008-10-12 20:16:03 +000024#include "host-utils.h"
Blue Swirld8023f32010-10-20 16:41:28 +000025#include "trace.h"
Jan Kiszkad96e1732011-10-07 09:19:37 +020026#include "pc.h"
Anthony PERARD9886c232012-06-21 15:41:28 +000027#include "apic-msidef.h"
bellard574bbf72005-01-03 23:27:31 +000028
bellardd3e9db92005-12-17 01:27:28 +000029#define MAX_APIC_WORDS 8
30
Jan Kiszkae5ad9362012-02-17 18:31:19 +010031#define SYNC_FROM_VAPIC 0x1
32#define SYNC_TO_VAPIC 0x2
33#define SYNC_ISR_IRR_TO_VAPIC 0x4
34
Jan Kiszkadae01682011-10-16 11:16:36 +020035static APICCommonState *local_apics[MAX_APICS + 1];
Michael S. Tsirkin54c96da2009-06-21 19:50:03 +030036
Jan Kiszkadae01682011-10-16 11:16:36 +020037static void apic_set_irq(APICCommonState *s, int vector_num, int trigger_mode);
38static void apic_update_irq(APICCommonState *s);
aliguori610626a2009-03-12 20:25:12 +000039static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask,
40 uint8_t dest, uint8_t dest_mode);
bellardd592d302005-07-23 19:05:37 +000041
aurel323b63c042008-12-06 10:46:35 +000042/* Find first bit starting from msb */
43static int fls_bit(uint32_t value)
44{
45 return 31 - clz32(value);
46}
47
aurel32e95f5492008-10-12 00:53:17 +000048/* Find first bit starting from lsb */
bellardd3e9db92005-12-17 01:27:28 +000049static int ffs_bit(uint32_t value)
50{
aurel32bb7e7292008-10-12 20:16:03 +000051 return ctz32(value);
bellardd3e9db92005-12-17 01:27:28 +000052}
53
54static inline void set_bit(uint32_t *tab, int index)
55{
56 int i, mask;
57 i = index >> 5;
58 mask = 1 << (index & 0x1f);
59 tab[i] |= mask;
60}
61
62static inline void reset_bit(uint32_t *tab, int index)
63{
64 int i, mask;
65 i = index >> 5;
66 mask = 1 << (index & 0x1f);
67 tab[i] &= ~mask;
68}
69
aliguori73822ec2009-01-15 20:11:34 +000070static inline int get_bit(uint32_t *tab, int index)
71{
72 int i, mask;
73 i = index >> 5;
74 mask = 1 << (index & 0x1f);
75 return !!(tab[i] & mask);
76}
77
Jan Kiszkae5ad9362012-02-17 18:31:19 +010078/* return -1 if no bit is set */
79static int get_highest_priority_int(uint32_t *tab)
80{
81 int i;
82 for (i = 7; i >= 0; i--) {
83 if (tab[i] != 0) {
84 return i * 32 + fls_bit(tab[i]);
85 }
86 }
87 return -1;
88}
89
90static void apic_sync_vapic(APICCommonState *s, int sync_type)
91{
92 VAPICState vapic_state;
93 size_t length;
94 off_t start;
95 int vector;
96
97 if (!s->vapic_paddr) {
98 return;
99 }
100 if (sync_type & SYNC_FROM_VAPIC) {
101 cpu_physical_memory_rw(s->vapic_paddr, (void *)&vapic_state,
102 sizeof(vapic_state), 0);
103 s->tpr = vapic_state.tpr;
104 }
105 if (sync_type & (SYNC_TO_VAPIC | SYNC_ISR_IRR_TO_VAPIC)) {
106 start = offsetof(VAPICState, isr);
107 length = offsetof(VAPICState, enabled) - offsetof(VAPICState, isr);
108
109 if (sync_type & SYNC_TO_VAPIC) {
Andreas Färber60e82572012-05-02 22:23:49 +0200110 assert(qemu_cpu_is_self(CPU(s->cpu)));
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100111
112 vapic_state.tpr = s->tpr;
113 vapic_state.enabled = 1;
114 start = 0;
115 length = sizeof(VAPICState);
116 }
117
118 vector = get_highest_priority_int(s->isr);
119 if (vector < 0) {
120 vector = 0;
121 }
122 vapic_state.isr = vector & 0xf0;
123
124 vapic_state.zero = 0;
125
126 vector = get_highest_priority_int(s->irr);
127 if (vector < 0) {
128 vector = 0;
129 }
130 vapic_state.irr = vector & 0xff;
131
132 cpu_physical_memory_write_rom(s->vapic_paddr + start,
133 ((void *)&vapic_state) + start, length);
134 }
135}
136
137static void apic_vapic_base_update(APICCommonState *s)
138{
139 apic_sync_vapic(s, SYNC_TO_VAPIC);
140}
141
Jan Kiszkadae01682011-10-16 11:16:36 +0200142static void apic_local_deliver(APICCommonState *s, int vector)
aurel32a5b38b52008-04-13 16:08:30 +0000143{
aurel32a5b38b52008-04-13 16:08:30 +0000144 uint32_t lvt = s->lvt[vector];
145 int trigger_mode;
146
Blue Swirld8023f32010-10-20 16:41:28 +0000147 trace_apic_local_deliver(vector, (lvt >> 8) & 7);
148
aurel32a5b38b52008-04-13 16:08:30 +0000149 if (lvt & APIC_LVT_MASKED)
150 return;
151
152 switch ((lvt >> 8) & 7) {
153 case APIC_DM_SMI:
Andreas Färber60671e52012-10-10 14:10:07 +0200154 cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_SMI);
aurel32a5b38b52008-04-13 16:08:30 +0000155 break;
156
157 case APIC_DM_NMI:
Andreas Färber60671e52012-10-10 14:10:07 +0200158 cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_NMI);
aurel32a5b38b52008-04-13 16:08:30 +0000159 break;
160
161 case APIC_DM_EXTINT:
Andreas Färber60671e52012-10-10 14:10:07 +0200162 cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
aurel32a5b38b52008-04-13 16:08:30 +0000163 break;
164
165 case APIC_DM_FIXED:
166 trigger_mode = APIC_TRIGGER_EDGE;
167 if ((vector == APIC_LVT_LINT0 || vector == APIC_LVT_LINT1) &&
168 (lvt & APIC_LVT_LEVEL_TRIGGER))
169 trigger_mode = APIC_TRIGGER_LEVEL;
170 apic_set_irq(s, lvt & 0xff, trigger_mode);
171 }
172}
173
Blue Swirl92a16d72010-06-19 07:47:42 +0000174void apic_deliver_pic_intr(DeviceState *d, int level)
aurel321a7de942008-08-21 03:14:52 +0000175{
Jan Kiszkadae01682011-10-16 11:16:36 +0200176 APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
Blue Swirl92a16d72010-06-19 07:47:42 +0000177
Blue Swirlcf6d64b2010-06-19 10:42:08 +0300178 if (level) {
179 apic_local_deliver(s, APIC_LVT_LINT0);
180 } else {
aurel321a7de942008-08-21 03:14:52 +0000181 uint32_t lvt = s->lvt[APIC_LVT_LINT0];
182
183 switch ((lvt >> 8) & 7) {
184 case APIC_DM_FIXED:
185 if (!(lvt & APIC_LVT_LEVEL_TRIGGER))
186 break;
187 reset_bit(s->irr, lvt & 0xff);
188 /* fall through */
189 case APIC_DM_EXTINT:
Andreas Färber60671e52012-10-10 14:10:07 +0200190 cpu_reset_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
aurel321a7de942008-08-21 03:14:52 +0000191 break;
192 }
193 }
194}
195
Jan Kiszkadae01682011-10-16 11:16:36 +0200196static void apic_external_nmi(APICCommonState *s)
Jan Kiszka02c09192011-10-18 00:00:06 +0800197{
Jan Kiszka02c09192011-10-18 00:00:06 +0800198 apic_local_deliver(s, APIC_LVT_LINT1);
199}
200
bellardd3e9db92005-12-17 01:27:28 +0000201#define foreach_apic(apic, deliver_bitmask, code) \
202{\
203 int __i, __j, __mask;\
204 for(__i = 0; __i < MAX_APIC_WORDS; __i++) {\
205 __mask = deliver_bitmask[__i];\
206 if (__mask) {\
207 for(__j = 0; __j < 32; __j++) {\
208 if (__mask & (1 << __j)) {\
209 apic = local_apics[__i * 32 + __j];\
210 if (apic) {\
211 code;\
212 }\
213 }\
214 }\
215 }\
216 }\
217}
218
ths5fafdf22007-09-16 21:08:06 +0000219static void apic_bus_deliver(const uint32_t *deliver_bitmask,
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200220 uint8_t delivery_mode, uint8_t vector_num,
bellardd592d302005-07-23 19:05:37 +0000221 uint8_t trigger_mode)
222{
Jan Kiszkadae01682011-10-16 11:16:36 +0200223 APICCommonState *apic_iter;
bellardd592d302005-07-23 19:05:37 +0000224
225 switch (delivery_mode) {
226 case APIC_DM_LOWPRI:
bellard8dd69b82005-11-23 20:59:44 +0000227 /* XXX: search for focus processor, arbitration */
bellardd3e9db92005-12-17 01:27:28 +0000228 {
229 int i, d;
230 d = -1;
231 for(i = 0; i < MAX_APIC_WORDS; i++) {
232 if (deliver_bitmask[i]) {
233 d = i * 32 + ffs_bit(deliver_bitmask[i]);
234 break;
235 }
236 }
237 if (d >= 0) {
238 apic_iter = local_apics[d];
239 if (apic_iter) {
240 apic_set_irq(apic_iter, vector_num, trigger_mode);
241 }
242 }
bellard8dd69b82005-11-23 20:59:44 +0000243 }
bellardd3e9db92005-12-17 01:27:28 +0000244 return;
bellard8dd69b82005-11-23 20:59:44 +0000245
bellardd592d302005-07-23 19:05:37 +0000246 case APIC_DM_FIXED:
bellardd592d302005-07-23 19:05:37 +0000247 break;
248
249 case APIC_DM_SMI:
aurel32e2eb9d32008-04-13 16:08:23 +0000250 foreach_apic(apic_iter, deliver_bitmask,
Andreas Färber60671e52012-10-10 14:10:07 +0200251 cpu_interrupt(&apic_iter->cpu->env, CPU_INTERRUPT_SMI)
252 );
aurel32e2eb9d32008-04-13 16:08:23 +0000253 return;
254
bellardd592d302005-07-23 19:05:37 +0000255 case APIC_DM_NMI:
aurel32e2eb9d32008-04-13 16:08:23 +0000256 foreach_apic(apic_iter, deliver_bitmask,
Andreas Färber60671e52012-10-10 14:10:07 +0200257 cpu_interrupt(&apic_iter->cpu->env, CPU_INTERRUPT_NMI)
258 );
aurel32e2eb9d32008-04-13 16:08:23 +0000259 return;
bellardd592d302005-07-23 19:05:37 +0000260
261 case APIC_DM_INIT:
262 /* normal INIT IPI sent to processors */
ths5fafdf22007-09-16 21:08:06 +0000263 foreach_apic(apic_iter, deliver_bitmask,
Andreas Färber60671e52012-10-10 14:10:07 +0200264 cpu_interrupt(&apic_iter->cpu->env,
265 CPU_INTERRUPT_INIT)
266 );
bellardd592d302005-07-23 19:05:37 +0000267 return;
ths3b46e622007-09-17 08:09:54 +0000268
bellardd592d302005-07-23 19:05:37 +0000269 case APIC_DM_EXTINT:
bellardb1fc0342005-07-23 21:43:15 +0000270 /* handled in I/O APIC code */
bellardd592d302005-07-23 19:05:37 +0000271 break;
272
273 default:
274 return;
275 }
276
ths5fafdf22007-09-16 21:08:06 +0000277 foreach_apic(apic_iter, deliver_bitmask,
bellardd3e9db92005-12-17 01:27:28 +0000278 apic_set_irq(apic_iter, vector_num, trigger_mode) );
bellardd592d302005-07-23 19:05:37 +0000279}
bellard574bbf72005-01-03 23:27:31 +0000280
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200281void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode,
282 uint8_t vector_num, uint8_t trigger_mode)
aliguori610626a2009-03-12 20:25:12 +0000283{
284 uint32_t deliver_bitmask[MAX_APIC_WORDS];
285
Blue Swirld8023f32010-10-20 16:41:28 +0000286 trace_apic_deliver_irq(dest, dest_mode, delivery_mode, vector_num,
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200287 trigger_mode);
Blue Swirld8023f32010-10-20 16:41:28 +0000288
aliguori610626a2009-03-12 20:25:12 +0000289 apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode);
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200290 apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode);
aliguori610626a2009-03-12 20:25:12 +0000291}
292
Jan Kiszkadae01682011-10-16 11:16:36 +0200293static void apic_set_base(APICCommonState *s, uint64_t val)
bellard574bbf72005-01-03 23:27:31 +0000294{
ths5fafdf22007-09-16 21:08:06 +0000295 s->apicbase = (val & 0xfffff000) |
bellard574bbf72005-01-03 23:27:31 +0000296 (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
297 /* if disabled, cannot be enabled again */
298 if (!(val & MSR_IA32_APICBASE_ENABLE)) {
299 s->apicbase &= ~MSR_IA32_APICBASE_ENABLE;
Andreas Färber60671e52012-10-10 14:10:07 +0200300 cpu_clear_apic_feature(&s->cpu->env);
bellard574bbf72005-01-03 23:27:31 +0000301 s->spurious_vec &= ~APIC_SV_ENABLE;
302 }
303}
304
Jan Kiszkadae01682011-10-16 11:16:36 +0200305static void apic_set_tpr(APICCommonState *s, uint8_t val)
bellard574bbf72005-01-03 23:27:31 +0000306{
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100307 /* Updates from cr8 are ignored while the VAPIC is active */
308 if (!s->vapic_paddr) {
309 s->tpr = val << 4;
310 apic_update_irq(s);
311 }
bellard9230e662005-01-23 20:46:56 +0000312}
313
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100314static uint8_t apic_get_tpr(APICCommonState *s)
bellardd592d302005-07-23 19:05:37 +0000315{
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100316 apic_sync_vapic(s, SYNC_FROM_VAPIC);
317 return s->tpr >> 4;
bellardd592d302005-07-23 19:05:37 +0000318}
319
Jan Kiszkadae01682011-10-16 11:16:36 +0200320static int apic_get_ppr(APICCommonState *s)
bellard574bbf72005-01-03 23:27:31 +0000321{
322 int tpr, isrv, ppr;
323
324 tpr = (s->tpr >> 4);
325 isrv = get_highest_priority_int(s->isr);
326 if (isrv < 0)
327 isrv = 0;
328 isrv >>= 4;
329 if (tpr >= isrv)
330 ppr = s->tpr;
331 else
332 ppr = isrv << 4;
333 return ppr;
334}
335
Jan Kiszkadae01682011-10-16 11:16:36 +0200336static int apic_get_arb_pri(APICCommonState *s)
bellardd592d302005-07-23 19:05:37 +0000337{
338 /* XXX: arbitration */
339 return 0;
340}
341
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200342
343/*
344 * <0 - low prio interrupt,
345 * 0 - no interrupt,
346 * >0 - interrupt number
347 */
Jan Kiszkadae01682011-10-16 11:16:36 +0200348static int apic_irq_pending(APICCommonState *s)
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200349{
350 int irrv, ppr;
351 irrv = get_highest_priority_int(s->irr);
352 if (irrv < 0) {
353 return 0;
354 }
355 ppr = apic_get_ppr(s);
356 if (ppr && (irrv & 0xf0) <= (ppr & 0xf0)) {
357 return -1;
358 }
359
360 return irrv;
361}
362
bellard574bbf72005-01-03 23:27:31 +0000363/* signal the CPU if an irq is pending */
Jan Kiszkadae01682011-10-16 11:16:36 +0200364static void apic_update_irq(APICCommonState *s)
bellard574bbf72005-01-03 23:27:31 +0000365{
Andreas Färber60e82572012-05-02 22:23:49 +0200366 CPUState *cpu = CPU(s->cpu);
367
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200368 if (!(s->spurious_vec & APIC_SV_ENABLE)) {
bellardd592d302005-07-23 19:05:37 +0000369 return;
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200370 }
Andreas Färber60e82572012-05-02 22:23:49 +0200371 if (!qemu_cpu_is_self(cpu)) {
Andreas Färber60671e52012-10-10 14:10:07 +0200372 cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_POLL);
Jan Kiszka5d62c432012-07-09 16:42:32 +0200373 } else if (apic_irq_pending(s) > 0) {
Andreas Färber60671e52012-10-10 14:10:07 +0200374 cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_HARD);
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200375 }
bellard574bbf72005-01-03 23:27:31 +0000376}
377
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100378void apic_poll_irq(DeviceState *d)
379{
380 APICCommonState *s = APIC_COMMON(d);
381
382 apic_sync_vapic(s, SYNC_FROM_VAPIC);
383 apic_update_irq(s);
384}
385
Jan Kiszkadae01682011-10-16 11:16:36 +0200386static void apic_set_irq(APICCommonState *s, int vector_num, int trigger_mode)
bellard574bbf72005-01-03 23:27:31 +0000387{
Jan Kiszka343270e2011-12-13 15:39:04 +0100388 apic_report_irq_delivered(!get_bit(s->irr, vector_num));
aliguori73822ec2009-01-15 20:11:34 +0000389
bellard574bbf72005-01-03 23:27:31 +0000390 set_bit(s->irr, vector_num);
391 if (trigger_mode)
392 set_bit(s->tmr, vector_num);
393 else
394 reset_bit(s->tmr, vector_num);
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100395 if (s->vapic_paddr) {
396 apic_sync_vapic(s, SYNC_ISR_IRR_TO_VAPIC);
397 /*
398 * The vcpu thread needs to see the new IRR before we pull its current
399 * TPR value. That way, if we miss a lowering of the TRP, the guest
400 * has the chance to notice the new IRR and poll for IRQs on its own.
401 */
402 smp_wmb();
403 apic_sync_vapic(s, SYNC_FROM_VAPIC);
404 }
bellard574bbf72005-01-03 23:27:31 +0000405 apic_update_irq(s);
406}
407
Jan Kiszkadae01682011-10-16 11:16:36 +0200408static void apic_eoi(APICCommonState *s)
bellard574bbf72005-01-03 23:27:31 +0000409{
410 int isrv;
411 isrv = get_highest_priority_int(s->isr);
412 if (isrv < 0)
413 return;
414 reset_bit(s->isr, isrv);
Jan Kiszka0280b572011-02-03 22:54:11 +0100415 if (!(s->spurious_vec & APIC_SV_DIRECTED_IO) && get_bit(s->tmr, isrv)) {
416 ioapic_eoi_broadcast(isrv);
417 }
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100418 apic_sync_vapic(s, SYNC_FROM_VAPIC | SYNC_TO_VAPIC);
bellard574bbf72005-01-03 23:27:31 +0000419 apic_update_irq(s);
420}
421
Gleb Natapov678e12c2009-06-10 15:40:48 +0300422static int apic_find_dest(uint8_t dest)
423{
Jan Kiszkadae01682011-10-16 11:16:36 +0200424 APICCommonState *apic = local_apics[dest];
Gleb Natapov678e12c2009-06-10 15:40:48 +0300425 int i;
426
427 if (apic && apic->id == dest)
428 return dest; /* shortcut in case apic->id == apic->idx */
429
430 for (i = 0; i < MAX_APICS; i++) {
431 apic = local_apics[i];
432 if (apic && apic->id == dest)
433 return i;
Alex Williamsonb538e532010-11-05 16:01:29 -0600434 if (!apic)
435 break;
Gleb Natapov678e12c2009-06-10 15:40:48 +0300436 }
437
438 return -1;
439}
440
bellardd3e9db92005-12-17 01:27:28 +0000441static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask,
442 uint8_t dest, uint8_t dest_mode)
bellardd592d302005-07-23 19:05:37 +0000443{
Jan Kiszkadae01682011-10-16 11:16:36 +0200444 APICCommonState *apic_iter;
bellardd3e9db92005-12-17 01:27:28 +0000445 int i;
bellardd592d302005-07-23 19:05:37 +0000446
447 if (dest_mode == 0) {
bellardd3e9db92005-12-17 01:27:28 +0000448 if (dest == 0xff) {
449 memset(deliver_bitmask, 0xff, MAX_APIC_WORDS * sizeof(uint32_t));
450 } else {
Gleb Natapov678e12c2009-06-10 15:40:48 +0300451 int idx = apic_find_dest(dest);
bellardd3e9db92005-12-17 01:27:28 +0000452 memset(deliver_bitmask, 0x00, MAX_APIC_WORDS * sizeof(uint32_t));
Gleb Natapov678e12c2009-06-10 15:40:48 +0300453 if (idx >= 0)
454 set_bit(deliver_bitmask, idx);
bellardd3e9db92005-12-17 01:27:28 +0000455 }
bellardd592d302005-07-23 19:05:37 +0000456 } else {
457 /* XXX: cluster mode */
bellardd3e9db92005-12-17 01:27:28 +0000458 memset(deliver_bitmask, 0x00, MAX_APIC_WORDS * sizeof(uint32_t));
459 for(i = 0; i < MAX_APICS; i++) {
460 apic_iter = local_apics[i];
461 if (apic_iter) {
462 if (apic_iter->dest_mode == 0xf) {
463 if (dest & apic_iter->log_dest)
464 set_bit(deliver_bitmask, i);
465 } else if (apic_iter->dest_mode == 0x0) {
466 if ((dest & 0xf0) == (apic_iter->log_dest & 0xf0) &&
467 (dest & apic_iter->log_dest & 0x0f)) {
468 set_bit(deliver_bitmask, i);
469 }
470 }
Alex Williamsonb538e532010-11-05 16:01:29 -0600471 } else {
472 break;
bellardd3e9db92005-12-17 01:27:28 +0000473 }
bellardd592d302005-07-23 19:05:37 +0000474 }
475 }
bellardd592d302005-07-23 19:05:37 +0000476}
477
Jan Kiszkadae01682011-10-16 11:16:36 +0200478static void apic_startup(APICCommonState *s, int vector_num)
bellarde0fd8782005-11-21 23:26:26 +0000479{
Gleb Natapovb09ea7d2009-06-17 23:26:59 +0300480 s->sipi_vector = vector_num;
Andreas Färber60671e52012-10-10 14:10:07 +0200481 cpu_interrupt(&s->cpu->env, CPU_INTERRUPT_SIPI);
Gleb Natapovb09ea7d2009-06-17 23:26:59 +0300482}
483
Blue Swirl92a16d72010-06-19 07:47:42 +0000484void apic_sipi(DeviceState *d)
Gleb Natapovb09ea7d2009-06-17 23:26:59 +0300485{
Jan Kiszkadae01682011-10-16 11:16:36 +0200486 APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
Blue Swirl92a16d72010-06-19 07:47:42 +0000487
Andreas Färber60671e52012-10-10 14:10:07 +0200488 cpu_reset_interrupt(&s->cpu->env, CPU_INTERRUPT_SIPI);
Gleb Natapovb09ea7d2009-06-17 23:26:59 +0300489
490 if (!s->wait_for_sipi)
bellarde0fd8782005-11-21 23:26:26 +0000491 return;
Andreas Färbere9f9d6b2012-05-03 15:37:01 +0200492 cpu_x86_load_seg_cache_sipi(s->cpu, s->sipi_vector);
Gleb Natapovb09ea7d2009-06-17 23:26:59 +0300493 s->wait_for_sipi = 0;
bellarde0fd8782005-11-21 23:26:26 +0000494}
495
Blue Swirl92a16d72010-06-19 07:47:42 +0000496static void apic_deliver(DeviceState *d, uint8_t dest, uint8_t dest_mode,
bellardd592d302005-07-23 19:05:37 +0000497 uint8_t delivery_mode, uint8_t vector_num,
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200498 uint8_t trigger_mode)
bellardd592d302005-07-23 19:05:37 +0000499{
Jan Kiszkadae01682011-10-16 11:16:36 +0200500 APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
bellardd3e9db92005-12-17 01:27:28 +0000501 uint32_t deliver_bitmask[MAX_APIC_WORDS];
bellardd592d302005-07-23 19:05:37 +0000502 int dest_shorthand = (s->icr[0] >> 18) & 3;
Jan Kiszkadae01682011-10-16 11:16:36 +0200503 APICCommonState *apic_iter;
bellardd592d302005-07-23 19:05:37 +0000504
bellarde0fd8782005-11-21 23:26:26 +0000505 switch (dest_shorthand) {
bellardd3e9db92005-12-17 01:27:28 +0000506 case 0:
507 apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode);
508 break;
509 case 1:
510 memset(deliver_bitmask, 0x00, sizeof(deliver_bitmask));
Gleb Natapov678e12c2009-06-10 15:40:48 +0300511 set_bit(deliver_bitmask, s->idx);
bellardd3e9db92005-12-17 01:27:28 +0000512 break;
513 case 2:
514 memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask));
515 break;
516 case 3:
517 memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask));
Gleb Natapov678e12c2009-06-10 15:40:48 +0300518 reset_bit(deliver_bitmask, s->idx);
bellardd3e9db92005-12-17 01:27:28 +0000519 break;
bellarde0fd8782005-11-21 23:26:26 +0000520 }
521
bellardd592d302005-07-23 19:05:37 +0000522 switch (delivery_mode) {
bellardd592d302005-07-23 19:05:37 +0000523 case APIC_DM_INIT:
524 {
525 int trig_mode = (s->icr[0] >> 15) & 1;
526 int level = (s->icr[0] >> 14) & 1;
527 if (level == 0 && trig_mode == 1) {
ths5fafdf22007-09-16 21:08:06 +0000528 foreach_apic(apic_iter, deliver_bitmask,
bellardd3e9db92005-12-17 01:27:28 +0000529 apic_iter->arb_id = apic_iter->id );
bellardd592d302005-07-23 19:05:37 +0000530 return;
531 }
532 }
533 break;
534
535 case APIC_DM_SIPI:
ths5fafdf22007-09-16 21:08:06 +0000536 foreach_apic(apic_iter, deliver_bitmask,
bellardd3e9db92005-12-17 01:27:28 +0000537 apic_startup(apic_iter, vector_num) );
bellardd592d302005-07-23 19:05:37 +0000538 return;
539 }
540
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200541 apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode);
bellardd592d302005-07-23 19:05:37 +0000542}
543
Jan Kiszkaa94820d2012-07-09 16:42:31 +0200544static bool apic_check_pic(APICCommonState *s)
545{
546 if (!apic_accept_pic_intr(&s->busdev.qdev) || !pic_get_output(isa_pic)) {
547 return false;
548 }
549 apic_deliver_pic_intr(&s->busdev.qdev, 1);
550 return true;
551}
552
Blue Swirl92a16d72010-06-19 07:47:42 +0000553int apic_get_interrupt(DeviceState *d)
bellard574bbf72005-01-03 23:27:31 +0000554{
Jan Kiszkadae01682011-10-16 11:16:36 +0200555 APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
bellard574bbf72005-01-03 23:27:31 +0000556 int intno;
557
558 /* if the APIC is installed or enabled, we let the 8259 handle the
559 IRQs */
560 if (!s)
561 return -1;
562 if (!(s->spurious_vec & APIC_SV_ENABLE))
563 return -1;
ths3b46e622007-09-17 08:09:54 +0000564
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100565 apic_sync_vapic(s, SYNC_FROM_VAPIC);
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200566 intno = apic_irq_pending(s);
567
568 if (intno == 0) {
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100569 apic_sync_vapic(s, SYNC_TO_VAPIC);
bellard574bbf72005-01-03 23:27:31 +0000570 return -1;
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200571 } else if (intno < 0) {
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100572 apic_sync_vapic(s, SYNC_TO_VAPIC);
bellardd592d302005-07-23 19:05:37 +0000573 return s->spurious_vec & 0xff;
Gleb Natapov0fbfbb52011-02-07 16:14:44 +0200574 }
bellardb4511722006-10-08 18:20:51 +0000575 reset_bit(s->irr, intno);
bellard574bbf72005-01-03 23:27:31 +0000576 set_bit(s->isr, intno);
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100577 apic_sync_vapic(s, SYNC_TO_VAPIC);
Jan Kiszka3db36592012-07-09 16:42:30 +0200578
579 /* re-inject if there is still a pending PIC interrupt */
Jan Kiszkaa94820d2012-07-09 16:42:31 +0200580 apic_check_pic(s);
Jan Kiszka3db36592012-07-09 16:42:30 +0200581
bellard574bbf72005-01-03 23:27:31 +0000582 apic_update_irq(s);
Jan Kiszka3db36592012-07-09 16:42:30 +0200583
bellard574bbf72005-01-03 23:27:31 +0000584 return intno;
585}
586
Blue Swirl92a16d72010-06-19 07:47:42 +0000587int apic_accept_pic_intr(DeviceState *d)
ths0e21e122007-10-09 03:08:56 +0000588{
Jan Kiszkadae01682011-10-16 11:16:36 +0200589 APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d);
ths0e21e122007-10-09 03:08:56 +0000590 uint32_t lvt0;
591
592 if (!s)
593 return -1;
594
595 lvt0 = s->lvt[APIC_LVT_LINT0];
596
aurel32a5b38b52008-04-13 16:08:30 +0000597 if ((s->apicbase & MSR_IA32_APICBASE_ENABLE) == 0 ||
598 (lvt0 & APIC_LVT_MASKED) == 0)
ths0e21e122007-10-09 03:08:56 +0000599 return 1;
600
601 return 0;
602}
603
Jan Kiszkadae01682011-10-16 11:16:36 +0200604static uint32_t apic_get_current_count(APICCommonState *s)
bellard574bbf72005-01-03 23:27:31 +0000605{
606 int64_t d;
607 uint32_t val;
Paolo Bonzini74475452011-03-11 16:47:48 +0100608 d = (qemu_get_clock_ns(vm_clock) - s->initial_count_load_time) >>
bellard574bbf72005-01-03 23:27:31 +0000609 s->count_shift;
610 if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) {
611 /* periodic */
bellardd592d302005-07-23 19:05:37 +0000612 val = s->initial_count - (d % ((uint64_t)s->initial_count + 1));
bellard574bbf72005-01-03 23:27:31 +0000613 } else {
614 if (d >= s->initial_count)
615 val = 0;
616 else
617 val = s->initial_count - d;
618 }
619 return val;
620}
621
Jan Kiszkadae01682011-10-16 11:16:36 +0200622static void apic_timer_update(APICCommonState *s, int64_t current_time)
bellard574bbf72005-01-03 23:27:31 +0000623{
Jan Kiszka7a380ca2011-10-16 12:19:12 +0200624 if (apic_next_timer(s, current_time)) {
625 qemu_mod_timer(s->timer, s->next_time);
bellard574bbf72005-01-03 23:27:31 +0000626 } else {
bellard574bbf72005-01-03 23:27:31 +0000627 qemu_del_timer(s->timer);
628 }
629}
630
631static void apic_timer(void *opaque)
632{
Jan Kiszkadae01682011-10-16 11:16:36 +0200633 APICCommonState *s = opaque;
bellard574bbf72005-01-03 23:27:31 +0000634
Blue Swirlcf6d64b2010-06-19 10:42:08 +0300635 apic_local_deliver(s, APIC_LVT_TIMER);
bellard574bbf72005-01-03 23:27:31 +0000636 apic_timer_update(s, s->next_time);
637}
638
Avi Kivitya8170e52012-10-23 12:30:10 +0200639static uint32_t apic_mem_readb(void *opaque, hwaddr addr)
bellard574bbf72005-01-03 23:27:31 +0000640{
641 return 0;
642}
643
Avi Kivitya8170e52012-10-23 12:30:10 +0200644static uint32_t apic_mem_readw(void *opaque, hwaddr addr)
bellard574bbf72005-01-03 23:27:31 +0000645{
646 return 0;
647}
648
Avi Kivitya8170e52012-10-23 12:30:10 +0200649static void apic_mem_writeb(void *opaque, hwaddr addr, uint32_t val)
bellard574bbf72005-01-03 23:27:31 +0000650{
651}
652
Avi Kivitya8170e52012-10-23 12:30:10 +0200653static void apic_mem_writew(void *opaque, hwaddr addr, uint32_t val)
bellard574bbf72005-01-03 23:27:31 +0000654{
655}
656
Avi Kivitya8170e52012-10-23 12:30:10 +0200657static uint32_t apic_mem_readl(void *opaque, hwaddr addr)
bellard574bbf72005-01-03 23:27:31 +0000658{
Blue Swirl92a16d72010-06-19 07:47:42 +0000659 DeviceState *d;
Jan Kiszkadae01682011-10-16 11:16:36 +0200660 APICCommonState *s;
bellard574bbf72005-01-03 23:27:31 +0000661 uint32_t val;
662 int index;
663
Blue Swirl92a16d72010-06-19 07:47:42 +0000664 d = cpu_get_current_apic();
665 if (!d) {
bellard574bbf72005-01-03 23:27:31 +0000666 return 0;
Blue Swirl0e26b7b2010-06-19 10:42:34 +0300667 }
Jan Kiszkadae01682011-10-16 11:16:36 +0200668 s = DO_UPCAST(APICCommonState, busdev.qdev, d);
bellard574bbf72005-01-03 23:27:31 +0000669
670 index = (addr >> 4) & 0xff;
671 switch(index) {
672 case 0x02: /* id */
673 val = s->id << 24;
674 break;
675 case 0x03: /* version */
676 val = 0x11 | ((APIC_LVT_NB - 1) << 16); /* version 0x11 */
677 break;
678 case 0x08:
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100679 apic_sync_vapic(s, SYNC_FROM_VAPIC);
680 if (apic_report_tpr_access) {
Andreas Färber60671e52012-10-10 14:10:07 +0200681 cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_READ);
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100682 }
bellard574bbf72005-01-03 23:27:31 +0000683 val = s->tpr;
684 break;
bellardd592d302005-07-23 19:05:37 +0000685 case 0x09:
686 val = apic_get_arb_pri(s);
687 break;
bellard574bbf72005-01-03 23:27:31 +0000688 case 0x0a:
689 /* ppr */
690 val = apic_get_ppr(s);
691 break;
aurel32b237db32008-03-28 22:31:36 +0000692 case 0x0b:
693 val = 0;
694 break;
bellardd592d302005-07-23 19:05:37 +0000695 case 0x0d:
696 val = s->log_dest << 24;
697 break;
698 case 0x0e:
699 val = s->dest_mode << 28;
700 break;
bellard574bbf72005-01-03 23:27:31 +0000701 case 0x0f:
702 val = s->spurious_vec;
703 break;
704 case 0x10 ... 0x17:
705 val = s->isr[index & 7];
706 break;
707 case 0x18 ... 0x1f:
708 val = s->tmr[index & 7];
709 break;
710 case 0x20 ... 0x27:
711 val = s->irr[index & 7];
712 break;
713 case 0x28:
714 val = s->esr;
715 break;
bellard574bbf72005-01-03 23:27:31 +0000716 case 0x30:
717 case 0x31:
718 val = s->icr[index & 1];
719 break;
bellarde0fd8782005-11-21 23:26:26 +0000720 case 0x32 ... 0x37:
721 val = s->lvt[index - 0x32];
722 break;
bellard574bbf72005-01-03 23:27:31 +0000723 case 0x38:
724 val = s->initial_count;
725 break;
726 case 0x39:
727 val = apic_get_current_count(s);
728 break;
729 case 0x3e:
730 val = s->divide_conf;
731 break;
732 default:
733 s->esr |= ESR_ILLEGAL_ADDRESS;
734 val = 0;
735 break;
736 }
Blue Swirld8023f32010-10-20 16:41:28 +0000737 trace_apic_mem_readl(addr, val);
bellard574bbf72005-01-03 23:27:31 +0000738 return val;
739}
740
Avi Kivitya8170e52012-10-23 12:30:10 +0200741static void apic_send_msi(hwaddr addr, uint32_t data)
Michael S. Tsirkin54c96da2009-06-21 19:50:03 +0300742{
743 uint8_t dest = (addr & MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT;
744 uint8_t vector = (data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT;
745 uint8_t dest_mode = (addr >> MSI_ADDR_DEST_MODE_SHIFT) & 0x1;
746 uint8_t trigger_mode = (data >> MSI_DATA_TRIGGER_SHIFT) & 0x1;
747 uint8_t delivery = (data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x7;
748 /* XXX: Ignore redirection hint. */
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200749 apic_deliver_irq(dest, dest_mode, delivery, vector, trigger_mode);
Michael S. Tsirkin54c96da2009-06-21 19:50:03 +0300750}
751
Avi Kivitya8170e52012-10-23 12:30:10 +0200752static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)
bellard574bbf72005-01-03 23:27:31 +0000753{
Blue Swirl92a16d72010-06-19 07:47:42 +0000754 DeviceState *d;
Jan Kiszkadae01682011-10-16 11:16:36 +0200755 APICCommonState *s;
Michael S. Tsirkin54c96da2009-06-21 19:50:03 +0300756 int index = (addr >> 4) & 0xff;
757 if (addr > 0xfff || !index) {
758 /* MSI and MMIO APIC are at the same memory location,
759 * but actually not on the global bus: MSI is on PCI bus
760 * APIC is connected directly to the CPU.
761 * Mapping them on the global bus happens to work because
762 * MSI registers are reserved in APIC MMIO and vice versa. */
763 apic_send_msi(addr, val);
764 return;
765 }
bellard574bbf72005-01-03 23:27:31 +0000766
Blue Swirl92a16d72010-06-19 07:47:42 +0000767 d = cpu_get_current_apic();
768 if (!d) {
bellard574bbf72005-01-03 23:27:31 +0000769 return;
Blue Swirl0e26b7b2010-06-19 10:42:34 +0300770 }
Jan Kiszkadae01682011-10-16 11:16:36 +0200771 s = DO_UPCAST(APICCommonState, busdev.qdev, d);
bellard574bbf72005-01-03 23:27:31 +0000772
Blue Swirld8023f32010-10-20 16:41:28 +0000773 trace_apic_mem_writel(addr, val);
bellard574bbf72005-01-03 23:27:31 +0000774
bellard574bbf72005-01-03 23:27:31 +0000775 switch(index) {
776 case 0x02:
777 s->id = (val >> 24);
778 break;
bellarde0fd8782005-11-21 23:26:26 +0000779 case 0x03:
780 break;
bellard574bbf72005-01-03 23:27:31 +0000781 case 0x08:
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100782 if (apic_report_tpr_access) {
Andreas Färber60671e52012-10-10 14:10:07 +0200783 cpu_report_tpr_access(&s->cpu->env, TPR_ACCESS_WRITE);
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100784 }
bellard574bbf72005-01-03 23:27:31 +0000785 s->tpr = val;
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100786 apic_sync_vapic(s, SYNC_TO_VAPIC);
bellardd592d302005-07-23 19:05:37 +0000787 apic_update_irq(s);
bellard574bbf72005-01-03 23:27:31 +0000788 break;
bellarde0fd8782005-11-21 23:26:26 +0000789 case 0x09:
790 case 0x0a:
791 break;
bellard574bbf72005-01-03 23:27:31 +0000792 case 0x0b: /* EOI */
793 apic_eoi(s);
794 break;
bellardd592d302005-07-23 19:05:37 +0000795 case 0x0d:
796 s->log_dest = val >> 24;
797 break;
798 case 0x0e:
799 s->dest_mode = val >> 28;
800 break;
bellard574bbf72005-01-03 23:27:31 +0000801 case 0x0f:
802 s->spurious_vec = val & 0x1ff;
bellardd592d302005-07-23 19:05:37 +0000803 apic_update_irq(s);
bellard574bbf72005-01-03 23:27:31 +0000804 break;
bellarde0fd8782005-11-21 23:26:26 +0000805 case 0x10 ... 0x17:
806 case 0x18 ... 0x1f:
807 case 0x20 ... 0x27:
808 case 0x28:
809 break;
bellard574bbf72005-01-03 23:27:31 +0000810 case 0x30:
bellardd592d302005-07-23 19:05:37 +0000811 s->icr[0] = val;
Blue Swirl92a16d72010-06-19 07:47:42 +0000812 apic_deliver(d, (s->icr[1] >> 24) & 0xff, (s->icr[0] >> 11) & 1,
bellardd592d302005-07-23 19:05:37 +0000813 (s->icr[0] >> 8) & 7, (s->icr[0] & 0xff),
Jan Kiszka1f6f4082011-08-22 17:46:31 +0200814 (s->icr[0] >> 15) & 1);
bellardd592d302005-07-23 19:05:37 +0000815 break;
bellard574bbf72005-01-03 23:27:31 +0000816 case 0x31:
bellardd592d302005-07-23 19:05:37 +0000817 s->icr[1] = val;
bellard574bbf72005-01-03 23:27:31 +0000818 break;
819 case 0x32 ... 0x37:
820 {
821 int n = index - 0x32;
822 s->lvt[n] = val;
Jan Kiszkaa94820d2012-07-09 16:42:31 +0200823 if (n == APIC_LVT_TIMER) {
Paolo Bonzini74475452011-03-11 16:47:48 +0100824 apic_timer_update(s, qemu_get_clock_ns(vm_clock));
Jan Kiszkaa94820d2012-07-09 16:42:31 +0200825 } else if (n == APIC_LVT_LINT0 && apic_check_pic(s)) {
826 apic_update_irq(s);
827 }
bellard574bbf72005-01-03 23:27:31 +0000828 }
829 break;
830 case 0x38:
831 s->initial_count = val;
Paolo Bonzini74475452011-03-11 16:47:48 +0100832 s->initial_count_load_time = qemu_get_clock_ns(vm_clock);
bellard574bbf72005-01-03 23:27:31 +0000833 apic_timer_update(s, s->initial_count_load_time);
834 break;
bellarde0fd8782005-11-21 23:26:26 +0000835 case 0x39:
836 break;
bellard574bbf72005-01-03 23:27:31 +0000837 case 0x3e:
838 {
839 int v;
840 s->divide_conf = val & 0xb;
841 v = (s->divide_conf & 3) | ((s->divide_conf >> 1) & 4);
842 s->count_shift = (v + 1) & 7;
843 }
844 break;
845 default:
846 s->esr |= ESR_ILLEGAL_ADDRESS;
847 break;
848 }
849}
850
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100851static void apic_pre_save(APICCommonState *s)
852{
853 apic_sync_vapic(s, SYNC_FROM_VAPIC);
854}
855
Jan Kiszka7a380ca2011-10-16 12:19:12 +0200856static void apic_post_load(APICCommonState *s)
857{
858 if (s->timer_expiry != -1) {
859 qemu_mod_timer(s->timer, s->timer_expiry);
860 } else {
861 qemu_del_timer(s->timer);
862 }
863}
864
Avi Kivity312b4232011-08-15 17:17:16 +0300865static const MemoryRegionOps apic_io_ops = {
866 .old_mmio = {
867 .read = { apic_mem_readb, apic_mem_readw, apic_mem_readl, },
868 .write = { apic_mem_writeb, apic_mem_writew, apic_mem_writel, },
869 },
870 .endianness = DEVICE_NATIVE_ENDIAN,
bellard574bbf72005-01-03 23:27:31 +0000871};
872
Jan Kiszkadae01682011-10-16 11:16:36 +0200873static void apic_init(APICCommonState *s)
Blue Swirl8546b092010-06-19 07:44:07 +0000874{
Jan Kiszkadae01682011-10-16 11:16:36 +0200875 memory_region_init_io(&s->io_memory, &apic_io_ops, s, "apic-msi",
876 MSI_SPACE_SIZE);
Blue Swirl8546b092010-06-19 07:44:07 +0000877
Paolo Bonzini74475452011-03-11 16:47:48 +0100878 s->timer = qemu_new_timer_ns(vm_clock, apic_timer, s);
Blue Swirl8546b092010-06-19 07:44:07 +0000879 local_apics[s->idx] = s;
Jan Kiszka08a82ac2012-05-16 15:41:11 -0300880
881 msi_supported = true;
Blue Swirl8546b092010-06-19 07:44:07 +0000882}
883
Anthony Liguori999e12b2012-01-24 13:12:29 -0600884static void apic_class_init(ObjectClass *klass, void *data)
885{
886 APICCommonClass *k = APIC_COMMON_CLASS(klass);
887
888 k->init = apic_init;
889 k->set_base = apic_set_base;
890 k->set_tpr = apic_set_tpr;
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100891 k->get_tpr = apic_get_tpr;
892 k->vapic_base_update = apic_vapic_base_update;
Anthony Liguori999e12b2012-01-24 13:12:29 -0600893 k->external_nmi = apic_external_nmi;
Jan Kiszkae5ad9362012-02-17 18:31:19 +0100894 k->pre_save = apic_pre_save;
Anthony Liguori999e12b2012-01-24 13:12:29 -0600895 k->post_load = apic_post_load;
896}
897
Anthony Liguori39bffca2011-12-07 21:34:16 -0600898static TypeInfo apic_info = {
899 .name = "apic",
900 .instance_size = sizeof(APICCommonState),
901 .parent = TYPE_APIC_COMMON,
902 .class_init = apic_class_init,
Blue Swirl8546b092010-06-19 07:44:07 +0000903};
904
Andreas Färber83f7d432012-02-09 15:20:55 +0100905static void apic_register_types(void)
Blue Swirl8546b092010-06-19 07:44:07 +0000906{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600907 type_register_static(&apic_info);
Blue Swirl8546b092010-06-19 07:44:07 +0000908}
909
Andreas Färber83f7d432012-02-09 15:20:55 +0100910type_init(apic_register_types)