xref: /linux/arch/powerpc/include/asm/fadump-internal.h (revision d3833a7010817f82bff373e26d146e6401c695f4)
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 /* Platform specific callback functions */
81 struct fadump_ops;
82 
83 /* Firmware-assisted dump configuration details. */
84 struct fw_dump {
85 	unsigned long	reserve_dump_area_start;
86 	unsigned long	reserve_dump_area_size;
87 	/* cmd line option during boot */
88 	unsigned long	reserve_bootvar;
89 
90 	unsigned long	cpu_state_data_size;
91 	unsigned long	hpte_region_size;
92 	unsigned long	boot_memory_size;
93 
94 	unsigned long	fadumphdr_addr;
95 	unsigned long	cpu_notes_buf_vaddr;
96 	unsigned long	cpu_notes_buf_size;
97 
98 	int		ibm_configure_kernel_dump;
99 
100 	unsigned long	fadump_enabled:1;
101 	unsigned long	fadump_supported:1;
102 	unsigned long	dump_active:1;
103 	unsigned long	dump_registered:1;
104 	unsigned long	nocma:1;
105 
106 	struct fadump_ops	*ops;
107 };
108 
109 struct fadump_ops {
110 	u64	(*fadump_init_mem_struct)(struct fw_dump *fadump_conf);
111 	int	(*fadump_register)(struct fw_dump *fadump_conf);
112 	int	(*fadump_unregister)(struct fw_dump *fadump_conf);
113 	int	(*fadump_invalidate)(struct fw_dump *fadump_conf);
114 	int	(*fadump_process)(struct fw_dump *fadump_conf);
115 	void	(*fadump_region_show)(struct fw_dump *fadump_conf,
116 				      struct seq_file *m);
117 	void	(*fadump_trigger)(struct fadump_crash_info_header *fdh,
118 				  const char *msg);
119 };
120 
121 /* Helper functions */
122 s32 fadump_setup_cpu_notes_buf(u32 num_cpus);
123 void fadump_free_cpu_notes_buf(void);
124 u32 *fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
125 void fadump_update_elfcore_header(char *bufp);
126 bool is_fadump_boot_mem_contiguous(void);
127 bool is_fadump_reserved_mem_contiguous(void);
128 
129 #ifdef CONFIG_PPC_PSERIES
130 extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
131 #else
132 static inline void
133 rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
134 #endif
135 
136 #endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */
137