Commit | Line | Data |
---|---|---|
ca01d6dd TL |
1 | /* |
2 | * Persistent Storage - pstore.h | |
3 | * | |
4 | * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com> | |
5 | * | |
6 | * This code is the generic layer to export data records from platform | |
7 | * level persistent storage via a file system. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
22 | #ifndef _LINUX_PSTORE_H | |
23 | #define _LINUX_PSTORE_H | |
24 | ||
5bf6d1b9 MS |
25 | #include <linux/compiler.h> |
26 | #include <linux/errno.h> | |
3d6d8d20 | 27 | #include <linux/kmsg_dump.h> |
67a101f5 | 28 | #include <linux/mutex.h> |
67a101f5 | 29 | #include <linux/spinlock.h> |
5bf6d1b9 MS |
30 | #include <linux/time.h> |
31 | #include <linux/types.h> | |
3d6d8d20 | 32 | |
0edae0b3 | 33 | /* pstore record types (see fs/pstore/inode.c for filename templates) */ |
ca01d6dd TL |
34 | enum pstore_type_id { |
35 | PSTORE_TYPE_DMESG = 0, | |
36 | PSTORE_TYPE_MCE = 1, | |
f29e5956 | 37 | PSTORE_TYPE_CONSOLE = 2, |
060287b8 | 38 | PSTORE_TYPE_FTRACE = 3, |
69020eea AB |
39 | /* PPC64 partition types */ |
40 | PSTORE_TYPE_PPC_RTAS = 4, | |
f33f748c | 41 | PSTORE_TYPE_PPC_OF = 5, |
a5e4797b | 42 | PSTORE_TYPE_PPC_COMMON = 6, |
9d5438f4 | 43 | PSTORE_TYPE_PMSG = 7, |
ae011d2e | 44 | PSTORE_TYPE_PPC_OPAL = 8, |
ca01d6dd TL |
45 | PSTORE_TYPE_UNKNOWN = 255 |
46 | }; | |
47 | ||
67a101f5 AV |
48 | struct module; |
49 | ||
0edae0b3 KC |
50 | /** |
51 | * struct pstore_info - backend pstore driver structure | |
52 | * | |
53 | * @owner: module which is repsonsible for this backend driver | |
54 | * @name: name of the backend driver | |
55 | * | |
56 | * @buf_lock: spinlock to serialize access to @buf | |
57 | * @buf: preallocated crash dump buffer | |
58 | * @bufsize: size of @buf available for crash dump writes | |
59 | * | |
60 | * @read_mutex: serializes @open, @read, @close, and @erase callbacks | |
61 | * @flags: bitfield of frontends the backend can accept writes for | |
62 | * @data: backend-private pointer passed back during callbacks | |
63 | * | |
64 | * Callbacks: | |
65 | * | |
66 | * @open: | |
67 | * Notify backend that pstore is starting a full read of backend | |
68 | * records. Followed by one or more @read calls, and a final @close. | |
69 | * | |
70 | * @psi: in: pointer to the struct pstore_info for the backend | |
71 | * | |
72 | * Returns 0 on success, and non-zero on error. | |
73 | * | |
74 | * @close: | |
75 | * Notify backend that pstore has finished a full read of backend | |
76 | * records. Always preceded by an @open call and one or more @read | |
77 | * calls. | |
78 | * | |
79 | * @psi: in: pointer to the struct pstore_info for the backend | |
80 | * | |
81 | * Returns 0 on success, and non-zero on error. (Though pstore will | |
82 | * ignore the error.) | |
83 | * | |
84 | * @read: | |
85 | * Read next available backend record. Called after a successful | |
86 | * @open. | |
87 | * | |
88 | * @id: out: unique identifier for the record | |
89 | * @type: out: pstore record type | |
90 | * @count: out: for PSTORE_TYPE_DMESG, the Oops count. | |
91 | * @time: out: timestamp for the record | |
92 | * @buf: out: kmalloc copy of record contents, to be freed by pstore | |
93 | * @compressed: | |
94 | * out: if the record contents are compressed | |
95 | * @ecc_notice_size: | |
96 | * out: ECC information | |
97 | * @psi: in: pointer to the struct pstore_info for the backend | |
98 | * | |
99 | * Returns record size on success, zero when no more records are | |
100 | * available, or negative on error. | |
101 | * | |
102 | * @write: | |
103 | * Perform a frontend notification of a write to a backend record. The | |
104 | * data to be stored has already been written to the registered @buf | |
105 | * of the @psi structure. | |
106 | * | |
107 | * @type: in: pstore record type to write | |
108 | * @reason: | |
109 | * in: pstore write reason | |
110 | * @id: out: unique identifier for the record | |
111 | * @part: in: position in a multipart write | |
112 | * @count: in: increasing from 0 since boot, the number of this Oops | |
113 | * @compressed: | |
114 | * in: if the record is compressed | |
115 | * @size: in: size of the write | |
116 | * @psi: in: pointer to the struct pstore_info for the backend | |
117 | * | |
118 | * Returns 0 on success, and non-zero on error. | |
119 | * | |
120 | * @write_buf: | |
121 | * Perform a frontend write to a backend record, using a specified | |
122 | * buffer. Unlike @write, this does not use the @psi @buf. | |
123 | * | |
124 | * @type: in: pstore record type to write | |
125 | * @reason: | |
126 | * in: pstore write reason | |
127 | * @id: out: unique identifier for the record | |
128 | * @part: in: position in a multipart write | |
129 | * @buf: in: pointer to contents to write to backend record | |
130 | * @compressed: | |
131 | * in: if the record is compressed | |
132 | * @size: in: size of the write | |
133 | * @psi: in: pointer to the struct pstore_info for the backend | |
134 | * | |
135 | * Returns 0 on success, and non-zero on error. | |
136 | * | |
137 | * @write_buf_user: | |
138 | * Perform a frontend write to a backend record, using a specified | |
139 | * buffer that is coming directly from userspace. | |
140 | * | |
141 | * @type: in: pstore record type to write | |
142 | * @reason: | |
143 | * in: pstore write reason | |
144 | * @id: out: unique identifier for the record | |
145 | * @part: in: position in a multipart write | |
146 | * @buf: in: pointer to userspace contents to write to backend record | |
147 | * @compressed: | |
148 | * in: if the record is compressed | |
149 | * @size: in: size of the write | |
150 | * @psi: in: pointer to the struct pstore_info for the backend | |
151 | * | |
152 | * Returns 0 on success, and non-zero on error. | |
153 | * | |
154 | * @erase: | |
155 | * Delete a record from backend storage. Different backends | |
156 | * identify records differently, so all possible methods of | |
157 | * identification are included to help the backend locate the | |
158 | * record to remove. | |
159 | * | |
160 | * @type: in: pstore record type to write | |
161 | * @id: in: per-type unique identifier for the record | |
162 | * @count: in: Oops count | |
163 | * @time: in: timestamp for the record | |
164 | * @psi: in: pointer to the struct pstore_info for the backend | |
165 | * | |
166 | * Returns 0 on success, and non-zero on error. | |
167 | * | |
168 | */ | |
ca01d6dd TL |
169 | struct pstore_info { |
170 | struct module *owner; | |
171 | char *name; | |
0edae0b3 KC |
172 | |
173 | spinlock_t buf_lock; | |
ca01d6dd TL |
174 | char *buf; |
175 | size_t bufsize; | |
0edae0b3 KC |
176 | |
177 | struct mutex read_mutex; | |
178 | ||
df36ac1b | 179 | int flags; |
0edae0b3 KC |
180 | void *data; |
181 | ||
06cf91b4 CG |
182 | int (*open)(struct pstore_info *psi); |
183 | int (*close)(struct pstore_info *psi); | |
8d38d74b | 184 | ssize_t (*read)(u64 *id, enum pstore_type_id *type, |
755d4fe4 | 185 | int *count, struct timespec *time, char **buf, |
8cfc8ddc GT |
186 | bool *compressed, ssize_t *ecc_notice_size, |
187 | struct pstore_info *psi); | |
3d6d8d20 KC |
188 | int (*write)(enum pstore_type_id type, |
189 | enum kmsg_dump_reason reason, u64 *id, | |
b3b515bb | 190 | unsigned int part, int count, bool compressed, |
6bbbca73 | 191 | size_t size, struct pstore_info *psi); |
897dba02 AV |
192 | int (*write_buf)(enum pstore_type_id type, |
193 | enum kmsg_dump_reason reason, u64 *id, | |
b3b515bb | 194 | unsigned int part, const char *buf, bool compressed, |
6bbbca73 | 195 | size_t size, struct pstore_info *psi); |
5bf6d1b9 MS |
196 | int (*write_buf_user)(enum pstore_type_id type, |
197 | enum kmsg_dump_reason reason, u64 *id, | |
198 | unsigned int part, const char __user *buf, | |
199 | bool compressed, size_t size, struct pstore_info *psi); | |
56280682 | 200 | int (*erase)(enum pstore_type_id type, u64 id, |
755d4fe4 SA |
201 | int count, struct timespec time, |
202 | struct pstore_info *psi); | |
ca01d6dd TL |
203 | }; |
204 | ||
0edae0b3 | 205 | /* Supported frontends */ |
c950fd6f | 206 | #define PSTORE_FLAGS_DMESG (1 << 0) |
c950fd6f NK |
207 | #define PSTORE_FLAGS_CONSOLE (1 << 1) |
208 | #define PSTORE_FLAGS_FTRACE (1 << 2) | |
209 | #define PSTORE_FLAGS_PMSG (1 << 3) | |
210 | ||
ca01d6dd | 211 | extern int pstore_register(struct pstore_info *); |
ee1d2674 | 212 | extern void pstore_unregister(struct pstore_info *); |
9f244e9c | 213 | extern bool pstore_cannot_block_path(enum kmsg_dump_reason reason); |
ca01d6dd | 214 | |
fbccdeb8 JF |
215 | struct pstore_ftrace_record { |
216 | unsigned long ip; | |
217 | unsigned long parent_ip; | |
218 | u64 ts; | |
219 | }; | |
220 | ||
221 | /* | |
222 | * ftrace related stuff: Both backends and frontends need these so expose | |
223 | * them here. | |
224 | */ | |
225 | ||
226 | #if NR_CPUS <= 2 && defined(CONFIG_ARM_THUMB) | |
227 | #define PSTORE_CPU_IN_IP 0x1 | |
228 | #elif NR_CPUS <= 4 && defined(CONFIG_ARM) | |
229 | #define PSTORE_CPU_IN_IP 0x3 | |
230 | #endif | |
231 | ||
232 | #define TS_CPU_SHIFT 8 | |
233 | #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1) | |
234 | ||
235 | /* | |
236 | * If CPU number can be stored in IP, store it there, otherwise store it in | |
237 | * the time stamp. This means more timestamp resolution is available when | |
238 | * the CPU can be stored in the IP. | |
239 | */ | |
240 | #ifdef PSTORE_CPU_IN_IP | |
241 | static inline void | |
242 | pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu) | |
243 | { | |
244 | rec->ip |= cpu; | |
245 | } | |
246 | ||
247 | static inline unsigned int | |
248 | pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) | |
249 | { | |
250 | return rec->ip & PSTORE_CPU_IN_IP; | |
251 | } | |
252 | ||
253 | static inline u64 | |
254 | pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec) | |
255 | { | |
256 | return rec->ts; | |
257 | } | |
258 | ||
259 | static inline void | |
260 | pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) | |
261 | { | |
262 | rec->ts = val; | |
263 | } | |
264 | #else | |
265 | static inline void | |
266 | pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu) | |
267 | { | |
268 | rec->ts &= ~(TS_CPU_MASK); | |
269 | rec->ts |= cpu; | |
270 | } | |
271 | ||
272 | static inline unsigned int | |
273 | pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) | |
274 | { | |
275 | return rec->ts & TS_CPU_MASK; | |
276 | } | |
277 | ||
278 | static inline u64 | |
279 | pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec) | |
280 | { | |
281 | return rec->ts >> TS_CPU_SHIFT; | |
282 | } | |
283 | ||
284 | static inline void | |
285 | pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) | |
286 | { | |
287 | rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT); | |
288 | } | |
289 | #endif | |
290 | ||
ca01d6dd | 291 | #endif /*_LINUX_PSTORE_H*/ |