1 #include <linux/types.h>
2 #include <linux/config.h>
3 #include <linux/init.h>
4 #include <linux/kernel_stat.h>
5 #include <linux/sched.h>
6 #include <linux/spinlock.h>
8 #include <asm/mipsregs.h>
9 #include <asm/ptrace.h>
10 #include <asm/hardirq.h>
11 #include <asm/div64.h>
15 #include <linux/interrupt.h>
16 #include <linux/mc146818rtc.h>
17 #include <linux/timex.h>
18 #include <asm/mipsregs.h>
19 #include <asm/ptrace.h>
20 #include <asm/hardirq.h>
22 #include <asm/div64.h>
25 #include <asm/mc146818-time.h>
26 #include <asm/msc01_ic.h>
28 #include <asm/mips-boards/generic.h>
29 #include <asm/mips-boards/prom.h>
30 #include <asm/mips-boards/simint.h>
31 #include <asm/mc146818-time.h>
35 unsigned long cpu_khz;
37 extern asmlinkage void ll_local_timer_interrupt(int irq, struct pt_regs *regs);
39 irqreturn_t sim_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
42 int cpu = smp_processor_id();
45 * CPU 0 handles the global timer interrupt job
46 * resets count/compare registers to trigger next timer int.
48 #ifndef CONFIG_MIPS_MT_SMTC
50 timer_interrupt(irq, dev_id, regs);
53 /* Everyone else needs to reset the timer int here as
54 ll_local_timer_interrupt doesn't */
56 * FIXME: need to cope with counter underflow.
57 * More support needs to be added to kernel/time for
58 * counter/timer interrupts on multiple CPU's
60 write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
64 * In SMTC system, one Count/Compare set exists per VPE.
65 * Which TC within a VPE gets the interrupt is essentially
66 * random - we only know that it shouldn't be one with
67 * IXMT set. Whichever TC gets the interrupt needs to
68 * send special interprocessor interrupts to the other
69 * TCs to make sure that they schedule, etc.
71 * That code is specific to the SMTC kernel, not to
72 * the simulation platform, so it's invoked from
73 * the general MIPS timer_interrupt routine.
75 * We have a problem in that the interrupt vector code
76 * had to turn off the timer IM bit to avoid redundant
77 * entries, but we may never get to mips_cpu_irq_end
78 * to turn it back on again if the scheduler gets
79 * involved. So we clear the pending timer here,
80 * and re-enable the mask...
84 write_c0_compare (read_c0_count() - 1);
85 clear_c0_cause(0x100 << MIPSCPU_INT_CPUCTR);
86 set_c0_status(0x100 << MIPSCPU_INT_CPUCTR);
90 if(cpu_data[cpu].vpe_id == 0) timer_interrupt(irq, dev_id, regs);
91 else write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
92 smtc_timer_broadcast(cpu_data[cpu].vpe_id);
94 #endif /* CONFIG_MIPS_MT_SMTC */
97 * every CPU should do profiling and process accounting
99 local_timer_interrupt (irq, dev_id, regs);
102 return timer_interrupt (irq, dev_id, regs);
109 * Estimate CPU frequency. Sets mips_counter_frequency as a side-effect
111 static unsigned int __init estimate_cpu_frequency(void)
113 unsigned int prid = read_c0_prid() & 0xffff00;
118 * hardwire the board frequency to 12MHz.
121 if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) ||
122 (prid == (PRID_COMP_MIPS | PRID_IMP_25KF)))
129 local_irq_save(flags);
131 /* Start counter exactly on falling edge of update flag */
132 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
133 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
135 /* Start r4k counter. */
138 /* Read counter exactly on falling edge of update flag */
139 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
140 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
142 count = read_c0_count();
144 /* restore interrupts */
145 local_irq_restore(flags);
148 mips_hpt_frequency = count;
150 if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
151 (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
154 count += 5000; /* round */
155 count -= count%10000;
160 void __init sim_time_init(void)
162 unsigned int est_freq, flags;
164 local_irq_save(flags);
167 /* Set Data mode - binary. */
168 CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL);
171 est_freq = estimate_cpu_frequency ();
173 printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
174 (est_freq%1000000)*100/1000000);
176 cpu_khz = est_freq / 1000;
178 local_irq_restore(flags);
181 static int mips_cpu_timer_irq;
183 static void mips_timer_dispatch (struct pt_regs *regs)
185 do_IRQ (mips_cpu_timer_irq, regs);
189 void __init sim_timer_setup(struct irqaction *irq)
192 set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
193 mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
197 set_vi_handler(MIPSCPU_INT_CPUCTR, mips_timer_dispatch);
198 mips_cpu_timer_irq = MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR;
201 /* we are using the cpu counter for timer interrupts */
202 irq->handler = sim_timer_interrupt;
203 setup_irq(mips_cpu_timer_irq, irq);
206 /* irq_desc(riptor) is a global resource, when the interrupt overlaps
207 on seperate cpu's the first one tries to handle the second interrupt.
208 The effect is that the int remains disabled on the second cpu.
209 Mark the interrupt with IRQ_PER_CPU to avoid any confusion */
210 irq_desc[mips_cpu_timer_irq].status |= IRQ_PER_CPU;
213 /* to generate the first timer interrupt */
214 write_c0_compare(read_c0_count() + (mips_hpt_frequency/HZ));