diff options
author | Atsushi Nemoto <anemo@mba.ocn.ne.jp> | 2005-11-02 11:01:15 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2005-11-07 13:05:38 -0500 |
commit | 53c2df2f4ebbc1d8231ca7cc13ac5381230888b1 (patch) | |
tree | a7446ec56dd877d77ef7318b4bcdc3d38555ff0a /include/asm-mips/mc146818-time.h | |
parent | e329331aedeca0f2a7e15bd26a829ee1619c05e0 (diff) |
Use rtc_lock to protect RTC operations
Many RTC routines were not protected against each other, so there are
potential races, for example, ntp-update against /dev/rtc. This patch
fixes them using rtc_lock.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'include/asm-mips/mc146818-time.h')
-rw-r--r-- | include/asm-mips/mc146818-time.h | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/include/asm-mips/mc146818-time.h b/include/asm-mips/mc146818-time.h index a2c2d2c24303..47214861093b 100644 --- a/include/asm-mips/mc146818-time.h +++ b/include/asm-mips/mc146818-time.h | |||
@@ -33,7 +33,9 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime) | |||
33 | int real_seconds, real_minutes, cmos_minutes; | 33 | int real_seconds, real_minutes, cmos_minutes; |
34 | unsigned char save_control, save_freq_select; | 34 | unsigned char save_control, save_freq_select; |
35 | int retval = 0; | 35 | int retval = 0; |
36 | unsigned long flags; | ||
36 | 37 | ||
38 | spin_lock_irqsave(&rtc_lock, flags); | ||
37 | save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */ | 39 | save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */ |
38 | CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); | 40 | CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); |
39 | 41 | ||
@@ -79,14 +81,30 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime) | |||
79 | */ | 81 | */ |
80 | CMOS_WRITE(save_control, RTC_CONTROL); | 82 | CMOS_WRITE(save_control, RTC_CONTROL); |
81 | CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); | 83 | CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); |
84 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
82 | 85 | ||
83 | return retval; | 86 | return retval; |
84 | } | 87 | } |
85 | 88 | ||
89 | /* | ||
90 | * Returns true if a clock update is in progress | ||
91 | */ | ||
92 | static inline unsigned char rtc_is_updating(void) | ||
93 | { | ||
94 | unsigned char uip; | ||
95 | unsigned long flags; | ||
96 | |||
97 | spin_lock_irqsave(&rtc_lock, flags); | ||
98 | uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP); | ||
99 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
100 | return uip; | ||
101 | } | ||
102 | |||
86 | static inline unsigned long mc146818_get_cmos_time(void) | 103 | static inline unsigned long mc146818_get_cmos_time(void) |
87 | { | 104 | { |
88 | unsigned int year, mon, day, hour, min, sec; | 105 | unsigned int year, mon, day, hour, min, sec; |
89 | int i; | 106 | int i; |
107 | unsigned long flags; | ||
90 | 108 | ||
91 | /* | 109 | /* |
92 | * The Linux interpretation of the CMOS clock register contents: | 110 | * The Linux interpretation of the CMOS clock register contents: |
@@ -97,12 +115,13 @@ static inline unsigned long mc146818_get_cmos_time(void) | |||
97 | 115 | ||
98 | /* read RTC exactly on falling edge of update flag */ | 116 | /* read RTC exactly on falling edge of update flag */ |
99 | for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ | 117 | for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ |
100 | if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) | 118 | if (rtc_is_updating()) |
101 | break; | 119 | break; |
102 | for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */ | 120 | for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */ |
103 | if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)) | 121 | if (!rtc_is_updating()) |
104 | break; | 122 | break; |
105 | 123 | ||
124 | spin_lock_irqsave(&rtc_lock, flags); | ||
106 | do { /* Isn't this overkill ? UIP above should guarantee consistency */ | 125 | do { /* Isn't this overkill ? UIP above should guarantee consistency */ |
107 | sec = CMOS_READ(RTC_SECONDS); | 126 | sec = CMOS_READ(RTC_SECONDS); |
108 | min = CMOS_READ(RTC_MINUTES); | 127 | min = CMOS_READ(RTC_MINUTES); |
@@ -120,6 +139,7 @@ static inline unsigned long mc146818_get_cmos_time(void) | |||
120 | BCD_TO_BIN(mon); | 139 | BCD_TO_BIN(mon); |
121 | BCD_TO_BIN(year); | 140 | BCD_TO_BIN(year); |
122 | } | 141 | } |
142 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
123 | year = mc146818_decode_year(year); | 143 | year = mc146818_decode_year(year); |
124 | 144 | ||
125 | return mktime(year, mon, day, hour, min, sec); | 145 | return mktime(year, mon, day, hour, min, sec); |