1 /* $NetBSD: sysmon_envsys_tables.c,v 1.11 2012/08/27 21:42:04 pgoyette Exp $ */ 2 3 /*- 4 * Copyright (c) 2007 Juan Romero Pardines. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.11 2012/08/27 21:42:04 pgoyette Exp $"); 30 31 #include <sys/types.h> 32 33 #include <dev/sysmon/sysmonvar.h> 34 #include <dev/sysmon/sysmon_envsysvar.h> 35 36 /* 37 * Available units type descriptions. 38 */ 39 static const struct sme_descr_entry sme_units_description[] = { 40 { ENVSYS_STEMP, PENVSYS_TYPE_TEMP, "Temperature" }, 41 { ENVSYS_SFANRPM, PENVSYS_TYPE_FAN, "Fan" }, 42 { ENVSYS_SVOLTS_AC, PENVSYS_TYPE_VOLTAGE, "Voltage AC" }, 43 { ENVSYS_SVOLTS_DC, PENVSYS_TYPE_VOLTAGE, "Voltage DC" }, 44 { ENVSYS_SOHMS, PENVSYS_TYPE_RESISTANCE,"Ohms" }, 45 { ENVSYS_SWATTS, PENVSYS_TYPE_POWER, "Watts" }, 46 { ENVSYS_SAMPS, PENVSYS_TYPE_POWER, "Ampere" }, 47 { ENVSYS_SWATTHOUR, PENVSYS_TYPE_BATTERY, "Watt hour" }, 48 { ENVSYS_SAMPHOUR, PENVSYS_TYPE_BATTERY, "Ampere hour" }, 49 { ENVSYS_INDICATOR, PENVSYS_TYPE_INDICATOR, "Indicator" }, 50 { ENVSYS_INTEGER, PENVSYS_TYPE_INDICATOR, "Integer" }, 51 { ENVSYS_DRIVE, PENVSYS_TYPE_DRIVE, "Drive" }, 52 { ENVSYS_BATTERY_CAPACITY, PENVSYS_TYPE_BATTERY,"Battery capacity" }, 53 { ENVSYS_BATTERY_CHARGE, -1, "Battery charge" }, 54 { -1, -1, "unknown" } 55 }; 56 57 /* 58 * Available sensor state descriptions. 59 */ 60 static const struct sme_descr_entry sme_state_description[] = { 61 { ENVSYS_SVALID, -1, "valid" }, 62 { ENVSYS_SINVALID, -1, "invalid" }, 63 { ENVSYS_SCRITICAL, -1, "critical" }, 64 { ENVSYS_SCRITUNDER, -1, "critical-under" }, 65 { ENVSYS_SCRITOVER, -1, "critical-over" }, 66 { ENVSYS_SWARNUNDER, -1, "warning-under" }, 67 { ENVSYS_SWARNOVER, -1, "warning-over" }, 68 { -1, -1, "unknown" } 69 }; 70 71 /* 72 * Available drive state descriptions. 73 */ 74 static const struct sme_descr_entry sme_drivestate_description[] = { 75 { ENVSYS_DRIVE_EMPTY, -1, "unknown" }, 76 { ENVSYS_DRIVE_READY, -1, "ready" }, 77 { ENVSYS_DRIVE_POWERUP, -1, "powering up" }, 78 { ENVSYS_DRIVE_ONLINE, -1, "online" }, 79 { ENVSYS_DRIVE_OFFLINE, -1, "offline" }, 80 { ENVSYS_DRIVE_IDLE, -1, "idle" }, 81 { ENVSYS_DRIVE_ACTIVE, -1, "active" }, 82 { ENVSYS_DRIVE_BUILD, -1, "building" }, 83 { ENVSYS_DRIVE_REBUILD, -1, "rebuilding" }, 84 { ENVSYS_DRIVE_POWERDOWN, -1, "powering down" }, 85 { ENVSYS_DRIVE_FAIL, -1, "failed" }, 86 { ENVSYS_DRIVE_PFAIL, -1, "degraded" }, 87 { ENVSYS_DRIVE_MIGRATING, -1, "migrating" }, 88 { ENVSYS_DRIVE_CHECK, -1, "checking" }, 89 { -1, -1, "unknown" } 90 }; 91 92 /* 93 * Available battery capacity descriptions. 94 */ 95 static const struct sme_descr_entry sme_batterycap_description[] = { 96 { ENVSYS_BATTERY_CAPACITY_NORMAL, -1, "NORMAL" }, 97 { ENVSYS_BATTERY_CAPACITY_WARNING, -1, "WARNING" }, 98 { ENVSYS_BATTERY_CAPACITY_CRITICAL, -1, "CRITICAL" }, 99 { ENVSYS_BATTERY_CAPACITY_LOW, -1, "LOW" }, 100 { -1, -1, "UNKNOWN" } 101 }; 102 103 /* 104 * Available indicator descriptions. 105 */ 106 static const struct sme_descr_entry sme_indicator_description[] = { 107 { ENVSYS_INDICATOR_FALSE, -1, "FALSE" }, 108 { ENVSYS_INDICATOR_TRUE, -1, "TRUE" }, 109 { -1, -1, "UNKNOWN" } 110 }; 111 112 static const struct sme_descr_entry * 113 sme_find_table(enum sme_descr_type table_id) 114 { 115 switch (table_id) { 116 case SME_DESC_UNITS: 117 return sme_units_description; 118 break; 119 case SME_DESC_STATES: 120 return sme_state_description; 121 break; 122 case SME_DESC_DRIVE_STATES: 123 return sme_drivestate_description; 124 break; 125 case SME_DESC_BATTERY_CAPACITY: 126 return sme_batterycap_description; 127 break; 128 case SME_DESC_INDICATOR: 129 return sme_indicator_description; 130 break; 131 default: 132 return NULL; 133 } 134 } 135 136 /* 137 * Returns the entry from specified table with type == key 138 */ 139 const struct sme_descr_entry * 140 sme_find_table_entry(enum sme_descr_type table_id, int key) 141 { 142 const struct sme_descr_entry *table = sme_find_table(table_id); 143 144 if (table != NULL) 145 for (; table->type != -1; table++) 146 if (table->type == key) 147 return table; 148 149 return NULL; 150 } 151 152 const struct sme_descr_entry * 153 sme_find_table_desc(enum sme_descr_type table_id, const char *str) 154 { 155 const struct sme_descr_entry *table = sme_find_table(table_id); 156 157 if (table != NULL) 158 for (; table->type != -1; table++) 159 if (strcmp(table->desc, str) == 0) 160 return table; 161 return NULL; 162 } 163