60#include "opt_ffclock.h"
64#include <sys/kernel.h>
68#include <sys/malloc.h>
70#include <sys/sysctl.h>
71#include <sys/taskqueue.h>
73#include <sys/timeffc.h>
75#include <sys/timetc.h>
81 "Enable debug printing of RTC clock I/O; 1=reads, 2=writes, 3=both.");
86 "Trigger one-time IO on RTC clocks; 1=read (and discard), 2=write");
91 0,
"Disallow adjusting time-of-day clock");
144 if (!(rtc->
flags & CLOCKF_SETTIME_NO_TS)) {
146 if (!(rtc->
flags & CLOCKF_SETTIME_NO_ADJ)) {
165 device_printf(dev,
"%s at ", (rw & CLOCK_DBG_READ) ?
"read " :
"write");
198 printf(
"error = %d\n", err);
218 newrtc =
malloc(
sizeof(*newrtc), M_DEVBUF, M_WAITOK);
225 TIMEOUT_TASK_INIT(taskqueue_thread, &newrtc->
stask, 0,
245 "registered as a time-of-day clock, resolution %d.%6.6ds\n",
300 if ((error = CLOCK_GETTIME(rtc->
clockdev,
ts)) != 0)
302 if (
ts->tv_sec < 0 ||
ts->tv_nsec < 0) {
306 if (!(rtc->
flags & CLOCKF_GETTIME_NO_ADJ)) {
313 "providing initial system time\n");
349 printf(
"Warning: no time-of-day clock registered, ");
352 printf(
"Warning: bad time from time-of-day clock, ");
355 printf(
"Error reading time-of-day clock (%d), ", error);
358 printf(
"system time will not be set accurately\n");
359 ts.tv_sec = (base > 0) ? base : -1;
363 if (
ts.tv_sec >= 0) {
366 ffclock_reset_clock(&
ts);
391 waitns = rtc->
schedns - now.tv_nsec;
393 waitns += 1000000000;
394 sbt = nstosbt(waitns);
398 &rtc->
stask, -sbt, 0, C_PREL(31));
406 struct timespec ts_discard;
411 if (error != 0 || req->newptr == NULL)
417 printf(
"No registered RTC clocks\n");
419 case CLOCK_DBG_WRITE:
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
int sysctl_handle_int(SYSCTL_HANDLER_ARGS)
void tc_setclock(struct timespec *ts)
void getnanotime(struct timespec *tsp)
struct timeout_task stask
int device_printf(device_t dev, const char *fmt,...)
Print the name of the device followed by a colon, a space and the result of calling vprintf() with th...
void clock_print_bcd(const struct bcd_clocktime *bct, int nsdigits)
void clock_print_ts(const struct timespec *ts, int nsdigits)
void clock_print_ct(const struct clocktime *ct, int nsdigits)
int printf(const char *fmt,...)
void clock_register_flags(device_t clockdev, long resolution, int flags)
void clock_unregister(device_t clockdev)
static struct rtc_listhead rtc_list
static int read_clocks(struct timespec *ts, bool debug_read)
SYSCTL_PROC(_debug, OID_AUTO, clock_do_io, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, 0, sysctl_clock_do_io, "I", "Trigger one-time IO on RTC clocks; 1=read (and discard), 2=write")
void clock_dbgprint_err(device_t dev, int rw, int err)
void inittodr(time_t base)
SX_SYSINIT(rtc_list_lock_init, &rtc_list_lock, "rtc list")
void clock_dbgprint_ct(device_t dev, int rw, const struct clocktime *ct)
static int disable_rtc_set
static void settime_task_func(void *arg, int pending)
void clock_dbgprint_ts(device_t dev, int rw, const struct timespec *ts)
static int sysctl_clock_do_io(SYSCTL_HANDLER_ARGS)
void clock_register(device_t dev, long res)
void clock_schedule(device_t clockdev, u_int offsetns)
static struct sx rtc_list_lock
static void clock_dbgprint_hdr(device_t dev, int rw)
LIST_HEAD(rtc_listhead, rtc_instance)
SYSCTL_INT(_debug, OID_AUTO, clock_show_io, CTLFLAG_RWTUN, &show_io, 0, "Enable debug printing of RTC clock I/O; 1=reads, 2=writes, 3=both.")
void clock_dbgprint_bcd(device_t dev, int rw, const struct bcd_clocktime *bct)
void taskqueue_drain_timeout(struct taskqueue *queue, struct timeout_task *timeout_task)
int taskqueue_enqueue_timeout_sbt(struct taskqueue *queue, struct timeout_task *timeout_task, sbintime_t sbt, sbintime_t pr, int flags)
int taskqueue_cancel_timeout(struct taskqueue *queue, struct timeout_task *timeout_task, u_int *pendp)