summaryrefslogtreecommitdiff
path: root/sys/dev/sysmon
diff options
context:
space:
mode:
authorxtraeme <xtraeme@NetBSD.org>2007-09-04 16:54:02 +0000
committerxtraeme <xtraeme@NetBSD.org>2007-09-04 16:54:02 +0000
commit5b53183e980a51653e322ecbc25a9aa9deec03ae (patch)
tree5f3ca2954afe4fc171f2fae7bb557bb4ad26d76b /sys/dev/sysmon
parent96356ccdfd8eaed56ea4f483f879d766c3bd149b (diff)
- Remove ENVSYS_GSTRING and the genstr member from envsys_data_t.
(at least three or four persons were against it). - Add a new sensor type: ENVSYS_BATTERY_STATE, this uses value_cur and some predefined values in a static table, like ENVSYS_DRIVE. - Move all static tables to sysmon_envsys_tables.c and use a function on it to retrieve a pointer to the struct of the specified type. - Rename the ENVSYS_FMONDRVSTCHANGED to ENVSYS_FMONSTCHANGED and make it generic for Battery state and drive sensors (this flag enables monitoring on these sensors when state has been changed). - Update sysmon_penvsys_event() to report state changes on ENVSYS_BATTERY_STATE sensors and remove other type of events, with PENVSYS_EVENT_STATE_CHANGED they are not necessary anymore.
Diffstat (limited to 'sys/dev/sysmon')
-rw-r--r--sys/dev/sysmon/files.sysmon3
-rw-r--r--sys/dev/sysmon/sysmon_envsys.c204
-rw-r--r--sys/dev/sysmon/sysmon_envsys_events.c64
-rw-r--r--sys/dev/sysmon/sysmon_envsys_tables.c132
-rw-r--r--sys/dev/sysmon/sysmon_envsysvar.h17
-rw-r--r--sys/dev/sysmon/sysmon_power.c26
6 files changed, 268 insertions, 178 deletions
diff --git a/sys/dev/sysmon/files.sysmon b/sys/dev/sysmon/files.sysmon
index af4bcd63120..62dbeb037d9 100644
--- a/sys/dev/sysmon/files.sysmon
+++ b/sys/dev/sysmon/files.sysmon
@@ -1,4 +1,4 @@
-# $NetBSD: files.sysmon,v 1.9 2007/09/02 00:28:28 xtraeme Exp $
+# $NetBSD: files.sysmon,v 1.10 2007/09/04 16:54:02 xtraeme Exp $
define sysmon_taskq
file dev/sysmon/sysmon_taskq.c sysmon_taskq needs-flag
@@ -9,6 +9,7 @@ file dev/sysmon/sysmon_power.c sysmon_power needs-flag
define sysmon_envsys: sysmon_power, sysmon_taskq
file dev/sysmon/sysmon_envsys.c sysmon_envsys needs-flag
file dev/sysmon/sysmon_envsys_events.c sysmon_envsys
+file dev/sysmon/sysmon_envsys_tables.c sysmon_envsys
file dev/sysmon/sysmon_envsys_util.c sysmon_envsys
define sysmon_wdog
diff --git a/sys/dev/sysmon/sysmon_envsys.c b/sys/dev/sysmon/sysmon_envsys.c
index edb2c4d9393..9c51d797285 100644
--- a/sys/dev/sysmon/sysmon_envsys.c
+++ b/sys/dev/sysmon/sysmon_envsys.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys.c,v 1.54 2007/09/02 19:36:59 xtraeme Exp $ */
+/* $NetBSD: sysmon_envsys.c,v 1.55 2007/09/04 16:54:02 xtraeme Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.54 2007/09/02 19:36:59 xtraeme Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.55 2007/09/04 16:54:02 xtraeme Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -94,54 +94,6 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.54 2007/09/02 19:36:59 xtraeme E
#include "opt_compat_netbsd.h"
-struct sme_sensor_type {
- int type;
- int crittype;
- const char *desc;
-};
-
-static const struct sme_sensor_type sme_sensor_type[] = {
- { ENVSYS_STEMP, PENVSYS_TYPE_TEMP, "Temperature" },
- { ENVSYS_SFANRPM, PENVSYS_TYPE_FAN, "Fan" },
- { ENVSYS_SVOLTS_AC, PENVSYS_TYPE_VOLTAGE, "Voltage AC" },
- { ENVSYS_SVOLTS_DC, PENVSYS_TYPE_VOLTAGE, "Voltage DC" },
- { ENVSYS_SOHMS, PENVSYS_TYPE_RESISTANCE,"Ohms" },
- { ENVSYS_SWATTS, PENVSYS_TYPE_POWER, "Watts" },
- { ENVSYS_SAMPS, PENVSYS_TYPE_POWER, "Ampere" },
- { ENVSYS_SWATTHOUR, PENVSYS_TYPE_BATTERY, "Watt hour" },
- { ENVSYS_SAMPHOUR, PENVSYS_TYPE_BATTERY, "Ampere hour" },
- { ENVSYS_INDICATOR, PENVSYS_TYPE_INDICATOR, "Indicator" },
- { ENVSYS_INTEGER, PENVSYS_TYPE_INDICATOR, "Integer" },
- { ENVSYS_DRIVE, PENVSYS_TYPE_DRIVE, "Drive" },
- { ENVSYS_GSTRING, -1, "Generic string" },
- { -1, -1, "unknown" }
-};
-
-static const struct sme_sensor_type sme_sensor_state[] = {
- { ENVSYS_SVALID, -1, "valid" },
- { ENVSYS_SINVALID, -1, "invalid" },
- { ENVSYS_SCRITICAL, -1, "critical" },
- { ENVSYS_SCRITUNDER, -1, "critical-under" },
- { ENVSYS_SCRITOVER, -1, "critical-over" },
- { ENVSYS_SWARNUNDER, -1, "warning-under" },
- { ENVSYS_SWARNOVER, -1, "warning-over" },
- { -1, -1, "unknown" }
-};
-
-static const struct sme_sensor_type sme_sensor_drive_state[] = {
- { ENVSYS_DRIVE_EMPTY, -1, "drive state is unknown" },
- { ENVSYS_DRIVE_READY, -1, "drive is ready" },
- { ENVSYS_DRIVE_POWERUP, -1, "drive is powering up" },
- { ENVSYS_DRIVE_ONLINE, -1, "drive is online" },
- { ENVSYS_DRIVE_IDLE, -1, "drive is idle" },
- { ENVSYS_DRIVE_ACTIVE, -1, "drive is active" },
- { ENVSYS_DRIVE_REBUILD, -1, "drive is rebuilding" },
- { ENVSYS_DRIVE_POWERDOWN, -1, "drive is powering down" },
- { ENVSYS_DRIVE_FAIL, -1, "drive failed" },
- { ENVSYS_DRIVE_PFAIL, -1, "drive degraded" },
- { -1, -1, "unknown" }
-};
-
static prop_dictionary_t sme_propd;
static kcondvar_t sme_list_cv;
@@ -748,20 +700,19 @@ void
sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
prop_dictionary_t dict, envsys_data_t *edata)
{
- const struct sme_sensor_type *est = sme_sensor_type;
- const struct sme_sensor_type *ess = sme_sensor_state;
- const struct sme_sensor_type *esds = sme_sensor_drive_state;
+ const struct sme_description_table *sdt, *sdt_units;
sme_event_drv_t *sme_evdrv_t = NULL;
int i, j;
i = j = 0;
/* find the correct unit for this sensor. */
- for (i = 0; est[i].type != -1; i++)
- if (est[i].type == edata->units)
+ sdt_units = sme_get_description_table(SME_DESC_UNITS);
+ for (i = 0; sdt_units[i].type != -1; i++)
+ if (sdt_units[i].type == edata->units)
break;
- if (strcmp(est[i].desc, "unknown") == 0) {
+ if (strcmp(sdt_units[i].desc, "unknown") == 0) {
DPRINTF(("%s: invalid units type for sensor=%d\n",
__func__, edata->sensor));
goto invalidate_sensor;
@@ -775,7 +726,7 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
* <string>blah blah</string>
* ...
*/
- if (sme_sensor_upstring(dict, "type", est[i].desc))
+ if (sme_sensor_upstring(dict, "type", sdt_units[i].desc))
goto invalidate_sensor;
if (strlen(edata->desc) == 0) {
@@ -795,11 +746,12 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
* <string>valid</string>
* ...
*/
- for (j = 0; ess[j].type != -1; j++)
- if (ess[j].type == edata->state)
+ sdt = sme_get_description_table(SME_DESC_STATES);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->state)
break;
- if (strcmp(ess[j].desc, "unknown") == 0) {
+ if (strcmp(sdt[j].desc, "unknown") == 0) {
DPRINTF(("%s: invalid state for sensor=%d\n",
__func__, edata->sensor));
goto invalidate_sensor;
@@ -808,7 +760,7 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
DPRINTF(("%s: sensor desc=%s type=%d state=%d\n",
__func__, edata->desc, edata->units, edata->state));
- if (sme_sensor_upstring(dict, "state", ess[j].desc))
+ if (sme_sensor_upstring(dict, "state", sdt[j].desc))
goto invalidate_sensor;
/*
@@ -819,14 +771,14 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
* <true/>
* ...
*
- * always false on Drive, Generic strings and Indicator types.
+ * always false on Battery state, Drive and Indicator types.
* They cannot be monitored.
*
*/
if ((edata->flags & ENVSYS_FMONNOTSUPP) ||
(edata->units == ENVSYS_INDICATOR) ||
(edata->units == ENVSYS_DRIVE) ||
- (edata->units == ENVSYS_GSTRING)) {
+ (edata->units == ENVSYS_BATTERY_STATE)) {
if (sme_sensor_upbool(dict, "monitoring-supported", false))
return;
} else {
@@ -835,38 +787,34 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
}
/*
- * Add the generic-state-string object for gstring sensors:
+ * add the percentage boolean object:
*
* ...
- * <key>generic-state-string</key>
- * <string>NORMAL</string>
+ * <key>want-percentage</key>
+ * <true/>
* ...
*/
- if (edata->units == ENVSYS_GSTRING) {
- if (strlen(edata->genstr) == 0) {
- DPRINTF(("%s: invalid generic state string for "
- "sensor=%s\n", __func__, edata->desc));
- goto invalidate_sensor;
- }
- if (sme_sensor_upstring(dict,
- "generic-state-string",
- edata->genstr))
- goto invalidate_sensor;
-
- goto add_sensor;
- }
+ if (edata->flags & ENVSYS_FPERCENT)
+ if (sme_sensor_upbool(dict, "want-percentage", true))
+ return;
/*
- * add the percentage boolean object:
+ * Add the battery-state object for battery state sensors:
*
* ...
- * <key>want-percentage</key>
- * <true/>
+ * <key>battery-state</key>
+ * <string>NORMAL</string>
* ...
*/
- if (edata->flags & ENVSYS_FPERCENT)
- if (sme_sensor_upbool(dict, "want-percentage", true))
+ if (edata->units == ENVSYS_BATTERY_STATE) {
+ sdt = sme_get_description_table(SME_DESC_BATTERY_STATES);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->value_cur)
+ break;
+
+ if (sme_sensor_upstring(dict, "battery-state", sdt[j].desc))
return;
+ }
/*
* Add the drive-state object for drive sensors:
@@ -877,11 +825,12 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
* ...
*/
if (edata->units == ENVSYS_DRIVE) {
- for (j = 0; esds[j].type != -1; j++)
- if (esds[j].type == edata->value_cur)
+ sdt = sme_get_description_table(SME_DESC_DRIVE_STATES);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->value_cur)
break;
- if (sme_sensor_upstring(dict, "drive-state", esds[j].desc))
+ if (sme_sensor_upstring(dict, "drive-state", sdt[j].desc))
return;
}
@@ -947,7 +896,6 @@ sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
*
*/
-add_sensor:
if (!prop_array_set(array, sme->sme_uniqsensors - 1, dict)) {
DPRINTF(("%s: prop_array_add\n", __func__));
goto invalidate_sensor;
@@ -966,7 +914,7 @@ add_sensor:
sme_evdrv_t->sdict = dict;
sme_evdrv_t->edata = edata;
sme_evdrv_t->sme = sme;
- sme_evdrv_t->powertype = est[i].crittype;
+ sme_evdrv_t->powertype = sdt_units[i].crittype;
sysmon_task_queue_init();
sysmon_task_queue_sched(0, sme_event_drvadd, sme_evdrv_t);
@@ -987,10 +935,8 @@ invalidate_sensor:
int
sme_update_dictionary(struct sysmon_envsys *sme)
{
- const struct sme_sensor_type *est = sme_sensor_type;
- const struct sme_sensor_type *ess = sme_sensor_state;
- const struct sme_sensor_type *esds = sme_sensor_drive_state;
- envsys_data_t *edata = NULL;
+ const struct sme_description_table *sdt;
+ envsys_data_t *edata;
prop_object_t array, dict;
int i, j, error, invalid;
@@ -1041,44 +987,31 @@ sme_update_dictionary(struct sysmon_envsys *sme)
return EINVAL;
}
- for (j = 0; ess[j].type != -1; j++)
- if (ess[j].type == edata->state)
+ /* update sensor's state */
+ sdt = sme_get_description_table(SME_DESC_STATES);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->state)
break;
DPRINTFOBJ(("%s: state=%s type=%d flags=%d "
- "units=%d sensor=%d\n", __func__, ess[j].desc,
- ess[j].type, edata->flags, edata->units, edata->sensor));
+ "units=%d sensor=%d\n", __func__, sdt[j].desc,
+ sdt[j].type, edata->flags, edata->units, edata->sensor));
/* update sensor state */
- error = sme_sensor_upstring(dict, "state", ess[j].desc);
+ error = sme_sensor_upstring(dict, "state", sdt[j].desc);
if (error)
break;
- for (j = 0; est[j].type != -1; j++)
- if (est[j].type == edata->units)
+ /* update sensor type */
+ sdt = sme_get_description_table(SME_DESC_UNITS);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->units)
break;
- /* update sensor type */
- error = sme_sensor_upstring(dict, "type", est[j].desc);
+ error = sme_sensor_upstring(dict, "type", sdt[j].desc);
if (error)
break;
- /*
- * Update the generic-state-string object for gstring
- * sensors, they only need the following objects:
- *
- * description, generic-state-string, state and type.
- *
- */
- if (edata->units == ENVSYS_GSTRING) {
- error = sme_sensor_upstring(dict,
- "generic-state-string",
- edata->genstr);
- if (error)
- break;
- continue;
- }
-
/* update sensor current value */
error = sme_sensor_upint32(dict,
"cur-value",
@@ -1148,13 +1081,29 @@ sme_update_dictionary(struct sysmon_envsys *sme)
/* update 'drive-state' only in ENVSYS_DRIVE. */
if (edata->units == ENVSYS_DRIVE) {
- for (j = 0; esds[j].type != -1; j++)
- if (esds[j].type == edata->value_cur)
+ sdt = sme_get_description_table(SME_DESC_DRIVE_STATES);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->value_cur)
break;
error = sme_sensor_upstring(dict,
"drive-state",
- esds[j].desc);
+ sdt[j].desc);
+ if (error)
+ break;
+ }
+
+ /* update 'battery-state' only in ENVSYS_BATTERY_STATE. */
+ if (edata->units == ENVSYS_BATTERY_STATE) {
+ sdt =
+ sme_get_description_table(SME_DESC_BATTERY_STATES);
+ for (j = 0; sdt[j].type != -1; j++)
+ if (sdt[j].type == edata->value_cur)
+ break;
+
+ error = sme_sensor_upstring(dict,
+ "battery-state",
+ sdt[j].desc);
if (error)
break;
}
@@ -1173,7 +1122,7 @@ int
sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
prop_array_t array)
{
- const struct sme_sensor_type *sst = sme_sensor_type;
+ const struct sme_description_table *sdt;
envsys_data_t *edata, *nedata;
prop_dictionary_t dict;
prop_object_t obj, obj1, obj2;
@@ -1301,8 +1250,9 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
break;
}
- for (i = 0; sst[i].type != -1; i++)
- if (sst[i].type == edata->units)
+ sdt = sme_get_description_table(SME_DESC_UNITS);
+ for (i = 0; sdt[i].type != -1; i++)
+ if (sdt[i].type == edata->units)
break;
/* did the user want to set a critical capacity event? */
@@ -1322,7 +1272,7 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
"critical-capacity",
critval,
PENVSYS_EVENT_BATT_USERCAP,
- sst[i].crittype);
+ sdt[i].crittype);
break;
}
@@ -1343,7 +1293,7 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
"critical-max-limit",
critval,
PENVSYS_EVENT_USER_CRITMAX,
- sst[i].crittype);
+ sdt[i].crittype);
break;
}
@@ -1364,7 +1314,7 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
"critical-min-limit",
critval,
PENVSYS_EVENT_USER_CRITMIN,
- sst[i].crittype);
+ sdt[i].crittype);
break;
}
}
diff --git a/sys/dev/sysmon/sysmon_envsys_events.c b/sys/dev/sysmon/sysmon_envsys_events.c
index b56de729207..47498c377bd 100644
--- a/sys/dev/sysmon/sysmon_envsys_events.c
+++ b/sys/dev/sysmon/sysmon_envsys_events.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.27 2007/09/01 12:46:04 xtraeme Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.28 2007/09/04 16:54:02 xtraeme Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.27 2007/09/01 12:46:04 xtraeme Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.28 2007/09/04 16:54:02 xtraeme Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -58,30 +58,11 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.27 2007/09/01 12:46:04 xt
#include <dev/sysmon/sysmonvar.h>
#include <dev/sysmon/sysmon_envsysvar.h>
-struct sme_sensor_state {
- int type;
- const char *desc;
-};
-
struct sme_sensor_event {
int state;
int event;
};
-static const struct sme_sensor_state sme_sensor_drive_state[] = {
- { ENVSYS_DRIVE_EMPTY, "drive state is unknown" },
- { ENVSYS_DRIVE_READY, "drive is ready" },
- { ENVSYS_DRIVE_POWERUP, "drive is powering up" },
- { ENVSYS_DRIVE_ONLINE, "drive is online" },
- { ENVSYS_DRIVE_IDLE, "drive is idle" },
- { ENVSYS_DRIVE_ACTIVE, "drive is active" },
- { ENVSYS_DRIVE_REBUILD, "drive is rebuilding" },
- { ENVSYS_DRIVE_POWERDOWN, "drive is powering down" },
- { ENVSYS_DRIVE_FAIL, "drive failed" },
- { ENVSYS_DRIVE_PFAIL, "drive degraded" },
- { -1, "unknown" }
-};
-
static const struct sme_sensor_event sme_sensor_event[] = {
{ ENVSYS_SVALID, PENVSYS_EVENT_NORMAL },
{ ENVSYS_SCRITICAL, PENVSYS_EVENT_CRITICAL },
@@ -427,9 +408,9 @@ do { \
PENVSYS_EVENT_WARNOVER,
"warnover");
- SEE_REGEVENT(ENVSYS_FMONDRVSTATE,
- PENVSYS_EVENT_DRIVE_STCHANGED,
- "drvstchanged");
+ SEE_REGEVENT(ENVSYS_FMONSTCHANGED,
+ PENVSYS_EVENT_STATE_CHANGED,
+ "state-changed");
/* we are done, free memory now */
kmem_free(sed_t, sizeof(*sed_t));
@@ -512,15 +493,17 @@ sme_events_check(void *arg)
void
sme_events_worker(struct work *wk, void *arg)
{
- const struct sme_sensor_state *esds = sme_sensor_drive_state;
+ const struct sme_description_table *sdt = NULL;
const struct sme_sensor_event *sse = sme_sensor_event;
sme_event_t *see = (void *)wk;
struct sysmon_envsys *sme;
envsys_data_t *edata;
- int i, error = 0;
+ int i, state, error;
KASSERT(wk == &see->see_wk);
+ state = error = 0;
+
mutex_enter(&sme_event_mtx);
see->see_flags |= SME_EVENT_WORKING;
@@ -610,27 +593,40 @@ do { \
break;
/*
- * if value_cur is not ENVSYS_DRIVE_ONLINE, send the event...
+ * if value_cur is not normal (battery) or online (drive),
+ * send the event...
*/
- case PENVSYS_EVENT_DRIVE_STCHANGED:
+ case PENVSYS_EVENT_STATE_CHANGED:
/* the state has not been changed, just ignore the event */
if (edata->value_cur == see->evsent)
break;
- for (i = 0; esds[i].type != -1; i++)
- if (esds[i].type == edata->value_cur)
+ switch (edata->units) {
+ case ENVSYS_DRIVE:
+ sdt = sme_get_description_table(SME_DESC_DRIVE_STATES);
+ state = ENVSYS_DRIVE_ONLINE;
+ break;
+ case ENVSYS_BATTERY_STATE:
+ sdt =
+ sme_get_description_table(SME_DESC_BATTERY_STATES);
+ state = ENVSYS_BATTERY_STATE_NORMAL;
+ break;
+ }
+
+ for (i = 0; sdt[i].type != -1; i++)
+ if (sdt[i].type == edata->value_cur)
break;
/* copy current state description */
- (void)strlcpy(see->pes.pes_statedesc, esds[i].desc,
+ (void)strlcpy(see->pes.pes_statedesc, sdt[i].desc,
sizeof(see->pes.pes_statedesc));
/* state is ok again... send a normal event */
- if (see->evsent && edata->value_cur == ENVSYS_DRIVE_ONLINE)
+ if (see->evsent && edata->value_cur == state)
SME_SEND_NORMALEVENT();
- /* something bad happened to the drive... send the event */
- if (see->evsent || edata->value_cur != ENVSYS_DRIVE_ONLINE) {
+ /* state has been changed... send event */
+ if (see->evsent || edata->value_cur != state) {
/* save current drive state */
see->evsent = edata->value_cur;
sysmon_penvsys_event(&see->pes, see->type);
diff --git a/sys/dev/sysmon/sysmon_envsys_tables.c b/sys/dev/sysmon/sysmon_envsys_tables.c
new file mode 100644
index 00000000000..f08e66cf997
--- /dev/null
+++ b/sys/dev/sysmon/sysmon_envsys_tables.c
@@ -0,0 +1,132 @@
+/* $NetBSD: sysmon_envsys_tables.c,v 1.1 2007/09/04 16:54:02 xtraeme Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Juan Romero Pardines.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Juan Romero Pardines
+ * for the NetBSD Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.1 2007/09/04 16:54:02 xtraeme Exp $");
+
+#include <sys/types.h>
+
+#include <dev/sysmon/sysmonvar.h>
+#include <dev/sysmon/sysmon_envsysvar.h>
+
+/*
+ * Available units type descriptions.
+ */
+static const struct sme_description_table sme_units_description[] = {
+ { ENVSYS_STEMP, PENVSYS_TYPE_TEMP, "Temperature" },
+ { ENVSYS_SFANRPM, PENVSYS_TYPE_FAN, "Fan" },
+ { ENVSYS_SVOLTS_AC, PENVSYS_TYPE_VOLTAGE, "Voltage AC" },
+ { ENVSYS_SVOLTS_DC, PENVSYS_TYPE_VOLTAGE, "Voltage DC" },
+ { ENVSYS_SOHMS, PENVSYS_TYPE_RESISTANCE,"Ohms" },
+ { ENVSYS_SWATTS, PENVSYS_TYPE_POWER, "Watts" },
+ { ENVSYS_SAMPS, PENVSYS_TYPE_POWER, "Ampere" },
+ { ENVSYS_SWATTHOUR, PENVSYS_TYPE_BATTERY, "Watt hour" },
+ { ENVSYS_SAMPHOUR, PENVSYS_TYPE_BATTERY, "Ampere hour" },
+ { ENVSYS_INDICATOR, PENVSYS_TYPE_INDICATOR, "Indicator" },
+ { ENVSYS_INTEGER, PENVSYS_TYPE_INDICATOR, "Integer" },
+ { ENVSYS_DRIVE, PENVSYS_TYPE_DRIVE, "Drive" },
+ { ENVSYS_BATTERY_STATE, PENVSYS_TYPE_BATTERY, "Battery state" },
+ { -1, -1, "unknown" }
+};
+
+/*
+ * Available sensor state descriptions.
+ */
+static const struct sme_description_table sme_state_description[] = {
+ { ENVSYS_SVALID, -1, "valid" },
+ { ENVSYS_SINVALID, -1, "invalid" },
+ { ENVSYS_SCRITICAL, -1, "critical" },
+ { ENVSYS_SCRITUNDER, -1, "critical-under" },
+ { ENVSYS_SCRITOVER, -1, "critical-over" },
+ { ENVSYS_SWARNUNDER, -1, "warning-under" },
+ { ENVSYS_SWARNOVER, -1, "warning-over" },
+ { -1, -1, "unknown" }
+};
+
+/*
+ * Available drive state descriptions.
+ */
+static const struct sme_description_table sme_drivestate_description[] = {
+ { ENVSYS_DRIVE_EMPTY, -1, "drive state is unknown" },
+ { ENVSYS_DRIVE_READY, -1, "drive is ready" },
+ { ENVSYS_DRIVE_POWERUP, -1, "drive is powering up" },
+ { ENVSYS_DRIVE_ONLINE, -1, "drive is online" },
+ { ENVSYS_DRIVE_IDLE, -1, "drive is idle" },
+ { ENVSYS_DRIVE_ACTIVE, -1, "drive is active" },
+ { ENVSYS_DRIVE_REBUILD, -1, "drive is rebuilding" },
+ { ENVSYS_DRIVE_POWERDOWN, -1, "drive is powering down" },
+ { ENVSYS_DRIVE_FAIL, -1, "drive failed" },
+ { ENVSYS_DRIVE_PFAIL, -1, "drive degraded" },
+ { -1, -1, "unknown" }
+};
+
+/*
+ * Available battery state descriptions.
+ */
+static const struct sme_description_table sme_batterystate_description[] = {
+ { ENVSYS_BATTERY_STATE_NORMAL, -1, "NORMAL" },
+ { ENVSYS_BATTERY_STATE_WARNING, -1, "WARNING" },
+ { ENVSYS_BATTERY_STATE_CRITICAL, -1, "CRITICAL" },
+ { ENVSYS_BATTERY_STATE_LOW, -1, "LOW" },
+ { -1, -1, "UNKNOWN" }
+};
+
+/*
+ * Returns the table associated with type.
+ */
+const struct sme_description_table *
+sme_get_description_table(int type)
+{
+ const struct sme_description_table *ud = sme_units_description;
+ const struct sme_description_table *sd = sme_state_description;
+ const struct sme_description_table *dd = sme_drivestate_description;
+ const struct sme_description_table *bd = sme_batterystate_description;
+
+ switch (type) {
+ case SME_DESC_UNITS:
+ return ud;
+ case SME_DESC_STATES:
+ return sd;
+ case SME_DESC_DRIVE_STATES:
+ return dd;
+ case SME_DESC_BATTERY_STATES:
+ return bd;
+ default:
+ return NULL;
+ }
+}
diff --git a/sys/dev/sysmon/sysmon_envsysvar.h b/sys/dev/sysmon/sysmon_envsysvar.h
index b6c9fc96549..f463cbb981e 100644
--- a/sys/dev/sysmon/sysmon_envsysvar.h
+++ b/sys/dev/sysmon/sysmon_envsysvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.16 2007/08/31 22:44:39 xtraeme Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.17 2007/09/04 16:54:02 xtraeme Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -51,6 +51,13 @@
#include <dev/sysmon/sysmonvar.h>
#include <prop/proplib.h>
+enum sme_description_types {
+ SME_DESC_UNITS = 1,
+ SME_DESC_STATES,
+ SME_DESC_DRIVE_STATES,
+ SME_DESC_BATTERY_STATES
+};
+
#ifdef ENVSYS_DEBUG
#define DPRINTF(x) printf x
#else
@@ -91,6 +98,12 @@ typedef struct sme_event_drv {
int powertype;
} sme_event_drv_t;
+struct sme_description_table {
+ int type;
+ int crittype;
+ const char *desc;
+};
+
/* common */
extern kmutex_t sme_list_mtx; /* mutex to protect the sysmon envsys list */
extern kmutex_t sme_event_mtx; /* mutex to protect the sme event data */
@@ -131,4 +144,6 @@ int sme_sensor_upint32(prop_dictionary_t, const char *, int32_t);
int sme_sensor_upuint32(prop_dictionary_t, const char *, uint32_t);
int sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
+const struct sme_description_table *sme_get_description_table(int);
+
#endif /* _DEV_SYSMON_ENVSYSVAR_H_ */
diff --git a/sys/dev/sysmon/sysmon_power.c b/sys/dev/sysmon/sysmon_power.c
index 151c59729e4..2294154671e 100644
--- a/sys/dev/sysmon/sysmon_power.c
+++ b/sys/dev/sysmon/sysmon_power.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_power.c,v 1.23 2007/09/03 01:29:51 xtraeme Exp $ */
+/* $NetBSD: sysmon_power.c,v 1.24 2007/09/04 16:54:02 xtraeme Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.23 2007/09/03 01:29:51 xtraeme Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.24 2007/09/04 16:54:02 xtraeme Exp $");
#include "opt_compat_netbsd.h"
#include <sys/param.h>
@@ -140,7 +140,7 @@ static const struct power_event_description penvsys_event_desc[] = {
{ PENVSYS_EVENT_USER_CRITMAX, "critical-over" },
{ PENVSYS_EVENT_USER_CRITMIN, "critical-under" },
{ PENVSYS_EVENT_BATT_USERCAP, "user-capacity" },
- { PENVSYS_EVENT_DRIVE_STCHANGED,"state-changed" },
+ { PENVSYS_EVENT_STATE_CHANGED, "state-changed" },
{ -1, NULL }
};
@@ -304,7 +304,7 @@ sysmon_power_daemon_task(void *pev_data, int event)
case PENVSYS_EVENT_USER_CRITMAX:
case PENVSYS_EVENT_USER_CRITMIN:
case PENVSYS_EVENT_BATT_USERCAP:
- case PENVSYS_EVENT_DRIVE_STCHANGED:
+ case PENVSYS_EVENT_STATE_CHANGED:
{
struct penvsys_state *penvsys =
(struct penvsys_state *)pev_data;
@@ -623,7 +623,7 @@ do { \
SETPROP("driver-name", pes->pes_dvname);
SETPROP("sensor-name", pes->pes_sensname);
- SETPROP("drive-state-desc", pes->pes_statedesc);
+ SETPROP("state-description", pes->pes_statedesc);
for (i = 0; peevent[i].type != -1; i++)
if (peevent[i].type == event)
@@ -690,21 +690,17 @@ sysmon_penvsys_event(struct penvsys_state *pes, int event)
switch (pes->pes_type) {
case PENVSYS_TYPE_BATTERY:
switch (event) {
- case PENVSYS_EVENT_WARNUNDER:
- mystr = "warning capacity";
- PENVSYS_SHOWSTATE(mystr);
- break;
- case PENVSYS_EVENT_CRITUNDER:
- mystr = "low capacity";
- PENVSYS_SHOWSTATE(mystr);
+ case PENVSYS_EVENT_STATE_CHANGED:
+ printf("%s: state changed on '%s' to '%s'\n",
+ pes->pes_dvname, pes->pes_sensname,
+ pes->pes_statedesc);
break;
- case PENVSYS_EVENT_CRITICAL:
case PENVSYS_EVENT_BATT_USERCAP:
mystr = "critical capacity";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_NORMAL:
- printf("%s: acceptable capacity on '%s'\n",
+ printf("%s: normal capacity on '%s'\n",
pes->pes_dvname, pes->pes_sensname);
break;
}
@@ -748,7 +744,7 @@ sysmon_penvsys_event(struct penvsys_state *pes, int event)
break;
case PENVSYS_TYPE_DRIVE:
switch (event) {
- case PENVSYS_EVENT_DRIVE_STCHANGED:
+ case PENVSYS_EVENT_STATE_CHANGED:
printf("%s: state changed on '%s' to '%s'\n",
pes->pes_dvname, pes->pes_sensname,
pes->pes_statedesc);