17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * This file contains code for setting up environmental related nodes
297c478bd9Sstevel@tonic-gate * and properties in the PICL tree.
307c478bd9Sstevel@tonic-gate *
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <fcntl.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <syslog.h>
377c478bd9Sstevel@tonic-gate #include <stdlib.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <limits.h>
407c478bd9Sstevel@tonic-gate #include <sys/open.h>
417c478bd9Sstevel@tonic-gate #include <ctype.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include <alloca.h>
447c478bd9Sstevel@tonic-gate #include <libintl.h>
457c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
467c478bd9Sstevel@tonic-gate #include <picl.h>
477c478bd9Sstevel@tonic-gate #include <picltree.h>
487c478bd9Sstevel@tonic-gate #include <picld_pluginutil.h>
497c478bd9Sstevel@tonic-gate #include <pthread.h>
507c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
517c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
527c478bd9Sstevel@tonic-gate #include "picldefs.h"
537c478bd9Sstevel@tonic-gate #include "envd.h"
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate * Volatile property read/write function typedef
577c478bd9Sstevel@tonic-gate */
587c478bd9Sstevel@tonic-gate typedef int ptree_vol_rdfunc_t(ptree_rarg_t *parg, void *buf);
597c478bd9Sstevel@tonic-gate typedef int ptree_vol_wrfunc_t(ptree_warg_t *parg, const void *buf);
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate extern sensor_ctrl_blk_t sensor_ctrl[];
637c478bd9Sstevel@tonic-gate extern fan_ctrl_blk_t fan_ctrl[];
647c478bd9Sstevel@tonic-gate extern env_tuneable_t tuneables[];
657c478bd9Sstevel@tonic-gate extern int ntuneables;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #define PROP_FAN_SPEED_UNIT_VALUE "rpm"
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate * Sensor node data structure
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate typedef struct {
737c478bd9Sstevel@tonic-gate char *parent_path; /* parent path */
747c478bd9Sstevel@tonic-gate char *sensor_name; /* sensor name */
757c478bd9Sstevel@tonic-gate env_sensor_t *sensorp; /* sensor info */
767c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh; /* sensor node handle */
777c478bd9Sstevel@tonic-gate picl_prophdl_t proph; /* "Temperature" property handle */
787c478bd9Sstevel@tonic-gate picl_prophdl_t target_proph; /* "TargetTemp" property handle */
797c478bd9Sstevel@tonic-gate } sensor_node_t;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate * Sensor nodes array
847c478bd9Sstevel@tonic-gate */
857c478bd9Sstevel@tonic-gate static sensor_node_t sensor_nodes[] = {
867c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
877c478bd9Sstevel@tonic-gate SENSOR_CPU_DIE, NULL,
88*ada2da53SToomas Soome 0, 0, 0},
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
917c478bd9Sstevel@tonic-gate SENSOR_INT_AMB, NULL,
92*ada2da53SToomas Soome 0, 0, 0},
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
957c478bd9Sstevel@tonic-gate SENSOR_SYS_IN, NULL,
96*ada2da53SToomas Soome 0, 0, 0}
977c478bd9Sstevel@tonic-gate };
987c478bd9Sstevel@tonic-gate #define NSENSORS (sizeof (sensor_nodes)/sizeof (sensor_nodes[0]))
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate * Fan node data structure
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate typedef struct {
1057c478bd9Sstevel@tonic-gate char *parent_path; /* parent node path */
1067c478bd9Sstevel@tonic-gate char *fan_name; /* fan name */
107*ada2da53SToomas Soome env_fan_t *fanp; /* fan information */
1087c478bd9Sstevel@tonic-gate char *speed_unit; /* speed unit string */
1097c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh; /* "fan" node handle */
1107c478bd9Sstevel@tonic-gate picl_prophdl_t proph; /* "Speed" property handle */
1117c478bd9Sstevel@tonic-gate } fan_node_t;
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * Fan node array
1167c478bd9Sstevel@tonic-gate */
1177c478bd9Sstevel@tonic-gate static fan_node_t fan_nodes[] = {
1187c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
119*ada2da53SToomas Soome ENV_CPU_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
122*ada2da53SToomas Soome ENV_SYSTEM_INTAKE_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0},
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate {"/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c",
125*ada2da53SToomas Soome ENV_SYSTEM_OUT_FAN, NULL, PROP_FAN_SPEED_UNIT_VALUE, 0, 0}
1267c478bd9Sstevel@tonic-gate };
1277c478bd9Sstevel@tonic-gate #define NFANS (sizeof (fan_nodes)/sizeof (fan_nodes[0]))
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * Miscellaneous declarations
1317c478bd9Sstevel@tonic-gate */
1327c478bd9Sstevel@tonic-gate static void delete_sensor_nodes_and_props(void);
1337c478bd9Sstevel@tonic-gate static void delete_fan_nodes_and_props(void);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate * Read function for volatile "Temperature" property
1387c478bd9Sstevel@tonic-gate */
1397c478bd9Sstevel@tonic-gate static int
get_current_temp(ptree_rarg_t * parg,void * buf)1407c478bd9Sstevel@tonic-gate get_current_temp(ptree_rarg_t *parg, void *buf)
1417c478bd9Sstevel@tonic-gate {
142*ada2da53SToomas Soome tempr_t temp;
1437c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
1447c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
1457c478bd9Sstevel@tonic-gate int i;
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate * Locate the sensor in our sensor_nodes table by matching the
1497c478bd9Sstevel@tonic-gate * property handle and get its temperature.
1507c478bd9Sstevel@tonic-gate */
1517c478bd9Sstevel@tonic-gate proph = parg->proph;
1527c478bd9Sstevel@tonic-gate for (i = 0; i < NSENSORS; ++i) {
1537c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
1547c478bd9Sstevel@tonic-gate if (snodep->proph != proph)
1557c478bd9Sstevel@tonic-gate continue;
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate if (get_temperature(snodep->sensorp, &temp) < 0)
1587c478bd9Sstevel@tonic-gate break;
1597c478bd9Sstevel@tonic-gate (void) memcpy(buf, (caddr_t)&temp, sizeof (tempr_t));
1607c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate * Read function for volatile "Speed" property on "fan" class node
1667c478bd9Sstevel@tonic-gate */
1677c478bd9Sstevel@tonic-gate static int
set_current_speed(ptree_warg_t * parg,const void * buf)1687c478bd9Sstevel@tonic-gate set_current_speed(ptree_warg_t *parg, const void *buf)
1697c478bd9Sstevel@tonic-gate {
1707c478bd9Sstevel@tonic-gate fanspeed_t speed;
1717c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
1727c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
1737c478bd9Sstevel@tonic-gate int i, ret;
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * Locate the fan in our fan_nodes table by matching the
1777c478bd9Sstevel@tonic-gate * property handle and get fan speed.
1787c478bd9Sstevel@tonic-gate */
1797c478bd9Sstevel@tonic-gate proph = parg->proph;
1807c478bd9Sstevel@tonic-gate for (i = 0; i < NFANS; ++i) {
1817c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
1827c478bd9Sstevel@tonic-gate if (fnodep->proph != proph)
1837c478bd9Sstevel@tonic-gate continue;
1847c478bd9Sstevel@tonic-gate if (fnodep->fanp->fd == -1)
1857c478bd9Sstevel@tonic-gate continue;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate (void) memcpy((caddr_t)&speed, buf, sizeof (speed));
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate ret = set_fan_speed(fnodep->fanp, speed);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate if (ret < 0) {
1927c478bd9Sstevel@tonic-gate if (ret == -1 && errno == EBUSY)
1937c478bd9Sstevel@tonic-gate return (PICL_NOTWRITABLE);
1947c478bd9Sstevel@tonic-gate if (ret == -2)
1957c478bd9Sstevel@tonic-gate return (PICL_INVALIDARG);
1967c478bd9Sstevel@tonic-gate break;
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate * Read function for volatile "Speed" property on "fan" class node
2077c478bd9Sstevel@tonic-gate */
2087c478bd9Sstevel@tonic-gate static int
get_current_speed(ptree_rarg_t * parg,void * buf)2097c478bd9Sstevel@tonic-gate get_current_speed(ptree_rarg_t *parg, void *buf)
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate fanspeed_t speed;
2127c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2137c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
2147c478bd9Sstevel@tonic-gate int i;
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate /*
2177c478bd9Sstevel@tonic-gate * Locate the fan in our fan_nodes table by matching the
2187c478bd9Sstevel@tonic-gate * property handle and get fan speed.
2197c478bd9Sstevel@tonic-gate */
2207c478bd9Sstevel@tonic-gate proph = parg->proph;
2217c478bd9Sstevel@tonic-gate for (i = 0; i < NFANS; ++i) {
2227c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
2237c478bd9Sstevel@tonic-gate if (fnodep->proph != proph)
2247c478bd9Sstevel@tonic-gate continue;
2257c478bd9Sstevel@tonic-gate if (fnodep->fanp->fd == -1)
2267c478bd9Sstevel@tonic-gate continue;
2277c478bd9Sstevel@tonic-gate if (get_fan_speed(fnodep->fanp, &speed) < 0)
2287c478bd9Sstevel@tonic-gate break;
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate (void) memcpy(buf, (caddr_t)&speed, sizeof (speed));
2317c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate * Create and add the specified regular property
2387c478bd9Sstevel@tonic-gate */
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate static int
add_regular_prop(picl_nodehdl_t nodeh,char * name,int type,int access,int size,void * valbuf,picl_prophdl_t * prophp)2417c478bd9Sstevel@tonic-gate add_regular_prop(picl_nodehdl_t nodeh, char *name, int type, int access,
2427c478bd9Sstevel@tonic-gate int size, void *valbuf, picl_prophdl_t *prophp)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate int err;
2457c478bd9Sstevel@tonic-gate ptree_propinfo_t propinfo;
2467c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION,
2497c478bd9Sstevel@tonic-gate type, access, size, name, NULL, NULL);
2507c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
2517c478bd9Sstevel@tonic-gate return (err);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate err = ptree_create_and_add_prop(nodeh, &propinfo, valbuf, &proph);
2547c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS && prophp)
2557c478bd9Sstevel@tonic-gate *prophp = proph;
2567c478bd9Sstevel@tonic-gate return (err);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate * Create and add the specified volatile property
2627c478bd9Sstevel@tonic-gate */
2637c478bd9Sstevel@tonic-gate static int
add_volatile_prop(picl_nodehdl_t nodeh,char * name,int type,int access,int size,ptree_vol_rdfunc_t * rdfunc,ptree_vol_wrfunc_t * wrfunc,picl_prophdl_t * prophp)2647c478bd9Sstevel@tonic-gate add_volatile_prop(picl_nodehdl_t nodeh, char *name, int type, int access,
2657c478bd9Sstevel@tonic-gate int size, ptree_vol_rdfunc_t *rdfunc, ptree_vol_wrfunc_t *wrfunc,
2667c478bd9Sstevel@tonic-gate picl_prophdl_t *prophp)
2677c478bd9Sstevel@tonic-gate {
2687c478bd9Sstevel@tonic-gate int err;
2697c478bd9Sstevel@tonic-gate ptree_propinfo_t propinfo;
2707c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION,
2737c478bd9Sstevel@tonic-gate type, (access|PICL_VOLATILE), size, name, rdfunc, wrfunc);
2747c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
2757c478bd9Sstevel@tonic-gate return (err);
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate err = ptree_create_and_add_prop(nodeh, &propinfo, NULL, &proph);
2787c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS && prophp)
2797c478bd9Sstevel@tonic-gate *prophp = proph;
2807c478bd9Sstevel@tonic-gate return (err);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate * Add temperature threshold properties
2857c478bd9Sstevel@tonic-gate */
2867c478bd9Sstevel@tonic-gate static void
add_sensor_thresh_props(picl_nodehdl_t nodeh,sensor_ctrl_blk_t * threshp)2877c478bd9Sstevel@tonic-gate add_sensor_thresh_props(picl_nodehdl_t nodeh, sensor_ctrl_blk_t *threshp)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_LOW_POWER_OFF,
2927c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
2937c478bd9Sstevel@tonic-gate sizeof (threshp->low_power_off),
2947c478bd9Sstevel@tonic-gate (void *)&(threshp->low_power_off), &proph);
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_LOW_SHUTDOWN,
2977c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
2987c478bd9Sstevel@tonic-gate sizeof (threshp->low_shutdown),
2997c478bd9Sstevel@tonic-gate (void *)&(threshp->low_shutdown), &proph);
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_LOW_WARNING,
3027c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3037c478bd9Sstevel@tonic-gate sizeof (threshp->low_warning),
3047c478bd9Sstevel@tonic-gate (void *)&(threshp->low_warning), &proph);
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_HIGH_WARNING,
3077c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3087c478bd9Sstevel@tonic-gate sizeof (threshp->high_warning),
3097c478bd9Sstevel@tonic-gate (void *)&(threshp->high_warning), &proph);
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_HIGH_SHUTDOWN,
3127c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3137c478bd9Sstevel@tonic-gate sizeof (threshp->high_shutdown),
3147c478bd9Sstevel@tonic-gate (void *)&(threshp->high_shutdown), &proph);
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate (void) add_regular_prop(nodeh, PICL_PROP_HIGH_POWER_OFF,
3177c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ,
3187c478bd9Sstevel@tonic-gate sizeof (threshp->high_power_off),
3197c478bd9Sstevel@tonic-gate (void *)&(threshp->high_power_off), &proph);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate * Go through the sensor_nodes array and create those nodes
3247c478bd9Sstevel@tonic-gate * and the Temperature property to report the temperature.
3257c478bd9Sstevel@tonic-gate */
3267c478bd9Sstevel@tonic-gate static int
add_sensor_nodes_and_props(void)3277c478bd9Sstevel@tonic-gate add_sensor_nodes_and_props(void)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate int err;
3307c478bd9Sstevel@tonic-gate char *pname, *nodename, *devfs_path;
3317c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
3327c478bd9Sstevel@tonic-gate sensor_ctrl_blk_t *threshp;
3337c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh, cnodeh;
3347c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
3357c478bd9Sstevel@tonic-gate env_sensor_t *sensorp;
3367c478bd9Sstevel@tonic-gate int i;
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate for (i = 0; i < NSENSORS; ++i) {
3397c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate * Get the parent nodeh
3427c478bd9Sstevel@tonic-gate */
3437c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path(snodep->parent_path, &nodeh);
3447c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
3457c478bd9Sstevel@tonic-gate continue;
3467c478bd9Sstevel@tonic-gate sensorp = snodep->sensorp;
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate * Create temperature-sensor node
3507c478bd9Sstevel@tonic-gate */
3517c478bd9Sstevel@tonic-gate nodename = snodep->sensor_name;
3527c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, nodename,
3537c478bd9Sstevel@tonic-gate PICL_CLASS_TEMPERATURE_SENSOR, &cnodeh);
3547c478bd9Sstevel@tonic-gate if (env_debug)
3557c478bd9Sstevel@tonic-gate envd_log(LOG_INFO,
3567c478bd9Sstevel@tonic-gate "Creating PICL sensor node '%s' err:%d\n",
3577c478bd9Sstevel@tonic-gate nodename, err);
3587c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
3597c478bd9Sstevel@tonic-gate break;
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate /* save node handle */
3627c478bd9Sstevel@tonic-gate snodep->nodeh = cnodeh;
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate * Add "devfs_path" property in child node
3667c478bd9Sstevel@tonic-gate */
3677c478bd9Sstevel@tonic-gate devfs_path = sensorp->devfs_path;
3687c478bd9Sstevel@tonic-gate pname = PICL_PROP_DEVFS_PATH;
3697c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
3707c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
3717c478bd9Sstevel@tonic-gate strlen(devfs_path)+1, (void *)devfs_path, &proph);
3727c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
3737c478bd9Sstevel@tonic-gate break;
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate * Now add volatile "temperature" volatile property
3777c478bd9Sstevel@tonic-gate * in this "temperature-sensor" class node.
3787c478bd9Sstevel@tonic-gate */
3797c478bd9Sstevel@tonic-gate pname = PICL_PROP_TEMPERATURE;
3807c478bd9Sstevel@tonic-gate err = add_volatile_prop(cnodeh, pname,
3817c478bd9Sstevel@tonic-gate PICL_PTYPE_INT, PICL_READ, sizeof (tempr_t),
3827c478bd9Sstevel@tonic-gate get_current_temp, NULL, &proph);
3837c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
3847c478bd9Sstevel@tonic-gate break;
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate /* Save prop handle */
3877c478bd9Sstevel@tonic-gate snodep->proph = proph;
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate /*
3907c478bd9Sstevel@tonic-gate * Add threshold related properties
3917c478bd9Sstevel@tonic-gate */
3927c478bd9Sstevel@tonic-gate threshp = sensorp->es_ptr;
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate if (threshp != NULL)
3957c478bd9Sstevel@tonic-gate add_sensor_thresh_props(cnodeh, threshp);
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
3997c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props();
4007c478bd9Sstevel@tonic-gate if (env_debug)
4017c478bd9Sstevel@tonic-gate envd_log(LOG_INFO,
4027c478bd9Sstevel@tonic-gate "Can't create prop/node for sensor '%s'\n",
4037c478bd9Sstevel@tonic-gate nodename);
4047c478bd9Sstevel@tonic-gate return (err);
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate * Delete all sensor nodes and related properties created by the
4117c478bd9Sstevel@tonic-gate * add_sensor_prop() for each sensor node in the PICL tree.
4127c478bd9Sstevel@tonic-gate */
4137c478bd9Sstevel@tonic-gate static void
delete_sensor_nodes_and_props(void)4147c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props(void)
4157c478bd9Sstevel@tonic-gate {
4167c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
4177c478bd9Sstevel@tonic-gate int i;
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate /*
4207c478bd9Sstevel@tonic-gate * Delete/destroy any property created in the sensed device
4217c478bd9Sstevel@tonic-gate * as well as the sensor node and all properties under it.
4227c478bd9Sstevel@tonic-gate * Note that deleiing/destroying a node deletes/destroys
4237c478bd9Sstevel@tonic-gate * all properties within that node.
4247c478bd9Sstevel@tonic-gate */
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate for (i = 0; i < NSENSORS; ++i) {
4277c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
428*ada2da53SToomas Soome if (snodep->nodeh != 0) {
4297c478bd9Sstevel@tonic-gate /* delete node and all properties under it */
4307c478bd9Sstevel@tonic-gate (void) ptree_delete_node(snodep->nodeh);
4317c478bd9Sstevel@tonic-gate (void) ptree_destroy_node(snodep->nodeh);
432*ada2da53SToomas Soome snodep->nodeh = 0;
433*ada2da53SToomas Soome snodep->proph = 0;
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate /*
4407c478bd9Sstevel@tonic-gate * For each entry in fan_nodes[] array, do the following:
4417c478bd9Sstevel@tonic-gate * - Create specified "fan" class node.
4427c478bd9Sstevel@tonic-gate * - Create "Speed" volatile propery under "fan" class node.
4437c478bd9Sstevel@tonic-gate * - Create "SpeedUnit" property under "fan" class node.
4447c478bd9Sstevel@tonic-gate */
4457c478bd9Sstevel@tonic-gate static int
add_fan_nodes_and_props()4467c478bd9Sstevel@tonic-gate add_fan_nodes_and_props()
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate int err;
4497c478bd9Sstevel@tonic-gate char *pname, *nodename, *devfs_path;
4507c478bd9Sstevel@tonic-gate env_fan_t *fanp;
4517c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
4527c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh, cnodeh;
4537c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
4547c478bd9Sstevel@tonic-gate int i;
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate for (i = 0; i < NFANS; ++i) {
4587c478bd9Sstevel@tonic-gate /*
4597c478bd9Sstevel@tonic-gate * Add various fan nodes and properties
4607c478bd9Sstevel@tonic-gate */
4617c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
4627c478bd9Sstevel@tonic-gate /*
4637c478bd9Sstevel@tonic-gate * get parent nodeh
4647c478bd9Sstevel@tonic-gate */
4657c478bd9Sstevel@tonic-gate err = ptree_get_node_by_path(fnodep->parent_path, &nodeh);
4667c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4677c478bd9Sstevel@tonic-gate continue;
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate /*
4707c478bd9Sstevel@tonic-gate * Create "fan" class node and save node handle
4717c478bd9Sstevel@tonic-gate */
4727c478bd9Sstevel@tonic-gate nodename = fnodep->fan_name;
4737c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, nodename,
4747c478bd9Sstevel@tonic-gate PICL_CLASS_FAN, &cnodeh);
4757c478bd9Sstevel@tonic-gate if (env_debug)
4767c478bd9Sstevel@tonic-gate envd_log(LOG_INFO,
4777c478bd9Sstevel@tonic-gate "Creating PICL fan node '%s' err:%d\n",
4787c478bd9Sstevel@tonic-gate nodename, err);
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4817c478bd9Sstevel@tonic-gate break;
4827c478bd9Sstevel@tonic-gate fnodep->nodeh = cnodeh;
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate /*
4857c478bd9Sstevel@tonic-gate * Add "devfs_path" property in child node
4867c478bd9Sstevel@tonic-gate */
4877c478bd9Sstevel@tonic-gate fanp = fnodep->fanp;
4887c478bd9Sstevel@tonic-gate devfs_path = fanp->devfs_path;
4897c478bd9Sstevel@tonic-gate pname = PICL_PROP_DEVFS_PATH;
4907c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
4917c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
4927c478bd9Sstevel@tonic-gate strlen(devfs_path)+1, (void *)devfs_path, &proph);
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate break;
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate * Add "Speed" volatile property in this "fan"
5007c478bd9Sstevel@tonic-gate * class node and save prop handle.
5017c478bd9Sstevel@tonic-gate */
5027c478bd9Sstevel@tonic-gate pname = PICL_PROP_FAN_SPEED;
5037c478bd9Sstevel@tonic-gate err = add_volatile_prop(cnodeh, pname, PICL_PTYPE_INT,
5047c478bd9Sstevel@tonic-gate PICL_READ|PICL_WRITE, sizeof (fanspeed_t),
5057c478bd9Sstevel@tonic-gate get_current_speed,
5067c478bd9Sstevel@tonic-gate set_current_speed, &proph);
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
5097c478bd9Sstevel@tonic-gate break;
5107c478bd9Sstevel@tonic-gate fnodep->proph = proph;
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate /*
5137c478bd9Sstevel@tonic-gate * Add other "fan" class properties
5147c478bd9Sstevel@tonic-gate */
5157c478bd9Sstevel@tonic-gate pname = PICL_PROP_FAN_SPEED_UNIT;
5167c478bd9Sstevel@tonic-gate err = add_regular_prop(cnodeh, pname,
5177c478bd9Sstevel@tonic-gate PICL_PTYPE_CHARSTRING, PICL_READ,
5187c478bd9Sstevel@tonic-gate strlen(fnodep->speed_unit)+1,
5197c478bd9Sstevel@tonic-gate (void *)fnodep->speed_unit, &proph);
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
5227c478bd9Sstevel@tonic-gate break;
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
5257c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props();
5267c478bd9Sstevel@tonic-gate if (env_debug)
5277c478bd9Sstevel@tonic-gate envd_log(LOG_WARNING,
5287c478bd9Sstevel@tonic-gate "Can't create prop/node for fan '%s'\n",
5297c478bd9Sstevel@tonic-gate nodename);
5307c478bd9Sstevel@tonic-gate return (err);
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate /*
5377c478bd9Sstevel@tonic-gate * Delete all fan nodes and related properties created by the
5387c478bd9Sstevel@tonic-gate * add_fan_props() for each fan node in the PICL tree.
5397c478bd9Sstevel@tonic-gate */
5407c478bd9Sstevel@tonic-gate static void
delete_fan_nodes_and_props(void)5417c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props(void)
5427c478bd9Sstevel@tonic-gate {
5437c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
5447c478bd9Sstevel@tonic-gate int i;
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate /*
5477c478bd9Sstevel@tonic-gate * Delete/destroy fan node and all properties under it.
5487c478bd9Sstevel@tonic-gate * Note that deleiing/destroying a node deletes/destroys
5497c478bd9Sstevel@tonic-gate * all properties within that node.
5507c478bd9Sstevel@tonic-gate */
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate for (i = 0; i < NFANS; ++i) {
5537c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
554*ada2da53SToomas Soome if (fnodep->nodeh != 0) {
5557c478bd9Sstevel@tonic-gate (void) ptree_delete_node(fnodep->nodeh);
5567c478bd9Sstevel@tonic-gate (void) ptree_destroy_node(fnodep->nodeh);
557*ada2da53SToomas Soome fnodep->nodeh = 0;
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate /*
5637c478bd9Sstevel@tonic-gate * Tuneables publishing functions
5647c478bd9Sstevel@tonic-gate */
5657c478bd9Sstevel@tonic-gate static int
copy_persistent_tuneable(env_tuneable_t * tune,char * buf)5667c478bd9Sstevel@tonic-gate copy_persistent_tuneable(env_tuneable_t *tune, char *buf)
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate switch (tune->type) {
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate case PICL_PTYPE_INT : {
5727c478bd9Sstevel@tonic-gate (void) memcpy((int *)tune->value,
5737c478bd9Sstevel@tonic-gate buf, tune->nbytes);
5747c478bd9Sstevel@tonic-gate break;
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate case PICL_PTYPE_CHARSTRING : {
5777c478bd9Sstevel@tonic-gate (void) memcpy((caddr_t)tune->value,
5787c478bd9Sstevel@tonic-gate buf, tune->nbytes);
5797c478bd9Sstevel@tonic-gate break;
5807c478bd9Sstevel@tonic-gate }
5817c478bd9Sstevel@tonic-gate default : {
5827c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate static void
env_parse_tunables(picl_nodehdl_t rooth)5897c478bd9Sstevel@tonic-gate env_parse_tunables(picl_nodehdl_t rooth)
5907c478bd9Sstevel@tonic-gate {
5917c478bd9Sstevel@tonic-gate char nmbuf[SYS_NMLN];
5927c478bd9Sstevel@tonic-gate char pname[PATH_MAX];
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
5957c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
5967c478bd9Sstevel@tonic-gate (void) strlcat(pname, TUNABLE_CONF_FILE, PATH_MAX);
5977c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
5987c478bd9Sstevel@tonic-gate (void) picld_pluginutil_parse_config_file(rooth, pname);
5997c478bd9Sstevel@tonic-gate return;
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate int
env_picl_setup_tuneables(void)6057c478bd9Sstevel@tonic-gate env_picl_setup_tuneables(void)
6067c478bd9Sstevel@tonic-gate {
6077c478bd9Sstevel@tonic-gate int err;
6087c478bd9Sstevel@tonic-gate int i;
6097c478bd9Sstevel@tonic-gate picl_nodehdl_t nodeh;
6107c478bd9Sstevel@tonic-gate picl_nodehdl_t rooth;
6117c478bd9Sstevel@tonic-gate picl_prophdl_t proph;
6127c478bd9Sstevel@tonic-gate env_tuneable_t *tuneablep;
6137c478bd9Sstevel@tonic-gate char read_buf[BUFSIZ];
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate if (ptree_get_root(&rooth) != PICL_SUCCESS) {
6167c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
6177c478bd9Sstevel@tonic-gate }
6187c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(rooth, PICL_PLUGINS_NODE,
6197c478bd9Sstevel@tonic-gate PICL_CLASS_PICL, &nodeh);
6207c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
6217c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
6227c478bd9Sstevel@tonic-gate err = ptree_create_and_add_node(nodeh, PICL_ENVIRONMENTAL_NODE,
6237c478bd9Sstevel@tonic-gate PICL_CLASS_PICL, &nodeh);
6247c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
6257c478bd9Sstevel@tonic-gate return (PICL_FAILURE);
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate /*
6297c478bd9Sstevel@tonic-gate * Parse the conf file
6307c478bd9Sstevel@tonic-gate */
6317c478bd9Sstevel@tonic-gate env_parse_tunables(rooth);
6327c478bd9Sstevel@tonic-gate for (i = 0; i < ntuneables; i++) {
6337c478bd9Sstevel@tonic-gate tuneablep = &tuneables[i];
6347c478bd9Sstevel@tonic-gate err = ptree_get_propval_by_name(nodeh, tuneablep->name,
6357c478bd9Sstevel@tonic-gate read_buf, tuneablep->nbytes);
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate * Add volitle functions to environmental node
6407c478bd9Sstevel@tonic-gate */
6417c478bd9Sstevel@tonic-gate err = add_volatile_prop(nodeh, tuneablep->name,
6427c478bd9Sstevel@tonic-gate tuneablep->type,
6437c478bd9Sstevel@tonic-gate PICL_READ|PICL_WRITE, tuneablep->nbytes,
6447c478bd9Sstevel@tonic-gate tuneablep->rfunc,
6457c478bd9Sstevel@tonic-gate tuneablep->wfunc, &proph);
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate tuneablep->proph = proph;
6487c478bd9Sstevel@tonic-gate } else {
6497c478bd9Sstevel@tonic-gate /*
6507c478bd9Sstevel@tonic-gate * property is persistent
6517c478bd9Sstevel@tonic-gate */
6527c478bd9Sstevel@tonic-gate (void) copy_persistent_tuneable(tuneablep,
6537c478bd9Sstevel@tonic-gate read_buf);
6547c478bd9Sstevel@tonic-gate }
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
6587c478bd9Sstevel@tonic-gate }
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate /*
6617c478bd9Sstevel@tonic-gate * Find the ENVMODEL_CONF_FILE file.
6627c478bd9Sstevel@tonic-gate */
6637c478bd9Sstevel@tonic-gate static int
get_envmodel_conf_file(char * outfilename)6647c478bd9Sstevel@tonic-gate get_envmodel_conf_file(char *outfilename)
6657c478bd9Sstevel@tonic-gate {
6667c478bd9Sstevel@tonic-gate char nmbuf[SYS_NMLN];
6677c478bd9Sstevel@tonic-gate char pname[PATH_MAX];
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
6707c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
6717c478bd9Sstevel@tonic-gate (void) strlcat(pname, ENV_CONF_FILE, PATH_MAX);
6727c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
6737c478bd9Sstevel@tonic-gate (void) strlcpy(outfilename, pname, PATH_MAX);
6747c478bd9Sstevel@tonic-gate return (0);
6757c478bd9Sstevel@tonic-gate }
6767c478bd9Sstevel@tonic-gate }
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
6797c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
6807c478bd9Sstevel@tonic-gate (void) strlcat(pname, ENV_CONF_FILE, PATH_MAX);
6817c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
6827c478bd9Sstevel@tonic-gate (void) strlcpy(outfilename, pname, PATH_MAX);
6837c478bd9Sstevel@tonic-gate return (0);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
6887c478bd9Sstevel@tonic-gate ENV_CONF_FILE);
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate if (access(pname, R_OK) == 0) {
6917c478bd9Sstevel@tonic-gate (void) strlcpy(outfilename, pname, PATH_MAX);
6927c478bd9Sstevel@tonic-gate return (0);
6937c478bd9Sstevel@tonic-gate }
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate return (-1);
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate /* Delete all sensor/fan nodes and any properties created by this plugin */
6997c478bd9Sstevel@tonic-gate void
env_picl_destroy(void)7007c478bd9Sstevel@tonic-gate env_picl_destroy(void)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate delete_fan_nodes_and_props();
7037c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props();
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate void
env_picl_setup(void)7077c478bd9Sstevel@tonic-gate env_picl_setup(void)
7087c478bd9Sstevel@tonic-gate {
7097c478bd9Sstevel@tonic-gate int err;
7107c478bd9Sstevel@tonic-gate sensor_node_t *snodep;
7117c478bd9Sstevel@tonic-gate fan_node_t *fnodep;
7127c478bd9Sstevel@tonic-gate char fullfilename[PATH_MAX];
7137c478bd9Sstevel@tonic-gate picl_nodehdl_t rooth;
7147c478bd9Sstevel@tonic-gate int i;
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate /*
7187c478bd9Sstevel@tonic-gate * Initialize sensorp and other fields in the sensor_nodes[] array
7197c478bd9Sstevel@tonic-gate */
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate for (i = 0; i < NSENSORS; ++i) {
7227c478bd9Sstevel@tonic-gate snodep = &sensor_nodes[i];
7237c478bd9Sstevel@tonic-gate snodep->sensorp = sensor_lookup(snodep->sensor_name);
724*ada2da53SToomas Soome snodep->nodeh = 0;
725*ada2da53SToomas Soome snodep->proph = 0;
726*ada2da53SToomas Soome snodep->target_proph = 0;
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate /*
7307c478bd9Sstevel@tonic-gate * Initialize fanp and other fields in the fan_nodes[] array
7317c478bd9Sstevel@tonic-gate */
7327c478bd9Sstevel@tonic-gate for (i = 0; i < NFANS; ++i) {
7337c478bd9Sstevel@tonic-gate fnodep = &fan_nodes[i];
7347c478bd9Sstevel@tonic-gate fnodep->fanp = fan_lookup(fnodep->fan_name);
735*ada2da53SToomas Soome fnodep->nodeh = 0;
736*ada2da53SToomas Soome fnodep->proph = 0;
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate /*
7407c478bd9Sstevel@tonic-gate * Get platform handle and populate PICL tree with environmental
7417c478bd9Sstevel@tonic-gate * nodes and properties
7427c478bd9Sstevel@tonic-gate */
7437c478bd9Sstevel@tonic-gate
7447c478bd9Sstevel@tonic-gate err = add_sensor_nodes_and_props();
7457c478bd9Sstevel@tonic-gate
7467c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS)
7477c478bd9Sstevel@tonic-gate err = add_fan_nodes_and_props();
7487c478bd9Sstevel@tonic-gate
7497c478bd9Sstevel@tonic-gate
7507c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS) {
7517c478bd9Sstevel@tonic-gate delete_sensor_nodes_and_props();
7527c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
7537c478bd9Sstevel@tonic-gate return;
7547c478bd9Sstevel@tonic-gate }
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate /*
7577c478bd9Sstevel@tonic-gate * Parse the envmodel.conf file and populate the PICL tree
7587c478bd9Sstevel@tonic-gate */
7597c478bd9Sstevel@tonic-gate if (get_envmodel_conf_file(fullfilename) < 0)
7607c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
7617c478bd9Sstevel@tonic-gate if (ptree_get_root(&rooth) != PICL_SUCCESS)
7627c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
7637c478bd9Sstevel@tonic-gate err = picld_pluginutil_parse_config_file(rooth, fullfilename);
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
7667c478bd9Sstevel@tonic-gate envd_log(LOG_CRIT, ENVD_PICL_SETUP_FAILED);
7677c478bd9Sstevel@tonic-gate }
768