[ALSA] ice1724: fix MIDI
[firewire-audio.git] / arch / mn10300 / kernel / mn10300-watchdog.c
blob10811e981d20fd397792151bc3c7693471368da4
1 /* MN10300 Watchdog timer
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/i386/kernel/nmi.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel_stat.h>
19 #include <linux/nmi.h>
20 #include <asm/processor.h>
21 #include <asm/system.h>
22 #include <asm/atomic.h>
23 #include <asm/intctl-regs.h>
24 #include <asm/rtc-regs.h>
25 #include <asm/div64.h>
26 #include <asm/smp.h>
27 #include <asm/gdb-stub.h>
28 #include <asm/proc/clock.h>
30 static DEFINE_SPINLOCK(watchdog_print_lock);
31 static unsigned int watchdog;
32 static unsigned int watchdog_hz = 1;
33 unsigned int watchdog_alert_counter;
35 EXPORT_SYMBOL(touch_nmi_watchdog);
38 * the best way to detect whether a CPU has a 'hard lockup' problem
39 * is to check its timer makes IRQ counts. If they are not
40 * changing then that CPU has some problem.
42 * as these watchdog NMI IRQs are generated on every CPU, we only
43 * have to check the current processor.
45 * since NMIs dont listen to _any_ locks, we have to be extremely
46 * careful not to rely on unsafe variables. The printk might lock
47 * up though, so we have to break up any console locks first ...
48 * [when there will be more tty-related locks, break them up
49 * here too!]
51 static unsigned int last_irq_sums[NR_CPUS];
53 int __init check_watchdog(void)
55 irq_cpustat_t tmp[1];
57 printk(KERN_INFO "Testing Watchdog... ");
59 memcpy(tmp, irq_stat, sizeof(tmp));
60 local_irq_enable();
61 mdelay((10 * 1000) / watchdog_hz); /* wait 10 ticks */
62 local_irq_disable();
64 if (nmi_count(0) - tmp[0].__nmi_count <= 5) {
65 printk(KERN_WARNING "CPU#%d: Watchdog appears to be stuck!\n",
66 0);
67 return -1;
70 printk(KERN_INFO "OK.\n");
72 /* now that we know it works we can reduce NMI frequency to
73 * something more reasonable; makes a difference in some configs
75 watchdog_hz = 1;
77 return 0;
80 static int __init setup_watchdog(char *str)
82 unsigned tmp;
83 int opt;
84 u8 ctr;
86 get_option(&str, &opt);
87 if (opt != 1)
88 return 0;
90 watchdog = opt;
91 if (watchdog) {
92 set_intr_stub(EXCEP_WDT, watchdog_handler);
93 ctr = WDCTR_WDCK_65536th;
94 WDCTR = WDCTR_WDRST | ctr;
95 WDCTR = ctr;
96 tmp = WDCTR;
98 tmp = __muldiv64u(1 << (16 + ctr * 2), 1000000, MN10300_WDCLK);
99 tmp = 1000000000 / tmp;
100 watchdog_hz = (tmp + 500) / 1000;
103 return 1;
106 __setup("watchdog=", setup_watchdog);
108 void __init watchdog_go(void)
110 u8 wdt;
112 if (watchdog) {
113 printk(KERN_INFO "Watchdog: running at %uHz\n", watchdog_hz);
114 wdt = WDCTR & ~WDCTR_WDCNE;
115 WDCTR = wdt | WDCTR_WDRST;
116 wdt = WDCTR;
117 WDCTR = wdt | WDCTR_WDCNE;
118 wdt = WDCTR;
120 check_watchdog();
124 asmlinkage
125 void watchdog_interrupt(struct pt_regs *regs, enum exception_code excep)
129 * Since current-> is always on the stack, and we always switch
130 * the stack NMI-atomically, it's safe to use smp_processor_id().
132 int sum, cpu = smp_processor_id();
133 u8 wdt, tmp;
135 wdt = WDCTR & ~WDCTR_WDCNE;
136 WDCTR = wdt;
137 tmp = WDCTR;
138 NMICR = NMICR_WDIF;
140 nmi_count(cpu)++;
141 kstat_this_cpu.irqs[NMIIRQ]++;
142 sum = irq_stat[cpu].__irq_count;
144 if (last_irq_sums[cpu] == sum) {
146 * Ayiee, looks like this CPU is stuck ...
147 * wait a few IRQs (5 seconds) before doing the oops ...
149 watchdog_alert_counter++;
150 if (watchdog_alert_counter == 5 * watchdog_hz) {
151 spin_lock(&watchdog_print_lock);
153 * We are in trouble anyway, lets at least try
154 * to get a message out.
156 bust_spinlocks(1);
157 printk(KERN_ERR
158 "NMI Watchdog detected LOCKUP on CPU%d,"
159 " pc %08lx, registers:\n",
160 cpu, regs->pc);
161 show_registers(regs);
162 printk("console shuts up ...\n");
163 console_silent();
164 spin_unlock(&watchdog_print_lock);
165 bust_spinlocks(0);
166 #ifdef CONFIG_GDBSTUB
167 if (gdbstub_busy)
168 gdbstub_exception(regs, excep);
169 else
170 gdbstub_intercept(regs, excep);
171 #endif
172 do_exit(SIGSEGV);
174 } else {
175 last_irq_sums[cpu] = sum;
176 watchdog_alert_counter = 0;
179 WDCTR = wdt | WDCTR_WDRST;
180 tmp = WDCTR;
181 WDCTR = wdt | WDCTR_WDCNE;
182 tmp = WDCTR;