summaryrefslogtreecommitdiff
path: root/usr/src/man/man9e/chpoll.9e
blob: 1e8aac5e8180e46c8c006a7fb565e29ed307c836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
'\" te
.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" Copyright 2017 Joyent, Inc
.\" 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 "Jan 18, 2017"
.SH NAME
chpoll \- poll entry point for a non-STREAMS character driver
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/poll.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>



\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 ((*reventsp == 0 && !anyyet) || (events & POLLET))
      *phpp = &my_local_pollhead_structure;
return (0);
.fi
.in -2

Note: Prior to the integration of \fBepoll\fR(5), which included
edge-triggering via the \fBPOLLET\fR flag, standard chpoll mechanisms would
only provide a pollhead in \fBphpp\fR if there were no matching events.
Edge-triggered polling requires that \fBpollwakeup()\fR always be called for a
resource, so if \fBPOLLET\fR is set in the \fBevents\fR of interest, the chpoll
method must yield a pollhead and prepare to issue \fBpollwakeup()\fR calls on
it.

Drivers which are not wired up to make \fBpollwakeup()\fR calls on a pollhead
when their status changes should emit one from their \fBchpoll\fR routine.
This will exclude the resource from caching by pollers, since it cannot alert
them to new events without \fBpollwakeup()\fR notification.

.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
.RS +4
.TP
4.
In the \fBclose\fR(9E) entry point, the driver should call \fBpollwakeup()\fR
on the \fBpollhead\fR structure that corresponds to the closing software
state, specifying \fBPOLLERR\fR for the events.  Further, upon return from
\fBpollwakeup()\fR, the driver's \fBclose\fR(9E) entry point should call
the \fBpollhead_clean\fR(9F) function, specifying the \fBpollhead\fR that
corresponds to the structure that will be deallocated:

.sp
.in +2
.nf
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);
      ...
.fi
.in -2

This step is necessary to inform other kernel subsystems that the memory
associated with the \fBpollhead\fR is about to be deallocated by the
\fBclose\fR(9E) entry point.

.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), \fBepoll\fR(5), \fBnochpoll\fR(9F), \fBpollwakeup\fR(9F)
.sp
.LP
\fIWriting Device Drivers\fR