summaryrefslogtreecommitdiffstats
path: root/sys/contrib/dev/acpica/hwtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/dev/acpica/hwtimer.c')
-rw-r--r--sys/contrib/dev/acpica/hwtimer.c76
1 files changed, 20 insertions, 56 deletions
diff --git a/sys/contrib/dev/acpica/hwtimer.c b/sys/contrib/dev/acpica/hwtimer.c
index 4a03117..8339b27 100644
--- a/sys/contrib/dev/acpica/hwtimer.c
+++ b/sys/contrib/dev/acpica/hwtimer.c
@@ -2,7 +2,7 @@
/******************************************************************************
*
* Name: hwtimer.c - ACPI Power Management Timer Interface
- * $Revision: 14 $
+ * $Revision: 19 $
*
*****************************************************************************/
@@ -10,7 +10,7 @@
*
* 1. Copyright Notice
*
- * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
+ * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
* All rights reserved.
*
* 2. License
@@ -119,7 +119,7 @@
#include "achware.h"
#define _COMPONENT ACPI_HARDWARE
- MODULE_NAME ("hwtimer")
+ ACPI_MODULE_NAME ("hwtimer")
/******************************************************************************
@@ -138,7 +138,7 @@ ACPI_STATUS
AcpiGetTimerResolution (
UINT32 *Resolution)
{
- FUNCTION_TRACE ("AcpiGetTimerResolution");
+ ACPI_FUNCTION_TRACE ("AcpiGetTimerResolution");
if (!Resolution)
@@ -150,7 +150,6 @@ AcpiGetTimerResolution (
{
*Resolution = 24;
}
-
else
{
*Resolution = 32;
@@ -176,7 +175,7 @@ ACPI_STATUS
AcpiGetTimer (
UINT32 *Ticks)
{
- FUNCTION_TRACE ("AcpiGetTimer");
+ ACPI_FUNCTION_TRACE ("AcpiGetTimer");
if (!Ticks)
@@ -224,13 +223,12 @@ AcpiGetTimerDuration (
UINT32 *TimeElapsed)
{
UINT32 DeltaTicks = 0;
- UINT32 Seconds = 0;
- UINT32 Milliseconds = 0;
- UINT32 Microseconds = 0;
- UINT32 Remainder = 0;
+ UINT64_OVERLAY NormalizedTicks;
+ ACPI_STATUS Status;
+ ACPI_INTEGER OutQuotient;
- FUNCTION_TRACE ("AcpiGetTimerDuration");
+ ACPI_FUNCTION_TRACE ("AcpiGetTimerDuration");
if (!TimeElapsed)
@@ -247,24 +245,21 @@ AcpiGetTimerDuration (
{
DeltaTicks = EndTicks - StartTicks;
}
-
else if (StartTicks > EndTicks)
{
- /* 24-bit Timer */
-
if (0 == AcpiGbl_FADT->TmrValExt)
{
+ /* 24-bit Timer */
+
DeltaTicks = (((0x00FFFFFF - StartTicks) + EndTicks) & 0x00FFFFFF);
}
-
- /* 32-bit Timer */
-
else
{
+ /* 32-bit Timer */
+
DeltaTicks = (0xFFFFFFFF - StartTicks) + EndTicks;
}
}
-
else
{
*TimeElapsed = 0;
@@ -274,49 +269,18 @@ AcpiGetTimerDuration (
/*
* Compute Duration:
* -----------------
- * Since certain compilers (gcc/Linux, argh!) don't support 64-bit
- * divides in kernel-space we have to do some trickery to preserve
- * accuracy while using 32-bit math.
- *
- * TBD: Change to use 64-bit math when supported.
*
- * The process is as follows:
- * 1. Compute the number of seconds by dividing Delta Ticks by
- * the timer frequency.
- * 2. Compute the number of milliseconds in the remainder from step #1
- * by multiplying by 1000 and then dividing by the timer frequency.
- * 3. Compute the number of microseconds in the remainder from step #2
- * by multiplying by 1000 and then dividing by the timer frequency.
- * 4. Add the results from steps 1, 2, and 3 to get the total duration.
+ * Requires a 64-bit divide:
*
- * Example: The time elapsed for DeltaTicks = 0xFFFFFFFF should be
- * 1199864031 microseconds. This is computed as follows:
- * Step #1: Seconds = 1199; Remainder = 3092840
- * Step #2: Milliseconds = 864; Remainder = 113120
- * Step #3: Microseconds = 31; Remainder = <don't care!>
+ * TimeElapsed = (DeltaTicks * 1000000) / PM_TIMER_FREQUENCY;
*/
+ NormalizedTicks.Full = ((UINT64) DeltaTicks) * 1000000;
- /* Step #1 */
+ Status = AcpiUtShortDivide (&NormalizedTicks.Full, PM_TIMER_FREQUENCY,
+ &OutQuotient, NULL);
- Seconds = DeltaTicks / PM_TIMER_FREQUENCY;
- Remainder = DeltaTicks % PM_TIMER_FREQUENCY;
-
- /* Step #2 */
-
- Milliseconds = (Remainder * 1000) / PM_TIMER_FREQUENCY;
- Remainder = (Remainder * 1000) % PM_TIMER_FREQUENCY;
-
- /* Step #3 */
-
- Microseconds = (Remainder * 1000) / PM_TIMER_FREQUENCY;
-
- /* Step #4 */
-
- *TimeElapsed = Seconds * 1000000;
- *TimeElapsed += Milliseconds * 1000;
- *TimeElapsed += Microseconds;
-
- return_ACPI_STATUS (AE_OK);
+ *TimeElapsed = (UINT32) OutQuotient;
+ return_ACPI_STATUS (Status);
}
OpenPOWER on IntegriCloud