2000-10-28 06:59:48 +00:00
|
|
|
/*-
|
2001-07-21 04:08:42 +00:00
|
|
|
* Copyright (c) 2000, 2001 Michael Smith
|
2000-10-28 06:59:48 +00:00
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
2001-07-21 04:08:42 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/timetc.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
#include "acpi.h"
|
2002-10-09 20:38:21 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
2003-08-22 06:06:16 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
2001-07-21 04:08:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A timecounter based on the free-running ACPI timer.
|
|
|
|
*
|
|
|
|
* Based on the i386-only mp_clock.c by <phk@FreeBSD.ORG>.
|
|
|
|
*/
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure */
|
2004-03-03 03:02:17 +00:00
|
|
|
#define _COMPONENT ACPI_TIMER
|
2002-02-23 05:31:38 +00:00
|
|
|
ACPI_MODULE_NAME("TIMER")
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
static device_t acpi_timer_dev;
|
|
|
|
struct resource *acpi_timer_reg;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
static u_int acpi_timer_frequency = 14318182 / 4;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
static void acpi_timer_identify(driver_t *driver, device_t parent);
|
|
|
|
static int acpi_timer_probe(device_t dev);
|
|
|
|
static int acpi_timer_attach(device_t dev);
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
static u_int acpi_timer_get_timecount(struct timecounter *tc);
|
|
|
|
static u_int acpi_timer_get_timecount_safe(struct timecounter *tc);
|
2001-07-21 04:08:42 +00:00
|
|
|
static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS);
|
|
|
|
static void acpi_timer_test(void);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
static u_int read_counter(void);
|
2003-08-28 16:06:30 +00:00
|
|
|
static int test_counter(void);
|
2003-04-30 05:27:01 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static device_method_t acpi_timer_methods[] = {
|
|
|
|
DEVMETHOD(device_identify, acpi_timer_identify),
|
|
|
|
DEVMETHOD(device_probe, acpi_timer_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_timer_attach),
|
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_timer_driver = {
|
|
|
|
"acpi_timer",
|
|
|
|
acpi_timer_methods,
|
2001-07-21 04:08:42 +00:00
|
|
|
0,
|
2000-10-28 06:59:48 +00:00
|
|
|
};
|
|
|
|
|
2002-01-08 06:46:01 +00:00
|
|
|
static devclass_t acpi_timer_devclass;
|
2000-10-28 06:59:48 +00:00
|
|
|
DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0);
|
2004-04-09 18:14:32 +00:00
|
|
|
MODULE_DEPEND(acpi_timer, acpi, 1, 1, 1);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
static struct timecounter acpi_timer_timecounter = {
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
.tc_get_timecount = acpi_timer_get_timecount_safe,
|
|
|
|
.tc_poll_pps = 0,
|
|
|
|
.tc_counter_mask = 0,
|
|
|
|
.tc_frequency = 0,
|
|
|
|
.tc_name = "ACPI",
|
|
|
|
.tc_quality = 1000
|
2001-07-21 04:08:42 +00:00
|
|
|
};
|
|
|
|
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
static u_int
|
2003-04-30 05:27:01 +00:00
|
|
|
read_counter()
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
bus_space_handle_t bsh;
|
|
|
|
bus_space_tag_t bst;
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
uint32_t tv;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
bsh = rman_get_bushandle(acpi_timer_reg);
|
|
|
|
bst = rman_get_bustag(acpi_timer_reg);
|
|
|
|
tv = bus_space_read_4(bst, bsh, 0);
|
|
|
|
bus_space_barrier(bst, bsh, 0, 4, BUS_SPACE_BARRIER_READ);
|
|
|
|
|
|
|
|
return (tv);
|
2003-04-30 05:27:01 +00:00
|
|
|
}
|
2002-02-25 09:51:17 +00:00
|
|
|
|
|
|
|
#define N 2000
|
|
|
|
static int
|
|
|
|
test_counter()
|
|
|
|
{
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
uint32_t last, this;
|
2003-08-28 16:06:30 +00:00
|
|
|
int min, max, n, delta;
|
|
|
|
|
|
|
|
min = 10000000;
|
|
|
|
max = 0;
|
|
|
|
last = read_counter();
|
|
|
|
for (n = 0; n < N; n++) {
|
|
|
|
this = read_counter();
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
delta = acpi_TimerDelta(this, last);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (delta > max)
|
|
|
|
max = delta;
|
|
|
|
else if (delta < min)
|
|
|
|
min = delta;
|
|
|
|
last = this;
|
|
|
|
}
|
|
|
|
if (max - min > 2)
|
|
|
|
n = 0;
|
|
|
|
else if (min < 0 || max == 0)
|
|
|
|
n = 0;
|
|
|
|
else
|
|
|
|
n = 1;
|
|
|
|
if (bootverbose) {
|
|
|
|
printf("ACPI timer looks %s min = %d, max = %d, width = %d\n",
|
|
|
|
n ? "GOOD" : "BAD ",
|
|
|
|
min, max, max - min);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (n);
|
2002-02-25 09:51:17 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
#undef N
|
2001-07-21 04:08:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Locate the ACPI timer using the FADT, set up and allocate the I/O resources
|
|
|
|
* we will be using.
|
|
|
|
*/
|
2000-10-28 06:59:48 +00:00
|
|
|
static void
|
|
|
|
acpi_timer_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
2001-07-21 04:08:42 +00:00
|
|
|
device_t dev;
|
|
|
|
char desc[40];
|
2003-04-30 05:27:01 +00:00
|
|
|
u_long rlen, rstart;
|
|
|
|
int i, j, rid, rtype;
|
2000-12-01 10:18:57 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (acpi_disabled("timer") || AcpiGbl_FADT == NULL)
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
if ((dev = BUS_ADD_CHILD(parent, 0, "acpi_timer", 0)) == NULL) {
|
|
|
|
device_printf(parent, "could not add acpi_timer0\n");
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-07-21 04:08:42 +00:00
|
|
|
acpi_timer_dev = dev;
|
2003-04-30 05:27:01 +00:00
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
rid = 0;
|
2003-04-30 05:27:01 +00:00
|
|
|
rlen = AcpiGbl_FADT->PmTmLen;
|
|
|
|
rtype = (AcpiGbl_FADT->XPmTmrBlk.AddressSpaceId)
|
|
|
|
? SYS_RES_IOPORT : SYS_RES_MEMORY;
|
|
|
|
rstart = AcpiGbl_FADT->XPmTmrBlk.Address;
|
|
|
|
bus_set_resource(dev, rtype, rid, rstart, rlen);
|
2004-03-17 17:50:55 +00:00
|
|
|
acpi_timer_reg = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE);
|
2003-04-30 05:27:01 +00:00
|
|
|
if (acpi_timer_reg == NULL) {
|
|
|
|
device_printf(dev, "couldn't allocate I/O resource (%s 0x%lx)\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
rtype == SYS_RES_IOPORT ? "port" : "mem", rstart);
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
if (AcpiGbl_FADT->TmrValExt != 0)
|
|
|
|
acpi_timer_timecounter.tc_counter_mask = 0xffffffff;
|
|
|
|
else
|
|
|
|
acpi_timer_timecounter.tc_counter_mask = 0x00ffffff;
|
|
|
|
acpi_timer_timecounter.tc_frequency = acpi_timer_frequency;
|
2002-04-17 13:06:36 +00:00
|
|
|
if (testenv("debug.acpi.timer_test"))
|
2001-07-21 04:08:42 +00:00
|
|
|
acpi_timer_test();
|
|
|
|
|
2002-02-25 09:51:17 +00:00
|
|
|
j = 0;
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
2002-02-25 09:51:17 +00:00
|
|
|
j += test_counter();
|
|
|
|
if (j == 10) {
|
|
|
|
acpi_timer_timecounter.tc_name = "ACPI-fast";
|
|
|
|
acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount;
|
|
|
|
} else {
|
|
|
|
acpi_timer_timecounter.tc_name = "ACPI-safe";
|
|
|
|
acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount_safe;
|
|
|
|
}
|
2001-07-21 04:08:42 +00:00
|
|
|
tc_init(&acpi_timer_timecounter);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
sprintf(desc, "%d-bit timer at 3.579545MHz",
|
|
|
|
AcpiGbl_FADT->TmrValExt ? 32 : 24);
|
2000-10-28 06:59:48 +00:00
|
|
|
device_set_desc_copy(dev, desc);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_timer_probe(device_t dev)
|
|
|
|
{
|
2001-07-21 04:08:42 +00:00
|
|
|
if (dev == acpi_timer_dev)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (ENXIO);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_timer_attach(device_t dev)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2001-07-21 04:08:42 +00:00
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
/*
|
2001-08-03 09:52:53 +00:00
|
|
|
* Fetch current time value from reliable hardware.
|
2001-07-21 04:08:42 +00:00
|
|
|
*/
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
static u_int
|
2001-07-21 04:08:42 +00:00
|
|
|
acpi_timer_get_timecount(struct timecounter *tc)
|
|
|
|
{
|
2003-04-30 05:27:01 +00:00
|
|
|
return (read_counter());
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-07-21 04:08:42 +00:00
|
|
|
|
2001-08-03 09:52:53 +00:00
|
|
|
/*
|
|
|
|
* Fetch current time value from hardware that may not correctly
|
|
|
|
* latch the counter.
|
|
|
|
*/
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
static u_int
|
2001-08-03 09:52:53 +00:00
|
|
|
acpi_timer_get_timecount_safe(struct timecounter *tc)
|
|
|
|
{
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
u_int u1, u2, u3;
|
2001-08-03 09:52:53 +00:00
|
|
|
|
2003-04-30 05:27:01 +00:00
|
|
|
u2 = read_counter();
|
|
|
|
u3 = read_counter();
|
2001-08-03 09:52:53 +00:00
|
|
|
do {
|
|
|
|
u1 = u2;
|
|
|
|
u2 = u3;
|
2003-04-30 05:27:01 +00:00
|
|
|
u3 = read_counter();
|
2003-08-28 16:06:30 +00:00
|
|
|
} while (u1 > u2 || u2 > u3 || u3 - u1 > 15);
|
|
|
|
|
2001-08-03 09:52:53 +00:00
|
|
|
return (u2);
|
|
|
|
}
|
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
/*
|
|
|
|
* Timecounter freqency adjustment interface.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
u_int freq;
|
|
|
|
|
|
|
|
if (acpi_timer_timecounter.tc_frequency == 0)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
freq = acpi_timer_frequency;
|
|
|
|
error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
|
|
|
|
if (error == 0 && req->newptr != NULL) {
|
|
|
|
acpi_timer_frequency = freq;
|
|
|
|
acpi_timer_timecounter.tc_frequency = acpi_timer_frequency;
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_machdep, OID_AUTO, acpi_timer_freq, CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
0, sizeof(u_int), acpi_timer_sysctl_freq, "I", "");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test harness for verifying ACPI timer behaviour.
|
|
|
|
* Boot with debug.acpi.timer_test set to invoke this.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_timer_test(void)
|
|
|
|
{
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
uint32_t u1, u2, u3;
|
|
|
|
|
2003-04-30 05:27:01 +00:00
|
|
|
u1 = read_counter();
|
|
|
|
u2 = read_counter();
|
|
|
|
u3 = read_counter();
|
Fix several bugs where 32-bit timers and wraparound were not properly
supported. Symptoms of this bug included unnecessary use of ACPI-safe
and a dmesg that has deltas of about 2^24:
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 16777206, width = 16777204
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 2, max = 16777210, width = 16777208
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
ACPI timer looks GOOD min = 4, max = 5, width = 1
ACPI timer looks BAD min = 2, max = 7, width = 5
ACPI timer looks BAD min = 4, max = 16777189, width = 16777185
To fix this:
* Use a 32 bit timecounter mask when the timer is 32 bits.
* In test_counter(), use the acpi_TimerDelta function which handles 24/32
bit timers and wraparound.
Miscellaneous fixes:
* Use C99 initializers for timecounter struct.
* Use u_int and uint32_t where appropriate instead of unsigned.
* Remove whitespace-only lines
* Remove the old PIIX4 PCI workaround. The timecounter testing code has
been in use for long enough to prove it's functional.
2004-04-21 00:48:16 +00:00
|
|
|
|
2001-07-21 04:08:42 +00:00
|
|
|
device_printf(acpi_timer_dev, "timer test in progress, reboot to quit.\n");
|
|
|
|
for (;;) {
|
|
|
|
/*
|
2003-08-28 16:06:30 +00:00
|
|
|
* The failure case is where u3 > u1, but u2 does not fall between
|
|
|
|
* the two, ie. it contains garbage.
|
2001-07-21 04:08:42 +00:00
|
|
|
*/
|
|
|
|
if (u3 > u1) {
|
2003-08-28 16:06:30 +00:00
|
|
|
if (u2 < u1 || u2 > u3)
|
|
|
|
device_printf(acpi_timer_dev,
|
|
|
|
"timer is not monotonic: 0x%08x,0x%08x,0x%08x\n",
|
2001-07-21 04:08:42 +00:00
|
|
|
u1, u2, u3);
|
|
|
|
}
|
|
|
|
u1 = u2;
|
|
|
|
u2 = u3;
|
2003-04-30 05:27:01 +00:00
|
|
|
u3 = read_counter();
|
2001-07-21 04:08:42 +00:00
|
|
|
}
|
|
|
|
}
|