From: "Tom Spink" <tspink@gmail.com>
To: "Hans J. Koch" <hjk@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
"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: Re: [PATCH 1/1] UIO: Add a write() function to enable/disable interrupts
Date: Thu, 22 May 2008 21:26:28 +0100 [thread overview]
Message-ID: <7b9198260805221326t6d23b757p2ffe646db70fceba@mail.gmail.com> (raw)
In-Reply-To: <20080522200814.GD3226@local>
2008/5/22 Hans J. Koch <hjk@linutronix.de>:
> On Thu, May 22, 2008 at 08:47:16PM +0100, Tom Spink wrote:
>
> Hi Tom,
>
>> 2008/5/22 Hans J. Koch <hjk@linutronix.de>:
>> > 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>
>>
>> <snip>
>>
>> Hi,
>>
>> I wonder if it would be better to implement this as an ioctl,
>
> No way. We don't want to introduce new ioctls.
Why not? A typical usage scenario would then be:
fd = open("/dev/uio0", O_RDONLY);
...
ioctl(fd, UIO_IOC_SETIRQ, 0);
...
ioctl(fd, UIO_IOC_SETIRQ, 1);
...
close(fd);
The added benefit is that the code becomes less complex, as you don't
have to check buffer sizes and copy the integer from userspace. You
just implement an ioctl handle on the uio char device, reducing the
code to something like this (not compiled or tested in any way, and
missing the definition of UIO_IOC_SETIRQ):
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 55cc7b8..9edc7c0 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -534,11 +534,31 @@ static int uio_mmap(struct file *filep, struct
vm_area_struct *vma)
}
}
+static int uio_ioctl(struct inode *inode, struct file *filp, unsigned
int cmd, unsigned long arg)
+{
+ struct uio_listener *listener = filp->private_data;
+ struct uio_device *idev = listener->dev;
+
+ switch (cmd) {
+ case UIO_IOC_SETIRQ:
+ if (idev->info->irq == UIO_IRQ_NONE)
+ return -EIO;
+
+ if (idev->info->irqcontrol)
+ return idev->info->irqcontrol(idev->info, arg);
+ else
+ return -ENOSYS;
+ }
+
+ return -ENOTTY;
+}
+
static const struct file_operations uio_fops = {
.owner = THIS_MODULE,
.open = uio_open,
.release = uio_release,
.read = uio_read,
+ .ioctl = uio_ioctl,
.mmap = uio_mmap,
.poll = uio_poll,
.fasync = uio_fasync,
>
>> rather
>> than a write to the device. Writing to a device is a pretty generic
>> thing, and this patch would tie that up to specifically controlling
>> interrupts.
>
> UIO userspace drivers do their whole work by accessing the device's
> memory directly. The purpose of the kernel part is mainly
>
> 1) allow this memory to be mapped
> 2) handle interrupts
>
> We have an mmap() implementation for 1) and a read() implementation to
> wait for interrupts. Now we add write to enable/disable interrupts,
> which completes 2). Looks clean to me.
Okay, I understand that. Fair point, but what happens if later write
needs to do something else?
>
>> An ioctl would be more appropriate, IMO, as you are
>> issuing a controlling command, i.e. disable or enable interrupts.
>>
>> By the way, I have absolutely no idea how the UIO driver works, other
>> than reading http://lwn.net/Articles/232575/
>
> You could read the docs that come with the kernel sources:
> Documentation/DocBook/uio_howto
Thanks! That document certainly helps.
> Thanks,
> Hans
--
Tom Spink
next prev parent reply other threads:[~2008-05-22 20:26 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-22 19:22 [PATCH 0/1] " 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 [this message]
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
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=7b9198260805221326t6d23b757p2ffe646db70fceba@mail.gmail.com \
--to=tspink@gmail.com \
--cc=Uwe.Kleine-Koenig@digi.com \
--cc=gregkh@suse.de \
--cc=hjk@linutronix.de \
--cc=jan.altenberg@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=magnus.damm@gmail.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
all inboxes | Powered by JetHome®