2 * Firmware Assisted dump: A robust mechanism to get reliable kernel crash
3 * dump with assistance from firmware. This approach does not use kexec,
4 * instead firmware assists in booting the kdump kernel while preserving
5 * memory contents. The most of the code implementation has been adapted
6 * from phyp assisted dump implementation written by Linas Vepstas and
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Copyright 2011 IBM Corporation
24 * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
28 #define pr_fmt(fmt) "fadump: " fmt
30 #include <linux/string.h>
31 #include <linux/memblock.h>
32 #include <linux/delay.h>
33 #include <linux/seq_file.h>
34 #include <linux/crash_dump.h>
35 #include <linux/kobject.h>
36 #include <linux/sysfs.h>
37 #include <linux/slab.h>
38 #include <linux/cma.h>
39 #include <linux/hugetlb.h>
41 #include <asm/debugfs.h>
45 #include <asm/fadump.h>
46 #include <asm/setup.h>
48 static struct fw_dump fw_dump
;
49 static struct fadump_mem_struct fdm
;
50 static const struct fadump_mem_struct
*fdm_active
;
52 static struct cma
*fadump_cma
;
55 static DEFINE_MUTEX(fadump_mutex
);
56 struct fad_crash_memory_ranges
*crash_memory_ranges
;
57 int crash_memory_ranges_size
;
59 int max_crash_mem_ranges
;
63 * fadump_cma_init() - Initialize CMA area from a fadump reserved memory
65 * This function initializes CMA area from fadump reserved memory.
66 * The total size of fadump reserved memory covers for boot memory size
67 * + cpu data size + hpte size and metadata.
68 * Initialize only the area equivalent to boot memory size for CMA use.
69 * The reamining portion of fadump reserved memory will be not given
70 * to CMA and pages for thoes will stay reserved. boot memory size is
71 * aligned per CMA requirement to satisy cma_init_reserved_mem() call.
72 * But for some reason even if it fails we still have the memory reservation
73 * with us and we can still continue doing fadump.
75 int __init
fadump_cma_init(void)
77 unsigned long long base
, size
;
80 if (!fw_dump
.fadump_enabled
)
84 * Do not use CMA if user has provided fadump=nocma kernel parameter.
85 * Return 1 to continue with fadump old behaviour.
90 base
= fw_dump
.reserve_dump_area_start
;
91 size
= fw_dump
.boot_memory_size
;
96 rc
= cma_init_reserved_mem(base
, size
, 0, "fadump_cma", &fadump_cma
);
98 pr_err("Failed to init cma area for firmware-assisted dump,%d\n", rc
);
100 * Though the CMA init has failed we still have memory
101 * reservation with us. The reserved memory will be
102 * blocked from production system usage. Hence return 1,
103 * so that we can continue with fadump.
109 * So we now have successfully initialized cma area for fadump.
111 pr_info("Initialized 0x%lx bytes cma area at %ldMB from 0x%lx "
112 "bytes of memory reserved for firmware-assisted dump\n",
113 cma_get_size(fadump_cma
),
114 (unsigned long)cma_get_base(fadump_cma
) >> 20,
115 fw_dump
.reserve_dump_area_size
);
119 static int __init
fadump_cma_init(void) { return 1; }
120 #endif /* CONFIG_CMA */
122 /* Scan the Firmware Assisted dump configuration details. */
123 int __init
early_init_dt_scan_fw_dump(unsigned long node
,
124 const char *uname
, int depth
, void *data
)
126 const __be32
*sections
;
131 if (depth
!= 1 || strcmp(uname
, "rtas") != 0)
135 * Check if Firmware Assisted dump is supported. if yes, check
136 * if dump has been initiated on last reboot.
138 token
= of_get_flat_dt_prop(node
, "ibm,configure-kernel-dump", NULL
);
142 fw_dump
.fadump_supported
= 1;
143 fw_dump
.ibm_configure_kernel_dump
= be32_to_cpu(*token
);
146 * The 'ibm,kernel-dump' rtas node is present only if there is
147 * dump data waiting for us.
149 fdm_active
= of_get_flat_dt_prop(node
, "ibm,kernel-dump", NULL
);
151 fw_dump
.dump_active
= 1;
153 /* Get the sizes required to store dump data for the firmware provided
155 * For each dump section type supported, a 32bit cell which defines
156 * the ID of a supported section followed by two 32 bit cells which
157 * gives teh size of the section in bytes.
159 sections
= of_get_flat_dt_prop(node
, "ibm,configure-kernel-dump-sizes",
165 num_sections
= size
/ (3 * sizeof(u32
));
167 for (i
= 0; i
< num_sections
; i
++, sections
+= 3) {
168 u32 type
= (u32
)of_read_number(sections
, 1);
171 case FADUMP_CPU_STATE_DATA
:
172 fw_dump
.cpu_state_data_size
=
173 of_read_ulong(§ions
[1], 2);
175 case FADUMP_HPTE_REGION
:
176 fw_dump
.hpte_region_size
=
177 of_read_ulong(§ions
[1], 2);
186 * If fadump is registered, check if the memory provided
187 * falls within boot memory area and reserved memory area.
189 int is_fadump_memory_area(u64 addr
, ulong size
)
191 u64 d_start
= fw_dump
.reserve_dump_area_start
;
192 u64 d_end
= d_start
+ fw_dump
.reserve_dump_area_size
;
194 if (!fw_dump
.dump_registered
)
197 if (((addr
+ size
) > d_start
) && (addr
<= d_end
))
200 return (addr
+ size
) > RMA_START
&& addr
<= fw_dump
.boot_memory_size
;
203 int should_fadump_crash(void)
205 if (!fw_dump
.dump_registered
|| !fw_dump
.fadumphdr_addr
)
210 int is_fadump_active(void)
212 return fw_dump
.dump_active
;
216 * Returns 1, if there are no holes in boot memory area,
219 static int is_boot_memory_area_contiguous(void)
221 struct memblock_region
*reg
;
222 unsigned long tstart
, tend
;
223 unsigned long start_pfn
= PHYS_PFN(RMA_START
);
224 unsigned long end_pfn
= PHYS_PFN(RMA_START
+ fw_dump
.boot_memory_size
);
225 unsigned int ret
= 0;
227 for_each_memblock(memory
, reg
) {
228 tstart
= max(start_pfn
, memblock_region_memory_base_pfn(reg
));
229 tend
= min(end_pfn
, memblock_region_memory_end_pfn(reg
));
231 /* Memory hole from start_pfn to tstart */
232 if (tstart
> start_pfn
)
235 if (tend
== end_pfn
) {
240 start_pfn
= tend
+ 1;
248 * Returns true, if there are no holes in reserved memory area,
251 static bool is_reserved_memory_area_contiguous(void)
253 struct memblock_region
*reg
;
254 unsigned long start
, end
;
255 unsigned long d_start
= fw_dump
.reserve_dump_area_start
;
256 unsigned long d_end
= d_start
+ fw_dump
.reserve_dump_area_size
;
258 for_each_memblock(memory
, reg
) {
259 start
= max(d_start
, (unsigned long)reg
->base
);
260 end
= min(d_end
, (unsigned long)(reg
->base
+ reg
->size
));
262 /* Memory hole from d_start to start */
276 /* Print firmware assisted dump configurations for debugging purpose. */
277 static void fadump_show_config(void)
279 pr_debug("Support for firmware-assisted dump (fadump): %s\n",
280 (fw_dump
.fadump_supported
? "present" : "no support"));
282 if (!fw_dump
.fadump_supported
)
285 pr_debug("Fadump enabled : %s\n",
286 (fw_dump
.fadump_enabled
? "yes" : "no"));
287 pr_debug("Dump Active : %s\n",
288 (fw_dump
.dump_active
? "yes" : "no"));
289 pr_debug("Dump section sizes:\n");
290 pr_debug(" CPU state data size: %lx\n", fw_dump
.cpu_state_data_size
);
291 pr_debug(" HPTE region size : %lx\n", fw_dump
.hpte_region_size
);
292 pr_debug("Boot memory size : %lx\n", fw_dump
.boot_memory_size
);
295 static unsigned long init_fadump_mem_struct(struct fadump_mem_struct
*fdm
,
301 memset(fdm
, 0, sizeof(struct fadump_mem_struct
));
302 addr
= addr
& PAGE_MASK
;
304 fdm
->header
.dump_format_version
= cpu_to_be32(0x00000001);
305 fdm
->header
.dump_num_sections
= cpu_to_be16(3);
306 fdm
->header
.dump_status_flag
= 0;
307 fdm
->header
.offset_first_dump_section
=
308 cpu_to_be32((u32
)offsetof(struct fadump_mem_struct
, cpu_state_data
));
311 * Fields for disk dump option.
312 * We are not using disk dump option, hence set these fields to 0.
314 fdm
->header
.dd_block_size
= 0;
315 fdm
->header
.dd_block_offset
= 0;
316 fdm
->header
.dd_num_blocks
= 0;
317 fdm
->header
.dd_offset_disk_path
= 0;
319 /* set 0 to disable an automatic dump-reboot. */
320 fdm
->header
.max_time_auto
= 0;
322 /* Kernel dump sections */
323 /* cpu state data section. */
324 fdm
->cpu_state_data
.request_flag
= cpu_to_be32(FADUMP_REQUEST_FLAG
);
325 fdm
->cpu_state_data
.source_data_type
= cpu_to_be16(FADUMP_CPU_STATE_DATA
);
326 fdm
->cpu_state_data
.source_address
= 0;
327 fdm
->cpu_state_data
.source_len
= cpu_to_be64(fw_dump
.cpu_state_data_size
);
328 fdm
->cpu_state_data
.destination_address
= cpu_to_be64(addr
);
329 addr
+= fw_dump
.cpu_state_data_size
;
331 /* hpte region section */
332 fdm
->hpte_region
.request_flag
= cpu_to_be32(FADUMP_REQUEST_FLAG
);
333 fdm
->hpte_region
.source_data_type
= cpu_to_be16(FADUMP_HPTE_REGION
);
334 fdm
->hpte_region
.source_address
= 0;
335 fdm
->hpte_region
.source_len
= cpu_to_be64(fw_dump
.hpte_region_size
);
336 fdm
->hpte_region
.destination_address
= cpu_to_be64(addr
);
337 addr
+= fw_dump
.hpte_region_size
;
339 /* RMA region section */
340 fdm
->rmr_region
.request_flag
= cpu_to_be32(FADUMP_REQUEST_FLAG
);
341 fdm
->rmr_region
.source_data_type
= cpu_to_be16(FADUMP_REAL_MODE_REGION
);
342 fdm
->rmr_region
.source_address
= cpu_to_be64(RMA_START
);
343 fdm
->rmr_region
.source_len
= cpu_to_be64(fw_dump
.boot_memory_size
);
344 fdm
->rmr_region
.destination_address
= cpu_to_be64(addr
);
345 addr
+= fw_dump
.boot_memory_size
;
351 * fadump_calculate_reserve_size(): reserve variable boot area 5% of System RAM
353 * Function to find the largest memory size we need to reserve during early
354 * boot process. This will be the size of the memory that is required for a
355 * kernel to boot successfully.
357 * This function has been taken from phyp-assisted dump feature implementation.
359 * returns larger of 256MB or 5% rounded down to multiples of 256MB.
361 * TODO: Come up with better approach to find out more accurate memory size
362 * that is required for a kernel to boot successfully.
365 static inline unsigned long fadump_calculate_reserve_size(void)
368 unsigned long long base
, size
;
370 if (fw_dump
.reserve_bootvar
)
371 pr_warn("'fadump_reserve_mem=' parameter is deprecated in favor of 'crashkernel=' parameter.\n");
374 * Check if the size is specified through crashkernel= cmdline
375 * option. If yes, then use that but ignore base as fadump reserves
376 * memory at a predefined offset.
378 ret
= parse_crashkernel(boot_command_line
, memblock_phys_mem_size(),
380 if (ret
== 0 && size
> 0) {
381 unsigned long max_size
;
383 if (fw_dump
.reserve_bootvar
)
384 pr_info("Using 'crashkernel=' parameter for memory reservation.\n");
386 fw_dump
.reserve_bootvar
= (unsigned long)size
;
389 * Adjust if the boot memory size specified is above
392 max_size
= memblock_phys_mem_size() / MAX_BOOT_MEM_RATIO
;
393 if (fw_dump
.reserve_bootvar
> max_size
) {
394 fw_dump
.reserve_bootvar
= max_size
;
395 pr_info("Adjusted boot memory size to %luMB\n",
396 (fw_dump
.reserve_bootvar
>> 20));
399 return fw_dump
.reserve_bootvar
;
400 } else if (fw_dump
.reserve_bootvar
) {
402 * 'fadump_reserve_mem=' is being used to reserve memory
403 * for firmware-assisted dump.
405 return fw_dump
.reserve_bootvar
;
408 /* divide by 20 to get 5% of value */
409 size
= memblock_phys_mem_size() / 20;
411 /* round it down in multiples of 256 */
412 size
= size
& ~0x0FFFFFFFUL
;
414 /* Truncate to memory_limit. We don't want to over reserve the memory.*/
415 if (memory_limit
&& size
> memory_limit
)
418 return (size
> MIN_BOOT_MEM
? size
: MIN_BOOT_MEM
);
422 * Calculate the total memory size required to be reserved for
423 * firmware-assisted dump registration.
425 static unsigned long get_fadump_area_size(void)
427 unsigned long size
= 0;
429 size
+= fw_dump
.cpu_state_data_size
;
430 size
+= fw_dump
.hpte_region_size
;
431 size
+= fw_dump
.boot_memory_size
;
432 size
+= sizeof(struct fadump_crash_info_header
);
433 size
+= sizeof(struct elfhdr
); /* ELF core header.*/
434 size
+= sizeof(struct elf_phdr
); /* place holder for cpu notes */
435 /* Program headers for crash memory regions. */
436 size
+= sizeof(struct elf_phdr
) * (memblock_num_regions(memory
) + 2);
438 size
= PAGE_ALIGN(size
);
442 static void __init
fadump_reserve_crash_area(unsigned long base
,
445 struct memblock_region
*reg
;
446 unsigned long mstart
, mend
, msize
;
448 for_each_memblock(memory
, reg
) {
449 mstart
= max_t(unsigned long, base
, reg
->base
);
450 mend
= reg
->base
+ reg
->size
;
451 mend
= min(base
+ size
, mend
);
454 msize
= mend
- mstart
;
455 memblock_reserve(mstart
, msize
);
456 pr_info("Reserved %ldMB of memory at %#016lx for saving crash dump\n",
457 (msize
>> 20), mstart
);
462 int __init
fadump_reserve_mem(void)
464 unsigned long base
, size
, memory_boundary
;
466 if (!fw_dump
.fadump_enabled
)
469 if (!fw_dump
.fadump_supported
) {
470 printk(KERN_INFO
"Firmware-assisted dump is not supported on"
472 fw_dump
.fadump_enabled
= 0;
476 * Initialize boot memory size
477 * If dump is active then we have already calculated the size during
481 fw_dump
.boot_memory_size
= be64_to_cpu(fdm_active
->rmr_region
.source_len
);
483 fw_dump
.boot_memory_size
= fadump_calculate_reserve_size();
486 fw_dump
.boot_memory_size
=
487 ALIGN(fw_dump
.boot_memory_size
,
488 FADUMP_CMA_ALIGNMENT
);
493 * Calculate the memory boundary.
494 * If memory_limit is less than actual memory boundary then reserve
495 * the memory for fadump beyond the memory_limit and adjust the
496 * memory_limit accordingly, so that the running kernel can run with
497 * specified memory_limit.
499 if (memory_limit
&& memory_limit
< memblock_end_of_DRAM()) {
500 size
= get_fadump_area_size();
501 if ((memory_limit
+ size
) < memblock_end_of_DRAM())
502 memory_limit
+= size
;
504 memory_limit
= memblock_end_of_DRAM();
505 printk(KERN_INFO
"Adjusted memory_limit for firmware-assisted"
506 " dump, now %#016llx\n", memory_limit
);
509 memory_boundary
= memory_limit
;
511 memory_boundary
= memblock_end_of_DRAM();
513 if (fw_dump
.dump_active
) {
514 pr_info("Firmware-assisted dump is active.\n");
516 #ifdef CONFIG_HUGETLB_PAGE
518 * FADump capture kernel doesn't care much about hugepages.
519 * In fact, handling hugepages in capture kernel is asking for
520 * trouble. So, disable HugeTLB support when fadump is active.
522 hugetlb_disabled
= true;
525 * If last boot has crashed then reserve all the memory
526 * above boot_memory_size so that we don't touch it until
527 * dump is written to disk by userspace tool. This memory
528 * will be released for general use once the dump is saved.
530 base
= fw_dump
.boot_memory_size
;
531 size
= memory_boundary
- base
;
532 fadump_reserve_crash_area(base
, size
);
534 fw_dump
.fadumphdr_addr
=
535 be64_to_cpu(fdm_active
->rmr_region
.destination_address
) +
536 be64_to_cpu(fdm_active
->rmr_region
.source_len
);
537 pr_debug("fadumphdr_addr = %pa\n", &fw_dump
.fadumphdr_addr
);
538 fw_dump
.reserve_dump_area_start
= base
;
539 fw_dump
.reserve_dump_area_size
= size
;
541 size
= get_fadump_area_size();
544 * Reserve memory at an offset closer to bottom of the RAM to
545 * minimize the impact of memory hot-remove operation. We can't
546 * use memblock_find_in_range() here since it doesn't allocate
547 * from bottom to top.
549 for (base
= fw_dump
.boot_memory_size
;
550 base
<= (memory_boundary
- size
);
552 if (memblock_is_region_memory(base
, size
) &&
553 !memblock_is_region_reserved(base
, size
))
556 if ((base
> (memory_boundary
- size
)) ||
557 memblock_reserve(base
, size
)) {
558 pr_err("Failed to reserve memory\n");
562 pr_info("Reserved %ldMB of memory at %ldMB for firmware-"
563 "assisted dump (System RAM: %ldMB)\n",
564 (unsigned long)(size
>> 20),
565 (unsigned long)(base
>> 20),
566 (unsigned long)(memblock_phys_mem_size() >> 20));
568 fw_dump
.reserve_dump_area_start
= base
;
569 fw_dump
.reserve_dump_area_size
= size
;
570 return fadump_cma_init();
575 unsigned long __init
arch_reserved_kernel_pages(void)
577 return memblock_reserved_size() / PAGE_SIZE
;
580 /* Look for fadump= cmdline option. */
581 static int __init
early_fadump_param(char *p
)
586 if (strncmp(p
, "on", 2) == 0)
587 fw_dump
.fadump_enabled
= 1;
588 else if (strncmp(p
, "off", 3) == 0)
589 fw_dump
.fadump_enabled
= 0;
590 else if (strncmp(p
, "nocma", 5) == 0) {
591 fw_dump
.fadump_enabled
= 1;
597 early_param("fadump", early_fadump_param
);
600 * Look for fadump_reserve_mem= cmdline option
601 * TODO: Remove references to 'fadump_reserve_mem=' parameter,
602 * the sooner 'crashkernel=' parameter is accustomed to.
604 static int __init
early_fadump_reserve_mem(char *p
)
607 fw_dump
.reserve_bootvar
= memparse(p
, &p
);
610 early_param("fadump_reserve_mem", early_fadump_reserve_mem
);
612 static int register_fw_dump(struct fadump_mem_struct
*fdm
)
615 unsigned int wait_time
;
617 pr_debug("Registering for firmware-assisted kernel dump...\n");
619 /* TODO: Add upper time limit for the delay */
621 rc
= rtas_call(fw_dump
.ibm_configure_kernel_dump
, 3, 1, NULL
,
622 FADUMP_REGISTER
, fdm
,
623 sizeof(struct fadump_mem_struct
));
625 wait_time
= rtas_busy_delay_time(rc
);
634 pr_err("Failed to register. Unknown Error(%d).\n", rc
);
637 printk(KERN_ERR
"Failed to register firmware-assisted kernel"
638 " dump. Hardware Error(%d).\n", rc
);
641 if (!is_boot_memory_area_contiguous())
642 pr_err("Can't have holes in boot memory area while registering fadump\n");
643 else if (!is_reserved_memory_area_contiguous())
644 pr_err("Can't have holes in reserved memory area while"
645 " registering fadump\n");
647 printk(KERN_ERR
"Failed to register firmware-assisted kernel"
648 " dump. Parameter Error(%d).\n", rc
);
652 printk(KERN_ERR
"firmware-assisted kernel dump is already "
654 fw_dump
.dump_registered
= 1;
658 printk(KERN_INFO
"firmware-assisted kernel dump registration"
660 fw_dump
.dump_registered
= 1;
667 void crash_fadump(struct pt_regs
*regs
, const char *str
)
669 struct fadump_crash_info_header
*fdh
= NULL
;
670 int old_cpu
, this_cpu
;
672 if (!should_fadump_crash())
676 * old_cpu == -1 means this is the first CPU which has come here,
677 * go ahead and trigger fadump.
679 * old_cpu != -1 means some other CPU has already on it's way
680 * to trigger fadump, just keep looping here.
682 this_cpu
= smp_processor_id();
683 old_cpu
= cmpxchg(&crashing_cpu
, -1, this_cpu
);
687 * We can't loop here indefinitely. Wait as long as fadump
688 * is in force. If we race with fadump un-registration this
689 * loop will break and then we go down to normal panic path
690 * and reboot. If fadump is in force the first crashing
691 * cpu will definitely trigger fadump.
693 while (fw_dump
.dump_registered
)
698 fdh
= __va(fw_dump
.fadumphdr_addr
);
699 fdh
->crashing_cpu
= crashing_cpu
;
700 crash_save_vmcoreinfo();
705 ppc_save_regs(&fdh
->regs
);
707 fdh
->online_mask
= *cpu_online_mask
;
709 /* Call ibm,os-term rtas call to trigger firmware assisted dump */
710 rtas_os_term((char *)str
);
713 #define GPR_MASK 0xffffff0000000000
714 static inline int fadump_gpr_index(u64 id
)
719 if ((id
& GPR_MASK
) == REG_ID("GPR")) {
720 /* get the digits at the end */
725 str
[0] = (id
>> 8) & 0xff;
726 sscanf(str
, "%d", &i
);
733 static inline void fadump_set_regval(struct pt_regs
*regs
, u64 reg_id
,
738 i
= fadump_gpr_index(reg_id
);
740 regs
->gpr
[i
] = (unsigned long)reg_val
;
741 else if (reg_id
== REG_ID("NIA"))
742 regs
->nip
= (unsigned long)reg_val
;
743 else if (reg_id
== REG_ID("MSR"))
744 regs
->msr
= (unsigned long)reg_val
;
745 else if (reg_id
== REG_ID("CTR"))
746 regs
->ctr
= (unsigned long)reg_val
;
747 else if (reg_id
== REG_ID("LR"))
748 regs
->link
= (unsigned long)reg_val
;
749 else if (reg_id
== REG_ID("XER"))
750 regs
->xer
= (unsigned long)reg_val
;
751 else if (reg_id
== REG_ID("CR"))
752 regs
->ccr
= (unsigned long)reg_val
;
753 else if (reg_id
== REG_ID("DAR"))
754 regs
->dar
= (unsigned long)reg_val
;
755 else if (reg_id
== REG_ID("DSISR"))
756 regs
->dsisr
= (unsigned long)reg_val
;
759 static struct fadump_reg_entry
*
760 fadump_read_registers(struct fadump_reg_entry
*reg_entry
, struct pt_regs
*regs
)
762 memset(regs
, 0, sizeof(struct pt_regs
));
764 while (be64_to_cpu(reg_entry
->reg_id
) != REG_ID("CPUEND")) {
765 fadump_set_regval(regs
, be64_to_cpu(reg_entry
->reg_id
),
766 be64_to_cpu(reg_entry
->reg_value
));
773 static u32
*fadump_regs_to_elf_notes(u32
*buf
, struct pt_regs
*regs
)
775 struct elf_prstatus prstatus
;
777 memset(&prstatus
, 0, sizeof(prstatus
));
779 * FIXME: How do i get PID? Do I really need it?
780 * prstatus.pr_pid = ????
782 elf_core_copy_kernel_regs(&prstatus
.pr_reg
, regs
);
783 buf
= append_elf_note(buf
, CRASH_CORE_NOTE_NAME
, NT_PRSTATUS
,
784 &prstatus
, sizeof(prstatus
));
788 static void fadump_update_elfcore_header(char *bufp
)
791 struct elf_phdr
*phdr
;
793 elf
= (struct elfhdr
*)bufp
;
794 bufp
+= sizeof(struct elfhdr
);
796 /* First note is a place holder for cpu notes info. */
797 phdr
= (struct elf_phdr
*)bufp
;
799 if (phdr
->p_type
== PT_NOTE
) {
800 phdr
->p_paddr
= fw_dump
.cpu_notes_buf
;
801 phdr
->p_offset
= phdr
->p_paddr
;
802 phdr
->p_filesz
= fw_dump
.cpu_notes_buf_size
;
803 phdr
->p_memsz
= fw_dump
.cpu_notes_buf_size
;
808 static void *fadump_cpu_notes_buf_alloc(unsigned long size
)
812 unsigned long order
, count
, i
;
814 order
= get_order(size
);
815 vaddr
= (void *)__get_free_pages(GFP_KERNEL
|__GFP_ZERO
, order
);
820 page
= virt_to_page(vaddr
);
821 for (i
= 0; i
< count
; i
++)
822 SetPageReserved(page
+ i
);
826 static void fadump_cpu_notes_buf_free(unsigned long vaddr
, unsigned long size
)
829 unsigned long order
, count
, i
;
831 order
= get_order(size
);
833 page
= virt_to_page(vaddr
);
834 for (i
= 0; i
< count
; i
++)
835 ClearPageReserved(page
+ i
);
836 __free_pages(page
, order
);
840 * Read CPU state dump data and convert it into ELF notes.
841 * The CPU dump starts with magic number "REGSAVE". NumCpusOffset should be
842 * used to access the data to allow for additional fields to be added without
843 * affecting compatibility. Each list of registers for a CPU starts with
844 * "CPUSTRT" and ends with "CPUEND". Each register entry is of 16 bytes,
845 * 8 Byte ASCII identifier and 8 Byte register value. The register entry
846 * with identifier "CPUSTRT" and "CPUEND" contains 4 byte cpu id as part
847 * of register value. For more details refer to PAPR document.
849 * Only for the crashing cpu we ignore the CPU dump data and get exact
850 * state from fadump crash info structure populated by first kernel at the
853 static int __init
fadump_build_cpu_notes(const struct fadump_mem_struct
*fdm
)
855 struct fadump_reg_save_area_header
*reg_header
;
856 struct fadump_reg_entry
*reg_entry
;
857 struct fadump_crash_info_header
*fdh
= NULL
;
860 u32 num_cpus
, *note_buf
;
862 int i
, rc
= 0, cpu
= 0;
864 if (!fdm
->cpu_state_data
.bytes_dumped
)
867 addr
= be64_to_cpu(fdm
->cpu_state_data
.destination_address
);
871 if (be64_to_cpu(reg_header
->magic_number
) != REGSAVE_AREA_MAGIC
) {
872 printk(KERN_ERR
"Unable to read register save area.\n");
875 pr_debug("--------CPU State Data------------\n");
876 pr_debug("Magic Number: %llx\n", be64_to_cpu(reg_header
->magic_number
));
877 pr_debug("NumCpuOffset: %x\n", be32_to_cpu(reg_header
->num_cpu_offset
));
879 vaddr
+= be32_to_cpu(reg_header
->num_cpu_offset
);
880 num_cpus
= be32_to_cpu(*((__be32
*)(vaddr
)));
881 pr_debug("NumCpus : %u\n", num_cpus
);
882 vaddr
+= sizeof(u32
);
883 reg_entry
= (struct fadump_reg_entry
*)vaddr
;
885 /* Allocate buffer to hold cpu crash notes. */
886 fw_dump
.cpu_notes_buf_size
= num_cpus
* sizeof(note_buf_t
);
887 fw_dump
.cpu_notes_buf_size
= PAGE_ALIGN(fw_dump
.cpu_notes_buf_size
);
888 note_buf
= fadump_cpu_notes_buf_alloc(fw_dump
.cpu_notes_buf_size
);
890 printk(KERN_ERR
"Failed to allocate 0x%lx bytes for "
891 "cpu notes buffer\n", fw_dump
.cpu_notes_buf_size
);
894 fw_dump
.cpu_notes_buf
= __pa(note_buf
);
896 pr_debug("Allocated buffer for cpu notes of size %ld at %p\n",
897 (num_cpus
* sizeof(note_buf_t
)), note_buf
);
899 if (fw_dump
.fadumphdr_addr
)
900 fdh
= __va(fw_dump
.fadumphdr_addr
);
902 for (i
= 0; i
< num_cpus
; i
++) {
903 if (be64_to_cpu(reg_entry
->reg_id
) != REG_ID("CPUSTRT")) {
904 printk(KERN_ERR
"Unable to read CPU state data\n");
908 /* Lower 4 bytes of reg_value contains logical cpu id */
909 cpu
= be64_to_cpu(reg_entry
->reg_value
) & FADUMP_CPU_ID_MASK
;
910 if (fdh
&& !cpumask_test_cpu(cpu
, &fdh
->online_mask
)) {
911 SKIP_TO_NEXT_CPU(reg_entry
);
914 pr_debug("Reading register data for cpu %d...\n", cpu
);
915 if (fdh
&& fdh
->crashing_cpu
== cpu
) {
917 note_buf
= fadump_regs_to_elf_notes(note_buf
, ®s
);
918 SKIP_TO_NEXT_CPU(reg_entry
);
921 reg_entry
= fadump_read_registers(reg_entry
, ®s
);
922 note_buf
= fadump_regs_to_elf_notes(note_buf
, ®s
);
925 final_note(note_buf
);
928 pr_debug("Updating elfcore header (%llx) with cpu notes\n",
929 fdh
->elfcorehdr_addr
);
930 fadump_update_elfcore_header((char *)__va(fdh
->elfcorehdr_addr
));
935 fadump_cpu_notes_buf_free((unsigned long)__va(fw_dump
.cpu_notes_buf
),
936 fw_dump
.cpu_notes_buf_size
);
937 fw_dump
.cpu_notes_buf
= 0;
938 fw_dump
.cpu_notes_buf_size
= 0;
944 * Validate and process the dump data stored by firmware before exporting
945 * it through '/proc/vmcore'.
947 static int __init
process_fadump(const struct fadump_mem_struct
*fdm_active
)
949 struct fadump_crash_info_header
*fdh
;
952 if (!fdm_active
|| !fw_dump
.fadumphdr_addr
)
955 /* Check if the dump data is valid. */
956 if ((be16_to_cpu(fdm_active
->header
.dump_status_flag
) == FADUMP_ERROR_FLAG
) ||
957 (fdm_active
->cpu_state_data
.error_flags
!= 0) ||
958 (fdm_active
->rmr_region
.error_flags
!= 0)) {
959 printk(KERN_ERR
"Dump taken by platform is not valid\n");
962 if ((fdm_active
->rmr_region
.bytes_dumped
!=
963 fdm_active
->rmr_region
.source_len
) ||
964 !fdm_active
->cpu_state_data
.bytes_dumped
) {
965 printk(KERN_ERR
"Dump taken by platform is incomplete\n");
969 /* Validate the fadump crash info header */
970 fdh
= __va(fw_dump
.fadumphdr_addr
);
971 if (fdh
->magic_number
!= FADUMP_CRASH_INFO_MAGIC
) {
972 printk(KERN_ERR
"Crash info header is not valid.\n");
976 rc
= fadump_build_cpu_notes(fdm_active
);
981 * We are done validating dump info and elfcore header is now ready
982 * to be exported. set elfcorehdr_addr so that vmcore module will
983 * export the elfcore header through '/proc/vmcore'.
985 elfcorehdr_addr
= fdh
->elfcorehdr_addr
;
990 static void free_crash_memory_ranges(void)
992 kfree(crash_memory_ranges
);
993 crash_memory_ranges
= NULL
;
994 crash_memory_ranges_size
= 0;
995 max_crash_mem_ranges
= 0;
999 * Allocate or reallocate crash memory ranges array in incremental units
1002 static int allocate_crash_memory_ranges(void)
1004 struct fad_crash_memory_ranges
*new_array
;
1007 new_size
= crash_memory_ranges_size
+ PAGE_SIZE
;
1008 pr_debug("Allocating %llu bytes of memory for crash memory ranges\n",
1011 new_array
= krealloc(crash_memory_ranges
, new_size
, GFP_KERNEL
);
1012 if (new_array
== NULL
) {
1013 pr_err("Insufficient memory for setting up crash memory ranges\n");
1014 free_crash_memory_ranges();
1018 crash_memory_ranges
= new_array
;
1019 crash_memory_ranges_size
= new_size
;
1020 max_crash_mem_ranges
= (new_size
/
1021 sizeof(struct fad_crash_memory_ranges
));
1025 static inline int fadump_add_crash_memory(unsigned long long base
,
1026 unsigned long long end
)
1029 bool is_adjacent
= false;
1035 * Fold adjacent memory ranges to bring down the memory ranges/
1036 * PT_LOAD segments count.
1038 if (crash_mem_ranges
) {
1039 start
= crash_memory_ranges
[crash_mem_ranges
- 1].base
;
1040 size
= crash_memory_ranges
[crash_mem_ranges
- 1].size
;
1042 if ((start
+ size
) == base
)
1046 /* resize the array on reaching the limit */
1047 if (crash_mem_ranges
== max_crash_mem_ranges
) {
1050 ret
= allocate_crash_memory_ranges();
1056 crash_memory_ranges
[crash_mem_ranges
].base
= start
;
1060 crash_memory_ranges
[crash_mem_ranges
- 1].size
= (end
- start
);
1061 pr_debug("crash_memory_range[%d] [%#016llx-%#016llx], %#llx bytes\n",
1062 (crash_mem_ranges
- 1), start
, end
- 1, (end
- start
));
1066 static int fadump_exclude_reserved_area(unsigned long long start
,
1067 unsigned long long end
)
1069 unsigned long long ra_start
, ra_end
;
1072 ra_start
= fw_dump
.reserve_dump_area_start
;
1073 ra_end
= ra_start
+ fw_dump
.reserve_dump_area_size
;
1075 if ((ra_start
< end
) && (ra_end
> start
)) {
1076 if ((start
< ra_start
) && (end
> ra_end
)) {
1077 ret
= fadump_add_crash_memory(start
, ra_start
);
1081 ret
= fadump_add_crash_memory(ra_end
, end
);
1082 } else if (start
< ra_start
) {
1083 ret
= fadump_add_crash_memory(start
, ra_start
);
1084 } else if (ra_end
< end
) {
1085 ret
= fadump_add_crash_memory(ra_end
, end
);
1088 ret
= fadump_add_crash_memory(start
, end
);
1093 static int fadump_init_elfcore_header(char *bufp
)
1097 elf
= (struct elfhdr
*) bufp
;
1098 bufp
+= sizeof(struct elfhdr
);
1099 memcpy(elf
->e_ident
, ELFMAG
, SELFMAG
);
1100 elf
->e_ident
[EI_CLASS
] = ELF_CLASS
;
1101 elf
->e_ident
[EI_DATA
] = ELF_DATA
;
1102 elf
->e_ident
[EI_VERSION
] = EV_CURRENT
;
1103 elf
->e_ident
[EI_OSABI
] = ELF_OSABI
;
1104 memset(elf
->e_ident
+EI_PAD
, 0, EI_NIDENT
-EI_PAD
);
1105 elf
->e_type
= ET_CORE
;
1106 elf
->e_machine
= ELF_ARCH
;
1107 elf
->e_version
= EV_CURRENT
;
1109 elf
->e_phoff
= sizeof(struct elfhdr
);
1111 #if defined(_CALL_ELF)
1112 elf
->e_flags
= _CALL_ELF
;
1116 elf
->e_ehsize
= sizeof(struct elfhdr
);
1117 elf
->e_phentsize
= sizeof(struct elf_phdr
);
1119 elf
->e_shentsize
= 0;
1121 elf
->e_shstrndx
= 0;
1127 * Traverse through memblock structure and setup crash memory ranges. These
1128 * ranges will be used create PT_LOAD program headers in elfcore header.
1130 static int fadump_setup_crash_memory_ranges(void)
1132 struct memblock_region
*reg
;
1133 unsigned long long start
, end
;
1136 pr_debug("Setup crash memory ranges.\n");
1137 crash_mem_ranges
= 0;
1140 * add the first memory chunk (RMA_START through boot_memory_size) as
1141 * a separate memory chunk. The reason is, at the time crash firmware
1142 * will move the content of this memory chunk to different location
1143 * specified during fadump registration. We need to create a separate
1144 * program header for this chunk with the correct offset.
1146 ret
= fadump_add_crash_memory(RMA_START
, fw_dump
.boot_memory_size
);
1150 for_each_memblock(memory
, reg
) {
1151 start
= (unsigned long long)reg
->base
;
1152 end
= start
+ (unsigned long long)reg
->size
;
1155 * skip the first memory chunk that is already added (RMA_START
1156 * through boot_memory_size). This logic needs a relook if and
1157 * when RMA_START changes to a non-zero value.
1159 BUILD_BUG_ON(RMA_START
!= 0);
1160 if (start
< fw_dump
.boot_memory_size
) {
1161 if (end
> fw_dump
.boot_memory_size
)
1162 start
= fw_dump
.boot_memory_size
;
1167 /* add this range excluding the reserved dump area. */
1168 ret
= fadump_exclude_reserved_area(start
, end
);
1177 * If the given physical address falls within the boot memory region then
1178 * return the relocated address that points to the dump region reserved
1179 * for saving initial boot memory contents.
1181 static inline unsigned long fadump_relocate(unsigned long paddr
)
1183 if (paddr
> RMA_START
&& paddr
< fw_dump
.boot_memory_size
)
1184 return be64_to_cpu(fdm
.rmr_region
.destination_address
) + paddr
;
1189 static int fadump_create_elfcore_headers(char *bufp
)
1192 struct elf_phdr
*phdr
;
1195 fadump_init_elfcore_header(bufp
);
1196 elf
= (struct elfhdr
*)bufp
;
1197 bufp
+= sizeof(struct elfhdr
);
1200 * setup ELF PT_NOTE, place holder for cpu notes info. The notes info
1201 * will be populated during second kernel boot after crash. Hence
1202 * this PT_NOTE will always be the first elf note.
1204 * NOTE: Any new ELF note addition should be placed after this note.
1206 phdr
= (struct elf_phdr
*)bufp
;
1207 bufp
+= sizeof(struct elf_phdr
);
1208 phdr
->p_type
= PT_NOTE
;
1220 /* setup ELF PT_NOTE for vmcoreinfo */
1221 phdr
= (struct elf_phdr
*)bufp
;
1222 bufp
+= sizeof(struct elf_phdr
);
1223 phdr
->p_type
= PT_NOTE
;
1228 phdr
->p_paddr
= fadump_relocate(paddr_vmcoreinfo_note());
1229 phdr
->p_offset
= phdr
->p_paddr
;
1230 phdr
->p_memsz
= phdr
->p_filesz
= VMCOREINFO_NOTE_SIZE
;
1232 /* Increment number of program headers. */
1235 /* setup PT_LOAD sections. */
1237 for (i
= 0; i
< crash_mem_ranges
; i
++) {
1238 unsigned long long mbase
, msize
;
1239 mbase
= crash_memory_ranges
[i
].base
;
1240 msize
= crash_memory_ranges
[i
].size
;
1245 phdr
= (struct elf_phdr
*)bufp
;
1246 bufp
+= sizeof(struct elf_phdr
);
1247 phdr
->p_type
= PT_LOAD
;
1248 phdr
->p_flags
= PF_R
|PF_W
|PF_X
;
1249 phdr
->p_offset
= mbase
;
1251 if (mbase
== RMA_START
) {
1253 * The entire RMA region will be moved by firmware
1254 * to the specified destination_address. Hence set
1255 * the correct offset.
1257 phdr
->p_offset
= be64_to_cpu(fdm
.rmr_region
.destination_address
);
1260 phdr
->p_paddr
= mbase
;
1261 phdr
->p_vaddr
= (unsigned long)__va(mbase
);
1262 phdr
->p_filesz
= msize
;
1263 phdr
->p_memsz
= msize
;
1266 /* Increment number of program headers. */
1272 static unsigned long init_fadump_header(unsigned long addr
)
1274 struct fadump_crash_info_header
*fdh
;
1279 fw_dump
.fadumphdr_addr
= addr
;
1281 addr
+= sizeof(struct fadump_crash_info_header
);
1283 memset(fdh
, 0, sizeof(struct fadump_crash_info_header
));
1284 fdh
->magic_number
= FADUMP_CRASH_INFO_MAGIC
;
1285 fdh
->elfcorehdr_addr
= addr
;
1286 /* We will set the crashing cpu id in crash_fadump() during crash. */
1287 fdh
->crashing_cpu
= CPU_UNKNOWN
;
1292 static int register_fadump(void)
1299 * If no memory is reserved then we can not register for firmware-
1302 if (!fw_dump
.reserve_dump_area_size
)
1305 ret
= fadump_setup_crash_memory_ranges();
1309 addr
= be64_to_cpu(fdm
.rmr_region
.destination_address
) + be64_to_cpu(fdm
.rmr_region
.source_len
);
1310 /* Initialize fadump crash info header. */
1311 addr
= init_fadump_header(addr
);
1314 pr_debug("Creating ELF core headers at %#016lx\n", addr
);
1315 fadump_create_elfcore_headers(vaddr
);
1317 /* register the future kernel dump with firmware. */
1318 return register_fw_dump(&fdm
);
1321 static int fadump_unregister_dump(struct fadump_mem_struct
*fdm
)
1324 unsigned int wait_time
;
1326 pr_debug("Un-register firmware-assisted dump\n");
1328 /* TODO: Add upper time limit for the delay */
1330 rc
= rtas_call(fw_dump
.ibm_configure_kernel_dump
, 3, 1, NULL
,
1331 FADUMP_UNREGISTER
, fdm
,
1332 sizeof(struct fadump_mem_struct
));
1334 wait_time
= rtas_busy_delay_time(rc
);
1337 } while (wait_time
);
1340 printk(KERN_ERR
"Failed to un-register firmware-assisted dump."
1341 " unexpected error(%d).\n", rc
);
1344 fw_dump
.dump_registered
= 0;
1348 static int fadump_invalidate_dump(const struct fadump_mem_struct
*fdm
)
1351 unsigned int wait_time
;
1353 pr_debug("Invalidating firmware-assisted dump registration\n");
1355 /* TODO: Add upper time limit for the delay */
1357 rc
= rtas_call(fw_dump
.ibm_configure_kernel_dump
, 3, 1, NULL
,
1358 FADUMP_INVALIDATE
, fdm
,
1359 sizeof(struct fadump_mem_struct
));
1361 wait_time
= rtas_busy_delay_time(rc
);
1364 } while (wait_time
);
1367 pr_err("Failed to invalidate firmware-assisted dump registration. Unexpected error (%d).\n", rc
);
1370 fw_dump
.dump_active
= 0;
1375 void fadump_cleanup(void)
1377 /* Invalidate the registration only if dump is active. */
1378 if (fw_dump
.dump_active
) {
1379 /* pass the same memory dump structure provided by platform */
1380 fadump_invalidate_dump(fdm_active
);
1381 } else if (fw_dump
.dump_registered
) {
1382 /* Un-register Firmware-assisted dump if it was registered. */
1383 fadump_unregister_dump(&fdm
);
1384 free_crash_memory_ranges();
1388 static void fadump_free_reserved_memory(unsigned long start_pfn
,
1389 unsigned long end_pfn
)
1392 unsigned long time_limit
= jiffies
+ HZ
;
1394 pr_info("freeing reserved memory (0x%llx - 0x%llx)\n",
1395 PFN_PHYS(start_pfn
), PFN_PHYS(end_pfn
));
1397 for (pfn
= start_pfn
; pfn
< end_pfn
; pfn
++) {
1398 free_reserved_page(pfn_to_page(pfn
));
1400 if (time_after(jiffies
, time_limit
)) {
1402 time_limit
= jiffies
+ HZ
;
1408 * Skip memory holes and free memory that was actually reserved.
1410 static void fadump_release_reserved_area(unsigned long start
, unsigned long end
)
1412 struct memblock_region
*reg
;
1413 unsigned long tstart
, tend
;
1414 unsigned long start_pfn
= PHYS_PFN(start
);
1415 unsigned long end_pfn
= PHYS_PFN(end
);
1417 for_each_memblock(memory
, reg
) {
1418 tstart
= max(start_pfn
, memblock_region_memory_base_pfn(reg
));
1419 tend
= min(end_pfn
, memblock_region_memory_end_pfn(reg
));
1420 if (tstart
< tend
) {
1421 fadump_free_reserved_memory(tstart
, tend
);
1423 if (tend
== end_pfn
)
1426 start_pfn
= tend
+ 1;
1432 * Release the memory that was reserved in early boot to preserve the memory
1433 * contents. The released memory will be available for general use.
1435 static void fadump_release_memory(unsigned long begin
, unsigned long end
)
1437 unsigned long ra_start
, ra_end
;
1439 ra_start
= fw_dump
.reserve_dump_area_start
;
1440 ra_end
= ra_start
+ fw_dump
.reserve_dump_area_size
;
1443 * exclude the dump reserve area. Will reuse it for next
1444 * fadump registration.
1446 if (begin
< ra_end
&& end
> ra_start
) {
1447 if (begin
< ra_start
)
1448 fadump_release_reserved_area(begin
, ra_start
);
1450 fadump_release_reserved_area(ra_end
, end
);
1452 fadump_release_reserved_area(begin
, end
);
1455 static void fadump_invalidate_release_mem(void)
1457 unsigned long reserved_area_start
, reserved_area_end
;
1458 unsigned long destination_address
;
1460 mutex_lock(&fadump_mutex
);
1461 if (!fw_dump
.dump_active
) {
1462 mutex_unlock(&fadump_mutex
);
1466 destination_address
= be64_to_cpu(fdm_active
->cpu_state_data
.destination_address
);
1468 mutex_unlock(&fadump_mutex
);
1471 * Save the current reserved memory bounds we will require them
1472 * later for releasing the memory for general use.
1474 reserved_area_start
= fw_dump
.reserve_dump_area_start
;
1475 reserved_area_end
= reserved_area_start
+
1476 fw_dump
.reserve_dump_area_size
;
1478 * Setup reserve_dump_area_start and its size so that we can
1479 * reuse this reserved memory for Re-registration.
1481 fw_dump
.reserve_dump_area_start
= destination_address
;
1482 fw_dump
.reserve_dump_area_size
= get_fadump_area_size();
1484 fadump_release_memory(reserved_area_start
, reserved_area_end
);
1485 if (fw_dump
.cpu_notes_buf
) {
1486 fadump_cpu_notes_buf_free(
1487 (unsigned long)__va(fw_dump
.cpu_notes_buf
),
1488 fw_dump
.cpu_notes_buf_size
);
1489 fw_dump
.cpu_notes_buf
= 0;
1490 fw_dump
.cpu_notes_buf_size
= 0;
1492 /* Initialize the kernel dump memory structure for FAD registration. */
1493 init_fadump_mem_struct(&fdm
, fw_dump
.reserve_dump_area_start
);
1496 static ssize_t
fadump_release_memory_store(struct kobject
*kobj
,
1497 struct kobj_attribute
*attr
,
1498 const char *buf
, size_t count
)
1502 if (!fw_dump
.dump_active
)
1505 if (kstrtoint(buf
, 0, &input
))
1510 * Take away the '/proc/vmcore'. We are releasing the dump
1511 * memory, hence it will not be valid anymore.
1513 #ifdef CONFIG_PROC_VMCORE
1516 fadump_invalidate_release_mem();
1523 static ssize_t
fadump_enabled_show(struct kobject
*kobj
,
1524 struct kobj_attribute
*attr
,
1527 return sprintf(buf
, "%d\n", fw_dump
.fadump_enabled
);
1530 static ssize_t
fadump_register_show(struct kobject
*kobj
,
1531 struct kobj_attribute
*attr
,
1534 return sprintf(buf
, "%d\n", fw_dump
.dump_registered
);
1537 static ssize_t
fadump_register_store(struct kobject
*kobj
,
1538 struct kobj_attribute
*attr
,
1539 const char *buf
, size_t count
)
1544 if (!fw_dump
.fadump_enabled
|| fdm_active
)
1547 if (kstrtoint(buf
, 0, &input
))
1550 mutex_lock(&fadump_mutex
);
1554 if (fw_dump
.dump_registered
== 0) {
1557 /* Un-register Firmware-assisted dump */
1558 fadump_unregister_dump(&fdm
);
1561 if (fw_dump
.dump_registered
== 1) {
1562 /* Un-register Firmware-assisted dump */
1563 fadump_unregister_dump(&fdm
);
1565 /* Register Firmware-assisted dump */
1566 ret
= register_fadump();
1574 mutex_unlock(&fadump_mutex
);
1575 return ret
< 0 ? ret
: count
;
1578 static int fadump_region_show(struct seq_file
*m
, void *private)
1580 const struct fadump_mem_struct
*fdm_ptr
;
1582 if (!fw_dump
.fadump_enabled
)
1585 mutex_lock(&fadump_mutex
);
1587 fdm_ptr
= fdm_active
;
1589 mutex_unlock(&fadump_mutex
);
1594 "CPU : [%#016llx-%#016llx] %#llx bytes, "
1596 be64_to_cpu(fdm_ptr
->cpu_state_data
.destination_address
),
1597 be64_to_cpu(fdm_ptr
->cpu_state_data
.destination_address
) +
1598 be64_to_cpu(fdm_ptr
->cpu_state_data
.source_len
) - 1,
1599 be64_to_cpu(fdm_ptr
->cpu_state_data
.source_len
),
1600 be64_to_cpu(fdm_ptr
->cpu_state_data
.bytes_dumped
));
1602 "HPTE: [%#016llx-%#016llx] %#llx bytes, "
1604 be64_to_cpu(fdm_ptr
->hpte_region
.destination_address
),
1605 be64_to_cpu(fdm_ptr
->hpte_region
.destination_address
) +
1606 be64_to_cpu(fdm_ptr
->hpte_region
.source_len
) - 1,
1607 be64_to_cpu(fdm_ptr
->hpte_region
.source_len
),
1608 be64_to_cpu(fdm_ptr
->hpte_region
.bytes_dumped
));
1610 "DUMP: [%#016llx-%#016llx] %#llx bytes, "
1612 be64_to_cpu(fdm_ptr
->rmr_region
.destination_address
),
1613 be64_to_cpu(fdm_ptr
->rmr_region
.destination_address
) +
1614 be64_to_cpu(fdm_ptr
->rmr_region
.source_len
) - 1,
1615 be64_to_cpu(fdm_ptr
->rmr_region
.source_len
),
1616 be64_to_cpu(fdm_ptr
->rmr_region
.bytes_dumped
));
1619 (fw_dump
.reserve_dump_area_start
==
1620 be64_to_cpu(fdm_ptr
->cpu_state_data
.destination_address
)))
1623 /* Dump is active. Show reserved memory region. */
1625 " : [%#016llx-%#016llx] %#llx bytes, "
1627 (unsigned long long)fw_dump
.reserve_dump_area_start
,
1628 be64_to_cpu(fdm_ptr
->cpu_state_data
.destination_address
) - 1,
1629 be64_to_cpu(fdm_ptr
->cpu_state_data
.destination_address
) -
1630 fw_dump
.reserve_dump_area_start
,
1631 be64_to_cpu(fdm_ptr
->cpu_state_data
.destination_address
) -
1632 fw_dump
.reserve_dump_area_start
);
1635 mutex_unlock(&fadump_mutex
);
1639 static struct kobj_attribute fadump_release_attr
= __ATTR(fadump_release_mem
,
1641 fadump_release_memory_store
);
1642 static struct kobj_attribute fadump_attr
= __ATTR(fadump_enabled
,
1643 0444, fadump_enabled_show
,
1645 static struct kobj_attribute fadump_register_attr
= __ATTR(fadump_registered
,
1646 0644, fadump_register_show
,
1647 fadump_register_store
);
1649 DEFINE_SHOW_ATTRIBUTE(fadump_region
);
1651 static void fadump_init_files(void)
1653 struct dentry
*debugfs_file
;
1656 rc
= sysfs_create_file(kernel_kobj
, &fadump_attr
.attr
);
1658 printk(KERN_ERR
"fadump: unable to create sysfs file"
1659 " fadump_enabled (%d)\n", rc
);
1661 rc
= sysfs_create_file(kernel_kobj
, &fadump_register_attr
.attr
);
1663 printk(KERN_ERR
"fadump: unable to create sysfs file"
1664 " fadump_registered (%d)\n", rc
);
1666 debugfs_file
= debugfs_create_file("fadump_region", 0444,
1667 powerpc_debugfs_root
, NULL
,
1668 &fadump_region_fops
);
1670 printk(KERN_ERR
"fadump: unable to create debugfs file"
1671 " fadump_region\n");
1673 if (fw_dump
.dump_active
) {
1674 rc
= sysfs_create_file(kernel_kobj
, &fadump_release_attr
.attr
);
1676 printk(KERN_ERR
"fadump: unable to create sysfs file"
1677 " fadump_release_mem (%d)\n", rc
);
1683 * Prepare for firmware-assisted dump.
1685 int __init
setup_fadump(void)
1687 if (!fw_dump
.fadump_enabled
)
1690 if (!fw_dump
.fadump_supported
) {
1691 printk(KERN_ERR
"Firmware-assisted dump is not supported on"
1692 " this hardware\n");
1696 fadump_show_config();
1698 * If dump data is available then see if it is valid and prepare for
1699 * saving it to the disk.
1701 if (fw_dump
.dump_active
) {
1703 * if dump process fails then invalidate the registration
1704 * and release memory before proceeding for re-registration.
1706 if (process_fadump(fdm_active
) < 0)
1707 fadump_invalidate_release_mem();
1709 /* Initialize the kernel dump memory structure for FAD registration. */
1710 else if (fw_dump
.reserve_dump_area_size
)
1711 init_fadump_mem_struct(&fdm
, fw_dump
.reserve_dump_area_start
);
1712 fadump_init_files();
1716 subsys_initcall(setup_fadump
);