xref: /openbmc/linux/arch/powerpc/platforms/pseries/rtas-fadump.c (revision d3833a7010817f82bff373e26d146e6401c695f4)
1*d3833a70SHari Bathini // SPDX-License-Identifier: GPL-2.0-or-later
2*d3833a70SHari Bathini /*
3*d3833a70SHari Bathini  * Firmware-Assisted Dump support on POWERVM platform.
4*d3833a70SHari Bathini  *
5*d3833a70SHari Bathini  * Copyright 2011, Mahesh Salgaonkar, IBM Corporation.
6*d3833a70SHari Bathini  * Copyright 2019, Hari Bathini, IBM Corporation.
7*d3833a70SHari Bathini  */
8*d3833a70SHari Bathini 
9*d3833a70SHari Bathini #define pr_fmt(fmt) "rtas fadump: " fmt
10*d3833a70SHari Bathini 
11*d3833a70SHari Bathini #include <linux/string.h>
12*d3833a70SHari Bathini #include <linux/memblock.h>
13*d3833a70SHari Bathini #include <linux/delay.h>
14*d3833a70SHari Bathini #include <linux/seq_file.h>
15*d3833a70SHari Bathini #include <linux/crash_dump.h>
16*d3833a70SHari Bathini 
17*d3833a70SHari Bathini #include <asm/page.h>
18*d3833a70SHari Bathini #include <asm/prom.h>
19*d3833a70SHari Bathini #include <asm/rtas.h>
20*d3833a70SHari Bathini #include <asm/fadump.h>
21*d3833a70SHari Bathini #include <asm/fadump-internal.h>
22*d3833a70SHari Bathini 
23*d3833a70SHari Bathini #include "rtas-fadump.h"
24*d3833a70SHari Bathini 
25*d3833a70SHari Bathini static u64 rtas_fadump_init_mem_struct(struct fw_dump *fadump_conf)
26*d3833a70SHari Bathini {
27*d3833a70SHari Bathini 	return fadump_conf->reserve_dump_area_start;
28*d3833a70SHari Bathini }
29*d3833a70SHari Bathini 
30*d3833a70SHari Bathini static int rtas_fadump_register(struct fw_dump *fadump_conf)
31*d3833a70SHari Bathini {
32*d3833a70SHari Bathini 	return -EIO;
33*d3833a70SHari Bathini }
34*d3833a70SHari Bathini 
35*d3833a70SHari Bathini static int rtas_fadump_unregister(struct fw_dump *fadump_conf)
36*d3833a70SHari Bathini {
37*d3833a70SHari Bathini 	return -EIO;
38*d3833a70SHari Bathini }
39*d3833a70SHari Bathini 
40*d3833a70SHari Bathini static int rtas_fadump_invalidate(struct fw_dump *fadump_conf)
41*d3833a70SHari Bathini {
42*d3833a70SHari Bathini 	return -EIO;
43*d3833a70SHari Bathini }
44*d3833a70SHari Bathini 
45*d3833a70SHari Bathini /*
46*d3833a70SHari Bathini  * Validate and process the dump data stored by firmware before exporting
47*d3833a70SHari Bathini  * it through '/proc/vmcore'.
48*d3833a70SHari Bathini  */
49*d3833a70SHari Bathini static int __init rtas_fadump_process(struct fw_dump *fadump_conf)
50*d3833a70SHari Bathini {
51*d3833a70SHari Bathini 	return -EINVAL;
52*d3833a70SHari Bathini }
53*d3833a70SHari Bathini 
54*d3833a70SHari Bathini static void rtas_fadump_region_show(struct fw_dump *fadump_conf,
55*d3833a70SHari Bathini 				    struct seq_file *m)
56*d3833a70SHari Bathini {
57*d3833a70SHari Bathini }
58*d3833a70SHari Bathini 
59*d3833a70SHari Bathini static void rtas_fadump_trigger(struct fadump_crash_info_header *fdh,
60*d3833a70SHari Bathini 				const char *msg)
61*d3833a70SHari Bathini {
62*d3833a70SHari Bathini 	/* Call ibm,os-term rtas call to trigger firmware assisted dump */
63*d3833a70SHari Bathini 	rtas_os_term((char *)msg);
64*d3833a70SHari Bathini }
65*d3833a70SHari Bathini 
66*d3833a70SHari Bathini static struct fadump_ops rtas_fadump_ops = {
67*d3833a70SHari Bathini 	.fadump_init_mem_struct		= rtas_fadump_init_mem_struct,
68*d3833a70SHari Bathini 	.fadump_register		= rtas_fadump_register,
69*d3833a70SHari Bathini 	.fadump_unregister		= rtas_fadump_unregister,
70*d3833a70SHari Bathini 	.fadump_invalidate		= rtas_fadump_invalidate,
71*d3833a70SHari Bathini 	.fadump_process			= rtas_fadump_process,
72*d3833a70SHari Bathini 	.fadump_region_show		= rtas_fadump_region_show,
73*d3833a70SHari Bathini 	.fadump_trigger			= rtas_fadump_trigger,
74*d3833a70SHari Bathini };
75*d3833a70SHari Bathini 
76*d3833a70SHari Bathini void __init rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
77*d3833a70SHari Bathini {
78*d3833a70SHari Bathini 	int i, size, num_sections;
79*d3833a70SHari Bathini 	const __be32 *sections;
80*d3833a70SHari Bathini 	const __be32 *token;
81*d3833a70SHari Bathini 
82*d3833a70SHari Bathini 	/*
83*d3833a70SHari Bathini 	 * Check if Firmware Assisted dump is supported. if yes, check
84*d3833a70SHari Bathini 	 * if dump has been initiated on last reboot.
85*d3833a70SHari Bathini 	 */
86*d3833a70SHari Bathini 	token = of_get_flat_dt_prop(node, "ibm,configure-kernel-dump", NULL);
87*d3833a70SHari Bathini 	if (!token)
88*d3833a70SHari Bathini 		return;
89*d3833a70SHari Bathini 
90*d3833a70SHari Bathini 	fadump_conf->ibm_configure_kernel_dump = be32_to_cpu(*token);
91*d3833a70SHari Bathini 	fadump_conf->ops		= &rtas_fadump_ops;
92*d3833a70SHari Bathini 	fadump_conf->fadump_supported	= 1;
93*d3833a70SHari Bathini 
94*d3833a70SHari Bathini 	/* Get the sizes required to store dump data for the firmware provided
95*d3833a70SHari Bathini 	 * dump sections.
96*d3833a70SHari Bathini 	 * For each dump section type supported, a 32bit cell which defines
97*d3833a70SHari Bathini 	 * the ID of a supported section followed by two 32 bit cells which
98*d3833a70SHari Bathini 	 * gives the size of the section in bytes.
99*d3833a70SHari Bathini 	 */
100*d3833a70SHari Bathini 	sections = of_get_flat_dt_prop(node, "ibm,configure-kernel-dump-sizes",
101*d3833a70SHari Bathini 					&size);
102*d3833a70SHari Bathini 
103*d3833a70SHari Bathini 	if (!sections)
104*d3833a70SHari Bathini 		return;
105*d3833a70SHari Bathini 
106*d3833a70SHari Bathini 	num_sections = size / (3 * sizeof(u32));
107*d3833a70SHari Bathini 
108*d3833a70SHari Bathini 	for (i = 0; i < num_sections; i++, sections += 3) {
109*d3833a70SHari Bathini 		u32 type = (u32)of_read_number(sections, 1);
110*d3833a70SHari Bathini 
111*d3833a70SHari Bathini 		switch (type) {
112*d3833a70SHari Bathini 		case RTAS_FADUMP_CPU_STATE_DATA:
113*d3833a70SHari Bathini 			fadump_conf->cpu_state_data_size =
114*d3833a70SHari Bathini 					of_read_ulong(&sections[1], 2);
115*d3833a70SHari Bathini 			break;
116*d3833a70SHari Bathini 		case RTAS_FADUMP_HPTE_REGION:
117*d3833a70SHari Bathini 			fadump_conf->hpte_region_size =
118*d3833a70SHari Bathini 					of_read_ulong(&sections[1], 2);
119*d3833a70SHari Bathini 			break;
120*d3833a70SHari Bathini 		}
121*d3833a70SHari Bathini 	}
122*d3833a70SHari Bathini }
123