summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2013-05-17 22:38:26 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2013-05-17 22:38:26 +0000
commitac2926810ed186ffb6bf1a5d56a417c2fdc1825e (patch)
treef1f808f36ea3717051027aec78889589ce2dfcc7 /sys/arch
parent5b0a459fbe1de0a4775b7320ff25c5825450e07b (diff)
Split inittodr/resettodr code from actual tod routines, to allow for
multiple tod routines in the near future. Use the mi clock_ymdhms_to_secs and clock_secs_to_ymdhms routines.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/mvme88k/conf/files.mvme88k3
-rw-r--r--sys/arch/mvme88k/dev/nvram.c93
-rw-r--r--sys/arch/mvme88k/dev/nvramreg.h4
-rw-r--r--sys/arch/mvme88k/mvme88k/clock.c104
-rw-r--r--sys/arch/mvme88k/mvme88k/clockvar.h8
-rw-r--r--sys/arch/mvme88k/mvme88k/locore.S16
-rw-r--r--sys/arch/mvme88k/mvme88k/machdep.c9
7 files changed, 157 insertions, 80 deletions
diff --git a/sys/arch/mvme88k/conf/files.mvme88k b/sys/arch/mvme88k/conf/files.mvme88k
index 4aa487314fe..12f3710c4d0 100644
--- a/sys/arch/mvme88k/conf/files.mvme88k
+++ b/sys/arch/mvme88k/conf/files.mvme88k
@@ -1,4 +1,4 @@
-# $OpenBSD: files.mvme88k,v 1.45 2010/12/31 21:38:08 miod Exp $
+# $OpenBSD: files.mvme88k,v 1.46 2013/05/17 22:38:25 miod Exp $
#
maxpartitions 16
@@ -63,6 +63,7 @@ file dev/cninit.c
file arch/mvme88k/mvme88k/autoconf.c
file arch/mvme88k/mvme88k/bus_dma.c
+file arch/mvme88k/mvme88k/clock.c
file arch/mvme88k/mvme88k/conf.c
file arch/mvme88k/mvme88k/db_machdep.c ddb
file arch/mvme88k/mvme88k/disksubr.c
diff --git a/sys/arch/mvme88k/dev/nvram.c b/sys/arch/mvme88k/dev/nvram.c
index 70527843a58..7d220d5268f 100644
--- a/sys/arch/mvme88k/dev/nvram.c
+++ b/sys/arch/mvme88k/dev/nvram.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nvram.c,v 1.33 2010/12/26 15:40:59 miod Exp $ */
+/* $OpenBSD: nvram.c,v 1.34 2013/05/17 22:38:25 miod Exp $ */
/*
* Copyright (c) 1995 Theo de Raadt
@@ -32,22 +32,20 @@
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/ioctl.h>
+#include <sys/time.h>
#include <sys/uio.h>
-#include <sys/timetc.h>
#include <machine/autoconf.h>
#include <machine/bugio.h>
#include <machine/conf.h>
#include <machine/cpu.h>
#include <machine/mioctl.h>
-#include <machine/psl.h>
-#include <machine/vmparam.h>
#include <uvm/uvm_param.h>
+#include <mvme88k/mvme88k/clockvar.h>
#include <mvme88k/dev/memdevs.h>
#include <mvme88k/dev/nvramreg.h>
-#include <mvme88k/dev/pcctworeg.h>
struct nvramsoftc {
struct device sc_dev;
@@ -73,7 +71,11 @@ struct cfdriver nvram_cd = {
NULL, "nvram", DV_DULL
};
-u_long chiptotime(int, int, int, int, int, int);
+time_t chiptotime(struct clock_ymdhms *);
+void timetochip(struct clock_ymdhms *);
+time_t nvram_inittodr(void);
+void nvram_resettodr(void);
+
int nvram188read(struct nvramsoftc *, struct uio *, int);
int nvram188write(struct nvramsoftc *, struct uio *, int);
@@ -129,7 +131,7 @@ nvramattach(parent, self, args)
sc->sc_ioh = ioh;
- printf(": MK48T0%d\n", sc->sc_len / 1024);
+ printf(": MK48T0%lu\n", sc->sc_len / 1024);
}
/*
@@ -316,33 +318,7 @@ inittodr(time_t base)
sc->sc_regs + CLK_CSR) & ~CLK_READ);
}
- if ((ts.tv_sec = chiptotime(sec, min, hour, day, mon, year)) == 0) {
- printf("WARNING: bad date in nvram");
-#ifdef DEBUG
- printf("\nday = %d, mon = %d, year = %d, hour = %d, min = %d, sec = %d",
- FROMBCD(day), FROMBCD(mon), FROMBCD(year) + YEAR0,
- FROMBCD(hour), FROMBCD(min), FROMBCD(sec));
-#endif
- /*
- * Believe the time in the file system for lack of
- * anything better, resetting the clock.
- */
- ts.tv_sec = base;
- if (!badbase)
- resettodr();
- } else {
- int deltat = ts.tv_sec - base;
-
- if (deltat < 0)
- deltat = -deltat;
- if (waszero || deltat < 2 * SECDAY)
- goto done;
- printf("WARNING: clock %s %d days",
- ts.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
- }
- printf(" -- CHECK AND RESET THE DATE!\n");
-done:
- tc_setclock(&ts);
+ return chiptotime(&c);
}
/*
@@ -352,61 +328,64 @@ done:
* when crashing during autoconfig.
*/
void
-resettodr()
+nvram_resettodr()
{
- struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[0];
- struct chiptime c;
+ struct nvramsoftc *sc = nvram_cd.cd_devs[0];
+ struct clock_ymdhms c;
- if (time_second == 0 || sc == NULL)
- return;
timetochip(&c);
- if (brdtyp == BRD_188) {
+ switch (brdtyp) {
+#ifdef MVME188
+ case BRD_188:
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + (CLK_CSR << 2), CLK_WRITE |
bus_space_read_4(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + (CLK_CSR << 2)));
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_SEC << 2), c.sec);
+ sc->sc_regs + (CLK_SEC << 2), c.dt_sec);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_MIN << 2), c.min);
+ sc->sc_regs + (CLK_MIN << 2), c.dt_min);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_HOUR << 2), c.hour);
+ sc->sc_regs + (CLK_HOUR << 2), c.dt_hour);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_WDAY << 2), c.wday);
+ sc->sc_regs + (CLK_WDAY << 2), c.dt_wday);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_DAY << 2), c.day);
+ sc->sc_regs + (CLK_DAY << 2), c.dt_day);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_MONTH << 2), c.mon);
+ sc->sc_regs + (CLK_MONTH << 2), c.dt_mon);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + (CLK_YEAR << 2), c.year);
+ sc->sc_regs + (CLK_YEAR << 2), c.dt_year);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + (CLK_CSR << 2),
bus_space_read_4(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + (CLK_CSR << 2)) & ~CLK_WRITE);
- } else {
+ break;
+#endif
+ default:
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + CLK_CSR, CLK_WRITE |
bus_space_read_1(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + CLK_CSR));
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_SEC, c.sec);
+ sc->sc_regs + CLK_SEC, c.dt_sec);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_MIN, c.min);
+ sc->sc_regs + CLK_MIN, c.dt_min);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_HOUR, c.hour);
+ sc->sc_regs + CLK_HOUR, c.dt_hour);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_WDAY, c.wday);
+ sc->sc_regs + CLK_WDAY, c.dt_wday);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_DAY, c.day);
+ sc->sc_regs + CLK_DAY, c.dt_day);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_MONTH, c.mon);
+ sc->sc_regs + CLK_MONTH, c.dt_mon);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
- sc->sc_regs + CLK_YEAR, c.year);
+ sc->sc_regs + CLK_YEAR, c.dt_year);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + CLK_CSR,
bus_space_read_1(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + CLK_CSR) & ~CLK_WRITE);
+ break;
}
}
@@ -527,7 +506,7 @@ int read_nvram(struct nvramsoftc *);
int
read_nvram(struct nvramsoftc *sc)
{
- u_int cnt;
+ size_t cnt;
u_int8_t *dest;
u_int32_t *src;
@@ -572,7 +551,7 @@ nvram188read(struct nvramsoftc *sc, struct uio *uio, int flags)
int
nvram188write(struct nvramsoftc *sc, struct uio *uio, int flags)
{
- u_int cnt;
+ size_t cnt;
u_int8_t *src;
u_int32_t *dest;
int rc;
diff --git a/sys/arch/mvme88k/dev/nvramreg.h b/sys/arch/mvme88k/dev/nvramreg.h
index dad0dd2f8a1..4816a329d05 100644
--- a/sys/arch/mvme88k/dev/nvramreg.h
+++ b/sys/arch/mvme88k/dev/nvramreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: nvramreg.h,v 1.8 2007/04/10 17:47:54 miod Exp $ */
+/* $OpenBSD: nvramreg.h,v 1.9 2013/05/17 22:38:25 miod Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -81,7 +81,7 @@
* Motorola chose the year `1900' as their base count. It has already
* wrapped by now...
*/
-#define YEAR0 00
+#define YEAR0 1900
#define SBC_NVRAM_TOD_OFF 0x1ff8 /* offset of tod in NVRAM space */
#define M188_NVRAM_TOD_OFF 0x1fe0 /* offset of tod in NVRAM space */
diff --git a/sys/arch/mvme88k/mvme88k/clock.c b/sys/arch/mvme88k/mvme88k/clock.c
new file mode 100644
index 00000000000..a7cc6849119
--- /dev/null
+++ b/sys/arch/mvme88k/mvme88k/clock.c
@@ -0,0 +1,104 @@
+/* $OpenBSD: clock.c,v 1.5 2013/05/17 22:38:25 miod Exp $ */
+
+/*
+ * Copyright (c) 1995 Theo de Raadt
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/time.h>
+#include <sys/timetc.h>
+
+#include <mvme88k/mvme88k/clockvar.h>
+
+time_t (*md_inittodr)(void);
+void (*md_resettodr)(void);
+
+/*
+ * Set up the system's time, given a `reasonable' time value.
+ */
+
+void
+inittodr(time_t base)
+{
+ int badbase = 0, waszero = base == 0;
+ struct timespec ts;
+
+ ts.tv_sec = ts.tv_nsec = 0;
+
+ if (base < 43 * 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 = 43 * SECYR;
+ badbase = 1;
+ }
+
+ if (md_inittodr != NULL)
+ ts.tv_sec = (*md_inittodr)();
+
+ if (ts.tv_sec == 0) {
+ printf("WARNING: bad date in nvram");
+ /*
+ * Believe the time in the file system for lack of
+ * anything better, resetting the clock.
+ */
+ ts.tv_sec = base;
+ if (!badbase)
+ resettodr();
+ } else {
+ int deltat = ts.tv_sec - base;
+
+ if (deltat < 0)
+ deltat = -deltat;
+ if (waszero || deltat < 2 * SECDAY)
+ goto done;
+ printf("WARNING: clock %s %d days",
+ ts.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
+ }
+ printf(" -- CHECK AND RESET THE DATE!\n");
+done:
+ tc_setclock(&ts);
+}
+
+/*
+ * 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()
+{
+ if (time_second == 0)
+ return;
+
+ if (md_resettodr != NULL)
+ (*md_resettodr)();
+}
diff --git a/sys/arch/mvme88k/mvme88k/clockvar.h b/sys/arch/mvme88k/mvme88k/clockvar.h
index 0cf098c2f1c..77cb7e541cb 100644
--- a/sys/arch/mvme88k/mvme88k/clockvar.h
+++ b/sys/arch/mvme88k/mvme88k/clockvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: clockvar.h,v 1.3 2009/02/13 23:26:51 miod Exp $ */
+/* $OpenBSD: clockvar.h,v 1.4 2013/05/17 22:38:25 miod Exp $ */
/*
* Copyright (c) 1999 Steve Murphree, Jr.
* Copyright (c) 1995 Theo de Raadt
@@ -72,6 +72,10 @@ extern struct intrhand statclock_ih;
extern int statvar;
extern int statmin;
-void m188_delay(int);
+void dumb_delay(int);
+extern u_int dumb_delay_const;
void m1x7_delay(int);
void m1x7_init_clocks(void);
+
+extern time_t (*md_inittodr)(void);
+extern void (*md_resettodr)(void);
diff --git a/sys/arch/mvme88k/mvme88k/locore.S b/sys/arch/mvme88k/mvme88k/locore.S
index bd9936a2f01..a4feb678648 100644
--- a/sys/arch/mvme88k/mvme88k/locore.S
+++ b/sys/arch/mvme88k/mvme88k/locore.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: locore.S,v 1.70 2013/01/05 11:20:56 miod Exp $ */
+/* $OpenBSD: locore.S,v 1.71 2013/05/17 22:38:25 miod Exp $ */
/*
* Copyright (c) 2005, Miodrag Vallat.
* Copyright (c) 1998 Steve Murphree, Jr.
@@ -325,22 +325,17 @@ GLOBAL(doboot)
or %r31, %r31, %lo16(_ASM_LABEL(initstack_end))
/*NOTREACHED*/
-/*
- * MVME188 specific support routines
- */
-
-#ifdef MVME188
/*
- * void m188_delay(int us)
+ * void dumb_delay(int us)
*
* The processor loops (busy waits) for the given number of microseconds:
* Thus, delay(1000000) will delay for one second.
* (originally from Mach 2.5)
*/
-GLOBAL(m188_delay)
+GLOBAL(dumb_delay)
bcnd eq0, %r2, 2f
- or.u %r3, %r0, %hi16(_C_LABEL(m188_delay_const))
- ld %r3, %r3, %lo16(_C_LABEL(m188_delay_const))
+ or.u %r3, %r0, %hi16(_C_LABEL(dumb_delay_const))
+ ld %r3, %r3, %lo16(_C_LABEL(dumb_delay_const))
mul %r4, %r2, %r3
subu %r4, %r4, 4 /* overhead of these instructions */
@@ -350,7 +345,6 @@ GLOBAL(m188_delay)
subu %r4, %r4, 2 /* two cycles per iteration */
2:
jmp %r1
-#endif
/*****************************************************************************/
diff --git a/sys/arch/mvme88k/mvme88k/machdep.c b/sys/arch/mvme88k/mvme88k/machdep.c
index c000b1ef7b5..4ed375d515f 100644
--- a/sys/arch/mvme88k/mvme88k/machdep.c
+++ b/sys/arch/mvme88k/mvme88k/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.250 2013/05/15 20:18:04 miod Exp $ */
+/* $OpenBSD: machdep.c,v 1.251 2013/05/17 22:38:25 miod Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
* Copyright (c) 1996 Nivas Madhur
@@ -168,6 +168,7 @@ int bootdev; /* set in locore.S */
int cputyp; /* set in locore.S */
int brdtyp; /* set in locore.S */
int cpuspeed = 25; /* safe guess */
+u_int dumb_delay_const = 25;
vaddr_t first_addr;
vaddr_t last_addr;
@@ -1158,9 +1159,3 @@ delay(int us)
{
(*md_delay)(us);
}
-
-/* delay() routine used until a proper routine is set up */
-void
-dumb_delay(int us)
-{
-}