2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Copyright 2017 Joyent, Inc
5 .\" 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.
6 .\" 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.
7 .\" 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]
8 .TH CHPOLL 9E "Jan 18, 2017"
10 chpoll \- poll entry point for a non-STREAMS character driver
14 #include <sys/types.h>
17 #include <sys/sunddi.h>
21 \fBint prefix\fR\fBchpoll\fR(\fBdev_t\fR \fIdev\fR, \fBshort\fR \fIevents\fR, \fBint\fR \fIanyyet\fR,
22 \fBshort *\fR\fIreventsp\fR, \fBstruct pollhead **\fR\fIphpp\fR);
27 This entry point is optional. Architecture independent level 1 (DDI/DKI).
34 The device number for the device to be polled.
43 The events that may occur. Valid events are:
50 Data other than high priority data may be read without blocking.
59 Normal data may be written without blocking.
68 High priority data may be received without blocking.
77 A device hangup has occurred.
86 An error has occurred on the device.
92 \fB\fBPOLLRDNORM\fR\fR
95 Normal data (priority band = 0) may be read without blocking.
101 \fB\fBPOLLRDBAND\fR\fR
104 Data from a non-zero priority band may be read without blocking
110 \fB\fBPOLLWRNORM\fR\fR
113 The same as \fBPOLLOUT\fR.
119 \fB\fBPOLLWRBAND\fR\fR
122 Priority data (priority band > 0) may be written.
131 The desired event is to be edge-triggered; calls to \fBpollwakeup\fR(9F)
132 should not be suppressed, even if the event is pending at the time of
133 call to the \fBchpoll()\fR function.
144 A flag that is non-zero if any other file descriptors in the \fBpollfd\fR array
145 have events pending. The \fBpoll\fR(2) system call takes a pointer to an array
146 of \fBpollfd\fR structures as one of its arguments. See the \fBpoll\fR(2)
147 reference page for more details.
156 A pointer to a bitmask of the returned events satisfied.
165 A pointer to a pointer to a \fBpollhead\fR structure.
170 The \fBchpoll()\fR entry point routine is used by non-STREAMS character device
171 drivers that wish to support polling. The driver must implement the polling
172 discipline itself. The following rules must be followed when implementing the
177 Implement the following algorithm when the \fBchpoll()\fR entry point is
182 if (specified_events_are_satisfied_now) {
183 *reventsp = satisfied_events & events;
187 if ((*reventsp == 0 && !anyyet) || (events & POLLET))
188 *phpp = &my_local_pollhead_structure;
193 Note: Prior to the integration of \fBepoll\fR(5), which included
194 edge-triggering via the \fBPOLLET\fR flag, standard chpoll mechanisms would
195 only provide a pollhead in \fBphpp\fR if there were no matching events.
196 Edge-triggered polling requires that \fBpollwakeup()\fR always be called for a
197 resource, so if \fBPOLLET\fR is set in the \fBevents\fR of interest, the chpoll
198 method must yield a pollhead and prepare to issue \fBpollwakeup()\fR calls on
201 Drivers which are not wired up to make \fBpollwakeup()\fR calls on a pollhead
202 when their status changes should emit one from their \fBchpoll\fR routine.
203 This will exclude the resource from caching by pollers, since it cannot alert
204 them to new events without \fBpollwakeup()\fR notification.
210 Allocate an instance of the \fBpollhead\fR structure. This instance may be
211 tied to the per-minor data structure defined by the driver. The \fBpollhead\fR
212 structure should be treated as a "black box" by the driver. Initialize the
213 \fBpollhead\fR structure by filling it with zeroes. The size of this structure
214 is guaranteed to remain the same across releases.
219 Call the \fBpollwakeup()\fR function with \fBevents\fR listed above whenever
220 pollable \fBevents\fR which the driver should monitor occur. This function can
221 be called with multiple events at one time. The \fBpollwakup()\fR can be called
222 regardless of whether or not the \fBchpoll()\fR entry is called; it should be
223 called every time the driver detects the pollable event. The driver must not
224 hold any mutex across the call to \fBpollwakeup\fR(9F) that is acquired in its
225 \fBchpoll()\fR entry point, or a deadlock may result. Note that if
226 \fBPOLLET\fR is set in the specified events, the driver must call
227 \fBpollwakeup\fR(9F) on subsequent events, even if events are pending at
228 the time of the call to \fBchpoll()\fR.
234 In the \fBclose\fR(9E) entry point, the driver should call \fBpollwakeup()\fR
235 on the \fBpollhead\fR structure that corresponds to the closing software
236 state, specifying \fBPOLLERR\fR for the events. Further, upon return from
237 \fBpollwakeup()\fR, the driver's \fBclose\fR(9E) entry point should call
238 the \fBpollhead_clean\fR(9F) function, specifying the \fBpollhead\fR that
239 corresponds to the structure that will be deallocated:
245 mydriver_close(dev_t dev, int flag, int otyp, cred_t *cp)
247 minor_t minor = getminor(dev);
248 mydriver_state_t *state;
250 state = ddi_get_soft_state(mydriver_softstate, minor);
252 pollwakeup(&state->mydriver_pollhd, POLLERR);
253 pollhead_clean(&state->mydriver_pollhd);
258 This step is necessary to inform other kernel subsystems that the memory
259 associated with the \fBpollhead\fR is about to be deallocated by the
260 \fBclose\fR(9E) entry point.
265 \fBchpoll()\fR should return \fB0\fR for success, or the appropriate error
269 \fBpoll\fR(2), \fBepoll\fR(5), \fBnochpoll\fR(9F), \fBpollwakeup\fR(9F)
272 \fIWriting Device Drivers\fR