int irq_set_chip(unsigned int irq, struct irq_chip *chip)为形参的irq设置对应的irq_chip
其使用的例程如下:
void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
unsigned int clr, unsigned int set)
{
unsigned int i = gc->irq_base;
raw_spin_lock(&gc_lock);
list_del(&gc->list);
raw_spin_unlock(&gc_lock);
for (; msk; msk >>= 1, i++) {
if (!(msk & 0x01))
continue;
/* Remove handler first. That will mask the irq line */
irq_set_handler(i, NULL);
irq_set_chip(i, &no_irq_chip);
irq_set_chip_data(i, NULL);
irq_modify_status(i, clr, set);
}
}
其源码分析如下:
int irq_set_chip(unsigned int irq, struct irq_chip *chip)
{
unsigned long flags;
#根据中断号得到中断描述符
struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
#中断描述符为null,则退出
if (!desc)
return -EINVAL;
#要设置的形参chip为null的话,则设置为no_irq_chip
if (!chip)
chip = &no_irq_chip;
#更新中断描述符的irq_data.chip,从这里看到irq_set_chip 可以被反复调用,新值会覆盖旧值
desc->irq_data.chip = chip;
irq_put_desc_unlock(desc, flags);
/*
* For !CONFIG_SPARSE_IRQ make the irq show up in
* allocated_irqs.
*/
#在allocated_irqs中设置irq对应的bit
irq_mark_irq(irq);
return 0;
}
void irq_mark_irq(unsigned int irq)
{
mutex_lock(&sparse_irq_lock);
bitmap_set(allocated_irqs, irq, 1);
mutex_unlock(&sparse_irq_lock);
}
中断API之irq_set_chip
最新推荐文章于 2022-05-13 22:07:06 发布