1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Adding an interrupt handler</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The Userspace I/O HOWTO"><link rel="up" href="custom_kernel_module.html" title="Chapter 3. Writing your own kernel module"><link rel="prev" href="custom_kernel_module.html" title="Chapter 3. Writing your own kernel module"><link rel="next" href="using_uio_pdrv.html" title="Using uio_pdrv for platform devices"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Adding an interrupt handler</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="custom_kernel_module.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Writing your own kernel module</th><td width="20%" align="right"> <a accesskey="n" href="using_uio_pdrv.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="adding_irq_handler"></a>Adding an interrupt handler</h2></div></div></div><p> 2 What you need to do in your interrupt handler depends on your 3 hardware and on how you want to handle it. You should try to 4 keep the amount of code in your kernel interrupt handler low. 5 If your hardware requires no action that you 6 <span class="emphasis"><em>have</em></span> to perform after each interrupt, 7 then your handler can be empty.</p><p>If, on the other 8 hand, your hardware <span class="emphasis"><em>needs</em></span> some action to 9 be performed after each interrupt, then you 10 <span class="emphasis"><em>must</em></span> do it in your kernel module. Note 11 that you cannot rely on the userspace part of your driver. Your 12 userspace program can terminate at any time, possibly leaving 13 your hardware in a state where proper interrupt handling is 14 still required. 15 </p><p> 16 There might also be applications where you want to read data 17 from your hardware at each interrupt and buffer it in a piece 18 of kernel memory you've allocated for that purpose. With this 19 technique you could avoid loss of data if your userspace 20 program misses an interrupt. 21 </p><p> 22 A note on shared interrupts: Your driver should support 23 interrupt sharing whenever this is possible. It is possible if 24 and only if your driver can detect whether your hardware has 25 triggered the interrupt or not. This is usually done by looking 26 at an interrupt status register. If your driver sees that the 27 IRQ bit is actually set, it will perform its actions, and the 28 handler returns IRQ_HANDLED. If the driver detects that it was 29 not your hardware that caused the interrupt, it will do nothing 30 and return IRQ_NONE, allowing the kernel to call the next 31 possible interrupt handler. 32 </p><p> 33 If you decide not to support shared interrupts, your card 34 won't work in computers with no free interrupts. As this 35 frequently happens on the PC platform, you can save yourself a 36 lot of trouble by supporting interrupt sharing. 37 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="custom_kernel_module.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="custom_kernel_module.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="using_uio_pdrv.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 3. Writing your own kernel module </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Using uio_pdrv for platform devices</td></tr></table></div></body></html> 38