1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com> 4 * Copyright (C) 2011 Kees Cook <keescook@chromium.org> 5 * Copyright (C) 2011 Google, Inc. 6 */ 7 8 #ifndef __LINUX_PSTORE_RAM_H__ 9 #define __LINUX_PSTORE_RAM_H__ 10 11 #include <linux/compiler.h> 12 #include <linux/device.h> 13 #include <linux/init.h> 14 #include <linux/kernel.h> 15 #include <linux/list.h> 16 #include <linux/pstore.h> 17 #include <linux/types.h> 18 19 /* 20 * Choose whether access to the RAM zone requires locking or not. If a zone 21 * can be written to from different CPUs like with ftrace for example, then 22 * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required. 23 */ 24 #define PRZ_FLAG_NO_LOCK BIT(0) 25 /* 26 * If a PRZ should only have a single-boot lifetime, this marks it as 27 * getting wiped after its contents get copied out after boot. 28 */ 29 #define PRZ_FLAG_ZAP_OLD BIT(1) 30 31 struct persistent_ram_buffer; 32 struct rs_control; 33 34 struct persistent_ram_ecc_info { 35 int block_size; 36 int ecc_size; 37 int symsize; 38 int poly; 39 uint16_t *par; 40 }; 41 42 /** 43 * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ) 44 * used as a pstore backend 45 * 46 * @paddr: physical address of the mapped RAM area 47 * @size: size of mapping 48 * @label: unique name of this PRZ 49 * @type: frontend type for this PRZ 50 * @flags: holds PRZ_FLAGS_* bits 51 * 52 * @buffer_lock: 53 * locks access to @buffer "size" bytes and "start" offset 54 * @buffer: 55 * pointer to actual RAM area managed by this PRZ 56 * @buffer_size: 57 * bytes in @buffer->data (not including any trailing ECC bytes) 58 * 59 * @par_buffer: 60 * pointer into @buffer->data containing ECC bytes for @buffer->data 61 * @par_header: 62 * pointer into @buffer->data containing ECC bytes for @buffer header 63 * (i.e. all fields up to @data) 64 * @rs_decoder: 65 * RSLIB instance for doing ECC calculations 66 * @corrected_bytes: 67 * ECC corrected bytes accounting since boot 68 * @bad_blocks: 69 * ECC uncorrectable bytes accounting since boot 70 * @ecc_info: 71 * ECC configuration details 72 * 73 * @old_log: 74 * saved copy of @buffer->data prior to most recent wipe 75 * @old_log_size: 76 * bytes contained in @old_log 77 * 78 */ 79 struct persistent_ram_zone { 80 phys_addr_t paddr; 81 size_t size; 82 void *vaddr; 83 char *label; 84 enum pstore_type_id type; 85 u32 flags; 86 87 raw_spinlock_t buffer_lock; 88 struct persistent_ram_buffer *buffer; 89 size_t buffer_size; 90 91 char *par_buffer; 92 char *par_header; 93 struct rs_control *rs_decoder; 94 int corrected_bytes; 95 int bad_blocks; 96 struct persistent_ram_ecc_info ecc_info; 97 98 char *old_log; 99 size_t old_log_size; 100 }; 101 102 struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, 103 u32 sig, struct persistent_ram_ecc_info *ecc_info, 104 unsigned int memtype, u32 flags, char *label); 105 void persistent_ram_free(struct persistent_ram_zone *prz); 106 void persistent_ram_zap(struct persistent_ram_zone *prz); 107 108 int persistent_ram_write(struct persistent_ram_zone *prz, const void *s, 109 unsigned int count); 110 int persistent_ram_write_user(struct persistent_ram_zone *prz, 111 const void __user *s, unsigned int count); 112 113 void persistent_ram_save_old(struct persistent_ram_zone *prz); 114 size_t persistent_ram_old_size(struct persistent_ram_zone *prz); 115 void *persistent_ram_old(struct persistent_ram_zone *prz); 116 void persistent_ram_free_old(struct persistent_ram_zone *prz); 117 ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, 118 char *str, size_t len); 119 120 /* 121 * Ramoops platform data 122 * @mem_size memory size for ramoops 123 * @mem_address physical memory address to contain ramoops 124 */ 125 126 #define RAMOOPS_FLAG_FTRACE_PER_CPU BIT(0) 127 128 struct ramoops_platform_data { 129 unsigned long mem_size; 130 phys_addr_t mem_address; 131 unsigned int mem_type; 132 unsigned long record_size; 133 unsigned long console_size; 134 unsigned long ftrace_size; 135 unsigned long pmsg_size; 136 int max_reason; 137 u32 flags; 138 struct persistent_ram_ecc_info ecc_info; 139 }; 140 141 #endif 142