kbuild: Fix instrumentation removal breakage on avr32
[wrt350n-kernel.git] / arch / powerpc / platforms / cell / ras.c
blobb2494ebcdbe9a131beb472f2ca45d04825a509d9
1 #define DEBUG
3 #include <linux/types.h>
4 #include <linux/kernel.h>
5 #include <linux/smp.h>
6 #include <linux/reboot.h>
8 #include <asm/reg.h>
9 #include <asm/io.h>
10 #include <asm/prom.h>
11 #include <asm/machdep.h>
12 #include <asm/rtas.h>
13 #include <asm/cell-regs.h>
15 #include "ras.h"
18 static void dump_fir(int cpu)
20 struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu);
21 struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu);
23 if (pregs == NULL)
24 return;
26 /* Todo: do some nicer parsing of bits and based on them go down
27 * to other sub-units FIRs and not only IIC
29 printk(KERN_ERR "Global Checkstop FIR : 0x%016lx\n",
30 in_be64(&pregs->checkstop_fir));
31 printk(KERN_ERR "Global Recoverable FIR : 0x%016lx\n",
32 in_be64(&pregs->checkstop_fir));
33 printk(KERN_ERR "Global MachineCheck FIR : 0x%016lx\n",
34 in_be64(&pregs->spec_att_mchk_fir));
36 if (iregs == NULL)
37 return;
38 printk(KERN_ERR "IOC FIR : 0x%016lx\n",
39 in_be64(&iregs->ioc_fir));
43 void cbe_system_error_exception(struct pt_regs *regs)
45 int cpu = smp_processor_id();
47 printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu);
48 dump_fir(cpu);
49 dump_stack();
52 void cbe_maintenance_exception(struct pt_regs *regs)
54 int cpu = smp_processor_id();
57 * Nothing implemented for the maintenance interrupt at this point
60 printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu);
61 dump_stack();
64 void cbe_thermal_exception(struct pt_regs *regs)
66 int cpu = smp_processor_id();
69 * Nothing implemented for the thermal interrupt at this point
72 printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu);
73 dump_stack();
76 static int cbe_machine_check_handler(struct pt_regs *regs)
78 int cpu = smp_processor_id();
80 printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu);
81 dump_fir(cpu);
83 /* No recovery from this code now, lets continue */
84 return 0;
87 struct ptcal_area {
88 struct list_head list;
89 int nid;
90 int order;
91 struct page *pages;
94 static LIST_HEAD(ptcal_list);
96 static int ptcal_start_tok, ptcal_stop_tok;
98 static int __init cbe_ptcal_enable_on_node(int nid, int order)
100 struct ptcal_area *area;
101 int ret = -ENOMEM;
102 unsigned long addr;
104 #ifdef CONFIG_CRASH_DUMP
105 rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
106 #endif
108 area = kmalloc(sizeof(*area), GFP_KERNEL);
109 if (!area)
110 goto out_err;
112 area->nid = nid;
113 area->order = order;
114 area->pages = alloc_pages_node(area->nid, GFP_KERNEL, area->order);
116 if (!area->pages)
117 goto out_free_area;
119 addr = __pa(page_address(area->pages));
121 ret = -EIO;
122 if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid,
123 (unsigned int)(addr >> 32),
124 (unsigned int)(addr & 0xffffffff))) {
125 printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n",
126 __FUNCTION__, nid);
127 goto out_free_pages;
130 list_add(&area->list, &ptcal_list);
132 return 0;
134 out_free_pages:
135 __free_pages(area->pages, area->order);
136 out_free_area:
137 kfree(area);
138 out_err:
139 return ret;
142 static int __init cbe_ptcal_enable(void)
144 const u32 *size;
145 struct device_node *np;
146 int order, found_mic = 0;
148 np = of_find_node_by_path("/rtas");
149 if (!np)
150 return -ENODEV;
152 size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
153 if (!size)
154 return -ENODEV;
156 pr_debug("%s: enabling PTCAL, size = 0x%x\n", __FUNCTION__, *size);
157 order = get_order(*size);
158 of_node_put(np);
160 /* support for malta device trees, with be@/mic@ nodes */
161 for_each_node_by_type(np, "mic-tm") {
162 cbe_ptcal_enable_on_node(of_node_to_nid(np), order);
163 found_mic = 1;
166 if (found_mic)
167 return 0;
169 /* support for older device tree - use cpu nodes */
170 for_each_node_by_type(np, "cpu") {
171 const u32 *nid = of_get_property(np, "node-id", NULL);
172 if (!nid) {
173 printk(KERN_ERR "%s: node %s is missing node-id?\n",
174 __FUNCTION__, np->full_name);
175 continue;
177 cbe_ptcal_enable_on_node(*nid, order);
178 found_mic = 1;
181 return found_mic ? 0 : -ENODEV;
184 static int cbe_ptcal_disable(void)
186 struct ptcal_area *area, *tmp;
187 int ret = 0;
189 pr_debug("%s: disabling PTCAL\n", __FUNCTION__);
191 list_for_each_entry_safe(area, tmp, &ptcal_list, list) {
192 /* disable ptcal on this node */
193 if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) {
194 printk(KERN_ERR "%s: error disabling PTCAL "
195 "on node %d!\n", __FUNCTION__,
196 area->nid);
197 ret = -EIO;
198 continue;
201 /* ensure we can access the PTCAL area */
202 memset(page_address(area->pages), 0,
203 1 << (area->order + PAGE_SHIFT));
205 /* clean up */
206 list_del(&area->list);
207 __free_pages(area->pages, area->order);
208 kfree(area);
211 return ret;
214 static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
215 unsigned long code, void *data)
217 return cbe_ptcal_disable();
220 static struct notifier_block cbe_ptcal_reboot_notifier = {
221 .notifier_call = cbe_ptcal_notify_reboot
224 int __init cbe_ptcal_init(void)
226 int ret;
227 ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal");
228 ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal");
230 if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE
231 || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)
232 return -ENODEV;
234 ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);
235 if (ret) {
236 printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
237 return ret;
240 return cbe_ptcal_enable();
243 arch_initcall(cbe_ptcal_init);
245 void __init cbe_ras_init(void)
247 unsigned long hid0;
250 * Enable System Error & thermal interrupts and wakeup conditions
253 hid0 = mfspr(SPRN_HID0);
254 hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP |
255 HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP;
256 mtspr(SPRN_HID0, hid0);
257 mb();
260 * Install machine check handler. Leave setting of precise mode to
261 * what the firmware did for now
263 ppc_md.machine_check_exception = cbe_machine_check_handler;
264 mb();
267 * For now, we assume that IOC_FIR is already set to forward some
268 * error conditions to the System Error handler. If that is not true
269 * then it will have to be fixed up here.