From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161510AbXD2WTG (ORCPT ); Sun, 29 Apr 2007 18:19:06 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1161513AbXD2WTG (ORCPT ); Sun, 29 Apr 2007 18:19:06 -0400 Received: from www.osadl.org ([213.239.205.134]:40648 "EHLO mail.tglx.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1161510AbXD2WTC convert rfc822-to-8bit (ORCPT ); Sun, 29 Apr 2007 18:19:02 -0400 From: =?utf-8?q?Hans-J=C3=BCrgen_Koch?= To: tglx@linutronix.de Subject: Re: Flaws with "UIO: Add the User IO core code" (with patch) Date: Mon, 30 Apr 2007 00:18:34 +0200 User-Agent: KMail/1.9.5 Cc: Alan Cox , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, torvalds@osdl.org, Benedikt Spranger References: <20070427224957.GA17967@kroah.com> <1177794532.7646.313.camel@localhost.localdomain> <200704282314.15274.hjk@linutronix.de> In-Reply-To: <200704282314.15274.hjk@linutronix.de> Organization: Linutronix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT Content-Disposition: inline Message-Id: <200704300018.35064.hjk@linutronix.de> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Am Samstag 28 April 2007 23:14 schrieb Hans-Jürgen Koch: > Am Samstag 28 April 2007 23:08 schrieb Thomas Gleixner: > > On Sat, 2007-04-28 at 23:03 +0200, Hans-Jürgen Koch wrote: > > > Am Samstag 28 April 2007 22:24 schrieb Alan Cox: > > > > > > AFAIK we don't currently have any platform that runs binaries with > > > > > > different sizes of "int" but this is a) an unsigned value anyway, and b) > > > > > > should be a fixed type (eg u32) > > > > > > > > > > I reviewed the code once more and find it OK. There is only one legal > > > > > value for the parameter "count" of uio_read(), and that's sizeof(int). > > > > > > > > If you are a box with multiple supported binary types how big is an > > > > "int". We use explicit sizes to ensure that uio_read() will work when/if > > > > we get platforms which support binaries with differing ideas of the size > > > > of "int". Thus it should use s32 or s64 or similar. > > > > > > Here's a fix to that effect: > > > > Can you please add a matching paragraph to the documentation ? > > > > Yes, I'll add a "How to write userspace code" section tomorrow. I'll send a > patch as soon as it's ready. > > Hans > Here's the promised update for the documentation: Hans Index: linux-2.6.22-rc/Documentation/DocBook/uio-howto.tmpl =================================================================== --- linux-2.6.22-rc.orig/Documentation/DocBook/uio-howto.tmpl 2007-04-29 22:17:45.000000000 +0200 +++ linux-2.6.22-rc/Documentation/DocBook/uio-howto.tmpl 2007-04-30 00:15:38.000000000 +0200 @@ -30,6 +30,12 @@ + 0.3 + 2007-04-29 + hjk + Added section about userspace drivers. + + 0.2 2007-02-13 hjk @@ -484,14 +490,121 @@ + + +Writing a driver in userspace + + Once you have a working kernel module for your hardware, you can + write the userspace part of your driver. You don't need any special + libraries, your driver can be written in any reasonable language, + you can use floating point numbers and so on. In short, you can + use all the tools and libraries you'd normally use for writing a + userspace application. + + + +Getting information about your UIO device + + Information about all UIO devices is available in sysfs. The + first thing you should do in your driver is check + name and version to + make sure your talking to the right device and that its kernel + driver has the version you expect. + + + You should also make sure that the memory mapping you need + exists and has the size you expect. + + + There is a tool called lsuio that lists + UIO devices and their attributes. It is available here: + + + + http://www.osadl.org/projects/downloads/UIO/user/ + + + With lsuio you can quickly check if your + kernel module is loaded and which attributes it exports. + Have a look at the manpage for details. + + + The source code of lsuio can serve as an + example for getting information about an UIO device. + The file uio_helper.c contains a lot of + functions you could use in your userspace driver code. + + + + +mmap() device memory + + After you made sure you've got the right device with the + memory mappings you need, all you have to do is to call + mmap() to map the device's memory + to userspace. + + + The parameter offset of the + mmap() call has a special meaning + for UIO devices: It is used to select which mapping of + your device you want to map. To map the memory of + mapping N, you have to use N times the page size as + your offset: + + + offset = N * getpagesize(); + + + N starts from zero, so if you've got only one memory + range to map, set offset = 0. + A drawback of this technique is that memory is always + mapped beginning with its start address. + + + + +Waiting for interrupts + + After you successfully mapped your devices memory, you + can access it like an ordinary array. Usually, you will + perform some initialization. After that, your hardware + starts working and will generate an interrupt as soon + as it's finished, has some data available, or needs your + attention because an error occured. + + + /dev/uioX is a read-only file. A + read() will always block until an + interrupt occurs. There is only one legal value for the + count parameter of + read(), and that is the size of a + signed 32 bit integer (4). Any other value for + count causes read() + to fail. The signed 32 bit integer read is the interrupt + count of your device. If the value is one more than the value + you read the last time, everything is OK. If the difference + is greater than one, you missed interrupts. + + + You can also use select() on + /dev/uioX. + + + + + Further information + + OSADL homepage. + + Linutronix homepage. - ...