]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/hwclock-cmos.c
misc: add static keyword to where needed [smatch scan]
[thirdparty/util-linux.git] / sys-utils / hwclock-cmos.c
1 /*
2 * i386 CMOS starts out with 14 bytes clock data alpha has something
3 * similar, but with details depending on the machine type.
4 *
5 * byte 0: seconds 0-59
6 * byte 2: minutes 0-59
7 * byte 4: hours 0-23 in 24hr mode,
8 * 1-12 in 12hr mode, with high bit unset/set
9 * if am/pm.
10 * byte 6: weekday 1-7, Sunday=1
11 * byte 7: day of the month 1-31
12 * byte 8: month 1-12
13 * byte 9: year 0-99
14 *
15 * Numbers are stored in BCD/binary if bit 2 of byte 11 is unset/set The
16 * clock is in 12hr/24hr mode if bit 1 of byte 11 is unset/set The clock is
17 * undefined (being updated) if bit 7 of byte 10 is set. The clock is frozen
18 * (to be updated) by setting bit 7 of byte 11 Bit 7 of byte 14 indicates
19 * whether the CMOS clock is reliable: it is 1 if RTC power has been good
20 * since this bit was last read; it is 0 when the battery is dead and system
21 * power has been off.
22 *
23 * Avoid setting the RTC clock within 2 seconds of the day rollover that
24 * starts a new month or enters daylight saving time.
25 *
26 * The century situation is messy:
27 *
28 * Usually byte 50 (0x32) gives the century (in BCD, so 19 or 20 hex), but
29 * IBM PS/2 has (part of) a checksum there and uses byte 55 (0x37).
30 * Sometimes byte 127 (0x7f) or Bank 1, byte 0x48 gives the century. The
31 * original RTC will not access any century byte; some modern versions will.
32 * If a modern RTC or BIOS increments the century byte it may go from 0x19
33 * to 0x20, but in some buggy cases 0x1a is produced.
34 */
35 /*
36 * A struct tm has int fields
37 * tm_sec 0-59, 60 or 61 only for leap seconds
38 * tm_min 0-59
39 * tm_hour 0-23
40 * tm_mday 1-31
41 * tm_mon 0-11
42 * tm_year number of years since 1900
43 * tm_wday 0-6, 0=Sunday
44 * tm_yday 0-365
45 * tm_isdst >0: yes, 0: no, <0: unknown
46 */
47
48 #include <errno.h>
49 #include <fcntl.h>
50 #include <stdio.h>
51 #include <string.h>
52 #include <time.h>
53 #include <unistd.h>
54
55 #include "c.h"
56 #include "nls.h"
57 #include "pathnames.h"
58
59 /* for inb, outb */
60 #if defined(__i386__) || defined(__x86_64__)
61 # ifdef HAVE_SYS_IO_H
62 # include <sys/io.h>
63 # elif defined(HAVE_ASM_IO_H)
64 # include <asm/io.h>
65 # else
66 # undef __i386__
67 # undef __x86_64__
68 # warning "disable cmos access - no sys/io.h or asm/io.h"
69 static void outb(int a __attribute__((__unused__)),
70 int b __attribute__((__unused__)))
71 {
72 }
73
74 static int inb(int c __attribute__((__unused__)))
75 {
76 return 0;
77 }
78 # endif /* __i386__ __x86_64__ */
79 #elif defined(__alpha__)
80 # ifdef HAVE_SYS_IO_H
81 # include <sys/io.h>
82 # else
83 /* <asm/io.h> fails to compile, probably because of u8 etc */
84 extern unsigned int inb(unsigned long port);
85 extern void outb(unsigned char b, unsigned long port);
86 extern int iopl(int level);
87 # endif
88 #else /* __alpha__ */
89 # warning "disable cmos access - not i386, x86_64, or alpha"
90 static void outb(int a __attribute__((__unused__)),
91 int b __attribute__((__unused__)))
92 {
93 }
94
95 static int inb(int c __attribute__((__unused__)))
96 {
97 return 0;
98 }
99 #endif /* for inb, outb */
100
101 #include "hwclock.h"
102
103 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
104 #define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
105
106 #define IOPL_NOT_IMPLEMENTED -2
107
108 /*
109 * The epoch.
110 *
111 * Unix uses 1900 as epoch for a struct tm, and 1970 for a time_t. But what
112 * was written to CMOS?
113 *
114 * Digital DECstations use 1928 - this is on a mips or alpha Digital Unix
115 * uses 1952, e.g. on AXPpxi33. Windows NT uses 1980. The ARC console
116 * expects to boot Windows NT and uses 1980. (But a Ruffian uses 1900, just
117 * like SRM.) It is reported that ALPHA_PRE_V1_2_SRM_CONSOLE uses 1958.
118 */
119 #define TM_EPOCH 1900
120 static int cmos_epoch = 1900;
121
122 /*
123 * Martin Ostermann writes:
124 *
125 * The problem with the Jensen is twofold: First, it has the clock at a
126 * different address. Secondly, it has a distinction between "local" and
127 * normal bus addresses. The local ones pertain to the hardware integrated
128 * into the chipset, like serial/parallel ports and of course, the RTC.
129 * Those need to be addressed differently. This is handled fine in the
130 * kernel, and it's not a problem, since this usually gets totally optimized
131 * by the compile. But the i/o routines of (g)libc lack this support so far.
132 * The result of this is, that the old clock program worked only on the
133 * Jensen when USE_DEV_PORT was defined, but not with the normal inb/outb
134 * functions.
135 */
136 static int use_dev_port = 0; /* 1 for Jensen */
137 static int dev_port_fd;
138 static unsigned short clock_ctl_addr = 0x70; /* 0x170 for Jensen */
139 static unsigned short clock_data_addr = 0x71; /* 0x171 for Jensen */
140
141 static int century_byte = 0; /* 0: don't access a century byte
142 * 50 (0x32): usual PC value
143 * 55 (0x37): PS/2
144 */
145
146 #ifdef __alpha__
147 static int funkyTOY = 0; /* 1 for PC164/LX164/SX164 type alpha */
148 #endif
149
150 #ifdef __alpha
151
152 static int is_in_cpuinfo(char *fmt, char *str)
153 {
154 FILE *cpuinfo;
155 char field[256];
156 char format[sizeof(field)];
157 int found = 0;
158
159 sprintf(format, "%s : %s", fmt, "%255s");
160
161 cpuinfo = fopen(_PATH_PROC_CPUINFO, "r");
162 if (cpuinfo) {
163 do {
164 if (fscanf(cpuinfo, format, field) == 1) {
165 if (strncmp(field, str, strlen(str)) == 0)
166 found = 1;
167 break;
168 }
169 } while (fgets(field, 256, cpuinfo));
170 fclose(cpuinfo);
171 }
172 return found;
173 }
174
175 /*
176 * Set cmos_epoch, either from user options, or by asking the kernel, or by
177 * looking at /proc/cpu_info
178 */
179 void set_cmos_epoch(const struct hwclock_control *ctl)
180 {
181 unsigned long epoch;
182
183 /* Believe the user */
184 if (ctl->epoch_option) {
185 cmos_epoch = ctl->epoch_option;
186 return;
187 }
188
189 if (ctl->ARCconsole)
190 cmos_epoch = 1980;
191
192 if (ctl->ARCconsole || ctl->SRM)
193 return;
194
195 #ifdef __linux__
196 /*
197 * If we can ask the kernel, we don't need guessing from
198 * /proc/cpuinfo
199 */
200 if (get_epoch_rtc(ctl, &epoch, 1) == 0) {
201 cmos_epoch = epoch;
202 return;
203 }
204 #endif
205
206 /*
207 * The kernel source today says: read the year.
208 *
209 * If it is in 0-19 then the epoch is 2000.
210 * If it is in 20-47 then the epoch is 1980.
211 * If it is in 48-69 then the epoch is 1952.
212 * If it is in 70-99 then the epoch is 1928.
213 *
214 * Otherwise the epoch is 1900.
215 * TODO: Clearly, this must be changed before 2019.
216 */
217 /*
218 * See whether we are dealing with SRM or MILO, as they have
219 * different "epoch" ideas.
220 */
221 if (is_in_cpuinfo("system serial number", "MILO")) {
222 if (ctl->debug)
223 printf(_("booted from MILO\n"));
224 /*
225 * See whether we are dealing with a RUFFIAN aka Alpha PC-164
226 * UX (or BX), as they have REALLY different TOY (TimeOfYear)
227 * format: BCD, and not an ARC-style epoch. BCD is detected
228 * dynamically, but we must NOT adjust like ARC.
229 */
230 if (is_in_cpuinfo("system type", "Ruffian")) {
231 if (debug)
232 printf(_("Ruffian BCD clock\n"));
233 return;
234 }
235 }
236
237 cmos_epoch = 1980;
238 }
239
240 void set_cmos_access(const struct hwclock_control *ctl)
241 {
242
243 /*
244 * See whether we're dealing with a Jensen---it has a weird I/O
245 * system. DEC was just learning how to build Alpha PCs.
246 */
247 if (ctl->Jensen || is_in_cpuinfo("system type", "Jensen")) {
248 use_dev_port = 1;
249 clock_ctl_addr = 0x170;
250 clock_data_addr = 0x171;
251 if (ctl->debug)
252 printf(_("clockport adjusted to 0x%x\n"),
253 clock_ctl_addr);
254 }
255
256 /*
257 * See whether we are dealing with PC164/LX164/SX164, as they have a
258 * TOY that must be accessed differently to work correctly.
259 */
260 /* Nautilus stuff reported by Neoklis Kyriazis */
261 if (ctl->funky_toy ||
262 is_in_cpuinfo("system variation", "PC164") ||
263 is_in_cpuinfo("system variation", "LX164") ||
264 is_in_cpuinfo("system variation", "SX164") ||
265 is_in_cpuinfo("system type", "Nautilus")) {
266 funkyTOY = 1;
267 if (ctl->debug)
268 printf(_("funky TOY!\n"));
269 }
270 }
271 #endif /* __alpha */
272
273 #ifdef __alpha__
274 /*
275 * The Alpha doesn't allow user-level code to disable interrupts (for good
276 * reasons). Instead, we ensure atomic operation by performing the operation
277 * and checking whether the high 32 bits of the cycle counter changed. If
278 * they did, a context switch must have occurred and we redo the operation.
279 * As long as the operation is reasonably short, it will complete
280 * atomically, eventually.
281 */
282 static unsigned long
283 atomic(const char *name,
284 unsigned long (*op) (const struct hwclock_control *ctl, unsigned long),
285 const struct hwclock_control *ctl,
286 unsigned long arg)
287 {
288 unsigned long ts1, ts2, n, v;
289
290 for (n = 0; n < 1000; ++n) {
291 asm volatile ("rpcc %0":"r=" (ts1));
292 v = (*op) (ctl, arg);
293 asm volatile ("rpcc %0":"r=" (ts2));
294
295 if ((ts1 ^ ts2) >> 32 == 0) {
296 return v;
297 }
298 }
299 errx(EXIT_FAILURE, _("atomic %s failed for 1000 iterations!"),
300 name);
301 }
302 #else
303
304 /*
305 * Hmmh, this isn't very atomic. Maybe we should force an error instead?
306 *
307 * TODO: optimize the access to CMOS by mlockall(MCL_CURRENT) and SCHED_FIFO
308 */
309 static unsigned long
310 atomic(const char *name __attribute__ ((__unused__)),
311 unsigned long (*op) (const struct hwclock_control *ctl, unsigned long),
312 const struct hwclock_control *ctl,
313 unsigned long arg)
314 {
315 return (*op) (ctl, arg);
316 }
317
318 #endif
319
320 static inline unsigned long cmos_read(const struct hwclock_control *ctl,
321 unsigned long reg)
322 {
323 if (use_dev_port) {
324 unsigned char v = reg | 0x80;
325 lseek(dev_port_fd, clock_ctl_addr, 0);
326 if (write(dev_port_fd, &v, 1) == -1 && ctl->debug)
327 warn(_("cmos_read(): write to control address %X failed"),
328 clock_ctl_addr);
329 lseek(dev_port_fd, clock_data_addr, 0);
330 if (read(dev_port_fd, &v, 1) == -1 && ctl->debug)
331 warn(_("cmos_read(): read from data address %X failed"),
332 clock_data_addr);
333 return v;
334 } else {
335 /*
336 * We only want to read CMOS data, but unfortunately writing
337 * to bit 7 disables (1) or enables (0) NMI; since this bit
338 * is read-only we have to guess the old status. Various
339 * docs suggest that one should disable NMI while
340 * reading/writing CMOS data, and enable it again
341 * afterwards. This would yield the sequence
342 *
343 * outb (reg | 0x80, 0x70);
344 * val = inb(0x71);
345 * outb (0x0d, 0x70); // 0x0d: random read-only location
346 *
347 * Other docs state that "any write to 0x70 should be
348 * followed by an action to 0x71 or the RTC will be left in
349 * an unknown state". Most docs say that it doesn't matter at
350 * all what one does.
351 */
352 /*
353 * bit 0x80: disable NMI while reading - should we? Let us
354 * follow the kernel and not disable. Called only with 0 <=
355 * reg < 128
356 */
357 outb(reg, clock_ctl_addr);
358 return inb(clock_data_addr);
359 }
360 }
361
362 static inline unsigned long cmos_write(const struct hwclock_control *ctl,
363 unsigned long reg, unsigned long val)
364 {
365 if (use_dev_port) {
366 unsigned char v = reg | 0x80;
367 lseek(dev_port_fd, clock_ctl_addr, 0);
368 if (write(dev_port_fd, &v, 1) == -1 && ctl->debug)
369 warn(_("cmos_write(): write to control address %X failed"),
370 clock_ctl_addr);
371 v = (val & 0xff);
372 lseek(dev_port_fd, clock_data_addr, 0);
373 if (write(dev_port_fd, &v, 1) == -1 && ctl->debug)
374 warn(_("cmos_write(): write to data address %X failed"),
375 clock_data_addr);
376 } else {
377 outb(reg, clock_ctl_addr);
378 outb(val, clock_data_addr);
379 }
380 return 0;
381 }
382
383 static unsigned long cmos_set_time(const struct hwclock_control *ctl,
384 unsigned long arg)
385 {
386 unsigned char save_control, save_freq_select, pmbit = 0;
387 struct tm tm = *(struct tm *)arg;
388 unsigned int century;
389
390 /*
391 * CMOS byte 10 (clock status register A) has 3 bitfields:
392 * bit 7: 1 if data invalid, update in progress (read-only bit)
393 * (this is raised 224 us before the actual update starts)
394 * 6-4 select base frequency
395 * 010: 32768 Hz time base (default)
396 * 111: reset
397 * all other combinations are manufacturer-dependent
398 * (e.g.: DS1287: 010 = start oscillator, anything else = stop)
399 * 3-0 rate selection bits for interrupt
400 * 0000 none (may stop RTC)
401 * 0001, 0010 give same frequency as 1000, 1001
402 * 0011 122 microseconds (minimum, 8192 Hz)
403 * .... each increase by 1 halves the frequency, doubles the period
404 * 1111 500 milliseconds (maximum, 2 Hz)
405 * 0110 976.562 microseconds (default 1024 Hz)
406 */
407 save_control = cmos_read(ctl, 11); /* tell the clock it's being set */
408 cmos_write(ctl, 11, (save_control | 0x80));
409 save_freq_select = cmos_read(ctl, 10); /* stop and reset prescaler */
410 cmos_write(ctl, 10, (save_freq_select | 0x70));
411
412 tm.tm_year += TM_EPOCH;
413 century = tm.tm_year / 100;
414 tm.tm_year -= cmos_epoch;
415 tm.tm_year %= 100;
416 tm.tm_mon += 1;
417 tm.tm_wday += 1;
418
419 if (!(save_control & 0x02)) { /* 12hr mode; the default is 24hr mode */
420 if (tm.tm_hour == 0)
421 tm.tm_hour = 24;
422 if (tm.tm_hour > 12) {
423 tm.tm_hour -= 12;
424 pmbit = 0x80;
425 }
426 }
427
428 if (!(save_control & 0x04)) { /* BCD mode - the default */
429 BIN_TO_BCD(tm.tm_sec);
430 BIN_TO_BCD(tm.tm_min);
431 BIN_TO_BCD(tm.tm_hour);
432 BIN_TO_BCD(tm.tm_wday);
433 BIN_TO_BCD(tm.tm_mday);
434 BIN_TO_BCD(tm.tm_mon);
435 BIN_TO_BCD(tm.tm_year);
436 BIN_TO_BCD(century);
437 }
438
439 cmos_write(ctl, 0, tm.tm_sec);
440 cmos_write(ctl, 2, tm.tm_min);
441 cmos_write(ctl, 4, tm.tm_hour | pmbit);
442 cmos_write(ctl, 6, tm.tm_wday);
443 cmos_write(ctl, 7, tm.tm_mday);
444 cmos_write(ctl, 8, tm.tm_mon);
445 cmos_write(ctl, 9, tm.tm_year);
446 if (century_byte)
447 cmos_write(ctl, century_byte, century);
448
449 /*
450 * The kernel sources, linux/arch/i386/kernel/time.c, have the
451 * following comment:
452 *
453 * The following flags have to be released exactly in this order,
454 * otherwise the DS12887 (popular MC146818A clone with integrated
455 * battery and quartz) will not reset the oscillator and will not
456 * update precisely 500 ms later. You won't find this mentioned in
457 * the Dallas Semiconductor data sheets, but who believes data
458 * sheets anyway ... -- Markus Kuhn
459 */
460 cmos_write(ctl, 11, save_control);
461 cmos_write(ctl, 10, save_freq_select);
462 return 0;
463 }
464
465 static int hclock_read(const struct hwclock_control *ctl, unsigned long reg)
466 {
467 return atomic("clock read", cmos_read, ctl, reg);
468 }
469
470 static void hclock_set_time(const struct hwclock_control *ctl, const struct tm *tm)
471 {
472 atomic("set time", cmos_set_time, ctl, (unsigned long)(tm));
473 }
474
475 static inline int cmos_clock_busy(const struct hwclock_control *ctl)
476 {
477 return
478 #ifdef __alpha__
479 /* poll bit 4 (UF) of Control Register C */
480 funkyTOY ? (hclock_read(ctl, 12) & 0x10) :
481 #endif
482 /* poll bit 7 (UIP) of Control Register A */
483 (hclock_read(ctl, 10) & 0x80);
484 }
485
486 static int synchronize_to_clock_tick_cmos(const struct hwclock_control *ctl
487 __attribute__((__unused__)))
488 {
489 int i;
490
491 /*
492 * Wait for rise. Should be within a second, but in case something
493 * weird happens, we have a limit on this loop to reduce the impact
494 * of this failure.
495 */
496 for (i = 0; !cmos_clock_busy(ctl); i++)
497 if (i >= 10000000)
498 return 1;
499
500 /* Wait for fall. Should be within 2.228 ms. */
501 for (i = 0; cmos_clock_busy(ctl); i++)
502 if (i >= 1000000)
503 return 1;
504 return 0;
505 }
506
507 /*
508 * Read the hardware clock and return the current time via <tm> argument.
509 * Assume we have an ISA machine and read the clock directly with CPU I/O
510 * instructions.
511 *
512 * This function is not totally reliable. It takes a finite and
513 * unpredictable amount of time to execute the code below. During that time,
514 * the clock may change and we may even read an invalid value in the middle
515 * of an update. We do a few checks to minimize this possibility, but only
516 * the kernel can actually read the clock properly, since it can execute
517 * code in a short and predictable amount of time (by turning of
518 * interrupts).
519 *
520 * In practice, the chance of this function returning the wrong time is
521 * extremely remote.
522 */
523 static int read_hardware_clock_cmos(const struct hwclock_control *ctl
524 __attribute__((__unused__)), struct tm *tm)
525 {
526 bool got_time = FALSE;
527 unsigned char status = 0, pmbit = 0;
528
529 while (!got_time) {
530 /*
531 * Bit 7 of Byte 10 of the Hardware Clock value is the
532 * Update In Progress (UIP) bit, which is on while and 244
533 * uS before the Hardware Clock updates itself. It updates
534 * the counters individually, so reading them during an
535 * update would produce garbage. The update takes 2mS, so we
536 * could be spinning here that long waiting for this bit to
537 * turn off.
538 *
539 * Furthermore, it is pathologically possible for us to be
540 * in this code so long that even if the UIP bit is not on
541 * at first, the clock has changed while we were running. We
542 * check for that too, and if it happens, we start over.
543 */
544 if (!cmos_clock_busy(ctl)) {
545 /* No clock update in progress, go ahead and read */
546 tm->tm_sec = hclock_read(ctl, 0);
547 tm->tm_min = hclock_read(ctl, 2);
548 tm->tm_hour = hclock_read(ctl, 4);
549 tm->tm_wday = hclock_read(ctl, 6);
550 tm->tm_mday = hclock_read(ctl, 7);
551 tm->tm_mon = hclock_read(ctl, 8);
552 tm->tm_year = hclock_read(ctl, 9);
553 status = hclock_read(ctl, 11);
554 #if 0
555 if (century_byte)
556 century = hclock_read(ctl, century_byte);
557 #endif
558 /*
559 * Unless the clock changed while we were reading,
560 * consider this a good clock read .
561 */
562 if (tm->tm_sec == hclock_read(ctl, 0))
563 got_time = TRUE;
564 }
565 /*
566 * Yes, in theory we could have been running for 60 seconds
567 * and the above test wouldn't work!
568 */
569 }
570
571 if (!(status & 0x04)) { /* BCD mode - the default */
572 BCD_TO_BIN(tm->tm_sec);
573 BCD_TO_BIN(tm->tm_min);
574 pmbit = (tm->tm_hour & 0x80);
575 tm->tm_hour &= 0x7f;
576 BCD_TO_BIN(tm->tm_hour);
577 BCD_TO_BIN(tm->tm_wday);
578 BCD_TO_BIN(tm->tm_mday);
579 BCD_TO_BIN(tm->tm_mon);
580 BCD_TO_BIN(tm->tm_year);
581 #if 0
582 BCD_TO_BIN(century);
583 #endif
584 }
585
586 /*
587 * We don't use the century byte of the Hardware Clock since we
588 * don't know its address (usually 50 or 55). Here, we follow the
589 * advice of the X/Open Base Working Group: "if century is not
590 * specified, then values in the range [69-99] refer to years in the
591 * twentieth century (1969 to 1999 inclusive), and values in the
592 * range [00-68] refer to years in the twenty-first century (2000 to
593 * 2068 inclusive)."
594 */
595 tm->tm_wday -= 1;
596 tm->tm_mon -= 1;
597 tm->tm_year += (cmos_epoch - TM_EPOCH);
598 if (tm->tm_year < 69)
599 tm->tm_year += 100;
600 if (pmbit) {
601 tm->tm_hour += 12;
602 if (tm->tm_hour == 24)
603 tm->tm_hour = 0;
604 }
605
606 tm->tm_isdst = -1; /* don't know whether it's daylight */
607 return 0;
608 }
609
610 static int set_hardware_clock_cmos(const struct hwclock_control *ctl
611 __attribute__((__unused__)),
612 const struct tm *new_broken_time)
613 {
614
615 hclock_set_time(ctl, new_broken_time);
616 return 0;
617 }
618
619 #if defined(__i386__) || defined(__alpha__) || defined(__x86_64__)
620 # if defined(HAVE_IOPL)
621 static int i386_iopl(const int level)
622 {
623 return iopl(level);
624 }
625 # else
626 static int i386_iopl(const int level __attribute__ ((__unused__)))
627 {
628 extern int ioperm(unsigned long from, unsigned long num, int turn_on);
629 return ioperm(clock_ctl_addr, 2, 1);
630 }
631 # endif
632 #else
633 static int i386_iopl(const int level __attribute__ ((__unused__)))
634 {
635 return IOPL_NOT_IMPLEMENTED;
636 }
637 #endif
638
639 static int get_permissions_cmos(void)
640 {
641 int rc;
642
643 if (use_dev_port) {
644 if ((dev_port_fd = open(_PATH_DEV_PORT, O_RDWR)) < 0) {
645 warn(_("cannot open %s"), _PATH_DEV_PORT);
646 rc = 1;
647 } else
648 rc = 0;
649 } else {
650 rc = i386_iopl(3);
651 if (rc == IOPL_NOT_IMPLEMENTED) {
652 warnx(_("I failed to get permission because I didn't try."));
653 } else if (rc != 0) {
654 rc = errno;
655 warn(_("unable to get I/O port access: "
656 "the iopl(3) call failed"));
657 if (rc == EPERM && geteuid())
658 warnx(_("Probably you need root privileges.\n"));
659 }
660 }
661 return rc ? 1 : 0;
662 }
663
664 static struct clock_ops cmos_interface = {
665 N_("Using direct I/O instructions to ISA clock."),
666 get_permissions_cmos,
667 read_hardware_clock_cmos,
668 set_hardware_clock_cmos,
669 synchronize_to_clock_tick_cmos,
670 };
671
672 /*
673 * return &cmos if cmos clock present, NULL otherwise choose this
674 * construction to avoid gcc messages about unused variables
675 */
676 struct clock_ops *probe_for_cmos_clock(void)
677 {
678 static const int have_cmos =
679 #if defined(__i386__) || defined(__alpha__) || defined(__x86_64__)
680 TRUE;
681 #else
682 FALSE;
683 #endif
684 return have_cmos ? &cmos_interface : NULL;
685 }