1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Firmware Assisted dump header file. 4 * 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 33 /* The upper limit percentage for user specified boot memory size (25%) */ 34 #define MAX_BOOT_MEM_RATIO 4 35 36 #define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt) 37 38 /* Alignement per CMA requirement. */ 39 #define FADUMP_CMA_ALIGNMENT (PAGE_SIZE << \ 40 max_t(unsigned long, MAX_ORDER - 1, pageblock_order)) 41 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 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 55 /* Dump status flag */ 56 #define FADUMP_ERROR_FLAG 0x2000 57 58 #define FADUMP_CPU_ID_MASK ((1UL << 32) - 1) 59 60 #define CPU_UNKNOWN (~((u32)0)) 61 62 /* Utility macros */ 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++; \ 68 }) 69 70 extern int crashing_cpu; 71 72 /* Kernel Dump section info */ 73 struct fadump_section { 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; 81 }; 82 83 /* ibm,configure-kernel-dump header. */ 84 struct fadump_section_header { 85 __be32 dump_format_version; 86 __be16 dump_num_sections; 87 __be16 dump_status_flag; 88 __be32 offset_first_dump_section; 89 90 /* Fields for disk dump option. */ 91 __be32 dd_block_size; 92 __be64 dd_block_offset; 93 __be64 dd_num_blocks; 94 __be32 dd_offset_disk_path; 95 96 /* Maximum time allowed to prevent an automatic dump-reboot. */ 97 __be32 max_time_auto; 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 */ 106 struct 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. */ 116 struct 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 125 unsigned long fadumphdr_addr; 126 unsigned long cpu_notes_buf; 127 unsigned long cpu_notes_buf_size; 128 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; 134 unsigned long dump_registered:1; 135 unsigned long nocma:1; 136 }; 137 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 */ 144 static 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) 154 #define REG_ID(x) str_to_u64(x) 155 156 #define FADUMP_CRASH_INFO_MAGIC STR_TO_HEX("FADMPINF") 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. */ 169 struct fadump_reg_save_area_header { 170 __be64 magic_number; 171 __be32 version; 172 __be32 num_cpu_offset; 173 }; 174 175 /* Register entry. */ 176 struct fadump_reg_entry { 177 __be64 reg_id; 178 __be64 reg_value; 179 }; 180 181 /* fadump crash info structure */ 182 struct fadump_crash_info_header { 183 u64 magic_number; 184 u64 elfcorehdr_addr; 185 u32 crashing_cpu; 186 struct pt_regs regs; 187 struct cpumask online_mask; 188 }; 189 190 struct fad_crash_memory_ranges { 191 unsigned long long base; 192 unsigned long long size; 193 }; 194 195 extern int is_fadump_memory_area(u64 addr, ulong size); 196 extern int early_init_dt_scan_fw_dump(unsigned long node, 197 const char *uname, int depth, void *data); 198 extern int fadump_reserve_mem(void); 199 extern int setup_fadump(void); 200 extern int is_fadump_active(void); 201 extern int should_fadump_crash(void); 202 extern void crash_fadump(struct pt_regs *, const char *); 203 extern void fadump_cleanup(void); 204 205 #else /* CONFIG_FA_DUMP */ 206 static inline int is_fadump_active(void) { return 0; } 207 static inline int should_fadump_crash(void) { return 0; } 208 static inline void crash_fadump(struct pt_regs *regs, const char *str) { } 209 static inline void fadump_cleanup(void) { } 210 #endif 211 #endif 212