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