Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/emips/ebus - misc KNF



details:   https://anonhg.NetBSD.org/src/rev/069fa6828ae1
branches:  trunk
changeset: 765962:069fa6828ae1
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sun Jun 12 04:17:30 2011 +0000

description:
- misc KNF
- use device_t and cfdata_t

diffstat:

 sys/arch/emips/ebus/clock_ebus.c |  269 +++++++++++++++++++++-----------------
 1 files changed, 146 insertions(+), 123 deletions(-)

diffs (truncated from 397 to 300 lines):

diff -r ad517539bcd4 -r 069fa6828ae1 sys/arch/emips/ebus/clock_ebus.c
--- a/sys/arch/emips/ebus/clock_ebus.c  Sun Jun 12 04:00:33 2011 +0000
+++ b/sys/arch/emips/ebus/clock_ebus.c  Sun Jun 12 04:17:30 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock_ebus.c,v 1.1 2011/01/26 01:18:50 pooka Exp $     */
+/*     $NetBSD: clock_ebus.c,v 1.2 2011/06/12 04:17:30 tsutsui Exp $   */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: clock_ebus.c,v 1.1 2011/01/26 01:18:50 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock_ebus.c,v 1.2 2011/06/12 04:17:30 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -51,62 +51,67 @@
 struct eclock_softc {
        struct device sc_dev;
        struct _Tc *sc_dp;
-    uint32_t reload;
-    struct timecounter sc_tc;
+       uint32_t reload;
+       struct timecounter sc_tc;
 #ifdef __HAVE_GENERIC_TODR
-    struct todr_chip_handle sc_todr;
+       struct todr_chip_handle sc_todr;
 #endif
 };
 
-static int     eclock_ebus_match (struct device *, struct cfdata *, void *);
-static void    eclock_ebus_attach (struct device *, struct device *, void *);
+static int     eclock_ebus_match(device_t, cfdata_t, void *);
+static void    eclock_ebus_attach(device_t, device_t, void *);
 
 CFATTACH_DECL(eclock_ebus, sizeof (struct eclock_softc),
     eclock_ebus_match, eclock_ebus_attach, NULL, NULL);
 
-       void    eclock_init(struct device *);
-static void    __eclock_init(struct device *);
-static int     eclock_gettime(struct todr_chip_handle *,
-                           struct timeval *);
-static int     eclock_settime(struct todr_chip_handle *,
-                           struct timeval *);
-static int  eclock_ebus_intr(void *cookie, void *f);
-static u_int eclock_counter(struct timecounter *tc);
+void   eclock_init(device_t);
 
-struct device *clockdev = NULL; /* BUGBUG resolve the gap between cpu_initclocks() and eclock_init(x) */
+static void    __eclock_init(device_t);
+static int     eclock_gettime(struct todr_chip_handle *, struct timeval *);
+static int     eclock_settime(struct todr_chip_handle *, struct timeval *);
+static int     eclock_ebus_intr(void *, void *);
+static u_int   eclock_counter(struct timecounter *);
+
+/* BUGBUG resolve the gap between cpu_initclocks() and eclock_init(x) */
+device_t clockdev = NULL;
 
 void
-eclock_init(struct device *dev)
+eclock_init(device_t dev)
 {
-    if (dev == NULL)
-        dev = clockdev;
-    if (dev == NULL)
-        panic("eclock_init");
-    __eclock_init(dev);
+
+       if (dev == NULL)
+               dev = clockdev;
+       if (dev == NULL)
+               panic("eclock_init");
+       __eclock_init(dev);
 }
 
 static void
-__eclock_init(struct device *dev)
+__eclock_init(device_t dev)
 {
        struct eclock_softc *sc = (struct eclock_softc *)dev;
-    struct _Tc *tc = sc->sc_dp;
-    uint32_t reload = 10*1000000; /* 1sec in 100ns units (10MHz clock) */
+       struct _Tc *tc = sc->sc_dp;
+       uint32_t reload = 10*1000000; /* 1sec in 100ns units (10MHz clock) */
 
-    /* Compute reload according to whatever value passed in, Warn if fractional */
-    if (hz > 1) {
-        uint32_t r = reload / hz;
-        if ((r * hz) != reload)
-            printf("%s: %d Hz clock will cause roundoffs with 10MHz xtal (%d)\n",
-                   sc->sc_dev.dv_xname, hz, reload - (r * hz));
+       /*
+        * Compute reload according to whatever value passed in,
+        * Warn if fractional
+        */
+       if (hz > 1) {
+               uint32_t r = reload / hz;
+               if ((r * hz) != reload)
+                       printf("%s: %d Hz clock will cause roundoffs"
+                           " with 10MHz xtal (%d)\n",
+                           sc->sc_dev.dv_xname, hz, reload - (r * hz));
                reload = r;
        }
 
-    sc->reload = reload;
+       sc->reload = reload;
 
-    /* Start the counter */
-    tc->DownCounterHigh = 0;
-    tc->DownCounter = sc->reload;
-    tc->Control = TCCT_ENABLE | TCCT_INT_ENABLE;
+       /* Start the counter */
+       tc->DownCounterHigh = 0;
+       tc->DownCounter = sc->reload;
+       tc->Control = TCCT_ENABLE | TCCT_INT_ENABLE;
 }
 
 /*
@@ -120,48 +125,61 @@
 static int
 eclock_gettime(struct todr_chip_handle *todr, struct timeval *tv)
 {
-       struct eclock_softc *sc = (struct eclock_softc *) todr->cookie;
-    struct _Tc *tc = sc->sc_dp;
-    uint64_t free;
-    int s;
+       struct eclock_softc *sc = todr->cookie;
+       struct _Tc *tc = sc->sc_dp;
+       uint64_t free;
+       int s;
 
-    /* 32bit processor, guard against interrupts in the middle of reading this 64bit entity
-     * BUGBUG Should read it "twice" to guard against rollover too.
-     */
+       /*
+        * 32bit processor, guard against interrupts in the middle of
+        * reading this 64bit entity
+        */
+       /* BUGBUG Should read it "twice" to guard against rollover too. */
        s = splhigh();
-    free = tc->FreeRunning;
+       free = tc->FreeRunning;
        splx(s);
 
-    /* Big fight with the compiler here, it gets very confused by 64bits.
-     */
+       /*
+        * Big fight with the compiler here, it gets very confused by 64bits.
+        */
 #if 0
-    /* This is in C: 
-     */
-    {
-        uint64_t freeS, freeU;
-        freeS = free / (10*1000*1000);
-        freeU = free % (10*1000*1000);
-        tv->tv_sec  = freeS;
-        tv->tv_usec = freeU / 10;
-        //printf("egt: s x%lx u x%lx (fs %lld fu %lld f %lld)\n",tv->tv_sec,tv->tv_usec,freeS,freeU,free);
-    }
+       /*
+        * This is in C: 
+        */
+       {
+               uint64_t freeS, freeU;
+               freeS = free / (10 * 1000 * 1000);
+               freeU = free % (10 * 1000 * 1000);
+               tv->tv_sec  = freeS;
+               tv->tv_usec = freeU / 10;
+#if 0
+               printf("egt: s x%" PRIx64 " u x%lx (fs %" PRId64
+                   " fu %" PRId64 " f %" PRId64 ")\n",
+                   tv->tv_sec, tv->tv_usec, freeS, freeU, free);
+#endif
+       }
 #else
-    /* And this is in assembly :-)
-     */
-    {
-        u_quad_t r;
-        u_quad_t d = __qdivrem(free,(u_quad_t)10000000,&r);
-        uint32_t su, uu;
-        su = (uint32_t) d;
-        uu = (uint32_t) r;
-        uu = uu / 10; /* in usecs */
-        tv->tv_sec  = su;
-        tv->tv_usec = uu;
-        //printf("egt: s x%lx u x%lx  (d %lld r %lld  f %lld)\n",tv->tv_sec,tv->tv_usec,d,r,free);
-    }
+       /*
+        * And this is in assembly :-)
+        */
+       {
+               u_quad_t r;
+               u_quad_t d = __qdivrem(free,(u_quad_t)10000000,&r);
+               uint32_t su, uu;
+               su = (uint32_t)d;
+               uu = (uint32_t)r;
+               uu = uu / 10;   /* in usecs */
+               tv->tv_sec  = su;
+               tv->tv_usec = uu;
+#if 0
+               printf("egt: s x%" PRIx64 " u x%lx (fs %" PRId64
+                   " fu %" PRId64 " f %" PRId64 ")\n",
+                   tv->tv_sec, tv->tv_usec, d, r, free);
+#endif
+       }
 #endif
 
-    return 0;
+       return 0;
 }
 
 /*
@@ -170,26 +188,27 @@
 static int
 eclock_settime(struct todr_chip_handle *todr, struct timeval *tv)
 {
-       struct eclock_softc *sc = (struct eclock_softc *) todr->cookie;
-    struct _Tc *tc = sc->sc_dp;
-    uint64_t free;
-    uint32_t su, uu;
-    int s;
+       struct eclock_softc *sc = todr->cookie;
+       struct _Tc *tc = sc->sc_dp;
+       uint64_t free;
+       uint32_t su, uu;
+       int s;
 
-    /* Careful with what we do here, else the compilerbugs hit hard */
+       /* Careful with what we do here, else the compilerbugs hit hard */
        s = splhigh();
 
-    su = (uint32_t) tv->tv_sec;  //0(tv)
-    uu = (uint32_t) tv->tv_usec; //4(tv)
+       su = (uint32_t)tv->tv_sec;      /* 0(tv) */
+       uu = (uint32_t)tv->tv_usec;     /* 4(tv) */
 
 
-    free  = 10*1000*1000 * (uint64_t)su;
-    free += uu * 10;
+       free  = 10 * 1000 * 1000 * (uint64_t)su;
+       free += uu * 10;
 
-    tc->FreeRunning = free;
+       tc->FreeRunning = free;
        splx(s);
 
 #if 0
+/* 
 Should compile to something like this:
 80260c84 <eclock_settime>:
 80260c84:      27bdffc0        addiu   sp,sp,-64
@@ -226,81 +245,85 @@
 80260d00:      aeb00008        sw      s0,8(s5)
 80260d04:      0c00413f        jal     800104fc <_splset>
 80260d08:      00000000        nop
-
+*/
 #endif
 
-    //printf("est: s x%lx u x%lx (%d %d), free %lld\n",tv->tv_sec,tv->tv_usec,su,uu,free);
+#if 0
+       printf("est: s x%" PRIx64 " u x%lx (%d %d), free %" PRId64 "\n",
+           tv->tv_sec, tv->tv_usec, su, uu, free);
+#endif
 
-    return 0;
+       return 0;
 }
 
 static int
 eclock_ebus_intr(void *cookie, void *f)
 {
        struct eclock_softc *sc = cookie;
-    struct _Tc *tc = sc->sc_dp;
-    struct clockframe *cf = f;
-    volatile uint32_t x;
+       struct _Tc *tc = sc->sc_dp;
+       struct clockframe *cf = f;
+       volatile uint32_t x;
 
-    x = tc->Control;
-    tc->DownCounterHigh = 0;
-    tc->DownCounter = sc->reload;
+       x = tc->Control;
+       tc->DownCounterHigh = 0;
+       tc->DownCounter = sc->reload;
 
-    hardclock(cf);
-    emips_clock_evcnt.ev_count++;
+       hardclock(cf);
+       emips_clock_evcnt.ev_count++;
 
-       return (0);
+       return 0;
 }
 



Home | Main Index | Thread Index | Old Index