Fix IP22 timer calibration.
[linux-2.6/linux-mips.git] / arch / um / kernel / time_kern.c
blob8ae06b0d7cce36aa37370b9d92a6676b556f3724
1 /*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include "linux/kernel.h"
7 #include "linux/unistd.h"
8 #include "linux/stddef.h"
9 #include "linux/spinlock.h"
10 #include "linux/time.h"
11 #include "linux/sched.h"
12 #include "linux/interrupt.h"
13 #include "linux/init.h"
14 #include "linux/delay.h"
15 #include "asm/irq.h"
16 #include "asm/param.h"
17 #include "asm/current.h"
18 #include "kern_util.h"
19 #include "user_util.h"
20 #include "time_user.h"
21 #include "mode.h"
23 u64 jiffies_64;
25 int hz(void)
27 return(HZ);
30 /* Changed at early boot */
31 int timer_irq_inited = 0;
33 /* missed_ticks will be modified after kernel memory has been
34 * write-protected, so this puts it in a section which will be left
35 * write-enabled.
37 int __attribute__ ((__section__ (".unprotected"))) missed_ticks[NR_CPUS];
39 void timer_irq(union uml_pt_regs *regs)
41 int cpu = current->thread_info->cpu, ticks = missed_ticks[cpu];
43 if(!timer_irq_inited) return;
44 missed_ticks[cpu] = 0;
45 while(ticks--) do_IRQ(TIMER_IRQ, regs);
48 void boot_timer_handler(int sig)
50 struct pt_regs regs;
52 CHOOSE_MODE((void)
53 (UPT_SC(&regs.regs) = (struct sigcontext *) (&sig + 1)),
54 (void) (regs.regs.skas.is_user = 0));
55 do_timer(&regs);
58 void um_timer(int irq, void *dev, struct pt_regs *regs)
60 do_timer(regs);
61 write_seqlock(&xtime_lock);
62 timer();
63 write_sequnlock(&xtime_lock);
66 long um_time(int * tloc)
68 struct timeval now;
70 do_gettimeofday(&now);
71 if (tloc) {
72 if (put_user(now.tv_sec,tloc))
73 now.tv_sec = -EFAULT;
75 return now.tv_sec;
78 long um_stime(int * tptr)
80 int value;
81 struct timeval new;
83 if (get_user(value, tptr))
84 return -EFAULT;
85 new.tv_sec = value;
86 new.tv_usec = 0;
87 do_settimeofday(&new);
88 return 0;
91 /* XXX Needs to be moved under sys-i386 */
92 void __delay(um_udelay_t time)
94 /* Stolen from the i386 __loop_delay */
95 int d0;
96 __asm__ __volatile__(
97 "\tjmp 1f\n"
98 ".align 16\n"
99 "1:\tjmp 2f\n"
100 ".align 16\n"
101 "2:\tdecl %0\n\tjns 2b"
102 :"=&a" (d0)
103 :"0" (time));
106 void __udelay(um_udelay_t usecs)
108 int i, n;
110 n = (loops_per_jiffy * HZ * usecs) / 1000000;
111 for(i=0;i<n;i++) ;
114 void __const_udelay(um_udelay_t usecs)
116 int i, n;
118 n = (loops_per_jiffy * HZ * usecs) / 1000000;
119 for(i=0;i<n;i++) ;
122 void timer_handler(int sig, union uml_pt_regs *regs)
124 #ifdef CONFIG_SMP
125 update_process_times(user_context(UPT_SP(regs)));
126 #endif
127 if(current->thread_info->cpu == 0)
128 timer_irq(regs);
131 static spinlock_t timer_spinlock = SPIN_LOCK_UNLOCKED;
133 unsigned long time_lock(void)
135 unsigned long flags;
136 spin_lock_irqsave(&timer_spinlock, flags);
137 return(flags);
140 void time_unlock(unsigned long flags)
142 spin_unlock_irqrestore(&timer_spinlock, flags);
145 int __init timer_init(void)
147 int err;
149 CHOOSE_MODE(user_time_init_tt(), user_time_init_skas());
150 if((err = request_irq(TIMER_IRQ, um_timer, SA_INTERRUPT, "timer",
151 NULL)) != 0)
152 printk(KERN_ERR "timer_init : request_irq failed - "
153 "errno = %d\n", -err);
154 timer_irq_inited = 1;
155 return(0);
158 __initcall(timer_init);
162 * Overrides for Emacs so that we follow Linus's tabbing style.
163 * Emacs will notice this stuff at the end of the file and automatically
164 * adjust the settings for this buffer only. This must remain at the end
165 * of the file.
166 * ---------------------------------------------------------------------------
167 * Local variables:
168 * c-file-style: "linux"
169 * End: