Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/sgimips/sgimips New clock functions, based on the n...
details: https://anonhg.NetBSD.org/src/rev/459e231e6c07
branches: trunk
changeset: 509710:459e231e6c07
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri May 11 03:42:59 2001 +0000
description:
New clock functions, based on the newsmips versions. These
actually do something, by calling into the hardware clock
routines set up during autoconfiguration.
>From Rafal K. Boni.
diffstat:
sys/arch/sgimips/sgimips/clock.c | 201 ++++++++++++++++++++++++++++-------
sys/arch/sgimips/sgimips/clockvar.h | 35 ++++++
2 files changed, 195 insertions(+), 41 deletions(-)
diffs (270 lines):
diff -r 2ca79148e45d -r 459e231e6c07 sys/arch/sgimips/sgimips/clock.c
--- a/sys/arch/sgimips/sgimips/clock.c Fri May 11 03:23:38 2001 +0000
+++ b/sys/arch/sgimips/sgimips/clock.c Fri May 11 03:42:59 2001 +0000
@@ -1,9 +1,15 @@
-/* $NetBSD: clock.c,v 1.1 2000/06/14 16:02:42 soren Exp $ */
+/* $NetBSD: clock.c,v 1.2 2001/05/11 03:42:59 thorpej Exp $ */
/*
- * Copyright (c) 2000 Soren S. Jorvang
- * All rights reserved.
- *
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department, Ralph Campbell, and Kazumasa Utashiro of
+ * Software Research Associates, Inc.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -14,57 +20,170 @@
* 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 for the
- * NetBSD Project. See http://www.netbsd.org/ for
- * information about NetBSD.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * 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.
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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.
+ *
+ * from: Utah $Hdr: clock.c 1.18 91/01/21$
+ *
+ * @(#)clock.c 8.1 (Berkeley) 6/11/93
*/
#include <sys/param.h>
-#include <sys/proc.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/device.h>
+
+#include <dev/clock_subr.h>
+#include <sgimips/sgimips/clockvar.h>
+
+#define MINYEAR 2001 /* "today" */
+
+static struct device *clockdev;
+static const struct clockfns *clockfns;
+static int clockinitted;
+
+void
+clockattach(dev, fns)
+ struct device *dev;
+ const struct clockfns *fns;
+{
+ if (clockfns != NULL)
+ panic("clockattach: multiple clocks");
+
+ clockdev = dev;
+ clockfns = fns;
+}
-void cpu_initclocks(void);
-void inittodr(time_t);
-void resettodr(void);
-void setstatclockrate(int);
+/*
+ * 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.
+ */
-void
+/*
+ * We assume newhz is either stathz or profhz, and that neither will
+ * change after being set up above. Could recalculate intervals here
+ * but that would be a drag.
+ */
+void
+setstatclockrate(newhz)
+ int newhz;
+{
+
+ /* do something? */
+}
+
+/*
+ * Set up the real-time and statistics clocks. Leave stathz 0 only if
+ * no alternative timer is available.
+ */
+void
cpu_initclocks()
{
- return;
+ (*clockfns->cf_init)(clockdev);
}
+/*
+ * 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;
-{
- return;
+{
+ int deltat, badbase = 0;
+ struct clock_ymdhms dt;
+
+ if (base < (MINYEAR-1970)*SECYR) {
+ printf("WARNING: preposterous time in file system");
+ /* read the system clock anyway */
+ base = (MINYEAR-1970)*SECYR;
+ badbase = 1;
+ }
+
+ (*clockfns->cf_get)(clockdev, &dt);
+#ifdef DEBUG
+ printf("readclock: %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
+ clockinitted = 1;
+
+ /* simple sanity checks */
+ if (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) {
+ printf("WARNING: preposterous clock chip time\n");
+ /*
+ * Believe the time in the file system for lack of
+ * anything better, resetting the TODR.
+ */
+ time.tv_sec = base;
+ if (!badbase)
+ resettodr();
+ return;
+ }
+
+ 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", deltat / SECDAY);
+ }
+ printf(" -- CHECK AND RESET THE DATE!\n");
}
-void
-resettodr(void)
-{
- return;
-}
+/*
+ * 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;
-void
-setstatclockrate(arg)
- int arg;
-{
- return;
+ if (! clockinitted)
+ return;
+
+ clock_secs_to_ymdhms(time.tv_sec, &dt);
+
+#ifdef DEBUG
+ printf("setclock: %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
+ (*clockfns->cf_set)(clockdev, &dt);
}
diff -r 2ca79148e45d -r 459e231e6c07 sys/arch/sgimips/sgimips/clockvar.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sgimips/sgimips/clockvar.h Fri May 11 03:42:59 2001 +0000
@@ -0,0 +1,35 @@
+/* $NetBSD: clockvar.h,v 1.1 2001/05/11 03:42:59 thorpej Exp $ */
+
+/*-
+ * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
+ *
+ * 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. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * 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.
+ */
+
+struct clockfns {
+ void (*cf_init)(struct device *);
+ void (*cf_get)(struct device *, struct clock_ymdhms *);
+ void (*cf_set)(struct device *, struct clock_ymdhms *);
+};
+
+void clockattach(struct device *, const struct clockfns *);
Home |
Main Index |
Thread Index |
Old Index