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 2000-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
39 #define SENSOR_POLL_INTERVAL 4 /* in seconds */
40 #define WARNING_INTERVAL 30 /* in seconds */
41 #define SHUTDOWN_INTERVAL 20 /* in seconds */
42 #define ENV_CONF_FILE "piclenvd.conf"
43 #define ENVMODEL_CONF_FILE "envmodel.conf"
44 #define PM_DEVICE "/dev/pm"
45 #define SHUTDOWN_CMD "/usr/sbin/shutdown -y -g 60 -i 5"
48 * devfs-path for various fans and their min/max speeds
50 #define ENV_CPU_FAN_DEVFS \
51 "/pci@1f,0/pmu@3/fan-control@0,c8:cpu_fan"
52 #define ENV_SYSTEM_FAN_DEVFS \
53 "/pci@1f,0/pmu@3/fan-control@0,c8:sys_fan"
55 #define SYSTEM_FAN_SPEED_MIN 0
56 #define SYSTEM_FAN_SPEED_MAX 100
60 * devfs-path for various temperature sensors and CPU platform path
62 #define CPU_DIE_SENSOR_DEVFS \
63 "/pci@1f,0/pmu@3/i2c@0,0/temperature@30:die_temp"
64 #define CPU_AMB_SENSOR_DEVFS \
65 "/pci@1f,0/pmu@3/i2c@0,0/temperature@30:amb_temp"
68 * Temperature thresholds structure
70 typedef int16_t tempr_t
;
73 tempr_t low_power_off
; /* low power-off temperature */
74 tempr_t high_power_off
; /* high power-off temperature */
75 tempr_t low_shutdown
; /* low shutdown temperature */
76 tempr_t high_shutdown
; /* high shutdown temperature */
77 tempr_t low_warning
; /* low warning temperature */
78 tempr_t high_warning
; /* high warning temperature */
79 tempr_t target_temp
; /* target temperature */
82 #define TEMP_IN_SHUTDOWN_RANGE(val, threshp) \
83 ((val) > (threshp)->high_shutdown || (val) < (threshp)->low_shutdown)
85 #define TEMP_IN_WARNING_RANGE(val, threshp) \
86 ((val) > (threshp)->high_warning || (val) < (threshp)->low_warning)
90 * CPU "die" temperature thresholds
92 #define CPU_DIE_HIGH_POWER_OFF 125
93 #define CPU_DIE_HIGH_SHUTDOWN 90
94 #define CPU_DIE_HIGH_WARNING 85
95 #define CPU_DIE_TARGET_TEMP 80
96 #define CPU_DIE_LOW_WARNING 0
97 #define CPU_DIE_LOW_SHUTDOWN -10
98 #define CPU_DIE_LOW_POWER_OFF -20
101 * CPU ambient temperature thresholds
103 #define CPU_AMB_HIGH_POWER_OFF 70
104 #define CPU_AMB_HIGH_SHUTDOWN 60
105 #define CPU_AMB_HIGH_WARNING 40
106 #define CPU_AMB_TARGET_TEMP 32
107 #define CPU_AMB_LOW_WARNING 0
108 #define CPU_AMB_LOW_SHUTDOWN -10
109 #define CPU_AMB_LOW_POWER_OFF -20
115 #define ENV_SYSTEM_FAN "system"
120 #define SENSOR_CPU_DIE "cpu"
121 #define SENSOR_CPU_AMB "cpu-ambient"
124 * Temperature sensor related data structure
126 typedef struct env_sensor
{
127 char *name
; /* sensor name */
128 char *devfs_path
; /* sensor device devfs path */
129 sensor_thresh_t
*temp_thresh
; /* sensor temp threshold */
130 int fd
; /* device file descriptor */
131 int error
; /* error flag */
132 boolean_t present
; /* sensor present */
133 tempr_t cur_temp
; /* current temperature */
134 time_t warning_tstamp
; /* last warning time in secs */
135 time_t shutdown_tstamp
; /* shutdown temp time (secs) */
136 boolean_t shutdown_initiated
; /* shutdown initated */
139 extern env_sensor_t
*sensor_lookup(char *sensor_name
);
140 extern int get_temperature(env_sensor_t
*, tempr_t
*);
143 * Fan information data structure
145 typedef uint8_t fanspeed_t
;
147 typedef struct env_fan
{
148 char *name
; /* fan name */
149 char *devfs_path
; /* fan device devfs path */
150 fanspeed_t speed_min
; /* minimum speed */
151 fanspeed_t speed_max
; /* maximum speed */
152 int fd
; /* device file descriptor */
153 boolean_t present
; /* fan present */
154 fanspeed_t cur_speed
; /* current fan speed */
155 fanspeed_t prev_speed
; /* previous fan speed */
159 extern env_fan_t
*fan_lookup(char *fan_name
);
160 extern int get_fan_speed(env_fan_t
*, fanspeed_t
*);
162 extern int env_debug
;
163 extern void envd_log(int pri
, const char *fmt
, ...);
168 #define ENVD_PLUGIN_INIT_FAILED \
169 gettext("SUNW_piclenvd: initialization failed!\n")
171 #define ENVD_PICL_SETUP_FAILED \
172 gettext("SUNW_piclenvd: PICL setup failed!\n")
174 #define PM_THREAD_CREATE_FAILED \
175 gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
177 #define PM_THREAD_EXITING \
178 gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
180 #define ENV_THREAD_CREATE_FAILED \
181 gettext("SUNW_piclenvd: envthr thread creation failed!\n")
183 #define ENV_SHUTDOWN_MSG \
184 gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
185 "limits (%d...%d). Shutting down the system.\n")
187 #define ENV_WARNING_MSG \
188 gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
189 "operating limits (%d...%d).\n")
191 #define ENV_FAN_OPEN_FAIL \
192 gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
194 #define ENV_SENSOR_OPEN_FAIL \
195 gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
197 #define ENV_SENSOR_ACCESS_FAIL \
198 gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
200 #define ENV_SENSOR_ACCESS_OK \
201 gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
203 #define ENV_CONF_INT_EXPECTED \
204 gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax or integer " \
205 "value outside range for keyword '%s'.\n")
207 #define ENV_CONF_STRING_EXPECTED \
208 gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax for keyword " \
209 "'%s'. Expecting string in double quotes (length < %d).\n")
211 #define ENV_CONF_UNSUPPORTED_TYPE \
212 gettext("SUNW_piclenvd: file:%s line:%d Unsupported type:%d for " \
215 #define ENV_CONF_UNSUPPORTED_KEYWORD \
216 gettext("SUNW_piclenvd: file:%s line:%d Unsupported keyword '%s'.\n")