aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-i386/mc146818rtc.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-i386/mc146818rtc.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-i386/mc146818rtc.h')
-rw-r--r--include/asm-i386/mc146818rtc.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/include/asm-i386/mc146818rtc.h b/include/asm-i386/mc146818rtc.h
new file mode 100644
index 000000000000..99a890047023
--- /dev/null
+++ b/include/asm-i386/mc146818rtc.h
@@ -0,0 +1,94 @@
1/*
2 * Machine dependent access functions for RTC registers.
3 */
4#ifndef _ASM_MC146818RTC_H
5#define _ASM_MC146818RTC_H
6
7#include <asm/io.h>
8#include <asm/system.h>
9#include <linux/mc146818rtc.h>
10
11#ifndef RTC_PORT
12#define RTC_PORT(x) (0x70 + (x))
13#define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
14#endif
15
16#ifdef __HAVE_ARCH_CMPXCHG
17/*
18 * This lock provides nmi access to the CMOS/RTC registers. It has some
19 * special properties. It is owned by a CPU and stores the index register
20 * currently being accessed (if owned). The idea here is that it works
21 * like a normal lock (normally). However, in an NMI, the NMI code will
22 * first check to see if its CPU owns the lock, meaning that the NMI
23 * interrupted during the read/write of the device. If it does, it goes ahead
24 * and performs the access and then restores the index register. If it does
25 * not, it locks normally.
26 *
27 * Note that since we are working with NMIs, we need this lock even in
28 * a non-SMP machine just to mark that the lock is owned.
29 *
30 * This only works with compare-and-swap. There is no other way to
31 * atomically claim the lock and set the owner.
32 */
33#include <linux/smp.h>
34extern volatile unsigned long cmos_lock;
35
36/*
37 * All of these below must be called with interrupts off, preempt
38 * disabled, etc.
39 */
40
41static inline void lock_cmos(unsigned char reg)
42{
43 unsigned long new;
44 new = ((smp_processor_id()+1) << 8) | reg;
45 for (;;) {
46 if (cmos_lock)
47 continue;
48 if (__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)) == 0)
49 return;
50 }
51}
52
53static inline void unlock_cmos(void)
54{
55 cmos_lock = 0;
56}
57static inline int do_i_have_lock_cmos(void)
58{
59 return (cmos_lock >> 8) == (smp_processor_id()+1);
60}
61static inline unsigned char current_lock_cmos_reg(void)
62{
63 return cmos_lock & 0xff;
64}
65#define lock_cmos_prefix(reg) \
66 do { \
67 unsigned long cmos_flags; \
68 local_irq_save(cmos_flags); \
69 lock_cmos(reg)
70#define lock_cmos_suffix(reg) \
71 unlock_cmos(); \
72 local_irq_restore(cmos_flags); \
73 } while (0)
74#else
75#define lock_cmos_prefix(reg) do {} while (0)
76#define lock_cmos_suffix(reg) do {} while (0)
77#define lock_cmos(reg)
78#define unlock_cmos()
79#define do_i_have_lock_cmos() 0
80#define current_lock_cmos_reg() 0
81#endif
82
83/*
84 * The yet supported machines all access the RTC index register via
85 * an ISA port access but the way to access the date register differs ...
86 */
87#define CMOS_READ(addr) rtc_cmos_read(addr)
88#define CMOS_WRITE(val, addr) rtc_cmos_write(val, addr)
89unsigned char rtc_cmos_read(unsigned char addr);
90void rtc_cmos_write(unsigned char val, unsigned char addr);
91
92#define RTC_IRQ 8
93
94#endif /* _ASM_MC146818RTC_H */