summaryrefslogtreecommitdiff
path: root/sys/arch/aviion/dev/nvram.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/aviion/dev/nvram.c')
-rw-r--r--sys/arch/aviion/dev/nvram.c54
1 files changed, 14 insertions, 40 deletions
diff --git a/sys/arch/aviion/dev/nvram.c b/sys/arch/aviion/dev/nvram.c
index 767e189d2f1..7a9f8f17469 100644
--- a/sys/arch/aviion/dev/nvram.c
+++ b/sys/arch/aviion/dev/nvram.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nvram.c,v 1.5 2007/12/20 05:19:35 miod Exp $ */
+/* $OpenBSD: nvram.c,v 1.6 2010/04/21 19:33:47 miod Exp $ */
/*
* Copyright (c) 1995 Theo de Raadt
@@ -33,6 +33,7 @@
#include <sys/proc.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
+#include <sys/timetc.h>
#include <machine/autoconf.h>
#include <machine/conf.h>
@@ -118,38 +119,6 @@ nvramattach(parent, self, args)
printf(": MK48T0%d\n", sc->sc_len / 1024);
}
-/*
- * Return the best possible estimate of the time in the timeval
- * to which tvp points. We do this by returning the current time
- * plus the amount of time since the last clock interrupt (clock.c:clkread).
- *
- * Check that this time is no less than any previously-reported time,
- * which could happen around the time of a clock adjustment. Just for fun,
- * we guarantee that the time will be greater than the value obtained by a
- * previous call.
- */
-void
-microtime(tvp)
- struct timeval *tvp;
-{
- int s = splhigh();
- static struct timeval lasttime;
-
- *tvp = time;
- while (tvp->tv_usec >= 1000000) {
- tvp->tv_sec++;
- tvp->tv_usec -= 1000000;
- }
- if (tvp->tv_sec == lasttime.tv_sec &&
- tvp->tv_usec <= lasttime.tv_usec &&
- (tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
- tvp->tv_sec++;
- tvp->tv_usec -= 1000000;
- }
- lasttime = *tvp;
- splx(s);
-}
-
#define LEAPYEAR(y) (((y) & 3) == 0)
/*
@@ -212,7 +181,7 @@ void
timetochip(c)
struct chiptime *c;
{
- int t, t2, t3, now = time.tv_sec;
+ int t, t2, t3, now = time_second;
/* January 1 1970 was a Thursday (4 in unix wdays) */
/* compute the days since the epoch */
@@ -268,6 +237,9 @@ inittodr(base)
struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[0];
int sec, min, hour, day, mon, year;
int badbase = 0, waszero = base == 0;
+ struct timespec ts;
+
+ ts.tv_sec = ts.tv_nsec = 0;
if (base < 36 * SECYR) { /* this code did not exist until 2006 */
/*
@@ -302,7 +274,7 @@ inittodr(base)
bus_space_read_4(sc->sc_iot, sc->sc_ioh,
sc->sc_regs + (CLK_CSR << 2)) & ~CLK_READ);
- if ((time.tv_sec = chiptotime(sec, min, hour, day, mon, year)) == 0) {
+ 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",
@@ -313,20 +285,22 @@ inittodr(base)
* Believe the time in the file system for lack of
* anything better, resetting the clock.
*/
- time.tv_sec = base;
+ ts.tv_sec = base;
if (!badbase)
resettodr();
} else {
- int deltat = time.tv_sec - base;
+ int deltat = ts.tv_sec - base;
if (deltat < 0)
deltat = -deltat;
if (waszero || deltat < 2 * SECDAY)
- return;
+ goto done;
printf("WARNING: clock %s %d days",
- time.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
+ ts.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
}
printf(" -- CHECK AND RESET THE DATE!\n");
+done:
+ tc_setclock(&ts);
}
/*
@@ -341,7 +315,7 @@ resettodr()
struct nvramsoftc *sc = (struct nvramsoftc *) nvram_cd.cd_devs[0];
struct chiptime c;
- if (!time.tv_sec || sc == NULL)
+ if (time_second == 0 || sc == NULL)
return;
timetochip(&c);