]>
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 | |
9abdcccc KC |
33 | struct module; |
34 | ||
0edae0b3 | 35 | /* pstore record types (see fs/pstore/inode.c for filename templates) */ |
ca01d6dd TL |
36 | enum pstore_type_id { |
37 | PSTORE_TYPE_DMESG = 0, | |
38 | PSTORE_TYPE_MCE = 1, | |
f29e5956 | 39 | PSTORE_TYPE_CONSOLE = 2, |
060287b8 | 40 | PSTORE_TYPE_FTRACE = 3, |
69020eea AB |
41 | /* PPC64 partition types */ |
42 | PSTORE_TYPE_PPC_RTAS = 4, | |
f33f748c | 43 | PSTORE_TYPE_PPC_OF = 5, |
a5e4797b | 44 | PSTORE_TYPE_PPC_COMMON = 6, |
9d5438f4 | 45 | PSTORE_TYPE_PMSG = 7, |
ae011d2e | 46 | PSTORE_TYPE_PPC_OPAL = 8, |
ca01d6dd TL |
47 | PSTORE_TYPE_UNKNOWN = 255 |
48 | }; | |
49 | ||
9abdcccc KC |
50 | struct pstore_info; |
51 | /** | |
52 | * struct pstore_record - details of a pstore record entry | |
53 | * @psi: pstore backend driver information | |
54 | * @type: pstore record type | |
55 | * @id: per-type unique identifier for record | |
56 | * @time: timestamp of the record | |
9abdcccc KC |
57 | * @buf: pointer to record contents |
58 | * @size: size of @buf | |
59 | * @ecc_notice_size: | |
60 | * ECC information for @buf | |
76cc9580 KC |
61 | * |
62 | * Valid for PSTORE_TYPE_DMESG @type: | |
63 | * | |
64 | * @count: Oops count since boot | |
65 | * @reason: kdump reason for notification | |
66 | * @part: position in a multipart record | |
67 | * @compressed: whether the buffer is compressed | |
68 | * | |
9abdcccc KC |
69 | */ |
70 | struct pstore_record { | |
71 | struct pstore_info *psi; | |
72 | enum pstore_type_id type; | |
73 | u64 id; | |
74 | struct timespec time; | |
9abdcccc KC |
75 | char *buf; |
76 | ssize_t size; | |
77 | ssize_t ecc_notice_size; | |
76cc9580 KC |
78 | |
79 | int count; | |
80 | enum kmsg_dump_reason reason; | |
81 | unsigned int part; | |
82 | bool compressed; | |
9abdcccc | 83 | }; |
67a101f5 | 84 | |
0edae0b3 KC |
85 | /** |
86 | * struct pstore_info - backend pstore driver structure | |
87 | * | |
88 | * @owner: module which is repsonsible for this backend driver | |
89 | * @name: name of the backend driver | |
90 | * | |
91 | * @buf_lock: spinlock to serialize access to @buf | |
92 | * @buf: preallocated crash dump buffer | |
93 | * @bufsize: size of @buf available for crash dump writes | |
94 | * | |
95 | * @read_mutex: serializes @open, @read, @close, and @erase callbacks | |
96 | * @flags: bitfield of frontends the backend can accept writes for | |
97 | * @data: backend-private pointer passed back during callbacks | |
98 | * | |
99 | * Callbacks: | |
100 | * | |
101 | * @open: | |
102 | * Notify backend that pstore is starting a full read of backend | |
103 | * records. Followed by one or more @read calls, and a final @close. | |
104 | * | |
105 | * @psi: in: pointer to the struct pstore_info for the backend | |
106 | * | |
107 | * Returns 0 on success, and non-zero on error. | |
108 | * | |
109 | * @close: | |
110 | * Notify backend that pstore has finished a full read of backend | |
111 | * records. Always preceded by an @open call and one or more @read | |
112 | * calls. | |
113 | * | |
114 | * @psi: in: pointer to the struct pstore_info for the backend | |
115 | * | |
116 | * Returns 0 on success, and non-zero on error. (Though pstore will | |
117 | * ignore the error.) | |
118 | * | |
119 | * @read: | |
120 | * Read next available backend record. Called after a successful | |
121 | * @open. | |
122 | * | |
125cc42b KC |
123 | * @record: |
124 | * pointer to record to populate. @buf should be allocated | |
125 | * by the backend and filled. At least @type and @id should | |
126 | * be populated, since these are used when creating pstorefs | |
127 | * file names. | |
0edae0b3 KC |
128 | * |
129 | * Returns record size on success, zero when no more records are | |
130 | * available, or negative on error. | |
131 | * | |
132 | * @write: | |
133 | * Perform a frontend notification of a write to a backend record. The | |
134 | * data to be stored has already been written to the registered @buf | |
135 | * of the @psi structure. | |
136 | * | |
76cc9580 KC |
137 | * @record: |
138 | * pointer to record metadata. Note that @buf is NULL, since | |
139 | * the @buf registered with @psi is what has been written. The | |
140 | * backend is expected to update @id. | |
0edae0b3 KC |
141 | * |
142 | * Returns 0 on success, and non-zero on error. | |
143 | * | |
144 | * @write_buf: | |
b10b4711 KC |
145 | * Perform a frontend write to a backend record. The record contains |
146 | * all metadata and the buffer to write to backend storage. (Unlike | |
147 | * @write, this does not use the @psi @buf.) | |
0edae0b3 | 148 | * |
b10b4711 | 149 | * @record: pointer to record metadata. |
0edae0b3 KC |
150 | * |
151 | * Returns 0 on success, and non-zero on error. | |
152 | * | |
153 | * @write_buf_user: | |
154 | * Perform a frontend write to a backend record, using a specified | |
155 | * buffer that is coming directly from userspace. | |
156 | * | |
157 | * @type: in: pstore record type to write | |
158 | * @reason: | |
159 | * in: pstore write reason | |
160 | * @id: out: unique identifier for the record | |
161 | * @part: in: position in a multipart write | |
162 | * @buf: in: pointer to userspace contents to write to backend record | |
163 | * @compressed: | |
164 | * in: if the record is compressed | |
165 | * @size: in: size of the write | |
166 | * @psi: in: pointer to the struct pstore_info for the backend | |
167 | * | |
168 | * Returns 0 on success, and non-zero on error. | |
169 | * | |
170 | * @erase: | |
171 | * Delete a record from backend storage. Different backends | |
a61072aa KC |
172 | * identify records differently, so entire original record is |
173 | * passed back to assist in identification of what the backend | |
174 | * should remove from storage. | |
0edae0b3 | 175 | * |
a61072aa | 176 | * @record: pointer to record metadata. |
0edae0b3 KC |
177 | * |
178 | * Returns 0 on success, and non-zero on error. | |
179 | * | |
180 | */ | |
ca01d6dd TL |
181 | struct pstore_info { |
182 | struct module *owner; | |
183 | char *name; | |
0edae0b3 KC |
184 | |
185 | spinlock_t buf_lock; | |
ca01d6dd TL |
186 | char *buf; |
187 | size_t bufsize; | |
0edae0b3 KC |
188 | |
189 | struct mutex read_mutex; | |
190 | ||
df36ac1b | 191 | int flags; |
0edae0b3 KC |
192 | void *data; |
193 | ||
06cf91b4 CG |
194 | int (*open)(struct pstore_info *psi); |
195 | int (*close)(struct pstore_info *psi); | |
125cc42b | 196 | ssize_t (*read)(struct pstore_record *record); |
76cc9580 | 197 | int (*write)(struct pstore_record *record); |
b10b4711 | 198 | int (*write_buf)(struct pstore_record *record); |
5bf6d1b9 MS |
199 | int (*write_buf_user)(enum pstore_type_id type, |
200 | enum kmsg_dump_reason reason, u64 *id, | |
201 | unsigned int part, const char __user *buf, | |
202 | bool compressed, size_t size, struct pstore_info *psi); | |
a61072aa | 203 | int (*erase)(struct pstore_record *record); |
ca01d6dd TL |
204 | }; |
205 | ||
0edae0b3 | 206 | /* Supported frontends */ |
c950fd6f | 207 | #define PSTORE_FLAGS_DMESG (1 << 0) |
c950fd6f NK |
208 | #define PSTORE_FLAGS_CONSOLE (1 << 1) |
209 | #define PSTORE_FLAGS_FTRACE (1 << 2) | |
210 | #define PSTORE_FLAGS_PMSG (1 << 3) | |
211 | ||
ca01d6dd | 212 | extern int pstore_register(struct pstore_info *); |
ee1d2674 | 213 | extern void pstore_unregister(struct pstore_info *); |
9f244e9c | 214 | extern bool pstore_cannot_block_path(enum kmsg_dump_reason reason); |
ca01d6dd | 215 | |
fbccdeb8 JF |
216 | struct pstore_ftrace_record { |
217 | unsigned long ip; | |
218 | unsigned long parent_ip; | |
219 | u64 ts; | |
220 | }; | |
221 | ||
222 | /* | |
223 | * ftrace related stuff: Both backends and frontends need these so expose | |
224 | * them here. | |
225 | */ | |
226 | ||
227 | #if NR_CPUS <= 2 && defined(CONFIG_ARM_THUMB) | |
228 | #define PSTORE_CPU_IN_IP 0x1 | |
229 | #elif NR_CPUS <= 4 && defined(CONFIG_ARM) | |
230 | #define PSTORE_CPU_IN_IP 0x3 | |
231 | #endif | |
232 | ||
233 | #define TS_CPU_SHIFT 8 | |
234 | #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1) | |
235 | ||
236 | /* | |
237 | * If CPU number can be stored in IP, store it there, otherwise store it in | |
238 | * the time stamp. This means more timestamp resolution is available when | |
239 | * the CPU can be stored in the IP. | |
240 | */ | |
241 | #ifdef PSTORE_CPU_IN_IP | |
242 | static inline void | |
243 | pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu) | |
244 | { | |
245 | rec->ip |= cpu; | |
246 | } | |
247 | ||
248 | static inline unsigned int | |
249 | pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) | |
250 | { | |
251 | return rec->ip & PSTORE_CPU_IN_IP; | |
252 | } | |
253 | ||
254 | static inline u64 | |
255 | pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec) | |
256 | { | |
257 | return rec->ts; | |
258 | } | |
259 | ||
260 | static inline void | |
261 | pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) | |
262 | { | |
263 | rec->ts = val; | |
264 | } | |
265 | #else | |
266 | static inline void | |
267 | pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu) | |
268 | { | |
269 | rec->ts &= ~(TS_CPU_MASK); | |
270 | rec->ts |= cpu; | |
271 | } | |
272 | ||
273 | static inline unsigned int | |
274 | pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) | |
275 | { | |
276 | return rec->ts & TS_CPU_MASK; | |
277 | } | |
278 | ||
279 | static inline u64 | |
280 | pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec) | |
281 | { | |
282 | return rec->ts >> TS_CPU_SHIFT; | |
283 | } | |
284 | ||
285 | static inline void | |
286 | pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) | |
287 | { | |
288 | rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT); | |
289 | } | |
290 | #endif | |
291 | ||
ca01d6dd | 292 | #endif /*_LINUX_PSTORE_H*/ |