arm linux 下中断流程简要分析注册中断
function might sleep, we want to call it first,
* outside of the atomic block.
* Yes, this might clear the entropy pool if the wrong
* driver is attempted to be loaded, without actually
* installing a new handler, but is this really a problem,
* only the sysadmin is able to do this.
*/
rand_initialize_irq(irq);
}
/*
* The following block of code has to be executed atomically
*/
/*
*下面if代码段主要是查看该中断是否可以共享,如可以,则把中断例程链入中断例程
* list中,至于中断共享的条件有:1触发方式相同,2都允许中断共享*/
spin_lock_irqsave(&desc->lock, flags);
p = &desc->action;
old = *p;
if (old) { /*对于IRQ_WDT,这个if不成立,但它已经设置了handle_irq喔*/
/*
* Cant 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))
goto mismatch;
#if defined(CONFIG_IRQ_PER_CPU)
/* All handlers must agree on per-cpuness */
if ((old->flags & IRQF_PERCPU) !=
(new->flags & IRQF_PERCPU))
goto mismatch;
#endif
/* add new interrupt at end of irq queue */
/*把中断例程加入list中*/
do {
p = &old->next;
old = *p;
} while (old);
shared = 1;
}
*p = new;/*该行很关键, 它把中断的处理函数添加到该中断描述符的中断例程list里*/
#if defined(CONFIG_IRQ_PER_CPU)
if (new->flags & IRQF_PERCPU)
desc->status |= IRQ_PER_CPU;
#endif
if (!shared) {
/*对于IRQ_WDT来说这步是多余的,初始化的时候已做过*/
irq_chip_set_defaults(desc->chip);
/* Setup the type (level, edge polarity) if configured: */
/*对于IRQ_WDT来说,没有定义触发方式, 即默认触发方式*/
if (new->flags & IRQF_TRIGGER_MASK) {
/*如果要设触发方式,则调用平台特定的函数,因此如果我们的平台要实现该功能则必*须要在irq_chip对象里加入对set_type函数的支持*/
if (desc->chip && desc->chip->set_type)
desc->chip->set_type(irq,
new->flags & IRQF_TRIGGER_MASK);
else
/*
* IRQF_TRIGGER_* but the PIC does not support
* multiple flow-types?
*/
printk(KERN_WARNING "No IRQF_TRIGGER set_type "
"function for IRQ %d (%s)/n", irq,
desc->chip ? desc->chip->name :
"unknown");
} else
/*这函数只是简单的检查是否有handle_irq*/
compat_irq_chip_set_default_handler(desc);
/*去掉中断的相关状态,让它就绪*/
desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING |
IRQ_INPROGRESS);
if (!(desc->status & IRQ_NOAUTOEN)) {
/*使能该中断*/
desc->depth = 0;
desc->status &= ~IRQ_DISABLED;
if (desc->chip->startup)
desc->chip->startup(irq); /*平台相关函数*/
else
desc->chip->enable(irq);/*平台相关函数*/
} else
/* Undo nested disables: */
desc->depth = 1;
}
spin_unlock_irqrestore(&desc->lock, flags);
new->irq = irq;
register_irq_proc(irq);/*在/proc/irq/下创建该中断的一个文件*/
new->dir = NULL;
register_handler_proc(irq, new); /*为/proc/irq/下创建的文件设置处理函数*/
return 0;
mismatch:
spin_unlock_irqrestore(&desc->lock, flags);
if (!(new->flags & IRQF_PROBE_SHARED)) {
printk(KERN_ERR "IRQ handler type mismatch for IRQ %d/n", irq);
dump_stack();
}
return -EBUSY;
}
该函数主要是安装了一个中断,并使能它。 我们先看使能函数,它是平台相关的,对于s3c2410的IRQ_WDT来说使用的是默认的使能函数(default_startup(),初始化赋值),如果我们要使用自己的使能函数,只要在chip对象里添加就行了。
kernel/irq/Chip.c:
static unsigned int default_startup(unsigned int irq)
{
irq_desc[irq].chip->enable(irq);
return 0;
}
对于IRQ_WDT来说调用的irq_desc[irq].chip->enable(irq)仍是默认函数:default_enable()
kernel/irq/Chip.c:
static void default_enable(unsigned int irq)
{
struct irq_desc *desc = irq_desc + irq;
desc->chip->unmask(irq);/*unmask该中断*/
desc->status &= ~IRQ_MASKED;
}
,对于IRQ_WDT来说这次的调用desc->chip->,对于IRQ_WDT来说这次的调用desc->chip->unmask(irq),实际上是s3c_irq_unmask,具体可查看前面分析的ch
armlinux中断流程注册中 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
