CVS commit: src/sys/dev/sysmon

2020-10-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 30 22:19:19 UTC 2020

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
fix indentation


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.64 src/sys/dev/sysmon/sysmon_power.c:1.65
--- src/sys/dev/sysmon/sysmon_power.c:1.64	Wed Jun 10 22:39:31 2020
+++ src/sys/dev/sysmon/sysmon_power.c	Fri Oct 30 18:19:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.64 2020/06/11 02:39:31 thorpej Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.65 2020/10/30 22:19:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.64 2020/06/11 02:39:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.65 2020/10/30 22:19:18 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -555,17 +555,17 @@ filt_sysmon_power_read(struct knote *kn,
 }
 
 static const struct filterops sysmon_power_read_filtops = {
-.f_isfd = 1,
-.f_attach = NULL,
-.f_detach = filt_sysmon_power_rdetach,
-.f_event = filt_sysmon_power_read,
+	.f_isfd = 1,
+	.f_attach = NULL,
+	.f_detach = filt_sysmon_power_rdetach,
+	.f_event = filt_sysmon_power_read,
 };
 
 static const struct filterops sysmon_power_write_filtops = {
-.f_isfd = 1,
-.f_attach = NULL,
-.f_detach = filt_sysmon_power_rdetach,
-.f_event = filt_seltrue,
+	.f_isfd = 1,
+	.f_attach = NULL,
+	.f_detach = filt_sysmon_power_rdetach,
+	.f_event = filt_seltrue,
 };
 
 /*



CVS commit: src/sys/dev/sysmon

2020-12-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Dec 18 01:46:40 UTC 2020

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
Use sel{remove,record}_knote().


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.65 src/sys/dev/sysmon/sysmon_power.c:1.66
--- src/sys/dev/sysmon/sysmon_power.c:1.65	Fri Oct 30 22:19:18 2020
+++ src/sys/dev/sysmon/sysmon_power.c	Fri Dec 18 01:46:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.65 2020/10/30 22:19:18 christos Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.66 2020/12/18 01:46:39 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.65 2020/10/30 22:19:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.66 2020/12/18 01:46:39 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -538,8 +538,7 @@ filt_sysmon_power_rdetach(struct knote *
 {
 
 	mutex_enter(&sysmon_power_event_queue_mtx);
-	SLIST_REMOVE(&sysmon_power_event_queue_selinfo.sel_klist,
-	kn, knote, kn_selnext);
+	selremove_knote(&sysmon_power_event_queue_selinfo, kn);
 	mutex_exit(&sysmon_power_event_queue_mtx);
 }
 
@@ -576,16 +575,13 @@ static const struct filterops sysmon_pow
 int
 sysmonkqfilter_power(dev_t dev, struct knote *kn)
 {
-	struct klist *klist;
 
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
-		klist = &sysmon_power_event_queue_selinfo.sel_klist;
 		kn->kn_fop = &sysmon_power_read_filtops;
 		break;
 
 	case EVFILT_WRITE:
-		klist = &sysmon_power_event_queue_selinfo.sel_klist;
 		kn->kn_fop = &sysmon_power_write_filtops;
 		break;
 
@@ -594,7 +590,7 @@ sysmonkqfilter_power(dev_t dev, struct k
 	}
 
 	mutex_enter(&sysmon_power_event_queue_mtx);
-	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+	selrecord_knote(&sysmon_power_event_queue_selinfo, kn);
 	mutex_exit(&sysmon_power_event_queue_mtx);
 
 	return 0;



CVS commit: src/sys/dev/sysmon

2010-01-01 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jan  1 15:41:25 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Don't infer a sensor driver's ability to handle limit checking itself.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.72 src/sys/dev/sysmon/sysmon_envsys_events.c:1.73
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.72	Wed Dec 23 18:31:00 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Fri Jan  1 15:41:25 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.72 2009/12/23 18:31:00 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.73 2010/01/01 15:41:25 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.72 2009/12/23 18:31:00 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.73 2010/01/01 15:41:25 pgoyette Exp $");
 
 #include 
 #include 
@@ -481,16 +481,9 @@
 } while (/* CONSTCOND */ 0)
 
 	/*
-	 * If driver provides method to retrieve its internal limit
-	 * values, call it.  If it returns any values, set the flag
-	 * PROP_DRIVER_LIMITS to indicate that the driver can process
-	 * all the limits we have.  (If userland limits are specified
-	 * later and the driver cannot handle them, this flag will be
-	 * cleared.)
-	 *
-	 * If the driver cannot or does not provide us with limit values
-	 * we cannot monitor limits now;  we get another chance to create
-	 * the FMONLIMITS entry later if userland specifies some limits.
+	 * If driver provides a method to retrieve its internal limit
+	 * values, call it and use thoe returned values as initial
+	 * limits for event monitoring.
 	 */
 	lims.sel_flags = 0;
 	if (sed_t->sed_edata->flags & ENVSYS_FMONLIMITS)
@@ -498,11 +491,21 @@
 			(*sed_t->sed_sme->sme_get_limits)(sed_t->sed_sme,
 			  sed_t->sed_edata,
 			  &lims);
-	if (lims.sel_flags)
-		lims.sel_flags |= PROP_DRIVER_LIMITS;
-	else
+	/*
+	 * If no values returned, don't create the event monitor at
+	 * this time.  We'll get another chance later when the user
+	 * provides us with limits.
+	 */
+	if (lims.sel_flags == 0)
 		sed_t->sed_edata->flags &= ~ENVSYS_FMONLIMITS;
 
+	/*
+	 * If driver doesn't provide a way to "absorb" user-specified
+	 * limit values, we must monitor all limits ourselves
+	 */
+	else if (sed_t->sed_sme->sme_get_limits == NULL)
+		lims.sel_flags |= PROP_DRIVER_LIMITS;
+
 	/* Register the events that were specified */
 
 	SEE_REGEVENT(ENVSYS_FMONCRITICAL,



CVS commit: src/sys/dev/sysmon

2010-01-02 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jan  2 19:02:40 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Flags for existence of limit values need to be propagated to the
event data.  Otherwise, they're not processed.

XXX This needs to be rethought.  While fixing it this way makes things
XXX "work", we really shouldn't need to replicate these flags.  The
XXX limits and their flags should be kept as part of the sensor data,
XXX and not part of the event-monitor data.  I'll work on this in the
XXX near future.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.73 src/sys/dev/sysmon/sysmon_envsys_events.c:1.74
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.73	Fri Jan  1 15:41:25 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Jan  2 19:02:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.73 2010/01/01 15:41:25 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.74 2010/01/02 19:02:39 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.73 2010/01/01 15:41:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.74 2010/01/02 19:02:39 pgoyette Exp $");
 
 #include 
 #include 
@@ -209,6 +209,7 @@
 		if (error && error != EEXIST)
 			goto out;
 		see->see_edata->upropset |= PROP_CRITMAX;
+		see->see_lims.sel_flags |= PROP_CRITMAX;
 	}
 
 	if (lims->sel_flags & PROP_WARNMAX) {
@@ -229,6 +230,7 @@
 		if (error && error != EEXIST)
 			goto out;
 		see->see_edata->upropset |= PROP_WARNMAX;
+		see->see_lims.sel_flags |= PROP_WARNMAX;
 	}
 
 	if (lims->sel_flags & PROP_WARNMIN) {
@@ -249,6 +251,7 @@
 		if (error && error != EEXIST)
 			goto out;
 		see->see_edata->upropset |= PROP_WARNMIN;
+		see->see_lims.sel_flags |= PROP_WARNMIN;
 	}
 
 	if (lims->sel_flags & PROP_CRITMIN) {
@@ -269,6 +272,7 @@
 		if (error && error != EEXIST)
 			goto out;
 		see->see_edata->upropset |= PROP_CRITMIN;
+		see->see_lims.sel_flags |= PROP_CRITMIN;
 	}
 
 	if (lims->sel_flags & PROP_BATTWARN) {
@@ -289,6 +293,7 @@
 		if (error && error != EEXIST)
 			goto out;
 		see->see_edata->upropset |= PROP_BATTWARN;
+		see->see_lims.sel_flags |= PROP_BATTWARN;
 	}
 
 	if (lims->sel_flags & PROP_BATTCAP) {
@@ -309,8 +314,12 @@
 		if (error && error != EEXIST)
 			goto out;
 		see->see_edata->upropset |= PROP_BATTCAP;
+		see->see_lims.sel_flags |= PROP_BATTCAP;
 	}
 
+	if (lims->sel_flags & PROP_DRIVER_LIMITS)
+		see->see_lims.sel_flags |= PROP_DRIVER_LIMITS;
+
 	DPRINTF(("%s: (%s) event registered (sensor=%s snum=%d type=%d "
 	"critmin=%" PRIu32 " warnmin=%" PRIu32 " warnmax=%" PRIu32
 	" critmax=%" PRIu32 " props 0x%04x)\n", __func__,
@@ -482,7 +491,7 @@
 
 	/*
 	 * If driver provides a method to retrieve its internal limit
-	 * values, call it and use thoe returned values as initial
+	 * values, call it and use those returned values as initial
 	 * limits for event monitoring.
 	 */
 	lims.sel_flags = 0;
@@ -503,8 +512,8 @@
 	 * If driver doesn't provide a way to "absorb" user-specified
 	 * limit values, we must monitor all limits ourselves
 	 */
-	else if (sed_t->sed_sme->sme_get_limits == NULL)
-		lims.sel_flags |= PROP_DRIVER_LIMITS;
+	else if (sed_t->sed_sme->sme_set_limits == NULL)
+		lims.sel_flags &= ~PROP_DRIVER_LIMITS;
 
 	/* Register the events that were specified */
 



CVS commit: src/sys/dev/sysmon

2010-01-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Jan 18 21:48:15 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
If no limits are exceeded, make sure we set state to SVALID


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.74 src/sys/dev/sysmon/sysmon_envsys_events.c:1.75
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.74	Sat Jan  2 19:02:39 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Mon Jan 18 21:48:15 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.74 2010/01/02 19:02:39 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.75 2010/01/18 21:48:15 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.74 2010/01/02 19:02:39 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.75 2010/01/18 21:48:15 pgoyette Exp $");
 
 #include 
 #include 
@@ -687,6 +687,8 @@
 edata->state = ENVSYS_SCRITOVER;
 			else if __EXCEED_LIM(PROP_WARNMAX, sel_warnmax, >)
 edata->state = ENVSYS_SWARNOVER;
+			else
+edata->state = ENVSYS_SVALID;
 		}
 #undef	__EXCEED_LIM
 



CVS commit: src/sys/dev/sysmon

2010-01-29 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jan 30 02:46:53 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c

Log Message:
Validate limit-based monitoring in one place, so we can apply the
constraints to both driver-requested and user-requested monitoring.

While here, clean up some of the debugging DPRINTFs.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.76 -r1.77 src/sys/dev/sysmon/sysmon_envsys_events.c

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.90 src/sys/dev/sysmon/sysmon_envsys.c:1.91
--- src/sys/dev/sysmon/sysmon_envsys.c:1.90	Fri Jul 10 13:09:09 2009
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Jan 30 02:46:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.90 2009/07/10 13:09:09 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.91 2010/01/30 02:46:52 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.90 2009/07/10 13:09:09 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.91 2010/01/30 02:46:52 pgoyette Exp $");
 
 #include 
 #include 
@@ -1791,12 +1791,6 @@
 		obj2 = prop_dictionary_get(udict, "critical-capacity");
 		if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
 			targetfound = true;
-			if ((edata->flags & ENVSYS_FMONNOTSUPP) ||
-			(edata->flags & ENVSYS_FPERCENT) == 0) {
-error = ENOTSUP;
-goto out;
-			}
-
 			lims.sel_critmin = prop_number_integer_value(obj2);
 			lims.sel_flags |= PROP_BATTCAP;
 		}
@@ -1807,12 +1801,6 @@
 		obj2 = prop_dictionary_get(udict, "warning-capacity");
 		if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
 			targetfound = true;
-			if ((edata->flags & ENVSYS_FMONNOTSUPP) ||
-			(edata->flags & ENVSYS_FPERCENT) == 0) {
-error = ENOTSUP;
-goto out;
-			}
-
 			lims.sel_warnmin = prop_number_integer_value(obj2);
 			lims.sel_flags |= PROP_BATTWARN;
 		}
@@ -1823,13 +1811,6 @@
 		obj2 = prop_dictionary_get(udict, "critical-max");
 		if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
 			targetfound = true;
-			if (edata->units == ENVSYS_INDICATOR ||
-			edata->flags &
-(ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
-error = ENOTSUP;
-goto out;
-			}
-
 			lims.sel_critmax = prop_number_integer_value(obj2);
 			lims.sel_flags |= PROP_CRITMAX;
 		}
@@ -1840,13 +1821,6 @@
 		obj2 = prop_dictionary_get(udict, "warning-max");
 		if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
 			targetfound = true;
-			if (edata->units == ENVSYS_INDICATOR ||
-			edata->flags &
-(ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
-error = ENOTSUP;
-goto out;
-			}
-
 			lims.sel_warnmax = prop_number_integer_value(obj2);
 			lims.sel_flags |= PROP_WARNMAX;
 		}
@@ -1857,13 +1831,6 @@
 		obj2 = prop_dictionary_get(udict, "critical-min");
 		if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
 			targetfound = true;
-			if (edata->units == ENVSYS_INDICATOR ||
-			edata->flags &
-(ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
-error = ENOTSUP;
-goto out;
-			}
-
 			lims.sel_critmin = prop_number_integer_value(obj2);
 			lims.sel_flags |= PROP_CRITMIN;
 		}
@@ -1874,18 +1841,15 @@
 		obj2 = prop_dictionary_get(udict, "warning-min");
 		if (obj2 && prop_object_type(obj2) == PROP_TYPE_NUMBER) {
 			targetfound = true;
-			if (edata->units == ENVSYS_INDICATOR ||
-			edata->flags &
-(ENVSYS_FPERCENT | ENVSYS_FMONNOTSUPP)) {
-error = ENOTSUP;
-goto out;
-			}
-
 			lims.sel_warnmin = prop_number_integer_value(obj2);
 			lims.sel_flags |= PROP_WARNMIN;
 		}
 
 		if (lims.sel_flags) {
+			if (edata->flags & ENVSYS_FMONNOTSUPP) {
+error = ENOTSUP;
+goto out;
+			}
 			error = sme_event_register(dict, edata, sme, &lims,
 	  (edata->flags & ENVSYS_FPERCENT)?
 		PENVSYS_EVENT_CAPACITY:

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.76 src/sys/dev/sysmon/sysmon_envsys_events.c:1.77
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.76	Tue Jan 26 14:22:00 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Jan 30 02:46:52 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.76 2010/01/26 14:22:00 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.77 2010/01/30 02:46:52 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.76 2010/01/26 14:22:00 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.77 2010/01/30 02:46:52 pgoyette Exp $");
 
 #include 
 #include 
@@ -93,6 +93,27 @@
 	KASSERT(sdict != NULL);
 	KASSERT(edata != NU

CVS commit: src/sys/dev/sysmon

2010-01-30 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Jan 31 02:54:56 UTC 2010

Modified Files:
src/sys/dev/sysmon: swwdog.c

Log Message:
print newline after timer expiry message


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/sysmon/swwdog.c

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/swwdog.c
diff -u src/sys/dev/sysmon/swwdog.c:1.8 src/sys/dev/sysmon/swwdog.c:1.9
--- src/sys/dev/sysmon/swwdog.c:1.8	Sat Jan 30 21:55:30 2010
+++ src/sys/dev/sysmon/swwdog.c	Sun Jan 31 02:54:56 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swwdog.c,v 1.8 2010/01/30 21:55:30 pooka Exp $	*/
+/*	$NetBSD: swwdog.c,v 1.9 2010/01/31 02:54:56 pooka Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.8 2010/01/30 21:55:30 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.9 2010/01/31 02:54:56 pooka Exp $");
 
 /*
  *
@@ -150,7 +150,7 @@
 	swwdog_reboot = 1;
 	callout_schedule(&sc->sc_c, 60 * hz);	/* deliberate double-panic */
 
-	printf("%s: %d second timer expired", sc->sc_name,
+	printf("%s: %d second timer expired\n", sc->sc_name,
 	sc->sc_smw.smw_period);
 
 	if (do_panic)



CVS commit: src/sys/dev/sysmon

2010-01-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 31 21:36:38 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmonvar.h

Log Message:
Add a convenience function to find the maximum value currently reported
by a set (selected via a passed callback predicate) of sensors.
This provides an easy way to query the current temperature of a thermal
zone, for example, from within the kernel - assuming the caller knows
the topology.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/sysmon/sysmonvar.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.91 src/sys/dev/sysmon/sysmon_envsys.c:1.92
--- src/sys/dev/sysmon/sysmon_envsys.c:1.91	Sat Jan 30 02:46:52 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Jan 31 21:36:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.91 2010/01/30 02:46:52 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.92 2010/01/31 21:36:38 martin Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.91 2010/01/30 02:46:52 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.92 2010/01/31 21:36:38 martin Exp $");
 
 #include 
 #include 
@@ -93,6 +93,8 @@
 static int sme_add_property_dictionary(struct sysmon_envsys *, prop_array_t,
    prop_dictionary_t);
 static void sme_initial_refresh(void *);
+static uint32_t sme_get_max_value(struct sysmon_envsys *,
+ bool (*)(const envsys_data_t*), bool);
 
 /*
  * sysmon_envsys_init:
@@ -1412,6 +1414,71 @@
 }
 
 /*
+ * Find the maximum of all currently reported values.
+ * The provided callback decides wether a sensor is part of the
+ * maximum calculation (by returning true) or ignored (callback
+ * returns false). Example usage: callback selects temperature
+ * sensors in a given thermal zone, the function calculates the
+ * maximum currently reported temperature in this zone.
+ * If the parameter "refresh" is true, new values will be aquired
+ * from the hardware, if not, the last reported value will be used.
+ */
+uint32_t
+sysmon_envsys_get_max_value(bool (*predicate)(const envsys_data_t*),
+	bool refresh)
+{
+	struct sysmon_envsys *sme;
+	uint32_t maxv, v;
+
+	maxv = 0;
+	mutex_enter(&sme_global_mtx);
+	LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) {
+		sysmon_envsys_acquire(sme, false);
+		v = sme_get_max_value(sme, predicate, refresh);
+		sysmon_envsys_release(sme, false);
+		if (v > maxv)
+			maxv = v;
+	}
+	mutex_exit(&sme_global_mtx);
+	return maxv;
+}
+
+static uint32_t
+sme_get_max_value(struct sysmon_envsys *sme,
+bool (*predicate)(const envsys_data_t*),
+bool refresh)
+{
+	envsys_data_t *edata;
+	uint32_t maxv, v;
+
+	/* 
+	 * iterate over all sensors and find temperature ones.
+	 */
+	maxv = 0;
+	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
+		if (!(*predicate)(edata))
+			continue;
+
+		/* 
+		 * refresh sensor data via sme_refresh only if the
+		 * flag is not set.
+		 */
+		if (refresh && (sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
+			mutex_enter(&sme->sme_mtx);
+			(*sme->sme_refresh)(sme, edata);
+			mutex_exit(&sme->sme_mtx);
+		}
+
+		v = edata->value_cur;
+		if (v > maxv)
+			maxv = v;
+
+	}
+
+	return maxv;
+}
+
+/*
  * sme_update_dictionary:
  *
  * 	+ Update per-sensor dictionaries with new values if there were

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.29 src/sys/dev/sysmon/sysmonvar.h:1.30
--- src/sys/dev/sysmon/sysmonvar.h:1.29	Sun Jun 14 19:43:12 2009
+++ src/sys/dev/sysmon/sysmonvar.h	Sun Jan 31 21:36:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.29 2009/06/14 19:43:12 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.30 2010/01/31 21:36:38 martin Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -134,6 +134,8 @@
 int	sysmon_envsys_sensor_attach(struct sysmon_envsys *, envsys_data_t *);
 int	sysmon_envsys_sensor_detach(struct sysmon_envsys *, envsys_data_t *);
 
+uint32_t	sysmon_envsys_get_max_value(bool (*)(const envsys_data_t*), bool);
+
 void	sysmon_envsys_init(void);
 
 /*



CVS commit: src/sys/dev/sysmon

2010-01-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 31 22:53:56 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Fix an outdated comment, noticed by Paul Goyette.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/sysmon/sysmon_envsys.c

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.92 src/sys/dev/sysmon/sysmon_envsys.c:1.93
--- src/sys/dev/sysmon/sysmon_envsys.c:1.92	Sun Jan 31 21:36:38 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Jan 31 22:53:56 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.92 2010/01/31 21:36:38 martin Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.93 2010/01/31 22:53:56 martin Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.92 2010/01/31 21:36:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.93 2010/01/31 22:53:56 martin Exp $");
 
 #include 
 #include 
@@ -1452,7 +1452,7 @@
 	uint32_t maxv, v;
 
 	/* 
-	 * iterate over all sensors and find temperature ones.
+	 * Iterate over all sensors that match the predicate
 	 */
 	maxv = 0;
 	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {



CVS commit: src/sys/dev/sysmon

2010-02-04 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Feb  4 18:06:53 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
If the AC adapter is flagged with SME_DISABLE_REFRESH, don't try to call
its refresh() callback.  Just assume that its value has been properly
updated by other means.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.77 src/sys/dev/sysmon/sysmon_envsys_events.c:1.78
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.77	Sat Jan 30 02:46:52 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Feb  4 18:06:53 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.77 2010/01/30 02:46:52 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.78 2010/02/04 18:06:53 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.77 2010/01/30 02:46:52 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.78 2010/02/04 18:06:53 pgoyette Exp $");
 
 #include 
 #include 
@@ -888,7 +888,8 @@
 		if (edata->units == ENVSYS_INDICATOR) {
 			sensor = true;
 			/* refresh current sensor */
-			(*sme->sme_refresh)(sme, edata);
+			if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0)
+(*sme->sme_refresh)(sme, edata);
 			if (edata->value_cur)
 return false;
 		}



CVS commit: src/sys/dev/sysmon

2010-02-05 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Feb  5 17:44:27 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
One more callback of sme_refresh() routine needs to check first that
there is a routine to be called!


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/sysmon/sysmon_envsys.c

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.93 src/sys/dev/sysmon/sysmon_envsys.c:1.94
--- src/sys/dev/sysmon/sysmon_envsys.c:1.93	Sun Jan 31 22:53:56 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Fri Feb  5 17:44:27 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.93 2010/01/31 22:53:56 martin Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.94 2010/02/05 17:44:27 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.93 2010/01/31 22:53:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.94 2010/02/05 17:44:27 pgoyette Exp $");
 
 #include 
 #include 
@@ -987,7 +987,8 @@
 	mutex_enter(&sme->sme_mtx);
 	sysmon_envsys_acquire(sme, true);
 	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head)
-		(*sme->sme_refresh)(sme, edata);
+		if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0)
+			(*sme->sme_refresh)(sme, edata);
 	sysmon_envsys_release(sme, true);
 	mutex_exit(&sme->sme_mtx);
 }



CVS commit: src/sys/dev/sysmon

2010-02-05 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Fri Feb  5 19:22:25 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Fix a typo in one DPRINTF (s/edata->des/edata->desc/).


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.78 src/sys/dev/sysmon/sysmon_envsys_events.c:1.79
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.78	Thu Feb  4 18:06:53 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Fri Feb  5 19:22:25 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.78 2010/02/04 18:06:53 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.79 2010/02/05 19:22:25 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.78 2010/02/04 18:06:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.79 2010/02/05 19:22:25 jruoho Exp $");
 
 #include 
 #include 
@@ -178,7 +178,7 @@
 			return ENOMEM;
 
 		DPRINTF(("%s: dev %s sensor %s: new event\n",
-		__func__, sme->sme_name, edata->des));
+		__func__, sme->sme_name, edata->desc));
 
 		see->see_type = crittype;
 		see->see_sme = sme;



CVS commit: src/sys/dev/sysmon

2010-02-13 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Feb 13 19:34:14 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
When checking current sensor value vs limits, check the correct set of
flags to determine which limits are present.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.79 src/sys/dev/sysmon/sysmon_envsys_events.c:1.80
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.79	Fri Feb  5 19:22:25 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Feb 13 19:34:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.79 2010/02/05 19:22:25 jruoho Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.80 2010/02/13 19:34:14 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.79 2010/02/05 19:22:25 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.80 2010/02/13 19:34:14 pgoyette Exp $");
 
 #include 
 #include 
@@ -696,7 +696,7 @@
 	case PENVSYS_EVENT_LIMITS:
 	case PENVSYS_EVENT_CAPACITY:
 #define	__EXCEED_LIM(valid, lim, rel) \
-		((edata->limits.sel_flags & (valid)) && \
+		((edata->upropset & (valid)) && \
 		 (edata->value_cur rel (edata->limits.lim)))
 
 		if ((edata->limits.sel_flags & PROP_DRIVER_LIMITS) == 0) {



CVS commit: src/sys/dev/sysmon

2010-02-14 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Feb 14 16:22:09 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Correct one more instance of checking flags in the wrong place.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.80 src/sys/dev/sysmon/sysmon_envsys_events.c:1.81
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.80	Sat Feb 13 19:34:14 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sun Feb 14 16:22:09 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.80 2010/02/13 19:34:14 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.81 2010/02/14 16:22:09 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.80 2010/02/13 19:34:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.81 2010/02/14 16:22:09 pgoyette Exp $");
 
 #include 
 #include 
@@ -699,7 +699,7 @@
 		((edata->upropset & (valid)) && \
 		 (edata->value_cur rel (edata->limits.lim)))
 
-		if ((edata->limits.sel_flags & PROP_DRIVER_LIMITS) == 0) {
+		if ((edata->upropset & PROP_DRIVER_LIMITS) == 0) {
 			if __EXCEED_LIM(PROP_CRITMIN | PROP_BATTCAP,
 	sel_critmin, <)
 edata->state = ENVSYS_SCRITUNDER;



CVS commit: src/sys/dev/sysmon

2010-02-14 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Feb 14 23:30:52 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Replace large amount of replicated code with a macro to improve readability.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.82 src/sys/dev/sysmon/sysmon_envsys_events.c:1.83
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.82	Sun Feb 14 23:06:02 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sun Feb 14 23:30:52 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.82 2010/02/14 23:06:02 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.83 2010/02/14 23:30:52 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.82 2010/02/14 23:06:02 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.83 2010/02/14 23:30:52 pgoyette Exp $");
 
 #include 
 #include 
@@ -218,126 +218,39 @@
 	/*
 	 * Limit operation requested.
 	 */
-	if (props & 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 {
-			edata->limits.sel_critmax = lims->sel_critmax;
-			error = sme_sensor_upint32(sdict, objkey,
-		   lims->sel_critmax);
-			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;
-		edata->upropset |= PROP_CRITMAX;
-	}
-
-	if (props & 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 {
-			edata->limits.sel_warnmax = lims->sel_warnmax;
-			error = sme_sensor_upint32(sdict, objkey,
-		   lims->sel_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;
-		edata->upropset |= PROP_WARNMAX;
-	}
-
-	if (props & 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 {
-			edata->limits.sel_warnmin = lims->sel_warnmin;
-			error = sme_sensor_upint32(sdict, objkey,
-		   lims->sel_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;
-		edata->upropset |= PROP_WARNMIN;
-	}
-
-	if (props & 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 {
-			edata->limits.sel_critmin = lims->sel_critmin;
-			error = sme_sensor_upint32(sdict, objkey,
-		   lims->sel_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;
-		edata->upropset |= PROP_CRITMIN;
-	}
-
-	if (props & 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 {
-			edata->limits.sel_warnmin = lims->sel_warnmin;
-			error = sme_sensor_upint32(sdict, objkey,
-		   lims->sel_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;
-		edata->upropset |= PROP_BATTWARN;
-	}
-
-	if (props & 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 {
-			edata->limits.sel_critmin = lims->sel_critmin;
-			error = sme_sensor_upint32(sdi

CVS commit: src/sys/dev/sysmon

2010-02-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Feb 18 12:30:53 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
If we're going to valdate things, at least do it correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.84 src/sys/dev/sysmon/sysmon_envsys_events.c:1.85
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.84	Mon Feb 15 22:32:04 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Feb 18 12:30:53 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.84 2010/02/15 22:32:04 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.85 2010/02/18 12:30:53 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.84 2010/02/15 22:32:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.85 2010/02/18 12:30:53 pgoyette Exp $");
 
 #include 
 #include 
@@ -101,21 +101,32 @@
 	/*
 	 * Some validation first for limit-checking events
 	 *
-	 * Capacity limits are permitted only if the sensor has the
-	 * ENVSYS_FPERCENT flag set.
-	 * Value limits are permitted only if the ENVSYS_FPERCENT
-	 * flag is not set and the units is not ENVSYS_INDICATOR.
+	 * 1. Limits are not permitted if the units is ENVSYS_INDICATOR.
+	 *
+	 * 2. Capacity limits are permitted only if the sensor has the
+	 *ENVSYS_FPERCENT flag set and value_max is set.
+	 *
+	 * 3. It is not permissible for both capacity and value limits
+	 *to coexist.
+	 *
+	 * Note that it permissible for a sensor to have value limits
+	 * even if its ENVSYS_FPERCENT flag and value_max are set.
 	 */
 
 	DPRINTF(("%s: units %d props 0x%04x edata-flags 0x%04x\n",
 		__func__, edata->units, props, edata->flags));
 
-	if ((props & PROP_VAL_LIMITS) &&
-	((edata->flags & ENVSYS_FPERCENT) ||
-	 (edata->units == ENVSYS_INDICATOR)))
+	if (props && edata->units == ENVSYS_INDICATOR)
 		return ENOTSUP;
+
 	if ((props & PROP_CAP_LIMITS) &&
-	!(edata->flags & ENVSYS_FPERCENT))
+	((edata->value_max == 0) ||
+	 !(edata->flags & ENVSYS_FPERCENT) ||
+	 (props & PROP_VAL_LIMITS) ||
+	 (edata->upropset & PROP_VAL_LIMITS)))
+		return ENOTSUP;
+
+	if ((props & PROP_VAL_LIMITS) && (edata->upropset & PROP_CAP_LIMITS))
 		return ENOTSUP;
 
 	/* 



CVS commit: src/sys/dev/sysmon

2010-03-11 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Mar 11 13:51:01 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
Fix comment typos (mangement, managmenet).


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.43 src/sys/dev/sysmon/sysmon_power.c:1.44
--- src/sys/dev/sysmon/sysmon_power.c:1.43	Mon Feb 15 22:32:04 2010
+++ src/sys/dev/sysmon/sysmon_power.c	Thu Mar 11 13:51:01 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.43 2010/02/15 22:32:04 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.44 2010/03/11 13:51:01 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.43 2010/02/15 22:32:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.44 2010/03/11 13:51:01 jruoho Exp $");
 
 #include "opt_compat_netbsd.h"
 #include 
@@ -201,7 +201,7 @@
 /*
  * sysmon_queue_power_event:
  *
- *	Enqueue a power event for the power mangement daemon.  Returns
+ *	Enqueue a power event for the power management daemon.  Returns
  *	non-zero if we were able to enqueue a power event.
  */
 static int
@@ -541,7 +541,7 @@
 /*
  * sysmonioctl_power:
  *
- *	Perform a power managmenet control request.
+ *	Perform a power management control request.
  */
 int
 sysmonioctl_power(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)



CVS commit: src/sys/dev/sysmon

2010-03-14 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Mar 14 18:03:15 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsysvar.h sysmonvar.h

Log Message:
Retire the 'monitor' member of the envsys_data_t.  It was only used in
one place, and functioned as a logical OR of the ENVSYS_FMON* flag bits.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/sysmon/sysmon_envsysvar.h
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/sysmon/sysmonvar.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.96 src/sys/dev/sysmon/sysmon_envsys.c:1.97
--- src/sys/dev/sysmon/sysmon_envsys.c:1.96	Mon Feb 15 22:32:04 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Mar 14 18:03:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.96 2010/02/15 22:32:04 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.97 2010/03/14 18:03:15 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.96 2010/02/15 22:32:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.97 2010/03/14 18:03:15 pgoyette Exp $");
 
 #include 
 #include 
@@ -92,6 +92,8 @@
 static void sme_remove_userprops(void);
 static int sme_add_property_dictionary(struct sysmon_envsys *, prop_array_t,
    prop_dictionary_t);
+static sme_event_drv_t * sme_add_sensor_dictionary(struct sysmon_envsys *,
+	prop_array_t, prop_dictionary_t, envsys_data_t *);
 static void sme_initial_refresh(void *);
 static uint32_t sme_get_max_value(struct sysmon_envsys *,
  bool (*)(const envsys_data_t*), bool);
@@ -633,6 +635,7 @@
 	prop_dictionary_t dict, dict2;
 	envsys_data_t *edata = NULL;
 	sme_event_drv_t *this_evdrv;
+	int nevent;
 	int error = 0;
 
 	KASSERT(sme != NULL);
@@ -756,13 +759,15 @@
 	 * and make an initial data refresh if was requested.
 	 */
 	if (error == 0) {
+		nevent = 0;
 		sysmon_task_queue_init();
 		SLIST_FOREACH(evdv, &sme_evdrv_list, evdrv_head) {
 			sysmon_task_queue_sched(0,
 			sme_event_drvadd, evdv->evdrv);
+			nevent++;
 		}
-		DPRINTF(("%s: driver '%s' registered (nsens=%d)\n",
-		__func__, sme->sme_name, sme->sme_nsensors));
+		DPRINTF(("%s: driver '%s' registered (nsens=%d nevent=%d)\n",
+		__func__, sme->sme_name, sme->sme_nsensors, nevent));
 
 		if (sme->sme_flags & SME_INIT_REFRESH)
 			sysmon_task_queue_sched(0, sme_initial_refresh, sme);
@@ -1184,7 +1189,7 @@
  * 	  to a sme_event_drv_t object if a monitoring flag was set
  * 	  (or NULL otherwise).
  */
-sme_event_drv_t *
+static sme_event_drv_t *
 sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
 			  prop_dictionary_t dict, envsys_data_t *edata)
 {
@@ -1408,9 +1413,9 @@
 	}
 
 	/*
-	 * Register a new event if a monitoring flag was set.
+	 * Register new event(s) if any monitoring flag was set.
 	 */
-	if (edata->monitor) {
+	if (edata->flags & ENVSYS_FMONANY) {
 		sme_evdrv_t = kmem_zalloc(sizeof(*sme_evdrv_t), KM_SLEEP);
 		sme_evdrv_t->sed_sdict = dict;
 		sme_evdrv_t->sed_edata = edata;

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.31 src/sys/dev/sysmon/sysmon_envsysvar.h:1.32
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.31	Sun Feb 14 23:06:02 2010
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Sun Mar 14 18:03:15 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.31 2010/02/14 23:06:02 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.32 2010/03/14 18:03:15 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -109,10 +109,6 @@
 /* 
  * functions to handle sysmon envsys devices.
  */
-sme_event_drv_t *sme_add_sensor_dictionary(struct sysmon_envsys *,
-	   prop_array_t,
-				  	   prop_dictionary_t,
-	   envsys_data_t *);
 int	sme_update_dictionary(struct sysmon_envsys *);
 int	sme_userset_dictionary(struct sysmon_envsys *,
 			   prop_dictionary_t, prop_array_t);

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.32 src/sys/dev/sysmon/sysmonvar.h:1.33
--- src/sys/dev/sysmon/sysmonvar.h:1.32	Sun Feb 28 20:04:04 2010
+++ src/sys/dev/sysmon/sysmonvar.h	Sun Mar 14 18:03:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.32 2010/02/28 20:04:04 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.33 2010/03/14 18:03:15 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -86,7 +86,6 @@
 	int32_t		value_avg;	/* avg value */
 	sysmon_envsys_lim_t limits;	/* thresholds for monitoring */
 	int		upropset;	/* userland property set? */
-	bool		monitor;	/* monitoring enabled/disabled */
 	char		desc[ENVSYS_DESCLEN];	/* sensor description */
 };
 
@@ -103,6 +102,8 @@
 #define ENVSYS_FMONCRITICAL	0x0020	/* monitor a critical st

CVS commit: src/sys/dev/sysmon

2010-03-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Mar 19 01:16:45 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c sysmon_envsysvar.h

Log Message:
Separate event delivery from polling and limit evaluation in
sme_events_worker().

Provide a wrapper that can be called from sensor drivers' interrupt
routines to find and deliver a specific event.

XXX Actually updating sensor drivers (and their parent devices) to
XXX have interrupts is a future enhancement.  This is simply an
XXX enabler.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/sysmon/sysmon_envsysvar.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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.85 src/sys/dev/sysmon/sysmon_envsys_events.c:1.86
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.85	Thu Feb 18 12:30:53 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Fri Mar 19 01:16:44 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.85 2010/02/18 12:30:53 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.86 2010/03/19 01:16:44 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.85 2010/02/18 12:30:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.86 2010/03/19 01:16:44 pgoyette Exp $");
 
 #include 
 #include 
@@ -578,19 +578,15 @@
 void
 sme_events_worker(struct work *wk, void *arg)
 {
-	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 = see->see_sme;
 	envsys_data_t *edata = see->see_edata;
-	int i, state = 0;
 
 	KASSERT(wk == &see->see_wk);
 	KASSERT(sme != NULL || edata != NULL);
 
 	mutex_enter(&sme->sme_mtx);
-	if ((see->see_flags & SEE_EVENT_WORKING) == 0)
-		see->see_flags |= SEE_EVENT_WORKING;
+	see->see_flags |= SEE_EVENT_WORKING;
 	/* 
 	 * sme_events_check marks the sensors to make us refresh them here.
 	 * Don't refresh if the driver uses its own method for refreshing.
@@ -612,7 +608,6 @@
 	if (edata->state == ENVSYS_SINVALID)
 		goto out;
 
-	switch (see->see_type) {
 	/*
 	 * For range limits, if the driver claims responsibility for
 	 * limit/range checking, just user driver-supplied status.
@@ -620,30 +615,74 @@
 	 * relinquish responsibility for ALL limits if there is even
 	 * one limit that it cannot handle!
 	 */
+	if ((see->see_type == PENVSYS_EVENT_LIMITS ||
+	 see->see_type == PENVSYS_EVENT_CAPACITY) &&
+	(edata->upropset & PROP_DRIVER_LIMITS) == 0) {
+		if ((edata->upropset & (PROP_CRITMIN | PROP_BATTCAP)) &&
+		(edata->value_cur < edata->limits.sel_critmin))
+			edata->state = ENVSYS_SCRITUNDER;
+		else if ((edata->upropset & (PROP_WARNMIN | PROP_BATTWARN)) &&
+			 (edata->value_cur < edata->limits.sel_warnmin))
+			edata->state = ENVSYS_SWARNUNDER;
+		else if ((edata->upropset & (PROP_CRITMAX | PROP_BATTMAX)) &&
+			 (edata->value_cur > edata->limits.sel_critmax))
+			edata->state = ENVSYS_SCRITOVER;
+		else if ((edata->upropset & (PROP_WARNMAX | PROP_BATTHIGH)) &&
+			 (edata->value_cur > edata->limits.sel_warnmax))
+			edata->state = ENVSYS_SWARNOVER;
+		else
+			edata->state = ENVSYS_SVALID;
+	}
+	sme_deliver_event(see);
+
+out:
+	see->see_flags &= ~SEE_EVENT_WORKING;
+	cv_broadcast(&sme->sme_condvar);
+	mutex_exit(&sme->sme_mtx);
+}
+
+/*
+ * sme_deliver_typed_event
+ *
+ *	+ Find the monitor event of a particular type for a given sensor
+ *	  on a device and deliver the event if one is required.
+ */
+void
+sme_deliver_typed_event(struct sysmon_envsys *sme, envsys_data_t *edata, 
+			int ev_type)
+{
+	sme_event_t *see;
+
+	mutex_enter(&sme->sme_mtx);
+	LIST_FOREACH(see, &sme->sme_events_list, see_list) {
+		if (edata != see->see_edata ||
+		see->see_type != ev_type)
+			continue; 
+		sme_deliver_event(see);
+		break;
+	}
+	mutex_exit(&sme->sme_mtx);
+}
+
+/*
+ * sme_deliver_event:
+ *
+ * 	+ If new sensor state requires it, send an event to powerd
+ *
+ *	  Must be called with the device's sysmon mutex held
+ *		see->see_sme->sme_mtx
+ */
+void
+sme_deliver_event(sme_event_t *see)
+{
+	envsys_data_t *edata = see->see_edata;
+	const struct sme_description_table *sdt = NULL;
+	const struct sme_sensor_event *sse = sme_sensor_event;
+	int i, state = 0;
+
+	switch (see->see_type) {
 	case PENVSYS_EVENT_LIMITS:
 	case PENVSYS_EVENT_CAPACITY:
-#define	__EXCEED_LIM(valid, lim, rel) \
-		((edata->upropset & (valid)) && \
-		 (edata->value_cur rel (edata->limits.lim)))
-
-		if ((edata->upropset & PROP_DRIVER_LIMITS) == 0) {
-			if __EXCEED_LIM(PROP_CRITMIN | PROP_BATTCAP,
-	sel_critmin, <)
-edata->state = ENVSYS_SCRITUNDER;
-			else if __EXCEED_LIM(PROP_WARNM

CVS commit: src/sys/dev/sysmon

2010-03-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Mar 19 02:19:13 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c sysmon_envsysvar.h
sysmonvar.h

Log Message:
Modify previous commit.  The routine to deliver events is intended to be
exported to device drivers, so rename it and move the declaration to



To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/sysmon/sysmon_envsysvar.h \
src/sys/dev/sysmon/sysmonvar.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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.86 src/sys/dev/sysmon/sysmon_envsys_events.c:1.87
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.86	Fri Mar 19 01:16:44 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Fri Mar 19 02:19:13 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.86 2010/03/19 01:16:44 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.87 2010/03/19 02:19:13 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.86 2010/03/19 01:16:44 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.87 2010/03/19 02:19:13 pgoyette Exp $");
 
 #include 
 #include 
@@ -642,14 +642,14 @@
 }
 
 /*
- * sme_deliver_typed_event
+ * sysmon_envsys_sensor_event
  *
  *	+ Find the monitor event of a particular type for a given sensor
  *	  on a device and deliver the event if one is required.
  */
 void
-sme_deliver_typed_event(struct sysmon_envsys *sme, envsys_data_t *edata, 
-			int ev_type)
+sysmon_envsys_sensor_event(struct sysmon_envsys *sme, envsys_data_t *edata, 
+			   int ev_type)
 {
 	sme_event_t *see;
 

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.33 src/sys/dev/sysmon/sysmon_envsysvar.h:1.34
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.33	Fri Mar 19 01:16:44 2010
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Fri Mar 19 02:19:13 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.33 2010/03/19 01:16:44 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.34 2010/03/19 02:19:13 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -131,7 +131,6 @@
 void	sme_events_check(void *);
 void	sme_events_worker(struct work *, void *);
 void	sme_deliver_event(sme_event_t *);
-void	sme_deliver_typed_event(struct sysmon_envsys *, envsys_data_t *, int);
 
 /* 
  * common functions to create/update objects in a dictionary.
Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.33 src/sys/dev/sysmon/sysmonvar.h:1.34
--- src/sys/dev/sysmon/sysmonvar.h:1.33	Sun Mar 14 18:03:15 2010
+++ src/sys/dev/sysmon/sysmonvar.h	Fri Mar 19 02:19:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.33 2010/03/14 18:03:15 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.34 2010/03/19 02:19:13 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -205,6 +205,9 @@
 
 uint32_t	sysmon_envsys_get_max_value(bool (*)(const envsys_data_t*), bool);
 
+void	sysmon_envsys_sensor_event(struct sysmon_envsys *, envsys_data_t *,
+   int);
+
 void	sysmon_envsys_init(void);
 
 /*



CVS commit: src/sys/dev/sysmon

2010-03-23 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Mar 23 16:52:02 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Additional info in DPRINTF to help debugging efforts


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.87 src/sys/dev/sysmon/sysmon_envsys_events.c:1.88
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.87	Fri Mar 19 02:19:13 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Tue Mar 23 16:52:02 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.87 2010/03/19 02:19:13 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.88 2010/03/23 16:52:02 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.87 2010/03/19 02:19:13 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.88 2010/03/23 16:52:02 pgoyette Exp $");
 
 #include 
 #include 
@@ -113,8 +113,9 @@
 	 * even if its ENVSYS_FPERCENT flag and value_max are set.
 	 */
 
-	DPRINTF(("%s: units %d props 0x%04x edata-flags 0x%04x\n",
-		__func__, edata->units, props, edata->flags));
+	DPRINTF(("%s: units %d props 0x%04x upropset 0x%04x max_val %"PRId64
+		" edata-flags 0x%04x\n", __func__, edata->units, props,
+		edata->upropset, edata->value_max, edata->flags));
 
 	if (props && edata->units == ENVSYS_INDICATOR)
 		return ENOTSUP;



CVS commit: src/sys/dev/sysmon

2010-08-06 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Aug  6 16:02:56 UTC 2010

Modified Files:
src/sys/dev/sysmon: swwdog.c

Log Message:
* fix logic inversion in swwdog_reboot (and the sysctl).
* attach sysctl in constructor instead of as a link set to give it
  a chance to work in a module
* teardown sysctl when driver is detached to avoid dangling pointer


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/sysmon/swwdog.c

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/swwdog.c
diff -u src/sys/dev/sysmon/swwdog.c:1.10 src/sys/dev/sysmon/swwdog.c:1.11
--- src/sys/dev/sysmon/swwdog.c:1.10	Thu Jul 22 14:10:15 2010
+++ src/sys/dev/sysmon/swwdog.c	Fri Aug  6 16:02:56 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swwdog.c,v 1.10 2010/07/22 14:10:15 pgoyette Exp $	*/
+/*	$NetBSD: swwdog.c,v 1.11 2010/08/06 16:02:56 pooka Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.10 2010/07/22 14:10:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.11 2010/08/06 16:02:56 pooka Exp $");
 
 /*
  *
@@ -82,6 +82,9 @@
 CFATTACH_DECL_NEW(swwdog, sizeof(struct swwdog_softc),
 	swwdog_match, swwdog_attach, swwdog_detach, NULL);
 
+static void swwdog_sysctl_setup(void);
+static struct sysctllog *swwdog_sysctllog;
+
 void
 swwdogattach(int n __unused)
 {
@@ -134,6 +137,8 @@
 
 	if (!pmf_device_register(self, swwdog_suspend, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
+
+	swwdog_sysctl_setup();
 }
 
 static int
@@ -143,6 +148,7 @@
 
 	swwdog_disarm(sc);
 	callout_destroy(&sc->sc_c);
+	sysctl_teardown(&swwdog_sysctllog);
 
 	return 1;
 }
@@ -207,8 +213,8 @@
 	struct swwdog_softc *sc = vsc;
 	bool do_panic;
 
-	do_panic = swwdog_reboot;
-	swwdog_reboot = 1;
+	do_panic = !swwdog_reboot;
+	swwdog_reboot = false;
 	callout_schedule(&sc->sc_c, 60 * hz);	/* deliberate double-panic */
 
 	printf("%s: %d second timer expired\n", device_xname(sc->sc_dev),
@@ -220,25 +226,19 @@
 		cpu_reboot(0, NULL);
 }
 
-SYSCTL_SETUP(sysctl_swwdog, "swwdog subtree setup")
+static void
+swwdog_sysctl_setup(void)
 {
-	int err;
 	const struct sysctlnode *me;
 
-	err = sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_PERMANENT,
-	CTLTYPE_NODE, "machdep", NULL,
-	NULL, 0, NULL, 0,
-	CTL_HW, CTL_EOL);
+	KASSERT(swwdog_sysctllog == NULL);
 
-	if (err == 0)
-		err = sysctl_createv(NULL, 0, NULL, &me, CTLFLAG_READWRITE,
-		CTLTYPE_NODE, "swwdog", NULL,
-		NULL, 0, NULL, 0,
-		CTL_HW, CTL_CREATE, CTL_EOL);
-
-	if (err == 0)
-		err = sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READWRITE,
-		CTLTYPE_BOOL, "reboot", "reboot if timer expires",
-		NULL, 0, &swwdog_reboot, sizeof(bool),
-		CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
+	sysctl_createv(&swwdog_sysctllog, 0, NULL, &me, CTLFLAG_READWRITE,
+	CTLTYPE_NODE, "swwdog", NULL,
+	NULL, 0, NULL, 0,
+	CTL_HW, CTL_CREATE, CTL_EOL);
+	sysctl_createv(&swwdog_sysctllog, 0, NULL, NULL, CTLFLAG_READWRITE,
+	CTLTYPE_BOOL, "reboot", "reboot if timer expires",
+	NULL, 0, &swwdog_reboot, sizeof(bool),
+	CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
 }



CVS commit: src/sys/dev/sysmon

2009-04-07 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Tue Apr  7 21:49:36 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Fix spelling: mak -> make.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.62 src/sys/dev/sysmon/sysmon_envsys_events.c:1.63
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.62	Tue Nov 11 19:03:06 2008
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Tue Apr  7 21:49:36 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.62 2008/11/11 19:03:06 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.63 2009/04/07 21:49:36 dyoung Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.62 2008/11/11 19:03:06 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.63 2009/04/07 21:49:36 dyoung Exp $");
 
 #include 
 #include 
@@ -567,7 +567,7 @@
 		see->see_flags |= SEE_EVENT_WORKING;
 	/* 
 	 * sme_events_check marks the first event for the device to
-	 * mak us refresh it here.  Don't refresh if the driver uses
+	 * make us refresh it here.  Don't refresh if the driver uses
 	 * its own method for refreshing.
 	 */
 	if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0) {



CVS commit: src/sys/dev/sysmon

2009-06-03 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jun  3 11:43:16 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Don't allocate the private list-threading structure unless we're going
to use it.  Otherwise we end up leaking little bits of memory for each
sensor that is not monitored at time of initial registration.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/sysmon/sysmon_envsys.c

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.85 src/sys/dev/sysmon/sysmon_envsys.c:1.86
--- src/sys/dev/sysmon/sysmon_envsys.c:1.85	Fri Aug 22 11:27:50 2008
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Jun  3 11:43:15 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.85 2008/08/22 11:27:50 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.86 2009/06/03 11:43:15 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.85 2008/08/22 11:27:50 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.86 2009/06/03 11:43:15 pgoyette Exp $");
 
 #include 
 #include 
@@ -640,6 +640,7 @@
 	prop_array_t array = NULL;
 	prop_dictionary_t dict, dict2;
 	envsys_data_t *edata = NULL;
+	sme_event_drv_t *this_evdrv;
 	int error = 0;
 
 	KASSERT(sme != NULL);
@@ -698,11 +699,13 @@
 		/*
 		 * Create all objects in sensor's dictionary.
 		 */
-		evdv = kmem_zalloc(sizeof(*evdv), KM_SLEEP);
-		evdv->evdrv = sme_add_sensor_dictionary(sme, array,
-	  		dict, edata);
-		if (evdv->evdrv)
+		this_evdrv = sme_add_sensor_dictionary(sme, array,
+		   dict, edata);
+		if (this_evdrv) {
+			evdv = kmem_zalloc(sizeof(*evdv), KM_SLEEP);
+			evdv->evdrv = this_evdrv;
 			SLIST_INSERT_HEAD(&sme_evdrv_list, evdv, evdrv_head);
+		}
 	}
 
 	/* 



CVS commit: src/sys/dev/sysmon

2009-06-08 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Jun  8 13:06:33 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Correct typo in last so we can #undef the correct macro.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.65 src/sys/dev/sysmon/sysmon_envsys_events.c:1.66
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.65	Mon Jun  8 00:55:35 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Mon Jun  8 13:06:33 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.65 2009/06/08 00:55:35 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.66 2009/06/08 13:06:33 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.65 2009/06/08 00:55:35 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.66 2009/06/08 13:06:33 pgoyette Exp $");
 
 #include 
 #include 
@@ -620,7 +620,7 @@
 		else if __EXCEEDED_LIMIT(see->see_critmax, >)
 			edata->state = ENVSYS_SCRITOVER;
 		/* FALLTHROUGH */
-#undef __EXCEED_LIMIT
+#undef __EXCEEDED_LIMIT
 
 		if (edata->state == see->see_evsent)
 			break;



CVS commit: src/sys/dev/sysmon

2009-07-08 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jul  8 13:34:11 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Clean up a couple of debug statements that got missed previously.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.68 src/sys/dev/sysmon/sysmon_envsys_events.c:1.69
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.68	Sun Jun 14 19:43:12 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Jul  8 13:34:11 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.68 2009/06/14 19:43:12 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.69 2009/07/08 13:34:11 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.68 2009/06/14 19:43:12 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.69 2009/07/08 13:34:11 pgoyette Exp $");
 
 #include 
 #include 
@@ -104,7 +104,7 @@
 			continue;
 
 		DPRINTF(("%s: dev %s sensor %s lim_flags 0x%04x event exists\n",
-		__func__, sme->sme_name, edata->desc, lim_flags));
+		__func__, sme->sme_name, edata->desc, lims->sel_flags));
 
 		see = osee;
 		if (lims->sel_flags & PROP_CRITMAX) {
@@ -150,7 +150,7 @@
 			return ENOMEM;
 
 		DPRINTF(("%s: dev %s sensor %s lim_flags 0x%04x new event\n",
-		__func__, sme->sme_name, edata->desc, lim_flags));
+		__func__, sme->sme_name, edata->desc, lims->sel_flags));
 
 		see->see_type = crittype;
 		see->see_sme = sme;



CVS commit: src/sys/dev/sysmon

2009-07-08 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jul  8 17:28:53 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Initialize lims.sel_flags before using it.  Prevents spurious limit
events being created for devices that don't provide internal limits.

Thanks to Mattias for finding this.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.69 src/sys/dev/sysmon/sysmon_envsys_events.c:1.70
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.69	Wed Jul  8 13:34:11 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Jul  8 17:28:53 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.69 2009/07/08 13:34:11 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.70 2009/07/08 17:28:53 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.69 2009/07/08 13:34:11 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.70 2009/07/08 17:28:53 pgoyette Exp $");
 
 #include 
 #include 
@@ -480,6 +480,7 @@
 	}\
 } while (/* CONSTCOND */ 0)
 
+	lims.sel_flags = 0;
 	if (sed_t->sed_edata->flags & ENVSYS_FMONLIMITS) {
 		if (sed_t->sed_sme->sme_get_limits)
 			(*sed_t->sed_sme->sme_get_limits)(sed_t->sed_sme,



CVS commit: src/sys/dev/sysmon

2009-07-08 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jul  8 17:54:27 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Remove driver name from debug message.  Not all drivers have set this
early enough, and we can easily figure out the driver name from some
subsequent debug messages.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/sysmon/sysmon_envsys.c

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.88 src/sys/dev/sysmon/sysmon_envsys.c:1.89
--- src/sys/dev/sysmon/sysmon_envsys.c:1.88	Sat Jun 13 16:08:25 2009
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Jul  8 17:54:27 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.88 2009/06/13 16:08:25 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.89 2009/07/08 17:54:27 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.88 2009/06/13 16:08:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.89 2009/07/08 17:54:27 pgoyette Exp $");
 
 #include 
 #include 
@@ -560,8 +560,8 @@
 	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,
+	DPRINTF(("%s: attached #%d (%s), units=%d (%s)\n",
+	__func__, edata->sensor, edata->desc,
 	sdt_units[i].type, sdt_units[i].desc));
 
 	return 0;



CVS commit: src/sys/dev/sysmon

2009-07-10 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 10 13:09:10 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Remove some code (bracketed by #ifdef NOTYET / #endif) that should not
have been committed in the first place.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/sysmon/sysmon_envsys.c

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.89 src/sys/dev/sysmon/sysmon_envsys.c:1.90
--- src/sys/dev/sysmon/sysmon_envsys.c:1.89	Wed Jul  8 17:54:27 2009
+++ src/sys/dev/sysmon/sysmon_envsys.c	Fri Jul 10 13:09:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.89 2009/07/08 17:54:27 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.90 2009/07/10 13:09:09 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.89 2009/07/08 17:54:27 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.90 2009/07/10 13:09:09 pgoyette Exp $");
 
 #include 
 #include 
@@ -1633,76 +1633,6 @@
 			if (error)
 break;
 		}
-
-#ifdef NOTYET
-		/*
-		 * Update limits from driver if they've been changed
-		 */
-		if ((edata->flags & ENVSYS_FLIMITS_CHANGED) == 0)
-			continue;
-
-		if (edata->upropset & PROP_DRVR_CRITMAX) {
-			error = sme_sensor_upint32(dict, "critical-max",
-		   edata->lim_critmax);
-			if (error)
-break;
-			edata->upropset &= ~PROP_USER_CRITMAX;
-		} else if ((edata->upropset & PROP_USER_CRITMAX) == 0)
-			prop_dictionary_remove(dict, "critical-max");
-
-		if (edata->upropset & PROP_DRVR_WARNMAX) {
-			error = sme_sensor_upint32(dict, "warning-max",
-		   edata->lim_warnmax);
-			if (error)
-break;
-			edata->upropset &= ~PROP_USER_WARNMAX;
-		} else if ((edata->upropset & PROP_USER_WARNMAX) == 0)
-			prop_dictionary_remove(dict, "warning-max");
-
-		if (edata->flags & ENVSYS_FPERCENT) {
-			if (edata->upropset & PROP_DRVR_BATTWARN) {
-error = sme_sensor_upint32(dict,
-			   "warning-capacity",
-			   edata->lim_warnmin);
-if (error)
-	break;
-edata->upropset &= ~PROP_USER_BATTWARN;
-			} else if ((edata->upropset & PROP_USER_BATTWARN) == 0)
-prop_dictionary_remove(dict,
-		   "warning-capacity");
-
-			if (edata->upropset & PROP_DRVR_BATTCAP) {
-error = sme_sensor_upint32(dict,
-			   "critical-capacity",
-			   edata->lim_critmin);
-if (error)
-	break;
-edata->upropset &= ~PROP_USER_BATTCAP;
-			} else if ((edata->upropset & PROP_USER_BATTCAP) == 0)
-prop_dictionary_remove(dict,
-		   "critical-capacity");
-		} else {
-			if (edata->upropset & PROP_DRVR_WARNMIN) {
-error = sme_sensor_upint32(dict,
-			   "warning-min",
-			   edata->lim_warnmin);
-if (error)
-	break;
-edata->upropset &= ~PROP_USER_WARNMIN;
-			} else if ((edata->upropset & PROP_USER_WARNMIN) == 0)
-prop_dictionary_remove(dict, "warning-min");
-
-			if (edata->upropset & PROP_DRVR_CRITMIN) {
-error = sme_sensor_upint32(dict,
-			   "critical-min",
-			   edata->lim_critmin);
-if (error)
-	break;
-edata->upropset &= ~PROP_USER_CRITMIN;
-			} else if ((edata->upropset & PROP_USER_CRITMIN) == 0)
-prop_dictionary_remove(dict, "critical-min");
-		}
-#endif
 	}
 
 	return error;



CVS commit: src/sys/dev/sysmon

2009-07-10 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 10 15:27:33 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Document usage of PROP_DRIVER_LIMITS flag and set it correctly.

Use flag bits to determine validity of limit values, rather than
assuming that invalid/not-present values are set to zero.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.70 src/sys/dev/sysmon/sysmon_envsys_events.c:1.71
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.70	Wed Jul  8 17:28:53 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Fri Jul 10 15:27:33 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.70 2009/07/08 17:28:53 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.71 2009/07/10 15:27:33 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.70 2009/07/08 17:28:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.71 2009/07/10 15:27:33 pgoyette Exp $");
 
 #include 
 #include 
@@ -480,15 +480,30 @@
 	}\
 } while (/* CONSTCOND */ 0)
 
+	/*
+	 * If driver provides method to retrieve its internal limit
+	 * values, call it.  If it returns any values, set the flag
+	 * PROP_DRIVER_LIMITS to indicate that the driver can process
+	 * all the limits we have.  (If userland limits are specified
+	 * later and the driver cannot handle them, this flag will be
+	 * cleared.)
+	 *
+	 * If the driver cannot or does not provide us with limit values
+	 * we cannot monitor limits now;  we get another chance to create
+	 * the FMONLIMITS entry later if userland specifies some limits.
+	 */
 	lims.sel_flags = 0;
-	if (sed_t->sed_edata->flags & ENVSYS_FMONLIMITS) {
+	if (sed_t->sed_edata->flags & ENVSYS_FMONLIMITS)
 		if (sed_t->sed_sme->sme_get_limits)
 			(*sed_t->sed_sme->sme_get_limits)(sed_t->sed_sme,
 			  sed_t->sed_edata,
 			  &lims);
-		else
-			sed_t->sed_edata->flags &= ~ENVSYS_FMONLIMITS;
-	}
+	if (lims.sel_flags)
+		lims.sel_flags |= PROP_DRIVER_LIMITS;
+	else
+		sed_t->sed_edata->flags &= ~ENVSYS_FMONLIMITS;
+
+	/* Register the events that were specified */
 
 	SEE_REGEVENT(ENVSYS_FMONCRITICAL,
 		 PENVSYS_EVENT_CRITICAL,
@@ -645,18 +660,22 @@
 	 */
 	case PENVSYS_EVENT_LIMITS:
 	case PENVSYS_EVENT_CAPACITY:
-#define __EXCEED_LIM(lim, rel) ((lim) && edata->value_cur rel (lim))
+#define	__EXCEED_LIM(valid, lim, rel) \
+		((see->see_lims.sel_flags & (valid)) && \
+		 (edata->value_cur rel (see->see_lims.lim)))
+
 		if ((see->see_lims.sel_flags & PROP_DRIVER_LIMITS) == 0) {
-			if __EXCEED_LIM(see->see_lims.sel_critmin, <)
+			if __EXCEED_LIM(PROP_CRITMIN | PROP_BATTCAP,
+	sel_critmin, <)
 edata->state = ENVSYS_SCRITUNDER;
-			else if __EXCEED_LIM(see->see_lims.sel_warnmin, <)
+			else if __EXCEED_LIM(PROP_WARNMIN | PROP_BATTWARN, 
+	sel_warnmin, <)
 edata->state = ENVSYS_SWARNUNDER;
-			else if __EXCEED_LIM(see->see_lims.sel_warnmax, >)
+			else if __EXCEED_LIM(PROP_WARNMAX, sel_warnmax, >)
 edata->state = ENVSYS_SWARNOVER;
-			else if __EXCEED_LIM(see->see_lims.sel_critmax, >)
+			else if __EXCEED_LIM(PROP_CRITMAX, sel_critmax, >)
 edata->state = ENVSYS_SCRITOVER;
 		}
-		/* FALLTHROUGH */
 #undef	__EXCEED_LIM
 
 		/*



CVS commit: src/sys/dev/sysmon

2010-03-24 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Mar 24 12:15:54 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Do the initial refresh before creating the event monitors, in case the
event monitors require some of the data loaded by the refresh.  For
example, the initial refresh might load sensor limits and max_value in
addition to the cur_value.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/dev/sysmon/sysmon_envsys.c

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.97 src/sys/dev/sysmon/sysmon_envsys.c:1.98
--- src/sys/dev/sysmon/sysmon_envsys.c:1.97	Sun Mar 14 18:03:15 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Mar 24 12:15:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.97 2010/03/14 18:03:15 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.98 2010/03/24 12:15:54 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.97 2010/03/14 18:03:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.98 2010/03/24 12:15:54 pgoyette Exp $");
 
 #include 
 #include 
@@ -755,12 +755,20 @@
 
 out:
 	/*
-	 * No errors? register the events that were set in the driver
-	 * and make an initial data refresh if was requested.
+	 * No errors?  Make an initial data refresh if was requested,
+	 * then register the events that were set in the driver.  Do
+	 * the refresh first in case it is needed to establish the
+	 * limits or max_value needed by some events.
 	 */
 	if (error == 0) {
 		nevent = 0;
 		sysmon_task_queue_init();
+
+		if (sme->sme_flags & SME_INIT_REFRESH) {
+			sysmon_task_queue_sched(0, sme_initial_refresh, sme);
+			DPRINTF(("%s: scheduled initial refresh for '%s'\n",
+__func__, sme->sme_name));
+		}
 		SLIST_FOREACH(evdv, &sme_evdrv_list, evdrv_head) {
 			sysmon_task_queue_sched(0,
 			sme_event_drvadd, evdv->evdrv);
@@ -768,9 +776,6 @@
 		}
 		DPRINTF(("%s: driver '%s' registered (nsens=%d nevent=%d)\n",
 		__func__, sme->sme_name, sme->sme_nsensors, nevent));
-
-		if (sme->sme_flags & SME_INIT_REFRESH)
-			sysmon_task_queue_sched(0, sme_initial_refresh, sme);
 	}
 
 out2:



CVS commit: src/sys/dev/sysmon

2010-03-24 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Mar 24 13:11:41 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
In sysmon_envsys_sensor_event(), permit delivery of all events for the
sensor if no event type is specified.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.88 src/sys/dev/sysmon/sysmon_envsys_events.c:1.89
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.88	Tue Mar 23 16:52:02 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Mar 24 13:11:41 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.88 2010/03/23 16:52:02 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.89 2010/03/24 13:11:41 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.88 2010/03/23 16:52:02 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.89 2010/03/24 13:11:41 pgoyette Exp $");
 
 #include 
 #include 
@@ -646,7 +646,8 @@
  * sysmon_envsys_sensor_event
  *
  *	+ Find the monitor event of a particular type for a given sensor
- *	  on a device and deliver the event if one is required.
+ *	  on a device and deliver the event if one is required.  If
+ *	  no event type is specified, deliver all events for the sensor.
  */
 void
 sysmon_envsys_sensor_event(struct sysmon_envsys *sme, envsys_data_t *edata, 
@@ -656,11 +657,14 @@
 
 	mutex_enter(&sme->sme_mtx);
 	LIST_FOREACH(see, &sme->sme_events_list, see_list) {
-		if (edata != see->see_edata ||
-		see->see_type != ev_type)
-			continue; 
-		sme_deliver_event(see);
-		break;
+		if (edata != see->see_edata)
+			continue;
+		if (ev_type == 0 ||
+		ev_type == see->see_type) {
+			sme_deliver_event(see);
+			if (ev_type != 0)
+break;
+		}
 	}
 	mutex_exit(&sme->sme_mtx);
 }



CVS commit: src/sys/dev/sysmon

2010-03-24 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Wed Mar 24 19:15:00 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Fix ENVSYS_DEBUG build.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.89 src/sys/dev/sysmon/sysmon_envsys_events.c:1.90
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.89	Wed Mar 24 13:11:41 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Mar 24 19:15:00 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.89 2010/03/24 13:11:41 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.90 2010/03/24 19:15:00 njoly Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.89 2010/03/24 13:11:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.90 2010/03/24 19:15:00 njoly Exp $");
 
 #include 
 #include 
@@ -113,7 +113,7 @@
 	 * even if its ENVSYS_FPERCENT flag and value_max are set.
 	 */
 
-	DPRINTF(("%s: units %d props 0x%04x upropset 0x%04x max_val %"PRId64
+	DPRINTF(("%s: units %d props 0x%04x upropset 0x%04x max_val %d"
 		" edata-flags 0x%04x\n", __func__, edata->units, props,
 		edata->upropset, edata->value_max, edata->flags));
 



CVS commit: src/sys/dev/sysmon

2010-03-26 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Mar 26 12:37:00 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Export the sensor device's class.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/sysmon/sysmon_envsys.c

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.98 src/sys/dev/sysmon/sysmon_envsys.c:1.99
--- src/sys/dev/sysmon/sysmon_envsys.c:1.98	Wed Mar 24 12:15:54 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Fri Mar 26 12:36:59 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.98 2010/03/24 12:15:54 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.99 2010/03/26 12:36:59 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.98 2010/03/24 12:15:54 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.99 2010/03/26 12:36:59 pgoyette Exp $");
 
 #include 
 #include 
@@ -1141,6 +1141,7 @@
 			prop_dictionary_t dict)
 {
 	prop_dictionary_t pdict;
+	const char *class;
 	int error = 0;
 
 	pdict = prop_dictionary_create();
@@ -1148,8 +1149,8 @@
 		return EINVAL;
 
 	/*
-	 * Add the 'refresh-timeout' object into the 'device-properties'
-	 * dictionary. We use by default 30 seconds.
+	 * Add the 'refresh-timeout' and 'dev-class' objects into the
+	 * 'device-properties' dictionary.
 	 *
 	 * 	...
 	 * 	
@@ -1157,7 +1158,9 @@
 	 * 		
 	 * 			refresh-timeout
 	 * 			120device-class
+	 *			class_name
+	 * 		
 	 * 	
 	 * 	...
 	 *
@@ -1170,6 +1173,16 @@
 		error = EINVAL;
 		goto out;
 	}
+	if (sme->sme_class == SME_CLASS_BATTERY)
+		class = "battery";
+	else if (sme->sme_class == SME_CLASS_ACADAPTER)
+		class = "ac-adapter";
+	else
+		class = "other";
+	if (!prop_dictionary_set_cstring_nocopy(pdict, "device-class", class)) {
+		error = EINVAL;
+		goto out;
+	}
 
 	if (!prop_dictionary_set(dict, "device-properties", pdict)) {
 		error = EINVAL;



CVS commit: src/sys/dev/sysmon

2010-03-26 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Mar 26 20:31:06 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmonvar.h

Log Message:
Add a routine to iterate over all the sensors on the system.  This will
be needed to update acpiapm_get_powstat() which is currently slightly
broken due to recent rearrangement of acpi_bat(4)'s sensors.  (This
approach is in lieu of exporting proplists between kernel entities, and
avoids exposing some internal sysmon_envsys details.)


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/sysmon/sysmonvar.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.99 src/sys/dev/sysmon/sysmon_envsys.c:1.100
--- src/sys/dev/sysmon/sysmon_envsys.c:1.99	Fri Mar 26 12:36:59 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Fri Mar 26 20:31:06 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.99 2010/03/26 12:36:59 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.100 2010/03/26 20:31:06 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.99 2010/03/26 12:36:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.100 2010/03/26 20:31:06 pgoyette Exp $");
 
 #include 
 #include 
@@ -2001,3 +2001,30 @@
 
 	return error;
 }
+
+/*
+ * + sysmon_envsys_foreach_sensor
+ *
+ *	Walk through the devices' sensor lists and execute the callback.
+ *	If the callback returns false, the remainder of the current
+ *	device's sensors are skipped.
+ */
+void   
+sysmon_envsys_foreach_sensor(bool(*func)(struct sysmon_envsys *,
+			 envsys_data_t *, void*), void *arg)
+{
+	struct sysmon_envsys *sme;
+	envsys_data_t *sensor;
+
+	mutex_enter(&sme_global_mtx);
+	LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) {
+
+		mutex_enter(&sme->sme_mtx);
+		TAILQ_FOREACH(sensor, &sme->sme_sensors_list, sensors_head) {
+			if ((*func)(sme, sensor, arg))
+break;
+		}
+		mutex_exit(&sme->sme_mtx);
+	}
+	mutex_exit(&sme_global_mtx);
+}

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.34 src/sys/dev/sysmon/sysmonvar.h:1.35
--- src/sys/dev/sysmon/sysmonvar.h:1.34	Fri Mar 19 02:19:13 2010
+++ src/sys/dev/sysmon/sysmonvar.h	Fri Mar 26 20:31:06 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.34 2010/03/19 02:19:13 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.35 2010/03/26 20:31:06 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -208,6 +208,9 @@
 void	sysmon_envsys_sensor_event(struct sysmon_envsys *, envsys_data_t *,
    int);
 
+void	sysmon_envsys_foreach_sensor(bool(*)(struct sysmon_envsys *,
+ envsys_data_t *, void*), void *);
+
 void	sysmon_envsys_init(void);
 
 /*



CVS commit: src/sys/dev/sysmon

2010-03-26 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Mar 26 21:06:25 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Make this work the way the preceeding comment blocks says it works, and
break out of the while{ } when the callback returns false, not when it
returns true!


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/dev/sysmon/sysmon_envsys.c

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.100 src/sys/dev/sysmon/sysmon_envsys.c:1.101
--- src/sys/dev/sysmon/sysmon_envsys.c:1.100	Fri Mar 26 20:31:06 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Fri Mar 26 21:06:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.100 2010/03/26 20:31:06 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.101 2010/03/26 21:06:25 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.100 2010/03/26 20:31:06 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.101 2010/03/26 21:06:25 pgoyette Exp $");
 
 #include 
 #include 
@@ -2021,7 +2021,7 @@
 
 		mutex_enter(&sme->sme_mtx);
 		TAILQ_FOREACH(sensor, &sme->sme_sensors_list, sensors_head) {
-			if ((*func)(sme, sensor, arg))
+			if (!(*func)(sme, sensor, arg))
 break;
 		}
 		mutex_exit(&sme->sme_mtx);



CVS commit: src/sys/dev/sysmon

2010-03-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Mar 27 13:23:18 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmonvar.h

Log Message:
Fix the locking protocol in sysmon_envsys_foreach_sensor(), and add an
additional argument to control whether or not the sensors are refreshed
before invoking the callback routine.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.35 -r1.36 src/sys/dev/sysmon/sysmonvar.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.101 src/sys/dev/sysmon/sysmon_envsys.c:1.102
--- src/sys/dev/sysmon/sysmon_envsys.c:1.101	Fri Mar 26 21:06:25 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Mar 27 13:23:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.101 2010/03/26 21:06:25 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.102 2010/03/27 13:23:18 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.101 2010/03/26 21:06:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.102 2010/03/27 13:23:18 pgoyette Exp $");
 
 #include 
 #include 
@@ -2011,7 +2011,8 @@
  */
 void   
 sysmon_envsys_foreach_sensor(bool(*func)(struct sysmon_envsys *,
-			 envsys_data_t *, void*), void *arg)
+	 envsys_data_t *, void*), void *arg,
+			 bool refresh)
 {
 	struct sysmon_envsys *sme;
 	envsys_data_t *sensor;
@@ -2019,12 +2020,18 @@
 	mutex_enter(&sme_global_mtx);
 	LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) {
 
-		mutex_enter(&sme->sme_mtx);
+		sysmon_envsys_acquire(sme, false);
 		TAILQ_FOREACH(sensor, &sme->sme_sensors_list, sensors_head) {
+			if (refresh &&
+			(sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
+mutex_enter(&sme->sme_mtx);
+(*sme->sme_refresh)(sme, sensor);
+mutex_exit(&sme->sme_mtx);
+			}
 			if (!(*func)(sme, sensor, arg))
 break;
 		}
-		mutex_exit(&sme->sme_mtx);
+		sysmon_envsys_release(sme, false);
 	}
 	mutex_exit(&sme_global_mtx);
 }

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.35 src/sys/dev/sysmon/sysmonvar.h:1.36
--- src/sys/dev/sysmon/sysmonvar.h:1.35	Fri Mar 26 20:31:06 2010
+++ src/sys/dev/sysmon/sysmonvar.h	Sat Mar 27 13:23:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.35 2010/03/26 20:31:06 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.36 2010/03/27 13:23:18 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -209,7 +209,8 @@
    int);
 
 void	sysmon_envsys_foreach_sensor(bool(*)(struct sysmon_envsys *,
- envsys_data_t *, void*), void *);
+	 envsys_data_t *, void*), void *,
+	 bool);
 
 void	sysmon_envsys_init(void);
 



CVS commit: src/sys/dev/sysmon

2010-03-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Mar 27 13:34:16 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmonvar.h

Log Message:
Constify the args to sysmon_envsys_foreach_sensor()'s callback function.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/sysmon/sysmonvar.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.102 src/sys/dev/sysmon/sysmon_envsys.c:1.103
--- src/sys/dev/sysmon/sysmon_envsys.c:1.102	Sat Mar 27 13:23:18 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Mar 27 13:34:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.102 2010/03/27 13:23:18 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.103 2010/03/27 13:34:16 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.102 2010/03/27 13:23:18 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.103 2010/03/27 13:34:16 pgoyette Exp $");
 
 #include 
 #include 
@@ -2010,9 +2010,9 @@
  *	device's sensors are skipped.
  */
 void   
-sysmon_envsys_foreach_sensor(bool(*func)(struct sysmon_envsys *,
-	 envsys_data_t *, void*), void *arg,
-			 bool refresh)
+sysmon_envsys_foreach_sensor(bool(*func)(const struct sysmon_envsys *,
+	 const envsys_data_t *, void*),
+			 void *arg, bool refresh)
 {
 	struct sysmon_envsys *sme;
 	envsys_data_t *sensor;

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.36 src/sys/dev/sysmon/sysmonvar.h:1.37
--- src/sys/dev/sysmon/sysmonvar.h:1.36	Sat Mar 27 13:23:18 2010
+++ src/sys/dev/sysmon/sysmonvar.h	Sat Mar 27 13:34:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.36 2010/03/27 13:23:18 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.37 2010/03/27 13:34:16 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -208,9 +208,9 @@
 void	sysmon_envsys_sensor_event(struct sysmon_envsys *, envsys_data_t *,
    int);
 
-void	sysmon_envsys_foreach_sensor(bool(*)(struct sysmon_envsys *,
-	 envsys_data_t *, void*), void *,
-	 bool);
+void	sysmon_envsys_foreach_sensor(bool(*)(const struct sysmon_envsys *,
+	 const envsys_data_t *, void*),
+ void *, bool);
 
 void	sysmon_envsys_init(void);
 



CVS commit: src/sys/dev/sysmon

2010-04-01 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Apr  1 12:16:14 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
sysmon_envsysvar.h sysmonvar.h

Log Message:
Permit creation of an event-monitor for alarm limits even if the limits
are not currently set (and, in case of battery capacity sensors, if there
is no value_max).  Ensure that such an event-monitor does not trigger the
delivery of any actual events.

Provide a mechanism for sensors to set their limits at time other than
system startup (for example, when a battery is inserted).

This allows us to boot a system with a battery missing, install the
battery some time later, and automatically monitor it without requiring
any user intervention to create the event-monitor.  (The actual changes
for battery sensors to use this new capability will come later.)


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/sysmon/sysmon_envsysvar.h
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/sysmon/sysmonvar.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.103 src/sys/dev/sysmon/sysmon_envsys.c:1.104
--- src/sys/dev/sysmon/sysmon_envsys.c:1.103	Sat Mar 27 13:34:16 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Apr  1 12:16:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.103 2010/03/27 13:34:16 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.104 2010/04/01 12:16:14 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.103 2010/03/27 13:34:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.104 2010/04/01 12:16:14 pgoyette Exp $");
 
 #include 
 #include 
@@ -84,7 +84,8 @@
 
 kmutex_t sme_global_mtx;
 
-static prop_dictionary_t sme_propd;
+prop_dictionary_t sme_propd;
+
 static uint32_t sysmon_envsys_next_sensor_index;
 static struct sysmon_envsys *sysmon_envsys_find_40(u_int);
 

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.90 src/sys/dev/sysmon/sysmon_envsys_events.c:1.91
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.90	Wed Mar 24 19:15:00 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Apr  1 12:16:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.90 2010/03/24 19:15:00 njoly Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.91 2010/04/01 12:16:14 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.90 2010/03/24 19:15:00 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.91 2010/04/01 12:16:14 pgoyette Exp $");
 
 #include 
 #include 
@@ -125,10 +125,10 @@
 	 !(edata->flags & ENVSYS_FPERCENT) ||
 	 (props & PROP_VAL_LIMITS) ||
 	 (edata->upropset & PROP_VAL_LIMITS)))
-		return ENOTSUP;
+		props = 0;
 
 	if ((props & PROP_VAL_LIMITS) && (edata->upropset & PROP_CAP_LIMITS))
-		return ENOTSUP;
+		props = 0;
 
 	/* 
 	 * check if the event is already on the list and return
@@ -452,18 +452,10 @@
 			  sed_t->sed_edata,
 			  &lims, &props);
 	/*
-	 * If no values returned, don't create the event monitor at
-	 * this time.  We'll get another chance later when the user
-	 * provides us with limits.
-	 */
-	if (props == 0)
-		sed_t->sed_edata->flags &= ~ENVSYS_FMONLIMITS;
-
-	/*
 	 * If driver doesn't provide a way to "absorb" user-specified
 	 * limit values, we must monitor all limits ourselves
 	 */
-	else if (sed_t->sed_sme->sme_set_limits == NULL)
+	if (sed_t->sed_sme->sme_set_limits == NULL)
 		props &= ~PROP_DRIVER_LIMITS;
 
 	/* Register the events that were specified */
@@ -542,6 +534,64 @@
 }
 
 /*
+ * sysmon_envsys_update_limits
+ *
+ *	+ If a driver needs to update the limits that it is providing,
+ *	  we need to update the dictionary data as well as the limits.
+ *	  This only makes sense if the driver is capable of providing
+ *	  its limits, and if there is a limits event-monitor.
+ */
+int
+sysmon_envsys_update_limits(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
+	prop_dictionary_t sdict = NULL;
+	prop_array_t array = NULL;
+	sysmon_envsys_lim_t lims;
+	sme_event_t *see;
+	uint32_t props = 0;
+
+	if (sme->sme_get_limits == NULL ||
+	(edata->flags & ENVSYS_FMONLIMITS) == 0)
+		return EINVAL;
+
+	/* Find the dictionary for this sensor */
+	sysmon_envsys_acquire(sme, false);
+	array = prop_dictionary_get(sme_propd, sme->sme_name);
+	if (array == NULL ||
+	prop_object_type(array) != PROP_TYPE_ARRAY) {
+		DPRINTF(("%s: array device failed\n", __func__));
+		sysmon_envsys_release(sme, false);
+		return

CVS commit: src/sys/dev/sysmon

2010-04-03 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Apr  3 13:55:09 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
When unregistering a device, in addition to reducing the global count
of sensors, we need to adjust the sme_fsensor values for some devices.
Failure to do this leaves a sparesly-populated number-space and can
subsequently result in overlapping sensors number assignments.  (This
only affects the compatability-mode API, but still needs to be fixed.)


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/sysmon/sysmon_envsys.c

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.104 src/sys/dev/sysmon/sysmon_envsys.c:1.105
--- src/sys/dev/sysmon/sysmon_envsys.c:1.104	Thu Apr  1 12:16:14 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Apr  3 13:55:09 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.104 2010/04/01 12:16:14 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.105 2010/04/03 13:55:09 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.104 2010/04/01 12:16:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.105 2010/04/03 13:55:09 pgoyette Exp $");
 
 #include 
 #include 
@@ -860,6 +860,7 @@
 sysmon_envsys_unregister(struct sysmon_envsys *sme)
 {
 	prop_array_t array;
+	struct sysmon_envsys *osme;
 
 	KASSERT(sme != NULL);
 
@@ -868,11 +869,16 @@
 	 */
 	sme_event_unregister_all(sme);
 	/*
-	 * Decrement global sensors counter (only used for compatibility
-	 * with previous API) and remove the device from the list.
+	 * Decrement global sensors counter and the first_sensor index
+	 * for remaining devices in the list (only used for compatibility
+	 * with previous API), and remove the device from the list.
 	 */
 	mutex_enter(&sme_global_mtx);
 	sysmon_envsys_next_sensor_index -= sme->sme_nsensors;
+	LIST_FOREACH(osme, &sysmon_envsys_list, sme_list) {
+		if (osme->sme_fsensor >= sme->sme_fsensor)
+			osme->sme_fsensor -= sme->sme_nsensors;
+	}
 	LIST_REMOVE(sme, sme_list);
 	mutex_exit(&sme_global_mtx);
 



CVS commit: src/sys/dev/sysmon

2010-04-10 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Apr 10 19:01:01 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
sysmon_envsysvar.h

Log Message:
When removing sensor properties with envstat -S, ensure that drivers
which could have modified hardware state are informed so that original
state can be restored.

Welcome to 5.99.27


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.35 -r1.36 src/sys/dev/sysmon/sysmon_envsysvar.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.105 src/sys/dev/sysmon/sysmon_envsys.c:1.106
--- src/sys/dev/sysmon/sysmon_envsys.c:1.105	Sat Apr  3 13:55:09 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Apr 10 19:01:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.105 2010/04/03 13:55:09 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.106 2010/04/10 19:01:00 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.105 2010/04/03 13:55:09 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.106 2010/04/10 19:01:00 pgoyette Exp $");
 
 #include 
 #include 
@@ -1053,6 +1053,7 @@
 	prop_dictionary_t sdict;
 	envsys_data_t *edata = NULL;
 	char tmp[ENVSYS_DESCLEN];
+	sysmon_envsys_lim_t lims;
 	int ptype;
 
 	mutex_enter(&sme_global_mtx);
@@ -1090,10 +1091,6 @@
 "maximum-capacity");
 ptype = PENVSYS_EVENT_CAPACITY;
 			}
-			if (ptype != 0)
-sme_event_unregister(sme, edata->desc, ptype);
-
-			ptype = 0;
 			if (edata->upropset & PROP_WARNMAX) {
 prop_dictionary_remove(sdict, "warning-max");
 ptype = PENVSYS_EVENT_LIMITS;
@@ -1113,9 +1110,6 @@
 prop_dictionary_remove(sdict, "critical-min");
 ptype = PENVSYS_EVENT_LIMITS;
 			}
-			if (ptype != 0)
-sme_event_unregister(sme, edata->desc, ptype);
-
 			if (edata->upropset & PROP_RFACT) {
 (void)sme_sensor_upint32(sdict, "rfact", 0);
 edata->rfact = 0;
@@ -1125,8 +1119,36 @@
 (void)sme_sensor_upstring(sdict,
 			  	"description", edata->desc);
 
-			if (edata->upropset)
-edata->upropset = 0;
+			if (ptype == 0)
+continue;
+
+			/*
+			 * If there were any limit values removed, we
+			 * need to revert to initial limits.
+			 *
+			 * First, tell the driver that we need it to 
+			 * restore any h/w limits which may have been 
+			 * changed to stored, boot-time values.  Then
+			 * we need to retrieve those limits and update
+			 * the event data in the dictionary.
+			 */
+			if (sme->sme_set_limits) {
+DPRINTF(("%s: reset limits for %s %s\n",
+	__func__, sme->sme_name, edata->desc));
+(*sme->sme_set_limits)(sme, edata, NULL, NULL);
+			}
+			if (sme->sme_get_limits) {
+DPRINTF(("%s: retrieve limits for %s %s\n",
+	__func__, sme->sme_name, edata->desc));
+lims = edata->limits;
+(*sme->sme_get_limits)(sme, edata, &lims,
+		   &edata->upropset);
+			}
+			if (edata->upropset) {
+DPRINTF(("%s: install limits for %s %s\n",
+	__func__, sme->sme_name, edata->desc));
+sme_update_limits(sme, edata);
+			}
 		}
 
 		/*

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.91 src/sys/dev/sysmon/sysmon_envsys_events.c:1.92
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.91	Thu Apr  1 12:16:14 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Apr 10 19:01:01 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.91 2010/04/01 12:16:14 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.92 2010/04/10 19:01:01 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.91 2010/04/01 12:16:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.92 2010/04/10 19:01:01 pgoyette Exp $");
 
 #include 
 #include 
@@ -544,29 +544,45 @@
 int
 sysmon_envsys_update_limits(struct sysmon_envsys *sme, envsys_data_t *edata)
 {
+	int err;
+
+	if (sme->sme_get_limits == NULL ||
+	(edata->flags & ENVSYS_FMONLIMITS) == 0)
+		return EINVAL;
+
+	sysmon_envsys_acquire(sme, false);
+	err = sme_update_limits(sme, edata);
+	sysmon_envsys_release(sme, false);
+
+	return err;
+}
+
+/*
+ * sme_update_limits
+ *
+ *	+ Internal version of sysmon_envsys_update_limits() to be used
+ *	  when the device has already been sysmon_envsys_acquire()d.
+ */
+
+int
+sme_update_limits(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
 	prop_dictionary_t sdict = NULL;
 	prop_array_t array = NULL;
 	sysmon_envsys_lim_t lims;
 	sme_event_t *see;
 	uint32_t props = 0;
 
-	if (sme->sme_get_limits == N

CVS commit: src/sys/dev/sysmon

2010-09-21 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Sep 22 00:13:55 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
1. Don't try to call the driver's get_limits routine if it doesn't have
   one.  Fixes a panic reported by njoly@ in private Email

2. Acquire the device before checking whether or not the get_limits
   routine exists.

XXX There's still a bug in here somewhere that prevents setting of
XXX limit values after using 'envstat -S'


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.92 src/sys/dev/sysmon/sysmon_envsys_events.c:1.93
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.92	Sat Apr 10 19:01:01 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Sep 22 00:13:55 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.92 2010/04/10 19:01:01 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.93 2010/09/22 00:13:55 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.92 2010/04/10 19:01:01 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.93 2010/09/22 00:13:55 pgoyette Exp $");
 
 #include 
 #include 
@@ -546,12 +546,12 @@
 {
 	int err;
 
+	sysmon_envsys_acquire(sme, false);
 	if (sme->sme_get_limits == NULL ||
 	(edata->flags & ENVSYS_FMONLIMITS) == 0)
-		return EINVAL;
-
-	sysmon_envsys_acquire(sme, false);
-	err = sme_update_limits(sme, edata);
+		err = EINVAL;
+	else
+		err = sme_update_limits(sme, edata);
 	sysmon_envsys_release(sme, false);
 
 	return err;
@@ -595,8 +595,9 @@
 	if (see == NULL)
 		return EINVAL;
 
-	/* Get new limit values */
-	(*sme->sme_get_limits)(sme, edata, &lims, &props);
+	/* Update limit values from driver if possible */
+	if (sme->sme_get_limits != NULL)
+		(*sme->sme_get_limits)(sme, edata, &lims, &props);
 
 	/* Update event and dictionary */
 	sme_event_register(sdict, edata, sme, &lims, props,



CVS commit: src/sys/dev/sysmon

2010-10-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Oct 20 18:50:47 UTC 2010

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
remove unused routine (per comment)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.1 src/sys/dev/sysmon/swsensor.c:1.2
--- src/sys/dev/sysmon/swsensor.c:1.1	Tue Oct 19 11:55:38 2010
+++ src/sys/dev/sysmon/swsensor.c	Wed Oct 20 18:50:46 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.1 2010/10/19 11:55:38 pgoyette Exp $ */
+/*	$NetBSD: swsensor.c,v 1.2 2010/10/20 18:50:46 pooka Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.1 2010/10/19 11:55:38 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.2 2010/10/20 18:50:46 pooka Exp $");
 
 #include 
 #include 
@@ -192,15 +192,3 @@
 
 	return ret;
 }
-
-/*
- * Initialization entry for rump
- */
-
-int
-swsensorattach(int n __unused)
-{
-	printf("%s: ", "swsensor0");
-
-	return swsensor_init(NULL);
-}



CVS commit: src/sys/dev/sysmon

2010-10-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Oct 20 19:21:05 UTC 2010

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Set sensor state to valid upon refresh to make things generally work.

pgoyette ok


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.2 src/sys/dev/sysmon/swsensor.c:1.3
--- src/sys/dev/sysmon/swsensor.c:1.2	Wed Oct 20 18:50:46 2010
+++ src/sys/dev/sysmon/swsensor.c	Wed Oct 20 19:21:04 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.2 2010/10/20 18:50:46 pooka Exp $ */
+/*	$NetBSD: swsensor.c,v 1.3 2010/10/20 19:21:04 pooka Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.2 2010/10/20 18:50:46 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.3 2010/10/20 19:21:04 pooka Exp $");
 
 #include 
 #include 
@@ -93,6 +93,7 @@
 {
 
 	edata->value_cur = sw_sensor_value;
+	edata->state = ENVSYS_SVALID;
 }
 
 /*



CVS commit: src/sys/dev/sysmon

2010-10-23 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sat Oct 23 11:24:16 UTC 2010

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Revert 1.2 apart from incorrect comment.  the devattach() routine
is of course still used by kernel&config pseudodev.

pointed out by jakllsch


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.3 src/sys/dev/sysmon/swsensor.c:1.4
--- src/sys/dev/sysmon/swsensor.c:1.3	Wed Oct 20 19:21:04 2010
+++ src/sys/dev/sysmon/swsensor.c	Sat Oct 23 11:24:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.3 2010/10/20 19:21:04 pooka Exp $ */
+/*	$NetBSD: swsensor.c,v 1.4 2010/10/23 11:24:16 pooka Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.3 2010/10/20 19:21:04 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.4 2010/10/23 11:24:16 pooka Exp $");
 
 #include 
 #include 
@@ -193,3 +193,11 @@
 
 	return ret;
 }
+
+int
+swsensorattach(int n __unused)
+{
+	printf("%s: ", "swsensor0");
+
+	return swsensor_init(NULL);
+}



CVS commit: src/sys/dev/sysmon

2010-11-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Nov 11 21:55:04 UTC 2010

Modified Files:
src/sys/dev/sysmon: swwdog.c

Log Message:
Apparently swwdog reboot hasn't worked in several years since it
tried to cpu_reboot() from a callout.  Make it reboot from a workq
instead.

problem made manifest
by atf test
rumpfs unmount flush
caused issue to un-shush

tested: rump kernel (tests/dev/sysmon) and qemu


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/sysmon/swwdog.c

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/swwdog.c
diff -u src/sys/dev/sysmon/swwdog.c:1.11 src/sys/dev/sysmon/swwdog.c:1.12
--- src/sys/dev/sysmon/swwdog.c:1.11	Fri Aug  6 16:02:56 2010
+++ src/sys/dev/sysmon/swwdog.c	Thu Nov 11 21:55:04 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swwdog.c,v 1.11 2010/08/06 16:02:56 pooka Exp $	*/
+/*	$NetBSD: swwdog.c,v 1.12 2010/11/11 21:55:04 pooka Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.11 2010/08/06 16:02:56 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.12 2010/11/11 21:55:04 pooka Exp $");
 
 /*
  *
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "ioconf.h"
@@ -85,17 +86,32 @@
 static void swwdog_sysctl_setup(void);
 static struct sysctllog *swwdog_sysctllog;
 
+static void
+doreboot(struct work *wrkwrkwrk, void *p)
+{
+
+	cpu_reboot(0, NULL);
+}
+
+static struct workqueue *wq;
+
 void
 swwdogattach(int n __unused)
 {
 	int err;
 	static struct cfdata cf;
 
+	if (workqueue_create(&wq, "swwreboot", doreboot, NULL,
+	PRI_NONE, IPL_NONE, 0) != 0) {
+		aprint_error("failed to create swwdog reboot wq");
+	}
+
 	err = config_cfattach_attach(swwdog_cd.cd_name, &swwdog_ca);
 	if (err) {
 		aprint_error("%s: couldn't register cfattach: %d\n",
 		swwdog_cd.cd_name, err);
 		config_cfdriver_detach(&swwdog_cd);
+		workqueue_destroy(wq);
 		return;
 	}
 
@@ -149,6 +165,7 @@
 	swwdog_disarm(sc);
 	callout_destroy(&sc->sc_c);
 	sysctl_teardown(&swwdog_sysctllog);
+	workqueue_destroy(wq);
 
 	return 1;
 }
@@ -211,6 +228,7 @@
 swwdog_panic(void *vsc)
 {
 	struct swwdog_softc *sc = vsc;
+	static struct work wk; /* we'll need it max once */
 	bool do_panic;
 
 	do_panic = !swwdog_reboot;
@@ -223,7 +241,7 @@
 	if (do_panic)
 		panic("watchdog timer expired");
 	else
-		cpu_reboot(0, NULL);
+		workqueue_enqueue(wq, &wk, NULL);
 }
 
 static void



CVS commit: src/sys/dev/sysmon

2010-12-06 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Dec  6 23:26:44 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Make this compile when "options ENVSYS_OBJECTS_DEBUG" is defined.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.93 src/sys/dev/sysmon/sysmon_envsys_events.c:1.94
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.93	Wed Sep 22 00:13:55 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Mon Dec  6 23:26:44 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.93 2010/09/22 00:13:55 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.94 2010/12/06 23:26:44 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.93 2010/09/22 00:13:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.94 2010/12/06 23:26:44 pgoyette Exp $");
 
 #include 
 #include 
@@ -780,8 +780,8 @@
 
 		see->see_evsent = edata->state;
 		DPRINTFOBJ(("%s: (%s) desc=%s sensor=%d state=%d send_ev=%d\n",
-		__func__, sme->sme_name, edata->desc, edata->sensor,
-		edata->state,
+		__func__, see->see_sme->sme_name, edata->desc,
+		edata->sensor, edata->state,
 		(edata->state == ENVSYS_SVALID) ? PENVSYS_EVENT_NORMAL :
 			sse[i].event));
 



CVS commit: src/sys/dev/sysmon

2010-12-07 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Dec  8 00:09:14 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c

Log Message:
When removing properties (as in envstat -S), clear the flags that track
whether the properties actually exist.

When setting new limit values, don't complain/ignore about duplicate
values if the associated flag bits (indicating that the limit is valid)
are not set.

These two fixes together should fix a problem reported in private Email
by njoly@ a couple months ago.  Issue replicated and solution tested
using my recent swsensor pseudo-device running inside qemu world!


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/sysmon/sysmon_envsys_events.c

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.107 src/sys/dev/sysmon/sysmon_envsys.c:1.108
--- src/sys/dev/sysmon/sysmon_envsys.c:1.107	Sun Apr 11 01:12:28 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Dec  8 00:09:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.107 2010/04/11 01:12:28 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.108 2010/12/08 00:09:14 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.107 2010/04/11 01:12:28 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.108 2010/12/08 00:09:14 pgoyette Exp $");
 
 #include 
 #include 
@@ -1143,8 +1143,10 @@
 lims = edata->limits;
 (*sme->sme_get_limits)(sme, edata, &lims,
 		   &edata->upropset);
-			}
-			if (edata->upropset) {
+			} else
+edata->upropset &= ~PROP_LIMITS;
+
+			if (edata->upropset & PROP_LIMITS) {
 DPRINTF(("%s: install limits for %s %s\n",
 	__func__, sme->sme_name, edata->desc));
 sme_update_limits(sme, edata);

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.94 src/sys/dev/sysmon/sysmon_envsys_events.c:1.95
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.94	Mon Dec  6 23:26:44 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Dec  8 00:09:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.94 2010/12/06 23:26:44 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.95 2010/12/08 00:09:14 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.94 2010/12/06 23:26:44 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.95 2010/12/08 00:09:14 pgoyette Exp $");
 
 #include 
 #include 
@@ -151,29 +151,28 @@
 		__func__, sme->sme_name, edata->desc, crittype));
 
 		see = osee;
-		if (props & (PROP_CRITMAX | PROP_BATTMAX)) {
+		if (props & edata->upropset & (PROP_CRITMAX | PROP_BATTMAX)) {
 			if (lims->sel_critmax == edata->limits.sel_critmax) {
-DPRINTF(("%s: type=%d (critmax exists)\n",
-__func__, crittype));
+DPRINTF(("%s: critmax exists\n", __func__));
 error = EEXIST;
 props &= ~(PROP_CRITMAX | PROP_BATTMAX);
 			}
 		}
-		if (props & (PROP_WARNMAX | PROP_BATTHIGH)) {
+		if (props & edata->upropset & (PROP_WARNMAX | PROP_BATTHIGH)) {
 			if (lims->sel_warnmax == edata->limits.sel_warnmax) {
 DPRINTF(("%s: warnmax exists\n", __func__));
 error = EEXIST;
 props &= ~(PROP_WARNMAX | PROP_BATTHIGH);
 			}
 		}
-		if (props & (PROP_WARNMIN | PROP_BATTWARN)) {
+		if (props & edata->upropset & (PROP_WARNMIN | PROP_BATTWARN)) {
 			if (lims->sel_warnmin == edata->limits.sel_warnmin) {
 DPRINTF(("%s: warnmin exists\n", __func__));
 error = EEXIST;
 props &= ~(PROP_WARNMIN | PROP_BATTWARN);
 			}
 		}
-		if (props & (PROP_CRITMIN | PROP_BATTCAP)) {
+		if (props & edata->upropset & (PROP_CRITMIN | PROP_BATTCAP)) {
 			if (lims->sel_critmin == edata->limits.sel_critmin) {
 DPRINTF(("%s: critmin exists\n", __func__));
 error = EEXIST;



CVS commit: src/sys/dev/sysmon

2010-12-11 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Dec 11 15:17:16 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Handle removal of limit properties correctly, even for sensors that
provide their own internal limit(s).


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/dev/sysmon/sysmon_envsys.c

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.108 src/sys/dev/sysmon/sysmon_envsys.c:1.109
--- src/sys/dev/sysmon/sysmon_envsys.c:1.108	Wed Dec  8 00:09:14 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Dec 11 15:17:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.108 2010/12/08 00:09:14 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.109 2010/12/11 15:17:15 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.108 2010/12/08 00:09:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.109 2010/12/11 15:17:15 pgoyette Exp $");
 
 #include 
 #include 
@@ -1054,7 +1054,9 @@
 	envsys_data_t *edata = NULL;
 	char tmp[ENVSYS_DESCLEN];
 	sysmon_envsys_lim_t lims;
-	int ptype;
+	const struct sme_description_table *sdt_units;
+	uint32_t props;
+	int ptype, i;
 
 	mutex_enter(&sme_global_mtx);
 	LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) {
@@ -1128,28 +1130,51 @@
 			 *
 			 * First, tell the driver that we need it to 
 			 * restore any h/w limits which may have been 
-			 * changed to stored, boot-time values.  Then
-			 * we need to retrieve those limits and update
-			 * the event data in the dictionary.
+			 * changed to stored, boot-time values.
 			 */
 			if (sme->sme_set_limits) {
 DPRINTF(("%s: reset limits for %s %s\n",
 	__func__, sme->sme_name, edata->desc));
 (*sme->sme_set_limits)(sme, edata, NULL, NULL);
 			}
+
+			/*
+			 * Next, we need to retrieve those initial limits.
+			 */
+			edata->upropset &= ~PROP_LIMITS;
 			if (sme->sme_get_limits) {
 DPRINTF(("%s: retrieve limits for %s %s\n",
 	__func__, sme->sme_name, edata->desc));
 lims = edata->limits;
 (*sme->sme_get_limits)(sme, edata, &lims,
-		   &edata->upropset);
-			} else
-edata->upropset &= ~PROP_LIMITS;
+		   &props);
+			}
 
-			if (edata->upropset & PROP_LIMITS) {
+			/*
+			 * Finally, remove any old limits event, then
+			 * install a new event (which will update the
+			 * dictionary)
+			 */
+			sme_event_unregister(sme, edata->desc,
+			PENVSYS_EVENT_LIMITS);
+
+			if (props & PROP_LIMITS) {
 DPRINTF(("%s: install limits for %s %s\n",
 	__func__, sme->sme_name, edata->desc));
-sme_update_limits(sme, edata);
+
+
+/*
+ * Find the correct units for this sensor.
+ */
+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;
+
+sme_event_register(sdict, edata, sme,
+&lims, props, PENVSYS_EVENT_LIMITS,
+sdt_units[i].crittype);
 			}
 		}
 



CVS commit: src/sys/dev/sysmon

2009-12-23 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Dec 23 18:31:00 UTC 2009

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Check for value exceeding crit-max limit before checking against warn-max
limit.  Otherwise we'll never notice if we exceed crit-max (assuming that
crit-max is at least as large as warn-max).


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.71 src/sys/dev/sysmon/sysmon_envsys_events.c:1.72
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.71	Fri Jul 10 15:27:33 2009
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Dec 23 18:31:00 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.71 2009/07/10 15:27:33 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.72 2009/12/23 18:31:00 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.71 2009/07/10 15:27:33 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.72 2009/12/23 18:31:00 pgoyette Exp $");
 
 #include 
 #include 
@@ -671,10 +671,10 @@
 			else if __EXCEED_LIM(PROP_WARNMIN | PROP_BATTWARN, 
 	sel_warnmin, <)
 edata->state = ENVSYS_SWARNUNDER;
-			else if __EXCEED_LIM(PROP_WARNMAX, sel_warnmax, >)
-edata->state = ENVSYS_SWARNOVER;
 			else if __EXCEED_LIM(PROP_CRITMAX, sel_critmax, >)
 edata->state = ENVSYS_SCRITOVER;
+			else if __EXCEED_LIM(PROP_WARNMAX, sel_warnmax, >)
+edata->state = ENVSYS_SWARNOVER;
 		}
 #undef	__EXCEED_LIM
 



CVS commit: src/sys/dev/sysmon

2010-12-15 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Dec 15 17:17:17 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
sysmon_envsys_tables.c sysmon_envsysvar.h

Log Message:
Extract searching of description tables into a single function, rather
than duplicating the code every time.  Minor reduction in code size
(about 1200 bytes on amd64), no change in functionality.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/sysmon/sysmon_envsys_tables.c
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/sysmon/sysmon_envsysvar.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.109 src/sys/dev/sysmon/sysmon_envsys.c:1.110
--- src/sys/dev/sysmon/sysmon_envsys.c:1.109	Sat Dec 11 15:17:15 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Dec 15 17:17:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.109 2010/12/11 15:17:15 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.110 2010/12/15 17:17:16 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.109 2010/12/11 15:17:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.110 2010/12/15 17:17:16 pgoyette Exp $");
 
 #include 
 #include 
@@ -520,21 +520,16 @@
 int
 sysmon_envsys_sensor_attach(struct sysmon_envsys *sme, envsys_data_t *edata)
 {
-	const struct sme_description_table *sdt_units;
+	const struct sme_descr_entry *sdt_units;
 	envsys_data_t *oedata;
-	int i;
 
 	KASSERT(sme != NULL || edata != NULL);
 
 	/* 
 	 * Find the correct units for this sensor.
 	 */
-	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(sdt_units[i].desc, "unknown") == 0)
+	sdt_units = sme_find_table_entry(SME_DESC_UNITS, edata->units);
+	if (sdt_units->type == -1)
 		return EINVAL;
 
 	/*
@@ -567,7 +562,7 @@
 
 	DPRINTF(("%s: attached #%d (%s), units=%d (%s)\n",
 	__func__, edata->sensor, edata->desc,
-	sdt_units[i].type, sdt_units[i].desc));
+	sdt_units->type, sdt_units->desc));
 
 	return 0;
 }
@@ -1054,9 +1049,9 @@
 	envsys_data_t *edata = NULL;
 	char tmp[ENVSYS_DESCLEN];
 	sysmon_envsys_lim_t lims;
-	const struct sme_description_table *sdt_units;
+	const struct sme_descr_entry *sdt_units;
 	uint32_t props;
-	int ptype, i;
+	int ptype;
 
 	mutex_enter(&sme_global_mtx);
 	LIST_FOREACH(sme, &sysmon_envsys_list, sme_list) {
@@ -1166,15 +1161,12 @@
 /*
  * Find the correct units for this sensor.
  */
-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;
+sdt_units = sme_find_table_entry(SME_DESC_UNITS,
+edata->units);
 
 sme_event_register(sdict, edata, sme,
 &lims, props, PENVSYS_EVENT_LIMITS,
-sdt_units[i].crittype);
+sdt_units->crittype);
 			}
 		}
 
@@ -1267,18 +1259,15 @@
 sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
 			  prop_dictionary_t dict, envsys_data_t *edata)
 {
-	const struct sme_description_table *sdt, *sdt_units;
+	const struct sme_descr_entry *sdt_state, *sdt_units, *sdt_battcap;
+	const struct sme_descr_entry *sdt_drive;
 	sme_event_drv_t *sme_evdrv_t = NULL;
-	int i, j;
 	char indexstr[ENVSYS_DESCLEN];
 
 	/* 
 	 * Find the correct units for this sensor.
 	 */
-	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;
+	sdt_units = sme_find_table_entry(SME_DESC_UNITS, edata->units);
 
 	/*
 	 * Add the index sensor string.
@@ -1300,7 +1289,7 @@
 	 * 		blah blah
 	 * 		...
 	 */
-	if (sme_sensor_upstring(dict, "type", sdt_units[i].desc))
+	if (sme_sensor_upstring(dict, "type", sdt_units->desc))
 		goto bad;
 
 	if (sme_sensor_upstring(dict, "description", edata->desc))
@@ -1314,15 +1303,12 @@
 	 * 		valid
 	 * 		...
 	 */
-	sdt = sme_get_description_table(SME_DESC_STATES);
-	for (j = 0; sdt[j].type != -1; j++)
-		if (sdt[j].type == edata->state) 
-			break;
+	sdt_state = sme_find_table_entry(SME_DESC_STATES, edata->state);
 
 	DPRINTF(("%s: sensor desc=%s type=%d state=%d\n",
 	__func__, edata->desc, edata->units, edata->state));
 
-	if (sme_sensor_upstring(dict, "state", sdt[j].desc))
+	if (sme_sensor_upstring(dict, "state", sdt_state->desc))
 		goto bad;
 
 	/*
@@ -1391,12 +1377,10 @@
 	 * 		...
 	 */
 	if (edata->units == ENVSYS_BATTERY_CAPACITY) {
-		sdt = sme_get_description_table(SME_DESC_BATTERY_CAPACITY);
-		for (j = 0; sdt[j].type !=

CVS commit: src/sys/dev/sysmon

2010-12-16 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Thu Dec 16 16:08:57 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Be sure to always initialize props variable to a sensible value.
Fix a problem with envstat -S call which was installing bogus/random
limits.

ok pgoyette.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/dev/sysmon/sysmon_envsys.c

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.110 src/sys/dev/sysmon/sysmon_envsys.c:1.111
--- src/sys/dev/sysmon/sysmon_envsys.c:1.110	Wed Dec 15 17:17:16 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Dec 16 16:08:57 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.110 2010/12/15 17:17:16 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.111 2010/12/16 16:08:57 njoly Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.110 2010/12/15 17:17:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.111 2010/12/16 16:08:57 njoly Exp $");
 
 #include 
 #include 
@@ -1136,6 +1136,7 @@
 			/*
 			 * Next, we need to retrieve those initial limits.
 			 */
+			props = 0;
 			edata->upropset &= ~PROP_LIMITS;
 			if (sme->sme_get_limits) {
 DPRINTF(("%s: retrieve limits for %s %s\n",



CVS commit: src/sys/dev/sysmon

2010-12-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Dec 17 13:37:38 UTC 2010

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
use aprint


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.6 src/sys/dev/sysmon/swsensor.c:1.7
--- src/sys/dev/sysmon/swsensor.c:1.6	Thu Dec 16 14:33:30 2010
+++ src/sys/dev/sysmon/swsensor.c	Fri Dec 17 13:37:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.6 2010/12/16 14:33:30 pgoyette Exp $ */
+/*	$NetBSD: swsensor.c,v 1.7 2010/12/17 13:37:37 pooka Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.6 2010/12/16 14:33:30 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.7 2010/12/17 13:37:37 pooka Exp $");
 
 #include 
 #include 
@@ -243,17 +243,17 @@
 	if (error == 0)
 		error = sysmon_envsys_register(swsensor_sme);
 	else {
-		printf("sysmon_envsys_sensor_attach failed: %d\n", error);
+		aprint_error("sysmon_envsys_sensor_attach failed: %d\n", error);
 		return error;
 	}
 
 	if (error == 0)
 		sysctl_swsensor_setup();
 	else
-		printf("sysmon_envsys_register failed: %d\n", error);
+		aprint_error("sysmon_envsys_register failed: %d\n", error);
 
 	if (error == 0)
-		printf("swsensor: initialized\n");
+		aprint_normal("swsensor: initialized\n");
 	return error;
 }
 



CVS commit: src/sys/dev/sysmon

2010-12-29 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Dec 30 04:00:00 UTC 2010

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
sysmon_envsysvar.h

Log Message:
When the user updates the sensor device's refresh timer, reset the
callout immediately rather than waiting for the previous timer to
expire.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/sysmon/sysmon_envsysvar.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.111 src/sys/dev/sysmon/sysmon_envsys.c:1.112
--- src/sys/dev/sysmon/sysmon_envsys.c:1.111	Thu Dec 16 16:08:57 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Dec 30 03:59:59 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.111 2010/12/16 16:08:57 njoly Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.112 2010/12/30 03:59:59 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.111 2010/12/16 16:08:57 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.112 2010/12/30 03:59:59 pgoyette Exp $");
 
 #include 
 #include 
@@ -1175,6 +1175,7 @@
 		 * Restore default timeout value.
 		 */
 		sme->sme_events_timeout = SME_EVENTS_DEFTIMEOUT;
+		sme_schedule_callout(sme);
 		sysmon_envsys_release(sme, false);
 	}
 	mutex_exit(&sme_global_mtx);
@@ -1214,8 +1215,10 @@
 	 * 	...
 	 *
 	 */
-	if (!sme->sme_events_timeout)
+	if (sme->sme_events_timeout == 0) {
 		sme->sme_events_timeout = SME_EVENTS_DEFTIMEOUT;
+		sme_schedule_callout(sme);
+	}
 
 	if (!prop_dictionary_set_uint64(pdict, "refresh-timeout",
 	sme->sme_events_timeout)) {
@@ -1805,7 +1808,10 @@
 error = EINVAL;
 			else {
 mutex_enter(&sme->sme_mtx);
-sme->sme_events_timeout = refresh_timo;
+if (sme->sme_events_timeout != refresh_timo) {
+	sme->sme_events_timeout = refresh_timo;
+	sme_schedule_callout(sme);
+}
 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.96 src/sys/dev/sysmon/sysmon_envsys_events.c:1.97
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.96	Wed Dec 15 17:17:17 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Dec 30 03:59:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.96 2010/12/15 17:17:17 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.96 2010/12/15 17:17:17 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $");
 
 #include 
 #include 
@@ -486,16 +486,10 @@
 sme_events_init(struct sysmon_envsys *sme)
 {
 	int error = 0;
-	uint64_t timo;
 
 	KASSERT(sme != NULL);
 	KASSERT(mutex_owned(&sme->sme_mtx));
 
-	if (sme->sme_events_timeout)
-		timo = sme->sme_events_timeout * hz;
-	else
-		timo = SME_EVTIMO;
-
 	error = workqueue_create(&sme->sme_wq, sme->sme_name,
 	sme_events_worker, sme, PRI_NONE, IPL_SOFTCLOCK, WQ_MPSAFE);
 	if (error)
@@ -504,8 +498,8 @@
 	mutex_init(&sme->sme_callout_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
 	callout_init(&sme->sme_callout, CALLOUT_MPSAFE);
 	callout_setfunc(&sme->sme_callout, sme_events_check, sme);
-	callout_schedule(&sme->sme_callout, timo);
 	sme->sme_flags |= SME_CALLOUT_INITIALIZED;
+	sme_schedule_callout(sme);
 	DPRINTF(("%s: events framework initialized for '%s'\n",
 	__func__, sme->sme_name));
 
@@ -513,6 +507,30 @@
 }
 
 /*
+ * sme_schedule_callout
+ *
+ *	(Re)-schedule the device's callout timer
+ */
+void
+sme_schedule_callout(struct sysmon_envsys *sme)
+{
+	uint64_t timo;
+
+	KASSERT(sme != NULL);
+
+	if ((sme->sme_flags & SME_CALLOUT_INITIALIZED) == 0)
+		return;
+
+	if (sme->sme_events_timeout)
+		timo = sme->sme_events_timeout * hz;
+	else
+		timo = SME_EVTIMO;
+
+	callout_stop(&sme->sme_callout);
+	callout_schedule(&sme->sme_callout, timo);
+}
+
+/*
  * sme_events_destroy:
  *
  * 	+ Destroys the event framework for this device: callout
@@ -630,7 +648,7 @@
 	else
 		timo = SME_EVTIMO;
 	if (!sysmon_low_power)
-		callout_schedule(&sme->sme_callout, timo);
+		sme_schedule_callout(sme);
 	mutex_exit(&sme->sme_callout_mtx);
 }
 

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.37 src/sys/dev/sysmon/sysmon_envsysvar.h:1.38
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.37	Wed Dec 15 17:17:17 2010
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Thu Dec 30 03:59:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.37 2010/12/15 17:17:17 pgoy

CVS commit: src/sys/dev/sysmon

2011-01-03 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Jan  4 01:51:06 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_wdog.c sysmonvar.h

Log Message:
add support for autostarting watchdogs (wdog was started by firmware
and can't be disabled).  Add critical pool hooks for kernel tickled
watchdogs.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/sysmon/sysmon_wdog.c
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/sysmon/sysmonvar.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_wdog.c
diff -u src/sys/dev/sysmon/sysmon_wdog.c:1.24 src/sys/dev/sysmon/sysmon_wdog.c:1.25
--- src/sys/dev/sysmon/sysmon_wdog.c:1.24	Sun Dec 16 21:07:45 2007
+++ src/sys/dev/sysmon/sysmon_wdog.c	Tue Jan  4 01:51:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_wdog.c,v 1.24 2007/12/16 21:07:45 dyoung Exp $	*/
+/*	$NetBSD: sysmon_wdog.c,v 1.25 2011/01/04 01:51:06 matt Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.24 2007/12/16 21:07:45 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.25 2011/01/04 01:51:06 matt Exp $");
 
 #include 
 #include 
@@ -64,11 +64,13 @@
 static struct sysmon_wdog *sysmon_armed_wdog;
 static callout_t sysmon_wdog_callout;
 static void *sysmon_wdog_sdhook;
+static void *sysmon_wdog_cphook;
 
 struct sysmon_wdog *sysmon_wdog_find(const char *);
 void	sysmon_wdog_release(struct sysmon_wdog *);
 int	sysmon_wdog_setmode(struct sysmon_wdog *, int, u_int);
 void	sysmon_wdog_ktickle(void *);
+void	sysmon_wdog_critpoll(void *);
 void	sysmon_wdog_shutdown(void *);
 void	sysmon_wdog_ref(struct sysmon_wdog *);
 
@@ -78,6 +80,13 @@
 	mutex_init(&sysmon_wdog_list_mtx, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(&sysmon_wdog_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
 	cv_init(&sysmon_wdog_cv, "wdogref");
+	sysmon_wdog_sdhook = shutdownhook_establish(sysmon_wdog_shutdown, NULL);
+	if (sysmon_wdog_sdhook == NULL)
+		printf("WARNING: unable to register watchdog shutdown hook\n");
+	sysmon_wdog_cphook = critpollhook_establish(sysmon_wdog_critpoll, NULL);
+	if (sysmon_wdog_cphook == NULL)
+		printf("WARNING: unable to register watchdog critpoll hook\n");
+	callout_init(&sysmon_wdog_callout, 0);
 }
 
 /*
@@ -89,17 +98,6 @@
 sysmonopen_wdog(dev_t dev, int flag, int mode, struct lwp *l)
 {
 
-	mutex_enter(&sysmon_wdog_list_mtx);
-	if (sysmon_wdog_sdhook == NULL) {
-		sysmon_wdog_sdhook =
-		shutdownhook_establish(sysmon_wdog_shutdown, NULL);
-		if (sysmon_wdog_sdhook == NULL)
-			printf("WARNING: unable to register watchdog "
-			"shutdown hook\n");
-		callout_init(&sysmon_wdog_callout, 0);
-	}
-	mutex_exit(&sysmon_wdog_list_mtx);
-
 	return 0;
 }
 
@@ -323,6 +321,27 @@
 }
 
 /*
+ * sysmon_wdog_critpoll:
+ *
+ *	Perform critical operations during long polling periods
+ */
+void
+sysmon_wdog_critpoll(void *arg)
+{
+	struct sysmon_wdog *smw = sysmon_armed_wdog;
+
+	if (smw == NULL)
+		return;
+
+	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_KTICKLE) {
+		if ((*smw->smw_tickle)(smw) != 0) {
+			printf("WARNING: KERNEL TICKLE OF WATCHDOG %s "
+			"FAILED!\n", smw->smw_name);
+		}
+	}
+}
+
+/*
  * sysmon_wdog_find:
  *
  *	Find a watchdog device.  We increase the reference

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.39 src/sys/dev/sysmon/sysmonvar.h:1.40
--- src/sys/dev/sysmon/sysmonvar.h:1.39	Sun Apr 11 01:12:28 2010
+++ src/sys/dev/sysmon/sysmonvar.h	Tue Jan  4 01:51:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.39 2010/04/11 01:12:28 pgoyette Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.40 2011/01/04 01:51:06 matt Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -239,6 +239,7 @@
 int	sysmonclose_wdog(dev_t, int, int, struct lwp *);
 int	sysmonioctl_wdog(dev_t, u_long, void *, int, struct lwp *);
 
+int sysmon_wdog_setmode(struct sysmon_wdog *, int, u_int);
 int sysmon_wdog_register(struct sysmon_wdog *);
 int sysmon_wdog_unregister(struct sysmon_wdog *);
 



CVS commit: src/sys/dev/sysmon

2012-11-29 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Nov 29 10:29:46 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Remove trailing white space(s) from name of random source.
And also, changind space(s) in the middle with '-'.
PR#47232.


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/dev/sysmon/sysmon_envsys.c

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.125 src/sys/dev/sysmon/sysmon_envsys.c:1.126
--- src/sys/dev/sysmon/sysmon_envsys.c:1.125	Thu Sep  6 12:21:40 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Nov 29 10:29:45 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.125 2012/09/06 12:21:40 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.126 2012/11/29 10:29:45 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.125 2012/09/06 12:21:40 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.126 2012/11/29 10:29:45 msaitoh Exp $");
 
 #include 
 #include 
@@ -778,8 +778,25 @@ out:
 		 */
 		TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
 			if (edata->flags & ENVSYS_FHAS_ENTROPY) {
+size_t n;
+int tail = 1;
+
 snprintf(rnd_name, sizeof(rnd_name), "%s-%s",
 sme->sme_name, edata->desc);
+n = strlen(rnd_name);
+/*
+ * 1) Remove trailing white space(s).
+ * 2) If space exist, replace it with '-'
+ */
+while (--n) {
+	if (rnd_name[n] == ' ') {
+		if (tail != 0)
+			rnd_name[n] = '\0';
+		else
+			rnd_name[n] = '-';
+	} else
+		tail = 0;
+}
 rnd_attach_source(&edata->rnd_src, rnd_name,
 RND_TYPE_ENV, 0);
 			}



CVS commit: src/sys/dev/sysmon

2012-12-11 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Dec 11 15:39:06 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c sysmonvar.h

Log Message:
Replace a couple of many-line #define with equivalent code loops.

No functional change intended, and atf tests (using swsensor(4)) still
pass 100%


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/sysmon/sysmonvar.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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.106 src/sys/dev/sysmon/sysmon_envsys_events.c:1.107
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.106	Wed Oct 31 05:42:47 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Tue Dec 11 15:39:06 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.106 2012/10/31 05:42:47 macallan Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.107 2012/12/11 15:39:06 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.106 2012/10/31 05:42:47 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.107 2012/12/11 15:39:06 pgoyette Exp $");
 
 #include 
 #include 
@@ -65,6 +65,37 @@ static const struct sme_sensor_event sme
 	{ -1, 	-1 }
 };
 
+struct op_t {
+	const char *name;
+	enum envsys_lims idx;
+	uint32_t prop;
+} limit_ops[] = {
+	/* Value-based limits */
+	{ "critical-max", ENVSYS_LIM_CRITMAX, PROP_CRITMAX },
+	{ "warning-max",  ENVSYS_LIM_WARNMAX, PROP_WARNMAX },
+	{ "warning-min",  ENVSYS_LIM_WARNMIN, PROP_WARNMIN },
+	{ "critical-min", ENVSYS_LIM_CRITMIN, PROP_CRITMIN },
+
+	/* %Capacity-based limits */
+	{ "maximum-capacity",  ENVSYS_LIM_CRITMAX,  PROP_BATTMAX },
+	{ "high-capacity", ENVSYS_LIM_WARNMAX,  PROP_BATTHIGH },
+	{ "warning-capacity",  ENVSYS_LIM_WARNMIN,  PROP_BATTWARN },
+	{ "critical-capacity", ENVSYS_LIM_CRITMIN,  PROP_BATTCAP },
+	{ NULL, 0, 0 }
+};
+
+struct ev_reg_t {
+	uint32_t crittype;
+	uint32_t powertype;
+	const char *name;
+} reg_events[] = {
+	{ ENVSYS_FMONCRITICAL,  PENVSYS_EVENT_CRITICAL,  "critical" },
+	{ ENVSYS_FMONSTCHANGED,	PENVSYS_EVENT_STATE_CHANGED, "state-changed" },
+	{ ENVSYS_FMONLIMITS,PENVSYS_EVENT_LIMITS,"hw-range-limits" },
+	{ ENVSYS_FHAS_ENTROPY,  PENVSYS_EVENT_NULL,  "refresh-event" },
+	{ 0, 0, NULL }
+};
+
 static bool sysmon_low_power;
 
 #define SME_EVTIMO	(SME_EVENTS_DEFTIMEOUT * hz)
@@ -91,6 +122,7 @@ sme_event_register(prop_dictionary_t sdi
 	prop_object_t obj;
 	int error = 0;
 	const char *objkey;
+	struct op_t *op;
 
 	KASSERT(sdict != NULL);
 	KASSERT(edata != NULL);
@@ -244,41 +276,30 @@ sme_event_register(prop_dictionary_t sdi
 	/*
 	 * Limit operation requested.
 	 */
-#define	LIMIT_OP(k, l, p)		\
-	if (props & p) {		\
-		objkey = k;		\
-		obj = prop_dictionary_get(sdict, objkey);		\
-		if (obj != NULL &&	\
-		prop_object_type(obj) != PROP_TYPE_NUMBER) {	\
-			DPRINTF(("%s: (%s) %s object no TYPE_NUMBER\n",	\
-			__func__, sme->sme_name, objkey));		\
-			error = ENOTSUP;\
-		} else {		\
-			edata->limits.l = lims->l;			\
-			error = sme_sensor_upint32(sdict, objkey,lims->l); \
-			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;	\
-		edata->upropset |= p;	\
+	for (op = limit_ops; op->name != NULL; op++) {
+		if (props & op->prop) {
+			objkey = op->name;
+			obj = prop_dictionary_get(sdict, objkey);
+			if (obj != NULL &&
+			prop_object_type(obj) != PROP_TYPE_NUMBER) {
+DPRINTF(("%s: (%s) %s object not TYPE_NUMBER\n",
+__func__, sme->sme_name, objkey));
+error = ENOTSUP;
+			} else {
+edata->limits.sel_limit_list[op->idx] =
+lims->sel_limit_list[op->idx];
+error = sme_sensor_upint32(sdict, objkey,
+	   lims->sel_limit_list[op->idx]);
+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;
+			edata->upropset |= op->prop;
+		}
 	}
 
-	/* Value-based limits */
-	LIMIT_OP("critical-max", sel_critmax, PROP_CRITMAX);
-	LIMIT_OP("warning-max",  sel_warnmax, PROP_WARNMAX);
-	LIMIT_OP("warning-min",  sel_warnmin, PROP_WARNMIN);
-	LIMIT_OP("critical-min", sel_critmin, PROP_CRITMIN);
-
-	/* %Capacity-based limits */
-	LIMIT_OP("maximum-capacity",  sel_critmax,  PROP_BATTMAX);
-	LIMIT_OP("high-capacity", sel_warnmax,  PROP_BATTHIGH);
-	LIMIT_OP("warning-capacity",  sel_warnmin,  PROP_BATTWARN);
-	LIMIT_OP("critical-capacity", sel_critmin,  PROP_BATTCAP);
-
-#undef LIMIT_OP
-
 	if (props & PROP_DR

CVS commit: src/sys/dev/sysmon

2012-12-13 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Dec 14 03:31:10 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsysvar.h

Log Message:
The sensor limit values were moved out of the event structure and into the
per-sensor structure a long time ago.  Garbage collect the old structure
member which is now unused.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/sysmon/sysmon_envsysvar.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_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.45 src/sys/dev/sysmon/sysmon_envsysvar.h:1.46
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.45	Thu Sep  6 12:59:00 2012
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Fri Dec 14 03:31:10 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.45 2012/09/06 12:59:00 macallan Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.46 2012/12/14 03:31:10 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -78,7 +78,6 @@ typedef struct sme_event {
 	struct sysmon_envsys	*see_sme;	/* device associated */
 	struct penvsys_state	see_pes;	/* our power envsys */
 	envsys_data_t		*see_edata;	/* our sensor data */
-	sysmon_envsys_lim_t	see_lims;	/* limit values */
 	int			see_type;	/* type of the event */
 	int			see_evstate;	/* state of prev event */
 	int			see_evvalue;	/* value of prev event */



CVS commit: src/sys/dev/sysmon

2012-12-14 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Dec 14 15:33:20 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Constify


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.107 src/sys/dev/sysmon/sysmon_envsys_events.c:1.108
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.107	Tue Dec 11 15:39:06 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Fri Dec 14 15:33:19 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.107 2012/12/11 15:39:06 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.108 2012/12/14 15:33:19 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.107 2012/12/11 15:39:06 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.108 2012/12/14 15:33:19 pgoyette Exp $");
 
 #include 
 #include 
@@ -65,7 +65,7 @@ static const struct sme_sensor_event sme
 	{ -1, 	-1 }
 };
 
-struct op_t {
+static const struct op_t {
 	const char *name;
 	enum envsys_lims idx;
 	uint32_t prop;
@@ -84,7 +84,7 @@ struct op_t {
 	{ NULL, 0, 0 }
 };
 
-struct ev_reg_t {
+static const struct ev_reg_t {
 	uint32_t crittype;
 	uint32_t powertype;
 	const char *name;
@@ -122,7 +122,7 @@ sme_event_register(prop_dictionary_t sdi
 	prop_object_t obj;
 	int error = 0;
 	const char *objkey;
-	struct op_t *op;
+	const struct op_t *op;
 
 	KASSERT(sdict != NULL);
 	KASSERT(edata != NULL);
@@ -495,7 +495,7 @@ sme_event_drvadd(void *arg)
 	sysmon_envsys_lim_t lims;
 	uint32_t props;
 	int error = 0;
-	struct ev_reg_t *reg;
+	const struct ev_reg_t *reg;
 
 	KASSERT(sed_t != NULL);
 



CVS commit: src/sys/dev/sysmon

2013-01-23 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Jan 23 18:04:34 UTC 2013

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Fix spelling, grammar, typos.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.108 src/sys/dev/sysmon/sysmon_envsys_events.c:1.109
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.108	Fri Dec 14 15:33:19 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Jan 23 18:04:33 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.108 2012/12/14 15:33:19 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.109 2013/01/23 18:04:33 mbalmer Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.108 2012/12/14 15:33:19 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.109 2013/01/23 18:04:33 mbalmer Exp $");
 
 #include 
 #include 
@@ -409,8 +409,8 @@ sme_event_unregister(struct sysmon_envsy
 	}
 
 	/*
-	 * Wait for the event to finish its work, remove from the list
-	 * and release resouces.
+	 * Wait for the event to finish its work, remove it from the list
+	 * and release resources.
 	 */
 	while (see->see_flags & SEE_EVENT_WORKING)
 		cv_wait(&sme->sme_condvar, &sme->sme_mtx);
@@ -447,8 +447,8 @@ sme_event_unregister_sensor(struct sysmo
 		return EINVAL;
 
 	/*
-	 * Wait for the event to finish its work, remove from the list
-	 * and release resouces.
+	 * Wait for the event to finish its work, remove it from the list
+	 * and release resources.
 	 */
 	while (see->see_flags & SEE_EVENT_WORKING)
 		cv_wait(&sme->sme_condvar, &sme->sme_mtx);



CVS commit: src/sys/dev/sysmon

2011-07-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Jul 22 14:21:40 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
Ensure events come off the list in the same order they went on.
Hotkey press/release events now happen in the correct order.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.44 src/sys/dev/sysmon/sysmon_power.c:1.45
--- src/sys/dev/sysmon/sysmon_power.c:1.44	Thu Mar 11 13:51:01 2010
+++ src/sys/dev/sysmon/sysmon_power.c	Fri Jul 22 14:21:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.44 2010/03/11 13:51:01 jruoho Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.45 2011/07/22 14:21:40 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.44 2010/03/11 13:51:01 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.45 2011/07/22 14:21:40 jakllsch Exp $");
 
 #include "opt_compat_netbsd.h"
 #include 
@@ -91,7 +91,7 @@
  * Singly linked list for dictionaries to be stored/sent.
  */
 struct power_event_dictionary {
-	SLIST_ENTRY(power_event_dictionary) pev_dict_head;
+	SIMPLEQ_ENTRY(power_event_dictionary) pev_dict_head;
 	prop_dictionary_t dict;
 	int flags;
 };
@@ -166,8 +166,8 @@
 static int sysmon_power_event_queue_tail;
 static int sysmon_power_event_queue_count;
 
-static SLIST_HEAD(, power_event_dictionary) pev_dict_list =
-SLIST_HEAD_INITIALIZER(&pev_dict_list);
+static SIMPLEQ_HEAD(, power_event_dictionary) pev_dict_list =
+SIMPLEQ_HEAD_INITIALIZER(pev_dict_list);
 
 static struct selinfo sysmon_power_event_queue_selinfo;
 static struct lwp *sysmon_power_daemon;
@@ -261,7 +261,7 @@
  * sysmon_power_daemon_task:
  *
  *	Assign required power event members and sends a signal
- *	to the process to notify that an event was enqueued succesfully.
+ *	to the process to notify that an event was enqueued successfully.
  */
 static int
 sysmon_power_daemon_task(struct power_event_dictionary *ped,
@@ -363,7 +363,7 @@
 		 * dictionary is ready to be fetched.
 		 */
 		ped->flags |= SYSMON_POWER_DICTIONARY_READY;
-		SLIST_INSERT_HEAD(&pev_dict_list, ped, pev_dict_head);
+		SIMPLEQ_INSERT_TAIL(&pev_dict_list, ped, pev_dict_head);
 		cv_broadcast(&sysmon_power_event_queue_cv);
 		mutex_exit(&sysmon_power_event_queue_mtx);
 		selnotify(&sysmon_power_event_queue_selinfo, 0, 0);
@@ -569,7 +569,7 @@
 		 * as busy.
 		 */
 		mutex_enter(&sysmon_power_event_queue_mtx);
-		ped = SLIST_FIRST(&pev_dict_list);
+		ped = SIMPLEQ_FIRST(&pev_dict_list);
 		if (!ped || !ped->dict) {
 			mutex_exit(&sysmon_power_event_queue_mtx);
 			error = ENOTSUP;
@@ -604,7 +604,7 @@
 		mutex_enter(&sysmon_power_event_queue_mtx);
 		ped->flags &= ~SYSMON_POWER_DICTIONARY_BUSY;
 		ped->flags &= ~SYSMON_POWER_DICTIONARY_READY;
-		SLIST_REMOVE_HEAD(&pev_dict_list, pev_dict_head);
+		SIMPLEQ_REMOVE_HEAD(&pev_dict_list, pev_dict_head);
 		mutex_exit(&sysmon_power_event_queue_mtx);
 		sysmon_power_destroy_dictionary(ped);
 
@@ -768,7 +768,7 @@
  * sysmon_penvsys_event:
  *
  * 	Puts an event onto the sysmon power queue and sends the
- * 	appropiate event if the daemon is running, otherwise a
+ * 	appropriate event if the daemon is running, otherwise a
  * 	message is shown.
  */
 void



CVS commit: src/sys/dev/sysmon

2012-02-17 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sat Feb 18 01:08:00 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsysvar.h

Log Message:
Don't export sysmon_envsys_list as a common.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/sysmon/sysmon_envsysvar.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.117 src/sys/dev/sysmon/sysmon_envsys.c:1.118
--- src/sys/dev/sysmon/sysmon_envsys.c:1.117	Mon Aug  1 12:28:53 2011
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Feb 18 01:08:00 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.117 2011/08/01 12:28:53 mbalmer Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.118 2012/02/18 01:08:00 matt Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.117 2011/08/01 12:28:53 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.118 2012/02/18 01:08:00 matt Exp $");
 
 #include 
 #include 
@@ -86,6 +86,8 @@ kmutex_t sme_global_mtx;
 
 prop_dictionary_t sme_propd;
 
+struct sysmon_envsys_lh sysmon_envsys_list;
+
 static uint32_t sysmon_envsys_next_sensor_index;
 static struct sysmon_envsys *sysmon_envsys_find_40(u_int);
 

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.40 src/sys/dev/sysmon/sysmon_envsysvar.h:1.41
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.40	Sun Jun 19 03:09:43 2011
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Sat Feb 18 01:08:00 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.40 2011/06/19 03:09:43 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.41 2012/02/18 01:08:00 matt Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -105,7 +105,8 @@ extern	prop_dictionary_t sme_propd;	/* t
 /* 
  * linked list for the sysmon envsys devices.
  */
-LIST_HEAD(, sysmon_envsys) sysmon_envsys_list;
+LIST_HEAD(sysmon_envsys_lh, sysmon_envsys);
+extern	struct sysmon_envsys_lh sysmon_envsys_list;
 
 /* 
  * functions to handle sysmon envsys devices.



CVS commit: src/sys/dev/sysmon

2012-07-15 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Jul 15 17:41:39 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c
sysmon_envsysvar.h

Log Message:
When unregistering a sensor device, make sure we unregister and delete
all the associated events.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/sysmon/sysmon_envsysvar.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.118 src/sys/dev/sysmon/sysmon_envsys.c:1.119
--- src/sys/dev/sysmon/sysmon_envsys.c:1.118	Sat Feb 18 01:08:00 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Jul 15 17:41:39 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.118 2012/02/18 01:08:00 matt Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.119 2012/07/15 17:41:39 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.118 2012/02/18 01:08:00 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.119 2012/07/15 17:41:39 pgoyette Exp $");
 
 #include 
 #include 
@@ -604,6 +604,7 @@ sysmon_envsys_sensor_detach(struct sysmo
 	/*
 	 * remove it and decrement the sensors count.
 	 */
+	sme_event_unregister_sensor(sme, edata);
 	TAILQ_REMOVE(&sme->sme_sensors_list, edata, sensors_head);
 	sme->sme_nsensors--;
 	sysmon_envsys_release(sme, true);

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.98 src/sys/dev/sysmon/sysmon_envsys_events.c:1.99
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.98	Wed Jun  8 16:14:57 2011
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sun Jul 15 17:41:39 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.99 2012/07/15 17:41:39 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.99 2012/07/15 17:41:39 pgoyette Exp $");
 
 #include 
 #include 
@@ -77,6 +77,8 @@ static bool sme_battery_check(void);
 static bool sme_battery_critical(envsys_data_t *);
 static bool sme_acadapter_check(void);
 
+static void sme_remove_event(sme_event_t *, struct sysmon_envsys *);
+
 /*
  * sme_event_register:
  *
@@ -334,11 +336,11 @@ sme_event_unregister_all(struct sysmon_e
 			break;
 
 		if (strcmp(see->see_pes.pes_dvname, sme->sme_name) == 0) {
-			LIST_REMOVE(see, see_list);
 			DPRINTF(("%s: event %s %d removed (%s)\n", __func__,
 			see->see_pes.pes_sensname, see->see_type,
 			sme->sme_name));
-			kmem_free(see, sizeof(*see));
+			sme_remove_event(see, sme);
+
 			evcounter--;
 		}
 	}
@@ -386,6 +388,58 @@ sme_event_unregister(struct sysmon_envsy
 
 	DPRINTF(("%s: removed dev=%s sensor=%s type=%d\n",
 	__func__, see->see_pes.pes_dvname, sensor, type));
+
+	sme_remove_event(see, sme);
+
+	mutex_exit(&sme->sme_mtx);
+	return 0;
+}
+
+/*
+ * sme_event_unregister_sensor:
+ *
+ *	+ Unregisters any event associated with a specific sensor
+ *	  The caller must already own the sme_mtx.
+ */
+int
+sme_event_unregister_sensor(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
+	sme_event_t *see;
+	bool found = false;
+
+	KASSERT(mutex_owned(&sme->sme_mtx));
+	LIST_FOREACH(see, &sme->sme_events_list, see_list) {
+		if (see->see_edata == edata) {
+			found = true;
+			break;
+		}
+	}
+	if (!found)
+		return EINVAL;
+
+	/*
+	 * Wait for the event to finish its work, remove from the list
+	 * and release resouces.
+	 */
+	while (see->see_flags & SEE_EVENT_WORKING)
+		cv_wait(&sme->sme_condvar, &sme->sme_mtx);
+
+	DPRINTF(("%s: removed dev=%s sensor=%s\n",
+	__func__, see->see_pes.pes_dvname, edata->desc));
+
+	sme_remove_event(see, sme);
+
+	return 0;
+}
+
+static void
+sme_remove_event(sme_event_t *see, struct sysmon_envsys *sme)
+{
+
+	KASSERT(mutex_owned(&sme->sme_mtx));
+
+	if (see->see_edata->flags & ENVSYS_FHAS_ENTROPY)
+		rnd_detach_source(&see->see_edata->rnd_src);
 	LIST_REMOVE(see, see_list);
 	/*
 	 * So the events list is empty, we'll do the following:
@@ -395,10 +449,8 @@ sme_event_unregister(struct sysmon_envsy
 	 */
 	if (LIST_EMPTY(&sme->sme_events_list))
 		sme_events_destroy(sme);
-	mutex_exit(&sme->sme_mtx);
 
 	kmem_free(see, sizeof(*see));
-	return 0;
 }
 
 /*

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.41 src/sys/dev/sysmon/sysmon_envsysvar.h:1.42
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.41	Sat Feb 18 01:08:00 2012
+++ src/sys/dev/sysmon/sysmon_envsysva

CVS commit: src/sys/dev/sysmon

2012-07-15 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Jul 15 18:33:07 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c sysmonvar.h

Log Message:
If a sensor is flagged as capable of providing rnd(4) with entropy,
hook the sensor into rnd subsystem, and make sure we periodically
refresh the sensor whether or not it is being actively monitored.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/sysmon/sysmonvar.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.119 src/sys/dev/sysmon/sysmon_envsys.c:1.120
--- src/sys/dev/sysmon/sysmon_envsys.c:1.119	Sun Jul 15 17:41:39 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Jul 15 18:33:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.119 2012/07/15 17:41:39 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.120 2012/07/15 18:33:07 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.119 2012/07/15 17:41:39 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.120 2012/07/15 18:33:07 pgoyette Exp $");
 
 #include 
 #include 
@@ -76,6 +76,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsy
 #include 
 #include 
 #include 
+#include 
 
 /* #define ENVSYS_DEBUG */
 #include 
@@ -360,7 +361,7 @@ sysmonioctl_envsys(dev_t dev, u_long cmd
 			if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0 &&
 			(sme->sme_flags & SME_POLL_ONLY) == 0) {
 mutex_enter(&sme->sme_mtx);
-(*sme->sme_refresh)(sme, edata);
+sysmon_envsys_refresh_sensor(sme, edata);
 mutex_exit(&sme->sme_mtx);
 			}
 
@@ -602,7 +603,7 @@ sysmon_envsys_sensor_detach(struct sysmo
 	}
 
 	/*
-	 * remove it and decrement the sensors count.
+	 * remove it, unhook from rnd(4), and decrement the sensors count.
 	 */
 	sme_event_unregister_sensor(sme, edata);
 	TAILQ_REMOVE(&sme->sme_sensors_list, edata, sensors_head);
@@ -636,6 +637,7 @@ sysmon_envsys_register(struct sysmon_env
 	sme_event_drv_t *this_evdrv;
 	int nevent;
 	int error = 0;
+	char rnd_name[sizeof(edata->rnd_src.name)];
 
 	KASSERT(sme != NULL);
 	KASSERT(sme->sme_name != NULL);
@@ -773,6 +775,17 @@ out:
 			sme_event_drvadd, evdv->evdrv);
 			nevent++;
 		}
+		/*
+		 * Hook the sensor into rnd(4) entropy pool if requested
+		 */
+		TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
+			if (edata->flags & ENVSYS_FHAS_ENTROPY) {
+snprintf(rnd_name, sizeof(rnd_name), "%s-%s",
+sme->sme_name, edata->desc);
+rnd_attach_source(&edata->rnd_src, rnd_name,
+RND_TYPE_ENV, 0);
+			}
+		}
 		DPRINTF(("%s: driver '%s' registered (nsens=%d nevent=%d)\n",
 		__func__, sme->sme_name, sme->sme_nsensors, nevent));
 	}
@@ -1003,7 +1016,7 @@ sme_initial_refresh(void *arg)
 	sysmon_envsys_acquire(sme, true);
 	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head)
 		if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0)
-			(*sme->sme_refresh)(sme, edata);
+			sysmon_envsys_refresh_sensor(sme, edata);
 	sysmon_envsys_release(sme, true);
 	mutex_exit(&sme->sme_mtx);
 }
@@ -1356,9 +1369,10 @@ sme_add_sensor_dictionary(struct sysmon_
 	}
 
 	/*
-	 * Register new event(s) if any monitoring flag was set.
+	 * Register new event(s) if any monitoring flag was set or if
+	 * the sensor provides entropy for rnd(4).
 	 */
-	if (edata->flags & ENVSYS_FMONANY) {
+	if (edata->flags & (ENVSYS_FMONANY | ENVSYS_FHAS_ENTROPY)) {
 		sme_evdrv_t = kmem_zalloc(sizeof(*sme_evdrv_t), KM_SLEEP);
 		sme_evdrv_t->sed_sdict = dict;
 		sme_evdrv_t->sed_edata = edata;
@@ -1427,7 +1441,7 @@ sme_get_max_value(struct sysmon_envsys *
 		 */
 		if (refresh && (sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
 			mutex_enter(&sme->sme_mtx);
-			(*sme->sme_refresh)(sme, edata);
+			sysmon_envsys_refresh_sensor(sme, edata);
 			mutex_exit(&sme->sme_mtx);
 		}
 
@@ -1504,7 +1518,7 @@ sme_update_dictionary(struct sysmon_envs
 		 */
 		if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
 			mutex_enter(&sme->sme_mtx);
-			(*sme->sme_refresh)(sme, edata);
+			sysmon_envsys_refresh_sensor(sme, edata);
 			mutex_exit(&sme->sme_mtx);
 		}
 
@@ -1937,7 +1951,7 @@ sysmon_envsys_foreach_sensor(sysmon_envs
 			if (refresh &&
 			(sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
 mutex_enter(&sme->sme_mtx);
-(*sme->sme_refresh)(sme, sensor);
+sysmon_envsys_refresh_sensor(sme, sensor);
 mutex_exit(&sme->sme_mtx);
 			}
 			if (!(*func)(sme, sensor, arg))
@@ -1947,3 +1961,25 @@ sysmon_envsys_foreach_sensor(sysmon_envs
 	}
 	mutex_exit(&sme_global_mtx);
 }
+
+/*
+ * Call the sensor's refresh function, and collect/stir entropy
+ */
+void
+sysmon_envsys_refresh_

CVS commit: src/sys/dev/sysmon

2012-07-16 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Jul 16 13:55:01 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c sysmonvar.h

Log Message:
Extend previous changes so that even sensors which don't use a refresh()
callback to update the value can be polled to provide rnd(4) entropy.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.100 -r1.101 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/sysmon/sysmonvar.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.120 src/sys/dev/sysmon/sysmon_envsys.c:1.121
--- src/sys/dev/sysmon/sysmon_envsys.c:1.120	Sun Jul 15 18:33:07 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Mon Jul 16 13:55:01 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.120 2012/07/15 18:33:07 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.121 2012/07/16 13:55:01 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.120 2012/07/15 18:33:07 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.121 2012/07/16 13:55:01 pgoyette Exp $");
 
 #include 
 #include 
@@ -358,8 +358,7 @@ sysmonioctl_envsys(dev_t dev, u_long cmd
 		}
 
 		if (tred->sensor < sme->sme_nsensors) {
-			if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0 &&
-			(sme->sme_flags & SME_POLL_ONLY) == 0) {
+			if ((sme->sme_flags & SME_POLL_ONLY) == 0) {
 mutex_enter(&sme->sme_mtx);
 sysmon_envsys_refresh_sensor(sme, edata);
 mutex_exit(&sme->sme_mtx);
@@ -1015,8 +1014,7 @@ sme_initial_refresh(void *arg)
 	mutex_enter(&sme->sme_mtx);
 	sysmon_envsys_acquire(sme, true);
 	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head)
-		if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0)
-			sysmon_envsys_refresh_sensor(sme, edata);
+		sysmon_envsys_refresh_sensor(sme, edata);
 	sysmon_envsys_release(sme, true);
 	mutex_exit(&sme->sme_mtx);
 }
@@ -1436,14 +1434,11 @@ sme_get_max_value(struct sysmon_envsys *
 			continue;
 
 		/* 
-		 * refresh sensor data via sme_refresh only if the
-		 * flag is not set.
+		 * refresh sensor data
 		 */
-		if (refresh && (sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
-			mutex_enter(&sme->sme_mtx);
-			sysmon_envsys_refresh_sensor(sme, edata);
-			mutex_exit(&sme->sme_mtx);
-		}
+		mutex_enter(&sme->sme_mtx);
+		sysmon_envsys_refresh_sensor(sme, edata);
+		mutex_exit(&sme->sme_mtx);
 
 		v = edata->value_cur;
 		if (v > maxv)
@@ -1513,14 +1508,11 @@ sme_update_dictionary(struct sysmon_envs
 	 */
 	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
 		/* 
-		 * refresh sensor data via sme_refresh only if the
-		 * flag is not set.
+		 * refresh sensor data via sme_envsys_refresh_sensor
 		 */
-		if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
-			mutex_enter(&sme->sme_mtx);
-			sysmon_envsys_refresh_sensor(sme, edata);
-			mutex_exit(&sme->sme_mtx);
-		}
+		mutex_enter(&sme->sme_mtx);
+		sysmon_envsys_refresh_sensor(sme, edata);
+		mutex_exit(&sme->sme_mtx);
 
 		/* 
 		 * retrieve sensor's dictionary.
@@ -1896,11 +1888,11 @@ sme_userset_dictionary(struct sysmon_env
 			props |= PROP_WARNMIN;
 		}
 
-		if (props) {
-			if (edata->flags & ENVSYS_FMONNOTSUPP) {
-error = ENOTSUP;
-goto out;
-			}
+		if (props && (edata->flags & ENVSYS_FMONNOTSUPP) != 0) {
+			error = ENOTSUP;
+			goto out;
+		}
+		if (props || (edata->flags & ENVSYS_FHAS_ENTROPY) != 0) {
 			error = sme_event_register(dict, edata, sme, &lims,
 	props,
 	(edata->flags & ENVSYS_FPERCENT)?
@@ -1948,8 +1940,7 @@ sysmon_envsys_foreach_sensor(sysmon_envs
 
 		sysmon_envsys_acquire(sme, false);
 		TAILQ_FOREACH(sensor, &sme->sme_sensors_list, sensors_head) {
-			if (refresh &&
-			(sme->sme_flags & SME_DISABLE_REFRESH) == 0) {
+			if (refresh) {
 mutex_enter(&sme->sme_mtx);
 sysmon_envsys_refresh_sensor(sme, sensor);
 mutex_exit(&sme->sme_mtx);
@@ -1968,18 +1959,13 @@ sysmon_envsys_foreach_sensor(sysmon_envs
 void
 sysmon_envsys_refresh_sensor(struct sysmon_envsys *sme, envsys_data_t *edata)
 {
-	int32_t	old_state;
-	int32_t	old_value;
 
-	if (edata->flags & ENVSYS_FHAS_ENTROPY) {
-		old_state = edata->state;
-		old_value = edata->value_cur;
-		(*sme->sme_refresh)(sme, edata);
-		if (old_state != ENVSYS_SINVALID &&
-		edata->state != ENVSYS_SINVALID &&
-		old_value != edata->value_cur)
-			rnd_add_uint32(&edata->rnd_src, edata->value_cur);
-	}
-	else
+	if ((sme->sme_flags & SME_DISABLE_REFRESH) == 0)
 		(*sme->sme_refresh)(sme, edata);
+
+	if (edata->flags & ENVSYS_FHAS_ENTROPY &&
+	edata->state != ENVSYS_SINVALID &&
+	edata->value_prev != edata->value_cur)
+		rnd_add_uint32(&edata->rnd_src, edata->value_cur);
+	edata->value_prev = edat

CVS commit: src/sys/dev/sysmon

2012-07-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jul 18 20:50:40 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Release the mutex before taking a quick exit.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.101 src/sys/dev/sysmon/sysmon_envsys_events.c:1.102
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.101	Mon Jul 16 13:55:01 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Jul 18 20:50:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.101 2012/07/16 13:55:01 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.102 2012/07/18 20:50:40 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.101 2012/07/16 13:55:01 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.102 2012/07/18 20:50:40 pgoyette Exp $");
 
 #include 
 #include 
@@ -186,8 +186,10 @@ sme_event_register(prop_dictionary_t sdi
 		}
 		break;
 	}
-	if (crittype == PENVSYS_EVENT_NULL && see != NULL)
+	if (crittype == PENVSYS_EVENT_NULL && see != NULL) {
+		mutex_exit(&sme->sme_mtx);
 		return EEXIST;
+	}
 
 	if (see == NULL) {
 		/*



CVS commit: src/sys/dev/sysmon

2012-07-19 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Jul 19 13:30:01 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
If previously there was only a dummy event entry (to force refresh for
entropy gathering), allow it to be updated for the current request to
add a real entry.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.102 src/sys/dev/sysmon/sysmon_envsys_events.c:1.103
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.102	Wed Jul 18 20:50:40 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Jul 19 13:30:01 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.102 2012/07/18 20:50:40 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.103 2012/07/19 13:30:01 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.102 2012/07/18 20:50:40 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.103 2012/07/19 13:30:01 pgoyette Exp $");
 
 #include 
 #include 
@@ -143,7 +143,8 @@ sme_event_register(prop_dictionary_t sdi
 	LIST_FOREACH(osee, &sme->sme_events_list, see_list) {
 		if (strcmp(edata->desc, osee->see_pes.pes_sensname) != 0)
 			continue;
-		if (crittype != osee->see_type)
+		if (crittype != osee->see_type &&
+		osee->see_type != PENVSYS_EVENT_NULL)
 			continue;
 
 		/*
@@ -184,6 +185,9 @@ sme_event_register(prop_dictionary_t sdi
 props &= ~(PROP_CRITMIN | PROP_BATTCAP);
 			}
 		}
+		if (props && see->see_type == PENVSYS_EVENT_NULL)
+			see->see_type = crittype;
+
 		break;
 	}
 	if (crittype == PENVSYS_EVENT_NULL && see != NULL) {



CVS commit: src/sys/dev/sysmon

2012-07-19 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Jul 19 13:31:06 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Make sure to re-add the sensor as an entropy source after user request
to reset (via envstat -S)


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/dev/sysmon/sysmon_envsys.c

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.121 src/sys/dev/sysmon/sysmon_envsys.c:1.122
--- src/sys/dev/sysmon/sysmon_envsys.c:1.121	Mon Jul 16 13:55:01 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Jul 19 13:31:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.121 2012/07/16 13:55:01 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.122 2012/07/19 13:31:06 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.121 2012/07/16 13:55:01 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.122 2012/07/19 13:31:06 pgoyette Exp $");
 
 #include 
 #include 
@@ -1062,6 +1062,7 @@ sme_remove_userprops(void)
 	prop_dictionary_t sdict;
 	envsys_data_t *edata = NULL;
 	char tmp[ENVSYS_DESCLEN];
+	char rnd_name[sizeof(edata->rnd_src.name)];
 	sysmon_envsys_lim_t lims;
 	const struct sme_descr_entry *sdt_units;
 	uint32_t props;
@@ -1168,21 +1169,29 @@ sme_remove_userprops(void)
 			sme_event_unregister(sme, edata->desc,
 			PENVSYS_EVENT_LIMITS);
 
+			/*
+			 * Find the correct units for this sensor.
+			 */
+			sdt_units = sme_find_table_entry(SME_DESC_UNITS,
+			edata->units);
+
 			if (props & PROP_LIMITS) {
 DPRINTF(("%s: install limits for %s %s\n",
 	__func__, sme->sme_name, edata->desc));
 
-
-/*
- * Find the correct units for this sensor.
- */
-sdt_units = sme_find_table_entry(SME_DESC_UNITS,
-edata->units);
-
 sme_event_register(sdict, edata, sme,
 &lims, props, PENVSYS_EVENT_LIMITS,
 sdt_units->crittype);
 			}
+			if (edata->flags & ENVSYS_FHAS_ENTROPY) {
+sme_event_register(sdict, edata, sme,
+&lims, props, PENVSYS_EVENT_NULL,
+sdt_units->crittype);
+snprintf(rnd_name, sizeof(rnd_name), "%s-%s",
+sme->sme_name, edata->desc);
+rnd_attach_source(&edata->rnd_src, rnd_name,
+RND_TYPE_ENV, 0);
+			}
 		}
 
 		/*



CVS commit: src/sys/dev/sysmon

2011-06-03 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jun  4 02:02:55 UTC 2011

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Enable creation of value_{max,min,avg} entries via the proplist, as well
as setting the ENVSYS_FPERCENT flag


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.7 src/sys/dev/sysmon/swsensor.c:1.8
--- src/sys/dev/sysmon/swsensor.c:1.7	Fri Dec 17 13:37:37 2010
+++ src/sys/dev/sysmon/swsensor.c	Sat Jun  4 02:02:55 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.7 2010/12/17 13:37:37 pooka Exp $ */
+/*	$NetBSD: swsensor.c,v 1.8 2011/06/04 02:02:55 pgoyette Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.7 2010/12/17 13:37:37 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.8 2011/06/04 02:02:55 pgoyette Exp $");
 
 #include 
 #include 
@@ -234,6 +234,40 @@
 	if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER)
 		sw_sensor_value = prop_number_integer_value(po);
 
+	/* Retrieve any value_{max,min,avg} that might be present */
+	if (pd != NULL) {
+		po = prop_dictionary_get(pd, "value_max");
+		if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER) {
+			swsensor_edata.value_max =
+			prop_number_integer_value(po);
+			swsensor_edata.flags |= ENVSYS_FVALID_MAX;
+		}
+
+		po = prop_dictionary_get(pd, "value_min");
+		if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER) {
+			swsensor_edata.value_min =
+			prop_number_integer_value(po);
+			swsensor_edata.flags |= ENVSYS_FVALID_MIN;
+		}
+
+		po = prop_dictionary_get(pd, "value_avg");
+		if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER) {
+			swsensor_edata.value_avg =
+			prop_number_integer_value(po);
+			swsensor_edata.flags |= ENVSYS_FVALID_AVG;
+		}
+	}
+
+	/* See if this sensor should report percentages vs raw values */
+	if (pd != NULL) {
+		po = prop_dictionary_get(pd, "percentage");
+		if (po != NULL &&
+		prop_object_type(po) == PROP_TYPE_BOOL &&
+		prop_bool_true(po))
+			swsensor_edata.flags |= ENVSYS_FPERCENT;
+	}
+
+	swsensor_edata.state = ENVSYS_SVALID;
 	swsensor_edata.value_cur = 0;
 
 	strlcpy(swsensor_edata.desc, "sensor", ENVSYS_DESCLEN);



CVS commit: src/sys/dev/sysmon

2011-06-04 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jun  4 13:24:33 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmonvar.h

Log Message:
Since nothing actually records or maintains an average sensor value,
remove value_avg from the prop_dict.  We can't completely remove it
because there's one driver that uses this field for its own private
purposes, so for now we just rename the member.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/sysmon/sysmonvar.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.112 src/sys/dev/sysmon/sysmon_envsys.c:1.113
--- src/sys/dev/sysmon/sysmon_envsys.c:1.112	Thu Dec 30 03:59:59 2010
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Jun  4 13:24:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.112 2010/12/30 03:59:59 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.113 2011/06/04 13:24:33 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.112 2010/12/30 03:59:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.113 2011/06/04 13:24:33 pgoyette Exp $");
 
 #include 
 #include 
@@ -372,8 +372,8 @@
 			tred->max.data_s = edata->value_max;
 			tred->min.data_us = edata->value_min;
 			tred->min.data_s = edata->value_min;
-			tred->avg.data_us = edata->value_avg;
-			tred->avg.data_s = edata->value_avg;
+			tred->avg.data_us = 0;
+			tred->avg.data_s = 0;
 			if (edata->units == ENVSYS_BATTERY_CHARGE)
 tred->units = ENVSYS_INDICATOR;
 			else
@@ -1421,8 +1421,6 @@
 	 	 * 	800
 	 	 * 	max-value
 	 	 * 	3000
-	 	 * 	avg-value
-	 	 * 	1400
 	 	 * 	...
 	 	 */
 		if (edata->units == ENVSYS_SFANRPM)
@@ -1450,13 +1448,6 @@
 	   edata->value_max))
 			goto out;
 		}
-
-		if (edata->flags & ENVSYS_FVALID_AVG) {
-			if (sme_sensor_upint32(dict,
-	   "avg-value",
-	   edata->value_avg))
-			goto out;
-		}
 	}
 
 	/*
@@ -1689,7 +1680,7 @@
 		}
 
 		/*
-		 * update sensor's {avg,max,min}-value.
+		 * update sensor's {max,min}-value.
 		 */
 		if (edata->flags & ENVSYS_FVALID_MAX) {
 			error = sme_sensor_upint32(dict,
@@ -1707,14 +1698,6 @@
 break;
 		}
 
-		if (edata->flags & ENVSYS_FVALID_AVG) {
-			error = sme_sensor_upint32(dict,
-		   "avg-value",
-		   edata->value_avg);
-			if (error)
-break;
-		}
-
 		/* 
 		 * update 'rpms' only for ENVSYS_SFANRPM sensors.
 		 */

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.40 src/sys/dev/sysmon/sysmonvar.h:1.41
--- src/sys/dev/sysmon/sysmonvar.h:1.40	Tue Jan  4 01:51:06 2011
+++ src/sys/dev/sysmon/sysmonvar.h	Sat Jun  4 13:24:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.40 2011/01/04 01:51:06 matt Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.41 2011/06/04 13:24:33 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -83,7 +83,7 @@
 	int32_t		value_cur;	/* current value */
 	int32_t		value_max;	/* max value */
 	int32_t		value_min;	/* min value */
-	int32_t		value_avg;	/* avg value */
+	int32_t		private;	/* private data for drivers */
 	sysmon_envsys_lim_t limits;	/* thresholds for monitoring */
 	int		upropset;	/* userland property set? */
 	char		desc[ENVSYS_DESCLEN];	/* sensor description */
@@ -95,7 +95,7 @@
 #define ENVSYS_FPERCENT 	0x0001	/* sensor wants a percentage */
 #define ENVSYS_FVALID_MAX	0x0002	/* max value is ok */
 #define ENVSYS_FVALID_MIN	0x0004	/* min value is ok */
-#define ENVSYS_FVALID_AVG	0x0008	/* avg value is ok */
+#define ENVSYS_F_OBSOLETE	0x0008
 #define ENVSYS_FCHANGERFACT	0x0010	/* sensor can change rfact */
 
 /* monitoring flags */



CVS commit: src/sys/dev/sysmon

2011-06-04 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jun  4 13:26:52 UTC 2011

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Remove ability to the value_avg since it no longer exists


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.8 src/sys/dev/sysmon/swsensor.c:1.9
--- src/sys/dev/sysmon/swsensor.c:1.8	Sat Jun  4 02:02:55 2011
+++ src/sys/dev/sysmon/swsensor.c	Sat Jun  4 13:26:51 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.8 2011/06/04 02:02:55 pgoyette Exp $ */
+/*	$NetBSD: swsensor.c,v 1.9 2011/06/04 13:26:51 pgoyette Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.8 2011/06/04 02:02:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.9 2011/06/04 13:26:51 pgoyette Exp $");
 
 #include 
 #include 
@@ -234,7 +234,7 @@
 	if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER)
 		sw_sensor_value = prop_number_integer_value(po);
 
-	/* Retrieve any value_{max,min,avg} that might be present */
+	/* Retrieve any value_{max,min} that might be present */
 	if (pd != NULL) {
 		po = prop_dictionary_get(pd, "value_max");
 		if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER) {
@@ -249,13 +249,6 @@
 			prop_number_integer_value(po);
 			swsensor_edata.flags |= ENVSYS_FVALID_MIN;
 		}
-
-		po = prop_dictionary_get(pd, "value_avg");
-		if (po != NULL && prop_object_type(po) == PROP_TYPE_NUMBER) {
-			swsensor_edata.value_avg =
-			prop_number_integer_value(po);
-			swsensor_edata.flags |= ENVSYS_FVALID_AVG;
-		}
 	}
 
 	/* See if this sensor should report percentages vs raw values */



CVS commit: src/sys/dev/sysmon

2011-06-08 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jun  8 16:14:57 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
Restrict limit monitoring for Indicator sensors as well as for
Battery-charge sensors.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.97 src/sys/dev/sysmon/sysmon_envsys_events.c:1.98
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.97	Thu Dec 30 03:59:59 2010
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Jun  8 16:14:57 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.97 2010/12/30 03:59:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.98 2011/06/08 16:14:57 pgoyette Exp $");
 
 #include 
 #include 
@@ -101,7 +101,8 @@
 	/*
 	 * Some validation first for limit-checking events
 	 *
-	 * 1. Limits are not permitted if the units is ENVSYS_INDICATOR.
+	 * 1. Limits are not permitted if the units is ENVSYS_INDICATOR
+	 *or ENVSYS_BATTERY_CHARGE.
 	 *
 	 * 2. Capacity limits are permitted only if the sensor has the
 	 *ENVSYS_FPERCENT flag set and value_max is set.
@@ -117,8 +118,10 @@
 		" edata-flags 0x%04x\n", __func__, edata->units, props,
 		edata->upropset, edata->value_max, edata->flags));
 
-	if (props && edata->units == ENVSYS_INDICATOR)
-		return ENOTSUP;
+	if (props)
+		if (edata->units == ENVSYS_INDICATOR ||
+		edata->units == ENVSYS_BATTERY_CHARGE)
+			return ENOTSUP;
 
 	if ((props & PROP_CAP_LIMITS) &&
 	((edata->value_max == 0) ||



CVS commit: src/sys/dev/sysmon

2011-06-08 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jun  8 18:22:24 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsysvar.h

Log Message:
Factor out some duplicated code to simplify maintenance.  Reduces
the source file by ~100 lines, and amd64 object file shrinks by
~650 bytes.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/sysmon/sysmon_envsysvar.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.113 src/sys/dev/sysmon/sysmon_envsys.c:1.114
--- src/sys/dev/sysmon/sysmon_envsys.c:1.113	Sat Jun  4 13:24:33 2011
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Jun  8 18:22:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.113 2011/06/04 13:24:33 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.114 2011/06/08 18:22:24 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.113 2011/06/04 13:24:33 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.114 2011/06/08 18:22:24 pgoyette Exp $");
 
 #include 
 #include 
@@ -1263,16 +1263,11 @@
 sme_add_sensor_dictionary(struct sysmon_envsys *sme, prop_array_t array,
 			  prop_dictionary_t dict, envsys_data_t *edata)
 {
-	const struct sme_descr_entry *sdt_state, *sdt_units, *sdt_battcap;
-	const struct sme_descr_entry *sdt_drive;
+	const struct sme_descr_entry *sdt;
+	int error;
 	sme_event_drv_t *sme_evdrv_t = NULL;
 	char indexstr[ENVSYS_DESCLEN];
 
-	/* 
-	 * Find the correct units for this sensor.
-	 */
-	sdt_units = sme_find_table_entry(SME_DESC_UNITS, edata->units);
-
 	/*
 	 * Add the index sensor string.
 	 *
@@ -1287,35 +1282,14 @@
 
 	/*
 	 * 		...
-	 * 		type
-	 * 		foo
 	 * 		description
 	 * 		blah blah
 	 * 		...
 	 */
-	if (sme_sensor_upstring(dict, "type", sdt_units->desc))
-		goto bad;
-
 	if (sme_sensor_upstring(dict, "description", edata->desc))
 		goto bad;
 
 	/*
-	 * Add sensor's state description.
-	 *
-	 * 		...
-	 * 		state
-	 * 		valid
-	 * 		...
-	 */
-	sdt_state = sme_find_table_entry(SME_DESC_STATES, edata->state);
-
-	DPRINTF(("%s: sensor desc=%s type=%d state=%d\n",
-	__func__, edata->desc, edata->units, edata->state));
-
-	if (sme_sensor_upstring(dict, "state", sdt_state->desc))
-		goto bad;
-
-	/*
 	 * Add the monitoring boolean object:
 	 *
 	 * 		...
@@ -1340,21 +1314,8 @@
 	}
 
 	/*
-	 * Add the percentage boolean object, true if ENVSYS_FPERCENT
-	 * is set or false otherwise.
-	 *
-	 * 		...
-	 * 		want-percentage
-	 * 		
-	 * 		...
-	 */
-	if (edata->flags & ENVSYS_FPERCENT)
-		if (sme_sensor_upbool(dict, "want-percentage", true))
-			goto out;
-
-	/*
 	 * Add the allow-rfact boolean object, true if
-	 * ENVSYS_FCHANGERFACT if set or false otherwise.
+	 * ENVSYS_FCHANGERFACT is set, false otherwise.
 	 *
 	 * 		...
 	 * 		allow-rfact
@@ -1372,83 +1333,12 @@
 		}
 	}
 
-	/*
-	 * Add the object for battery capacity sensors:
-	 *
-	 * 		...
-	 * 		battery-capacity
-	 * 		NORMAL
-	 * 		...
-	 */
-	if (edata->units == ENVSYS_BATTERY_CAPACITY) {
-		sdt_battcap = sme_find_table_entry(SME_DESC_BATTERY_CAPACITY,
-		edata->value_cur);
-		if (sme_sensor_upstring(dict, "battery-capacity",
-	sdt_battcap->desc))
-			goto out;
-	}
-
-	/*
-	 * Add the drive-state object for drive sensors:
-	 *
-	 * 		...
-	 * 		drive-state
-	 * 		drive is online
-	 * 		...
-	 */
-	if (edata->units == ENVSYS_DRIVE) {
-		sdt_drive = sme_find_table_entry(SME_DESC_DRIVE_STATES,
-		edata->value_cur);
-		if (sme_sensor_upstring(dict, "drive-state", sdt_drive->desc))
-			goto out;
-	}
-
-	/*
-	 * Add the following objects if sensor is enabled...
-	 */
-	if (edata->state == ENVSYS_SVALID) {
-		/*
-		 * Add the following objects:
-		 *
-		 * 	...
-		 * 	rpms
-		 * 	2500
-		 * 	rfact
-		 * 	1
-		 * 	cur-value
-	 	 * 	1250
-	 	 * 	min-value
-	 	 * 	800
-	 	 * 	max-value
-	 	 * 	3000
-	 	 * 	...
-	 	 */
-		if (edata->units == ENVSYS_SFANRPM)
-			if (sme_sensor_upuint32(dict, "rpms", edata->rpms))
-goto out;
-
-		if (edata->units == ENVSYS_SVOLTS_AC ||
-		edata->units == ENVSYS_SVOLTS_DC)
-			if (sme_sensor_upint32(dict, "rfact", edata->rfact))
-goto out;
-
-		if (sme_sensor_upint32(dict, "cur-value", edata->value_cur))
-			goto out;
-
-		if (edata->flags & ENVSYS_FVALID_MIN) {
-			if (sme_sensor_upint32(dict,
-	   "min-value",
-	   edata->value_min))
-			goto out;
-		}
-
-		if (edata->flags & ENVSYS_FVALID_MAX) {
-			if (sme_sensor_upint32(dict,
-	   "max-value",
-	   edata->value_max))
-			goto out;
-		}
-	}
+	error = sme_update_sensor_dictionary(dict, edata,
+			(edata->state == ENVSYS_SVALID));
+	if (error < 0)
+		goto bad;
+	else if (error)
+		g

CVS commit: src/sys/dev/sysmon

2011-06-15 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jun 15 13:34:13 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Previous fix broke the setting of current value for Indicator and
Battery-Charge sensors.  Fix this.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/dev/sysmon/sysmon_envsys.c

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.114 src/sys/dev/sysmon/sysmon_envsys.c:1.115
--- src/sys/dev/sysmon/sysmon_envsys.c:1.114	Wed Jun  8 18:22:24 2011
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Jun 15 13:34:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.114 2011/06/08 18:22:24 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.115 2011/06/15 13:34:13 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.114 2011/06/08 18:22:24 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.115 2011/06/15 13:34:13 pgoyette Exp $");
 
 #include 
 #include 
@@ -1555,6 +1555,15 @@
 	if (error)
 		return (-error);
 
+	if (value_update) {
+		/* 
+		 * update sensor's current value.
+		 */
+		error = sme_sensor_upint32(dict, "cur-value", edata->value_cur);
+		if (error)
+			return error;
+	}
+
 	/*
 	 * Battery charge and Indicator types do not
 	 * need the remaining objects, so skip them.
@@ -1573,13 +1582,6 @@
 	}
 
 	if (value_update) {
-		/* 
-		 * update sensor's current value.
-		 */
-		error = sme_sensor_upint32(dict, "cur-value", edata->value_cur);
-		if (error)
-			return error;
-
 		/*
 		 * update sensor's {max,min}-value.
 		 */



CVS commit: src/sys/dev/sysmon

2011-06-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Jun 19 03:09:44 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_tables.c sysmon_envsysvar.h

Log Message:
Add routine to lookup description tables by description instead of by
type.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/sysmon/sysmon_envsys_tables.c
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/sysmon/sysmon_envsysvar.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_tables.c
diff -u src/sys/dev/sysmon/sysmon_envsys_tables.c:1.6 src/sys/dev/sysmon/sysmon_envsys_tables.c:1.7
--- src/sys/dev/sysmon/sysmon_envsys_tables.c:1.6	Wed Dec 15 17:17:17 2010
+++ src/sys/dev/sysmon/sysmon_envsys_tables.c	Sun Jun 19 03:09:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_tables.c,v 1.6 2010/12/15 17:17:17 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_tables.c,v 1.7 2011/06/19 03:09:43 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.6 2010/12/15 17:17:17 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.7 2011/06/19 03:09:43 pgoyette Exp $");
 
 #include 
 
@@ -129,3 +129,29 @@
 
 	return table;
 }
+const struct sme_descr_entry *
+sme_find_table_desc(enum sme_descr_type table_id, const char *str)
+{
+	const struct sme_descr_entry *table = NULL;
+
+	switch (table_id) {
+	case SME_DESC_UNITS:
+		table = sme_units_description;
+		break;
+	case SME_DESC_STATES:
+		table = sme_state_description;
+		break;
+	case SME_DESC_DRIVE_STATES:
+		table = sme_drivestate_description;
+		break;
+	case SME_DESC_BATTERY_CAPACITY:
+		table = sme_batterycap_description;
+		break;
+	}
+
+	for (; table->type != -1; table++)
+		if (strcmp(table->desc, str) == 0)
+			break;
+	return table;
+}
+

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.39 src/sys/dev/sysmon/sysmon_envsysvar.h:1.40
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.39	Wed Jun  8 18:22:24 2011
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Sun Jun 19 03:09:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.39 2011/06/08 18:22:24 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.40 2011/06/19 03:09:43 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -145,5 +145,7 @@
 int	sme_sensor_upstring(prop_dictionary_t, const char *, const char *);
 
 const struct sme_descr_entry *sme_find_table_entry(enum sme_descr_type, int);
+const struct sme_descr_entry * sme_find_table_desc(enum sme_descr_type,
+		   const char *);
 
 #endif /* _DEV_SYSMON_ENVSYSVAR_H_ */



CVS commit: src/sys/dev/sysmon

2011-06-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Jun 19 04:08:48 UTC 2011

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Use correct routine to retrieve string value from prop-dictionary


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.10 src/sys/dev/sysmon/swsensor.c:1.11
--- src/sys/dev/sysmon/swsensor.c:1.10	Sun Jun 19 03:12:31 2011
+++ src/sys/dev/sysmon/swsensor.c	Sun Jun 19 04:08:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.10 2011/06/19 03:12:31 pgoyette Exp $ */
+/*	$NetBSD: swsensor.c,v 1.11 2011/06/19 04:08:48 pgoyette Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.10 2011/06/19 03:12:31 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.11 2011/06/19 04:08:48 pgoyette Exp $");
 
 #include 
 #include 
@@ -205,7 +205,7 @@
 }
 if (type != PROP_TYPE_STRING)
 	return EINVAL;
-str = prop_dictionary_keysym_cstring_nocopy(po);
+str = prop_string_cstring_nocopy(po);
 descr = sme_find_table_desc(SME_DESC_UNITS,
 			str);
 if (descr->type < 0)



CVS commit: src/sys/dev/sysmon

2011-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 04:23:18 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_tables.c

Log Message:
simplify and don't deref NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/sysmon/sysmon_envsys_tables.c

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_tables.c
diff -u src/sys/dev/sysmon/sysmon_envsys_tables.c:1.7 src/sys/dev/sysmon/sysmon_envsys_tables.c:1.8
--- src/sys/dev/sysmon/sysmon_envsys_tables.c:1.7	Sat Jun 18 23:09:43 2011
+++ src/sys/dev/sysmon/sysmon_envsys_tables.c	Sun Jun 19 00:23:18 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_tables.c,v 1.7 2011/06/19 03:09:43 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_tables.c,v 1.8 2011/06/19 04:23:18 christos Exp $ */
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.7 2011/06/19 03:09:43 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.8 2011/06/19 04:23:18 christos Exp $");
 
 #include 
 
@@ -100,58 +100,51 @@
 	{ -1,	-1, 	"UNKNOWN" }
 };
 
-/*
- * Returns the entry from specified table with type == key
- */
-const struct sme_descr_entry *
-sme_find_table_entry(enum sme_descr_type table_id, int key)
+static const struct sme_desc_entry *
+sme_find_table(enum sme_descr_type table_id)
 {
-	const struct sme_descr_entry *table = NULL;
-
 	switch (table_id) {
 	case SME_DESC_UNITS:
-		table = sme_units_description;
+		return sme_units_description;
 		break;
 	case SME_DESC_STATES:
-		table = sme_state_description;
+		return sme_state_description;
 		break;
 	case SME_DESC_DRIVE_STATES:
-		table = sme_drivestate_description;
+		return sme_drivestate_description;
 		break;
 	case SME_DESC_BATTERY_CAPACITY:
-		table = sme_batterycap_description;
+		return sme_batterycap_description;
 		break;
+	default:
+		return NULL;
 	}
+}
+
+/*
+ * Returns the entry from specified table with type == key
+ */
+const struct sme_descr_entry *
+sme_find_table_entry(enum sme_descr_type table_id, int key)
+{
+	const struct sme_descr_entry *table = sme_find_table();
 
-	for (; table->type != -1; table++)
-		if (table->type == key)
-			break;
+	if (table != NULL)
+		for (; table->type != -1; table++)
+			if (table->type == key)
+return table;
 
-	return table;
+	return NULL;
 }
+
 const struct sme_descr_entry *
 sme_find_table_desc(enum sme_descr_type table_id, const char *str)
 {
-	const struct sme_descr_entry *table = NULL;
+	const struct sme_descr_entry *table = sme_find_table();
 
-	switch (table_id) {
-	case SME_DESC_UNITS:
-		table = sme_units_description;
-		break;
-	case SME_DESC_STATES:
-		table = sme_state_description;
-		break;
-	case SME_DESC_DRIVE_STATES:
-		table = sme_drivestate_description;
-		break;
-	case SME_DESC_BATTERY_CAPACITY:
-		table = sme_batterycap_description;
-		break;
-	}
-
-	for (; table->type != -1; table++)
-		if (strcmp(table->desc, str) == 0)
-			break;
-	return table;
+	if (table != NULL)
+		for (; table->type != -1; table++)
+			if (strcmp(table->desc, str) == 0)
+return table;
+	return NULL;
 }
-



CVS commit: src/sys/dev/sysmon

2011-06-18 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Sun Jun 19 05:17:38 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_tables.c

Log Message:
fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/sysmon/sysmon_envsys_tables.c

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_tables.c
diff -u src/sys/dev/sysmon/sysmon_envsys_tables.c:1.8 src/sys/dev/sysmon/sysmon_envsys_tables.c:1.9
--- src/sys/dev/sysmon/sysmon_envsys_tables.c:1.8	Sun Jun 19 04:23:18 2011
+++ src/sys/dev/sysmon/sysmon_envsys_tables.c	Sun Jun 19 05:17:38 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_tables.c,v 1.8 2011/06/19 04:23:18 christos Exp $ */
+/* $NetBSD: sysmon_envsys_tables.c,v 1.9 2011/06/19 05:17:38 nonaka Exp $ */
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.8 2011/06/19 04:23:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.9 2011/06/19 05:17:38 nonaka Exp $");
 
 #include 
 
@@ -100,7 +100,7 @@
 	{ -1,	-1, 	"UNKNOWN" }
 };
 
-static const struct sme_desc_entry *
+static const struct sme_descr_entry *
 sme_find_table(enum sme_descr_type table_id)
 {
 	switch (table_id) {



CVS commit: src/sys/dev/sysmon

2011-06-18 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Sun Jun 19 05:26:32 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_tables.c

Log Message:
Pass table_id to sme_find_table().


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/sysmon/sysmon_envsys_tables.c

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_tables.c
diff -u src/sys/dev/sysmon/sysmon_envsys_tables.c:1.9 src/sys/dev/sysmon/sysmon_envsys_tables.c:1.10
--- src/sys/dev/sysmon/sysmon_envsys_tables.c:1.9	Sun Jun 19 05:17:38 2011
+++ src/sys/dev/sysmon/sysmon_envsys_tables.c	Sun Jun 19 05:26:31 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_tables.c,v 1.9 2011/06/19 05:17:38 nonaka Exp $ */
+/* $NetBSD: sysmon_envsys_tables.c,v 1.10 2011/06/19 05:26:31 nonaka Exp $ */
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.9 2011/06/19 05:17:38 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.10 2011/06/19 05:26:31 nonaka Exp $");
 
 #include 
 
@@ -127,7 +127,7 @@
 const struct sme_descr_entry *
 sme_find_table_entry(enum sme_descr_type table_id, int key)
 {
-	const struct sme_descr_entry *table = sme_find_table();
+	const struct sme_descr_entry *table = sme_find_table(table_id);
 
 	if (table != NULL)
 		for (; table->type != -1; table++)
@@ -140,7 +140,7 @@
 const struct sme_descr_entry *
 sme_find_table_desc(enum sme_descr_type table_id, const char *str)
 {
-	const struct sme_descr_entry *table = sme_find_table();
+	const struct sme_descr_entry *table = sme_find_table(table_id);
 
 	if (table != NULL)
 		for (; table->type != -1; table++)



CVS commit: src/sys/dev/sysmon

2011-06-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun 19 11:40:26 UTC 2011

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Instead of crashing, print a usable error message when a driver eroneously
does not properly initialize sensor state.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/dev/sysmon/sysmon_envsys.c

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.115 src/sys/dev/sysmon/sysmon_envsys.c:1.116
--- src/sys/dev/sysmon/sysmon_envsys.c:1.115	Wed Jun 15 13:34:13 2011
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Jun 19 11:40:26 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.115 2011/06/15 13:34:13 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.116 2011/06/19 11:40:26 martin Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.115 2011/06/15 13:34:13 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.116 2011/06/19 11:40:26 martin Exp $");
 
 #include 
 #include 
@@ -1535,6 +1535,11 @@
 	int error = 0;
 
 	sdt = sme_find_table_entry(SME_DESC_STATES, edata->state);
+	if (sdt == NULL) {
+		printf("sme_update_sensor_dictionary: can not update sensor "
+		"state %d unknown\n", edata->state);
+		return EINVAL;
+	}
 
 	DPRINTFOBJ(("%s: sensor #%d type=%d (%s) flags=%d\n", __func__,
 	edata->sensor, sdt->type, sdt->desc, edata->flags));



CVS commit: src/sys/dev/sysmon

2011-06-19 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Jun 19 15:52:48 UTC 2011

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Use {...} to prevent premature exit from initialization function - this
lets the atf tests run again.

Move validation of current value vs min/max into the refresh routine
where it will get checked every time, not just at initialization.

While here, do a little more housekeeping:
  - Retrieve numeric property value once
  - Ensure that a numeric-specified sensor type is valid
  - printout any unrecognized properties (DEBUG only)


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.11 src/sys/dev/sysmon/swsensor.c:1.12
--- src/sys/dev/sysmon/swsensor.c:1.11	Sun Jun 19 04:08:48 2011
+++ src/sys/dev/sysmon/swsensor.c	Sun Jun 19 15:52:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.11 2011/06/19 04:08:48 pgoyette Exp $ */
+/*	$NetBSD: swsensor.c,v 1.12 2011/06/19 15:52:48 pgoyette Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.11 2011/06/19 04:08:48 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.12 2011/06/19 15:52:48 pgoyette Exp $");
 
 #include 
 #include 
@@ -103,6 +103,15 @@
 
 	edata->value_cur = sw_sensor_value;
 
+	/* If value outside of legal range, mark it invalid */
+	if ((edata->flags & ENVSYS_FVALID_MIN &&
+	 edata->value_cur < edata->value_min) ||
+	(edata->flags & ENVSYS_FVALID_MAX &&
+	 edata->value_cur > edata->value_max)) {
+		edata->state = ENVSYS_SINVALID;
+		return;
+	}
+
 	/*
 	 * Set state.  If we're handling the limits ourselves, do the
 	 * compare; otherwise just assume the value is valid.
@@ -159,7 +168,7 @@
 int
 swsensor_init(void *arg)
 {
-	int error;
+	int error, val = 0;
 	const char *key, *str;
 	prop_dictionary_t pd = (prop_dictionary_t)arg;
 	prop_object_t po, obj;
@@ -195,12 +204,17 @@
 			key = prop_dictionary_keysym_cstring_nocopy(obj);
 			po  = prop_dictionary_get_keysym(pd, obj);
 			type = prop_object_type(po);
+			if (type == PROP_TYPE_NUMBER)
+val = prop_number_integer_value(po);
 
 			/* Sensor type/units */
 			if (strcmp(key, "type") == 0) {
 if (type == PROP_TYPE_NUMBER) {
-	swsensor_edata.units =
-	prop_number_integer_value(po);
+	descr = sme_find_table_entry(
+			SME_DESC_UNITS, val);
+	if (descr == NULL)
+		return EINVAL;
+	swsensor_edata.units = descr->type;
 	continue;
 }
 if (type != PROP_TYPE_STRING)
@@ -208,7 +222,7 @@
 str = prop_string_cstring_nocopy(po);
 descr = sme_find_table_desc(SME_DESC_UNITS,
 			str);
-if (descr->type < 0)
+if (descr == NULL)
 	return EINVAL;
 swsensor_edata.units = descr->type;
 continue;
@@ -218,8 +232,7 @@
 			if (strcmp(key, "flags") == 0) {
 if (type != PROP_TYPE_NUMBER)
 	return EINVAL;
-swsensor_edata.flags =
-prop_number_integer_value(po);
+swsensor_edata.flags = val;
 continue;
 			}
 
@@ -232,7 +245,7 @@
 			if (strcmp(key, "mode") == 0) {
 if (type != PROP_TYPE_NUMBER)
 	return EINVAL;
-sw_sensor_mode = prop_number_integer_value(po);
+sw_sensor_mode = val;
 if (sw_sensor_mode > 2)
 	sw_sensor_mode = 2;
 else if (sw_sensor_mode < 0)
@@ -244,7 +257,7 @@
 			if (strcmp(key, "limit") == 0) {
 if (type != PROP_TYPE_NUMBER)
 	return EINVAL;
-sw_sensor_limit = prop_number_integer_value(po);
+sw_sensor_limit = val;
 continue;
 			}
 
@@ -252,7 +265,7 @@
 			if (strcmp(key, "value") == 0) {
 if (type != PROP_TYPE_NUMBER)
 	return EINVAL;
-sw_sensor_value = prop_number_integer_value(po);
+sw_sensor_value = val;
 continue;
 			}
 
@@ -260,16 +273,14 @@
 			if (strcmp(key, "value_min") == 0) {
 if (type != PROP_TYPE_NUMBER)
 	return EINVAL;
-swsensor_edata.value_min =
-prop_number_integer_value(po);
+swsensor_edata.value_min = val;
 swsensor_edata.flags |= ENVSYS_FVALID_MIN;
 continue;
 			}
 			if (strcmp(key, "value_max") == 0) {
 if (type != PROP_TYPE_NUMBER)
 	return EINVAL;
-swsensor_edata.value_max =
-prop_number_integer_value(po);
+swsensor_edata.value_max = val;
 swsensor_edata.flags |= ENVSYS_FVALID_MAX;
 continue;
 			}
@@ -284,6 +295,9 @@
 			}
 
 			/* Unrecognized dicttionary object */
+#ifdef DEBUG
+			printf("%s: unknown attribute %s\n", __func__, key);
+#endif
 			return EINVAL;
 
 		} /* while */
@@ -303,22 +317,11 @@
 		&sw_sensor_deflims, &sw_sensor_defprops);
 	}
 
-	/*
-	 * If {min, max} value range was specified, make sure that the
-	 * current value is within the range.
-	 */
-	if (swsensor_edata.flags & ENVS

CVS commit: src/sys/dev/sysmon

2012-08-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Aug 27 14:08:36 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Simplify some logic - no functional change intended.

While here, clean up a couple of comments.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/sysmon/sysmon_envsys.c

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.122 src/sys/dev/sysmon/sysmon_envsys.c:1.123
--- src/sys/dev/sysmon/sysmon_envsys.c:1.122	Thu Jul 19 13:31:06 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Mon Aug 27 14:08:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.122 2012/07/19 13:31:06 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.123 2012/08/27 14:08:36 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.122 2012/07/19 13:31:06 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.123 2012/08/27 14:08:36 pgoyette Exp $");
 
 #include 
 #include 
@@ -516,7 +516,7 @@ sysmon_envsys_destroy(struct sysmon_envs
 /*
  * sysmon_envsys_sensor_attach:
  *
- * 	+ Attachs a sensor into a sysmon_envsys device checking that units
+ * 	+ Attaches a sensor into a sysmon_envsys device checking that units
  * 	  is set to a valid type and description is unique and not empty.
  */
 int
@@ -555,7 +555,7 @@ sysmon_envsys_sensor_attach(struct sysmo
 	TAILQ_INSERT_TAIL(&sme->sme_sensors_list, edata, sensors_head);
 
 	/*
-	 * Give the sensor a index position.
+	 * Give the sensor an index position.
 	 */
 	edata->sensor = sme->sme_nsensors;
 	sme->sme_nsensors++;
@@ -1290,6 +1290,7 @@ sme_add_sensor_dictionary(struct sysmon_
 	int error;
 	sme_event_drv_t *sme_evdrv_t = NULL;
 	char indexstr[ENVSYS_DESCLEN];
+	bool mon_supported, allow_rfact;
 
 	/*
 	 * Add the index sensor string.
@@ -1328,13 +1329,12 @@ sme_add_sensor_dictionary(struct sysmon_
 	(edata->units == ENVSYS_INDICATOR) ||
 	(edata->units == ENVSYS_DRIVE) ||
 	(edata->units == ENVSYS_BATTERY_CAPACITY) ||
-	(edata->units == ENVSYS_BATTERY_CHARGE)) {
-		if (sme_sensor_upbool(dict, "monitoring-supported", false))
-			goto out;
-	} else {
-		if (sme_sensor_upbool(dict, "monitoring-supported", true))
+	(edata->units == ENVSYS_BATTERY_CHARGE))
+		mon_supported = false;
+	else
+		mon_supported = true;
+	if (sme_sensor_upbool(dict, "monitoring-supported", mon_supported))
 			goto out;
-	}
 
 	/*
 	 * Add the allow-rfact boolean object, true if
@@ -1347,13 +1347,12 @@ sme_add_sensor_dictionary(struct sysmon_
 	 */
 	if (edata->units == ENVSYS_SVOLTS_DC ||
 	edata->units == ENVSYS_SVOLTS_AC) {
-		if (edata->flags & ENVSYS_FCHANGERFACT) {
-			if (sme_sensor_upbool(dict, "allow-rfact", true))
-goto out;
-		} else {
-			if (sme_sensor_upbool(dict, "allow-rfact", false))
+		if (edata->flags & ENVSYS_FCHANGERFACT)
+			allow_rfact = true;
+		else
+			allow_rfact = false;
+		if (sme_sensor_upbool(dict, "allow-rfact", allow_rfact))
 goto out;
-		}
 	}
 
 	error = sme_update_sensor_dictionary(dict, edata,



CVS commit: src/sys/dev/sysmon

2012-08-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Aug 27 14:15:52 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Fix indentation.  No code change.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/dev/sysmon/sysmon_envsys.c

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.123 src/sys/dev/sysmon/sysmon_envsys.c:1.124
--- src/sys/dev/sysmon/sysmon_envsys.c:1.123	Mon Aug 27 14:08:36 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Mon Aug 27 14:15:52 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.123 2012/08/27 14:08:36 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.124 2012/08/27 14:15:52 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.123 2012/08/27 14:08:36 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.124 2012/08/27 14:15:52 pgoyette Exp $");
 
 #include 
 #include 
@@ -1334,7 +1334,7 @@ sme_add_sensor_dictionary(struct sysmon_
 	else
 		mon_supported = true;
 	if (sme_sensor_upbool(dict, "monitoring-supported", mon_supported))
-			goto out;
+		goto out;
 
 	/*
 	 * Add the allow-rfact boolean object, true if
@@ -1352,7 +1352,7 @@ sme_add_sensor_dictionary(struct sysmon_
 		else
 			allow_rfact = false;
 		if (sme_sensor_upbool(dict, "allow-rfact", allow_rfact))
-goto out;
+			goto out;
 	}
 
 	error = sme_update_sensor_dictionary(dict, edata,



CVS commit: src/sys/dev/sysmon

2012-08-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Aug 27 20:29:12 UTC 2012

Modified Files:
src/sys/dev/sysmon: swsensor.c

Log Message:
Add hw.swsensor.state variable for additional control capability.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/sysmon/swsensor.c

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/swsensor.c
diff -u src/sys/dev/sysmon/swsensor.c:1.12 src/sys/dev/sysmon/swsensor.c:1.13
--- src/sys/dev/sysmon/swsensor.c:1.12	Sun Jun 19 15:52:48 2011
+++ src/sys/dev/sysmon/swsensor.c	Mon Aug 27 20:29:11 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: swsensor.c,v 1.12 2011/06/19 15:52:48 pgoyette Exp $ */
+/*	$NetBSD: swsensor.c,v 1.13 2012/08/27 20:29:11 pgoyette Exp $ */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.12 2011/06/19 15:52:48 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swsensor.c,v 1.13 2012/08/27 20:29:11 pgoyette Exp $");
 
 #include 
 #include 
@@ -48,11 +48,13 @@ int swsensorattach(int);
 static struct sysctllog *swsensor_sysctllog = NULL;
 
 static int sensor_value_sysctl = 0;
+static int sensor_state_sysctl = 0;
 
 static struct sysmon_envsys *swsensor_sme;
 static envsys_data_t swsensor_edata;
 
 static int32_t sw_sensor_value;
+static int32_t sw_sensor_state;
 static int32_t sw_sensor_limit;
 static int32_t sw_sensor_mode;
 static int32_t sw_sensor_defprops;
@@ -71,6 +73,7 @@ sysctl_swsensor_setup(void)
 	int ret;
 	int node_sysctl_num;
 	const struct sysctlnode *me = NULL;
+	const struct sysctlnode *me2;
 
 	KASSERT(swsensor_sysctllog == NULL);
 
@@ -83,14 +86,24 @@ sysctl_swsensor_setup(void)
 		return;
 
 	node_sysctl_num = me->sysctl_num;
-	ret = sysctl_createv(&swsensor_sysctllog, 0, NULL, &me,
+	ret = sysctl_createv(&swsensor_sysctllog, 0, NULL, &me2,
 			 CTLFLAG_READWRITE,
 			 CTLTYPE_INT, "cur_value", NULL,
 			 NULL, 0, &sw_sensor_value, 0,
 			 CTL_HW, node_sysctl_num, CTL_CREATE, CTL_EOL);
 
 	if (ret == 0)
-		sensor_value_sysctl = me->sysctl_num;
+		sensor_value_sysctl = me2->sysctl_num;
+
+	node_sysctl_num = me->sysctl_num;
+	ret = sysctl_createv(&swsensor_sysctllog, 0, NULL, &me2,
+			 CTLFLAG_READWRITE,
+			 CTLTYPE_INT, "state", NULL,
+			 NULL, 0, &sw_sensor_state, 0,
+			 CTL_HW, node_sysctl_num, CTL_CREATE, CTL_EOL);
+
+	if (ret == 0)
+		sensor_state_sysctl = me2->sysctl_num;
 }
 
 /*
@@ -115,8 +128,12 @@ swsensor_refresh(struct sysmon_envsys *s
 	/*
 	 * Set state.  If we're handling the limits ourselves, do the
 	 * compare; otherwise just assume the value is valid.
+	 * If sensor state has been set from userland (via sysctl),
+	 * just report that value.
 	 */
-	if ((sw_sensor_mode == 2) && (edata->upropset & PROP_CRITMIN) &&
+	if (sw_sensor_state != ENVSYS_SVALID)
+		edata->state = sw_sensor_state;
+	else if ((sw_sensor_mode == 2) && (edata->upropset & PROP_CRITMIN) &&
 	(edata->upropset & PROP_DRIVER_LIMITS) &&
 	(edata->value_cur < edata->limits.sel_critmin))
 		edata->state = ENVSYS_SCRITUNDER;
@@ -321,6 +338,7 @@ swsensor_init(void *arg)
 
 	/* Wait for refresh to validate the sensor value */
 	swsensor_edata.state = ENVSYS_SINVALID;
+	sw_sensor_state = ENVSYS_SVALID;
 
 	error = sysmon_envsys_sensor_attach(swsensor_sme, &swsensor_edata);
 	if (error != 0) {



CVS commit: src/sys/dev/sysmon

2012-08-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Aug 27 21:42:04 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c sysmon_envsys_tables.c
sysmon_envsysvar.h

Log Message:
1. Enable use of FMONSTCHANGED events for INDICATOR sensors
2. Update handling of FMONCRITICAL event reporting.   The state
   transition does not require a corresponding change in value.

With these changes, you can now have an INDICATOR sensor that
reports the presence or absence of a device, and (if the device
is present) separately monitor it for proper functioning.

Should address the concerns expressed recently with the commit
of changes to wmi(4) BBU handling.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/sysmon/sysmon_envsys_tables.c
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/sysmon/sysmon_envsysvar.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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.103 src/sys/dev/sysmon/sysmon_envsys_events.c:1.104
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.103	Thu Jul 19 13:30:01 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Mon Aug 27 21:42:04 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.103 2012/07/19 13:30:01 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.104 2012/08/27 21:42:04 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.103 2012/07/19 13:30:01 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.104 2012/08/27 21:42:04 pgoyette Exp $");
 
 #include 
 #include 
@@ -215,26 +215,28 @@ sme_event_register(prop_dictionary_t sdi
 		see->see_pes.pes_type = powertype;
 
 		switch (crittype) {
-		case PENVSYS_EVENT_LIMITS:
-			see->see_evsent = ENVSYS_SVALID;
-			break;
 		case PENVSYS_EVENT_CAPACITY:
-			see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
+			see->see_evstate = ENVSYS_BATTERY_CAPACITY_NORMAL;
 			break;
 		case PENVSYS_EVENT_STATE_CHANGED:
 			if (edata->units == ENVSYS_BATTERY_CAPACITY)
-see->see_evsent = ENVSYS_BATTERY_CAPACITY_NORMAL;
+see->see_evstate = 
+ENVSYS_BATTERY_CAPACITY_NORMAL;
 			else if (edata->units == ENVSYS_DRIVE)
-see->see_evsent = ENVSYS_DRIVE_EMPTY;
+see->see_evstate = ENVSYS_DRIVE_EMPTY;
+			else if (edata->units == ENVSYS_INDICATOR)
+see->see_evstate = ENVSYS_SVALID;
 			else
 panic("%s: bad units for "
   "PENVSYS_EVENT_STATE_CHANGED", __func__);
 			break;
 		case PENVSYS_EVENT_CRITICAL:
+		case PENVSYS_EVENT_LIMITS:
 		default:
-			see->see_evsent = 0;
+			see->see_evstate = ENVSYS_SVALID;
 			break;
 		}
+		see->see_evvalue = 0;
 
 		(void)strlcpy(see->see_pes.pes_dvname, sme->sme_name,
 		sizeof(see->see_pes.pes_dvname));
@@ -846,7 +848,7 @@ sme_deliver_event(sme_event_t *see)
 		/*
 		 * Send event if state has changed
 		 */
-		if (edata->state == see->see_evsent)
+		if (edata->state == see->see_evstate)
 			break;
 
 		for (i = 0; sse[i].state != -1; i++)
@@ -862,7 +864,7 @@ sme_deliver_event(sme_event_t *see)
 		else
 			sysmon_penvsys_event(&see->see_pes, sse[i].event);
 
-		see->see_evsent = edata->state;
+		see->see_evstate = edata->state;
 		DPRINTFOBJ(("%s: (%s) desc=%s sensor=%d state=%d send_ev=%d\n",
 		__func__, see->see_sme->sme_name, edata->desc,
 		edata->sensor, edata->state,
@@ -878,17 +880,24 @@ sme_deliver_event(sme_event_t *see)
 	 *	State has returned from CRITICAL to non-CRITICAL
 	 */
 	case PENVSYS_EVENT_CRITICAL:
+		DPRINTF(("%s: CRITICAL: old/new state %d/%d, old/new value "
+		"%d/%d\n", __func__, see->see_evstate, edata->state,
+		see->see_evvalue, edata->value_cur));
 		if (edata->state == ENVSYS_SVALID &&
-		see->see_evsent != 0) {
+		see->see_evstate != ENVSYS_SVALID) {
 			sysmon_penvsys_event(&see->see_pes,
 	 PENVSYS_EVENT_NORMAL);
-			see->see_evsent = 0;
-		} else if (edata->state == ENVSYS_SCRITICAL &&
-		see->see_evsent != edata->value_cur) {
+			see->see_evstate = ENVSYS_SVALID;
+			break;
+		} else if (edata->state != ENVSYS_SCRITICAL)
+			break;
+		if (see->see_evstate != ENVSYS_SCRITICAL ||
+		see->see_evvalue != edata->value_cur) {
 			sysmon_penvsys_event(&see->see_pes,
 	 PENVSYS_EVENT_CRITICAL);
-			see->see_evsent = edata->value_cur;
+			see->see_evstate = ENVSYS_SCRITICAL;
 		}
+		see->see_evvalue = edata->value_cur;
 		break;
 
 	/*
@@ -899,7 +908,7 @@ sme_deliver_event(sme_event_t *see)
 		/* 
 		 * the state has not been changed, just ignore the event.
 		 */
-		if (edata->value_cur == see->see_evsent)
+		if (edata->value_cur == see->see_evvalue)
 			break;
 
 		switch (edata->units) {
@@ -913,6 +922,11 @@ sme_deliver_event(sme_event_t *see)
 			edata->v

CVS commit: src/sys/dev/sysmon

2012-09-06 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Thu Sep  6 12:10:29 UTC 2012

Modified Files:
src/sys/dev/sysmon: files.sysmon sysmon_envsysvar.h

Log Message:
defflag debug #defines


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/sysmon/files.sysmon
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/sysmon/sysmon_envsysvar.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/files.sysmon
diff -u src/sys/dev/sysmon/files.sysmon:1.13 src/sys/dev/sysmon/files.sysmon:1.14
--- src/sys/dev/sysmon/files.sysmon:1.13	Tue Oct 19 11:55:38 2010
+++ src/sys/dev/sysmon/files.sysmon	Thu Sep  6 12:10:28 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sysmon,v 1.13 2010/10/19 11:55:38 pgoyette Exp $
+#	$NetBSD: files.sysmon,v 1.14 2012/09/06 12:10:28 macallan Exp $
 
 define	sysmon_taskq
 file	dev/sysmon/sysmon_taskq.c	sysmon_taskq 		needs-flag
@@ -11,6 +11,7 @@ file	dev/sysmon/sysmon_envsys.c		sysmon_
 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
+defflag opt_envsys.h ENVSYS_DEBUG ENVSYS_OBJECTS_DEBUG
 
 define	sysmon_wdog
 file	dev/sysmon/sysmon_wdog.c	sysmon_wdog		needs-flag

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.43 src/sys/dev/sysmon/sysmon_envsysvar.h:1.44
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.43	Mon Aug 27 21:42:04 2012
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Thu Sep  6 12:10:28 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.43 2012/08/27 21:42:04 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.44 2012/09/06 12:10:28 macallan Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -40,6 +40,8 @@
 #include 
 #include 
 
+#include "opt_envsys.h"
+
 enum sme_descr_type {
 	SME_DESC_UNITS = 1,
 	SME_DESC_STATES,



CVS commit: src/sys/dev/sysmon

2012-09-06 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Sep  6 12:21:40 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c

Log Message:
Remove (commented-out) definitions for debugging - thanks to macallan@
for defflagging these.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/sysmon/sysmon_envsys_events.c

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.124 src/sys/dev/sysmon/sysmon_envsys.c:1.125
--- src/sys/dev/sysmon/sysmon_envsys.c:1.124	Mon Aug 27 14:15:52 2012
+++ src/sys/dev/sysmon/sysmon_envsys.c	Thu Sep  6 12:21:40 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.124 2012/08/27 14:15:52 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.125 2012/09/06 12:21:40 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.124 2012/08/27 14:15:52 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.125 2012/09/06 12:21:40 pgoyette Exp $");
 
 #include 
 #include 
@@ -78,7 +78,6 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsy
 #include 
 #include 
 
-/* #define ENVSYS_DEBUG */
 #include 
 #include 
 #include 

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.104 src/sys/dev/sysmon/sysmon_envsys_events.c:1.105
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.104	Mon Aug 27 21:42:04 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Thu Sep  6 12:21:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.104 2012/08/27 21:42:04 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.105 2012/09/06 12:21:40 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.104 2012/08/27 21:42:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.105 2012/09/06 12:21:40 pgoyette Exp $");
 
 #include 
 #include 
@@ -43,9 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsy
 #include 
 #include 
 
-/* #define ENVSYS_DEBUG */
-/* #define ENVSYS_OBJECTS_DEBUG */
-
 #include 
 #include 
 



CVS commit: src/sys/dev/sysmon

2012-09-06 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Thu Sep  6 12:59:00 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsysvar.h

Log Message:
opt_envsys.h needs #ifdef _KERNEL_OPT
( thanks martin@ )


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/sysmon/sysmon_envsysvar.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_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.44 src/sys/dev/sysmon/sysmon_envsysvar.h:1.45
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.44	Thu Sep  6 12:10:28 2012
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Thu Sep  6 12:59:00 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.44 2012/09/06 12:10:28 macallan Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.45 2012/09/06 12:59:00 macallan Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -40,7 +40,9 @@
 #include 
 #include 
 
+#ifdef _KERNEL_OPT
 #include "opt_envsys.h"
+#endif
 
 enum sme_descr_type {
 	SME_DESC_UNITS = 1,



CVS commit: src/sys/dev/sysmon

2012-10-30 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Wed Oct 31 05:42:48 UTC 2012

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
in sme_battery_check():
- don't assume that all batteries have exactly one ENVSYS_INDICATOR
- check capacity and charge sensors for ENVSYS_SVALID before using them
now this works on macppc


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/sysmon/sysmon_envsys_events.c

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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.105 src/sys/dev/sysmon/sysmon_envsys_events.c:1.106
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.105	Thu Sep  6 12:21:40 2012
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Oct 31 05:42:47 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.105 2012/09/06 12:21:40 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.106 2012/10/31 05:42:47 macallan Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.105 2012/09/06 12:21:40 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.106 2012/10/31 05:42:47 macallan Exp $");
 
 #include 
 #include 
@@ -1027,6 +1027,7 @@ sme_acadapter_check(void)
 			sensor = true;
 			/* refresh current sensor */
 			sysmon_envsys_refresh_sensor(sme, edata);
+
 			if (edata->value_cur)
 return false;
 		}
@@ -1061,10 +1062,16 @@ sme_battery_check(void)
 			continue;
 
 		present = true;
+
+		/*
+		 * XXX
+		 * this assumes that the first valid ENVSYS_INDICATOR is the
+		 * presence indicator
+		 */
 		TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
-			if (edata->units == ENVSYS_INDICATOR &&
-			!edata->value_cur) {
-present = false;
+			if ((edata->units == ENVSYS_INDICATOR) &&
+			(edata->state == ENVSYS_SVALID)) {
+present = edata->value_cur;
 break;
 			}
 		}
@@ -1076,6 +1083,9 @@ sme_battery_check(void)
 		batteriesfound++;
 		batterycap = batterycharge = false;
 		TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
+			/* no need to even look at sensors that aren't valid */
+			if (edata->state != ENVSYS_SVALID)
+continue;
 			if (edata->units == ENVSYS_BATTERY_CAPACITY) {
 batterycap = true;
 if (!sme_battery_critical(edata))



CVS commit: src/sys/dev/sysmon

2015-03-14 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Mar 14 09:52:49 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c sysmonvar.h

Log Message:
Add a counter of busy events and stop enqueueing more work if a device is busy.
Protect this counter with a new short time lock "sme_work_mtx" and
keep "sme_mtx" as long time lock.

Removes a deadlock where an active event holds "sme_mtx", the callout
"sme_events_check" blocks on "sme_mtx" and callout processing stops.


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.113 -r1.114 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/sysmon/sysmonvar.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.128 src/sys/dev/sysmon/sysmon_envsys.c:1.129
--- src/sys/dev/sysmon/sysmon_envsys.c:1.128	Sun Nov 23 10:00:20 2014
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sat Mar 14 09:52:49 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.128 2014/11/23 10:00:20 ozaki-r Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.129 2015/03/14 09:52:49 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.128 2014/11/23 10:00:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.129 2015/03/14 09:52:49 hannken Exp $");
 
 #include 
 #include 
@@ -485,6 +485,7 @@ sysmon_envsys_create(void)
 	TAILQ_INIT(&sme->sme_sensors_list);
 	LIST_INIT(&sme->sme_events_list);
 	mutex_init(&sme->sme_mtx, MUTEX_DEFAULT, IPL_NONE);
+	mutex_init(&sme->sme_work_mtx, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(&sme->sme_condvar, "sme_wait");
 
 	return sme;
@@ -508,6 +509,7 @@ sysmon_envsys_destroy(struct sysmon_envs
 		TAILQ_REMOVE(&sme->sme_sensors_list, edata, sensors_head);
 	}
 	mutex_destroy(&sme->sme_mtx);
+	mutex_destroy(&sme->sme_work_mtx);
 	cv_destroy(&sme->sme_condvar);
 	kmem_free(sme, sizeof(*sme));
 }

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.113 src/sys/dev/sysmon/sysmon_envsys_events.c:1.114
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.113	Sun Nov 23 10:00:20 2014
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Mar 14 09:52:49 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.113 2014/11/23 10:00:20 ozaki-r Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.114 2015/03/14 09:52:49 hannken Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.113 2014/11/23 10:00:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.114 2015/03/14 09:52:49 hannken Exp $");
 
 #include 
 #include 
@@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon_envsy
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -731,11 +732,23 @@ sme_events_check(void *arg)
 
 	KASSERT(sme != NULL);
 
+	mutex_enter(&sme->sme_work_mtx);
+	if (sme->sme_busy > 0) {
+		log(LOG_WARNING, "%s: workqueue busy: updates stopped\n",
+		sme->sme_name);
+		mutex_exit(&sme->sme_work_mtx);
+		return;
+	}
+	mutex_exit(&sme->sme_work_mtx);
+
 	mutex_enter(&sme->sme_mtx);
+	mutex_enter(&sme->sme_work_mtx);
 	LIST_FOREACH(see, &sme->sme_events_list, see_list) {
 		workqueue_enqueue(sme->sme_wq, &see->see_wk, NULL);
 		see->see_edata->flags |= ENVSYS_FNEED_REFRESH;
+		sme->sme_busy++;
 	}
+	mutex_exit(&sme->sme_work_mtx);
 	if (!sysmon_low_power)
 		sme_schedule_callout(sme);
 	mutex_exit(&sme->sme_mtx);
@@ -815,6 +828,10 @@ sme_events_worker(struct work *wk, void 
 out:
 	see->see_flags &= ~SEE_EVENT_WORKING;
 	cv_broadcast(&sme->sme_condvar);
+	mutex_enter(&sme->sme_work_mtx);
+	KASSERT(sme->sme_busy > 0);
+	sme->sme_busy--;
+	mutex_exit(&sme->sme_work_mtx);
 	mutex_exit(&sme->sme_mtx);
 }
 

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.45 src/sys/dev/sysmon/sysmonvar.h:1.46
--- src/sys/dev/sysmon/sysmonvar.h:1.45	Sat Nov 22 15:00:05 2014
+++ src/sys/dev/sysmon/sysmonvar.h	Sat Mar 14 09:52:49 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.45 2014/11/22 15:00:05 ozaki-r Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.46 2015/03/14 09:52:49 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -207,7 +207,11 @@ struct sysmon_envsys {
 	/*
 	 * Locking/synchronization.
 	 */
+	int sme_busy;			/* number of items on workqueue,
+	   sme_mtx or sme_work_mtx to read,
+	   both to write */
 	kmutex_t sme_mtx;
+	kmutex_t sme_work_mtx;
 	kcondvar_t sme_condvar;
 };
 



CVS commit: src/sys/dev/sysmon

2015-04-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  4 15:25:16 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
Free ped if we can't hand it to the power daemon.

Found by Brainy, reported by maxv@.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.49 src/sys/dev/sysmon/sysmon_power.c:1.50
--- src/sys/dev/sysmon/sysmon_power.c:1.49	Tue Jan  6 15:39:54 2015
+++ src/sys/dev/sysmon/sysmon_power.c	Sat Apr  4 15:25:16 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.49 2015/01/06 15:39:54 bouyer Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.50 2015/04/04 15:25:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.49 2015/01/06 15:39:54 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.50 2015/04/04 15:25:16 riastradh Exp $");
 
 #include "opt_compat_netbsd.h"
 #include 
@@ -800,6 +800,7 @@ sysmon_penvsys_event(struct penvsys_stat
 
 		if (sysmon_power_daemon_task(ped, pes, event) == 0)
 			return;
+		kmem_free(ped, sizeof(*ped));
 	}
 
 	switch (pes->pes_type) {
@@ -954,6 +955,7 @@ sysmon_pswitch_event(struct sysmon_pswit
 
 		if (sysmon_power_daemon_task(ped, smpsw, event) == 0)
 			return;
+		kmem_free(ped, sizeof(*ped));
 	}
 	
 	switch (smpsw->smpsw_type) {



CVS commit: src/sys/dev/sysmon

2015-04-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr  4 15:29:59 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
don't forget to free the dictionary.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.50 src/sys/dev/sysmon/sysmon_power.c:1.51
--- src/sys/dev/sysmon/sysmon_power.c:1.50	Sat Apr  4 11:25:16 2015
+++ src/sys/dev/sysmon/sysmon_power.c	Sat Apr  4 11:29:59 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.50 2015/04/04 15:25:16 riastradh Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.51 2015/04/04 15:29:59 christos Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.50 2015/04/04 15:25:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.51 2015/04/04 15:29:59 christos Exp $");
 
 #include "opt_compat_netbsd.h"
 #include 
@@ -800,6 +800,8 @@ sysmon_penvsys_event(struct penvsys_stat
 
 		if (sysmon_power_daemon_task(ped, pes, event) == 0)
 			return;
+		/* We failed */
+		prop_object_release(ped->dict);
 		kmem_free(ped, sizeof(*ped));
 	}
 



CVS commit: src/sys/dev/sysmon

2015-04-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr  4 15:31:17 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_power.c

Log Message:
another missing free dict.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/sysmon/sysmon_power.c

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_power.c
diff -u src/sys/dev/sysmon/sysmon_power.c:1.51 src/sys/dev/sysmon/sysmon_power.c:1.52
--- src/sys/dev/sysmon/sysmon_power.c:1.51	Sat Apr  4 11:29:59 2015
+++ src/sys/dev/sysmon/sysmon_power.c	Sat Apr  4 11:31:17 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_power.c,v 1.51 2015/04/04 15:29:59 christos Exp $	*/
+/*	$NetBSD: sysmon_power.c,v 1.52 2015/04/04 15:31:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 2007 Juan Romero Pardines.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.51 2015/04/04 15:29:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_power.c,v 1.52 2015/04/04 15:31:17 christos Exp $");
 
 #include "opt_compat_netbsd.h"
 #include 
@@ -957,6 +957,8 @@ sysmon_pswitch_event(struct sysmon_pswit
 
 		if (sysmon_power_daemon_task(ped, smpsw, event) == 0)
 			return;
+		/* We failed */
+		prop_object_release(ped->dict);
 		kmem_free(ped, sizeof(*ped));
 	}
 	



CVS commit: src/sys/dev/sysmon

2015-04-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Apr 18 10:49:32 UTC 2015

Modified Files:
src/sys/dev/sysmon: swwdog.c

Log Message:
Update attach/detach routines and provide MODULE interface.

Confirmed that atf tests (which run via rump) still pass, and also
confirmed that panic/reboot work in both monolithic kernel and
loaded module.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/sysmon/swwdog.c

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/swwdog.c
diff -u src/sys/dev/sysmon/swwdog.c:1.13 src/sys/dev/sysmon/swwdog.c:1.14
--- src/sys/dev/sysmon/swwdog.c:1.13	Sun Apr 13 13:19:50 2014
+++ src/sys/dev/sysmon/swwdog.c	Sat Apr 18 10:49:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: swwdog.c,v 1.13 2014/04/13 13:19:50 pgoyette Exp $	*/
+/*	$NetBSD: swwdog.c,v 1.14 2015/04/18 10:49:31 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.13 2014/04/13 13:19:50 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.14 2015/04/18 10:49:31 pgoyette Exp $");
 
 /*
  *
@@ -41,8 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1
  *
  */
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -50,41 +50,58 @@ __KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1
 #include 
 #include 
 #include 
+#include 
 #include 
 
-#include "ioconf.h"
+#ifndef _MODULE
+#include "opt_modular.h"
+#endif
 
 struct swwdog_softc {
-	device_t sc_dev;
-	struct sysmon_wdog sc_smw;
-	struct callout sc_c;
-	int sc_wdog_armed;
+	device_t		sc_dev;
+	struct sysmon_wdog	sc_smw;
+	struct callout		sc_c;
+	int			sc_armed;
 };
 
-void		swwdogattach(int);
+bool	swwdog_reboot = false;	/* false --> panic , true  --> reboot */
 
-static int	swwdog_match(device_t, cfdata_t, void *);
-static void	swwdog_attach(device_t, device_t, void *);
-static int	swwdog_detach(device_t, int);
-static bool	swwdog_suspend(device_t, const pmf_qual_t *);
+static struct workqueue *wq;
+static device_t		swwdog_dev;
 
-static int swwdog_setmode(struct sysmon_wdog *);
-static int swwdog_tickle(struct sysmon_wdog *);
+MODULE(MODULE_CLASS_DRIVER, swwdog, NULL);
 
-static int swwdog_arm(struct swwdog_softc *);
-static int swwdog_disarm(struct swwdog_softc *);
+#ifdef _LKM
+CFDRIVER_DECL(swwdog, DV_DULL, NULL);
+#endif
 
-static void swwdog_panic(void *);
+int swwdogattach(int);
 
-bool swwdog_reboot = false;		/* set for panic instead of reboot */
+static int	swwdog_setmode(struct sysmon_wdog *);
+static int	swwdog_tickle(struct sysmon_wdog *);
+static bool	swwdog_suspend(device_t, const pmf_qual_t *);
+static int	swwdog_arm(struct swwdog_softc *);
+static int	swwdog_disarm(struct swwdog_softc *);
 
-#define	SWDOG_DEFAULT	60		/* 60-second default period */
+static void	swwdog_panic(void *);
+
+static void	swwdog_sysctl_setup(void);
+static struct sysctllog *swwdog_sysctllog = NULL;
+
+static int	swwdog_match(device_t, cfdata_t, void *);
+static void	swwdog_attach(device_t, device_t, void *);
+static int	swwdog_detach(device_t, int);
+static bool	swwdog_suspend(device_t, const pmf_qual_t *);
+
+static int	swwdog_init(void *);
+static int	swwdog_fini(void *);
+static int	swwdog_modcmd(modcmd_t, void *);
 
 CFATTACH_DECL_NEW(swwdog, sizeof(struct swwdog_softc),
 	swwdog_match, swwdog_attach, swwdog_detach, NULL);
+extern struct cfdriver swwdog_cd;
 
-static void swwdog_sysctl_setup(void);
-static struct sysctllog *swwdog_sysctllog;
+#define	SWDOG_DEFAULT	60		/* 60-second default period */
 
 static void
 doreboot(struct work *wrkwrkwrk, void *p)
@@ -93,41 +110,51 @@ doreboot(struct work *wrkwrkwrk, void *p
 	cpu_reboot(0, NULL);
 }
 
-static struct workqueue *wq;
-
-void
+int
 swwdogattach(int n __unused)
 {
-	int err;
+	int error;
 	static struct cfdata cf;
 
+printf("%s: entered\n", __func__); /* XXX PRG */
 	if (workqueue_create(&wq, "swwreboot", doreboot, NULL,
 	PRI_NONE, IPL_NONE, 0) != 0) {
 		aprint_error("failed to create swwdog reboot wq");
+		return 1;
 	}
 
-	err = config_cfattach_attach(swwdog_cd.cd_name, &swwdog_ca);
-	if (err) {
-		aprint_error("%s: couldn't register cfattach: %d\n",
-		swwdog_cd.cd_name, err);
-		config_cfdriver_detach(&swwdog_cd);
+	error = config_cfattach_attach(swwdog_cd.cd_name, &swwdog_ca);
+	if (error) {
+		aprint_error("%s: unable to attach cfattach\n",
+		swwdog_cd.cd_name);
 		workqueue_destroy(wq);
-		return;
+		return error;
 	}
 
 	cf.cf_name = swwdog_cd.cd_name;
 	cf.cf_atname = swwdog_cd.cd_name;
 	cf.cf_unit = 0;
 	cf.cf_fstate = FSTATE_STAR;
-
-	(void)config_attach_pseudo(&cf);
-
-	return;
+	cf.cf_pspec = NULL;
+	cf.cf_loc = NULL;
+	cf.cf_flags = 0;
+
+	swwdog_dev = config_attach_pseudo(&cf);
+
+printf("%s: swwdog_dev = 0x%p\n", __func__, swwdog_dev); /* XXX PRG */
+	if (swwdog_dev == NULL) {
+		config_cfattach_detach(swwdog_cd.cd_name, &swwdog_ca);
+		workque

CVS commit: src/sys/dev/sysmon

2015-04-18 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Apr 18 14:44:44 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_envsys_events.c sysmonvar.h

Log Message:
use unsigned type for flag bits.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/dev/sysmon/sysmon_envsys_events.c
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/sysmon/sysmonvar.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_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.114 src/sys/dev/sysmon/sysmon_envsys_events.c:1.115
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.114	Sat Mar 14 09:52:49 2015
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Apr 18 14:44:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.114 2015/03/14 09:52:49 hannken Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.115 2015/04/18 14:44:44 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.114 2015/03/14 09:52:49 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.115 2015/04/18 14:44:44 mlelstv Exp $");
 
 #include 
 #include 
@@ -784,7 +784,7 @@ sme_events_worker(struct work *wk, void 
 	}
 
 	DPRINTFOBJ(("%s: (%s) desc=%s sensor=%d type=%d state=%d units=%d "
-	"value_cur=%d upropset=%d\n", __func__, sme->sme_name, edata->desc,
+	"value_cur=%d upropset=0x%04x\n", __func__, sme->sme_name, edata->desc,
 	edata->sensor, see->see_type, edata->state, edata->units,
 	edata->value_cur, edata->upropset));
 

Index: src/sys/dev/sysmon/sysmonvar.h
diff -u src/sys/dev/sysmon/sysmonvar.h:1.47 src/sys/dev/sysmon/sysmonvar.h:1.48
--- src/sys/dev/sysmon/sysmonvar.h:1.47	Mon Apr 13 16:33:25 2015
+++ src/sys/dev/sysmon/sysmonvar.h	Sat Apr 18 14:44:44 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmonvar.h,v 1.47 2015/04/13 16:33:25 riastradh Exp $	*/
+/*	$NetBSD: sysmonvar.h,v 1.48 2015/04/18 14:44:44 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -104,7 +104,7 @@ struct envsys_data {
 	int32_t		value_min;	/* min value */
 	int32_t		private;	/* private data for drivers */
 	sysmon_envsys_lim_t limits;	/* thresholds for monitoring */
-	int		upropset;	/* userland property set? */
+	uint32_t	upropset;	/* userland property set? */
 	krndsource_t	rnd_src;	/* source element for rnd(4) */
 	char		desc[ENVSYS_DESCLEN];	/* sensor description */
 };



CVS commit: src/sys/dev/sysmon

2015-04-18 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Apr 18 22:56:52 UTC 2015

Modified Files:
src/sys/dev/sysmon: swwdog.c

Log Message:
Remove some debugging printf()s that were erroneously committed.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/sysmon/swwdog.c

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/swwdog.c
diff -u src/sys/dev/sysmon/swwdog.c:1.14 src/sys/dev/sysmon/swwdog.c:1.15
--- src/sys/dev/sysmon/swwdog.c:1.14	Sat Apr 18 10:49:31 2015
+++ src/sys/dev/sysmon/swwdog.c	Sat Apr 18 22:56:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: swwdog.c,v 1.14 2015/04/18 10:49:31 pgoyette Exp $	*/
+/*	$NetBSD: swwdog.c,v 1.15 2015/04/18 22:56:52 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.14 2015/04/18 10:49:31 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.15 2015/04/18 22:56:52 pgoyette Exp $");
 
 /*
  *
@@ -116,7 +116,6 @@ swwdogattach(int n __unused)
 	int error;
 	static struct cfdata cf;
 
-printf("%s: entered\n", __func__); /* XXX PRG */
 	if (workqueue_create(&wq, "swwreboot", doreboot, NULL,
 	PRI_NONE, IPL_NONE, 0) != 0) {
 		aprint_error("failed to create swwdog reboot wq");
@@ -141,7 +140,6 @@ printf("%s: entered\n", __func__); /* XX
 
 	swwdog_dev = config_attach_pseudo(&cf);
 
-printf("%s: swwdog_dev = 0x%p\n", __func__, swwdog_dev); /* XXX PRG */
 	if (swwdog_dev == NULL) {
 		config_cfattach_detach(swwdog_cd.cd_name, &swwdog_ca);
 		workqueue_destroy(wq);
@@ -154,7 +152,6 @@ static int
 swwdog_match(device_t parent, cfdata_t data, void *aux)
 {
 
-printf("%s: entered\n", __func__); /* XXX PRG */
 	return 1;
 }
 
@@ -163,7 +160,6 @@ swwdog_attach(device_t parent, device_t 
 {
 	struct swwdog_softc *sc = device_private(self);
 
-printf("%s: entered\n", __func__); /* XXX PRG */
 	if (workqueue_create(&wq, "swwreboot", doreboot, NULL,
 	PRI_NONE, IPL_NONE, 0) != 0) {
 		aprint_error_dev(self, "failed to create reboot workqueue");
@@ -200,7 +196,6 @@ swwdog_detach(device_t self, int flags)
 {
 	struct swwdog_softc *sc = device_private(self);
 
-printf("%s: entered\n", __func__); /* XXX PRG */
 	pmf_device_deregister(self);
 	swwdog_disarm(sc);
 	sysctl_teardown(&swwdog_sysctllog);
@@ -365,7 +360,6 @@ swwdog_modcmd(modcmd_t cmd, void *arg)
 {
 	int ret;
  
-printf("%s: cmd %d\n", __func__, cmd); /* XXX PRG */
 	switch (cmd) {
 	case MODULE_CMD_INIT:
 		ret = swwdog_init(arg);



CVS commit: src/sys/dev/sysmon

2015-04-23 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Apr 23 23:22:03 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon.c sysmon_envsys.c sysmon_power.c
sysmon_taskq.c sysmon_wdog.c sysmonvar.h
Removed Files:
src/sys/dev/sysmon: sysmonconf.h

Log Message:
Modularize sysmon and its components


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/sysmon/sysmon.c
cvs rdiff -u -r1.130 -r1.131 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/sysmon/sysmon_power.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/sysmon/sysmon_taskq.c
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/sysmon/sysmon_wdog.c
cvs rdiff -u -r1.3 -r0 src/sys/dev/sysmon/sysmonconf.h
cvs rdiff -u -r1.48 -r1.49 src/sys/dev/sysmon/sysmonvar.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.c
diff -u src/sys/dev/sysmon/sysmon.c:1.19 src/sys/dev/sysmon/sysmon.c:1.20
--- src/sys/dev/sysmon/sysmon.c:1.19	Fri Jul 25 08:10:39 2014
+++ src/sys/dev/sysmon/sysmon.c	Thu Apr 23 23:22:03 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon.c,v 1.19 2014/07/25 08:10:39 dholland Exp $	*/
+/*	$NetBSD: sysmon.c,v 1.20 2015/04/23 23:22:03 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.19 2014/07/25 08:10:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.20 2015/04/23 23:22:03 pgoyette Exp $");
 
 #include 
 #include 
@@ -49,9 +49,11 @@ __KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
-#include 
 
 dev_type_open(sysmonopen);
 dev_type_close(sysmonclose);
@@ -75,6 +77,97 @@ const struct cdevsw sysmon_cdevsw = {
 	.d_flag = D_OTHER | D_MPSAFE
 };
 
+static int	sysmon_match(device_t, cfdata_t, void *);
+static void	sysmon_attach(device_t, device_t, void *);
+static int	sysmon_detach(device_t, int);
+
+static int	sysmon_modcmd(modcmd_t, void *); 
+
+CFDRIVER_DECL(sysmon, DV_DULL, NULL);
+
+/*
+ * Info about our minor "devices"
+ */
+static struct sysmon_opvec	*sysmon_opvec_table[] = { NULL, NULL, NULL };
+static int			sysmon_refcnt[] = { 0, 0, 0 };
+static const char		*sysmon_mod[] = { "sysmon_envsys",
+		  "sysmon_wdog",
+		  "sysmon_power" };
+
+struct sysmon_softc { 
+	device_t sc_dev;
+	kmutex_t sc_minor_mtx;
+}; 
+
+static device_t sysmon_dev = NULL;
+
+CFATTACH_DECL_NEW(sysmon, sizeof(struct sysmon_softc),
+sysmon_match, sysmon_attach, sysmon_detach, NULL);
+extern struct cfdriver sysmon_cd;
+
+static int
+sysmon_match(device_t parent, cfdata_t data, void *aux)   
+{
+
+	return 1;
+}
+
+static void
+sysmon_attach(device_t parent, device_t self, void *aux)
+{
+
+struct sysmon_softc *sc = device_private(self);
+
+sc->sc_dev = self;
+
+	mutex_init(&sc->sc_minor_mtx, MUTEX_DEFAULT, IPL_NONE);
+}
+
+static int
+sysmon_detach(device_t self, int flags)
+{
+struct sysmon_softc *sc = device_private(self);
+
+	mutex_destroy(&sc->sc_minor_mtx);
+	return 0;
+}
+
+/*
+ * sysmon_attach_minor
+ *
+ *	Attach a minor device for wdog, power, or envsys.  Manage a
+ *	reference count so we can prevent the device from being
+ *	detached if there are still users with the minor device opened.
+ *
+ *	If the opvec argument is NULL, this is a request to detach the
+ *	minor device - make sure the refcnt is zero!
+ */
+int
+sysmon_attach_minor(int minor, struct sysmon_opvec *opvec)
+{
+	struct sysmon_softc *sc = device_private(sysmon_dev);
+	int ret;
+
+	mutex_enter(&sc->sc_minor_mtx);
+	if (opvec) {
+		if (sysmon_opvec_table[minor] == NULL) {
+			sysmon_refcnt[minor] = 0;
+			sysmon_opvec_table[minor] = opvec;
+			ret = 0;
+		} else
+			ret = EEXIST;
+	} else {
+		if (sysmon_refcnt[minor] == 0) {
+			sysmon_opvec_table[minor] = NULL;
+			ret = 0;
+		} else
+			ret = EBUSY;
+	}
+
+	mutex_exit(&sc->sc_minor_mtx);
+	return ret;
+}
+
 /*
  * sysmonopen:
  *
@@ -83,28 +176,33 @@ const struct cdevsw sysmon_cdevsw = {
 int
 sysmonopen(dev_t dev, int flag, int mode, struct lwp *l)
 {
+	struct sysmon_softc *sc = device_private(sysmon_dev);
 	int error;
 
+	mutex_enter(&sc->sc_minor_mtx);
+
 	switch (minor(dev)) {
-#if NSYSMON_ENVSYS > 0
 	case SYSMON_MINOR_ENVSYS:
-		error = sysmonopen_envsys(dev, flag, mode, l);
-		break;
-#endif
-#if NSYSMON_WDOG > 0
 	case SYSMON_MINOR_WDOG:
-		error = sysmonopen_wdog(dev, flag, mode, l);
-		break;
-#endif
-#if NSYSMON_POWER > 0
 	case SYSMON_MINOR_POWER:
-		error = sysmonopen_power(dev, flag, mode, l);
+		if (sysmon_opvec_table[minor(dev)] == NULL) {
+			mutex_exit(&sc->sc_minor_mtx);
+			error = module_autoload(sysmon_mod[minor(dev)],
+		MODULE_CLASS_MISC);
+			mutex_enter(&sc->sc_minor_mtx);
+			if (sysmon_opvec_table[minor(dev)] == NULL)
+error = ENODEV;
+		}
+		error = (sysmon_opvec_table[minor(dev)]->so_open)(dev, flag,
+		mode, l);

CVS commit: src/sys/dev/sysmon

2015-04-23 Thread Alistair G. Crooks
Module Name:src
Committed By:   agc
Date:   Fri Apr 24 00:04:47 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_taskq.c

Log Message:
It's a function returning void; don't return an error code.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/sysmon/sysmon_taskq.c

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_taskq.c
diff -u src/sys/dev/sysmon/sysmon_taskq.c:1.15 src/sys/dev/sysmon/sysmon_taskq.c:1.16
--- src/sys/dev/sysmon/sysmon_taskq.c:1.15	Thu Apr 23 23:22:03 2015
+++ src/sys/dev/sysmon/sysmon_taskq.c	Fri Apr 24 00:04:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_taskq.c,v 1.15 2015/04/23 23:22:03 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_taskq.c,v 1.16 2015/04/24 00:04:47 agc Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_taskq.c,v 1.15 2015/04/23 23:22:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_taskq.c,v 1.16 2015/04/24 00:04:47 agc Exp $");
 
 #include 
 #include 
@@ -139,7 +139,7 @@ sysmon_task_queue_fini(void)
 {
 
 	if (sysmon_task_queue_initialized > 1)
-		return EBUSY;
+		return;
 
 	mutex_enter(&sysmon_task_queue_mtx);
 



CVS commit: src/sys/dev/sysmon

2015-04-23 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Apr 24 00:31:04 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_taskq.c sysmon_taskq.h

Log Message:
This really does need to return an error code, so change the
sysmon_task_queue_fini() function to have a non-void type.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/sysmon/sysmon_taskq.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/sysmon/sysmon_taskq.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_taskq.c
diff -u src/sys/dev/sysmon/sysmon_taskq.c:1.16 src/sys/dev/sysmon/sysmon_taskq.c:1.17
--- src/sys/dev/sysmon/sysmon_taskq.c:1.16	Fri Apr 24 00:04:47 2015
+++ src/sys/dev/sysmon/sysmon_taskq.c	Fri Apr 24 00:31:04 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_taskq.c,v 1.16 2015/04/24 00:04:47 agc Exp $	*/
+/*	$NetBSD: sysmon_taskq.c,v 1.17 2015/04/24 00:31:04 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_taskq.c,v 1.16 2015/04/24 00:04:47 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_taskq.c,v 1.17 2015/04/24 00:31:04 pgoyette Exp $");
 
 #include 
 #include 
@@ -134,12 +134,12 @@ sysmon_task_queue_init(void)
  *
  *	Tear town the sysmon task queue.
  */
-void
+int
 sysmon_task_queue_fini(void)
 {
 
 	if (sysmon_task_queue_initialized > 1)
-		return;
+		return EBUSY;
 
 	mutex_enter(&sysmon_task_queue_mtx);
 
@@ -151,6 +151,8 @@ sysmon_task_queue_fini(void)
 			&sysmon_task_queue_mtx);
 
 	mutex_exit(&sysmon_task_queue_mtx);
+
+	return 0;
 }
 
 /*
@@ -250,8 +252,7 @@ sysmon_taskq_modcmd(modcmd_t cmd, void *
 		break;
  
 	case MODULE_CMD_FINI: 
-		sysmon_task_queue_fini();
-		ret = 0;
+		ret = sysmon_task_queue_fini();
 		break;
  
 	case MODULE_CMD_STAT:

Index: src/sys/dev/sysmon/sysmon_taskq.h
diff -u src/sys/dev/sysmon/sysmon_taskq.h:1.2 src/sys/dev/sysmon/sysmon_taskq.h:1.3
--- src/sys/dev/sysmon/sysmon_taskq.h:1.2	Sat Jul 21 23:15:17 2007
+++ src/sys/dev/sysmon/sysmon_taskq.h	Fri Apr 24 00:31:04 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_taskq.h,v 1.2 2007/07/21 23:15:17 xtraeme Exp $	*/
+/*	$NetBSD: sysmon_taskq.h,v 1.3 2015/04/24 00:31:04 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
 
 void	sysmon_task_queue_preinit(void);
 void	sysmon_task_queue_init(void);
-void	sysmon_task_queue_fini(void);
+int	sysmon_task_queue_fini(void);
 int	sysmon_task_queue_sched(u_int, void (*)(void *), void *);
 
 #endif /* _DEV_SYSMON_SYSMON_TASKQ_H_ */



CVS commit: src/sys/dev/sysmon

2015-04-23 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Apr 24 03:32:25 UTC 2015

Modified Files:
src/sys/dev/sysmon: sysmon_envsys.c

Log Message:
Remove a left-over debugging printf()


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/dev/sysmon/sysmon_envsys.c

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.131 src/sys/dev/sysmon/sysmon_envsys.c:1.132
--- src/sys/dev/sysmon/sysmon_envsys.c:1.131	Thu Apr 23 23:22:03 2015
+++ src/sys/dev/sysmon/sysmon_envsys.c	Fri Apr 24 03:32:25 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.131 2015/04/23 23:22:03 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.132 2015/04/24 03:32:25 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.131 2015/04/23 23:22:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.132 2015/04/24 03:32:25 pgoyette Exp $");
 
 #include 
 #include 
@@ -877,7 +877,6 @@ out2:
 		SLIST_REMOVE_HEAD(&sme_evdrv_list, evdrv_head);
 		kmem_free(evdv, sizeof(*evdv));
 	}
-printf("%s: finished, error %d\n", __func__, error);
 	if (!error)
 		return 0;
 



  1   2   >