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 <sys/cdefs.h>
-__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 <sys/param.h>
 #include <sys/types.h>
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
 #include <sys/types.h>
@@ -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 == 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 EINVAL;
 	}
 	
 	sdict = prop_array_get(array, edata->sensor);
 	if (sdict == NULL) {
-		sysmon_envsys_release(sme, false);
 		return EINVAL;
 	}
 
@@ -576,10 +592,9 @@
 		    see->see_type == PENVSYS_EVENT_LIMITS)
 			break;
 	}
-	if (see == NULL) {
-		sysmon_envsys_release(sme, false);
+	if (see == NULL)
 		return EINVAL;
-	}
+
 	/* Get new limit values */
 	(*sme->sme_get_limits)(sme, edata, &lims, &props);
 
@@ -587,7 +602,6 @@
 	sme_event_register(sdict, edata, sme, &lims, props,
 			   PENVSYS_EVENT_LIMITS, see->see_pes.pes_type);
 
-	sysmon_envsys_release(sme, false);
 	return 0;
 }
 

Index: src/sys/dev/sysmon/sysmon_envsysvar.h
diff -u src/sys/dev/sysmon/sysmon_envsysvar.h:1.35 src/sys/dev/sysmon/sysmon_envsysvar.h:1.36
--- src/sys/dev/sysmon/sysmon_envsysvar.h:1.35	Thu Apr  1 12:16:14 2010
+++ src/sys/dev/sysmon/sysmon_envsysvar.h	Sat Apr 10 19:01:01 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsysvar.h,v 1.35 2010/04/01 12:16:14 pgoyette Exp $ */
+/* $NetBSD: sysmon_envsysvar.h,v 1.36 2010/04/10 19:01:01 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -132,6 +132,7 @@
 void	sme_events_check(void *);
 void	sme_events_worker(struct work *, void *);
 void	sme_deliver_event(sme_event_t *);
+int	sme_update_limits(struct sysmon_envsys *, envsys_data_t *);
 
 /* 
  * common functions to create/update objects in a dictionary.

Reply via email to