'\" te .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 1989 AT&T .\" 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. .\" 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. .\" 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] .TH CHPOLL 9E "May 7, 2008" .SH NAME chpoll \- poll entry point for a non-STREAMS character driver .SH SYNOPSIS .LP .nf #include #include #include #include \fBint prefix\fR\fBchpoll\fR(\fBdev_t\fR \fIdev\fR, \fBshort\fR \fIevents\fR, \fBint\fR \fIanyyet\fR, \fBshort *\fR\fIreventsp\fR, \fBstruct pollhead **\fR\fIphpp\fR); .fi .SH INTERFACE LEVEL .LP This entry point is optional. Architecture independent level 1 (DDI/DKI). .SH PARAMETERS .ne 2 .na \fB\fIdev\fR\fR .ad .RS 12n The device number for the device to be polled. .RE .sp .ne 2 .na \fB\fIevents\fR\fR .ad .RS 12n The events that may occur. Valid events are: .sp .ne 2 .na \fB\fBPOLLIN\fR\fR .ad .RS 14n Data other than high priority data may be read without blocking. .RE .sp .ne 2 .na \fB\fBPOLLOUT\fR\fR .ad .RS 14n Normal data may be written without blocking. .RE .sp .ne 2 .na \fB\fBPOLLPRI\fR\fR .ad .RS 14n High priority data may be received without blocking. .RE .sp .ne 2 .na \fB\fBPOLLHUP\fR\fR .ad .RS 14n A device hangup has occurred. .RE .sp .ne 2 .na \fB\fBPOLLERR\fR\fR .ad .RS 14n An error has occurred on the device. .RE .sp .ne 2 .na \fB\fBPOLLRDNORM\fR\fR .ad .RS 14n Normal data (priority band = 0) may be read without blocking. .RE .sp .ne 2 .na \fB\fBPOLLRDBAND\fR\fR .ad .RS 14n Data from a non-zero priority band may be read without blocking .RE .sp .ne 2 .na \fB\fBPOLLWRNORM\fR\fR .ad .RS 14n The same as \fBPOLLOUT\fR. .RE .sp .ne 2 .na \fB\fBPOLLWRBAND\fR\fR .ad .RS 14n Priority data (priority band > 0) may be written. .RE .sp .ne 2 .na \fB\fBPOLLET\fR\fR .ad .RS 14n The desired event is to be edge-triggered; calls to \fBpollwakeup\fR(9F) should not be suppressed, even if the event is pending at the time of call to the \fBchpoll()\fR function. .RE .RE .sp .ne 2 .na \fB\fIanyyet\fR\fR .ad .RS 12n A flag that is non-zero if any other file descriptors in the \fBpollfd\fR array have events pending. The \fBpoll\fR(2) system call takes a pointer to an array of \fBpollfd\fR structures as one of its arguments. See the \fBpoll\fR(2) reference page for more details. .RE .sp .ne 2 .na \fB\fIreventsp\fR\fR .ad .RS 12n A pointer to a bitmask of the returned events satisfied. .RE .sp .ne 2 .na \fB\fIphpp\fR\fR .ad .RS 12n A pointer to a pointer to a \fBpollhead\fR structure. .RE .SH DESCRIPTION .LP The \fBchpoll()\fR 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: .RS +4 .TP 1. Implement the following algorithm when the \fBchpoll()\fR entry point is called: .sp .in +2 .nf if (specified_events_are_satisfied_now) { *reventsp = satisfied_events & events; } else { *reventsp = 0; if (!anyyet) *phpp = &my_local_pollhead_structure; } return (0); .fi .in -2 .RE .RS +4 .TP 2. Allocate an instance of the \fBpollhead\fR structure. This instance may be tied to the per-minor data structure defined by the driver. The \fBpollhead\fR structure should be treated as a "black box" by the driver. Initialize the \fBpollhead\fR structure by filling it with zeroes. The size of this structure is guaranteed to remain the same across releases. .RE .RS +4 .TP 3. Call the \fBpollwakeup()\fR function with \fBevents\fR listed above whenever pollable \fBevents\fR which the driver should monitor occur. This function can be called with multiple events at one time. The \fBpollwakup()\fR can be called regardless of whether or not the \fBchpoll()\fR entry is called; it should be called every time the driver detects the pollable event. The driver must not hold any mutex across the call to \fBpollwakeup\fR(9F) that is acquired in its \fBchpoll()\fR entry point, or a deadlock may result. Note that if \fBPOLLET\fR is set in the specified events, the driver must call \fBpollwakeup\fR(9F) on subsequent events, even if events are pending at the time of the call to \fBchpoll()\fR. .RE .SH RETURN VALUES .LP \fBchpoll()\fR should return \fB0\fR for success, or the appropriate error number. .SH SEE ALSO .LP \fBpoll\fR(2), \fBnochpoll\fR(9F), \fBpollwakeup\fR(9F) .sp .LP \fIWriting Device Drivers\fR