The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/xscale/i80321/i80321_wdog.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: i80321_wdog.c,v 1.6 2003/07/15 00:24:54 lukem Exp $    */
    2 
    3 /*-
    4  * Copyright (c) 2005 Olivier Houchard
    5  * Copyright (c) 2002 Wasabi Systems, Inc.
    6  * All rights reserved.
    7  *
    8  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed for the NetBSD Project by
   21  *      Wasabi Systems, Inc.
   22  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
   23  *    or promote products derived from this software without specific prior
   24  *    written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
   27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 /*
   40  * Watchdog timer support for the Intel i80321 I/O processor.
   41  */
   42 
   43 #include <sys/cdefs.h>
   44 __FBSDID("$FreeBSD: releng/6.0/sys/arm/xscale/i80321/i80321_wdog.c 140307 2005-01-15 18:38:10Z cognet $");
   45 
   46 #include <sys/param.h>
   47 #include <sys/systm.h>
   48 #include <sys/watchdog.h>
   49 #include <sys/bus.h>
   50 #include <sys/kernel.h>
   51 #include <sys/module.h>
   52 
   53 #include <machine/bus.h>
   54 #include <machine/cpufunc.h>
   55 #include <machine/machdep.h>
   56 
   57 #include <arm/xscale/i80321/i80321reg.h>
   58 #include <arm/xscale/i80321/i80321var.h>
   59 
   60 
   61 struct iopwdog_softc {
   62         device_t dev;
   63         int armed;
   64         int wdog_period;
   65         struct callout_handle wdog_callout;
   66 };
   67 
   68 static __inline void
   69 wdtcr_write(uint32_t val)
   70 {
   71 
   72         __asm __volatile("mcr p6, 0, %0, c7, c1, 0"
   73                 :
   74                 : "r" (val));
   75 }
   76 
   77 static void
   78 iopwdog_tickle(void *arg)
   79 {
   80         struct iopwdog_softc *sc = arg;
   81 
   82         if (!sc->armed)
   83                 return;
   84         wdtcr_write(WDTCR_ENABLE1);
   85         wdtcr_write(WDTCR_ENABLE2);
   86         sc->wdog_callout = timeout(iopwdog_tickle, sc,
   87             hz * (sc->wdog_period - 1));
   88 }
   89 
   90 static int
   91 iopwdog_probe(device_t dev)
   92 {
   93         struct iopwdog_softc *sc = device_get_softc(dev);
   94         char buf[128];
   95 
   96         /*
   97          * XXX Should compute the period based on processor speed.
   98          * For a 600MHz XScale core, the wdog must be tickled approx.
   99          * every 7 seconds.
  100          */
  101 
  102         sc->wdog_period = 7;
  103         sprintf(buf, "i80321 Watchdog, must be tickled every %d seconds",
  104             sc->wdog_period);
  105         device_set_desc_copy(dev, buf);
  106 
  107         return (0);
  108 }
  109 
  110 static void
  111 iopwdog_watchdog_fn(void *private, u_int cmd, int *error)
  112 {
  113         struct iopwdog_softc *sc = private;
  114 
  115         if (cmd == 0)
  116                 return;
  117         if ((((uint64_t)1 << (cmd & WD_INTERVAL))) >
  118             (uint64_t)sc->wdog_period * 1000000000)
  119                 return;
  120         sc->armed = 1;
  121         iopwdog_tickle(sc);
  122         *error = 0;
  123 }
  124 
  125 static int
  126 iopwdog_attach(device_t dev)
  127 {
  128         struct iopwdog_softc *sc = device_get_softc(dev);
  129         
  130         sc->dev = dev;
  131         sc->armed = 0;
  132         EVENTHANDLER_REGISTER(watchdog_list, iopwdog_watchdog_fn, sc, 0);
  133         return (0);
  134 }
  135 
  136 static device_method_t iopwdog_methods[] = {
  137         DEVMETHOD(device_probe, iopwdog_probe),
  138         DEVMETHOD(device_attach, iopwdog_attach),
  139         {0, 0},
  140 };
  141 
  142 static driver_t iopwdog_driver = {
  143         "iopwdog",
  144         iopwdog_methods,
  145         sizeof(struct iopwdog_softc),
  146 };
  147 static devclass_t iopwdog_devclass;
  148 
  149 DRIVER_MODULE(iopwdog, iq, iopwdog_driver, iopwdog_devclass, 0, 0);

Cache object: ceb61f10d27390920a931b9ceaf42d57


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.