diff --git a/sys/arch/cobalt/cobalt/autoconf.c b/sys/arch/cobalt/cobalt/autoconf.c index 173ef6fdbfd1..1d9721586090 100644 --- a/sys/arch/cobalt/cobalt/autoconf.c +++ b/sys/arch/cobalt/cobalt/autoconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.17 2006/04/05 15:03:27 tsutsui Exp $ */ +/* $NetBSD: autoconf.c,v 1.18 2006/04/21 16:52:15 tsutsui Exp $ */ /* * Copyright (c) 2000 Soren S. Jorvang. All rights reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.17 2006/04/05 15:03:27 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.18 2006/04/21 16:52:15 tsutsui Exp $"); #include #include @@ -41,8 +41,6 @@ extern int netboot; extern int bootunit; extern int bootpart; -int cpuspeed = 100; /* Until we know more precisely. */ - void cpu_configure(void) { diff --git a/sys/arch/cobalt/cobalt/clock.c b/sys/arch/cobalt/cobalt/clock.c index e02661478a38..adb264e87971 100644 --- a/sys/arch/cobalt/cobalt/clock.c +++ b/sys/arch/cobalt/cobalt/clock.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.11 2006/04/15 13:33:04 tsutsui Exp $ */ +/* $NetBSD: clock.c,v 1.12 2006/04/21 16:52:15 tsutsui Exp $ */ /* * Copyright (c) 2000 Soren S. Jorvang. All rights reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.11 2006/04/15 13:33:04 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.12 2006/04/21 16:52:15 tsutsui Exp $"); #include #include @@ -36,6 +36,8 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.11 2006/04/15 13:33:04 tsutsui Exp $"); #include +#include + #include static todr_chip_handle_t todr_handle; @@ -172,3 +174,29 @@ microtime(struct timeval *tvp) lasttime = *tvp; splx(s); } + +void +delay(unsigned int n) +{ + uint32_t cur, last, delta, usecs; + + last = mips3_cp0_count_read(); + delta = usecs = 0; + + while (n > usecs) { + cur = mips3_cp0_count_read(); + + /* Check to see if the timer has wrapped around. */ + if (cur < last) + delta += ((curcpu()->ci_cycles_per_hz - last) + cur); + else + delta += (cur - last); + + last = cur; + + if (delta >= curcpu()->ci_divisor_delay) { + usecs += delta / curcpu()->ci_divisor_delay; + delta %= curcpu()->ci_divisor_delay; + } + } +} diff --git a/sys/arch/cobalt/cobalt/machdep.c b/sys/arch/cobalt/cobalt/machdep.c index 6c224583147f..0afa23f84229 100644 --- a/sys/arch/cobalt/cobalt/machdep.c +++ b/sys/arch/cobalt/cobalt/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.61 2006/04/21 16:27:33 tsutsui Exp $ */ +/* $NetBSD: machdep.c,v 1.62 2006/04/21 16:52:15 tsutsui Exp $ */ /* * Copyright (c) 2000 Soren S. Jorvang. All rights reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.61 2006/04/21 16:27:33 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.62 2006/04/21 16:52:15 tsutsui Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -104,6 +104,8 @@ char * root_bstr = NULL; int bootunit = -1; int bootpart = -1; +int cpuspeed; + u_int cobalt_id; static const char * const cobalt_model[] = { @@ -201,6 +203,29 @@ mach_init(unsigned int memsize, u_int bim, char *bip) else strcpy(cpu_model, cobalt_model[cobalt_id]); + switch (cobalt_id) { + case COBALT_ID_QUBE2700: + case COBALT_ID_RAQ: + cpuspeed = 150; /* MHz */ + break; + case COBALT_ID_QUBE2: + case COBALT_ID_RAQ2: + cpuspeed = 250; /* MHz */ + break; + default: + /* assume the fastest, so that delay(9) works */ + cpuspeed = 250; + break; + } + curcpu()->ci_cpu_freq = cpuspeed * 1000 * 1000; + curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz; + curcpu()->ci_divisor_delay = + ((curcpu()->ci_cpu_freq + (1000000 / 2)) / 1000000); + /* all models have Rm5200, which is CPU_MIPS_DOUBLE_COUNT */ + curcpu()->ci_cycles_per_hz /= 2; + curcpu()->ci_divisor_delay /= 2; + MIPS_SET_CI_RECIPRICAL(curcpu()); + physmem = btoc(memsize - MIPS_KSEG0_START); consinit(); @@ -370,16 +395,6 @@ cpu_reboot(int howto, char *bootstr) ; } -unsigned long cpuspeed; - -inline void -delay(unsigned long n) -{ - volatile register long N = cpuspeed * n; - - while (--N > 0); -} - #define NINTR 6 static struct cobalt_intrhand intrtab[NINTR]; diff --git a/sys/arch/cobalt/include/param.h b/sys/arch/cobalt/include/param.h index 51c1df2d322d..0661920bf199 100644 --- a/sys/arch/cobalt/include/param.h +++ b/sys/arch/cobalt/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.11 2006/02/16 20:17:13 perry Exp $ */ +/* $NetBSD: param.h,v 1.12 2006/04/21 16:52:15 tsutsui Exp $ */ /* * Copyright (c) 1992, 1993 @@ -112,7 +112,7 @@ #ifdef _KERNEL #ifndef _LOCORE -__inline extern void delay(unsigned long); +void delay(unsigned int); #define DELAY(n) delay(n) #include