cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

fadump-internal.h (4370B)


      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 */