Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * RAM Oops/Panic logger |
| 3 | * |
| 4 | * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com> |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 5 | * Copyright (C) 2011 Kees Cook <keescook@chromium.org> |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
Marco Stornelli | 0169256 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 25 | #include <linux/kernel.h> |
James Bottomley | 83c1b31 | 2011-07-29 17:11:32 +0400 | [diff] [blame] | 26 | #include <linux/err.h> |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
Anton Vorontsov | cbe7cbf | 2012-07-17 12:11:12 -0700 | [diff] [blame] | 28 | #include <linux/version.h> |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 29 | #include <linux/pstore.h> |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 30 | #include <linux/time.h> |
| 31 | #include <linux/io.h> |
| 32 | #include <linux/ioport.h> |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 34 | #include <linux/slab.h> |
Anton Vorontsov | 2420303 | 2012-07-17 19:49:37 -0700 | [diff] [blame] | 35 | #include <linux/compiler.h> |
Anton Vorontsov | 1894a25 | 2012-05-16 05:43:08 -0700 | [diff] [blame] | 36 | #include <linux/pstore_ram.h> |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 37 | |
| 38 | #define RAMOOPS_KERNMSG_HDR "====" |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 39 | #define MIN_MEM_SIZE 4096UL |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 40 | |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 41 | static ulong record_size = MIN_MEM_SIZE; |
| 42 | module_param(record_size, ulong, 0400); |
| 43 | MODULE_PARM_DESC(record_size, |
| 44 | "size of each dump done on oops/panic"); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 45 | |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 46 | static ulong ramoops_console_size = MIN_MEM_SIZE; |
| 47 | module_param_named(console_size, ramoops_console_size, ulong, 0400); |
| 48 | MODULE_PARM_DESC(console_size, "size of kernel console log"); |
| 49 | |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 50 | static ulong ramoops_ftrace_size = MIN_MEM_SIZE; |
| 51 | module_param_named(ftrace_size, ramoops_ftrace_size, ulong, 0400); |
| 52 | MODULE_PARM_DESC(ftrace_size, "size of ftrace log"); |
| 53 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 54 | static ulong mem_address; |
| 55 | module_param(mem_address, ulong, 0400); |
| 56 | MODULE_PARM_DESC(mem_address, |
| 57 | "start of reserved RAM used to store oops/panic logs"); |
| 58 | |
| 59 | static ulong mem_size; |
| 60 | module_param(mem_size, ulong, 0400); |
| 61 | MODULE_PARM_DESC(mem_size, |
| 62 | "size of reserved RAM used to store oops/panic logs"); |
| 63 | |
Tony Lindgren | 027bc8b | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 64 | static unsigned int mem_type; |
| 65 | module_param(mem_type, uint, 0600); |
| 66 | MODULE_PARM_DESC(mem_type, |
| 67 | "set to 1 to try to use unbuffered memory (default 0)"); |
| 68 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 69 | static int dump_oops = 1; |
| 70 | module_param(dump_oops, int, 0600); |
| 71 | MODULE_PARM_DESC(dump_oops, |
| 72 | "set to 1 to dump oopses, 0 to only dump panics (default 1)"); |
| 73 | |
Anton Vorontsov | 39eb7e97 | 2012-05-17 00:15:34 -0700 | [diff] [blame] | 74 | static int ramoops_ecc; |
| 75 | module_param_named(ecc, ramoops_ecc, int, 0600); |
| 76 | MODULE_PARM_DESC(ramoops_ecc, |
Anton Vorontsov | 5ca5d4e | 2012-07-09 17:03:19 -0700 | [diff] [blame] | 77 | "if non-zero, the option enables ECC support and specifies " |
| 78 | "ECC buffer size in bytes (1 is a special value, means 16 " |
| 79 | "bytes ECC)"); |
Anton Vorontsov | 39eb7e97 | 2012-05-17 00:15:34 -0700 | [diff] [blame] | 80 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 81 | struct ramoops_context { |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 82 | struct persistent_ram_zone **przs; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 83 | struct persistent_ram_zone *cprz; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 84 | struct persistent_ram_zone *fprz; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 85 | phys_addr_t phys_addr; |
| 86 | unsigned long size; |
Tony Lindgren | 027bc8b | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 87 | unsigned int memtype; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 88 | size_t record_size; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 89 | size_t console_size; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 90 | size_t ftrace_size; |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 91 | int dump_oops; |
Arve Hjønnevåg | c31ad08 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 92 | struct persistent_ram_ecc_info ecc_info; |
Anton Vorontsov | cac2eb7 | 2012-05-26 06:20:20 -0700 | [diff] [blame] | 93 | unsigned int max_dump_cnt; |
| 94 | unsigned int dump_write_cnt; |
Liu ShuoX | 57fd835 | 2014-03-17 11:24:49 +1100 | [diff] [blame] | 95 | /* _read_cnt need clear on ramoops_pstore_open */ |
Anton Vorontsov | cac2eb7 | 2012-05-26 06:20:20 -0700 | [diff] [blame] | 96 | unsigned int dump_read_cnt; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 97 | unsigned int console_read_cnt; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 98 | unsigned int ftrace_read_cnt; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 99 | struct pstore_info pstore; |
| 100 | }; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 101 | |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 102 | static struct platform_device *dummy; |
| 103 | static struct ramoops_platform_data *dummy_data; |
| 104 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 105 | static int ramoops_pstore_open(struct pstore_info *psi) |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 106 | { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 107 | struct ramoops_context *cxt = psi->data; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 108 | |
Anton Vorontsov | cac2eb7 | 2012-05-26 06:20:20 -0700 | [diff] [blame] | 109 | cxt->dump_read_cnt = 0; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 110 | cxt->console_read_cnt = 0; |
Liu ShuoX | 57fd835 | 2014-03-17 11:24:49 +1100 | [diff] [blame] | 111 | cxt->ftrace_read_cnt = 0; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
Anton Vorontsov | 755d66b | 2012-05-26 06:20:22 -0700 | [diff] [blame] | 115 | static struct persistent_ram_zone * |
| 116 | ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, |
| 117 | u64 *id, |
| 118 | enum pstore_type_id *typep, enum pstore_type_id type, |
| 119 | bool update) |
| 120 | { |
| 121 | struct persistent_ram_zone *prz; |
| 122 | int i = (*c)++; |
| 123 | |
| 124 | if (i >= max) |
| 125 | return NULL; |
| 126 | |
| 127 | prz = przs[i]; |
Liu ShuoX | b0aa931 | 2014-03-17 13:57:49 -0700 | [diff] [blame] | 128 | if (!prz) |
| 129 | return NULL; |
Anton Vorontsov | 755d66b | 2012-05-26 06:20:22 -0700 | [diff] [blame] | 130 | |
Liu ShuoX | aa9a4a1 | 2014-03-17 11:24:49 +1100 | [diff] [blame] | 131 | /* Update old/shadowed buffer. */ |
| 132 | if (update) |
Anton Vorontsov | 755d66b | 2012-05-26 06:20:22 -0700 | [diff] [blame] | 133 | persistent_ram_save_old(prz); |
Liu ShuoX | aa9a4a1 | 2014-03-17 11:24:49 +1100 | [diff] [blame] | 134 | |
| 135 | if (!persistent_ram_old_size(prz)) |
| 136 | return NULL; |
Anton Vorontsov | 755d66b | 2012-05-26 06:20:22 -0700 | [diff] [blame] | 137 | |
| 138 | *typep = type; |
| 139 | *id = i; |
| 140 | |
| 141 | return prz; |
| 142 | } |
| 143 | |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 144 | static int ramoops_read_kmsg_hdr(char *buffer, struct timespec *time, |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 145 | bool *compressed) |
| 146 | { |
| 147 | char data_type; |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 148 | int header_length = 0; |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 149 | |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 150 | if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n%n", &time->tv_sec, |
| 151 | &time->tv_nsec, &data_type, &header_length) == 3) { |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 152 | if (data_type == 'C') |
| 153 | *compressed = true; |
| 154 | else |
| 155 | *compressed = false; |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 156 | } else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu\n%n", |
| 157 | &time->tv_sec, &time->tv_nsec, &header_length) == 2) { |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 158 | *compressed = false; |
| 159 | } else { |
| 160 | time->tv_sec = 0; |
| 161 | time->tv_nsec = 0; |
| 162 | *compressed = false; |
| 163 | } |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 164 | return header_length; |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 167 | static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, |
Seiji Aguchi | 755d4fe | 2012-11-26 16:07:44 -0800 | [diff] [blame] | 168 | int *count, struct timespec *time, |
Aruna Balakrishnaiah | 9a4e139 | 2013-08-16 13:53:19 -0700 | [diff] [blame] | 169 | char **buf, bool *compressed, |
| 170 | struct pstore_info *psi) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 171 | { |
| 172 | ssize_t size; |
Arve Hjønnevåg | bd08ec3 | 2012-12-05 21:19:51 -0800 | [diff] [blame] | 173 | ssize_t ecc_notice_size; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 174 | struct ramoops_context *cxt = psi->data; |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 175 | struct persistent_ram_zone *prz; |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 176 | int header_length; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 177 | |
Anton Vorontsov | 755d66b | 2012-05-26 06:20:22 -0700 | [diff] [blame] | 178 | prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt, |
| 179 | cxt->max_dump_cnt, id, type, |
| 180 | PSTORE_TYPE_DMESG, 1); |
| 181 | if (!prz) |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 182 | prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt, |
| 183 | 1, id, type, PSTORE_TYPE_CONSOLE, 0); |
| 184 | if (!prz) |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 185 | prz = ramoops_get_next_prz(&cxt->fprz, &cxt->ftrace_read_cnt, |
| 186 | 1, id, type, PSTORE_TYPE_FTRACE, 0); |
| 187 | if (!prz) |
Anton Vorontsov | 755d66b | 2012-05-26 06:20:22 -0700 | [diff] [blame] | 188 | return 0; |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 189 | |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 190 | if (!persistent_ram_old(prz)) |
| 191 | return 0; |
| 192 | |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 193 | size = persistent_ram_old_size(prz); |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 194 | header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz), time, |
| 195 | compressed); |
| 196 | size -= header_length; |
Arve Hjønnevåg | bd08ec3 | 2012-12-05 21:19:51 -0800 | [diff] [blame] | 197 | |
| 198 | /* ECC correction notice */ |
| 199 | ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0); |
| 200 | |
| 201 | *buf = kmalloc(size + ecc_notice_size + 1, GFP_KERNEL); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 202 | if (*buf == NULL) |
| 203 | return -ENOMEM; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 204 | |
Ben Zhang | a28726b | 2014-10-30 17:14:21 -0700 | [diff] [blame] | 205 | memcpy(*buf, (char *)persistent_ram_old(prz) + header_length, size); |
Arve Hjønnevåg | bd08ec3 | 2012-12-05 21:19:51 -0800 | [diff] [blame] | 206 | persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1); |
| 207 | |
| 208 | return size + ecc_notice_size; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 209 | } |
| 210 | |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 211 | static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, |
| 212 | bool compressed) |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 213 | { |
| 214 | char *hdr; |
Kees Cook | 1e817fb | 2012-11-19 10:26:16 -0800 | [diff] [blame] | 215 | struct timespec timestamp; |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 216 | size_t len; |
| 217 | |
Kees Cook | 1e817fb | 2012-11-19 10:26:16 -0800 | [diff] [blame] | 218 | /* Report zeroed timestamp if called before timekeeping has resumed. */ |
| 219 | if (__getnstimeofday(×tamp)) { |
| 220 | timestamp.tv_sec = 0; |
| 221 | timestamp.tv_nsec = 0; |
| 222 | } |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 223 | hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n", |
| 224 | (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000), |
| 225 | compressed ? 'C' : 'D'); |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 226 | WARN_ON_ONCE(!hdr); |
| 227 | len = hdr ? strlen(hdr) : 0; |
| 228 | persistent_ram_write(prz, hdr, len); |
| 229 | kfree(hdr); |
| 230 | |
| 231 | return len; |
| 232 | } |
| 233 | |
Anton Vorontsov | 2420303 | 2012-07-17 19:49:37 -0700 | [diff] [blame] | 234 | static int notrace ramoops_pstore_write_buf(enum pstore_type_id type, |
| 235 | enum kmsg_dump_reason reason, |
| 236 | u64 *id, unsigned int part, |
Aruna Balakrishnaiah | 6bbbca7 | 2013-06-27 14:02:56 +0530 | [diff] [blame] | 237 | const char *buf, |
Aruna Balakrishnaiah | b3b515b | 2013-08-16 13:52:47 -0700 | [diff] [blame] | 238 | bool compressed, size_t size, |
Anton Vorontsov | 2420303 | 2012-07-17 19:49:37 -0700 | [diff] [blame] | 239 | struct pstore_info *psi) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 240 | { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 241 | struct ramoops_context *cxt = psi->data; |
Arve Hjønnevåg | c628937 | 2012-12-11 17:49:24 -0800 | [diff] [blame] | 242 | struct persistent_ram_zone *prz; |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 243 | size_t hlen; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 244 | |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 245 | if (type == PSTORE_TYPE_CONSOLE) { |
| 246 | if (!cxt->cprz) |
| 247 | return -ENOMEM; |
Anton Vorontsov | c2b7113 | 2012-07-09 17:10:43 -0700 | [diff] [blame] | 248 | persistent_ram_write(cxt->cprz, buf, size); |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 249 | return 0; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 250 | } else if (type == PSTORE_TYPE_FTRACE) { |
| 251 | if (!cxt->fprz) |
| 252 | return -ENOMEM; |
| 253 | persistent_ram_write(cxt->fprz, buf, size); |
| 254 | return 0; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 257 | if (type != PSTORE_TYPE_DMESG) |
| 258 | return -EINVAL; |
| 259 | |
| 260 | /* Out of the various dmesg dump types, ramoops is currently designed |
| 261 | * to only store crash logs, rather than storing general kernel logs. |
| 262 | */ |
Seiji Aguchi | fc2d557 | 2011-01-12 16:59:29 -0800 | [diff] [blame] | 263 | if (reason != KMSG_DUMP_OOPS && |
WANG Cong | a3dd332 | 2012-01-12 17:20:11 -0800 | [diff] [blame] | 264 | reason != KMSG_DUMP_PANIC) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 265 | return -EINVAL; |
Seiji Aguchi | fc2d557 | 2011-01-12 16:59:29 -0800 | [diff] [blame] | 266 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 267 | /* Skip Oopes when configured to do so. */ |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 268 | if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 269 | return -EINVAL; |
| 270 | |
| 271 | /* Explicitly only take the first part of any new crash. |
| 272 | * If our buffer is larger than kmsg_bytes, this can never happen, |
| 273 | * and if our buffer is smaller than kmsg_bytes, we don't want the |
| 274 | * report split across multiple records. |
| 275 | */ |
| 276 | if (part != 1) |
| 277 | return -ENOSPC; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 278 | |
Arve Hjønnevåg | c628937 | 2012-12-11 17:49:24 -0800 | [diff] [blame] | 279 | if (!cxt->przs) |
| 280 | return -ENOSPC; |
| 281 | |
| 282 | prz = cxt->przs[cxt->dump_write_cnt]; |
| 283 | |
Aruna Balakrishnaiah | 3f8f80f | 2013-08-16 13:58:00 -0700 | [diff] [blame] | 284 | hlen = ramoops_write_kmsg_hdr(prz, compressed); |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 285 | if (size + hlen > prz->buffer_size) |
| 286 | size = prz->buffer_size - hlen; |
Anton Vorontsov | c2b7113 | 2012-07-09 17:10:43 -0700 | [diff] [blame] | 287 | persistent_ram_write(prz, buf, size); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 288 | |
Anton Vorontsov | cac2eb7 | 2012-05-26 06:20:20 -0700 | [diff] [blame] | 289 | cxt->dump_write_cnt = (cxt->dump_write_cnt + 1) % cxt->max_dump_cnt; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 290 | |
| 291 | return 0; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Seiji Aguchi | 755d4fe | 2012-11-26 16:07:44 -0800 | [diff] [blame] | 294 | static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count, |
Seiji Aguchi | a9efd39 | 2012-11-14 20:27:28 +0000 | [diff] [blame] | 295 | struct timespec time, struct pstore_info *psi) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 296 | { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 297 | struct ramoops_context *cxt = psi->data; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 298 | struct persistent_ram_zone *prz; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 299 | |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 300 | switch (type) { |
| 301 | case PSTORE_TYPE_DMESG: |
| 302 | if (id >= cxt->max_dump_cnt) |
| 303 | return -EINVAL; |
| 304 | prz = cxt->przs[id]; |
| 305 | break; |
| 306 | case PSTORE_TYPE_CONSOLE: |
| 307 | prz = cxt->cprz; |
| 308 | break; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 309 | case PSTORE_TYPE_FTRACE: |
| 310 | prz = cxt->fprz; |
| 311 | break; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 312 | default: |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 313 | return -EINVAL; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 314 | } |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 315 | |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 316 | persistent_ram_free_old(prz); |
| 317 | persistent_ram_zap(prz); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static struct ramoops_context oops_cxt = { |
| 323 | .pstore = { |
| 324 | .owner = THIS_MODULE, |
| 325 | .name = "ramoops", |
| 326 | .open = ramoops_pstore_open, |
| 327 | .read = ramoops_pstore_read, |
Anton Vorontsov | c2b7113 | 2012-07-09 17:10:43 -0700 | [diff] [blame] | 328 | .write_buf = ramoops_pstore_write_buf, |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 329 | .erase = ramoops_pstore_erase, |
| 330 | }, |
| 331 | }; |
| 332 | |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 333 | static void ramoops_free_przs(struct ramoops_context *cxt) |
| 334 | { |
| 335 | int i; |
| 336 | |
Liu ShuoX | 34f0ec8 | 2014-03-17 14:07:00 -0700 | [diff] [blame] | 337 | cxt->max_dump_cnt = 0; |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 338 | if (!cxt->przs) |
| 339 | return; |
| 340 | |
Anton Vorontsov | 90b58d9 | 2012-06-18 19:15:51 -0700 | [diff] [blame] | 341 | for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++) |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 342 | persistent_ram_free(cxt->przs[i]); |
| 343 | kfree(cxt->przs); |
| 344 | } |
| 345 | |
Greg Kroah-Hartman | f568f6c | 2012-12-21 15:02:05 -0800 | [diff] [blame] | 346 | static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt, |
| 347 | phys_addr_t *paddr, size_t dump_mem_sz) |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 348 | { |
| 349 | int err = -ENOMEM; |
| 350 | int i; |
| 351 | |
| 352 | if (!cxt->record_size) |
| 353 | return 0; |
| 354 | |
Arve Hjønnevåg | c628937 | 2012-12-11 17:49:24 -0800 | [diff] [blame] | 355 | if (*paddr + dump_mem_sz - cxt->phys_addr > cxt->size) { |
| 356 | dev_err(dev, "no room for dumps\n"); |
| 357 | return -ENOMEM; |
| 358 | } |
| 359 | |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 360 | cxt->max_dump_cnt = dump_mem_sz / cxt->record_size; |
| 361 | if (!cxt->max_dump_cnt) |
| 362 | return -ENOMEM; |
| 363 | |
| 364 | cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_cnt, |
| 365 | GFP_KERNEL); |
| 366 | if (!cxt->przs) { |
| 367 | dev_err(dev, "failed to initialize a prz array for dumps\n"); |
Liu ShuoX | 34f0ec8 | 2014-03-17 14:07:00 -0700 | [diff] [blame] | 368 | goto fail_prz; |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | for (i = 0; i < cxt->max_dump_cnt; i++) { |
| 372 | size_t sz = cxt->record_size; |
| 373 | |
Arve Hjønnevåg | c31ad08 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 374 | cxt->przs[i] = persistent_ram_new(*paddr, sz, 0, |
Tony Lindgren | 027bc8b | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 375 | &cxt->ecc_info, |
| 376 | cxt->memtype); |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 377 | if (IS_ERR(cxt->przs[i])) { |
| 378 | err = PTR_ERR(cxt->przs[i]); |
| 379 | dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", |
| 380 | sz, (unsigned long long)*paddr, err); |
| 381 | goto fail_prz; |
| 382 | } |
| 383 | *paddr += sz; |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | fail_prz: |
| 388 | ramoops_free_przs(cxt); |
| 389 | return err; |
| 390 | } |
| 391 | |
Greg Kroah-Hartman | f568f6c | 2012-12-21 15:02:05 -0800 | [diff] [blame] | 392 | static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt, |
| 393 | struct persistent_ram_zone **prz, |
| 394 | phys_addr_t *paddr, size_t sz, u32 sig) |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 395 | { |
| 396 | if (!sz) |
| 397 | return 0; |
| 398 | |
Arve Hjønnevåg | c628937 | 2012-12-11 17:49:24 -0800 | [diff] [blame] | 399 | if (*paddr + sz - cxt->phys_addr > cxt->size) { |
| 400 | dev_err(dev, "no room for mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n", |
| 401 | sz, (unsigned long long)*paddr, |
| 402 | cxt->size, (unsigned long long)cxt->phys_addr); |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 403 | return -ENOMEM; |
Arve Hjønnevåg | c628937 | 2012-12-11 17:49:24 -0800 | [diff] [blame] | 404 | } |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 405 | |
Tony Lindgren | 027bc8b | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 406 | *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, cxt->memtype); |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 407 | if (IS_ERR(*prz)) { |
| 408 | int err = PTR_ERR(*prz); |
| 409 | |
| 410 | dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", |
| 411 | sz, (unsigned long long)*paddr, err); |
| 412 | return err; |
| 413 | } |
| 414 | |
| 415 | persistent_ram_zap(*prz); |
| 416 | |
| 417 | *paddr += sz; |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
Greg Kroah-Hartman | f568f6c | 2012-12-21 15:02:05 -0800 | [diff] [blame] | 422 | static int ramoops_probe(struct platform_device *pdev) |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 423 | { |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 424 | struct device *dev = &pdev->dev; |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 425 | struct ramoops_platform_data *pdata = pdev->dev.platform_data; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 426 | struct ramoops_context *cxt = &oops_cxt; |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 427 | size_t dump_mem_sz; |
| 428 | phys_addr_t paddr; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 429 | int err = -EINVAL; |
| 430 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 431 | /* Only a single ramoops area allowed at a time, so fail extra |
| 432 | * probes. |
| 433 | */ |
Anton Vorontsov | cac2eb7 | 2012-05-26 06:20:20 -0700 | [diff] [blame] | 434 | if (cxt->max_dump_cnt) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 435 | goto fail_out; |
| 436 | |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 437 | if (!pdata->mem_size || (!pdata->record_size && !pdata->console_size && |
| 438 | !pdata->ftrace_size)) { |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 439 | pr_err("The memory size and the record/console size must be " |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 440 | "non-zero\n"); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 441 | goto fail_out; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Maxime Bizon | 3bd11cf | 2013-08-30 18:06:41 +0200 | [diff] [blame] | 444 | if (pdata->record_size && !is_power_of_2(pdata->record_size)) |
Maxime Bizon | b042e47 | 2012-10-22 11:19:28 +0200 | [diff] [blame] | 445 | pdata->record_size = rounddown_pow_of_two(pdata->record_size); |
Maxime Bizon | 3bd11cf | 2013-08-30 18:06:41 +0200 | [diff] [blame] | 446 | if (pdata->console_size && !is_power_of_2(pdata->console_size)) |
Maxime Bizon | b042e47 | 2012-10-22 11:19:28 +0200 | [diff] [blame] | 447 | pdata->console_size = rounddown_pow_of_two(pdata->console_size); |
Maxime Bizon | 3bd11cf | 2013-08-30 18:06:41 +0200 | [diff] [blame] | 448 | if (pdata->ftrace_size && !is_power_of_2(pdata->ftrace_size)) |
Maxime Bizon | b042e47 | 2012-10-22 11:19:28 +0200 | [diff] [blame] | 449 | pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 450 | |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 451 | cxt->size = pdata->mem_size; |
| 452 | cxt->phys_addr = pdata->mem_address; |
Tony Lindgren | 027bc8b | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 453 | cxt->memtype = pdata->mem_type; |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 454 | cxt->record_size = pdata->record_size; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 455 | cxt->console_size = pdata->console_size; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 456 | cxt->ftrace_size = pdata->ftrace_size; |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 457 | cxt->dump_oops = pdata->dump_oops; |
Arve Hjønnevåg | c31ad08 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 458 | cxt->ecc_info = pdata->ecc_info; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 459 | |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 460 | paddr = cxt->phys_addr; |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 461 | |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 462 | dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size; |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 463 | err = ramoops_init_przs(dev, cxt, &paddr, dump_mem_sz); |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 464 | if (err) |
| 465 | goto fail_out; |
| 466 | |
Anton Vorontsov | cbe7cbf | 2012-07-17 12:11:12 -0700 | [diff] [blame] | 467 | err = ramoops_init_prz(dev, cxt, &cxt->cprz, &paddr, |
| 468 | cxt->console_size, 0); |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 469 | if (err) |
| 470 | goto fail_init_cprz; |
| 471 | |
Anton Vorontsov | cbe7cbf | 2012-07-17 12:11:12 -0700 | [diff] [blame] | 472 | err = ramoops_init_prz(dev, cxt, &cxt->fprz, &paddr, cxt->ftrace_size, |
| 473 | LINUX_VERSION_CODE); |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 474 | if (err) |
| 475 | goto fail_init_fprz; |
| 476 | |
| 477 | if (!cxt->przs && !cxt->cprz && !cxt->fprz) { |
Randy Dunlap | 0427193 | 2012-08-03 17:02:48 -0700 | [diff] [blame] | 478 | pr_err("memory size too small, minimum is %zu\n", |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 479 | cxt->console_size + cxt->record_size + |
| 480 | cxt->ftrace_size); |
Wei Yongjun | 47110b8 | 2013-05-07 19:39:20 +0800 | [diff] [blame] | 481 | err = -EINVAL; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 482 | goto fail_cnt; |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 485 | cxt->pstore.data = cxt; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 486 | /* |
Anton Vorontsov | a384f641 | 2012-07-19 15:47:11 -0700 | [diff] [blame] | 487 | * Console can handle any buffer size, so prefer LOG_LINE_MAX. If we |
| 488 | * have to handle dumps, we must have at least record_size buffer. And |
| 489 | * for ftrace, bufsize is irrelevant (if bufsize is 0, buf will be |
| 490 | * ZERO_SIZE_PTR). |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 491 | */ |
Anton Vorontsov | a384f641 | 2012-07-19 15:47:11 -0700 | [diff] [blame] | 492 | if (cxt->console_size) |
| 493 | cxt->pstore.bufsize = 1024; /* LOG_LINE_MAX */ |
| 494 | cxt->pstore.bufsize = max(cxt->record_size, cxt->pstore.bufsize); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 495 | cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL); |
| 496 | spin_lock_init(&cxt->pstore.buf_lock); |
| 497 | if (!cxt->pstore.buf) { |
| 498 | pr_err("cannot allocate pstore buffer\n"); |
Wei Yongjun | 47110b8 | 2013-05-07 19:39:20 +0800 | [diff] [blame] | 499 | err = -ENOMEM; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 500 | goto fail_clear; |
| 501 | } |
| 502 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 503 | err = pstore_register(&cxt->pstore); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 504 | if (err) { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 505 | pr_err("registering with pstore failed\n"); |
Anton Vorontsov | 896fc1f | 2012-05-17 00:15:18 -0700 | [diff] [blame] | 506 | goto fail_buf; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Kees Cook | c755201 | 2012-01-12 17:20:59 -0800 | [diff] [blame] | 509 | /* |
| 510 | * Update the module parameter variables as well so they are visible |
| 511 | * through /sys/module/ramoops/parameters/ |
| 512 | */ |
| 513 | mem_size = pdata->mem_size; |
| 514 | mem_address = pdata->mem_address; |
| 515 | record_size = pdata->record_size; |
| 516 | dump_oops = pdata->dump_oops; |
| 517 | |
Arve Hjønnevåg | c31ad08 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 518 | pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n", |
Randy Dunlap | d109a67 | 2012-05-03 15:45:03 +1000 | [diff] [blame] | 519 | cxt->size, (unsigned long long)cxt->phys_addr, |
Arve Hjønnevåg | c31ad08 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 520 | cxt->ecc_info.ecc_size, cxt->ecc_info.block_size); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 521 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 522 | return 0; |
| 523 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 524 | fail_buf: |
| 525 | kfree(cxt->pstore.buf); |
| 526 | fail_clear: |
| 527 | cxt->pstore.bufsize = 0; |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 528 | fail_cnt: |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 529 | kfree(cxt->fprz); |
| 530 | fail_init_fprz: |
Anton Vorontsov | b5d38e9 | 2012-05-26 06:20:23 -0700 | [diff] [blame] | 531 | kfree(cxt->cprz); |
| 532 | fail_init_cprz: |
Anton Vorontsov | f4c5d24 | 2012-05-26 06:20:21 -0700 | [diff] [blame] | 533 | ramoops_free_przs(cxt); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 534 | fail_out: |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 535 | return err; |
| 536 | } |
| 537 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 538 | static int __exit ramoops_remove(struct platform_device *pdev) |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 539 | { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 540 | #if 0 |
| 541 | /* TODO(kees): We cannot unload ramoops since pstore doesn't support |
| 542 | * unregistering yet. |
| 543 | */ |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 544 | struct ramoops_context *cxt = &oops_cxt; |
| 545 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 546 | iounmap(cxt->virt_addr); |
| 547 | release_mem_region(cxt->phys_addr, cxt->size); |
Anton Vorontsov | cac2eb7 | 2012-05-26 06:20:20 -0700 | [diff] [blame] | 548 | cxt->max_dump_cnt = 0; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 549 | |
| 550 | /* TODO(kees): When pstore supports unregistering, call it here. */ |
| 551 | kfree(cxt->pstore.buf); |
| 552 | cxt->pstore.bufsize = 0; |
| 553 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 554 | return 0; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 555 | #endif |
| 556 | return -EBUSY; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 559 | static struct platform_driver ramoops_driver = { |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 560 | .probe = ramoops_probe, |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 561 | .remove = __exit_p(ramoops_remove), |
| 562 | .driver = { |
| 563 | .name = "ramoops", |
| 564 | .owner = THIS_MODULE, |
| 565 | }, |
| 566 | }; |
| 567 | |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 568 | static void ramoops_register_dummy(void) |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 569 | { |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 570 | if (!mem_size) |
| 571 | return; |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 572 | |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 573 | pr_info("using module parameters\n"); |
| 574 | |
| 575 | dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL); |
| 576 | if (!dummy_data) { |
| 577 | pr_info("could not allocate pdata\n"); |
| 578 | return; |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 581 | dummy_data->mem_size = mem_size; |
| 582 | dummy_data->mem_address = mem_address; |
Tony Lindgren | 027bc8b | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 583 | dummy_data->mem_type = 0; |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 584 | dummy_data->record_size = record_size; |
| 585 | dummy_data->console_size = ramoops_console_size; |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 586 | dummy_data->ftrace_size = ramoops_ftrace_size; |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 587 | dummy_data->dump_oops = dump_oops; |
Anton Vorontsov | 5ca5d4e | 2012-07-09 17:03:19 -0700 | [diff] [blame] | 588 | /* |
| 589 | * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC |
| 590 | * (using 1 byte for ECC isn't much of use anyway). |
| 591 | */ |
Arve Hjønnevåg | c31ad08 | 2012-05-22 16:33:23 -0700 | [diff] [blame] | 592 | dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 593 | |
| 594 | dummy = platform_device_register_data(NULL, "ramoops", -1, |
| 595 | dummy_data, sizeof(struct ramoops_platform_data)); |
| 596 | if (IS_ERR(dummy)) { |
| 597 | pr_info("could not create platform device: %ld\n", |
| 598 | PTR_ERR(dummy)); |
| 599 | } |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Anton Vorontsov | 924d371 | 2012-06-18 19:15:50 -0700 | [diff] [blame] | 602 | static int __init ramoops_init(void) |
| 603 | { |
| 604 | ramoops_register_dummy(); |
| 605 | return platform_driver_register(&ramoops_driver); |
| 606 | } |
| 607 | postcore_initcall(ramoops_init); |
| 608 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 609 | static void __exit ramoops_exit(void) |
| 610 | { |
| 611 | platform_driver_unregister(&ramoops_driver); |
Jovi Zhang | b4a871b | 2012-08-20 14:58:26 +0800 | [diff] [blame] | 612 | platform_device_unregister(dummy); |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 613 | kfree(dummy_data); |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 614 | } |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 615 | module_exit(ramoops_exit); |
| 616 | |
| 617 | MODULE_LICENSE("GPL"); |
| 618 | MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>"); |
| 619 | MODULE_DESCRIPTION("RAM Oops/Panic logger/driver"); |