10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57656SSherry.Moore@Sun.COM * Common Development and Distribution License (the "License").
67656SSherry.Moore@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12967Sgavin.maltby@oracle.com * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate * Sysevent Driver for GPEC
280Sstevel@tonic-gate */
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/param.h>
320Sstevel@tonic-gate #include <sys/cred.h>
330Sstevel@tonic-gate #include <sys/file.h>
340Sstevel@tonic-gate #include <sys/stat.h>
350Sstevel@tonic-gate #include <sys/conf.h>
360Sstevel@tonic-gate #include <sys/ddi.h>
370Sstevel@tonic-gate #include <sys/sunddi.h>
380Sstevel@tonic-gate #include <sys/modctl.h>
390Sstevel@tonic-gate #include <sys/open.h> /* OTYP_CHR definition */
400Sstevel@tonic-gate #include <sys/sysmacros.h> /* L_BITSMINOR definition */
410Sstevel@tonic-gate #include <sys/bitmap.h>
420Sstevel@tonic-gate #include <sys/sysevent.h>
430Sstevel@tonic-gate #include <sys/sysevent_impl.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate static dev_info_t *sysevent_devi;
460Sstevel@tonic-gate
470Sstevel@tonic-gate /* Definitions for binding handle array */
480Sstevel@tonic-gate static ulong_t sysevent_bitmap_initial = 1; /* index 0 indicates error */
490Sstevel@tonic-gate static ulong_t *sysevent_minor_bitmap = &sysevent_bitmap_initial;
500Sstevel@tonic-gate static size_t sysevent_minor_bits = BT_NBIPUL;
510Sstevel@tonic-gate static kmutex_t sysevent_minor_mutex;
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * evchan_ctl acts as a container for the binding handle
550Sstevel@tonic-gate */
560Sstevel@tonic-gate typedef struct evchan_ctl {
570Sstevel@tonic-gate evchan_t *chp;
580Sstevel@tonic-gate } evchan_ctl_t;
590Sstevel@tonic-gate
600Sstevel@tonic-gate static void *evchan_ctlp;
610Sstevel@tonic-gate
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate * Check if it's a null terminated array - to avoid DoS attack
640Sstevel@tonic-gate * It is supposed that string points to an array with
650Sstevel@tonic-gate * a minimum length of len. len must be strlen + 1.
660Sstevel@tonic-gate * Checks for printable characters are already done in library.
670Sstevel@tonic-gate */
680Sstevel@tonic-gate static int
sysevent_isstrend(char * string,size_t len)690Sstevel@tonic-gate sysevent_isstrend(char *string, size_t len)
700Sstevel@tonic-gate {
710Sstevel@tonic-gate /* Return 0 if string has length of zero */
720Sstevel@tonic-gate if (len > 0) {
730Sstevel@tonic-gate return (string[len - 1] == '\0' ? 1 : 0);
740Sstevel@tonic-gate } else {
750Sstevel@tonic-gate return (0);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate }
780Sstevel@tonic-gate
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate * Following sysevent_minor_* routines map
810Sstevel@tonic-gate * a binding handle (evchan_t *) to a minor number
820Sstevel@tonic-gate * Has to be called w/ locks held.
830Sstevel@tonic-gate */
840Sstevel@tonic-gate static ulong_t *
sysevent_minor_alloc(void)850Sstevel@tonic-gate sysevent_minor_alloc(void)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate ulong_t *bhst = sysevent_minor_bitmap;
880Sstevel@tonic-gate
890Sstevel@tonic-gate /* Increase bitmap by one BT_NBIPUL */
900Sstevel@tonic-gate if (sysevent_minor_bits + BT_NBIPUL > SYSEVENT_MINOR_MAX) {
910Sstevel@tonic-gate return ((ulong_t *)NULL);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate sysevent_minor_bitmap = kmem_zalloc(
940Sstevel@tonic-gate BT_SIZEOFMAP(sysevent_minor_bits + BT_NBIPUL), KM_SLEEP);
950Sstevel@tonic-gate bcopy(bhst, sysevent_minor_bitmap, BT_SIZEOFMAP(sysevent_minor_bits));
960Sstevel@tonic-gate if (bhst != &sysevent_bitmap_initial)
970Sstevel@tonic-gate kmem_free(bhst, BT_SIZEOFMAP(sysevent_minor_bits));
980Sstevel@tonic-gate sysevent_minor_bits += BT_NBIPUL;
990Sstevel@tonic-gate
1000Sstevel@tonic-gate return (sysevent_minor_bitmap);
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate static void
sysevent_minor_free(ulong_t * bitmap)1040Sstevel@tonic-gate sysevent_minor_free(ulong_t *bitmap)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate if (bitmap != &sysevent_bitmap_initial)
1070Sstevel@tonic-gate kmem_free(bitmap, BT_SIZEOFMAP(sysevent_minor_bits));
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate static index_t
sysevent_minor_get(void)1110Sstevel@tonic-gate sysevent_minor_get(void)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate index_t idx;
1140Sstevel@tonic-gate ulong_t *bhst;
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate /* Search for an available index */
1170Sstevel@tonic-gate mutex_enter(&sysevent_minor_mutex);
1180Sstevel@tonic-gate if ((idx = bt_availbit(sysevent_minor_bitmap,
1190Sstevel@tonic-gate sysevent_minor_bits)) == -1) {
1200Sstevel@tonic-gate /* All busy - allocate additional binding handle bitmap space */
1210Sstevel@tonic-gate if ((bhst = sysevent_minor_alloc()) == NULL) {
1220Sstevel@tonic-gate /* Reached our maximum of id's == SHRT_MAX */
1230Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex);
1240Sstevel@tonic-gate return (0);
1250Sstevel@tonic-gate } else {
1260Sstevel@tonic-gate sysevent_minor_bitmap = bhst;
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate idx = bt_availbit(sysevent_minor_bitmap, sysevent_minor_bits);
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate BT_SET(sysevent_minor_bitmap, idx);
1310Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex);
1320Sstevel@tonic-gate return (idx);
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate static void
sysevent_minor_rele(index_t idx)1360Sstevel@tonic-gate sysevent_minor_rele(index_t idx)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate mutex_enter(&sysevent_minor_mutex);
1390Sstevel@tonic-gate ASSERT(BT_TEST(sysevent_minor_bitmap, idx) == 1);
1400Sstevel@tonic-gate BT_CLEAR(sysevent_minor_bitmap, idx);
1410Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex);
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate static void
sysevent_minor_init(void)1450Sstevel@tonic-gate sysevent_minor_init(void)
1460Sstevel@tonic-gate {
1470Sstevel@tonic-gate mutex_init(&sysevent_minor_mutex, NULL, MUTEX_DEFAULT, NULL);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate /* ARGSUSED */
1510Sstevel@tonic-gate static int
sysevent_publish(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)1520Sstevel@tonic-gate sysevent_publish(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
1530Sstevel@tonic-gate {
1540Sstevel@tonic-gate int km_flags;
1550Sstevel@tonic-gate sev_publish_args_t uargs;
1560Sstevel@tonic-gate sysevent_impl_t *ev;
1570Sstevel@tonic-gate evchan_ctl_t *ctl;
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
1600Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL)
1610Sstevel@tonic-gate return (ENXIO);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_publish_args_t)) != 0)
1640Sstevel@tonic-gate return (EFAULT);
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate /*
1670Sstevel@tonic-gate * This limits the size of an event
1680Sstevel@tonic-gate */
1690Sstevel@tonic-gate if (uargs.ev.len > MAX_EV_SIZE_LEN)
1700Sstevel@tonic-gate return (EOVERFLOW);
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate * Check for valid uargs.flags
1740Sstevel@tonic-gate */
1750Sstevel@tonic-gate if (uargs.flags & ~(EVCH_NOSLEEP | EVCH_SLEEP | EVCH_QWAIT))
1760Sstevel@tonic-gate return (EINVAL);
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate * Check that at least one of EVCH_NOSLEEP or EVCH_SLEEP is
1800Sstevel@tonic-gate * specified
1810Sstevel@tonic-gate */
1820Sstevel@tonic-gate km_flags = uargs.flags & (EVCH_NOSLEEP | EVCH_SLEEP);
1830Sstevel@tonic-gate if (km_flags != EVCH_NOSLEEP && km_flags != EVCH_SLEEP)
1840Sstevel@tonic-gate return (EINVAL);
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate ev = evch_usrallocev(uargs.ev.len, uargs.flags);
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.ev.name, ev, uargs.ev.len) != 0) {
1890Sstevel@tonic-gate evch_usrfreeev(ev);
1900Sstevel@tonic-gate return (EFAULT);
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate return (evch_usrpostevent(ctl->chp, ev, uargs.flags));
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate /* Event will be freed internally */
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate /*
1990Sstevel@tonic-gate * sysevent_chan_open - used to open a channel in the GPEC channel layer
2000Sstevel@tonic-gate */
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /* ARGSUSED */
2030Sstevel@tonic-gate static int
sysevent_chan_open(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)2040Sstevel@tonic-gate sysevent_chan_open(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
2050Sstevel@tonic-gate {
2060Sstevel@tonic-gate sev_bind_args_t uargs;
2070Sstevel@tonic-gate evchan_ctl_t *ctl;
2080Sstevel@tonic-gate char *chan_name;
2090Sstevel@tonic-gate int ec;
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
2120Sstevel@tonic-gate if (ctl == NULL) {
2130Sstevel@tonic-gate return (ENXIO);
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_bind_args_t)) != 0)
2170Sstevel@tonic-gate return (EFAULT);
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate if (uargs.chan_name.len > MAX_CHNAME_LEN)
2200Sstevel@tonic-gate return (EINVAL);
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate chan_name = kmem_alloc(uargs.chan_name.len, KM_SLEEP);
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.chan_name.name, chan_name,
2250Sstevel@tonic-gate uargs.chan_name.len) != 0) {
2260Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len);
2270Sstevel@tonic-gate return (EFAULT);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate if (!sysevent_isstrend(chan_name, uargs.chan_name.len)) {
2310Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len);
2320Sstevel@tonic-gate return (EINVAL);
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate /*
2360Sstevel@tonic-gate * Check of uargs.flags and uargs.perms just to avoid DoS attacks.
2370Sstevel@tonic-gate * libsysevent does this carefully
2380Sstevel@tonic-gate */
2390Sstevel@tonic-gate ctl->chp = evch_usrchanopen((const char *)chan_name,
2400Sstevel@tonic-gate uargs.flags & EVCH_B_FLAGS, &ec);
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len);
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate if (ec != 0) {
2450Sstevel@tonic-gate return (ec);
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate
2480Sstevel@tonic-gate return (0);
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate /* ARGSUSED */
2520Sstevel@tonic-gate static int
sysevent_chan_control(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)2530Sstevel@tonic-gate sysevent_chan_control(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
2540Sstevel@tonic-gate {
2550Sstevel@tonic-gate sev_control_args_t uargs;
2560Sstevel@tonic-gate evchan_ctl_t *ctl;
2570Sstevel@tonic-gate int rc;
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
2600Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL)
2610Sstevel@tonic-gate return (ENXIO);
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_control_args_t)) != 0)
2640Sstevel@tonic-gate return (EFAULT);
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate switch (uargs.cmd) {
2670Sstevel@tonic-gate case EVCH_GET_CHAN_LEN:
2680Sstevel@tonic-gate case EVCH_GET_CHAN_LEN_MAX:
2690Sstevel@tonic-gate rc = evch_usrcontrol_get(ctl->chp, uargs.cmd, &uargs.value);
2700Sstevel@tonic-gate if (rc == 0) {
2710Sstevel@tonic-gate if (copyout((void *)&uargs, arg,
2720Sstevel@tonic-gate sizeof (sev_control_args_t)) != 0) {
2730Sstevel@tonic-gate rc = EFAULT;
2740Sstevel@tonic-gate }
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate break;
2770Sstevel@tonic-gate case EVCH_SET_CHAN_LEN:
2780Sstevel@tonic-gate rc = evch_usrcontrol_set(ctl->chp, uargs.cmd, uargs.value);
2790Sstevel@tonic-gate break;
2800Sstevel@tonic-gate default:
2810Sstevel@tonic-gate rc = EINVAL;
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate return (rc);
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate /* ARGSUSED */
2870Sstevel@tonic-gate static int
sysevent_subscribe(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)2880Sstevel@tonic-gate sysevent_subscribe(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
2890Sstevel@tonic-gate {
2900Sstevel@tonic-gate sev_subscribe_args_t uargs;
2910Sstevel@tonic-gate char *sid;
2920Sstevel@tonic-gate char *class_info = NULL;
2930Sstevel@tonic-gate evchan_ctl_t *ctl;
2940Sstevel@tonic-gate int rc;
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
2970Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL)
2980Sstevel@tonic-gate return (ENXIO);
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_subscribe_args_t)) != 0)
3010Sstevel@tonic-gate return (EFAULT);
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate if (uargs.sid.len > MAX_SUBID_LEN ||
3040Sstevel@tonic-gate uargs.class_info.len > MAX_CLASS_LEN)
3050Sstevel@tonic-gate return (EINVAL);
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate sid = kmem_alloc(uargs.sid.len, KM_SLEEP);
3080Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.sid.name,
3090Sstevel@tonic-gate sid, uargs.sid.len) != 0) {
3100Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3110Sstevel@tonic-gate return (EFAULT);
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate if (!sysevent_isstrend(sid, uargs.sid.len)) {
3140Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3150Sstevel@tonic-gate return (EINVAL);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate /* If class string empty then class EC_ALL is assumed */
3190Sstevel@tonic-gate if (uargs.class_info.len != 0) {
3200Sstevel@tonic-gate class_info = kmem_alloc(uargs.class_info.len, KM_SLEEP);
3210Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.class_info.name, class_info,
3220Sstevel@tonic-gate uargs.class_info.len) != 0) {
3230Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len);
3240Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3250Sstevel@tonic-gate return (EFAULT);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate if (!sysevent_isstrend(class_info, uargs.class_info.len)) {
3280Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len);
3290Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3300Sstevel@tonic-gate return (EINVAL);
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate /*
3350Sstevel@tonic-gate * Check of uargs.flags just to avoid DoS attacks
3360Sstevel@tonic-gate * libsysevent does this carefully.
3370Sstevel@tonic-gate */
3380Sstevel@tonic-gate rc = evch_usrsubscribe(ctl->chp, sid, class_info,
3390Sstevel@tonic-gate (int)uargs.door_desc, uargs.flags);
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len);
3420Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate return (rc);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate
3470Sstevel@tonic-gate /* ARGSUSED */
3480Sstevel@tonic-gate static int
sysevent_unsubscribe(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)3490Sstevel@tonic-gate sysevent_unsubscribe(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
3500Sstevel@tonic-gate {
3510Sstevel@tonic-gate sev_unsubscribe_args_t uargs;
3520Sstevel@tonic-gate char *sid;
3530Sstevel@tonic-gate evchan_ctl_t *ctl;
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_unsubscribe_args_t)) != 0)
3560Sstevel@tonic-gate return (EFAULT);
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
3590Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL)
3600Sstevel@tonic-gate return (ENXIO);
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate if (uargs.sid.len > MAX_SUBID_LEN)
3630Sstevel@tonic-gate return (EINVAL);
3640Sstevel@tonic-gate
3650Sstevel@tonic-gate /* Unsubscribe for all */
3660Sstevel@tonic-gate if (uargs.sid.len == 0) {
3670Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, NULL, 0);
3680Sstevel@tonic-gate return (0);
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate sid = kmem_alloc(uargs.sid.len, KM_SLEEP);
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.sid.name,
3740Sstevel@tonic-gate sid, uargs.sid.len) != 0) {
3750Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3760Sstevel@tonic-gate return (EFAULT);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, sid, 0);
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate kmem_free(sid, uargs.sid.len);
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate return (0);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate /* ARGSUSED */
3870Sstevel@tonic-gate static int
sysevent_channames(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)3880Sstevel@tonic-gate sysevent_channames(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
3890Sstevel@tonic-gate {
3900Sstevel@tonic-gate sev_chandata_args_t uargs;
3910Sstevel@tonic-gate char *buf;
3920Sstevel@tonic-gate int len;
3930Sstevel@tonic-gate int rc = 0;
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_chandata_args_t)) != 0)
3960Sstevel@tonic-gate return (EFAULT);
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate if (uargs.out_data.len == 0 || uargs.out_data.len > EVCH_MAX_DATA_SIZE)
3990Sstevel@tonic-gate return (EINVAL);
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate buf = kmem_alloc(uargs.out_data.len, KM_SLEEP);
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate if ((len = evch_usrgetchnames(buf, uargs.out_data.len)) == -1) {
4040Sstevel@tonic-gate rc = EOVERFLOW;
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate if (rc == 0) {
4080Sstevel@tonic-gate ASSERT(len <= uargs.out_data.len);
4090Sstevel@tonic-gate if (copyout(buf,
4100Sstevel@tonic-gate (void *)(uintptr_t)uargs.out_data.name, len) != 0) {
4110Sstevel@tonic-gate rc = EFAULT;
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate kmem_free(buf, uargs.out_data.len);
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate return (rc);
4180Sstevel@tonic-gate }
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate /* ARGSUSED */
4210Sstevel@tonic-gate static int
sysevent_chandata(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)4220Sstevel@tonic-gate sysevent_chandata(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
4230Sstevel@tonic-gate {
4240Sstevel@tonic-gate sev_chandata_args_t uargs;
4250Sstevel@tonic-gate char *channel;
4260Sstevel@tonic-gate char *buf;
4270Sstevel@tonic-gate int len;
4280Sstevel@tonic-gate int rc = 0;
4290Sstevel@tonic-gate
4300Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_chandata_args_t)) != 0)
4310Sstevel@tonic-gate return (EFAULT);
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate if (uargs.in_data.len > MAX_CHNAME_LEN ||
4340Sstevel@tonic-gate uargs.out_data.len > EVCH_MAX_DATA_SIZE)
4350Sstevel@tonic-gate return (EINVAL);
4360Sstevel@tonic-gate
4370Sstevel@tonic-gate channel = kmem_alloc(uargs.in_data.len, KM_SLEEP);
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.in_data.name, channel,
4400Sstevel@tonic-gate uargs.in_data.len) != 0) {
4410Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len);
4420Sstevel@tonic-gate return (EFAULT);
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate if (!sysevent_isstrend(channel, uargs.in_data.len)) {
4460Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len);
4470Sstevel@tonic-gate return (EINVAL);
4480Sstevel@tonic-gate }
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate buf = kmem_alloc(uargs.out_data.len, KM_SLEEP);
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate len = evch_usrgetchdata(channel, buf, uargs.out_data.len);
4530Sstevel@tonic-gate if (len == 0) {
4540Sstevel@tonic-gate rc = EOVERFLOW;
4550Sstevel@tonic-gate } else if (len == -1) {
4560Sstevel@tonic-gate rc = ENOENT;
4570Sstevel@tonic-gate }
4580Sstevel@tonic-gate
4590Sstevel@tonic-gate if (rc == 0) {
4600Sstevel@tonic-gate ASSERT(len <= uargs.out_data.len);
4610Sstevel@tonic-gate if (copyout(buf,
4620Sstevel@tonic-gate (void *)(uintptr_t)uargs.out_data.name, len) != 0) {
4630Sstevel@tonic-gate rc = EFAULT;
4640Sstevel@tonic-gate }
4650Sstevel@tonic-gate }
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate kmem_free(buf, uargs.out_data.len);
4680Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len);
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate return (rc);
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate
473*12967Sgavin.maltby@oracle.com /* ARGSUSED */
474*12967Sgavin.maltby@oracle.com static int
sysevent_setpropnvl(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)475*12967Sgavin.maltby@oracle.com sysevent_setpropnvl(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
476*12967Sgavin.maltby@oracle.com {
477*12967Sgavin.maltby@oracle.com sev_propnvl_args_t uargs;
478*12967Sgavin.maltby@oracle.com nvlist_t *nvl = NULL;
479*12967Sgavin.maltby@oracle.com evchan_ctl_t *ctl;
480*12967Sgavin.maltby@oracle.com size_t bufsz;
481*12967Sgavin.maltby@oracle.com char *buf;
482*12967Sgavin.maltby@oracle.com
483*12967Sgavin.maltby@oracle.com ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
484*12967Sgavin.maltby@oracle.com if (ctl == NULL || ctl->chp == NULL)
485*12967Sgavin.maltby@oracle.com return (ENXIO);
486*12967Sgavin.maltby@oracle.com
487*12967Sgavin.maltby@oracle.com if (copyin(arg, &uargs, sizeof (uargs)) != 0)
488*12967Sgavin.maltby@oracle.com return (EFAULT);
489*12967Sgavin.maltby@oracle.com
490*12967Sgavin.maltby@oracle.com if (uargs.packednvl.name != 0) {
491*12967Sgavin.maltby@oracle.com bufsz = uargs.packednvl.len;
492*12967Sgavin.maltby@oracle.com
493*12967Sgavin.maltby@oracle.com if (bufsz == 0)
494*12967Sgavin.maltby@oracle.com return (EINVAL);
495*12967Sgavin.maltby@oracle.com
496*12967Sgavin.maltby@oracle.com if (bufsz > EVCH_MAX_DATA_SIZE)
497*12967Sgavin.maltby@oracle.com return (EOVERFLOW);
498*12967Sgavin.maltby@oracle.com
499*12967Sgavin.maltby@oracle.com buf = kmem_alloc(bufsz, KM_SLEEP);
500*12967Sgavin.maltby@oracle.com
501*12967Sgavin.maltby@oracle.com if (copyin((void *)(uintptr_t)uargs.packednvl.name, buf,
502*12967Sgavin.maltby@oracle.com bufsz) != 0 ||
503*12967Sgavin.maltby@oracle.com nvlist_unpack(buf, bufsz, &nvl, KM_SLEEP) != 0) {
504*12967Sgavin.maltby@oracle.com kmem_free(buf, bufsz);
505*12967Sgavin.maltby@oracle.com return (EFAULT);
506*12967Sgavin.maltby@oracle.com }
507*12967Sgavin.maltby@oracle.com
508*12967Sgavin.maltby@oracle.com kmem_free(buf, bufsz);
509*12967Sgavin.maltby@oracle.com
510*12967Sgavin.maltby@oracle.com if (nvl == NULL)
511*12967Sgavin.maltby@oracle.com return (EINVAL);
512*12967Sgavin.maltby@oracle.com }
513*12967Sgavin.maltby@oracle.com
514*12967Sgavin.maltby@oracle.com evch_usrsetpropnvl(ctl->chp, nvl);
515*12967Sgavin.maltby@oracle.com return (0);
516*12967Sgavin.maltby@oracle.com }
517*12967Sgavin.maltby@oracle.com
518*12967Sgavin.maltby@oracle.com /* ARGSUSED */
519*12967Sgavin.maltby@oracle.com static int
sysevent_getpropnvl(dev_t dev,int * rvalp,void * arg,int flag,cred_t * cr)520*12967Sgavin.maltby@oracle.com sysevent_getpropnvl(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr)
521*12967Sgavin.maltby@oracle.com {
522*12967Sgavin.maltby@oracle.com sev_propnvl_args_t uargs;
523*12967Sgavin.maltby@oracle.com size_t reqsz, avlsz;
524*12967Sgavin.maltby@oracle.com evchan_ctl_t *ctl;
525*12967Sgavin.maltby@oracle.com nvlist_t *nvl;
526*12967Sgavin.maltby@oracle.com int64_t gen;
527*12967Sgavin.maltby@oracle.com int rc;
528*12967Sgavin.maltby@oracle.com
529*12967Sgavin.maltby@oracle.com ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev));
530*12967Sgavin.maltby@oracle.com
531*12967Sgavin.maltby@oracle.com if (ctl == NULL || ctl->chp == NULL)
532*12967Sgavin.maltby@oracle.com return (ENXIO);
533*12967Sgavin.maltby@oracle.com
534*12967Sgavin.maltby@oracle.com if (copyin(arg, &uargs, sizeof (uargs)) != 0)
535*12967Sgavin.maltby@oracle.com return (EFAULT);
536*12967Sgavin.maltby@oracle.com
537*12967Sgavin.maltby@oracle.com if ((rc = evch_usrgetpropnvl(ctl->chp, &nvl, &gen)) != 0)
538*12967Sgavin.maltby@oracle.com return (rc);
539*12967Sgavin.maltby@oracle.com
540*12967Sgavin.maltby@oracle.com if (nvl != NULL) {
541*12967Sgavin.maltby@oracle.com avlsz = uargs.packednvl.len;
542*12967Sgavin.maltby@oracle.com
543*12967Sgavin.maltby@oracle.com if (nvlist_size(nvl, &reqsz, NV_ENCODE_NATIVE) != 0) {
544*12967Sgavin.maltby@oracle.com nvlist_free(nvl);
545*12967Sgavin.maltby@oracle.com return (EINVAL);
546*12967Sgavin.maltby@oracle.com }
547*12967Sgavin.maltby@oracle.com
548*12967Sgavin.maltby@oracle.com if (reqsz > EVCH_MAX_DATA_SIZE) {
549*12967Sgavin.maltby@oracle.com nvlist_free(nvl);
550*12967Sgavin.maltby@oracle.com return (E2BIG);
551*12967Sgavin.maltby@oracle.com }
552*12967Sgavin.maltby@oracle.com
553*12967Sgavin.maltby@oracle.com if (reqsz <= avlsz) {
554*12967Sgavin.maltby@oracle.com char *buf = kmem_alloc(reqsz, KM_SLEEP);
555*12967Sgavin.maltby@oracle.com
556*12967Sgavin.maltby@oracle.com if (nvlist_pack(nvl, &buf, &reqsz,
557*12967Sgavin.maltby@oracle.com NV_ENCODE_NATIVE, 0) != 0 || copyout(buf,
558*12967Sgavin.maltby@oracle.com (void *)(uintptr_t)uargs.packednvl.name,
559*12967Sgavin.maltby@oracle.com reqsz) != 0) {
560*12967Sgavin.maltby@oracle.com kmem_free(buf, reqsz);
561*12967Sgavin.maltby@oracle.com nvlist_free(nvl);
562*12967Sgavin.maltby@oracle.com return (EFAULT);
563*12967Sgavin.maltby@oracle.com }
564*12967Sgavin.maltby@oracle.com kmem_free(buf, reqsz);
565*12967Sgavin.maltby@oracle.com rc = 0;
566*12967Sgavin.maltby@oracle.com } else {
567*12967Sgavin.maltby@oracle.com rc = EOVERFLOW;
568*12967Sgavin.maltby@oracle.com }
569*12967Sgavin.maltby@oracle.com uargs.packednvl.len = (uint32_t)reqsz;
570*12967Sgavin.maltby@oracle.com nvlist_free(nvl);
571*12967Sgavin.maltby@oracle.com } else {
572*12967Sgavin.maltby@oracle.com uargs.packednvl.len = 0;
573*12967Sgavin.maltby@oracle.com rc = 0;
574*12967Sgavin.maltby@oracle.com }
575*12967Sgavin.maltby@oracle.com
576*12967Sgavin.maltby@oracle.com uargs.generation = gen;
577*12967Sgavin.maltby@oracle.com if (copyout((void *)&uargs, arg, sizeof (uargs)) != 0)
578*12967Sgavin.maltby@oracle.com rc = EFAULT;
579*12967Sgavin.maltby@oracle.com
580*12967Sgavin.maltby@oracle.com return (rc);
581*12967Sgavin.maltby@oracle.com }
582*12967Sgavin.maltby@oracle.com
5830Sstevel@tonic-gate /*ARGSUSED*/
5840Sstevel@tonic-gate static int
sysevent_ioctl(dev_t dev,int cmd,intptr_t arg,int flag,cred_t * cr,int * rvalp)5850Sstevel@tonic-gate sysevent_ioctl(dev_t dev, int cmd, intptr_t arg,
5860Sstevel@tonic-gate int flag, cred_t *cr, int *rvalp)
5870Sstevel@tonic-gate {
5880Sstevel@tonic-gate int rc;
5890Sstevel@tonic-gate
5900Sstevel@tonic-gate switch (cmd) {
5910Sstevel@tonic-gate case SEV_PUBLISH:
5920Sstevel@tonic-gate rc = sysevent_publish(dev, rvalp, (void *)arg, flag, cr);
5930Sstevel@tonic-gate break;
5940Sstevel@tonic-gate case SEV_CHAN_OPEN:
5950Sstevel@tonic-gate rc = sysevent_chan_open(dev, rvalp, (void *)arg, flag, cr);
5960Sstevel@tonic-gate break;
5970Sstevel@tonic-gate case SEV_CHAN_CONTROL:
5980Sstevel@tonic-gate rc = sysevent_chan_control(dev, rvalp, (void *)arg, flag, cr);
5990Sstevel@tonic-gate break;
6000Sstevel@tonic-gate case SEV_SUBSCRIBE:
6010Sstevel@tonic-gate rc = sysevent_subscribe(dev, rvalp, (void *)arg, flag, cr);
6020Sstevel@tonic-gate break;
6030Sstevel@tonic-gate case SEV_UNSUBSCRIBE:
6040Sstevel@tonic-gate rc = sysevent_unsubscribe(dev, rvalp, (void *)arg, flag, cr);
6050Sstevel@tonic-gate break;
6060Sstevel@tonic-gate case SEV_CHANNAMES:
6070Sstevel@tonic-gate rc = sysevent_channames(dev, rvalp, (void *)arg, flag, cr);
6080Sstevel@tonic-gate break;
6090Sstevel@tonic-gate case SEV_CHANDATA:
6100Sstevel@tonic-gate rc = sysevent_chandata(dev, rvalp, (void *)arg, flag, cr);
6110Sstevel@tonic-gate break;
612*12967Sgavin.maltby@oracle.com case SEV_SETPROPNVL:
613*12967Sgavin.maltby@oracle.com rc = sysevent_setpropnvl(dev, rvalp, (void *)arg, flag, cr);
614*12967Sgavin.maltby@oracle.com break;
615*12967Sgavin.maltby@oracle.com case SEV_GETPROPNVL:
616*12967Sgavin.maltby@oracle.com rc = sysevent_getpropnvl(dev, rvalp, (void *)arg, flag, cr);
617*12967Sgavin.maltby@oracle.com break;
6180Sstevel@tonic-gate default:
6190Sstevel@tonic-gate rc = EINVAL;
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate
6220Sstevel@tonic-gate return (rc);
6230Sstevel@tonic-gate }
6240Sstevel@tonic-gate
6250Sstevel@tonic-gate /*ARGSUSED*/
6260Sstevel@tonic-gate static int
sysevent_open(dev_t * devp,int flag,int otyp,cred_t * cr)6270Sstevel@tonic-gate sysevent_open(dev_t *devp, int flag, int otyp, cred_t *cr)
6280Sstevel@tonic-gate {
6290Sstevel@tonic-gate int minor;
6300Sstevel@tonic-gate
6310Sstevel@tonic-gate if (otyp != OTYP_CHR)
6320Sstevel@tonic-gate return (EINVAL);
6330Sstevel@tonic-gate
6340Sstevel@tonic-gate if (getminor(*devp) != 0)
6350Sstevel@tonic-gate return (ENXIO);
6360Sstevel@tonic-gate
6370Sstevel@tonic-gate minor = sysevent_minor_get();
6380Sstevel@tonic-gate if (minor == 0)
6390Sstevel@tonic-gate /* All minors are busy */
6400Sstevel@tonic-gate return (EBUSY);
6410Sstevel@tonic-gate
6420Sstevel@tonic-gate if (ddi_soft_state_zalloc(evchan_ctlp, minor)
6430Sstevel@tonic-gate != DDI_SUCCESS) {
6440Sstevel@tonic-gate sysevent_minor_rele(minor);
6450Sstevel@tonic-gate return (ENOMEM);
6460Sstevel@tonic-gate }
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate *devp = makedevice(getmajor(*devp), minor);
6490Sstevel@tonic-gate
6500Sstevel@tonic-gate return (0);
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate /*ARGSUSED*/
6540Sstevel@tonic-gate static int
sysevent_close(dev_t dev,int flag,int otyp,cred_t * cr)6550Sstevel@tonic-gate sysevent_close(dev_t dev, int flag, int otyp, cred_t *cr)
6560Sstevel@tonic-gate {
6570Sstevel@tonic-gate int minor = (int)getminor(dev);
6580Sstevel@tonic-gate evchan_ctl_t *ctl;
6590Sstevel@tonic-gate
6600Sstevel@tonic-gate if (otyp != OTYP_CHR)
6610Sstevel@tonic-gate return (EINVAL);
6620Sstevel@tonic-gate
6630Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, minor);
6640Sstevel@tonic-gate if (ctl == NULL) {
6650Sstevel@tonic-gate return (ENXIO);
6660Sstevel@tonic-gate }
6670Sstevel@tonic-gate
6680Sstevel@tonic-gate if (ctl->chp) {
6690Sstevel@tonic-gate /* Release all non-persistant subscriptions */
6700Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, NULL, EVCH_SUB_KEEP);
6710Sstevel@tonic-gate evch_usrchanclose(ctl->chp);
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate
6740Sstevel@tonic-gate ddi_soft_state_free(evchan_ctlp, minor);
6750Sstevel@tonic-gate sysevent_minor_rele(minor);
6760Sstevel@tonic-gate
6770Sstevel@tonic-gate return (0);
6780Sstevel@tonic-gate }
6790Sstevel@tonic-gate
6800Sstevel@tonic-gate /* ARGSUSED */
6810Sstevel@tonic-gate static int
sysevent_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)6820Sstevel@tonic-gate sysevent_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
6830Sstevel@tonic-gate void *arg, void **result)
6840Sstevel@tonic-gate {
6850Sstevel@tonic-gate switch (infocmd) {
6860Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
6870Sstevel@tonic-gate *result = sysevent_devi;
6880Sstevel@tonic-gate return (DDI_SUCCESS);
6890Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
6900Sstevel@tonic-gate *result = 0;
6910Sstevel@tonic-gate return (DDI_SUCCESS);
6920Sstevel@tonic-gate }
6930Sstevel@tonic-gate return (DDI_FAILURE);
6940Sstevel@tonic-gate }
6950Sstevel@tonic-gate
6960Sstevel@tonic-gate /* ARGSUSED */
6970Sstevel@tonic-gate static int
sysevent_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)6980Sstevel@tonic-gate sysevent_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
6990Sstevel@tonic-gate {
7000Sstevel@tonic-gate
7010Sstevel@tonic-gate if (cmd != DDI_ATTACH) {
7020Sstevel@tonic-gate return (DDI_FAILURE);
7030Sstevel@tonic-gate }
7040Sstevel@tonic-gate
7050Sstevel@tonic-gate if (ddi_create_minor_node(devi, "sysevent", S_IFCHR,
7060Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
7070Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
7080Sstevel@tonic-gate return (DDI_FAILURE);
7090Sstevel@tonic-gate }
7100Sstevel@tonic-gate sysevent_devi = devi;
7110Sstevel@tonic-gate
7120Sstevel@tonic-gate sysevent_minor_init();
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate return (DDI_SUCCESS);
7150Sstevel@tonic-gate }
7160Sstevel@tonic-gate
7170Sstevel@tonic-gate static int
sysevent_detach(dev_info_t * devi,ddi_detach_cmd_t cmd)7180Sstevel@tonic-gate sysevent_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
7190Sstevel@tonic-gate {
7200Sstevel@tonic-gate if (cmd != DDI_DETACH) {
7210Sstevel@tonic-gate return (DDI_FAILURE);
7220Sstevel@tonic-gate }
7230Sstevel@tonic-gate
7240Sstevel@tonic-gate sysevent_minor_free(sysevent_minor_bitmap);
7250Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
7260Sstevel@tonic-gate return (DDI_SUCCESS);
7270Sstevel@tonic-gate }
7280Sstevel@tonic-gate
7290Sstevel@tonic-gate static struct cb_ops sysevent_cb_ops = {
7300Sstevel@tonic-gate sysevent_open, /* open */
7310Sstevel@tonic-gate sysevent_close, /* close */
7320Sstevel@tonic-gate nodev, /* strategy */
7330Sstevel@tonic-gate nodev, /* print */
7340Sstevel@tonic-gate nodev, /* dump */
7350Sstevel@tonic-gate nodev, /* read */
7360Sstevel@tonic-gate nodev, /* write */
7370Sstevel@tonic-gate sysevent_ioctl, /* ioctl */
7380Sstevel@tonic-gate nodev, /* devmap */
7390Sstevel@tonic-gate nodev, /* mmap */
7400Sstevel@tonic-gate nodev, /* segmap */
7410Sstevel@tonic-gate nochpoll, /* poll */
7420Sstevel@tonic-gate ddi_prop_op, /* prop_op */
7430Sstevel@tonic-gate 0, /* streamtab */
7440Sstevel@tonic-gate D_NEW|D_MP, /* flag */
7450Sstevel@tonic-gate NULL, /* aread */
7460Sstevel@tonic-gate NULL /* awrite */
7470Sstevel@tonic-gate };
7480Sstevel@tonic-gate
7490Sstevel@tonic-gate static struct dev_ops sysevent_ops = {
7500Sstevel@tonic-gate DEVO_REV, /* devo_rev */
7510Sstevel@tonic-gate 0, /* refcnt */
7520Sstevel@tonic-gate sysevent_info, /* info */
7530Sstevel@tonic-gate nulldev, /* identify */
7540Sstevel@tonic-gate nulldev, /* probe */
7550Sstevel@tonic-gate sysevent_attach, /* attach */
7560Sstevel@tonic-gate sysevent_detach, /* detach */
7570Sstevel@tonic-gate nodev, /* reset */
7580Sstevel@tonic-gate &sysevent_cb_ops, /* driver operations */
7590Sstevel@tonic-gate (struct bus_ops *)0, /* no bus operations */
7607656SSherry.Moore@Sun.COM nulldev, /* power */
7617656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */
7620Sstevel@tonic-gate };
7630Sstevel@tonic-gate
7640Sstevel@tonic-gate static struct modldrv modldrv = {
7657656SSherry.Moore@Sun.COM &mod_driverops, "sysevent driver", &sysevent_ops
7660Sstevel@tonic-gate };
7670Sstevel@tonic-gate
7680Sstevel@tonic-gate static struct modlinkage modlinkage = {
7690Sstevel@tonic-gate MODREV_1, &modldrv, NULL
7700Sstevel@tonic-gate };
7710Sstevel@tonic-gate
7720Sstevel@tonic-gate int
_init(void)7730Sstevel@tonic-gate _init(void)
7740Sstevel@tonic-gate {
7750Sstevel@tonic-gate int s;
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate s = ddi_soft_state_init(&evchan_ctlp, sizeof (evchan_ctl_t), 1);
7780Sstevel@tonic-gate if (s != 0)
7790Sstevel@tonic-gate return (s);
7800Sstevel@tonic-gate
7810Sstevel@tonic-gate if ((s = mod_install(&modlinkage)) != 0)
7820Sstevel@tonic-gate ddi_soft_state_fini(&evchan_ctlp);
7830Sstevel@tonic-gate return (s);
7840Sstevel@tonic-gate }
7850Sstevel@tonic-gate
7860Sstevel@tonic-gate int
_fini(void)7870Sstevel@tonic-gate _fini(void)
7880Sstevel@tonic-gate {
7890Sstevel@tonic-gate int s;
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate if ((s = mod_remove(&modlinkage)) != 0)
7920Sstevel@tonic-gate return (s);
7930Sstevel@tonic-gate
7940Sstevel@tonic-gate ddi_soft_state_fini(&evchan_ctlp);
7950Sstevel@tonic-gate return (s);
7960Sstevel@tonic-gate }
7970Sstevel@tonic-gate
7980Sstevel@tonic-gate int
_info(struct modinfo * modinfop)7990Sstevel@tonic-gate _info(struct modinfo *modinfop)
8000Sstevel@tonic-gate {
8010Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
8020Sstevel@tonic-gate }
803