[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / mips / sgi-ip27 / ip27-timer.c
blob8c1b96fffa764e8e3a4c9d7ea163c04d2a61620e
1 /*
2 * Copytight (C) 1999, 2000, 05 Ralf Baechle (ralf@linux-mips.org)
3 * Copytight (C) 1999, 2000 Silicon Graphics, Inc.
4 */
5 #include <linux/bcd.h>
6 #include <linux/init.h>
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/interrupt.h>
10 #include <linux/kernel_stat.h>
11 #include <linux/param.h>
12 #include <linux/time.h>
13 #include <linux/timex.h>
14 #include <linux/mm.h>
16 #include <asm/time.h>
17 #include <asm/pgtable.h>
18 #include <asm/sgialib.h>
19 #include <asm/sn/ioc3.h>
20 #include <asm/m48t35.h>
21 #include <asm/sn/klconfig.h>
22 #include <asm/sn/arch.h>
23 #include <asm/sn/addrs.h>
24 #include <asm/sn/sn_private.h>
25 #include <asm/sn/sn0/ip27.h>
26 #include <asm/sn/sn0/hub.h>
29 * This is a hack; we really need to figure these values out dynamically
31 * Since 800 ns works very well with various HUB frequencies, such as
32 * 360, 380, 390 and 400 MHZ, we use 800 ns rtc cycle time.
34 * Ralf: which clock rate is used to feed the counter?
36 #define NSEC_PER_CYCLE 800
37 #define CYCLES_PER_SEC (NSEC_PER_SEC/NSEC_PER_CYCLE)
38 #define CYCLES_PER_JIFFY (CYCLES_PER_SEC/HZ)
40 #define TICK_SIZE (tick_nsec / 1000)
42 static unsigned long ct_cur[NR_CPUS]; /* What counter should be at next timer irq */
43 static long last_rtc_update; /* Last time the rtc clock got updated */
45 extern volatile unsigned long wall_jiffies;
47 #if 0
48 static int set_rtc_mmss(unsigned long nowtime)
50 int retval = 0;
51 int real_seconds, real_minutes, cmos_minutes;
52 struct m48t35_rtc *rtc;
53 nasid_t nid;
55 nid = get_nasid();
56 rtc = (struct m48t35_rtc *)(KL_CONFIG_CH_CONS_INFO(nid)->memory_base +
57 IOC3_BYTEBUS_DEV0);
59 rtc->control |= M48T35_RTC_READ;
60 cmos_minutes = BCD2BIN(rtc->min);
61 rtc->control &= ~M48T35_RTC_READ;
64 * Since we're only adjusting minutes and seconds, don't interfere with
65 * hour overflow. This avoids messing with unknown time zones but
66 * requires your RTC not to be off by more than 15 minutes
68 real_seconds = nowtime % 60;
69 real_minutes = nowtime / 60;
70 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
71 real_minutes += 30; /* correct for half hour time zone */
72 real_minutes %= 60;
74 if (abs(real_minutes - cmos_minutes) < 30) {
75 real_seconds = BIN2BCD(real_seconds);
76 real_minutes = BIN2BCD(real_minutes);
77 rtc->control |= M48T35_RTC_SET;
78 rtc->sec = real_seconds;
79 rtc->min = real_minutes;
80 rtc->control &= ~M48T35_RTC_SET;
81 } else {
82 printk(KERN_WARNING
83 "set_rtc_mmss: can't update from %d to %d\n",
84 cmos_minutes, real_minutes);
85 retval = -1;
88 return retval;
90 #endif
92 void ip27_rt_timer_interrupt(struct pt_regs *regs)
94 int cpu = smp_processor_id();
95 int cpuA = cputoslice(cpu) == 0;
96 int irq = 9; /* XXX Assign number */
98 irq_enter();
99 write_seqlock(&xtime_lock);
101 again:
102 LOCAL_HUB_S(cpuA ? PI_RT_PEND_A : PI_RT_PEND_B, 0); /* Ack */
103 ct_cur[cpu] += CYCLES_PER_JIFFY;
104 LOCAL_HUB_S(cpuA ? PI_RT_COMPARE_A : PI_RT_COMPARE_B, ct_cur[cpu]);
106 if (LOCAL_HUB_L(PI_RT_COUNT) >= ct_cur[cpu])
107 goto again;
109 kstat_this_cpu.irqs[irq]++; /* kstat only for bootcpu? */
111 if (cpu == 0)
112 do_timer(regs);
114 update_process_times(user_mode(regs));
117 * If we have an externally synchronized Linux clock, then update
118 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
119 * called as close as possible to when a second starts.
121 if ((time_status & STA_UNSYNC) == 0 &&
122 xtime.tv_sec > last_rtc_update + 660 &&
123 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
124 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
125 if (rtc_set_time(xtime.tv_sec) == 0) {
126 last_rtc_update = xtime.tv_sec;
127 } else {
128 last_rtc_update = xtime.tv_sec - 600;
129 /* do it again in 60 s */
133 write_sequnlock(&xtime_lock);
134 irq_exit();
137 unsigned long ip27_do_gettimeoffset(void)
139 unsigned long ct_cur1;
140 ct_cur1 = REMOTE_HUB_L(cputonasid(0), PI_RT_COUNT) + CYCLES_PER_JIFFY;
141 return (ct_cur1 - ct_cur[0]) * NSEC_PER_CYCLE / 1000;
144 /* Includes for ioc3_init(). */
145 #include <asm/sn/types.h>
146 #include <asm/sn/sn0/addrs.h>
147 #include <asm/sn/sn0/hubni.h>
148 #include <asm/sn/sn0/hubio.h>
149 #include <asm/pci/bridge.h>
151 static __init unsigned long get_m48t35_time(void)
153 unsigned int year, month, date, hour, min, sec;
154 struct m48t35_rtc *rtc;
155 nasid_t nid;
157 nid = get_nasid();
158 rtc = (struct m48t35_rtc *)(KL_CONFIG_CH_CONS_INFO(nid)->memory_base +
159 IOC3_BYTEBUS_DEV0);
161 rtc->control |= M48T35_RTC_READ;
162 sec = rtc->sec;
163 min = rtc->min;
164 hour = rtc->hour;
165 date = rtc->date;
166 month = rtc->month;
167 year = rtc->year;
168 rtc->control &= ~M48T35_RTC_READ;
170 sec = BCD2BIN(sec);
171 min = BCD2BIN(min);
172 hour = BCD2BIN(hour);
173 date = BCD2BIN(date);
174 month = BCD2BIN(month);
175 year = BCD2BIN(year);
177 year += 1970;
179 return mktime(year, month, date, hour, min, sec);
182 static void ip27_timer_setup(struct irqaction *irq)
184 /* over-write the handler, we use our own way */
185 irq->handler = no_action;
187 /* setup irqaction */
188 // setup_irq(IP27_TIMER_IRQ, irq); /* XXX Can't do this yet. */
191 void __init ip27_time_init(void)
193 xtime.tv_sec = get_m48t35_time();
194 xtime.tv_nsec = 0;
196 do_gettimeoffset = ip27_do_gettimeoffset;
198 board_timer_setup = ip27_timer_setup;
201 void __init cpu_time_init(void)
203 lboard_t *board;
204 klcpu_t *cpu;
205 int cpuid;
207 /* Don't use ARCS. ARCS is fragile. Klconfig is simple and sane. */
208 board = find_lboard(KL_CONFIG_INFO(get_nasid()), KLTYPE_IP27);
209 if (!board)
210 panic("Can't find board info for myself.");
212 cpuid = LOCAL_HUB_L(PI_CPU_NUM) ? IP27_CPU0_INDEX : IP27_CPU1_INDEX;
213 cpu = (klcpu_t *) KLCF_COMP(board, cpuid);
214 if (!cpu)
215 panic("No information about myself?");
217 printk("CPU %d clock is %dMHz.\n", smp_processor_id(), cpu->cpu_speed);
219 set_c0_status(SRB_TIMOCLK);
222 void __init hub_rtc_init(cnodeid_t cnode)
225 * We only need to initialize the current node.
226 * If this is not the current node then it is a cpuless
227 * node and timeouts will not happen there.
229 if (get_compact_nodeid() == cnode) {
230 int cpu = smp_processor_id();
231 LOCAL_HUB_S(PI_RT_EN_A, 1);
232 LOCAL_HUB_S(PI_RT_EN_B, 1);
233 LOCAL_HUB_S(PI_PROF_EN_A, 0);
234 LOCAL_HUB_S(PI_PROF_EN_B, 0);
235 ct_cur[cpu] = CYCLES_PER_JIFFY;
236 LOCAL_HUB_S(PI_RT_COMPARE_A, ct_cur[cpu]);
237 LOCAL_HUB_S(PI_RT_COUNT, 0);
238 LOCAL_HUB_S(PI_RT_PEND_A, 0);
239 LOCAL_HUB_S(PI_RT_COMPARE_B, ct_cur[cpu]);
240 LOCAL_HUB_S(PI_RT_COUNT, 0);
241 LOCAL_HUB_S(PI_RT_PEND_B, 0);