简体   繁体   English

简单中断处理程序:request_irq返回错误代码-22

[英]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.

相关问题 中断处理程序:request_irq 返回错误代码 -16 - Interrupt handler: request_irq returns error code -16 内核模块中的中断处理:request_irq() 返回 -22,无效参数 - Interrupt-handling within kernel-module: request_irq() returns -22, Invalid Parameter request_irq 和 __interrupt 的区别 - Difference between request_irq and __interrupt request_irq中的dev_id参数是什么? - What is dev_id parameter in request_irq? 如何使用request_threaded_irq以便在线程处理程序工作时调用中断处理程序? - How to use request_threaded_irq so that the interrupt handler is called while the threaded handler works? 为什么 Linux kernel 不会在返回 IRQ_HANDLED 的共享 IRQ 的第一个处理程序处停止? - Why does the Linux kernel not stop at the first handler for a shared IRQ that returns IRQ_HANDLED? 为什么不管被中断的指令如何,我的 ARM 中断处理程序中的 IRQ 延迟总是相同的? - Why is the IRQ latency in my ARM interrupt handler always the same, regardless of the instruction that is being interrupted? 与用户代码同时执行的中断处理程序代码 - Interrupt handler code executed concurrently with the user code IRQ处理程序未注册 - IRQ handler not getting registered RPi Pico 在 IRQ 中断调用时冻结 - RPi Pico freezes on IRQ Interrupt call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM