summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorjruoho <jruoho@NetBSD.org>2010-07-10 13:08:09 +0000
committerjruoho <jruoho@NetBSD.org>2010-07-10 13:08:09 +0000
commitbd772854cf7b971d5f2da6800a0f5037c4cb9346 (patch)
tree4a84c3842e2c9c30fa8be96d9e747133ebda9846 /sys/dev
parent9d33b2b330a33981e05405bfbe06fec686aaf005 (diff)
Export the wrapper functions that read from the ACPI PM timer.
Needed for ACPI CPUs. Also KNF, cosmetics. No functional change.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/acpi/acpi.c7
-rw-r--r--sys/dev/acpi/acpi_timer.c66
-rw-r--r--sys/dev/acpi/acpi_timer.h6
3 files changed, 48 insertions, 31 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index d039f93136a..134b9f9ac65 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.205 2010/07/02 05:18:38 jruoho Exp $ */
+/* $NetBSD: acpi.c,v 1.206 2010/07/10 13:08:09 jruoho Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.205 2010/07/02 05:18:38 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.206 2010/07/10 13:08:09 jruoho Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.205 2010/07/02 05:18:38 jruoho Exp $");
#include <sys/mutex.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
+#include <sys/timetc.h>
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
@@ -528,7 +529,7 @@ acpi_attach(device_t parent, device_t self, void *aux)
acpi_register_fixed_button(sc, ACPI_EVENT_POWER_BUTTON);
acpi_register_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON);
- acpitimer_init();
+ acpitimer_init(sc);
#ifdef ACPI_DEBUGGER
if (acpi_dbgr & ACPI_DBGR_PROBE)
diff --git a/sys/dev/acpi/acpi_timer.c b/sys/dev/acpi/acpi_timer.c
index 409cfa5a60d..13e65d04230 100644
--- a/sys/dev/acpi/acpi_timer.c
+++ b/sys/dev/acpi/acpi_timer.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_timer.c,v 1.16 2010/03/05 17:04:26 jruoho Exp $ */
+/* $NetBSD: acpi_timer.c,v 1.17 2010/07/10 13:08:09 jruoho Exp $ */
/*-
* Copyright (c) 2006 Matthias Drochner <drochner@NetBSD.org>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.16 2010/03/05 17:04:26 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.17 2010/07/10 13:08:09 jruoho Exp $");
#include <sys/types.h>
#include <sys/systm.h>
@@ -39,10 +39,8 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.16 2010/03/05 17:04:26 jruoho Exp $
#include <machine/acpi_machdep.h>
-static int acpitimer_test(void);
-static uint32_t acpitimer_delta(uint32_t, uint32_t);
-static u_int acpitimer_read_safe(struct timecounter *);
-static u_int acpitimer_read_fast(struct timecounter *);
+static int acpitimer_test(void);
+static uint32_t acpitimer_delta(uint32_t, uint32_t);
static struct timecounter acpi_timecounter = {
acpitimer_read_safe,
@@ -56,21 +54,21 @@ static struct timecounter acpi_timecounter = {
};
int
-acpitimer_init(void)
+acpitimer_init(struct acpi_softc *sc)
{
+ ACPI_STATUS res;
uint32_t bits;
int i, j;
- ACPI_STATUS res;
res = AcpiGetTimerResolution(&bits);
+
if (res != AE_OK)
return (-1);
if (bits == 32)
acpi_timecounter.tc_counter_mask = 0xffffffff;
- j = 0;
- for (i = 0; i < 10; i++)
+ for (i = j = 0; i < 10; i++)
j += acpitimer_test();
if (j >= 10) {
@@ -78,62 +76,71 @@ acpitimer_init(void)
acpi_timecounter.tc_get_timecount = acpitimer_read_fast;
acpi_timecounter.tc_quality = 1000;
}
-
+
tc_init(&acpi_timecounter);
- aprint_verbose("%s %d-bit timer\n", acpi_timecounter.tc_name, bits);
- return (0);
+ aprint_debug_dev(sc->sc_dev,
+ "%s %d-bit timer\n", acpi_timecounter.tc_name, bits);
+
+ return 0;
}
int
acpitimer_detach(void)
{
+
return tc_detach(&acpi_timecounter);
}
-static u_int
+u_int
acpitimer_read_fast(struct timecounter *tc)
{
uint32_t t;
- AcpiGetTimer(&t);
- return (t);
+ (void)AcpiGetTimer(&t);
+
+ return t;
}
/*
* Some chipsets (PIIX4 variants) do not latch correctly; there
* is a chance that a transition is hit.
*/
-static u_int
+u_int
acpitimer_read_safe(struct timecounter *tc)
{
uint32_t t1, t2, t3;
- AcpiGetTimer(&t2);
- AcpiGetTimer(&t3);
+ (void)AcpiGetTimer(&t2);
+ (void)AcpiGetTimer(&t3);
+
do {
t1 = t2;
t2 = t3;
- AcpiGetTimer(&t3);
+
+ (void)AcpiGetTimer(&t3);
+
} while ((t1 > t2) || (t2 > t3));
- return (t2);
+
+ return t2;
}
static uint32_t
acpitimer_delta(uint32_t end, uint32_t start)
{
+ const u_int mask = acpi_timecounter.tc_counter_mask;
uint32_t delta;
- u_int mask = acpi_timecounter.tc_counter_mask;
if (end >= start)
delta = end - start;
else
delta = ((mask - start) + end + 1) & mask;
- return (delta);
+ return delta;
}
#define N 2000
+
static int
acpitimer_test(void)
{
@@ -144,16 +151,23 @@ acpitimer_test(void)
maxl = 0;
acpi_md_OsDisableInterrupt();
- AcpiGetTimer(&last);
+
+ (void)AcpiGetTimer(&last);
+
for (n = 0; n < N; n++) {
- AcpiGetTimer(&this);
+
+ (void)AcpiGetTimer(&this);
+
delta = acpitimer_delta(this, last);
+
if (delta > maxl)
maxl = delta;
else if (delta < minl)
minl = delta;
+
last = this;
}
+
acpi_md_OsEnableInterrupt();
if (maxl - minl > 2 )
@@ -163,5 +177,5 @@ acpitimer_test(void)
else
n = 1;
- return (n);
+ return n;
}
diff --git a/sys/dev/acpi/acpi_timer.h b/sys/dev/acpi/acpi_timer.h
index 1aaabf7b32d..3fda7361a2f 100644
--- a/sys/dev/acpi/acpi_timer.h
+++ b/sys/dev/acpi/acpi_timer.h
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_timer.h,v 1.4 2010/03/05 17:04:26 jruoho Exp $ */
+/* $NetBSD: acpi_timer.h,v 1.5 2010/07/10 13:08:09 jruoho Exp $ */
/*-
* Copyright (c) 2006 Matthias Drochner <drochner@NetBSD.org>
@@ -29,7 +29,9 @@
#ifndef _SYS_DEV_ACPI_ACPI_TIMER_H
#define _SYS_DEV_ACPI_ACPI_TIMER_H
-int acpitimer_init(void);
+int acpitimer_init(struct acpi_softc *);
int acpitimer_detach(void);
+u_int acpitimer_read_safe(struct timecounter *);
+u_int acpitimer_read_fast(struct timecounter *);
#endif /* !_SYS_DEV_ACPI_ACPI_TIMER_H */