中断驱动程序加载和卸载过程分析:箭头代表进入该函数内部 部分代码省略
- //1.注册中断服务程序
- >>int request_irq(unsigned int irq, irq_handler_t handler,
- unsigned long irqflags, const char *devname, void *dev_id)
- //1.1分配irqaction结构体
- action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
- //1.2设置irq
- >>retval = setup_irq(irq, action);
- //1.2.a 找到中断号对应的irq_desc结构体 irq_desc[irq]
-
- struct irq_desc *desc = irq_desc + irq;
- struct irqaction *old, **p;
- const char *old_name = NULL;
- unsigned long flags;
- int shared = 0;
- p = &desc->action;
- old = *p;
- // 判断是否有链入action结构体,如果有,
- // 则判断是否为IRQF_SHARED,IRQF_TRIGGER_MASK才能链入action
- if (old) {
- /*
- * Can't share interrupts unless both agree to and are
- * the same type (level, edge, polarity). So both flag
- * fields must have IRQF_SHARED set and the bits which
- * set the trigger type must match.
- */
- if (!((old->flags & new->flags) & IRQF_SHARED) ||
- ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK)) {
- old_name = old->name;
- goto mismatch; //跳到出错处理
- }
- //将action添加到链表
- do {
- p = &old->next;
- old = *p;
- } while (old);
- }
- //chip结构体中set_type,starup,enable等操作
- desc->chip->set_type(irq,new->flags & IRQF_TRIGGER_MASK);
- if (desc->chip->startup)
- desc->chip->startup(irq);
- else
- desc->chip->enable(irq);
- //2 卸载中断服务程序
- >>void free_irq(unsigned int irq, void *dev_id)
- //2.1找到对应的irq_desc结构体,释放action结构体
- desc = irq_desc + irq;
- if (desc->chip->shutdown)
- desc->chip->shutdown(irq);
- else
- desc->chip->disable(irq);
- kfree(action);
阅读(1152) | 评论(0) | 转发(0) |