Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Remove hardcoded values for HZ (under different names!) ...



details:   https://anonhg.NetBSD.org/src/rev/6710a82f98a2
branches:  trunk
changeset: 517995:6710a82f98a2
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri Nov 23 01:04:11 2001 +0000

description:
Remove hardcoded values for HZ (under different names!) from mcclock.c
and clock_machdep.h, so that now HZ can be any supported frequency of
the mc146818a/ds1287a RTCs.
Tested at 256Hz and 2048Hz.

diffstat:

 sys/arch/pmax/include/clock_machdep.h |  57 -----------------------------------
 sys/arch/pmax/pmax/clock.c            |  37 +++++++++++-----------
 sys/dev/dec/mcclock.c                 |  57 +++++++++++++++++++++++++++++++---
 3 files changed, 70 insertions(+), 81 deletions(-)

diffs (225 lines):

diff -r 01277796faa0 -r 6710a82f98a2 sys/arch/pmax/include/clock_machdep.h
--- a/sys/arch/pmax/include/clock_machdep.h     Thu Nov 22 23:27:38 2001 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*     $NetBSD: clock_machdep.h,v 1.5 2000/01/09 15:34:42 ad Exp $     */
-
-/*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jonathan Stone.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by the NetBSD
- *      Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * System-dependent clock declarations for the ``cpu-independent''
- * clock interface.
- *
- * This file must prototype or define the following functions or
- * macros (one or more of which may be no-ops):
- *
- * CLOCK_RATE  default rate at which clock runs. Some platforms
- *             run the RTC at a fixed rate, independent of
- *             the acutal RTC hardware in use. clock
- */
-
-#ifndef _PMAX_CLOCK_MACHDEP_H_
-#define _PMAX_CLOCK_MACHDEP_H_
-
-/* The default clock rate on a pmax is 256 Hz. */
-#define CLOCK_RATE     256
-
-#endif /* !_PMAX_CLOCK_MACHDEP_H_ */
diff -r 01277796faa0 -r 6710a82f98a2 sys/arch/pmax/pmax/clock.c
--- a/sys/arch/pmax/pmax/clock.c        Thu Nov 22 23:27:38 2001 +0000
+++ b/sys/arch/pmax/pmax/clock.c        Fri Nov 23 01:04:11 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.31 2000/06/04 19:14:54 cgd Exp $ */
+/* $NetBSD: clock.c,v 1.32 2001/11/23 01:04:11 simonb Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -44,7 +44,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.31 2000/06/04 19:14:54 cgd Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.32 2001/11/23 01:04:11 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -52,8 +52,6 @@
 
 #include <dev/clock_subr.h>
 
-#include <machine/clock_machdep.h>
-
 #include <dev/dec/clockvar.h>
 
 #include "opt_ntp.h"
@@ -113,20 +111,6 @@
        if (clockfns == NULL)
                panic("cpu_initclocks: no clock attached");
 
-       hz = CLOCK_RATE;        /* 256 Hz clock */
-       tick = 1000000 / hz;    /* number of microseconds between interrupts */
-       tickfix = 1000000 - (hz * tick);
-#ifdef NTP
-       fixtick = tickfix;
-#endif
-       if (tickfix) {
-               int ftp;
-
-               ftp = min(ffs(tickfix), ffs(hz));
-               tickfix >>= (ftp - 1);
-               tickfixinterval = hz >> (ftp - 1);
-        }
-
        /*
         * Establish the clock interrupt; it's a special case.
         *
@@ -144,6 +128,23 @@
         * Get the clock started.
         */
        (*clockfns->cf_init)(clockdev);
+
+       /*
+        * Set hz-related variables after the clock is initialised in
+        * case the initialisation routines adjusted hz.
+        */
+       tick = 1000000 / hz;    /* number of microseconds between interrupts */
+       tickfix = 1000000 - (hz * tick);
+#ifdef NTP
+       fixtick = tickfix;
+#endif
+       if (tickfix) {
+               int ftp;
+
+               ftp = min(ffs(tickfix), ffs(hz));
+               tickfix >>= (ftp - 1);
+               tickfixinterval = hz >> (ftp - 1);
+        }
 }
 
 /*
diff -r 01277796faa0 -r 6710a82f98a2 sys/dev/dec/mcclock.c
--- a/sys/dev/dec/mcclock.c     Thu Nov 22 23:27:38 2001 +0000
+++ b/sys/dev/dec/mcclock.c     Fri Nov 23 01:04:11 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcclock.c,v 1.13 2001/11/13 12:49:45 lukem Exp $ */
+/* $NetBSD: mcclock.c,v 1.14 2001/11/23 01:04:11 simonb Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.13 2001/11/13 12:49:45 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.14 2001/11/23 01:04:11 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -40,13 +40,13 @@
 #include <dev/ic/mc146818reg.h>
 
 /*
- * XXX rate is machine-dependent.
+ * XXX default rate is machine-dependent.
  */
 #ifdef __alpha__
-#define MC_DFEAULTRATE MC_RATE_1024_Hz
+#define MC_DFEAULTHZ   1024
 #endif
 #ifdef pmax
-#define MC_DEFAULTRATE MC_RATE_256_Hz
+#define MC_DEFAULTHZ   256
 #endif
 
 
@@ -84,10 +84,55 @@
        struct device *dev;
 {
        struct mcclock_softc *sc = (struct mcclock_softc *)dev;
+       int rate;
 
-       mc146818_write(sc, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE);
+printf("%s: try to set hz to %d\n", sc->sc_dev.dv_xname, hz);
+
+again:
+       switch (hz) {
+       case 32:
+               rate = MC_BASE_32_KHz | MC_RATE_32_Hz;
+               break;
+       case 64:
+               rate = MC_BASE_32_KHz | MC_RATE_64_Hz;
+               break;
+       case 128:
+               rate = MC_BASE_32_KHz | MC_RATE_128_Hz;
+               break;
+       case 256:
+               rate = MC_BASE_32_KHz | MC_RATE_256_Hz;
+               break;
+       case 512:
+               rate = MC_BASE_32_KHz | MC_RATE_512_Hz;
+               break;
+       case 1024:
+               rate = MC_BASE_32_KHz | MC_RATE_1024_Hz;
+               break;
+       case 2048:
+               rate = MC_BASE_32_KHz | MC_RATE_2048_Hz;
+               break;
+       case 4096:
+               rate = MC_BASE_32_KHz | MC_RATE_4096_Hz;
+               break;
+       case 8192:
+               rate = MC_BASE_32_KHz | MC_RATE_8192_Hz;
+               break;
+       case 16384:
+               rate = MC_BASE_4_MHz | MC_RATE_1;
+               break;
+       case 32768:
+               rate = MC_BASE_4_MHz | MC_RATE_2;
+               break;
+       default:
+               printf("%s: Cannot get %d Hz clock; using %d Hz\n",
+                   sc->sc_dev.dv_xname, hz, MC_DEFAULTHZ);
+               hz = MC_DEFAULTHZ;
+               goto again;
+       }
+       mc146818_write(sc, MC_REGA, rate);
        mc146818_write(sc, MC_REGB,
            MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR);
+printf("%s: hz set to %d\n", sc->sc_dev.dv_xname, hz);
 }
 
 /*



Home | Main Index | Thread Index | Old Index