天天看点

linux中断子系统(二) - 注册用户中断处理函数

区别系统中断函数和用户中断函数

和前面一篇文章区别开来,之所以要区别系统中断函数和用户中断函数,这是我自己的理解。

来看一个结构体:

struct irq_desc {
    unsigned int        irq;
    struct irq_chip     *chip;
    irq_flow_handler_t  handle_irq;
    struct irqaction    *action;/* IRQ action list */
    ...
} ____cacheline_internodealigned_in_smp;      

前面通过set_irq_chip和set_irq_handler是设置了struct irq_desc结构体中的chip和handler_irq,中断产生后,handler_irq对应的系统中断处理函数会首先被调用,这个系统中断处理函数又会去调用irq_desc->action即用户中断处理函数,并且会遍历irq_desc下所有的action,所以要把系统中断处理函数handler_irq与用户中断处理函数action区别开来。以handler_irq为handle_level_irq的例子,如下:

void handle_level_irq(unsigned int irq, struct irq_desc *desc)
{
    ...
    action = desc->action;
    action_ret = handle_IRQ_event(irq, action);
    ...
}

irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
{
    ...
    do {
        ret = action->handler(irq, action->dev_id);
        switch (ret) {
        case IRQ_WAKE_THREAD:
            ...
        case IRQ_HANDLED:
            ...
        default:
            break;
        }

        retval |= ret;
        action = action->next;
    } while (action);

    return retval;
}      

注册用户中断处理函数

继续阅读