c - 简单中断处理程序 : request_irq returns error code -22

标签 c linux module linux-kernel interrupt

我正在编写一个简单的内核模块,它可以注册一个中断并处理它。 但是,当我尝试通过调用 request_irq 函数来注册中断时, 它返回错误代码 -22 :

ERROR: Cannot request IRQ 30 - code -22 , EIO 5 , EINVAL 22

我相信,这个错误代码等于 EINVAL(无效参数)

请告诉我,我做错了什么。这是一个模块:

#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);

最佳答案

在处理共享中断线(IRQF_SHARED 标志打开)时,您不能传递 NULL 上下文(request_irq() 调用的最后一个参数)。

要理解为什么考虑以下场景:您有两个相同的网卡共享相同的 IRQ。相同的驱动程序将传递相同的中断处理函数、相同的 irq 号和相同的描述。除非通过上下文参数,否则无法区分注册的两个实例。

因此,作为预防措施,如果您传递 IRQF_SHARED 标志,则不能传递 NULL 上下文参数。

关于c - 简单中断处理程序 : request_irq returns error code -22,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15245626/

相关文章:

c++ - 在处理大于其高速缓存行的类型时,英特尔 CPU 的预期行为是什么?

无法在 Cygwin 中使用#include <sys/times.h> 编译 C 代码

c - 当我将 0 作为 getline 的第二个参数传递时会发生什么?

Javascript模块,如何在开发构建中添加额外的内容?

c - 从文件中读取一行并用 C 解析它

linux - 为什么 Bash 在定义函数时返回错误 `' ash`?

linux - awk 模式可以匹配多行吗?

c# - 位于 linux 服务器上的 PHP 代码需要运行 windows .exe

python - 返回脚本中使用的导入 Python 模块的列表?

rust - 如何避免 rust 中单个结构模块的冗余模块命名?