summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_clock.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2006-10-02 15:42:02 +0000
committerphk <phk@FreeBSD.org>2006-10-02 15:42:02 +0000
commit84cc0f277fd9e49e824e8ae9424d9a976b7f21bd (patch)
tree0bb3ea96259ad035c87da7424d8294bbca513c8b /sys/kern/subr_clock.c
parent81bdd4b32997569134b13c7951c97dd500d71623 (diff)
downloadFreeBSD-src-84cc0f277fd9e49e824e8ae9424d9a976b7f21bd.zip
FreeBSD-src-84cc0f277fd9e49e824e8ae9424d9a976b7f21bd.tar.gz
Second part of a little cleanup in the calendar/timezone/RTC handling.
Split subr_clock.c in two parts (by repo-copy): subr_clock.c contains generic RTC and calendaric stuff. etc. subr_rtc.c contains the newbus'ified RTC interface. Centralize the machdep.{adjkerntz,disable_rtc_set,wall_cmos_clock} sysctls and associated variables into subr_clock.c. They are not machine dependent and we have generic code that relies on being present so they are not even optional.
Diffstat (limited to 'sys/kern/subr_clock.c')
-rw-r--r--sys/kern/subr_clock.c165
1 files changed, 22 insertions, 143 deletions
diff --git a/sys/kern/subr_clock.c b/sys/kern/subr_clock.c
index 18be8bc..89ba14e 100644
--- a/sys/kern/subr_clock.c
+++ b/sys/kern/subr_clock.c
@@ -38,21 +38,6 @@
* from: src/sys/i386/isa/clock.c,v 1.176 2001/09/04
*/
-/*
- * Helpers for time-of-day clocks. This is useful for architectures that need
- * support multiple models of such clocks, and generally serves to make the
- * code more machine-independent.
- * If the clock in question can also be used as a time counter, the driver
- * needs to initiate this.
- * This code is not yet used by all architectures.
- */
-
-/*
- * Generic routines to convert between a POSIX date
- * (seconds since 1/1/1970) and yr/mo/day/hr/min/sec
- * Derived from NetBSD arch/hp300/hp300/clock.c
- */
-
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -64,28 +49,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/timetc.h>
-/* XXX: for the CPU_* sysctl OID constants. */
-#include <machine/cpu.h>
-
-#include "clock_if.h"
-
-static __inline int leapyear(int year);
-static int sysctl_machdep_adjkerntz(SYSCTL_HANDLER_ARGS);
-
-#define FEBRUARY 2
-#define days_in_year(y) (leapyear(y) ? 366 : 365)
-#define days_in_month(y, m) \
- (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))
-/* Day of week. Days are counted from 1/1/1970, which was a Thursday */
-#define day_of_week(days) (((days) + 4) % 7)
-
-static const int month_days[12] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-static device_t clock_dev = NULL;
-static long clock_res;
-
int adjkerntz; /* local offset from GMT in seconds */
int disable_rtc_set; /* disable resettodr() if != 0 */
int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
@@ -94,9 +57,6 @@ int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */
* These have traditionally been in machdep, but should probably be moved to
* kern.
*/
-SYSCTL_PROC(_machdep, OID_AUTO, adjkerntz, CTLTYPE_INT|CTLFLAG_RW,
- &adjkerntz, 0, sysctl_machdep_adjkerntz, "I", "");
-
SYSCTL_INT(_machdep, OID_AUTO, disable_rtc_set,
CTLFLAG_RW, &disable_rtc_set, 0, "");
@@ -114,6 +74,28 @@ sysctl_machdep_adjkerntz(SYSCTL_HANDLER_ARGS)
return (error);
}
+SYSCTL_PROC(_machdep, OID_AUTO, adjkerntz, CTLTYPE_INT|CTLFLAG_RW,
+ &adjkerntz, 0, sysctl_machdep_adjkerntz, "I", "");
+
+/*--------------------------------------------------------------------*
+ * Generic routines to convert between a POSIX date
+ * (seconds since 1/1/1970) and yr/mo/day/hr/min/sec
+ * Derived from NetBSD arch/hp300/hp300/clock.c
+ */
+
+
+#define FEBRUARY 2
+#define days_in_year(y) (leapyear(y) ? 366 : 365)
+#define days_in_month(y, m) \
+ (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))
+/* Day of week. Days are counted from 1/1/1970, which was a Thursday */
+#define day_of_week(days) (((days) + 4) % 7)
+
+static const int month_days[12] = {
+ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+
+
/*
* This inline avoids some unnecessary modulo operations
* as compared with the usual macro:
@@ -212,106 +194,3 @@ clock_ts_to_ct(struct timespec *ts, struct clocktime *ct)
ct->sec = rsec;
ct->nsec = ts->tv_nsec;
}
-
-void
-clock_register(device_t dev, long res) /* res has units of microseconds */
-{
-
- if (clock_dev != NULL) {
- if (clock_res > res) {
- if (bootverbose) {
- device_printf(dev, "not installed as "
- "time-of-day clock: clock %s has higher "
- "resolution\n", device_get_name(clock_dev));
- }
- return;
- } else {
- if (bootverbose) {
- device_printf(clock_dev, "removed as "
- "time-of-day clock: clock %s has higher "
- "resolution\n", device_get_name(dev));
- }
- }
- }
- clock_dev = dev;
- clock_res = res;
- if (bootverbose) {
- device_printf(dev, "registered as a time-of-day clock "
- "(resolution %ldus)\n", res);
- }
-}
-
-/*
- * inittodr and settodr derived from the i386 versions written
- * by Christoph Robitschko <chmr@edvz.tu-graz.ac.at>, reintroduced and
- * updated by Chris Stenton <chris@gnome.co.uk> 8/10/94
- */
-
-/*
- * Initialize the time of day register, based on the time base which is, e.g.
- * from a filesystem.
- */
-void
-inittodr(time_t base)
-{
- struct timespec diff, ref, ts;
- int error;
-
- if (base) {
- ref.tv_sec = base;
- ref.tv_nsec = 0;
- tc_setclock(&ref);
- }
-
- if (clock_dev == NULL) {
- printf("warning: no time-of-day clock registered, system time "
- "will not be set accurately\n");
- return;
- }
- error = CLOCK_GETTIME(clock_dev, &ts);
- if (error != 0 && error != EINVAL) {
- printf("warning: clock_gettime failed (%d), the system time "
- "will not be set accurately\n", error);
- return;
- }
- if (error == EINVAL || ts.tv_sec < 0) {
- printf("Invalid time in real time clock.\n");
- printf("Check and reset the date immediately!\n");
- }
-
- ts.tv_sec += tz_minuteswest * 60 +
- (wall_cmos_clock ? adjkerntz : 0);
-
- if (timespeccmp(&ref, &ts, >)) {
- diff = ref;
- timespecsub(&ref, &ts);
- } else {
- diff = ts;
- timespecsub(&diff, &ref);
- }
- if (ts.tv_sec >= 2) {
- /* badly off, adjust it */
- tc_setclock(&ts);
- }
-}
-
-/*
- * Write system time back to RTC
- */
-void
-resettodr()
-{
- struct timespec ts;
- int error;
-
- if (disable_rtc_set || clock_dev == NULL)
- return;
-
- getnanotime(&ts);
- ts.tv_sec -= tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
- if ((error = CLOCK_SETTIME(clock_dev, &ts)) != 0) {
- printf("warning: clock_settime failed (%d), time-of-day clock "
- "not adjusted to system time\n", error);
- return;
- }
-}
OpenPOWER on IntegriCloud