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