1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Firmware-Assisted Dump support on POWER platform (OPAL).
4  *
5  * Copyright 2019, Hari Bathini, IBM Corporation.
6  */
7 
8 #define pr_fmt(fmt) "opal fadump: " fmt
9 
10 #include <linux/string.h>
11 #include <linux/seq_file.h>
12 #include <linux/of_fdt.h>
13 #include <linux/libfdt.h>
14 #include <linux/mm.h>
15 #include <linux/crash_dump.h>
16 
17 #include <asm/page.h>
18 #include <asm/opal.h>
19 #include <asm/fadump-internal.h>
20 
21 #include "opal-fadump.h"
22 
23 static const struct opal_fadump_mem_struct *opal_fdm_active;
24 static const struct opal_mpipl_fadump *opal_cpu_metadata;
25 static struct opal_fadump_mem_struct *opal_fdm;
26 
27 static int opal_fadump_unregister(struct fw_dump *fadump_conf);
28 
29 static void opal_fadump_update_config(struct fw_dump *fadump_conf,
30 				      const struct opal_fadump_mem_struct *fdm)
31 {
32 	pr_debug("Boot memory regions count: %d\n", fdm->region_cnt);
33 
34 	/*
35 	 * The destination address of the first boot memory region is the
36 	 * destination address of boot memory regions.
37 	 */
38 	fadump_conf->boot_mem_dest_addr = fdm->rgn[0].dest;
39 	pr_debug("Destination address of boot memory regions: %#016llx\n",
40 		 fadump_conf->boot_mem_dest_addr);
41 
42 	fadump_conf->fadumphdr_addr = fdm->fadumphdr_addr;
43 }
44 
45 /*
46  * This function is called in the capture kernel to get configuration details
47  * from metadata setup by the first kernel.
48  */
49 static void opal_fadump_get_config(struct fw_dump *fadump_conf,
50 				   const struct opal_fadump_mem_struct *fdm)
51 {
52 	int i;
53 
54 	if (!fadump_conf->dump_active)
55 		return;
56 
57 	fadump_conf->boot_memory_size = 0;
58 
59 	pr_debug("Boot memory regions:\n");
60 	for (i = 0; i < fdm->region_cnt; i++) {
61 		pr_debug("\t%d. base: 0x%llx, size: 0x%llx\n",
62 			 (i + 1), fdm->rgn[i].src, fdm->rgn[i].size);
63 
64 		fadump_conf->boot_memory_size += fdm->rgn[i].size;
65 	}
66 
67 	/*
68 	 * Start address of reserve dump area (permanent reservation) for
69 	 * re-registering FADump after dump capture.
70 	 */
71 	fadump_conf->reserve_dump_area_start = fdm->rgn[0].dest;
72 
73 	/*
74 	 * Rarely, but it can so happen that system crashes before all
75 	 * boot memory regions are registered for MPIPL. In such
76 	 * cases, warn that the vmcore may not be accurate and proceed
77 	 * anyway as that is the best bet considering free pages, cache
78 	 * pages, user pages, etc are usually filtered out.
79 	 *
80 	 * Hope the memory that could not be preserved only has pages
81 	 * that are usually filtered out while saving the vmcore.
82 	 */
83 	if (fdm->region_cnt > fdm->registered_regions) {
84 		pr_warn("Not all memory regions were saved!!!\n");
85 		pr_warn("  Unsaved memory regions:\n");
86 		i = fdm->registered_regions;
87 		while (i < fdm->region_cnt) {
88 			pr_warn("\t[%03d] base: 0x%llx, size: 0x%llx\n",
89 				i, fdm->rgn[i].src, fdm->rgn[i].size);
90 			i++;
91 		}
92 
93 		pr_warn("If the unsaved regions only contain pages that are filtered out (eg. free/user pages), the vmcore should still be usable.\n");
94 		pr_warn("WARNING: If the unsaved regions contain kernel pages, the vmcore will be corrupted.\n");
95 	}
96 
97 	opal_fadump_update_config(fadump_conf, fdm);
98 }
99 
100 /* Initialize kernel metadata */
101 static void opal_fadump_init_metadata(struct opal_fadump_mem_struct *fdm)
102 {
103 	fdm->version = OPAL_FADUMP_VERSION;
104 	fdm->region_cnt = 0;
105 	fdm->registered_regions = 0;
106 	fdm->fadumphdr_addr = 0;
107 }
108 
109 static u64 opal_fadump_init_mem_struct(struct fw_dump *fadump_conf)
110 {
111 	int max_copy_size, cur_size, size;
112 	u64 src_addr, dest_addr;
113 
114 	opal_fdm = __va(fadump_conf->kernel_metadata);
115 	opal_fadump_init_metadata(opal_fdm);
116 
117 	/*
118 	 * Firmware supports 32-bit field for size. Align it to PAGE_SIZE
119 	 * and request firmware to copy multiple kernel boot memory regions.
120 	 */
121 	max_copy_size = _ALIGN_DOWN(U32_MAX, PAGE_SIZE);
122 
123 	/* Boot memory regions */
124 	src_addr = 0;
125 	dest_addr = fadump_conf->reserve_dump_area_start;
126 	size = fadump_conf->boot_memory_size;
127 	while (size) {
128 		cur_size = size > max_copy_size ? max_copy_size : size;
129 
130 		opal_fdm->rgn[opal_fdm->region_cnt].src  = src_addr;
131 		opal_fdm->rgn[opal_fdm->region_cnt].dest = dest_addr;
132 		opal_fdm->rgn[opal_fdm->region_cnt].size = cur_size;
133 
134 		opal_fdm->region_cnt++;
135 		dest_addr	+= cur_size;
136 		src_addr	+= cur_size;
137 		size		-= cur_size;
138 	}
139 
140 	/*
141 	 * Kernel metadata is passed to f/w and retrieved in capture kerenl.
142 	 * So, use it to save fadump header address instead of calculating it.
143 	 */
144 	opal_fdm->fadumphdr_addr = (opal_fdm->rgn[0].dest +
145 				    fadump_conf->boot_memory_size);
146 
147 	opal_fadump_update_config(fadump_conf, opal_fdm);
148 
149 	return dest_addr;
150 }
151 
152 static u64 opal_fadump_get_metadata_size(void)
153 {
154 	return PAGE_ALIGN(sizeof(struct opal_fadump_mem_struct));
155 }
156 
157 static int opal_fadump_setup_metadata(struct fw_dump *fadump_conf)
158 {
159 	int err = 0;
160 	s64 ret;
161 
162 	/*
163 	 * Use the last page(s) in FADump memory reservation for
164 	 * kernel metadata.
165 	 */
166 	fadump_conf->kernel_metadata = (fadump_conf->reserve_dump_area_start +
167 					fadump_conf->reserve_dump_area_size -
168 					opal_fadump_get_metadata_size());
169 	pr_info("Kernel metadata addr: %llx\n", fadump_conf->kernel_metadata);
170 
171 	/* Initialize kernel metadata before registering the address with f/w */
172 	opal_fdm = __va(fadump_conf->kernel_metadata);
173 	opal_fadump_init_metadata(opal_fdm);
174 
175 	/*
176 	 * Register metadata address with f/w. Can be retrieved in
177 	 * the capture kernel.
178 	 */
179 	ret = opal_mpipl_register_tag(OPAL_MPIPL_TAG_KERNEL,
180 				      fadump_conf->kernel_metadata);
181 	if (ret != OPAL_SUCCESS) {
182 		pr_err("Failed to set kernel metadata tag!\n");
183 		err = -EPERM;
184 	}
185 
186 	return err;
187 }
188 
189 static int opal_fadump_register(struct fw_dump *fadump_conf)
190 {
191 	s64 rc = OPAL_PARAMETER;
192 	int i, err = -EIO;
193 
194 	for (i = 0; i < opal_fdm->region_cnt; i++) {
195 		rc = opal_mpipl_update(OPAL_MPIPL_ADD_RANGE,
196 				       opal_fdm->rgn[i].src,
197 				       opal_fdm->rgn[i].dest,
198 				       opal_fdm->rgn[i].size);
199 		if (rc != OPAL_SUCCESS)
200 			break;
201 
202 		opal_fdm->registered_regions++;
203 	}
204 
205 	switch (rc) {
206 	case OPAL_SUCCESS:
207 		pr_info("Registration is successful!\n");
208 		fadump_conf->dump_registered = 1;
209 		err = 0;
210 		break;
211 	case OPAL_RESOURCE:
212 		/* If MAX regions limit in f/w is hit, warn and proceed. */
213 		pr_warn("%d regions could not be registered for MPIPL as MAX limit is reached!\n",
214 			(opal_fdm->region_cnt - opal_fdm->registered_regions));
215 		fadump_conf->dump_registered = 1;
216 		err = 0;
217 		break;
218 	case OPAL_PARAMETER:
219 		pr_err("Failed to register. Parameter Error(%lld).\n", rc);
220 		break;
221 	case OPAL_HARDWARE:
222 		pr_err("Support not available.\n");
223 		fadump_conf->fadump_supported = 0;
224 		fadump_conf->fadump_enabled = 0;
225 		break;
226 	default:
227 		pr_err("Failed to register. Unknown Error(%lld).\n", rc);
228 		break;
229 	}
230 
231 	/*
232 	 * If some regions were registered before OPAL_MPIPL_ADD_RANGE
233 	 * OPAL call failed, unregister all regions.
234 	 */
235 	if ((err < 0) && (opal_fdm->registered_regions > 0))
236 		opal_fadump_unregister(fadump_conf);
237 
238 	return err;
239 }
240 
241 static int opal_fadump_unregister(struct fw_dump *fadump_conf)
242 {
243 	s64 rc;
244 
245 	rc = opal_mpipl_update(OPAL_MPIPL_REMOVE_ALL, 0, 0, 0);
246 	if (rc) {
247 		pr_err("Failed to un-register - unexpected Error(%lld).\n", rc);
248 		return -EIO;
249 	}
250 
251 	opal_fdm->registered_regions = 0;
252 	fadump_conf->dump_registered = 0;
253 	return 0;
254 }
255 
256 static int opal_fadump_invalidate(struct fw_dump *fadump_conf)
257 {
258 	s64 rc;
259 
260 	rc = opal_mpipl_update(OPAL_MPIPL_FREE_PRESERVED_MEMORY, 0, 0, 0);
261 	if (rc) {
262 		pr_err("Failed to invalidate - unexpected Error(%lld).\n", rc);
263 		return -EIO;
264 	}
265 
266 	fadump_conf->dump_active = 0;
267 	opal_fdm_active = NULL;
268 	return 0;
269 }
270 
271 static void opal_fadump_cleanup(struct fw_dump *fadump_conf)
272 {
273 	s64 ret;
274 
275 	ret = opal_mpipl_register_tag(OPAL_MPIPL_TAG_KERNEL, 0);
276 	if (ret != OPAL_SUCCESS)
277 		pr_warn("Could not reset (%llu) kernel metadata tag!\n", ret);
278 }
279 
280 static inline void opal_fadump_set_regval_regnum(struct pt_regs *regs,
281 						 u32 reg_type, u32 reg_num,
282 						 u64 reg_val)
283 {
284 	if (reg_type == HDAT_FADUMP_REG_TYPE_GPR) {
285 		if (reg_num < 32)
286 			regs->gpr[reg_num] = reg_val;
287 		return;
288 	}
289 
290 	switch (reg_num) {
291 	case SPRN_CTR:
292 		regs->ctr = reg_val;
293 		break;
294 	case SPRN_LR:
295 		regs->link = reg_val;
296 		break;
297 	case SPRN_XER:
298 		regs->xer = reg_val;
299 		break;
300 	case SPRN_DAR:
301 		regs->dar = reg_val;
302 		break;
303 	case SPRN_DSISR:
304 		regs->dsisr = reg_val;
305 		break;
306 	case HDAT_FADUMP_REG_ID_NIP:
307 		regs->nip = reg_val;
308 		break;
309 	case HDAT_FADUMP_REG_ID_MSR:
310 		regs->msr = reg_val;
311 		break;
312 	case HDAT_FADUMP_REG_ID_CCR:
313 		regs->ccr = reg_val;
314 		break;
315 	}
316 }
317 
318 static inline void opal_fadump_read_regs(char *bufp, unsigned int regs_cnt,
319 					 unsigned int reg_entry_size,
320 					 struct pt_regs *regs)
321 {
322 	struct hdat_fadump_reg_entry *reg_entry;
323 	int i;
324 
325 	memset(regs, 0, sizeof(struct pt_regs));
326 
327 	for (i = 0; i < regs_cnt; i++, bufp += reg_entry_size) {
328 		reg_entry = (struct hdat_fadump_reg_entry *)bufp;
329 		opal_fadump_set_regval_regnum(regs,
330 					      be32_to_cpu(reg_entry->reg_type),
331 					      be32_to_cpu(reg_entry->reg_num),
332 					      be64_to_cpu(reg_entry->reg_val));
333 	}
334 }
335 
336 /*
337  * Verify if CPU state data is available. If available, do a bit of sanity
338  * checking before processing this data.
339  */
340 static bool __init is_opal_fadump_cpu_data_valid(struct fw_dump *fadump_conf)
341 {
342 	if (!opal_cpu_metadata)
343 		return false;
344 
345 	fadump_conf->cpu_state_data_version =
346 		be32_to_cpu(opal_cpu_metadata->cpu_data_version);
347 	fadump_conf->cpu_state_entry_size =
348 		be32_to_cpu(opal_cpu_metadata->cpu_data_size);
349 	fadump_conf->cpu_state_dest_vaddr =
350 		(u64)__va(be64_to_cpu(opal_cpu_metadata->region[0].dest));
351 	fadump_conf->cpu_state_data_size =
352 		be64_to_cpu(opal_cpu_metadata->region[0].size);
353 
354 	if (fadump_conf->cpu_state_data_version != HDAT_FADUMP_CPU_DATA_VER) {
355 		pr_warn("Supported CPU state data version: %u, found: %d!\n",
356 			HDAT_FADUMP_CPU_DATA_VER,
357 			fadump_conf->cpu_state_data_version);
358 		pr_warn("WARNING: F/W using newer CPU state data format!!\n");
359 	}
360 
361 	if ((fadump_conf->cpu_state_dest_vaddr == 0) ||
362 	    (fadump_conf->cpu_state_entry_size == 0) ||
363 	    (fadump_conf->cpu_state_entry_size >
364 	     fadump_conf->cpu_state_data_size)) {
365 		pr_err("CPU state data is invalid. Ignoring!\n");
366 		return false;
367 	}
368 
369 	return true;
370 }
371 
372 /*
373  * Convert CPU state data saved at the time of crash into ELF notes.
374  *
375  * While the crashing CPU's register data is saved by the kernel, CPU state
376  * data for all CPUs is saved by f/w. In CPU state data provided by f/w,
377  * each register entry is of 16 bytes, a numerical identifier along with
378  * a GPR/SPR flag in the first 8 bytes and the register value in the next
379  * 8 bytes. For more details refer to F/W documentation. If this data is
380  * missing or in unsupported format, append crashing CPU's register data
381  * saved by the kernel in the PT_NOTE, to have something to work with in
382  * the vmcore file.
383  */
384 static int __init
385 opal_fadump_build_cpu_notes(struct fw_dump *fadump_conf,
386 			    struct fadump_crash_info_header *fdh)
387 {
388 	u32 thread_pir, size_per_thread, regs_offset, regs_cnt, reg_esize;
389 	struct hdat_fadump_thread_hdr *thdr;
390 	bool is_cpu_data_valid = false;
391 	u32 num_cpus = 1, *note_buf;
392 	struct pt_regs regs;
393 	char *bufp;
394 	int rc, i;
395 
396 	if (is_opal_fadump_cpu_data_valid(fadump_conf)) {
397 		size_per_thread = fadump_conf->cpu_state_entry_size;
398 		num_cpus = (fadump_conf->cpu_state_data_size / size_per_thread);
399 		bufp = __va(fadump_conf->cpu_state_dest_vaddr);
400 		is_cpu_data_valid = true;
401 	}
402 
403 	rc = fadump_setup_cpu_notes_buf(num_cpus);
404 	if (rc != 0)
405 		return rc;
406 
407 	note_buf = (u32 *)fadump_conf->cpu_notes_buf_vaddr;
408 	if (!is_cpu_data_valid)
409 		goto out;
410 
411 	/*
412 	 * Offset for register entries, entry size and registers count is
413 	 * duplicated in every thread header in keeping with HDAT format.
414 	 * Use these values from the first thread header.
415 	 */
416 	thdr = (struct hdat_fadump_thread_hdr *)bufp;
417 	regs_offset = (offsetof(struct hdat_fadump_thread_hdr, offset) +
418 		       be32_to_cpu(thdr->offset));
419 	reg_esize = be32_to_cpu(thdr->esize);
420 	regs_cnt  = be32_to_cpu(thdr->ecnt);
421 
422 	pr_debug("--------CPU State Data------------\n");
423 	pr_debug("NumCpus     : %u\n", num_cpus);
424 	pr_debug("\tOffset: %u, Entry size: %u, Cnt: %u\n",
425 		 regs_offset, reg_esize, regs_cnt);
426 
427 	for (i = 0; i < num_cpus; i++, bufp += size_per_thread) {
428 		thdr = (struct hdat_fadump_thread_hdr *)bufp;
429 
430 		thread_pir = be32_to_cpu(thdr->pir);
431 		pr_debug("[%04d] PIR: 0x%x, core state: 0x%02x\n",
432 			 i, thread_pir, thdr->core_state);
433 
434 		/*
435 		 * If this is kernel initiated crash, crashing_cpu would be set
436 		 * appropriately and register data of the crashing CPU saved by
437 		 * crashing kernel. Add this saved register data of crashing CPU
438 		 * to elf notes and populate the pt_regs for the remaining CPUs
439 		 * from register state data provided by firmware.
440 		 */
441 		if (fdh->crashing_cpu == thread_pir) {
442 			note_buf = fadump_regs_to_elf_notes(note_buf,
443 							    &fdh->regs);
444 			pr_debug("Crashing CPU PIR: 0x%x - R1 : 0x%lx, NIP : 0x%lx\n",
445 				 fdh->crashing_cpu, fdh->regs.gpr[1],
446 				 fdh->regs.nip);
447 			continue;
448 		}
449 
450 		/*
451 		 * Register state data of MAX cores is provided by firmware,
452 		 * but some of this cores may not be active. So, while
453 		 * processing register state data, check core state and
454 		 * skip threads that belong to inactive cores.
455 		 */
456 		if (thdr->core_state == HDAT_FADUMP_CORE_INACTIVE)
457 			continue;
458 
459 		opal_fadump_read_regs((bufp + regs_offset), regs_cnt,
460 				      reg_esize, &regs);
461 		note_buf = fadump_regs_to_elf_notes(note_buf, &regs);
462 		pr_debug("CPU PIR: 0x%x - R1 : 0x%lx, NIP : 0x%lx\n",
463 			 thread_pir, regs.gpr[1], regs.nip);
464 	}
465 
466 out:
467 	/*
468 	 * CPU state data is invalid/unsupported. Try appending crashing CPU's
469 	 * register data, if it is saved by the kernel.
470 	 */
471 	if (fadump_conf->cpu_notes_buf_vaddr == (u64)note_buf) {
472 		if (fdh->crashing_cpu == FADUMP_CPU_UNKNOWN) {
473 			fadump_free_cpu_notes_buf();
474 			return -ENODEV;
475 		}
476 
477 		pr_warn("WARNING: appending only crashing CPU's register data\n");
478 		note_buf = fadump_regs_to_elf_notes(note_buf, &(fdh->regs));
479 	}
480 
481 	final_note(note_buf);
482 
483 	pr_debug("Updating elfcore header (%llx) with cpu notes\n",
484 		 fdh->elfcorehdr_addr);
485 	fadump_update_elfcore_header(__va(fdh->elfcorehdr_addr));
486 	return 0;
487 }
488 
489 static int __init opal_fadump_process(struct fw_dump *fadump_conf)
490 {
491 	struct fadump_crash_info_header *fdh;
492 	int rc = -EINVAL;
493 
494 	if (!opal_fdm_active || !fadump_conf->fadumphdr_addr)
495 		return rc;
496 
497 	/* Validate the fadump crash info header */
498 	fdh = __va(fadump_conf->fadumphdr_addr);
499 	if (fdh->magic_number != FADUMP_CRASH_INFO_MAGIC) {
500 		pr_err("Crash info header is not valid.\n");
501 		return rc;
502 	}
503 
504 	rc = opal_fadump_build_cpu_notes(fadump_conf, fdh);
505 	if (rc)
506 		return rc;
507 
508 	/*
509 	 * We are done validating dump info and elfcore header is now ready
510 	 * to be exported. set elfcorehdr_addr so that vmcore module will
511 	 * export the elfcore header through '/proc/vmcore'.
512 	 */
513 	elfcorehdr_addr = fdh->elfcorehdr_addr;
514 
515 	return rc;
516 }
517 
518 static void opal_fadump_region_show(struct fw_dump *fadump_conf,
519 				    struct seq_file *m)
520 {
521 	const struct opal_fadump_mem_struct *fdm_ptr;
522 	u64 dumped_bytes = 0;
523 	int i;
524 
525 	if (fadump_conf->dump_active)
526 		fdm_ptr = opal_fdm_active;
527 	else
528 		fdm_ptr = opal_fdm;
529 
530 	for (i = 0; i < fdm_ptr->region_cnt; i++) {
531 		/*
532 		 * Only regions that are registered for MPIPL
533 		 * would have dump data.
534 		 */
535 		if ((fadump_conf->dump_active) &&
536 		    (i < fdm_ptr->registered_regions))
537 			dumped_bytes = fdm_ptr->rgn[i].size;
538 
539 		seq_printf(m, "DUMP: Src: %#016llx, Dest: %#016llx, ",
540 			   fdm_ptr->rgn[i].src, fdm_ptr->rgn[i].dest);
541 		seq_printf(m, "Size: %#llx, Dumped: %#llx bytes\n",
542 			   fdm_ptr->rgn[i].size, dumped_bytes);
543 	}
544 
545 	/* Dump is active. Show reserved area start address. */
546 	if (fadump_conf->dump_active) {
547 		seq_printf(m, "\nMemory above %#016lx is reserved for saving crash dump\n",
548 			   fadump_conf->reserve_dump_area_start);
549 	}
550 }
551 
552 static void opal_fadump_trigger(struct fadump_crash_info_header *fdh,
553 				const char *msg)
554 {
555 	int rc;
556 
557 	/*
558 	 * Unlike on pSeries platform, logical CPU number is not provided
559 	 * with architected register state data. So, store the crashing
560 	 * CPU's PIR instead to plug the appropriate register data for
561 	 * crashing CPU in the vmcore file.
562 	 */
563 	fdh->crashing_cpu = (u32)mfspr(SPRN_PIR);
564 
565 	rc = opal_cec_reboot2(OPAL_REBOOT_MPIPL, msg);
566 	if (rc == OPAL_UNSUPPORTED) {
567 		pr_emerg("Reboot type %d not supported.\n",
568 			 OPAL_REBOOT_MPIPL);
569 	} else if (rc == OPAL_HARDWARE)
570 		pr_emerg("No backend support for MPIPL!\n");
571 }
572 
573 static struct fadump_ops opal_fadump_ops = {
574 	.fadump_init_mem_struct		= opal_fadump_init_mem_struct,
575 	.fadump_get_metadata_size	= opal_fadump_get_metadata_size,
576 	.fadump_setup_metadata		= opal_fadump_setup_metadata,
577 	.fadump_register		= opal_fadump_register,
578 	.fadump_unregister		= opal_fadump_unregister,
579 	.fadump_invalidate		= opal_fadump_invalidate,
580 	.fadump_cleanup			= opal_fadump_cleanup,
581 	.fadump_process			= opal_fadump_process,
582 	.fadump_region_show		= opal_fadump_region_show,
583 	.fadump_trigger			= opal_fadump_trigger,
584 };
585 
586 void __init opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
587 {
588 	const __be32 *prop;
589 	unsigned long dn;
590 	u64 addr = 0;
591 	s64 ret;
592 
593 
594 	/*
595 	 * Check if Firmware-Assisted Dump is supported. if yes, check
596 	 * if dump has been initiated on last reboot.
597 	 */
598 	dn = of_get_flat_dt_subnode_by_name(node, "dump");
599 	if (dn == -FDT_ERR_NOTFOUND) {
600 		pr_debug("FADump support is missing!\n");
601 		return;
602 	}
603 
604 	if (!of_flat_dt_is_compatible(dn, "ibm,opal-dump")) {
605 		pr_err("Support missing for this f/w version!\n");
606 		return;
607 	}
608 
609 	fadump_conf->ops		= &opal_fadump_ops;
610 	fadump_conf->fadump_supported	= 1;
611 
612 	/*
613 	 * Check if dump has been initiated on last reboot.
614 	 */
615 	prop = of_get_flat_dt_prop(dn, "mpipl-boot", NULL);
616 	if (!prop)
617 		return;
618 
619 	ret = opal_mpipl_query_tag(OPAL_MPIPL_TAG_KERNEL, &addr);
620 	if ((ret != OPAL_SUCCESS) || !addr) {
621 		pr_err("Failed to get Kernel metadata (%lld)\n", ret);
622 		return;
623 	}
624 
625 	addr = be64_to_cpu(addr);
626 	pr_debug("Kernel metadata addr: %llx\n", addr);
627 
628 	opal_fdm_active = __va(addr);
629 	if (opal_fdm_active->version != OPAL_FADUMP_VERSION) {
630 		pr_warn("Supported kernel metadata version: %u, found: %d!\n",
631 			OPAL_FADUMP_VERSION, opal_fdm_active->version);
632 		pr_warn("WARNING: Kernel metadata format mismatch identified! Core file maybe corrupted..\n");
633 	}
634 
635 	/* Kernel regions not registered with f/w for MPIPL */
636 	if (opal_fdm_active->registered_regions == 0) {
637 		opal_fdm_active = NULL;
638 		return;
639 	}
640 
641 	ret = opal_mpipl_query_tag(OPAL_MPIPL_TAG_CPU, &addr);
642 	if (addr) {
643 		addr = be64_to_cpu(addr);
644 		pr_debug("CPU metadata addr: %llx\n", addr);
645 		opal_cpu_metadata = __va(addr);
646 	}
647 
648 	pr_info("Firmware-assisted dump is active.\n");
649 	fadump_conf->dump_active = 1;
650 	opal_fadump_get_config(fadump_conf, opal_fdm_active);
651 }
652