root / hw / apic.c @ be62a2eb
History | View | Annotate | Download (26.5 kB)
1 | 574bbf7b | bellard | /*
|
---|---|---|---|
2 | 574bbf7b | bellard | * APIC support
|
3 | 5fafdf24 | ths | *
|
4 | 574bbf7b | bellard | * Copyright (c) 2004-2005 Fabrice Bellard
|
5 | 574bbf7b | bellard | *
|
6 | 574bbf7b | bellard | * This library is free software; you can redistribute it and/or
|
7 | 574bbf7b | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 574bbf7b | bellard | * License as published by the Free Software Foundation; either
|
9 | 574bbf7b | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 574bbf7b | bellard | *
|
11 | 574bbf7b | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 574bbf7b | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 574bbf7b | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 574bbf7b | bellard | * Lesser General Public License for more details.
|
15 | 574bbf7b | bellard | *
|
16 | 574bbf7b | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 8167ee88 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>
|
18 | 574bbf7b | bellard | */
|
19 | 87ecb68b | pbrook | #include "hw.h" |
20 | aa28b9bf | Blue Swirl | #include "apic.h" |
21 | 0280b571 | Jan Kiszka | #include "ioapic.h" |
22 | 87ecb68b | pbrook | #include "qemu-timer.h" |
23 | bb7e7293 | aurel32 | #include "host-utils.h" |
24 | 8546b099 | Blue Swirl | #include "sysbus.h" |
25 | d8023f31 | Blue Swirl | #include "trace.h" |
26 | d96e1737 | Jan Kiszka | #include "pc.h" |
27 | 574bbf7b | bellard | |
28 | 574bbf7b | bellard | /* APIC Local Vector Table */
|
29 | 574bbf7b | bellard | #define APIC_LVT_TIMER 0 |
30 | 574bbf7b | bellard | #define APIC_LVT_THERMAL 1 |
31 | 574bbf7b | bellard | #define APIC_LVT_PERFORM 2 |
32 | 574bbf7b | bellard | #define APIC_LVT_LINT0 3 |
33 | 574bbf7b | bellard | #define APIC_LVT_LINT1 4 |
34 | 574bbf7b | bellard | #define APIC_LVT_ERROR 5 |
35 | 574bbf7b | bellard | #define APIC_LVT_NB 6 |
36 | 574bbf7b | bellard | |
37 | 574bbf7b | bellard | /* APIC delivery modes */
|
38 | 574bbf7b | bellard | #define APIC_DM_FIXED 0 |
39 | 574bbf7b | bellard | #define APIC_DM_LOWPRI 1 |
40 | 574bbf7b | bellard | #define APIC_DM_SMI 2 |
41 | 574bbf7b | bellard | #define APIC_DM_NMI 4 |
42 | 574bbf7b | bellard | #define APIC_DM_INIT 5 |
43 | 574bbf7b | bellard | #define APIC_DM_SIPI 6 |
44 | 574bbf7b | bellard | #define APIC_DM_EXTINT 7 |
45 | 574bbf7b | bellard | |
46 | d592d303 | bellard | /* APIC destination mode */
|
47 | d592d303 | bellard | #define APIC_DESTMODE_FLAT 0xf |
48 | d592d303 | bellard | #define APIC_DESTMODE_CLUSTER 1 |
49 | d592d303 | bellard | |
50 | 574bbf7b | bellard | #define APIC_TRIGGER_EDGE 0 |
51 | 574bbf7b | bellard | #define APIC_TRIGGER_LEVEL 1 |
52 | 574bbf7b | bellard | |
53 | 574bbf7b | bellard | #define APIC_LVT_TIMER_PERIODIC (1<<17) |
54 | 574bbf7b | bellard | #define APIC_LVT_MASKED (1<<16) |
55 | 574bbf7b | bellard | #define APIC_LVT_LEVEL_TRIGGER (1<<15) |
56 | 574bbf7b | bellard | #define APIC_LVT_REMOTE_IRR (1<<14) |
57 | 574bbf7b | bellard | #define APIC_INPUT_POLARITY (1<<13) |
58 | 574bbf7b | bellard | #define APIC_SEND_PENDING (1<<12) |
59 | 574bbf7b | bellard | |
60 | 574bbf7b | bellard | #define ESR_ILLEGAL_ADDRESS (1 << 7) |
61 | 574bbf7b | bellard | |
62 | 0280b571 | Jan Kiszka | #define APIC_SV_DIRECTED_IO (1<<12) |
63 | 0280b571 | Jan Kiszka | #define APIC_SV_ENABLE (1<<8) |
64 | 574bbf7b | bellard | |
65 | d3e9db93 | bellard | #define MAX_APICS 255 |
66 | d3e9db93 | bellard | #define MAX_APIC_WORDS 8 |
67 | d3e9db93 | bellard | |
68 | 54c96da7 | Michael S. Tsirkin | /* Intel APIC constants: from include/asm/msidef.h */
|
69 | 54c96da7 | Michael S. Tsirkin | #define MSI_DATA_VECTOR_SHIFT 0 |
70 | 54c96da7 | Michael S. Tsirkin | #define MSI_DATA_VECTOR_MASK 0x000000ff |
71 | 54c96da7 | Michael S. Tsirkin | #define MSI_DATA_DELIVERY_MODE_SHIFT 8 |
72 | 54c96da7 | Michael S. Tsirkin | #define MSI_DATA_TRIGGER_SHIFT 15 |
73 | 54c96da7 | Michael S. Tsirkin | #define MSI_DATA_LEVEL_SHIFT 14 |
74 | 54c96da7 | Michael S. Tsirkin | #define MSI_ADDR_DEST_MODE_SHIFT 2 |
75 | 54c96da7 | Michael S. Tsirkin | #define MSI_ADDR_DEST_ID_SHIFT 12 |
76 | 54c96da7 | Michael S. Tsirkin | #define MSI_ADDR_DEST_ID_MASK 0x00ffff0 |
77 | 54c96da7 | Michael S. Tsirkin | |
78 | 54c96da7 | Michael S. Tsirkin | #define MSI_ADDR_SIZE 0x100000 |
79 | 54c96da7 | Michael S. Tsirkin | |
80 | 92a16d7a | Blue Swirl | typedef struct APICState APICState; |
81 | 92a16d7a | Blue Swirl | |
82 | cf6d64bf | Blue Swirl | struct APICState {
|
83 | 8546b099 | Blue Swirl | SysBusDevice busdev; |
84 | 312b4234 | Avi Kivity | MemoryRegion io_memory; |
85 | 8546b099 | Blue Swirl | void *cpu_env;
|
86 | 574bbf7b | bellard | uint32_t apicbase; |
87 | 574bbf7b | bellard | uint8_t id; |
88 | d592d303 | bellard | uint8_t arb_id; |
89 | 574bbf7b | bellard | uint8_t tpr; |
90 | 574bbf7b | bellard | uint32_t spurious_vec; |
91 | d592d303 | bellard | uint8_t log_dest; |
92 | d592d303 | bellard | uint8_t dest_mode; |
93 | 574bbf7b | bellard | uint32_t isr[8]; /* in service register */ |
94 | 574bbf7b | bellard | uint32_t tmr[8]; /* trigger mode register */ |
95 | 574bbf7b | bellard | uint32_t irr[8]; /* interrupt request register */ |
96 | 574bbf7b | bellard | uint32_t lvt[APIC_LVT_NB]; |
97 | 574bbf7b | bellard | uint32_t esr; /* error register */
|
98 | 574bbf7b | bellard | uint32_t icr[2];
|
99 | 574bbf7b | bellard | |
100 | 574bbf7b | bellard | uint32_t divide_conf; |
101 | 574bbf7b | bellard | int count_shift;
|
102 | 574bbf7b | bellard | uint32_t initial_count; |
103 | 574bbf7b | bellard | int64_t initial_count_load_time, next_time; |
104 | 678e12cc | Gleb Natapov | uint32_t idx; |
105 | 574bbf7b | bellard | QEMUTimer *timer; |
106 | b09ea7d5 | Gleb Natapov | int sipi_vector;
|
107 | b09ea7d5 | Gleb Natapov | int wait_for_sipi;
|
108 | cf6d64bf | Blue Swirl | }; |
109 | 574bbf7b | bellard | |
110 | d3e9db93 | bellard | static APICState *local_apics[MAX_APICS + 1]; |
111 | 73822ec8 | aliguori | static int apic_irq_delivered; |
112 | 73822ec8 | aliguori | |
113 | d592d303 | bellard | static void apic_set_irq(APICState *s, int vector_num, int trigger_mode); |
114 | d592d303 | bellard | static void apic_update_irq(APICState *s); |
115 | 610626af | aliguori | static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask, |
116 | 610626af | aliguori | uint8_t dest, uint8_t dest_mode); |
117 | d592d303 | bellard | |
118 | 3b63c04e | aurel32 | /* Find first bit starting from msb */
|
119 | 3b63c04e | aurel32 | static int fls_bit(uint32_t value) |
120 | 3b63c04e | aurel32 | { |
121 | 3b63c04e | aurel32 | return 31 - clz32(value); |
122 | 3b63c04e | aurel32 | } |
123 | 3b63c04e | aurel32 | |
124 | e95f5491 | aurel32 | /* Find first bit starting from lsb */
|
125 | d3e9db93 | bellard | static int ffs_bit(uint32_t value) |
126 | d3e9db93 | bellard | { |
127 | bb7e7293 | aurel32 | return ctz32(value);
|
128 | d3e9db93 | bellard | } |
129 | d3e9db93 | bellard | |
130 | d3e9db93 | bellard | static inline void set_bit(uint32_t *tab, int index) |
131 | d3e9db93 | bellard | { |
132 | d3e9db93 | bellard | int i, mask;
|
133 | d3e9db93 | bellard | i = index >> 5;
|
134 | d3e9db93 | bellard | mask = 1 << (index & 0x1f); |
135 | d3e9db93 | bellard | tab[i] |= mask; |
136 | d3e9db93 | bellard | } |
137 | d3e9db93 | bellard | |
138 | d3e9db93 | bellard | static inline void reset_bit(uint32_t *tab, int index) |
139 | d3e9db93 | bellard | { |
140 | d3e9db93 | bellard | int i, mask;
|
141 | d3e9db93 | bellard | i = index >> 5;
|
142 | d3e9db93 | bellard | mask = 1 << (index & 0x1f); |
143 | d3e9db93 | bellard | tab[i] &= ~mask; |
144 | d3e9db93 | bellard | } |
145 | d3e9db93 | bellard | |
146 | 73822ec8 | aliguori | static inline int get_bit(uint32_t *tab, int index) |
147 | 73822ec8 | aliguori | { |
148 | 73822ec8 | aliguori | int i, mask;
|
149 | 73822ec8 | aliguori | i = index >> 5;
|
150 | 73822ec8 | aliguori | mask = 1 << (index & 0x1f); |
151 | 73822ec8 | aliguori | return !!(tab[i] & mask);
|
152 | 73822ec8 | aliguori | } |
153 | 73822ec8 | aliguori | |
154 | cf6d64bf | Blue Swirl | static void apic_local_deliver(APICState *s, int vector) |
155 | a5b38b51 | aurel32 | { |
156 | a5b38b51 | aurel32 | uint32_t lvt = s->lvt[vector]; |
157 | a5b38b51 | aurel32 | int trigger_mode;
|
158 | a5b38b51 | aurel32 | |
159 | d8023f31 | Blue Swirl | trace_apic_local_deliver(vector, (lvt >> 8) & 7); |
160 | d8023f31 | Blue Swirl | |
161 | a5b38b51 | aurel32 | if (lvt & APIC_LVT_MASKED)
|
162 | a5b38b51 | aurel32 | return;
|
163 | a5b38b51 | aurel32 | |
164 | a5b38b51 | aurel32 | switch ((lvt >> 8) & 7) { |
165 | a5b38b51 | aurel32 | case APIC_DM_SMI:
|
166 | cf6d64bf | Blue Swirl | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SMI); |
167 | a5b38b51 | aurel32 | break;
|
168 | a5b38b51 | aurel32 | |
169 | a5b38b51 | aurel32 | case APIC_DM_NMI:
|
170 | cf6d64bf | Blue Swirl | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_NMI); |
171 | a5b38b51 | aurel32 | break;
|
172 | a5b38b51 | aurel32 | |
173 | a5b38b51 | aurel32 | case APIC_DM_EXTINT:
|
174 | cf6d64bf | Blue Swirl | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD); |
175 | a5b38b51 | aurel32 | break;
|
176 | a5b38b51 | aurel32 | |
177 | a5b38b51 | aurel32 | case APIC_DM_FIXED:
|
178 | a5b38b51 | aurel32 | trigger_mode = APIC_TRIGGER_EDGE; |
179 | a5b38b51 | aurel32 | if ((vector == APIC_LVT_LINT0 || vector == APIC_LVT_LINT1) &&
|
180 | a5b38b51 | aurel32 | (lvt & APIC_LVT_LEVEL_TRIGGER)) |
181 | a5b38b51 | aurel32 | trigger_mode = APIC_TRIGGER_LEVEL; |
182 | a5b38b51 | aurel32 | apic_set_irq(s, lvt & 0xff, trigger_mode);
|
183 | a5b38b51 | aurel32 | } |
184 | a5b38b51 | aurel32 | } |
185 | a5b38b51 | aurel32 | |
186 | 92a16d7a | Blue Swirl | void apic_deliver_pic_intr(DeviceState *d, int level) |
187 | 1a7de94a | aurel32 | { |
188 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
189 | 92a16d7a | Blue Swirl | |
190 | cf6d64bf | Blue Swirl | if (level) {
|
191 | cf6d64bf | Blue Swirl | apic_local_deliver(s, APIC_LVT_LINT0); |
192 | cf6d64bf | Blue Swirl | } else {
|
193 | 1a7de94a | aurel32 | uint32_t lvt = s->lvt[APIC_LVT_LINT0]; |
194 | 1a7de94a | aurel32 | |
195 | 1a7de94a | aurel32 | switch ((lvt >> 8) & 7) { |
196 | 1a7de94a | aurel32 | case APIC_DM_FIXED:
|
197 | 1a7de94a | aurel32 | if (!(lvt & APIC_LVT_LEVEL_TRIGGER))
|
198 | 1a7de94a | aurel32 | break;
|
199 | 1a7de94a | aurel32 | reset_bit(s->irr, lvt & 0xff);
|
200 | 1a7de94a | aurel32 | /* fall through */
|
201 | 1a7de94a | aurel32 | case APIC_DM_EXTINT:
|
202 | cf6d64bf | Blue Swirl | cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_HARD); |
203 | 1a7de94a | aurel32 | break;
|
204 | 1a7de94a | aurel32 | } |
205 | 1a7de94a | aurel32 | } |
206 | 1a7de94a | aurel32 | } |
207 | 1a7de94a | aurel32 | |
208 | d3e9db93 | bellard | #define foreach_apic(apic, deliver_bitmask, code) \
|
209 | d3e9db93 | bellard | {\ |
210 | d3e9db93 | bellard | int __i, __j, __mask;\
|
211 | d3e9db93 | bellard | for(__i = 0; __i < MAX_APIC_WORDS; __i++) {\ |
212 | d3e9db93 | bellard | __mask = deliver_bitmask[__i];\ |
213 | d3e9db93 | bellard | if (__mask) {\
|
214 | d3e9db93 | bellard | for(__j = 0; __j < 32; __j++) {\ |
215 | d3e9db93 | bellard | if (__mask & (1 << __j)) {\ |
216 | d3e9db93 | bellard | apic = local_apics[__i * 32 + __j];\
|
217 | d3e9db93 | bellard | if (apic) {\
|
218 | d3e9db93 | bellard | code;\ |
219 | d3e9db93 | bellard | }\ |
220 | d3e9db93 | bellard | }\ |
221 | d3e9db93 | bellard | }\ |
222 | d3e9db93 | bellard | }\ |
223 | d3e9db93 | bellard | }\ |
224 | d3e9db93 | bellard | } |
225 | d3e9db93 | bellard | |
226 | 5fafdf24 | ths | static void apic_bus_deliver(const uint32_t *deliver_bitmask, |
227 | 1f6f408c | Jan Kiszka | uint8_t delivery_mode, uint8_t vector_num, |
228 | d592d303 | bellard | uint8_t trigger_mode) |
229 | d592d303 | bellard | { |
230 | d592d303 | bellard | APICState *apic_iter; |
231 | d592d303 | bellard | |
232 | d592d303 | bellard | switch (delivery_mode) {
|
233 | d592d303 | bellard | case APIC_DM_LOWPRI:
|
234 | 8dd69b8f | bellard | /* XXX: search for focus processor, arbitration */
|
235 | d3e9db93 | bellard | { |
236 | d3e9db93 | bellard | int i, d;
|
237 | d3e9db93 | bellard | d = -1;
|
238 | d3e9db93 | bellard | for(i = 0; i < MAX_APIC_WORDS; i++) { |
239 | d3e9db93 | bellard | if (deliver_bitmask[i]) {
|
240 | d3e9db93 | bellard | d = i * 32 + ffs_bit(deliver_bitmask[i]);
|
241 | d3e9db93 | bellard | break;
|
242 | d3e9db93 | bellard | } |
243 | d3e9db93 | bellard | } |
244 | d3e9db93 | bellard | if (d >= 0) { |
245 | d3e9db93 | bellard | apic_iter = local_apics[d]; |
246 | d3e9db93 | bellard | if (apic_iter) {
|
247 | d3e9db93 | bellard | apic_set_irq(apic_iter, vector_num, trigger_mode); |
248 | d3e9db93 | bellard | } |
249 | d3e9db93 | bellard | } |
250 | 8dd69b8f | bellard | } |
251 | d3e9db93 | bellard | return;
|
252 | 8dd69b8f | bellard | |
253 | d592d303 | bellard | case APIC_DM_FIXED:
|
254 | d592d303 | bellard | break;
|
255 | d592d303 | bellard | |
256 | d592d303 | bellard | case APIC_DM_SMI:
|
257 | e2eb9d3e | aurel32 | foreach_apic(apic_iter, deliver_bitmask, |
258 | e2eb9d3e | aurel32 | cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_SMI) ); |
259 | e2eb9d3e | aurel32 | return;
|
260 | e2eb9d3e | aurel32 | |
261 | d592d303 | bellard | case APIC_DM_NMI:
|
262 | e2eb9d3e | aurel32 | foreach_apic(apic_iter, deliver_bitmask, |
263 | e2eb9d3e | aurel32 | cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_NMI) ); |
264 | e2eb9d3e | aurel32 | return;
|
265 | d592d303 | bellard | |
266 | d592d303 | bellard | case APIC_DM_INIT:
|
267 | d592d303 | bellard | /* normal INIT IPI sent to processors */
|
268 | 5fafdf24 | ths | foreach_apic(apic_iter, deliver_bitmask, |
269 | b09ea7d5 | Gleb Natapov | cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_INIT) ); |
270 | d592d303 | bellard | return;
|
271 | 3b46e624 | ths | |
272 | d592d303 | bellard | case APIC_DM_EXTINT:
|
273 | b1fc0348 | bellard | /* handled in I/O APIC code */
|
274 | d592d303 | bellard | break;
|
275 | d592d303 | bellard | |
276 | d592d303 | bellard | default:
|
277 | d592d303 | bellard | return;
|
278 | d592d303 | bellard | } |
279 | d592d303 | bellard | |
280 | 5fafdf24 | ths | foreach_apic(apic_iter, deliver_bitmask, |
281 | d3e9db93 | bellard | apic_set_irq(apic_iter, vector_num, trigger_mode) ); |
282 | d592d303 | bellard | } |
283 | 574bbf7b | bellard | |
284 | 1f6f408c | Jan Kiszka | void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode,
|
285 | 1f6f408c | Jan Kiszka | uint8_t vector_num, uint8_t trigger_mode) |
286 | 610626af | aliguori | { |
287 | 610626af | aliguori | uint32_t deliver_bitmask[MAX_APIC_WORDS]; |
288 | 610626af | aliguori | |
289 | d8023f31 | Blue Swirl | trace_apic_deliver_irq(dest, dest_mode, delivery_mode, vector_num, |
290 | 1f6f408c | Jan Kiszka | trigger_mode); |
291 | d8023f31 | Blue Swirl | |
292 | 610626af | aliguori | apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode); |
293 | 1f6f408c | Jan Kiszka | apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode); |
294 | 610626af | aliguori | } |
295 | 610626af | aliguori | |
296 | 92a16d7a | Blue Swirl | void cpu_set_apic_base(DeviceState *d, uint64_t val)
|
297 | 574bbf7b | bellard | { |
298 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
299 | 92a16d7a | Blue Swirl | |
300 | d8023f31 | Blue Swirl | trace_cpu_set_apic_base(val); |
301 | d8023f31 | Blue Swirl | |
302 | 2c7c13d4 | aurel32 | if (!s)
|
303 | 2c7c13d4 | aurel32 | return;
|
304 | 5fafdf24 | ths | s->apicbase = (val & 0xfffff000) |
|
305 | 574bbf7b | bellard | (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE)); |
306 | 574bbf7b | bellard | /* if disabled, cannot be enabled again */
|
307 | 574bbf7b | bellard | if (!(val & MSR_IA32_APICBASE_ENABLE)) {
|
308 | 574bbf7b | bellard | s->apicbase &= ~MSR_IA32_APICBASE_ENABLE; |
309 | 0e26b7b8 | Blue Swirl | cpu_clear_apic_feature(s->cpu_env); |
310 | 574bbf7b | bellard | s->spurious_vec &= ~APIC_SV_ENABLE; |
311 | 574bbf7b | bellard | } |
312 | 574bbf7b | bellard | } |
313 | 574bbf7b | bellard | |
314 | 92a16d7a | Blue Swirl | uint64_t cpu_get_apic_base(DeviceState *d) |
315 | 574bbf7b | bellard | { |
316 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
317 | 92a16d7a | Blue Swirl | |
318 | d8023f31 | Blue Swirl | trace_cpu_get_apic_base(s ? (uint64_t)s->apicbase: 0);
|
319 | d8023f31 | Blue Swirl | |
320 | 2c7c13d4 | aurel32 | return s ? s->apicbase : 0; |
321 | 574bbf7b | bellard | } |
322 | 574bbf7b | bellard | |
323 | 92a16d7a | Blue Swirl | void cpu_set_apic_tpr(DeviceState *d, uint8_t val)
|
324 | 9230e66e | bellard | { |
325 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
326 | 92a16d7a | Blue Swirl | |
327 | 2c7c13d4 | aurel32 | if (!s)
|
328 | 2c7c13d4 | aurel32 | return;
|
329 | 9230e66e | bellard | s->tpr = (val & 0x0f) << 4; |
330 | d592d303 | bellard | apic_update_irq(s); |
331 | 9230e66e | bellard | } |
332 | 9230e66e | bellard | |
333 | 92a16d7a | Blue Swirl | uint8_t cpu_get_apic_tpr(DeviceState *d) |
334 | 9230e66e | bellard | { |
335 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
336 | 92a16d7a | Blue Swirl | |
337 | 2c7c13d4 | aurel32 | return s ? s->tpr >> 4 : 0; |
338 | 9230e66e | bellard | } |
339 | 9230e66e | bellard | |
340 | d592d303 | bellard | /* return -1 if no bit is set */
|
341 | d592d303 | bellard | static int get_highest_priority_int(uint32_t *tab) |
342 | d592d303 | bellard | { |
343 | d592d303 | bellard | int i;
|
344 | d592d303 | bellard | for(i = 7; i >= 0; i--) { |
345 | d592d303 | bellard | if (tab[i] != 0) { |
346 | 3b63c04e | aurel32 | return i * 32 + fls_bit(tab[i]); |
347 | d592d303 | bellard | } |
348 | d592d303 | bellard | } |
349 | d592d303 | bellard | return -1; |
350 | d592d303 | bellard | } |
351 | d592d303 | bellard | |
352 | 574bbf7b | bellard | static int apic_get_ppr(APICState *s) |
353 | 574bbf7b | bellard | { |
354 | 574bbf7b | bellard | int tpr, isrv, ppr;
|
355 | 574bbf7b | bellard | |
356 | 574bbf7b | bellard | tpr = (s->tpr >> 4);
|
357 | 574bbf7b | bellard | isrv = get_highest_priority_int(s->isr); |
358 | 574bbf7b | bellard | if (isrv < 0) |
359 | 574bbf7b | bellard | isrv = 0;
|
360 | 574bbf7b | bellard | isrv >>= 4;
|
361 | 574bbf7b | bellard | if (tpr >= isrv)
|
362 | 574bbf7b | bellard | ppr = s->tpr; |
363 | 574bbf7b | bellard | else
|
364 | 574bbf7b | bellard | ppr = isrv << 4;
|
365 | 574bbf7b | bellard | return ppr;
|
366 | 574bbf7b | bellard | } |
367 | 574bbf7b | bellard | |
368 | d592d303 | bellard | static int apic_get_arb_pri(APICState *s) |
369 | d592d303 | bellard | { |
370 | d592d303 | bellard | /* XXX: arbitration */
|
371 | d592d303 | bellard | return 0; |
372 | d592d303 | bellard | } |
373 | d592d303 | bellard | |
374 | 0fbfbb59 | Gleb Natapov | |
375 | 0fbfbb59 | Gleb Natapov | /*
|
376 | 0fbfbb59 | Gleb Natapov | * <0 - low prio interrupt,
|
377 | 0fbfbb59 | Gleb Natapov | * 0 - no interrupt,
|
378 | 0fbfbb59 | Gleb Natapov | * >0 - interrupt number
|
379 | 0fbfbb59 | Gleb Natapov | */
|
380 | 0fbfbb59 | Gleb Natapov | static int apic_irq_pending(APICState *s) |
381 | 574bbf7b | bellard | { |
382 | d592d303 | bellard | int irrv, ppr;
|
383 | 574bbf7b | bellard | irrv = get_highest_priority_int(s->irr); |
384 | 0fbfbb59 | Gleb Natapov | if (irrv < 0) { |
385 | 0fbfbb59 | Gleb Natapov | return 0; |
386 | 0fbfbb59 | Gleb Natapov | } |
387 | d592d303 | bellard | ppr = apic_get_ppr(s); |
388 | 0fbfbb59 | Gleb Natapov | if (ppr && (irrv & 0xf0) <= (ppr & 0xf0)) { |
389 | 0fbfbb59 | Gleb Natapov | return -1; |
390 | 0fbfbb59 | Gleb Natapov | } |
391 | 0fbfbb59 | Gleb Natapov | |
392 | 0fbfbb59 | Gleb Natapov | return irrv;
|
393 | 0fbfbb59 | Gleb Natapov | } |
394 | 0fbfbb59 | Gleb Natapov | |
395 | 0fbfbb59 | Gleb Natapov | /* signal the CPU if an irq is pending */
|
396 | 0fbfbb59 | Gleb Natapov | static void apic_update_irq(APICState *s) |
397 | 0fbfbb59 | Gleb Natapov | { |
398 | 0fbfbb59 | Gleb Natapov | if (!(s->spurious_vec & APIC_SV_ENABLE)) {
|
399 | 574bbf7b | bellard | return;
|
400 | 0fbfbb59 | Gleb Natapov | } |
401 | 0fbfbb59 | Gleb Natapov | if (apic_irq_pending(s) > 0) { |
402 | 0fbfbb59 | Gleb Natapov | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD); |
403 | d96e1737 | Jan Kiszka | } else if (apic_accept_pic_intr(&s->busdev.qdev) && |
404 | d96e1737 | Jan Kiszka | pic_get_output(isa_pic)) { |
405 | d96e1737 | Jan Kiszka | apic_deliver_pic_intr(&s->busdev.qdev, 1);
|
406 | 0fbfbb59 | Gleb Natapov | } |
407 | 574bbf7b | bellard | } |
408 | 574bbf7b | bellard | |
409 | 73822ec8 | aliguori | void apic_reset_irq_delivered(void) |
410 | 73822ec8 | aliguori | { |
411 | d8023f31 | Blue Swirl | trace_apic_reset_irq_delivered(apic_irq_delivered); |
412 | d8023f31 | Blue Swirl | |
413 | 73822ec8 | aliguori | apic_irq_delivered = 0;
|
414 | 73822ec8 | aliguori | } |
415 | 73822ec8 | aliguori | |
416 | 73822ec8 | aliguori | int apic_get_irq_delivered(void) |
417 | 73822ec8 | aliguori | { |
418 | d8023f31 | Blue Swirl | trace_apic_get_irq_delivered(apic_irq_delivered); |
419 | d8023f31 | Blue Swirl | |
420 | 73822ec8 | aliguori | return apic_irq_delivered;
|
421 | 73822ec8 | aliguori | } |
422 | 73822ec8 | aliguori | |
423 | 574bbf7b | bellard | static void apic_set_irq(APICState *s, int vector_num, int trigger_mode) |
424 | 574bbf7b | bellard | { |
425 | 73822ec8 | aliguori | apic_irq_delivered += !get_bit(s->irr, vector_num); |
426 | d8023f31 | Blue Swirl | |
427 | d8023f31 | Blue Swirl | trace_apic_set_irq(apic_irq_delivered); |
428 | 73822ec8 | aliguori | |
429 | 574bbf7b | bellard | set_bit(s->irr, vector_num); |
430 | 574bbf7b | bellard | if (trigger_mode)
|
431 | 574bbf7b | bellard | set_bit(s->tmr, vector_num); |
432 | 574bbf7b | bellard | else
|
433 | 574bbf7b | bellard | reset_bit(s->tmr, vector_num); |
434 | 574bbf7b | bellard | apic_update_irq(s); |
435 | 574bbf7b | bellard | } |
436 | 574bbf7b | bellard | |
437 | 574bbf7b | bellard | static void apic_eoi(APICState *s) |
438 | 574bbf7b | bellard | { |
439 | 574bbf7b | bellard | int isrv;
|
440 | 574bbf7b | bellard | isrv = get_highest_priority_int(s->isr); |
441 | 574bbf7b | bellard | if (isrv < 0) |
442 | 574bbf7b | bellard | return;
|
443 | 574bbf7b | bellard | reset_bit(s->isr, isrv); |
444 | 0280b571 | Jan Kiszka | if (!(s->spurious_vec & APIC_SV_DIRECTED_IO) && get_bit(s->tmr, isrv)) {
|
445 | 0280b571 | Jan Kiszka | ioapic_eoi_broadcast(isrv); |
446 | 0280b571 | Jan Kiszka | } |
447 | 574bbf7b | bellard | apic_update_irq(s); |
448 | 574bbf7b | bellard | } |
449 | 574bbf7b | bellard | |
450 | 678e12cc | Gleb Natapov | static int apic_find_dest(uint8_t dest) |
451 | 678e12cc | Gleb Natapov | { |
452 | 678e12cc | Gleb Natapov | APICState *apic = local_apics[dest]; |
453 | 678e12cc | Gleb Natapov | int i;
|
454 | 678e12cc | Gleb Natapov | |
455 | 678e12cc | Gleb Natapov | if (apic && apic->id == dest)
|
456 | 678e12cc | Gleb Natapov | return dest; /* shortcut in case apic->id == apic->idx */ |
457 | 678e12cc | Gleb Natapov | |
458 | 678e12cc | Gleb Natapov | for (i = 0; i < MAX_APICS; i++) { |
459 | 678e12cc | Gleb Natapov | apic = local_apics[i]; |
460 | 678e12cc | Gleb Natapov | if (apic && apic->id == dest)
|
461 | 678e12cc | Gleb Natapov | return i;
|
462 | b538e53e | Alex Williamson | if (!apic)
|
463 | b538e53e | Alex Williamson | break;
|
464 | 678e12cc | Gleb Natapov | } |
465 | 678e12cc | Gleb Natapov | |
466 | 678e12cc | Gleb Natapov | return -1; |
467 | 678e12cc | Gleb Natapov | } |
468 | 678e12cc | Gleb Natapov | |
469 | d3e9db93 | bellard | static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask, |
470 | d3e9db93 | bellard | uint8_t dest, uint8_t dest_mode) |
471 | d592d303 | bellard | { |
472 | d592d303 | bellard | APICState *apic_iter; |
473 | d3e9db93 | bellard | int i;
|
474 | d592d303 | bellard | |
475 | d592d303 | bellard | if (dest_mode == 0) { |
476 | d3e9db93 | bellard | if (dest == 0xff) { |
477 | d3e9db93 | bellard | memset(deliver_bitmask, 0xff, MAX_APIC_WORDS * sizeof(uint32_t)); |
478 | d3e9db93 | bellard | } else {
|
479 | 678e12cc | Gleb Natapov | int idx = apic_find_dest(dest);
|
480 | d3e9db93 | bellard | memset(deliver_bitmask, 0x00, MAX_APIC_WORDS * sizeof(uint32_t)); |
481 | 678e12cc | Gleb Natapov | if (idx >= 0) |
482 | 678e12cc | Gleb Natapov | set_bit(deliver_bitmask, idx); |
483 | d3e9db93 | bellard | } |
484 | d592d303 | bellard | } else {
|
485 | d592d303 | bellard | /* XXX: cluster mode */
|
486 | d3e9db93 | bellard | memset(deliver_bitmask, 0x00, MAX_APIC_WORDS * sizeof(uint32_t)); |
487 | d3e9db93 | bellard | for(i = 0; i < MAX_APICS; i++) { |
488 | d3e9db93 | bellard | apic_iter = local_apics[i]; |
489 | d3e9db93 | bellard | if (apic_iter) {
|
490 | d3e9db93 | bellard | if (apic_iter->dest_mode == 0xf) { |
491 | d3e9db93 | bellard | if (dest & apic_iter->log_dest)
|
492 | d3e9db93 | bellard | set_bit(deliver_bitmask, i); |
493 | d3e9db93 | bellard | } else if (apic_iter->dest_mode == 0x0) { |
494 | d3e9db93 | bellard | if ((dest & 0xf0) == (apic_iter->log_dest & 0xf0) && |
495 | d3e9db93 | bellard | (dest & apic_iter->log_dest & 0x0f)) {
|
496 | d3e9db93 | bellard | set_bit(deliver_bitmask, i); |
497 | d3e9db93 | bellard | } |
498 | d3e9db93 | bellard | } |
499 | b538e53e | Alex Williamson | } else {
|
500 | b538e53e | Alex Williamson | break;
|
501 | d3e9db93 | bellard | } |
502 | d592d303 | bellard | } |
503 | d592d303 | bellard | } |
504 | d592d303 | bellard | } |
505 | d592d303 | bellard | |
506 | 92a16d7a | Blue Swirl | void apic_init_reset(DeviceState *d)
|
507 | d592d303 | bellard | { |
508 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
509 | d592d303 | bellard | int i;
|
510 | d592d303 | bellard | |
511 | b09ea7d5 | Gleb Natapov | if (!s)
|
512 | b09ea7d5 | Gleb Natapov | return;
|
513 | b09ea7d5 | Gleb Natapov | |
514 | d592d303 | bellard | s->tpr = 0;
|
515 | d592d303 | bellard | s->spurious_vec = 0xff;
|
516 | d592d303 | bellard | s->log_dest = 0;
|
517 | e0fd8781 | bellard | s->dest_mode = 0xf;
|
518 | d592d303 | bellard | memset(s->isr, 0, sizeof(s->isr)); |
519 | d592d303 | bellard | memset(s->tmr, 0, sizeof(s->tmr)); |
520 | d592d303 | bellard | memset(s->irr, 0, sizeof(s->irr)); |
521 | b4511723 | bellard | for(i = 0; i < APIC_LVT_NB; i++) |
522 | b4511723 | bellard | s->lvt[i] = 1 << 16; /* mask LVT */ |
523 | d592d303 | bellard | s->esr = 0;
|
524 | d592d303 | bellard | memset(s->icr, 0, sizeof(s->icr)); |
525 | d592d303 | bellard | s->divide_conf = 0;
|
526 | d592d303 | bellard | s->count_shift = 0;
|
527 | d592d303 | bellard | s->initial_count = 0;
|
528 | d592d303 | bellard | s->initial_count_load_time = 0;
|
529 | d592d303 | bellard | s->next_time = 0;
|
530 | b09ea7d5 | Gleb Natapov | s->wait_for_sipi = 1;
|
531 | d592d303 | bellard | } |
532 | d592d303 | bellard | |
533 | e0fd8781 | bellard | static void apic_startup(APICState *s, int vector_num) |
534 | e0fd8781 | bellard | { |
535 | b09ea7d5 | Gleb Natapov | s->sipi_vector = vector_num; |
536 | b09ea7d5 | Gleb Natapov | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI); |
537 | b09ea7d5 | Gleb Natapov | } |
538 | b09ea7d5 | Gleb Natapov | |
539 | 92a16d7a | Blue Swirl | void apic_sipi(DeviceState *d)
|
540 | b09ea7d5 | Gleb Natapov | { |
541 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
542 | 92a16d7a | Blue Swirl | |
543 | 4a942cea | Blue Swirl | cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI); |
544 | b09ea7d5 | Gleb Natapov | |
545 | b09ea7d5 | Gleb Natapov | if (!s->wait_for_sipi)
|
546 | e0fd8781 | bellard | return;
|
547 | 0e26b7b8 | Blue Swirl | cpu_x86_load_seg_cache_sipi(s->cpu_env, s->sipi_vector); |
548 | b09ea7d5 | Gleb Natapov | s->wait_for_sipi = 0;
|
549 | e0fd8781 | bellard | } |
550 | e0fd8781 | bellard | |
551 | 92a16d7a | Blue Swirl | static void apic_deliver(DeviceState *d, uint8_t dest, uint8_t dest_mode, |
552 | d592d303 | bellard | uint8_t delivery_mode, uint8_t vector_num, |
553 | 1f6f408c | Jan Kiszka | uint8_t trigger_mode) |
554 | d592d303 | bellard | { |
555 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
556 | d3e9db93 | bellard | uint32_t deliver_bitmask[MAX_APIC_WORDS]; |
557 | d592d303 | bellard | int dest_shorthand = (s->icr[0] >> 18) & 3; |
558 | d592d303 | bellard | APICState *apic_iter; |
559 | d592d303 | bellard | |
560 | e0fd8781 | bellard | switch (dest_shorthand) {
|
561 | d3e9db93 | bellard | case 0: |
562 | d3e9db93 | bellard | apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode); |
563 | d3e9db93 | bellard | break;
|
564 | d3e9db93 | bellard | case 1: |
565 | d3e9db93 | bellard | memset(deliver_bitmask, 0x00, sizeof(deliver_bitmask)); |
566 | 678e12cc | Gleb Natapov | set_bit(deliver_bitmask, s->idx); |
567 | d3e9db93 | bellard | break;
|
568 | d3e9db93 | bellard | case 2: |
569 | d3e9db93 | bellard | memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask)); |
570 | d3e9db93 | bellard | break;
|
571 | d3e9db93 | bellard | case 3: |
572 | d3e9db93 | bellard | memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask)); |
573 | 678e12cc | Gleb Natapov | reset_bit(deliver_bitmask, s->idx); |
574 | d3e9db93 | bellard | break;
|
575 | e0fd8781 | bellard | } |
576 | e0fd8781 | bellard | |
577 | d592d303 | bellard | switch (delivery_mode) {
|
578 | d592d303 | bellard | case APIC_DM_INIT:
|
579 | d592d303 | bellard | { |
580 | d592d303 | bellard | int trig_mode = (s->icr[0] >> 15) & 1; |
581 | d592d303 | bellard | int level = (s->icr[0] >> 14) & 1; |
582 | d592d303 | bellard | if (level == 0 && trig_mode == 1) { |
583 | 5fafdf24 | ths | foreach_apic(apic_iter, deliver_bitmask, |
584 | d3e9db93 | bellard | apic_iter->arb_id = apic_iter->id ); |
585 | d592d303 | bellard | return;
|
586 | d592d303 | bellard | } |
587 | d592d303 | bellard | } |
588 | d592d303 | bellard | break;
|
589 | d592d303 | bellard | |
590 | d592d303 | bellard | case APIC_DM_SIPI:
|
591 | 5fafdf24 | ths | foreach_apic(apic_iter, deliver_bitmask, |
592 | d3e9db93 | bellard | apic_startup(apic_iter, vector_num) ); |
593 | d592d303 | bellard | return;
|
594 | d592d303 | bellard | } |
595 | d592d303 | bellard | |
596 | 1f6f408c | Jan Kiszka | apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, trigger_mode); |
597 | d592d303 | bellard | } |
598 | d592d303 | bellard | |
599 | 92a16d7a | Blue Swirl | int apic_get_interrupt(DeviceState *d)
|
600 | 574bbf7b | bellard | { |
601 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
602 | 574bbf7b | bellard | int intno;
|
603 | 574bbf7b | bellard | |
604 | 574bbf7b | bellard | /* if the APIC is installed or enabled, we let the 8259 handle the
|
605 | 574bbf7b | bellard | IRQs */
|
606 | 574bbf7b | bellard | if (!s)
|
607 | 574bbf7b | bellard | return -1; |
608 | 574bbf7b | bellard | if (!(s->spurious_vec & APIC_SV_ENABLE))
|
609 | 574bbf7b | bellard | return -1; |
610 | 3b46e624 | ths | |
611 | 0fbfbb59 | Gleb Natapov | intno = apic_irq_pending(s); |
612 | 0fbfbb59 | Gleb Natapov | |
613 | 0fbfbb59 | Gleb Natapov | if (intno == 0) { |
614 | 574bbf7b | bellard | return -1; |
615 | 0fbfbb59 | Gleb Natapov | } else if (intno < 0) { |
616 | d592d303 | bellard | return s->spurious_vec & 0xff; |
617 | 0fbfbb59 | Gleb Natapov | } |
618 | b4511723 | bellard | reset_bit(s->irr, intno); |
619 | 574bbf7b | bellard | set_bit(s->isr, intno); |
620 | 574bbf7b | bellard | apic_update_irq(s); |
621 | 574bbf7b | bellard | return intno;
|
622 | 574bbf7b | bellard | } |
623 | 574bbf7b | bellard | |
624 | 92a16d7a | Blue Swirl | int apic_accept_pic_intr(DeviceState *d)
|
625 | 0e21e12b | ths | { |
626 | 92a16d7a | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
627 | 0e21e12b | ths | uint32_t lvt0; |
628 | 0e21e12b | ths | |
629 | 0e21e12b | ths | if (!s)
|
630 | 0e21e12b | ths | return -1; |
631 | 0e21e12b | ths | |
632 | 0e21e12b | ths | lvt0 = s->lvt[APIC_LVT_LINT0]; |
633 | 0e21e12b | ths | |
634 | a5b38b51 | aurel32 | if ((s->apicbase & MSR_IA32_APICBASE_ENABLE) == 0 || |
635 | a5b38b51 | aurel32 | (lvt0 & APIC_LVT_MASKED) == 0)
|
636 | 0e21e12b | ths | return 1; |
637 | 0e21e12b | ths | |
638 | 0e21e12b | ths | return 0; |
639 | 0e21e12b | ths | } |
640 | 0e21e12b | ths | |
641 | 574bbf7b | bellard | static uint32_t apic_get_current_count(APICState *s)
|
642 | 574bbf7b | bellard | { |
643 | 574bbf7b | bellard | int64_t d; |
644 | 574bbf7b | bellard | uint32_t val; |
645 | 74475455 | Paolo Bonzini | d = (qemu_get_clock_ns(vm_clock) - s->initial_count_load_time) >> |
646 | 574bbf7b | bellard | s->count_shift; |
647 | 574bbf7b | bellard | if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) {
|
648 | 574bbf7b | bellard | /* periodic */
|
649 | d592d303 | bellard | val = s->initial_count - (d % ((uint64_t)s->initial_count + 1));
|
650 | 574bbf7b | bellard | } else {
|
651 | 574bbf7b | bellard | if (d >= s->initial_count)
|
652 | 574bbf7b | bellard | val = 0;
|
653 | 574bbf7b | bellard | else
|
654 | 574bbf7b | bellard | val = s->initial_count - d; |
655 | 574bbf7b | bellard | } |
656 | 574bbf7b | bellard | return val;
|
657 | 574bbf7b | bellard | } |
658 | 574bbf7b | bellard | |
659 | 574bbf7b | bellard | static void apic_timer_update(APICState *s, int64_t current_time) |
660 | 574bbf7b | bellard | { |
661 | 574bbf7b | bellard | int64_t next_time, d; |
662 | 3b46e624 | ths | |
663 | 574bbf7b | bellard | if (!(s->lvt[APIC_LVT_TIMER] & APIC_LVT_MASKED)) {
|
664 | 5fafdf24 | ths | d = (current_time - s->initial_count_load_time) >> |
665 | 574bbf7b | bellard | s->count_shift; |
666 | 574bbf7b | bellard | if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) {
|
667 | 681f8c29 | aliguori | if (!s->initial_count)
|
668 | 681f8c29 | aliguori | goto no_timer;
|
669 | d592d303 | bellard | d = ((d / ((uint64_t)s->initial_count + 1)) + 1) * ((uint64_t)s->initial_count + 1); |
670 | 574bbf7b | bellard | } else {
|
671 | 574bbf7b | bellard | if (d >= s->initial_count)
|
672 | 574bbf7b | bellard | goto no_timer;
|
673 | d592d303 | bellard | d = (uint64_t)s->initial_count + 1;
|
674 | 574bbf7b | bellard | } |
675 | 574bbf7b | bellard | next_time = s->initial_count_load_time + (d << s->count_shift); |
676 | 574bbf7b | bellard | qemu_mod_timer(s->timer, next_time); |
677 | 574bbf7b | bellard | s->next_time = next_time; |
678 | 574bbf7b | bellard | } else {
|
679 | 574bbf7b | bellard | no_timer:
|
680 | 574bbf7b | bellard | qemu_del_timer(s->timer); |
681 | 574bbf7b | bellard | } |
682 | 574bbf7b | bellard | } |
683 | 574bbf7b | bellard | |
684 | 574bbf7b | bellard | static void apic_timer(void *opaque) |
685 | 574bbf7b | bellard | { |
686 | 574bbf7b | bellard | APICState *s = opaque; |
687 | 574bbf7b | bellard | |
688 | cf6d64bf | Blue Swirl | apic_local_deliver(s, APIC_LVT_TIMER); |
689 | 574bbf7b | bellard | apic_timer_update(s, s->next_time); |
690 | 574bbf7b | bellard | } |
691 | 574bbf7b | bellard | |
692 | c227f099 | Anthony Liguori | static uint32_t apic_mem_readb(void *opaque, target_phys_addr_t addr) |
693 | 574bbf7b | bellard | { |
694 | 574bbf7b | bellard | return 0; |
695 | 574bbf7b | bellard | } |
696 | 574bbf7b | bellard | |
697 | c227f099 | Anthony Liguori | static uint32_t apic_mem_readw(void *opaque, target_phys_addr_t addr) |
698 | 574bbf7b | bellard | { |
699 | 574bbf7b | bellard | return 0; |
700 | 574bbf7b | bellard | } |
701 | 574bbf7b | bellard | |
702 | c227f099 | Anthony Liguori | static void apic_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
703 | 574bbf7b | bellard | { |
704 | 574bbf7b | bellard | } |
705 | 574bbf7b | bellard | |
706 | c227f099 | Anthony Liguori | static void apic_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
707 | 574bbf7b | bellard | { |
708 | 574bbf7b | bellard | } |
709 | 574bbf7b | bellard | |
710 | c227f099 | Anthony Liguori | static uint32_t apic_mem_readl(void *opaque, target_phys_addr_t addr) |
711 | 574bbf7b | bellard | { |
712 | 92a16d7a | Blue Swirl | DeviceState *d; |
713 | 574bbf7b | bellard | APICState *s; |
714 | 574bbf7b | bellard | uint32_t val; |
715 | 574bbf7b | bellard | int index;
|
716 | 574bbf7b | bellard | |
717 | 92a16d7a | Blue Swirl | d = cpu_get_current_apic(); |
718 | 92a16d7a | Blue Swirl | if (!d) {
|
719 | 574bbf7b | bellard | return 0; |
720 | 0e26b7b8 | Blue Swirl | } |
721 | 92a16d7a | Blue Swirl | s = DO_UPCAST(APICState, busdev.qdev, d); |
722 | 574bbf7b | bellard | |
723 | 574bbf7b | bellard | index = (addr >> 4) & 0xff; |
724 | 574bbf7b | bellard | switch(index) {
|
725 | 574bbf7b | bellard | case 0x02: /* id */ |
726 | 574bbf7b | bellard | val = s->id << 24;
|
727 | 574bbf7b | bellard | break;
|
728 | 574bbf7b | bellard | case 0x03: /* version */ |
729 | 574bbf7b | bellard | val = 0x11 | ((APIC_LVT_NB - 1) << 16); /* version 0x11 */ |
730 | 574bbf7b | bellard | break;
|
731 | 574bbf7b | bellard | case 0x08: |
732 | 574bbf7b | bellard | val = s->tpr; |
733 | 574bbf7b | bellard | break;
|
734 | d592d303 | bellard | case 0x09: |
735 | d592d303 | bellard | val = apic_get_arb_pri(s); |
736 | d592d303 | bellard | break;
|
737 | 574bbf7b | bellard | case 0x0a: |
738 | 574bbf7b | bellard | /* ppr */
|
739 | 574bbf7b | bellard | val = apic_get_ppr(s); |
740 | 574bbf7b | bellard | break;
|
741 | b237db36 | aurel32 | case 0x0b: |
742 | b237db36 | aurel32 | val = 0;
|
743 | b237db36 | aurel32 | break;
|
744 | d592d303 | bellard | case 0x0d: |
745 | d592d303 | bellard | val = s->log_dest << 24;
|
746 | d592d303 | bellard | break;
|
747 | d592d303 | bellard | case 0x0e: |
748 | d592d303 | bellard | val = s->dest_mode << 28;
|
749 | d592d303 | bellard | break;
|
750 | 574bbf7b | bellard | case 0x0f: |
751 | 574bbf7b | bellard | val = s->spurious_vec; |
752 | 574bbf7b | bellard | break;
|
753 | 574bbf7b | bellard | case 0x10 ... 0x17: |
754 | 574bbf7b | bellard | val = s->isr[index & 7];
|
755 | 574bbf7b | bellard | break;
|
756 | 574bbf7b | bellard | case 0x18 ... 0x1f: |
757 | 574bbf7b | bellard | val = s->tmr[index & 7];
|
758 | 574bbf7b | bellard | break;
|
759 | 574bbf7b | bellard | case 0x20 ... 0x27: |
760 | 574bbf7b | bellard | val = s->irr[index & 7];
|
761 | 574bbf7b | bellard | break;
|
762 | 574bbf7b | bellard | case 0x28: |
763 | 574bbf7b | bellard | val = s->esr; |
764 | 574bbf7b | bellard | break;
|
765 | 574bbf7b | bellard | case 0x30: |
766 | 574bbf7b | bellard | case 0x31: |
767 | 574bbf7b | bellard | val = s->icr[index & 1];
|
768 | 574bbf7b | bellard | break;
|
769 | e0fd8781 | bellard | case 0x32 ... 0x37: |
770 | e0fd8781 | bellard | val = s->lvt[index - 0x32];
|
771 | e0fd8781 | bellard | break;
|
772 | 574bbf7b | bellard | case 0x38: |
773 | 574bbf7b | bellard | val = s->initial_count; |
774 | 574bbf7b | bellard | break;
|
775 | 574bbf7b | bellard | case 0x39: |
776 | 574bbf7b | bellard | val = apic_get_current_count(s); |
777 | 574bbf7b | bellard | break;
|
778 | 574bbf7b | bellard | case 0x3e: |
779 | 574bbf7b | bellard | val = s->divide_conf; |
780 | 574bbf7b | bellard | break;
|
781 | 574bbf7b | bellard | default:
|
782 | 574bbf7b | bellard | s->esr |= ESR_ILLEGAL_ADDRESS; |
783 | 574bbf7b | bellard | val = 0;
|
784 | 574bbf7b | bellard | break;
|
785 | 574bbf7b | bellard | } |
786 | d8023f31 | Blue Swirl | trace_apic_mem_readl(addr, val); |
787 | 574bbf7b | bellard | return val;
|
788 | 574bbf7b | bellard | } |
789 | 574bbf7b | bellard | |
790 | f5095c63 | Andreas Fรคrber | static void apic_send_msi(target_phys_addr_t addr, uint32_t data) |
791 | 54c96da7 | Michael S. Tsirkin | { |
792 | 54c96da7 | Michael S. Tsirkin | uint8_t dest = (addr & MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; |
793 | 54c96da7 | Michael S. Tsirkin | uint8_t vector = (data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT; |
794 | 54c96da7 | Michael S. Tsirkin | uint8_t dest_mode = (addr >> MSI_ADDR_DEST_MODE_SHIFT) & 0x1;
|
795 | 54c96da7 | Michael S. Tsirkin | uint8_t trigger_mode = (data >> MSI_DATA_TRIGGER_SHIFT) & 0x1;
|
796 | 54c96da7 | Michael S. Tsirkin | uint8_t delivery = (data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x7;
|
797 | 54c96da7 | Michael S. Tsirkin | /* XXX: Ignore redirection hint. */
|
798 | 1f6f408c | Jan Kiszka | apic_deliver_irq(dest, dest_mode, delivery, vector, trigger_mode); |
799 | 54c96da7 | Michael S. Tsirkin | } |
800 | 54c96da7 | Michael S. Tsirkin | |
801 | c227f099 | Anthony Liguori | static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
802 | 574bbf7b | bellard | { |
803 | 92a16d7a | Blue Swirl | DeviceState *d; |
804 | 574bbf7b | bellard | APICState *s; |
805 | 54c96da7 | Michael S. Tsirkin | int index = (addr >> 4) & 0xff; |
806 | 54c96da7 | Michael S. Tsirkin | if (addr > 0xfff || !index) { |
807 | 54c96da7 | Michael S. Tsirkin | /* MSI and MMIO APIC are at the same memory location,
|
808 | 54c96da7 | Michael S. Tsirkin | * but actually not on the global bus: MSI is on PCI bus
|
809 | 54c96da7 | Michael S. Tsirkin | * APIC is connected directly to the CPU.
|
810 | 54c96da7 | Michael S. Tsirkin | * Mapping them on the global bus happens to work because
|
811 | 54c96da7 | Michael S. Tsirkin | * MSI registers are reserved in APIC MMIO and vice versa. */
|
812 | 54c96da7 | Michael S. Tsirkin | apic_send_msi(addr, val); |
813 | 54c96da7 | Michael S. Tsirkin | return;
|
814 | 54c96da7 | Michael S. Tsirkin | } |
815 | 574bbf7b | bellard | |
816 | 92a16d7a | Blue Swirl | d = cpu_get_current_apic(); |
817 | 92a16d7a | Blue Swirl | if (!d) {
|
818 | 574bbf7b | bellard | return;
|
819 | 0e26b7b8 | Blue Swirl | } |
820 | 92a16d7a | Blue Swirl | s = DO_UPCAST(APICState, busdev.qdev, d); |
821 | 574bbf7b | bellard | |
822 | d8023f31 | Blue Swirl | trace_apic_mem_writel(addr, val); |
823 | 574bbf7b | bellard | |
824 | 574bbf7b | bellard | switch(index) {
|
825 | 574bbf7b | bellard | case 0x02: |
826 | 574bbf7b | bellard | s->id = (val >> 24);
|
827 | 574bbf7b | bellard | break;
|
828 | e0fd8781 | bellard | case 0x03: |
829 | e0fd8781 | bellard | break;
|
830 | 574bbf7b | bellard | case 0x08: |
831 | 574bbf7b | bellard | s->tpr = val; |
832 | d592d303 | bellard | apic_update_irq(s); |
833 | 574bbf7b | bellard | break;
|
834 | e0fd8781 | bellard | case 0x09: |
835 | e0fd8781 | bellard | case 0x0a: |
836 | e0fd8781 | bellard | break;
|
837 | 574bbf7b | bellard | case 0x0b: /* EOI */ |
838 | 574bbf7b | bellard | apic_eoi(s); |
839 | 574bbf7b | bellard | break;
|
840 | d592d303 | bellard | case 0x0d: |
841 | d592d303 | bellard | s->log_dest = val >> 24;
|
842 | d592d303 | bellard | break;
|
843 | d592d303 | bellard | case 0x0e: |
844 | d592d303 | bellard | s->dest_mode = val >> 28;
|
845 | d592d303 | bellard | break;
|
846 | 574bbf7b | bellard | case 0x0f: |
847 | 574bbf7b | bellard | s->spurious_vec = val & 0x1ff;
|
848 | d592d303 | bellard | apic_update_irq(s); |
849 | 574bbf7b | bellard | break;
|
850 | e0fd8781 | bellard | case 0x10 ... 0x17: |
851 | e0fd8781 | bellard | case 0x18 ... 0x1f: |
852 | e0fd8781 | bellard | case 0x20 ... 0x27: |
853 | e0fd8781 | bellard | case 0x28: |
854 | e0fd8781 | bellard | break;
|
855 | 574bbf7b | bellard | case 0x30: |
856 | d592d303 | bellard | s->icr[0] = val;
|
857 | 92a16d7a | Blue Swirl | apic_deliver(d, (s->icr[1] >> 24) & 0xff, (s->icr[0] >> 11) & 1, |
858 | d592d303 | bellard | (s->icr[0] >> 8) & 7, (s->icr[0] & 0xff), |
859 | 1f6f408c | Jan Kiszka | (s->icr[0] >> 15) & 1); |
860 | d592d303 | bellard | break;
|
861 | 574bbf7b | bellard | case 0x31: |
862 | d592d303 | bellard | s->icr[1] = val;
|
863 | 574bbf7b | bellard | break;
|
864 | 574bbf7b | bellard | case 0x32 ... 0x37: |
865 | 574bbf7b | bellard | { |
866 | 574bbf7b | bellard | int n = index - 0x32; |
867 | 574bbf7b | bellard | s->lvt[n] = val; |
868 | 574bbf7b | bellard | if (n == APIC_LVT_TIMER)
|
869 | 74475455 | Paolo Bonzini | apic_timer_update(s, qemu_get_clock_ns(vm_clock)); |
870 | 574bbf7b | bellard | } |
871 | 574bbf7b | bellard | break;
|
872 | 574bbf7b | bellard | case 0x38: |
873 | 574bbf7b | bellard | s->initial_count = val; |
874 | 74475455 | Paolo Bonzini | s->initial_count_load_time = qemu_get_clock_ns(vm_clock); |
875 | 574bbf7b | bellard | apic_timer_update(s, s->initial_count_load_time); |
876 | 574bbf7b | bellard | break;
|
877 | e0fd8781 | bellard | case 0x39: |
878 | e0fd8781 | bellard | break;
|
879 | 574bbf7b | bellard | case 0x3e: |
880 | 574bbf7b | bellard | { |
881 | 574bbf7b | bellard | int v;
|
882 | 574bbf7b | bellard | s->divide_conf = val & 0xb;
|
883 | 574bbf7b | bellard | v = (s->divide_conf & 3) | ((s->divide_conf >> 1) & 4); |
884 | 574bbf7b | bellard | s->count_shift = (v + 1) & 7; |
885 | 574bbf7b | bellard | } |
886 | 574bbf7b | bellard | break;
|
887 | 574bbf7b | bellard | default:
|
888 | 574bbf7b | bellard | s->esr |= ESR_ILLEGAL_ADDRESS; |
889 | 574bbf7b | bellard | break;
|
890 | 574bbf7b | bellard | } |
891 | 574bbf7b | bellard | } |
892 | 574bbf7b | bellard | |
893 | 695dcf71 | Juan Quintela | /* This function is only used for old state version 1 and 2 */
|
894 | 695dcf71 | Juan Quintela | static int apic_load_old(QEMUFile *f, void *opaque, int version_id) |
895 | d592d303 | bellard | { |
896 | d592d303 | bellard | APICState *s = opaque; |
897 | d592d303 | bellard | int i;
|
898 | d592d303 | bellard | |
899 | e6cf6a8c | bellard | if (version_id > 2) |
900 | d592d303 | bellard | return -EINVAL;
|
901 | d592d303 | bellard | |
902 | d592d303 | bellard | /* XXX: what if the base changes? (registered memory regions) */
|
903 | d592d303 | bellard | qemu_get_be32s(f, &s->apicbase); |
904 | d592d303 | bellard | qemu_get_8s(f, &s->id); |
905 | d592d303 | bellard | qemu_get_8s(f, &s->arb_id); |
906 | d592d303 | bellard | qemu_get_8s(f, &s->tpr); |
907 | d592d303 | bellard | qemu_get_be32s(f, &s->spurious_vec); |
908 | d592d303 | bellard | qemu_get_8s(f, &s->log_dest); |
909 | d592d303 | bellard | qemu_get_8s(f, &s->dest_mode); |
910 | d592d303 | bellard | for (i = 0; i < 8; i++) { |
911 | d592d303 | bellard | qemu_get_be32s(f, &s->isr[i]); |
912 | d592d303 | bellard | qemu_get_be32s(f, &s->tmr[i]); |
913 | d592d303 | bellard | qemu_get_be32s(f, &s->irr[i]); |
914 | d592d303 | bellard | } |
915 | d592d303 | bellard | for (i = 0; i < APIC_LVT_NB; i++) { |
916 | d592d303 | bellard | qemu_get_be32s(f, &s->lvt[i]); |
917 | d592d303 | bellard | } |
918 | d592d303 | bellard | qemu_get_be32s(f, &s->esr); |
919 | d592d303 | bellard | qemu_get_be32s(f, &s->icr[0]);
|
920 | d592d303 | bellard | qemu_get_be32s(f, &s->icr[1]);
|
921 | d592d303 | bellard | qemu_get_be32s(f, &s->divide_conf); |
922 | bee8d684 | ths | s->count_shift=qemu_get_be32(f); |
923 | d592d303 | bellard | qemu_get_be32s(f, &s->initial_count); |
924 | bee8d684 | ths | s->initial_count_load_time=qemu_get_be64(f); |
925 | bee8d684 | ths | s->next_time=qemu_get_be64(f); |
926 | e6cf6a8c | bellard | |
927 | e6cf6a8c | bellard | if (version_id >= 2) |
928 | e6cf6a8c | bellard | qemu_get_timer(f, s->timer); |
929 | d592d303 | bellard | return 0; |
930 | d592d303 | bellard | } |
931 | 574bbf7b | bellard | |
932 | 695dcf71 | Juan Quintela | static const VMStateDescription vmstate_apic = { |
933 | 695dcf71 | Juan Quintela | .name = "apic",
|
934 | 695dcf71 | Juan Quintela | .version_id = 3,
|
935 | 695dcf71 | Juan Quintela | .minimum_version_id = 3,
|
936 | 695dcf71 | Juan Quintela | .minimum_version_id_old = 1,
|
937 | 695dcf71 | Juan Quintela | .load_state_old = apic_load_old, |
938 | 695dcf71 | Juan Quintela | .fields = (VMStateField []) { |
939 | 695dcf71 | Juan Quintela | VMSTATE_UINT32(apicbase, APICState), |
940 | 695dcf71 | Juan Quintela | VMSTATE_UINT8(id, APICState), |
941 | 695dcf71 | Juan Quintela | VMSTATE_UINT8(arb_id, APICState), |
942 | 695dcf71 | Juan Quintela | VMSTATE_UINT8(tpr, APICState), |
943 | 695dcf71 | Juan Quintela | VMSTATE_UINT32(spurious_vec, APICState), |
944 | 695dcf71 | Juan Quintela | VMSTATE_UINT8(log_dest, APICState), |
945 | 695dcf71 | Juan Quintela | VMSTATE_UINT8(dest_mode, APICState), |
946 | 695dcf71 | Juan Quintela | VMSTATE_UINT32_ARRAY(isr, APICState, 8),
|
947 | 695dcf71 | Juan Quintela | VMSTATE_UINT32_ARRAY(tmr, APICState, 8),
|
948 | 695dcf71 | Juan Quintela | VMSTATE_UINT32_ARRAY(irr, APICState, 8),
|
949 | 695dcf71 | Juan Quintela | VMSTATE_UINT32_ARRAY(lvt, APICState, APIC_LVT_NB), |
950 | 695dcf71 | Juan Quintela | VMSTATE_UINT32(esr, APICState), |
951 | 695dcf71 | Juan Quintela | VMSTATE_UINT32_ARRAY(icr, APICState, 2),
|
952 | 695dcf71 | Juan Quintela | VMSTATE_UINT32(divide_conf, APICState), |
953 | 695dcf71 | Juan Quintela | VMSTATE_INT32(count_shift, APICState), |
954 | 695dcf71 | Juan Quintela | VMSTATE_UINT32(initial_count, APICState), |
955 | 695dcf71 | Juan Quintela | VMSTATE_INT64(initial_count_load_time, APICState), |
956 | 695dcf71 | Juan Quintela | VMSTATE_INT64(next_time, APICState), |
957 | 695dcf71 | Juan Quintela | VMSTATE_TIMER(timer, APICState), |
958 | 695dcf71 | Juan Quintela | VMSTATE_END_OF_LIST() |
959 | 695dcf71 | Juan Quintela | } |
960 | 695dcf71 | Juan Quintela | }; |
961 | 695dcf71 | Juan Quintela | |
962 | 8546b099 | Blue Swirl | static void apic_reset(DeviceState *d) |
963 | d592d303 | bellard | { |
964 | 8546b099 | Blue Swirl | APICState *s = DO_UPCAST(APICState, busdev.qdev, d); |
965 | 4c0960c0 | Avi Kivity | int bsp;
|
966 | fec5fa02 | aurel32 | |
967 | 4c0960c0 | Avi Kivity | bsp = cpu_is_bsp(s->cpu_env); |
968 | fec5fa02 | aurel32 | s->apicbase = 0xfee00000 |
|
969 | 678e12cc | Gleb Natapov | (bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE;
|
970 | fec5fa02 | aurel32 | |
971 | 92a16d7a | Blue Swirl | apic_init_reset(d); |
972 | 0e21e12b | ths | |
973 | 678e12cc | Gleb Natapov | if (bsp) {
|
974 | a5b38b51 | aurel32 | /*
|
975 | a5b38b51 | aurel32 | * LINT0 delivery mode on CPU #0 is set to ExtInt at initialization
|
976 | a5b38b51 | aurel32 | * time typically by BIOS, so PIC interrupt can be delivered to the
|
977 | a5b38b51 | aurel32 | * processor when local APIC is enabled.
|
978 | a5b38b51 | aurel32 | */
|
979 | a5b38b51 | aurel32 | s->lvt[APIC_LVT_LINT0] = 0x700;
|
980 | a5b38b51 | aurel32 | } |
981 | d592d303 | bellard | } |
982 | 574bbf7b | bellard | |
983 | 312b4234 | Avi Kivity | static const MemoryRegionOps apic_io_ops = { |
984 | 312b4234 | Avi Kivity | .old_mmio = { |
985 | 312b4234 | Avi Kivity | .read = { apic_mem_readb, apic_mem_readw, apic_mem_readl, }, |
986 | 312b4234 | Avi Kivity | .write = { apic_mem_writeb, apic_mem_writew, apic_mem_writel, }, |
987 | 312b4234 | Avi Kivity | }, |
988 | 312b4234 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
989 | 574bbf7b | bellard | }; |
990 | 574bbf7b | bellard | |
991 | 8546b099 | Blue Swirl | static int apic_init1(SysBusDevice *dev) |
992 | 8546b099 | Blue Swirl | { |
993 | 8546b099 | Blue Swirl | APICState *s = FROM_SYSBUS(APICState, dev); |
994 | 8546b099 | Blue Swirl | static int last_apic_idx; |
995 | 8546b099 | Blue Swirl | |
996 | 8546b099 | Blue Swirl | if (last_apic_idx >= MAX_APICS) {
|
997 | 8546b099 | Blue Swirl | return -1; |
998 | 8546b099 | Blue Swirl | } |
999 | 312b4234 | Avi Kivity | memory_region_init_io(&s->io_memory, &apic_io_ops, s, "apic",
|
1000 | 312b4234 | Avi Kivity | MSI_ADDR_SIZE); |
1001 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->io_memory); |
1002 | 8546b099 | Blue Swirl | |
1003 | 74475455 | Paolo Bonzini | s->timer = qemu_new_timer_ns(vm_clock, apic_timer, s); |
1004 | 8546b099 | Blue Swirl | s->idx = last_apic_idx++; |
1005 | 8546b099 | Blue Swirl | local_apics[s->idx] = s; |
1006 | 8546b099 | Blue Swirl | return 0; |
1007 | 8546b099 | Blue Swirl | } |
1008 | 8546b099 | Blue Swirl | |
1009 | 8546b099 | Blue Swirl | static SysBusDeviceInfo apic_info = {
|
1010 | 8546b099 | Blue Swirl | .init = apic_init1, |
1011 | 8546b099 | Blue Swirl | .qdev.name = "apic",
|
1012 | 8546b099 | Blue Swirl | .qdev.size = sizeof(APICState),
|
1013 | 8546b099 | Blue Swirl | .qdev.vmsd = &vmstate_apic, |
1014 | 8546b099 | Blue Swirl | .qdev.reset = apic_reset, |
1015 | 8546b099 | Blue Swirl | .qdev.no_user = 1,
|
1016 | 8546b099 | Blue Swirl | .qdev.props = (Property[]) { |
1017 | 8546b099 | Blue Swirl | DEFINE_PROP_UINT8("id", APICState, id, -1), |
1018 | 8546b099 | Blue Swirl | DEFINE_PROP_PTR("cpu_env", APICState, cpu_env),
|
1019 | 8546b099 | Blue Swirl | DEFINE_PROP_END_OF_LIST(), |
1020 | 8546b099 | Blue Swirl | } |
1021 | 8546b099 | Blue Swirl | }; |
1022 | 8546b099 | Blue Swirl | |
1023 | 8546b099 | Blue Swirl | static void apic_register_devices(void) |
1024 | 8546b099 | Blue Swirl | { |
1025 | 8546b099 | Blue Swirl | sysbus_register_withprop(&apic_info); |
1026 | 8546b099 | Blue Swirl | } |
1027 | 8546b099 | Blue Swirl | |
1028 | 8546b099 | Blue Swirl | device_init(apic_register_devices) |