| CHPOLL(9E) | Driver Entry Points | CHPOLL(9E) |
chpoll - poll entry point for a non-STREAMS character driver
#include <sys/types.h> #include <sys/poll.h> #include <sys/ddi.h> #include <sys/sunddi.h> int prefixchpoll(dev_t dev, short events, int anyyet,
short *reventsp, struct pollhead **phpp);
This entry point is optional. Architecture independent level 1 (DDI/DKI).
dev
events
POLLIN
POLLOUT
POLLPRI
POLLHUP
POLLERR
POLLRDNORM
POLLRDBAND
POLLWRNORM
POLLWRBAND
POLLET
anyyet
reventsp
phpp
The chpoll() entry point routine is used by non-STREAMS character device drivers that wish to support polling. The driver must implement the polling discipline itself. The following rules must be followed when implementing the polling discipline:
if (specified_events_are_satisfied_now) {
*reventsp = satisfied_events & events;
} else {
*reventsp = 0;
}
if ((*reventsp == 0 && !anyyet) || (events & POLLET))
*phpp = &my_local_pollhead_structure;
return (0);
Note: Prior to the integration of epoll(7), which included edge-triggering via the POLLET flag, standard chpoll mechanisms would only provide a pollhead in phpp if there were no matching events. Edge-triggered polling requires that pollwakeup() always be called for a resource, so if POLLET is set in the events of interest, the chpoll method must yield a pollhead and prepare to issue pollwakeup() calls on it.
Drivers which are not wired up to make pollwakeup() calls on a pollhead when their status changes should emit one from their chpoll routine. This will exclude the resource from caching by pollers, since it cannot alert them to new events without pollwakeup() notification.
static int
mydriver_close(dev_t dev, int flag, int otyp, cred_t *cp)
{
minor_t minor = getminor(dev);
mydriver_state_t *state;
state = ddi_get_soft_state(mydriver_softstate, minor);
pollwakeup(&state->mydriver_pollhd, POLLERR);
pollhead_clean(&state->mydriver_pollhd);
...
This step is necessary to inform other kernel subsystems that the memory associated with the pollhead is about to be deallocated by the close(9E) entry point.
chpoll() should return 0 for success, or the appropriate error number.
poll(2), epoll(7), nochpoll(9F), pollwakeup(9F)
Writing Device Drivers
| January 18, 2017 | OmniOS |