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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8a5a902 was 5e4f22b, checked in by Jakub Jermar <jakub@…>, 13 years ago

When sending an IPI, wait for its successful delivery.

  • Property mode set to 100644
File size: 14.7 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 */
[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
[7f043c0]137 printf("cpu%u: APIC spurious interrupt\n", 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
[f701b236]243 if (esr.send_checksum_error)
[9149135]244 printf("Send Checksum Error\n");
[f701b236]245 if (esr.receive_checksum_error)
[9149135]246 printf("Receive Checksum Error\n");
[f701b236]247 if (esr.send_accept_error)
[f761f1eb]248 printf("Send Accept Error\n");
[f701b236]249 if (esr.receive_accept_error)
[f761f1eb]250 printf("Receive Accept Error\n");
[f701b236]251 if (esr.send_illegal_vector)
[f761f1eb]252 printf("Send Illegal Vector\n");
[f701b236]253 if (esr.received_illegal_vector)
[f761f1eb]254 printf("Received Illegal Vector\n");
[f701b236]255 if (esr.illegal_register_address)
[f761f1eb]256 printf("Illegal Register Address\n");
[da1bafb]257
[f701b236]258 return !esr.err_bitmap;
[f761f1eb]259}
260
[5e4f22b]261#define DELIVS_PENDING_SILENT_RETRIES 4
262
263static void l_apic_wait_for_delivery(void)
264{
265 icr_t icr;
266 unsigned retries = 0;
267
268 do {
269 if (retries++ > DELIVS_PENDING_SILENT_RETRIES) {
270 retries = 0;
271#ifdef CONFIG_DEBUG
272 printf("IPI is pending.\n");
273#endif
274 delay(20);
275 }
276 icr.lo = l_apic[ICRlo];
277 } while (icr.delivs == DELIVS_PENDING);
278
279}
280
[f701b236]281/** Send all CPUs excluding CPU IPI vector.
282 *
283 * @param vector Interrupt vector to be sent.
284 *
285 * @return 0 on failure, 1 on success.
[da1bafb]286 *
[169587a]287 */
[7f1c620]288int l_apic_broadcast_custom_ipi(uint8_t vector)
[169587a]289{
[8418c7d]290 icr_t icr;
[da1bafb]291
[8418c7d]292 icr.lo = l_apic[ICRlo];
293 icr.delmod = DELMOD_FIXED;
294 icr.destmod = DESTMOD_LOGIC;
295 icr.level = LEVEL_ASSERT;
296 icr.shorthand = SHORTHAND_ALL_EXCL;
297 icr.trigger_mode = TRIGMOD_LEVEL;
298 icr.vector = vector;
[da1bafb]299
[8418c7d]300 l_apic[ICRlo] = icr.lo;
[5e4f22b]301
302 l_apic_wait_for_delivery();
[da1bafb]303
[169587a]304 return apic_poll_errors();
305}
306
[f701b236]307/** Universal Start-up Algorithm for bringing up the AP processors.
308 *
309 * @param apicid APIC ID of the processor to be brought up.
310 *
311 * @return 0 on failure, 1 on success.
[da1bafb]312 *
[f761f1eb]313 */
[7f1c620]314int l_apic_send_init_ipi(uint8_t apicid)
[f761f1eb]315{
316 /*
317 * Read the ICR register in and zero all non-reserved fields.
318 */
[da1bafb]319 icr_t icr;
320
[8418c7d]321 icr.lo = l_apic[ICRlo];
322 icr.hi = l_apic[ICRhi];
[f761f1eb]323
[8418c7d]324 icr.delmod = DELMOD_INIT;
325 icr.destmod = DESTMOD_PHYS;
326 icr.level = LEVEL_ASSERT;
327 icr.trigger_mode = TRIGMOD_LEVEL;
328 icr.shorthand = SHORTHAND_NONE;
329 icr.vector = 0;
330 icr.dest = apicid;
[f761f1eb]331
[8418c7d]332 l_apic[ICRhi] = icr.hi;
333 l_apic[ICRlo] = icr.lo;
[da1bafb]334
[f761f1eb]335 /*
336 * According to MP Specification, 20us should be enough to
337 * deliver the IPI.
338 */
339 delay(20);
[da1bafb]340
[88636f68]341 if (!apic_poll_errors())
342 return 0;
[da1bafb]343
[5e4f22b]344 l_apic_wait_for_delivery();
345
[8418c7d]346 icr.lo = l_apic[ICRlo];
347 icr.delmod = DELMOD_INIT;
348 icr.destmod = DESTMOD_PHYS;
349 icr.level = LEVEL_DEASSERT;
350 icr.shorthand = SHORTHAND_NONE;
351 icr.trigger_mode = TRIGMOD_LEVEL;
352 icr.vector = 0;
353 l_apic[ICRlo] = icr.lo;
[da1bafb]354
[f761f1eb]355 /*
356 * Wait 10ms as MP Specification specifies.
357 */
358 delay(10000);
[da1bafb]359
[c9b8c5c]360 if (!is_82489DX_apic(l_apic[LAVR])) {
361 /*
362 * If this is not 82489DX-based l_apic we must send two STARTUP IPI's.
363 */
[da1bafb]364 unsigned int i;
365 for (i = 0; i < 2; i++) {
[8418c7d]366 icr.lo = l_apic[ICRlo];
[7f043c0]367 icr.vector = (uint8_t) (((uintptr_t) ap_boot) >> 12); /* calculate the reset vector */
[8418c7d]368 icr.delmod = DELMOD_STARTUP;
369 icr.destmod = DESTMOD_PHYS;
370 icr.level = LEVEL_ASSERT;
371 icr.shorthand = SHORTHAND_NONE;
372 icr.trigger_mode = TRIGMOD_LEVEL;
373 l_apic[ICRlo] = icr.lo;
[c9b8c5c]374 delay(200);
375 }
[f761f1eb]376 }
377
378 return apic_poll_errors();
379}
380
[f701b236]381/** Initialize Local APIC. */
[f761f1eb]382void l_apic_init(void)
383{
[8418c7d]384 /* Initialize LVT Error register. */
[da1bafb]385 lvt_error_t error;
386
[8418c7d]387 error.value = l_apic[LVT_Err];
388 error.masked = true;
389 l_apic[LVT_Err] = error.value;
[da1bafb]390
[8418c7d]391 /* Initialize LVT LINT0 register. */
[da1bafb]392 lvt_lint_t lint;
393
[8418c7d]394 lint.value = l_apic[LVT_LINT0];
395 lint.masked = true;
396 l_apic[LVT_LINT0] = lint.value;
[da1bafb]397
[8418c7d]398 /* Initialize LVT LINT1 register. */
399 lint.value = l_apic[LVT_LINT1];
400 lint.masked = true;
401 l_apic[LVT_LINT1] = lint.value;
[da1bafb]402
[d0780b4c]403 /* Task Priority Register initialization. */
[da1bafb]404 tpr_t tpr;
405
[d0780b4c]406 tpr.value = l_apic[TPR];
407 tpr.pri_sc = 0;
408 tpr.pri = 0;
409 l_apic[TPR] = tpr.value;
[8418c7d]410
411 /* Spurious-Interrupt Vector Register initialization. */
[da1bafb]412 svr_t svr;
413
[8418c7d]414 svr.value = l_apic[SVR];
415 svr.vector = VECTOR_APIC_SPUR;
416 svr.lapic_enabled = true;
[d0780b4c]417 svr.focus_checking = true;
[8418c7d]418 l_apic[SVR] = svr.value;
[da1bafb]419
[434f700]420 if (CPU->arch.family >= 6)
421 enable_l_apic_in_msr();
[f761f1eb]422
[8418c7d]423 /* Interrupt Command Register initialization. */
[da1bafb]424 icr_t icr;
425
[8418c7d]426 icr.lo = l_apic[ICRlo];
427 icr.delmod = DELMOD_INIT;
428 icr.destmod = DESTMOD_PHYS;
429 icr.level = LEVEL_DEASSERT;
430 icr.shorthand = SHORTHAND_ALL_INCL;
431 icr.trigger_mode = TRIGMOD_LEVEL;
432 l_apic[ICRlo] = icr.lo;
[f761f1eb]433
[f701b236]434 /* Timer Divide Configuration Register initialization. */
[da1bafb]435 tdcr_t tdcr;
436
[f701b236]437 tdcr.value = l_apic[TDCR];
438 tdcr.div_value = DIVIDE_1;
439 l_apic[TDCR] = tdcr.value;
[da1bafb]440
[f701b236]441 /* Program local timer. */
[da1bafb]442 lvt_tm_t tm;
443
[8418c7d]444 tm.value = l_apic[LVT_Tm];
445 tm.vector = VECTOR_CLK;
446 tm.mode = TIMER_PERIODIC;
447 tm.masked = false;
448 l_apic[LVT_Tm] = tm.value;
[da1bafb]449
[e20de55]450 /*
451 * Measure and configure the timer to generate timer
452 * interrupt with period 1s/HZ seconds.
453 */
[da1bafb]454 uint32_t t1 = l_apic[CCRT];
[f761f1eb]455 l_apic[ICRT] = 0xffffffff;
[da1bafb]456
457 while (l_apic[CCRT] == t1);
458
[f761f1eb]459 t1 = l_apic[CCRT];
[da1bafb]460 delay(1000000 / HZ);
461 uint32_t t2 = l_apic[CCRT];
[f761f1eb]462
[da1bafb]463 l_apic[ICRT] = t1 - t2;
[93e90c7]464
465 /* Program Logical Destination Register. */
[5f0e39e8]466 ASSERT(CPU->id < 8);
[da1bafb]467 ldr_t ldr;
468
[93e90c7]469 ldr.value = l_apic[LDR];
[7f043c0]470 ldr.id = (uint8_t) (1 << CPU->id);
[93e90c7]471 l_apic[LDR] = ldr.value;
472
473 /* Program Destination Format Register for Flat mode. */
[da1bafb]474 dfr_t dfr;
475
[93e90c7]476 dfr.value = l_apic[DFR];
477 dfr.model = MODEL_FLAT;
478 l_apic[DFR] = dfr.value;
[f761f1eb]479}
480
[f701b236]481/** Local APIC End of Interrupt. */
[f761f1eb]482void l_apic_eoi(void)
483{
484 l_apic[EOI] = 0;
485}
486
[f701b236]487/** Dump content of Local APIC registers. */
[f761f1eb]488void l_apic_debug(void)
489{
490#ifdef LAPIC_VERBOSE
[7e752b2]491 printf("LVT on cpu%u, LAPIC ID: %" PRIu8 "\n",
[99718a2e]492 CPU->id, l_apic_id());
[f761f1eb]493
[da1bafb]494 lvt_tm_t tm;
[f701b236]495 tm.value = l_apic[LVT_Tm];
[99718a2e]496 printf("LVT Tm: vector=%" PRIu8 ", %s, %s, %s\n",
497 tm.vector, delivs_str[tm.delivs], mask_str[tm.masked],
498 tm_mode_str[tm.mode]);
[da1bafb]499
500 lvt_lint_t lint;
[f701b236]501 lint.value = l_apic[LVT_LINT0];
[99718a2e]502 printf("LVT LINT0: vector=%" PRIu8 ", %s, %s, %s, irr=%u, %s, %s\n",
503 tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs],
504 intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode],
505 mask_str[lint.masked]);
506
507 lint.value = l_apic[LVT_LINT1];
508 printf("LVT LINT1: vector=%" PRIu8 ", %s, %s, %s, irr=%u, %s, %s\n",
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]);
[da1bafb]512
513 lvt_error_t error;
[f701b236]514 error.value = l_apic[LVT_Err];
[99718a2e]515 printf("LVT Err: vector=%" PRIu8 ", %s, %s\n", error.vector,
516 delivs_str[error.delivs], mask_str[error.masked]);
[f761f1eb]517#endif
518}
519
[f701b236]520/** Read from IO APIC register.
521 *
522 * @param address IO APIC register address.
523 *
524 * @return Content of the addressed IO APIC register.
[da1bafb]525 *
[f701b236]526 */
[7f1c620]527uint32_t io_apic_read(uint8_t address)
[f761f1eb]528{
[f701b236]529 io_regsel_t regsel;
[f761f1eb]530
[f701b236]531 regsel.value = io_apic[IOREGSEL];
532 regsel.reg_addr = address;
533 io_apic[IOREGSEL] = regsel.value;
[f761f1eb]534 return io_apic[IOWIN];
535}
536
[f701b236]537/** Write to IO APIC register.
538 *
539 * @param address IO APIC register address.
[da1bafb]540 * @param val Content to be written to the addressed IO APIC register.
541 *
[f701b236]542 */
[da1bafb]543void io_apic_write(uint8_t address, uint32_t val)
[f761f1eb]544{
[f701b236]545 io_regsel_t regsel;
546
547 regsel.value = io_apic[IOREGSEL];
548 regsel.reg_addr = address;
549 io_apic[IOREGSEL] = regsel.value;
[da1bafb]550 io_apic[IOWIN] = val;
[f761f1eb]551}
552
[f701b236]553/** Change some attributes of one item in I/O Redirection Table.
554 *
[da1bafb]555 * @param pin IO APIC pin number.
556 * @param dest Interrupt destination address.
557 * @param vec Interrupt vector to trigger.
[f701b236]558 * @param flags Flags.
[da1bafb]559 *
[f701b236]560 */
[da1bafb]561void io_apic_change_ioredtbl(uint8_t pin, uint8_t dest, uint8_t vec,
562 unsigned int flags)
[f761f1eb]563{
[da1bafb]564 unsigned int dlvr;
[f761f1eb]565
566 if (flags & LOPRI)
[a83a802]567 dlvr = DELMOD_LOWPRI;
[da1bafb]568 else
569 dlvr = DELMOD_FIXED;
570
571 io_redirection_reg_t reg;
[7f043c0]572 reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
573 reg.hi = io_apic_read((uint8_t) (IOREDTBL + pin * 2 + 1));
[f761f1eb]574
[93e90c7]575 reg.dest = dest;
[a83a802]576 reg.destmod = DESTMOD_LOGIC;
577 reg.trigger_mode = TRIGMOD_EDGE;
578 reg.intpol = POLARITY_HIGH;
579 reg.delmod = dlvr;
[da1bafb]580 reg.intvec = vec;
581
[7f043c0]582 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
583 io_apic_write((uint8_t) (IOREDTBL + pin * 2 + 1), reg.hi);
[f761f1eb]584}
585
[f701b236]586/** Mask IRQs in IO APIC.
587 *
588 * @param irqmask Bitmask of IRQs to be masked (0 = do not mask, 1 = mask).
[da1bafb]589 *
[f701b236]590 */
[7f1c620]591void io_apic_disable_irqs(uint16_t irqmask)
[f761f1eb]592{
[623b49f1]593 unsigned int i;
594 for (i = 0; i < 16; i++) {
595 if (irqmask & (1 << i)) {
[f761f1eb]596 /*
597 * Mask 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 = true;
[7f043c0]606 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
[f761f1eb]607 }
608
609 }
610 }
611}
612
[f701b236]613/** Unmask IRQs in IO APIC.
614 *
615 * @param irqmask Bitmask of IRQs to be unmasked (0 = do not unmask, 1 = unmask).
[da1bafb]616 *
[f701b236]617 */
[7f1c620]618void io_apic_enable_irqs(uint16_t irqmask)
[f761f1eb]619{
[623b49f1]620 unsigned int i;
[7f043c0]621 for (i = 0; i < 16; i++) {
[623b49f1]622 if (irqmask & (1 << i)) {
[f761f1eb]623 /*
624 * Unmask the signal input in IO APIC if there is a
625 * mapping for the respective IRQ number.
626 */
[da1bafb]627 int pin = smp_irq_to_pin(i);
[f761f1eb]628 if (pin != -1) {
[da1bafb]629 io_redirection_reg_t reg;
630
[7f043c0]631 reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
[a83a802]632 reg.masked = false;
[7f043c0]633 io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
[f761f1eb]634 }
635
636 }
637 }
638}
639
[5f85c91]640#endif /* CONFIG_SMP */
[b45c443]641
[06e1e95]642/** @}
[b45c443]643 */
Note: See TracBrowser for help on using the repository browser.