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