Print this page
8634 epoll fails to wake on certain edge-triggered conditions
8635 epoll should not emit POLLNVAL
8636 recursive epoll should emit EPOLLRDNORM
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Igor Kozhukhov <igor@dilos.org>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/xen/io/evtchn_dev.c
+++ new/usr/src/uts/common/xen/io/evtchn_dev.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 + * Copyright 2017 Joyent, Inc.
25 26 */
26 27
27 28
28 29 /*
29 30 * evtchn.c
30 31 *
31 32 * Driver for receiving and demuxing event-channel signals.
32 33 *
33 34 * Copyright (c) 2004-2005, K A Fraser
34 35 * Multi-process extensions Copyright (c) 2004, Steven Smith
35 36 *
36 37 * This file may be distributed separately from the Linux kernel, or
37 38 * incorporated into other software packages, subject to the following license:
38 39 *
39 40 * Permission is hereby granted, free of charge, to any person obtaining a copy
40 41 * of this source file (the "Software"), to deal in the Software without
41 42 * restriction, including without limitation the rights to use, copy, modify,
42 43 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
43 44 * and to permit persons to whom the Software is furnished to do so, subject to
44 45 * the following conditions:
45 46 *
46 47 * The above copyright notice and this permission notice shall be included in
47 48 * all copies or substantial portions of the Software.
48 49 *
49 50 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 51 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 52 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52 53 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53 54 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
54 55 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
55 56 * IN THE SOFTWARE.
56 57 */
57 58
58 59 #include <sys/types.h>
59 60 #include <sys/hypervisor.h>
60 61 #include <sys/machsystm.h>
61 62 #include <sys/mutex.h>
62 63 #include <sys/evtchn_impl.h>
63 64 #include <sys/ddi_impldefs.h>
64 65 #include <sys/avintr.h>
65 66 #include <sys/cpuvar.h>
66 67 #include <sys/smp_impldefs.h>
67 68 #include <sys/archsystm.h>
68 69 #include <sys/sysmacros.h>
69 70 #include <sys/fcntl.h>
70 71 #include <sys/open.h>
71 72 #include <sys/stat.h>
72 73 #include <sys/psm.h>
73 74 #include <sys/cpu.h>
74 75 #include <sys/cmn_err.h>
75 76 #include <sys/xen_errno.h>
76 77 #include <sys/policy.h>
77 78 #include <xen/sys/evtchn.h>
78 79
79 80 /* Some handy macros */
80 81 #define EVTCHNDRV_MINOR2INST(minor) ((int)(minor))
81 82 #define EVTCHNDRV_DEFAULT_NCLONES 256
82 83 #define EVTCHNDRV_INST2SOFTS(inst) \
83 84 (ddi_get_soft_state(evtchndrv_statep, (inst)))
84 85
85 86 /* Soft state data structure for evtchn driver */
86 87 struct evtsoftdata {
87 88 dev_info_t *dip;
88 89 /* Notification ring, accessed via /dev/xen/evtchn. */
89 90 #define EVTCHN_RING_SIZE (PAGESIZE / sizeof (evtchn_port_t))
90 91 #define EVTCHN_RING_MASK(_i) ((_i) & (EVTCHN_RING_SIZE - 1))
91 92 evtchn_port_t *ring;
92 93 unsigned int ring_cons, ring_prod, ring_overflow;
93 94
94 95 kcondvar_t evtchn_wait; /* Processes wait on this when ring is empty. */
95 96 kmutex_t evtchn_lock;
96 97 struct pollhead evtchn_pollhead;
97 98
98 99 pid_t pid; /* last pid to bind to this event channel. */
99 100 processorid_t cpu; /* cpu thread/evtchn is bound to */
100 101 };
101 102
102 103 static void *evtchndrv_statep;
103 104 int evtchndrv_nclones = EVTCHNDRV_DEFAULT_NCLONES;
104 105 static int *evtchndrv_clone_tab;
105 106 static dev_info_t *evtchndrv_dip;
106 107 static kmutex_t evtchndrv_clone_tab_mutex;
107 108
108 109 static int evtchndrv_detach(dev_info_t *, ddi_detach_cmd_t);
109 110
110 111 /* Who's bound to each port? */
111 112 static struct evtsoftdata *port_user[NR_EVENT_CHANNELS];
112 113 static kmutex_t port_user_lock;
113 114
114 115 void
115 116 evtchn_device_upcall()
116 117 {
117 118 struct evtsoftdata *ep;
118 119 int port;
119 120
120 121 /*
121 122 * This is quite gross, we had to leave the evtchn that led to this
122 123 * invocation in a per-cpu mailbox, retrieve it now.
123 124 * We do this because the interface doesn't offer us a way to pass
124 125 * a dynamic argument up through the generic interrupt service layer.
125 126 * The mailbox is safe since we either run with interrupts disabled or
126 127 * non-preemptable till we reach here.
127 128 */
128 129 port = CPU->cpu_m.mcpu_ec_mbox;
129 130 ASSERT(port != 0);
130 131 CPU->cpu_m.mcpu_ec_mbox = 0;
131 132 ec_clear_evtchn(port);
132 133 mutex_enter(&port_user_lock);
133 134
134 135 if ((ep = port_user[port]) != NULL) {
135 136 mutex_enter(&ep->evtchn_lock);
136 137 if ((ep->ring_prod - ep->ring_cons) < EVTCHN_RING_SIZE) {
137 138 ep->ring[EVTCHN_RING_MASK(ep->ring_prod)] = port;
138 139 /*
139 140 * Wake up reader when ring goes non-empty
140 141 */
141 142 if (ep->ring_cons == ep->ring_prod++) {
142 143 cv_signal(&ep->evtchn_wait);
143 144 mutex_exit(&ep->evtchn_lock);
144 145 pollwakeup(&ep->evtchn_pollhead,
145 146 POLLIN | POLLRDNORM);
146 147 goto done;
147 148 }
148 149 } else {
149 150 ep->ring_overflow = 1;
150 151 }
151 152 mutex_exit(&ep->evtchn_lock);
152 153 }
153 154
154 155 done:
155 156 mutex_exit(&port_user_lock);
156 157 }
157 158
158 159 /* ARGSUSED */
159 160 static int
160 161 evtchndrv_read(dev_t dev, struct uio *uio, cred_t *cr)
161 162 {
162 163 int rc = 0;
163 164 ssize_t count;
164 165 unsigned int c, p, bytes1 = 0, bytes2 = 0;
165 166 struct evtsoftdata *ep;
166 167 minor_t minor = getminor(dev);
167 168
168 169 if (secpolicy_xvm_control(cr))
169 170 return (EPERM);
170 171
171 172 ep = EVTCHNDRV_INST2SOFTS(EVTCHNDRV_MINOR2INST(minor));
172 173
173 174 /* Whole number of ports. */
174 175 count = uio->uio_resid;
175 176 count &= ~(sizeof (evtchn_port_t) - 1);
176 177
177 178 if (count == 0)
178 179 return (0);
179 180
180 181 if (count > PAGESIZE)
181 182 count = PAGESIZE;
182 183
183 184 mutex_enter(&ep->evtchn_lock);
184 185 for (;;) {
185 186 if (ep->ring_overflow) {
186 187 rc = EFBIG;
187 188 goto done;
188 189 }
189 190
190 191 if ((c = ep->ring_cons) != (p = ep->ring_prod))
191 192 break;
192 193
193 194 if (uio->uio_fmode & O_NONBLOCK) {
194 195 rc = EAGAIN;
195 196 goto done;
196 197 }
197 198
198 199 if (cv_wait_sig(&ep->evtchn_wait, &ep->evtchn_lock) == 0) {
199 200 rc = EINTR;
200 201 goto done;
201 202 }
202 203 }
203 204
204 205 /* Byte lengths of two chunks. Chunk split (if any) is at ring wrap. */
205 206 if (((c ^ p) & EVTCHN_RING_SIZE) != 0) {
206 207 bytes1 = (EVTCHN_RING_SIZE - EVTCHN_RING_MASK(c)) *
207 208 sizeof (evtchn_port_t);
208 209 bytes2 = EVTCHN_RING_MASK(p) * sizeof (evtchn_port_t);
209 210 } else {
210 211 bytes1 = (p - c) * sizeof (evtchn_port_t);
211 212 bytes2 = 0;
212 213 }
213 214
214 215 /* Truncate chunks according to caller's maximum byte count. */
215 216 if (bytes1 > count) {
216 217 bytes1 = count;
217 218 bytes2 = 0;
218 219 } else if ((bytes1 + bytes2) > count) {
219 220 bytes2 = count - bytes1;
220 221 }
221 222
222 223 if (uiomove(&ep->ring[EVTCHN_RING_MASK(c)], bytes1, UIO_READ, uio) ||
223 224 ((bytes2 != 0) && uiomove(&ep->ring[0], bytes2, UIO_READ, uio))) {
224 225 rc = EFAULT;
225 226 goto done;
226 227 }
227 228
228 229 ep->ring_cons += (bytes1 + bytes2) / sizeof (evtchn_port_t);
229 230 done:
230 231 mutex_exit(&ep->evtchn_lock);
231 232 return (rc);
232 233 }
233 234
234 235 /* ARGSUSED */
235 236 static int
236 237 evtchndrv_write(dev_t dev, struct uio *uio, cred_t *cr)
237 238 {
238 239 int rc, i;
239 240 ssize_t count;
240 241 evtchn_port_t *kbuf;
241 242 struct evtsoftdata *ep;
242 243 ulong_t flags;
243 244 minor_t minor = getminor(dev);
244 245 evtchn_port_t sbuf[32];
245 246
246 247 if (secpolicy_xvm_control(cr))
247 248 return (EPERM);
248 249
249 250 ep = EVTCHNDRV_INST2SOFTS(EVTCHNDRV_MINOR2INST(minor));
250 251
251 252
252 253 /* Whole number of ports. */
253 254 count = uio->uio_resid;
254 255 count &= ~(sizeof (evtchn_port_t) - 1);
255 256
256 257 if (count == 0)
257 258 return (0);
258 259
259 260 if (count > PAGESIZE)
260 261 count = PAGESIZE;
261 262
262 263 if (count <= sizeof (sbuf))
263 264 kbuf = sbuf;
264 265 else
265 266 kbuf = kmem_alloc(PAGESIZE, KM_SLEEP);
266 267 if ((rc = uiomove(kbuf, count, UIO_WRITE, uio)) != 0)
267 268 goto out;
268 269
269 270 mutex_enter(&port_user_lock);
270 271 for (i = 0; i < (count / sizeof (evtchn_port_t)); i++)
271 272 if ((kbuf[i] < NR_EVENT_CHANNELS) &&
272 273 (port_user[kbuf[i]] == ep)) {
273 274 flags = intr_clear();
274 275 ec_unmask_evtchn(kbuf[i]);
275 276 intr_restore(flags);
276 277 }
277 278 mutex_exit(&port_user_lock);
278 279
279 280 out:
280 281 if (kbuf != sbuf)
281 282 kmem_free(kbuf, PAGESIZE);
282 283 return (rc);
283 284 }
284 285
285 286 static void
286 287 evtchn_bind_to_user(struct evtsoftdata *u, int port)
287 288 {
288 289 ulong_t flags;
289 290
290 291 /*
291 292 * save away the PID of the last process to bind to this event channel.
292 293 * Useful for debugging.
293 294 */
294 295 u->pid = ddi_get_pid();
295 296
296 297 mutex_enter(&port_user_lock);
297 298 ASSERT(port_user[port] == NULL);
298 299 port_user[port] = u;
299 300 ec_irq_add_evtchn(ec_dev_irq, port);
300 301 flags = intr_clear();
301 302 ec_unmask_evtchn(port);
302 303 intr_restore(flags);
303 304 mutex_exit(&port_user_lock);
304 305 }
305 306
306 307 static void
307 308 evtchndrv_close_evtchn(int port)
308 309 {
309 310 struct evtsoftdata *ep;
310 311
311 312 ASSERT(MUTEX_HELD(&port_user_lock));
312 313 ep = port_user[port];
313 314 ASSERT(ep != NULL);
314 315 (void) ec_mask_evtchn(port);
315 316 /*
316 317 * It is possible the event is in transit to us.
317 318 * If it is already in the ring buffer, then a client may
318 319 * get a spurious event notification on the next read of
319 320 * of the evtchn device. Clients will need to be able to
320 321 * handle getting a spurious event notification.
321 322 */
322 323 port_user[port] = NULL;
323 324 /*
324 325 * The event is masked and should stay so, clean it up.
325 326 */
326 327 ec_irq_rm_evtchn(ec_dev_irq, port);
327 328 }
328 329
329 330 /* ARGSUSED */
330 331 static int
331 332 evtchndrv_ioctl(dev_t dev, int cmd, intptr_t data, int flag, cred_t *cr,
332 333 int *rvalp)
333 334 {
334 335 int err = 0;
335 336 struct evtsoftdata *ep;
336 337 minor_t minor = getminor(dev);
337 338
338 339 if (secpolicy_xvm_control(cr))
339 340 return (EPERM);
340 341
341 342 ep = EVTCHNDRV_INST2SOFTS(EVTCHNDRV_MINOR2INST(minor));
342 343
343 344 *rvalp = 0;
344 345
345 346 switch (cmd) {
346 347 case IOCTL_EVTCHN_BIND_VIRQ: {
347 348 struct ioctl_evtchn_bind_virq bind;
348 349
349 350 if (copyin((void *)data, &bind, sizeof (bind))) {
350 351 err = EFAULT;
351 352 break;
352 353 }
353 354
354 355 if ((err = xen_bind_virq(bind.virq, 0, rvalp)) != 0)
355 356 break;
356 357
357 358 evtchn_bind_to_user(ep, *rvalp);
358 359 break;
359 360 }
360 361
361 362 case IOCTL_EVTCHN_BIND_INTERDOMAIN: {
362 363 struct ioctl_evtchn_bind_interdomain bind;
363 364
364 365 if (copyin((void *)data, &bind, sizeof (bind))) {
365 366 err = EFAULT;
366 367 break;
367 368 }
368 369
369 370 if ((err = xen_bind_interdomain(bind.remote_domain,
370 371 bind.remote_port, rvalp)) != 0)
371 372 break;
372 373
373 374 ec_bind_vcpu(*rvalp, 0);
374 375 evtchn_bind_to_user(ep, *rvalp);
375 376 break;
376 377 }
377 378
378 379 case IOCTL_EVTCHN_BIND_UNBOUND_PORT: {
379 380 struct ioctl_evtchn_bind_unbound_port bind;
380 381
381 382 if (copyin((void *)data, &bind, sizeof (bind))) {
382 383 err = EFAULT;
383 384 break;
384 385 }
385 386
386 387 if ((err = xen_alloc_unbound_evtchn(bind.remote_domain,
387 388 rvalp)) != 0)
388 389 break;
389 390
390 391 evtchn_bind_to_user(ep, *rvalp);
391 392 break;
392 393 }
393 394
394 395 case IOCTL_EVTCHN_UNBIND: {
395 396 struct ioctl_evtchn_unbind unbind;
396 397
397 398 if (copyin((void *)data, &unbind, sizeof (unbind))) {
398 399 err = EFAULT;
399 400 break;
400 401 }
401 402
402 403 if (unbind.port >= NR_EVENT_CHANNELS) {
403 404 err = EFAULT;
404 405 break;
405 406 }
406 407
407 408 mutex_enter(&port_user_lock);
408 409
409 410 if (port_user[unbind.port] != ep) {
410 411 mutex_exit(&port_user_lock);
411 412 err = ENOTCONN;
412 413 break;
413 414 }
414 415
415 416 evtchndrv_close_evtchn(unbind.port);
416 417 mutex_exit(&port_user_lock);
417 418 break;
418 419 }
419 420
420 421 case IOCTL_EVTCHN_NOTIFY: {
421 422 struct ioctl_evtchn_notify notify;
422 423
423 424 if (copyin((void *)data, ¬ify, sizeof (notify))) {
424 425 err = EFAULT;
425 426 break;
426 427 }
427 428
428 429 if (notify.port >= NR_EVENT_CHANNELS) {
429 430 err = EINVAL;
430 431 } else if (port_user[notify.port] != ep) {
431 432 err = ENOTCONN;
432 433 } else {
433 434 ec_notify_via_evtchn(notify.port);
434 435 }
435 436 break;
436 437 }
437 438
438 439 default:
439 440 err = ENOSYS;
440 441 }
441 442
442 443 return (err);
|
↓ open down ↓ |
408 lines elided |
↑ open up ↑ |
443 444 }
444 445
445 446 static int
446 447 evtchndrv_poll(dev_t dev, short ev, int anyyet, short *revp, pollhead_t **phpp)
447 448 {
448 449 struct evtsoftdata *ep;
449 450 minor_t minor = getminor(dev);
450 451 short mask = 0;
451 452
452 453 ep = EVTCHNDRV_INST2SOFTS(EVTCHNDRV_MINOR2INST(minor));
453 - *phpp = (struct pollhead *)NULL;
454 454
455 455 if (ev & POLLOUT)
456 456 mask |= POLLOUT;
457 457 if (ep->ring_overflow)
458 458 mask |= POLLERR;
459 459 if (ev & (POLLIN | POLLRDNORM)) {
460 460 mutex_enter(&ep->evtchn_lock);
461 - if (ep->ring_cons != ep->ring_prod)
461 + if (ep->ring_cons != ep->ring_prod) {
462 462 mask |= (POLLIN | POLLRDNORM) & ev;
463 - else
464 - if (mask == 0 && !anyyet)
465 - *phpp = &ep->evtchn_pollhead;
463 + }
466 464 mutex_exit(&ep->evtchn_lock);
467 465 }
466 + if ((mask == 0 && !anyyet) || (ev & POLLET)) {
467 + *phpp = &ep->evtchn_pollhead;
468 + }
468 469 *revp = mask;
469 470 return (0);
470 471 }
471 472
472 473
473 474 /* ARGSUSED */
474 475 static int
475 476 evtchndrv_open(dev_t *devp, int flag, int otyp, cred_t *credp)
476 477 {
477 478 struct evtsoftdata *ep;
478 479 minor_t minor = getminor(*devp);
479 480
480 481 if (otyp == OTYP_BLK)
481 482 return (ENXIO);
482 483
483 484 /*
484 485 * only allow open on minor = 0 - the clone device
485 486 */
486 487 if (minor != 0)
487 488 return (ENXIO);
488 489
489 490 /*
490 491 * find a free slot and grab it
491 492 */
492 493 mutex_enter(&evtchndrv_clone_tab_mutex);
493 494 for (minor = 1; minor < evtchndrv_nclones; minor++) {
494 495 if (evtchndrv_clone_tab[minor] == 0) {
495 496 evtchndrv_clone_tab[minor] = 1;
496 497 break;
497 498 }
498 499 }
499 500 mutex_exit(&evtchndrv_clone_tab_mutex);
500 501 if (minor == evtchndrv_nclones)
501 502 return (EAGAIN);
502 503
503 504 /* Allocate softstate structure */
504 505 if (ddi_soft_state_zalloc(evtchndrv_statep,
505 506 EVTCHNDRV_MINOR2INST(minor)) != DDI_SUCCESS) {
506 507 mutex_enter(&evtchndrv_clone_tab_mutex);
507 508 evtchndrv_clone_tab[minor] = 0;
508 509 mutex_exit(&evtchndrv_clone_tab_mutex);
509 510 return (EAGAIN);
510 511 }
511 512 ep = EVTCHNDRV_INST2SOFTS(EVTCHNDRV_MINOR2INST(minor));
512 513
513 514 /* ... and init it */
514 515 ep->dip = evtchndrv_dip;
515 516
516 517 cv_init(&ep->evtchn_wait, NULL, CV_DEFAULT, NULL);
517 518 mutex_init(&ep->evtchn_lock, NULL, MUTEX_DEFAULT, NULL);
518 519
519 520 ep->ring = kmem_alloc(PAGESIZE, KM_SLEEP);
520 521
521 522 /* clone driver */
522 523 *devp = makedevice(getmajor(*devp), minor);
523 524
524 525 return (0);
525 526 }
526 527
527 528 /* ARGSUSED */
528 529 static int
529 530 evtchndrv_close(dev_t dev, int flag, int otyp, struct cred *credp)
530 531 {
531 532 struct evtsoftdata *ep;
532 533 minor_t minor = getminor(dev);
533 534 int i;
534 535
535 536 ep = EVTCHNDRV_INST2SOFTS(EVTCHNDRV_MINOR2INST(minor));
536 537 if (ep == NULL)
537 538 return (ENXIO);
538 539
539 540 mutex_enter(&port_user_lock);
540 541
541 542
542 543 for (i = 0; i < NR_EVENT_CHANNELS; i++) {
543 544 if (port_user[i] != ep)
544 545 continue;
545 546
546 547 evtchndrv_close_evtchn(i);
547 548 }
548 549
549 550 mutex_exit(&port_user_lock);
550 551
551 552 kmem_free(ep->ring, PAGESIZE);
552 553 ddi_soft_state_free(evtchndrv_statep, EVTCHNDRV_MINOR2INST(minor));
553 554
554 555 /*
555 556 * free clone tab slot
556 557 */
557 558 mutex_enter(&evtchndrv_clone_tab_mutex);
558 559 evtchndrv_clone_tab[minor] = 0;
559 560 mutex_exit(&evtchndrv_clone_tab_mutex);
560 561
561 562 return (0);
562 563 }
563 564
564 565 /* ARGSUSED */
565 566 static int
566 567 evtchndrv_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
567 568 {
568 569 dev_t dev = (dev_t)arg;
569 570 minor_t minor = getminor(dev);
570 571 int retval;
571 572
572 573 switch (cmd) {
573 574 case DDI_INFO_DEVT2DEVINFO:
574 575 if (minor != 0 || evtchndrv_dip == NULL) {
575 576 *result = (void *)NULL;
576 577 retval = DDI_FAILURE;
577 578 } else {
578 579 *result = (void *)evtchndrv_dip;
579 580 retval = DDI_SUCCESS;
580 581 }
581 582 break;
582 583 case DDI_INFO_DEVT2INSTANCE:
583 584 *result = (void *)0;
584 585 retval = DDI_SUCCESS;
585 586 break;
586 587 default:
587 588 retval = DDI_FAILURE;
588 589 }
589 590 return (retval);
590 591 }
591 592
592 593
593 594 static int
594 595 evtchndrv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
595 596 {
596 597 int error;
597 598 int unit = ddi_get_instance(dip);
598 599
599 600
600 601 switch (cmd) {
601 602 case DDI_ATTACH:
602 603 break;
603 604 case DDI_RESUME:
604 605 return (DDI_SUCCESS);
605 606 default:
606 607 cmn_err(CE_WARN, "evtchn_attach: unknown cmd 0x%x\n", cmd);
607 608 return (DDI_FAILURE);
608 609 }
609 610
610 611 /* DDI_ATTACH */
611 612
612 613 /*
613 614 * only one instance - but we clone using the open routine
614 615 */
615 616 if (ddi_get_instance(dip) > 0)
616 617 return (DDI_FAILURE);
617 618
618 619 mutex_init(&evtchndrv_clone_tab_mutex, NULL, MUTEX_DRIVER,
619 620 NULL);
620 621
621 622 error = ddi_create_minor_node(dip, "evtchn", S_IFCHR, unit,
622 623 DDI_PSEUDO, NULL);
623 624 if (error != DDI_SUCCESS)
624 625 goto fail;
625 626
626 627 /*
627 628 * save dip for getinfo
628 629 */
629 630 evtchndrv_dip = dip;
630 631 ddi_report_dev(dip);
631 632
632 633 mutex_init(&port_user_lock, NULL, MUTEX_DRIVER, NULL);
633 634 (void) memset(port_user, 0, sizeof (port_user));
634 635
635 636 ec_dev_irq = ec_dev_alloc_irq();
636 637 (void) add_avintr(NULL, IPL_EVTCHN, (avfunc)evtchn_device_upcall,
637 638 "evtchn_driver", ec_dev_irq, NULL, NULL, NULL, dip);
638 639
639 640 return (DDI_SUCCESS);
640 641
641 642 fail:
642 643 (void) evtchndrv_detach(dip, DDI_DETACH);
643 644 return (error);
644 645 }
645 646
646 647 /*ARGSUSED*/
647 648 static int
648 649 evtchndrv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
649 650 {
650 651 /*
651 652 * Don't allow detach for now.
652 653 */
653 654 return (DDI_FAILURE);
654 655 }
655 656
656 657 /* Solaris driver framework */
657 658
658 659 static struct cb_ops evtchndrv_cb_ops = {
659 660 evtchndrv_open, /* cb_open */
660 661 evtchndrv_close, /* cb_close */
661 662 nodev, /* cb_strategy */
662 663 nodev, /* cb_print */
663 664 nodev, /* cb_dump */
664 665 evtchndrv_read, /* cb_read */
665 666 evtchndrv_write, /* cb_write */
666 667 evtchndrv_ioctl, /* cb_ioctl */
667 668 nodev, /* cb_devmap */
668 669 nodev, /* cb_mmap */
669 670 nodev, /* cb_segmap */
670 671 evtchndrv_poll, /* cb_chpoll */
671 672 ddi_prop_op, /* cb_prop_op */
672 673 0, /* cb_stream */
673 674 D_NEW | D_MP | D_64BIT /* cb_flag */
674 675 };
675 676
676 677 static struct dev_ops evtchndrv_dev_ops = {
677 678 DEVO_REV, /* devo_rev */
678 679 0, /* devo_refcnt */
679 680 evtchndrv_info, /* devo_getinfo */
680 681 nulldev, /* devo_identify */
681 682 nulldev, /* devo_probe */
682 683 evtchndrv_attach, /* devo_attach */
683 684 evtchndrv_detach, /* devo_detach */
684 685 nodev, /* devo_reset */
685 686 &evtchndrv_cb_ops, /* devo_cb_ops */
686 687 NULL, /* devo_bus_ops */
687 688 NULL, /* power */
688 689 ddi_quiesce_not_needed, /* devo_quiesce */
689 690 };
690 691
691 692 static struct modldrv modldrv = {
692 693 &mod_driverops, /* Type of module. This one is a driver */
693 694 "Evtchn driver", /* Name of the module. */
694 695 &evtchndrv_dev_ops /* driver ops */
695 696 };
696 697
697 698 static struct modlinkage modlinkage = {
698 699 MODREV_1,
699 700 &modldrv,
700 701 NULL
701 702 };
702 703
703 704 int
704 705 _init(void)
705 706 {
706 707 int err;
707 708
708 709 err = ddi_soft_state_init(&evtchndrv_statep,
709 710 sizeof (struct evtsoftdata), 1);
710 711 if (err)
711 712 return (err);
712 713
713 714 err = mod_install(&modlinkage);
714 715 if (err)
715 716 ddi_soft_state_fini(&evtchndrv_statep);
716 717 else
717 718 evtchndrv_clone_tab = kmem_zalloc(
718 719 sizeof (int) * evtchndrv_nclones, KM_SLEEP);
719 720 return (err);
720 721 }
721 722
722 723 int
723 724 _fini(void)
724 725 {
725 726 int e;
726 727
727 728 e = mod_remove(&modlinkage);
728 729 if (e)
729 730 return (e);
730 731
731 732 ddi_soft_state_fini(&evtchndrv_statep);
732 733
733 734 return (0);
734 735 }
735 736
736 737 int
737 738 _info(struct modinfo *modinfop)
738 739 {
739 740 return (mod_info(&modlinkage, modinfop));
740 741 }
|
↓ open down ↓ |
263 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX