微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > arm linux 下中断流程简要分析注册中断

arm linux 下中断流程简要分析注册中断

时间:11-09 来源:互联网 点击:
注册中断

这部分我们以3sc2410下的watchdog的中断为例来讲解中断的注册及调用过程。

drivers/char/watchdog/s3c2410_wdt.c:

static int s3c2410wdt_probe(struct platform_device *pdev)

{

……

/*注册中断*/

ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev);

……

}

在s3c2410wdt_probe函数中为watchdog注册了一个中断,中断号为IRQ_WDT,

#define IRQ_WDTS3C2410_IRQ(9)

中断处理函数是s3c2410wdt_irq。

我们来看request_irq是如何实现的:

kernel/irq/Manage.c:

/

*request_irq - allocate an interrupt line

*@irq: Interrupt line to allocate

*@handler: Function to be called when the IRQ occurs

*@irqflags: Interrupt type flags

*@devname: An ascii name for the claiming device

*@dev_id: A cookie passed back to the handler function

*

*This call allocates interrupt resources and enables the

*interrupt line and IRQ handling. From the point this

*call is made your handler function may be invoked. Since

*your handler function must clear any interrupt the board

*raises, you must take care both to initialise your hardware

*and to set up the interrupt handler in the right order.

*

*Dev_id must be globally unique. Normally the address of the

*device data structure is used as the cookie. Since the handler

*receives this value it makes sense to use it.

*

*If your interrupt is shared you must pass a non NULL dev_id

*as this is required when freeing the interrupt.

*

*Flags:

*

*IRQF_SHAREDInterrupt is shared

*IRQF_DISABLEDDisable local interrupts while processing

*IRQF_SAMPLE_RANDOMThe interrupt can be used for entropy

*

*/

int request_irq(unsigned int irq,

irqreturn_t (*handler)(int, void *, struct pt_regs *),

unsigned long irqflags, const char *devname, void *dev_id)

{

struct irqaction *action;

int retval;

#ifdef CONFIG_LOCKDEP

/*

* Lockdep wants atomic interrupt handlers:

*/

irqflags |= SA_INTERRUPT;

#endif

/*

* Sanity-check: shared interrupts must pass in a real dev-ID,

* otherwise well have trouble later trying to figure out

* which interrupt is which (messes up the interrupt freeing

* logic etc).

*/

/*允许共享的中断必须要有一个独一无二的dev_id,看上面函数的解释

if ((irqflags & IRQF_SHARED) && !dev_id)

return -EINVAL;

if (irq >= NR_IRQS) /*中断号是否合法*/

return -EINVAL;

/*这个标记对s3c2410来说在s3c24xx_init_irq里通过调用set_irq_flags()被去掉了*/

if (irq_desc[irq].status & IRQ_NOREQUEST)

return -EINVAL;

if (!handler)/*中断例程*/

return -EINVAL;

/*分配一个irqaction对象,来保存这个中断信息*/

action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);

if (!action)

return -ENOMEM;

/*保存中断例程等信息*/

action->handler = handler;

action->flags = irqflags;

cpus_clear(action->mask);/*清除相应位*/

action->name = devname;

action->next = NULL;

action->dev_id = dev_id;

select_smp_affinity(irq);

retval = setup_irq(irq, action);/*申请中断*/

if (retval)

kfree(action);

return retval;

}

该函数的功能及参数含义在函数头有详细的说明,这里就不多介绍了,值得注意的是我们在申请中断之前,必须要去掉该中断的IRQ_NOREQUEST标记(系统初始化的时候赋了这个标记), 具体方法是调用set_irq_flags()函数。

接着看setup_irq

kernel/irq/Manage.c:

/*

* Internal function to register an irqaction - typically used to

* allocate special interrupts that are part of the architecture.

*/

int setup_irq(unsigned int irq, struct irqaction *new)

{

struct irq_desc *desc = irq_desc + irq; /*获取保存该中断的中断描述符地址*/

struct irqaction *old, p;

unsigned long flags;

int shared = 0;

if (irq >= NR_IRQS)

return -EINVAL;

/*对于s3c2410的中断在s3c24xx_init_irq里已经初始化过了*/

if (desc->chip == &no_irq_chip)

return -ENOSYS;

/*

* Some drivers like serial.c use request_irq() heavily,

* so we have to be careful not to interfere with a

* running system.

*/

if (new->flags & IRQF_SAMPLE_RANDOM) {

/*

* This

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top