/* A couple of routines to implement a low-overhead timer for drivers */
/*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2, or (at
* your option) any later version.
*/
#include "grub.h"
#include "osdep.h"
#include "io.h"
#include "timer.h"
#include "latch.h"
{
/*
* Now let's take care of PPC channel 2
*
* Set the Gate high, program PPC channel 2 for mode 0,
* (interrupt on terminal count mode), binary count,
* load 5 * LATCH count, (LSB and MSB) to begin countdown.
*
* Note some implementations have a bug where the high bits byte
* of channel 2 is ignored.
*/
/* Set up the timer gate, turn off the speaker */
/* Set the Gate high, disable speaker */
/* LSB of ticks */
/* MSB of ticks */
}
static int __timer2_running(void)
{
}
#if !defined(CONFIG_TSC_CURRTICKS)
void setup_timers(void)
{
return;
}
{
return __load_timer2(ticks);
}
int timer2_running(void)
{
return __timer2_running();
}
{
}
{
}
#endif /* !defined(CONFIG_TSC_CURRTICKS) */
#if defined(CONFIG_TSC_CURRTICKS)
/* Number of clock ticks to time with the rtc */
static void sleep_latch(void)
{
while(__timer2_running());
}
/* ------ Calibrate the TSC -------
* Time how long it takes to excute a loop that runs in known time.
* And find the convertion needed to get to CLOCK_TICK_RATE
*/
static unsigned long long calibrate_tsc(void)
{
sleep_latch();
/* 64-bit subtract - gcc just messes up with long longs */
__asm__("subl %2,%0\n\t"
"sbbl %3,%1"
/* Error: ECPUTOOFAST */
if (endhigh)
goto bad_ctc;
return endlow;
/*
* The CTC wasn't reliable: we got a hit on the very first read,
* 32 bits..
*/
printf("bad_ctc\n");
return 0;
}
static unsigned long clocks_per_tick;
void setup_timers(void)
{
if (!clocks_per_tick) {
/* Display the CPU Mhz to easily test if the calibration was bad */
}
}
unsigned long currticks(void)
{
unsigned long currticks;
/* Read the Time Stamp Counter */
/* currticks = clocks / clocks_per_tick; */
__asm__("divl %1"
:"=a" (currticks)
return currticks;
}
static unsigned long long timer_timeout;
static int __timer_running(void)
{
unsigned long long now;
return now < timer_timeout;
}
{
unsigned long long now;
while(__timer_running());
}
{
unsigned long long now;
while(__timer_running());
}
{
unsigned long long now;
unsigned long clocks;
}
int timer2_running(void)
{
return __timer_running();
}
#endif /* RTC_CURRTICKS */