xref: /linux/include/linux/pstore.h (revision 32786fdc9506aeba98278c1844d4bfb766863832)
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 
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>
32 
33 /* types */
34 enum pstore_type_id {
35 	PSTORE_TYPE_DMESG	= 0,
36 	PSTORE_TYPE_MCE		= 1,
37 	PSTORE_TYPE_CONSOLE	= 2,
38 	PSTORE_TYPE_FTRACE	= 3,
39 	/* PPC64 partition types */
40 	PSTORE_TYPE_PPC_RTAS	= 4,
41 	PSTORE_TYPE_PPC_OF	= 5,
42 	PSTORE_TYPE_PPC_COMMON	= 6,
43 	PSTORE_TYPE_PMSG	= 7,
44 	PSTORE_TYPE_PPC_OPAL	= 8,
45 	PSTORE_TYPE_UNKNOWN	= 255
46 };
47 
48 struct module;
49 
50 struct pstore_info {
51 	struct module	*owner;
52 	char		*name;
53 	spinlock_t	buf_lock;	/* serialize access to 'buf' */
54 	char		*buf;
55 	size_t		bufsize;
56 	struct mutex	read_mutex;	/* serialize open/read/close */
57 	int		flags;
58 	int		(*open)(struct pstore_info *psi);
59 	int		(*close)(struct pstore_info *psi);
60 	ssize_t		(*read)(u64 *id, enum pstore_type_id *type,
61 			int *count, struct timespec *time, char **buf,
62 			bool *compressed, ssize_t *ecc_notice_size,
63 			struct pstore_info *psi);
64 	int		(*write)(enum pstore_type_id type,
65 			enum kmsg_dump_reason reason, u64 *id,
66 			unsigned int part, int count, bool compressed,
67 			size_t size, struct pstore_info *psi);
68 	int		(*write_buf)(enum pstore_type_id type,
69 			enum kmsg_dump_reason reason, u64 *id,
70 			unsigned int part, const char *buf, bool compressed,
71 			size_t size, struct pstore_info *psi);
72 	int		(*write_buf_user)(enum pstore_type_id type,
73 			enum kmsg_dump_reason reason, u64 *id,
74 			unsigned int part, const char __user *buf,
75 			bool compressed, size_t size, struct pstore_info *psi);
76 	int		(*erase)(enum pstore_type_id type, u64 id,
77 			int count, struct timespec time,
78 			struct pstore_info *psi);
79 	void		*data;
80 };
81 
82 #define PSTORE_FLAGS_DMESG	(1 << 0)
83 #define PSTORE_FLAGS_FRAGILE	PSTORE_FLAGS_DMESG
84 #define PSTORE_FLAGS_CONSOLE	(1 << 1)
85 #define PSTORE_FLAGS_FTRACE	(1 << 2)
86 #define PSTORE_FLAGS_PMSG	(1 << 3)
87 
88 extern int pstore_register(struct pstore_info *);
89 extern void pstore_unregister(struct pstore_info *);
90 extern bool pstore_cannot_block_path(enum kmsg_dump_reason reason);
91 
92 struct pstore_ftrace_record {
93 	unsigned long ip;
94 	unsigned long parent_ip;
95 	u64 ts;
96 };
97 
98 /*
99  * ftrace related stuff: Both backends and frontends need these so expose
100  * them here.
101  */
102 
103 #if NR_CPUS <= 2 && defined(CONFIG_ARM_THUMB)
104 #define PSTORE_CPU_IN_IP 0x1
105 #elif NR_CPUS <= 4 && defined(CONFIG_ARM)
106 #define PSTORE_CPU_IN_IP 0x3
107 #endif
108 
109 #define TS_CPU_SHIFT 8
110 #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1)
111 
112 /*
113  * If CPU number can be stored in IP, store it there, otherwise store it in
114  * the time stamp. This means more timestamp resolution is available when
115  * the CPU can be stored in the IP.
116  */
117 #ifdef PSTORE_CPU_IN_IP
118 static inline void
119 pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
120 {
121 	rec->ip |= cpu;
122 }
123 
124 static inline unsigned int
125 pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
126 {
127 	return rec->ip & PSTORE_CPU_IN_IP;
128 }
129 
130 static inline u64
131 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
132 {
133 	return rec->ts;
134 }
135 
136 static inline void
137 pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
138 {
139 	rec->ts = val;
140 }
141 #else
142 static inline void
143 pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
144 {
145 	rec->ts &= ~(TS_CPU_MASK);
146 	rec->ts |= cpu;
147 }
148 
149 static inline unsigned int
150 pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
151 {
152 	return rec->ts & TS_CPU_MASK;
153 }
154 
155 static inline u64
156 pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
157 {
158 	return rec->ts >> TS_CPU_SHIFT;
159 }
160 
161 static inline void
162 pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
163 {
164 	rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT);
165 }
166 #endif
167 
168 #endif /*_LINUX_PSTORE_H*/
169