aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel
diff options
context:
space:
mode:
authorJohn Stultz <johnstul@us.ibm.com>2010-01-15 04:34:28 -0500
committerDavid S. Miller <davem@davemloft.net>2010-01-15 04:34:28 -0500
commit0299b1371d8f1b074c8284a19beb9094ada9405f (patch)
tree8a10f1e309640013a802c622f06702ca108f87d7 /arch/sparc/kernel
parent093171465235a8482fbf08a9a2e365247e1f7dd5 (diff)
sparc: convert to arch_gettimeoffset()
This patch converts sparc (specifically sparc32) to use GENERIC_TIME via the arch_getoffset() infrastructure, reducing the amount of arch specific code we need to maintain. The sparc architecture is one of the last 3 arches that need to be converted. This patch applies on top of Linus' current -git tree I've taken my best swing at converting this, but I'm not 100% confident I got it right. My cross-compiler is now out of date (gcc4.2) so I wasn't able to check if it compiled. Any assistance from arch maintainers or testers to get this merged would be great. Signed-off-by: John Stultz <johnstul@us.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/kernel')
-rw-r--r--arch/sparc/kernel/pcic.c103
-rw-r--r--arch/sparc/kernel/time_32.c116
2 files changed, 41 insertions, 178 deletions
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c
index 85e7037429b9..4e2724ec2bb6 100644
--- a/arch/sparc/kernel/pcic.c
+++ b/arch/sparc/kernel/pcic.c
@@ -30,6 +30,7 @@
30#include <asm/oplib.h> 30#include <asm/oplib.h>
31#include <asm/prom.h> 31#include <asm/prom.h>
32#include <asm/pcic.h> 32#include <asm/pcic.h>
33#include <asm/timex.h>
33#include <asm/timer.h> 34#include <asm/timer.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35#include <asm/irq_regs.h> 36#include <asm/irq_regs.h>
@@ -163,8 +164,6 @@ void __iomem *pcic_regs;
163volatile int pcic_speculative; 164volatile int pcic_speculative;
164volatile int pcic_trapped; 165volatile int pcic_trapped;
165 166
166static void pci_do_gettimeofday(struct timeval *tv);
167static int pci_do_settimeofday(struct timespec *tv);
168 167
169#define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (((unsigned int)bus) << 16) | (((unsigned int)device_fn) << 8) | (where & ~3)) 168#define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (((unsigned int)bus) << 16) | (((unsigned int)device_fn) << 8) | (where & ~3))
170 169
@@ -716,19 +715,27 @@ static irqreturn_t pcic_timer_handler (int irq, void *h)
716#define USECS_PER_JIFFY 10000 /* We have 100HZ "standard" timer for sparc */ 715#define USECS_PER_JIFFY 10000 /* We have 100HZ "standard" timer for sparc */
717#define TICK_TIMER_LIMIT ((100*1000000/4)/100) 716#define TICK_TIMER_LIMIT ((100*1000000/4)/100)
718 717
718u32 pci_gettimeoffset(void)
719{
720 /*
721 * We divide all by 100
722 * to have microsecond resolution and to avoid overflow
723 */
724 unsigned long count =
725 readl(pcic0.pcic_regs+PCI_SYS_COUNTER) & ~PCI_SYS_COUNTER_OVERFLOW;
726 count = ((count/100)*USECS_PER_JIFFY) / (TICK_TIMER_LIMIT/100);
727 return count * 1000;
728}
729
730
719void __init pci_time_init(void) 731void __init pci_time_init(void)
720{ 732{
721 struct linux_pcic *pcic = &pcic0; 733 struct linux_pcic *pcic = &pcic0;
722 unsigned long v; 734 unsigned long v;
723 int timer_irq, irq; 735 int timer_irq, irq;
724 736
725 /* A hack until do_gettimeofday prototype is moved to arch specific headers 737 do_arch_gettimeoffset = pci_gettimeoffset;
726 and btfixupped. Patch do_gettimeofday with ba pci_do_gettimeofday; nop */ 738
727 ((unsigned int *)do_gettimeofday)[0] =
728 0x10800000 | ((((unsigned long)pci_do_gettimeofday -
729 (unsigned long)do_gettimeofday) >> 2) & 0x003fffff);
730 ((unsigned int *)do_gettimeofday)[1] = 0x01000000;
731 BTFIXUPSET_CALL(bus_do_settimeofday, pci_do_settimeofday, BTFIXUPCALL_NORM);
732 btfixup(); 739 btfixup();
733 740
734 writel (TICK_TIMER_LIMIT, pcic->pcic_regs+PCI_SYS_LIMIT); 741 writel (TICK_TIMER_LIMIT, pcic->pcic_regs+PCI_SYS_LIMIT);
@@ -746,84 +753,6 @@ void __init pci_time_init(void)
746 local_irq_enable(); 753 local_irq_enable();
747} 754}
748 755
749static inline unsigned long do_gettimeoffset(void)
750{
751 /*
752 * We divide all by 100
753 * to have microsecond resolution and to avoid overflow
754 */
755 unsigned long count =
756 readl(pcic0.pcic_regs+PCI_SYS_COUNTER) & ~PCI_SYS_COUNTER_OVERFLOW;
757 count = ((count/100)*USECS_PER_JIFFY) / (TICK_TIMER_LIMIT/100);
758 return count;
759}
760
761static void pci_do_gettimeofday(struct timeval *tv)
762{
763 unsigned long flags;
764 unsigned long seq;
765 unsigned long usec, sec;
766 unsigned long max_ntp_tick = tick_usec - tickadj;
767
768 do {
769 seq = read_seqbegin_irqsave(&xtime_lock, flags);
770 usec = do_gettimeoffset();
771
772 /*
773 * If time_adjust is negative then NTP is slowing the clock
774 * so make sure not to go into next possible interval.
775 * Better to lose some accuracy than have time go backwards..
776 */
777 if (unlikely(time_adjust < 0))
778 usec = min(usec, max_ntp_tick);
779
780 sec = xtime.tv_sec;
781 usec += (xtime.tv_nsec / 1000);
782 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
783
784 while (usec >= 1000000) {
785 usec -= 1000000;
786 sec++;
787 }
788
789 tv->tv_sec = sec;
790 tv->tv_usec = usec;
791}
792
793static int pci_do_settimeofday(struct timespec *tv)
794{
795 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
796 return -EINVAL;
797
798 /*
799 * This is revolting. We need to set "xtime" correctly. However, the
800 * value in this location is the value at the most recent update of
801 * wall time. Discover what correction gettimeofday() would have
802 * made, and then undo it!
803 */
804 tv->tv_nsec -= 1000 * do_gettimeoffset();
805 while (tv->tv_nsec < 0) {
806 tv->tv_nsec += NSEC_PER_SEC;
807 tv->tv_sec--;
808 }
809
810 wall_to_monotonic.tv_sec += xtime.tv_sec - tv->tv_sec;
811 wall_to_monotonic.tv_nsec += xtime.tv_nsec - tv->tv_nsec;
812
813 if (wall_to_monotonic.tv_nsec > NSEC_PER_SEC) {
814 wall_to_monotonic.tv_nsec -= NSEC_PER_SEC;
815 wall_to_monotonic.tv_sec++;
816 }
817 if (wall_to_monotonic.tv_nsec < 0) {
818 wall_to_monotonic.tv_nsec += NSEC_PER_SEC;
819 wall_to_monotonic.tv_sec--;
820 }
821
822 xtime.tv_sec = tv->tv_sec;
823 xtime.tv_nsec = tv->tv_nsec;
824 ntp_clear();
825 return 0;
826}
827 756
828#if 0 757#if 0
829static void watchdog_reset() { 758static void watchdog_reset() {
diff --git a/arch/sparc/kernel/time_32.c b/arch/sparc/kernel/time_32.c
index 5b2f595fe65b..0d4c09b15efc 100644
--- a/arch/sparc/kernel/time_32.c
+++ b/arch/sparc/kernel/time_32.c
@@ -35,6 +35,7 @@
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36 36
37#include <asm/oplib.h> 37#include <asm/oplib.h>
38#include <asm/timex.h>
38#include <asm/timer.h> 39#include <asm/timer.h>
39#include <asm/system.h> 40#include <asm/system.h>
40#include <asm/irq.h> 41#include <asm/irq.h>
@@ -51,7 +52,6 @@ DEFINE_SPINLOCK(rtc_lock);
51EXPORT_SYMBOL(rtc_lock); 52EXPORT_SYMBOL(rtc_lock);
52 53
53static int set_rtc_mmss(unsigned long); 54static int set_rtc_mmss(unsigned long);
54static int sbus_do_settimeofday(struct timespec *tv);
55 55
56unsigned long profile_pc(struct pt_regs *regs) 56unsigned long profile_pc(struct pt_regs *regs)
57{ 57{
@@ -76,6 +76,8 @@ EXPORT_SYMBOL(profile_pc);
76 76
77__volatile__ unsigned int *master_l10_counter; 77__volatile__ unsigned int *master_l10_counter;
78 78
79u32 (*do_arch_gettimeoffset)(void);
80
79/* 81/*
80 * timer_interrupt() needs to keep up the real-time clock, 82 * timer_interrupt() needs to keep up the real-time clock,
81 * as well as call the "do_timer()" routine every clocktick 83 * as well as call the "do_timer()" routine every clocktick
@@ -196,35 +198,14 @@ static int __init clock_init(void)
196{ 198{
197 return of_register_driver(&clock_driver, &of_platform_bus_type); 199 return of_register_driver(&clock_driver, &of_platform_bus_type);
198} 200}
199
200/* Must be after subsys_initcall() so that busses are probed. Must 201/* Must be after subsys_initcall() so that busses are probed. Must
201 * be before device_initcall() because things like the RTC driver 202 * be before device_initcall() because things like the RTC driver
202 * need to see the clock registers. 203 * need to see the clock registers.
203 */ 204 */
204fs_initcall(clock_init); 205fs_initcall(clock_init);
205 206
206static void __init sbus_time_init(void)
207{
208
209 BTFIXUPSET_CALL(bus_do_settimeofday, sbus_do_settimeofday, BTFIXUPCALL_NORM);
210 btfixup();
211
212 sparc_init_timers(timer_interrupt);
213}
214
215void __init time_init(void)
216{
217#ifdef CONFIG_PCI
218 extern void pci_time_init(void);
219 if (pcic_present()) {
220 pci_time_init();
221 return;
222 }
223#endif
224 sbus_time_init();
225}
226 207
227static inline unsigned long do_gettimeoffset(void) 208u32 sbus_do_gettimeoffset(void)
228{ 209{
229 unsigned long val = *master_l10_counter; 210 unsigned long val = *master_l10_counter;
230 unsigned long usec = (val >> 10) & 0x1fffff; 211 unsigned long usec = (val >> 10) & 0x1fffff;
@@ -233,86 +214,39 @@ static inline unsigned long do_gettimeoffset(void)
233 if (val & 0x80000000) 214 if (val & 0x80000000)
234 usec += 1000000 / HZ; 215 usec += 1000000 / HZ;
235 216
236 return usec; 217 return usec * 1000;
237} 218}
238 219
239/* Ok, my cute asm atomicity trick doesn't work anymore.
240 * There are just too many variables that need to be protected
241 * now (both members of xtime, et al.)
242 */
243void do_gettimeofday(struct timeval *tv)
244{
245 unsigned long flags;
246 unsigned long seq;
247 unsigned long usec, sec;
248 unsigned long max_ntp_tick = tick_usec - tickadj;
249
250 do {
251 seq = read_seqbegin_irqsave(&xtime_lock, flags);
252 usec = do_gettimeoffset();
253
254 /*
255 * If time_adjust is negative then NTP is slowing the clock
256 * so make sure not to go into next possible interval.
257 * Better to lose some accuracy than have time go backwards..
258 */
259 if (unlikely(time_adjust < 0))
260 usec = min(usec, max_ntp_tick);
261
262 sec = xtime.tv_sec;
263 usec += (xtime.tv_nsec / 1000);
264 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
265
266 while (usec >= 1000000) {
267 usec -= 1000000;
268 sec++;
269 }
270 220
271 tv->tv_sec = sec; 221u32 arch_gettimeoffset(void)
272 tv->tv_usec = usec;
273}
274
275EXPORT_SYMBOL(do_gettimeofday);
276
277int do_settimeofday(struct timespec *tv)
278{ 222{
279 int ret; 223 if (unlikely(!do_arch_gettimeoffset))
280 224 return 0;
281 write_seqlock_irq(&xtime_lock); 225 return do_arch_gettimeoffset();
282 ret = bus_do_settimeofday(tv);
283 write_sequnlock_irq(&xtime_lock);
284 clock_was_set();
285 return ret;
286} 226}
287 227
288EXPORT_SYMBOL(do_settimeofday); 228static void __init sbus_time_init(void)
289
290static int sbus_do_settimeofday(struct timespec *tv)
291{ 229{
292 time_t wtm_sec, sec = tv->tv_sec; 230 do_arch_gettimeoffset = sbus_do_gettimeoffset;
293 long wtm_nsec, nsec = tv->tv_nsec;
294 231
295 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) 232 btfixup();
296 return -EINVAL;
297
298 /*
299 * This is revolting. We need to set "xtime" correctly. However, the
300 * value in this location is the value at the most recent update of
301 * wall time. Discover what correction gettimeofday() would have
302 * made, and then undo it!
303 */
304 nsec -= 1000 * do_gettimeoffset();
305
306 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
307 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
308 233
309 set_normalized_timespec(&xtime, sec, nsec); 234 sparc_init_timers(timer_interrupt);
310 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 235}
311 236
312 ntp_clear(); 237void __init time_init(void)
313 return 0; 238{
239#ifdef CONFIG_PCI
240 extern void pci_time_init(void);
241 if (pcic_present()) {
242 pci_time_init();
243 return;
244 }
245#endif
246 sbus_time_init();
314} 247}
315 248
249
316static int set_rtc_mmss(unsigned long secs) 250static int set_rtc_mmss(unsigned long secs)
317{ 251{
318 struct rtc_device *rtc = rtc_class_open("rtc0"); 252 struct rtc_device *rtc = rtc_class_open("rtc0");