Home | History | Annotate | Line # | Download | only in sysmon
sysmon_envsys_tables.c revision 1.4.8.1
      1 /* $NetBSD: sysmon_envsys_tables.c,v 1.4.8.1 2008/03/24 07:16:09 keiichi 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.4.8.1 2008/03/24 07:16:09 keiichi 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_description_table 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_description_table 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_description_table 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_description_table 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  * Returns the table associated with type.
    105  */
    106 const struct sme_description_table *
    107 sme_get_description_table(int type)
    108 {
    109 	const struct sme_description_table *ud = sme_units_description;
    110 	const struct sme_description_table *sd = sme_state_description;
    111 	const struct sme_description_table *dd = sme_drivestate_description;
    112 	const struct sme_description_table *bd = sme_batterycap_description;
    113 
    114 	switch (type) {
    115 	case SME_DESC_UNITS:
    116 		return ud;
    117 	case SME_DESC_STATES:
    118 		return sd;
    119 	case SME_DESC_DRIVE_STATES:
    120 		return dd;
    121 	case SME_DESC_BATTERY_CAPACITY:
    122 		return bd;
    123 	default:
    124 		return NULL;
    125 	}
    126 }
    127