Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 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 | |
Hari Bathini | 48a316e | 2017-06-02 13:00:27 +0530 | [diff] [blame^] | 46 | /* The upper limit percentage for user specified boot memory size (25%) */ |
| 47 | #define MAX_BOOT_MEM_RATIO 4 |
| 48 | |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 49 | #define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt) |
| 50 | |
Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 51 | /* Firmware provided dump sections */ |
| 52 | #define FADUMP_CPU_STATE_DATA 0x0001 |
| 53 | #define FADUMP_HPTE_REGION 0x0002 |
| 54 | #define FADUMP_REAL_MODE_REGION 0x0011 |
| 55 | |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 56 | /* Dump request flag */ |
| 57 | #define FADUMP_REQUEST_FLAG 0x00000001 |
| 58 | |
| 59 | /* FAD commands */ |
| 60 | #define FADUMP_REGISTER 1 |
| 61 | #define FADUMP_UNREGISTER 2 |
| 62 | #define FADUMP_INVALIDATE 3 |
| 63 | |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 64 | /* Dump status flag */ |
| 65 | #define FADUMP_ERROR_FLAG 0x2000 |
| 66 | |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 67 | #define FADUMP_CPU_ID_MASK ((1UL << 32) - 1) |
| 68 | |
| 69 | #define CPU_UNKNOWN (~((u32)0)) |
| 70 | |
| 71 | /* Utility macros */ |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 72 | #define SKIP_TO_NEXT_CPU(reg_entry) \ |
| 73 | ({ \ |
| 74 | while (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUEND")) \ |
| 75 | reg_entry++; \ |
| 76 | reg_entry++; \ |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 77 | }) |
| 78 | |
Hari Bathini | 22bd017 | 2017-05-08 15:56:24 -0700 | [diff] [blame] | 79 | extern int crashing_cpu; |
| 80 | |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 81 | /* Kernel Dump section info */ |
| 82 | struct fadump_section { |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 83 | __be32 request_flag; |
| 84 | __be16 source_data_type; |
| 85 | __be16 error_flags; |
| 86 | __be64 source_address; |
| 87 | __be64 source_len; |
| 88 | __be64 bytes_dumped; |
| 89 | __be64 destination_address; |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* ibm,configure-kernel-dump header. */ |
| 93 | struct fadump_section_header { |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 94 | __be32 dump_format_version; |
| 95 | __be16 dump_num_sections; |
| 96 | __be16 dump_status_flag; |
| 97 | __be32 offset_first_dump_section; |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 98 | |
| 99 | /* Fields for disk dump option. */ |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 100 | __be32 dd_block_size; |
| 101 | __be64 dd_block_offset; |
| 102 | __be64 dd_num_blocks; |
| 103 | __be32 dd_offset_disk_path; |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 104 | |
| 105 | /* Maximum time allowed to prevent an automatic dump-reboot. */ |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 106 | __be32 max_time_auto; |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | /* |
| 110 | * Firmware Assisted dump memory structure. This structure is required for |
| 111 | * registering future kernel dump with power firmware through rtas call. |
| 112 | * |
| 113 | * No disk dump option. Hence disk dump path string section is not included. |
| 114 | */ |
| 115 | struct fadump_mem_struct { |
| 116 | struct fadump_section_header header; |
| 117 | |
| 118 | /* Kernel dump sections */ |
| 119 | struct fadump_section cpu_state_data; |
| 120 | struct fadump_section hpte_region; |
| 121 | struct fadump_section rmr_region; |
| 122 | }; |
| 123 | |
| 124 | /* Firmware-assisted dump configuration details. */ |
Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 125 | struct fw_dump { |
| 126 | unsigned long cpu_state_data_size; |
| 127 | unsigned long hpte_region_size; |
| 128 | unsigned long boot_memory_size; |
| 129 | unsigned long reserve_dump_area_start; |
| 130 | unsigned long reserve_dump_area_size; |
| 131 | /* cmd line option during boot */ |
| 132 | unsigned long reserve_bootvar; |
| 133 | |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 134 | unsigned long fadumphdr_addr; |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 135 | unsigned long cpu_notes_buf; |
| 136 | unsigned long cpu_notes_buf_size; |
| 137 | |
Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 138 | int ibm_configure_kernel_dump; |
| 139 | |
| 140 | unsigned long fadump_enabled:1; |
| 141 | unsigned long fadump_supported:1; |
| 142 | unsigned long dump_active:1; |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 143 | unsigned long dump_registered:1; |
Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 146 | /* |
| 147 | * Copy the ascii values for first 8 characters from a string into u64 |
| 148 | * variable at their respective indexes. |
| 149 | * e.g. |
| 150 | * The string "FADMPINF" will be converted into 0x4641444d50494e46 |
| 151 | */ |
| 152 | static inline u64 str_to_u64(const char *str) |
| 153 | { |
| 154 | u64 val = 0; |
| 155 | int i; |
| 156 | |
| 157 | for (i = 0; i < sizeof(val); i++) |
| 158 | val = (*str) ? (val << 8) | *str++ : val << 8; |
| 159 | return val; |
| 160 | } |
| 161 | #define STR_TO_HEX(x) str_to_u64(x) |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 162 | #define REG_ID(x) str_to_u64(x) |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 163 | |
| 164 | #define FADUMP_CRASH_INFO_MAGIC STR_TO_HEX("FADMPINF") |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 165 | #define REGSAVE_AREA_MAGIC STR_TO_HEX("REGSAVE") |
| 166 | |
| 167 | /* The firmware-assisted dump format. |
| 168 | * |
| 169 | * The register save area is an area in the partition's memory used to preserve |
| 170 | * the register contents (CPU state data) for the active CPUs during a firmware |
| 171 | * assisted dump. The dump format contains register save area header followed |
| 172 | * by register entries. Each list of registers for a CPU starts with |
| 173 | * "CPUSTRT" and ends with "CPUEND". |
| 174 | */ |
| 175 | |
| 176 | /* Register save area header. */ |
| 177 | struct fadump_reg_save_area_header { |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 178 | __be64 magic_number; |
| 179 | __be32 version; |
| 180 | __be32 num_cpu_offset; |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /* Register entry. */ |
| 184 | struct fadump_reg_entry { |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 185 | __be64 reg_id; |
| 186 | __be64 reg_value; |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 187 | }; |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 188 | |
| 189 | /* fadump crash info structure */ |
| 190 | struct fadump_crash_info_header { |
| 191 | u64 magic_number; |
| 192 | u64 elfcorehdr_addr; |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 193 | u32 crashing_cpu; |
| 194 | struct pt_regs regs; |
Rasmus Villemoes | a051216 | 2016-01-20 15:00:13 -0800 | [diff] [blame] | 195 | struct cpumask online_mask; |
Mahesh Salgaonkar | 2df173d | 2012-02-16 01:14:37 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | /* Crash memory ranges */ |
| 199 | #define INIT_CRASHMEM_RANGES (INIT_MEMBLOCK_REGIONS + 2) |
| 200 | |
| 201 | struct fad_crash_memory_ranges { |
| 202 | unsigned long long base; |
| 203 | unsigned long long size; |
| 204 | }; |
| 205 | |
Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 206 | extern int early_init_dt_scan_fw_dump(unsigned long node, |
| 207 | const char *uname, int depth, void *data); |
| 208 | extern int fadump_reserve_mem(void); |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 209 | extern int setup_fadump(void); |
| 210 | extern int is_fadump_active(void); |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 211 | extern void crash_fadump(struct pt_regs *, const char *); |
Mahesh Salgaonkar | b500aff | 2012-02-16 01:15:08 +0000 | [diff] [blame] | 212 | extern void fadump_cleanup(void); |
| 213 | |
Mahesh Salgaonkar | 3ccc00a | 2012-02-20 02:15:03 +0000 | [diff] [blame] | 214 | #else /* CONFIG_FA_DUMP */ |
| 215 | static inline int is_fadump_active(void) { return 0; } |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 216 | static inline void crash_fadump(struct pt_regs *regs, const char *str) { } |
Mahesh Salgaonkar | eb39c88 | 2012-02-16 01:14:22 +0000 | [diff] [blame] | 217 | #endif |
| 218 | #endif |