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 #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <unistd.h>
30*0Sstevel@tonic-gate #include <picl.h>
31*0Sstevel@tonic-gate #include <picltree.h>
32*0Sstevel@tonic-gate #include <picldefs.h>
33*0Sstevel@tonic-gate #include <pthread.h>
34*0Sstevel@tonic-gate #include <syslog.h>
35*0Sstevel@tonic-gate #include <string.h>
36*0Sstevel@tonic-gate #include <libnvpair.h>
37*0Sstevel@tonic-gate #include <libintl.h>
38*0Sstevel@tonic-gate #include "piclenvmond.h"
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate /* external funcs and varaibles */
41*0Sstevel@tonic-gate extern void env_handle_event(const char *, const void *, size_t);
42*0Sstevel@tonic-gate extern picl_errno_t env_init();
43*0Sstevel@tonic-gate extern void env_platmod_fini();
44*0Sstevel@tonic-gate extern int sensor_fd;
45*0Sstevel@tonic-gate extern pthread_t env_temp_thr_tid;
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate /* local defines */
48*0Sstevel@tonic-gate #define TIMEOUT (10)
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate #pragma init(piclenvmond_register)
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate /*
53*0Sstevel@tonic-gate * Plugin registration entry points
54*0Sstevel@tonic-gate */
55*0Sstevel@tonic-gate static void piclenvmond_register(void);
56*0Sstevel@tonic-gate static void piclenvmond_init(void);
57*0Sstevel@tonic-gate static void piclenvmond_fini(void);
58*0Sstevel@tonic-gate static void piclenvmond_evhandler(const char *, const void *, size_t, void *);
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate int env_debug = 0x0;
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate static picld_plugin_reg_t envmond_reg_info = {
63*0Sstevel@tonic-gate PICLD_PLUGIN_VERSION_1,
64*0Sstevel@tonic-gate PICLD_PLUGIN_CRITICAL,
65*0Sstevel@tonic-gate "SUNW_piclenvmond",
66*0Sstevel@tonic-gate piclenvmond_init,
67*0Sstevel@tonic-gate piclenvmond_fini
68*0Sstevel@tonic-gate };
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate typedef struct {
71*0Sstevel@tonic-gate picl_nodehdl_t nodehdl;
72*0Sstevel@tonic-gate char node_name[PICL_PROPNAMELEN_MAX];
73*0Sstevel@tonic-gate } env_callback_args_t;
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate * picld entry points
77*0Sstevel@tonic-gate */
78*0Sstevel@tonic-gate static void
piclenvmond_register(void)79*0Sstevel@tonic-gate piclenvmond_register(void)
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate (void) picld_plugin_register(&envmond_reg_info);
82*0Sstevel@tonic-gate }
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gate /*
85*0Sstevel@tonic-gate * picld entry point
86*0Sstevel@tonic-gate * - do all the initialization
87*0Sstevel@tonic-gate * - register for interested picl events
88*0Sstevel@tonic-gate */
89*0Sstevel@tonic-gate static void
piclenvmond_init(void)90*0Sstevel@tonic-gate piclenvmond_init(void)
91*0Sstevel@tonic-gate {
92*0Sstevel@tonic-gate picl_errno_t rc = PICL_SUCCESS;
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate if ((rc = env_init()) != PICL_SUCCESS) {
95*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:envmond init failed, "
96*0Sstevel@tonic-gate "error = %d"), rc);
97*0Sstevel@tonic-gate return;
98*0Sstevel@tonic-gate }
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate /* register handler for state change events */
101*0Sstevel@tonic-gate (void) ptree_register_handler(PICLEVENT_STATE_CHANGE,
102*0Sstevel@tonic-gate piclenvmond_evhandler, NULL);
103*0Sstevel@tonic-gate /* register handler for condition change events */
104*0Sstevel@tonic-gate (void) ptree_register_handler(PICLEVENT_CONDITION_CHANGE,
105*0Sstevel@tonic-gate piclenvmond_evhandler, NULL);
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate }
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate static void
piclenvmond_fini(void)110*0Sstevel@tonic-gate piclenvmond_fini(void)
111*0Sstevel@tonic-gate {
112*0Sstevel@tonic-gate void *exitval;
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate /* unregister event handler */
115*0Sstevel@tonic-gate (void) ptree_unregister_handler(PICLEVENT_STATE_CHANGE,
116*0Sstevel@tonic-gate piclenvmond_evhandler, NULL);
117*0Sstevel@tonic-gate (void) ptree_unregister_handler(PICLEVENT_CONDITION_CHANGE,
118*0Sstevel@tonic-gate piclenvmond_evhandler, NULL);
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate /* cancel all the threads */
121*0Sstevel@tonic-gate (void) pthread_cancel(env_temp_thr_tid);
122*0Sstevel@tonic-gate (void) pthread_join(env_temp_thr_tid, &exitval);
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate /* do any platform specific cleanups required */
125*0Sstevel@tonic-gate env_platmod_fini();
126*0Sstevel@tonic-gate (void) close(sensor_fd);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate /*ARGSUSED*/
130*0Sstevel@tonic-gate static void
piclenvmond_evhandler(const char * ename,const void * earg,size_t size,void * cookie)131*0Sstevel@tonic-gate piclenvmond_evhandler(const char *ename, const void *earg, size_t size,
132*0Sstevel@tonic-gate void *cookie)
133*0Sstevel@tonic-gate {
134*0Sstevel@tonic-gate env_handle_event(ename, earg, size);
135*0Sstevel@tonic-gate }
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate /*
138*0Sstevel@tonic-gate * Utility functions
139*0Sstevel@tonic-gate */
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate /*
142*0Sstevel@tonic-gate * create_property -- Create a PICL property
143*0Sstevel@tonic-gate */
144*0Sstevel@tonic-gate picl_errno_t
env_create_property(int ptype,int pmode,size_t psize,char * pname,int (* readfn)(ptree_rarg_t *,void *),int (* writefn)(ptree_warg_t *,const void *),picl_nodehdl_t nodeh,picl_prophdl_t * propp,void * vbuf)145*0Sstevel@tonic-gate env_create_property(int ptype, int pmode, size_t psize, char *pname,
146*0Sstevel@tonic-gate int (*readfn)(ptree_rarg_t *, void *),
147*0Sstevel@tonic-gate int (*writefn)(ptree_warg_t *, const void *),
148*0Sstevel@tonic-gate picl_nodehdl_t nodeh, picl_prophdl_t *propp, void *vbuf)
149*0Sstevel@tonic-gate {
150*0Sstevel@tonic-gate picl_errno_t rc; /* return code */
151*0Sstevel@tonic-gate ptree_propinfo_t propinfo; /* propinfo structure */
152*0Sstevel@tonic-gate picl_prophdl_t proph;
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate rc = ptree_get_prop_by_name(nodeh, pname, &proph);
155*0Sstevel@tonic-gate if (rc == PICL_SUCCESS) { /* prop. already exists */
156*0Sstevel@tonic-gate return (rc);
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate rc = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION,
160*0Sstevel@tonic-gate ptype, pmode, psize, pname, readfn, writefn);
161*0Sstevel@tonic-gate if (rc != PICL_SUCCESS) {
162*0Sstevel@tonic-gate syslog(LOG_ERR, PTREE_INIT_PROPINFO_FAILED_MSG, rc);
163*0Sstevel@tonic-gate return (rc);
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate rc = ptree_create_and_add_prop(nodeh, &propinfo, vbuf, propp);
167*0Sstevel@tonic-gate if (rc != PICL_SUCCESS) {
168*0Sstevel@tonic-gate syslog(LOG_ERR, PTREE_CREATE_AND_ADD_PROP_FAILED_MSG, rc);
169*0Sstevel@tonic-gate return (rc);
170*0Sstevel@tonic-gate }
171*0Sstevel@tonic-gate return (PICL_SUCCESS);
172*0Sstevel@tonic-gate }
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate /*
175*0Sstevel@tonic-gate * The picl event completion handler.
176*0Sstevel@tonic-gate */
177*0Sstevel@tonic-gate /* ARGSUSED */
178*0Sstevel@tonic-gate static void
event_completion_handler(char * ename,void * earg,size_t size)179*0Sstevel@tonic-gate event_completion_handler(char *ename, void *earg, size_t size)
180*0Sstevel@tonic-gate {
181*0Sstevel@tonic-gate free(earg);
182*0Sstevel@tonic-gate free(ename);
183*0Sstevel@tonic-gate }
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate /*
186*0Sstevel@tonic-gate * utility routine to post PICL events
187*0Sstevel@tonic-gate */
188*0Sstevel@tonic-gate /*ARGSUSED*/
189*0Sstevel@tonic-gate static int
post_picl_event(const char * ename,char * envl,size_t elen,picl_nodehdl_t nodeh,int cond_wait)190*0Sstevel@tonic-gate post_picl_event(const char *ename, char *envl, size_t elen,
191*0Sstevel@tonic-gate picl_nodehdl_t nodeh, int cond_wait)
192*0Sstevel@tonic-gate {
193*0Sstevel@tonic-gate nvlist_t *nvlp;
194*0Sstevel@tonic-gate size_t nvl_size;
195*0Sstevel@tonic-gate char *pack_buf = NULL;
196*0Sstevel@tonic-gate char *evname;
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate if (nodeh == 0) {
199*0Sstevel@tonic-gate return (PICL_FAILURE);
200*0Sstevel@tonic-gate }
201*0Sstevel@tonic-gate if ((evname = strdup(ename)) == NULL)
202*0Sstevel@tonic-gate return (PICL_FAILURE);
203*0Sstevel@tonic-gate if (envl) {
204*0Sstevel@tonic-gate if (nvlist_unpack(envl, elen, &nvlp, 0) < 0) {
205*0Sstevel@tonic-gate nvlist_free(nvlp);
206*0Sstevel@tonic-gate free(evname);
207*0Sstevel@tonic-gate return (PICL_FAILURE);
208*0Sstevel@tonic-gate }
209*0Sstevel@tonic-gate } else {
210*0Sstevel@tonic-gate if (nvlist_alloc(&nvlp, NV_UNIQUE_NAME_TYPE, NULL)) {
211*0Sstevel@tonic-gate free(evname);
212*0Sstevel@tonic-gate return (PICL_FAILURE);
213*0Sstevel@tonic-gate }
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate
216*0Sstevel@tonic-gate if (nvlist_add_uint64(nvlp, PICLEVENTARG_NODEHANDLE, nodeh) == -1) {
217*0Sstevel@tonic-gate nvlist_free(nvlp);
218*0Sstevel@tonic-gate free(evname);
219*0Sstevel@tonic-gate return (PICL_FAILURE);
220*0Sstevel@tonic-gate }
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate if (nvlist_pack(nvlp, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, NULL)) {
223*0Sstevel@tonic-gate nvlist_free(nvlp);
224*0Sstevel@tonic-gate free(evname);
225*0Sstevel@tonic-gate return (PICL_FAILURE);
226*0Sstevel@tonic-gate }
227*0Sstevel@tonic-gate nvlist_free(nvlp);
228*0Sstevel@tonic-gate
229*0Sstevel@tonic-gate if (env_debug & EVENTS) {
230*0Sstevel@tonic-gate char enodename[PICL_PROPNAMELEN_MAX];
231*0Sstevel@tonic-gate if (ptree_get_propval_by_name(nodeh, PICL_PROP_NAME,
232*0Sstevel@tonic-gate enodename, sizeof (enodename)) == PICL_SUCCESS)
233*0Sstevel@tonic-gate syslog(LOG_INFO, "envmond:Posting %s on %s\n",
234*0Sstevel@tonic-gate ename, enodename);
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate if (ptree_post_event(evname, pack_buf, nvl_size,
238*0Sstevel@tonic-gate event_completion_handler) != 0) {
239*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond: Error posting %s PICL"
240*0Sstevel@tonic-gate " event."), ename);
241*0Sstevel@tonic-gate free(pack_buf);
242*0Sstevel@tonic-gate free(evname);
243*0Sstevel@tonic-gate return (PICL_FAILURE);
244*0Sstevel@tonic-gate }
245*0Sstevel@tonic-gate return (PICL_SUCCESS);
246*0Sstevel@tonic-gate }
247*0Sstevel@tonic-gate
248*0Sstevel@tonic-gate /*
249*0Sstevel@tonic-gate * post dr_req events
250*0Sstevel@tonic-gate */
251*0Sstevel@tonic-gate picl_errno_t
post_dr_req_event(picl_nodehdl_t fruh,char * dr_req_type,uint8_t wait)252*0Sstevel@tonic-gate post_dr_req_event(picl_nodehdl_t fruh, char *dr_req_type, uint8_t wait)
253*0Sstevel@tonic-gate {
254*0Sstevel@tonic-gate nvlist_t *nvlp; /* nvlist of event specific args */
255*0Sstevel@tonic-gate size_t nvl_size;
256*0Sstevel@tonic-gate char *pack_buf = NULL;
257*0Sstevel@tonic-gate char dr_ap_id[PICL_PROPNAMELEN_MAX];
258*0Sstevel@tonic-gate int rc = PICL_SUCCESS;
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate if (env_debug & DEBUG)
261*0Sstevel@tonic-gate syslog(LOG_DEBUG, "Post %s on %llx", dr_req_type, fruh);
262*0Sstevel@tonic-gate if (fruh == 0) {
263*0Sstevel@tonic-gate return (PICL_INVALIDARG);
264*0Sstevel@tonic-gate }
265*0Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(fruh, PICL_PROP_NAME,
266*0Sstevel@tonic-gate dr_ap_id, sizeof (dr_ap_id))) != PICL_SUCCESS) {
267*0Sstevel@tonic-gate return (rc);
268*0Sstevel@tonic-gate }
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gate if (nvlist_alloc(&nvlp, NV_UNIQUE_NAME_TYPE, NULL)) {
271*0Sstevel@tonic-gate return (PICL_FAILURE);
272*0Sstevel@tonic-gate }
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate if (nvlist_add_string(nvlp, PICLEVENTARG_AP_ID, dr_ap_id) == -1) {
275*0Sstevel@tonic-gate nvlist_free(nvlp);
276*0Sstevel@tonic-gate return (PICL_FAILURE);
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate if (nvlist_add_string(nvlp, PICLEVENTARG_DR_REQ_TYPE, dr_req_type)
279*0Sstevel@tonic-gate == -1) {
280*0Sstevel@tonic-gate nvlist_free(nvlp);
281*0Sstevel@tonic-gate return (PICL_FAILURE);
282*0Sstevel@tonic-gate }
283*0Sstevel@tonic-gate if (nvlist_pack(nvlp, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, NULL)) {
284*0Sstevel@tonic-gate nvlist_free(nvlp);
285*0Sstevel@tonic-gate return (PICL_FAILURE);
286*0Sstevel@tonic-gate }
287*0Sstevel@tonic-gate nvlist_free(nvlp);
288*0Sstevel@tonic-gate
289*0Sstevel@tonic-gate if (env_debug & DEBUG)
290*0Sstevel@tonic-gate syslog(LOG_DEBUG, "Posting %s on %s", dr_req_type, dr_ap_id);
291*0Sstevel@tonic-gate rc = post_picl_event(PICLEVENT_DR_REQ, pack_buf, nvl_size, fruh,
292*0Sstevel@tonic-gate wait);
293*0Sstevel@tonic-gate
294*0Sstevel@tonic-gate free(pack_buf);
295*0Sstevel@tonic-gate return (rc);
296*0Sstevel@tonic-gate }
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate /*
299*0Sstevel@tonic-gate * routine to post dr_ap_state change events
300*0Sstevel@tonic-gate */
301*0Sstevel@tonic-gate picl_errno_t
post_dr_ap_state_change_event(picl_nodehdl_t nodehdl,char * dr_hint,uint8_t wait)302*0Sstevel@tonic-gate post_dr_ap_state_change_event(picl_nodehdl_t nodehdl, char *dr_hint,
303*0Sstevel@tonic-gate uint8_t wait)
304*0Sstevel@tonic-gate {
305*0Sstevel@tonic-gate nvlist_t *nvlp; /* nvlist of event specific args */
306*0Sstevel@tonic-gate size_t nvl_size;
307*0Sstevel@tonic-gate char *pack_buf = NULL;
308*0Sstevel@tonic-gate char dr_ap_id[PICL_PROPNAMELEN_MAX];
309*0Sstevel@tonic-gate int rc = PICL_SUCCESS;
310*0Sstevel@tonic-gate
311*0Sstevel@tonic-gate if (nodehdl == 0) {
312*0Sstevel@tonic-gate return (PICL_FAILURE);
313*0Sstevel@tonic-gate }
314*0Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(nodehdl, PICL_PROP_NAME,
315*0Sstevel@tonic-gate dr_ap_id, sizeof (dr_ap_id))) != PICL_SUCCESS) {
316*0Sstevel@tonic-gate return (rc);
317*0Sstevel@tonic-gate }
318*0Sstevel@tonic-gate if (nvlist_alloc(&nvlp, NV_UNIQUE_NAME_TYPE, NULL)) {
319*0Sstevel@tonic-gate return (PICL_FAILURE);
320*0Sstevel@tonic-gate }
321*0Sstevel@tonic-gate
322*0Sstevel@tonic-gate if (nvlist_add_string(nvlp, PICLEVENTARG_AP_ID, dr_ap_id) == -1) {
323*0Sstevel@tonic-gate nvlist_free(nvlp);
324*0Sstevel@tonic-gate return (PICL_FAILURE);
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate if (nvlist_add_string(nvlp, PICLEVENTARG_HINT, dr_hint) == -1) {
327*0Sstevel@tonic-gate nvlist_free(nvlp);
328*0Sstevel@tonic-gate return (PICL_FAILURE);
329*0Sstevel@tonic-gate }
330*0Sstevel@tonic-gate if (nvlist_pack(nvlp, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, NULL)) {
331*0Sstevel@tonic-gate nvlist_free(nvlp);
332*0Sstevel@tonic-gate return (PICL_FAILURE);
333*0Sstevel@tonic-gate }
334*0Sstevel@tonic-gate nvlist_free(nvlp);
335*0Sstevel@tonic-gate rc = post_picl_event(PICLEVENT_DR_AP_STATE_CHANGE, pack_buf,
336*0Sstevel@tonic-gate nvl_size, nodehdl, wait);
337*0Sstevel@tonic-gate free(pack_buf);
338*0Sstevel@tonic-gate return (rc);
339*0Sstevel@tonic-gate }
340*0Sstevel@tonic-gate
341*0Sstevel@tonic-gate picl_errno_t
post_cpu_state_change_event(picl_nodehdl_t fruh,char * event_type,uint8_t wait)342*0Sstevel@tonic-gate post_cpu_state_change_event(picl_nodehdl_t fruh, char *event_type, uint8_t wait)
343*0Sstevel@tonic-gate {
344*0Sstevel@tonic-gate nvlist_t *nvlp; /* nvlist of event specific args */
345*0Sstevel@tonic-gate size_t nvl_size;
346*0Sstevel@tonic-gate char *pack_buf = NULL;
347*0Sstevel@tonic-gate int rc = PICL_SUCCESS;
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate if (fruh == 0) {
350*0Sstevel@tonic-gate return (PICL_FAILURE);
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate
353*0Sstevel@tonic-gate if (nvlist_alloc(&nvlp, NV_UNIQUE_NAME_TYPE, NULL))
354*0Sstevel@tonic-gate return (PICL_FAILURE);
355*0Sstevel@tonic-gate
356*0Sstevel@tonic-gate if (nvlist_add_int64(nvlp, PICLEVENTARG_NODEHANDLE, fruh)) {
357*0Sstevel@tonic-gate nvlist_free(nvlp);
358*0Sstevel@tonic-gate return (PICL_FAILURE);
359*0Sstevel@tonic-gate }
360*0Sstevel@tonic-gate
361*0Sstevel@tonic-gate if (nvlist_add_string(nvlp, PICLEVENTARG_CPU_EV_TYPE,
362*0Sstevel@tonic-gate event_type) == -1) {
363*0Sstevel@tonic-gate nvlist_free(nvlp);
364*0Sstevel@tonic-gate return (PICL_FAILURE);
365*0Sstevel@tonic-gate }
366*0Sstevel@tonic-gate
367*0Sstevel@tonic-gate if (nvlist_pack(nvlp, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, NULL)) {
368*0Sstevel@tonic-gate nvlist_free(nvlp);
369*0Sstevel@tonic-gate return (PICL_FAILURE);
370*0Sstevel@tonic-gate }
371*0Sstevel@tonic-gate nvlist_free(nvlp);
372*0Sstevel@tonic-gate rc = post_picl_event(PICLEVENT_CPU_STATE_CHANGE, pack_buf,
373*0Sstevel@tonic-gate nvl_size, fruh, wait);
374*0Sstevel@tonic-gate free(pack_buf);
375*0Sstevel@tonic-gate return (rc);
376*0Sstevel@tonic-gate }
377*0Sstevel@tonic-gate
378*0Sstevel@tonic-gate int
post_sensor_event(picl_nodehdl_t hdl,char * sensor_evalue,uint8_t wait)379*0Sstevel@tonic-gate post_sensor_event(picl_nodehdl_t hdl, char *sensor_evalue, uint8_t wait)
380*0Sstevel@tonic-gate {
381*0Sstevel@tonic-gate nvlist_t *nvlp; /* nvlist of event specific args */
382*0Sstevel@tonic-gate size_t nvl_size;
383*0Sstevel@tonic-gate char *pack_buf = NULL;
384*0Sstevel@tonic-gate char dr_ap_id[PICL_PROPNAMELEN_MAX];
385*0Sstevel@tonic-gate int rc = PICL_SUCCESS;
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gate if (env_debug & DEBUG)
388*0Sstevel@tonic-gate syslog(LOG_DEBUG, "Post %s on %llx", sensor_evalue, hdl);
389*0Sstevel@tonic-gate if (hdl == 0)
390*0Sstevel@tonic-gate return (PICL_FAILURE);
391*0Sstevel@tonic-gate
392*0Sstevel@tonic-gate if (nvlist_alloc(&nvlp, NV_UNIQUE_NAME_TYPE, NULL))
393*0Sstevel@tonic-gate return (PICL_FAILURE);
394*0Sstevel@tonic-gate
395*0Sstevel@tonic-gate if (nvlist_add_string(nvlp, PICLEVENTARG_CONDITION,
396*0Sstevel@tonic-gate sensor_evalue) == -1) {
397*0Sstevel@tonic-gate nvlist_free(nvlp);
398*0Sstevel@tonic-gate return (PICL_FAILURE);
399*0Sstevel@tonic-gate }
400*0Sstevel@tonic-gate if (nvlist_pack(nvlp, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, NULL)) {
401*0Sstevel@tonic-gate nvlist_free(nvlp);
402*0Sstevel@tonic-gate return (PICL_FAILURE);
403*0Sstevel@tonic-gate }
404*0Sstevel@tonic-gate nvlist_free(nvlp);
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate if (env_debug & DEBUG) {
407*0Sstevel@tonic-gate if (ptree_get_propval_by_name(hdl, PICL_PROP_NAME, dr_ap_id,
408*0Sstevel@tonic-gate sizeof (dr_ap_id)) == PICL_SUCCESS)
409*0Sstevel@tonic-gate syslog(LOG_DEBUG, "Posting %s on %s", sensor_evalue,
410*0Sstevel@tonic-gate dr_ap_id);
411*0Sstevel@tonic-gate }
412*0Sstevel@tonic-gate rc = post_picl_event(PICLEVENT_CONDITION_CHANGE, pack_buf, nvl_size,
413*0Sstevel@tonic-gate hdl, wait);
414*0Sstevel@tonic-gate free(pack_buf);
415*0Sstevel@tonic-gate return (rc);
416*0Sstevel@tonic-gate }
417*0Sstevel@tonic-gate
418*0Sstevel@tonic-gate /*
419*0Sstevel@tonic-gate * return B_TRUE if admin lock is enabled
420*0Sstevel@tonic-gate * return B_FALSE if admin lock is disabled
421*0Sstevel@tonic-gate */
422*0Sstevel@tonic-gate boolean_t
env_admin_lock_enabled(picl_nodehdl_t fruh)423*0Sstevel@tonic-gate env_admin_lock_enabled(picl_nodehdl_t fruh)
424*0Sstevel@tonic-gate {
425*0Sstevel@tonic-gate char adminlock[PICL_PROPNAMELEN_MAX];
426*0Sstevel@tonic-gate
427*0Sstevel@tonic-gate if (ptree_get_propval_by_name(fruh, PICL_PROP_ADMIN_LOCK,
428*0Sstevel@tonic-gate adminlock, sizeof (adminlock))
429*0Sstevel@tonic-gate != PICL_SUCCESS) {
430*0Sstevel@tonic-gate return (B_FALSE);
431*0Sstevel@tonic-gate }
432*0Sstevel@tonic-gate if (strcmp(adminlock, PICL_ADMINLOCK_ENABLED) == 0) {
433*0Sstevel@tonic-gate return (B_TRUE);
434*0Sstevel@tonic-gate }
435*0Sstevel@tonic-gate return (B_FALSE);
436*0Sstevel@tonic-gate }
437