<div dir="ltr">It's a mess, but you are welcome to it :-)<div><br></div><div>//-------------------------------cut here---------------------</div><div><div>#include <linux/kernel.h></div><div>#include <linux/module.h></div>
<div>#include <linux/fs.h></div><div>//#include <linux/proc_fs.h></div><div>#include <linux/cdev.h></div><div>#include <linux/slab.h></div><div>#include <linux/init.h></div><div>#include <linux/delay.h></div>
<div>#include <asm/uaccess.h></div><div>#include <linux/seq_file.h></div><div>#include <linux/interrupt.h></div><div><br></div><div>MODULE_LICENSE("GPL");</div><div><br></div><div>#define NUM_DEVICES (1)</div>
<div>#define DEVNAME "foobar"</div><div>#define DEVPROCNAME "foobar_mem"</div><div>#define FOOBAR_MAJOR (248)</div><div>#define FOOBAR_MINOR (0)</div><div> </div><div>int foobar_init(void); </div><div>
void foobar_exit(void); </div><div>int foobar_release(struct inode *, struct file*);</div><div>ssize_t foobar_read(struct file *, char __user *, size_t, loff_t *); </div><div>ssize_t foobar_write(struct file *, const char __user *, size_t, loff_t *);</div>
<div>int foobar_read_procmem(char * buf, char **start, off_t offset, int count, int * eof, void * data); </div><div>int foobar_open(struct inode * inode, struct file * file);</div><div>void set_port_and_irq(void);</div><div>
static irqreturn_t irqhandler(int irq, void * data);</div><div>int foobar_set_irq(void);</div><div><br></div><div>int port_address = -1;</div><div>module_param(port_address, int, 0); </div><div><br></div><div>unsigned int irq = 0; </div>
<div>module_param(irq, uint, 0);</div><div><br></div><div>int irqavail = -1;</div><div><br></div><div>static struct file_operations foobar_i_fops = </div><div> {</div><div> .owner = THIS_MODULE, </div><div> .read = foobar_read, </div>
<div> .write = foobar_write,</div><div> .open = foobar_open,</div><div> .release = foobar_release,</div><div> };</div><div><br></div><div><br></div><div>static dev_t g_dev;</div><div>unsigned dev_id = (unsigned)&foobar_i_fops;</div>
<div><br></div><div>int foobar_init(void)</div><div>{</div><div> int result = 0; </div><div> </div><div> result = register_chrdev(0, DEVNAME, &foobar_i_fops); </div><div> g_dev = MKDEV(result, FOOBAR_MINOR); </div>
<div> if(result < 0)</div><div> {</div><div> printk(KERN_WARNING "foobar: can't get device number, returning %d", result); </div><div> return result; </div><div> }</div><div> </div><div> printk(KERN_WARNING "foobar: Module %s got device number %d, minor is %d, result is %d\n", THIS_MODULE->name, MAJOR(g_dev), MINOR(g_dev), result); </div>
<div> g_dev = MKDEV(MAJOR(g_dev), FOOBAR_MINOR + NUM_DEVICES);</div><div><br></div><div> set_port_and_irq();</div><div> printk(KERN_WARNING "Port address is 0x%x, IRQ is %d\n", port_address, irq);</div><div> return 0; </div>
<div>}</div><div><br></div><div>void set_port_and_irq(void)</div><div>{</div><div> if(irq < 0)</div><div> switch(port_address)</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">        </span>case 0x378:</div>
<div><span class="" style="white-space:pre">        </span> irq = 7; </div><div><span class="" style="white-space:pre">        </span> break; </div><div><br></div><div><span class="" style="white-space:pre">        </span>case 0x278:</div><div>
<span class="" style="white-space:pre">        </span> irq = 2; </div><div><span class="" style="white-space:pre">        </span> break; </div><div><span class="" style="white-space:pre">        </span>}</div><div><br></div><div> switch(irq)</div>
<div> {</div><div> case 2:</div><div><span class="" style="white-space:pre">        </span>port_address = 0x278; </div><div><span class="" style="white-space:pre">        </span>break; </div><div><br></div><div> case 7:</div>
<div><span class="" style="white-space:pre">        </span>port_address = 0x378; </div><div><span class="" style="white-space:pre">        </span>break; </div><div> </div><div> } </div><div>}</div><div><br></div><div>void foobar_exit(void)</div>
<div>{</div><div> int major = MAJOR(g_dev); </div><div><br></div><div> if(irqavail == 0)</div><div> {</div><div> printk(KERN_WARNING "Freeing irq %d, dev_id is 0x%x\n", irq, dev_id);</div><div> free_irq(irq, (void*)dev_id);</div>
<div> }</div><div> </div><div> printk(KERN_WARNING "unregister_chrdev(%d) called for %s, dev # is %d\n", major, DEVNAME, g_dev); </div><div><br></div><div> unregister_chrdev(major, DEVNAME); </div><div>}</div>
<div><br></div><div>int foobar_set_irq(void)</div><div>{</div><div> irqavail = request_irq(irq, irqhandler, IRQF_SHARED, DEVNAME, (void*)dev_id);</div><div> printk(KERN_WARNING "IRQ:%d\tPort Address:0x%x\tAvailable:%s\n", irq, port_address, irqavail == 0 ? "true" : "false"); </div>
<div><br></div><div> return irqavail;</div><div>}</div><div><br></div><div>static irqreturn_t irqhandler(int irq, void * data)</div><div>{</div><div> printk(KERN_WARNING "Interrupt is fired, IRQ is %d, data is 0x%p\n", irq, data);</div>
<div> return IRQ_HANDLED;</div><div>}</div><div><br></div><div>int foobar_open(struct inode * inode, struct file * file)</div><div>{</div><div> return foobar_set_irq(); </div><div>}</div><div><br></div><div><br></div><div>
int foobar_release(struct inode * inode, struct file * filp)</div><div>{</div><div> printk(KERN_WARNING "foobar_release() is called, fil is 0x%p, inode is 0x%p\n", filp, inode);</div><div> return 0;</div><div>
} </div><div><br></div><div>ssize_t foobar_read(struct file * filp, char __user * buf, size_t count, loff_t * f_pos)</div><div>{</div><div> printk(KERN_WARNING "Read is called\n");</div><div> return 0;</div><div>
}</div><div><br></div><div>ssize_t foobar_write(struct file * filp, const char __user * buf, size_t count, loff_t *f_pos)</div><div>{</div><div> unsigned long address = (unsigned long)port_address;</div><div> printk(KERN_WARNING "Write is called, address is 0x%lx\n", address);</div>
<div> outb_p(0x10, address + 2); </div><div> outb_p(0x00, address); </div><div> outb_p(0xff, address);</div><div> udelay(5);</div><div> outb_p(0x00, address + 2);</div><div> if(f_pos)</div><div> * f_pos = 0; </div>
<div> return count; </div><div>}</div><div><br></div><div>module_init(foobar_init); </div><div>module_exit(foobar_exit); </div><div><br></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Jan 6, 2014 at 4:27 PM, Rajat Sharma <span dir="ltr"><<a href="mailto:fs.rajat@gmail.com" target="_blank">fs.rajat@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>It would be nice to post the code when asking for debugging help. Looks like your interrupts are in masked state but when you unload the driver they are getting unmasked and hence you are receiving them on unload.<br>
<br></div>-Rajat<br></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Mon, Jan 6, 2014 at 4:09 PM, Eric Fowler <span dir="ltr"><<a href="mailto:eric.fowler@gmail.com" target="_blank">eric.fowler@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.666666984558105px">I am trying to figure out interrupts by writing a shadow of Rubini's 'short' program. Recall that Rubini tells us to enable parallel port interrupts by wiring pins 9&10 together, then writing binary data to the parallel port's address. </span><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">I am doing that, but: </div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">- I don't see interrupts when I write to the port</div>
<div style="font-family:arial,sans-serif;font-size:12.666666984558105px">- I do see one interrupt when I unload the driver (in the fop's .release method)</div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
- This happens whether or not the pins are wired up. </div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><br></div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">What is going on here?</div>
<div><br></div><div dir="ltr"><br></div>
</div>
<br></div></div>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">cc:NSA<br></div>
</div>