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/i386/mp_clock.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  * ----------------------------------------------------------------------------
    3  * "THE BEER-WARE LICENSE" (Revision 42):
    4  * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
    5  * can do whatever you want with this stuff. If we meet some day, and you think
    6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
    7  * ----------------------------------------------------------------------------
    8  *
    9  * Just when we thought life were beautiful, reality pops its grim face over
   10  * the edge again:
   11  *
   12  * ] 20. ACPI Timer Errata
   13  * ]
   14  * ]   Problem: The power management timer may return improper result when
   15  * ]   read. Although the timer value settles properly after incrementing,
   16  * ]   while incrementing there is a 3nS window every 69.8nS where the
   17  * ]   timer value is indeterminate (a 4.2% chance that the data will be
   18  * ]   incorrect when read). As a result, the ACPI free running count up
   19  * ]   timer specification is violated due to erroneous reads.  Implication:
   20  * ]   System hangs due to the "inaccuracy" of the timer when used by
   21  * ]   software for time critical events and delays.
   22  * ] 
   23  * ] Workaround: Read the register twice and compare.
   24  * ] Status: This will not be fixed in the PIIX4 or PIIX4E.
   25  *
   26  * The counter is in other words not latched to the PCI bus clock when
   27  * read.  Notice the workaround isn't:  We need to read until we have
   28  * three monotonic samples and then use the middle one, otherwise we are
   29  * not protected against the fact that the bits can be wrong in two
   30  * directions.  If we only cared about monosity two reads would be enough.
   31  *
   32  * $FreeBSD: releng/5.1/sys/i386/i386/mp_clock.c 113173 2003-04-06 18:42:22Z des $
   33  *
   34  */
   35 
   36 /* #include "opt_bus.h" */
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/timetc.h>
   41 #include <sys/kernel.h>
   42 #include <sys/sysctl.h>
   43 #include <sys/bus.h>
   44 
   45 #include <pci/pcivar.h>
   46 
   47 static unsigned piix_get_timecount(struct timecounter *tc);
   48 
   49 static u_int32_t piix_timecounter_address;
   50 static u_int piix_freq = 14318182/4;
   51 
   52 static struct timecounter piix_timecounter = {
   53         piix_get_timecount,
   54         0,
   55         0xffffff,
   56         0,
   57         "PIIX"
   58 };
   59 
   60 
   61 static int
   62 sysctl_machdep_piix_freq(SYSCTL_HANDLER_ARGS)
   63 {
   64         int error;
   65         u_int freq;
   66 
   67         if (piix_timecounter.tc_frequency == 0)
   68                 return (EOPNOTSUPP);
   69         freq = piix_freq;
   70         error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
   71         if (error == 0 && req->newptr != NULL) {
   72                 piix_freq = freq;
   73                 piix_timecounter.tc_frequency = piix_freq;
   74         }
   75         return (error);
   76 }
   77 
   78 SYSCTL_PROC(_machdep, OID_AUTO, piix_freq, CTLTYPE_INT | CTLFLAG_RW,
   79     0, sizeof(u_int), sysctl_machdep_piix_freq, "I", "");
   80 
   81 static unsigned
   82 piix_get_timecount(struct timecounter *tc)
   83 {
   84         unsigned u1, u2, u3;
   85 
   86         u2 = inl(piix_timecounter_address);
   87         u3 = inl(piix_timecounter_address);
   88         do {
   89                 u1 = u2;
   90                 u2 = u3;
   91                 u3 = inl(piix_timecounter_address);
   92         } while (u1 > u2 || u2 > u3);
   93         return (u2);
   94 }
   95 
   96 static int
   97 piix_probe (device_t dev)
   98 {
   99         u_int32_t       d;
  100 
  101         switch (pci_get_devid(dev)) {
  102         case 0x71138086:
  103                 d = pci_read_config(dev, 0x4, 2);
  104                 if (d & 1)
  105                         return (0);
  106                 printf("PIIX I/O space not mapped\n");
  107                 return (ENXIO);
  108         default:
  109                 return (ENXIO);
  110         };
  111         return (ENXIO);
  112 }
  113 
  114 static int
  115 piix_attach (device_t dev)
  116 {
  117         u_int32_t       d;
  118 
  119         d = pci_read_config(dev, 0x40, 4);
  120         piix_timecounter_address = (d & 0xffc0) + 8;
  121         piix_timecounter.tc_frequency = piix_freq;
  122         tc_init(&piix_timecounter);
  123         return (0);
  124 }
  125 
  126 static device_method_t piix_methods[] = {
  127         /* Device interface */
  128         DEVMETHOD(device_probe,         piix_probe),
  129         DEVMETHOD(device_attach,        piix_attach),
  130         { 0, 0 }
  131 };
  132 
  133 static driver_t piix_driver = {
  134         "piix",
  135         piix_methods,
  136         1,
  137 };
  138 
  139 static devclass_t piix_devclass;
  140 
  141 DRIVER_MODULE(piix, pci, piix_driver, piix_devclass, 0, 0);

Cache object: dc66f770b71bd8d87a23fdfe4cda6350


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