blob: c814a2b55389325393d8edfbfed5411d6bc2e039 [file] [log] [blame]
Hari Bathinica986d72019-09-11 20:16:21 +05301/* 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 Bathini7dee93a2019-09-11 20:27:39 +053012/* Maximum number of memory regions kernel supports */
13#define FADUMP_MAX_MEM_REGS 128
14
Hari Bathinibec53192019-09-11 20:26:03 +053015#ifndef CONFIG_PRESERVE_FA_DUMP
Hari Bathinica986d72019-09-11 20:16:21 +053016
Hari Bathinica986d72019-09-11 20:16:21 +053017/* 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 Bathini0226e552019-09-11 20:18:14 +053032/*
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 */
38static 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 Bathinica986d72019-09-11 20:16:21 +053051
52/* fadump crash info structure */
53struct 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 Bathinie4fc48f2019-09-11 20:25:05 +053061struct fadump_memory_range {
62 u64 base;
63 u64 size;
64};
65
66/* fadump memory ranges info */
67struct fadump_mrange_info {
68 char name[16];
69 struct fadump_memory_range *mem_ranges;
70 u32 mem_ranges_sz;
71 u32 mem_range_cnt;
72 u32 max_mem_ranges;
Hari Bathinica986d72019-09-11 20:16:21 +053073};
74
Hari Bathinid3833a72019-09-11 20:18:40 +053075/* Platform specific callback functions */
76struct fadump_ops;
77
Hari Bathinica986d72019-09-11 20:16:21 +053078/* Firmware-assisted dump configuration details. */
79struct fw_dump {
80 unsigned long reserve_dump_area_start;
81 unsigned long reserve_dump_area_size;
82 /* cmd line option during boot */
83 unsigned long reserve_bootvar;
84
85 unsigned long cpu_state_data_size;
Hari Bathini5000a172019-09-11 20:24:50 +053086 u64 cpu_state_dest_vaddr;
87 u32 cpu_state_data_version;
88 u32 cpu_state_entry_size;
89
Hari Bathinica986d72019-09-11 20:16:21 +053090 unsigned long hpte_region_size;
Hari Bathini41a65d12019-09-11 20:18:57 +053091
Hari Bathinica986d72019-09-11 20:16:21 +053092 unsigned long boot_memory_size;
Hari Bathini41a65d12019-09-11 20:18:57 +053093 u64 boot_mem_dest_addr;
Hari Bathini7dee93a2019-09-11 20:27:39 +053094 u64 boot_mem_addr[FADUMP_MAX_MEM_REGS];
95 u64 boot_mem_sz[FADUMP_MAX_MEM_REGS];
96 u64 boot_mem_top;
97 u64 boot_mem_regs_cnt;
Hari Bathinica986d72019-09-11 20:16:21 +053098
99 unsigned long fadumphdr_addr;
Hari Bathini961cf262019-09-11 20:16:36 +0530100 unsigned long cpu_notes_buf_vaddr;
Hari Bathinica986d72019-09-11 20:16:21 +0530101 unsigned long cpu_notes_buf_size;
102
Hari Bathini7dee93a2019-09-11 20:27:39 +0530103 /*
104 * Maximum size supported by firmware to copy from source to
105 * destination address per entry.
106 */
107 u64 max_copy_size;
Hari Bathini742a2652019-09-11 20:20:57 +0530108 u64 kernel_metadata;
109
Hari Bathinica986d72019-09-11 20:16:21 +0530110 int ibm_configure_kernel_dump;
111
112 unsigned long fadump_enabled:1;
113 unsigned long fadump_supported:1;
114 unsigned long dump_active:1;
115 unsigned long dump_registered:1;
116 unsigned long nocma:1;
Hari Bathinid3833a72019-09-11 20:18:40 +0530117
118 struct fadump_ops *ops;
119};
120
121struct fadump_ops {
122 u64 (*fadump_init_mem_struct)(struct fw_dump *fadump_conf);
Hari Bathini742a2652019-09-11 20:20:57 +0530123 u64 (*fadump_get_metadata_size)(void);
124 int (*fadump_setup_metadata)(struct fw_dump *fadump_conf);
Hari Bathini7b1b3b42019-09-11 20:26:59 +0530125 u64 (*fadump_get_bootmem_min)(void);
Hari Bathinid3833a72019-09-11 20:18:40 +0530126 int (*fadump_register)(struct fw_dump *fadump_conf);
127 int (*fadump_unregister)(struct fw_dump *fadump_conf);
128 int (*fadump_invalidate)(struct fw_dump *fadump_conf);
Hari Bathini2790d012019-09-11 20:21:16 +0530129 void (*fadump_cleanup)(struct fw_dump *fadump_conf);
Hari Bathinid3833a72019-09-11 20:18:40 +0530130 int (*fadump_process)(struct fw_dump *fadump_conf);
131 void (*fadump_region_show)(struct fw_dump *fadump_conf,
132 struct seq_file *m);
133 void (*fadump_trigger)(struct fadump_crash_info_header *fdh,
134 const char *msg);
Hari Bathinica986d72019-09-11 20:16:21 +0530135};
136
Hari Bathini7f0ad112019-09-11 20:16:52 +0530137/* Helper functions */
138s32 fadump_setup_cpu_notes_buf(u32 num_cpus);
139void fadump_free_cpu_notes_buf(void);
140u32 *fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
141void fadump_update_elfcore_header(char *bufp);
142bool is_fadump_boot_mem_contiguous(void);
143bool is_fadump_reserved_mem_contiguous(void);
144
Hari Bathinibec53192019-09-11 20:26:03 +0530145#else /* !CONFIG_PRESERVE_FA_DUMP */
146
147/* Firmware-assisted dump configuration details. */
148struct fw_dump {
149 u64 boot_mem_top;
150 u64 dump_active;
151};
152
153#endif /* CONFIG_PRESERVE_FA_DUMP */
154
Hari Bathinid3833a72019-09-11 20:18:40 +0530155#ifdef CONFIG_PPC_PSERIES
156extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
157#else
158static inline void
159rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
160#endif
161
Hari Bathini41df5922019-09-11 20:20:26 +0530162#ifdef CONFIG_PPC_POWERNV
163extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
164#else
165static inline void
166opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
167#endif
168
Hari Bathinica986d72019-09-11 20:16:21 +0530169#endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */