Data passing from kernel module to user space?

Data passing from kernel module to user space?

Post by Fredric Moreniu » Thu, 19 Jul 2001 23:21:02



I am writing an interrupt handler that should pass data from an external
hardware device to a user space application. Which is the best way to
accomplish this? There seem to be two alternatives:

1) Use the /proc file system
2) Use ioctl

Common for both alternatives is that the effect should be that the user
space application only gets new data when the intterrupt handler has new
data to provide. The only way I have figured out that could work to
accomplish this is for the user space app. to request data from the
interrupt handler module (via 1) or 2)), and then the interrupt handler
module puts the user space app. to sleep using

module_interruptible_sleep_on()

until the next interrupt arrives and new data is fetched from the hardware
device. The user space app. is woken up using

module_wake_up()

and gets the data via 1) or 2).

Which is the best/standard way to do things like this? Is it by using
1), 2) or perhaps something else?
Does anybody have or know of some simple interrupt handler code that does
this?

Regards,

Fredric Morenius

 
 
 

Data passing from kernel module to user space?

Post by Lew Pitch » Thu, 19 Jul 2001 23:44:29


On Wed, 18 Jul 2001 16:21:02 +0200, Fredric Morenius


>I am writing an interrupt handler that should pass data from an external
>hardware device to a user space application. Which is the best way to
>accomplish this? There seem to be two alternatives:

>1) Use the /proc file system
>2) Use ioctl

I'll add a third alternative: use the open()/read() interface
(file_operations open, read, close pointers)

Quote:>Common for both alternatives is that the effect should be that the user
>space application only gets new data when the intterrupt handler has new
>data to provide.

Think of how a read() against a raw device works. The read() blocks
until the device has data to provide. The devicedriver retrieves the
data from the device (in part through the device's interrupt handler),
and moves the data into the userspace processes read() buffer. Then,
the devicedriver releases the block, and the user process magically
sees the read data in the buffer. This seems to be exactly the
behaviour that you are asking for.

Quote:>The only way I have figured out that could work to
>accomplish this is for the user space app. to request data from the
>interrupt handler module (via 1) or 2)),

or read()

Quote:>and then the interrupt handler
>module puts the user space app. to sleep using

>module_interruptible_sleep_on()

>until the next interrupt arrives and new data is fetched from the hardware
>device.

At this point, the interrupt handler and device driver work together
to fill the user space buffer with the available data, then

Quote:> The user space app. is woken up using

>module_wake_up()

>and gets the data via 1) or 2).

no need with read(). It's already done.

Quote:>Which is the best/standard way to do things like this? Is it by using
>1), 2) or perhaps something else?
>Does anybody have or know of some simple interrupt handler code that does
>this?

Take a look at the /usr/src/linux/drivers/block/floppy.c (the floppy
disk driver).

Quote:>Regards,

>Fredric Morenius

Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employer's.)

 
 
 

Data passing from kernel module to user space?

Post by AndrĂ© Davi » Fri, 20 Jul 2001 23:49:33



> Which is the best/standard way to do things like this? Is it by using
> 1), 2) or perhaps something else?
> Does anybody have or know of some simple interrupt handler code that does
> this?

Hi,

You definitely want to get your hands on Rubini's "Linux Device
Drivers," now in its second ed.

HIH,

Andre
--

 "Share the code. If you hide it ain't good."
                                                Popular knowledge

  Andre.David.vcf
< 1K Download
 
 
 

1. Help - how to exchage data between a kernel module and a user space lib?

Hi,

I would appreciate it if someone could help me on this.  I'm fairly new in
Linux but have quite a few years programming experience on Windows
programming.

I have a module running in kernel space, and a lib in user space.  Data
exchanges are required between the module and the lib.  How can I do it?
Detailed info would be helpful.  Code snip or web site where I can find
sample code are even better.

Thank you in advance.

Ls.

2. linux mandrake 6.5

3. a novice question - about partition

4. exchange data from user space to kernel space

5. Linux with Adaptec 2940 HELP PLEASE!!

6. Writing Data from Kernel Space to User Space.

7. Stats on what kernel people are running

8. Writing data from Kernel to a data file in user space

9. message passing between user processes AND between a user process and kernel space

10. Writing data from Kernel to a data file in user space

11. Passing data from kernel mode to user mode