summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-04-28 12:24:21 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-04-28 12:24:21 +0000
commit6887b193b9ca540f1400351cad1d1dbf7dca36b2 (patch)
tree0936eace2487bdd5cac6df1c8b36a817f8cef322 /sys
parent16dbe77d9f3281f39779b671dfc667b5a2197458 (diff)
Use the same inittodr()/resettodr() implementation as on arm64/armv7
and move it to the end of machdep.o. ok mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/sparc64/sparc64/clock.c96
-rw-r--r--sys/arch/sparc64/sparc64/machdep.c101
2 files changed, 92 insertions, 105 deletions
diff --git a/sys/arch/sparc64/sparc64/clock.c b/sys/arch/sparc64/sparc64/clock.c
index 3b053f96023..f1a4e453ae7 100644
--- a/sys/arch/sparc64/sparc64/clock.c
+++ b/sys/arch/sparc64/sparc64/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.59 2017/04/30 16:45:45 mpi Exp $ */
+/* $OpenBSD: clock.c,v 1.60 2020/04/28 12:24:20 kettenis Exp $ */
/* $NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp $ */
/*
@@ -884,100 +884,6 @@ schedintr(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(time_t base)
-{
- int badbase = 0, waszero = base == 0;
- char *bad = NULL;
- struct timeval tv;
- struct timespec ts;
-
- tv.tv_sec = tv.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_handle != NULL)
- todr_gettime(todr_handle, &tv);
-
- if (tv.tv_sec == 0) {
- /*
- * Believe the time in the file system for lack of
- * anything better, resetting the clock.
- */
- bad = "WARNING: bad date in battery clock";
- tv.tv_sec = base;
- tv.tv_usec = 0;
- if (!badbase)
- resettodr();
- } else {
- time_t deltat = tv.tv_sec - base;
-
- sparc_clock_time_is_ok = 1;
-
- if (deltat < 0)
- deltat = -deltat;
- if (!(waszero || deltat < 2 * SECDAY)) {
-#ifndef SMALL_KERNEL
- printf("WARNING: clock %s %lld days",
- tv.tv_sec < base ? "lost" : "gained",
- (long long)(deltat / SECDAY));
- bad = "";
-#endif
- }
- }
-
- ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = tv.tv_usec * 1000;
- tc_setclock(&ts);
-
- if (bad) {
- printf("%s", bad);
- 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 tv;
-
- if (time_second == 1)
- return;
-
- microtime(&tv);
-
- 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");
-}
-
void
tick_start(void)
{
diff --git a/sys/arch/sparc64/sparc64/machdep.c b/sys/arch/sparc64/sparc64/machdep.c
index ab10aedb977..b29a6cb3364 100644
--- a/sys/arch/sparc64/sparc64/machdep.c
+++ b/sys/arch/sparc64/sparc64/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.191 2019/04/01 07:00:52 tedu Exp $ */
+/* $OpenBSD: machdep.c,v 1.192 2020/04/28 12:24:20 kettenis Exp $ */
/* $NetBSD: machdep.c,v 1.108 2001/07/24 19:30:14 eeh Exp $ */
/*-
@@ -608,18 +608,10 @@ boot(int howto)
fb_unblank();
boothowto = howto;
if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
- extern int sparc_clock_time_is_ok;
-
waittime = 0;
vfs_shutdown(curproc);
- /*
- * XXX
- * 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()).
- */
- if ((howto & RB_TIMEBAD) == 0 && sparc_clock_time_is_ok) {
+ if ((howto & RB_TIMEBAD) == 0) {
resettodr();
} else {
printf("WARNING: not updating battery clock\n");
@@ -2123,3 +2115,92 @@ blink_led_timeout(void *vsc)
t = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
timeout_add(&sc->bls_to, t);
}
+
+#include <sys/timetc.h>
+#include <dev/clock_subr.h>
+
+todr_chip_handle_t todr_handle;
+
+#define MINYEAR ((OpenBSD / 100) - 1) /* minimum plausible year */
+
+/*
+ * inittodr:
+ *
+ * Initialize time from the time-of-day register.
+ */
+void
+inittodr(time_t base)
+{
+ time_t deltat;
+ struct timeval rtctime;
+ struct timespec ts;
+ int badbase;
+
+ if (base < (MINYEAR - 1970) * SECYR) {
+ printf("WARNING: preposterous time in file system\n");
+ /* read the system clock anyway */
+ base = (MINYEAR - 1970) * SECYR;
+ badbase = 1;
+ } else
+ badbase = 0;
+
+ if (todr_handle == NULL ||
+ todr_gettime(todr_handle, &rtctime) != 0 ||
+ rtctime.tv_sec < (MINYEAR - 1970) * SECYR) {
+ /*
+ * Believe the time in the file system for lack of
+ * anything better, resetting the TODR.
+ */
+ rtctime.tv_sec = base;
+ rtctime.tv_usec = 0;
+ if (todr_handle != NULL && !badbase)
+ printf("WARNING: bad clock chip time\n");
+ ts.tv_sec = rtctime.tv_sec;
+ ts.tv_nsec = rtctime.tv_usec * 1000;
+ tc_setclock(&ts);
+ goto bad;
+ } else {
+ ts.tv_sec = rtctime.tv_sec;
+ ts.tv_nsec = rtctime.tv_usec * 1000;
+ tc_setclock(&ts);
+ }
+
+ if (!badbase) {
+ /*
+ * See if we gained/lost two or more days; if
+ * so, assume something is amiss.
+ */
+ deltat = rtctime.tv_sec - base;
+ if (deltat < 0)
+ deltat = -deltat;
+ if (deltat < 2 * SECDAY)
+ return; /* all is well */
+#ifndef SMALL_KERNEL
+ printf("WARNING: clock %s %lld days\n",
+ rtctime.tv_sec < base ? "lost" : "gained",
+ (long long)(deltat / SECDAY));
+#endif
+ }
+ bad:
+ printf("WARNING: CHECK AND RESET THE DATE!\n");
+}
+
+/*
+ * resettodr:
+ *
+ * Reset the time-of-day register with the current time.
+ */
+void
+resettodr(void)
+{
+ struct timeval rtctime;
+
+ if (time_second == 1)
+ return;
+
+ microtime(&rtctime);
+
+ if (todr_handle != NULL &&
+ todr_settime(todr_handle, &rtctime) != 0)
+ printf("WARNING: can't update clock chip time\n");
+}