2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH CHPOLL 9E "May 7, 2008"
9 chpoll \- poll entry point for a non-STREAMS character driver
13 #include <sys/types.h>
16 #include <sys/sunddi.h>
20 \fBint prefix\fR\fBchpoll\fR(\fBdev_t\fR \fIdev\fR, \fBshort\fR \fIevents\fR, \fBint\fR \fIanyyet\fR,
21 \fBshort *\fR\fIreventsp\fR, \fBstruct pollhead **\fR\fIphpp\fR);
26 This entry point is optional. Architecture independent level 1 (DDI/DKI).
33 The device number for the device to be polled.
42 The events that may occur. Valid events are:
49 Data other than high priority data may be read without blocking.
58 Normal data may be written without blocking.
67 High priority data may be received without blocking.
76 A device hangup has occurred.
85 An error has occurred on the device.
91 \fB\fBPOLLRDNORM\fR\fR
94 Normal data (priority band = 0) may be read without blocking.
100 \fB\fBPOLLRDBAND\fR\fR
103 Data from a non-zero priority band may be read without blocking
109 \fB\fBPOLLWRNORM\fR\fR
112 The same as \fBPOLLOUT\fR.
118 \fB\fBPOLLWRBAND\fR\fR
121 Priority data (priority band > 0) may be written.
130 The desired event is to be edge-triggered; calls to \fBpollwakeup\fR(9F)
131 should not be suppressed, even if the event is pending at the time of
132 call to the \fBchpoll()\fR function.
143 A flag that is non-zero if any other file descriptors in the \fBpollfd\fR array
144 have events pending. The \fBpoll\fR(2) system call takes a pointer to an array
145 of \fBpollfd\fR structures as one of its arguments. See the \fBpoll\fR(2)
146 reference page for more details.
155 A pointer to a bitmask of the returned events satisfied.
164 A pointer to a pointer to a \fBpollhead\fR structure.
169 The \fBchpoll()\fR entry point routine is used by non-STREAMS character device
170 drivers that wish to support polling. The driver must implement the polling
171 discipline itself. The following rules must be followed when implementing the
176 Implement the following algorithm when the \fBchpoll()\fR entry point is
181 if (specified_events_are_satisfied_now) {
182 *reventsp = satisfied_events & events;
186 *phpp = &my_local_pollhead_structure;
196 Allocate an instance of the \fBpollhead\fR structure. This instance may be
197 tied to the per-minor data structure defined by the driver. The \fBpollhead\fR
198 structure should be treated as a "black box" by the driver. Initialize the
199 \fBpollhead\fR structure by filling it with zeroes. The size of this structure
200 is guaranteed to remain the same across releases.
205 Call the \fBpollwakeup()\fR function with \fBevents\fR listed above whenever
206 pollable \fBevents\fR which the driver should monitor occur. This function can
207 be called with multiple events at one time. The \fBpollwakup()\fR can be called
208 regardless of whether or not the \fBchpoll()\fR entry is called; it should be
209 called every time the driver detects the pollable event. The driver must not
210 hold any mutex across the call to \fBpollwakeup\fR(9F) that is acquired in its
211 \fBchpoll()\fR entry point, or a deadlock may result. Note that if
212 \fBPOLLET\fR is set in the specified events, the driver must call
213 \fBpollwakeup\fR(9F) on subsequent events, even if events are pending at
214 the time of the call to \fBchpoll()\fR.
220 In the \fBclose\fR(9E) entry point, the driver should call \fBpollwakeup()\fR
221 on the \fBpollhead\fR structure that corresponds to the closing software
222 state, specifying \fBPOLLERR\fR for the events. Further, upon return from
223 \fBpollwakeup()\fR, the driver's \fBclose\fR(9E) entry point should call
224 the \fBpollhead_clean\fR(9F) function, specifying the \fBpollhead\fR that
225 corresponds to the structure that will be deallocated:
231 mydriver_close(dev_t dev, int flag, int otyp, cred_t *cp)
233 minor_t minor = getminor(dev);
234 mydriver_state_t *state;
236 state = ddi_get_soft_state(mydriver_softstate, minor);
238 pollwakeup(&state->mydriver_pollhd, POLLERR);
239 pollhead_clean(&state->mydriver_pollhd);
244 This step is necessary to inform other kernel subsystems that the memory
245 associated with the \fBpollhead\fR is about to be deallocated by the
246 \fBclose\fR(9E) entry point.
251 \fBchpoll()\fR should return \fB0\fR for success, or the appropriate error
255 \fBpoll\fR(2), \fBnochpoll\fR(9F), \fBpollwakeup\fR(9F)
258 \fIWriting Device Drivers\fR