[英]Simple interrupt handler: request_irq returns error code -22
I am writing a simple kernel module, which could register an interrupt and handle it. 我正在编写一个简单的内核模块,它可以注册一个中断并处理它。 However, when I try to register interrupt by calling the request_irq function, it returns error code -22 :
但是,当我尝试通过调用request_irq函数来注册中断时,它返回错误代码-22:
ERROR: Cannot request IRQ 30 - code -22 , EIO 5 , EINVAL 22
错误:无法请求IRQ 30 - 代码-22,EIO 5,EINVAL 22
I believe, this error code is equal to EINVAL (invalid argument) 我相信,这个错误代码等于EINVAL(无效参数)
Please tell me, what I am doing wrong. 请告诉我,我做错了什么。 Here is a module:
这是一个模块:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/irqdomain.h>
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <asm/exception.h>
#include <asm/mach/irq.h>
void int068_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
printk("Interrupt should be handled there\n");
}
static int __init
clcdint_init(void)
{
unsigned int irq;
unsigned int irqflags;
int ret;
irq=68;
irqflags=IRQF_SHARED | IRQF_NO_SUSPEND;
ret = request_irq(irq, int068_interrupt,
irqflags, "clcdint-int068", NULL);
if (ret!=0) {
printk("ERROR: Cannot request IRQ %d", irq);
printk(" - code %d , EIO %d , EINVAL %d\n", ret, EIO, EINVAL);
}
printk("CLCDINT_INIT\n");
return 0;
}
module_init(clcdint_init);
static void __exit
clcdint_exit(void)
{
unsigned int irq;
irq=68;
free_irq(irq, NULL);
printk("CLCDINT_EXIT\n");
}
module_exit(clcdint_exit);
You can't pass a NULL context (last parameters of the request_irq() call) when dealing with a shared interrupt line (IRQF_SHARED flag is on). 在处理共享中断行(IRQF_SHARED标志打开)时,不能传递NULL上下文(request_irq()调用的最后一个参数)。
To understand why consider the following scenario: you have two identical network cards sharing the same IRQ. 要了解为什么要考虑以下情形:您有两个相同的网卡共享相同的IRQ。 The same driver will pass the same interrupt handler function, the same irq number and the same description.
相同的驱动程序将传递相同的中断处理函数,相同的irq编号和相同的描述。 There is no way to distinguish the two instances of the registration except via the context parameter.
除了通过context参数之外,无法区分注册的两个实例。
Therefore, as a precaution, you can't pass a NULL context parameter if you pass the IRQF_SHARED flag. 因此,作为预防措施,如果传递IRQF_SHARED标志,则无法传递NULL上下文参数。
irqflags
has a type of unsigned int
, but originally it had type long
. irqflags
有一种unsigned int
类型,但最初它的类型为long
。
Try the following statement, it will definitely work: 尝试以下语句,它肯定会起作用:
request_irq(irq, int068_interrupt,IRQF_SHARED | IRQF_NO_SUSPEND, "clcdint-int068", NULL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.