Commit | Line | Data |
---|---|---|
9c92ab61 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
cddb8751 AV |
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. | |
cddb8751 AV |
6 | */ |
7 | ||
1894a253 AV |
8 | #ifndef __LINUX_PSTORE_RAM_H__ |
9 | #define __LINUX_PSTORE_RAM_H__ | |
c3b92ce9 | 10 | |
5bf6d1b9 | 11 | #include <linux/compiler.h> |
cddb8751 | 12 | #include <linux/device.h> |
5bf6d1b9 | 13 | #include <linux/init.h> |
cddb8751 AV |
14 | #include <linux/kernel.h> |
15 | #include <linux/list.h> | |
f0f23e54 | 16 | #include <linux/pstore.h> |
cddb8751 | 17 | #include <linux/types.h> |
cddb8751 | 18 | |
663deb47 JF |
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) | |
c208f7d4 KC |
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 | */ | |
7684bd33 | 29 | #define PRZ_FLAG_ZAP_OLD BIT(1) |
663deb47 | 30 | |
cddb8751 | 31 | struct persistent_ram_buffer; |
67a101f5 | 32 | struct rs_control; |
cddb8751 | 33 | |
c31ad081 AH |
34 | struct persistent_ram_ecc_info { |
35 | int block_size; | |
36 | int ecc_size; | |
37 | int symsize; | |
38 | int poly; | |
f2531f19 | 39 | uint16_t *par; |
c31ad081 AH |
40 | }; |
41 | ||
c208f7d4 KC |
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 | |
f0f23e54 | 49 | * @type: frontend type for this PRZ |
c208f7d4 KC |
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 | */ | |
cddb8751 AV |
79 | struct persistent_ram_zone { |
80 | phys_addr_t paddr; | |
81 | size_t size; | |
82 | void *vaddr; | |
1227daa4 | 83 | char *label; |
f0f23e54 | 84 | enum pstore_type_id type; |
663deb47 | 85 | u32 flags; |
c208f7d4 | 86 | |
10970449 | 87 | raw_spinlock_t buffer_lock; |
c208f7d4 KC |
88 | struct persistent_ram_buffer *buffer; |
89 | size_t buffer_size; | |
cddb8751 | 90 | |
cddb8751 AV |
91 | char *par_buffer; |
92 | char *par_header; | |
93 | struct rs_control *rs_decoder; | |
94 | int corrected_bytes; | |
95 | int bad_blocks; | |
c31ad081 | 96 | struct persistent_ram_ecc_info ecc_info; |
cddb8751 AV |
97 | |
98 | char *old_log; | |
99 | size_t old_log_size; | |
100 | }; | |
101 | ||
f568f6ca | 102 | struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, |
027bc8b0 | 103 | u32 sig, struct persistent_ram_ecc_info *ecc_info, |
1227daa4 | 104 | unsigned int memtype, u32 flags, char *label); |
cddb8751 | 105 | void persistent_ram_free(struct persistent_ram_zone *prz); |
fce39793 | 106 | void persistent_ram_zap(struct persistent_ram_zone *prz); |
cddb8751 AV |
107 | |
108 | int persistent_ram_write(struct persistent_ram_zone *prz, const void *s, | |
5bf6d1b9 MS |
109 | unsigned int count); |
110 | int persistent_ram_write_user(struct persistent_ram_zone *prz, | |
111 | const void __user *s, unsigned int count); | |
cddb8751 | 112 | |
201e4aca | 113 | void persistent_ram_save_old(struct persistent_ram_zone *prz); |
cddb8751 AV |
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 | ||
c3b92ce9 KP |
120 | /* |
121 | * Ramoops platform data | |
122 | * @mem_size memory size for ramoops | |
123 | * @mem_address physical memory address to contain ramoops | |
124 | */ | |
125 | ||
a1cf53ac JF |
126 | #define RAMOOPS_FLAG_FTRACE_PER_CPU BIT(0) |
127 | ||
c3b92ce9 KP |
128 | struct ramoops_platform_data { |
129 | unsigned long mem_size; | |
764fd639 | 130 | phys_addr_t mem_address; |
027bc8b0 | 131 | unsigned int mem_type; |
3e5c4fad | 132 | unsigned long record_size; |
b5d38e9b | 133 | unsigned long console_size; |
a694d1b5 | 134 | unsigned long ftrace_size; |
9d5438f4 | 135 | unsigned long pmsg_size; |
6b4d2a27 | 136 | int dump_oops; |
a1cf53ac | 137 | u32 flags; |
c31ad081 | 138 | struct persistent_ram_ecc_info ecc_info; |
c3b92ce9 KP |
139 | }; |
140 | ||
141 | #endif |