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