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