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/dev/ic/acpipmtimer.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: acpipmtimer.c,v 1.6 2008/04/08 12:07:25 cegger Exp $ */
    2 
    3 #include <sys/cdefs.h>
    4 __KERNEL_RCSID(0, "$NetBSD: acpipmtimer.c,v 1.6 2008/04/08 12:07:25 cegger Exp $");
    5 
    6 #include <sys/types.h>
    7 
    8 #include <sys/systm.h>
    9 #include <sys/device.h>
   10 #include <sys/malloc.h>
   11 #include <sys/bus.h>
   12 #include <sys/time.h>
   13 #include <sys/timetc.h>
   14 
   15 #include <dev/ic/acpipmtimer.h>
   16 
   17 #define ACPI_PM_TIMER_FREQUENCY 3579545
   18 
   19 struct hwtc {
   20         struct timecounter tc;
   21         bus_space_tag_t t;
   22         bus_space_handle_t h;
   23         bus_size_t off;
   24 };
   25 
   26 static u_int acpihwtimer_read_safe(struct timecounter *);
   27 static u_int acpihwtimer_read_fast(struct timecounter *);
   28 
   29 int
   30 acpipmtimer_attach(struct device *dev,
   31                    bus_space_tag_t t, bus_space_handle_t h, bus_size_t off,
   32                    int flags)
   33 {
   34         struct hwtc *tc;
   35 
   36         tc = malloc(sizeof(struct hwtc), M_DEVBUF, M_WAITOK|M_ZERO);
   37         if (!tc)
   38                 return (-1);
   39 
   40         tc->tc.tc_name = device_xname(dev);
   41         tc->tc.tc_frequency = ACPI_PM_TIMER_FREQUENCY;
   42         if (flags & ACPIPMT_32BIT)
   43                 tc->tc.tc_counter_mask = 0xffffffff;
   44         else
   45                 tc->tc.tc_counter_mask = 0x00ffffff;
   46         if (flags & ACPIPMT_BADLATCH) {
   47                 tc->tc.tc_get_timecount = acpihwtimer_read_safe;
   48                 tc->tc.tc_quality = 900;
   49         } else {
   50                 tc->tc.tc_get_timecount = acpihwtimer_read_fast;
   51                 tc->tc.tc_quality = 1000;
   52         }
   53 
   54         tc->t = t;
   55         tc->h = h;
   56         tc->off = off;
   57 
   58         tc->tc.tc_priv = tc;
   59         tc_init(&tc->tc);
   60         aprint_normal("%s: %d-bit timer\n", tc->tc.tc_name,
   61                       (flags & ACPIPMT_32BIT ? 32 : 24));
   62         return (0);
   63 }
   64 
   65 #define r(h) bus_space_read_4(h->t, h->h, h->off)
   66 
   67 static u_int
   68 acpihwtimer_read_safe(struct timecounter *tc)
   69 {
   70         struct hwtc *h = tc->tc_priv;
   71         uint32_t t1, t2, t3;
   72 
   73         t2 = r(h);
   74         t3 = r(h);
   75         do {
   76                 t1 = t2;
   77                 t2 = t3;
   78                 t3 = r(h);
   79         } while ((t1 > t2) || (t2 > t3));
   80         return (t2);
   81 }
   82 
   83 static u_int
   84 acpihwtimer_read_fast(struct timecounter *tc)
   85 {
   86         struct hwtc *h = tc->tc_priv;
   87 
   88         return r(h);
   89 }

Cache object: e63a438e71bd634ff77308427e9a3ca3


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