From owner-p4-projects@FreeBSD.ORG Wed Jul 4 01:33:40 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E334316A468; Wed, 4 Jul 2007 01:33:39 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B6C6616A41F for ; Wed, 4 Jul 2007 01:33:39 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id A79B613C458 for ; Wed, 4 Jul 2007 01:33:39 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l641XdPJ062432 for ; Wed, 4 Jul 2007 01:33:39 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l641XdlB062429 for perforce@freebsd.org; Wed, 4 Jul 2007 01:33:39 GMT (envelope-from rpaulo@FreeBSD.org) Date: Wed, 4 Jul 2007 01:33:39 GMT Message-Id: <200707040133.l641XdlB062429@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rpaulo@FreeBSD.org using -f From: Rui Paulo To: Perforce Change Reviews Cc: Subject: PERFORCE change 122821 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2007 01:33:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=122821 Change 122821 by rpaulo@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 #include #include +#include #include #include #include #include +#include #include @@ -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 {