Port-evbsh5 archive

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

attachment this time!



the timecounter patch is really attached this time!

-- 
Garrett D'Amore, Principal Software Engineer
Tadpole Computer / Computing Technologies Division,
General Dynamics C4 Systems
http://www.tadpolecomputer.com/
Phone: 951 325-2134  Fax: 951 325-2191

Index: sys/arch/sh5/dev/tmu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh5/dev/tmu.c,v
retrieving revision 1.10
diff -d -p -u -r1.10 tmu.c
--- sys/arch/sh5/dev/tmu.c      11 Dec 2005 12:19:00 -0000      1.10
+++ sys/arch/sh5/dev/tmu.c      5 Sep 2006 18:57:03 -0000
@@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: tmu.c,v 1.10
 #include <sys/systm.h>
 #include <sys/device.h>
 #include <sys/conf.h>
+#include <sys/timetc.h>
 
 #include <machine/cpu.h>
 #include <machine/bus.h>
@@ -68,6 +69,7 @@ struct tmu_softc {
        void *sc_clkih;
        void *sc_statih;
        u_int sc_ticksperms;
+       struct timecounter sc_tc;
 };
 
 static int tmumatch(struct device *, struct cfdata *, void *);
@@ -81,9 +83,10 @@ static struct tmu_softc *tmu_sc;
 
 
 static void tmu_start(void *, int, u_int);
-static long tmu_microtime(void *);
 static int tmu_clkint(void *);
 static int tmu_statint(void *);
+static void tmu_init_timecounter(struct tmu_softc *);
+static unsigned tmu_get_timecounter(struct timecounter *);
 
 
 /*ARGSUSED*/
@@ -177,8 +180,12 @@ tmuattach(struct device *parent, struct 
        sc->sc_ca.ca_has_stat_clock = 0;
        sc->sc_ca.ca_arg = sc;
        sc->sc_ca.ca_start = tmu_start;
-       sc->sc_ca.ca_microtime = tmu_microtime;
        clock_config(self, &sc->sc_ca, sh5_intr_evcnt(sc->sc_clkih));
+
+       /*
+        * Attach to timecounters.
+        */
+       tmu_init_timecounter(sc);
 }
 
 static void
@@ -225,24 +232,34 @@ tmu_start(void *arg, int which, u_int cl
        }
 }
 
-static long
-tmu_microtime(void *arg)
+static void
+tmu_init_timecounter(struct tmu_softc *sc)
 {
-       struct tmu_softc *sc = arg;
-       u_int32_t tcnt, d;
 
-       tcnt = bus_space_read_4(sc->sc_bust, sc->sc_bush, TMU_REG_TCNT(0));
-       d = bus_space_read_4(sc->sc_bust, sc->sc_bush, TMU_REG_TCOR(0)) - tcnt;
+       sc->sc_tc.tc_priv = sc;
+       sc->sc_tc.tc_get_timecount = tmu_get_timecounter;
+       sc->sc_tc.tc_name = "tmu_pclock_4";
+       sc->sc_tc.tc_frequency = sc->sc_ca.ca_rate;
+       sc->sc_tc.tc_counter_mask = ~0;
+       sc->sc_tc.tc_quality = 0;
 
-       /*
-        * Catch the common case of a 64MHz peripheral bus clock.
-        * This turns an expensive integer division into a simple shift.
-        */
-       if (sc->sc_ticksperms == 16000)
-               return ((long)(d >> 4));
+       bus_space_write_4(sc->sc_bust, sc->sc_bush, TMU_REG_TCNT(2), ~0);
+       bus_space_write_2(sc->sc_bust, sc->sc_bush, TMU_REG_TCR(2),
+           TMU_TCR_TPSC_PDIV4 | TMU_TCR_CKEG_RISING);
+       /* start timer 2 running */
+       bus_space_write_1(sc->sc_bust, sc->sc_bush, TMU_REG_TSTR,
+           bus_space_read_1(sc->sc_bust, sc->sc_bush, TMU_REG_TSTR) |
+           TMU_TSTR(2));
+}
 
-       /* Otherwise, need to do things the hard way */
-       return ((long)((d * 1000) / sc->sc_ticksperms));
+static unsigned
+tmu_get_timecounter(struct timecounter *tc)
+{
+       struct tmu_softc *sc = tc->tc_priv;
+       unsigned        count;
+
+       count = bus_space_read_4(sc->sc_bust, sc->sc_bush, TMU_REG_TCNT(2));
+       return (~count);
 }
 
 static int
Index: sys/arch/sh5/include/types.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sh5/include/types.h,v
retrieving revision 1.13
diff -d -p -u -r1.13 types.h
--- sys/arch/sh5/include/types.h        5 Sep 2006 07:34:54 -0000       1.13
+++ sys/arch/sh5/include/types.h        5 Sep 2006 18:57:03 -0000
@@ -81,6 +81,7 @@ typedef       volatile __int64_t      __cpu_simple_
 #define        __HAVE_SYSCALL_INTERN
 #define        __HAVE_FUNCTION_DESCRIPTORS
 #define        __HAVE_GENERIC_TODR
+#define        __HAVE_TIMECOUNTER
 
 #if defined(_KERNEL)
 #define        __HAVE_RAS
Index: sys/arch/sh5/sh5/clockvar.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sh5/sh5/clockvar.h,v
retrieving revision 1.3
diff -d -p -u -r1.3 clockvar.h
--- sys/arch/sh5/sh5/clockvar.h 11 Dec 2005 12:19:02 -0000      1.3
+++ sys/arch/sh5/sh5/clockvar.h 5 Sep 2006 18:57:03 -0000
@@ -45,7 +45,6 @@ struct clock_attach_args {
        int     ca_has_stat_clock;      /* Non-zero if supports stat clock */
        void    *ca_arg;                /* Back-end cookie */
        void    (*ca_start)(void *, int, u_int);        /* Start/Reset timer */
-       long    (*ca_microtime)(void *);        /* uS since last hardclock() */
 };
 
 /*
Index: sys/arch/sh5/sh5/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh5/sh5/pmap.c,v
retrieving revision 1.43
diff -d -p -u -r1.43 pmap.c
--- sys/arch/sh5/sh5/pmap.c     24 Dec 2005 22:45:36 -0000      1.43
+++ sys/arch/sh5/sh5/pmap.c     5 Sep 2006 18:57:03 -0000
@@ -1294,7 +1294,7 @@ pmap_create(void)
 static void
 pmap_pinit(pmap_t pm)
 {
-       u_int entropy = (sh5_getctc() >> 2) + (u_int)time.tv_sec;
+       u_int entropy = (sh5_getctc() >> 2) + (u_int)time_second;
        int i;
 
        pm->pm_refs = 1;
Index: sys/arch/sh5/sh5/sh5_clock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh5/sh5/sh5_clock.c,v
retrieving revision 1.10
diff -d -p -u -r1.10 sh5_clock.c
--- sys/arch/sh5/sh5/sh5_clock.c        5 Sep 2006 07:34:54 -0000       1.10
+++ sys/arch/sh5/sh5/sh5_clock.c        5 Sep 2006 18:57:03 -0000
@@ -198,37 +198,3 @@ clock_statint(struct clockframe *cf)
         */
        (*clock_args->ca_start)(clock_args->ca_arg, CLK_STATCLOCK, newint);
 }
-
-/*
- * Return the best possible estimate of the time in the timeval
- * to which tvp points.  We do this by returning the current time
- * plus the amount of time, in uSec, since the last clock interrupt
- * (clock_args->ca_microtime()) was handled.
- *
- * Check that this time is no less than any previously-reported time,
- * which could happen around the time of a clock adjustment.  Just for fun,
- * we guarantee that the time will be greater than the value obtained by a
- * previous call.
- */
-
-void
-microtime(struct timeval *tvp)
-{
-       int s = splhigh();
-       static struct timeval lasttime;
-
-       *tvp = time;
-       tvp->tv_usec += (*clock_args->ca_microtime)(clock_args->ca_arg);
-       while (tvp->tv_usec >= 1000000) {
-               tvp->tv_sec++;
-               tvp->tv_usec -= 1000000;
-       }
-       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);
-}


Home | Main Index | Thread Index | Old Index