Rev 1667 | Rev 1702 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #include <arch/types.h> |
||
11 | jermar | 30 | #include <arch/smp/apic.h> |
31 | #include <arch/smp/ap.h> |
||
34 | jermar | 32 | #include <arch/smp/mps.h> |
693 | decky | 33 | #include <arch/boot/boot.h> |
1 | jermar | 34 | #include <mm/page.h> |
35 | #include <time/delay.h> |
||
576 | palkovsky | 36 | #include <interrupt.h> |
1 | jermar | 37 | #include <arch/interrupt.h> |
38 | #include <print.h> |
||
39 | #include <arch/asm.h> |
||
40 | #include <arch.h> |
||
41 | |||
458 | decky | 42 | #ifdef CONFIG_SMP |
16 | jermar | 43 | |
1 | jermar | 44 | /* |
512 | jermar | 45 | * Advanced Programmable Interrupt Controller for SMP systems. |
1 | jermar | 46 | * Tested on: |
750 | jermar | 47 | * Bochs 2.0.2 - Bochs 2.2.6 with 2-8 CPUs |
523 | jermar | 48 | * Simics 2.0.28 - Simics 2.2.19 2-15 CPUs |
516 | jermar | 49 | * VMware Workstation 5.5 with 2 CPUs |
812 | jermar | 50 | * QEMU 0.8.0 with 2-15 CPUs |
1 | jermar | 51 | * ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs |
437 | decky | 52 | * ASUS PCH-DL with 2x 3000Mhz Pentium 4 Xeon (HT) CPUs |
53 | * MSI K7D Master-L with 2x 2100MHz Athlon MP CPUs |
||
1 | jermar | 54 | */ |
55 | |||
56 | /* |
||
57 | * These variables either stay configured as initilalized, or are changed by |
||
58 | * the MP configuration code. |
||
59 | * |
||
60 | * Pay special attention to the volatile keyword. Without it, gcc -O2 would |
||
61 | * optimize the code too much and accesses to l_apic and io_apic, that must |
||
62 | * always be 32-bit, would use byte oriented instructions. |
||
63 | */ |
||
64 | volatile __u32 *l_apic = (__u32 *) 0xfee00000; |
||
65 | volatile __u32 *io_apic = (__u32 *) 0xfec00000; |
||
66 | |||
67 | __u32 apic_id_mask = 0; |
||
68 | |||
514 | jermar | 69 | static int apic_poll_errors(void); |
1 | jermar | 70 | |
515 | jermar | 71 | #ifdef LAPIC_VERBOSE |
514 | jermar | 72 | static char *delmod_str[] = { |
73 | "Fixed", |
||
74 | "Lowest Priority", |
||
75 | "SMI", |
||
76 | "Reserved", |
||
77 | "NMI", |
||
78 | "INIT", |
||
79 | "STARTUP", |
||
80 | "ExtInt" |
||
81 | }; |
||
82 | |||
83 | static char *destmod_str[] = { |
||
84 | "Physical", |
||
85 | "Logical" |
||
86 | }; |
||
87 | |||
88 | static char *trigmod_str[] = { |
||
89 | "Edge", |
||
90 | "Level" |
||
91 | }; |
||
92 | |||
93 | static char *mask_str[] = { |
||
94 | "Unmasked", |
||
95 | "Masked" |
||
96 | }; |
||
97 | |||
98 | static char *delivs_str[] = { |
||
99 | "Idle", |
||
100 | "Send Pending" |
||
101 | }; |
||
102 | |||
103 | static char *tm_mode_str[] = { |
||
104 | "One-shot", |
||
105 | "Periodic" |
||
106 | }; |
||
107 | |||
108 | static char *intpol_str[] = { |
||
109 | "Polarity High", |
||
110 | "Polarity Low" |
||
111 | }; |
||
515 | jermar | 112 | #endif /* LAPIC_VERBOSE */ |
514 | jermar | 113 | |
576 | palkovsky | 114 | |
958 | jermar | 115 | static void apic_spurious(int n, istate_t *istate); |
116 | static void l_apic_timer_interrupt(int n, istate_t *istate); |
||
576 | palkovsky | 117 | |
513 | jermar | 118 | /** Initialize APIC on BSP. */ |
1 | jermar | 119 | void apic_init(void) |
120 | { |
||
515 | jermar | 121 | io_apic_id_t idreg; |
122 | int i; |
||
1 | jermar | 123 | |
958 | jermar | 124 | exc_register(VECTOR_APIC_SPUR, "apic_spurious", (iroutine) apic_spurious); |
1 | jermar | 125 | |
126 | enable_irqs_function = io_apic_enable_irqs; |
||
127 | disable_irqs_function = io_apic_disable_irqs; |
||
128 | eoi_function = l_apic_eoi; |
||
129 | |||
130 | /* |
||
131 | * Configure interrupt routing. |
||
132 | * IRQ 0 remains masked as the time signal is generated by l_apic's themselves. |
||
133 | * Other interrupts will be forwarded to the lowest priority CPU. |
||
134 | */ |
||
135 | io_apic_disable_irqs(0xffff); |
||
958 | jermar | 136 | exc_register(VECTOR_CLK, "l_apic_timer", (iroutine) l_apic_timer_interrupt); |
515 | jermar | 137 | for (i = 0; i < IRQ_COUNT; i++) { |
1 | jermar | 138 | int pin; |
139 | |||
512 | jermar | 140 | if ((pin = smp_irq_to_pin(i)) != -1) { |
515 | jermar | 141 | io_apic_change_ioredtbl(pin, DEST_ALL, IVT_IRQBASE+i, LOPRI); |
512 | jermar | 142 | } |
1 | jermar | 143 | } |
144 | |||
145 | /* |
||
146 | * Ensure that io_apic has unique ID. |
||
147 | */ |
||
515 | jermar | 148 | idreg.value = io_apic_read(IOAPICID); |
149 | if ((1<<idreg.apic_id) & apic_id_mask) { /* see if IO APIC ID is used already */ |
||
150 | for (i = 0; i < APIC_ID_COUNT; i++) { |
||
1 | jermar | 151 | if (!((1<<i) & apic_id_mask)) { |
515 | jermar | 152 | idreg.apic_id = i; |
153 | io_apic_write(IOAPICID, idreg.value); |
||
1 | jermar | 154 | break; |
155 | } |
||
156 | } |
||
157 | } |
||
158 | |||
159 | /* |
||
160 | * Configure the BSP's lapic. |
||
161 | */ |
||
162 | l_apic_init(); |
||
515 | jermar | 163 | |
1 | jermar | 164 | l_apic_debug(); |
165 | } |
||
166 | |||
514 | jermar | 167 | /** APIC spurious interrupt handler. |
168 | * |
||
169 | * @param n Interrupt vector. |
||
170 | * @param stack Interrupted stack. |
||
171 | */ |
||
958 | jermar | 172 | void apic_spurious(int n, istate_t *istate) |
1 | jermar | 173 | { |
1667 | jermar | 174 | #ifdef CONFIG_DEBUG |
15 | jermar | 175 | printf("cpu%d: APIC spurious interrupt\n", CPU->id); |
1667 | jermar | 176 | #endif |
1 | jermar | 177 | } |
178 | |||
514 | jermar | 179 | /** Poll for APIC errors. |
180 | * |
||
181 | * Examine Error Status Register and report all errors found. |
||
182 | * |
||
183 | * @return 0 on error, 1 on success. |
||
184 | */ |
||
1 | jermar | 185 | int apic_poll_errors(void) |
186 | { |
||
514 | jermar | 187 | esr_t esr; |
1 | jermar | 188 | |
514 | jermar | 189 | esr.value = l_apic[ESR]; |
1 | jermar | 190 | |
514 | jermar | 191 | if (esr.send_checksum_error) |
515 | jermar | 192 | printf("Send Checksum Error\n"); |
514 | jermar | 193 | if (esr.receive_checksum_error) |
515 | jermar | 194 | printf("Receive Checksum Error\n"); |
514 | jermar | 195 | if (esr.send_accept_error) |
1 | jermar | 196 | printf("Send Accept Error\n"); |
514 | jermar | 197 | if (esr.receive_accept_error) |
1 | jermar | 198 | printf("Receive Accept Error\n"); |
514 | jermar | 199 | if (esr.send_illegal_vector) |
1 | jermar | 200 | printf("Send Illegal Vector\n"); |
514 | jermar | 201 | if (esr.received_illegal_vector) |
1 | jermar | 202 | printf("Received Illegal Vector\n"); |
514 | jermar | 203 | if (esr.illegal_register_address) |
1 | jermar | 204 | printf("Illegal Register Address\n"); |
125 | jermar | 205 | |
514 | jermar | 206 | return !esr.err_bitmap; |
1 | jermar | 207 | } |
208 | |||
514 | jermar | 209 | /** Send all CPUs excluding CPU IPI vector. |
210 | * |
||
211 | * @param vector Interrupt vector to be sent. |
||
212 | * |
||
213 | * @return 0 on failure, 1 on success. |
||
5 | jermar | 214 | */ |
215 | int l_apic_broadcast_custom_ipi(__u8 vector) |
||
216 | { |
||
513 | jermar | 217 | icr_t icr; |
5 | jermar | 218 | |
513 | jermar | 219 | icr.lo = l_apic[ICRlo]; |
220 | icr.delmod = DELMOD_FIXED; |
||
221 | icr.destmod = DESTMOD_LOGIC; |
||
222 | icr.level = LEVEL_ASSERT; |
||
223 | icr.shorthand = SHORTHAND_ALL_EXCL; |
||
224 | icr.trigger_mode = TRIGMOD_LEVEL; |
||
225 | icr.vector = vector; |
||
5 | jermar | 226 | |
513 | jermar | 227 | l_apic[ICRlo] = icr.lo; |
5 | jermar | 228 | |
513 | jermar | 229 | icr.lo = l_apic[ICRlo]; |
1684 | jermar | 230 | if (icr.delivs == DELIVS_PENDING) { |
231 | #ifdef CONFIG_DEBUG |
||
5 | jermar | 232 | printf("IPI is pending.\n"); |
1684 | jermar | 233 | #endif |
234 | } |
||
5 | jermar | 235 | |
236 | return apic_poll_errors(); |
||
237 | } |
||
238 | |||
514 | jermar | 239 | /** Universal Start-up Algorithm for bringing up the AP processors. |
240 | * |
||
241 | * @param apicid APIC ID of the processor to be brought up. |
||
242 | * |
||
243 | * @return 0 on failure, 1 on success. |
||
1 | jermar | 244 | */ |
245 | int l_apic_send_init_ipi(__u8 apicid) |
||
246 | { |
||
513 | jermar | 247 | icr_t icr; |
1 | jermar | 248 | int i; |
249 | |||
250 | /* |
||
251 | * Read the ICR register in and zero all non-reserved fields. |
||
252 | */ |
||
513 | jermar | 253 | icr.lo = l_apic[ICRlo]; |
254 | icr.hi = l_apic[ICRhi]; |
||
1 | jermar | 255 | |
513 | jermar | 256 | icr.delmod = DELMOD_INIT; |
257 | icr.destmod = DESTMOD_PHYS; |
||
258 | icr.level = LEVEL_ASSERT; |
||
259 | icr.trigger_mode = TRIGMOD_LEVEL; |
||
260 | icr.shorthand = SHORTHAND_NONE; |
||
261 | icr.vector = 0; |
||
262 | icr.dest = apicid; |
||
1 | jermar | 263 | |
513 | jermar | 264 | l_apic[ICRhi] = icr.hi; |
265 | l_apic[ICRlo] = icr.lo; |
||
27 | jermar | 266 | |
1 | jermar | 267 | /* |
268 | * According to MP Specification, 20us should be enough to |
||
269 | * deliver the IPI. |
||
270 | */ |
||
271 | delay(20); |
||
272 | |||
1684 | jermar | 273 | if (!apic_poll_errors()) |
274 | return 0; |
||
1 | jermar | 275 | |
513 | jermar | 276 | icr.lo = l_apic[ICRlo]; |
1684 | jermar | 277 | if (icr.delivs == DELIVS_PENDING) { |
278 | #ifdef CONFIG_DEBUG |
||
1 | jermar | 279 | printf("IPI is pending.\n"); |
1684 | jermar | 280 | #endif |
281 | } |
||
27 | jermar | 282 | |
513 | jermar | 283 | icr.delmod = DELMOD_INIT; |
284 | icr.destmod = DESTMOD_PHYS; |
||
285 | icr.level = LEVEL_DEASSERT; |
||
286 | icr.shorthand = SHORTHAND_NONE; |
||
287 | icr.trigger_mode = TRIGMOD_LEVEL; |
||
288 | icr.vector = 0; |
||
289 | l_apic[ICRlo] = icr.lo; |
||
1 | jermar | 290 | |
291 | /* |
||
292 | * Wait 10ms as MP Specification specifies. |
||
293 | */ |
||
294 | delay(10000); |
||
295 | |||
27 | jermar | 296 | if (!is_82489DX_apic(l_apic[LAVR])) { |
297 | /* |
||
298 | * If this is not 82489DX-based l_apic we must send two STARTUP IPI's. |
||
299 | */ |
||
300 | for (i = 0; i<2; i++) { |
||
513 | jermar | 301 | icr.lo = l_apic[ICRlo]; |
302 | icr.vector = ((__address) ap_boot) / 4096; /* calculate the reset vector */ |
||
303 | icr.delmod = DELMOD_STARTUP; |
||
304 | icr.destmod = DESTMOD_PHYS; |
||
305 | icr.level = LEVEL_ASSERT; |
||
306 | icr.shorthand = SHORTHAND_NONE; |
||
307 | icr.trigger_mode = TRIGMOD_LEVEL; |
||
308 | l_apic[ICRlo] = icr.lo; |
||
27 | jermar | 309 | delay(200); |
310 | } |
||
1 | jermar | 311 | } |
312 | |||
313 | return apic_poll_errors(); |
||
314 | } |
||
315 | |||
514 | jermar | 316 | /** Initialize Local APIC. */ |
1 | jermar | 317 | void l_apic_init(void) |
318 | { |
||
513 | jermar | 319 | lvt_error_t error; |
320 | lvt_lint_t lint; |
||
750 | jermar | 321 | tpr_t tpr; |
513 | jermar | 322 | svr_t svr; |
514 | jermar | 323 | icr_t icr; |
324 | tdcr_t tdcr; |
||
513 | jermar | 325 | lvt_tm_t tm; |
672 | jermar | 326 | ldr_t ldr; |
327 | dfr_t dfr; |
||
513 | jermar | 328 | __u32 t1, t2; |
1 | jermar | 329 | |
513 | jermar | 330 | /* Initialize LVT Error register. */ |
331 | error.value = l_apic[LVT_Err]; |
||
332 | error.masked = true; |
||
333 | l_apic[LVT_Err] = error.value; |
||
1 | jermar | 334 | |
513 | jermar | 335 | /* Initialize LVT LINT0 register. */ |
336 | lint.value = l_apic[LVT_LINT0]; |
||
337 | lint.masked = true; |
||
338 | l_apic[LVT_LINT0] = lint.value; |
||
1 | jermar | 339 | |
513 | jermar | 340 | /* Initialize LVT LINT1 register. */ |
341 | lint.value = l_apic[LVT_LINT1]; |
||
342 | lint.masked = true; |
||
343 | l_apic[LVT_LINT1] = lint.value; |
||
750 | jermar | 344 | |
345 | /* Task Priority Register initialization. */ |
||
346 | tpr.value = l_apic[TPR]; |
||
347 | tpr.pri_sc = 0; |
||
348 | tpr.pri = 0; |
||
349 | l_apic[TPR] = tpr.value; |
||
513 | jermar | 350 | |
351 | /* Spurious-Interrupt Vector Register initialization. */ |
||
352 | svr.value = l_apic[SVR]; |
||
353 | svr.vector = VECTOR_APIC_SPUR; |
||
354 | svr.lapic_enabled = true; |
||
750 | jermar | 355 | svr.focus_checking = true; |
513 | jermar | 356 | l_apic[SVR] = svr.value; |
357 | |||
31 | jermar | 358 | if (CPU->arch.family >= 6) |
359 | enable_l_apic_in_msr(); |
||
1 | jermar | 360 | |
513 | jermar | 361 | /* Interrupt Command Register initialization. */ |
362 | icr.lo = l_apic[ICRlo]; |
||
363 | icr.delmod = DELMOD_INIT; |
||
364 | icr.destmod = DESTMOD_PHYS; |
||
365 | icr.level = LEVEL_DEASSERT; |
||
366 | icr.shorthand = SHORTHAND_ALL_INCL; |
||
367 | icr.trigger_mode = TRIGMOD_LEVEL; |
||
368 | l_apic[ICRlo] = icr.lo; |
||
1 | jermar | 369 | |
514 | jermar | 370 | /* Timer Divide Configuration Register initialization. */ |
371 | tdcr.value = l_apic[TDCR]; |
||
372 | tdcr.div_value = DIVIDE_1; |
||
373 | l_apic[TDCR] = tdcr.value; |
||
1 | jermar | 374 | |
514 | jermar | 375 | /* Program local timer. */ |
513 | jermar | 376 | tm.value = l_apic[LVT_Tm]; |
377 | tm.vector = VECTOR_CLK; |
||
378 | tm.mode = TIMER_PERIODIC; |
||
379 | tm.masked = false; |
||
380 | l_apic[LVT_Tm] = tm.value; |
||
381 | |||
1540 | jermar | 382 | /* |
383 | * Measure and configure the timer to generate timer |
||
384 | * interrupt with period 1s/HZ seconds. |
||
385 | */ |
||
1 | jermar | 386 | t1 = l_apic[CCRT]; |
387 | l_apic[ICRT] = 0xffffffff; |
||
388 | |||
389 | while (l_apic[CCRT] == t1) |
||
390 | ; |
||
391 | |||
392 | t1 = l_apic[CCRT]; |
||
1540 | jermar | 393 | delay(1000000/HZ); |
1 | jermar | 394 | t2 = l_apic[CCRT]; |
395 | |||
396 | l_apic[ICRT] = t1-t2; |
||
672 | jermar | 397 | |
398 | /* Program Logical Destination Register. */ |
||
399 | ldr.value = l_apic[LDR]; |
||
400 | if (CPU->id < sizeof(CPU->id)*8) /* size in bits */ |
||
401 | ldr.id = (1<<CPU->id); |
||
402 | l_apic[LDR] = ldr.value; |
||
403 | |||
404 | /* Program Destination Format Register for Flat mode. */ |
||
405 | dfr.value = l_apic[DFR]; |
||
406 | dfr.model = MODEL_FLAT; |
||
407 | l_apic[DFR] = dfr.value; |
||
1 | jermar | 408 | } |
409 | |||
514 | jermar | 410 | /** Local APIC End of Interrupt. */ |
1 | jermar | 411 | void l_apic_eoi(void) |
412 | { |
||
413 | l_apic[EOI] = 0; |
||
414 | } |
||
415 | |||
514 | jermar | 416 | /** Dump content of Local APIC registers. */ |
1 | jermar | 417 | void l_apic_debug(void) |
418 | { |
||
419 | #ifdef LAPIC_VERBOSE |
||
514 | jermar | 420 | lvt_tm_t tm; |
421 | lvt_lint_t lint; |
||
422 | lvt_error_t error; |
||
423 | |||
16 | jermar | 424 | printf("LVT on cpu%d, LAPIC ID: %d\n", CPU->id, l_apic_id()); |
1 | jermar | 425 | |
514 | jermar | 426 | tm.value = l_apic[LVT_Tm]; |
1196 | cejka | 427 | printf("LVT Tm: vector=%hhd, %s, %s, %s\n", tm.vector, delivs_str[tm.delivs], mask_str[tm.masked], tm_mode_str[tm.mode]); |
514 | jermar | 428 | lint.value = l_apic[LVT_LINT0]; |
1196 | cejka | 429 | printf("LVT LINT0: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]); |
514 | jermar | 430 | lint.value = l_apic[LVT_LINT1]; |
1196 | cejka | 431 | printf("LVT LINT1: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]); |
514 | jermar | 432 | error.value = l_apic[LVT_Err]; |
1196 | cejka | 433 | printf("LVT Err: vector=%hhd, %s, %s\n", error.vector, delivs_str[error.delivs], mask_str[error.masked]); |
1 | jermar | 434 | #endif |
435 | } |
||
436 | |||
514 | jermar | 437 | /** Local APIC Timer Interrupt. |
438 | * |
||
439 | * @param n Interrupt vector number. |
||
440 | * @param stack Interrupted stack. |
||
441 | */ |
||
958 | jermar | 442 | void l_apic_timer_interrupt(int n, istate_t *istate) |
1 | jermar | 443 | { |
444 | l_apic_eoi(); |
||
445 | clock(); |
||
446 | } |
||
447 | |||
514 | jermar | 448 | /** Get Local APIC ID. |
449 | * |
||
450 | * @return Local APIC ID. |
||
451 | */ |
||
81 | jermar | 452 | __u8 l_apic_id(void) |
16 | jermar | 453 | { |
515 | jermar | 454 | l_apic_id_t idreg; |
514 | jermar | 455 | |
515 | jermar | 456 | idreg.value = l_apic[L_APIC_ID]; |
457 | return idreg.apic_id; |
||
16 | jermar | 458 | } |
459 | |||
514 | jermar | 460 | /** Read from IO APIC register. |
461 | * |
||
462 | * @param address IO APIC register address. |
||
463 | * |
||
464 | * @return Content of the addressed IO APIC register. |
||
465 | */ |
||
1 | jermar | 466 | __u32 io_apic_read(__u8 address) |
467 | { |
||
514 | jermar | 468 | io_regsel_t regsel; |
1 | jermar | 469 | |
514 | jermar | 470 | regsel.value = io_apic[IOREGSEL]; |
471 | regsel.reg_addr = address; |
||
472 | io_apic[IOREGSEL] = regsel.value; |
||
1 | jermar | 473 | return io_apic[IOWIN]; |
474 | } |
||
475 | |||
514 | jermar | 476 | /** Write to IO APIC register. |
477 | * |
||
478 | * @param address IO APIC register address. |
||
479 | * @param Content to be written to the addressed IO APIC register. |
||
480 | */ |
||
1 | jermar | 481 | void io_apic_write(__u8 address, __u32 x) |
482 | { |
||
514 | jermar | 483 | io_regsel_t regsel; |
484 | |||
485 | regsel.value = io_apic[IOREGSEL]; |
||
486 | regsel.reg_addr = address; |
||
487 | io_apic[IOREGSEL] = regsel.value; |
||
1 | jermar | 488 | io_apic[IOWIN] = x; |
489 | } |
||
490 | |||
514 | jermar | 491 | /** Change some attributes of one item in I/O Redirection Table. |
492 | * |
||
493 | * @param pin IO APIC pin number. |
||
494 | * @param dest Interrupt destination address. |
||
495 | * @param v Interrupt vector to trigger. |
||
496 | * @param flags Flags. |
||
497 | */ |
||
498 | void io_apic_change_ioredtbl(int pin, int dest, __u8 v, int flags) |
||
1 | jermar | 499 | { |
512 | jermar | 500 | io_redirection_reg_t reg; |
514 | jermar | 501 | int dlvr = DELMOD_FIXED; |
1 | jermar | 502 | |
503 | if (flags & LOPRI) |
||
512 | jermar | 504 | dlvr = DELMOD_LOWPRI; |
505 | |||
514 | jermar | 506 | reg.lo = io_apic_read(IOREDTBL + pin*2); |
507 | reg.hi = io_apic_read(IOREDTBL + pin*2 + 1); |
||
1 | jermar | 508 | |
672 | jermar | 509 | reg.dest = dest; |
512 | jermar | 510 | reg.destmod = DESTMOD_LOGIC; |
511 | reg.trigger_mode = TRIGMOD_EDGE; |
||
512 | reg.intpol = POLARITY_HIGH; |
||
513 | reg.delmod = dlvr; |
||
514 | reg.intvec = v; |
||
1 | jermar | 515 | |
514 | jermar | 516 | io_apic_write(IOREDTBL + pin*2, reg.lo); |
517 | io_apic_write(IOREDTBL + pin*2 + 1, reg.hi); |
||
1 | jermar | 518 | } |
519 | |||
514 | jermar | 520 | /** Mask IRQs in IO APIC. |
521 | * |
||
522 | * @param irqmask Bitmask of IRQs to be masked (0 = do not mask, 1 = mask). |
||
523 | */ |
||
1 | jermar | 524 | void io_apic_disable_irqs(__u16 irqmask) |
525 | { |
||
512 | jermar | 526 | io_redirection_reg_t reg; |
527 | int i, pin; |
||
1 | jermar | 528 | |
529 | for (i=0;i<16;i++) { |
||
515 | jermar | 530 | if (irqmask & (1<<i)) { |
1 | jermar | 531 | /* |
532 | * Mask the signal input in IO APIC if there is a |
||
533 | * mapping for the respective IRQ number. |
||
534 | */ |
||
512 | jermar | 535 | pin = smp_irq_to_pin(i); |
1 | jermar | 536 | if (pin != -1) { |
512 | jermar | 537 | reg.lo = io_apic_read(IOREDTBL + pin*2); |
538 | reg.masked = true; |
||
539 | io_apic_write(IOREDTBL + pin*2, reg.lo); |
||
1 | jermar | 540 | } |
541 | |||
542 | } |
||
543 | } |
||
544 | } |
||
545 | |||
514 | jermar | 546 | /** Unmask IRQs in IO APIC. |
547 | * |
||
548 | * @param irqmask Bitmask of IRQs to be unmasked (0 = do not unmask, 1 = unmask). |
||
549 | */ |
||
1 | jermar | 550 | void io_apic_enable_irqs(__u16 irqmask) |
551 | { |
||
512 | jermar | 552 | int i, pin; |
553 | io_redirection_reg_t reg; |
||
1 | jermar | 554 | |
555 | for (i=0;i<16;i++) { |
||
515 | jermar | 556 | if (irqmask & (1<<i)) { |
1 | jermar | 557 | /* |
558 | * Unmask the signal input in IO APIC if there is a |
||
559 | * mapping for the respective IRQ number. |
||
560 | */ |
||
512 | jermar | 561 | pin = smp_irq_to_pin(i); |
1 | jermar | 562 | if (pin != -1) { |
512 | jermar | 563 | reg.lo = io_apic_read(IOREDTBL + pin*2); |
564 | reg.masked = false; |
||
565 | io_apic_write(IOREDTBL + pin*2, reg.lo); |
||
1 | jermar | 566 | } |
567 | |||
568 | } |
||
569 | } |
||
570 | } |
||
571 | |||
458 | decky | 572 | #endif /* CONFIG_SMP */ |