1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2006-2008, IBM Corporation.
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include <linux/smp.h>
12 #include <linux/reboot.h>
13 #include <linux/kexec.h>
14 #include <linux/crash_dump.h>
16 #include <asm/kexec.h>
20 #include <asm/machdep.h>
22 #include <asm/cell-regs.h>
27 static void dump_fir(int cpu
)
29 struct cbe_pmd_regs __iomem
*pregs
= cbe_get_cpu_pmd_regs(cpu
);
30 struct cbe_iic_regs __iomem
*iregs
= cbe_get_cpu_iic_regs(cpu
);
35 /* Todo: do some nicer parsing of bits and based on them go down
36 * to other sub-units FIRs and not only IIC
38 printk(KERN_ERR
"Global Checkstop FIR : 0x%016llx\n",
39 in_be64(&pregs
->checkstop_fir
));
40 printk(KERN_ERR
"Global Recoverable FIR : 0x%016llx\n",
41 in_be64(&pregs
->checkstop_fir
));
42 printk(KERN_ERR
"Global MachineCheck FIR : 0x%016llx\n",
43 in_be64(&pregs
->spec_att_mchk_fir
));
47 printk(KERN_ERR
"IOC FIR : 0x%016llx\n",
48 in_be64(&iregs
->ioc_fir
));
52 void cbe_system_error_exception(struct pt_regs
*regs
)
54 int cpu
= smp_processor_id();
56 printk(KERN_ERR
"System Error Interrupt on CPU %d !\n", cpu
);
61 void cbe_maintenance_exception(struct pt_regs
*regs
)
63 int cpu
= smp_processor_id();
66 * Nothing implemented for the maintenance interrupt at this point
69 printk(KERN_ERR
"Unhandled Maintenance interrupt on CPU %d !\n", cpu
);
73 void cbe_thermal_exception(struct pt_regs
*regs
)
75 int cpu
= smp_processor_id();
78 * Nothing implemented for the thermal interrupt at this point
81 printk(KERN_ERR
"Unhandled Thermal interrupt on CPU %d !\n", cpu
);
85 static int cbe_machine_check_handler(struct pt_regs
*regs
)
87 int cpu
= smp_processor_id();
89 printk(KERN_ERR
"Machine Check Interrupt on CPU %d !\n", cpu
);
92 /* No recovery from this code now, lets continue */
97 struct list_head list
;
103 static LIST_HEAD(ptcal_list
);
105 static int ptcal_start_tok
, ptcal_stop_tok
;
107 static int __init
cbe_ptcal_enable_on_node(int nid
, int order
)
109 struct ptcal_area
*area
;
113 if (is_kdump_kernel())
114 rtas_call(ptcal_stop_tok
, 1, 1, NULL
, nid
);
116 area
= kmalloc(sizeof(*area
), GFP_KERNEL
);
122 area
->pages
= __alloc_pages_node(area
->nid
,
123 GFP_KERNEL
|__GFP_THISNODE
,
127 printk(KERN_WARNING
"%s: no page on node %d\n",
128 __func__
, area
->nid
);
133 * We move the ptcal area to the middle of the allocated
134 * page, in order to avoid prefetches in memcpy and similar
135 * functions stepping on it.
137 addr
= __pa(page_address(area
->pages
)) + (PAGE_SIZE
>> 1);
138 printk(KERN_DEBUG
"%s: enabling PTCAL on node %d address=0x%016lx\n",
139 __func__
, area
->nid
, addr
);
142 if (rtas_call(ptcal_start_tok
, 3, 1, NULL
, area
->nid
,
143 (unsigned int)(addr
>> 32),
144 (unsigned int)(addr
& 0xffffffff))) {
145 printk(KERN_ERR
"%s: error enabling PTCAL on node %d!\n",
150 list_add(&area
->list
, &ptcal_list
);
155 __free_pages(area
->pages
, area
->order
);
162 static int __init
cbe_ptcal_enable(void)
165 struct device_node
*np
;
166 int order
, found_mic
= 0;
168 np
= of_find_node_by_path("/rtas");
172 size
= of_get_property(np
, "ibm,cbe-ptcal-size", NULL
);
178 pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__
, *size
);
179 order
= get_order(*size
);
182 /* support for malta device trees, with be@/mic@ nodes */
183 for_each_node_by_type(np
, "mic-tm") {
184 cbe_ptcal_enable_on_node(of_node_to_nid(np
), order
);
191 /* support for older device tree - use cpu nodes */
192 for_each_node_by_type(np
, "cpu") {
193 const u32
*nid
= of_get_property(np
, "node-id", NULL
);
195 printk(KERN_ERR
"%s: node %pOF is missing node-id?\n",
199 cbe_ptcal_enable_on_node(*nid
, order
);
203 return found_mic
? 0 : -ENODEV
;
206 static int cbe_ptcal_disable(void)
208 struct ptcal_area
*area
, *tmp
;
211 pr_debug("%s: disabling PTCAL\n", __func__
);
213 list_for_each_entry_safe(area
, tmp
, &ptcal_list
, list
) {
214 /* disable ptcal on this node */
215 if (rtas_call(ptcal_stop_tok
, 1, 1, NULL
, area
->nid
)) {
216 printk(KERN_ERR
"%s: error disabling PTCAL "
217 "on node %d!\n", __func__
,
223 /* ensure we can access the PTCAL area */
224 memset(page_address(area
->pages
), 0,
225 1 << (area
->order
+ PAGE_SHIFT
));
228 list_del(&area
->list
);
229 __free_pages(area
->pages
, area
->order
);
236 static int cbe_ptcal_notify_reboot(struct notifier_block
*nb
,
237 unsigned long code
, void *data
)
239 return cbe_ptcal_disable();
242 static void cbe_ptcal_crash_shutdown(void)
247 static struct notifier_block cbe_ptcal_reboot_notifier
= {
248 .notifier_call
= cbe_ptcal_notify_reboot
251 #ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
252 static int sysreset_hack
;
254 static int __init
cbe_sysreset_init(void)
256 struct cbe_pmd_regs __iomem
*regs
;
258 sysreset_hack
= of_machine_is_compatible("IBM,CBPLUS-1.0");
262 regs
= cbe_get_cpu_pmd_regs(0);
266 /* Enable JTAG system-reset hack */
267 out_be32(®s
->fir_mode_reg
,
268 in_be32(®s
->fir_mode_reg
) |
269 CBE_PMD_FIR_MODE_M8
);
273 device_initcall(cbe_sysreset_init
);
275 int cbe_sysreset_hack(void)
277 struct cbe_pmd_regs __iomem
*regs
;
280 * The BMC can inject user triggered system reset exceptions,
281 * but cannot set the system reset reason in srr1,
282 * so check an extra register here.
284 if (sysreset_hack
&& (smp_processor_id() == 0)) {
285 regs
= cbe_get_cpu_pmd_regs(0);
288 if (in_be64(®s
->ras_esc_0
) & 0x0000ffff) {
289 out_be64(®s
->ras_esc_0
, 0);
295 #endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
297 static int __init
cbe_ptcal_init(void)
300 ptcal_start_tok
= rtas_token("ibm,cbe-start-ptcal");
301 ptcal_stop_tok
= rtas_token("ibm,cbe-stop-ptcal");
303 if (ptcal_start_tok
== RTAS_UNKNOWN_SERVICE
304 || ptcal_stop_tok
== RTAS_UNKNOWN_SERVICE
)
307 ret
= register_reboot_notifier(&cbe_ptcal_reboot_notifier
);
311 ret
= crash_shutdown_register(&cbe_ptcal_crash_shutdown
);
315 return cbe_ptcal_enable();
318 unregister_reboot_notifier(&cbe_ptcal_reboot_notifier
);
320 printk(KERN_ERR
"Can't disable PTCAL, so not enabling\n");
324 arch_initcall(cbe_ptcal_init
);
326 void __init
cbe_ras_init(void)
331 * Enable System Error & thermal interrupts and wakeup conditions
334 hid0
= mfspr(SPRN_HID0
);
335 hid0
|= HID0_CBE_THERM_INT_EN
| HID0_CBE_THERM_WAKEUP
|
336 HID0_CBE_SYSERR_INT_EN
| HID0_CBE_SYSERR_WAKEUP
;
337 mtspr(SPRN_HID0
, hid0
);
341 * Install machine check handler. Leave setting of precise mode to
342 * what the firmware did for now
344 ppc_md
.machine_check_exception
= cbe_machine_check_handler
;
348 * For now, we assume that IOC_FIR is already set to forward some
349 * error conditions to the System Error handler. If that is not true
350 * then it will have to be fixed up here.