Module Name: src
Committed By: pgoyette
Date: Mon Jun 8 00:55:35 UTC 2009
Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
sysmon_envsysvar.h sysmon_power.c
src/sys/sys: envsys.h power.h
Log Message:
General clean-up and some restructuring of event handling. This is a
precursor to letting sensor drivers actually exchange limits/thresholds
with user-land.
To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/sysmon/sysmon_envsysvar.h
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/sysmon/sysmon_power.c
cvs rdiff -u -r1.24 -r1.25 src/sys/sys/envsys.h
cvs rdiff -u -r1.12 -r1.13 src/sys/sys/power.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/sysmon/sysmon_envsys.c
diff -u src/sys/dev/sysmon/sysmon_envsys.c:1.86 src/sys/dev/sysmon/sysmon_envsys.c:1.87
--- src/sys/dev/sysmon/sysmon_envsys.c:1.86 Wed Jun 3 11:43:15 2009
+++ src/sys/dev/sysmon/sysmon_envsys.c Mon Jun 8 00:55:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys.c,v 1.86 2009/06/03 11:43:15 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys.c,v 1.87 2009/06/08 00:55:35 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.86 2009/06/03 11:43:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.87 2009/06/08 00:55:35 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -84,20 +84,6 @@
kmutex_t sme_global_mtx;
-/*
- * Types of properties that can be set via userland.
- */
-enum {
- USERPROP_DESC = 0x0001,
- USERPROP_BATTCAP = 0x0002,
- USERPROP_CRITMAX = 0x0004,
- USERPROP_CRITMIN = 0x0008,
- USERPROP_RFACT = 0x0010,
- USERPROP_WARNMAX = 0x0020,
- USERPROP_WARNMIN = 0x0040,
- USERPROP_BATTWARN = 0x0080
-};
-
static prop_dictionary_t sme_propd;
static uint32_t sysmon_envsys_next_sensor_index;
static struct sysmon_envsys *sysmon_envsys_find_40(u_int);
@@ -574,6 +560,10 @@
sysmon_envsys_release(sme, true);
mutex_exit(&sme->sme_mtx);
+ DPRINTF(("%s: (%s) attached #%d (%s), units=%d (%s)\n",
+ __func__, sme->sme_name, edata->sensor, edata->desc,
+ sdt_units[i].type, sdt_units[i].desc));
+
return 0;
}
@@ -1057,53 +1047,49 @@
KASSERT(sdict != NULL);
ptype = 0;
- if (edata->upropset & USERPROP_BATTCAP) {
+ if (edata->upropset & PROP_BATTCAP) {
prop_dictionary_remove(sdict,
"critical-capacity");
- ptype = PENVSYS_EVENT_BATT_USER_LIMITS;
+ ptype = PENVSYS_EVENT_CAPACITY;
}
- if (edata->upropset & USERPROP_BATTWARN) {
+ if (edata->upropset & PROP_BATTWARN) {
prop_dictionary_remove(sdict,
"warning-capacity");
- ptype = PENVSYS_EVENT_BATT_USER_LIMITS;
+ ptype = PENVSYS_EVENT_CAPACITY;
}
if (ptype != 0)
sme_event_unregister(sme, edata->desc, ptype);
ptype = 0;
- if (edata->upropset & USERPROP_WARNMAX) {
- prop_dictionary_remove(sdict,
- "warning-max");
- ptype = PENVSYS_EVENT_USER_LIMITS;
+ if (edata->upropset & PROP_WARNMAX) {
+ prop_dictionary_remove(sdict, "warning-max");
+ ptype = PENVSYS_EVENT_LIMITS;
}
- if (edata->upropset & USERPROP_WARNMIN) {
- prop_dictionary_remove(sdict,
- "warning-min");
- ptype = PENVSYS_EVENT_USER_LIMITS;
+ if (edata->upropset & PROP_WARNMIN) {
+ prop_dictionary_remove(sdict, "warning-min");
+ ptype = PENVSYS_EVENT_LIMITS;
}
- if (edata->upropset & USERPROP_CRITMAX) {
- prop_dictionary_remove(sdict,
- "critical-max");
- ptype = PENVSYS_EVENT_USER_LIMITS;
+ if (edata->upropset & PROP_CRITMAX) {
+ prop_dictionary_remove(sdict, "critical-max");
+ ptype = PENVSYS_EVENT_LIMITS;
}
- if (edata->upropset & USERPROP_CRITMIN) {
- prop_dictionary_remove(sdict,
- "critical-min");
- ptype = PENVSYS_EVENT_USER_LIMITS;
+ if (edata->upropset & PROP_CRITMIN) {
+ prop_dictionary_remove(sdict, "critical-min");
+ ptype = PENVSYS_EVENT_LIMITS;
}
if (ptype != 0)
sme_event_unregister(sme, edata->desc, ptype);
- if (edata->upropset & USERPROP_RFACT) {
+ if (edata->upropset & PROP_RFACT) {
(void)sme_sensor_upint32(sdict, "rfact", 0);
edata->rfact = 0;
}
- if (edata->upropset & USERPROP_DESC)
+ if (edata->upropset & PROP_DESC)
(void)sme_sensor_upstring(sdict,
"description", edata->desc);
@@ -1512,9 +1498,9 @@
if (sdt[j].type == edata->state)
break;
- DPRINTFOBJ(("%s: state=%s type=%d flags=%d "
- "units=%d sensor=%d\n", __func__, sdt[j].desc,
- sdt[j].type, edata->flags, edata->units, edata->sensor));
+ DPRINTFOBJ(("%s: sensor #%d type=%d (%s) flags=%d\n",
+ __func__, edata->sensor, sdt[j].type, sdt[j].desc,
+ edata->flags));
error = sme_sensor_upstring(dict, "state", sdt[j].desc);
if (error)
@@ -1528,6 +1514,9 @@
if (sdt[j].type == edata->units)
break;
+ DPRINTFOBJ(("%s: sensor #%d units=%d (%s)\n",
+ __func__, edata->sensor, sdt[j].type, sdt[j].desc));
+
error = sme_sensor_upstring(dict, "type", sdt[j].desc);
if (error)
break;
@@ -1664,7 +1653,8 @@
prop_dictionary_t dict, tdict = NULL;
prop_object_t obj, obj1, obj2, tobj = NULL;
uint64_t refresh_timo = 0;
- int32_t critval;
+ int32_t critmax = 0, warnmax = 0, warnmin = 0, critmin = 0;
+ int props = 0;
int i, error = 0;
const char *blah;
bool targetfound = false;
@@ -1766,7 +1756,7 @@
DPRINTF(("%s: sensor%d changed desc to: %s\n",
__func__, edata->sensor, blah));
- edata->upropset |= USERPROP_DESC;
+ edata->upropset |= PROP_DESC;
mutex_exit(&sme->sme_mtx);
}
@@ -1779,7 +1769,7 @@
if (edata->flags & ENVSYS_FCHANGERFACT) {
mutex_enter(&sme->sme_mtx);
edata->rfact = prop_number_integer_value(obj2);
- edata->upropset |= USERPROP_RFACT;
+ edata->upropset |= PROP_RFACT;
mutex_exit(&sme->sme_mtx);
DPRINTF(("%s: sensor%d changed rfact to %d\n",
__func__, edata->sensor, edata->rfact));
@@ -1796,10 +1786,6 @@
/*
* did the user want to set a critical capacity event?
- *
- * NOTE: if sme_event_register returns EEXIST that means
- * the object is already there, but this is not a real
- * error, because the object might be updated.
*/
obj2 = prop_dictionary_get(udict, "critical-capacity");
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
@@ -1810,30 +1796,12 @@
goto out;
}
- critval = prop_number_integer_value(obj2);
- error = sme_event_register(dict,
- edata,
- sme,
- "critical-capacity",
- critval,
- PENVSYS_EVENT_BATT_USERCAP,
- sdt[i].crittype);
- if (error == EEXIST)
- error = 0;
- if (error)
- goto out;
-
- mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_BATTCAP;
- mutex_exit(&sme->sme_mtx);
+ critmin = prop_number_integer_value(obj2);
+ props |= PROP_BATTCAP;
}
/*
* did the user want to set a warning capacity event?
- *
- * NOTE: if sme_event_register returns EEXIST that means
- * the object is already there, but this is not a real
- * error, because the object might be updated.
*/
obj2 = prop_dictionary_get(udict, "warning-capacity");
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
@@ -1844,22 +1812,8 @@
goto out;
}
- critval = prop_number_integer_value(obj2);
- error = sme_event_register(dict,
- edata,
- sme,
- "warning-capacity",
- critval,
- PENVSYS_EVENT_BATT_USERWARN,
- sdt[i].crittype);
- if (error == EEXIST)
- error = 0;
- if (error)
- goto out;
-
- mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_BATTWARN;
- mutex_exit(&sme->sme_mtx);
+ warnmin = prop_number_integer_value(obj2);
+ props |= PROP_BATTWARN;
}
/*
@@ -1869,27 +1823,14 @@
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
targetfound = true;
if (edata->units == ENVSYS_INDICATOR ||
- edata->flags & ENVSYS_FMONNOTSUPP) {
+ edata->flags &
+ (ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
error = ENOTSUP;
goto out;
}
- critval = prop_number_integer_value(obj2);
- error = sme_event_register(dict,
- edata,
- sme,
- "critical-max",
- critval,
- PENVSYS_EVENT_USER_CRITMAX,
- sdt[i].crittype);
- if (error == EEXIST)
- error = 0;
- if (error)
- goto out;
-
- mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_CRITMAX;
- mutex_exit(&sme->sme_mtx);
+ critmax = prop_number_integer_value(obj2);
+ props |= PROP_CRITMAX;
}
/*
@@ -1899,27 +1840,14 @@
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
targetfound = true;
if (edata->units == ENVSYS_INDICATOR ||
- edata->flags & ENVSYS_FMONNOTSUPP) {
+ edata->flags &
+ (ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
error = ENOTSUP;
goto out;
}
- critval = prop_number_integer_value(obj2);
- error = sme_event_register(dict,
- edata,
- sme,
- "warning-max",
- critval,
- PENVSYS_EVENT_USER_WARNMAX,
- sdt[i].crittype);
- if (error == EEXIST)
- error = 0;
- if (error)
- goto out;
-
- mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_WARNMAX;
- mutex_exit(&sme->sme_mtx);
+ warnmax = prop_number_integer_value(obj2);
+ props |= PROP_WARNMAX;
}
/*
@@ -1929,27 +1857,14 @@
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
targetfound = true;
if (edata->units == ENVSYS_INDICATOR ||
- edata->flags & ENVSYS_FMONNOTSUPP) {
+ edata->flags &
+ (ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
error = ENOTSUP;
goto out;
}
- critval = prop_number_integer_value(obj2);
- error = sme_event_register(dict,
- edata,
- sme,
- "critical-min",
- critval,
- PENVSYS_EVENT_USER_CRITMIN,
- sdt[i].crittype);
- if (error == EEXIST)
- error = 0;
- if (error)
- goto out;
-
- mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_CRITMIN;
- mutex_exit(&sme->sme_mtx);
+ critmin = prop_number_integer_value(obj2);
+ props |= PROP_CRITMIN;
}
/*
@@ -1959,18 +1874,25 @@
if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
targetfound = true;
if (edata->units == ENVSYS_INDICATOR ||
- edata->flags & ENVSYS_FMONNOTSUPP) {
+ edata->flags &
+ (ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
error = ENOTSUP;
goto out;
}
- critval = prop_number_integer_value(obj2);
+ warnmin = prop_number_integer_value(obj2);
+ props |= PROP_WARNMIN;
+ }
+
+ if (props) {
error = sme_event_register(dict,
edata,
sme,
- "warning-min",
- critval,
- PENVSYS_EVENT_USER_WARNMIN,
+ critmax, warnmax, warnmin,
+ critmin, props,
+ (edata->flags & ENVSYS_FPERCENT)?
+ PENVSYS_EVENT_CAPACITY:
+ PENVSYS_EVENT_LIMITS,
sdt[i].crittype);
if (error == EEXIST)
error = 0;
@@ -1978,7 +1900,7 @@
goto out;
mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_WARNMIN;
+ edata->upropset |= props;
mutex_exit(&sme->sme_mtx);
}
Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.64 src/sys/dev/sysmon/sysmon_envsys_events.c:1.65
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.64 Mon Jun 1 20:08:45 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c Mon Jun 8 00:55:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.64 2009/06/01 20:08:45 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.65 2009/06/08 00:55:35 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.64 2009/06/01 20:08:45 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.65 2009/06/08 00:55:35 pgoyette Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -54,12 +54,15 @@
};
static const struct sme_sensor_event sme_sensor_event[] = {
- { ENVSYS_SVALID, PENVSYS_EVENT_NORMAL },
- { ENVSYS_SCRITOVER, PENVSYS_EVENT_CRITOVER },
- { ENVSYS_SCRITUNDER, PENVSYS_EVENT_CRITUNDER },
- { ENVSYS_SWARNOVER, PENVSYS_EVENT_WARNOVER },
- { ENVSYS_SWARNUNDER, PENVSYS_EVENT_WARNUNDER },
- { -1, -1 }
+ { ENVSYS_SVALID, PENVSYS_EVENT_NORMAL },
+ { ENVSYS_SCRITOVER, PENVSYS_EVENT_CRITOVER },
+ { ENVSYS_SCRITUNDER, PENVSYS_EVENT_CRITUNDER },
+ { ENVSYS_SWARNOVER, PENVSYS_EVENT_WARNOVER },
+ { ENVSYS_SWARNUNDER, PENVSYS_EVENT_WARNUNDER },
+ { ENVSYS_BATTERY_CAPACITY_NORMAL, PENVSYS_EVENT_NORMAL },
+ { ENVSYS_BATTERY_CAPACITY_WARNING, PENVSYS_EVENT_BATT_WARN },
+ { ENVSYS_BATTERY_CAPACITY_CRITICAL, PENVSYS_EVENT_BATT_CRIT },
+ { -1, -1 }
};
static bool sysmon_low_power;
@@ -79,41 +82,16 @@
*/
int
sme_event_register(prop_dictionary_t sdict, envsys_data_t *edata,
- struct sysmon_envsys *sme, const char *objkey,
- int32_t critval, int crittype, int powertype)
+ struct sysmon_envsys *sme, int32_t critmax,
+ int32_t warnmax, int32_t warnmin, int32_t critmin,
+ int lim_flags, int crittype, int powertype)
{
sme_event_t *see = NULL, *osee = NULL;
prop_object_t obj;
- bool critvalup = false;
int error = 0;
- int real_crittype;
- int32_t o_critval;
+ const char *objkey;
KASSERT(sdict != NULL || edata != NULL || sme != NULL);
- /*
- * Allocate a new sysmon_envsys event.
- */
- see = kmem_zalloc(sizeof(*see), KM_SLEEP);
- if (see == NULL)
- return ENOMEM;
-
- /*
- * Map user-types to kernel types
- */
- switch (crittype) {
- case PENVSYS_EVENT_USER_CRITMAX:
- case PENVSYS_EVENT_USER_CRITMIN:
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_USER_WARNMIN:
- real_crittype = PENVSYS_EVENT_USER_LIMITS;
- break;
- case PENVSYS_EVENT_BATT_USERCAP:
- case PENVSYS_EVENT_BATT_USERWARN:
- real_crittype = PENVSYS_EVENT_BATT_USER_LIMITS;
- break;
- default:
- real_crittype = crittype;
- }
/*
* check if the event is already on the list and return
@@ -121,185 +99,225 @@
*/
mutex_enter(&sme->sme_mtx);
LIST_FOREACH(osee, &sme->sme_events_list, see_list) {
- if (strcmp(edata->desc, osee->see_pes.pes_sensname) == 0)
- if (real_crittype == osee->see_type) {
- switch (crittype) {
- case PENVSYS_EVENT_USER_CRITMAX:
- case PENVSYS_EVENT_BATT_USERCAP:
- o_critval = osee->see_critmax;
- break;
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_BATT_USERWARN:
- o_critval = osee->see_warnmax;
- break;
- case PENVSYS_EVENT_USER_WARNMIN:
- o_critval = osee->see_warnmin;
- break;
- case PENVSYS_EVENT_USER_CRITMIN:
- default:
- o_critval = osee->see_critmin;
- break;
- }
- if (o_critval == critval) {
- DPRINTF(("%s: dev=%s sensor=%s type=%d "
- "(already exists)\n", __func__,
- osee->see_pes.pes_dvname,
- osee->see_pes.pes_sensname,
- osee->see_type));
- error = EEXIST;
- goto out;
- }
- critvalup = true;
- break;
- }
- }
+ if (strcmp(edata->desc, osee->see_pes.pes_sensname) != 0)
+ continue;
+ if (crittype != osee->see_type)
+ continue;
- /*
- * Critical condition operation requested by userland.
- */
- if (objkey && critval && critvalup) {
- obj = prop_dictionary_get(sdict, objkey);
- if (obj && prop_object_type(obj) == PROP_TYPE_NUMBER) {
- /*
- * object is already in dictionary and value
- * provided is not the same than we have
- * currently, update the critical value.
- */
- switch (crittype) {
- case PENVSYS_EVENT_USER_CRITMAX:
- case PENVSYS_EVENT_BATT_USERCAP:
- osee->see_critmax = critval;
- break;
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_BATT_USERWARN:
- osee->see_warnmax = critval;
- break;
- case PENVSYS_EVENT_USER_WARNMIN:
- osee->see_warnmin = critval;
- break;
- case PENVSYS_EVENT_USER_CRITMIN:
- default:
- osee->see_critmin = critval;
- break;
+ DPRINTF(("%s: dev %s sensor %s lim_flags 0x%04x event exists\n",
+ __func__, sme->sme_name, edata->desc, lim_flags));
+
+ see = osee;
+ if (lim_flags & PROP_CRITMAX) {
+ if (critmax == see->see_critmax) {
+ DPRINTF(("%s: type=%d (critmax exists)\n",
+ __func__, crittype));
+ error = EEXIST;
+ lim_flags &= ~PROP_CRITMAX;
}
- DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
- "(critval updated)\n", __func__, sme->sme_name,
- edata->desc, osee->see_type));
- error = sme_sensor_upint32(sdict, objkey, critval);
- goto out;
}
+ if (lim_flags & PROP_WARNMAX) {
+ if (warnmax == see->see_warnmax) {
+ DPRINTF(("%s: type=%d (warnmax exists)\n",
+ __func__, crittype));
+ error = EEXIST;
+ lim_flags &= ~PROP_WARNMAX;
+ }
+ }
+ if (lim_flags & (PROP_WARNMIN | PROP_BATTWARN)) {
+ if (warnmin == see->see_warnmin) {
+ DPRINTF(("%s: type=%d (warnmin exists)\n",
+ __func__, crittype));
+ error = EEXIST;
+ lim_flags &= ~(PROP_WARNMIN | PROP_BATTWARN);
+ }
+ }
+ if (lim_flags & (PROP_CRITMIN | PROP_BATTCAP)) {
+ if (critmin == see->see_critmin) {
+ DPRINTF(("%s: type=%d (critmin exists)\n",
+ __func__, crittype));
+ error = EEXIST;
+ lim_flags &= ~(PROP_CRITMIN | PROP_BATTCAP);
+ }
+ }
+ break;
}
+ if (see == NULL) {
+ /*
+ * New event requested - allocate a sysmon_envsys event.
+ */
+ see = kmem_zalloc(sizeof(*see), KM_SLEEP);
+ if (see == NULL)
+ return ENOMEM;
+
+ DPRINTF(("%s: dev %s sensor %s lim_flags 0x%04x new event\n",
+ __func__, sme->sme_name, edata->desc, lim_flags));
+
+ see->see_type = crittype;
+ see->see_sme = sme;
+ see->see_edata = edata;
+
+ /* Initialize sensor type and previously-sent state */
+
+ see->see_pes.pes_type = powertype;
- /*
- * New limit defined for existing event
- */
- if (osee != NULL) {
- osee->see_edata = edata;
switch (crittype) {
- case PENVSYS_EVENT_USER_CRITMAX:
- case PENVSYS_EVENT_BATT_USERCAP:
- osee->see_critmax = critval;
- break;
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_BATT_USERWARN:
- osee->see_warnmax = critval;
+ case PENVSYS_EVENT_LIMITS:
+ see->see_evsent = ENVSYS_SVALID;
+ break;
+ case PENVSYS_EVENT_CAPACITY:
+ see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
break;
- case PENVSYS_EVENT_USER_WARNMIN:
- osee->see_warnmin = critval;
+ case PENVSYS_EVENT_STATE_CHANGED:
+ if (edata->units == ENVSYS_BATTERY_CAPACITY)
+ see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
+ else if (edata->units == ENVSYS_DRIVE)
+ see->see_evsent = ENVSYS_DRIVE_EMPTY;
+ else
+ panic("%s: bad units for "
+ "PENVSYS_EVENT_STATE_CHANGED", __func__);
break;
- case PENVSYS_EVENT_USER_CRITMIN:
+ case PENVSYS_EVENT_CRITICAL:
default:
- osee->see_critmin = critval;
+ see->see_evsent = 0;
break;
}
- if (objkey && critval) {
- error = sme_sensor_upint32(sdict, objkey, critval);
- if (error)
- goto out;
- }
- DPRINTF(("%s: (%s) new limit added to existing event, type %d "
- "critmin=%" PRIu32 " warnmin=%" PRIu32 " warnmax=%"
- PRIu32 " critmax=%d\n", __func__, osee->see_sme->sme_name,
- osee->see_type, osee->see_critmin, osee->see_warnmin,
- osee->see_warnmax, osee->see_critmax));
- goto out;
+
+ (void)strlcpy(see->see_pes.pes_dvname, sme->sme_name,
+ sizeof(see->see_pes.pes_dvname));
+ (void)strlcpy(see->see_pes.pes_sensname, edata->desc,
+ sizeof(see->see_pes.pes_sensname));
}
+
/*
- * New event requested.
+ * Limit operation requested.
*/
- see->see_edata = edata;
- switch (crittype) {
- case PENVSYS_EVENT_USER_CRITMAX:
- case PENVSYS_EVENT_BATT_USERCAP:
- see->see_critmax = critval;
- break;
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_BATT_USERWARN:
- see->see_warnmax = critval;
- break;
- case PENVSYS_EVENT_USER_WARNMIN:
- see->see_warnmin = critval;
- break;
- case PENVSYS_EVENT_USER_CRITMIN:
- default:
- see->see_critmin = critval;
- break;
+ if (lim_flags & PROP_CRITMAX) {
+ objkey = "critical-max";
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj && prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ see->see_critmax = critmax;
+ error = sme_sensor_upint32(sdict, objkey, critmax);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
}
- see->see_type = real_crittype;
- see->see_sme = sme;
+ if (error && error != EEXIST)
+ goto out;
- /* Initialize sensor type and previously-sent state */
+ if (lim_flags & PROP_WARNMAX) {
+ objkey = "warning-max";
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj && prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ see->see_warnmax = warnmax;
+ error = sme_sensor_upint32(sdict, objkey, warnmax);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
+ }
+ if (error && error != EEXIST)
+ goto out;
- see->see_pes.pes_type = powertype;
- switch (real_crittype) {
- case PENVSYS_EVENT_HW_LIMITS:
- case PENVSYS_EVENT_USER_LIMITS:
- case PENVSYS_EVENT_BATT_USER_LIMITS:
- see->see_evsent = ENVSYS_SVALID;
- break;
- case PENVSYS_EVENT_STATE_CHANGED:
- if (edata->units == ENVSYS_BATTERY_CAPACITY)
- see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
- else if (edata->units == ENVSYS_DRIVE)
- see->see_evsent = ENVSYS_DRIVE_EMPTY;
-#ifdef DIAGNOSTIC
- else
- panic("%s: bad units for "
- "PENVSYS_EVENT_STATE_CHANGED", __func__);
-#endif
- break;
- case PENVSYS_EVENT_CRITICAL:
- default:
- see->see_evsent = 0;
- break;
+ if (lim_flags & PROP_WARNMIN) {
+ objkey = "warning-min";
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj && prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ see->see_warnmin = warnmin;
+ error = sme_sensor_upint32(sdict, objkey, warnmin);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
}
+ if (error && error != EEXIST)
+ goto out;
- (void)strlcpy(see->see_pes.pes_dvname, sme->sme_name,
- sizeof(see->see_pes.pes_dvname));
- (void)strlcpy(see->see_pes.pes_sensname, edata->desc,
- sizeof(see->see_pes.pes_sensname));
-
- LIST_INSERT_HEAD(&sme->sme_events_list, see, see_list);
- if (objkey && critval) {
- error = sme_sensor_upint32(sdict, objkey, critval);
- if (error)
- goto out;
+ if (lim_flags & PROP_CRITMIN) {
+ objkey = "critical-min";
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj && prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ see->see_critmin = critmin;
+ error = sme_sensor_upint32(sdict, objkey, critmin);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
+ }
+ if (error && error != EEXIST)
+ goto out;
+
+ if (lim_flags & PROP_BATTWARN) {
+ objkey = "warning-capacity";
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj && prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ see->see_warnmin = warnmin;
+ error = sme_sensor_upint32(sdict, objkey, warnmin);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
}
+ if (error && error != EEXIST)
+ goto out;
+
+ if (lim_flags & PROP_BATTCAP) {
+ objkey = "critical-capacity";
+ obj = prop_dictionary_get(sdict, objkey);
+ if (obj && prop_object_type(obj) != PROP_TYPE_NUMBER) {
+ DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+ __func__, sme->sme_name, objkey));
+ error = ENOTSUP;
+ } else {
+ see->see_critmin = critmin;
+ error = sme_sensor_upint32(sdict, objkey, critmin);
+ DPRINTF(("%s: (%s) event [sensor=%s type=%d] "
+ "(%s updated)\n", __func__, sme->sme_name,
+ edata->desc, crittype, objkey));
+ }
+ }
+ if (error && error != EEXIST)
+ goto out;
+
DPRINTF(("%s: (%s) event registered (sensor=%s snum=%d type=%d "
"critmin=%" PRIu32 " warnmin=%" PRIu32 " warnmax=%" PRIu32
- " crixmax=%" PRIu32 ")\n", __func__,
+ " critmax=%" PRIu32 " props 0x%04x)\n", __func__,
see->see_sme->sme_name, see->see_pes.pes_sensname,
see->see_edata->sensor, see->see_type, see->see_critmin,
- see->see_warnmin, see->see_warnmax, see->see_critmax));
+ see->see_warnmin, see->see_warnmax, see->see_critmax,
+ see->see_edata->upropset));
/*
* Initialize the events framework if it wasn't initialized before.
*/
if ((sme->sme_flags & SME_CALLOUT_INITIALIZED) == 0)
error = sme_events_init(sme);
out:
+ if ((error == 0 || error == EEXIST) && osee == NULL)
+ LIST_INSERT_HEAD(&sme->sme_events_list, see, see_list);
+
mutex_exit(&sme->sme_mtx);
- if (error || critvalup)
- kmem_free(see, sizeof(*see));
+
return error;
}
@@ -422,8 +440,7 @@
error = sme_event_register(sed_t->sed_sdict, \
sed_t->sed_edata, \
sed_t->sed_sme, \
- NULL, \
- 0, \
+ 0, 0, 0, 0, 0, \
(b), \
sed_t->sed_powertype); \
if (error && error != EEXIST) \
@@ -445,7 +462,7 @@
"critical");
SEE_REGEVENT(ENVSYS_FMONLIMITS,
- PENVSYS_EVENT_HW_LIMITS,
+ PENVSYS_EVENT_LIMITS,
"hw-range-limits");
SEE_REGEVENT(ENVSYS_FMONSTCHANGED,
@@ -565,15 +582,14 @@
if ((see->see_flags & SEE_EVENT_WORKING) == 0)
see->see_flags |= SEE_EVENT_WORKING;
/*
- * sme_events_check marks the first event for the device to
- * make us refresh it here. Don't refresh if the driver uses
- * its own method for refreshing.
+ * sme_events_check marks the sensors to make us refresh them here.
+ * Don't refresh if the driver uses its own method for refreshing.
*/
if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
- if ((see->see_edata->flags & ENVSYS_FNEED_REFRESH) != 0) {
+ if ((edata->flags & ENVSYS_FNEED_REFRESH) != 0) {
/* refresh sensor in device */
(*sme->sme_refresh)(sme, edata);
- see->see_edata->flags &= ~ENVSYS_FNEED_REFRESH;
+ edata->flags &= ~ENVSYS_FNEED_REFRESH;
}
}
@@ -592,8 +608,8 @@
* State based on user limits will override any hardware
* detected state.
*/
- case PENVSYS_EVENT_USER_LIMITS:
- case PENVSYS_EVENT_BATT_USER_LIMITS:
+ case PENVSYS_EVENT_LIMITS:
+ case PENVSYS_EVENT_CAPACITY:
#define __EXCEEDED_LIMIT(lim, rel) ((lim) && edata->value_cur rel (lim))
if __EXCEEDED_LIMIT(see->see_critmin, <)
edata->state = ENVSYS_SCRITUNDER;
@@ -605,10 +621,7 @@
edata->state = ENVSYS_SCRITOVER;
/* FALLTHROUGH */
#undef __EXCEED_LIMIT
- /*
- * For hardware and user range limits, send event if state has changed
- */
- case PENVSYS_EVENT_HW_LIMITS:
+
if (edata->state == see->see_evsent)
break;
@@ -671,7 +684,7 @@
state = ENVSYS_BATTERY_CAPACITY_NORMAL;
break;
default:
- panic("%s: invalid units for ENVSYS_FMONSTCHANGED",
+ panic("%s: bad units for PENVSYS_EVENT_STATE_CHANGED",
__func__);
}
@@ -688,25 +701,19 @@
(void)strlcpy(see->see_pes.pes_statedesc, sdt[i].desc,
sizeof(see->see_pes.pes_statedesc));
- /*
- * state is ok again... send a normal event.
- */
- if (see->see_evsent && edata->value_cur == state) {
+ if (edata->value_cur == state)
+ /*
+ * state returned to normal condition
+ */
sysmon_penvsys_event(&see->see_pes,
PENVSYS_EVENT_NORMAL);
- see->see_evsent = false;
- }
-
- /*
- * state has been changed... send event.
- */
- if (see->see_evsent || edata->value_cur != state) {
- /*
- * save current drive state.
+ else
+ /*
+ * state changed to abnormal condition
*/
- see->see_evsent = edata->value_cur;
sysmon_penvsys_event(&see->see_pes, see->see_type);
- }
+
+ see->see_evsent = edata->value_cur;
/*
* There's no need to continue if it's a drive sensor.
Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.28 src/sys/dev/sysmon/sysmon_envsysvar.h:1.29
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.28 Fri Aug 22 11:27:50 2008
+++ src/sys/dev/sysmon/sysmon_envsysvar.h Mon Jun 8 00:55:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.28 2008/08/22 11:27:50 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.29 2009/06/08 00:55:35 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -65,15 +65,6 @@
#define SME_EVENTS_DEFTIMEOUT 30
/*
- * struct used by a sensor description in a sysmon envsys device.
- */
-struct sme_sensor_names {
- SLIST_ENTRY(sme_sensor_names) sme_names;
- int assigned;
- char desc[ENVSYS_DESCLEN];
-};
-
-/*
* struct used by a sysmon envsys event.
*/
typedef struct sme_event {
@@ -137,8 +128,8 @@
* functions to handle sysmon envsys events.
*/
int sme_event_register(prop_dictionary_t, envsys_data_t *,
- struct sysmon_envsys *, const char *,
- int32_t, int, int);
+ struct sysmon_envsys *, int32_t, int32_t,
+ int32_t, int32_t, int, int, int);
int sme_event_unregister(struct sysmon_envsys *, const char *, int);
void sme_event_unregister_all(struct sysmon_envsys *);
void sme_event_drvadd(void *);
Index: src/sys/dev/sysmon/sysmon_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.40 src/sys/dev/sysmon/sysmon_power.c:1.41
--- src/sys/dev/sysmon/sysmon_power.c:1.40 Fri Sep 5 21:58:32 2008
+++ src/sys/dev/sysmon/sysmon_power.c Mon Jun 8 00:55:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_power.c,v 1.40 2008/09/05 21:58:32 gmcgarry Exp $ */
+/* $NetBSD: sysmon_power.c,v 1.41 2009/06/08 00:55:35 pgoyette Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.40 2008/09/05 21:58:32 gmcgarry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.41 2009/06/08 00:55:35 pgoyette Exp $");
#include "opt_compat_netbsd.h"
#include <sys/param.h>
@@ -133,12 +133,8 @@
{ PENVSYS_EVENT_CRITUNDER, "critical-under" },
{ PENVSYS_EVENT_WARNOVER, "warning-over" },
{ PENVSYS_EVENT_WARNUNDER, "warning-under" },
- { PENVSYS_EVENT_USER_CRITMAX, "critical-over" },
- { PENVSYS_EVENT_USER_CRITMIN, "critical-under" },
- { PENVSYS_EVENT_USER_WARNMAX, "warning-over" },
- { PENVSYS_EVENT_USER_WARNMIN, "warning-under" },
- { PENVSYS_EVENT_BATT_USERCAP, "user-capacity" },
- { PENVSYS_EVENT_BATT_USERWARN, "user-cap-warning" },
+ { PENVSYS_EVENT_BATT_CRIT, "critical-capacity" },
+ { PENVSYS_EVENT_BATT_WARN, "warning-capacity" },
{ PENVSYS_EVENT_STATE_CHANGED, "state-changed" },
{ PENVSYS_EVENT_LOW_POWER, "low-power" },
{ -1, NULL }
@@ -320,12 +316,8 @@
case PENVSYS_EVENT_CRITOVER:
case PENVSYS_EVENT_WARNUNDER:
case PENVSYS_EVENT_WARNOVER:
- case PENVSYS_EVENT_USER_CRITMAX:
- case PENVSYS_EVENT_USER_CRITMIN:
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_USER_WARNMIN:
- case PENVSYS_EVENT_BATT_USERCAP:
- case PENVSYS_EVENT_BATT_USERWARN:
+ case PENVSYS_EVENT_BATT_CRIT:
+ case PENVSYS_EVENT_BATT_WARN:
case PENVSYS_EVENT_STATE_CHANGED:
case PENVSYS_EVENT_LOW_POWER:
{
@@ -807,11 +799,11 @@
pes->pes_dvname, pes->pes_sensname,
pes->pes_statedesc);
break;
- case PENVSYS_EVENT_BATT_USERCAP:
+ case PENVSYS_EVENT_BATT_CRIT:
mystr = "critical capacity";
PENVSYS_SHOWSTATE(mystr);
break;
- case PENVSYS_EVENT_BATT_USERWARN:
+ case PENVSYS_EVENT_BATT_WARN:
mystr = "warning capacity";
PENVSYS_SHOWSTATE(mystr);
break;
@@ -833,22 +825,18 @@
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_CRITOVER:
- case PENVSYS_EVENT_USER_CRITMAX:
mystr = "critical over";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_CRITUNDER:
- case PENVSYS_EVENT_USER_CRITMIN:
mystr = "critical under";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_WARNOVER:
- case PENVSYS_EVENT_USER_WARNMAX:
mystr = "warning over";
PENVSYS_SHOWSTATE(mystr);
break;
case PENVSYS_EVENT_WARNUNDER:
- case PENVSYS_EVENT_USER_WARNMIN:
mystr = "warning under";
PENVSYS_SHOWSTATE(mystr);
break;
Index: src/sys/sys/envsys.h
diff -u src/sys/sys/envsys.h:1.24 src/sys/sys/envsys.h:1.25
--- src/sys/sys/envsys.h:1.24 Mon Jun 1 20:08:44 2009
+++ src/sys/sys/envsys.h Mon Jun 8 00:55:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: envsys.h,v 1.24 2009/06/01 20:08:44 pgoyette Exp $ */
+/* $NetBSD: envsys.h,v 1.25 2009/06/08 00:55:35 pgoyette Exp $ */
/*-
* Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -137,11 +137,26 @@
#define ENVSYS_FMONNOTSUPP 0x00000800 /* monitoring not supported */
#define ENVSYS_FNEED_REFRESH 0x00001000 /* sensor needs refreshing */
+/*
+ * IOCTLs
+ */
#define ENVSYS_GETDICTIONARY _IOWR('E', 0, struct plistref)
#define ENVSYS_SETDICTIONARY _IOWR('E', 1, struct plistref)
#define ENVSYS_REMOVEPROPS _IOWR('E', 2, struct plistref)
/*
+ * Properties that can be set in upropset
+ */
+#define PROP_CRITMAX 0x0001
+#define PROP_CRITMIN 0x0002
+#define PROP_WARNMAX 0x0004
+#define PROP_WARNMIN 0x0008
+#define PROP_BATTCAP 0x0010
+#define PROP_BATTWARN 0x0020
+#define PROP_DESC 0x0040
+#define PROP_RFACT 0x0080
+
+/*
* Compatibility with old interface. Only ENVSYS_GTREDATA
* and ENVSYS_GTREINFO ioctls are supported.
*/
Index: src/sys/sys/power.h
diff -u src/sys/sys/power.h:1.12 src/sys/sys/power.h:1.13
--- src/sys/sys/power.h:1.12 Fri Aug 22 11:27:50 2008
+++ src/sys/sys/power.h Mon Jun 8 00:55:35 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: power.h,v 1.12 2008/08/22 11:27:50 pgoyette Exp $ */
+/* $NetBSD: power.h,v 1.13 2009/06/08 00:55:35 pgoyette Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -154,17 +154,7 @@
*
* PENVSYS_EVENT_WARNUNDER A warning over limit.
*
- * The following events apply to the same except for batteries:
- *
- * PENVSYS_EVENT_USER_CRITMAX User critical max limit.
- *
- * PENVSYS_EVENT_USER_CRITMIN User critical min limit.
- *
- * PENVSYS_EVENT_USER_WARNMAX User warning max limit.
- *
- * PENVSYS_EVENT_USER_WARNMIN User warning min limit.
- *
- * The folowing event apply to all sensors, when the state is
+ * The folowing event applies to all sensors, when the state is
* valid or the warning or critical limit is not valid anymore:
*
* PENVSYS_EVENT_NORMAL Normal state in the sensor.
@@ -176,25 +166,21 @@
#define PENVSYS_EVENT_CRITUNDER 120
#define PENVSYS_EVENT_WARNOVER 130
#define PENVSYS_EVENT_WARNUNDER 140
-#define PENVSYS_EVENT_USER_CRITMAX 150
-#define PENVSYS_EVENT_USER_WARNMAX 155
-#define PENVSYS_EVENT_USER_CRITMIN 160
-#define PENVSYS_EVENT_USER_WARNMIN 165
/*
* The following events apply for battery sensors:
*
- * PENVSYS_EVENT_BATT_USERCAP User critical capacity.
+ * PENVSYS_EVENT_BATT_CRIT User critical capacity.
*
- * PENVSYS_EVENT_BATT_USERWARN User warning capacity.
+ * PENVSYS_EVENT_BATT_WARN User warning capacity.
*
* PENVSYS_EVENT_LOW_POWER AC Adapter is OFF and all batteries
* are discharged.
*/
-#define PENVSYS_EVENT_BATT_USERCAP 170
-#define PENVSYS_EVENT_BATT_USERWARN 175
-#define PENVSYS_EVENT_LOW_POWER 180
+#define PENVSYS_EVENT_BATT_CRIT 170
+#define PENVSYS_EVENT_BATT_WARN 175
+#define PENVSYS_EVENT_LOW_POWER 180
/*
* The following event apply for battery state and drive sensors:
@@ -208,9 +194,8 @@
* The following events are used internally to associate multiple
* external states with a single event monitor
*/
-#define PENVSYS_EVENT_HW_LIMITS 200
-#define PENVSYS_EVENT_USER_LIMITS 210
-#define PENVSYS_EVENT_BATT_USER_LIMITS 220
+#define PENVSYS_EVENT_LIMITS 200
+#define PENVSYS_EVENT_CAPACITY 210
/*
* This structure defines the properties of an envsys event.