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"
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 monitor_disk_temp
;
64 extern sensor_ctrl_blk_t sensor_ctrl
[];
65 extern fan_ctrl_blk_t fan_ctrl
[];
66 extern env_tuneable_t tuneables
[];
68 extern int ntuneables
;
69 #define PROP_FAN_SPEED_UNIT_VALUE "rpm"
74 * Sensor node data structure
77 char *parent_path
; /* parent path */
78 char *sensor_name
; /* sensor name */
79 env_sensor_t
*sensorp
; /* sensor info */
80 picl_nodehdl_t nodeh
; /* sensor node handle */
81 picl_prophdl_t proph
; /* "Temperature" property handle */
82 picl_prophdl_t target_proph
; /* "TargetTemp" property handle */
89 static sensor_node_t sensor_nodes
[] = {
90 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
91 SENSOR_CPU0_DIE
, NULL
, NULL
, NULL
, NULL
},
93 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
94 SENSOR_CPU1_DIE
, NULL
, NULL
, NULL
, NULL
},
96 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
97 SENSOR_INT_AMB_0
, NULL
, NULL
, NULL
, NULL
},
99 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
100 SENSOR_SYS_OUT
, NULL
, NULL
, NULL
, NULL
},
102 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
103 SENSOR_SYS_IN
, NULL
, NULL
, NULL
, NULL
},
105 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
106 SENSOR_INT_AMB_1
, NULL
, NULL
, NULL
, NULL
},
109 #define N_SENSOR_NODES (sizeof (sensor_nodes)/sizeof (sensor_nodes[0]))
113 * Fan node data structure
116 char *parent_path
; /* parent node path */
117 char *fan_name
; /* fan name */
118 env_fan_t
*fanp
; /* fan information */
119 char *speed_unit
; /* speed unit string */
120 picl_nodehdl_t nodeh
; /* "fan" node handle */
121 picl_prophdl_t proph
; /* "Speed" property handle */
128 static fan_node_t fan_nodes
[] = {
129 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
130 ENV_CPU0_FAN
, NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
132 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58",
133 ENV_CPU1_FAN
, NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
135 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
136 ENV_SYSTEM_OUT_FAN
, NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
138 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
139 ENV_SYSTEM_INTAKE_FAN
, NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
141 {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,52",
142 ENV_DIMM_FAN
, NULL
, PROP_FAN_SPEED_UNIT_VALUE
, NULL
, NULL
},
145 #define N_FAN_NODES (sizeof (fan_nodes)/sizeof (fan_nodes[0]))
148 * Disk node data structure
151 char *parent_path
; /* parent node path */
152 char *disk_name
; /* disk name */
153 env_disk_t
*diskp
; /* disk information */
154 picl_nodehdl_t nodeh
; /* "disk" node handle */
155 picl_prophdl_t proph
; /* "Temperature" property handle */
161 static disk_node_t disk_nodes
[] = {
162 {DISK0_NODE_PATH
, ENV_DISK0
, NULL
, NULL
, NULL
},
163 {DISK1_NODE_PATH
, ENV_DISK1
, NULL
, NULL
, NULL
},
165 #define N_DISK_NODES (sizeof (disk_nodes)/sizeof (disk_nodes[0]))
168 * Miscellaneous declarations
170 static void delete_sensor_nodes_and_props(void);
171 static void delete_disk_nodes_and_props(void);
172 static void delete_fan_nodes_and_props(void);
176 * Read function for volatile "Temperature" property
179 get_current_temp(ptree_rarg_t
*parg
, void *buf
)
182 picl_prophdl_t proph
;
183 sensor_node_t
*snodep
;
187 * Locate the sensor in our sensor_nodes table by matching the
188 * property handle and get its temperature.
191 for (i
= 0; i
< N_SENSOR_NODES
; ++i
) {
192 snodep
= &sensor_nodes
[i
];
193 if (snodep
->proph
!= proph
)
196 if (get_temperature(snodep
->sensorp
, &temp
) < 0)
198 (void) memcpy(buf
, (caddr_t
)&temp
, sizeof (tempr_t
));
199 return (PICL_SUCCESS
);
201 return (PICL_FAILURE
);
205 * Read function for volatile "Temperature" property
208 get_disk_temp(ptree_rarg_t
*parg
, void *buf
)
211 picl_prophdl_t proph
;
216 * Locate the sensor in our sensor_nodes table by matching the
217 * property handle and get its temperature.
220 for (i
= 0; i
< N_DISK_NODES
; ++i
) {
221 dnodep
= &disk_nodes
[i
];
222 if (dnodep
->proph
!= proph
)
225 if (disk_temperature(dnodep
->diskp
, &temp
) < 0)
227 (void) memcpy(buf
, (caddr_t
)&temp
, sizeof (tempr_t
));
228 return (PICL_SUCCESS
);
230 return (PICL_FAILURE
);
234 * Read function for volatile "Speed" property on "fan" class node
237 set_current_speed(ptree_warg_t
*parg
, const void *buf
)
240 picl_prophdl_t proph
;
245 * Locate the fan in our fan_nodes table by matching the
246 * property handle and get fan speed.
249 for (i
= 0; i
< N_FAN_NODES
; ++i
) {
250 fnodep
= &fan_nodes
[i
];
251 if (fnodep
->proph
!= proph
)
253 if (fnodep
->fanp
->fd
== -1)
256 (void) memcpy((caddr_t
)&speed
, buf
, sizeof (speed
));
258 ret
= set_fan_speed(fnodep
->fanp
, speed
);
261 if (ret
== -1 && errno
== EBUSY
)
262 return (PICL_NOTWRITABLE
);
264 return (PICL_INVALIDARG
);
269 return (PICL_SUCCESS
);
271 return (PICL_FAILURE
);
276 * Read function for volatile "Speed" property on "fan" class node
279 get_current_speed(ptree_rarg_t
*parg
, void *buf
)
282 picl_prophdl_t proph
;
287 * Locate the fan in our fan_nodes table by matching the
288 * property handle and get fan speed.
291 for (i
= 0; i
< N_FAN_NODES
; ++i
) {
292 fnodep
= &fan_nodes
[i
];
293 if (fnodep
->proph
!= proph
)
295 if (fnodep
->fanp
->fd
== -1)
297 if (get_fan_speed(fnodep
->fanp
, &speed
) < 0)
300 (void) memcpy(buf
, (caddr_t
)&speed
, sizeof (speed
));
301 return (PICL_SUCCESS
);
303 return (PICL_FAILURE
);
307 * Create and add the specified regular property
311 add_regular_prop(picl_nodehdl_t nodeh
, char *name
, int type
, int access
,
312 int size
, void *valbuf
, picl_prophdl_t
*prophp
)
315 ptree_propinfo_t propinfo
;
316 picl_prophdl_t proph
;
318 err
= ptree_init_propinfo(&propinfo
, PTREE_PROPINFO_VERSION
,
319 type
, access
, size
, name
, NULL
, NULL
);
320 if (err
!= PICL_SUCCESS
)
323 err
= ptree_create_and_add_prop(nodeh
, &propinfo
, valbuf
, &proph
);
324 if (err
== PICL_SUCCESS
&& prophp
)
331 * Create and add the specified volatile property
334 add_volatile_prop(picl_nodehdl_t nodeh
, char *name
, int type
, int access
,
335 int size
, ptree_vol_rdfunc_t
*rdfunc
, ptree_vol_wrfunc_t
*wrfunc
,
336 picl_prophdl_t
*prophp
)
339 ptree_propinfo_t propinfo
;
340 picl_prophdl_t proph
;
342 err
= ptree_init_propinfo(&propinfo
, PTREE_PROPINFO_VERSION
,
343 type
, (access
|PICL_VOLATILE
), size
, name
, rdfunc
, wrfunc
);
344 if (err
!= PICL_SUCCESS
)
347 err
= ptree_create_and_add_prop(nodeh
, &propinfo
, NULL
, &proph
);
348 if (err
== PICL_SUCCESS
&& prophp
)
354 * Add temperature threshold properties
357 add_sensor_thresh_props(picl_nodehdl_t nodeh
, sensor_ctrl_blk_t
*threshp
)
359 picl_prophdl_t proph
;
361 (void) add_regular_prop(nodeh
, PICL_PROP_LOW_POWER_OFF
,
362 PICL_PTYPE_INT
, PICL_READ
,
363 sizeof (threshp
->low_power_off
),
364 (void *)&(threshp
->low_power_off
), &proph
);
366 (void) add_regular_prop(nodeh
, PICL_PROP_LOW_SHUTDOWN
,
367 PICL_PTYPE_INT
, PICL_READ
,
368 sizeof (threshp
->low_shutdown
),
369 (void *)&(threshp
->low_shutdown
), &proph
);
371 (void) add_regular_prop(nodeh
, PICL_PROP_LOW_WARNING
,
372 PICL_PTYPE_INT
, PICL_READ
,
373 sizeof (threshp
->low_warning
),
374 (void *)&(threshp
->low_warning
), &proph
);
376 (void) add_regular_prop(nodeh
, PICL_PROP_HIGH_WARNING
,
377 PICL_PTYPE_INT
, PICL_READ
,
378 sizeof (threshp
->high_warning
),
379 (void *)&(threshp
->high_warning
), &proph
);
381 (void) add_regular_prop(nodeh
, PICL_PROP_HIGH_SHUTDOWN
,
382 PICL_PTYPE_INT
, PICL_READ
,
383 sizeof (threshp
->high_shutdown
),
384 (void *)&(threshp
->high_shutdown
), &proph
);
386 (void) add_regular_prop(nodeh
, PICL_PROP_HIGH_POWER_OFF
,
387 PICL_PTYPE_INT
, PICL_READ
,
388 sizeof (threshp
->high_power_off
),
389 (void *)&(threshp
->high_power_off
), &proph
);
394 * Go through the sensor_nodes array and create those nodes
395 * and the Temperature property to report the temperature.
398 add_sensor_nodes_and_props()
401 char *pname
, *nodename
, *devfs_path
;
402 sensor_node_t
*snodep
;
403 sensor_ctrl_blk_t
*threshp
;
404 picl_nodehdl_t nodeh
, cnodeh
;
405 picl_prophdl_t proph
;
406 env_sensor_t
*sensorp
;
409 for (i
= 0; i
< N_SENSOR_NODES
; ++i
) {
410 snodep
= &sensor_nodes
[i
];
412 * Get the parent nodeh
414 err
= ptree_get_node_by_path(snodep
->parent_path
, &nodeh
);
415 if (err
!= PICL_SUCCESS
)
417 sensorp
= snodep
->sensorp
;
418 if (sensorp
->present
== B_FALSE
)
421 * Create temperature-sensor node
423 nodename
= snodep
->sensor_name
;
424 err
= ptree_create_and_add_node(nodeh
, nodename
,
425 PICL_CLASS_TEMPERATURE_SENSOR
, &cnodeh
);
428 "Creating PICL sensor node '%s' err:%d\n",
430 if (err
!= PICL_SUCCESS
)
433 /* save node handle */
434 snodep
->nodeh
= cnodeh
;
437 * Add "devfs_path" property in child node
439 devfs_path
= sensorp
->devfs_path
;
440 pname
= PICL_PROP_DEVFS_PATH
;
441 err
= add_regular_prop(cnodeh
, pname
,
442 PICL_PTYPE_CHARSTRING
, PICL_READ
,
443 strlen(devfs_path
)+1, (void *)devfs_path
, &proph
);
444 if (err
!= PICL_SUCCESS
)
448 * Now add volatile "temperature" volatile property
449 * in this "temperature-sensor" class node.
451 pname
= PICL_PROP_TEMPERATURE
;
452 err
= add_volatile_prop(cnodeh
, pname
,
453 PICL_PTYPE_INT
, PICL_READ
, sizeof (tempr_t
),
454 get_current_temp
, NULL
, &proph
);
455 if (err
!= PICL_SUCCESS
)
458 /* Save prop handle */
459 snodep
->proph
= proph
;
462 * Add threshold related properties
464 threshp
= sensorp
->es_ptr
;
467 add_sensor_thresh_props(cnodeh
, threshp
);
470 if (err
!= PICL_SUCCESS
) {
471 delete_sensor_nodes_and_props();
474 "Can't create prop/node for sensor '%s'\n",
478 return (PICL_SUCCESS
);
482 * Delete all sensor nodes and related properties created by the
483 * add_sensor_prop() for each sensor node in the PICL tree.
486 delete_sensor_nodes_and_props(void)
488 sensor_node_t
*snodep
;
492 * Delete/destroy any property created in the sensed device
493 * as well as the sensor node and all properties under it.
494 * Note that deleiing/destroying a node deletes/destroys
495 * all properties within that node.
498 for (i
= 0; i
< N_SENSOR_NODES
; ++i
) {
499 snodep
= &sensor_nodes
[i
];
500 if (snodep
->nodeh
!= NULL
) {
501 /* delete node and all properties under it */
502 (void) ptree_delete_node(snodep
->nodeh
);
503 (void) ptree_destroy_node(snodep
->nodeh
);
504 snodep
->nodeh
= NULL
;
505 snodep
->proph
= NULL
;
511 * Go through the disk_nodes array and create those nodes
512 * and the Temperature property to report the temperature.
515 add_disk_nodes_and_props()
518 char *pname
, *nodename
, *devfs_path
;
520 picl_nodehdl_t nodeh
, cnodeh
;
521 picl_prophdl_t proph
;
525 for (i
= 0; i
< N_DISK_NODES
; ++i
) {
526 dnodep
= &disk_nodes
[i
];
528 * Get the parent nodeh
530 err
= ptree_get_node_by_path(dnodep
->parent_path
, &nodeh
);
531 if (err
!= PICL_SUCCESS
) {
533 envd_log(LOG_ERR
, "failed to get node for path %s\n",
534 dnodep
->parent_path
);
538 diskp
= dnodep
->diskp
;
539 if (diskp
->present
== B_FALSE
)
542 * Create temperature-sensor node
544 nodename
= dnodep
->disk_name
;
545 err
= ptree_create_and_add_node(nodeh
, nodename
,
546 PICL_CLASS_TEMPERATURE_SENSOR
, &cnodeh
);
549 "Creating PICL disk node '%s' err:%d\n",
551 if (err
!= PICL_SUCCESS
)
554 /* save node handle */
555 dnodep
->nodeh
= cnodeh
;
558 * Add "devfs_path" property in child node
560 devfs_path
= diskp
->devfs_path
;
561 pname
= PICL_PROP_DEVFS_PATH
;
562 err
= add_regular_prop(cnodeh
, pname
,
563 PICL_PTYPE_CHARSTRING
, PICL_READ
,
564 strlen(devfs_path
)+1, (void *)devfs_path
, &proph
);
565 if (err
!= PICL_SUCCESS
)
569 * Now add volatile "temperature" volatile property
570 * in this "temperature-sensor" class node.
572 pname
= PICL_PROP_TEMPERATURE
;
573 err
= add_volatile_prop(cnodeh
, pname
,
574 PICL_PTYPE_INT
, PICL_READ
, sizeof (tempr_t
),
575 get_disk_temp
, NULL
, &proph
);
576 if (err
!= PICL_SUCCESS
)
579 /* Save prop handle */
580 dnodep
->proph
= proph
;
583 * Add threshold related properties
586 (void) add_regular_prop(cnodeh
, PICL_PROP_LOW_SHUTDOWN
,
587 PICL_PTYPE_INT
, PICL_READ
,
588 sizeof (diskp
->low_shutdown
),
589 (void *)&(diskp
->low_shutdown
), &proph
);
591 (void) add_regular_prop(cnodeh
, PICL_PROP_LOW_WARNING
,
592 PICL_PTYPE_INT
, PICL_READ
,
593 sizeof (diskp
->low_warning
),
594 (void *)&(diskp
->low_warning
), &proph
);
596 (void) add_regular_prop(cnodeh
, PICL_PROP_HIGH_WARNING
,
597 PICL_PTYPE_INT
, PICL_READ
,
598 sizeof (diskp
->high_warning
),
599 (void *)&(diskp
->high_warning
), &proph
);
601 (void) add_regular_prop(cnodeh
, PICL_PROP_HIGH_SHUTDOWN
,
602 PICL_PTYPE_INT
, PICL_READ
,
603 sizeof (diskp
->high_shutdown
),
604 (void *)&(diskp
->high_shutdown
), &proph
);
607 if (err
!= PICL_SUCCESS
) {
608 delete_disk_nodes_and_props();
611 "Can't create prop/node for disk '%s'\n",
615 return (PICL_SUCCESS
);
619 * Delete all disk nodes and related properties created by the
620 * add_disk_props() for each disk node in the PICL tree.
623 delete_disk_nodes_and_props(void)
629 * Delete/destroy disk node and all properties under it.
630 * Note that deleting/destroying a node deletes/destroys
631 * all properties within that node.
634 for (i
= 0; i
< N_DISK_NODES
; ++i
) {
635 dnodep
= &disk_nodes
[i
];
636 if (dnodep
->nodeh
!= NULL
) {
637 (void) ptree_delete_node(dnodep
->nodeh
);
638 (void) ptree_destroy_node(dnodep
->nodeh
);
639 dnodep
->nodeh
= NULL
;
640 dnodep
->proph
= NULL
;
646 * For each entry in fan_nodes[] array, do the following:
647 * - Create specified "fan" class node.
648 * - Create "Speed" volatile propery under "fan" class node.
649 * - Create "SpeedUnit" property under "fan" class node.
652 add_fan_nodes_and_props()
655 char *pname
, *nodename
, *devfs_path
;
658 picl_nodehdl_t nodeh
, cnodeh
;
659 picl_prophdl_t proph
;
662 for (i
= 0; i
< N_FAN_NODES
; ++i
) {
664 * Add various fan nodes and properties
666 fnodep
= &fan_nodes
[i
];
667 if (fnodep
->fanp
->present
== B_FALSE
)
672 err
= ptree_get_node_by_path(fnodep
->parent_path
, &nodeh
);
673 if (err
!= PICL_SUCCESS
) {
676 "node for %s NOT FOUND.\n", fnodep
->parent_path
);
681 * Create "fan" class node and save node handle
683 nodename
= fnodep
->fan_name
;
684 err
= ptree_create_and_add_node(nodeh
, nodename
,
685 PICL_CLASS_FAN
, &cnodeh
);
688 "Creating PICL fan node '%s' err:%d\n",
691 if (err
!= PICL_SUCCESS
)
693 fnodep
->nodeh
= cnodeh
;
696 * Add "devfs_path" property in child node
699 devfs_path
= fanp
->devfs_path
;
700 pname
= PICL_PROP_DEVFS_PATH
;
701 err
= add_regular_prop(cnodeh
, pname
,
702 PICL_PTYPE_CHARSTRING
, PICL_READ
,
703 strlen(devfs_path
)+1, (void *)devfs_path
, &proph
);
705 if (err
!= PICL_SUCCESS
)
710 * Add "Speed" volatile property in this "fan"
711 * class node and save prop handle.
713 pname
= PICL_PROP_FAN_SPEED
;
714 if (fanp
->id
== DIMM_FAN_ID
) {
716 * We do not permit setting of DIMM FAN speeds.
718 err
= add_volatile_prop(cnodeh
, pname
, PICL_PTYPE_INT
,
719 PICL_READ
, sizeof (fanspeed_t
),
723 err
= add_volatile_prop(cnodeh
, pname
, PICL_PTYPE_INT
,
724 PICL_READ
|PICL_WRITE
, sizeof (fanspeed_t
),
726 set_current_speed
, &proph
);
729 if (err
!= PICL_SUCCESS
)
731 fnodep
->proph
= proph
;
734 * Add other "fan" class properties
736 pname
= PICL_PROP_FAN_SPEED_UNIT
;
737 err
= add_regular_prop(cnodeh
, pname
,
738 PICL_PTYPE_CHARSTRING
, PICL_READ
,
739 strlen(fnodep
->speed_unit
)+1,
740 (void *)fnodep
->speed_unit
, &proph
);
742 if (err
!= PICL_SUCCESS
)
745 if (err
!= PICL_SUCCESS
) {
746 delete_fan_nodes_and_props();
748 envd_log(LOG_WARNING
,
749 "Can't create prop/node for fan '%s'\n",
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
850 env_parse_tunables(rooth
);
851 for (i
= 0; i
< ntuneables
; i
++) {
852 tuneablep
= &tuneables
[i
];
853 err
= ptree_get_propval_by_name(nodeh
, tuneablep
->name
,
854 read_buf
, tuneablep
->nbytes
);
856 if (err
!= PICL_SUCCESS
) {
858 * Add volitle functions to environmental node
860 err
= add_volatile_prop(nodeh
, tuneablep
->name
,
862 PICL_READ
|PICL_WRITE
, tuneablep
->nbytes
,
864 tuneablep
->wfunc
, &proph
);
866 tuneablep
->proph
= proph
;
869 * property is persistent
871 (void) copy_persistent_tuneable(tuneablep
,
876 return (PICL_SUCCESS
);
880 * Find the ENVMODEL_CONF_FILE file.
883 get_envmodel_conf_file(char *outfilename
)
885 char nmbuf
[SYS_NMLN
];
886 char pname
[PATH_MAX
];
888 if (sysinfo(SI_PLATFORM
, nmbuf
, sizeof (nmbuf
)) != -1) {
889 (void) snprintf(pname
, PATH_MAX
, PICLD_PLAT_PLUGIN_DIRF
, nmbuf
);
890 (void) strlcat(pname
, ENV_CONF_FILE
, PATH_MAX
);
891 if (access(pname
, R_OK
) == 0) {
892 (void) strlcpy(outfilename
, pname
, PATH_MAX
);
897 if (sysinfo(SI_MACHINE
, nmbuf
, sizeof (nmbuf
)) != -1) {
898 (void) snprintf(pname
, PATH_MAX
, PICLD_PLAT_PLUGIN_DIRF
, nmbuf
);
899 (void) strlcat(pname
, ENV_CONF_FILE
, PATH_MAX
);
900 if (access(pname
, R_OK
) == 0) {
901 (void) strlcpy(outfilename
, pname
, PATH_MAX
);
906 (void) snprintf(pname
, PATH_MAX
, "%s/%s", PICLD_COMMON_PLUGIN_DIR
,
909 if (access(pname
, R_OK
) == 0) {
910 (void) strlcpy(outfilename
, pname
, PATH_MAX
);
917 /* Delete all sensor/fan nodes and any properties created by this plugin */
919 env_picl_destroy(void)
921 delete_fan_nodes_and_props();
922 delete_sensor_nodes_and_props();
923 delete_disk_nodes_and_props();
930 sensor_node_t
*snodep
;
933 picl_nodehdl_t plath
;
934 char fullfilename
[PATH_MAX
];
935 picl_nodehdl_t rooth
;
940 * Initialize sensorp and other fields in the sensor_nodes[] array
943 for (i
= 0; i
< N_SENSOR_NODES
; ++i
) {
944 snodep
= &sensor_nodes
[i
];
945 snodep
->sensorp
= sensor_lookup(snodep
->sensor_name
);
946 snodep
->nodeh
= NULL
;
947 snodep
->proph
= NULL
;
948 snodep
->target_proph
= NULL
;
952 * Initialize fanp and other fields in the fan_nodes[] array
954 for (i
= 0; i
< N_FAN_NODES
; ++i
) {
955 fnodep
= &fan_nodes
[i
];
956 fnodep
->fanp
= fan_lookup(fnodep
->fan_name
);
957 fnodep
->nodeh
= NULL
;
958 fnodep
->proph
= NULL
;
962 * Initialize diskp and other fields in the disk_nodes[] array
964 for (i
= 0; i
< N_DISK_NODES
; ++i
) {
965 dnodep
= &disk_nodes
[i
];
966 dnodep
->diskp
= disk_lookup(dnodep
->disk_name
);
967 dnodep
->nodeh
= NULL
;
968 dnodep
->proph
= NULL
;
972 * Get platform handle and populate PICL tree with environmental
973 * nodes and properties
975 err
= ptree_get_node_by_path("/platform", &plath
);
977 if (err
== PICL_SUCCESS
)
978 err
= add_sensor_nodes_and_props();
979 if (err
== PICL_SUCCESS
)
980 err
= add_fan_nodes_and_props();
981 if ((err
== PICL_SUCCESS
) && (monitor_disk_temp
))
982 err
= add_disk_nodes_and_props();
985 * We can safely call delete_xxx_nodes_and_props even
986 * if nodes were not added.
989 if (err
!= PICL_SUCCESS
) {
990 delete_fan_nodes_and_props();
991 delete_disk_nodes_and_props();
992 delete_sensor_nodes_and_props();
993 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);
998 * Parse the envmodel.conf file and populate the PICL tree
1000 if (get_envmodel_conf_file(fullfilename
) < 0)
1001 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);
1002 if (ptree_get_root(&rooth
) != PICL_SUCCESS
)
1003 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);
1004 err
= picld_pluginutil_parse_config_file(rooth
, fullfilename
);
1006 if (err
!= PICL_SUCCESS
)
1007 envd_log(LOG_CRIT
, ENVD_PICL_SETUP_FAILED
);