diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2005-10-21 22:07:46 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2005-10-21 22:07:46 +0000 |
commit | 3a1daf896c40b23624423295c78629a1cfd97bb2 (patch) | |
tree | b037669f600c9dd663b19f59e0b42eadc5f8858e | |
parent | bb82df5fbd8018a6d0c3fc7ca256d7d4f9d912b0 (diff) |
Clean up RTC code.
ok drahn@
-rw-r--r-- | sys/arch/macppc/dev/adb.c | 13 | ||||
-rw-r--r-- | sys/arch/macppc/dev/adb_direct.c | 6 | ||||
-rw-r--r-- | sys/arch/macppc/dev/adbvar.h | 6 | ||||
-rw-r--r-- | sys/arch/macppc/dev/pm_direct.c | 6 | ||||
-rw-r--r-- | sys/arch/macppc/dev/pm_direct.h | 6 | ||||
-rw-r--r-- | sys/arch/macppc/dev/smu.c | 12 | ||||
-rw-r--r-- | sys/arch/macppc/include/adbsys.h | 4 | ||||
-rw-r--r-- | sys/arch/macppc/include/autoconf.h | 8 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/clock.c | 63 |
9 files changed, 27 insertions, 97 deletions
diff --git a/sys/arch/macppc/dev/adb.c b/sys/arch/macppc/dev/adb.c index 1529a6b90d1..dc57bf8c823 100644 --- a/sys/arch/macppc/dev/adb.c +++ b/sys/arch/macppc/dev/adb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adb.c,v 1.12 2005/10/15 15:01:23 martin Exp $ */ +/* $OpenBSD: adb.c,v 1.13 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: adb.c,v 1.6 1999/08/16 06:28:09 tsubai Exp $ */ /*- @@ -94,16 +94,6 @@ adbmatch(struct device *parent, void *cf, void *aux) return 0; } -/* HACK ALERT */ -typedef int (clock_read_t)(int *sec, int *min, int *hour, int *day, - int *mon, int *yr); -typedef int (time_read_t)(u_long *sec); -typedef int (time_write_t)(u_long sec); -extern time_read_t *time_read; -extern time_write_t *time_write; -extern clock_read_t *clock_read; - - void adbattach(struct device *parent, struct device *self, void *aux) { @@ -132,7 +122,6 @@ adbattach(struct device *parent, struct device *self, void *aux) adb_intr, sc, "adb"); /* init powerpc globals which control RTC functionality */ - clock_read = NULL; time_read = adb_read_date_time; time_write = adb_set_date_time; diff --git a/sys/arch/macppc/dev/adb_direct.c b/sys/arch/macppc/dev/adb_direct.c index 83aa9b73afb..827a4bb59b6 100644 --- a/sys/arch/macppc/dev/adb_direct.c +++ b/sys/arch/macppc/dev/adb_direct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adb_direct.c,v 1.12 2005/10/15 15:01:23 martin Exp $ */ +/* $OpenBSD: adb_direct.c,v 1.13 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: adb_direct.c,v 1.14 2000/06/08 22:10:45 tsubai Exp $ */ /* @@ -1374,7 +1374,7 @@ set_adb_info(ADBSetInfoBlock * info, int adbAddr) /* caller should really use machine-independent version: getPramTime */ /* this version does pseudo-adb access only */ int -adb_read_date_time(unsigned long *time) +adb_read_date_time(time_t *time) { u_char output[ADB_MAX_MSG_LENGTH]; int result; @@ -1424,7 +1424,7 @@ adb_read_date_time(unsigned long *time) /* caller should really use machine-independent version: setPramTime */ /* this version does pseudo-adb access only */ int -adb_set_date_time(unsigned long time) +adb_set_date_time(time_t time) { u_char output[ADB_MAX_MSG_LENGTH]; int result; diff --git a/sys/arch/macppc/dev/adbvar.h b/sys/arch/macppc/dev/adbvar.h index 5f54a821663..144d41ebf02 100644 --- a/sys/arch/macppc/dev/adbvar.h +++ b/sys/arch/macppc/dev/adbvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: adbvar.h,v 1.5 2005/10/15 15:01:23 martin Exp $ */ +/* $OpenBSD: adbvar.h,v 1.6 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: adbvar.h,v 1.3 2000/06/08 22:10:46 tsubai Exp $ */ /*- @@ -91,8 +91,8 @@ void ADBReInit(void); int GetIndADB(ADBDataBlock * info, int index); int GetADBInfo(ADBDataBlock * info, int adbAddr); int SetADBInfo(ADBSetInfoBlock * info, int adbAddr); -int adb_read_date_time(unsigned long *t); -int adb_set_date_time(unsigned long t); +int adb_read_date_time(time_t *t); +int adb_set_date_time(time_t t); int adb_intr(void *arg); void adb_cuda_autopoll(void); int adb_op_sync(Ptr, Ptr, Ptr, short); diff --git a/sys/arch/macppc/dev/pm_direct.c b/sys/arch/macppc/dev/pm_direct.c index 616c12ee46f..1d17a356969 100644 --- a/sys/arch/macppc/dev/pm_direct.c +++ b/sys/arch/macppc/dev/pm_direct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pm_direct.c,v 1.13 2003/10/16 03:54:48 deraadt Exp $ */ +/* $OpenBSD: pm_direct.c,v 1.14 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: pm_direct.c,v 1.9 2000/06/08 22:10:46 tsubai Exp $ */ /* @@ -734,7 +734,7 @@ pm_adb_poweroff() } void -pm_read_date_time(u_long *time) +pm_read_date_time(time_t *time) { PMData p; @@ -748,7 +748,7 @@ pm_read_date_time(u_long *time) } void -pm_set_date_time(u_long time) +pm_set_date_time(time_t time) { PMData p; diff --git a/sys/arch/macppc/dev/pm_direct.h b/sys/arch/macppc/dev/pm_direct.h index ce2aea3f6ba..065d518ecad 100644 --- a/sys/arch/macppc/dev/pm_direct.h +++ b/sys/arch/macppc/dev/pm_direct.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pm_direct.h,v 1.5 2003/10/16 03:54:48 deraadt Exp $ */ +/* $OpenBSD: pm_direct.h,v 1.6 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: pm_direct.h,v 1.5 1999/07/12 15:54:55 tsubai Exp $ */ /* @@ -53,8 +53,8 @@ void pm_adb_restart(void); void pm_adb_poweroff(void); void pm_check_adb_devices(int); void pm_intr(void); -void pm_read_date_time(u_long *); -void pm_set_date_time(u_long); +void pm_read_date_time(time_t *); +void pm_set_date_time(time_t); void pm_setup_adb(void); struct pmu_battery_info diff --git a/sys/arch/macppc/dev/smu.c b/sys/arch/macppc/dev/smu.c index f67f847baf6..d186d34d479 100644 --- a/sys/arch/macppc/dev/smu.c +++ b/sys/arch/macppc/dev/smu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smu.c,v 1.1 2005/10/19 14:46:00 kettenis Exp $ */ +/* $OpenBSD: smu.c,v 1.2 2005/10/21 22:07:45 kettenis Exp $ */ /* * Copyright (c) 2005 Mark Kettenis @@ -90,15 +90,6 @@ smu_match(struct device *parent, void *cf, void *aux) /* XXX */ extern struct powerpc_bus_dma_tag pci_bus_dma_tag; -/* XXX */ -typedef int (clock_read_t)(int *sec, int *min, int *hour, int *day, - int *mon, int *yr); -typedef int (time_read_t)(time_t *sec); -typedef int (time_write_t)(time_t sec); -extern time_read_t *time_read; -extern time_write_t *time_write; -extern clock_read_t *clock_read; - void smu_attach(struct device *parent, struct device *self, void *aux) { @@ -155,7 +146,6 @@ smu_attach(struct device *parent, struct device *self, void *aux) } /* Initialize global variables that control RTC functionality. */ - clock_read = NULL; time_read = smu_time_read; time_write = smu_time_write; diff --git a/sys/arch/macppc/include/adbsys.h b/sys/arch/macppc/include/adbsys.h index 0daa86b47dc..d989d0a7236 100644 --- a/sys/arch/macppc/include/adbsys.h +++ b/sys/arch/macppc/include/adbsys.h @@ -1,4 +1,4 @@ -/* $OpenBSD: adbsys.h,v 1.3 2002/03/14 01:26:36 millert Exp $ */ +/* $OpenBSD: adbsys.h,v 1.4 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: adbsys.h,v 1.4 2000/12/19 02:59:24 tsubai Exp $ */ /*- @@ -178,7 +178,7 @@ int adb_poweroff(void); void adb_restart(void); int CountADBs(void); void ADBReInit(void); -int adb_read_date_time(unsigned long *); +int adb_read_date_time(time_t *); #endif #endif /* _ADBSYS_MACHINE_ */ diff --git a/sys/arch/macppc/include/autoconf.h b/sys/arch/macppc/include/autoconf.h index 42805d9b91c..093ae271828 100644 --- a/sys/arch/macppc/include/autoconf.h +++ b/sys/arch/macppc/include/autoconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.h,v 1.5 2003/06/09 16:34:21 deraadt Exp $ */ +/* $OpenBSD: autoconf.h,v 1.6 2005/10/21 22:07:45 kettenis Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -93,6 +93,12 @@ int badaddr(void *, u_int32_t); void calc_delayconst(void); void ofrootfound(void); +typedef int (time_read_t)(time_t *sec); +typedef int (time_write_t)(time_t sec); + +extern time_read_t *time_read; +extern time_write_t *time_write; + typedef int mac_intr_handle_t; typedef void *(intr_establish_t)(void *, mac_intr_handle_t, int, int, int (*func)(void *), void *, char *); diff --git a/sys/arch/macppc/macppc/clock.c b/sys/arch/macppc/macppc/clock.c index d934478ea54..6f0e877c64f 100644 --- a/sys/arch/macppc/macppc/clock.c +++ b/sys/arch/macppc/macppc/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.15 2005/10/09 14:01:11 drahn Exp $ */ +/* $OpenBSD: clock.c,v 1.16 2005/10/21 22:07:45 kettenis Exp $ */ /* $NetBSD: clock.c,v 1.1 1996/09/30 16:34:40 ws Exp $ */ /* @@ -57,28 +57,11 @@ static u_int32_t ns_per_tick = 320; static int32_t ticks_per_intr; static volatile u_int64_t lasttb; -/* - * BCD to decimal and decimal to BCD. - */ -#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf)) -#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10)) - #define SECDAY (24 * 60 * 60) #define SECYR (SECDAY * 365) -#define LEAPYEAR(y) (((y) & 3) == 0) -#define YEAR0 1900 - -typedef int (clock_read_t)(int *sec, int *min, int *hour, int *day, - int *mon, int *yr); -typedef int (time_read_t)(u_int32_t *sec); -typedef int (time_write_t)(u_int32_t sec); -clock_read_t *clock_read = NULL; -time_read_t *time_read = NULL; -time_write_t *time_write = NULL; - -static u_int32_t chiptotime(int sec, int min, int hour, int day, int mon, - int year); +time_read_t *time_read; +time_write_t *time_write; /* event tracking variables, when the next events of each time should occur */ u_int64_t nexttimerevent, prevtb, nextstatevent; @@ -105,8 +88,6 @@ static int stat_irq = PPC_STAT_IRQ; void inittodr(time_t base) { - int sec, min, hour, day, mon, year; - int badbase = 0, waszero = base == 0; if (base < 5 * SECYR) { @@ -121,10 +102,7 @@ inittodr(time_t base) badbase = 1; } - if (clock_read != NULL ) { - (*clock_read)( &sec, &min, &hour, &day, &mon, &year); - time.tv_sec = chiptotime(sec, min, hour, day, mon, year); - } else if (time_read != NULL) { + if (time_read != NULL) { u_int32_t cursec; (*time_read)(&cursec); time.tv_sec = cursec; @@ -167,39 +145,6 @@ inittodr(time_t base) } /* - * This code is defunct after 2068. - * Will Unix still be here then?? - */ -const short dayyr[12] = - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - -static u_int32_t -chiptotime(int sec, int min, int hour, int day, int mon, int year) -{ - int days, yr; - - sec = FROMBCD(sec); - min = FROMBCD(min); - hour = FROMBCD(hour); - day = FROMBCD(day); - mon = FROMBCD(mon); - year = FROMBCD(year) + YEAR0; - - /* simple sanity checks */ - if (year < 1970 || mon < 1 || mon > 12 || day < 1 || day > 31) - return (0); - days = 0; - for (yr = 1970; yr < year; yr++) - days += LEAPYEAR(yr) ? 366 : 365; - days += dayyr[mon - 1] + day - 1; - if (LEAPYEAR(yr) && mon > 2) - days++; - /* now have days since Jan 1, 1970; the rest is easy... */ - return (days * SECDAY + hour * 3600 + min * 60 + sec); -} - - -/* * Similar to the above */ void |