Michael Ellerman | bdb226b | 2008-02-14 13:34:17 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006-2008, IBM Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | */ |
| 9 | |
| 10 | #undef DEBUG |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 11 | |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/smp.h> |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 15 | #include <linux/reboot.h> |
Milton Miller | 62a8bd6 | 2008-10-22 15:39:04 -0500 | [diff] [blame] | 16 | #include <linux/kexec.h> |
| 17 | #include <linux/crash_dump.h> |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 18 | |
Alexey Dobriyan | 9c8b4af | 2008-11-02 10:21:57 +0000 | [diff] [blame] | 19 | #include <asm/kexec.h> |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 20 | #include <asm/reg.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/prom.h> |
| 23 | #include <asm/machdep.h> |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 24 | #include <asm/rtas.h> |
Benjamin Herrenschmidt | eef686a0 | 2007-10-04 15:40:42 +1000 | [diff] [blame] | 25 | #include <asm/cell-regs.h> |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 26 | |
| 27 | #include "ras.h" |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 28 | |
| 29 | |
| 30 | static void dump_fir(int cpu) |
| 31 | { |
| 32 | struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu); |
| 33 | struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu); |
| 34 | |
| 35 | if (pregs == NULL) |
| 36 | return; |
| 37 | |
| 38 | /* Todo: do some nicer parsing of bits and based on them go down |
| 39 | * to other sub-units FIRs and not only IIC |
| 40 | */ |
Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 41 | printk(KERN_ERR "Global Checkstop FIR : 0x%016llx\n", |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 42 | in_be64(&pregs->checkstop_fir)); |
Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 43 | printk(KERN_ERR "Global Recoverable FIR : 0x%016llx\n", |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 44 | in_be64(&pregs->checkstop_fir)); |
Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 45 | printk(KERN_ERR "Global MachineCheck FIR : 0x%016llx\n", |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 46 | in_be64(&pregs->spec_att_mchk_fir)); |
| 47 | |
| 48 | if (iregs == NULL) |
| 49 | return; |
Ingo Molnar | fe33332 | 2009-01-06 14:26:03 +0000 | [diff] [blame] | 50 | printk(KERN_ERR "IOC FIR : 0x%016llx\n", |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 51 | in_be64(&iregs->ioc_fir)); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | void cbe_system_error_exception(struct pt_regs *regs) |
| 56 | { |
| 57 | int cpu = smp_processor_id(); |
| 58 | |
| 59 | printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu); |
| 60 | dump_fir(cpu); |
| 61 | dump_stack(); |
| 62 | } |
| 63 | |
| 64 | void cbe_maintenance_exception(struct pt_regs *regs) |
| 65 | { |
| 66 | int cpu = smp_processor_id(); |
| 67 | |
| 68 | /* |
| 69 | * Nothing implemented for the maintenance interrupt at this point |
| 70 | */ |
| 71 | |
| 72 | printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu); |
| 73 | dump_stack(); |
| 74 | } |
| 75 | |
| 76 | void cbe_thermal_exception(struct pt_regs *regs) |
| 77 | { |
| 78 | int cpu = smp_processor_id(); |
| 79 | |
| 80 | /* |
| 81 | * Nothing implemented for the thermal interrupt at this point |
| 82 | */ |
| 83 | |
| 84 | printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu); |
| 85 | dump_stack(); |
| 86 | } |
| 87 | |
| 88 | static int cbe_machine_check_handler(struct pt_regs *regs) |
| 89 | { |
| 90 | int cpu = smp_processor_id(); |
| 91 | |
| 92 | printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu); |
| 93 | dump_fir(cpu); |
| 94 | |
| 95 | /* No recovery from this code now, lets continue */ |
| 96 | return 0; |
| 97 | } |
| 98 | |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 99 | struct ptcal_area { |
| 100 | struct list_head list; |
| 101 | int nid; |
| 102 | int order; |
| 103 | struct page *pages; |
| 104 | }; |
| 105 | |
| 106 | static LIST_HEAD(ptcal_list); |
| 107 | |
| 108 | static int ptcal_start_tok, ptcal_stop_tok; |
| 109 | |
| 110 | static int __init cbe_ptcal_enable_on_node(int nid, int order) |
| 111 | { |
| 112 | struct ptcal_area *area; |
| 113 | int ret = -ENOMEM; |
| 114 | unsigned long addr; |
| 115 | |
Milton Miller | 62a8bd6 | 2008-10-22 15:39:04 -0500 | [diff] [blame] | 116 | if (is_kdump_kernel()) |
Mohan Kumar M | 54622f1 | 2008-10-21 17:38:10 +0000 | [diff] [blame] | 117 | rtas_call(ptcal_stop_tok, 1, 1, NULL, nid); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 118 | |
| 119 | area = kmalloc(sizeof(*area), GFP_KERNEL); |
| 120 | if (!area) |
| 121 | goto out_err; |
| 122 | |
| 123 | area->nid = nid; |
| 124 | area->order = order; |
| 125 | area->pages = alloc_pages_node(area->nid, GFP_KERNEL, area->order); |
| 126 | |
| 127 | if (!area->pages) |
| 128 | goto out_free_area; |
| 129 | |
| 130 | addr = __pa(page_address(area->pages)); |
| 131 | |
| 132 | ret = -EIO; |
| 133 | if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid, |
| 134 | (unsigned int)(addr >> 32), |
| 135 | (unsigned int)(addr & 0xffffffff))) { |
| 136 | printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n", |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 137 | __func__, nid); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 138 | goto out_free_pages; |
| 139 | } |
| 140 | |
| 141 | list_add(&area->list, &ptcal_list); |
| 142 | |
| 143 | return 0; |
| 144 | |
| 145 | out_free_pages: |
| 146 | __free_pages(area->pages, area->order); |
| 147 | out_free_area: |
| 148 | kfree(area); |
| 149 | out_err: |
| 150 | return ret; |
| 151 | } |
| 152 | |
| 153 | static int __init cbe_ptcal_enable(void) |
| 154 | { |
| 155 | const u32 *size; |
| 156 | struct device_node *np; |
| 157 | int order, found_mic = 0; |
| 158 | |
| 159 | np = of_find_node_by_path("/rtas"); |
| 160 | if (!np) |
| 161 | return -ENODEV; |
| 162 | |
Stephen Rothwell | 12d371a | 2007-04-29 16:29:08 +1000 | [diff] [blame] | 163 | size = of_get_property(np, "ibm,cbe-ptcal-size", NULL); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 164 | if (!size) |
| 165 | return -ENODEV; |
| 166 | |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 167 | pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 168 | order = get_order(*size); |
| 169 | of_node_put(np); |
| 170 | |
| 171 | /* support for malta device trees, with be@/mic@ nodes */ |
| 172 | for_each_node_by_type(np, "mic-tm") { |
| 173 | cbe_ptcal_enable_on_node(of_node_to_nid(np), order); |
| 174 | found_mic = 1; |
| 175 | } |
| 176 | |
| 177 | if (found_mic) |
| 178 | return 0; |
| 179 | |
| 180 | /* support for older device tree - use cpu nodes */ |
| 181 | for_each_node_by_type(np, "cpu") { |
Stephen Rothwell | 12d371a | 2007-04-29 16:29:08 +1000 | [diff] [blame] | 182 | const u32 *nid = of_get_property(np, "node-id", NULL); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 183 | if (!nid) { |
| 184 | printk(KERN_ERR "%s: node %s is missing node-id?\n", |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 185 | __func__, np->full_name); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 186 | continue; |
| 187 | } |
| 188 | cbe_ptcal_enable_on_node(*nid, order); |
| 189 | found_mic = 1; |
| 190 | } |
| 191 | |
| 192 | return found_mic ? 0 : -ENODEV; |
| 193 | } |
| 194 | |
| 195 | static int cbe_ptcal_disable(void) |
| 196 | { |
| 197 | struct ptcal_area *area, *tmp; |
| 198 | int ret = 0; |
| 199 | |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 200 | pr_debug("%s: disabling PTCAL\n", __func__); |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 201 | |
| 202 | list_for_each_entry_safe(area, tmp, &ptcal_list, list) { |
| 203 | /* disable ptcal on this node */ |
| 204 | if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) { |
| 205 | printk(KERN_ERR "%s: error disabling PTCAL " |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 206 | "on node %d!\n", __func__, |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 207 | area->nid); |
| 208 | ret = -EIO; |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | /* ensure we can access the PTCAL area */ |
| 213 | memset(page_address(area->pages), 0, |
| 214 | 1 << (area->order + PAGE_SHIFT)); |
| 215 | |
| 216 | /* clean up */ |
| 217 | list_del(&area->list); |
| 218 | __free_pages(area->pages, area->order); |
| 219 | kfree(area); |
| 220 | } |
| 221 | |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | static int cbe_ptcal_notify_reboot(struct notifier_block *nb, |
| 226 | unsigned long code, void *data) |
| 227 | { |
| 228 | return cbe_ptcal_disable(); |
| 229 | } |
| 230 | |
Arnd Bergmann | 5acb080 | 2008-06-12 19:14:36 +1000 | [diff] [blame] | 231 | static void cbe_ptcal_crash_shutdown(void) |
| 232 | { |
| 233 | cbe_ptcal_disable(); |
| 234 | } |
| 235 | |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 236 | static struct notifier_block cbe_ptcal_reboot_notifier = { |
| 237 | .notifier_call = cbe_ptcal_notify_reboot |
| 238 | }; |
| 239 | |
Christian Krafft | 70694a8 | 2008-07-16 05:51:44 +1000 | [diff] [blame] | 240 | #ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON |
| 241 | static int sysreset_hack; |
| 242 | |
| 243 | static int __init cbe_sysreset_init(void) |
| 244 | { |
| 245 | struct cbe_pmd_regs __iomem *regs; |
| 246 | |
| 247 | sysreset_hack = machine_is_compatible("IBM,CBPLUS-1.0"); |
| 248 | if (!sysreset_hack) |
| 249 | return 0; |
| 250 | |
| 251 | regs = cbe_get_cpu_pmd_regs(0); |
| 252 | if (!regs) |
| 253 | return 0; |
| 254 | |
| 255 | /* Enable JTAG system-reset hack */ |
| 256 | out_be32(®s->fir_mode_reg, |
| 257 | in_be32(®s->fir_mode_reg) | |
| 258 | CBE_PMD_FIR_MODE_M8); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | device_initcall(cbe_sysreset_init); |
| 263 | |
| 264 | int cbe_sysreset_hack(void) |
| 265 | { |
| 266 | struct cbe_pmd_regs __iomem *regs; |
| 267 | |
| 268 | /* |
| 269 | * The BMC can inject user triggered system reset exceptions, |
| 270 | * but cannot set the system reset reason in srr1, |
| 271 | * so check an extra register here. |
| 272 | */ |
| 273 | if (sysreset_hack && (smp_processor_id() == 0)) { |
| 274 | regs = cbe_get_cpu_pmd_regs(0); |
| 275 | if (!regs) |
| 276 | return 0; |
| 277 | if (in_be64(®s->ras_esc_0) & 0x0000ffff) { |
| 278 | out_be64(®s->ras_esc_0, 0); |
| 279 | return 0; |
| 280 | } |
| 281 | } |
| 282 | return 1; |
| 283 | } |
| 284 | #endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */ |
| 285 | |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 286 | int __init cbe_ptcal_init(void) |
| 287 | { |
| 288 | int ret; |
| 289 | ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal"); |
| 290 | ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal"); |
| 291 | |
| 292 | if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE |
| 293 | || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE) |
| 294 | return -ENODEV; |
| 295 | |
| 296 | ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier); |
Arnd Bergmann | 5acb080 | 2008-06-12 19:14:36 +1000 | [diff] [blame] | 297 | if (ret) |
| 298 | goto out1; |
| 299 | |
| 300 | ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown); |
| 301 | if (ret) |
| 302 | goto out2; |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 303 | |
| 304 | return cbe_ptcal_enable(); |
Arnd Bergmann | 5acb080 | 2008-06-12 19:14:36 +1000 | [diff] [blame] | 305 | |
| 306 | out2: |
| 307 | unregister_reboot_notifier(&cbe_ptcal_reboot_notifier); |
| 308 | out1: |
| 309 | printk(KERN_ERR "Can't disable PTCAL, so not enabling\n"); |
| 310 | return ret; |
Jeremy Kerr | 150f7e3 | 2007-04-23 21:35:47 +0200 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | arch_initcall(cbe_ptcal_init); |
| 314 | |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 315 | void __init cbe_ras_init(void) |
| 316 | { |
| 317 | unsigned long hid0; |
| 318 | |
| 319 | /* |
| 320 | * Enable System Error & thermal interrupts and wakeup conditions |
| 321 | */ |
| 322 | |
| 323 | hid0 = mfspr(SPRN_HID0); |
| 324 | hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP | |
| 325 | HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP; |
| 326 | mtspr(SPRN_HID0, hid0); |
| 327 | mb(); |
| 328 | |
| 329 | /* |
| 330 | * Install machine check handler. Leave setting of precise mode to |
| 331 | * what the firmware did for now |
| 332 | */ |
| 333 | ppc_md.machine_check_exception = cbe_machine_check_handler; |
| 334 | mb(); |
| 335 | |
| 336 | /* |
| 337 | * For now, we assume that IOC_FIR is already set to forward some |
| 338 | * error conditions to the System Error handler. If that is not true |
| 339 | * then it will have to be fixed up here. |
| 340 | */ |
| 341 | } |