powerpc/fadump: consider f/w load area
[linux-2.6-block.git] / arch / powerpc / include / asm / fadump-internal.h
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
12 #ifndef CONFIG_PRESERVE_FA_DUMP
13 /*
14  * The RMA region will be saved for later dumping when kernel crashes.
15  * RMA is Real Mode Area, the first block of logical memory address owned
16  * by logical partition, containing the storage that may be accessed with
17  * translate off.
18  */
19 #define RMA_START       0x0
20 #define RMA_END         (ppc64_rma_size)
21
22 /* The upper limit percentage for user specified boot memory size (25%) */
23 #define MAX_BOOT_MEM_RATIO                      4
24
25 #define memblock_num_regions(memblock_type)     (memblock.memblock_type.cnt)
26
27 /* Alignment per CMA requirement. */
28 #define FADUMP_CMA_ALIGNMENT    (PAGE_SIZE <<                           \
29                                  max_t(unsigned long, MAX_ORDER - 1,    \
30                                  pageblock_order))
31
32 /* FAD commands */
33 #define FADUMP_REGISTER                 1
34 #define FADUMP_UNREGISTER               2
35 #define FADUMP_INVALIDATE               3
36
37 /*
38  * Copy the ascii values for first 8 characters from a string into u64
39  * variable at their respective indexes.
40  * e.g.
41  *  The string "FADMPINF" will be converted into 0x4641444d50494e46
42  */
43 static inline u64 fadump_str_to_u64(const char *str)
44 {
45         u64 val = 0;
46         int i;
47
48         for (i = 0; i < sizeof(val); i++)
49                 val = (*str) ? (val << 8) | *str++ : val << 8;
50         return val;
51 }
52
53 #define FADUMP_CPU_UNKNOWN              (~((u32)0))
54
55 #define FADUMP_CRASH_INFO_MAGIC         fadump_str_to_u64("FADMPINF")
56
57 /* fadump crash info structure */
58 struct fadump_crash_info_header {
59         u64             magic_number;
60         u64             elfcorehdr_addr;
61         u32             crashing_cpu;
62         struct pt_regs  regs;
63         struct cpumask  online_mask;
64 };
65
66 struct fadump_memory_range {
67         u64     base;
68         u64     size;
69 };
70
71 /* fadump memory ranges info */
72 struct fadump_mrange_info {
73         char                            name[16];
74         struct fadump_memory_range      *mem_ranges;
75         u32                             mem_ranges_sz;
76         u32                             mem_range_cnt;
77         u32                             max_mem_ranges;
78 };
79
80 /* Platform specific callback functions */
81 struct fadump_ops;
82
83 /* Firmware-assisted dump configuration details. */
84 struct fw_dump {
85         unsigned long   reserve_dump_area_start;
86         unsigned long   reserve_dump_area_size;
87         /* cmd line option during boot */
88         unsigned long   reserve_bootvar;
89
90         unsigned long   cpu_state_data_size;
91         u64             cpu_state_dest_vaddr;
92         u32             cpu_state_data_version;
93         u32             cpu_state_entry_size;
94
95         unsigned long   hpte_region_size;
96
97         unsigned long   boot_memory_size;
98         u64             boot_mem_dest_addr;
99
100         unsigned long   fadumphdr_addr;
101         unsigned long   cpu_notes_buf_vaddr;
102         unsigned long   cpu_notes_buf_size;
103
104         u64             kernel_metadata;
105
106         int             ibm_configure_kernel_dump;
107
108         unsigned long   fadump_enabled:1;
109         unsigned long   fadump_supported:1;
110         unsigned long   dump_active:1;
111         unsigned long   dump_registered:1;
112         unsigned long   nocma:1;
113
114         struct fadump_ops       *ops;
115 };
116
117 struct fadump_ops {
118         u64     (*fadump_init_mem_struct)(struct fw_dump *fadump_conf);
119         u64     (*fadump_get_metadata_size)(void);
120         int     (*fadump_setup_metadata)(struct fw_dump *fadump_conf);
121         u64     (*fadump_get_bootmem_min)(void);
122         int     (*fadump_register)(struct fw_dump *fadump_conf);
123         int     (*fadump_unregister)(struct fw_dump *fadump_conf);
124         int     (*fadump_invalidate)(struct fw_dump *fadump_conf);
125         void    (*fadump_cleanup)(struct fw_dump *fadump_conf);
126         int     (*fadump_process)(struct fw_dump *fadump_conf);
127         void    (*fadump_region_show)(struct fw_dump *fadump_conf,
128                                       struct seq_file *m);
129         void    (*fadump_trigger)(struct fadump_crash_info_header *fdh,
130                                   const char *msg);
131 };
132
133 /* Helper functions */
134 s32 fadump_setup_cpu_notes_buf(u32 num_cpus);
135 void fadump_free_cpu_notes_buf(void);
136 u32 *fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
137 void fadump_update_elfcore_header(char *bufp);
138 bool is_fadump_boot_mem_contiguous(void);
139 bool is_fadump_reserved_mem_contiguous(void);
140
141 #else /* !CONFIG_PRESERVE_FA_DUMP */
142
143 /* Firmware-assisted dump configuration details. */
144 struct fw_dump {
145         u64     boot_mem_top;
146         u64     dump_active;
147 };
148
149 #endif /* CONFIG_PRESERVE_FA_DUMP */
150
151 #ifdef CONFIG_PPC_PSERIES
152 extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
153 #else
154 static inline void
155 rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
156 #endif
157
158 #ifdef CONFIG_PPC_POWERNV
159 extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
160 #else
161 static inline void
162 opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
163 #endif
164
165 #endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */