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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c101dc0 was b2fa1204, checked in by Martin Sucha <sucha14@…>, 12 years ago

Cherrypick usage of kernel logger

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