public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Hans-Jürgen Koch" <hjk@linutronix.de>
To: Randy Dunlap <randy.dunlap@oracle.com>
Cc: "Uwe Kleine-König" <Uwe.Kleine-Koenig@digi.com>,
	linux-kernel@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@suse.de>,
	"Jan Altenberg" <jan.altenberg@linutronix.de>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Magnus Damm" <magnus.damm@gmail.com>
Subject: Re: [PATCH 1/1] UIO: Add a write() function to enable/disable interrupts
Date: Sat, 24 May 2008 00:49:17 +0200	[thread overview]
Message-ID: <20080524004917.6a226e96@dilbert.local> (raw)
In-Reply-To: <20080523113650.2467f2ee.randy.dunlap@oracle.com>

Am Fri, 23 May 2008 11:36:50 -0700
schrieb Randy Dunlap <randy.dunlap@oracle.com>:

>
> > +	For some hardware that has more than one interrupt source internally,
> > +	but not seperate IRQ mask and status registers, there might be
> 
> 	        separate
> 
> > +	situations where userspace cannot determine what the interrupt source
> > +	was if the kernel handler disables them by writing to the chip's IRQ
> > +	register. In such a case, the kernel has to disable the IRQ completely
> > +	to leave the chip's register untouched. Now the userspace part can
> > +	determine the cause of the interrupt, but it cannot re-enable
> > +	interrupts. Another cornercase are chips where re-enabling interrupts
> 
> 	                               is
> 
> > +	is a read-modify-write operation to a combined IRQ status/acknowledge
> > +	register. This would be racy if a new interrupt occured
> 
> 	                                                occurred
> 
> > +	simultaneously.
> > +	</para>
> > +	<para>
> > +	To address these problems, UIO also implements a write() function. It
> > +	is normally not used and can be ignored for hardware that has only a
> > +	single interrupt source or has seperate IRQ mask and status registers.
> 
> 	                               separate
> ["There's <a rat> in separate."]

I'll certainly remember that one :-)

> 
> > +	If you need it, however, a write to <filename>/dev/uioX</filename>
> > +	will call the <function>irqcontrol()</function> function implemented
> > +	by the driver. You have to write a 32-bit value that is usually either
> > +	0 or 1 do disable or enable interrupts. If a driver does not implement
> 
> 	       to
> 
> > +	<function>irqcontrol()</function>, <function>write()</function> will
> > +	return with <varname>-ENOSYS</varname>.
> > +	</para>
> 
> ---
> ~Randy

Thanks a lot for reviewing this! Corrected patch below.

Hans

From: Hans J. Koch <hjk@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	Jan Altenberg <jan.altenberg@linutronix.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Uwe Kleine-König <Uwe.Kleine-Koenig@digi.com>,
	Magnus Damm <magnus.damm@gmail.com>
Subject: UIO: Add write function to allow irq masking
Date: Thu, Fri, 23 May 2008 13:50:14 +0200

Sometimes it is necessary to enable/disable the interrupt of a UIO device
from the userspace part of the driver. With this patch, the UIO kernel driver
can implement an "irqcontrol()" function that does this. Userspace can write
an s32 value to /dev/uioX (usually 0 or 1 to turn the irq off or on). The
UIO core will then call the driver's irqcontrol function.

Signed-off-by: Hans J. Koch <hjk@linutronix.de>
---
 Documentation/DocBook/uio-howto.tmpl |   40 ++++++++++++++++++++++++++++++++++-
 drivers/uio/uio.c                    |   26 ++++++++++++++++++++++
 include/linux/uio_driver.h           |    2 +
 3 files changed, 67 insertions(+), 1 deletion(-)

Index: linux-2.6.26-rc/include/linux/uio_driver.h
===================================================================
--- linux-2.6.26-rc.orig/include/linux/uio_driver.h	2008-05-22 20:22:57.000000000 +0200
+++ linux-2.6.26-rc/include/linux/uio_driver.h	2008-05-22 20:23:12.000000000 +0200
@@ -53,6 +53,7 @@
  * @mmap:		mmap operation for this uio device
  * @open:		open operation for this uio device
  * @release:		release operation for this uio device
+ * @irqcontrol:		disable/enable irqs when 0/1 is written to /dev/uioX
  */
 struct uio_info {
 	struct uio_device	*uio_dev;
@@ -66,6 +67,7 @@
 	int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
 	int (*open)(struct uio_info *info, struct inode *inode);
 	int (*release)(struct uio_info *info, struct inode *inode);
+	int (*irqcontrol)(struct uio_info *info, s32 irq_on);
 };
 
 extern int __must_check
Index: linux-2.6.26-rc/drivers/uio/uio.c
===================================================================
--- linux-2.6.26-rc.orig/drivers/uio/uio.c	2008-05-22 20:23:07.000000000 +0200
+++ linux-2.6.26-rc/drivers/uio/uio.c	2008-05-23 13:49:40.000000000 +0200
@@ -420,6 +420,31 @@
 	return retval;
 }
 
+static ssize_t uio_write(struct file *filep, const char __user *buf,
+			size_t count, loff_t *ppos)
+{
+	struct uio_listener *listener = filep->private_data;
+	struct uio_device *idev = listener->dev;
+	ssize_t retval;
+	s32 irq_on;
+
+	if (idev->info->irq == UIO_IRQ_NONE)
+		return -EIO;
+
+	if (count != sizeof(s32))
+		return -EINVAL;
+
+	if (!idev->info->irqcontrol)
+		return -ENOSYS;
+
+	if (copy_from_user(&irq_on, buf, count))
+		return -EFAULT;
+
+	retval = idev->info->irqcontrol(idev->info, irq_on);
+
+	return retval ? retval : sizeof(s32);
+}
+
 static int uio_find_mem_index(struct vm_area_struct *vma)
 {
 	int mi;
@@ -539,6 +564,7 @@
 	.open		= uio_open,
 	.release	= uio_release,
 	.read		= uio_read,
+	.write		= uio_write,
 	.mmap		= uio_mmap,
 	.poll		= uio_poll,
 	.fasync		= uio_fasync,
Index: linux-2.6.26-rc/Documentation/DocBook/uio-howto.tmpl
===================================================================
--- linux-2.6.26-rc.orig/Documentation/DocBook/uio-howto.tmpl	2008-05-22 20:22:57.000000000 +0200
+++ linux-2.6.26-rc/Documentation/DocBook/uio-howto.tmpl	2008-05-24 00:33:48.000000000 +0200
@@ -30,6 +30,12 @@
 
 <revhistory>
 	<revision>
+	<revnumber>0.5</revnumber>
+	<date>2008-05-22</date>
+	<authorinitials>hjk</authorinitials>
+	<revremark>Added description of write() function.</revremark>
+	</revision>
+	<revision>
 	<revnumber>0.4</revnumber>
 	<date>2007-11-26</date>
 	<authorinitials>hjk</authorinitials>
@@ -64,7 +70,7 @@
 <?dbhtml filename="copyright.html"?>
 <title>Copyright and License</title>
 <para>
-      Copyright (c) 2006 by Hans-Jürgen Koch.</para>
+      Copyright (c) 2006-2008 by Hans-Jürgen Koch.</para>
 <para>
 This documentation is Free Software licensed under the terms of the
 GPL version 2.
@@ -189,6 +195,30 @@
 	represents the total interrupt count. You can use this number
 	to figure out if you missed some interrupts.
 	</para>
+	<para>
+	For some hardware that has more than one interrupt source internally,
+	but not separate IRQ mask and status registers, there might be
+	situations where userspace cannot determine what the interrupt source
+	was if the kernel handler disables them by writing to the chip's IRQ
+	register. In such a case, the kernel has to disable the IRQ completely
+	to leave the chip's register untouched. Now the userspace part can
+	determine the cause of the interrupt, but it cannot re-enable
+	interrupts. Another cornercase is chips where re-enabling interrupts
+	is a read-modify-write operation to a combined IRQ status/acknowledge
+	register. This would be racy if a new interrupt occurred
+	simultaneously.
+	</para>
+	<para>
+	To address these problems, UIO also implements a write() function. It
+	is normally not used and can be ignored for hardware that has only a
+	single interrupt source or has separate IRQ mask and status registers.
+	If you need it, however, a write to <filename>/dev/uioX</filename>
+	will call the <function>irqcontrol()</function> function implemented
+	by the driver. You have to write a 32-bit value that is usually either
+	0 or 1 to disable or enable interrupts. If a driver does not implement
+	<function>irqcontrol()</function>, <function>write()</function> will
+	return with <varname>-ENOSYS</varname>.
+	</para>
 
 	<para>
 	To handle interrupts properly, your custom kernel module can
@@ -362,6 +392,14 @@
 <function>open()</function>, you will probably also want a custom
 <function>release()</function> function.
 </para></listitem>
+
+<listitem><para>
+<varname>int (*irqcontrol)(struct uio_info *info, s32 irq_on)
+</varname>: Optional. If you need to be able to enable or disable
+interrupts from userspace by writing to <filename>/dev/uioX</filename>,
+you can implement this function. The parameter <varname>irq_on</varname>
+will be 0 to disable interrupts and 1 to enable them.
+</para></listitem>
 </itemizedlist>
 
 <para>


  reply	other threads:[~2008-05-23 22:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22 19:22 [PATCH 0/1] UIO: Add a write() function to enable/disable interrupts Hans J. Koch
2008-05-22 19:26 ` [PATCH 1/1] " Hans J. Koch
2008-05-22 19:47   ` Tom Spink
2008-05-22 20:08     ` Hans J. Koch
2008-05-22 20:26       ` Tom Spink
2008-05-23  5:41         ` Uwe Kleine-König
2008-05-23  8:51           ` Hans J. Koch
2008-05-23 11:48           ` Tom Spink
2008-05-23 11:58             ` Uwe Kleine-König
2008-05-23 12:00               ` Tom Spink
2008-05-23 12:14                 ` Hans J. Koch
2008-05-23 12:20                   ` Tom Spink
2008-05-23 13:01                     ` Hans J. Koch
2008-05-23  5:55   ` Uwe Kleine-König
2008-05-23  8:44     ` Hans J. Koch
2008-05-23  9:10       ` Uwe Kleine-König
2008-05-23 10:03         ` Hans J. Koch
2008-05-23 10:56           ` Uwe Kleine-König
2008-05-23 11:55             ` Hans J. Koch
2008-05-23 12:03               ` Uwe Kleine-König
2008-05-23 18:36               ` Randy Dunlap
2008-05-23 22:49                 ` Hans-Jürgen Koch [this message]
2008-06-04  6:30                   ` Uwe Kleine-König
2008-06-04  7:05                     ` Thomas Gleixner
2008-05-23 20:44               ` Leon Woestenberg
2008-05-23 22:43                 ` Hans J. Koch
2008-05-24  0:02                   ` Leon Woestenberg
2008-05-24  4:43               ` Greg KH
2008-05-24 22:20                 ` Hans J. Koch
2008-05-24 22:22                 ` Thomas Gleixner
2008-05-24 22:34                   ` Tom Spink
2008-05-24 22:46                     ` Thomas Gleixner
2008-05-24 23:00                       ` Tom Spink
2008-05-27 17:55                   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080524004917.6a226e96@dilbert.local \
    --to=hjk@linutronix.de \
    --cc=Uwe.Kleine-Koenig@digi.com \
    --cc=gregkh@suse.de \
    --cc=jan.altenberg@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=randy.dunlap@oracle.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox