treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
[linux-block.git] / arch / powerpc / include / asm / fadump.h
CommitLineData
1a59d1b8 1/* SPDX-License-Identifier: GPL-2.0-or-later */
eb39c880
MS
2/*
3 * Firmware Assisted dump header file.
4 *
eb39c880
MS
5 * Copyright 2011 IBM Corporation
6 * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
7 */
8
9#ifndef __PPC64_FA_DUMP_H__
10#define __PPC64_FA_DUMP_H__
11
12#ifdef CONFIG_FA_DUMP
13
14/*
15 * The RMA region will be saved for later dumping when kernel crashes.
16 * RMA is Real Mode Area, the first block of logical memory address owned
17 * by logical partition, containing the storage that may be accessed with
18 * translate off.
19 */
20#define RMA_START 0x0
21#define RMA_END (ppc64_rma_size)
22
23/*
24 * On some Power systems where RMO is 128MB, it still requires minimum of
25 * 256MB for kernel to boot successfully. When kdump infrastructure is
26 * configured to save vmcore over network, we run into OOM issue while
27 * loading modules related to network setup. Hence we need aditional 64M
28 * of memory to avoid OOM issue.
29 */
30#define MIN_BOOT_MEM (((RMA_END < (0x1UL << 28)) ? (0x1UL << 28) : RMA_END) \
31 + (0x1UL << 26))
32
48a316e3
HB
33/* The upper limit percentage for user specified boot memory size (25%) */
34#define MAX_BOOT_MEM_RATIO 4
35
2df173d9
MS
36#define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt)
37
a4e92ce8
MS
38/* Alignement per CMA requirement. */
39#define FADUMP_CMA_ALIGNMENT (PAGE_SIZE << \
40 max_t(unsigned long, MAX_ORDER - 1, pageblock_order))
41
eb39c880
MS
42/* Firmware provided dump sections */
43#define FADUMP_CPU_STATE_DATA 0x0001
44#define FADUMP_HPTE_REGION 0x0002
45#define FADUMP_REAL_MODE_REGION 0x0011
46
3ccc00a7
MS
47/* Dump request flag */
48#define FADUMP_REQUEST_FLAG 0x00000001
49
50/* FAD commands */
51#define FADUMP_REGISTER 1
52#define FADUMP_UNREGISTER 2
53#define FADUMP_INVALIDATE 3
54
2df173d9
MS
55/* Dump status flag */
56#define FADUMP_ERROR_FLAG 0x2000
57
ebaeb5ae
MS
58#define FADUMP_CPU_ID_MASK ((1UL << 32) - 1)
59
60#define CPU_UNKNOWN (~((u32)0))
61
62/* Utility macros */
408cddd9
HB
63#define SKIP_TO_NEXT_CPU(reg_entry) \
64({ \
65 while (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUEND")) \
66 reg_entry++; \
67 reg_entry++; \
ebaeb5ae
MS
68})
69
22bd0177
HB
70extern int crashing_cpu;
71
3ccc00a7
MS
72/* Kernel Dump section info */
73struct fadump_section {
408cddd9
HB
74 __be32 request_flag;
75 __be16 source_data_type;
76 __be16 error_flags;
77 __be64 source_address;
78 __be64 source_len;
79 __be64 bytes_dumped;
80 __be64 destination_address;
3ccc00a7
MS
81};
82
83/* ibm,configure-kernel-dump header. */
84struct fadump_section_header {
408cddd9
HB
85 __be32 dump_format_version;
86 __be16 dump_num_sections;
87 __be16 dump_status_flag;
88 __be32 offset_first_dump_section;
3ccc00a7
MS
89
90 /* Fields for disk dump option. */
408cddd9
HB
91 __be32 dd_block_size;
92 __be64 dd_block_offset;
93 __be64 dd_num_blocks;
94 __be32 dd_offset_disk_path;
3ccc00a7
MS
95
96 /* Maximum time allowed to prevent an automatic dump-reboot. */
408cddd9 97 __be32 max_time_auto;
3ccc00a7
MS
98};
99
100/*
101 * Firmware Assisted dump memory structure. This structure is required for
102 * registering future kernel dump with power firmware through rtas call.
103 *
104 * No disk dump option. Hence disk dump path string section is not included.
105 */
106struct fadump_mem_struct {
107 struct fadump_section_header header;
108
109 /* Kernel dump sections */
110 struct fadump_section cpu_state_data;
111 struct fadump_section hpte_region;
112 struct fadump_section rmr_region;
113};
114
115/* Firmware-assisted dump configuration details. */
eb39c880
MS
116struct fw_dump {
117 unsigned long cpu_state_data_size;
118 unsigned long hpte_region_size;
119 unsigned long boot_memory_size;
120 unsigned long reserve_dump_area_start;
121 unsigned long reserve_dump_area_size;
122 /* cmd line option during boot */
123 unsigned long reserve_bootvar;
124
2df173d9 125 unsigned long fadumphdr_addr;
ebaeb5ae
MS
126 unsigned long cpu_notes_buf;
127 unsigned long cpu_notes_buf_size;
128
eb39c880
MS
129 int ibm_configure_kernel_dump;
130
131 unsigned long fadump_enabled:1;
132 unsigned long fadump_supported:1;
133 unsigned long dump_active:1;
3ccc00a7 134 unsigned long dump_registered:1;
a4e92ce8 135 unsigned long nocma:1;
eb39c880
MS
136};
137
2df173d9
MS
138/*
139 * Copy the ascii values for first 8 characters from a string into u64
140 * variable at their respective indexes.
141 * e.g.
142 * The string "FADMPINF" will be converted into 0x4641444d50494e46
143 */
144static inline u64 str_to_u64(const char *str)
145{
146 u64 val = 0;
147 int i;
148
149 for (i = 0; i < sizeof(val); i++)
150 val = (*str) ? (val << 8) | *str++ : val << 8;
151 return val;
152}
153#define STR_TO_HEX(x) str_to_u64(x)
ebaeb5ae 154#define REG_ID(x) str_to_u64(x)
2df173d9
MS
155
156#define FADUMP_CRASH_INFO_MAGIC STR_TO_HEX("FADMPINF")
ebaeb5ae
MS
157#define REGSAVE_AREA_MAGIC STR_TO_HEX("REGSAVE")
158
159/* The firmware-assisted dump format.
160 *
161 * The register save area is an area in the partition's memory used to preserve
162 * the register contents (CPU state data) for the active CPUs during a firmware
163 * assisted dump. The dump format contains register save area header followed
164 * by register entries. Each list of registers for a CPU starts with
165 * "CPUSTRT" and ends with "CPUEND".
166 */
167
168/* Register save area header. */
169struct fadump_reg_save_area_header {
408cddd9
HB
170 __be64 magic_number;
171 __be32 version;
172 __be32 num_cpu_offset;
ebaeb5ae
MS
173};
174
175/* Register entry. */
176struct fadump_reg_entry {
408cddd9
HB
177 __be64 reg_id;
178 __be64 reg_value;
ebaeb5ae 179};
2df173d9
MS
180
181/* fadump crash info structure */
182struct fadump_crash_info_header {
183 u64 magic_number;
184 u64 elfcorehdr_addr;
ebaeb5ae
MS
185 u32 crashing_cpu;
186 struct pt_regs regs;
a0512164 187 struct cpumask online_mask;
2df173d9
MS
188};
189
2df173d9
MS
190struct fad_crash_memory_ranges {
191 unsigned long long base;
192 unsigned long long size;
193};
194
0db6896f 195extern int is_fadump_memory_area(u64 addr, ulong size);
eb39c880
MS
196extern int early_init_dt_scan_fw_dump(unsigned long node,
197 const char *uname, int depth, void *data);
198extern int fadump_reserve_mem(void);
3ccc00a7
MS
199extern int setup_fadump(void);
200extern int is_fadump_active(void);
6fcd6baa 201extern int should_fadump_crash(void);
ebaeb5ae 202extern void crash_fadump(struct pt_regs *, const char *);
b500afff
MS
203extern void fadump_cleanup(void);
204
3ccc00a7
MS
205#else /* CONFIG_FA_DUMP */
206static inline int is_fadump_active(void) { return 0; }
6fcd6baa 207static inline int should_fadump_crash(void) { return 0; }
ebaeb5ae 208static inline void crash_fadump(struct pt_regs *regs, const char *str) { }
9c1d38b3 209static inline void fadump_cleanup(void) { }
eb39c880
MS
210#endif
211#endif