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 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This file contains code for setting up environmental related nodes
31 * and properties in the PICL tree.
47 #include <sys/systeminfo.h>
50 #include <picld_pluginutil.h>
52 #include <sys/utsname.h>
53 #include <sys/systeminfo.h>
58 * Volatile property read/write function typedef
60 typedef int ptree_vol_rdfunc_t(ptree_rarg_t
*parg
, void *buf
);
61 typedef int ptree_vol_wrfunc_t(ptree_warg_t
*parg
, const void *buf
);
63 extern int disk_temp_monitor
;
64 extern env_tuneable_t tuneables
[];
66 extern int ntuneables
;
67 #define PROP_FAN_SPEED_UNIT_VALUE "rpm"
70 * Sensor node data structure
73 char *parent_path
; /* parent path */
74 char *sensor_name
; /* sensor name */
75 env_sensor_t
*sensorp
; /* sensor info */
76 picl_nodehdl_t nodeh
; /* sensor node handle */
77 picl_prophdl_t proph
; /* "Temperature" property handle */
78 picl_prophdl_t target_proph
; /* "TargetTemp" property handle */
84 static sensor_node_t sensor_nodes
[] = {
85 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_CPU0
,
86 NULL
, NULL
, NULL
, NULL
},
87 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_CPU1
,
88 NULL
, NULL
, NULL
, NULL
},
89 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_MB
,
90 NULL
, NULL
, NULL
, NULL
},
91 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_ADT7462
,
92 NULL
, NULL
, NULL
, NULL
},
93 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_LM95221
,
94 NULL
, NULL
, NULL
, NULL
},
95 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_FIRE
,
96 NULL
, NULL
, NULL
, NULL
},
97 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_LSI1064
,
98 NULL
, NULL
, NULL
, NULL
},
99 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_FRONT_PANEL
,
100 NULL
, NULL
, NULL
, NULL
},
101 {"/platform/ebus@1f,464000/env-monitor@3,0", SENSOR_PSU
,
102 NULL
, NULL
, NULL
, NULL
}
104 #define N_SENSOR_NODES (sizeof (sensor_nodes)/sizeof (sensor_nodes[0]))
107 * Fan node data structure
110 char *parent_path
; /* parent node path */
111 char *fan_name
; /* fan name */
112 env_fan_t
*fanp
; /* fan information */
113 char *speed_unit
; /* speed unit string */
114 picl_nodehdl_t nodeh
; /* "fan" node handle */
115 picl_prophdl_t proph
; /* "Speed" property handle */
121 static fan_node_t fan_nodes
[] = {
122 {"/platform/ebus@1f,464000/env-monitor@3,0", ENV_SYSTEM_FAN0
,
123 NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
124 {"/platform/ebus@1f,464000/env-monitor@3,0", ENV_SYSTEM_FAN1
,
125 NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
126 {"/platform/ebus@1f,464000/env-monitor@3,0", ENV_SYSTEM_FAN2
,
127 NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
128 {"/platform/ebus@1f,464000/env-monitor@3,0", ENV_SYSTEM_FAN3
,
129 NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
130 {"/platform/ebus@1f,464000/env-monitor@3,0", ENV_SYSTEM_FAN4
,
131 NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
}
133 #define N_FAN_NODES (sizeof (fan_nodes)/sizeof (fan_nodes[0]))
136 * Disk node data structure
139 char *parent_path
; /* parent node path */
140 char *disk_name
; /* disk name */
141 env_disk_t
*diskp
; /* disk information */
142 picl_nodehdl_t nodeh
; /* "disk" node handle */
143 picl_prophdl_t proph
; /* "Temperature" property handle */
149 static disk_node_t disk_nodes
[] = {
150 {DISK0_NODE_PATH
, ENV_DISK0
, NULL
, NULL
, NULL
},
151 {DISK1_NODE_PATH
, ENV_DISK1
, NULL
, NULL
, NULL
},
152 {DISK2_NODE_PATH
, ENV_DISK2
, NULL
, NULL
, NULL
},
153 {DISK3_NODE_PATH
, ENV_DISK3
, NULL
, NULL
, NULL
}
155 #define N_DISK_NODES (sizeof (disk_nodes)/sizeof (disk_nodes[0]))
158 * Miscellaneous declarations
160 static void delete_sensor_nodes_and_props(void);
161 static void delete_disk_nodes_and_props(void);
162 static void delete_fan_nodes_and_props(void);
166 * Read function for volatile "Temperature" property
169 get_current_temp(ptree_rarg_t
*parg
, void *buf
)
172 picl_prophdl_t proph
;
173 sensor_node_t
*snodep
;
177 * Locate the sensor in our sensor_nodes table by matching the
178 * property handle and get its temperature.
181 for (i
= 0; i
< N_SENSOR_NODES
; i
++) {
182 snodep
= &sensor_nodes
[i
];
183 if (snodep
->proph
!= proph
)
186 if (get_temperature(snodep
->sensorp
, &temp
) < 0)
188 (void) memcpy(buf
, (caddr_t
)&temp
, sizeof (tempr_t
));
189 return (PICL_SUCCESS
);
191 return (PICL_FAILURE
);
195 * Read function for volatile "Temperature" property
198 get_disk_temp(ptree_rarg_t
*parg
, void *buf
)
201 picl_prophdl_t proph
;
206 * Locate the sensor in our sensor_nodes table by matching the
207 * property handle and get its temperature.
210 for (i
= 0; i
< N_DISK_NODES
; i
++) {
211 dnodep
= &disk_nodes
[i
];
212 if (dnodep
->proph
!= proph
)
215 if (disk_temperature(dnodep
->diskp
, &temp
) < 0)
217 (void) memcpy(buf
, (caddr_t
)&temp
, sizeof (tempr_t
));
218 return (PICL_SUCCESS
);
220 return (PICL_FAILURE
);
224 * Read function for volatile "Speed" property on "fan" class node
227 set_current_speed(ptree_warg_t
*parg
, const void *buf
)
230 picl_prophdl_t proph
;
235 * Locate the fan in our fan_nodes table by matching the
236 * property handle and get fan speed.
239 for (i
= 0; i
< N_FAN_NODES
; i
++) {
240 fnodep
= &fan_nodes
[i
];
241 if (fnodep
->proph
!= proph
)
243 if (fnodep
->fanp
->fd
== -1)
246 (void) memcpy((caddr_t
)&speed
, buf
, sizeof (speed
));
248 ret
= set_fan_speed(fnodep
->fanp
, speed
);
251 if (ret
== -1 && errno
== EBUSY
)
252 return (PICL_NOTWRITABLE
);
254 return (PICL_INVALIDARG
);
259 return (PICL_SUCCESS
);
261 return (PICL_FAILURE
);
266 * Read function for volatile "Speed" property on "fan" class node
269 get_current_speed(ptree_rarg_t
*parg
, void *buf
)
272 picl_prophdl_t proph
;
277 * Locate the fan in our fan_nodes table by matching the
278 * property handle and get fan speed.
281 for (i
= 0; i
< N_FAN_NODES
; i
++) {
282 fnodep
= &fan_nodes
[i
];
283 if (fnodep
->proph
!= proph
)
285 if (fnodep
->fanp
->fd
== -1)
287 if (get_fan_speed(fnodep
->fanp
, &speed
) < 0)
290 (void) memcpy(buf
, (caddr_t
)&speed
, sizeof (speed
));
291 return (PICL_SUCCESS
);
293 return (PICL_FAILURE
);
297 * Create and add the specified regular property
301 add_regular_prop(picl_nodehdl_t nodeh
, char *name
, int type
, int access
,
302 int size
, void *valbuf
, picl_prophdl_t
*prophp
)
305 ptree_propinfo_t propinfo
;
306 picl_prophdl_t proph
;
308 err
= ptree_init_propinfo(&propinfo
, PTREE_PROPINFO_VERSION
,
309 type
, access
, size
, name
, NULL
, NULL
);
310 if (err
!= PICL_SUCCESS
)
313 err
= ptree_create_and_add_prop(nodeh
, &propinfo
, valbuf
, &proph
);
314 if (err
== PICL_SUCCESS
&& prophp
)
321 * Create and add the specified volatile property
324 add_volatile_prop(picl_nodehdl_t nodeh
, char *name
, int type
, int access
,
325 int size
, ptree_vol_rdfunc_t
*rdfunc
, ptree_vol_wrfunc_t
*wrfunc
,
326 picl_prophdl_t
*prophp
)
329 ptree_propinfo_t propinfo
;
330 picl_prophdl_t proph
;
332 err
= ptree_init_propinfo(&propinfo
, PTREE_PROPINFO_VERSION
,
333 type
, (access
|PICL_VOLATILE
), size
, name
, rdfunc
, wrfunc
);
334 if (err
!= PICL_SUCCESS
)
337 err
= ptree_create_and_add_prop(nodeh
, &propinfo
, NULL
, &proph
);
338 if (err
== PICL_SUCCESS
&& prophp
)
344 * Add temperature threshold properties
347 add_sensor_thresh_props(picl_nodehdl_t nodeh
, es_sensor_blk_t
*sensor_blkp
)
349 picl_prophdl_t proph
;
351 (void) add_regular_prop(nodeh
, PICL_PROP_LOW_POWER_OFF
,
352 PICL_PTYPE_INT
, PICL_READ
,
353 sizeof (sensor_blkp
->esb_low_power_off
),
354 &sensor_blkp
->esb_low_power_off
, &proph
);
356 (void) add_regular_prop(nodeh
, PICL_PROP_LOW_SHUTDOWN
,
357 PICL_PTYPE_INT
, PICL_READ
,
358 sizeof (sensor_blkp
->esb_low_shutdown
),
359 &sensor_blkp
->esb_low_shutdown
, &proph
);
361 (void) add_regular_prop(nodeh
, PICL_PROP_LOW_WARNING
,
362 PICL_PTYPE_INT
, PICL_READ
,
363 sizeof (sensor_blkp
->esb_low_warning
),
364 &sensor_blkp
->esb_low_warning
, &proph
);
366 (void) add_regular_prop(nodeh
, PICL_PROP_HIGH_WARNING
,
367 PICL_PTYPE_INT
, PICL_READ
,
368 sizeof (sensor_blkp
->esb_high_warning
),
369 &sensor_blkp
->esb_high_warning
, &proph
);
371 (void) add_regular_prop(nodeh
, PICL_PROP_HIGH_SHUTDOWN
,
372 PICL_PTYPE_INT
, PICL_READ
,
373 sizeof (sensor_blkp
->esb_high_shutdown
),
374 &sensor_blkp
->esb_high_shutdown
, &proph
);
376 (void) add_regular_prop(nodeh
, PICL_PROP_HIGH_POWER_OFF
,
377 PICL_PTYPE_INT
, PICL_READ
,
378 sizeof (sensor_blkp
->esb_high_power_off
),
379 &sensor_blkp
->esb_high_power_off
, &proph
);
384 * Go through the sensor_nodes array and create those nodes
385 * and the Temperature property to report the temperature.
388 add_sensor_nodes_and_props()
391 char *pname
, *nodename
, *devfs_path
;
392 sensor_node_t
*snodep
;
393 picl_nodehdl_t nodeh
, cnodeh
;
394 picl_prophdl_t proph
;
395 env_sensor_t
*sensorp
;
396 es_sensor_blk_t
*sensor_blkp
;
399 for (i
= 0; i
< N_SENSOR_NODES
; i
++) {
400 snodep
= &sensor_nodes
[i
];
402 * Get the parent nodeh
404 err
= ptree_get_node_by_path(snodep
->parent_path
, &nodeh
);
405 if (err
!= PICL_SUCCESS
) {
407 envd_log(LOG_ERR
, "failed to get_node_by_path %s\n",
408 snodep
->parent_path
);
411 sensorp
= snodep
->sensorp
;
414 if (sensorp
->present
== B_FALSE
)
417 * Create temperature-sensor node
419 nodename
= snodep
->sensor_name
;
420 err
= ptree_create_and_add_node(nodeh
, nodename
,
421 PICL_CLASS_TEMPERATURE_SENSOR
, &cnodeh
);
424 "Creating PICL sensor node '%s' err:%d\n",
426 if (err
!= PICL_SUCCESS
)
429 /* save node handle */
430 snodep
->nodeh
= cnodeh
;
433 * Add "devfs_path" property in child node
435 devfs_path
= sensorp
->devfs_path
;
436 pname
= PICL_PROP_DEVFS_PATH
;
437 err
= add_regular_prop(cnodeh
, pname
,
438 PICL_PTYPE_CHARSTRING
, PICL_READ
,
439 strlen(devfs_path
)+1, (void *)devfs_path
, &proph
);
440 if (err
!= PICL_SUCCESS
)
444 * Now add volatile "temperature" volatile property
445 * in this "temperature-sensor" class node.
447 pname
= PICL_PROP_TEMPERATURE
;
448 err
= add_volatile_prop(cnodeh
, pname
,
449 PICL_PTYPE_INT
, PICL_READ
, sizeof (tempr_t
),
450 get_current_temp
, NULL
, &proph
);
451 if (err
!= PICL_SUCCESS
)
454 /* Save prop handle */
455 snodep
->proph
= proph
;
458 * Add threshold related properties
460 sensor_blkp
= sensorp
->es
;
461 if (sensor_blkp
!= NULL
)
462 add_sensor_thresh_props(cnodeh
, sensor_blkp
);
465 if (err
!= PICL_SUCCESS
) {
466 delete_sensor_nodes_and_props();
469 "Can't create prop/node for sensor '%s'\n",
473 return (PICL_SUCCESS
);
477 * Delete all sensor nodes and related properties created by the
478 * add_sensor_prop() for each sensor node in the PICL tree.
481 delete_sensor_nodes_and_props(void)
483 sensor_node_t
*snodep
;
487 * Delete/destroy any property created in the sensed device
488 * as well as the sensor node and all properties under it.
489 * Note that deleiing/destroying a node deletes/destroys
490 * all properties within that node.
493 for (i
= 0; i
< N_SENSOR_NODES
; i
++) {
494 snodep
= &sensor_nodes
[i
];
495 if (snodep
->nodeh
!= NULL
) {
496 /* delete node and all properties under it */
497 (void) ptree_delete_node(snodep
->nodeh
);
498 (void) ptree_destroy_node(snodep
->nodeh
);
499 snodep
->nodeh
= NULL
;
500 snodep
->proph
= NULL
;
506 * Go through the disk_nodes array and create those nodes
507 * and the Temperature property to report the temperature.
510 add_disk_nodes_and_props()
513 char *pname
, *nodename
, *devfs_path
;
515 picl_nodehdl_t nodeh
, cnodeh
;
516 picl_prophdl_t proph
;
520 for (i
= 0; i
< N_DISK_NODES
; i
++) {
522 envd_log(LOG_ERR
, "adding disk nodes...\n");
523 dnodep
= &disk_nodes
[i
];
525 * Get the parent nodeh
527 err
= ptree_get_node_by_path(dnodep
->parent_path
, &nodeh
);
528 if (err
!= PICL_SUCCESS
) {
531 "failed to get node for path %s\n",
532 dnodep
->parent_path
);
537 diskp
= dnodep
->diskp
;
540 if (diskp
->present
== B_FALSE
)
543 * Create temperature-sensor node
545 nodename
= dnodep
->disk_name
;
546 err
= ptree_create_and_add_node(nodeh
, nodename
,
547 PICL_CLASS_TEMPERATURE_SENSOR
, &cnodeh
);
550 "Creating PICL disk node '%s' err:%d\n",
552 if (err
!= PICL_SUCCESS
)
555 /* save node handle */
556 dnodep
->nodeh
= cnodeh
;
559 * Add "devfs_path" property in child node
561 devfs_path
= diskp
->devfs_path
;
562 pname
= PICL_PROP_DEVFS_PATH
;
563 err
= add_regular_prop(cnodeh
, pname
,
564 PICL_PTYPE_CHARSTRING
, PICL_READ
,
565 strlen(devfs_path
)+1, (void *)devfs_path
, &proph
);
566 if (err
!= PICL_SUCCESS
)
570 * Now add volatile "temperature" volatile property
571 * in this "temperature-sensor" class node.
573 pname
= PICL_PROP_TEMPERATURE
;
574 err
= add_volatile_prop(cnodeh
, pname
,
575 PICL_PTYPE_INT
, PICL_READ
, sizeof (tempr_t
),
576 get_disk_temp
, NULL
, &proph
);
577 if (err
!= PICL_SUCCESS
)
580 /* Save prop handle */
581 dnodep
->proph
= proph
;
584 * Add threshold related properties
587 (void) add_regular_prop(cnodeh
, PICL_PROP_LOW_SHUTDOWN
,
588 PICL_PTYPE_INT
, PICL_READ
,
589 sizeof (diskp
->low_shutdown
),
590 (void *)&(diskp
->low_shutdown
), &proph
);
592 (void) add_regular_prop(cnodeh
, PICL_PROP_LOW_WARNING
,
593 PICL_PTYPE_INT
, PICL_READ
,
594 sizeof (diskp
->low_warning
),
595 (void *)&(diskp
->low_warning
), &proph
);
597 (void) add_regular_prop(cnodeh
, PICL_PROP_HIGH_WARNING
,
598 PICL_PTYPE_INT
, PICL_READ
,
599 sizeof (diskp
->high_warning
),
600 (void *)&(diskp
->high_warning
), &proph
);
602 (void) add_regular_prop(cnodeh
, PICL_PROP_HIGH_SHUTDOWN
,
603 PICL_PTYPE_INT
, PICL_READ
,
604 sizeof (diskp
->high_shutdown
),
605 (void *)&(diskp
->high_shutdown
), &proph
);
608 if (err
!= PICL_SUCCESS
) {
609 delete_disk_nodes_and_props();
612 "Can't create prop/node for disk '%s'\n",
616 return (PICL_SUCCESS
);
620 * Delete all disk nodes and related properties created by the
621 * add_disk_props() for each disk node in the PICL tree.
624 delete_disk_nodes_and_props(void)
630 * Delete/destroy disk node and all properties under it.
631 * Note that deleting/destroying a node deletes/destroys
632 * all properties within that node.
635 for (i
= 0; i
< N_DISK_NODES
; i
++) {
636 dnodep
= &disk_nodes
[i
];
637 if (dnodep
->nodeh
!= NULL
) {
638 (void) ptree_delete_node(dnodep
->nodeh
);
639 (void) ptree_destroy_node(dnodep
->nodeh
);
640 dnodep
->nodeh
= NULL
;
641 dnodep
->proph
= NULL
;
647 * For each entry in fan_nodes[] array, do the following:
648 * - Create specified "fan" class node.
649 * - Create "Speed" volatile propery under "fan" class node.
650 * - Create "SpeedUnit" property under "fan" class node.
653 add_fan_nodes_and_props()
655 int err
= PICL_FAILURE
;
656 char *pname
, *nodename
, *devfs_path
;
659 picl_nodehdl_t nodeh
, cnodeh
;
660 picl_prophdl_t proph
;
663 for (i
= 0; i
< N_FAN_NODES
; i
++) {
665 * Add various fan nodes and properties
667 fnodep
= &fan_nodes
[i
];
670 if (fnodep
->fanp
== NULL
)
672 if (fnodep
->fanp
->present
== B_FALSE
)
677 err
= ptree_get_node_by_path(fnodep
->parent_path
, &nodeh
);
678 if (err
!= PICL_SUCCESS
) {
681 "node for %s NOT FOUND.\n", fnodep
->parent_path
);
686 * Create "fan" class node and save node handle
688 nodename
= fnodep
->fan_name
;
689 err
= ptree_create_and_add_node(nodeh
, nodename
,
690 PICL_CLASS_FAN
, &cnodeh
);
693 "Creating PICL fan node '%s' err:%d\n",
696 if (err
!= PICL_SUCCESS
)
698 fnodep
->nodeh
= cnodeh
;
701 * Add "devfs_path" property in child node
704 devfs_path
= fanp
->devfs_path
;
705 pname
= PICL_PROP_DEVFS_PATH
;
706 err
= add_regular_prop(cnodeh
, pname
,
707 PICL_PTYPE_CHARSTRING
, PICL_READ
,
708 strlen(devfs_path
)+1, (void *)devfs_path
, &proph
);
710 if (err
!= PICL_SUCCESS
)
715 * Add "Speed" volatile property in this "fan"
716 * class node and save prop handle.
718 pname
= PICL_PROP_FAN_SPEED
;
720 err
= add_volatile_prop(cnodeh
, pname
, PICL_PTYPE_INT
,
721 PICL_READ
|PICL_WRITE
, sizeof (fanspeed_t
),
722 get_current_speed
, set_current_speed
, &proph
);
724 if (err
!= PICL_SUCCESS
)
726 fnodep
->proph
= proph
;
729 * Add other "fan" class properties
731 pname
= PICL_PROP_FAN_SPEED_UNIT
;
732 err
= add_regular_prop(cnodeh
, pname
,
733 PICL_PTYPE_CHARSTRING
, PICL_READ
,
734 strlen(fnodep
->speed_unit
)+1,
735 (void *)fnodep
->speed_unit
, &proph
);
737 if (err
!= PICL_SUCCESS
)
740 pname
= PICL_PROP_LOW_WARNING
;
741 err
= add_regular_prop(cnodeh
, pname
,
742 PICL_PTYPE_INT
, PICL_READ
,
744 &(fnodep
->fanp
->speed_min
), &proph
);
746 if (err
!= PICL_SUCCESS
)
749 if (err
!= PICL_SUCCESS
) {
750 delete_fan_nodes_and_props();
753 return (PICL_SUCCESS
);
758 * Delete all fan nodes and related properties created by the
759 * add_fan_props() for each fan node in the PICL tree.
762 delete_fan_nodes_and_props(void)
768 * Delete/destroy fan node and all properties under it.
769 * Note that deleting/destroying a node deletes/destroys
770 * all properties within that node.
773 for (i
= 0; i
< N_FAN_NODES
; i
++) {
774 fnodep
= &fan_nodes
[i
];
775 if (fnodep
->nodeh
!= NULL
) {
776 (void) ptree_delete_node(fnodep
->nodeh
);
777 (void) ptree_destroy_node(fnodep
->nodeh
);
778 fnodep
->nodeh
= NULL
;
783 * Tuneables publishing functions
786 copy_persistent_tuneable(env_tuneable_t
*tune
, char *buf
)
789 switch (tune
->type
) {
790 case PICL_PTYPE_INT
: {
791 (void) memcpy((int *)tune
->value
,
795 case PICL_PTYPE_CHARSTRING
: {
796 (void) memcpy((caddr_t
)tune
->value
,
801 return (PICL_FAILURE
);
804 return (PICL_SUCCESS
);
808 env_parse_tunables(picl_nodehdl_t rooth
)
810 char nmbuf
[SYS_NMLN
];
811 char pname
[PATH_MAX
];
813 if (sysinfo(SI_PLATFORM
, nmbuf
, sizeof (nmbuf
)) != -1) {
814 (void) snprintf(pname
, PATH_MAX
, PICLD_PLAT_PLUGIN_DIRF
, nmbuf
);
815 (void) strlcat(pname
, TUNABLE_CONF_FILE
, PATH_MAX
);
816 if (access(pname
, R_OK
) == 0) {
817 (void) picld_pluginutil_parse_config_file(rooth
, pname
);
824 env_picl_setup_tuneables(void)
828 picl_nodehdl_t nodeh
;
829 picl_nodehdl_t rooth
;
830 picl_prophdl_t proph
;
831 env_tuneable_t
*tuneablep
;
832 char read_buf
[BUFSIZ
];
834 if (ptree_get_root(&rooth
) != PICL_SUCCESS
) {
835 return (PICL_FAILURE
);
837 err
= ptree_create_and_add_node(rooth
, PICL_PLUGINS_NODE
,
838 PICL_CLASS_PICL
, &nodeh
);
839 if (err
!= PICL_SUCCESS
)
840 return (PICL_FAILURE
);
841 err
= ptree_create_and_add_node(nodeh
, PICL_ENVIRONMENTAL_NODE
,
842 PICL_CLASS_PICL
, &nodeh
);
843 if (err
!= PICL_SUCCESS
) {
844 return (PICL_FAILURE
);
848 * Parse the conf file
851 envd_log(LOG_ERR
, "parsing tuneables...\n");
852 env_parse_tunables(rooth
);
853 for (i
= 0; i
< ntuneables
; i
++) {
855 envd_log(LOG_ERR
, "tuneable %d being added\n", i
);
856 tuneablep
= &tuneables
[i
];
857 err
= ptree_get_propval_by_name(nodeh
, tuneablep
->name
,
858 read_buf
, tuneablep
->nbytes
);
860 if (err
!= PICL_SUCCESS
) {
862 * Add volitle functions to environmental node
864 err
= add_volatile_prop(nodeh
, tuneablep
->name
,
866 PICL_READ
|PICL_WRITE
, tuneablep
->nbytes
,
868 tuneablep
->wfunc
, &proph
);
870 tuneablep
->proph
= proph
;
873 * property is persistent
875 (void) copy_persistent_tuneable(tuneablep
,
880 return (PICL_SUCCESS
);
884 * Find the ENVMODEL_CONF_FILE file.
887 get_envmodel_conf_file(char *outfilename
)
889 char nmbuf
[SYS_NMLN
];
890 char pname
[PATH_MAX
];
892 if (sysinfo(SI_PLATFORM
, nmbuf
, sizeof (nmbuf
)) != -1) {
893 (void) snprintf(pname
, PATH_MAX
, PICLD_PLAT_PLUGIN_DIRF
, nmbuf
);
894 (void) strlcat(pname
, ENV_CONF_FILE
, PATH_MAX
);
895 if (access(pname
, R_OK
) == 0) {
896 (void) strlcpy(outfilename
, pname
, PATH_MAX
);
901 if (sysinfo(SI_MACHINE
, nmbuf
, sizeof (nmbuf
)) != -1) {
902 (void) snprintf(pname
, PATH_MAX
, PICLD_PLAT_PLUGIN_DIRF
, nmbuf
);
903 (void) strlcat(pname
, ENV_CONF_FILE
, PATH_MAX
);
904 if (access(pname
, R_OK
) == 0) {
905 (void) strlcpy(outfilename
, pname
, PATH_MAX
);
910 (void) snprintf(pname
, PATH_MAX
, "%s/%s", PICLD_COMMON_PLUGIN_DIR
,
913 if (access(pname
, R_OK
) == 0) {
914 (void) strlcpy(outfilename
, pname
, PATH_MAX
);
921 /* Delete all sensor/fan nodes and any properties created by this plugin */
923 env_picl_destroy(void)
925 delete_fan_nodes_and_props();
926 delete_sensor_nodes_and_props();
927 delete_disk_nodes_and_props();
933 int err
, sensor_err
, fan_err
, disk_err
;
934 sensor_node_t
*snodep
;
937 picl_nodehdl_t plath
;
938 char fullfilename
[PATH_MAX
];
939 picl_nodehdl_t rooth
;
944 * Initialize sensorp and other fields in the sensor_nodes[] array
947 for (i
= 0; i
< N_SENSOR_NODES
; i
++) {
948 snodep
= &sensor_nodes
[i
];
949 snodep
->sensorp
= sensor_lookup(snodep
->sensor_name
);
950 snodep
->nodeh
= NULL
;
951 snodep
->proph
= NULL
;
952 snodep
->target_proph
= NULL
;
956 * Initialize fanp and other fields in the fan_nodes[] array
958 for (i
= 0; i
< N_FAN_NODES
; i
++) {
959 fnodep
= &fan_nodes
[i
];
960 fnodep
->fanp
= fan_lookup(fnodep
->fan_name
);
961 fnodep
->nodeh
= NULL
;
962 fnodep
->proph
= NULL
;
966 * Initialize diskp and other fields in the disk_nodes[] array
968 for (i
= 0; i
< N_DISK_NODES
; i
++) {
969 dnodep
= &disk_nodes
[i
];
970 dnodep
->diskp
= disk_lookup(dnodep
->disk_name
);
971 dnodep
->nodeh
= NULL
;
972 dnodep
->proph
= NULL
;
976 * Get platform handle and populate PICL tree with environmental
977 * nodes and properties
979 err
= ptree_get_node_by_path("/platform", &plath
);
981 if (err
== PICL_SUCCESS
) {
982 sensor_err
= add_sensor_nodes_and_props();
983 fan_err
= add_fan_nodes_and_props();
984 if (disk_temp_monitor
)
985 disk_err
= add_disk_nodes_and_props();
989 * We can safely call delete_xxx_nodes_and_props even
990 * if nodes were not added.
993 if (err
!= PICL_SUCCESS
) {
994 if (fan_err
!= PICL_SUCCESS
)
995 delete_fan_nodes_and_props();
996 if (disk_err
!= PICL_SUCCESS
)
997 delete_disk_nodes_and_props();
998 if (sensor_err
!= PICL_SUCCESS
)
999 delete_sensor_nodes_and_props();
1001 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);
1005 envd_log(LOG_ERR
, "parsing the envmodel.conf file...\n");
1008 * Parse the envmodel.conf file and populate the PICL tree
1010 if (get_envmodel_conf_file(fullfilename
) < 0)
1011 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);
1012 if (ptree_get_root(&rooth
) != PICL_SUCCESS
)
1013 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);
1014 err
= picld_pluginutil_parse_config_file(rooth
, fullfilename
);
1016 if (err
!= PICL_SUCCESS
)
1017 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);