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/i386/isa/pmtimer.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 /*-
    2  * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  *      $FreeBSD: releng/5.0/sys/i386/isa/pmtimer.c 105730 2002-10-22 17:30:52Z jhb $
   27  */
   28 
   29 /*
   30  * Timer device driver for power management events.
   31  * The code for suspend/resume is derived from APM device driver.
   32  */
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/bus.h>
   37 #include <sys/kernel.h>
   38 #include <sys/syslog.h>
   39 #include <machine/clock.h>
   40 
   41 #include <isa/isavar.h>
   42 
   43 static devclass_t pmtimer_devclass;
   44 
   45 /* reject any PnP devices for now */
   46 static struct isa_pnp_id pmtimer_ids[] = {
   47         {0}
   48 };
   49 
   50 static void
   51 pmtimer_identify(driver_t *driver, device_t parent)
   52 {
   53         device_t child;
   54 
   55         /*
   56          * Only add a child if one doesn't exist already.
   57          */
   58         child = devclass_get_device(pmtimer_devclass, 0);
   59         if (child == NULL) {
   60                 child = BUS_ADD_CHILD(parent, 0, "pmtimer", 0);
   61                 if (child == NULL)
   62                         panic("pmtimer_identify");
   63         }
   64 }
   65 
   66 static int
   67 pmtimer_probe(device_t dev)
   68 {
   69 
   70         if (ISA_PNP_PROBE(device_get_parent(dev), dev, pmtimer_ids) == ENXIO) {
   71                 return (ENXIO);
   72         }
   73 
   74         /* only one instance always */
   75         return (device_get_unit(dev));
   76 }
   77 
   78 static struct timeval suspend_time;
   79 static struct timeval diff_time;
   80 
   81 static int
   82 pmtimer_suspend(device_t dev)
   83 {
   84         int     pl;
   85 
   86         pl = splsoftclock();
   87         microtime(&diff_time);
   88         inittodr(0);
   89         microtime(&suspend_time);
   90         timevalsub(&diff_time, &suspend_time);
   91         splx(pl);
   92         return (0);
   93 }
   94 
   95 static int
   96 pmtimer_resume(device_t dev)
   97 {
   98         int pl;
   99         u_int second, minute, hour;
  100         struct timeval resume_time, tmp_time;
  101 
  102         /* modified for adjkerntz */
  103         pl = splsoftclock();
  104         timer_restore();                /* restore the all timers */
  105         inittodr(0);                    /* adjust time to RTC */
  106         microtime(&resume_time);
  107         getmicrotime(&tmp_time);
  108         timevaladd(&tmp_time, &diff_time);
  109 
  110 #ifdef FIXME
  111         /* XXX THIS DOESN'T WORK!!! */
  112         time = tmp_time;
  113 #endif
  114 
  115 #ifdef PMTIMER_FIXUP_CALLTODO
  116         /* Calculate the delta time suspended */
  117         timevalsub(&resume_time, &suspend_time);
  118         /* Fixup the calltodo list with the delta time. */
  119         adjust_timeout_calltodo(&resume_time);
  120 #endif /* PMTIMER_FIXUP_CALLTODOK */
  121         splx(pl);
  122 #ifndef PMTIMER_FIXUP_CALLTODO
  123         second = resume_time.tv_sec - suspend_time.tv_sec; 
  124 #else /* PMTIMER_FIXUP_CALLTODO */
  125         /* 
  126          * We've already calculated resume_time to be the delta between 
  127          * the suspend and the resume. 
  128          */
  129         second = resume_time.tv_sec; 
  130 #endif /* PMTIMER_FIXUP_CALLTODO */
  131         hour = second / 3600;
  132         second %= 3600;
  133         minute = second / 60;
  134         second %= 60;
  135         log(LOG_NOTICE, "wakeup from sleeping state (slept %02d:%02d:%02d)\n",
  136                 hour, minute, second);
  137         return (0);
  138 }
  139 
  140 static device_method_t pmtimer_methods[] = {
  141         /* Device interface */
  142         DEVMETHOD(device_identify,      pmtimer_identify),
  143         DEVMETHOD(device_probe,         pmtimer_probe),
  144         DEVMETHOD(device_attach,        bus_generic_attach),
  145         DEVMETHOD(device_suspend,       pmtimer_suspend),
  146         DEVMETHOD(device_resume,        pmtimer_resume),
  147         { 0, 0 }
  148 };
  149 
  150 static driver_t pmtimer_driver = {
  151         "pmtimer",
  152         pmtimer_methods,
  153         1,              /* no softc */
  154 };
  155 
  156 DRIVER_MODULE(pmtimer, isa, pmtimer_driver, pmtimer_devclass, 0, 0);

Cache object: d534e5e9908563ffa0e1d1ac4bc1d263


[ 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.