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