Blame view
include/linux/pstore.h
7.63 KB
450515395 treewide: Replace... |
1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
ca01d6dd2 pstore: new files... |
2 3 4 5 6 7 8 |
/* * Persistent Storage - pstore.h * * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com> * * This code is the generic layer to export data records from platform * level persistent storage via a file system. |
ca01d6dd2 pstore: new files... |
9 10 11 |
*/ #ifndef _LINUX_PSTORE_H #define _LINUX_PSTORE_H |
5bf6d1b92 pstore/pmsg: drop... |
12 13 |
#include <linux/compiler.h> #include <linux/errno.h> |
3d6d8d20e pstore: pass reas... |
14 |
#include <linux/kmsg_dump.h> |
67a101f57 pstore: Headers s... |
15 |
#include <linux/mutex.h> |
ea84b580b pstore: Convert b... |
16 |
#include <linux/semaphore.h> |
5bf6d1b92 pstore/pmsg: drop... |
17 18 |
#include <linux/time.h> #include <linux/types.h> |
3d6d8d20e pstore: pass reas... |
19 |
|
9abdcccc3 pstore: Extract c... |
20 |
struct module; |
f0f23e546 pstore: Map PSTOR... |
21 22 23 24 25 |
/* * pstore record types (see fs/pstore/platform.c for pstore_type_names[]) * These values may be written to storage (see EFI vars backend), so * they are kind of an ABI. Be careful changing the mappings. */ |
ca01d6dd2 pstore: new files... |
26 |
enum pstore_type_id { |
f0f23e546 pstore: Map PSTOR... |
27 |
/* Frontend storage types */ |
ca01d6dd2 pstore: new files... |
28 29 |
PSTORE_TYPE_DMESG = 0, PSTORE_TYPE_MCE = 1, |
f29e5956a pstore: Add conso... |
30 |
PSTORE_TYPE_CONSOLE = 2, |
060287b8c pstore: Add persi... |
31 |
PSTORE_TYPE_FTRACE = 3, |
f0f23e546 pstore: Map PSTOR... |
32 33 |
/* PPC64-specific partition types */ |
69020eea9 powerpc/pseries: ... |
34 |
PSTORE_TYPE_PPC_RTAS = 4, |
f33f748c9 powerpc/pseries: ... |
35 |
PSTORE_TYPE_PPC_OF = 5, |
a5e4797b0 powerpc/pseries: ... |
36 |
PSTORE_TYPE_PPC_COMMON = 6, |
9d5438f46 pstore: Add pmsg ... |
37 |
PSTORE_TYPE_PMSG = 7, |
ae011d2e4 pstore: Add pstor... |
38 |
PSTORE_TYPE_PPC_OPAL = 8, |
f0f23e546 pstore: Map PSTOR... |
39 40 41 |
/* End of the list */ PSTORE_TYPE_MAX |
ca01d6dd2 pstore: new files... |
42 |
}; |
f0f23e546 pstore: Map PSTOR... |
43 44 |
const char *pstore_type_to_name(enum pstore_type_id type); enum pstore_type_id pstore_name_to_type(const char *name); |
9abdcccc3 pstore: Extract c... |
45 46 47 48 49 50 51 |
struct pstore_info; /** * struct pstore_record - details of a pstore record entry * @psi: pstore backend driver information * @type: pstore record type * @id: per-type unique identifier for record * @time: timestamp of the record |
9abdcccc3 pstore: Extract c... |
52 53 54 55 |
* @buf: pointer to record contents * @size: size of @buf * @ecc_notice_size: * ECC information for @buf |
76cc9580e pstore: Replace a... |
56 57 58 59 60 61 62 63 |
* * Valid for PSTORE_TYPE_DMESG @type: * * @count: Oops count since boot * @reason: kdump reason for notification * @part: position in a multipart record * @compressed: whether the buffer is compressed * |
9abdcccc3 pstore: Extract c... |
64 65 66 67 68 |
*/ struct pstore_record { struct pstore_info *psi; enum pstore_type_id type; u64 id; |
7aaa822ed pstore: Convert i... |
69 |
struct timespec64 time; |
9abdcccc3 pstore: Extract c... |
70 71 72 |
char *buf; ssize_t size; ssize_t ecc_notice_size; |
76cc9580e pstore: Replace a... |
73 74 75 76 77 |
int count; enum kmsg_dump_reason reason; unsigned int part; bool compressed; |
9abdcccc3 pstore: Extract c... |
78 |
}; |
67a101f57 pstore: Headers s... |
79 |
|
0edae0b3f pstore: Add kerne... |
80 81 82 |
/** * struct pstore_info - backend pstore driver structure * |
0eed84ffb pstore: Improve a... |
83 |
* @owner: module which is responsible for this backend driver |
0edae0b3f pstore: Add kerne... |
84 85 |
* @name: name of the backend driver * |
ea84b580b pstore: Convert b... |
86 |
* @buf_lock: semaphore to serialize access to @buf |
0edae0b3f pstore: Add kerne... |
87 |
* @buf: preallocated crash dump buffer |
89d328f63 pstore/ram: Corre... |
88 89 90 91 |
* @bufsize: size of @buf available for crash dump bytes (must match * smallest number of bytes available for writing to a * backend entry, since compressed bytes don't take kindly * to being truncated) |
0edae0b3f pstore: Add kerne... |
92 93 94 |
* * @read_mutex: serializes @open, @read, @close, and @erase callbacks * @flags: bitfield of frontends the backend can accept writes for |
3524e688b pstore/platform: ... |
95 96 97 98 99 100 |
* @max_reason: Used when PSTORE_FLAGS_DMESG is set. Contains the * kmsg_dump_reason enum value. KMSG_DUMP_UNDEF means * "use existing kmsg_dump() filtering, based on the * printk.always_kmsg_dump boot param" (which is either * KMSG_DUMP_OOPS when false, or KMSG_DUMP_MAX when * true); see printk.always_kmsg_dump for more details. |
0edae0b3f pstore: Add kerne... |
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
* @data: backend-private pointer passed back during callbacks * * Callbacks: * * @open: * Notify backend that pstore is starting a full read of backend * records. Followed by one or more @read calls, and a final @close. * * @psi: in: pointer to the struct pstore_info for the backend * * Returns 0 on success, and non-zero on error. * * @close: * Notify backend that pstore has finished a full read of backend * records. Always preceded by an @open call and one or more @read * calls. * * @psi: in: pointer to the struct pstore_info for the backend * * Returns 0 on success, and non-zero on error. (Though pstore will * ignore the error.) * * @read: * Read next available backend record. Called after a successful * @open. * |
125cc42ba pstore: Replace a... |
127 128 129 130 131 |
* @record: * pointer to record to populate. @buf should be allocated * by the backend and filled. At least @type and @id should * be populated, since these are used when creating pstorefs * file names. |
0edae0b3f pstore: Add kerne... |
132 133 134 135 136 |
* * Returns record size on success, zero when no more records are * available, or negative on error. * * @write: |
4c9ec2197 pstore: Remove wr... |
137 |
* A newly generated record needs to be written to backend storage. |
0edae0b3f pstore: Add kerne... |
138 |
* |
76cc9580e pstore: Replace a... |
139 |
* @record: |
4c9ec2197 pstore: Remove wr... |
140 141 142 143 144 |
* pointer to record metadata. When @type is PSTORE_TYPE_DMESG, * @buf will be pointing to the preallocated @psi.buf, since * memory allocation may be broken during an Oops. Regardless, * @buf must be proccesed or copied before returning. The * backend is also expected to write @id with something that |
c7f3c595f pstore: Populate ... |
145 146 147 148 |
* can help identify this record to a future @erase callback. * The @time field will be prepopulated with the current time, * when available. The @size field will have the size of data * in @buf. |
0edae0b3f pstore: Add kerne... |
149 150 151 |
* * Returns 0 on success, and non-zero on error. * |
4c9ec2197 pstore: Remove wr... |
152 |
* @write_user: |
0edae0b3f pstore: Add kerne... |
153 |
* Perform a frontend write to a backend record, using a specified |
fdd031186 pstore: Replace a... |
154 155 156 157 158 |
* buffer that is coming directly from userspace, instead of the * @record @buf. * * @record: pointer to record metadata. * @buf: pointer to userspace contents to write to backend |
0edae0b3f pstore: Add kerne... |
159 160 161 162 163 |
* * Returns 0 on success, and non-zero on error. * * @erase: * Delete a record from backend storage. Different backends |
a61072aae pstore: Replace a... |
164 165 166 |
* identify records differently, so entire original record is * passed back to assist in identification of what the backend * should remove from storage. |
0edae0b3f pstore: Add kerne... |
167 |
* |
a61072aae pstore: Replace a... |
168 |
* @record: pointer to record metadata. |
0edae0b3f pstore: Add kerne... |
169 170 171 172 |
* * Returns 0 on success, and non-zero on error. * */ |
ca01d6dd2 pstore: new files... |
173 174 |
struct pstore_info { struct module *owner; |
563ca40dd pstore/platform: ... |
175 |
const char *name; |
0edae0b3f pstore: Add kerne... |
176 |
|
ea84b580b pstore: Convert b... |
177 |
struct semaphore buf_lock; |
ca01d6dd2 pstore: new files... |
178 179 |
char *buf; size_t bufsize; |
0edae0b3f pstore: Add kerne... |
180 181 |
struct mutex read_mutex; |
df36ac1bc pstore: Don't all... |
182 |
int flags; |
3524e688b pstore/platform: ... |
183 |
int max_reason; |
0edae0b3f pstore: Add kerne... |
184 |
void *data; |
06cf91b4b pstore: fix pstor... |
185 186 |
int (*open)(struct pstore_info *psi); int (*close)(struct pstore_info *psi); |
125cc42ba pstore: Replace a... |
187 |
ssize_t (*read)(struct pstore_record *record); |
76cc9580e pstore: Replace a... |
188 |
int (*write)(struct pstore_record *record); |
4c9ec2197 pstore: Remove wr... |
189 190 |
int (*write_user)(struct pstore_record *record, const char __user *buf); |
a61072aae pstore: Replace a... |
191 |
int (*erase)(struct pstore_record *record); |
ca01d6dd2 pstore: new files... |
192 |
}; |
0edae0b3f pstore: Add kerne... |
193 |
/* Supported frontends */ |
4af62a642 pstore: Replace o... |
194 195 196 197 |
#define PSTORE_FLAGS_DMESG BIT(0) #define PSTORE_FLAGS_CONSOLE BIT(1) #define PSTORE_FLAGS_FTRACE BIT(2) #define PSTORE_FLAGS_PMSG BIT(3) |
c950fd6f2 pstore: Split pst... |
198 |
|
ca01d6dd2 pstore: new files... |
199 |
extern int pstore_register(struct pstore_info *); |
ee1d26742 pstore: add pstor... |
200 |
extern void pstore_unregister(struct pstore_info *); |
ca01d6dd2 pstore: new files... |
201 |
|
fbccdeb8d pstore: Add ftrac... |
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
struct pstore_ftrace_record { unsigned long ip; unsigned long parent_ip; u64 ts; }; /* * ftrace related stuff: Both backends and frontends need these so expose * them here. */ #if NR_CPUS <= 2 && defined(CONFIG_ARM_THUMB) #define PSTORE_CPU_IN_IP 0x1 #elif NR_CPUS <= 4 && defined(CONFIG_ARM) #define PSTORE_CPU_IN_IP 0x3 #endif #define TS_CPU_SHIFT 8 #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1) /* * If CPU number can be stored in IP, store it there, otherwise store it in * the time stamp. This means more timestamp resolution is available when * the CPU can be stored in the IP. */ #ifdef PSTORE_CPU_IN_IP static inline void pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu) { rec->ip |= cpu; } static inline unsigned int pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) { return rec->ip & PSTORE_CPU_IN_IP; } static inline u64 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec) { return rec->ts; } static inline void pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) { rec->ts = val; } #else static inline void pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu) { rec->ts &= ~(TS_CPU_MASK); rec->ts |= cpu; } static inline unsigned int pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) { return rec->ts & TS_CPU_MASK; } static inline u64 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec) { return rec->ts >> TS_CPU_SHIFT; } static inline void pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) { rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT); } #endif |
ca01d6dd2 pstore: new files... |
277 |
#endif /*_LINUX_PSTORE_H*/ |