Convert both sparc and sparc64 to MI todr.

This commit is contained in:
gdamore 2006-09-03 22:27:45 +00:00
parent 93a520d8b0
commit b46bdc5e2b
7 changed files with 34 additions and 238 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: types.h,v 1.44 2006/09/03 13:51:24 bjh21 Exp $ */
/* $NetBSD: types.h,v 1.45 2006/09/03 22:27:45 gdamore Exp $ */
/*
* Copyright (c) 1992, 1993
@ -106,6 +106,7 @@ typedef volatile int __cpu_simple_lock_t;
#define __HAVE_SYSCALL_INTERN
#define __GENERIC_SOFT_INTERRUPTS_ALL_LEVELS
#define __HAVE_TIMECOUNTER
#define __HAVE_GENERIC_TODR
#ifdef SUN4U
#define __HAVE_CPU_COUNTER /* sparc v9 CPUs have %tick */

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.97 2006/06/07 22:38:49 kardel Exp $ */
/* $NetBSD: clock.c,v 1.98 2006/09/03 22:27:45 gdamore Exp $ */
/*
* Copyright (c) 1992, 1993
@ -88,7 +88,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.97 2006/06/07 22:38:49 kardel Exp $");
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.98 2006/09/03 22:27:45 gdamore Exp $");
#include "opt_sparc_arch.h"
@ -140,9 +140,6 @@ static void eeprom_give(void);
static int eeprom_update(char *, int, int);
#endif
/* Global TOD clock handle */
todr_chip_handle_t todr_handle;
/*
* Set up the real-time and statistics clocks.
* Leave stathz 0 only if no alternative timer is available.
@ -211,93 +208,6 @@ schedintr(void *v)
schedclock(l);
}
/*
* `sparc_clock_time_is_ok' is used in cpu_reboot() to determine
* whether it is appropriate to call resettodr() to consolidate
* pending time adjustments.
*/
int sparc_clock_time_is_ok;
/*
* Set up the system's time, given a `reasonable' time value.
*/
void
inittodr(time_t base)
{
int badbase = 0, waszero = base == 0;
struct timeval time;
struct timespec ts;
time.tv_sec = 0;
time.tv_usec = 0;
if (base < 5 * SECYR) {
/*
* If base is 0, assume filesystem time is just unknown
* in stead of preposterous. Don't bark.
*/
if (base != 0)
printf("WARNING: preposterous time in file system\n");
/* not going to use it anyway, if the chip is readable */
base = 21*SECYR + 186*SECDAY + SECDAY/2;
badbase = 1;
}
if (todr_gettime(todr_handle, &time) != 0 ||
time.tv_sec == 0) {
printf("WARNING: bad date in battery clock");
/*
* Believe the time in the file system for lack of
* anything better, resetting the clock.
*/
ts.tv_sec = base;
ts.tv_nsec = 0;
tc_setclock(&ts);
if (!badbase)
resettodr();
} else {
int deltat = time.tv_sec - base;
sparc_clock_time_is_ok = 1;
ts.tv_sec = time.tv_sec;
ts.tv_nsec = time.tv_usec * 1000;
tc_setclock(&ts);
if (deltat < 0)
deltat = -deltat;
if (waszero || deltat < 2 * SECDAY)
return;
printf("WARNING: clock %s %d days",
time.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
}
printf(" -- CHECK AND RESET THE DATE!\n");
}
/*
* Reset the clock based on the current time.
* Used when the current clock is preposterous, when the time is changed,
* and when rebooting. Do nothing if the time is not yet known, e.g.,
* when crashing during autoconfig.
*/
void
resettodr(void)
{
struct timeval time;
getmicrotime(&time);
if (time.tv_sec == 0)
return;
sparc_clock_time_is_ok = 1;
if (todr_settime(todr_handle, &time) != 0)
printf("Cannot set time in time-of-day clock\n");
}
/*
* XXX: these may actually belong somewhere else, but since the
* EEPROM is so closely tied to the clock on some models, perhaps

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.263 2005/12/11 12:19:08 christos Exp $ */
/* $NetBSD: machdep.c,v 1.264 2006/09/03 22:27:45 gdamore Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -78,7 +78,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.263 2005/12/11 12:19:08 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.264 2006/09/03 22:27:45 gdamore Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_sunos.h"
@ -1051,7 +1051,6 @@ cpu_reboot(int howto, char *user_boot_string)
boothowto = howto;
if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
extern struct lwp lwp0;
extern int sparc_clock_time_is_ok;
/* XXX protect against curlwp->p_stats.foo refs in sync() */
if (curlwp == NULL)
@ -1062,12 +1061,10 @@ cpu_reboot(int howto, char *user_boot_string)
/*
* If we've been adjusting the clock, the todr
* will be out of synch; adjust it now.
* Do this only if the TOD clock has already been read out
* successfully by inittodr() or set by an explicit call
* to resettodr() (e.g. from settimeofday()).
* resettodr will only do this only if inittodr()
* has already been called.
*/
if (sparc_clock_time_is_ok)
resettodr();
resettodr();
}
/* Disable interrupts. But still allow IPI on MP systems */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkclock.c,v 1.13 2005/11/14 19:11:24 uwe Exp $ */
/* $NetBSD: mkclock.c,v 1.14 2006/09/03 22:27:45 gdamore Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mkclock.c,v 1.13 2005/11/14 19:11:24 uwe Exp $");
__KERNEL_RCSID(0, "$NetBSD: mkclock.c,v 1.14 2006/09/03 22:27:45 gdamore Exp $");
#include "opt_sparc_arch.h"
@ -90,7 +90,6 @@ CFATTACH_DECL(clock_bootbus, sizeof(struct mk48txx_softc),
clockmatch_bootbus, clockattach_bootbus, NULL, NULL);
/* Imported from clock.c: */
extern todr_chip_handle_t todr_handle;
extern int (*eeprom_nvram_wenable)(int);
@ -248,9 +247,6 @@ clockattach(struct mk48txx_softc *sc, int node)
sc->sc_year0 = 1968;
mk48txx_attach(sc);
/* XXX this should be done by todr_attach() */
todr_handle = &sc->sc_handle;
printf("\n");
/*
@ -258,11 +254,13 @@ clockattach(struct mk48txx_softc *sc, int node)
* by mk_nvram_wenable().
*/
mk_nvram_base = sc->sc_bsh;
if (mk48txx_get_nvram_size(todr_handle, &mk_nvram_size) != 0)
if (mk48txx_get_nvram_size(&sc->sc_handle, &mk_nvram_size) != 0)
panic("Cannot get nvram size on %s", sc->sc_model);
/* Establish clock write-enable method */
todr_handle->todr_setwen = mk_clk_wenable;
sc->sc_handle.todr_setwen = mk_clk_wenable;
todr_attach(&sc->sc_handle);
#if defined(SUN4)
if (CPU_ISSUN4) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: oclock.c,v 1.12 2005/11/16 03:00:23 uwe Exp $ */
/* $NetBSD: oclock.c,v 1.13 2006/09/03 22:27:45 gdamore Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: oclock.c,v 1.12 2005/11/16 03:00:23 uwe Exp $");
__KERNEL_RCSID(0, "$NetBSD: oclock.c,v 1.13 2006/09/03 22:27:45 gdamore Exp $");
#include "opt_sparc_arch.h"
@ -61,7 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: oclock.c,v 1.12 2005/11/16 03:00:23 uwe Exp $");
#include <dev/ic/intersil7170.h>
/* Imported from clock.c: */
extern todr_chip_handle_t todr_handle;
extern int oldclk;
extern int timerblurb;
extern void (*timer_init)(void);
@ -132,6 +131,7 @@ oclockattach(struct device *parent, struct device *self, void *aux)
struct obio4_attach_args *oba = &uoba->uoba_oba4;
bus_space_tag_t bt = oba->oba_bustag;
bus_space_handle_t bh;
todr_chip_handle_t tch;
oldclk = 1; /* we've got an oldie! */
@ -192,9 +192,10 @@ oclockattach(struct device *parent, struct device *self, void *aux)
intr_establish(10, 0, &level10, NULL);
/* Our TOD clock year 0 represents 1968 */
if ((todr_handle = intersil7170_attach(bt, bh, 1968)) == NULL)
if ((tch = intersil7170_attach(bt, bh, 1968)) == NULL)
panic("Can't attach tod clock");
printf("\n");
todr_attach(tch);
#endif /* SUN4 */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.79 2006/06/07 22:39:38 kardel Exp $ */
/* $NetBSD: clock.c,v 1.80 2006/09/03 22:27:45 gdamore Exp $ */
/*
* Copyright (c) 1992, 1993
@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.79 2006/06/07 22:39:38 kardel Exp $");
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.80 2006/09/03 22:27:45 gdamore Exp $");
#include "opt_multiprocessor.h"
@ -146,9 +146,6 @@ CFATTACH_DECL(rtc_ebus, sizeof(struct mc146818_softc),
extern struct cfdriver clock_cd;
/* Global TOD clock handle */
static todr_chip_handle_t todr_handle = NULL;
static int timermatch(struct device *, struct cfdata *, void *);
static void timerattach(struct device *, struct device *, void *);
@ -244,7 +241,9 @@ clockattach_sbus(struct device *parent, struct device *self, void *aux)
clockattach(sc, sa->sa_node);
/* Save info for the clock wenable call. */
todr_handle->todr_setwen = clock_wenable;
sc->sc_handle.todr_setwen = clock_wenable;
todr_attach(&sc->sc_handle);
}
/*
@ -304,7 +303,9 @@ clockattach_ebus(struct device *parent, struct device *self, void *aux)
clockattach(sc, ea->ea_node);
/* Save info for the clock wenable call. */
todr_handle->todr_setwen = clock_wenable;
sc->sc_handle.todr_setwen = clock_wenable;
todr_attach(&sc->sc_handle);
}
@ -324,9 +325,6 @@ clockattach(struct mk48txx_softc *sc, int node)
mk48txx_attach(sc);
printf("\n");
/* XXX should be done by todr_attach() */
todr_handle = &sc->sc_handle;
}
/*
@ -412,8 +410,7 @@ clockattach_rtc(struct device *parent, struct device *self, void *aux)
*/
/*sc->sc_handle.todr_setwen = NULL;*/
/* XXX should be done by todr_attach() */
todr_handle = &sc->sc_handle;
todr_attach(&sc->sc_handle);
}
static u_int timer_get_timecount(struct timecounter *);
@ -801,111 +798,6 @@ schedintr(void *arg)
return (1);
}
/*
* `sparc_clock_time_is_ok' is used in cpu_reboot() to determine
* whether it is appropriate to call resettodr() to consolidate
* pending time adjustments.
*/
int sparc_clock_time_is_ok;
/*
* Set up the system's time, given a `reasonable' time value.
*/
void
inittodr(base)
time_t base;
{
int badbase = 0, waszero = base == 0;
int no_valid_todr = 1;
struct timeval tv;
struct timeval time;
struct timespec ts;
time.tv_sec = 0;
time.tv_usec = 0;
if (base < 5 * SECYR) {
/*
* If base is 0, assume filesystem time is just unknown
* in stead of preposterous. Don't bark.
*/
if (base != 0)
printf("WARNING: preposterous time in file system\n");
/* not going to use it anyway, if the chip is readable */
base = 33*SECYR + 186*SECDAY + SECDAY/2;
badbase = 1;
}
if (todr_handle) {
if (todr_gettime(todr_handle, &tv) == 0) {
if (tv.tv_sec != 0) {
time = tv;
no_valid_todr = 0;
}
}
}
if (no_valid_todr) {
printf("WARNING: bad date in battery clock");
/*
* Believe the time in the file system for lack of
* anything better, resetting the clock.
*/
ts.tv_sec = base;
ts.tv_nsec = 0;
tc_setclock(&ts);
if (!badbase)
resettodr();
} else {
int deltat;
deltat = time.tv_sec - base;
sparc_clock_time_is_ok = 1;
ts.tv_sec = time.tv_sec;
ts.tv_nsec = time.tv_usec * 1000;
tc_setclock(&ts);
if (waszero)
return;
if (deltat < 0) {
deltat = -deltat;
if (deltat < 2 * SECDAY)
return;
} else if (deltat < 2 * SECYR) {
return;
}
printf("WARNING: clock %s %d days",
time.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
}
printf(" -- CHECK AND RESET THE DATE!\n");
}
/*
* Reset the clock based on the current time.
* Used when the current clock is preposterous, when the time is changed,
* and when rebooting. Do nothing if the time is not yet known, e.g.,
* when crashing during autoconfig.
*/
void
resettodr()
{
struct timeval tv;
getmicrotime(&tv);
if (tv.tv_sec == 0)
return;
sparc_clock_time_is_ok = 1;
if (todr_handle == 0 || todr_settime(todr_handle, &tv) != 0)
printf("Cannot set time in time-of-day clock\n");
}
/*
* XXX: these may actually belong somewhere else, but since the
* EEPROM is so closely tied to the clock on some models, perhaps

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.188 2006/09/01 09:21:18 mrg Exp $ */
/* $NetBSD: machdep.c,v 1.189 2006/09/03 22:27:45 gdamore Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -78,7 +78,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.188 2006/09/01 09:21:18 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.189 2006/09/03 22:27:45 gdamore Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@ -615,7 +615,6 @@ cpu_reboot(register int howto, char *user_boot_string)
boothowto = howto;
if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
extern struct lwp lwp0;
extern int sparc_clock_time_is_ok;
/* XXX protect against curlwp->p_stats.foo refs in sync() */
if (curlwp == NULL)
@ -626,12 +625,10 @@ cpu_reboot(register int howto, char *user_boot_string)
/*
* If we've been adjusting the clock, the todr
* will be out of synch; adjust it now.
* Do this only if the TOD clock has already been read out
* successfully by inittodr() or set by an explicit call
* to resettodr() (e.g. from settimeofday()).
* resettodr will only do this only if inittodr()
* has already been called.
*/
if (sparc_clock_time_is_ok)
resettodr();
resettodr();
}
(void) splhigh(); /* ??? */