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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <libnvpair.h>
38 #include "piclenvmond.h"
40 /* external funcs and varaibles */
41 extern void env_handle_event(const char *, const void *, size_t);
42 extern picl_errno_t
env_init();
43 extern void env_platmod_fini();
45 extern pthread_t env_temp_thr_tid
;
50 #pragma init(piclenvmond_register)
53 * Plugin registration entry points
55 static void piclenvmond_register(void);
56 static void piclenvmond_init(void);
57 static void piclenvmond_fini(void);
58 static void piclenvmond_evhandler(const char *, const void *, size_t, void *);
62 static picld_plugin_reg_t envmond_reg_info
= {
63 PICLD_PLUGIN_VERSION_1
,
64 PICLD_PLUGIN_CRITICAL
,
71 picl_nodehdl_t nodehdl
;
72 char node_name
[PICL_PROPNAMELEN_MAX
];
73 } env_callback_args_t
;
79 piclenvmond_register(void)
81 (void) picld_plugin_register(&envmond_reg_info
);
86 * - do all the initialization
87 * - register for interested picl events
90 piclenvmond_init(void)
92 picl_errno_t rc
= PICL_SUCCESS
;
94 if ((rc
= env_init()) != PICL_SUCCESS
) {
95 syslog(LOG_ERR
, gettext("SUNW_envmond:envmond init failed, "
100 /* register handler for state change events */
101 (void) ptree_register_handler(PICLEVENT_STATE_CHANGE
,
102 piclenvmond_evhandler
, NULL
);
103 /* register handler for condition change events */
104 (void) ptree_register_handler(PICLEVENT_CONDITION_CHANGE
,
105 piclenvmond_evhandler
, NULL
);
110 piclenvmond_fini(void)
114 /* unregister event handler */
115 (void) ptree_unregister_handler(PICLEVENT_STATE_CHANGE
,
116 piclenvmond_evhandler
, NULL
);
117 (void) ptree_unregister_handler(PICLEVENT_CONDITION_CHANGE
,
118 piclenvmond_evhandler
, NULL
);
120 /* cancel all the threads */
121 (void) pthread_cancel(env_temp_thr_tid
);
122 (void) pthread_join(env_temp_thr_tid
, &exitval
);
124 /* do any platform specific cleanups required */
126 (void) close(sensor_fd
);
131 piclenvmond_evhandler(const char *ename
, const void *earg
, size_t size
,
134 env_handle_event(ename
, earg
, size
);
142 * create_property -- Create a PICL property
145 env_create_property(int ptype
, int pmode
, size_t psize
, char *pname
,
146 int (*readfn
)(ptree_rarg_t
*, void *),
147 int (*writefn
)(ptree_warg_t
*, const void *),
148 picl_nodehdl_t nodeh
, picl_prophdl_t
*propp
, void *vbuf
)
150 picl_errno_t rc
; /* return code */
151 ptree_propinfo_t propinfo
; /* propinfo structure */
152 picl_prophdl_t proph
;
154 rc
= ptree_get_prop_by_name(nodeh
, pname
, &proph
);
155 if (rc
== PICL_SUCCESS
) { /* prop. already exists */
159 rc
= ptree_init_propinfo(&propinfo
, PTREE_PROPINFO_VERSION
,
160 ptype
, pmode
, psize
, pname
, readfn
, writefn
);
161 if (rc
!= PICL_SUCCESS
) {
162 syslog(LOG_ERR
, PTREE_INIT_PROPINFO_FAILED_MSG
, rc
);
166 rc
= ptree_create_and_add_prop(nodeh
, &propinfo
, vbuf
, propp
);
167 if (rc
!= PICL_SUCCESS
) {
168 syslog(LOG_ERR
, PTREE_CREATE_AND_ADD_PROP_FAILED_MSG
, rc
);
171 return (PICL_SUCCESS
);
175 * The picl event completion handler.
179 event_completion_handler(char *ename
, void *earg
, size_t size
)
186 * utility routine to post PICL events
190 post_picl_event(const char *ename
, char *envl
, size_t elen
,
191 picl_nodehdl_t nodeh
, int cond_wait
)
195 char *pack_buf
= NULL
;
199 return (PICL_FAILURE
);
201 if ((evname
= strdup(ename
)) == NULL
)
202 return (PICL_FAILURE
);
204 if (nvlist_unpack(envl
, elen
, &nvlp
, 0) < 0) {
207 return (PICL_FAILURE
);
210 if (nvlist_alloc(&nvlp
, NV_UNIQUE_NAME_TYPE
, NULL
)) {
212 return (PICL_FAILURE
);
216 if (nvlist_add_uint64(nvlp
, PICLEVENTARG_NODEHANDLE
, nodeh
) == -1) {
219 return (PICL_FAILURE
);
222 if (nvlist_pack(nvlp
, &pack_buf
, &nvl_size
, NV_ENCODE_NATIVE
, NULL
)) {
225 return (PICL_FAILURE
);
229 if (env_debug
& EVENTS
) {
230 char enodename
[PICL_PROPNAMELEN_MAX
];
231 if (ptree_get_propval_by_name(nodeh
, PICL_PROP_NAME
,
232 enodename
, sizeof (enodename
)) == PICL_SUCCESS
)
233 syslog(LOG_INFO
, "envmond:Posting %s on %s\n",
237 if (ptree_post_event(evname
, pack_buf
, nvl_size
,
238 event_completion_handler
) != 0) {
239 syslog(LOG_ERR
, gettext("SUNW_envmond: Error posting %s PICL"
243 return (PICL_FAILURE
);
245 return (PICL_SUCCESS
);
252 post_dr_req_event(picl_nodehdl_t fruh
, char *dr_req_type
, uint8_t wait
)
254 nvlist_t
*nvlp
; /* nvlist of event specific args */
256 char *pack_buf
= NULL
;
257 char dr_ap_id
[PICL_PROPNAMELEN_MAX
];
258 int rc
= PICL_SUCCESS
;
260 if (env_debug
& DEBUG
)
261 syslog(LOG_DEBUG
, "Post %s on %llx", dr_req_type
, fruh
);
263 return (PICL_INVALIDARG
);
265 if ((rc
= ptree_get_propval_by_name(fruh
, PICL_PROP_NAME
,
266 dr_ap_id
, sizeof (dr_ap_id
))) != PICL_SUCCESS
) {
270 if (nvlist_alloc(&nvlp
, NV_UNIQUE_NAME_TYPE
, NULL
)) {
271 return (PICL_FAILURE
);
274 if (nvlist_add_string(nvlp
, PICLEVENTARG_AP_ID
, dr_ap_id
) == -1) {
276 return (PICL_FAILURE
);
278 if (nvlist_add_string(nvlp
, PICLEVENTARG_DR_REQ_TYPE
, dr_req_type
)
281 return (PICL_FAILURE
);
283 if (nvlist_pack(nvlp
, &pack_buf
, &nvl_size
, NV_ENCODE_NATIVE
, NULL
)) {
285 return (PICL_FAILURE
);
289 if (env_debug
& DEBUG
)
290 syslog(LOG_DEBUG
, "Posting %s on %s", dr_req_type
, dr_ap_id
);
291 rc
= post_picl_event(PICLEVENT_DR_REQ
, pack_buf
, nvl_size
, fruh
,
299 * routine to post dr_ap_state change events
302 post_dr_ap_state_change_event(picl_nodehdl_t nodehdl
, char *dr_hint
,
305 nvlist_t
*nvlp
; /* nvlist of event specific args */
307 char *pack_buf
= NULL
;
308 char dr_ap_id
[PICL_PROPNAMELEN_MAX
];
309 int rc
= PICL_SUCCESS
;
312 return (PICL_FAILURE
);
314 if ((rc
= ptree_get_propval_by_name(nodehdl
, PICL_PROP_NAME
,
315 dr_ap_id
, sizeof (dr_ap_id
))) != PICL_SUCCESS
) {
318 if (nvlist_alloc(&nvlp
, NV_UNIQUE_NAME_TYPE
, NULL
)) {
319 return (PICL_FAILURE
);
322 if (nvlist_add_string(nvlp
, PICLEVENTARG_AP_ID
, dr_ap_id
) == -1) {
324 return (PICL_FAILURE
);
326 if (nvlist_add_string(nvlp
, PICLEVENTARG_HINT
, dr_hint
) == -1) {
328 return (PICL_FAILURE
);
330 if (nvlist_pack(nvlp
, &pack_buf
, &nvl_size
, NV_ENCODE_NATIVE
, NULL
)) {
332 return (PICL_FAILURE
);
335 rc
= post_picl_event(PICLEVENT_DR_AP_STATE_CHANGE
, pack_buf
,
336 nvl_size
, nodehdl
, wait
);
342 post_cpu_state_change_event(picl_nodehdl_t fruh
, char *event_type
, uint8_t wait
)
344 nvlist_t
*nvlp
; /* nvlist of event specific args */
346 char *pack_buf
= NULL
;
347 int rc
= PICL_SUCCESS
;
350 return (PICL_FAILURE
);
353 if (nvlist_alloc(&nvlp
, NV_UNIQUE_NAME_TYPE
, NULL
))
354 return (PICL_FAILURE
);
356 if (nvlist_add_int64(nvlp
, PICLEVENTARG_NODEHANDLE
, fruh
)) {
358 return (PICL_FAILURE
);
361 if (nvlist_add_string(nvlp
, PICLEVENTARG_CPU_EV_TYPE
,
364 return (PICL_FAILURE
);
367 if (nvlist_pack(nvlp
, &pack_buf
, &nvl_size
, NV_ENCODE_NATIVE
, NULL
)) {
369 return (PICL_FAILURE
);
372 rc
= post_picl_event(PICLEVENT_CPU_STATE_CHANGE
, pack_buf
,
373 nvl_size
, fruh
, wait
);
379 post_sensor_event(picl_nodehdl_t hdl
, char *sensor_evalue
, uint8_t wait
)
381 nvlist_t
*nvlp
; /* nvlist of event specific args */
383 char *pack_buf
= NULL
;
384 char dr_ap_id
[PICL_PROPNAMELEN_MAX
];
385 int rc
= PICL_SUCCESS
;
387 if (env_debug
& DEBUG
)
388 syslog(LOG_DEBUG
, "Post %s on %llx", sensor_evalue
, hdl
);
390 return (PICL_FAILURE
);
392 if (nvlist_alloc(&nvlp
, NV_UNIQUE_NAME_TYPE
, NULL
))
393 return (PICL_FAILURE
);
395 if (nvlist_add_string(nvlp
, PICLEVENTARG_CONDITION
,
396 sensor_evalue
) == -1) {
398 return (PICL_FAILURE
);
400 if (nvlist_pack(nvlp
, &pack_buf
, &nvl_size
, NV_ENCODE_NATIVE
, NULL
)) {
402 return (PICL_FAILURE
);
406 if (env_debug
& DEBUG
) {
407 if (ptree_get_propval_by_name(hdl
, PICL_PROP_NAME
, dr_ap_id
,
408 sizeof (dr_ap_id
)) == PICL_SUCCESS
)
409 syslog(LOG_DEBUG
, "Posting %s on %s", sensor_evalue
,
412 rc
= post_picl_event(PICLEVENT_CONDITION_CHANGE
, pack_buf
, nvl_size
,
419 * return B_TRUE if admin lock is enabled
420 * return B_FALSE if admin lock is disabled
423 env_admin_lock_enabled(picl_nodehdl_t fruh
)
425 char adminlock
[PICL_PROPNAMELEN_MAX
];
427 if (ptree_get_propval_by_name(fruh
, PICL_PROP_ADMIN_LOCK
,
428 adminlock
, sizeof (adminlock
))
432 if (strcmp(adminlock
, PICL_ADMINLOCK_ENABLED
) == 0) {