summaryrefslogtreecommitdiff
path: root/sys/dev/sysmon
diff options
context:
space:
mode:
authorpgoyette <pgoyette@NetBSD.org>2009-06-08 00:55:35 +0000
committerpgoyette <pgoyette@NetBSD.org>2009-06-08 00:55:35 +0000
commitf7ad703892bf2749610de5bddda7dbefedb7b00f (patch)
treeae96e000e4a1bee4546a4eda898c5b44df8855a4 /sys/dev/sysmon
parent5c0faad4bd1b8904fdb360e3e7994135ad8f45dd (diff)
General clean-up and some restructuring of event handling. This is a
precursor to letting sensor drivers actually exchange limits/thresholds with user-land.
Diffstat (limited to 'sys/dev/sysmon')
-rw-r--r--sys/dev/sysmon/sysmon_envsys.c204
-rw-r--r--sys/dev/sysmon/sysmon_envsys_events.c433
-rw-r--r--sys/dev/sysmon/sysmon_envsysvar.h15
-rw-r--r--sys/dev/sysmon/sysmon_power.c28
4 files changed, 294 insertions, 386 deletions
diff --git a/sys/dev/sysmon/sysmon_envsys.c b/sys/dev/sysmon/sysmon_envsys.c
index fbfe194f043..aee2ee3425a 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.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 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.86 2009/06/03 11:43:15 pgoyette
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_sensor_attach(struct sysmon_envsys *sme, envsys_data_t *edata)
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 @@ sme_remove_userprops(void)
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 @@ sme_update_dictionary(struct sysmon_envsys *sme)
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 @@ sme_update_dictionary(struct sysmon_envsys *sme)
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
/*
* 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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
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 @@ sme_userset_dictionary(struct sysmon_envsys *sme, prop_dictionary_t udict,
goto out;
mutex_enter(&sme->sme_mtx);
- edata->upropset |= USERPROP_WARNMIN;
+ edata->upropset |= props;
mutex_exit(&sme->sme_mtx);
}
diff --git a/sys/dev/sysmon/sysmon_envsys_events.c b/sys/dev/sysmon/sysmon_envsys_events.c
index bdbe4329788..cfb08000d49 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.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 @@ struct sme_sensor_event {
};
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 @@ static bool sme_acadapter_check(void);
*/
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 @@ sme_event_register(prop_dictionary_t sdict, envsys_data_t *edata,
*/
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;
+ case PENVSYS_EVENT_LIMITS:
+ see->see_evsent = ENVSYS_SVALID;
break;
- case PENVSYS_EVENT_USER_WARNMAX:
- case PENVSYS_EVENT_BATT_USERWARN:
- osee->see_warnmax = critval;
+ 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));
+ 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;
- 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_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 @@ do { \
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 @@ do { \
"critical");
SEE_REGEVENT(ENVSYS_FMONLIMITS,
- PENVSYS_EVENT_HW_LIMITS,
+ PENVSYS_EVENT_LIMITS,
"hw-range-limits");
SEE_REGEVENT(ENVSYS_FMONSTCHANGED,
@@ -565,15 +582,14 @@ sme_events_worker(struct work *wk, void *arg)
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 @@ sme_events_worker(struct work *wk, void *arg)
* 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 @@ sme_events_worker(struct work *wk, void *arg)
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 @@ sme_events_worker(struct work *wk, void *arg)
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 @@ sme_events_worker(struct work *wk, void *arg)
(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.
diff --git a/sys/dev/sysmon/sysmon_envsysvar.h b/sys/dev/sysmon/sysmon_envsysvar.h
index 1335bab83cd..1c299a16a23 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.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 @@ enum sme_description_types {
#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 @@ void sysmon_envsys_release(struct sysmon_envsys *, bool);
* 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 *);
diff --git a/sys/dev/sysmon/sysmon_power.c b/sys/dev/sysmon/sysmon_power.c
index f04f021a87c..8bedcca4a31 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.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 @@ static const struct power_event_description penvsys_event_desc[] = {
{ 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 @@ sysmon_power_daemon_task(struct power_event_dictionary *ped,
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 @@ sysmon_penvsys_event(struct penvsys_state *pes, int event)
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 @@ sysmon_penvsys_event(struct penvsys_state *pes, int event)
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;