Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Firmware-Assisted Dump internal code. |
| 4 | * |
| 5 | * Copyright 2011, Mahesh Salgaonkar, IBM Corporation. |
| 6 | * Copyright 2019, Hari Bathini, IBM Corporation. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _ASM_POWERPC_FADUMP_INTERNAL_H |
| 10 | #define _ASM_POWERPC_FADUMP_INTERNAL_H |
| 11 | |
Hari Bathini | 7dee93a | 2019-09-11 20:27:39 +0530 | [diff] [blame] | 12 | /* Maximum number of memory regions kernel supports */ |
| 13 | #define FADUMP_MAX_MEM_REGS 128 |
| 14 | |
Hari Bathini | bec5319 | 2019-09-11 20:26:03 +0530 | [diff] [blame] | 15 | #ifndef CONFIG_PRESERVE_FA_DUMP |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 16 | |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 17 | /* The upper limit percentage for user specified boot memory size (25%) */ |
| 18 | #define MAX_BOOT_MEM_RATIO 4 |
| 19 | |
| 20 | #define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt) |
| 21 | |
| 22 | /* Alignment per CMA requirement. */ |
| 23 | #define FADUMP_CMA_ALIGNMENT (PAGE_SIZE << \ |
| 24 | max_t(unsigned long, MAX_ORDER - 1, \ |
| 25 | pageblock_order)) |
| 26 | |
| 27 | /* FAD commands */ |
| 28 | #define FADUMP_REGISTER 1 |
| 29 | #define FADUMP_UNREGISTER 2 |
| 30 | #define FADUMP_INVALIDATE 3 |
| 31 | |
Hari Bathini | 0226e55 | 2019-09-11 20:18:14 +0530 | [diff] [blame] | 32 | /* |
| 33 | * Copy the ascii values for first 8 characters from a string into u64 |
| 34 | * variable at their respective indexes. |
| 35 | * e.g. |
| 36 | * The string "FADMPINF" will be converted into 0x4641444d50494e46 |
| 37 | */ |
| 38 | static inline u64 fadump_str_to_u64(const char *str) |
| 39 | { |
| 40 | u64 val = 0; |
| 41 | int i; |
| 42 | |
| 43 | for (i = 0; i < sizeof(val); i++) |
| 44 | val = (*str) ? (val << 8) | *str++ : val << 8; |
| 45 | return val; |
| 46 | } |
| 47 | |
| 48 | #define FADUMP_CPU_UNKNOWN (~((u32)0)) |
| 49 | |
| 50 | #define FADUMP_CRASH_INFO_MAGIC fadump_str_to_u64("FADMPINF") |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 51 | |
| 52 | /* fadump crash info structure */ |
| 53 | struct fadump_crash_info_header { |
| 54 | u64 magic_number; |
| 55 | u64 elfcorehdr_addr; |
| 56 | u32 crashing_cpu; |
| 57 | struct pt_regs regs; |
| 58 | struct cpumask online_mask; |
| 59 | }; |
| 60 | |
Hari Bathini | e4fc48f | 2019-09-11 20:25:05 +0530 | [diff] [blame] | 61 | struct fadump_memory_range { |
| 62 | u64 base; |
| 63 | u64 size; |
| 64 | }; |
| 65 | |
| 66 | /* fadump memory ranges info */ |
Hari Bathini | 02c04e3 | 2020-04-20 14:26:09 +0530 | [diff] [blame] | 67 | #define RNG_NAME_SZ 16 |
Hari Bathini | e4fc48f | 2019-09-11 20:25:05 +0530 | [diff] [blame] | 68 | struct fadump_mrange_info { |
Hari Bathini | 02c04e3 | 2020-04-20 14:26:09 +0530 | [diff] [blame] | 69 | char name[RNG_NAME_SZ]; |
Hari Bathini | e4fc48f | 2019-09-11 20:25:05 +0530 | [diff] [blame] | 70 | struct fadump_memory_range *mem_ranges; |
| 71 | u32 mem_ranges_sz; |
| 72 | u32 mem_range_cnt; |
| 73 | u32 max_mem_ranges; |
Hari Bathini | 02c04e3 | 2020-04-20 14:26:09 +0530 | [diff] [blame] | 74 | bool is_static; |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 75 | }; |
| 76 | |
Hari Bathini | d3833a7 | 2019-09-11 20:18:40 +0530 | [diff] [blame] | 77 | /* Platform specific callback functions */ |
| 78 | struct fadump_ops; |
| 79 | |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 80 | /* Firmware-assisted dump configuration details. */ |
| 81 | struct fw_dump { |
| 82 | unsigned long reserve_dump_area_start; |
| 83 | unsigned long reserve_dump_area_size; |
| 84 | /* cmd line option during boot */ |
| 85 | unsigned long reserve_bootvar; |
| 86 | |
| 87 | unsigned long cpu_state_data_size; |
Hari Bathini | 5000a17 | 2019-09-11 20:24:50 +0530 | [diff] [blame] | 88 | u64 cpu_state_dest_vaddr; |
| 89 | u32 cpu_state_data_version; |
| 90 | u32 cpu_state_entry_size; |
| 91 | |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 92 | unsigned long hpte_region_size; |
Hari Bathini | 41a65d1 | 2019-09-11 20:18:57 +0530 | [diff] [blame] | 93 | |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 94 | unsigned long boot_memory_size; |
Hari Bathini | 41a65d1 | 2019-09-11 20:18:57 +0530 | [diff] [blame] | 95 | u64 boot_mem_dest_addr; |
Hari Bathini | 7dee93a | 2019-09-11 20:27:39 +0530 | [diff] [blame] | 96 | u64 boot_mem_addr[FADUMP_MAX_MEM_REGS]; |
| 97 | u64 boot_mem_sz[FADUMP_MAX_MEM_REGS]; |
| 98 | u64 boot_mem_top; |
| 99 | u64 boot_mem_regs_cnt; |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 100 | |
| 101 | unsigned long fadumphdr_addr; |
Hari Bathini | 961cf26 | 2019-09-11 20:16:36 +0530 | [diff] [blame] | 102 | unsigned long cpu_notes_buf_vaddr; |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 103 | unsigned long cpu_notes_buf_size; |
| 104 | |
Hari Bathini | 7dee93a | 2019-09-11 20:27:39 +0530 | [diff] [blame] | 105 | /* |
| 106 | * Maximum size supported by firmware to copy from source to |
| 107 | * destination address per entry. |
| 108 | */ |
| 109 | u64 max_copy_size; |
Hari Bathini | 742a265 | 2019-09-11 20:20:57 +0530 | [diff] [blame] | 110 | u64 kernel_metadata; |
| 111 | |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 112 | int ibm_configure_kernel_dump; |
| 113 | |
| 114 | unsigned long fadump_enabled:1; |
| 115 | unsigned long fadump_supported:1; |
| 116 | unsigned long dump_active:1; |
| 117 | unsigned long dump_registered:1; |
| 118 | unsigned long nocma:1; |
Hari Bathini | d3833a7 | 2019-09-11 20:18:40 +0530 | [diff] [blame] | 119 | |
| 120 | struct fadump_ops *ops; |
| 121 | }; |
| 122 | |
| 123 | struct fadump_ops { |
| 124 | u64 (*fadump_init_mem_struct)(struct fw_dump *fadump_conf); |
Hari Bathini | 742a265 | 2019-09-11 20:20:57 +0530 | [diff] [blame] | 125 | u64 (*fadump_get_metadata_size)(void); |
| 126 | int (*fadump_setup_metadata)(struct fw_dump *fadump_conf); |
Hari Bathini | 7b1b3b4 | 2019-09-11 20:26:59 +0530 | [diff] [blame] | 127 | u64 (*fadump_get_bootmem_min)(void); |
Hari Bathini | d3833a7 | 2019-09-11 20:18:40 +0530 | [diff] [blame] | 128 | int (*fadump_register)(struct fw_dump *fadump_conf); |
| 129 | int (*fadump_unregister)(struct fw_dump *fadump_conf); |
| 130 | int (*fadump_invalidate)(struct fw_dump *fadump_conf); |
Hari Bathini | 2790d01 | 2019-09-11 20:21:16 +0530 | [diff] [blame] | 131 | void (*fadump_cleanup)(struct fw_dump *fadump_conf); |
Hari Bathini | d3833a7 | 2019-09-11 20:18:40 +0530 | [diff] [blame] | 132 | int (*fadump_process)(struct fw_dump *fadump_conf); |
| 133 | void (*fadump_region_show)(struct fw_dump *fadump_conf, |
| 134 | struct seq_file *m); |
| 135 | void (*fadump_trigger)(struct fadump_crash_info_header *fdh, |
| 136 | const char *msg); |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 137 | }; |
| 138 | |
Hari Bathini | 7f0ad11 | 2019-09-11 20:16:52 +0530 | [diff] [blame] | 139 | /* Helper functions */ |
Nick Child | d276960 | 2021-12-16 17:00:16 -0500 | [diff] [blame] | 140 | s32 __init fadump_setup_cpu_notes_buf(u32 num_cpus); |
Hari Bathini | 7f0ad11 | 2019-09-11 20:16:52 +0530 | [diff] [blame] | 141 | void fadump_free_cpu_notes_buf(void); |
Nick Child | d276960 | 2021-12-16 17:00:16 -0500 | [diff] [blame] | 142 | u32 *__init fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs); |
| 143 | void __init fadump_update_elfcore_header(char *bufp); |
Hari Bathini | 7f0ad11 | 2019-09-11 20:16:52 +0530 | [diff] [blame] | 144 | bool is_fadump_boot_mem_contiguous(void); |
| 145 | bool is_fadump_reserved_mem_contiguous(void); |
| 146 | |
Hari Bathini | bec5319 | 2019-09-11 20:26:03 +0530 | [diff] [blame] | 147 | #else /* !CONFIG_PRESERVE_FA_DUMP */ |
| 148 | |
| 149 | /* Firmware-assisted dump configuration details. */ |
| 150 | struct fw_dump { |
| 151 | u64 boot_mem_top; |
| 152 | u64 dump_active; |
| 153 | }; |
| 154 | |
| 155 | #endif /* CONFIG_PRESERVE_FA_DUMP */ |
| 156 | |
Hari Bathini | d3833a7 | 2019-09-11 20:18:40 +0530 | [diff] [blame] | 157 | #ifdef CONFIG_PPC_PSERIES |
| 158 | extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node); |
| 159 | #else |
| 160 | static inline void |
| 161 | rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { } |
| 162 | #endif |
| 163 | |
Hari Bathini | 41df592 | 2019-09-11 20:20:26 +0530 | [diff] [blame] | 164 | #ifdef CONFIG_PPC_POWERNV |
| 165 | extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node); |
| 166 | #else |
| 167 | static inline void |
| 168 | opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { } |
| 169 | #endif |
| 170 | |
Hari Bathini | ca986d7 | 2019-09-11 20:16:21 +0530 | [diff] [blame] | 171 | #endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */ |