device driver: using poll to wait for an event

device driver: using poll to wait for an event

Post by Alex Raimond » Sat, 23 Nov 2002 23:34:35



Hi

I'm new to writing device drivers ;-)

I've got a device connected to my cpu which can arise an interrupt if it
wants
attention.
I succeded in getting an interrupt....

My problem is: How can I tell any user application that the device needs
attention.
First off all I thought of implementing the poll function.
I found some resources on the web telling me about this function, but I
can't get behind it (although it must be simple).

Some code:

unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
  unsigned int mask = 0;
 ...

  poll_wait(filp, &dev->inq, wait);
  poll_wait(filp, &dev->outq, wait);

  if ( isReadable() ) mask |= POLLIN | POLLRDNORM; /* readable */
  if ( isWritable() ) mask |= POLLOUT | POLLWRNORM; /* writable */
  return mask;

Quote:}

inq and outq are defined elsewhere.

Am'I right when mask is return as 0 (neither readable nor writeable) the
process blocks until the inq or outq is waked up?

But can I use this poll in my case? I don't have blocking read or write.
(The device can allways be read from or written to but its only interesting
after the device arised an interrupt.

The other thing I thought of was to implement an ioctl command, which puts
my process to sleep until an irq occours. Is this allowed and a good
behaviour of a device driver?

Thanks for any hint!

Alex

 
 
 

device driver: using poll to wait for an event

Post by Robert Schwebe » Sun, 24 Nov 2002 01:14:01



> I've got a device connected to my cpu which can arise an

 > interrupt if it wants attention.

You should buy a copy of Alessandro Rubini's "Linux Device Drivers,
2nd edition", which indeed was the source...

Quote:> Some code:

> unsigned int scull_p_poll(struct file *filp, poll_table *wait)
> {
>   unsigned int mask = 0;
>  ...

... of your example. It's the best reference if you want to
write device drivers.

Robert
--
  Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
  Pengutronix - Linux Solutions for Science and Industry
    Braunschweiger Str. 79,  31134 Hildesheim, Germany
    Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Phone: +49-5121-28619-0 |  Fax: +49-5121-28619-4

     Visit us at the SPS/IPC/Drives 2002 in Nuernberg!
    Hall 5, Booth 154 +++ Please contact us for details.

 
 
 

device driver: using poll to wait for an event

Post by Carl » Sun, 24 Nov 2002 06:55:24


Hello Alex,

use interruptable sleep functions. That is: put a user application to sleep
(by the driver) until a interrupt arrives (more precicely: when some
interesting data is available for the user process).

Use also top and bottom halves processing. But that's too complex to explain
here...

good luck
Carl.


Quote:> Hi

> I'm new to writing device drivers ;-)

> I've got a device connected to my cpu which can arise an interrupt if it
> wants
> attention.
> I succeded in getting an interrupt....

> My problem is: How can I tell any user application that the device needs
> attention.
> First off all I thought of implementing the poll function.
> I found some resources on the web telling me about this function, but I
> can't get behind it (although it must be simple).

> Some code:

> unsigned int scull_p_poll(struct file *filp, poll_table *wait)
> {
>   unsigned int mask = 0;
>  ...

>   poll_wait(filp, &dev->inq, wait);
>   poll_wait(filp, &dev->outq, wait);

>   if ( isReadable() ) mask |= POLLIN | POLLRDNORM; /* readable */
>   if ( isWritable() ) mask |= POLLOUT | POLLWRNORM; /* writable */
>   return mask;
> }

> inq and outq are defined elsewhere.

> Am'I right when mask is return as 0 (neither readable nor writeable) the
> process blocks until the inq or outq is waked up?

> But can I use this poll in my case? I don't have blocking read or write.
> (The device can allways be read from or written to but its only
interesting
> after the device arised an interrupt.

> The other thing I thought of was to implement an ioctl command, which puts
> my process to sleep until an irq occours. Is this allowed and a good
> behaviour of a device driver?

> Thanks for any hint!

> Alex

 
 
 

device driver: using poll to wait for an event

Post by Alex Raimond » Tue, 26 Nov 2002 16:04:02


H

Quote:> use interruptable sleep functions. That is: put a user application to
sleep
> (by the driver) until a interrupt arrives (more precicely: when some
> interesting data is available for the user process).

> Use also top and bottom halves processing. But that's too complex to
explain
> here...

It wouldn't be a problem for me to implement all these things you mentioned
above.
(In fact I have a copy of Alessandro Rubini's "Linux Device Drivers" ;-) )

My problem is were to put all these things! I just don't want to work
against the kernel. If I start to implement it in a way that was not
intended to do so, i would have to drop my work and start from scratch.

Thanks

Alex

> good luck
> Carl.



> > Hi

> > I'm new to writing device drivers ;-)

> > I've got a device connected to my cpu which can arise an interrupt if it
> > wants
> > attention.
> > I succeded in getting an interrupt....

> > My problem is: How can I tell any user application that the device needs
> > attention.
> > First off all I thought of implementing the poll function.
> > I found some resources on the web telling me about this function, but I
> > can't get behind it (although it must be simple).

> > Some code:

> > unsigned int scull_p_poll(struct file *filp, poll_table *wait)
> > {
> >   unsigned int mask = 0;
> >  ...

> >   poll_wait(filp, &dev->inq, wait);
> >   poll_wait(filp, &dev->outq, wait);

> >   if ( isReadable() ) mask |= POLLIN | POLLRDNORM; /* readable */
> >   if ( isWritable() ) mask |= POLLOUT | POLLWRNORM; /* writable */
> >   return mask;
> > }

> > inq and outq are defined elsewhere.

> > Am'I right when mask is return as 0 (neither readable nor writeable) the
> > process blocks until the inq or outq is waked up?

> > But can I use this poll in my case? I don't have blocking read or write.
> > (The device can allways be read from or written to but its only
> interesting
> > after the device arised an interrupt.

> > The other thing I thought of was to implement an ioctl command, which
puts
> > my process to sleep until an irq occours. Is this allowed and a good
> > behaviour of a device driver?

> > Thanks for any hint!

> > Alex

 
 
 

device driver: using poll to wait for an event

Post by Paul Taylo » Wed, 27 Nov 2002 20:37:59


What Carl says is valid - You won't be working against the Kernel.

If you want to know the best way of organising your driver for your
application, then a little more information would be useful, e.g. explain
some details on the hardware you are controlling - how much data is being
transferred between your user program and the driver, is response time
important - if so how quick does it need to respond. etc....

PT

 
 
 

1. device driver: using poll to wait for an event

Hi

I'm new to writing device drivers ;-)

I've got a device connected to my cpu which can arise an interrupt if it
wants
attention.
I succeded in getting an interrupt....

My problem is: How can I tell any user application that the device needs
attention.
First off all I thought of implementing the poll function.
I found some resources on the web telling me about this function, but I
can't get behind it (although it must be simple).

Some code:

unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
  unsigned int mask = 0;
 ...

  poll_wait(filp, &dev->inq, wait);
  poll_wait(filp, &dev->outq, wait);

  if ( isReadable() ) mask |= POLLIN | POLLRDNORM; /* readable */
  if ( isWritable() ) mask |= POLLOUT | POLLWRNORM; /* writable */
  return mask;

inq and outq are defined elsewhere.

Am'I right when mask is return as 0 (neither readable nor writeable) the
process blocks until the inq or outq is waked up?

But can I use this poll in my case? I don't have blocking read or write.
(The device can allways be read from or written to but its only interesting
after the device arised an interrupt.

The other thing I thought of was to implement an ioctl command, which puts
my process to sleep until an irq occours. Is this allowed and a good
behaviour of a device driver?

Thanks for any hint!

Alex

2. yamaha OPL3-SAx

3. fork,exec and wait and wait and wait and wait

4. Password Access

5. Poll()/select() device driver - new version available

6. Linux joystick mini howto Version 0.08

7. 8/25/92 CLB EVENT NOTICE - ZEN AND THE ART OF DEVICE DRIVER WRITING -

8. virtual webservers

9. Polling device driver

10. My Freebsd driver hangs in poll function after some time (problem with poll)

11. polling device drivers?

12. How many times does the poll method in device driver get called for each application select?

13. ? How do I find what device driver a device is using?