Subject: Re: device driver poll() example
To: None <tech-kern@NetBSD.org>
From: Chapman Flack <flack@cerias.purdue.edu>
List: tech-kern
Date: 08/19/2004 11:29:41
> Where i can find some simple example how to implement poll call in device 
> driver independently to tty level ? For example, @user level i'd like to 

There are non-tty devices that support poll - you can find them in
(iirc) <sys/conf.h> looking for any devices declared with the 'p' operation
in the macro name, as in iocwrp - you'll see what I mean when you look in the
file.                         ^     I've not caught up to gehenna devsw yet
though, so current mechanisms might be different.

> 
> My guess is that i can just sleep() inside poll handler and wakeup() process 
> from interrupt handler and this should satisfy userland poll/select calls. Am 
> i right in my guess or some more complicated handling required?

afaiu, in poll() you check the requested flags against anything you can
deliver, and you set the returned flags for whatever matched.  If anything
matched you just return.  If nothing matched, you use selrecord to remember
the process, and then just return; the kernel routine that called you will
take care of blocking that process if it wanted to be blocked.

In your interrupt service routine if something good has happened, you use
selwakeup to let any waiting process know.  More details from the examples.

selrecord and selwakeup did not seem to have man pages until last February:
  http://netbsd.gw.com/cgi-bin/man-cgi?selwakeup
and that might mean that stuff is changing for 2.0.  The man page says that
selnotify is now preferred to selwakeup, and selnotify seems to hook into
the new kqueue kernel event stuff, about which I plead ignorance for now.

-Chap