1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _ENVD_H 28*7c478bd9Sstevel@tonic-gate #define _ENVD_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 31*7c478bd9Sstevel@tonic-gate #include <libintl.h> 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 34*7c478bd9Sstevel@tonic-gate extern "C" { 35*7c478bd9Sstevel@tonic-gate #endif 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #define SENSOR_POLL_INTERVAL 4 /* in seconds */ 38*7c478bd9Sstevel@tonic-gate #define WARNING_INTERVAL 30 /* in seconds */ 39*7c478bd9Sstevel@tonic-gate #define SHUTDOWN_INTERVAL 20 /* in seconds */ 40*7c478bd9Sstevel@tonic-gate #define ENV_CONF_FILE "piclenvd.conf" 41*7c478bd9Sstevel@tonic-gate #define ENVMODEL_CONF_FILE "envmodel.conf" 42*7c478bd9Sstevel@tonic-gate #define PM_DEVICE "/dev/pm" 43*7c478bd9Sstevel@tonic-gate #define SHUTDOWN_CMD "/usr/sbin/shutdown -y -g 60 -i 5" 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate /* 46*7c478bd9Sstevel@tonic-gate * devfs-path for various fans and their min/max speeds 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate #define ENV_CPU_FAN_DEVFS \ 49*7c478bd9Sstevel@tonic-gate "/pci@1f,0/pmu@3/fan-control@0,c8:cpu_fan" 50*7c478bd9Sstevel@tonic-gate #define ENV_SYSTEM_FAN_DEVFS \ 51*7c478bd9Sstevel@tonic-gate "/pci@1f,0/pmu@3/fan-control@0,c8:sys_fan" 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #define SYSTEM_FAN_SPEED_MIN 0 54*7c478bd9Sstevel@tonic-gate #define SYSTEM_FAN_SPEED_MAX 100 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * devfs-path for various temperature sensors and CPU platform path 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate #define CPU_DIE_SENSOR_DEVFS \ 61*7c478bd9Sstevel@tonic-gate "/pci@1f,0/pmu@3/i2c@0,0/temperature@30:die_temp" 62*7c478bd9Sstevel@tonic-gate #define CPU_AMB_SENSOR_DEVFS \ 63*7c478bd9Sstevel@tonic-gate "/pci@1f,0/pmu@3/i2c@0,0/temperature@30:amb_temp" 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate /* 66*7c478bd9Sstevel@tonic-gate * Temperature thresholds structure 67*7c478bd9Sstevel@tonic-gate */ 68*7c478bd9Sstevel@tonic-gate typedef int16_t tempr_t; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate typedef struct { 71*7c478bd9Sstevel@tonic-gate tempr_t low_power_off; /* low power-off temperature */ 72*7c478bd9Sstevel@tonic-gate tempr_t high_power_off; /* high power-off temperature */ 73*7c478bd9Sstevel@tonic-gate tempr_t low_shutdown; /* low shutdown temperature */ 74*7c478bd9Sstevel@tonic-gate tempr_t high_shutdown; /* high shutdown temperature */ 75*7c478bd9Sstevel@tonic-gate tempr_t low_warning; /* low warning temperature */ 76*7c478bd9Sstevel@tonic-gate tempr_t high_warning; /* high warning temperature */ 77*7c478bd9Sstevel@tonic-gate tempr_t target_temp; /* target temperature */ 78*7c478bd9Sstevel@tonic-gate } sensor_thresh_t; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate #define TEMP_IN_SHUTDOWN_RANGE(val, threshp) \ 81*7c478bd9Sstevel@tonic-gate ((val) > (threshp)->high_shutdown || (val) < (threshp)->low_shutdown) 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate #define TEMP_IN_WARNING_RANGE(val, threshp) \ 84*7c478bd9Sstevel@tonic-gate ((val) > (threshp)->high_warning || (val) < (threshp)->low_warning) 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* 88*7c478bd9Sstevel@tonic-gate * CPU "die" temperature thresholds 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate #define CPU_DIE_HIGH_POWER_OFF 125 91*7c478bd9Sstevel@tonic-gate #define CPU_DIE_HIGH_SHUTDOWN 90 92*7c478bd9Sstevel@tonic-gate #define CPU_DIE_HIGH_WARNING 85 93*7c478bd9Sstevel@tonic-gate #define CPU_DIE_TARGET_TEMP 80 94*7c478bd9Sstevel@tonic-gate #define CPU_DIE_LOW_WARNING 0 95*7c478bd9Sstevel@tonic-gate #define CPU_DIE_LOW_SHUTDOWN -10 96*7c478bd9Sstevel@tonic-gate #define CPU_DIE_LOW_POWER_OFF -20 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * CPU ambient temperature thresholds 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate #define CPU_AMB_HIGH_POWER_OFF 70 102*7c478bd9Sstevel@tonic-gate #define CPU_AMB_HIGH_SHUTDOWN 60 103*7c478bd9Sstevel@tonic-gate #define CPU_AMB_HIGH_WARNING 40 104*7c478bd9Sstevel@tonic-gate #define CPU_AMB_TARGET_TEMP 32 105*7c478bd9Sstevel@tonic-gate #define CPU_AMB_LOW_WARNING 0 106*7c478bd9Sstevel@tonic-gate #define CPU_AMB_LOW_SHUTDOWN -10 107*7c478bd9Sstevel@tonic-gate #define CPU_AMB_LOW_POWER_OFF -20 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* 111*7c478bd9Sstevel@tonic-gate * Fan names 112*7c478bd9Sstevel@tonic-gate */ 113*7c478bd9Sstevel@tonic-gate #define ENV_SYSTEM_FAN "system" 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate /* 116*7c478bd9Sstevel@tonic-gate * Sensor names 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate #define SENSOR_CPU_DIE "cpu" 119*7c478bd9Sstevel@tonic-gate #define SENSOR_CPU_AMB "cpu-ambient" 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * Temperature sensor related data structure 123*7c478bd9Sstevel@tonic-gate */ 124*7c478bd9Sstevel@tonic-gate typedef struct env_sensor { 125*7c478bd9Sstevel@tonic-gate char *name; /* sensor name */ 126*7c478bd9Sstevel@tonic-gate char *devfs_path; /* sensor device devfs path */ 127*7c478bd9Sstevel@tonic-gate sensor_thresh_t *temp_thresh; /* sensor temp threshold */ 128*7c478bd9Sstevel@tonic-gate int fd; /* device file descriptor */ 129*7c478bd9Sstevel@tonic-gate int error; /* error flag */ 130*7c478bd9Sstevel@tonic-gate boolean_t present; /* sensor present */ 131*7c478bd9Sstevel@tonic-gate tempr_t cur_temp; /* current temperature */ 132*7c478bd9Sstevel@tonic-gate time_t warning_tstamp; /* last warning time in secs */ 133*7c478bd9Sstevel@tonic-gate time_t shutdown_tstamp; /* shutdown temp time (secs) */ 134*7c478bd9Sstevel@tonic-gate boolean_t shutdown_initiated; /* shutdown initated */ 135*7c478bd9Sstevel@tonic-gate } env_sensor_t; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate extern env_sensor_t *sensor_lookup(char *sensor_name); 138*7c478bd9Sstevel@tonic-gate extern int get_temperature(env_sensor_t *, tempr_t *); 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate /* 141*7c478bd9Sstevel@tonic-gate * Fan information data structure 142*7c478bd9Sstevel@tonic-gate */ 143*7c478bd9Sstevel@tonic-gate typedef uint8_t fanspeed_t; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate typedef struct env_fan { 146*7c478bd9Sstevel@tonic-gate char *name; /* fan name */ 147*7c478bd9Sstevel@tonic-gate char *devfs_path; /* fan device devfs path */ 148*7c478bd9Sstevel@tonic-gate fanspeed_t speed_min; /* minimum speed */ 149*7c478bd9Sstevel@tonic-gate fanspeed_t speed_max; /* maximum speed */ 150*7c478bd9Sstevel@tonic-gate int fd; /* device file descriptor */ 151*7c478bd9Sstevel@tonic-gate boolean_t present; /* fan present */ 152*7c478bd9Sstevel@tonic-gate fanspeed_t cur_speed; /* current fan speed */ 153*7c478bd9Sstevel@tonic-gate fanspeed_t prev_speed; /* previous fan speed */ 154*7c478bd9Sstevel@tonic-gate } env_fan_t; 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate extern env_fan_t *fan_lookup(char *fan_name); 158*7c478bd9Sstevel@tonic-gate extern int get_fan_speed(env_fan_t *, fanspeed_t *); 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate extern int env_debug; 161*7c478bd9Sstevel@tonic-gate extern void envd_log(int pri, const char *fmt, ...); 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate /* 164*7c478bd9Sstevel@tonic-gate * Various messages 165*7c478bd9Sstevel@tonic-gate */ 166*7c478bd9Sstevel@tonic-gate #define ENVD_PLUGIN_INIT_FAILED \ 167*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: initialization failed!\n") 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate #define ENVD_PICL_SETUP_FAILED \ 170*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: PICL setup failed!\n") 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate #define PM_THREAD_CREATE_FAILED \ 173*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: pmthr thread creation failed!\n") 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate #define PM_THREAD_EXITING \ 176*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n") 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate #define ENV_THREAD_CREATE_FAILED \ 179*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: envthr thread creation failed!\n") 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate #define ENV_SHUTDOWN_MSG \ 182*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \ 183*7c478bd9Sstevel@tonic-gate "limits (%d...%d). Shutting down the system.\n") 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate #define ENV_WARNING_MSG \ 186*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \ 187*7c478bd9Sstevel@tonic-gate "operating limits (%d...%d).\n") 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate #define ENV_FAN_OPEN_FAIL \ 190*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n") 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate #define ENV_SENSOR_OPEN_FAIL \ 193*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n") 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate #define ENV_SENSOR_ACCESS_FAIL \ 196*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n") 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate #define ENV_SENSOR_ACCESS_OK \ 199*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n") 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate #define ENV_CONF_INT_EXPECTED \ 202*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax or integer " \ 203*7c478bd9Sstevel@tonic-gate "value outside range for keyword '%s'.\n") 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate #define ENV_CONF_STRING_EXPECTED \ 206*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax for keyword " \ 207*7c478bd9Sstevel@tonic-gate "'%s'. Expecting string in double quotes (length < %d).\n") 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate #define ENV_CONF_UNSUPPORTED_TYPE \ 210*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: file:%s line:%d Unsupported type:%d for " \ 211*7c478bd9Sstevel@tonic-gate "keyword '%s'.\n") 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate #define ENV_CONF_UNSUPPORTED_KEYWORD \ 214*7c478bd9Sstevel@tonic-gate gettext("SUNW_piclenvd: file:%s line:%d Unsupported keyword '%s'.\n") 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate #endif 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate #endif /* _ENVD_H */ 221