Flesh out inittodr() and resettodr().

This commit is contained in:
thorpej 2003-07-26 05:51:11 +00:00
parent 6d7e3e1b0d
commit ca601a7747
4 changed files with 276 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: becc_timer.c,v 1.3 2003/07/15 00:24:52 lukem Exp $ */ /* $NetBSD: becc_timer.c,v 1.4 2003/07/26 05:51:11 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002 Wasabi Systems, Inc. * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
@ -40,13 +40,15 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: becc_timer.c,v 1.3 2003/07/15 00:24:52 lukem Exp $"); __KERNEL_RCSID(0, "$NetBSD: becc_timer.c,v 1.4 2003/07/26 05:51:11 thorpej Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/time.h> #include <sys/time.h>
#include <dev/clock_subr.h>
#include <machine/bus.h> #include <machine/bus.h>
#include <arm/cpufunc.h> #include <arm/cpufunc.h>
@ -264,17 +266,73 @@ delay(u_int n)
} }
} }
todr_chip_handle_t todr_handle;
/*
* todr_attach:
*
* Set the specified time-of-day register as the system real-time clock.
*/
void
todr_attach(todr_chip_handle_t todr)
{
if (todr_handle)
panic("todr_attach: rtc already configured");
}
/* /*
* inittodr: * inittodr:
* *
* Initialize time from the time-of-day register. * Initialize time from the time-of-day register.
*/ */
#define MINYEAR 2003 /* minimum plausible year */
void void
inittodr(time_t base) inittodr(time_t base)
{ {
time_t deltat;
int badbase;
time.tv_sec = base; if (base < (MINYEAR - 1970) * SECYR) {
time.tv_usec = 0; printf("WARNING: preposterous time in file system");
/* read the system clock anyway */
base = (MINYEAR - 1970) * SECYR;
badbase = 1;
} else
badbase = 0;
if (todr_handle == NULL ||
todr_gettime(todr_handle, (struct timeval *)&time) != 0 ||
time.tv_sec == 0) {
/*
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
*/
time.tv_sec = base;
time.tv_usec = 0;
if (todr_handle != NULL && !badbase) {
printf("WARNING: preposterous clock chip time\n");
resettodr();
}
goto bad;
}
if (!badbase) {
/*
* See if we tained/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; /* all is well */
printf("WARNING: clock %s %ld days\n",
time.tv_sec < base ? "lost" : "gained",
(long)deltat / SECDAY);
}
bad:
printf("WARNING: CHECK AND RESET THE DATE!\n");
} }
/* /*
@ -285,6 +343,13 @@ inittodr(time_t base)
void void
resettodr(void) resettodr(void)
{ {
if (time.tv_sec == 0)
return;
if (todr_handle != NULL &&
todr_settime(todr_handle, (struct timeval *)&time) != 0)
printf("resettodr: failed to set time\n");
} }
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: i80321_timer.c,v 1.5 2003/07/15 00:24:54 lukem Exp $ */ /* $NetBSD: i80321_timer.c,v 1.6 2003/07/26 05:51:11 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002 Wasabi Systems, Inc. * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
@ -40,7 +40,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: i80321_timer.c,v 1.5 2003/07/15 00:24:54 lukem Exp $"); __KERNEL_RCSID(0, "$NetBSD: i80321_timer.c,v 1.6 2003/07/26 05:51:11 thorpej Exp $");
#include "opt_perfctrs.h" #include "opt_perfctrs.h"
@ -49,6 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: i80321_timer.c,v 1.5 2003/07/15 00:24:54 lukem Exp $
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/time.h> #include <sys/time.h>
#include <dev/clock_subr.h>
#include <machine/bus.h> #include <machine/bus.h>
#include <arm/cpufunc.h> #include <arm/cpufunc.h>
@ -315,17 +317,73 @@ delay(u_int n)
} }
} }
todr_chip_handle_t todr_handle;
/*
* todr_attach:
*
* Set the specified time-of-day register as the system real-time clock.
*/
void
todr_attach(todr_chip_handle_t todr)
{
if (todr_handle)
panic("todr_attach: rtc already configured");
}
/* /*
* inittodr: * inittodr:
* *
* Initialize time from the time-of-day register. * Initialize time from the time-of-day register.
*/ */
#define MINYEAR 2003 /* minimum plausible year */
void void
inittodr(time_t base) inittodr(time_t base)
{ {
time_t deltat;
int badbase;
time.tv_sec = base; if (base < (MINYEAR - 1970) * SECYR) {
time.tv_usec = 0; printf("WARNING: preposterous time in file system");
/* read the system clock anyway */
base = (MINYEAR - 1970) * SECYR;
badbase = 1;
} else
badbase = 0;
if (todr_handle == NULL ||
todr_gettime(todr_handle, (struct timeval *)&time) != 0 ||
time.tv_sec == 0) {
/*
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
*/
time.tv_sec = base;
time.tv_usec = 0;
if (todr_handle != NULL && !badbase) {
printf("WARNING: preposterous clock chip time\n");
resettodr();
}
goto bad;
}
if (!badbase) {
/*
* See if we tained/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; /* all is well */
printf("WARNING: clock %s %ld days\n",
time.tv_sec < base ? "lost" : "gained",
(long)deltat / SECDAY);
}
bad:
printf("WARNING: CHECK AND RESET THE DATE!\n");
} }
/* /*
@ -336,6 +394,13 @@ inittodr(time_t base)
void void
resettodr(void) resettodr(void)
{ {
if (time.tv_sec == 0)
return;
if (todr_handle != NULL &&
todr_settime(todr_handle, (struct timeval *)&time) != 0)
printf("resettodr: failed to set time\n");
} }
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ixp425_timer.c,v 1.1 2003/05/23 00:57:26 ichiro Exp $ */ /* $NetBSD: ixp425_timer.c,v 1.2 2003/07/26 05:51:11 thorpej Exp $ */
/* /*
* Copyright (c) 2003 * Copyright (c) 2003
@ -34,7 +34,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ixp425_timer.c,v 1.1 2003/05/23 00:57:26 ichiro Exp $"); __KERNEL_RCSID(0, "$NetBSD: ixp425_timer.c,v 1.2 2003/07/26 05:51:11 thorpej Exp $");
#include "opt_perfctrs.h" #include "opt_perfctrs.h"
@ -45,6 +45,8 @@ __KERNEL_RCSID(0, "$NetBSD: ixp425_timer.c,v 1.1 2003/05/23 00:57:26 ichiro Exp
#include <sys/time.h> #include <sys/time.h>
#include <sys/device.h> #include <sys/device.h>
#include <dev/clock_subr.h>
#include <machine/bus.h> #include <machine/bus.h>
#include <machine/intr.h> #include <machine/intr.h>
@ -282,17 +284,73 @@ delay(u_int n)
} }
} }
todr_chip_handle_t todr_handle;
/*
* todr_attach:
*
* Set the specified time-of-day register as the system real-time clock.
*/
void
todr_attach(todr_chip_handle_t todr)
{
if (todr_handle)
panic("todr_attach: rtc already configured");
}
/* /*
* inittodr: * inittodr:
* *
* Initialize time from the time-of-day register. * Initialize time from the time-of-day register.
*/ */
#define MINYEAR 2003 /* minimum plausible year */
void void
inittodr(time_t base) inittodr(time_t base)
{ {
time_t deltat;
int badbase;
time.tv_sec = base; if (base < (MINYEAR - 1970) * SECYR) {
time.tv_usec = 0; printf("WARNING: preposterous time in file system");
/* read the system clock anyway */
base = (MINYEAR - 1970) * SECYR;
badbase = 1;
} else
badbase = 0;
if (todr_handle == NULL ||
todr_gettime(todr_handle, (struct timeval *)&time) != 0 ||
time.tv_sec == 0) {
/*
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
*/
time.tv_sec = base;
time.tv_usec = 0;
if (todr_handle != NULL && !badbase) {
printf("WARNING: preposterous clock chip time\n");
resettodr();
}
goto bad;
}
if (!badbase) {
/*
* See if we tained/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; /* all is well */
printf("WARNING: clock %s %ld days\n",
time.tv_sec < base ? "lost" : "gained",
(long)deltat / SECDAY);
}
bad:
printf("WARNING: CHECK AND RESET THE DATE!\n");
} }
/* /*
@ -303,6 +361,13 @@ inittodr(time_t base)
void void
resettodr(void) resettodr(void)
{ {
if (time.tv_sec == 0)
return;
if (todr_handle != NULL &&
todr_settime(todr_handle, (struct timeval *)&time) != 0)
printf("resettodr: failed to set time\n");
} }
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: iq80310_timer.c,v 1.12 2003/07/15 00:25:03 lukem Exp $ */ /* $NetBSD: iq80310_timer.c,v 1.13 2003/07/26 05:55:03 thorpej Exp $ */
/* /*
* Copyright (c) 2001, 2002 Wasabi Systems, Inc. * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
@ -47,13 +47,15 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: iq80310_timer.c,v 1.12 2003/07/15 00:25:03 lukem Exp $"); __KERNEL_RCSID(0, "$NetBSD: iq80310_timer.c,v 1.13 2003/07/26 05:55:03 thorpej Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/time.h> #include <sys/time.h>
#include <dev/clock_subr.h>
#include <machine/bus.h> #include <machine/bus.h>
#include <arm/cpufunc.h> #include <arm/cpufunc.h>
@ -317,17 +319,73 @@ delay(u_int n)
} }
} }
todr_chip_handle_t todr_handle;
/*
* todr_attach:
*
* Set the specified time-of-day register as the system real-time clock.
*/
void
todr_attach(todr_chip_handle_t todr)
{
if (todr_handle)
panic("todr_attach: rtc already configured");
}
/* /*
* inittodr: * inittodr:
* *
* Initialize time from the time-of-day register. * Initialize time from the time-of-day register.
*/ */
#define MINYEAR 2003 /* minimum plausible year */
void void
inittodr(time_t base) inittodr(time_t base)
{ {
time_t deltat;
int badbase;
time.tv_sec = base; if (base < (MINYEAR - 1970) * SECYR) {
time.tv_usec = 0; printf("WARNING: preposterous time in file system");
/* read the system clock anyway */
base = (MINYEAR - 1970) * SECYR;
badbase = 1;
} else
badbase = 0;
if (todr_handle == NULL ||
todr_gettime(todr_handle, (struct timeval *)&time) != 0 ||
time.tv_sec == 0) {
/*
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
*/
time.tv_sec = base;
time.tv_usec = 0;
if (todr_handle != NULL && !badbase) {
printf("WARNING: preposterous clock chip time\n");
resettodr();
}
goto bad;
}
if (!badbase) {
/*
* See if we tained/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; /* all is well */
printf("WARNING: clock %s %ld days\n",
time.tv_sec < base ? "lost" : "gained",
(long)deltat / SECDAY);
}
bad:
printf("WARNING: CHECK AND RESET THE DATE!\n");
} }
/* /*
@ -338,6 +396,13 @@ inittodr(time_t base)
void void
resettodr(void) resettodr(void)
{ {
if (time.tv_sec == 0)
return;
if (todr_handle != NULL &&
todr_settime(todr_handle, (struct timeval *)&time) != 0)
printf("resettodr: failed to set time\n");
} }
/* /*