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