Linux Audio

Check our new training course

Loading...
v6.9.4
  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/* Maximum number of memory regions kernel supports */
 13#define FADUMP_MAX_MEM_REGS			128
 14
 15#ifndef CONFIG_PRESERVE_FA_DUMP
 16
 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/* FAD commands */
 23#define FADUMP_REGISTER			1
 24#define FADUMP_UNREGISTER		2
 25#define FADUMP_INVALIDATE		3
 26
 27/*
 28 * Copy the ascii values for first 8 characters from a string into u64
 29 * variable at their respective indexes.
 30 * e.g.
 31 *  The string "FADMPINF" will be converted into 0x4641444d50494e46
 32 */
 33static inline u64 fadump_str_to_u64(const char *str)
 34{
 35	u64 val = 0;
 36	int i;
 37
 38	for (i = 0; i < sizeof(val); i++)
 39		val = (*str) ? (val << 8) | *str++ : val << 8;
 40	return val;
 41}
 42
 43#define FADUMP_CPU_UNKNOWN		(~((u32)0))
 44
 45#define FADUMP_CRASH_INFO_MAGIC		fadump_str_to_u64("FADMPINF")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 46
 47/* fadump crash info structure */
 48struct fadump_crash_info_header {
 49	u64		magic_number;
 50	u64		elfcorehdr_addr;
 51	u32		crashing_cpu;
 
 
 
 
 52	struct pt_regs	regs;
 53	struct cpumask	cpu_mask;
 54};
 55
 56struct fadump_memory_range {
 57	u64	base;
 58	u64	size;
 59};
 60
 61/* fadump memory ranges info */
 62#define RNG_NAME_SZ			16
 63struct fadump_mrange_info {
 64	char				name[RNG_NAME_SZ];
 65	struct fadump_memory_range	*mem_ranges;
 66	u32				mem_ranges_sz;
 67	u32				mem_range_cnt;
 68	u32				max_mem_ranges;
 69	bool				is_static;
 70};
 71
 72/* Platform specific callback functions */
 73struct fadump_ops;
 74
 75/* Firmware-assisted dump configuration details. */
 76struct fw_dump {
 77	unsigned long	reserve_dump_area_start;
 78	unsigned long	reserve_dump_area_size;
 79	/* cmd line option during boot */
 80	unsigned long	reserve_bootvar;
 81
 82	unsigned long	cpu_state_data_size;
 83	u64		cpu_state_dest_vaddr;
 84	u32		cpu_state_data_version;
 85	u32		cpu_state_entry_size;
 86
 87	unsigned long	hpte_region_size;
 88
 89	unsigned long	boot_memory_size;
 90	u64		boot_mem_dest_addr;
 91	u64		boot_mem_addr[FADUMP_MAX_MEM_REGS];
 92	u64		boot_mem_sz[FADUMP_MAX_MEM_REGS];
 93	u64		boot_mem_top;
 94	u64		boot_mem_regs_cnt;
 95
 96	unsigned long	fadumphdr_addr;
 
 
 97	unsigned long	cpu_notes_buf_vaddr;
 98	unsigned long	cpu_notes_buf_size;
 99
 
 
100	/*
101	 * Maximum size supported by firmware to copy from source to
102	 * destination address per entry.
103	 */
104	u64		max_copy_size;
105	u64		kernel_metadata;
106
107	int		ibm_configure_kernel_dump;
108
109	unsigned long	fadump_enabled:1;
110	unsigned long	fadump_supported:1;
111	unsigned long	dump_active:1;
112	unsigned long	dump_registered:1;
113	unsigned long	nocma:1;
 
114
115	struct fadump_ops	*ops;
116};
117
118struct fadump_ops {
119	u64	(*fadump_init_mem_struct)(struct fw_dump *fadump_conf);
120	u64	(*fadump_get_metadata_size)(void);
121	int	(*fadump_setup_metadata)(struct fw_dump *fadump_conf);
122	u64	(*fadump_get_bootmem_min)(void);
123	int	(*fadump_register)(struct fw_dump *fadump_conf);
124	int	(*fadump_unregister)(struct fw_dump *fadump_conf);
125	int	(*fadump_invalidate)(struct fw_dump *fadump_conf);
126	void	(*fadump_cleanup)(struct fw_dump *fadump_conf);
127	int	(*fadump_process)(struct fw_dump *fadump_conf);
128	void	(*fadump_region_show)(struct fw_dump *fadump_conf,
129				      struct seq_file *m);
130	void	(*fadump_trigger)(struct fadump_crash_info_header *fdh,
131				  const char *msg);
 
132};
133
134/* Helper functions */
135s32 __init fadump_setup_cpu_notes_buf(u32 num_cpus);
136void fadump_free_cpu_notes_buf(void);
137u32 *__init fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
138void __init fadump_update_elfcore_header(char *bufp);
139bool is_fadump_boot_mem_contiguous(void);
140bool is_fadump_reserved_mem_contiguous(void);
141
142#else /* !CONFIG_PRESERVE_FA_DUMP */
143
144/* Firmware-assisted dump configuration details. */
145struct fw_dump {
146	u64	boot_mem_top;
147	u64	dump_active;
148};
149
150#endif /* CONFIG_PRESERVE_FA_DUMP */
151
152#ifdef CONFIG_PPC_PSERIES
153extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
154#else
155static inline void
156rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
157#endif
158
159#ifdef CONFIG_PPC_POWERNV
160extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
161#else
162static inline void
163opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
164#endif
165
166#endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */
v6.13.7
  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/* Maximum number of memory regions kernel supports */
 13#define FADUMP_MAX_MEM_REGS			128
 14
 15#ifndef CONFIG_PRESERVE_FA_DUMP
 16
 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/* FAD commands */
 23#define FADUMP_REGISTER			1
 24#define FADUMP_UNREGISTER		2
 25#define FADUMP_INVALIDATE		3
 26
 27/*
 28 * Copy the ascii values for first 8 characters from a string into u64
 29 * variable at their respective indexes.
 30 * e.g.
 31 *  The string "FADMPINF" will be converted into 0x4641444d50494e46
 32 */
 33static inline u64 fadump_str_to_u64(const char *str)
 34{
 35	u64 val = 0;
 36	int i;
 37
 38	for (i = 0; i < sizeof(val); i++)
 39		val = (*str) ? (val << 8) | *str++ : val << 8;
 40	return val;
 41}
 42
 43#define FADUMP_CPU_UNKNOWN		(~((u32)0))
 44
 45/*
 46 * The introduction of new fields in the fadump crash info header has
 47 * led to a change in the magic key from `FADMPINF` to `FADMPSIG` for
 48 * identifying a kernel crash from an old kernel.
 49 *
 50 * To prevent the need for further changes to the magic number in the
 51 * event of future modifications to the fadump crash info header, a
 52 * version field has been introduced to track the fadump crash info
 53 * header version.
 54 *
 55 * Consider a few points before adding new members to the fadump crash info
 56 * header structure:
 57 *
 58 *  - Append new members; avoid adding them in between.
 59 *  - Non-primitive members should have a size member as well.
 60 *  - For every change in the fadump header, increment the
 61 *    fadump header version. This helps the updated kernel decide how to
 62 *    handle kernel dumps from older kernels.
 63 */
 64#define FADUMP_CRASH_INFO_MAGIC_OLD	fadump_str_to_u64("FADMPINF")
 65#define FADUMP_CRASH_INFO_MAGIC		fadump_str_to_u64("FADMPSIG")
 66#define FADUMP_HEADER_VERSION		1
 67
 68/* fadump crash info structure */
 69struct fadump_crash_info_header {
 70	u64		magic_number;
 71	u32		version;
 72	u32		crashing_cpu;
 73	u64		vmcoreinfo_raddr;
 74	u64		vmcoreinfo_size;
 75	u32		pt_regs_sz;
 76	u32		cpu_mask_sz;
 77	struct pt_regs	regs;
 78	struct cpumask	cpu_mask;
 79};
 80
 81struct fadump_memory_range {
 82	u64	base;
 83	u64	size;
 84};
 85
 86/* fadump memory ranges info */
 87#define RNG_NAME_SZ			16
 88struct fadump_mrange_info {
 89	char				name[RNG_NAME_SZ];
 90	struct fadump_memory_range	*mem_ranges;
 91	u32				mem_ranges_sz;
 92	u32				mem_range_cnt;
 93	u32				max_mem_ranges;
 94	bool				is_static;
 95};
 96
 97/* Platform specific callback functions */
 98struct fadump_ops;
 99
100/* Firmware-assisted dump configuration details. */
101struct fw_dump {
102	unsigned long	reserve_dump_area_start;
103	unsigned long	reserve_dump_area_size;
104	/* cmd line option during boot */
105	unsigned long	reserve_bootvar;
106
107	unsigned long	cpu_state_data_size;
108	u64		cpu_state_dest_vaddr;
109	u32		cpu_state_data_version;
110	u32		cpu_state_entry_size;
111
112	unsigned long	hpte_region_size;
113
114	unsigned long	boot_memory_size;
115	u64		boot_mem_dest_addr;
116	u64		boot_mem_addr[FADUMP_MAX_MEM_REGS];
117	u64		boot_mem_sz[FADUMP_MAX_MEM_REGS];
118	u64		boot_mem_top;
119	u64		boot_mem_regs_cnt;
120
121	unsigned long	fadumphdr_addr;
122	u64		elfcorehdr_addr;
123	u64		elfcorehdr_size;
124	unsigned long	cpu_notes_buf_vaddr;
125	unsigned long	cpu_notes_buf_size;
126
127	unsigned long	param_area;
128
129	/*
130	 * Maximum size supported by firmware to copy from source to
131	 * destination address per entry.
132	 */
133	u64		max_copy_size;
134	u64		kernel_metadata;
135
136	int		ibm_configure_kernel_dump;
137
138	unsigned long	fadump_enabled:1;
139	unsigned long	fadump_supported:1;
140	unsigned long	dump_active:1;
141	unsigned long	dump_registered:1;
142	unsigned long	nocma:1;
143	unsigned long	param_area_supported:1;
144
145	struct fadump_ops	*ops;
146};
147
148struct fadump_ops {
149	u64	(*fadump_init_mem_struct)(struct fw_dump *fadump_conf);
150	u64	(*fadump_get_metadata_size)(void);
151	int	(*fadump_setup_metadata)(struct fw_dump *fadump_conf);
152	u64	(*fadump_get_bootmem_min)(void);
153	int	(*fadump_register)(struct fw_dump *fadump_conf);
154	int	(*fadump_unregister)(struct fw_dump *fadump_conf);
155	int	(*fadump_invalidate)(struct fw_dump *fadump_conf);
156	void	(*fadump_cleanup)(struct fw_dump *fadump_conf);
157	int	(*fadump_process)(struct fw_dump *fadump_conf);
158	void	(*fadump_region_show)(struct fw_dump *fadump_conf,
159				      struct seq_file *m);
160	void	(*fadump_trigger)(struct fadump_crash_info_header *fdh,
161				  const char *msg);
162	int	(*fadump_max_boot_mem_rgns)(void);
163};
164
165/* Helper functions */
166s32 __init fadump_setup_cpu_notes_buf(u32 num_cpus);
167void fadump_free_cpu_notes_buf(void);
168u32 *__init fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
169void __init fadump_update_elfcore_header(char *bufp);
 
170bool is_fadump_reserved_mem_contiguous(void);
171
172#else /* !CONFIG_PRESERVE_FA_DUMP */
173
174/* Firmware-assisted dump configuration details. */
175struct fw_dump {
176	u64	boot_mem_top;
177	u64	dump_active;
178};
179
180#endif /* CONFIG_PRESERVE_FA_DUMP */
181
182#ifdef CONFIG_PPC_PSERIES
183extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
184#else
185static inline void
186rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
187#endif
188
189#ifdef CONFIG_PPC_POWERNV
190extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
191#else
192static inline void
193opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
194#endif
195
196#endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */