5353
5454unsigned long cpu_khz ;
5555
56- #define CPUCTR_IMASKBIT (0x100 << MIPSCPU_INT_CPUCTR)
57-
5856static int mips_cpu_timer_irq ;
57+ extern int mipsxx_perfcount_irq ;
5958extern void smtc_timer_broadcast (int );
6059
6160static void mips_timer_dispatch (void )
6261{
6362 do_IRQ (mips_cpu_timer_irq );
6463}
6564
65+ static void mips_perf_dispatch (void )
66+ {
67+ do_IRQ (mipsxx_perfcount_irq );
68+ }
69+
6670/*
6771 * Redeclare until I get around mopping the timer code insanity on MIPS.
6872 */
6973extern int null_perf_irq (void );
7074
7175extern int (* perf_irq )(void );
7276
77+ /*
78+ * Possibly handle a performance counter interrupt.
79+ * Return true if the timer interrupt should not be checked
80+ */
81+ static inline int handle_perf_irq (int r2 )
82+ {
83+ /*
84+ * The performance counter overflow interrupt may be shared with the
85+ * timer interrupt (mipsxx_perfcount_irq < 0). If it is and a
86+ * performance counter has overflowed (perf_irq() == IRQ_HANDLED)
87+ * and we can't reliably determine if a counter interrupt has also
88+ * happened (!r2) then don't check for a timer interrupt.
89+ */
90+ return (mipsxx_perfcount_irq < 0 ) &&
91+ perf_irq () == IRQ_HANDLED &&
92+ !r2 ;
93+ }
94+
7395irqreturn_t mips_timer_interrupt (int irq , void * dev_id )
7496{
7597 int cpu = smp_processor_id ();
@@ -92,8 +114,7 @@ irqreturn_t mips_timer_interrupt(int irq, void *dev_id)
92114 * We could be here due to timer interrupt,
93115 * perf counter overflow, or both.
94116 */
95- if (read_c0_cause () & (1 << 26 ))
96- perf_irq ();
117+ (void ) handle_perf_irq (1 );
97118
98119 if (read_c0_cause () & (1 << 30 )) {
99120 /*
@@ -115,19 +136,19 @@ irqreturn_t mips_timer_interrupt(int irq, void *dev_id)
115136#else /* CONFIG_MIPS_MT_SMTC */
116137 int r2 = cpu_has_mips_r2 ;
117138
139+ if (handle_perf_irq (r2 ))
140+ goto out ;
141+
142+ if (r2 && ((read_c0_cause () & (1 << 30 )) == 0 ))
143+ goto out ;
144+
118145 if (cpu == 0 ) {
119146 /*
120147 * CPU 0 handles the global timer interrupt job and process
121148 * accounting resets count/compare registers to trigger next
122149 * timer int.
123150 */
124- if (!r2 || (read_c0_cause () & (1 << 26 )))
125- if (perf_irq ())
126- goto out ;
127-
128- /* we keep interrupt disabled all the time */
129- if (!r2 || (read_c0_cause () & (1 << 30 )))
130- timer_interrupt (irq , NULL );
151+ timer_interrupt (irq , NULL );
131152 } else {
132153 /* Everyone else needs to reset the timer int here as
133154 ll_local_timer_interrupt doesn't */
@@ -225,35 +246,82 @@ void __init mips_time_init(void)
225246 mips_scroll_message ();
226247}
227248
228- void __init plat_timer_setup ( struct irqaction * irq )
249+ irqreturn_t mips_perf_interrupt ( int irq , void * dev_id )
229250{
251+ return perf_irq ();
252+ }
253+
254+ static struct irqaction perf_irqaction = {
255+ .handler = mips_perf_interrupt ,
256+ .flags = IRQF_DISABLED | IRQF_PERCPU ,
257+ .name = "performance" ,
258+ };
259+
260+ void __init plat_perf_setup (struct irqaction * irq )
261+ {
262+ int hwint = 0 ;
263+ mipsxx_perfcount_irq = -1 ;
264+
230265#ifdef MSC01E_INT_BASE
231266 if (cpu_has_veic ) {
232- set_vi_handler (MSC01E_INT_CPUCTR , mips_timer_dispatch );
233- mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR ;
267+ set_vi_handler (MSC01E_INT_PERFCTR , mips_perf_dispatch );
268+ mipsxx_perfcount_irq = MSC01E_INT_BASE + MSC01E_INT_PERFCTR ;
234269 } else
235270#endif
236- {
237- if (cpu_has_vint )
238- set_vi_handler (MIPSCPU_INT_CPUCTR , mips_timer_dispatch );
239- mips_cpu_timer_irq = MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR ;
271+ if (cpu_has_mips_r2 ) {
272+ /*
273+ * Read IntCtl.IPPCI to determine the performance
274+ * counter interrupt
275+ */
276+ hwint = (read_c0_intctl () >> 26 ) & 7 ;
277+ if (hwint != MIPSCPU_INT_CPUCTR ) {
278+ if (cpu_has_vint )
279+ set_vi_handler (hwint , mips_perf_dispatch );
280+ mipsxx_perfcount_irq = MIPSCPU_INT_BASE + hwint ;
281+ }
282+ }
283+ if (mipsxx_perfcount_irq >= 0 ) {
284+ #ifdef CONFIG_MIPS_MT_SMTC
285+ setup_irq_smtc (mipsxx_perfcount_irq , irq , 0x100 << hwint );
286+ #else
287+ setup_irq (mipsxx_perfcount_irq , irq );
288+ #endif /* CONFIG_MIPS_MT_SMTC */
289+ #ifdef CONFIG_SMP
290+ set_irq_handler (mipsxx_perfcount_irq , handle_percpu_irq );
291+ #endif
240292 }
293+ }
241294
295+ void __init plat_timer_setup (struct irqaction * irq )
296+ {
297+ int hwint = 0 ;
298+ if (cpu_has_veic ) {
299+ set_vi_handler (MSC01E_INT_CPUCTR , mips_timer_dispatch );
300+ mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR ;
301+ }
302+ else {
303+ if (cpu_has_mips_r2 )
304+ /*
305+ * Read IntCtl.IPTI to determine the timer interrupt
306+ */
307+ hwint = (read_c0_intctl () >> 29 ) & 7 ;
308+ else
309+ hwint = MIPSCPU_INT_CPUCTR ;
310+ if (cpu_has_vint )
311+ set_vi_handler (hwint , mips_timer_dispatch );
312+ mips_cpu_timer_irq = MIPSCPU_INT_BASE + hwint ;
313+ }
242314
243315 /* we are using the cpu counter for timer interrupts */
244316 irq -> handler = mips_timer_interrupt ; /* we use our own handler */
245317#ifdef CONFIG_MIPS_MT_SMTC
246- setup_irq_smtc (mips_cpu_timer_irq , irq , CPUCTR_IMASKBIT );
318+ setup_irq_smtc (mips_cpu_timer_irq , irq , 0x100 << hwint );
247319#else
248320 setup_irq (mips_cpu_timer_irq , irq );
249321#endif /* CONFIG_MIPS_MT_SMTC */
250-
251322#ifdef CONFIG_SMP
252- /* irq_desc(riptor) is a global resource, when the interrupt overlaps
253- on seperate cpu's the first one tries to handle the second interrupt.
254- The effect is that the int remains disabled on the second cpu.
255- Mark the interrupt with IRQ_PER_CPU to avoid any confusion */
256- irq_desc [mips_cpu_timer_irq ].status |= IRQ_PER_CPU ;
257323 set_irq_handler (mips_cpu_timer_irq , handle_percpu_irq );
258324#endif
325+
326+ plat_perf_setup (& perf_irqaction );
259327}
0 commit comments