xref: /OK3568_Linux_fs/kernel/include/linux/pstore_ram.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 #ifdef CONFIG_PSTORE_BOOT_LOG
120 ssize_t ramoops_pstore_read_for_boot_log(struct pstore_record *record);
121 #endif
122 
123 /*
124  * Ramoops platform data
125  * @mem_size	memory size for ramoops
126  * @mem_address	physical memory address to contain ramoops
127  */
128 
129 #define RAMOOPS_FLAG_FTRACE_PER_CPU	BIT(0)
130 
131 struct ramoops_platform_data {
132 	unsigned long	mem_size;
133 	phys_addr_t	mem_address;
134 	unsigned int	mem_type;
135 	unsigned long	record_size;
136 	unsigned long	console_size;
137 	unsigned long	ftrace_size;
138 	unsigned long	pmsg_size;
139 #ifdef CONFIG_PSTORE_BOOT_LOG
140 	unsigned long	boot_log_size;
141 	unsigned long	max_boot_log_cnt;
142 #endif
143 	int		max_reason;
144 	u32		flags;
145 	struct persistent_ram_ecc_info ecc_info;
146 };
147 
148 #endif
149