source: mainline/kernel/arch/ia32/src/smp/apic.c@ 0a79ad9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0a79ad9 was 214ec25c, checked in by Martin Decky <martin@…>, 16 years ago

use unsigned integers for exception and interrupt numbers

  • Property mode set to 100644
File size: 14.3 KB
RevLine 
[f761f1eb]1/*
[df4ed85]2 * Copyright (c) 2001-2004 Jakub Jermar
[f761f1eb]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
[84afc7b]29/** @addtogroup ia32
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[d99c1d2]35#include <typedefs.h>
[397c77f]36#include <arch/smp/apic.h>
37#include <arch/smp/ap.h>
[ed0dd65]38#include <arch/smp/mps.h>
[66def8d]39#include <arch/boot/boot.h>
[f761f1eb]40#include <mm/page.h>
41#include <time/delay.h>
[fcfac420]42#include <interrupt.h>
[f761f1eb]43#include <arch/interrupt.h>
44#include <print.h>
45#include <arch/asm.h>
46#include <arch.h>
[3e35fd7]47#include <ddi/irq.h>
48#include <ddi/device.h>
[f761f1eb]49
[5f85c91]50#ifdef CONFIG_SMP
[8262010]51
[f761f1eb]52/*
[a83a802]53 * Advanced Programmable Interrupt Controller for SMP systems.
[f761f1eb]54 * Tested on:
[da1bafb]55 * Bochs 2.0.2 - Bochs 2.2.6 with 2-8 CPUs
56 * Simics 2.0.28 - Simics 2.2.19 2-15 CPUs
57 * VMware Workstation 5.5 with 2 CPUs
58 * QEMU 0.8.0 with 2-15 CPUs
59 * ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
60 * ASUS PCH-DL with 2x 3000Mhz Pentium 4 Xeon (HT) CPUs
61 * MSI K7D Master-L with 2x 2100MHz Athlon MP CPUs
62 *
[f761f1eb]63 */
64
65/*
66 * These variables either stay configured as initilalized, or are changed by
67 * the MP configuration code.
68 *
69 * Pay special attention to the volatile keyword. Without it, gcc -O2 would
70 * optimize the code too much and accesses to l_apic and io_apic, that must
71 * always be 32-bit, would use byte oriented instructions.
[da1bafb]72 *
[f761f1eb]73 */
[7f1c620]74volatile uint32_t *l_apic = (uint32_t *) 0xfee00000;
75volatile uint32_t *io_apic = (uint32_t *) 0xfec00000;
[f761f1eb]76
[7f1c620]77uint32_t apic_id_mask = 0;
[3e35fd7]78static irq_t l_apic_timer_irq;
[f761f1eb]79
[f701b236]80static int apic_poll_errors(void);
81
[9149135]82#ifdef LAPIC_VERBOSE
[da1bafb]83static const char *delmod_str[] = {
[f701b236]84 "Fixed",
85 "Lowest Priority",
86 "SMI",
87 "Reserved",
88 "NMI",
89 "INIT",
90 "STARTUP",
91 "ExtInt"
92};
93
[da1bafb]94static const char *destmod_str[] = {
[f701b236]95 "Physical",
96 "Logical"
97};
98
[da1bafb]99static const char *trigmod_str[] = {
[f701b236]100 "Edge",
101 "Level"
102};
103
[da1bafb]104static const char *mask_str[] = {
[f701b236]105 "Unmasked",
106 "Masked"
107};
108
[da1bafb]109static const char *delivs_str[] = {
[f701b236]110 "Idle",
111 "Send Pending"
112};
113
[da1bafb]114static const char *tm_mode_str[] = {
[f701b236]115 "One-shot",
116 "Periodic"
117};
118
[da1bafb]119static const char *intpol_str[] = {
[f701b236]120 "Polarity High",
121 "Polarity Low"
122};
[9149135]123#endif /* LAPIC_VERBOSE */
[f761f1eb]124
[3e35fd7]125/** APIC spurious interrupt handler.
126 *
[da1bafb]127 * @param n Interrupt vector.
[3e35fd7]128 * @param istate Interrupted state.
[da1bafb]129 *
[3e35fd7]130 */
[214ec25c]131static void apic_spurious(unsigned int n __attribute__((unused)),
[da1bafb]132 istate_t *istate __attribute__((unused)))
[3e35fd7]133{
134#ifdef CONFIG_DEBUG
[7f043c0]135 printf("cpu%u: APIC spurious interrupt\n", CPU->id);
[3e35fd7]136#endif
137}
[fcfac420]138
[c9b550b]139static irq_ownership_t l_apic_timer_claim(irq_t *irq)
[3e35fd7]140{
141 return IRQ_ACCEPT;
142}
143
[6cd9aa6]144static void l_apic_timer_irq_handler(irq_t *irq)
[3e35fd7]145{
[7e58979]146 /*
147 * Holding a spinlock could prevent clock() from preempting
148 * the current thread. In this case, we don't need to hold the
149 * irq->lock so we just unlock it and then lock it again.
150 */
[da1bafb]151 irq_spinlock_unlock(&irq->lock, false);
[3e35fd7]152 clock();
[da1bafb]153 irq_spinlock_lock(&irq->lock, false);
[3e35fd7]154}
[fcfac420]155
[8418c7d]156/** Initialize APIC on BSP. */
[f761f1eb]157void apic_init(void)
158{
[b3b7e14a]159 exc_register(VECTOR_APIC_SPUR, "apic_spurious", false,
160 (iroutine_t) apic_spurious);
[da1bafb]161
[f761f1eb]162 enable_irqs_function = io_apic_enable_irqs;
163 disable_irqs_function = io_apic_disable_irqs;
164 eoi_function = l_apic_eoi;
165
166 /*
167 * Configure interrupt routing.
168 * IRQ 0 remains masked as the time signal is generated by l_apic's themselves.
169 * Other interrupts will be forwarded to the lowest priority CPU.
170 */
171 io_apic_disable_irqs(0xffff);
[3e35fd7]172
173 irq_initialize(&l_apic_timer_irq);
[7bcfbbc]174 l_apic_timer_irq.preack = true;
[3e35fd7]175 l_apic_timer_irq.devno = device_assign_devno();
176 l_apic_timer_irq.inr = IRQ_CLK;
177 l_apic_timer_irq.claim = l_apic_timer_claim;
178 l_apic_timer_irq.handler = l_apic_timer_irq_handler;
179 irq_register(&l_apic_timer_irq);
180
[7f043c0]181 uint8_t i;
[9149135]182 for (i = 0; i < IRQ_COUNT; i++) {
[f761f1eb]183 int pin;
[da1bafb]184
[3e35fd7]185 if ((pin = smp_irq_to_pin(i)) != -1)
[7f043c0]186 io_apic_change_ioredtbl((uint8_t) pin, DEST_ALL, (uint8_t) (IVT_IRQBASE + i), LOPRI);
[f761f1eb]187 }
188
189 /*
190 * Ensure that io_apic has unique ID.
191 */
[da1bafb]192 io_apic_id_t idreg;
193
[9149135]194 idreg.value = io_apic_read(IOAPICID);
[da1bafb]195 if ((1 << idreg.apic_id) & apic_id_mask) { /* See if IO APIC ID is used already */
[9149135]196 for (i = 0; i < APIC_ID_COUNT; i++) {
[3e35fd7]197 if (!((1 << i) & apic_id_mask)) {
[9149135]198 idreg.apic_id = i;
199 io_apic_write(IOAPICID, idreg.value);
[f761f1eb]200 break;
201 }
202 }
203 }
[da1bafb]204
[f761f1eb]205 /*
206 * Configure the BSP's lapic.
207 */
208 l_apic_init();
[da1bafb]209 l_apic_debug();
[f761f1eb]210}
211
[f701b236]212/** Poll for APIC errors.
213 *
214 * Examine Error Status Register and report all errors found.
215 *
216 * @return 0 on error, 1 on success.
[da1bafb]217 *
[f701b236]218 */
[f761f1eb]219int apic_poll_errors(void)
220{
[f701b236]221 esr_t esr;
[f761f1eb]222
[f701b236]223 esr.value = l_apic[ESR];
[f761f1eb]224
[f701b236]225 if (esr.send_checksum_error)
[9149135]226 printf("Send Checksum Error\n");
[f701b236]227 if (esr.receive_checksum_error)
[9149135]228 printf("Receive Checksum Error\n");
[f701b236]229 if (esr.send_accept_error)
[f761f1eb]230 printf("Send Accept Error\n");
[f701b236]231 if (esr.receive_accept_error)
[f761f1eb]232 printf("Receive Accept Error\n");
[f701b236]233 if (esr.send_illegal_vector)
[f761f1eb]234 printf("Send Illegal Vector\n");
[f701b236]235 if (esr.received_illegal_vector)
[f761f1eb]236 printf("Received Illegal Vector\n");
[f701b236]237 if (esr.illegal_register_address)
[f761f1eb]238 printf("Illegal Register Address\n");
[da1bafb]239
[f701b236]240 return !esr.err_bitmap;
[f761f1eb]241}
242
[f701b236]243/** Send all CPUs excluding CPU IPI vector.
244 *
245 * @param vector Interrupt vector to be sent.
246 *
247 * @return 0 on failure, 1 on success.
[da1bafb]248 *
[169587a]249 */
[7f1c620]250int l_apic_broadcast_custom_ipi(uint8_t vector)
[169587a]251{
[8418c7d]252 icr_t icr;
[da1bafb]253
[8418c7d]254 icr.lo = l_apic[ICRlo];
255 icr.delmod = DELMOD_FIXED;
256 icr.destmod = DESTMOD_LOGIC;
257 icr.level = LEVEL_ASSERT;
258 icr.shorthand = SHORTHAND_ALL_EXCL;
259 icr.trigger_mode = TRIGMOD_LEVEL;
260 icr.vector = vector;
[da1bafb]261
[8418c7d]262 l_apic[ICRlo] = icr.lo;
[da1bafb]263
[8418c7d]264 icr.lo = l_apic[ICRlo];
[88636f68]265 if (icr.delivs == DELIVS_PENDING) {
266#ifdef CONFIG_DEBUG
[169587a]267 printf("IPI is pending.\n");
[88636f68]268#endif
269 }
[da1bafb]270
[169587a]271 return apic_poll_errors();
272}
273
[f701b236]274/** Universal Start-up Algorithm for bringing up the AP processors.
275 *
276 * @param apicid APIC ID of the processor to be brought up.
277 *
278 * @return 0 on failure, 1 on success.
[da1bafb]279 *
[f761f1eb]280 */
[7f1c620]281int l_apic_send_init_ipi(uint8_t apicid)
[f761f1eb]282{
283 /*
284 * Read the ICR register in and zero all non-reserved fields.
285 */
[da1bafb]286 icr_t icr;
287
[8418c7d]288 icr.lo = l_apic[ICRlo];
289 icr.hi = l_apic[ICRhi];
[f761f1eb]290
[8418c7d]291 icr.delmod = DELMOD_INIT;
292 icr.destmod = DESTMOD_PHYS;
293 icr.level = LEVEL_ASSERT;
294 icr.trigger_mode = TRIGMOD_LEVEL;
295 icr.shorthand = SHORTHAND_NONE;
296 icr.vector = 0;
297 icr.dest = apicid;
[f761f1eb]298
[8418c7d]299 l_apic[ICRhi] = icr.hi;
300 l_apic[ICRlo] = icr.lo;
[da1bafb]301
[f761f1eb]302 /*
303 * According to MP Specification, 20us should be enough to
304 * deliver the IPI.
305 */
306 delay(20);
[da1bafb]307
[88636f68]308 if (!apic_poll_errors())
309 return 0;
[da1bafb]310
[8418c7d]311 icr.lo = l_apic[ICRlo];
[88636f68]312 if (icr.delivs == DELIVS_PENDING) {
313#ifdef CONFIG_DEBUG
[f761f1eb]314 printf("IPI is pending.\n");
[88636f68]315#endif
316 }
[da1bafb]317
[8418c7d]318 icr.delmod = DELMOD_INIT;
319 icr.destmod = DESTMOD_PHYS;
320 icr.level = LEVEL_DEASSERT;
321 icr.shorthand = SHORTHAND_NONE;
322 icr.trigger_mode = TRIGMOD_LEVEL;
323 icr.vector = 0;
324 l_apic[ICRlo] = icr.lo;
[da1bafb]325
[f761f1eb]326 /*
327 * Wait 10ms as MP Specification specifies.
328 */
329 delay(10000);
[da1bafb]330
[c9b8c5c]331 if (!is_82489DX_apic(l_apic[LAVR])) {
332 /*
333 * If this is not 82489DX-based l_apic we must send two STARTUP IPI's.
334 */
[da1bafb]335 unsigned int i;
336 for (i = 0; i < 2; i++) {
[8418c7d]337 icr.lo = l_apic[ICRlo];
[7f043c0]338 icr.vector = (uint8_t) (((uintptr_t) ap_boot) >> 12); /* calculate the reset vector */
[8418c7d]339 icr.delmod = DELMOD_STARTUP;
340 icr.destmod = DESTMOD_PHYS;
341 icr.level = LEVEL_ASSERT;
342 icr.shorthand = SHORTHAND_NONE;
343 icr.trigger_mode = TRIGMOD_LEVEL;
344 l_apic[ICRlo] = icr.lo;
[c9b8c5c]345 delay(200);
346 }
[f761f1eb]347 }
348
349 return apic_poll_errors();
350}
351
[f701b236]352/** Initialize Local APIC. */
[f761f1eb]353void l_apic_init(void)
354{
[8418c7d]355 /* Initialize LVT Error register. */
[da1bafb]356 lvt_error_t error;
357
[8418c7d]358 error.value = l_apic[LVT_Err];
359 error.masked = true;
360 l_apic[LVT_Err] = error.value;
[da1bafb]361
[8418c7d]362 /* Initialize LVT LINT0 register. */
[da1bafb]363 lvt_lint_t lint;
364
[8418c7d]365 lint.value = l_apic[LVT_LINT0];
366 lint.masked = true;
367 l_apic[LVT_LINT0] = lint.value;
[da1bafb]368
[8418c7d]369 /* Initialize LVT LINT1 register. */
370 lint.value = l_apic[LVT_LINT1];
371 lint.masked = true;
372 l_apic[LVT_LINT1] = lint.value;
[da1bafb]373
[d0780b4c]374 /* Task Priority Register initialization. */
[da1bafb]375 tpr_t tpr;
376
[d0780b4c]377 tpr.value = l_apic[TPR];
378 tpr.pri_sc = 0;
379 tpr.pri = 0;
380 l_apic[TPR] = tpr.value;
[8418c7d]381
382 /* Spurious-Interrupt Vector Register initialization. */
[da1bafb]383 svr_t svr;
384
[8418c7d]385 svr.value = l_apic[SVR];
386 svr.vector = VECTOR_APIC_SPUR;
387 svr.lapic_enabled = true;
[d0780b4c]388 svr.focus_checking = true;
[8418c7d]389 l_apic[SVR] = svr.value;
[da1bafb]390
[434f700]391 if (CPU->arch.family >= 6)
392 enable_l_apic_in_msr();
[f761f1eb]393
[8418c7d]394 /* Interrupt Command Register initialization. */
[da1bafb]395 icr_t icr;
396
[8418c7d]397 icr.lo = l_apic[ICRlo];
398 icr.delmod = DELMOD_INIT;
399 icr.destmod = DESTMOD_PHYS;
400 icr.level = LEVEL_DEASSERT;
401 icr.shorthand = SHORTHAND_ALL_INCL;
402 icr.trigger_mode = TRIGMOD_LEVEL;
403 l_apic[ICRlo] = icr.lo;
[f761f1eb]404
[f701b236]405 /* Timer Divide Configuration Register initialization. */
[da1bafb]406 tdcr_t tdcr;
407
[f701b236]408 tdcr.value = l_apic[TDCR];
409 tdcr.div_value = DIVIDE_1;
410 l_apic[TDCR] = tdcr.value;
[da1bafb]411
[f701b236]412 /* Program local timer. */
[da1bafb]413 lvt_tm_t tm;
414
[8418c7d]415 tm.value = l_apic[LVT_Tm];
416 tm.vector = VECTOR_CLK;
417 tm.mode = TIMER_PERIODIC;
418 tm.masked = false;
419 l_apic[LVT_Tm] = tm.value;
[da1bafb]420
[e20de55]421 /*
422 * Measure and configure the timer to generate timer
423 * interrupt with period 1s/HZ seconds.
424 */
[da1bafb]425 uint32_t t1 = l_apic[CCRT];
[f761f1eb]426 l_apic[ICRT] = 0xffffffff;
[da1bafb]427
428 while (l_apic[CCRT] == t1);
429
[f761f1eb]430 t1 = l_apic[CCRT];
[da1bafb]431 delay(1000000 / HZ);
432 uint32_t t2 = l_apic[CCRT];
[f761f1eb]433
[da1bafb]434 l_apic[ICRT] = t1 - t2;
[93e90c7]435
436 /* Program Logical Destination Register. */
[5f0e39e8]437 ASSERT(CPU->id < 8);
[da1bafb]438 ldr_t ldr;
439
[93e90c7]440 ldr.value = l_apic[LDR];
[7f043c0]441 ldr.id = (uint8_t) (1 << CPU->id);
[93e90c7]442 l_apic[LDR] = ldr.value;
443
444 /* Program Destination Format Register for Flat mode. */
[da1bafb]445 dfr_t dfr;
446
[93e90c7]447 dfr.value = l_apic[DFR];
448 dfr.model = MODEL_FLAT;
449 l_apic[DFR] = dfr.value;
[f761f1eb]450}
451
[f701b236]452/** Local APIC End of Interrupt. */
[f761f1eb]453void l_apic_eoi(void)
454{
455 l_apic[EOI] = 0;
456}
457
[f701b236]458/** Dump content of Local APIC registers. */
[f761f1eb]459void l_apic_debug(void)
460{
461#ifdef LAPIC_VERBOSE
[da1bafb]462 printf("LVT on cpu%" PRIs ", LAPIC ID: %" PRIu8 "\n", CPU->id, l_apic_id());
[f761f1eb]463
[da1bafb]464 lvt_tm_t tm;
[f701b236]465 tm.value = l_apic[LVT_Tm];
[280a27e]466 printf("LVT Tm: vector=%hhd, %s, %s, %s\n", tm.vector, delivs_str[tm.delivs], mask_str[tm.masked], tm_mode_str[tm.mode]);
[da1bafb]467
468 lvt_lint_t lint;
[f701b236]469 lint.value = l_apic[LVT_LINT0];
[280a27e]470 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]);
[f701b236]471 lint.value = l_apic[LVT_LINT1];
[280a27e]472 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]);
[da1bafb]473
474 lvt_error_t error;
[f701b236]475 error.value = l_apic[LVT_Err];
[280a27e]476 printf("LVT Err: vector=%hhd, %s, %s\n", error.vector, delivs_str[error.delivs], mask_str[error.masked]);
[f761f1eb]477#endif
478}
479
[f701b236]480/** Get Local APIC ID.
481 *
482 * @return Local APIC ID.
[da1bafb]483 *
[f701b236]484 */
[7f1c620]485uint8_t l_apic_id(void)
[8262010]486{
[9149135]487 l_apic_id_t idreg;
[f701b236]488
[9149135]489 idreg.value = l_apic[L_APIC_ID];
490 return idreg.apic_id;
[8262010]491}
492
[f701b236]493/** Read from IO APIC register.
494 *
495 * @param address IO APIC register address.
496 *
497 * @return Content of the addressed IO APIC register.
[da1bafb]498 *
[f701b236]499 */
[7f1c620]500uint32_t io_apic_read(uint8_t address)
[f761f1eb]501{
[f701b236]502 io_regsel_t regsel;
[f761f1eb]503
[f701b236]504 regsel.value = io_apic[IOREGSEL];
505 regsel.reg_addr = address;
506 io_apic[IOREGSEL] = regsel.value;
[f761f1eb]507 return io_apic[IOWIN];
508}
509
[f701b236]510/** Write to IO APIC register.
511 *
512 * @param address IO APIC register address.
[da1bafb]513 * @param val Content to be written to the addressed IO APIC register.
514 *
[f701b236]515 */
[da1bafb]516void io_apic_write(uint8_t address, uint32_t val)
[f761f1eb]517{
[f701b236]518 io_regsel_t regsel;
519
520 regsel.value = io_apic[IOREGSEL];
521 regsel.reg_addr = address;
522 io_apic[IOREGSEL] = regsel.value;
[da1bafb]523 io_apic[IOWIN] = val;
[f761f1eb]524}
525
[f701b236]526/** Change some attributes of one item in I/O Redirection Table.
527 *
[da1bafb]528 * @param pin IO APIC pin number.
529 * @param dest Interrupt destination address.
530 * @param vec Interrupt vector to trigger.
[f701b236]531 * @param flags Flags.
[da1bafb]532 *
[f701b236]533 */
[da1bafb]534void io_apic_change_ioredtbl(uint8_t pin, uint8_t dest, uint8_t vec,
535 unsigned int flags)
[f761f1eb]536{
[da1bafb]537 unsigned int dlvr;
[f761f1eb]538
539 if (flags & LOPRI)
[a83a802]540 dlvr = DELMOD_LOWPRI;
[da1bafb]541 else
542 dlvr = DELMOD_FIXED;
543
544 io_redirection_reg_t reg;
[7f043c0]545 reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
546 reg.hi = io_apic_read((uint8_t) (IOREDTBL + pin * 2 + 1));
[f761f1eb]547
[93e90c7]548 reg.dest = dest;
[a83a802]549 reg.destmod = DESTMOD_LOGIC;
550 reg.trigger_mode = TRIGMOD_EDGE;
551 reg.intpol = POLARITY_HIGH;
552 reg.delmod = dlvr;
[da1bafb]553 reg.intvec = vec;
554
[7f043c0]555 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
556 io_apic_write((uint8_t) (IOREDTBL + pin * 2 + 1), reg.hi);
[f761f1eb]557}
558
[f701b236]559/** Mask IRQs in IO APIC.
560 *
561 * @param irqmask Bitmask of IRQs to be masked (0 = do not mask, 1 = mask).
[da1bafb]562 *
[f701b236]563 */
[7f1c620]564void io_apic_disable_irqs(uint16_t irqmask)
[f761f1eb]565{
[623b49f1]566 unsigned int i;
567 for (i = 0; i < 16; i++) {
568 if (irqmask & (1 << i)) {
[f761f1eb]569 /*
570 * Mask the signal input in IO APIC if there is a
571 * mapping for the respective IRQ number.
572 */
[da1bafb]573 int pin = smp_irq_to_pin(i);
[f761f1eb]574 if (pin != -1) {
[da1bafb]575 io_redirection_reg_t reg;
576
[7f043c0]577 reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
[a83a802]578 reg.masked = true;
[7f043c0]579 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
[f761f1eb]580 }
581
582 }
583 }
584}
585
[f701b236]586/** Unmask IRQs in IO APIC.
587 *
588 * @param irqmask Bitmask of IRQs to be unmasked (0 = do not unmask, 1 = unmask).
[da1bafb]589 *
[f701b236]590 */
[7f1c620]591void io_apic_enable_irqs(uint16_t irqmask)
[f761f1eb]592{
[623b49f1]593 unsigned int i;
[7f043c0]594 for (i = 0; i < 16; i++) {
[623b49f1]595 if (irqmask & (1 << i)) {
[f761f1eb]596 /*
597 * Unmask the signal input in IO APIC if there is a
598 * mapping for the respective IRQ number.
599 */
[da1bafb]600 int pin = smp_irq_to_pin(i);
[f761f1eb]601 if (pin != -1) {
[da1bafb]602 io_redirection_reg_t reg;
603
[7f043c0]604 reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
[a83a802]605 reg.masked = false;
[7f043c0]606 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
[f761f1eb]607 }
608
609 }
610 }
611}
612
[5f85c91]613#endif /* CONFIG_SMP */
[b45c443]614
[06e1e95]615/** @}
[b45c443]616 */
Note: See TracBrowser for help on using the repository browser.