2 * Persistent Storage - pstore.h
4 * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
6 * This code is the generic layer to export data records from platform
7 * level persistent storage via a file system.
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.
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.
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
22 #ifndef _LINUX_PSTORE_H
23 #define _LINUX_PSTORE_H
25 #include <linux/compiler.h>
26 #include <linux/errno.h>
27 #include <linux/kmsg_dump.h>
28 #include <linux/mutex.h>
29 #include <linux/spinlock.h>
30 #include <linux/time.h>
31 #include <linux/types.h>
35 /* pstore record types (see fs/pstore/inode.c for filename templates) */
37 PSTORE_TYPE_DMESG = 0,
39 PSTORE_TYPE_CONSOLE = 2,
40 PSTORE_TYPE_FTRACE = 3,
41 /* PPC64 partition types */
42 PSTORE_TYPE_PPC_RTAS = 4,
43 PSTORE_TYPE_PPC_OF = 5,
44 PSTORE_TYPE_PPC_COMMON = 6,
46 PSTORE_TYPE_PPC_OPAL = 8,
47 PSTORE_TYPE_UNKNOWN = 255
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 * @buf: pointer to record contents
60 * ECC information for @buf
62 * Valid for PSTORE_TYPE_DMESG @type:
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
70 struct pstore_record {
71 struct pstore_info *psi;
72 enum pstore_type_id type;
77 ssize_t ecc_notice_size;
80 enum kmsg_dump_reason reason;
86 * struct pstore_info - backend pstore driver structure
88 * @owner: module which is repsonsible for this backend driver
89 * @name: name of the backend driver
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
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
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.
105 * @psi: in: pointer to the struct pstore_info for the backend
107 * Returns 0 on success, and non-zero on error.
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
114 * @psi: in: pointer to the struct pstore_info for the backend
116 * Returns 0 on success, and non-zero on error. (Though pstore will
120 * Read next available backend record. Called after a successful
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
129 * Returns record size on success, zero when no more records are
130 * available, or negative on error.
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.
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.
142 * Returns 0 on success, and non-zero on error.
145 * Perform a frontend write to a backend record, using a specified
146 * buffer. Unlike @write, this does not use the @psi @buf.
148 * @type: in: pstore record type to write
150 * in: pstore write reason
151 * @id: out: unique identifier for the record
152 * @part: in: position in a multipart write
153 * @buf: in: pointer to contents to write to backend record
155 * in: if the record is compressed
156 * @size: in: size of the write
157 * @psi: in: pointer to the struct pstore_info for the backend
159 * Returns 0 on success, and non-zero on error.
162 * Perform a frontend write to a backend record, using a specified
163 * buffer that is coming directly from userspace.
165 * @type: in: pstore record type to write
167 * in: pstore write reason
168 * @id: out: unique identifier for the record
169 * @part: in: position in a multipart write
170 * @buf: in: pointer to userspace contents to write to backend record
172 * in: if the record is compressed
173 * @size: in: size of the write
174 * @psi: in: pointer to the struct pstore_info for the backend
176 * Returns 0 on success, and non-zero on error.
179 * Delete a record from backend storage. Different backends
180 * identify records differently, so all possible methods of
181 * identification are included to help the backend locate the
184 * @type: in: pstore record type to write
185 * @id: in: per-type unique identifier for the record
186 * @count: in: Oops count
187 * @time: in: timestamp for the record
188 * @psi: in: pointer to the struct pstore_info for the backend
190 * Returns 0 on success, and non-zero on error.
194 struct module *owner;
201 struct mutex read_mutex;
206 int (*open)(struct pstore_info *psi);
207 int (*close)(struct pstore_info *psi);
208 ssize_t (*read)(struct pstore_record *record);
209 int (*write)(struct pstore_record *record);
210 int (*write_buf)(enum pstore_type_id type,
211 enum kmsg_dump_reason reason, u64 *id,
212 unsigned int part, const char *buf, bool compressed,
213 size_t size, struct pstore_info *psi);
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);
218 int (*erase)(enum pstore_type_id type, u64 id,
219 int count, struct timespec time,
220 struct pstore_info *psi);
223 /* Supported frontends */
224 #define PSTORE_FLAGS_DMESG (1 << 0)
225 #define PSTORE_FLAGS_CONSOLE (1 << 1)
226 #define PSTORE_FLAGS_FTRACE (1 << 2)
227 #define PSTORE_FLAGS_PMSG (1 << 3)
229 extern int pstore_register(struct pstore_info *);
230 extern void pstore_unregister(struct pstore_info *);
231 extern bool pstore_cannot_block_path(enum kmsg_dump_reason reason);
233 struct pstore_ftrace_record {
235 unsigned long parent_ip;
240 * ftrace related stuff: Both backends and frontends need these so expose
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
250 #define TS_CPU_SHIFT 8
251 #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1)
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.
258 #ifdef PSTORE_CPU_IN_IP
260 pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
265 static inline unsigned int
266 pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
268 return rec->ip & PSTORE_CPU_IN_IP;
272 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
278 pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
284 pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
286 rec->ts &= ~(TS_CPU_MASK);
290 static inline unsigned int
291 pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
293 return rec->ts & TS_CPU_MASK;
297 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
299 return rec->ts >> TS_CPU_SHIFT;
303 pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
305 rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT);
309 #endif /*_LINUX_PSTORE_H*/