From 8e61a34d9fa70331751beac5eb62d7def78f8f82 Mon Sep 17 00:00:00 2001 From: gdamore Date: Thu, 14 Sep 2006 15:04:07 +0000 Subject: [PATCH] Update luna68k to MI todr and timecounters. --- sys/arch/luna68k/dev/timekeeper.c | 81 +++++++------------ sys/arch/luna68k/include/types.h | 5 +- sys/arch/luna68k/luna68k/clock.c | 118 +--------------------------- sys/arch/luna68k/luna68k/clockvar.h | 53 ------------- sys/arch/luna68k/luna68k/machdep.c | 35 +-------- 5 files changed, 38 insertions(+), 254 deletions(-) delete mode 100644 sys/arch/luna68k/luna68k/clockvar.h diff --git a/sys/arch/luna68k/dev/timekeeper.c b/sys/arch/luna68k/dev/timekeeper.c index 1f105584464c..237e8f0be9d7 100644 --- a/sys/arch/luna68k/dev/timekeeper.c +++ b/sys/arch/luna68k/dev/timekeeper.c @@ -1,4 +1,4 @@ -/* $NetBSD: timekeeper.c,v 1.3 2006/03/12 22:55:19 he Exp $ */ +/* $NetBSD: timekeeper.c,v 1.4 2006/09/14 15:04:07 gdamore Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: timekeeper.c,v 1.3 2006/03/12 22:55:19 he Exp $"); +__KERNEL_RCSID(0, "$NetBSD: timekeeper.c,v 1.4 2006/09/14 15:04:07 gdamore Exp $"); #include #include @@ -48,7 +48,6 @@ __KERNEL_RCSID(0, "$NetBSD: timekeeper.c,v 1.3 2006/03/12 22:55:19 he Exp $"); #include #include -#include #include #include @@ -59,6 +58,7 @@ struct timekeeper_softc { void *sc_clock, *sc_nvram; int sc_nvramsize; u_int8_t sc_image[2040]; + struct todr_chip_handle sc_todr; }; static int clock_match __P((struct device *, struct cfdata *, void *)); @@ -68,18 +68,10 @@ CFATTACH_DECL(clock, sizeof (struct timekeeper_softc), clock_match, clock_attach, NULL, NULL); extern struct cfdriver clock_cd; -static void mkclock_get __P((struct device *, time_t, struct clock_ymdhms *)); -static void mkclock_set __P((struct device *, struct clock_ymdhms *)); -static void dsclock_get __P((struct device *, time_t, struct clock_ymdhms *)); -static void dsclock_set __P((struct device *, struct clock_ymdhms *)); - -static struct clockfns mkclock_clockfns = { - NULL /* never used */, mkclock_get, mkclock_set, -}; - -static struct clockfns dsclock_clockfns = { - NULL /* never used */, dsclock_get, dsclock_set, -}; +static int mkclock_get __P((todr_chip_handle_t, struct clock_ymdhms *)); +static int mkclock_set __P((todr_chip_handle_t, struct clock_ymdhms *)); +static int dsclock_get __P((todr_chip_handle_t, struct clock_ymdhms *)); +static int dsclock_set __P((todr_chip_handle_t, struct clock_ymdhms *)); static int clock_match(parent, match, aux) @@ -101,7 +93,6 @@ clock_attach(parent, self, aux) { struct timekeeper_softc *sc = (void *)self; struct mainbus_attach_args *ma = aux; - struct clockfns *clockwork; switch (machtype) { default: @@ -109,31 +100,32 @@ clock_attach(parent, self, aux) sc->sc_clock = (void *)(ma->ma_addr + 2040); sc->sc_nvram = (void *)ma->ma_addr; sc->sc_nvramsize = 2040; - clockwork = &mkclock_clockfns; + sc->sc_todr.todr_gettime_ymdhms = mkclock_get; + sc->sc_todr.todr_settime_ymdhms = mkclock_set; + sc->sc_todr.cookie = sc; printf(": mk48t02\n"); break; case LUNA_II: /* Dallas DS1287A */ sc->sc_clock = (void *)ma->ma_addr; sc->sc_nvram = (void *)(ma->ma_addr + 50); sc->sc_nvramsize = 50; - clockwork = &dsclock_clockfns; + sc->sc_todr.todr_gettime_ymdhms = dsclock_get; + sc->sc_todr.todr_settime_ymdhms = dsclock_set; + sc->sc_todr.cookie = sc; printf(": ds1287a\n"); break; } - clockattach(&sc->sc_dev, clockwork); + todr_attach(&sc->sc_todr); memcpy(sc->sc_image, sc->sc_nvram, sc->sc_nvramsize); } /* * Get the time of day, based on the clock's value and/or the base value. */ -static void -mkclock_get(dev, base, dt) - struct device *dev; - time_t base; - struct clock_ymdhms *dt; +static int +mkclock_get(todr_chip_handle_t tch, struct clock_ymdhms *dt) { - struct timekeeper_softc *sc = (void *)dev; + struct timekeeper_softc *sc = (void *)tch->cookie; volatile u_int8_t *chiptime = (void *)sc->sc_clock; int s; @@ -148,22 +140,16 @@ mkclock_get(dev, base, dt) dt->dt_year = FROMBCD(chiptime[MK_YEAR]) + YEAR0; chiptime[MK_CSR] &= ~MK_CSR_READ; /* time wears on */ splx(s); -#ifdef TIMEKEEPER_DEBUG - printf("get %d/%d/%d %d:%d:%d\n", - dt->dt_year, dt->dt_mon, dt->dt_day, - dt->dt_hour, dt->dt_min, dt->dt_sec); -#endif + return 0; } /* * Reset the TODR based on the time value. */ -static void -mkclock_set(dev, dt) - struct device *dev; - struct clock_ymdhms *dt; +static int +mkclock_set(todr_chip_handle_t tch, struct clock_ymdhms *dt) { - struct timekeeper_softc *sc = (void *)dev; + struct timekeeper_softc *sc = (void *)tch->cookie; volatile u_int8_t *chiptime = (void *)sc->sc_clock; volatile u_int8_t *stamp = (u_int8_t *)sc->sc_nvram + 0x10; int s; @@ -179,25 +165,18 @@ mkclock_set(dev, dt) chiptime[MK_YEAR] = TOBCD(dt->dt_year - YEAR0); chiptime[MK_CSR] &= ~MK_CSR_WRITE; /* load them up */ splx(s); -#ifdef TIMEKEEPER_DEBUG - printf("set %d/%d/%d %d:%d:%d\n", - dt->dt_year, dt->dt_mon, dt->dt_day, - dt->dt_hour, dt->dt_min, dt->dt_sec); -#endif stamp[0] = 'R'; stamp[1] = 'T'; stamp[2] = 'C'; stamp[3] = '\0'; + return 0; } /* * Get the time of day, based on the clock's value and/or the base value. */ -static void -dsclock_get(dev, base, dt) - struct device *dev; - time_t base; - struct clock_ymdhms *dt; +static int +dsclock_get(todr_chip_handle_t tch, struct clock_ymdhms *dt) { - struct timekeeper_softc *sc = (void *)dev; + struct timekeeper_softc *sc = (void *)tch->cookie; volatile u_int8_t *chiptime = (void *)sc->sc_clock; int s; @@ -213,17 +192,16 @@ dsclock_get(dev, base, dt) dt->dt_mon = chiptime[MC_MONTH]; dt->dt_year = chiptime[MC_YEAR] + YEAR0; splx(s); + return 0; } /* * Reset the TODR based on the time value. */ -static void -dsclock_set(dev, dt) - struct device *dev; - struct clock_ymdhms *dt; +static int +dsclock_set(todr_chip_handle_t tch, struct clock_ymdhms *dt) { - struct timekeeper_softc *sc = (void *)dev; + struct timekeeper_softc *sc = (void *)tch->cookie; volatile u_int8_t *chiptime = (void *)sc->sc_clock; int s; @@ -238,4 +216,5 @@ dsclock_set(dev, dt) chiptime[MC_YEAR] = dt->dt_year - YEAR0; chiptime[MC_REGB] &= ~MC_REGB_SET; /* load them up */ splx(s); + return 0; } diff --git a/sys/arch/luna68k/include/types.h b/sys/arch/luna68k/include/types.h index 1f63bb6a8038..3f559248bd81 100644 --- a/sys/arch/luna68k/include/types.h +++ b/sys/arch/luna68k/include/types.h @@ -1,8 +1,11 @@ -/* $NetBSD: types.h,v 1.2 2002/02/28 03:17:33 simonb Exp $ */ +/* $NetBSD: types.h,v 1.3 2006/09/14 15:04:07 gdamore Exp $ */ #ifndef _MACHINE_TYPES_H_ #define _MACHINE_TYPES_H_ #include +#define __HAVE_TIMECOUNTER +#define __HAVE_GENERIC_TODR + #endif diff --git a/sys/arch/luna68k/luna68k/clock.c b/sys/arch/luna68k/luna68k/clock.c index d3afb8208fd3..655449f0cf08 100644 --- a/sys/arch/luna68k/luna68k/clock.c +++ b/sys/arch/luna68k/luna68k/clock.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.4 2005/12/11 12:17:52 christos Exp $ */ +/* $NetBSD: clock.c,v 1.5 2006/09/14 15:04:07 gdamore Exp $ */ /* * Copyright (c) 1992, 1993 @@ -78,7 +78,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.4 2005/12/11 12:17:52 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.5 2006/09/14 15:04:07 gdamore Exp $"); #include #include @@ -88,28 +88,6 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.4 2005/12/11 12:17:52 christos Exp $"); #include #include -#include - -#define CLOCK_LEVEL 5 -#include - -static struct device *clockdev; -static struct clockfns *clockfns; -static int clockinitted; - -void -clockattach(dev, fns) - struct device *dev; - struct clockfns *fns; -{ - /* - * Just bookkeeping. - */ - if (clockfns != NULL) - panic("clockattach: multiple clocks"); - clockdev = dev; - clockfns = fns; -} /* * Machine-dependent clock routines. @@ -117,11 +95,6 @@ clockattach(dev, fns) * Startrtclock restarts the real-time clock, which provides * hardclock interrupts to kern_clock.c. * - * Inittodr initializes the time of day hardware which provides - * date functions. Its primary function is to use some file - * system information in case the hardare clock lost state. - * - * Resettodr restores the time of day hardware after a time change. */ int clock_enable; /* XXX to be removed XXX */ @@ -135,21 +108,11 @@ cpu_initclocks() { int s; - if (clockfns == NULL) - panic("cpu_initclocks: no clock attached"); - if (machtype == LUNA_I) hz = 60; /* LUNA-I is clocked at 60Hz, not 100Hz */ tick = 1000000 / hz; /* number of microseconds between interrupts */ - tickfix = 1000000 - (hz * tick); - if (tickfix) { - int ftp; - ftp = min(ffs(tickfix), ffs(hz)); - tickfix >>= (ftp - 1); - tickfixinterval = hz >> (ftp - 1); - } /* * Get the clock started. */ @@ -175,80 +138,3 @@ setstatclockrate(newhz) { /* nothing we can do */ } - -/* - * Initialze the time of day register, based on the time base which is, e.g. - * from a filesystem. Base provides the time to within six months, - * and the time of year clock (if any) provides the rest. - */ -void -inittodr(base) - time_t base; -{ - struct clock_ymdhms dt; - time_t deltat; - int badbase; - - if (base < 5*SECYR) { - printf("WARNING: preposterous time in file system"); - /* read the system clock anyway */ - base = 6*SECYR + 186*SECDAY + SECDAY/2; - badbase = 1; - } else - badbase = 0; - - (*clockfns->cf_get)(clockdev, base, &dt); - clockinitted = 1; - /* simple sanity checks */ - if (dt.dt_year < 1970 || dt.dt_mon < 1 || dt.dt_mon > 12 - || dt.dt_day < 1 || dt.dt_day > 31 - || dt.dt_hour > 23 || dt.dt_min > 59 || dt.dt_sec > 59) { - /* - * Believe the time in the file system for lack of - * anything better, resetting the TODR. - */ - time.tv_sec = base; - if (!badbase) { - printf("WARNING: preposterous clock chip time"); - resettodr(); - } - goto bad; - } - /* now have days since Jan 1, 1970; the rest is easy... */ - time.tv_sec = clock_ymdhms_to_secs(&dt); - - if (!badbase) { - /* - * See if we gained/lost two or more days; - * if so, assume something is amiss. - */ - deltat = time.tv_sec - base; - if (deltat < 0) - deltat = -deltat; - if (deltat < 2 * SECDAY) - return; - printf("WARNING: clock %s %d days", - time.tv_sec < base ? "lost" : "gained", - (int) (deltat / SECDAY)); - } -bad: - printf(" -- CHECK AND RESET THE DATE!\n"); -} - -/* - * Reset the TODR based on the time value; used when the TODR - * has a preposterous value and also when the time is reset - * by the stime system call. Also called when the TODR goes past - * TODRZERO + 100*(SECYEAR+2*SECDAY) (e.g. on Jan 2 just after midnight) - * to wrap the TODR around. - */ -void -resettodr() -{ - struct clock_ymdhms dt; - - if (!clockinitted) - return; - clock_secs_to_ymdhms(time.tv_sec, &dt); - (*clockfns->cf_set)(clockdev, &dt); -} diff --git a/sys/arch/luna68k/luna68k/clockvar.h b/sys/arch/luna68k/luna68k/clockvar.h deleted file mode 100644 index 69795a025701..000000000000 --- a/sys/arch/luna68k/luna68k/clockvar.h +++ /dev/null @@ -1,53 +0,0 @@ -/* $NetBSD: clockvar.h,v 1.1 2000/01/05 08:49:02 nisimura Exp $ */ - -/*- - * Copyright (c) 2000 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Tohru Nishimura. - * - * 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 REGENTS 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. - */ - -struct clock_ymdhms; - -/* - * clockfns structure: - * - * function switch used by chip-independent clock code, to access - * chip-dependent routines. - */ -struct clockfns { - void (*cf_init) __P((struct device *)); - void (*cf_get) __P((struct device *, time_t, struct clock_ymdhms *)); - void (*cf_set) __P((struct device *, struct clock_ymdhms *)); -}; - -void clockattach __P((struct device *, struct clockfns *)); diff --git a/sys/arch/luna68k/luna68k/machdep.c b/sys/arch/luna68k/luna68k/machdep.c index a01656d005f3..67469e6f23e1 100644 --- a/sys/arch/luna68k/luna68k/machdep.c +++ b/sys/arch/luna68k/luna68k/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.45 2006/08/04 02:26:49 mhitch Exp $ */ +/* $NetBSD: machdep.c,v 1.46 2006/09/14 15:04:07 gdamore Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.45 2006/08/04 02:26:49 mhitch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.46 2006/09/14 15:04:07 gdamore Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -804,37 +804,6 @@ cpu_exec_aout_makecmds(l, epp) return error; } -/* - * Return the best possible estimate of the time in the timeval - * to which tvp points. Unfortunately, we can't read the hardware registers. - * We guarantee that the time will be greater than the value obtained by a - * previous call. - */ -void -microtime(tvp) - register struct timeval *tvp; -{ - int s = splclock(); - static struct timeval lasttime; - - *tvp = time; -#ifdef notdef - tvp->tv_usec += clkread(); - while (tvp->tv_usec >= 1000000) { - tvp->tv_sec++; - tvp->tv_usec -= 1000000; - } -#endif - 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); -} - #if 1 struct consdev *cn_tab = &syscons;