1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * Sysevent Driver for GPEC 31*7c478bd9Sstevel@tonic-gate */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/cred.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/file.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/open.h> /* OTYP_CHR definition */ 43*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> /* L_BITSMINOR definition */ 44*7c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/sysevent.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/sysevent_impl.h> 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate static dev_info_t *sysevent_devi; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate /* Definitions for binding handle array */ 51*7c478bd9Sstevel@tonic-gate static ulong_t sysevent_bitmap_initial = 1; /* index 0 indicates error */ 52*7c478bd9Sstevel@tonic-gate static ulong_t *sysevent_minor_bitmap = &sysevent_bitmap_initial; 53*7c478bd9Sstevel@tonic-gate static size_t sysevent_minor_bits = BT_NBIPUL; 54*7c478bd9Sstevel@tonic-gate static kmutex_t sysevent_minor_mutex; 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /* 57*7c478bd9Sstevel@tonic-gate * evchan_ctl acts as a container for the binding handle 58*7c478bd9Sstevel@tonic-gate */ 59*7c478bd9Sstevel@tonic-gate typedef struct evchan_ctl { 60*7c478bd9Sstevel@tonic-gate evchan_t *chp; 61*7c478bd9Sstevel@tonic-gate } evchan_ctl_t; 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate static void *evchan_ctlp; 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate /* 66*7c478bd9Sstevel@tonic-gate * Check if it's a null terminated array - to avoid DoS attack 67*7c478bd9Sstevel@tonic-gate * It is supposed that string points to an array with 68*7c478bd9Sstevel@tonic-gate * a minimum length of len. len must be strlen + 1. 69*7c478bd9Sstevel@tonic-gate * Checks for printable characters are already done in library. 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate static int 72*7c478bd9Sstevel@tonic-gate sysevent_isstrend(char *string, size_t len) 73*7c478bd9Sstevel@tonic-gate { 74*7c478bd9Sstevel@tonic-gate /* Return 0 if string has length of zero */ 75*7c478bd9Sstevel@tonic-gate if (len > 0) { 76*7c478bd9Sstevel@tonic-gate return (string[len - 1] == '\0' ? 1 : 0); 77*7c478bd9Sstevel@tonic-gate } else { 78*7c478bd9Sstevel@tonic-gate return (0); 79*7c478bd9Sstevel@tonic-gate } 80*7c478bd9Sstevel@tonic-gate } 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * Following sysevent_minor_* routines map 84*7c478bd9Sstevel@tonic-gate * a binding handle (evchan_t *) to a minor number 85*7c478bd9Sstevel@tonic-gate * Has to be called w/ locks held. 86*7c478bd9Sstevel@tonic-gate */ 87*7c478bd9Sstevel@tonic-gate static ulong_t * 88*7c478bd9Sstevel@tonic-gate sysevent_minor_alloc(void) 89*7c478bd9Sstevel@tonic-gate { 90*7c478bd9Sstevel@tonic-gate ulong_t *bhst = sysevent_minor_bitmap; 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate /* Increase bitmap by one BT_NBIPUL */ 93*7c478bd9Sstevel@tonic-gate if (sysevent_minor_bits + BT_NBIPUL > SYSEVENT_MINOR_MAX) { 94*7c478bd9Sstevel@tonic-gate return ((ulong_t *)NULL); 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate sysevent_minor_bitmap = kmem_zalloc( 97*7c478bd9Sstevel@tonic-gate BT_SIZEOFMAP(sysevent_minor_bits + BT_NBIPUL), KM_SLEEP); 98*7c478bd9Sstevel@tonic-gate bcopy(bhst, sysevent_minor_bitmap, BT_SIZEOFMAP(sysevent_minor_bits)); 99*7c478bd9Sstevel@tonic-gate if (bhst != &sysevent_bitmap_initial) 100*7c478bd9Sstevel@tonic-gate kmem_free(bhst, BT_SIZEOFMAP(sysevent_minor_bits)); 101*7c478bd9Sstevel@tonic-gate sysevent_minor_bits += BT_NBIPUL; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate return (sysevent_minor_bitmap); 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate static void 107*7c478bd9Sstevel@tonic-gate sysevent_minor_free(ulong_t *bitmap) 108*7c478bd9Sstevel@tonic-gate { 109*7c478bd9Sstevel@tonic-gate if (bitmap != &sysevent_bitmap_initial) 110*7c478bd9Sstevel@tonic-gate kmem_free(bitmap, BT_SIZEOFMAP(sysevent_minor_bits)); 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate static index_t 114*7c478bd9Sstevel@tonic-gate sysevent_minor_get(void) 115*7c478bd9Sstevel@tonic-gate { 116*7c478bd9Sstevel@tonic-gate index_t idx; 117*7c478bd9Sstevel@tonic-gate ulong_t *bhst; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate /* Search for an available index */ 120*7c478bd9Sstevel@tonic-gate mutex_enter(&sysevent_minor_mutex); 121*7c478bd9Sstevel@tonic-gate if ((idx = bt_availbit(sysevent_minor_bitmap, 122*7c478bd9Sstevel@tonic-gate sysevent_minor_bits)) == -1) { 123*7c478bd9Sstevel@tonic-gate /* All busy - allocate additional binding handle bitmap space */ 124*7c478bd9Sstevel@tonic-gate if ((bhst = sysevent_minor_alloc()) == NULL) { 125*7c478bd9Sstevel@tonic-gate /* Reached our maximum of id's == SHRT_MAX */ 126*7c478bd9Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex); 127*7c478bd9Sstevel@tonic-gate return (0); 128*7c478bd9Sstevel@tonic-gate } else { 129*7c478bd9Sstevel@tonic-gate sysevent_minor_bitmap = bhst; 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate idx = bt_availbit(sysevent_minor_bitmap, sysevent_minor_bits); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate BT_SET(sysevent_minor_bitmap, idx); 134*7c478bd9Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex); 135*7c478bd9Sstevel@tonic-gate return (idx); 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate static void 139*7c478bd9Sstevel@tonic-gate sysevent_minor_rele(index_t idx) 140*7c478bd9Sstevel@tonic-gate { 141*7c478bd9Sstevel@tonic-gate mutex_enter(&sysevent_minor_mutex); 142*7c478bd9Sstevel@tonic-gate ASSERT(BT_TEST(sysevent_minor_bitmap, idx) == 1); 143*7c478bd9Sstevel@tonic-gate BT_CLEAR(sysevent_minor_bitmap, idx); 144*7c478bd9Sstevel@tonic-gate mutex_exit(&sysevent_minor_mutex); 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate static void 148*7c478bd9Sstevel@tonic-gate sysevent_minor_init(void) 149*7c478bd9Sstevel@tonic-gate { 150*7c478bd9Sstevel@tonic-gate mutex_init(&sysevent_minor_mutex, NULL, MUTEX_DEFAULT, NULL); 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 154*7c478bd9Sstevel@tonic-gate static int 155*7c478bd9Sstevel@tonic-gate sysevent_publish(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 156*7c478bd9Sstevel@tonic-gate { 157*7c478bd9Sstevel@tonic-gate int km_flags; 158*7c478bd9Sstevel@tonic-gate sev_publish_args_t uargs; 159*7c478bd9Sstevel@tonic-gate sysevent_impl_t *ev; 160*7c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 163*7c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 164*7c478bd9Sstevel@tonic-gate return (ENXIO); 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_publish_args_t)) != 0) 167*7c478bd9Sstevel@tonic-gate return (EFAULT); 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate /* 170*7c478bd9Sstevel@tonic-gate * This limits the size of an event 171*7c478bd9Sstevel@tonic-gate */ 172*7c478bd9Sstevel@tonic-gate if (uargs.ev.len > MAX_EV_SIZE_LEN) 173*7c478bd9Sstevel@tonic-gate return (EOVERFLOW); 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * Check for valid uargs.flags 177*7c478bd9Sstevel@tonic-gate */ 178*7c478bd9Sstevel@tonic-gate if (uargs.flags & ~(EVCH_NOSLEEP | EVCH_SLEEP | EVCH_QWAIT)) 179*7c478bd9Sstevel@tonic-gate return (EINVAL); 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate /* 182*7c478bd9Sstevel@tonic-gate * Check that at least one of EVCH_NOSLEEP or EVCH_SLEEP is 183*7c478bd9Sstevel@tonic-gate * specified 184*7c478bd9Sstevel@tonic-gate */ 185*7c478bd9Sstevel@tonic-gate km_flags = uargs.flags & (EVCH_NOSLEEP | EVCH_SLEEP); 186*7c478bd9Sstevel@tonic-gate if (km_flags != EVCH_NOSLEEP && km_flags != EVCH_SLEEP) 187*7c478bd9Sstevel@tonic-gate return (EINVAL); 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate ev = evch_usrallocev(uargs.ev.len, uargs.flags); 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.ev.name, ev, uargs.ev.len) != 0) { 192*7c478bd9Sstevel@tonic-gate evch_usrfreeev(ev); 193*7c478bd9Sstevel@tonic-gate return (EFAULT); 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate return (evch_usrpostevent(ctl->chp, ev, uargs.flags)); 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate /* Event will be freed internally */ 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate /* 202*7c478bd9Sstevel@tonic-gate * sysevent_chan_open - used to open a channel in the GPEC channel layer 203*7c478bd9Sstevel@tonic-gate */ 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 206*7c478bd9Sstevel@tonic-gate static int 207*7c478bd9Sstevel@tonic-gate sysevent_chan_open(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 208*7c478bd9Sstevel@tonic-gate { 209*7c478bd9Sstevel@tonic-gate sev_bind_args_t uargs; 210*7c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 211*7c478bd9Sstevel@tonic-gate char *chan_name; 212*7c478bd9Sstevel@tonic-gate int ec; 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 215*7c478bd9Sstevel@tonic-gate if (ctl == NULL) { 216*7c478bd9Sstevel@tonic-gate return (ENXIO); 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_bind_args_t)) != 0) 220*7c478bd9Sstevel@tonic-gate return (EFAULT); 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate if (uargs.chan_name.len > MAX_CHNAME_LEN) 223*7c478bd9Sstevel@tonic-gate return (EINVAL); 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate chan_name = kmem_alloc(uargs.chan_name.len, KM_SLEEP); 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.chan_name.name, chan_name, 228*7c478bd9Sstevel@tonic-gate uargs.chan_name.len) != 0) { 229*7c478bd9Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len); 230*7c478bd9Sstevel@tonic-gate return (EFAULT); 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(chan_name, uargs.chan_name.len)) { 234*7c478bd9Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len); 235*7c478bd9Sstevel@tonic-gate return (EINVAL); 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate /* 239*7c478bd9Sstevel@tonic-gate * Check of uargs.flags and uargs.perms just to avoid DoS attacks. 240*7c478bd9Sstevel@tonic-gate * libsysevent does this carefully 241*7c478bd9Sstevel@tonic-gate */ 242*7c478bd9Sstevel@tonic-gate ctl->chp = evch_usrchanopen((const char *)chan_name, 243*7c478bd9Sstevel@tonic-gate uargs.flags & EVCH_B_FLAGS, &ec); 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate kmem_free(chan_name, uargs.chan_name.len); 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate if (ec != 0) { 248*7c478bd9Sstevel@tonic-gate return (ec); 249*7c478bd9Sstevel@tonic-gate } 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate return (0); 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 255*7c478bd9Sstevel@tonic-gate static int 256*7c478bd9Sstevel@tonic-gate sysevent_chan_control(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 257*7c478bd9Sstevel@tonic-gate { 258*7c478bd9Sstevel@tonic-gate sev_control_args_t uargs; 259*7c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 260*7c478bd9Sstevel@tonic-gate int rc; 261*7c478bd9Sstevel@tonic-gate 262*7c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 263*7c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 264*7c478bd9Sstevel@tonic-gate return (ENXIO); 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_control_args_t)) != 0) 267*7c478bd9Sstevel@tonic-gate return (EFAULT); 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate switch (uargs.cmd) { 270*7c478bd9Sstevel@tonic-gate case EVCH_GET_CHAN_LEN: 271*7c478bd9Sstevel@tonic-gate case EVCH_GET_CHAN_LEN_MAX: 272*7c478bd9Sstevel@tonic-gate rc = evch_usrcontrol_get(ctl->chp, uargs.cmd, &uargs.value); 273*7c478bd9Sstevel@tonic-gate if (rc == 0) { 274*7c478bd9Sstevel@tonic-gate if (copyout((void *)&uargs, arg, 275*7c478bd9Sstevel@tonic-gate sizeof (sev_control_args_t)) != 0) { 276*7c478bd9Sstevel@tonic-gate rc = EFAULT; 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate } 279*7c478bd9Sstevel@tonic-gate break; 280*7c478bd9Sstevel@tonic-gate case EVCH_SET_CHAN_LEN: 281*7c478bd9Sstevel@tonic-gate rc = evch_usrcontrol_set(ctl->chp, uargs.cmd, uargs.value); 282*7c478bd9Sstevel@tonic-gate break; 283*7c478bd9Sstevel@tonic-gate default: 284*7c478bd9Sstevel@tonic-gate rc = EINVAL; 285*7c478bd9Sstevel@tonic-gate } 286*7c478bd9Sstevel@tonic-gate return (rc); 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 290*7c478bd9Sstevel@tonic-gate static int 291*7c478bd9Sstevel@tonic-gate sysevent_subscribe(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 292*7c478bd9Sstevel@tonic-gate { 293*7c478bd9Sstevel@tonic-gate sev_subscribe_args_t uargs; 294*7c478bd9Sstevel@tonic-gate char *sid; 295*7c478bd9Sstevel@tonic-gate char *class_info = NULL; 296*7c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 297*7c478bd9Sstevel@tonic-gate int rc; 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 300*7c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 301*7c478bd9Sstevel@tonic-gate return (ENXIO); 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_subscribe_args_t)) != 0) 304*7c478bd9Sstevel@tonic-gate return (EFAULT); 305*7c478bd9Sstevel@tonic-gate 306*7c478bd9Sstevel@tonic-gate if (uargs.sid.len > MAX_SUBID_LEN || 307*7c478bd9Sstevel@tonic-gate uargs.class_info.len > MAX_CLASS_LEN) 308*7c478bd9Sstevel@tonic-gate return (EINVAL); 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate sid = kmem_alloc(uargs.sid.len, KM_SLEEP); 311*7c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.sid.name, 312*7c478bd9Sstevel@tonic-gate sid, uargs.sid.len) != 0) { 313*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 314*7c478bd9Sstevel@tonic-gate return (EFAULT); 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(sid, uargs.sid.len)) { 317*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 318*7c478bd9Sstevel@tonic-gate return (EINVAL); 319*7c478bd9Sstevel@tonic-gate } 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate /* If class string empty then class EC_ALL is assumed */ 322*7c478bd9Sstevel@tonic-gate if (uargs.class_info.len != 0) { 323*7c478bd9Sstevel@tonic-gate class_info = kmem_alloc(uargs.class_info.len, KM_SLEEP); 324*7c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.class_info.name, class_info, 325*7c478bd9Sstevel@tonic-gate uargs.class_info.len) != 0) { 326*7c478bd9Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len); 327*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 328*7c478bd9Sstevel@tonic-gate return (EFAULT); 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(class_info, uargs.class_info.len)) { 331*7c478bd9Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len); 332*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 333*7c478bd9Sstevel@tonic-gate return (EINVAL); 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate /* 338*7c478bd9Sstevel@tonic-gate * Check of uargs.flags just to avoid DoS attacks 339*7c478bd9Sstevel@tonic-gate * libsysevent does this carefully. 340*7c478bd9Sstevel@tonic-gate */ 341*7c478bd9Sstevel@tonic-gate rc = evch_usrsubscribe(ctl->chp, sid, class_info, 342*7c478bd9Sstevel@tonic-gate (int)uargs.door_desc, uargs.flags); 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate kmem_free(class_info, uargs.class_info.len); 345*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate return (rc); 348*7c478bd9Sstevel@tonic-gate } 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 351*7c478bd9Sstevel@tonic-gate static int 352*7c478bd9Sstevel@tonic-gate sysevent_unsubscribe(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 353*7c478bd9Sstevel@tonic-gate { 354*7c478bd9Sstevel@tonic-gate sev_unsubscribe_args_t uargs; 355*7c478bd9Sstevel@tonic-gate char *sid; 356*7c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 357*7c478bd9Sstevel@tonic-gate 358*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_unsubscribe_args_t)) != 0) 359*7c478bd9Sstevel@tonic-gate return (EFAULT); 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, getminor(dev)); 362*7c478bd9Sstevel@tonic-gate if (ctl == NULL || ctl->chp == NULL) 363*7c478bd9Sstevel@tonic-gate return (ENXIO); 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate if (uargs.sid.len > MAX_SUBID_LEN) 366*7c478bd9Sstevel@tonic-gate return (EINVAL); 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate /* Unsubscribe for all */ 369*7c478bd9Sstevel@tonic-gate if (uargs.sid.len == 0) { 370*7c478bd9Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, NULL, 0); 371*7c478bd9Sstevel@tonic-gate return (0); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate sid = kmem_alloc(uargs.sid.len, KM_SLEEP); 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.sid.name, 377*7c478bd9Sstevel@tonic-gate sid, uargs.sid.len) != 0) { 378*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 379*7c478bd9Sstevel@tonic-gate return (EFAULT); 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, sid, 0); 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate kmem_free(sid, uargs.sid.len); 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate return (0); 387*7c478bd9Sstevel@tonic-gate } 388*7c478bd9Sstevel@tonic-gate 389*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 390*7c478bd9Sstevel@tonic-gate static int 391*7c478bd9Sstevel@tonic-gate sysevent_channames(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate sev_chandata_args_t uargs; 394*7c478bd9Sstevel@tonic-gate char *buf; 395*7c478bd9Sstevel@tonic-gate int len; 396*7c478bd9Sstevel@tonic-gate int rc = 0; 397*7c478bd9Sstevel@tonic-gate 398*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_chandata_args_t)) != 0) 399*7c478bd9Sstevel@tonic-gate return (EFAULT); 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate if (uargs.out_data.len == 0 || uargs.out_data.len > EVCH_MAX_DATA_SIZE) 402*7c478bd9Sstevel@tonic-gate return (EINVAL); 403*7c478bd9Sstevel@tonic-gate 404*7c478bd9Sstevel@tonic-gate buf = kmem_alloc(uargs.out_data.len, KM_SLEEP); 405*7c478bd9Sstevel@tonic-gate 406*7c478bd9Sstevel@tonic-gate if ((len = evch_usrgetchnames(buf, uargs.out_data.len)) == -1) { 407*7c478bd9Sstevel@tonic-gate rc = EOVERFLOW; 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate if (rc == 0) { 411*7c478bd9Sstevel@tonic-gate ASSERT(len <= uargs.out_data.len); 412*7c478bd9Sstevel@tonic-gate if (copyout(buf, 413*7c478bd9Sstevel@tonic-gate (void *)(uintptr_t)uargs.out_data.name, len) != 0) { 414*7c478bd9Sstevel@tonic-gate rc = EFAULT; 415*7c478bd9Sstevel@tonic-gate } 416*7c478bd9Sstevel@tonic-gate } 417*7c478bd9Sstevel@tonic-gate 418*7c478bd9Sstevel@tonic-gate kmem_free(buf, uargs.out_data.len); 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate return (rc); 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 424*7c478bd9Sstevel@tonic-gate static int 425*7c478bd9Sstevel@tonic-gate sysevent_chandata(dev_t dev, int *rvalp, void *arg, int flag, cred_t *cr) 426*7c478bd9Sstevel@tonic-gate { 427*7c478bd9Sstevel@tonic-gate sev_chandata_args_t uargs; 428*7c478bd9Sstevel@tonic-gate char *channel; 429*7c478bd9Sstevel@tonic-gate char *buf; 430*7c478bd9Sstevel@tonic-gate int len; 431*7c478bd9Sstevel@tonic-gate int rc = 0; 432*7c478bd9Sstevel@tonic-gate 433*7c478bd9Sstevel@tonic-gate if (copyin(arg, &uargs, sizeof (sev_chandata_args_t)) != 0) 434*7c478bd9Sstevel@tonic-gate return (EFAULT); 435*7c478bd9Sstevel@tonic-gate 436*7c478bd9Sstevel@tonic-gate if (uargs.in_data.len > MAX_CHNAME_LEN || 437*7c478bd9Sstevel@tonic-gate uargs.out_data.len > EVCH_MAX_DATA_SIZE) 438*7c478bd9Sstevel@tonic-gate return (EINVAL); 439*7c478bd9Sstevel@tonic-gate 440*7c478bd9Sstevel@tonic-gate channel = kmem_alloc(uargs.in_data.len, KM_SLEEP); 441*7c478bd9Sstevel@tonic-gate 442*7c478bd9Sstevel@tonic-gate if (copyin((void *)(uintptr_t)uargs.in_data.name, channel, 443*7c478bd9Sstevel@tonic-gate uargs.in_data.len) != 0) { 444*7c478bd9Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len); 445*7c478bd9Sstevel@tonic-gate return (EFAULT); 446*7c478bd9Sstevel@tonic-gate } 447*7c478bd9Sstevel@tonic-gate 448*7c478bd9Sstevel@tonic-gate if (!sysevent_isstrend(channel, uargs.in_data.len)) { 449*7c478bd9Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len); 450*7c478bd9Sstevel@tonic-gate return (EINVAL); 451*7c478bd9Sstevel@tonic-gate } 452*7c478bd9Sstevel@tonic-gate 453*7c478bd9Sstevel@tonic-gate buf = kmem_alloc(uargs.out_data.len, KM_SLEEP); 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate len = evch_usrgetchdata(channel, buf, uargs.out_data.len); 456*7c478bd9Sstevel@tonic-gate if (len == 0) { 457*7c478bd9Sstevel@tonic-gate rc = EOVERFLOW; 458*7c478bd9Sstevel@tonic-gate } else if (len == -1) { 459*7c478bd9Sstevel@tonic-gate rc = ENOENT; 460*7c478bd9Sstevel@tonic-gate } 461*7c478bd9Sstevel@tonic-gate 462*7c478bd9Sstevel@tonic-gate if (rc == 0) { 463*7c478bd9Sstevel@tonic-gate ASSERT(len <= uargs.out_data.len); 464*7c478bd9Sstevel@tonic-gate if (copyout(buf, 465*7c478bd9Sstevel@tonic-gate (void *)(uintptr_t)uargs.out_data.name, len) != 0) { 466*7c478bd9Sstevel@tonic-gate rc = EFAULT; 467*7c478bd9Sstevel@tonic-gate } 468*7c478bd9Sstevel@tonic-gate } 469*7c478bd9Sstevel@tonic-gate 470*7c478bd9Sstevel@tonic-gate kmem_free(buf, uargs.out_data.len); 471*7c478bd9Sstevel@tonic-gate kmem_free(channel, uargs.in_data.len); 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate return (rc); 474*7c478bd9Sstevel@tonic-gate } 475*7c478bd9Sstevel@tonic-gate 476*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 477*7c478bd9Sstevel@tonic-gate static int 478*7c478bd9Sstevel@tonic-gate sysevent_ioctl(dev_t dev, int cmd, intptr_t arg, 479*7c478bd9Sstevel@tonic-gate int flag, cred_t *cr, int *rvalp) 480*7c478bd9Sstevel@tonic-gate { 481*7c478bd9Sstevel@tonic-gate int rc; 482*7c478bd9Sstevel@tonic-gate 483*7c478bd9Sstevel@tonic-gate switch (cmd) { 484*7c478bd9Sstevel@tonic-gate case SEV_PUBLISH: 485*7c478bd9Sstevel@tonic-gate rc = sysevent_publish(dev, rvalp, (void *)arg, flag, cr); 486*7c478bd9Sstevel@tonic-gate break; 487*7c478bd9Sstevel@tonic-gate case SEV_CHAN_OPEN: 488*7c478bd9Sstevel@tonic-gate rc = sysevent_chan_open(dev, rvalp, (void *)arg, flag, cr); 489*7c478bd9Sstevel@tonic-gate break; 490*7c478bd9Sstevel@tonic-gate case SEV_CHAN_CONTROL: 491*7c478bd9Sstevel@tonic-gate rc = sysevent_chan_control(dev, rvalp, (void *)arg, flag, cr); 492*7c478bd9Sstevel@tonic-gate break; 493*7c478bd9Sstevel@tonic-gate case SEV_SUBSCRIBE: 494*7c478bd9Sstevel@tonic-gate rc = sysevent_subscribe(dev, rvalp, (void *)arg, flag, cr); 495*7c478bd9Sstevel@tonic-gate break; 496*7c478bd9Sstevel@tonic-gate case SEV_UNSUBSCRIBE: 497*7c478bd9Sstevel@tonic-gate rc = sysevent_unsubscribe(dev, rvalp, (void *)arg, flag, cr); 498*7c478bd9Sstevel@tonic-gate break; 499*7c478bd9Sstevel@tonic-gate case SEV_CHANNAMES: 500*7c478bd9Sstevel@tonic-gate rc = sysevent_channames(dev, rvalp, (void *)arg, flag, cr); 501*7c478bd9Sstevel@tonic-gate break; 502*7c478bd9Sstevel@tonic-gate case SEV_CHANDATA: 503*7c478bd9Sstevel@tonic-gate rc = sysevent_chandata(dev, rvalp, (void *)arg, flag, cr); 504*7c478bd9Sstevel@tonic-gate break; 505*7c478bd9Sstevel@tonic-gate default: 506*7c478bd9Sstevel@tonic-gate rc = EINVAL; 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate 509*7c478bd9Sstevel@tonic-gate return (rc); 510*7c478bd9Sstevel@tonic-gate } 511*7c478bd9Sstevel@tonic-gate 512*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 513*7c478bd9Sstevel@tonic-gate static int 514*7c478bd9Sstevel@tonic-gate sysevent_open(dev_t *devp, int flag, int otyp, cred_t *cr) 515*7c478bd9Sstevel@tonic-gate { 516*7c478bd9Sstevel@tonic-gate int minor; 517*7c478bd9Sstevel@tonic-gate 518*7c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 519*7c478bd9Sstevel@tonic-gate return (EINVAL); 520*7c478bd9Sstevel@tonic-gate 521*7c478bd9Sstevel@tonic-gate if (getminor(*devp) != 0) 522*7c478bd9Sstevel@tonic-gate return (ENXIO); 523*7c478bd9Sstevel@tonic-gate 524*7c478bd9Sstevel@tonic-gate minor = sysevent_minor_get(); 525*7c478bd9Sstevel@tonic-gate if (minor == 0) 526*7c478bd9Sstevel@tonic-gate /* All minors are busy */ 527*7c478bd9Sstevel@tonic-gate return (EBUSY); 528*7c478bd9Sstevel@tonic-gate 529*7c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(evchan_ctlp, minor) 530*7c478bd9Sstevel@tonic-gate != DDI_SUCCESS) { 531*7c478bd9Sstevel@tonic-gate sysevent_minor_rele(minor); 532*7c478bd9Sstevel@tonic-gate return (ENOMEM); 533*7c478bd9Sstevel@tonic-gate } 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate *devp = makedevice(getmajor(*devp), minor); 536*7c478bd9Sstevel@tonic-gate 537*7c478bd9Sstevel@tonic-gate return (0); 538*7c478bd9Sstevel@tonic-gate } 539*7c478bd9Sstevel@tonic-gate 540*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 541*7c478bd9Sstevel@tonic-gate static int 542*7c478bd9Sstevel@tonic-gate sysevent_close(dev_t dev, int flag, int otyp, cred_t *cr) 543*7c478bd9Sstevel@tonic-gate { 544*7c478bd9Sstevel@tonic-gate int minor = (int)getminor(dev); 545*7c478bd9Sstevel@tonic-gate evchan_ctl_t *ctl; 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 548*7c478bd9Sstevel@tonic-gate return (EINVAL); 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate ctl = ddi_get_soft_state(evchan_ctlp, minor); 551*7c478bd9Sstevel@tonic-gate if (ctl == NULL) { 552*7c478bd9Sstevel@tonic-gate return (ENXIO); 553*7c478bd9Sstevel@tonic-gate } 554*7c478bd9Sstevel@tonic-gate 555*7c478bd9Sstevel@tonic-gate if (ctl->chp) { 556*7c478bd9Sstevel@tonic-gate /* Release all non-persistant subscriptions */ 557*7c478bd9Sstevel@tonic-gate evch_usrunsubscribe(ctl->chp, NULL, EVCH_SUB_KEEP); 558*7c478bd9Sstevel@tonic-gate evch_usrchanclose(ctl->chp); 559*7c478bd9Sstevel@tonic-gate } 560*7c478bd9Sstevel@tonic-gate 561*7c478bd9Sstevel@tonic-gate ddi_soft_state_free(evchan_ctlp, minor); 562*7c478bd9Sstevel@tonic-gate sysevent_minor_rele(minor); 563*7c478bd9Sstevel@tonic-gate 564*7c478bd9Sstevel@tonic-gate return (0); 565*7c478bd9Sstevel@tonic-gate } 566*7c478bd9Sstevel@tonic-gate 567*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 568*7c478bd9Sstevel@tonic-gate static int 569*7c478bd9Sstevel@tonic-gate sysevent_info(dev_info_t *dip, ddi_info_cmd_t infocmd, 570*7c478bd9Sstevel@tonic-gate void *arg, void **result) 571*7c478bd9Sstevel@tonic-gate { 572*7c478bd9Sstevel@tonic-gate switch (infocmd) { 573*7c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 574*7c478bd9Sstevel@tonic-gate *result = sysevent_devi; 575*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 576*7c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 577*7c478bd9Sstevel@tonic-gate *result = 0; 578*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 579*7c478bd9Sstevel@tonic-gate } 580*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 581*7c478bd9Sstevel@tonic-gate } 582*7c478bd9Sstevel@tonic-gate 583*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 584*7c478bd9Sstevel@tonic-gate static int 585*7c478bd9Sstevel@tonic-gate sysevent_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 586*7c478bd9Sstevel@tonic-gate { 587*7c478bd9Sstevel@tonic-gate 588*7c478bd9Sstevel@tonic-gate if (cmd != DDI_ATTACH) { 589*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 590*7c478bd9Sstevel@tonic-gate } 591*7c478bd9Sstevel@tonic-gate 592*7c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, "sysevent", S_IFCHR, 593*7c478bd9Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 594*7c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 595*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 596*7c478bd9Sstevel@tonic-gate } 597*7c478bd9Sstevel@tonic-gate sysevent_devi = devi; 598*7c478bd9Sstevel@tonic-gate 599*7c478bd9Sstevel@tonic-gate sysevent_minor_init(); 600*7c478bd9Sstevel@tonic-gate 601*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 602*7c478bd9Sstevel@tonic-gate } 603*7c478bd9Sstevel@tonic-gate 604*7c478bd9Sstevel@tonic-gate static int 605*7c478bd9Sstevel@tonic-gate sysevent_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 606*7c478bd9Sstevel@tonic-gate { 607*7c478bd9Sstevel@tonic-gate if (cmd != DDI_DETACH) { 608*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 609*7c478bd9Sstevel@tonic-gate } 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate sysevent_minor_free(sysevent_minor_bitmap); 612*7c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 613*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 614*7c478bd9Sstevel@tonic-gate } 615*7c478bd9Sstevel@tonic-gate 616*7c478bd9Sstevel@tonic-gate static struct cb_ops sysevent_cb_ops = { 617*7c478bd9Sstevel@tonic-gate sysevent_open, /* open */ 618*7c478bd9Sstevel@tonic-gate sysevent_close, /* close */ 619*7c478bd9Sstevel@tonic-gate nodev, /* strategy */ 620*7c478bd9Sstevel@tonic-gate nodev, /* print */ 621*7c478bd9Sstevel@tonic-gate nodev, /* dump */ 622*7c478bd9Sstevel@tonic-gate nodev, /* read */ 623*7c478bd9Sstevel@tonic-gate nodev, /* write */ 624*7c478bd9Sstevel@tonic-gate sysevent_ioctl, /* ioctl */ 625*7c478bd9Sstevel@tonic-gate nodev, /* devmap */ 626*7c478bd9Sstevel@tonic-gate nodev, /* mmap */ 627*7c478bd9Sstevel@tonic-gate nodev, /* segmap */ 628*7c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 629*7c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 630*7c478bd9Sstevel@tonic-gate 0, /* streamtab */ 631*7c478bd9Sstevel@tonic-gate D_NEW|D_MP, /* flag */ 632*7c478bd9Sstevel@tonic-gate NULL, /* aread */ 633*7c478bd9Sstevel@tonic-gate NULL /* awrite */ 634*7c478bd9Sstevel@tonic-gate }; 635*7c478bd9Sstevel@tonic-gate 636*7c478bd9Sstevel@tonic-gate static struct dev_ops sysevent_ops = { 637*7c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 638*7c478bd9Sstevel@tonic-gate 0, /* refcnt */ 639*7c478bd9Sstevel@tonic-gate sysevent_info, /* info */ 640*7c478bd9Sstevel@tonic-gate nulldev, /* identify */ 641*7c478bd9Sstevel@tonic-gate nulldev, /* probe */ 642*7c478bd9Sstevel@tonic-gate sysevent_attach, /* attach */ 643*7c478bd9Sstevel@tonic-gate sysevent_detach, /* detach */ 644*7c478bd9Sstevel@tonic-gate nodev, /* reset */ 645*7c478bd9Sstevel@tonic-gate &sysevent_cb_ops, /* driver operations */ 646*7c478bd9Sstevel@tonic-gate (struct bus_ops *)0, /* no bus operations */ 647*7c478bd9Sstevel@tonic-gate nulldev /* power */ 648*7c478bd9Sstevel@tonic-gate }; 649*7c478bd9Sstevel@tonic-gate 650*7c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 651*7c478bd9Sstevel@tonic-gate &mod_driverops, "sysevent driver %I%", &sysevent_ops 652*7c478bd9Sstevel@tonic-gate }; 653*7c478bd9Sstevel@tonic-gate 654*7c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 655*7c478bd9Sstevel@tonic-gate MODREV_1, &modldrv, NULL 656*7c478bd9Sstevel@tonic-gate }; 657*7c478bd9Sstevel@tonic-gate 658*7c478bd9Sstevel@tonic-gate int 659*7c478bd9Sstevel@tonic-gate _init(void) 660*7c478bd9Sstevel@tonic-gate { 661*7c478bd9Sstevel@tonic-gate int s; 662*7c478bd9Sstevel@tonic-gate 663*7c478bd9Sstevel@tonic-gate s = ddi_soft_state_init(&evchan_ctlp, sizeof (evchan_ctl_t), 1); 664*7c478bd9Sstevel@tonic-gate if (s != 0) 665*7c478bd9Sstevel@tonic-gate return (s); 666*7c478bd9Sstevel@tonic-gate 667*7c478bd9Sstevel@tonic-gate if ((s = mod_install(&modlinkage)) != 0) 668*7c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&evchan_ctlp); 669*7c478bd9Sstevel@tonic-gate return (s); 670*7c478bd9Sstevel@tonic-gate } 671*7c478bd9Sstevel@tonic-gate 672*7c478bd9Sstevel@tonic-gate int 673*7c478bd9Sstevel@tonic-gate _fini(void) 674*7c478bd9Sstevel@tonic-gate { 675*7c478bd9Sstevel@tonic-gate int s; 676*7c478bd9Sstevel@tonic-gate 677*7c478bd9Sstevel@tonic-gate if ((s = mod_remove(&modlinkage)) != 0) 678*7c478bd9Sstevel@tonic-gate return (s); 679*7c478bd9Sstevel@tonic-gate 680*7c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&evchan_ctlp); 681*7c478bd9Sstevel@tonic-gate return (s); 682*7c478bd9Sstevel@tonic-gate } 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate int 685*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 686*7c478bd9Sstevel@tonic-gate { 687*7c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 688*7c478bd9Sstevel@tonic-gate } 689