2 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DDI_LOG_SYSEVENT 9F "Jan 16, 2006"
8 ddi_log_sysevent \- log system event for drivers
13 #include <sys/sunddi.h>
17 \fBint\fR \fBddi_log_sysevent\fR(\fBdev_info_t *\fR\fIdip\fR, \fBchar *\fR\fIvendor\fR,
18 \fBchar *\fR\fIclass\fR, \fBchar *\fR\fIsubclass\fR, \fBnvlist_t *\fR\fIattr_list\fR,
19 \fBsysevent_id_t *\fR\fIeidp\fR, \fBint\fR \fIsleep_flag\fR);
25 Solaris DDI specific (Solaris DDI).
33 A pointer to the \fBdev_info\fR node for this driver.
42 A pointer to a string defining the vendor. Third-party drivers should use their
43 company's stock symbol (or similarly enduring identifier). Sun-supplied drivers
44 should use \fBDDI_VENDOR_SUNW\fR.
53 A pointer to a string defining the event class.
62 A pointer to a string defining the event subclass.
71 A pointer to an \fBnvlist_t\fR, listing the name-value attributes associated
72 with the event or NULL if there are no such attributes for this event.
81 The address of a \fBsysevent_id_t\fR structure in which the event's sequence
82 number and timestamp are returned if the event is successfully queued. May be
83 NULL if this information is not of interest. See below for the definition of
90 \fB\fIsleep_flag\fR\fR
93 Indicates how a caller wants to handle the possibility of resources not being
94 available. If \fIsleep_flag\fR is \fBDDI_NOSLEEP\fR, the caller does not care
95 if the allocation fails or the queue is full and can handle a failure
96 appropriately. If \fBsleep_flag\fR is \fBDDI_SLEEP\fR, the caller wishes to
97 have the allocation and queuing routines wait for resources to become
104 The \fBddi_log_sysevent()\fR function causes a system event, of the specified
105 class and subclass, to be generated on behalf of the driver and queued for
106 delivery to \fBsyseventd\fR, the user-land \fBsysevent\fR daemon.
109 The publisher string for the event is constructed using the vendor name and
110 driver name, with the format:
114 "\fI<vendor>\fR:kern:\fI<driver-name>\fR"
121 The two fields of \fBeidp\fR, \fBeid_seq\fR and \fBeid_ts\fR, are sufficient to
122 uniquely identify an event.
123 .SH STRUCTURE MEMBERS
126 The structure members of \fBsysevent_id_t\fR are:
130 uint64_t eid_seq; /* sysevent sequence number */
131 hrtime_t eid_ts; /* sysevent timestamp */
138 The \fBddi_log_sysevent()\fR function returns:
142 \fB\fBDDI_SUCCESS\fR\fR
145 The event has been queued for delivery successfully.
151 \fB\fBDDI_ENOMEM\fR\fR
154 There is not enough memory to queue the system event at this time.
155 \fBDDI_ENOMEM\fR cannot be returned when \fIsleep_flag\fR is \fBDDI_SLEEP\fR.
161 \fB\fBDDI_EBUSY\fR\fR
164 The system event queue is full at this time. \fBDDI_EBUSY\fR cannot be returned
165 when \fIsleep_flag\fR is \fBDDI_SLEEP\fR.
171 \fB\fBDDI_ETRANSPORT\fR\fR
174 The \fBsyseventd\fR daemon is not responding and events cannot be queued or
175 delivered at this time. \fBDDI_ETRANSPORT\fR can be returned even when
176 \fIsleep_flag\fR is \fBDDI_SLEEP\fR.
182 \fB\fBDDI_ECONTEXT\fR\fR
185 \fIsleep_flag\fR is DDI_SLEEP and the driver is running in interrupt context.
190 \fBddi_log_sysevent\fR supports the following data types:
229 DATA_TYPE_INT16_ARRAY
233 DATA_TYPE_UINT16_ARRAY
237 DATA_TYPE_INT32_ARRAY
241 DATA_TYPE_UINT32_ARRAY
245 DATA_TYPE_INT64_ARRAY
249 DATA_TYPE_UINT64_ARRAY
254 The \fBddi_log_sysevent()\fR function can be called from user, interrupt, or
255 kernel context, except when \fIsleep_flag\fR is \fBDDI_SLEEP\fR, in which case
256 it cannot be called from interrupt context.
259 \fBExample 1 \fRLogging System Event with No Attributes
263 if (ddi_log_sysevent(dip, DDI_VENDOR_SUNW, "class", "subclass",
264 NULL, NULL, DDI_SLEEP) != DDI_SUCCESS) {
265 cmn_err(CE_WARN, "error logging system event\en");
271 \fBExample 2 \fRLogging System Event with Two Name/Value Attributes, an Integer
279 if (nvlist_alloc(&attr_list, NV_UNIQUE_NAME_TYPE, KM_SLEEP) == 0)
281 err = nvlist_add_uint32(attr_list, int_name, int_value);
283 err = nvlist_add_string(attr_list, str_name, str_value);
285 err = ddi_log_sysevent(dip, DDI_VENDOR_SUNW,
286 "class", "subclass", attr_list, &eid, DDI_SLEEP);
287 if (err != DDI_SUCCESS)
288 cmn_err(CE_WARN, "error logging system event\en");
289 nvlist_free(attr_list);
295 \fBExample 3 \fRUse Timeout to Handle \fBnvlist\fR and System Event Resource
299 Since no blocking calls are made, this example would be useable from a driver
300 needing to generate an event from interrupt context.
306 xx_se_timeout_handler(xx_state_t *xx)
308 xx->xx_timeoutid = (xx_generate_event(xx) ?
309 timeout(xx_se_timeout_handler, xx, 4) : 0);
313 xx_generate_event(xx_state_t *xx)
317 err = nvlist_alloc(&xx->xx_ev_attrlist, NV_UNIQUE_NAME_TYPE, 0);
320 err = nvlist_add_uint32(&xx->xx_ev_attrlist,
321 xx->xx_ev_name, xx->xx_ev_value);
323 nvlist_free(xx->xx_ev_attrlist);
327 err = ddi_log_sysevent(xx->xx_dip, DDI_VENDOR_SUNW,
328 xx->xx_ev_class, xx->xx_ev_sbclass,
329 xx->xx_ev_attrlist, NULL, DDI_NOSLEEP);
330 nvlist_free(xx->xx_ev_attrlist);
331 if (err == DDI_SUCCESS || err == DDI_ETRANSPORT) {
332 if (err == DDI_ETRANSPORT)
333 cmn_err(CE_WARN, "cannot log system event\en");
344 \fBsyseventd\fR(1M), \fBattributes\fR(5), \fBnvlist_add_boolean\fR(9F),
345 \fBnvlist_alloc\fR(9F)
348 \fIWriting Device Drivers\fR