Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Copyright 2006-2008, IBM Corporation.
 
 
 
 
 
  4 */
  5
  6#undef DEBUG
  7
  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>
 15#include <linux/of.h>
 16
 17#include <asm/kexec.h>
 18#include <asm/reg.h>
 19#include <asm/io.h>
 
 20#include <asm/machdep.h>
 21#include <asm/rtas.h>
 22#include <asm/cell-regs.h>
 23
 24#include "ras.h"
 25#include "pervasive.h"
 26
 27static void dump_fir(int cpu)
 28{
 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);
 31
 32	if (pregs == NULL)
 33		return;
 34
 35	/* Todo: do some nicer parsing of bits and based on them go down
 36	 * to other sub-units FIRs and not only IIC
 37	 */
 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));
 44
 45	if (iregs == NULL)
 46		return;
 47	printk(KERN_ERR "IOC FIR                 : 0x%016llx\n",
 48	       in_be64(&iregs->ioc_fir));
 49
 50}
 51
 52DEFINE_INTERRUPT_HANDLER(cbe_system_error_exception)
 53{
 54	int cpu = smp_processor_id();
 55
 56	printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu);
 57	dump_fir(cpu);
 58	dump_stack();
 59}
 60
 61DEFINE_INTERRUPT_HANDLER(cbe_maintenance_exception)
 62{
 63	int cpu = smp_processor_id();
 64
 65	/*
 66	 * Nothing implemented for the maintenance interrupt at this point
 67	 */
 68
 69	printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu);
 70	dump_stack();
 71}
 72
 73DEFINE_INTERRUPT_HANDLER(cbe_thermal_exception)
 74{
 75	int cpu = smp_processor_id();
 76
 77	/*
 78	 * Nothing implemented for the thermal interrupt at this point
 79	 */
 80
 81	printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu);
 82	dump_stack();
 83}
 84
 85static int cbe_machine_check_handler(struct pt_regs *regs)
 86{
 87	int cpu = smp_processor_id();
 88
 89	printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu);
 90	dump_fir(cpu);
 91
 92	/* No recovery from this code now, lets continue */
 93	return 0;
 94}
 95
 96struct ptcal_area {
 97	struct list_head list;
 98	int nid;
 99	int order;
100	struct page *pages;
101};
102
103static LIST_HEAD(ptcal_list);
104
105static int ptcal_start_tok, ptcal_stop_tok;
106
107static int __init cbe_ptcal_enable_on_node(int nid, int order)
108{
109	struct ptcal_area *area;
110	int ret = -ENOMEM;
111	unsigned long addr;
112
113	if (is_kdump_kernel())
114		rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
115
116	area = kmalloc(sizeof(*area), GFP_KERNEL);
117	if (!area)
118		goto out_err;
119
120	area->nid = nid;
121	area->order = order;
122	area->pages = __alloc_pages_node(area->nid,
123						GFP_KERNEL|__GFP_THISNODE,
124						area->order);
125
126	if (!area->pages) {
127		printk(KERN_WARNING "%s: no page on node %d\n",
128			__func__, area->nid);
129		goto out_free_area;
130	}
131
132	/*
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.
136	 */
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);
140
141	ret = -EIO;
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",
146				__func__, nid);
147		goto out_free_pages;
148	}
149
150	list_add(&area->list, &ptcal_list);
151
152	return 0;
153
154out_free_pages:
155	__free_pages(area->pages, area->order);
156out_free_area:
157	kfree(area);
158out_err:
159	return ret;
160}
161
162static int __init cbe_ptcal_enable(void)
163{
164	const u32 *size;
165	struct device_node *np;
166	int order, found_mic = 0;
167
168	np = of_find_node_by_path("/rtas");
169	if (!np)
170		return -ENODEV;
171
172	size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
173	if (!size) {
174		of_node_put(np);
175		return -ENODEV;
176	}
177
178	pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);
179	order = get_order(*size);
180	of_node_put(np);
181
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);
185		found_mic = 1;
186	}
187
188	if (found_mic)
189		return 0;
190
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);
194		if (!nid) {
195			printk(KERN_ERR "%s: node %pOF is missing node-id?\n",
196					__func__, np);
197			continue;
198		}
199		cbe_ptcal_enable_on_node(*nid, order);
200		found_mic = 1;
201	}
202
203	return found_mic ? 0 : -ENODEV;
204}
205
206static int cbe_ptcal_disable(void)
207{
208	struct ptcal_area *area, *tmp;
209	int ret = 0;
210
211	pr_debug("%s: disabling PTCAL\n", __func__);
212
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__,
218					area->nid);
219			ret = -EIO;
220			continue;
221		}
222
223		/* ensure we can access the PTCAL area */
224		memset(page_address(area->pages), 0,
225				1 << (area->order + PAGE_SHIFT));
226
227		/* clean up */
228		list_del(&area->list);
229		__free_pages(area->pages, area->order);
230		kfree(area);
231	}
232
233	return ret;
234}
235
236static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
237		unsigned long code, void *data)
238{
239	return cbe_ptcal_disable();
240}
241
242static void cbe_ptcal_crash_shutdown(void)
243{
244	cbe_ptcal_disable();
245}
246
247static struct notifier_block cbe_ptcal_reboot_notifier = {
248	.notifier_call = cbe_ptcal_notify_reboot
249};
250
251#ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
252static int sysreset_hack;
253
254static int __init cbe_sysreset_init(void)
255{
256	struct cbe_pmd_regs __iomem *regs;
257
258	sysreset_hack = of_machine_is_compatible("IBM,CBPLUS-1.0");
259	if (!sysreset_hack)
260		return 0;
261
262	regs = cbe_get_cpu_pmd_regs(0);
263	if (!regs)
264		return 0;
265
266	/* Enable JTAG system-reset hack */
267	out_be32(&regs->fir_mode_reg,
268		in_be32(&regs->fir_mode_reg) |
269		CBE_PMD_FIR_MODE_M8);
270
271	return 0;
272}
273device_initcall(cbe_sysreset_init);
274
275int cbe_sysreset_hack(void)
276{
277	struct cbe_pmd_regs __iomem *regs;
278
279	/*
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.
283	 */
284	if (sysreset_hack && (smp_processor_id() == 0)) {
285		regs = cbe_get_cpu_pmd_regs(0);
286		if (!regs)
287			return 0;
288		if (in_be64(&regs->ras_esc_0) & 0x0000ffff) {
289			out_be64(&regs->ras_esc_0, 0);
290			return 0;
291		}
292	}
293	return 1;
294}
295#endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
296
297static int __init cbe_ptcal_init(void)
298{
299	int ret;
300	ptcal_start_tok = rtas_function_token(RTAS_FN_IBM_CBE_START_PTCAL);
301	ptcal_stop_tok = rtas_function_token(RTAS_FN_IBM_CBE_STOP_PTCAL);
302
303	if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE
304			|| ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)
305		return -ENODEV;
306
307	ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);
308	if (ret)
309		goto out1;
310
311	ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown);
312	if (ret)
313		goto out2;
314
315	return cbe_ptcal_enable();
316
317out2:
318	unregister_reboot_notifier(&cbe_ptcal_reboot_notifier);
319out1:
320	printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
321	return ret;
322}
323
324arch_initcall(cbe_ptcal_init);
325
326void __init cbe_ras_init(void)
327{
328	unsigned long hid0;
329
330	/*
331	 * Enable System Error & thermal interrupts and wakeup conditions
332	 */
333
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);
338	mb();
339
340	/*
341	 * Install machine check handler. Leave setting of precise mode to
342	 * what the firmware did for now
343	 */
344	ppc_md.machine_check_exception = cbe_machine_check_handler;
345	mb();
346
347	/*
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.
351	 */
352}
v3.1
 
  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
 11
 12#include <linux/types.h>
 13#include <linux/kernel.h>
 14#include <linux/slab.h>
 15#include <linux/smp.h>
 16#include <linux/reboot.h>
 17#include <linux/kexec.h>
 18#include <linux/crash_dump.h>
 
 19
 20#include <asm/kexec.h>
 21#include <asm/reg.h>
 22#include <asm/io.h>
 23#include <asm/prom.h>
 24#include <asm/machdep.h>
 25#include <asm/rtas.h>
 26#include <asm/cell-regs.h>
 27
 28#include "ras.h"
 29
 30
 31static 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	 */
 42	printk(KERN_ERR "Global Checkstop FIR    : 0x%016llx\n",
 43	       in_be64(&pregs->checkstop_fir));
 44	printk(KERN_ERR "Global Recoverable FIR  : 0x%016llx\n",
 45	       in_be64(&pregs->checkstop_fir));
 46	printk(KERN_ERR "Global MachineCheck FIR : 0x%016llx\n",
 47	       in_be64(&pregs->spec_att_mchk_fir));
 48
 49	if (iregs == NULL)
 50		return;
 51	printk(KERN_ERR "IOC FIR                 : 0x%016llx\n",
 52	       in_be64(&iregs->ioc_fir));
 53
 54}
 55
 56void 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
 65void 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
 77void 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
 89static 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
100struct ptcal_area {
101	struct list_head list;
102	int nid;
103	int order;
104	struct page *pages;
105};
106
107static LIST_HEAD(ptcal_list);
108
109static int ptcal_start_tok, ptcal_stop_tok;
110
111static 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
117	if (is_kdump_kernel())
118		rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
119
120	area = kmalloc(sizeof(*area), GFP_KERNEL);
121	if (!area)
122		goto out_err;
123
124	area->nid = nid;
125	area->order = order;
126	area->pages = alloc_pages_exact_node(area->nid, GFP_KERNEL|GFP_THISNODE,
 
127						area->order);
128
129	if (!area->pages) {
130		printk(KERN_WARNING "%s: no page on node %d\n",
131			__func__, area->nid);
132		goto out_free_area;
133	}
134
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);
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",
149				__func__, nid);
150		goto out_free_pages;
151	}
152
153	list_add(&area->list, &ptcal_list);
154
155	return 0;
156
157out_free_pages:
158	__free_pages(area->pages, area->order);
159out_free_area:
160	kfree(area);
161out_err:
162	return ret;
163}
164
165static 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
175	size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
176	if (!size) {
177		of_node_put(np);
178		return -ENODEV;
179	}
180
181	pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);
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") {
196		const u32 *nid = of_get_property(np, "node-id", NULL);
197		if (!nid) {
198			printk(KERN_ERR "%s: node %s is missing node-id?\n",
199					__func__, np->full_name);
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
209static int cbe_ptcal_disable(void)
210{
211	struct ptcal_area *area, *tmp;
212	int ret = 0;
213
214	pr_debug("%s: disabling PTCAL\n", __func__);
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 "
220					"on node %d!\n", __func__,
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
239static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
240		unsigned long code, void *data)
241{
242	return cbe_ptcal_disable();
243}
244
245static void cbe_ptcal_crash_shutdown(void)
246{
247	cbe_ptcal_disable();
248}
249
250static struct notifier_block cbe_ptcal_reboot_notifier = {
251	.notifier_call = cbe_ptcal_notify_reboot
252};
253
254#ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
255static int sysreset_hack;
256
257static int __init cbe_sysreset_init(void)
258{
259	struct cbe_pmd_regs __iomem *regs;
260
261	sysreset_hack = of_machine_is_compatible("IBM,CBPLUS-1.0");
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(&regs->fir_mode_reg,
271		in_be32(&regs->fir_mode_reg) |
272		CBE_PMD_FIR_MODE_M8);
273
274	return 0;
275}
276device_initcall(cbe_sysreset_init);
277
278int 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(&regs->ras_esc_0) & 0x0000ffff) {
292			out_be64(&regs->ras_esc_0, 0);
293			return 0;
294		}
295	}
296	return 1;
297}
298#endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
299
300int __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);
311	if (ret)
312		goto out1;
313
314	ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown);
315	if (ret)
316		goto out2;
317
318	return cbe_ptcal_enable();
319
320out2:
321	unregister_reboot_notifier(&cbe_ptcal_reboot_notifier);
322out1:
323	printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
324	return ret;
325}
326
327arch_initcall(cbe_ptcal_init);
328
329void __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}