18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Firmware-Assisted Dump internal code. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2011, Mahesh Salgaonkar, IBM Corporation. 68c2ecf20Sopenharmony_ci * Copyright 2019, Hari Bathini, IBM Corporation. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_FADUMP_INTERNAL_H 108c2ecf20Sopenharmony_ci#define _ASM_POWERPC_FADUMP_INTERNAL_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* Maximum number of memory regions kernel supports */ 138c2ecf20Sopenharmony_ci#define FADUMP_MAX_MEM_REGS 128 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#ifndef CONFIG_PRESERVE_FA_DUMP 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* The upper limit percentage for user specified boot memory size (25%) */ 188c2ecf20Sopenharmony_ci#define MAX_BOOT_MEM_RATIO 4 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* Alignment per CMA requirement. */ 238c2ecf20Sopenharmony_ci#define FADUMP_CMA_ALIGNMENT (PAGE_SIZE << \ 248c2ecf20Sopenharmony_ci max_t(unsigned long, MAX_ORDER - 1, \ 258c2ecf20Sopenharmony_ci pageblock_order)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* FAD commands */ 288c2ecf20Sopenharmony_ci#define FADUMP_REGISTER 1 298c2ecf20Sopenharmony_ci#define FADUMP_UNREGISTER 2 308c2ecf20Sopenharmony_ci#define FADUMP_INVALIDATE 3 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* 338c2ecf20Sopenharmony_ci * Copy the ascii values for first 8 characters from a string into u64 348c2ecf20Sopenharmony_ci * variable at their respective indexes. 358c2ecf20Sopenharmony_ci * e.g. 368c2ecf20Sopenharmony_ci * The string "FADMPINF" will be converted into 0x4641444d50494e46 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_cistatic inline u64 fadump_str_to_u64(const char *str) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci u64 val = 0; 418c2ecf20Sopenharmony_ci int i; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci for (i = 0; i < sizeof(val); i++) 448c2ecf20Sopenharmony_ci val = (*str) ? (val << 8) | *str++ : val << 8; 458c2ecf20Sopenharmony_ci return val; 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define FADUMP_CPU_UNKNOWN (~((u32)0)) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define FADUMP_CRASH_INFO_MAGIC fadump_str_to_u64("FADMPINF") 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* fadump crash info structure */ 538c2ecf20Sopenharmony_cistruct fadump_crash_info_header { 548c2ecf20Sopenharmony_ci u64 magic_number; 558c2ecf20Sopenharmony_ci u64 elfcorehdr_addr; 568c2ecf20Sopenharmony_ci u32 crashing_cpu; 578c2ecf20Sopenharmony_ci struct pt_regs regs; 588c2ecf20Sopenharmony_ci struct cpumask online_mask; 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct fadump_memory_range { 628c2ecf20Sopenharmony_ci u64 base; 638c2ecf20Sopenharmony_ci u64 size; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* fadump memory ranges info */ 678c2ecf20Sopenharmony_ci#define RNG_NAME_SZ 16 688c2ecf20Sopenharmony_cistruct fadump_mrange_info { 698c2ecf20Sopenharmony_ci char name[RNG_NAME_SZ]; 708c2ecf20Sopenharmony_ci struct fadump_memory_range *mem_ranges; 718c2ecf20Sopenharmony_ci u32 mem_ranges_sz; 728c2ecf20Sopenharmony_ci u32 mem_range_cnt; 738c2ecf20Sopenharmony_ci u32 max_mem_ranges; 748c2ecf20Sopenharmony_ci bool is_static; 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* Platform specific callback functions */ 788c2ecf20Sopenharmony_cistruct fadump_ops; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Firmware-assisted dump configuration details. */ 818c2ecf20Sopenharmony_cistruct fw_dump { 828c2ecf20Sopenharmony_ci unsigned long reserve_dump_area_start; 838c2ecf20Sopenharmony_ci unsigned long reserve_dump_area_size; 848c2ecf20Sopenharmony_ci /* cmd line option during boot */ 858c2ecf20Sopenharmony_ci unsigned long reserve_bootvar; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci unsigned long cpu_state_data_size; 888c2ecf20Sopenharmony_ci u64 cpu_state_dest_vaddr; 898c2ecf20Sopenharmony_ci u32 cpu_state_data_version; 908c2ecf20Sopenharmony_ci u32 cpu_state_entry_size; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci unsigned long hpte_region_size; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci unsigned long boot_memory_size; 958c2ecf20Sopenharmony_ci u64 boot_mem_dest_addr; 968c2ecf20Sopenharmony_ci u64 boot_mem_addr[FADUMP_MAX_MEM_REGS]; 978c2ecf20Sopenharmony_ci u64 boot_mem_sz[FADUMP_MAX_MEM_REGS]; 988c2ecf20Sopenharmony_ci u64 boot_mem_top; 998c2ecf20Sopenharmony_ci u64 boot_mem_regs_cnt; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci unsigned long fadumphdr_addr; 1028c2ecf20Sopenharmony_ci unsigned long cpu_notes_buf_vaddr; 1038c2ecf20Sopenharmony_ci unsigned long cpu_notes_buf_size; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci /* 1068c2ecf20Sopenharmony_ci * Maximum size supported by firmware to copy from source to 1078c2ecf20Sopenharmony_ci * destination address per entry. 1088c2ecf20Sopenharmony_ci */ 1098c2ecf20Sopenharmony_ci u64 max_copy_size; 1108c2ecf20Sopenharmony_ci u64 kernel_metadata; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci int ibm_configure_kernel_dump; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci unsigned long fadump_enabled:1; 1158c2ecf20Sopenharmony_ci unsigned long fadump_supported:1; 1168c2ecf20Sopenharmony_ci unsigned long dump_active:1; 1178c2ecf20Sopenharmony_ci unsigned long dump_registered:1; 1188c2ecf20Sopenharmony_ci unsigned long nocma:1; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci struct fadump_ops *ops; 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct fadump_ops { 1248c2ecf20Sopenharmony_ci u64 (*fadump_init_mem_struct)(struct fw_dump *fadump_conf); 1258c2ecf20Sopenharmony_ci u64 (*fadump_get_metadata_size)(void); 1268c2ecf20Sopenharmony_ci int (*fadump_setup_metadata)(struct fw_dump *fadump_conf); 1278c2ecf20Sopenharmony_ci u64 (*fadump_get_bootmem_min)(void); 1288c2ecf20Sopenharmony_ci int (*fadump_register)(struct fw_dump *fadump_conf); 1298c2ecf20Sopenharmony_ci int (*fadump_unregister)(struct fw_dump *fadump_conf); 1308c2ecf20Sopenharmony_ci int (*fadump_invalidate)(struct fw_dump *fadump_conf); 1318c2ecf20Sopenharmony_ci void (*fadump_cleanup)(struct fw_dump *fadump_conf); 1328c2ecf20Sopenharmony_ci int (*fadump_process)(struct fw_dump *fadump_conf); 1338c2ecf20Sopenharmony_ci void (*fadump_region_show)(struct fw_dump *fadump_conf, 1348c2ecf20Sopenharmony_ci struct seq_file *m); 1358c2ecf20Sopenharmony_ci void (*fadump_trigger)(struct fadump_crash_info_header *fdh, 1368c2ecf20Sopenharmony_ci const char *msg); 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* Helper functions */ 1408c2ecf20Sopenharmony_cis32 fadump_setup_cpu_notes_buf(u32 num_cpus); 1418c2ecf20Sopenharmony_civoid fadump_free_cpu_notes_buf(void); 1428c2ecf20Sopenharmony_ciu32 *fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs); 1438c2ecf20Sopenharmony_civoid fadump_update_elfcore_header(char *bufp); 1448c2ecf20Sopenharmony_cibool is_fadump_boot_mem_contiguous(void); 1458c2ecf20Sopenharmony_cibool is_fadump_reserved_mem_contiguous(void); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#else /* !CONFIG_PRESERVE_FA_DUMP */ 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Firmware-assisted dump configuration details. */ 1508c2ecf20Sopenharmony_cistruct fw_dump { 1518c2ecf20Sopenharmony_ci u64 boot_mem_top; 1528c2ecf20Sopenharmony_ci u64 dump_active; 1538c2ecf20Sopenharmony_ci}; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#endif /* CONFIG_PRESERVE_FA_DUMP */ 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES 1588c2ecf20Sopenharmony_ciextern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node); 1598c2ecf20Sopenharmony_ci#else 1608c2ecf20Sopenharmony_cistatic inline void 1618c2ecf20Sopenharmony_cirtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { } 1628c2ecf20Sopenharmony_ci#endif 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_POWERNV 1658c2ecf20Sopenharmony_ciextern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node); 1668c2ecf20Sopenharmony_ci#else 1678c2ecf20Sopenharmony_cistatic inline void 1688c2ecf20Sopenharmony_ciopal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { } 1698c2ecf20Sopenharmony_ci#endif 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */ 172