1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _SYS_SYSEVENT_H 28*0Sstevel@tonic-gate #define _SYS_SYSEVENT_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #include <sys/nvpair.h> 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #ifdef __cplusplus 35*0Sstevel@tonic-gate extern "C" { 36*0Sstevel@tonic-gate #endif 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #ifndef NULL 39*0Sstevel@tonic-gate #if defined(_LP64) && !defined(__cplusplus) 40*0Sstevel@tonic-gate #define NULL 0L 41*0Sstevel@tonic-gate #else 42*0Sstevel@tonic-gate #define NULL 0 43*0Sstevel@tonic-gate #endif 44*0Sstevel@tonic-gate #endif 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate /* Internal registration class and subclass */ 47*0Sstevel@tonic-gate #define EC_ALL "register_all_classes" 48*0Sstevel@tonic-gate #define EC_SUB_ALL "register_all_subclasses" 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate /* 51*0Sstevel@tonic-gate * Event allocation/enqueuing sleep/nosleep flags 52*0Sstevel@tonic-gate */ 53*0Sstevel@tonic-gate #define SE_SLEEP 0 54*0Sstevel@tonic-gate #define SE_NOSLEEP 1 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate /* Framework error codes */ 57*0Sstevel@tonic-gate #define SE_EINVAL 1 /* Invalid argument */ 58*0Sstevel@tonic-gate #define SE_ENOMEM 2 /* Unable to allocate memory */ 59*0Sstevel@tonic-gate #define SE_EQSIZE 3 /* Maximum event q size exceeded */ 60*0Sstevel@tonic-gate #define SE_EFAULT 4 /* Copy fault */ 61*0Sstevel@tonic-gate #define SE_NOTFOUND 5 /* Attribute not found */ 62*0Sstevel@tonic-gate #define SE_NO_TRANSPORT 6 /* sysevent transport down */ 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate /* Internal data types */ 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate #define SE_DATA_TYPE_BYTE DATA_TYPE_BYTE 67*0Sstevel@tonic-gate #define SE_DATA_TYPE_INT16 DATA_TYPE_INT16 68*0Sstevel@tonic-gate #define SE_DATA_TYPE_UINT16 DATA_TYPE_UINT16 69*0Sstevel@tonic-gate #define SE_DATA_TYPE_INT32 DATA_TYPE_INT32 70*0Sstevel@tonic-gate #define SE_DATA_TYPE_UINT32 DATA_TYPE_UINT32 71*0Sstevel@tonic-gate #define SE_DATA_TYPE_INT64 DATA_TYPE_INT64 72*0Sstevel@tonic-gate #define SE_DATA_TYPE_UINT64 DATA_TYPE_UINT64 73*0Sstevel@tonic-gate #define SE_DATA_TYPE_STRING DATA_TYPE_STRING 74*0Sstevel@tonic-gate #define SE_DATA_TYPE_BYTES DATA_TYPE_BYTE_ARRAY 75*0Sstevel@tonic-gate #define SE_DATA_TYPE_TIME DATA_TYPE_HRTIME 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate #define SE_KERN_PID 0 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate #define SUNW_VENDOR "SUNW" 80*0Sstevel@tonic-gate #define SE_USR_PUB "usr:" 81*0Sstevel@tonic-gate #define SE_KERN_PUB "kern:" 82*0Sstevel@tonic-gate #define SUNW_KERN_PUB SUNW_VENDOR":"SE_KERN_PUB 83*0Sstevel@tonic-gate #define SUNW_USR_PUB SUNW_VENDOR":"SE_USR_PUB 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate /* 86*0Sstevel@tonic-gate * Event header and attribute value limits 87*0Sstevel@tonic-gate */ 88*0Sstevel@tonic-gate #define MAX_ATTR_NAME 1024 89*0Sstevel@tonic-gate #define MAX_STRING_SZ 1024 90*0Sstevel@tonic-gate #define MAX_BYTE_ARRAY 1024 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate #define MAX_CLASS_LEN 64 93*0Sstevel@tonic-gate #define MAX_SUBCLASS_LEN 64 94*0Sstevel@tonic-gate #define MAX_PUB_LEN 128 95*0Sstevel@tonic-gate #define MAX_CHNAME_LEN 128 96*0Sstevel@tonic-gate #define MAX_SUBID_LEN 16 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate /* 99*0Sstevel@tonic-gate * Limit for the event payload size 100*0Sstevel@tonic-gate */ 101*0Sstevel@tonic-gate #define MAX_EV_SIZE_LEN (SHRT_MAX/4) 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate /* Opaque sysevent_t data type */ 104*0Sstevel@tonic-gate typedef void *sysevent_t; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate /* Opaque channel bind data type */ 107*0Sstevel@tonic-gate typedef void evchan_t; 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate /* sysevent attribute list */ 110*0Sstevel@tonic-gate typedef nvlist_t sysevent_attr_list_t; 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate /* sysevent attribute name-value pair */ 113*0Sstevel@tonic-gate typedef nvpair_t sysevent_attr_t; 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* Unique event identifier */ 116*0Sstevel@tonic-gate typedef struct sysevent_id { 117*0Sstevel@tonic-gate uint64_t eid_seq; 118*0Sstevel@tonic-gate hrtime_t eid_ts; 119*0Sstevel@tonic-gate } sysevent_id_t; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate /* Event attribute value structures */ 122*0Sstevel@tonic-gate typedef struct sysevent_bytes { 123*0Sstevel@tonic-gate int32_t size; 124*0Sstevel@tonic-gate uchar_t *data; 125*0Sstevel@tonic-gate } sysevent_bytes_t; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate typedef struct sysevent_value { 128*0Sstevel@tonic-gate int32_t value_type; /* data type */ 129*0Sstevel@tonic-gate union { 130*0Sstevel@tonic-gate uchar_t sv_byte; 131*0Sstevel@tonic-gate int16_t sv_int16; 132*0Sstevel@tonic-gate uint16_t sv_uint16; 133*0Sstevel@tonic-gate int32_t sv_int32; 134*0Sstevel@tonic-gate uint32_t sv_uint32; 135*0Sstevel@tonic-gate int64_t sv_int64; 136*0Sstevel@tonic-gate uint64_t sv_uint64; 137*0Sstevel@tonic-gate hrtime_t sv_time; 138*0Sstevel@tonic-gate char *sv_string; 139*0Sstevel@tonic-gate sysevent_bytes_t sv_bytes; 140*0Sstevel@tonic-gate } value; 141*0Sstevel@tonic-gate } sysevent_value_t; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate /* 144*0Sstevel@tonic-gate * The following flags determine the memory allocation semantics to use for 145*0Sstevel@tonic-gate * kernel event buffer allocation by userland and kernel versions of 146*0Sstevel@tonic-gate * sysevent_evc_publish(). 147*0Sstevel@tonic-gate * 148*0Sstevel@tonic-gate * EVCH_SLEEP and EVCH_NOSLEEP respectively map to KM_SLEEP and KM_NOSLEEP. 149*0Sstevel@tonic-gate * EVCH_TRYHARD is a kernel-only publish flag that allow event allocation 150*0Sstevel@tonic-gate * routines to use use alternate kmem caches in situations where free memory 151*0Sstevel@tonic-gate * may be low. Kernel callers of sysevent_evc_publish() must set flags to 152*0Sstevel@tonic-gate * one of EVCH_SLEEP, EVCH_NOSLEEP or EVCH_TRYHARD. Userland callers of 153*0Sstevel@tonic-gate * sysevent_evc_publish() must set flags to one of EVCH_SLEEP or EVCH_NOSLEEP. 154*0Sstevel@tonic-gate * 155*0Sstevel@tonic-gate * EVCH_QWAIT determines whether or not we should wait for slots in the event 156*0Sstevel@tonic-gate * queue at publication time. EVCH_QWAIT may be used by kernel and userland 157*0Sstevel@tonic-gate * publishers and must be used in conjunction with any of one of EVCH_SLEEP, 158*0Sstevel@tonic-gate * EVCH_NOSLEEP or EVCH_TRYHARD (kernel-only). 159*0Sstevel@tonic-gate */ 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate #define EVCH_NOSLEEP 0x0001 /* No sleep on kmem_alloc() */ 162*0Sstevel@tonic-gate #define EVCH_SLEEP 0x0002 /* Sleep on kmem_alloc() */ 163*0Sstevel@tonic-gate #define EVCH_TRYHARD 0x0004 /* May use alternate kmem cache for alloc */ 164*0Sstevel@tonic-gate #define EVCH_QWAIT 0x0008 /* Wait for slot in event queue */ 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* 167*0Sstevel@tonic-gate * Meaning of flags for subscribe/unsubscribe. Bits 0 to 7 are dedicated to 168*0Sstevel@tonic-gate * the consolidation private interface. 169*0Sstevel@tonic-gate */ 170*0Sstevel@tonic-gate #define EVCH_SUB_KEEP 0x0001 171*0Sstevel@tonic-gate #define EVCH_ALLSUB "all_subs" 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate /* 174*0Sstevel@tonic-gate * Meaning of flags parameter of channel bind function 175*0Sstevel@tonic-gate */ 176*0Sstevel@tonic-gate #define EVCH_CREAT 0x0001 /* Create a channel if not present */ 177*0Sstevel@tonic-gate #define EVCH_HOLD_PEND 0x0002 178*0Sstevel@tonic-gate #define EVCH_B_FLAGS 0x0003 /* All valid bits */ 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate /* 181*0Sstevel@tonic-gate * Meaning of commands of evc_control function 182*0Sstevel@tonic-gate */ 183*0Sstevel@tonic-gate #define EVCH_GET_CHAN_LEN_MAX 1 /* Get event queue length limit */ 184*0Sstevel@tonic-gate #define EVCH_GET_CHAN_LEN 2 /* Get event queue length */ 185*0Sstevel@tonic-gate #define EVCH_SET_CHAN_LEN 3 /* Set event queue length */ 186*0Sstevel@tonic-gate #define EVCH_CMD_LAST EVCH_SET_CHAN_LEN /* Last command */ 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate /* 189*0Sstevel@tonic-gate * Event channel interface definitions 190*0Sstevel@tonic-gate */ 191*0Sstevel@tonic-gate int sysevent_evc_bind(const char *, evchan_t **, uint32_t); 192*0Sstevel@tonic-gate void sysevent_evc_unbind(evchan_t *); 193*0Sstevel@tonic-gate int sysevent_evc_subscribe(evchan_t *, const char *, const char *, 194*0Sstevel@tonic-gate int (*)(sysevent_t *, void *), void *, uint32_t); 195*0Sstevel@tonic-gate void sysevent_evc_unsubscribe(evchan_t *, const char *); 196*0Sstevel@tonic-gate int sysevent_evc_publish(evchan_t *, const char *, const char *, 197*0Sstevel@tonic-gate const char *, const char *, nvlist_t *, uint32_t); 198*0Sstevel@tonic-gate int sysevent_evc_control(evchan_t *, int, ...); 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate #ifdef _KERNEL 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate /* 203*0Sstevel@tonic-gate * Kernel log_event interfaces. 204*0Sstevel@tonic-gate */ 205*0Sstevel@tonic-gate int log_sysevent(sysevent_t *, int, sysevent_id_t *); 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate sysevent_t *sysevent_alloc(char *, char *, char *, int); 208*0Sstevel@tonic-gate void sysevent_free(sysevent_t *); 209*0Sstevel@tonic-gate int sysevent_add_attr(sysevent_attr_list_t **, char *, sysevent_value_t *, int); 210*0Sstevel@tonic-gate void sysevent_free_attr(sysevent_attr_list_t *); 211*0Sstevel@tonic-gate int sysevent_attach_attributes(sysevent_t *, sysevent_attr_list_t *); 212*0Sstevel@tonic-gate void sysevent_detach_attributes(sysevent_t *); 213*0Sstevel@tonic-gate char *sysevent_get_class_name(sysevent_t *); 214*0Sstevel@tonic-gate char *sysevent_get_subclass_name(sysevent_t *); 215*0Sstevel@tonic-gate uint64_t sysevent_get_seq(sysevent_t *); 216*0Sstevel@tonic-gate void sysevent_get_time(sysevent_t *, hrtime_t *); 217*0Sstevel@tonic-gate size_t sysevent_get_size(sysevent_t *); 218*0Sstevel@tonic-gate char *sysevent_get_pub(sysevent_t *); 219*0Sstevel@tonic-gate int sysevent_get_attr_list(sysevent_t *, nvlist_t **); 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate #endif /* _KERNEL */ 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate #ifdef __cplusplus 224*0Sstevel@tonic-gate } 225*0Sstevel@tonic-gate #endif 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate #endif /* _SYS_SYSEVENT_H */ 228