1 #include <linux/types.h>
2 #include <linux/init.h>
3 #include <linux/kernel_stat.h>
4 #include <linux/sched.h>
5 #include <linux/spinlock.h>
7 #include <asm/mipsregs.h>
8 #include <asm/ptrace.h>
9 #include <asm/hardirq.h>
10 #include <asm/div64.h>
14 #include <linux/interrupt.h>
15 #include <linux/mc146818rtc.h>
16 #include <linux/timex.h>
17 #include <asm/mipsregs.h>
18 #include <asm/ptrace.h>
19 #include <asm/hardirq.h>
21 #include <asm/div64.h>
24 #include <asm/mc146818-time.h>
25 #include <asm/msc01_ic.h>
27 #include <asm/mips-boards/generic.h>
28 #include <asm/mips-boards/prom.h>
29 #include <asm/mips-boards/simint.h>
30 #include <asm/mc146818-time.h>
34 unsigned long cpu_khz;
36 extern asmlinkage void ll_local_timer_interrupt(int irq, struct pt_regs *regs);
38 irqreturn_t sim_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
41 int cpu = smp_processor_id();
44 * CPU 0 handles the global timer interrupt job
45 * resets count/compare registers to trigger next timer int.
47 #ifndef CONFIG_MIPS_MT_SMTC
49 timer_interrupt(irq, dev_id, regs);
52 /* Everyone else needs to reset the timer int here as
53 ll_local_timer_interrupt doesn't */
55 * FIXME: need to cope with counter underflow.
56 * More support needs to be added to kernel/time for
57 * counter/timer interrupts on multiple CPU's
59 write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
63 * In SMTC system, one Count/Compare set exists per VPE.
64 * Which TC within a VPE gets the interrupt is essentially
65 * random - we only know that it shouldn't be one with
66 * IXMT set. Whichever TC gets the interrupt needs to
67 * send special interprocessor interrupts to the other
68 * TCs to make sure that they schedule, etc.
70 * That code is specific to the SMTC kernel, not to
71 * the simulation platform, so it's invoked from
72 * the general MIPS timer_interrupt routine.
74 * We have a problem in that the interrupt vector code
75 * had to turn off the timer IM bit to avoid redundant
76 * entries, but we may never get to mips_cpu_irq_end
77 * to turn it back on again if the scheduler gets
78 * involved. So we clear the pending timer here,
79 * and re-enable the mask...
83 write_c0_compare (read_c0_count() - 1);
84 clear_c0_cause(0x100 << MIPSCPU_INT_CPUCTR);
85 set_c0_status(0x100 << MIPSCPU_INT_CPUCTR);
89 if(cpu_data[cpu].vpe_id == 0) timer_interrupt(irq, dev_id, regs);
90 else write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
91 smtc_timer_broadcast(cpu_data[cpu].vpe_id);
93 #endif /* CONFIG_MIPS_MT_SMTC */
96 * every CPU should do profiling and process accounting
98 local_timer_interrupt (irq, dev_id, regs);
101 return timer_interrupt (irq, dev_id, regs);
108 * Estimate CPU frequency. Sets mips_counter_frequency as a side-effect
110 static unsigned int __init estimate_cpu_frequency(void)
112 unsigned int prid = read_c0_prid() & 0xffff00;
117 * hardwire the board frequency to 12MHz.
120 if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) ||
121 (prid == (PRID_COMP_MIPS | PRID_IMP_25KF)))
128 local_irq_save(flags);
130 /* Start counter exactly on falling edge of update flag */
131 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
132 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
134 /* Start r4k counter. */
137 /* Read counter exactly on falling edge of update flag */
138 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
139 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
141 count = read_c0_count();
143 /* restore interrupts */
144 local_irq_restore(flags);
147 mips_hpt_frequency = count;
149 if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
150 (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
153 count += 5000; /* round */
154 count -= count%10000;
159 void __init sim_time_init(void)
161 unsigned int est_freq, flags;
163 local_irq_save(flags);
166 /* Set Data mode - binary. */
167 CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL);
170 est_freq = estimate_cpu_frequency ();
172 printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
173 (est_freq%1000000)*100/1000000);
175 cpu_khz = est_freq / 1000;
177 local_irq_restore(flags);
180 static int mips_cpu_timer_irq;
182 static void mips_timer_dispatch (struct pt_regs *regs)
184 do_IRQ (mips_cpu_timer_irq, regs);
188 void __init sim_timer_setup(struct irqaction *irq)
191 set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
192 mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
196 set_vi_handler(MIPSCPU_INT_CPUCTR, mips_timer_dispatch);
197 mips_cpu_timer_irq = MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR;
200 /* we are using the cpu counter for timer interrupts */
201 irq->handler = sim_timer_interrupt;
202 setup_irq(mips_cpu_timer_irq, irq);
205 /* irq_desc(riptor) is a global resource, when the interrupt overlaps
206 on seperate cpu's the first one tries to handle the second interrupt.
207 The effect is that the int remains disabled on the second cpu.
208 Mark the interrupt with IRQ_PER_CPU to avoid any confusion */
209 irq_desc[mips_cpu_timer_irq].status |= IRQ_PER_CPU;
212 /* to generate the first timer interrupt */
213 write_c0_compare(read_c0_count() + (mips_hpt_frequency/HZ));