PERFORCE change 122821 for review

Rui Paulo rpaulo at FreeBSD.org
Wed Jul 4 01:33:40 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=122821

Change 122821 by rpaulo at rpaulo_epsilon on 2007/07/04 01:33:12

	When an interrupt from the Sudden Motion Sensor occurs call
	devctl_notify() so that we can turn off (standby, suspend) the
	disks.
	This is useful because it allows you to prevent disk damage.
	
	A taskqueue is now created to handle this (devctl_notify()
	can't be called directly from an interrupt handler).
	
	Reviewed by:	attilio	

Affected files ...

.. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#15 edit
.. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#6 edit

Differences ...

==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#15 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#14 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#15 $
  *
  */
 
@@ -42,10 +42,12 @@
 #include <sys/conf.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
+#include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
 #include <sys/sysctl.h>
 #include <sys/systm.h>
+#include <sys/taskqueue.h>
 
 #include <isa/isavar.h>
 
@@ -80,7 +82,7 @@
 static int	asmc_sms_intr(void *);
 static void	asmc_sms_fastintr(void *);
 static void	asmc_sms_printintr(device_t, uint8_t);
-
+static void	asmc_sms_task(void *, int);
 /*
  * Model functions.
  */
@@ -365,6 +367,22 @@
 			"Sudden Motion Sensor Z value");
 
 	/*
+	 * Need a taskqueue to send devctl_notify() events
+	 * when the SMS interrupt us.
+	 *
+	 * PI_REALTIME is used due to the sensitivity of the
+	 * interrupt. An interrupt from the SMS means that the
+	 * disk heads should be turned off as quickly as possible.
+	 */
+	TASK_INIT(&sc->sms_task, 0, asmc_sms_task, sc);
+	sc->sms_tq = taskqueue_create_fast("asmc_taskq", M_WAITOK,
+					   taskqueue_thread_enqueue,
+					   &sc->sms_tq);
+	taskqueue_start_threads(&sc->sms_tq, 1, PI_REALTIME, "%s sms taskq",
+				device_get_nameunit(dev));
+
+
+	/*
 	 * Allocate an IRQ for the SMS.
 	 */
 	sc->sc_rid = 0;
@@ -372,6 +390,7 @@
 					ASMC_IRQ, ASMC_IRQ, 1, RF_ACTIVE);
 	if (sc->sc_res == NULL) {
 		device_printf(dev, "unable to allocate IRQ resource\n");
+		taskqueue_free(sc->sms_tq);
 		goto out;
 	}
 
@@ -406,6 +425,11 @@
 
 	sysctl_ctx_free(&sc->sc_sysctl_ctx);
 
+	if (sc->sms_tq) {
+		taskqueue_drain(sc->sms_tq, &sc->sms_task);
+		taskqueue_free(sc->sms_tq);
+	}
+
 	if (sc->sc_cookie)
 		bus_teardown_intr(dev, sc->sc_res, sc->sc_cookie);
 	if (sc->sc_res)
@@ -773,7 +797,9 @@
 	type = inb(ASMC_INTPORT);
 	mtx_unlock_spin(&sc->sc_mtx);
 
+	sc->sms_intrtype = type;
 	asmc_sms_printintr(dev, type);
+	taskqueue_enqueue(sc->sms_tq, &sc->sms_task);
 
 	return (FILTER_HANDLED);
 }
@@ -789,7 +815,9 @@
 	type = inb(ASMC_INTPORT);
 	mtx_unlock_spin(&sc->sc_mtx);
 
+	sc->sms_intrtype = type;
 	asmc_sms_printintr(dev, type);
+	taskqueue_enqueue_fast(sc->sms_tq, &sc->sms_task);
 }
 
 
@@ -812,6 +840,32 @@
 	}
 }
 
+static void
+asmc_sms_task(void *arg, int pending)
+{
+	struct asmc_softc *sc = (struct asmc_softc *)arg;
+	char notify[16];
+	int type;
+
+	switch (sc->sms_intrtype) {
+	case ASMC_SMS_INTFF:
+		type = 0;
+		break;
+	case ASMC_SMS_INTHA:
+		type = 1;
+		break;
+	case ASMC_SMS_INTSH:
+		type = 2;
+		break;
+	default:
+		type = 255;
+	}
+
+	snprintf(notify, sizeof(notify) - 1, " notify=0x%x", type);
+
+	devctl_notify("ISA", "asmc", "SMS", notify); 
+}
+
 static int
 asmc_mb_sysctl_sms_x(SYSCTL_HANDLER_ARGS)
 {

==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#6 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#5 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#6 $
  *
  */
 
@@ -50,6 +50,10 @@
 	int			sc_rid;
 	struct resource		*sc_res;
 	void			*sc_cookie;
+
+	int			sms_intrtype;
+	struct taskqueue	*sms_tq;
+	struct task		sms_task;
 };
 
 struct asmc_model {


More information about the p4-projects mailing list