Changeset fd67c9f in mainline for kernel/genarch


Ignore:
Timestamp:
2019-04-06T08:10:27Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
534bcdf
Parents:
ef56a43
Message:

Handle PIC spurious IRQs with care

Location:
kernel/genarch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/include/genarch/drivers/i8259/i8259.h

    ref56a43 rfd67c9f  
    3838#include <typedefs.h>
    3939#include <arch/interrupt.h>
     40#include <stdbool.h>
    4041
    4142/* ICW1 bits */
     
    4344#define PIC_ICW1_NEEDICW4  (1 << 0)
    4445
     46/* OCW3 bits */
     47#define PIC_OCW3           (1 << 3)
     48#define PIC_OCW3_READ_ISR  (3 << 0)
     49
    4550/* OCW4 bits */
    4651#define PIC_OCW4           (0 << 3)
    4752#define PIC_OCW4_NSEOI     (1 << 5)
     53
     54#define PIC_IRQ_COUNT      8
     55#define PIC_SPURIOUS_IRQ   7
    4856
    4957typedef struct {
     
    5664extern void pic_disable_irqs(uint16_t);
    5765extern void pic_eoi(unsigned int);
     66extern bool pic_is_spurious(unsigned int);
     67extern void pic_handle_spurious(unsigned int);
    5868
    5969#endif
  • kernel/genarch/src/drivers/i8259/i8259.c

    ref56a43 rfd67c9f  
    9090                    (uint8_t) (x & (~(irqmask & 0xff))));
    9191        }
    92         if (irqmask >> 8) {
     92        if (irqmask >> PIC_IRQ_COUNT) {
    9393                x = pio_read_8(&saved_pic1->port2);
    9494                pio_write_8(&saved_pic1->port2,
    95                     (uint8_t) (x & (~(irqmask >> 8))));
     95                    (uint8_t) (x & (~(irqmask >> PIC_IRQ_COUNT))));
    9696        }
    9797}
     
    106106                    (uint8_t) (x | (irqmask & 0xff)));
    107107        }
    108         if (irqmask >> 8) {
     108        if (irqmask >> PIC_IRQ_COUNT) {
    109109                x = pio_read_8(&saved_pic1->port2);
    110                 pio_write_8(&saved_pic1->port2, (uint8_t) (x | (irqmask >> 8)));
     110                pio_write_8(&saved_pic1->port2,
     111                    (uint8_t) (x | (irqmask >> PIC_IRQ_COUNT)));
    111112        }
    112113}
     
    114115void pic_eoi(unsigned int irq)
    115116{
    116         if (irq >= 8)
     117        if (irq >= PIC_IRQ_COUNT)
    117118                pio_write_8(&saved_pic1->port1, PIC_OCW4 | PIC_OCW4_NSEOI);
    118119        pio_write_8(&saved_pic0->port1, PIC_OCW4 | PIC_OCW4_NSEOI);
    119120}
    120121
     122bool pic_is_spurious(unsigned int irq)
     123{
     124        pio_write_8(&saved_pic0->port1, PIC_OCW3 | PIC_OCW3_READ_ISR);
     125        pio_write_8(&saved_pic1->port1, PIC_OCW3 | PIC_OCW3_READ_ISR);
     126        uint8_t isr_lo = pio_read_8(&saved_pic0->port1);
     127        uint8_t isr_hi = pio_read_8(&saved_pic1->port1);
     128        return !(((isr_hi << PIC_IRQ_COUNT) | isr_lo) & (1 << irq));
     129}
     130
     131void pic_handle_spurious(unsigned int irq)
     132{
     133        /* For spurious IRQs from pic1, we need to isssue an EOI to pic0 */
     134        if (irq >= PIC_IRQ_COUNT)
     135                pio_write_8(&saved_pic0->port1, PIC_OCW4 | PIC_OCW4_NSEOI);
     136}
     137
    121138/** @}
    122139 */
Note: See TracChangeset for help on using the changeset viewer.