22
24
#if !defined(__m68k__) || !defined(KDGHWCLK)
25
probe_for_kd_clock() {
27
struct clock_ops *probe_for_kd_clock()
29
#else /* __m68k__ && KDGHWCLK */
32
#else /* __m68k__ && KDGHWCLK */
31
static int con_fd = -1; /* opened by probe_for_kd_clock() */
34
/* Opened by probe_for_kd_clock(), and never closed. */
35
static int con_fd = -1;
33
36
static char *con_fd_filename; /* usually "/dev/tty1" */
36
synchronize_to_clock_tick_kd(void) {
37
/*----------------------------------------------------------------------------
38
Wait for the top of a clock tick by calling KDGHWCLK in a busy loop until
40
-----------------------------------------------------------------------------*/
42
/* The time when we were called (and started waiting) */
43
struct hwclk_time start_time, nowtime;
44
struct timeval begin, now;
47
printf(_("Waiting in loop for time from KDGHWCLK to change\n"));
49
if (ioctl(con_fd, KDGHWCLK, &start_time) == -1) {
50
outsyserr(_("KDGHWCLK ioctl to read time failed"));
54
/* Wait for change. Should be within a second, but in case something
55
* weird happens, we have a time limit (1.5s) on this loop to reduce the
56
* impact of this failure.
58
gettimeofday(&begin, NULL);
60
/* Added by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
61
* "The culprit is the fast loop with KDGHWCLK ioctls. It seems
62
* the kernel gets confused by those on Amigas with A2000 RTCs
63
* and simply hangs after some time. Inserting a sleep helps."
67
if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
68
outsyserr(_("KDGHWCLK ioctl to read time failed in loop"));
71
if (start_time.tm_sec != nowtime.tm_sec)
73
gettimeofday(&now, NULL);
74
if (time_diff(now, begin) > 1.5) {
75
fprintf(stderr, _("Timed out waiting for time change.\n"));
85
read_hardware_clock_kd(struct tm *tm) {
86
/*----------------------------------------------------------------------------
87
Read the hardware clock and return the current time via <tm>
88
argument. Use ioctls to /dev/tty1 on what we assume is an m68k
91
Note that we don't use /dev/console here. That might be a serial
93
-----------------------------------------------------------------------------*/
96
if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
97
outsyserr(_("ioctl() failed to read time from %s"), con_fd_filename);
98
hwclock_exit(EX_IOERR);
103
tm->tm_hour = t.hour;
106
tm->tm_year = t.year;
107
tm->tm_wday = t.wday;
108
tm->tm_isdst = -1; /* Don't know if it's Daylight Savings Time */
115
set_hardware_clock_kd(const struct tm *new_broken_time) {
116
/*----------------------------------------------------------------------------
117
Set the Hardware Clock to the time <new_broken_time>. Use ioctls to
118
/dev/tty1 on what we assume is an m68k machine.
120
Note that we don't use /dev/console here. That might be a serial console.
121
----------------------------------------------------------------------------*/
124
t.sec = new_broken_time->tm_sec;
125
t.min = new_broken_time->tm_min;
126
t.hour = new_broken_time->tm_hour;
127
t.day = new_broken_time->tm_mday;
128
t.mon = new_broken_time->tm_mon;
129
t.year = new_broken_time->tm_year;
130
t.wday = new_broken_time->tm_wday;
132
if (ioctl(con_fd, KDSHWCLK, &t ) == -1) {
133
outsyserr(_("ioctl KDSHWCLK failed"));
140
get_permissions_kd(void) {
39
* Wait for the top of a clock tick by calling KDGHWCLK in a busy loop until
42
static int synchronize_to_clock_tick_kd(void)
44
/* The time when we were called (and started waiting) */
45
struct hwclk_time start_time, nowtime;
46
struct timeval begin, now;
49
printf(_("Waiting in loop for time from KDGHWCLK to change\n"));
51
if (ioctl(con_fd, KDGHWCLK, &start_time) == -1) {
52
warn(_("KDGHWCLK ioctl to read time failed"));
57
* Wait for change. Should be within a second, but in case something
58
* weird happens, we have a time limit (1.5s) on this loop to reduce
59
* the impact of this failure.
61
gettimeofday(&begin, NULL);
64
* Added by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
66
* "The culprit is the fast loop with KDGHWCLK ioctls. It
67
* seems the kernel gets confused by those on Amigas with
68
* A2000 RTCs and simply hangs after some time. Inserting a
73
if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
74
warn(_("KDGHWCLK ioctl to read time failed in loop"));
77
if (start_time.tm_sec != nowtime.tm_sec)
79
gettimeofday(&now, NULL);
80
if (time_diff(now, begin) > 1.5) {
81
warnx(_("Timed out waiting for time change."));
90
* Read the hardware clock and return the current time via <tm> argument.
91
* Use ioctls to /dev/tty1 on what we assume is an m68k machine.
93
* Note that we don't use /dev/console here. That might be a serial console.
95
static int read_hardware_clock_kd(struct tm *tm)
99
if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
100
warn(_("ioctl() failed to read time from %s"),
102
hwclock_exit(EX_IOERR);
107
tm->tm_hour = t.hour;
110
tm->tm_year = t.year;
111
tm->tm_wday = t.wday;
112
tm->tm_isdst = -1; /* Don't know if it's Daylight Savings Time */
118
* Set the Hardware Clock to the time <new_broken_time>. Use ioctls to
119
* /dev/tty1 on what we assume is an m68k machine.
121
* Note that we don't use /dev/console here. That might be a serial console.
123
static int set_hardware_clock_kd(const struct tm *new_broken_time)
127
t.sec = new_broken_time->tm_sec;
128
t.min = new_broken_time->tm_min;
129
t.hour = new_broken_time->tm_hour;
130
t.day = new_broken_time->tm_mday;
131
t.mon = new_broken_time->tm_mon;
132
t.year = new_broken_time->tm_year;
133
t.wday = new_broken_time->tm_wday;
135
if (ioctl(con_fd, KDSHWCLK, &t) == -1) {
136
warn(_("ioctl KDSHWCLK failed"));
137
hwclock_exit(EX_IOERR);
142
static int get_permissions_kd(void)
144
147
static struct clock_ops kd = {