blob: 58b93fbd117e0a032b8b815919c06b058746a897 [file] [log] [blame]
Marco Stornelli56d611a2010-05-26 14:43:54 -07001/*
2 * RAM Oops/Panic logger
3 *
4 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
Kees Cook9ba80d92012-05-03 15:45:02 +10005 * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
Marco Stornelli56d611a2010-05-26 14:43:54 -07006 *
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 Stornelli01692562011-07-26 16:08:57 -070023#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
Marco Stornelli56d611a2010-05-26 14:43:54 -070025#include <linux/kernel.h>
James Bottomley83c1b312011-07-29 17:11:32 +040026#include <linux/err.h>
Marco Stornelli56d611a2010-05-26 14:43:54 -070027#include <linux/module.h>
Kees Cook9ba80d92012-05-03 15:45:02 +100028#include <linux/pstore.h>
Marco Stornelli56d611a2010-05-26 14:43:54 -070029#include <linux/time.h>
30#include <linux/io.h>
31#include <linux/ioport.h>
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -070032#include <linux/platform_device.h>
Marco Stornelli13aefd72011-07-26 16:08:57 -070033#include <linux/slab.h>
Anton Vorontsov1894a252012-05-16 05:43:08 -070034#include <linux/pstore_ram.h>
Marco Stornelli56d611a2010-05-26 14:43:54 -070035
36#define RAMOOPS_KERNMSG_HDR "===="
Sergiu Iordache3e5c4fa2011-07-26 16:08:59 -070037#define MIN_MEM_SIZE 4096UL
Marco Stornelli56d611a2010-05-26 14:43:54 -070038
Sergiu Iordache3e5c4fa2011-07-26 16:08:59 -070039static ulong record_size = MIN_MEM_SIZE;
40module_param(record_size, ulong, 0400);
41MODULE_PARM_DESC(record_size,
42 "size of each dump done on oops/panic");
Marco Stornelli56d611a2010-05-26 14:43:54 -070043
Anton Vorontsovb5d38e92012-05-26 06:20:23 -070044static ulong ramoops_console_size = MIN_MEM_SIZE;
45module_param_named(console_size, ramoops_console_size, ulong, 0400);
46MODULE_PARM_DESC(console_size, "size of kernel console log");
47
Marco Stornelli56d611a2010-05-26 14:43:54 -070048static ulong mem_address;
49module_param(mem_address, ulong, 0400);
50MODULE_PARM_DESC(mem_address,
51 "start of reserved RAM used to store oops/panic logs");
52
53static ulong mem_size;
54module_param(mem_size, ulong, 0400);
55MODULE_PARM_DESC(mem_size,
56 "size of reserved RAM used to store oops/panic logs");
57
58static int dump_oops = 1;
59module_param(dump_oops, int, 0600);
60MODULE_PARM_DESC(dump_oops,
61 "set to 1 to dump oopses, 0 to only dump panics (default 1)");
62
Anton Vorontsov39eb7e972012-05-17 00:15:34 -070063static int ramoops_ecc;
64module_param_named(ecc, ramoops_ecc, int, 0600);
65MODULE_PARM_DESC(ramoops_ecc,
66 "set to 1 to enable ECC support");
67
Kees Cook9ba80d92012-05-03 15:45:02 +100068struct ramoops_context {
Anton Vorontsov896fc1f2012-05-17 00:15:18 -070069 struct persistent_ram_zone **przs;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -070070 struct persistent_ram_zone *cprz;
Marco Stornelli56d611a2010-05-26 14:43:54 -070071 phys_addr_t phys_addr;
72 unsigned long size;
Kees Cook9ba80d92012-05-03 15:45:02 +100073 size_t record_size;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -070074 size_t console_size;
Sergiu Iordache6b4d2a22011-07-26 16:08:58 -070075 int dump_oops;
Anton Vorontsov39eb7e972012-05-17 00:15:34 -070076 bool ecc;
Anton Vorontsovcac2eb72012-05-26 06:20:20 -070077 unsigned int max_dump_cnt;
78 unsigned int dump_write_cnt;
79 unsigned int dump_read_cnt;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -070080 unsigned int console_read_cnt;
Kees Cook9ba80d92012-05-03 15:45:02 +100081 struct pstore_info pstore;
82};
Marco Stornelli56d611a2010-05-26 14:43:54 -070083
Marco Stornelli13aefd72011-07-26 16:08:57 -070084static struct platform_device *dummy;
85static struct ramoops_platform_data *dummy_data;
86
Kees Cook9ba80d92012-05-03 15:45:02 +100087static int ramoops_pstore_open(struct pstore_info *psi)
Marco Stornelli56d611a2010-05-26 14:43:54 -070088{
Kees Cook9ba80d92012-05-03 15:45:02 +100089 struct ramoops_context *cxt = psi->data;
Marco Stornelli56d611a2010-05-26 14:43:54 -070090
Anton Vorontsovcac2eb72012-05-26 06:20:20 -070091 cxt->dump_read_cnt = 0;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -070092 cxt->console_read_cnt = 0;
Kees Cook9ba80d92012-05-03 15:45:02 +100093 return 0;
94}
95
Anton Vorontsov755d66b2012-05-26 06:20:22 -070096static struct persistent_ram_zone *
97ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
98 u64 *id,
99 enum pstore_type_id *typep, enum pstore_type_id type,
100 bool update)
101{
102 struct persistent_ram_zone *prz;
103 int i = (*c)++;
104
105 if (i >= max)
106 return NULL;
107
108 prz = przs[i];
109
110 if (update) {
111 /* Update old/shadowed buffer. */
112 persistent_ram_save_old(prz);
113 if (!persistent_ram_old_size(prz))
114 return NULL;
115 }
116
117 *typep = type;
118 *id = i;
119
120 return prz;
121}
122
Kees Cook9ba80d92012-05-03 15:45:02 +1000123static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
124 struct timespec *time,
125 char **buf,
126 struct pstore_info *psi)
127{
128 ssize_t size;
Kees Cook9ba80d92012-05-03 15:45:02 +1000129 struct ramoops_context *cxt = psi->data;
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700130 struct persistent_ram_zone *prz;
Kees Cook9ba80d92012-05-03 15:45:02 +1000131
Anton Vorontsov755d66b2012-05-26 06:20:22 -0700132 prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt,
133 cxt->max_dump_cnt, id, type,
134 PSTORE_TYPE_DMESG, 1);
135 if (!prz)
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700136 prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt,
137 1, id, type, PSTORE_TYPE_CONSOLE, 0);
138 if (!prz)
Anton Vorontsov755d66b2012-05-26 06:20:22 -0700139 return 0;
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700140
Kees Cook9ba80d92012-05-03 15:45:02 +1000141 /* TODO(kees): Bogus time for the moment. */
142 time->tv_sec = 0;
143 time->tv_nsec = 0;
144
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700145 size = persistent_ram_old_size(prz);
Kees Cook9ba80d92012-05-03 15:45:02 +1000146 *buf = kmalloc(size, GFP_KERNEL);
147 if (*buf == NULL)
148 return -ENOMEM;
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700149 memcpy(*buf, persistent_ram_old(prz), size);
Kees Cook9ba80d92012-05-03 15:45:02 +1000150
151 return size;
152}
153
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700154static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
155{
156 char *hdr;
157 struct timeval timestamp;
158 size_t len;
159
160 do_gettimeofday(&timestamp);
161 hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
162 (long)timestamp.tv_sec, (long)timestamp.tv_usec);
163 WARN_ON_ONCE(!hdr);
164 len = hdr ? strlen(hdr) : 0;
165 persistent_ram_write(prz, hdr, len);
166 kfree(hdr);
167
168 return len;
169}
170
Kees Cook9ba80d92012-05-03 15:45:02 +1000171static int ramoops_pstore_write(enum pstore_type_id type,
172 enum kmsg_dump_reason reason,
173 u64 *id,
174 unsigned int part,
175 size_t size, struct pstore_info *psi)
176{
Kees Cook9ba80d92012-05-03 15:45:02 +1000177 struct ramoops_context *cxt = psi->data;
Anton Vorontsovcac2eb72012-05-26 06:20:20 -0700178 struct persistent_ram_zone *prz = cxt->przs[cxt->dump_write_cnt];
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700179 size_t hlen;
Kees Cook9ba80d92012-05-03 15:45:02 +1000180
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700181 if (type == PSTORE_TYPE_CONSOLE) {
182 if (!cxt->cprz)
183 return -ENOMEM;
184 persistent_ram_write(cxt->cprz, cxt->pstore.buf, size);
185 return 0;
186 }
187
Kees Cook9ba80d92012-05-03 15:45:02 +1000188 if (type != PSTORE_TYPE_DMESG)
189 return -EINVAL;
190
191 /* Out of the various dmesg dump types, ramoops is currently designed
192 * to only store crash logs, rather than storing general kernel logs.
193 */
Seiji Aguchifc2d5572011-01-12 16:59:29 -0800194 if (reason != KMSG_DUMP_OOPS &&
WANG Conga3dd3322012-01-12 17:20:11 -0800195 reason != KMSG_DUMP_PANIC)
Kees Cook9ba80d92012-05-03 15:45:02 +1000196 return -EINVAL;
Seiji Aguchifc2d5572011-01-12 16:59:29 -0800197
Kees Cook9ba80d92012-05-03 15:45:02 +1000198 /* Skip Oopes when configured to do so. */
Sergiu Iordache6b4d2a22011-07-26 16:08:58 -0700199 if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
Kees Cook9ba80d92012-05-03 15:45:02 +1000200 return -EINVAL;
201
202 /* Explicitly only take the first part of any new crash.
203 * If our buffer is larger than kmsg_bytes, this can never happen,
204 * and if our buffer is smaller than kmsg_bytes, we don't want the
205 * report split across multiple records.
206 */
207 if (part != 1)
208 return -ENOSPC;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700209
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700210 hlen = ramoops_write_kmsg_hdr(prz);
211 if (size + hlen > prz->buffer_size)
212 size = prz->buffer_size - hlen;
213 persistent_ram_write(prz, cxt->pstore.buf, size);
Marco Stornelli56d611a2010-05-26 14:43:54 -0700214
Anton Vorontsovcac2eb72012-05-26 06:20:20 -0700215 cxt->dump_write_cnt = (cxt->dump_write_cnt + 1) % cxt->max_dump_cnt;
Kees Cook9ba80d92012-05-03 15:45:02 +1000216
217 return 0;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700218}
219
Kees Cook9ba80d92012-05-03 15:45:02 +1000220static int ramoops_pstore_erase(enum pstore_type_id type, u64 id,
221 struct pstore_info *psi)
222{
Kees Cook9ba80d92012-05-03 15:45:02 +1000223 struct ramoops_context *cxt = psi->data;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700224 struct persistent_ram_zone *prz;
Kees Cook9ba80d92012-05-03 15:45:02 +1000225
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700226 switch (type) {
227 case PSTORE_TYPE_DMESG:
228 if (id >= cxt->max_dump_cnt)
229 return -EINVAL;
230 prz = cxt->przs[id];
231 break;
232 case PSTORE_TYPE_CONSOLE:
233 prz = cxt->cprz;
234 break;
235 default:
Kees Cook9ba80d92012-05-03 15:45:02 +1000236 return -EINVAL;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700237 }
Kees Cook9ba80d92012-05-03 15:45:02 +1000238
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700239 persistent_ram_free_old(prz);
240 persistent_ram_zap(prz);
Kees Cook9ba80d92012-05-03 15:45:02 +1000241
242 return 0;
243}
244
245static struct ramoops_context oops_cxt = {
246 .pstore = {
247 .owner = THIS_MODULE,
248 .name = "ramoops",
249 .open = ramoops_pstore_open,
250 .read = ramoops_pstore_read,
251 .write = ramoops_pstore_write,
252 .erase = ramoops_pstore_erase,
253 },
254};
255
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700256static void ramoops_free_przs(struct ramoops_context *cxt)
257{
258 int i;
259
260 if (!cxt->przs)
261 return;
262
Anton Vorontsov90b58d92012-06-18 19:15:51 -0700263 for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++)
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700264 persistent_ram_free(cxt->przs[i]);
265 kfree(cxt->przs);
266}
267
268static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
269 phys_addr_t *paddr, size_t dump_mem_sz)
270{
271 int err = -ENOMEM;
272 int i;
273
274 if (!cxt->record_size)
275 return 0;
276
277 cxt->max_dump_cnt = dump_mem_sz / cxt->record_size;
278 if (!cxt->max_dump_cnt)
279 return -ENOMEM;
280
281 cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_cnt,
282 GFP_KERNEL);
283 if (!cxt->przs) {
284 dev_err(dev, "failed to initialize a prz array for dumps\n");
285 return -ENOMEM;
286 }
287
288 for (i = 0; i < cxt->max_dump_cnt; i++) {
289 size_t sz = cxt->record_size;
290
291 cxt->przs[i] = persistent_ram_new(*paddr, sz, cxt->ecc);
292 if (IS_ERR(cxt->przs[i])) {
293 err = PTR_ERR(cxt->przs[i]);
294 dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
295 sz, (unsigned long long)*paddr, err);
296 goto fail_prz;
297 }
298 *paddr += sz;
299 }
300
301 return 0;
302fail_prz:
303 ramoops_free_przs(cxt);
304 return err;
305}
306
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700307static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
308 struct persistent_ram_zone **prz,
309 phys_addr_t *paddr, size_t sz)
310{
311 if (!sz)
312 return 0;
313
314 if (*paddr + sz > *paddr + cxt->size)
315 return -ENOMEM;
316
317 *prz = persistent_ram_new(*paddr, sz, cxt->ecc);
318 if (IS_ERR(*prz)) {
319 int err = PTR_ERR(*prz);
320
321 dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
322 sz, (unsigned long long)*paddr, err);
323 return err;
324 }
325
326 persistent_ram_zap(*prz);
327
328 *paddr += sz;
329
330 return 0;
331}
332
Anton Vorontsov924d3712012-06-18 19:15:50 -0700333static int __devinit ramoops_probe(struct platform_device *pdev)
Marco Stornelli56d611a2010-05-26 14:43:54 -0700334{
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700335 struct device *dev = &pdev->dev;
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700336 struct ramoops_platform_data *pdata = pdev->dev.platform_data;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700337 struct ramoops_context *cxt = &oops_cxt;
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700338 size_t dump_mem_sz;
339 phys_addr_t paddr;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700340 int err = -EINVAL;
341
Kees Cook9ba80d92012-05-03 15:45:02 +1000342 /* Only a single ramoops area allowed at a time, so fail extra
343 * probes.
344 */
Anton Vorontsovcac2eb72012-05-26 06:20:20 -0700345 if (cxt->max_dump_cnt)
Kees Cook9ba80d92012-05-03 15:45:02 +1000346 goto fail_out;
347
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700348 if (!pdata->mem_size || (!pdata->record_size && !pdata->console_size)) {
349 pr_err("The memory size and the record/console size must be "
Sergiu Iordache3e5c4fa2011-07-26 16:08:59 -0700350 "non-zero\n");
Kees Cook9ba80d92012-05-03 15:45:02 +1000351 goto fail_out;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700352 }
353
Marco Stornellifdb59502012-01-12 17:20:58 -0800354 pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
355 pdata->record_size = rounddown_pow_of_two(pdata->record_size);
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700356 pdata->console_size = rounddown_pow_of_two(pdata->console_size);
Marco Stornelli56d611a2010-05-26 14:43:54 -0700357
Anton Vorontsovcac2eb72012-05-26 06:20:20 -0700358 cxt->dump_read_cnt = 0;
Marco Stornelli13aefd72011-07-26 16:08:57 -0700359 cxt->size = pdata->mem_size;
360 cxt->phys_addr = pdata->mem_address;
Sergiu Iordache3e5c4fa2011-07-26 16:08:59 -0700361 cxt->record_size = pdata->record_size;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700362 cxt->console_size = pdata->console_size;
Sergiu Iordache6b4d2a22011-07-26 16:08:58 -0700363 cxt->dump_oops = pdata->dump_oops;
Anton Vorontsov39eb7e972012-05-17 00:15:34 -0700364 cxt->ecc = pdata->ecc;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700365
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700366 paddr = cxt->phys_addr;
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700367
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700368 dump_mem_sz = cxt->size - cxt->console_size;
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700369 err = ramoops_init_przs(dev, cxt, &paddr, dump_mem_sz);
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700370 if (err)
371 goto fail_out;
372
373 err = ramoops_init_prz(dev, cxt, &cxt->cprz, &paddr, cxt->console_size);
374 if (err)
375 goto fail_init_cprz;
376
377 if (!cxt->przs && !cxt->cprz) {
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700378 pr_err("memory size too small, minimum is %lu\n",
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700379 cxt->console_size + cxt->record_size);
380 goto fail_cnt;
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700381 }
382
Kees Cook9ba80d92012-05-03 15:45:02 +1000383 cxt->pstore.data = cxt;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700384 /*
385 * Console can handle any buffer size, so prefer dumps buffer
386 * size since usually it is smaller.
387 */
388 if (cxt->przs)
389 cxt->pstore.bufsize = cxt->przs[0]->buffer_size;
390 else
391 cxt->pstore.bufsize = cxt->cprz->buffer_size;
Kees Cook9ba80d92012-05-03 15:45:02 +1000392 cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL);
393 spin_lock_init(&cxt->pstore.buf_lock);
394 if (!cxt->pstore.buf) {
395 pr_err("cannot allocate pstore buffer\n");
396 goto fail_clear;
397 }
398
Kees Cook9ba80d92012-05-03 15:45:02 +1000399 err = pstore_register(&cxt->pstore);
Marco Stornelli56d611a2010-05-26 14:43:54 -0700400 if (err) {
Kees Cook9ba80d92012-05-03 15:45:02 +1000401 pr_err("registering with pstore failed\n");
Anton Vorontsov896fc1f2012-05-17 00:15:18 -0700402 goto fail_buf;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700403 }
404
Kees Cookc7552012012-01-12 17:20:59 -0800405 /*
406 * Update the module parameter variables as well so they are visible
407 * through /sys/module/ramoops/parameters/
408 */
409 mem_size = pdata->mem_size;
410 mem_address = pdata->mem_address;
411 record_size = pdata->record_size;
412 dump_oops = pdata->dump_oops;
413
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700414 pr_info("attached 0x%lx@0x%llx, ecc: %s\n",
Randy Dunlapd109a672012-05-03 15:45:03 +1000415 cxt->size, (unsigned long long)cxt->phys_addr,
Anton Vorontsov39eb7e972012-05-17 00:15:34 -0700416 ramoops_ecc ? "on" : "off");
Kees Cook9ba80d92012-05-03 15:45:02 +1000417
Marco Stornelli56d611a2010-05-26 14:43:54 -0700418 return 0;
419
Kees Cook9ba80d92012-05-03 15:45:02 +1000420fail_buf:
421 kfree(cxt->pstore.buf);
422fail_clear:
423 cxt->pstore.bufsize = 0;
Anton Vorontsovcac2eb72012-05-26 06:20:20 -0700424 cxt->max_dump_cnt = 0;
Anton Vorontsovb5d38e92012-05-26 06:20:23 -0700425fail_cnt:
426 kfree(cxt->cprz);
427fail_init_cprz:
Anton Vorontsovf4c5d242012-05-26 06:20:21 -0700428 ramoops_free_przs(cxt);
Kees Cook9ba80d92012-05-03 15:45:02 +1000429fail_out:
Marco Stornelli56d611a2010-05-26 14:43:54 -0700430 return err;
431}
432
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700433static int __exit ramoops_remove(struct platform_device *pdev)
Marco Stornelli56d611a2010-05-26 14:43:54 -0700434{
Kees Cook9ba80d92012-05-03 15:45:02 +1000435#if 0
436 /* TODO(kees): We cannot unload ramoops since pstore doesn't support
437 * unregistering yet.
438 */
Marco Stornelli56d611a2010-05-26 14:43:54 -0700439 struct ramoops_context *cxt = &oops_cxt;
440
Marco Stornelli56d611a2010-05-26 14:43:54 -0700441 iounmap(cxt->virt_addr);
442 release_mem_region(cxt->phys_addr, cxt->size);
Anton Vorontsovcac2eb72012-05-26 06:20:20 -0700443 cxt->max_dump_cnt = 0;
Kees Cook9ba80d92012-05-03 15:45:02 +1000444
445 /* TODO(kees): When pstore supports unregistering, call it here. */
446 kfree(cxt->pstore.buf);
447 cxt->pstore.bufsize = 0;
448
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700449 return 0;
Kees Cook9ba80d92012-05-03 15:45:02 +1000450#endif
451 return -EBUSY;
Marco Stornelli56d611a2010-05-26 14:43:54 -0700452}
453
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700454static struct platform_driver ramoops_driver = {
Anton Vorontsov924d3712012-06-18 19:15:50 -0700455 .probe = ramoops_probe,
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700456 .remove = __exit_p(ramoops_remove),
457 .driver = {
458 .name = "ramoops",
459 .owner = THIS_MODULE,
460 },
461};
462
Anton Vorontsov924d3712012-06-18 19:15:50 -0700463static void ramoops_register_dummy(void)
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700464{
Anton Vorontsov924d3712012-06-18 19:15:50 -0700465 if (!mem_size)
466 return;
Marco Stornelli13aefd72011-07-26 16:08:57 -0700467
Anton Vorontsov924d3712012-06-18 19:15:50 -0700468 pr_info("using module parameters\n");
469
470 dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL);
471 if (!dummy_data) {
472 pr_info("could not allocate pdata\n");
473 return;
Marco Stornelli13aefd72011-07-26 16:08:57 -0700474 }
475
Anton Vorontsov924d3712012-06-18 19:15:50 -0700476 dummy_data->mem_size = mem_size;
477 dummy_data->mem_address = mem_address;
478 dummy_data->record_size = record_size;
479 dummy_data->console_size = ramoops_console_size;
480 dummy_data->dump_oops = dump_oops;
481 dummy_data->ecc = ramoops_ecc;
482
483 dummy = platform_device_register_data(NULL, "ramoops", -1,
484 dummy_data, sizeof(struct ramoops_platform_data));
485 if (IS_ERR(dummy)) {
486 pr_info("could not create platform device: %ld\n",
487 PTR_ERR(dummy));
488 }
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700489}
490
Anton Vorontsov924d3712012-06-18 19:15:50 -0700491static int __init ramoops_init(void)
492{
493 ramoops_register_dummy();
494 return platform_driver_register(&ramoops_driver);
495}
496postcore_initcall(ramoops_init);
497
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700498static void __exit ramoops_exit(void)
499{
500 platform_driver_unregister(&ramoops_driver);
Marco Stornelli13aefd72011-07-26 16:08:57 -0700501 kfree(dummy_data);
Kyungmin Parkc3b92ce2010-10-27 15:34:52 -0700502}
Marco Stornelli56d611a2010-05-26 14:43:54 -0700503module_exit(ramoops_exit);
504
505MODULE_LICENSE("GPL");
506MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>");
507MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");