Make timebase frequency value adjustable.
This commit is contained in:
parent
9bdf22f648
commit
500013914e
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: clock.c,v 1.10 2000/06/29 08:10:45 mrg Exp $ */
|
/* $NetBSD: clock.c,v 1.11 2000/07/14 05:53:31 tsubai Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
|
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
|
||||||
@ -43,13 +43,19 @@
|
|||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initially we assume a processor with a bus frequency of 12.5 MHz.
|
* Initially we assume a processor with a bus frequency of 50 MHz.
|
||||||
*/
|
*/
|
||||||
static u_long ticks_per_sec = 12500000;
|
static u_long ticks_per_sec = 50*1000*1000/4;
|
||||||
static u_long ns_per_tick = 80;
|
static u_long ns_per_tick = 80;
|
||||||
static long ticks_per_intr;
|
static long ticks_per_intr;
|
||||||
static volatile u_long lasttb;
|
static volatile u_long lasttb;
|
||||||
|
|
||||||
|
#ifdef TIMEBASE_FREQ
|
||||||
|
u_int timebase_freq = TIMEBASE_FREQ;
|
||||||
|
#else
|
||||||
|
u_int timebase_freq = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SECDAY 86400
|
#define SECDAY 86400
|
||||||
#define DIFF19041970 2082844800
|
#define DIFF19041970 2082844800
|
||||||
|
|
||||||
@ -178,28 +184,23 @@ void
|
|||||||
calc_delayconst()
|
calc_delayconst()
|
||||||
{
|
{
|
||||||
int qhandle, phandle;
|
int qhandle, phandle;
|
||||||
char name[32];
|
char type[32];
|
||||||
int msr, scratch;
|
int msr, scratch;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get this info during autoconf? XXX
|
* Get this info during autoconf? XXX
|
||||||
*/
|
*/
|
||||||
|
if (timebase_freq != 0) {
|
||||||
|
ticks_per_sec = timebase_freq;
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
|
||||||
for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
|
for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
|
||||||
if (OF_getprop(qhandle, "device_type", name, sizeof name) >= 0
|
if (OF_getprop(qhandle, "device_type", type, sizeof type) > 0
|
||||||
&& !strcmp(name, "cpu")
|
&& strcmp(type, "cpu") == 0
|
||||||
&& OF_getprop(qhandle, "timebase-frequency",
|
&& OF_getprop(qhandle, "timebase-frequency",
|
||||||
&ticks_per_sec, sizeof ticks_per_sec) >= 0) {
|
&ticks_per_sec, sizeof ticks_per_sec) > 0) {
|
||||||
/*
|
goto found;
|
||||||
* Should check for correct CPU here? XXX
|
|
||||||
*/
|
|
||||||
asm volatile ("mfmsr %0; andi. %1, %0, %2; mtmsr %1"
|
|
||||||
: "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
|
|
||||||
ns_per_tick = 1000000000 / ticks_per_sec;
|
|
||||||
ticks_per_intr = ticks_per_sec / hz;
|
|
||||||
asm volatile ("mftb %0" : "=r"(lasttb));
|
|
||||||
asm volatile ("mtdec %0" :: "r"(ticks_per_intr));
|
|
||||||
asm volatile ("mtmsr %0" :: "r"(msr));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if ((phandle = OF_child(qhandle)))
|
if ((phandle = OF_child(qhandle)))
|
||||||
continue;
|
continue;
|
||||||
@ -209,8 +210,19 @@ calc_delayconst()
|
|||||||
qhandle = OF_parent(qhandle);
|
qhandle = OF_parent(qhandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!phandle)
|
panic("no cpu node");
|
||||||
panic("no cpu node");
|
|
||||||
|
found:
|
||||||
|
/*
|
||||||
|
* Should check for correct CPU here? XXX
|
||||||
|
*/
|
||||||
|
asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
|
||||||
|
: "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
|
||||||
|
ns_per_tick = 1000000000 / ticks_per_sec;
|
||||||
|
ticks_per_intr = ticks_per_sec / hz;
|
||||||
|
asm volatile ("mftb %0" : "=r"(lasttb));
|
||||||
|
asm volatile ("mtdec %0" :: "r"(ticks_per_intr));
|
||||||
|
asm volatile ("mtmsr %0" :: "r"(msr));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u_quad_t
|
static inline u_quad_t
|
||||||
|
Loading…
Reference in New Issue
Block a user