blob: 17d9b6acaf638579addb59dea26752fe9bf2c35a [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +00002/*
3 * Firmware Assisted dump header file.
4 *
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +00005 * 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
Hari Bathini48a316e2017-06-02 13:00:27 +053033/* The upper limit percentage for user specified boot memory size (25%) */
34#define MAX_BOOT_MEM_RATIO 4
35
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +000036#define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt)
37
Mahesh Salgaonkara4e92ce2018-08-20 13:47:17 +053038/* Alignement per CMA requirement. */
39#define FADUMP_CMA_ALIGNMENT (PAGE_SIZE << \
40 max_t(unsigned long, MAX_ORDER - 1, pageblock_order))
41
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +000042/* 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
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +000047/* 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
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +000055/* Dump status flag */
56#define FADUMP_ERROR_FLAG 0x2000
57
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +000058#define FADUMP_CPU_ID_MASK ((1UL << 32) - 1)
59
60#define CPU_UNKNOWN (~((u32)0))
61
62/* Utility macros */
Hari Bathini408cddd2014-10-01 12:32:30 +053063#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++; \
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +000068})
69
Hari Bathini22bd0172017-05-08 15:56:24 -070070extern int crashing_cpu;
71
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +000072/* Kernel Dump section info */
73struct fadump_section {
Hari Bathini408cddd2014-10-01 12:32:30 +053074 __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;
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +000081};
82
83/* ibm,configure-kernel-dump header. */
84struct fadump_section_header {
Hari Bathini408cddd2014-10-01 12:32:30 +053085 __be32 dump_format_version;
86 __be16 dump_num_sections;
87 __be16 dump_status_flag;
88 __be32 offset_first_dump_section;
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +000089
90 /* Fields for disk dump option. */
Hari Bathini408cddd2014-10-01 12:32:30 +053091 __be32 dd_block_size;
92 __be64 dd_block_offset;
93 __be64 dd_num_blocks;
94 __be32 dd_offset_disk_path;
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +000095
96 /* Maximum time allowed to prevent an automatic dump-reboot. */
Hari Bathini408cddd2014-10-01 12:32:30 +053097 __be32 max_time_auto;
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +000098};
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. */
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +0000116struct 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
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +0000125 unsigned long fadumphdr_addr;
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000126 unsigned long cpu_notes_buf;
127 unsigned long cpu_notes_buf_size;
128
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +0000129 int ibm_configure_kernel_dump;
130
131 unsigned long fadump_enabled:1;
132 unsigned long fadump_supported:1;
133 unsigned long dump_active:1;
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +0000134 unsigned long dump_registered:1;
Mahesh Salgaonkara4e92ce2018-08-20 13:47:17 +0530135 unsigned long nocma:1;
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +0000136};
137
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +0000138/*
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)
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000154#define REG_ID(x) str_to_u64(x)
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +0000155
156#define FADUMP_CRASH_INFO_MAGIC STR_TO_HEX("FADMPINF")
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000157#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 {
Hari Bathini408cddd2014-10-01 12:32:30 +0530170 __be64 magic_number;
171 __be32 version;
172 __be32 num_cpu_offset;
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000173};
174
175/* Register entry. */
176struct fadump_reg_entry {
Hari Bathini408cddd2014-10-01 12:32:30 +0530177 __be64 reg_id;
178 __be64 reg_value;
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000179};
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +0000180
181/* fadump crash info structure */
182struct fadump_crash_info_header {
183 u64 magic_number;
184 u64 elfcorehdr_addr;
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000185 u32 crashing_cpu;
186 struct pt_regs regs;
Rasmus Villemoesa0512162016-01-20 15:00:13 -0800187 struct cpumask online_mask;
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +0000188};
189
Mahesh Salgaonkar2df173d2012-02-16 01:14:37 +0000190struct fad_crash_memory_ranges {
191 unsigned long long base;
192 unsigned long long size;
193};
194
Mahesh Salgaonkar0db68962018-08-20 13:47:32 +0530195extern int is_fadump_memory_area(u64 addr, ulong size);
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +0000196extern int early_init_dt_scan_fw_dump(unsigned long node,
197 const char *uname, int depth, void *data);
198extern int fadump_reserve_mem(void);
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +0000199extern int setup_fadump(void);
200extern int is_fadump_active(void);
Nicholas Piggin6fcd6ba2017-07-19 16:59:11 +1000201extern int should_fadump_crash(void);
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000202extern void crash_fadump(struct pt_regs *, const char *);
Mahesh Salgaonkarb500aff2012-02-16 01:15:08 +0000203extern void fadump_cleanup(void);
204
Mahesh Salgaonkar3ccc00a2012-02-20 02:15:03 +0000205#else /* CONFIG_FA_DUMP */
206static inline int is_fadump_active(void) { return 0; }
Nicholas Piggin6fcd6ba2017-07-19 16:59:11 +1000207static inline int should_fadump_crash(void) { return 0; }
Mahesh Salgaonkarebaeb5a2012-02-16 01:14:45 +0000208static inline void crash_fadump(struct pt_regs *regs, const char *str) { }
Christophe Leroy9c1d38b2019-03-22 08:08:39 +0000209static inline void fadump_cleanup(void) { }
Mahesh Salgaonkareb39c882012-02-16 01:14:22 +0000210#endif
211#endif