xref: /linux/fs/pstore/ram_internal.h (revision 8bd4da0f0626ae9a82099d3d99cd6efd4355879b)
1*8bd4da0fSKees Cook /* SPDX-License-Identifier: GPL-2.0-only */
2*8bd4da0fSKees Cook /*
3*8bd4da0fSKees Cook  * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
4*8bd4da0fSKees Cook  * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
5*8bd4da0fSKees Cook  * Copyright (C) 2011 Google, Inc.
6*8bd4da0fSKees Cook  */
7*8bd4da0fSKees Cook 
8*8bd4da0fSKees Cook #include <linux/pstore_ram.h>
9*8bd4da0fSKees Cook 
10*8bd4da0fSKees Cook /*
11*8bd4da0fSKees Cook  * Choose whether access to the RAM zone requires locking or not.  If a zone
12*8bd4da0fSKees Cook  * can be written to from different CPUs like with ftrace for example, then
13*8bd4da0fSKees Cook  * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required.
14*8bd4da0fSKees Cook  */
15*8bd4da0fSKees Cook #define PRZ_FLAG_NO_LOCK	BIT(0)
16*8bd4da0fSKees Cook /*
17*8bd4da0fSKees Cook  * If a PRZ should only have a single-boot lifetime, this marks it as
18*8bd4da0fSKees Cook  * getting wiped after its contents get copied out after boot.
19*8bd4da0fSKees Cook  */
20*8bd4da0fSKees Cook #define PRZ_FLAG_ZAP_OLD	BIT(1)
21*8bd4da0fSKees Cook 
22*8bd4da0fSKees Cook /**
23*8bd4da0fSKees Cook  * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ)
24*8bd4da0fSKees Cook  *                              used as a pstore backend
25*8bd4da0fSKees Cook  *
26*8bd4da0fSKees Cook  * @paddr:	physical address of the mapped RAM area
27*8bd4da0fSKees Cook  * @size:	size of mapping
28*8bd4da0fSKees Cook  * @label:	unique name of this PRZ
29*8bd4da0fSKees Cook  * @type:	frontend type for this PRZ
30*8bd4da0fSKees Cook  * @flags:	holds PRZ_FLAGS_* bits
31*8bd4da0fSKees Cook  *
32*8bd4da0fSKees Cook  * @buffer_lock:
33*8bd4da0fSKees Cook  *	locks access to @buffer "size" bytes and "start" offset
34*8bd4da0fSKees Cook  * @buffer:
35*8bd4da0fSKees Cook  *	pointer to actual RAM area managed by this PRZ
36*8bd4da0fSKees Cook  * @buffer_size:
37*8bd4da0fSKees Cook  *	bytes in @buffer->data (not including any trailing ECC bytes)
38*8bd4da0fSKees Cook  *
39*8bd4da0fSKees Cook  * @par_buffer:
40*8bd4da0fSKees Cook  *	pointer into @buffer->data containing ECC bytes for @buffer->data
41*8bd4da0fSKees Cook  * @par_header:
42*8bd4da0fSKees Cook  *	pointer into @buffer->data containing ECC bytes for @buffer header
43*8bd4da0fSKees Cook  *	(i.e. all fields up to @data)
44*8bd4da0fSKees Cook  * @rs_decoder:
45*8bd4da0fSKees Cook  *	RSLIB instance for doing ECC calculations
46*8bd4da0fSKees Cook  * @corrected_bytes:
47*8bd4da0fSKees Cook  *	ECC corrected bytes accounting since boot
48*8bd4da0fSKees Cook  * @bad_blocks:
49*8bd4da0fSKees Cook  *	ECC uncorrectable bytes accounting since boot
50*8bd4da0fSKees Cook  * @ecc_info:
51*8bd4da0fSKees Cook  *	ECC configuration details
52*8bd4da0fSKees Cook  *
53*8bd4da0fSKees Cook  * @old_log:
54*8bd4da0fSKees Cook  *	saved copy of @buffer->data prior to most recent wipe
55*8bd4da0fSKees Cook  * @old_log_size:
56*8bd4da0fSKees Cook  *	bytes contained in @old_log
57*8bd4da0fSKees Cook  *
58*8bd4da0fSKees Cook  */
59*8bd4da0fSKees Cook struct persistent_ram_zone {
60*8bd4da0fSKees Cook 	phys_addr_t paddr;
61*8bd4da0fSKees Cook 	size_t size;
62*8bd4da0fSKees Cook 	void *vaddr;
63*8bd4da0fSKees Cook 	char *label;
64*8bd4da0fSKees Cook 	enum pstore_type_id type;
65*8bd4da0fSKees Cook 	u32 flags;
66*8bd4da0fSKees Cook 
67*8bd4da0fSKees Cook 	raw_spinlock_t buffer_lock;
68*8bd4da0fSKees Cook 	struct persistent_ram_buffer *buffer;
69*8bd4da0fSKees Cook 	size_t buffer_size;
70*8bd4da0fSKees Cook 
71*8bd4da0fSKees Cook 	char *par_buffer;
72*8bd4da0fSKees Cook 	char *par_header;
73*8bd4da0fSKees Cook 	struct rs_control *rs_decoder;
74*8bd4da0fSKees Cook 	int corrected_bytes;
75*8bd4da0fSKees Cook 	int bad_blocks;
76*8bd4da0fSKees Cook 	struct persistent_ram_ecc_info ecc_info;
77*8bd4da0fSKees Cook 
78*8bd4da0fSKees Cook 	char *old_log;
79*8bd4da0fSKees Cook 	size_t old_log_size;
80*8bd4da0fSKees Cook };
81*8bd4da0fSKees Cook 
82*8bd4da0fSKees Cook struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
83*8bd4da0fSKees Cook 			u32 sig, struct persistent_ram_ecc_info *ecc_info,
84*8bd4da0fSKees Cook 			unsigned int memtype, u32 flags, char *label);
85*8bd4da0fSKees Cook void persistent_ram_free(struct persistent_ram_zone *prz);
86*8bd4da0fSKees Cook void persistent_ram_zap(struct persistent_ram_zone *prz);
87*8bd4da0fSKees Cook 
88*8bd4da0fSKees Cook int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
89*8bd4da0fSKees Cook 			 unsigned int count);
90*8bd4da0fSKees Cook int persistent_ram_write_user(struct persistent_ram_zone *prz,
91*8bd4da0fSKees Cook 			      const void __user *s, unsigned int count);
92*8bd4da0fSKees Cook 
93*8bd4da0fSKees Cook void persistent_ram_save_old(struct persistent_ram_zone *prz);
94*8bd4da0fSKees Cook size_t persistent_ram_old_size(struct persistent_ram_zone *prz);
95*8bd4da0fSKees Cook void *persistent_ram_old(struct persistent_ram_zone *prz);
96*8bd4da0fSKees Cook void persistent_ram_free_old(struct persistent_ram_zone *prz);
97*8bd4da0fSKees Cook ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
98*8bd4da0fSKees Cook 	char *str, size_t len);
99