Subversion Repositories HelenOS

Rev

Rev 2101 | Rev 2218 | 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
 
1888 jermar 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
 */
128
static void apic_spurious(int n, istate_t *istate)
129
{
130
#ifdef CONFIG_DEBUG
131
    printf("cpu%d: APIC spurious interrupt\n", CPU->id);
132
#endif
133
}
576 palkovsky 134
 
1970 decky 135
static irq_ownership_t l_apic_timer_claim(void)
136
{
137
    return IRQ_ACCEPT;
138
}
576 palkovsky 139
 
1970 decky 140
static void l_apic_timer_irq_handler(irq_t *irq, void *arg, ...)
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;
2101 decky 156
    unsigned int i;
1 jermar 157
 
958 jermar 158
    exc_register(VECTOR_APIC_SPUR, "apic_spurious", (iroutine) apic_spurious);
1 jermar 159
 
160
    enable_irqs_function = io_apic_enable_irqs;
161
    disable_irqs_function = io_apic_disable_irqs;
162
    eoi_function = l_apic_eoi;
163
 
164
    /*
165
     * Configure interrupt routing.
166
     * IRQ 0 remains masked as the time signal is generated by l_apic's themselves.
167
     * Other interrupts will be forwarded to the lowest priority CPU.
168
     */
169
    io_apic_disable_irqs(0xffff);
1970 decky 170
 
171
    irq_initialize(&l_apic_timer_irq);
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
 
515 jermar 178
    for (i = 0; i < IRQ_COUNT; i++) {
1 jermar 179
        int pin;
180
 
1970 decky 181
        if ((pin = smp_irq_to_pin(i)) != -1)
2101 decky 182
            io_apic_change_ioredtbl(pin, DEST_ALL, IVT_IRQBASE + i, LOPRI);
1 jermar 183
    }
184
 
185
    /*
186
     * Ensure that io_apic has unique ID.
187
     */
515 jermar 188
    idreg.value = io_apic_read(IOAPICID);
1970 decky 189
    if ((1 << idreg.apic_id) & apic_id_mask) {  /* see if IO APIC ID is used already */
515 jermar 190
        for (i = 0; i < APIC_ID_COUNT; i++) {
1970 decky 191
            if (!((1 << i) & apic_id_mask)) {
515 jermar 192
                idreg.apic_id = i;
193
                io_apic_write(IOAPICID, idreg.value);
1 jermar 194
                break;
195
            }
196
        }
197
    }
198
 
199
    /*
200
     * Configure the BSP's lapic.
201
     */
202
    l_apic_init();
515 jermar 203
 
1 jermar 204
    l_apic_debug();
205
}
206
 
514 jermar 207
/** Poll for APIC errors.
208
 *
209
 * Examine Error Status Register and report all errors found.
210
 *
211
 * @return 0 on error, 1 on success.
212
 */
1 jermar 213
int apic_poll_errors(void)
214
{
514 jermar 215
    esr_t esr;
1 jermar 216
 
514 jermar 217
    esr.value = l_apic[ESR];
1 jermar 218
 
514 jermar 219
    if (esr.send_checksum_error)
515 jermar 220
        printf("Send Checksum Error\n");
514 jermar 221
    if (esr.receive_checksum_error)
515 jermar 222
        printf("Receive Checksum Error\n");
514 jermar 223
    if (esr.send_accept_error)
1 jermar 224
        printf("Send Accept Error\n");
514 jermar 225
    if (esr.receive_accept_error)
1 jermar 226
        printf("Receive Accept Error\n");
514 jermar 227
    if (esr.send_illegal_vector)
1 jermar 228
        printf("Send Illegal Vector\n");
514 jermar 229
    if (esr.received_illegal_vector)
1 jermar 230
        printf("Received Illegal Vector\n");
514 jermar 231
    if (esr.illegal_register_address)
1 jermar 232
        printf("Illegal Register Address\n");
125 jermar 233
 
514 jermar 234
    return !esr.err_bitmap;
1 jermar 235
}
236
 
514 jermar 237
/** Send all CPUs excluding CPU IPI vector.
238
 *
239
 * @param vector Interrupt vector to be sent.
240
 *
241
 * @return 0 on failure, 1 on success.
5 jermar 242
 */
1780 jermar 243
int l_apic_broadcast_custom_ipi(uint8_t vector)
5 jermar 244
{
513 jermar 245
    icr_t icr;
5 jermar 246
 
513 jermar 247
    icr.lo = l_apic[ICRlo];
248
    icr.delmod = DELMOD_FIXED;
249
    icr.destmod = DESTMOD_LOGIC;
250
    icr.level = LEVEL_ASSERT;
251
    icr.shorthand = SHORTHAND_ALL_EXCL;
252
    icr.trigger_mode = TRIGMOD_LEVEL;
253
    icr.vector = vector;
5 jermar 254
 
513 jermar 255
    l_apic[ICRlo] = icr.lo;
5 jermar 256
 
513 jermar 257
    icr.lo = l_apic[ICRlo];
1684 jermar 258
    if (icr.delivs == DELIVS_PENDING) {
259
#ifdef CONFIG_DEBUG
5 jermar 260
        printf("IPI is pending.\n");
1684 jermar 261
#endif
262
    }
5 jermar 263
 
264
    return apic_poll_errors();
265
}
266
 
514 jermar 267
/** Universal Start-up Algorithm for bringing up the AP processors.
268
 *
269
 * @param apicid APIC ID of the processor to be brought up.
270
 *
271
 * @return 0 on failure, 1 on success.
1 jermar 272
 */
1780 jermar 273
int l_apic_send_init_ipi(uint8_t apicid)
1 jermar 274
{
513 jermar 275
    icr_t icr;
1 jermar 276
    int i;
277
 
278
    /*
279
     * Read the ICR register in and zero all non-reserved fields.
280
     */
513 jermar 281
    icr.lo = l_apic[ICRlo];
282
    icr.hi = l_apic[ICRhi];
1 jermar 283
 
513 jermar 284
    icr.delmod = DELMOD_INIT;
285
    icr.destmod = DESTMOD_PHYS;
286
    icr.level = LEVEL_ASSERT;
287
    icr.trigger_mode = TRIGMOD_LEVEL;
288
    icr.shorthand = SHORTHAND_NONE;
289
    icr.vector = 0;
290
    icr.dest = apicid;
1 jermar 291
 
513 jermar 292
    l_apic[ICRhi] = icr.hi;
293
    l_apic[ICRlo] = icr.lo;
27 jermar 294
 
1 jermar 295
    /*
296
     * According to MP Specification, 20us should be enough to
297
     * deliver the IPI.
298
     */
299
    delay(20);
300
 
1684 jermar 301
    if (!apic_poll_errors())
302
        return 0;
1 jermar 303
 
513 jermar 304
    icr.lo = l_apic[ICRlo];
1684 jermar 305
    if (icr.delivs == DELIVS_PENDING) {
306
#ifdef CONFIG_DEBUG
1 jermar 307
        printf("IPI is pending.\n");
1684 jermar 308
#endif
309
    }
27 jermar 310
 
513 jermar 311
    icr.delmod = DELMOD_INIT;
312
    icr.destmod = DESTMOD_PHYS;
313
    icr.level = LEVEL_DEASSERT;
314
    icr.shorthand = SHORTHAND_NONE;
315
    icr.trigger_mode = TRIGMOD_LEVEL;
316
    icr.vector = 0;
317
    l_apic[ICRlo] = icr.lo;
1 jermar 318
 
319
    /*
320
     * Wait 10ms as MP Specification specifies.
321
     */
322
    delay(10000);
323
 
27 jermar 324
    if (!is_82489DX_apic(l_apic[LAVR])) {
325
        /*
326
         * If this is not 82489DX-based l_apic we must send two STARTUP IPI's.
327
         */
328
        for (i = 0; i<2; i++) {
513 jermar 329
            icr.lo = l_apic[ICRlo];
1780 jermar 330
            icr.vector = ((uintptr_t) ap_boot) / 4096; /* calculate the reset vector */
513 jermar 331
            icr.delmod = DELMOD_STARTUP;
332
            icr.destmod = DESTMOD_PHYS;
333
            icr.level = LEVEL_ASSERT;
334
            icr.shorthand = SHORTHAND_NONE;
335
            icr.trigger_mode = TRIGMOD_LEVEL;
336
            l_apic[ICRlo] = icr.lo;
27 jermar 337
            delay(200);
338
        }
1 jermar 339
    }
340
 
341
    return apic_poll_errors();
342
}
343
 
514 jermar 344
/** Initialize Local APIC. */
1 jermar 345
void l_apic_init(void)
346
{
513 jermar 347
    lvt_error_t error;
348
    lvt_lint_t lint;
750 jermar 349
    tpr_t tpr;
513 jermar 350
    svr_t svr;
514 jermar 351
    icr_t icr;
352
    tdcr_t tdcr;
513 jermar 353
    lvt_tm_t tm;
672 jermar 354
    ldr_t ldr;
355
    dfr_t dfr;
1780 jermar 356
    uint32_t t1, t2;
1 jermar 357
 
513 jermar 358
    /* Initialize LVT Error register. */
359
    error.value = l_apic[LVT_Err];
360
    error.masked = true;
361
    l_apic[LVT_Err] = error.value;
1 jermar 362
 
513 jermar 363
    /* Initialize LVT LINT0 register. */
364
    lint.value = l_apic[LVT_LINT0];
365
    lint.masked = true;
366
    l_apic[LVT_LINT0] = lint.value;
1 jermar 367
 
513 jermar 368
    /* Initialize LVT LINT1 register. */
369
    lint.value = l_apic[LVT_LINT1];
370
    lint.masked = true;
371
    l_apic[LVT_LINT1] = lint.value;
750 jermar 372
 
373
    /* Task Priority Register initialization. */
374
    tpr.value = l_apic[TPR];
375
    tpr.pri_sc = 0;
376
    tpr.pri = 0;
377
    l_apic[TPR] = tpr.value;
513 jermar 378
 
379
    /* Spurious-Interrupt Vector Register initialization. */
380
    svr.value = l_apic[SVR];
381
    svr.vector = VECTOR_APIC_SPUR;
382
    svr.lapic_enabled = true;
750 jermar 383
    svr.focus_checking = true;
513 jermar 384
    l_apic[SVR] = svr.value;
385
 
31 jermar 386
    if (CPU->arch.family >= 6)
387
        enable_l_apic_in_msr();
1 jermar 388
 
513 jermar 389
    /* Interrupt Command Register initialization. */
390
    icr.lo = l_apic[ICRlo];
391
    icr.delmod = DELMOD_INIT;
392
    icr.destmod = DESTMOD_PHYS;
393
    icr.level = LEVEL_DEASSERT;
394
    icr.shorthand = SHORTHAND_ALL_INCL;
395
    icr.trigger_mode = TRIGMOD_LEVEL;
396
    l_apic[ICRlo] = icr.lo;
1 jermar 397
 
514 jermar 398
    /* Timer Divide Configuration Register initialization. */
399
    tdcr.value = l_apic[TDCR];
400
    tdcr.div_value = DIVIDE_1;
401
    l_apic[TDCR] = tdcr.value;
1 jermar 402
 
514 jermar 403
    /* Program local timer. */
513 jermar 404
    tm.value = l_apic[LVT_Tm];
405
    tm.vector = VECTOR_CLK;
406
    tm.mode = TIMER_PERIODIC;
407
    tm.masked = false;
408
    l_apic[LVT_Tm] = tm.value;
409
 
1540 jermar 410
    /*
411
     * Measure and configure the timer to generate timer
412
     * interrupt with period 1s/HZ seconds.
413
     */
1 jermar 414
    t1 = l_apic[CCRT];
415
    l_apic[ICRT] = 0xffffffff;
416
 
417
    while (l_apic[CCRT] == t1)
418
        ;
419
 
420
    t1 = l_apic[CCRT];
1540 jermar 421
    delay(1000000/HZ);
1 jermar 422
    t2 = l_apic[CCRT];
423
 
424
    l_apic[ICRT] = t1-t2;
672 jermar 425
 
426
    /* Program Logical Destination Register. */
427
    ldr.value = l_apic[LDR];
428
    if (CPU->id < sizeof(CPU->id)*8)    /* size in bits */
429
        ldr.id = (1<<CPU->id);
430
    l_apic[LDR] = ldr.value;
431
 
432
    /* Program Destination Format Register for Flat mode. */
433
    dfr.value = l_apic[DFR];
434
    dfr.model = MODEL_FLAT;
435
    l_apic[DFR] = dfr.value;
1 jermar 436
}
437
 
514 jermar 438
/** Local APIC End of Interrupt. */
1 jermar 439
void l_apic_eoi(void)
440
{
441
    l_apic[EOI] = 0;
442
}
443
 
514 jermar 444
/** Dump content of Local APIC registers. */
1 jermar 445
void l_apic_debug(void)
446
{
447
#ifdef LAPIC_VERBOSE
514 jermar 448
    lvt_tm_t tm;
449
    lvt_lint_t lint;
450
    lvt_error_t error; 
451
 
16 jermar 452
    printf("LVT on cpu%d, LAPIC ID: %d\n", CPU->id, l_apic_id());
1 jermar 453
 
514 jermar 454
    tm.value = l_apic[LVT_Tm];
1196 cejka 455
    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 456
    lint.value = l_apic[LVT_LINT0];
1196 cejka 457
    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 458
    lint.value = l_apic[LVT_LINT1];
1196 cejka 459
    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 460
    error.value = l_apic[LVT_Err];
1196 cejka 461
    printf("LVT Err: vector=%hhd, %s, %s\n", error.vector, delivs_str[error.delivs], mask_str[error.masked]);
1 jermar 462
#endif
463
}
464
 
514 jermar 465
/** Get Local APIC ID.
466
 *
467
 * @return Local APIC ID.
468
 */
1780 jermar 469
uint8_t l_apic_id(void)
16 jermar 470
{
515 jermar 471
    l_apic_id_t idreg;
514 jermar 472
 
515 jermar 473
    idreg.value = l_apic[L_APIC_ID];
474
    return idreg.apic_id;
16 jermar 475
}
476
 
514 jermar 477
/** Read from IO APIC register.
478
 *
479
 * @param address IO APIC register address.
480
 *
481
 * @return Content of the addressed IO APIC register.
482
 */
1780 jermar 483
uint32_t io_apic_read(uint8_t address)
1 jermar 484
{
514 jermar 485
    io_regsel_t regsel;
1 jermar 486
 
514 jermar 487
    regsel.value = io_apic[IOREGSEL];
488
    regsel.reg_addr = address;
489
    io_apic[IOREGSEL] = regsel.value;
1 jermar 490
    return io_apic[IOWIN];
491
}
492
 
514 jermar 493
/** Write to IO APIC register.
494
 *
495
 * @param address IO APIC register address.
1708 jermar 496
 * @param x Content to be written to the addressed IO APIC register.
514 jermar 497
 */
1780 jermar 498
void io_apic_write(uint8_t address, uint32_t x)
1 jermar 499
{
514 jermar 500
    io_regsel_t regsel;
501
 
502
    regsel.value = io_apic[IOREGSEL];
503
    regsel.reg_addr = address;
504
    io_apic[IOREGSEL] = regsel.value;
1 jermar 505
    io_apic[IOWIN] = x;
506
}
507
 
514 jermar 508
/** Change some attributes of one item in I/O Redirection Table.
509
 *
510
 * @param pin IO APIC pin number.
511
 * @param dest Interrupt destination address.
512
 * @param v Interrupt vector to trigger.
513
 * @param flags Flags.
514
 */
1780 jermar 515
void io_apic_change_ioredtbl(int pin, int dest, uint8_t v, int flags)
1 jermar 516
{
512 jermar 517
    io_redirection_reg_t reg;
514 jermar 518
    int dlvr = DELMOD_FIXED;
1 jermar 519
 
520
    if (flags & LOPRI)
512 jermar 521
        dlvr = DELMOD_LOWPRI;
522
 
514 jermar 523
    reg.lo = io_apic_read(IOREDTBL + pin*2);
524
    reg.hi = io_apic_read(IOREDTBL + pin*2 + 1);
1 jermar 525
 
672 jermar 526
    reg.dest = dest;
512 jermar 527
    reg.destmod = DESTMOD_LOGIC;
528
    reg.trigger_mode = TRIGMOD_EDGE;
529
    reg.intpol = POLARITY_HIGH;
530
    reg.delmod = dlvr;
531
    reg.intvec = v;
1 jermar 532
 
514 jermar 533
    io_apic_write(IOREDTBL + pin*2, reg.lo);
534
    io_apic_write(IOREDTBL + pin*2 + 1, reg.hi);
1 jermar 535
}
536
 
514 jermar 537
/** Mask IRQs in IO APIC.
538
 *
539
 * @param irqmask Bitmask of IRQs to be masked (0 = do not mask, 1 = mask).
540
 */
1780 jermar 541
void io_apic_disable_irqs(uint16_t irqmask)
1 jermar 542
{
512 jermar 543
    io_redirection_reg_t reg;
2101 decky 544
    unsigned int i;
545
    int pin;
1 jermar 546
 
2101 decky 547
    for (i = 0; i < 16; i++) {
548
        if (irqmask & (1 << i)) {
1 jermar 549
            /*
550
             * Mask the signal input in IO APIC if there is a
551
             * mapping for the respective IRQ number.
552
             */
512 jermar 553
            pin = smp_irq_to_pin(i);
1 jermar 554
            if (pin != -1) {
2101 decky 555
                reg.lo = io_apic_read(IOREDTBL + pin * 2);
512 jermar 556
                reg.masked = true;
2101 decky 557
                io_apic_write(IOREDTBL + pin * 2, reg.lo);
1 jermar 558
            }
559
 
560
        }
561
    }
562
}
563
 
514 jermar 564
/** Unmask IRQs in IO APIC.
565
 *
566
 * @param irqmask Bitmask of IRQs to be unmasked (0 = do not unmask, 1 = unmask).
567
 */
1780 jermar 568
void io_apic_enable_irqs(uint16_t irqmask)
1 jermar 569
{
2101 decky 570
    unsigned int i;
571
    int pin;
512 jermar 572
    io_redirection_reg_t reg;  
1 jermar 573
 
2101 decky 574
    for (i = 0;i < 16; i++) {
575
        if (irqmask & (1 << i)) {
1 jermar 576
            /*
577
             * Unmask the signal input in IO APIC if there is a
578
             * mapping for the respective IRQ number.
579
             */
512 jermar 580
            pin = smp_irq_to_pin(i);
1 jermar 581
            if (pin != -1) {
2101 decky 582
                reg.lo = io_apic_read(IOREDTBL + pin * 2);
512 jermar 583
                reg.masked = false;
2101 decky 584
                io_apic_write(IOREDTBL + pin * 2, reg.lo);
1 jermar 585
            }
586
 
587
        }
588
    }
589
}
590
 
458 decky 591
#endif /* CONFIG_SMP */
1702 cejka 592
 
1888 jermar 593
/** @}
1702 cejka 594
 */