add timer calibration

from Chris Sekiya
This commit is contained in:
pooka 2002-12-28 16:40:48 +00:00
parent da446ea2da
commit 00ddd0deec
2 changed files with 21 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: crimereg.h,v 1.4 2002/12/23 20:04:22 pooka Exp $ */
/* $NetBSD: crimereg.h,v 1.5 2002/12/28 16:40:48 pooka Exp $ */
/*
* Copyright (c) 2000 Soren S. Jorvang
@ -132,6 +132,7 @@
#define CRIME_DOG (CRIME_BASE+0x030)
#define CRIME_WATCHDOG CRIME_DOG
#define CRIME_TIME (CRIME_BASE+0x038)
#define CRIME_TIME_MASK 0x0000ffffffffffff
#define CRIME_CPU_ERROR_ADDR (CRIME_BASE+0x040)
#define CRIME_CPU_ERROR_STAT (CRIME_BASE+0x048)
#define CRIME_CPU_ERROR_ENA (CRIME_BASE+0x050)

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip32.c,v 1.12 2002/09/27 15:36:41 provos Exp $ */
/* $NetBSD: ip32.c,v 1.13 2002/12/28 16:40:48 pooka Exp $ */
/*
* Copyright (c) 2000 Soren S. Jorvang
@ -62,18 +62,30 @@ static struct evcnt mips_int5_evcnt =
static struct evcnt mips_spurint_evcnt =
EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "mips", "spurious interrupts");
void ip32_init(void)
void
ip32_init(void)
{
u_int64_t baseline;
u_int32_t cps;
/* XXXrkb: enable watchdog timer, clear it */
*(volatile u_int32_t *)0xb400000c |= 0x200;
*(volatile u_int32_t *)0xb4000034 = 0;
/*
* XXX: we have no clock calibration code for the IP32, so cpu speed
* is set from `cpuspeed' environment variable in machdep.c.
*/
#define WAIT_MS 50
baseline = *(volatile u_int64_t *)
MIPS_PHYS_TO_KSEG1(CRIME_TIME) & CRIME_TIME_MASK;
cps = mips3_cp0_count_read();
while (((*(volatile u_int64_t *)MIPS_PHYS_TO_KSEG1(CRIME_TIME)
& CRIME_TIME_MASK) - baseline) < WAIT_MS * 1000000 / 15)
continue;
cps = mips3_cp0_count_read() - cps;
cps = cps / 5;
#undef WAIT_MS
/* Counter on R4k/R4400/R4600/R5k counts at half the CPU frequency */
curcpu()->ci_cpu_freq = cps * 2 * hz;
curcpu()->ci_cycles_per_hz = curcpu()->ci_cpu_freq / (2 * hz);
curcpu()->ci_divisor_delay = curcpu()->ci_cpu_freq / (2 * 1000000);
MIPS_SET_CI_RECIPRICAL(curcpu());
@ -186,6 +198,7 @@ panic("pcierr: %x %x", *(volatile u_int32_t *)0xbf080004,
void
ip32_intr_establish(int level, int ipl, int (*func)(void *), void *arg)
{
(void) crime_intr_establish(level, IST_LEVEL, ipl, func, arg);
}
#endif /* IP32 */