Hello,
I am trying to test linux driver to understand how to handle interrupts.
Code:
// Linux Device Driver Template/Skeleton
// Kernel Module
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <asm/io.h>
#define SKELETON_MAJOR 32
#define SKELETON_NAME "skeleton"
#define BASEPORT 0x378
#define PARALLEL_PORT_INTERRUPT 7
#define CASE1 1
#define CASE2 2
static unsigned long devid;
int cntr;
// interrupt handler
static irqreturn_t handler(int irq, void *data)
{
cntr++;
printk("parint: >>> Interrupt PARALLEL PORT INT %d HANDLED\n", cntr);
return IRQ_HANDLED;
}
// define which file operations are supported
struct file_operations skeleton_fops = {
.owner = THIS_MODULE,
.llseek = NULL,
.readdir= NULL,
.poll = NULL,
.mmap = NULL,
.flush = NULL,
.fsync = NULL,
.fasync = NULL,
.lock = NULL
};
int xinit_module(void)
{
int ret;
ret = request_irq(PARALLEL_PORT_INTERRUPT, handler, IRQF_DISABLED , "parallelport", (void *)&devid);
if (ret) { printk ("parint: error requesting irq 7: returned %d\n", ret); }
enable_irq(PARALLEL_PORT_INTERRUPT);
outb_p(0x10, BASEPORT + 2);
printk("parint: Generating Interrupt now on all output pins (intr/ACK = pin 10)\n");
//generate interrupt
outb_p(0, BASEPORT);
outb_p(255, BASEPORT);
outb_p(0, BASEPORT);
printk("parint: Interrupt generated. You should see the handler-message\n");
return 0;
}
void xcleanup_module(void)
{
printk("Finlizando driver.\n");
disable_irq(PARALLEL_PORT_INTERRUPT);
free_irq(PARALLEL_PORT_INTERRUPT, (void *)&devid);
}
module_init(xinit_module);
module_exit(xcleanup_module);
MODULE_LICENSE("GPL");
Driver compile without problem, but , after request_irq in module_init, if I uncomment enable_irq, linux return me a problem:
Code:
Unbalanced enable for IRQ 7
------------[ cut here ]------------
WARNING: at kernel/irq/manage.c:174 enable_irq+0x6f/0xac()
Modules linked in: skeleton(+) usb_storage iptable_filter ip_tables ip6table_filter ip6_tables x_tables ext2 ipv6 i915 drm af_packet snd_pcm_oss snd_mixer_oss snd_seq snd_seq_device cpufreq_conservative cpufreq_userspace cpufreq_powersave acpi_cpufreq binfmt_misc microcode fuse nls_iso8859_1 nls_cp437 vfat fat loop dm_mod ide_disk pata_pcmcia ide_cs arc4 ecb crypto_blkcipher pcmcia snd_hda_intel snd_pcm snd_timer snd_page_alloc iwl3945 rtc_cmos snd_hwdep yenta_socket rtc_core ohci1394 video rsrc_nonstatic snd iTCO_wdt ieee1394 sr_mod wmi button intel_agp output pcmcia_core firmware_class battery tg3 rtc_lib dcdbas cdrom ac iTCO_vendor_support i2c_i801 joydev soundcore i2c_core mac80211 cfg80211 sg usbhid hid ff_memless sd_mod ehci_hcd uhci_hcd usbcore edd ext3 mbcache jbd fan ide_generic ide_core ata_piix libata scsi_mod dock thermal processor [last unloaded: skeleton]
Pid: 3713, comm: insmod Tainted: G D N 2.6.25.20-0.5-default #1
Call Trace:
[<ffffffff8020d696>] dump_trace+0xc4/0x57d
[<ffffffff8020db8f>] show_trace+0x40/0x57
[<ffffffff804477bd>] dump_stack+0x72/0x7b
[<ffffffff80237567>] warn_on_slowpath+0x58/0x80
[<ffffffff8026f5e9>] enable_irq+0x6f/0xac
[<ffffffff8862409f>] :skeleton:init_module+0x49/0xa6
[<ffffffff8025ab5d>] sys_init_module+0x1b10/0x1c4d
[<ffffffff8020bffa>] system_call_after_swapgs+0x8a/0x8f
[<00007f555c9cc6fa>]
---[ end trace 7e5c10f539e28698 ]---
parint: Generating Interrupt now on all output pins (intr/ACK = pin 10)
parint: Interrupt generated. You should see the handler-message
I dont understand what is the reason.
Could somebody tell me what is the problem???
Best regards.