summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-05-12 15:13:19 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-05-12 15:13:19 +0000
commit4fc0819da21a6f199bab883907ef72c4b2c78665 (patch)
tree63b193ed9f068cedb4bcc865ff9fc418e0b2e145 /sys
parente5a0bf78f71deb45fa20c46acf061566f6e6f074 (diff)
Finally switch luna88k to the same inittodr()/resettodr() implementation
as all the other architectures.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/luna88k/luna88k/clock.c122
-rw-r--r--sys/arch/luna88k/luna88k/machdep.c94
2 files changed, 123 insertions, 93 deletions
diff --git a/sys/arch/luna88k/luna88k/clock.c b/sys/arch/luna88k/luna88k/clock.c
index 70f0b5c053a..a04120987e0 100644
--- a/sys/arch/luna88k/luna88k/clock.c
+++ b/sys/arch/luna88k/luna88k/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.13 2017/11/03 09:07:54 aoyama Exp $ */
+/* $OpenBSD: clock.c,v 1.14 2020/05/12 15:13:18 kettenis Exp $ */
/* $NetBSD: clock.c,v 1.2 2000/01/11 10:29:35 nisimura Exp $ */
/*
@@ -61,7 +61,31 @@
struct device *clockdev;
const struct clockfns *clockfns;
struct evcount *clockevc;
-int clockinitted, todrvalid;
+int clockinitted;
+
+extern todr_chip_handle_t todr_handle;
+struct todr_chip_handle rtc_todr;
+
+int
+rtc_gettime(struct todr_chip_handle *handle, struct timeval *tv)
+{
+ struct clock_ymdhms dt;
+
+ (*clockfns->cf_get)(clockdev, tv->tv_sec, &dt);
+ tv->tv_sec = clock_ymdhms_to_secs(&dt);
+ tv->tv_usec = 0;
+ return 0;
+}
+
+int
+rtc_settime(struct todr_chip_handle *handle, struct timeval *tv)
+{
+ struct clock_ymdhms dt;
+
+ clock_secs_to_ymdhms(tv->tv_sec, &dt);
+ (*clockfns->cf_set)(clockdev, &dt);
+ return 0;
+}
void
clockattach(struct device *dev, const struct clockfns *fns,
@@ -79,15 +103,6 @@ clockattach(struct device *dev, const struct clockfns *fns,
/*
* Machine-dependent clock routines.
- *
- * 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.
*/
u_int clock_get_tc(struct timecounter *);
@@ -117,6 +132,10 @@ cpu_initclocks()
clock_tc.tc_frequency = hz;
tc_init(&clock_tc);
clockinitted = 1;
+
+ rtc_todr.todr_gettime = rtc_gettime;
+ rtc_todr.todr_settime = rtc_settime;
+ todr_handle = &rtc_todr;
}
/*
@@ -131,87 +150,6 @@ setstatclockrate(int newhz)
}
/*
- * 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(time_t base)
-{
- struct clock_ymdhms dt;
- struct timespec ts;
- time_t deltat;
- int badbase;
-
- ts.tv_sec = ts.tv_nsec = 0;
-
- if (base < (2012 - 1970) * SECYR) {
- printf("WARNING: preposterous time in file system");
- /* read the system clock anyway */
- base = (2012 - 1970) * SECYR;
- badbase = 1;
- } else
- badbase = 0;
-
- (*clockfns->cf_get)(clockdev, base, &dt);
- todrvalid = 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.
- */
- ts.tv_sec = base;
- tc_setclock(&ts);
- if (!badbase) {
- printf("WARNING: preposterous clock chip time");
- resettodr();
- }
- goto bad;
- }
- /* now have days since Jan 1, 1970; the rest is easy... */
- ts.tv_sec = clock_ymdhms_to_secs(&dt);
- tc_setclock(&ts);
-
- if (!badbase) {
- /*
- * See if we gained/lost two or more days;
- * if so, assume something is amiss.
- */
- deltat = ts.tv_sec - base;
- if (deltat < 0)
- deltat = -deltat;
- if (deltat < 2 * SECDAY)
- return;
- printf("WARNING: clock %s %d days",
- ts.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 (!todrvalid)
- return;
- clock_secs_to_ymdhms(time_second, &dt);
- (*clockfns->cf_set)(clockdev, &dt);
-}
-
-/*
* Clock interrupt routine
*/
int
diff --git a/sys/arch/luna88k/luna88k/machdep.c b/sys/arch/luna88k/luna88k/machdep.c
index f72349f830d..570940a754b 100644
--- a/sys/arch/luna88k/luna88k/machdep.c
+++ b/sys/arch/luna88k/luna88k/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.130 2020/01/04 03:17:56 aoyama Exp $ */
+/* $OpenBSD: machdep.c,v 1.131 2020/05/12 15:13:18 kettenis Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
* Copyright (c) 1996 Nivas Madhur
@@ -1356,3 +1356,95 @@ m88k_broadcast_ipi(int ipi)
}
}
#endif
+
+#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;
+
+ rtctime.tv_sec = base;
+ rtctime.tv_usec = 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");
+}