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/semaphore.h>
30 #include <linux/time.h>
31 #include <linux/types.h>
36 * pstore record types (see fs/pstore/platform.c for pstore_type_names[])
37 * These values may be written to storage (see EFI vars backend), so
38 * they are kind of an ABI. Be careful changing the mappings.
41 /* Frontend storage types */
42 PSTORE_TYPE_DMESG = 0,
44 PSTORE_TYPE_CONSOLE = 2,
45 PSTORE_TYPE_FTRACE = 3,
47 /* PPC64-specific partition types */
48 PSTORE_TYPE_PPC_RTAS = 4,
49 PSTORE_TYPE_PPC_OF = 5,
50 PSTORE_TYPE_PPC_COMMON = 6,
52 PSTORE_TYPE_PPC_OPAL = 8,
58 const char *pstore_type_to_name(enum pstore_type_id type);
59 enum pstore_type_id pstore_name_to_type(const char *name);
63 * struct pstore_record - details of a pstore record entry
64 * @psi: pstore backend driver information
65 * @type: pstore record type
66 * @id: per-type unique identifier for record
67 * @time: timestamp of the record
68 * @buf: pointer to record contents
71 * ECC information for @buf
73 * Valid for PSTORE_TYPE_DMESG @type:
75 * @count: Oops count since boot
76 * @reason: kdump reason for notification
77 * @part: position in a multipart record
78 * @compressed: whether the buffer is compressed
81 struct pstore_record {
82 struct pstore_info *psi;
83 enum pstore_type_id type;
85 struct timespec64 time;
88 ssize_t ecc_notice_size;
91 enum kmsg_dump_reason reason;
97 * struct pstore_info - backend pstore driver structure
99 * @owner: module which is responsible for this backend driver
100 * @name: name of the backend driver
102 * @buf_lock: semaphore to serialize access to @buf
103 * @buf: preallocated crash dump buffer
104 * @bufsize: size of @buf available for crash dump bytes (must match
105 * smallest number of bytes available for writing to a
106 * backend entry, since compressed bytes don't take kindly
107 * to being truncated)
109 * @read_mutex: serializes @open, @read, @close, and @erase callbacks
110 * @flags: bitfield of frontends the backend can accept writes for
111 * @data: backend-private pointer passed back during callbacks
116 * Notify backend that pstore is starting a full read of backend
117 * records. Followed by one or more @read calls, and a final @close.
119 * @psi: in: pointer to the struct pstore_info for the backend
121 * Returns 0 on success, and non-zero on error.
124 * Notify backend that pstore has finished a full read of backend
125 * records. Always preceded by an @open call and one or more @read
128 * @psi: in: pointer to the struct pstore_info for the backend
130 * Returns 0 on success, and non-zero on error. (Though pstore will
134 * Read next available backend record. Called after a successful
138 * pointer to record to populate. @buf should be allocated
139 * by the backend and filled. At least @type and @id should
140 * be populated, since these are used when creating pstorefs
143 * Returns record size on success, zero when no more records are
144 * available, or negative on error.
147 * A newly generated record needs to be written to backend storage.
150 * pointer to record metadata. When @type is PSTORE_TYPE_DMESG,
151 * @buf will be pointing to the preallocated @psi.buf, since
152 * memory allocation may be broken during an Oops. Regardless,
153 * @buf must be proccesed or copied before returning. The
154 * backend is also expected to write @id with something that
155 * can help identify this record to a future @erase callback.
156 * The @time field will be prepopulated with the current time,
157 * when available. The @size field will have the size of data
160 * Returns 0 on success, and non-zero on error.
163 * Perform a frontend write to a backend record, using a specified
164 * buffer that is coming directly from userspace, instead of the
167 * @record: pointer to record metadata.
168 * @buf: pointer to userspace contents to write to backend
170 * Returns 0 on success, and non-zero on error.
173 * Delete a record from backend storage. Different backends
174 * identify records differently, so entire original record is
175 * passed back to assist in identification of what the backend
176 * should remove from storage.
178 * @record: pointer to record metadata.
180 * Returns 0 on success, and non-zero on error.
184 struct module *owner;
187 struct semaphore buf_lock;
191 struct mutex read_mutex;
196 int (*open)(struct pstore_info *psi);
197 int (*close)(struct pstore_info *psi);
198 ssize_t (*read)(struct pstore_record *record);
199 int (*write)(struct pstore_record *record);
200 int (*write_user)(struct pstore_record *record,
201 const char __user *buf);
202 int (*erase)(struct pstore_record *record);
205 /* Supported frontends */
206 #define PSTORE_FLAGS_DMESG BIT(0)
207 #define PSTORE_FLAGS_CONSOLE BIT(1)
208 #define PSTORE_FLAGS_FTRACE BIT(2)
209 #define PSTORE_FLAGS_PMSG BIT(3)
211 extern int pstore_register(struct pstore_info *);
212 extern void pstore_unregister(struct pstore_info *);
214 struct pstore_ftrace_record {
216 unsigned long parent_ip;
221 * ftrace related stuff: Both backends and frontends need these so expose
225 #if NR_CPUS <= 2 && defined(CONFIG_ARM_THUMB)
226 #define PSTORE_CPU_IN_IP 0x1
227 #elif NR_CPUS <= 4 && defined(CONFIG_ARM)
228 #define PSTORE_CPU_IN_IP 0x3
231 #define TS_CPU_SHIFT 8
232 #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1)
235 * If CPU number can be stored in IP, store it there, otherwise store it in
236 * the time stamp. This means more timestamp resolution is available when
237 * the CPU can be stored in the IP.
239 #ifdef PSTORE_CPU_IN_IP
241 pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
246 static inline unsigned int
247 pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
249 return rec->ip & PSTORE_CPU_IN_IP;
253 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
259 pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
265 pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
267 rec->ts &= ~(TS_CPU_MASK);
271 static inline unsigned int
272 pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
274 return rec->ts & TS_CPU_MASK;
278 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
280 return rec->ts >> TS_CPU_SHIFT;
284 pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
286 rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT);
290 #endif /*_LINUX_PSTORE_H*/