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