diff --git a/sys/arch/arm/xscale/becc_timer.c b/sys/arch/arm/xscale/becc_timer.c index b726ae248c03..dd736a9850e5 100644 --- a/sys/arch/arm/xscale/becc_timer.c +++ b/sys/arch/arm/xscale/becc_timer.c @@ -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. @@ -40,13 +40,15 @@ */ #include -__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 #include #include #include +#include + #include #include @@ -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: * * Initialize time from the time-of-day register. */ +#define MINYEAR 2003 /* minimum plausible year */ void inittodr(time_t base) { + time_t deltat; + int badbase; - time.tv_sec = base; - time.tv_usec = 0; + if (base < (MINYEAR - 1970) * SECYR) { + 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 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"); } /* diff --git a/sys/arch/arm/xscale/i80321_timer.c b/sys/arch/arm/xscale/i80321_timer.c index 3ac64b8e1b30..b61e8e794dc6 100644 --- a/sys/arch/arm/xscale/i80321_timer.c +++ b/sys/arch/arm/xscale/i80321_timer.c @@ -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. @@ -40,7 +40,7 @@ */ #include -__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" @@ -49,6 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: i80321_timer.c,v 1.5 2003/07/15 00:24:54 lukem Exp $ #include #include +#include + #include #include @@ -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: * * Initialize time from the time-of-day register. */ +#define MINYEAR 2003 /* minimum plausible year */ void inittodr(time_t base) { + time_t deltat; + int badbase; - time.tv_sec = base; - time.tv_usec = 0; + if (base < (MINYEAR - 1970) * SECYR) { + 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 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"); } /* diff --git a/sys/arch/arm/xscale/ixp425_timer.c b/sys/arch/arm/xscale/ixp425_timer.c index 70d5164c5194..60bbc0f5e2df 100644 --- a/sys/arch/arm/xscale/ixp425_timer.c +++ b/sys/arch/arm/xscale/ixp425_timer.c @@ -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 @@ -34,7 +34,7 @@ */ #include -__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" @@ -45,6 +45,8 @@ __KERNEL_RCSID(0, "$NetBSD: ixp425_timer.c,v 1.1 2003/05/23 00:57:26 ichiro Exp #include #include +#include + #include #include @@ -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: * * Initialize time from the time-of-day register. */ +#define MINYEAR 2003 /* minimum plausible year */ void inittodr(time_t base) { + time_t deltat; + int badbase; - time.tv_sec = base; - time.tv_usec = 0; + if (base < (MINYEAR - 1970) * SECYR) { + 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 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"); } /* diff --git a/sys/arch/evbarm/iq80310/iq80310_timer.c b/sys/arch/evbarm/iq80310/iq80310_timer.c index 5c929e3d2731..28de4493a0bc 100644 --- a/sys/arch/evbarm/iq80310/iq80310_timer.c +++ b/sys/arch/evbarm/iq80310/iq80310_timer.c @@ -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. @@ -47,13 +47,15 @@ */ #include -__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 #include #include #include +#include + #include #include @@ -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: * * Initialize time from the time-of-day register. */ +#define MINYEAR 2003 /* minimum plausible year */ void inittodr(time_t base) { + time_t deltat; + int badbase; - time.tv_sec = base; - time.tv_usec = 0; + if (base < (MINYEAR - 1970) * SECYR) { + 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 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"); } /*