Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/cobalt - Reset timer0 of GT64111 in gt_attach() and...



details:   https://anonhg.NetBSD.org/src/rev/84ebe09f2d51
branches:  trunk
changeset: 569659:84ebe09f2d51
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Aug 28 12:32:48 2004 +0000

description:
- Reset timer0 of GT64111 in gt_attach() and start it
  in cpu_initclocks(9) via a callback function.
  Fixes the "hardclock(9) is called before cpu_initclocks(9)" problem
  reported by KIYOHARA Takashi on port-cobalt.
- Use bus_space(9) functions to access GT64111 registers and
  add register definitions for GT64111 in gtreg.h.
  (XXX this could be in sys/dev/marvell?)
- Move microtime(9) from machdep.c to clock.c, and read timer0 register
  via a callback function. Also change microtime(9) like other ports
  to guarantee that the time will be greater than the value obtained
  by a previous call.

diffstat:

 sys/arch/cobalt/cobalt/clock.c    |  47 +++++++++++++++++--
 sys/arch/cobalt/cobalt/clockvar.h |  30 +++++++++++++
 sys/arch/cobalt/cobalt/machdep.c  |  34 +--------------
 sys/arch/cobalt/dev/gt.c          |  87 +++++++++++++++++++++++++++++++++++---
 sys/arch/cobalt/dev/gtreg.h       |  89 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 242 insertions(+), 45 deletions(-)

diffs (truncated from 408 to 300 lines):

diff -r 70507a06ceb4 -r 84ebe09f2d51 sys/arch/cobalt/cobalt/clock.c
--- a/sys/arch/cobalt/cobalt/clock.c    Sat Aug 28 07:02:11 2004 +0000
+++ b/sys/arch/cobalt/cobalt/clock.c    Sat Aug 28 12:32:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.7 2004/07/05 07:28:45 pk Exp $     */
+/*     $NetBSD: clock.c,v 1.8 2004/08/28 12:32:48 tsutsui Exp $        */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.7 2004/07/05 07:28:45 pk Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.8 2004/08/28 12:32:48 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -38,15 +38,21 @@
 
 #include <dev/ic/mc146818reg.h>
 
-void   cpu_initclocks(void);
-void   inittodr(time_t);
-void   resettodr(void);
-void   setstatclockrate(int);
+#include <cobalt/cobalt/clockvar.h>
+
+void (*timer_start)(void *);
+long (*timer_read)(void *);
+void *timer_cookie;
 
 void
 cpu_initclocks()
 {
 
+       /* start timer */
+       if (timer_start == NULL)
+               panic("cpu_initclocks(): no timer configured");
+       (*timer_start)(timer_cookie);
+
        return;
 }
 
@@ -132,3 +138,32 @@
 
        return;
 }
+
+void
+microtime(struct timeval *tvp)
+{
+       int s;
+       static struct timeval lasttime;
+
+       s = splclock();
+
+       *tvp = time;
+
+       if (timer_read)
+               tvp->tv_usec += (*timer_read)(timer_cookie);
+
+       if (tvp->tv_usec >= 1000000) {
+               tvp->tv_usec -= 1000000;
+               tvp->tv_sec++;
+       }
+
+       if (tvp->tv_sec == lasttime.tv_sec &&
+           tvp->tv_usec <= lasttime.tv_usec &&
+           (tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
+               tvp->tv_sec++;
+               tvp->tv_usec -= 1000000;
+       }
+
+       lasttime = *tvp;
+       splx(s);
+}
diff -r 70507a06ceb4 -r 84ebe09f2d51 sys/arch/cobalt/cobalt/clockvar.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/cobalt/cobalt/clockvar.h Sat Aug 28 12:32:48 2004 +0000
@@ -0,0 +1,30 @@
+/* $NetBSD: clockvar.h,v 1.1 2004/08/28 12:32:48 tsutsui Exp $ */
+/*
+ * Copyright (C) 2004 Izumi Tsutsui.  All rights reserved.
+ *
+ * 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. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+extern void (*timer_start)(void *);
+extern long (*timer_read)(void *);
+extern void *timer_cookie;
diff -r 70507a06ceb4 -r 84ebe09f2d51 sys/arch/cobalt/cobalt/machdep.c
--- a/sys/arch/cobalt/cobalt/machdep.c  Sat Aug 28 07:02:11 2004 +0000
+++ b/sys/arch/cobalt/cobalt/machdep.c  Sat Aug 28 12:32:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.51 2004/04/02 23:18:09 tsutsui Exp $     */
+/*     $NetBSD: machdep.c,v 1.52 2004/08/28 12:32:48 tsutsui Exp $     */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.51 2004/04/02 23:18:09 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2004/08/28 12:32:48 tsutsui Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -355,36 +355,6 @@
        for (;;);
 }
 
-void
-microtime(tvp)
-       struct timeval *tvp;
-{
-       int s = splclock();
-       static struct timeval lasttime;
-       u_int32_t counter0;
-
-       *tvp = time;
-
-       counter0 = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x14000850);
-
-       /*
-        * XXX
-        */
-
-       counter0 /= 50;
-       counter0 %= 10000;
-
-       if (counter0 > 9999) {
-               counter0 = 9999;
-       }
-
-       tvp->tv_usec -= tvp->tv_usec % 10000;
-       tvp->tv_usec += 10000 - counter0;
-
-       lasttime = *tvp;
-       splx(s);
-}
-
 unsigned long cpuspeed;
 
 __inline void
diff -r 70507a06ceb4 -r 84ebe09f2d51 sys/arch/cobalt/dev/gt.c
--- a/sys/arch/cobalt/dev/gt.c  Sat Aug 28 07:02:11 2004 +0000
+++ b/sys/arch/cobalt/dev/gt.c  Sat Aug 28 12:32:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gt.c,v 1.9 2003/07/15 01:29:23 lukem Exp $     */
+/*     $NetBSD: gt.c,v 1.10 2004/08/28 12:32:48 tsutsui Exp $  */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gt.c,v 1.9 2003/07/15 01:29:23 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gt.c,v 1.10 2004/08/28 12:32:48 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -43,20 +43,32 @@
 #include <sys/types.h>
 #include <sys/device.h>
 
+#include <machine/autoconf.h>
+#include <machine/bus.h>
 #include <machine/intr.h>
-#include <machine/bus.h>
 
 #include <dev/pci/pcivar.h>
+
+#include <cobalt/cobalt/clockvar.h>
+#include <cobalt/dev/gtreg.h>
+
 #include "pci.h"
 
 struct gt_softc {
        struct device   sc_dev;
+
+       bus_space_tag_t sc_bst;
+       bus_space_handle_t sc_bsh;
 };
 
 static int     gt_match(struct device *, struct cfdata *, void *);
 static void    gt_attach(struct device *, struct device *, void *);
 static int     gt_print(void *aux, const char *pnp);
 
+static void    gt_timer_init(struct gt_softc *sc);
+static void    gt_timer0_init(void *);
+static long    gt_timer0_read(void *);
+
 CFATTACH_DECL(gt, sizeof(struct gt_softc),
     gt_match, gt_attach, NULL, NULL);
 
@@ -69,19 +81,34 @@
        return 1;
 }
 
+#define GT_REG_REGION  0x1000
+
 static void
 gt_attach(parent, self, aux)
        struct device *parent;
        struct device *self;
        void *aux;
 {
+       struct mainbus_attach_args *ma = aux;
+       struct gt_softc *sc = (void *)self;
+#if NPCI > 0
        struct pcibus_attach_args pba;
+#endif
+
+       sc->sc_bst = ma->ma_iot;
+       if (bus_space_map(sc->sc_bst, ma->ma_addr, GT_REG_REGION,
+           0, &sc->sc_bsh)) {
+               printf(": unable to map GT64111 registers\n");
+               return;
+       }
 
        printf("\n");
 
-       /* XXX */
-       *((volatile u_int32_t *)0xb4000c00) =
-               (*((volatile u_int32_t *)0xb4000c00) & ~0x6) | 0x2;
+       gt_timer_init(sc);
+
+       bus_space_write_4(sc->sc_bst, sc->sc_bsh, GT_PCI_COMMAND,
+           (bus_space_read_4(sc->sc_bst, sc->sc_bsh, GT_PCI_COMMAND) &
+           ~PCI_SYNCMODE) | PCI_PCLK_HIGH);
 
 #if NPCI > 0
        pba.pba_busname = "pci";
@@ -94,7 +121,6 @@
                PCI_FLAGS_MRL_OKAY | /*PCI_FLAGS_MRM_OKAY|*/ PCI_FLAGS_MWI_OKAY;
        config_found(self, &pba, gt_print);
 #endif
-       return;
 }
 
 static int
@@ -105,3 +131,50 @@
        /* XXX */
        return 0;
 }
+
+static void
+gt_timer_init(struct gt_softc *sc)
+{
+
+       /* stop timer0 */
+       bus_space_write_4(sc->sc_bst, sc->sc_bsh, GT_TIMER_CTRL,
+           bus_space_read_4(sc->sc_bst, sc->sc_bsh, GT_TIMER_CTRL) & ~ENTC0);
+
+       timer_start = gt_timer0_init;
+       timer_read  = gt_timer0_read;
+       timer_cookie = sc;
+}
+
+#define TIMER0_INIT_VALUE 500000
+
+static void
+gt_timer0_init(void *cookie)
+{
+       struct gt_softc *sc = cookie;
+
+       bus_space_write_4(sc->sc_bst, sc->sc_bsh,
+           GT_TIMER_COUNTER0, TIMER0_INIT_VALUE);
+       /* start timer0 */
+       bus_space_write_4(sc->sc_bst, sc->sc_bsh, GT_TIMER_CTRL,
+           bus_space_read_4(sc->sc_bst, sc->sc_bsh, GT_TIMER_CTRL) | ENTC0);
+}
+
+static long
+gt_timer0_read(void *cookie)
+{
+       struct gt_softc *sc = cookie;



Home | Main Index | Thread Index | Old Index