Linuxカーネルでの割り込み処理を学んでおり、以下のコードスニペットを試して、IRQ2にダミーのirqハンドラーを登録しました。しかし、実行しようとしているクリーンアップ関数から生じる負の戻り値と以下のようなメッセージがカーネルに表示されているため、登録されていないようですfree_irq()
:
[ 2203.989585] Trying to free already-free IRQ 2
以下は、カーネル ログからの printk であり、登録されていないことを示しています。
Here with registering IRQ handler on IRQ2 for flowTest...retval_irqreg= -22
以下は、4つの機能を持つ私のコードの関連部分です
1 the bottom half
2. handler
3. init function
4. cleanup function
下半分はまだ予定していませんが、下にあります。私はカーネル 3.5.0-17 に取り組んでいます。
//Bottom half for the irq handler
static void bh_flowTest()
{
printk(KERN_INFO "Inside bottom half for flowTest.\n");
}
// IRQ handler function
static irqreturn_t flow_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
{
printk(KERN_INFO "This is flowTest IRQ handler.\n");
//static struct tq_struct task = {NULL, 0, bh_flowTest, NULL};
/* Schedule bottom half to run */
//queue_task(&task, &tq_immediate);
// mark_bh(IMMEDIATE_BH);
return IRQ_HANDLED;
}
static int flow_init(void)
{
printk(KERN_ALERT "Here with flowTest module ... loading...\n");
int result=0;
dev_t dev=0;
result = alloc_chrdev_region(&dev, minor_num,
num_devices,"mod_flowtest"); // allocate major number dynamically.
i=MAJOR(dev);
printk(KERN_ALERT "Major allocated = %d",i);
cdev_init(&ms_flow_cd,&flow_fops);
cdev_add(&ms_flow_cd,dev,1);
//Registering interrupt handler on IRQ2 since IRQ2 is free as per /proc/interrupts
int retval_irqreg;
retval_irqreg=request_irq(2,(irq_handler_t)flow_irq_handler, /* our handler. It has been typecasted to remove warnings of incompatible pointer type , and enum irqreturn_t. Try removing the cast and see the warnings */
IRQF_SHARED,
"test_flow_irq_handler", NULL);
printk(KERN_ALERT "Here with registering IRQ handler on IRQ2 for flowTest...retval_irqreg= %d\n",retval_irqreg);
return 0;
}
static void flow_terminate(void)
{
dev_t devno=MKDEV(i,0); // wrap major/minor numbers in a dev_t structure , to pass for deassigning.
printk(KERN_ALERT "Going out... exiting...\n");
unregister_chrdev_region(devno,num_devices); //remove entry from the /proc/devices
free_irq(2, NULL);
}
基本的な間違いがあると思いますが、誰かが私にそれを指摘してくれたら..!