request_threaded_irq
先来看头文件的申明。
文件:include/linux/interrupt.h
extern int __must_check
request_threaded_irq(unsigned int irq, irq_handler_t handler,
irq_handler_t thread_fn,
unsigned long flags, const char *name, void *dev);
static inline int __must_check
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
const char *name, void *dev)
{
return request_threaded_irq(irq, handler, NULL, flags, name, dev);
}
request_irq也是调用request_threaded_irq函数,只不过thread_fn置为NULL了。下面来看看request_threaded_irq的实现:
int request_threaded_irq(unsigned int irq, irq_handler_t handler,
irq_handler_t thread_fn, unsigned long irqflags,
const char *devname, void *dev_id)
{
struct irqaction *action;
struct irq_desc *desc;
int retval;
/*
* Sanity-check: shared interrupts must pass in a real dev-ID,
* otherwise we'll have trouble later trying to figure out
* which interrupt is which (messes up the interrupt freeing
* logic etc).
*
* Also IRQF_COND_SUSPEND only makes sense for shared interrupts and
* it cannot be set along with IRQF_NO_SUSPEND.
*/
//合法性检查,可以看看哪些条件组合是不合法的
if (((irqflags & IRQF_SHARED) && !dev_id) ||
(!(irqflags & IRQF_SHARED) && (irqflags & IRQF_COND_SUSPEND)) ||
((irqflags & IRQF_NO_SUSPEND) && (irqflags & IRQF_COND_SUSPEND)))
return -EINVAL;
//申明了一个名叫irq_desc的结构体数据,大小为64.中断号为其下标,获取结构体用来存储数据,注意中断号不能大小64
desc = irq_to_desc(irq);
if (!desc)
return -EINVAL;
//查看status_use_accessors是否有IRQ_NOREQUEST标志,此标志定义如下:
IRQ_NOREQUEST - Interrupt cannot be requested via
if (!irq_settings_can_request(desc) ||
WARN_ON(irq_settings_is_per_cpu_devid(desc)))
return -EINVAL;
//如果handler和thread_fn都为空,是不合法的。如果只有handler为空,那么使用默认的handler.这个默认的handler很简单,直接返回IRQ_WAKE_THREAD。唤醒secondary也就是thread_fn执行
if (!handler) {
<