Switch to MI todr. Mostly copied from prep.
This commit is contained in:
parent
561c032f4c
commit
69e635a534
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clock.c,v 1.6 2006/08/11 15:19:59 rjs Exp $ */
|
||||
/* $NetBSD: clock.c,v 1.7 2006/09/07 18:27:09 rjs Exp $ */
|
||||
/* $OpenBSD: clock.c,v 1.3 1997/10/13 13:42:53 pefo Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -40,12 +40,6 @@
|
|||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
#include <dev/clock_subr.h>
|
||||
|
||||
#include <ibmnws/ibmnws/clockvar.h>
|
||||
|
||||
#define MINYEAR 1990
|
||||
|
||||
void decr_intr(struct clockframe *);
|
||||
void init_ibmnws_tc(void);
|
||||
static u_int get_ibmnws_timecount(struct timecounter *);
|
||||
|
@ -57,20 +51,8 @@ u_long ticks_per_sec;
|
|||
u_long ns_per_tick;
|
||||
static long ticks_per_intr;
|
||||
|
||||
struct device *clockdev;
|
||||
const struct clockfns *clockfns;
|
||||
int clockinitted;
|
||||
|
||||
static void ns1000_clock_init(struct device *);
|
||||
static void ns1000_clock_get(struct device *, time_t, struct clocktime *);
|
||||
static void ns1000_clock_set(struct device *, struct clocktime *);
|
||||
|
||||
const struct clockfns ns1000_clockfns = {
|
||||
ns1000_clock_init,
|
||||
ns1000_clock_get,
|
||||
ns1000_clock_set
|
||||
};
|
||||
|
||||
static struct timecounter ibmnws_timecounter = {
|
||||
get_ibmnws_timecount, /* get_timecount */
|
||||
0, /* no poll_pps */
|
||||
|
@ -80,41 +62,6 @@ static struct timecounter ibmnws_timecounter = {
|
|||
0 /* quality */
|
||||
};
|
||||
|
||||
void
|
||||
ns1000_clock_init(struct device *dev)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ns1000_clock_get(struct device *dev, time_t base, struct clocktime *ct)
|
||||
{
|
||||
ct->sec = 0;
|
||||
ct->min = 0;
|
||||
ct->hour = 0;
|
||||
ct->dow = 0;
|
||||
ct->day = 0;
|
||||
ct->mon = 0;
|
||||
ct->year = 0;
|
||||
}
|
||||
|
||||
void
|
||||
ns1000_clock_set(struct device *dev, struct clocktime *ct)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
clockattach(struct device *dev, const struct clockfns *fns)
|
||||
{
|
||||
|
||||
printf("\n");
|
||||
|
||||
if (clockfns != NULL)
|
||||
panic("clockattach: multiple clocks");
|
||||
|
||||
clockdev = dev;
|
||||
clockfns = fns;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start the real-time and statistics clocks. Leave stathz 0 since there
|
||||
* are no other timers available.
|
||||
|
@ -129,133 +76,6 @@ cpu_initclocks(void)
|
|||
__asm volatile ("mtdec %0" :: "r"(ticks_per_intr));
|
||||
|
||||
init_ibmnws_tc();
|
||||
/*
|
||||
* The NS 1000 has no RTC hardware, so fake the clock functions
|
||||
* to prevent odd failures...
|
||||
*/
|
||||
|
||||
clockattach (NULL, &ns1000_clockfns);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the time of day register, based on the time base which is, e.g.
|
||||
* from a filesystem.
|
||||
*/
|
||||
void
|
||||
inittodr(time_t base)
|
||||
{
|
||||
struct clocktime ct;
|
||||
int year;
|
||||
struct clock_ymdhms dt;
|
||||
time_t deltat;
|
||||
struct timespec ts;
|
||||
struct timeval time;
|
||||
int badbase;
|
||||
|
||||
badbase = 0;
|
||||
time.tv_sec = 0;
|
||||
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 + 186 * SECDAY + SECDAY / 2;
|
||||
badbase = 1;
|
||||
}
|
||||
|
||||
(*clockfns->cf_get)(clockdev, base, &ct);
|
||||
#ifdef DEBUG
|
||||
printf("readclock: %d/%d/%d/%d/%d/%d\n", ct.year, ct.mon, ct.day,
|
||||
ct.hour, ct.min, ct.sec);
|
||||
#endif
|
||||
clockinitted = 1;
|
||||
|
||||
year = 1900 + ct.year;
|
||||
if (year < 1970)
|
||||
year += 100;
|
||||
|
||||
/* simple sanity checks (2037 = time_t overflow) */
|
||||
if (year < MINYEAR || year > 2037 ||
|
||||
ct.mon < 1 || ct.mon > 12 || ct.day < 1 ||
|
||||
ct.day > 31 || ct.hour > 23 || ct.min > 59 || ct.sec > 59) {
|
||||
/*
|
||||
* Believe the time in the file system for lack of
|
||||
* anything better, resetting the TODR.
|
||||
*/
|
||||
ts.tv_sec = base;
|
||||
ts.tv_nsec = 0;
|
||||
tc_setclock(&ts);
|
||||
|
||||
if (!badbase) {
|
||||
printf("WARNING: preposterous clock chip time\n");
|
||||
resettodr();
|
||||
}
|
||||
goto bad;
|
||||
}
|
||||
|
||||
dt.dt_year = year;
|
||||
dt.dt_mon = ct.mon;
|
||||
dt.dt_day = ct.day;
|
||||
dt.dt_hour = ct.hour;
|
||||
dt.dt_min = ct.min;
|
||||
dt.dt_sec = ct.sec;
|
||||
time.tv_sec = clock_ymdhms_to_secs(&dt);
|
||||
#ifdef DEBUG
|
||||
printf("=>%ld (%d)\n", (long int)time.tv_sec, (int)base);
|
||||
#endif
|
||||
|
||||
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 %ld days",
|
||||
time.tv_sec < base ? "lost" : "gained",
|
||||
(long)deltat / SECDAY);
|
||||
}
|
||||
bad:
|
||||
printf(" -- CHECK AND RESET THE DATE!\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* 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(void)
|
||||
{
|
||||
struct clock_ymdhms dt;
|
||||
struct clocktime ct;
|
||||
struct timeval time;
|
||||
|
||||
if (!clockinitted)
|
||||
return;
|
||||
|
||||
getmicrotime(&time);
|
||||
clock_secs_to_ymdhms(time.tv_sec, &dt);
|
||||
|
||||
/* rt clock wants 2 digits */
|
||||
ct.year = dt.dt_year % 100;
|
||||
ct.mon = dt.dt_mon;
|
||||
ct.day = dt.dt_day;
|
||||
ct.hour = dt.dt_hour;
|
||||
ct.min = dt.dt_min;
|
||||
ct.sec = dt.dt_sec;
|
||||
ct.dow = dt.dt_wday;
|
||||
#ifdef DEBUG
|
||||
printf("setclock: %d/%d/%d/%d/%d/%d\n", ct.year, ct.mon, ct.day,
|
||||
ct.hour, ct.min, ct.sec);
|
||||
#endif
|
||||
|
||||
(*clockfns->cf_set)(clockdev, &ct);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/* $NetBSD: clockvar.h,v 1.3 2006/05/09 17:59:33 rjs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Chris G. Demetriou
|
||||
*
|
||||
* Permission to use, copy, modify and distribute this software and
|
||||
* its documentation is hereby granted, provided that both the copyright
|
||||
* notice and this permission notice appear in all copies of the
|
||||
* software, derivative works or modified versions, and any portions
|
||||
* thereof, and that both notices appear in supporting documentation.
|
||||
*
|
||||
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
||||
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
||||
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
||||
*
|
||||
* Carnegie Mellon requests users of this software to return to
|
||||
*
|
||||
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
||||
* School of Computer Science
|
||||
* Carnegie Mellon University
|
||||
* Pittsburgh PA 15213-3890
|
||||
*
|
||||
* any improvements or extensions that they make and grant Carnegie the
|
||||
* rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Definitions for cpu-independent clock handling for the alpha and pmax.
|
||||
*/
|
||||
|
||||
/*
|
||||
* clocktime structure:
|
||||
*
|
||||
* structure passed to TOY clocks when setting them. broken out this
|
||||
* way, so that the time_t -> field conversion can be shared.
|
||||
*/
|
||||
struct clocktime {
|
||||
int year; /* year - 1900 */
|
||||
int mon; /* month (1 - 12) */
|
||||
int day; /* day (1 - 31) */
|
||||
int hour; /* hour (0 - 23) */
|
||||
int min; /* minute (0 - 59) */
|
||||
int sec; /* second (0 - 59) */
|
||||
int dow; /* day of week (0 - 6; 0 = Sunday) */
|
||||
};
|
||||
|
||||
/*
|
||||
* clockfns structure:
|
||||
*
|
||||
* function switch used by chip-independent clock code, to access
|
||||
* chip-dependent routines.
|
||||
*/
|
||||
struct clockfns {
|
||||
void (*cf_init)(struct device *);
|
||||
void (*cf_get)(struct device *, time_t, struct clocktime *);
|
||||
void (*cf_set)(struct device *, struct clocktime *);
|
||||
};
|
||||
|
||||
void clockattach(struct device *, const struct clockfns *);
|
|
@ -1,6 +1,7 @@
|
|||
/* $NetBSD: types.h,v 1.5 2006/09/03 13:51:23 bjh21 Exp $ */
|
||||
/* $NetBSD: types.h,v 1.6 2006/09/07 18:27:09 rjs Exp $ */
|
||||
|
||||
#define __HAVE_GENERIC_SOFT_INTERRUPTS
|
||||
#define __HAVE_TIMECOUNTER
|
||||
#define __HAVE_GENERIC_TODR
|
||||
|
||||
#include <powerpc/types.h>
|
||||
|
|
Loading…
Reference in New Issue