1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/errno.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/param.h>
18#include <linux/string.h>
19#include <linux/mm.h>
20#include <linux/interrupt.h>
21#include <linux/time.h>
22#include <linux/init.h>
23#include <linux/smp.h>
24#include <linux/profile.h>
25#include <linux/clocksource.h>
26#include <linux/platform_device.h>
27#include <linux/ftrace.h>
28
29#include <asm/uaccess.h>
30#include <asm/io.h>
31#include <asm/irq.h>
32#include <asm/param.h>
33#include <asm/pdc.h>
34#include <asm/led.h>
35
36#include <linux/timex.h>
37
38static unsigned long clocktick __read_mostly;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
58{
59 unsigned long now, now2;
60 unsigned long next_tick;
61 unsigned long cycles_elapsed, ticks_elapsed = 1;
62 unsigned long cycles_remainder;
63 unsigned int cpu = smp_processor_id();
64 struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu);
65
66
67 unsigned long cpt = clocktick;
68
69 profile_tick(CPU_PROFILING);
70
71
72 next_tick = cpuinfo->it_value;
73
74
75 now = mfctl(16);
76
77 cycles_elapsed = now - next_tick;
78
79 if ((cycles_elapsed >> 6) < cpt) {
80
81
82
83 cycles_remainder = cycles_elapsed;
84 while (cycles_remainder > cpt) {
85 cycles_remainder -= cpt;
86 ticks_elapsed++;
87 }
88 } else {
89
90 cycles_remainder = cycles_elapsed % cpt;
91 ticks_elapsed += cycles_elapsed / cpt;
92 }
93
94
95 cycles_remainder = cpt - cycles_remainder;
96
97
98
99
100
101 next_tick = now + cycles_remainder;
102
103 cpuinfo->it_value = next_tick;
104
105
106
107
108 mtctl(next_tick, 16);
109
110
111
112
113
114
115
116
117
118
119
120 now2 = mfctl(16);
121 if (next_tick - now2 > cpt)
122 mtctl(next_tick+cpt, 16);
123
124#if 1
125
126
127
128 if (unlikely(now2 - now > 0x3000))
129 printk (KERN_CRIT "timer_interrupt(CPU %d): SLOW! 0x%lx cycles!"
130 " cyc %lX rem %lX "
131 " next/now %lX/%lX\n",
132 cpu, now2 - now, cycles_elapsed, cycles_remainder,
133 next_tick, now );
134#endif
135
136
137
138
139
140
141
142
143
144
145
146 if (unlikely(ticks_elapsed > HZ)) {
147
148 printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!"
149 " cycles %lX rem %lX "
150 " next/now %lX/%lX\n",
151 cpu,
152 cycles_elapsed, cycles_remainder,
153 next_tick, now );
154 }
155
156
157
158
159
160 if (!--cpuinfo->prof_counter) {
161 cpuinfo->prof_counter = cpuinfo->prof_multiplier;
162 update_process_times(user_mode(get_irq_regs()));
163 }
164
165 if (cpu == 0) {
166 write_seqlock(&xtime_lock);
167 do_timer(ticks_elapsed);
168 write_sequnlock(&xtime_lock);
169 }
170
171 return IRQ_HANDLED;
172}
173
174
175unsigned long profile_pc(struct pt_regs *regs)
176{
177 unsigned long pc = instruction_pointer(regs);
178
179 if (regs->gr[0] & PSW_N)
180 pc -= 4;
181
182#ifdef CONFIG_SMP
183 if (in_lock_functions(pc))
184 pc = regs->gr[2];
185#endif
186
187 return pc;
188}
189EXPORT_SYMBOL(profile_pc);
190
191
192
193
194static cycle_t read_cr16(struct clocksource *cs)
195{
196 return get_cycles();
197}
198
199static struct clocksource clocksource_cr16 = {
200 .name = "cr16",
201 .rating = 300,
202 .read = read_cr16,
203 .mask = CLOCKSOURCE_MASK(BITS_PER_LONG),
204 .mult = 0,
205 .shift = 22,
206 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
207};
208
209#ifdef CONFIG_SMP
210int update_cr16_clocksource(void)
211{
212
213
214 if (clocksource_cr16.rating != 0 && num_online_cpus() > 1) {
215 clocksource_change_rating(&clocksource_cr16, 0);
216 return 1;
217 }
218
219 return 0;
220}
221#else
222int update_cr16_clocksource(void)
223{
224 return 0;
225}
226#endif
227
228void __init start_cpu_itimer(void)
229{
230 unsigned int cpu = smp_processor_id();
231 unsigned long next_tick = mfctl(16) + clocktick;
232
233 mtctl(next_tick, 16);
234
235 per_cpu(cpu_data, cpu).it_value = next_tick;
236}
237
238static struct platform_device rtc_generic_dev = {
239 .name = "rtc-generic",
240 .id = -1,
241};
242
243static int __init rtc_init(void)
244{
245 if (platform_device_register(&rtc_generic_dev) < 0)
246 printk(KERN_ERR "unable to register rtc device...\n");
247
248
249 return 0;
250}
251module_init(rtc_init);
252
253void read_persistent_clock(struct timespec *ts)
254{
255 static struct pdc_tod tod_data;
256 if (pdc_tod_read(&tod_data) == 0) {
257 ts->tv_sec = tod_data.tod_sec;
258 ts->tv_nsec = tod_data.tod_usec * 1000;
259 } else {
260 printk(KERN_ERR "Error reading tod clock\n");
261 ts->tv_sec = 0;
262 ts->tv_nsec = 0;
263 }
264}
265
266void __init time_init(void)
267{
268 unsigned long current_cr16_khz;
269
270 clocktick = (100 * PAGE0->mem_10msec) / HZ;
271
272 start_cpu_itimer();
273
274
275 current_cr16_khz = PAGE0->mem_10msec/10;
276 clocksource_cr16.mult = clocksource_khz2mult(current_cr16_khz,
277 clocksource_cr16.shift);
278 clocksource_register(&clocksource_cr16);
279}
280