Subversion Repositories HelenOS

Rev

Rev 3386 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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