xref: /linux/arch/powerpc/include/asm/fadump-internal.h (revision 0226e55275e569126882a7befe0b1a1c9bd270aa)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Firmware-Assisted Dump internal code.
4  *
5  * Copyright 2011, Mahesh Salgaonkar, IBM Corporation.
6  * Copyright 2019, Hari Bathini, IBM Corporation.
7  */
8 
9 #ifndef _ASM_POWERPC_FADUMP_INTERNAL_H
10 #define _ASM_POWERPC_FADUMP_INTERNAL_H
11 
12 /*
13  * The RMA region will be saved for later dumping when kernel crashes.
14  * RMA is Real Mode Area, the first block of logical memory address owned
15  * by logical partition, containing the storage that may be accessed with
16  * translate off.
17  */
18 #define RMA_START	0x0
19 #define RMA_END		(ppc64_rma_size)
20 
21 /*
22  * On some Power systems where RMO is 128MB, it still requires minimum of
23  * 256MB for kernel to boot successfully. When kdump infrastructure is
24  * configured to save vmcore over network, we run into OOM issue while
25  * loading modules related to network setup. Hence we need additional 64M
26  * of memory to avoid OOM issue.
27  */
28 #define MIN_BOOT_MEM	(((RMA_END < (0x1UL << 28)) ? (0x1UL << 28) : RMA_END) \
29 			+ (0x1UL << 26))
30 
31 /* The upper limit percentage for user specified boot memory size (25%) */
32 #define MAX_BOOT_MEM_RATIO			4
33 
34 #define memblock_num_regions(memblock_type)	(memblock.memblock_type.cnt)
35 
36 /* Alignment per CMA requirement. */
37 #define FADUMP_CMA_ALIGNMENT	(PAGE_SIZE <<				\
38 				 max_t(unsigned long, MAX_ORDER - 1,	\
39 				 pageblock_order))
40 
41 /* FAD commands */
42 #define FADUMP_REGISTER			1
43 #define FADUMP_UNREGISTER		2
44 #define FADUMP_INVALIDATE		3
45 
46 /*
47  * Copy the ascii values for first 8 characters from a string into u64
48  * variable at their respective indexes.
49  * e.g.
50  *  The string "FADMPINF" will be converted into 0x4641444d50494e46
51  */
52 static inline u64 fadump_str_to_u64(const char *str)
53 {
54 	u64 val = 0;
55 	int i;
56 
57 	for (i = 0; i < sizeof(val); i++)
58 		val = (*str) ? (val << 8) | *str++ : val << 8;
59 	return val;
60 }
61 
62 #define FADUMP_CPU_UNKNOWN		(~((u32)0))
63 
64 #define FADUMP_CRASH_INFO_MAGIC		fadump_str_to_u64("FADMPINF")
65 
66 /* fadump crash info structure */
67 struct fadump_crash_info_header {
68 	u64		magic_number;
69 	u64		elfcorehdr_addr;
70 	u32		crashing_cpu;
71 	struct pt_regs	regs;
72 	struct cpumask	online_mask;
73 };
74 
75 struct fad_crash_memory_ranges {
76 	unsigned long long	base;
77 	unsigned long long	size;
78 };
79 
80 /* Firmware-assisted dump configuration details. */
81 struct fw_dump {
82 	unsigned long	reserve_dump_area_start;
83 	unsigned long	reserve_dump_area_size;
84 	/* cmd line option during boot */
85 	unsigned long	reserve_bootvar;
86 
87 	unsigned long	cpu_state_data_size;
88 	unsigned long	hpte_region_size;
89 	unsigned long	boot_memory_size;
90 
91 	unsigned long	fadumphdr_addr;
92 	unsigned long	cpu_notes_buf_vaddr;
93 	unsigned long	cpu_notes_buf_size;
94 
95 	int		ibm_configure_kernel_dump;
96 
97 	unsigned long	fadump_enabled:1;
98 	unsigned long	fadump_supported:1;
99 	unsigned long	dump_active:1;
100 	unsigned long	dump_registered:1;
101 	unsigned long	nocma:1;
102 };
103 
104 /* Helper functions */
105 s32 fadump_setup_cpu_notes_buf(u32 num_cpus);
106 void fadump_free_cpu_notes_buf(void);
107 u32 *fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
108 void fadump_update_elfcore_header(char *bufp);
109 bool is_fadump_boot_mem_contiguous(void);
110 bool is_fadump_reserved_mem_contiguous(void);
111 
112 #endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */
113