ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / mips / sgi-ip27 / ip27-nmi.c
1 #include <linux/kallsyms.h>
2 #include <linux/kernel.h>
3 #include <linux/mmzone.h>
4 #include <linux/spinlock.h>
5 #include <linux/smp.h>
6 #include <asm/atomic.h>
7 #include <asm/sn/types.h>
8 #include <asm/sn/addrs.h>
9 #include <asm/sn/nmi.h>
10 #include <asm/sn/arch.h>
11 #include <asm/sn/sn0/hub.h>
12
13 #if 0
14 #define NODE_NUM_CPUS(n)        CNODE_NUM_CPUS(n)
15 #else
16 #define NODE_NUM_CPUS(n)        CPUS_PER_NODE
17 #endif
18
19 #define CNODEID_NONE (cnodeid_t)-1
20 #define enter_panic_mode()      spin_lock(&nmi_lock)
21
22 typedef unsigned long machreg_t;
23
24 spinlock_t nmi_lock = SPIN_LOCK_UNLOCKED;
25
26 /*
27  * Lets see what else we need to do here. Set up sp, gp?
28  */
29 void nmi_dump(void)
30 {
31         void cont_nmi_dump(void);
32
33         cont_nmi_dump();
34 }
35
36 void install_cpu_nmi_handler(int slice)
37 {
38         nmi_t *nmi_addr;
39
40         nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice);
41         if (nmi_addr->call_addr)
42                 return;
43         nmi_addr->magic = NMI_MAGIC;
44         nmi_addr->call_addr = (void *)nmi_dump;
45         nmi_addr->call_addr_c =
46                 (void *)(~((unsigned long)(nmi_addr->call_addr)));
47         nmi_addr->call_parm = 0;
48 }
49
50 /*
51  * Copy the cpu registers which have been saved in the IP27prom format
52  * into the eframe format for the node under consideration.
53  */
54
55 void nmi_cpu_eframe_save(nasid_t nasid, int slice)
56 {
57         struct reg_struct *nr;
58         int             i;
59
60         /* Get the pointer to the current cpu's register set. */
61         nr = (struct reg_struct *)
62                 (TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) +
63                 slice * IP27_NMI_KREGS_CPU_SIZE);
64
65         printk("NMI nasid %d: slice %d\n", nasid, slice);
66
67         /*
68          * Saved main processor registers
69          */
70         for (i = 0; i < 32; ) {
71                 if ((i % 4) == 0)
72                         printk("$%2d   :", i);
73                 printk(" %016lx", nr->gpr[i]);
74
75                 i++;
76                 if ((i % 4) == 0)
77                         printk("\n");
78         }
79
80         printk("Hi    : (value lost)\n");
81         printk("Lo    : (value lost)\n");
82
83         /*
84          * Saved cp0 registers
85          */
86         printk("epc   : %016lx ", nr->epc);
87         print_symbol("%s ", nr->epc);
88         printk("%s\n", print_tainted());
89         printk("ErrEPC: %016lx ", nr->error_epc);
90         print_symbol("%s\n", nr->error_epc);
91         printk("ra    : %016lx ", nr->gpr[31]);
92         print_symbol("%s\n", nr->gpr[31]);
93         printk("Status: %08lx         ", nr->sr);
94
95         if (nr->sr & ST0_KX)
96                 printk("KX ");
97         if (nr->sr & ST0_SX)
98                 printk("SX      ");
99         if (nr->sr & ST0_UX)
100                 printk("UX ");
101
102         switch (nr->sr & ST0_KSU) {
103         case KSU_USER:
104                 printk("USER ");
105                 break;
106         case KSU_SUPERVISOR:
107                 printk("SUPERVISOR ");
108                 break;
109         case KSU_KERNEL:
110                 printk("KERNEL ");
111                 break;
112         default:
113                 printk("BAD_MODE ");
114                 break;
115         }
116
117         if (nr->sr & ST0_ERL)
118                 printk("ERL ");
119         if (nr->sr & ST0_EXL)
120                 printk("EXL ");
121         if (nr->sr & ST0_IE)
122                 printk("IE ");
123         printk("\n");
124
125         printk("Cause : %08lx\n", nr->cause);
126         printk("PrId  : %08x\n", read_c0_prid());
127         printk("BadVA : %016lx\n", nr->badva);
128         printk("CErr  : %016lx\n", nr->cache_err);
129         printk("NMI_SR: %016lx\n", nr->nmi_sr);
130
131         printk("\n");
132 }
133
134 void nmi_dump_hub_irq(nasid_t nasid, int slice)
135 {
136         hubreg_t mask0, mask1, pend0, pend1;
137
138         if (slice == 0) {                               /* Slice A */
139                 mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A);
140                 mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A);
141         } else {                                        /* Slice B */
142                 mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B);
143                 mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B);
144         }
145
146         pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0);
147         pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1);
148
149         printk("PI_INT_MASK0: %16lx PI_INT_MASK1: %16lx\n", mask0, mask1);
150         printk("PI_INT_PEND0: %16lx PI_INT_PEND1: %16lx\n", pend0, pend1);
151         printk("\n\n");
152 }
153
154 /*
155  * Copy the cpu registers which have been saved in the IP27prom format
156  * into the eframe format for the node under consideration.
157  */
158 void nmi_node_eframe_save(cnodeid_t  cnode)
159 {
160         nasid_t nasid;
161         int slice;
162
163         /* Make sure that we have a valid node */
164         if (cnode == CNODEID_NONE)
165                 return;
166
167         nasid = COMPACT_TO_NASID_NODEID(cnode);
168         if (nasid == INVALID_NASID)
169                 return;
170
171         /* Save the registers into eframe for each cpu */
172         for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) {
173                 nmi_cpu_eframe_save(nasid, slice);
174                 nmi_dump_hub_irq(nasid, slice);
175         }
176 }
177
178 /*
179  * Save the nmi cpu registers for all cpus in the system.
180  */
181 void
182 nmi_eframes_save(void)
183 {
184         cnodeid_t       cnode;
185
186         for(cnode = 0 ; cnode < numnodes; cnode++)
187                 nmi_node_eframe_save(cnode);
188 }
189
190 void
191 cont_nmi_dump(void)
192 {
193 #ifndef REAL_NMI_SIGNAL
194         static atomic_t nmied_cpus = ATOMIC_INIT(0);
195
196         atomic_inc(&nmied_cpus);
197 #endif
198         /*
199          * Use enter_panic_mode to allow only 1 cpu to proceed
200          */
201         enter_panic_mode();
202
203 #ifdef REAL_NMI_SIGNAL
204         /*
205          * Wait up to 15 seconds for the other cpus to respond to the NMI.
206          * If a cpu has not responded after 10 sec, send it 1 additional NMI.
207          * This is for 2 reasons:
208          *      - sometimes a MMSC fail to NMI all cpus.
209          *      - on 512p SN0 system, the MMSC will only send NMIs to
210          *        half the cpus. Unfortunately, we don't know which cpus may be
211          *        NMIed - it depends on how the site chooses to configure.
212          *
213          * Note: it has been measure that it takes the MMSC up to 2.3 secs to
214          * send NMIs to all cpus on a 256p system.
215          */
216         for (i=0; i < 1500; i++) {
217                 for (node=0; node < numnodes; node++)
218                         if (NODEPDA(node)->dump_count == 0)
219                                 break;
220                 if (node == numnodes)
221                         break;
222                 if (i == 1000) {
223                         for (node=0; node < numnodes; node++)
224                                 if (NODEPDA(node)->dump_count == 0) {
225                                         cpu = node_to_first_cpu(node);
226                                         for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
227                                                 CPUMASK_SETB(nmied_cpus, cpu);
228                                                 /*
229                                                  * cputonasid, cputoslice
230                                                  * needs kernel cpuid
231                                                  */
232                                                 SEND_NMI((cputonasid(cpu)), (cputoslice(cpu)));
233                                         }
234                                 }
235
236                 }
237                 udelay(10000);
238         }
239 #else
240         while (atomic_read(&nmied_cpus) != num_online_cpus());
241 #endif
242
243         /*
244          * Save the nmi cpu registers for all cpu in the eframe format.
245          */
246         nmi_eframes_save();
247         LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
248 }