pstore-ram: Allow optional mapping with pgprot_noncached
[linux-2.6-block.git] / fs / pstore / ram.c
CommitLineData
56d611a0
MS
1/*
2 * RAM Oops/Panic logger
3 *
4 * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
9ba80d99 5 * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
56d611a0
MS
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
0169256e
MS
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
56d611a0 25#include <linux/kernel.h>
83c1b317 26#include <linux/err.h>
56d611a0 27#include <linux/module.h>
cbe7cbf5 28#include <linux/version.h>
9ba80d99 29#include <linux/pstore.h>
56d611a0
MS
30#include <linux/time.h>
31#include <linux/io.h>
32#include <linux/ioport.h>
c3b92ce9 33#include <linux/platform_device.h>
13aefd72 34#include <linux/slab.h>
24203036 35#include <linux/compiler.h>
1894a253 36#include <linux/pstore_ram.h>
56d611a0
MS
37
38#define RAMOOPS_KERNMSG_HDR "===="
3e5c4fad 39#define MIN_MEM_SIZE 4096UL
56d611a0 40
3e5c4fad
SI
41static ulong record_size = MIN_MEM_SIZE;
42module_param(record_size, ulong, 0400);
43MODULE_PARM_DESC(record_size,
44 "size of each dump done on oops/panic");
56d611a0 45
b5d38e9b
AV
46static ulong ramoops_console_size = MIN_MEM_SIZE;
47module_param_named(console_size, ramoops_console_size, ulong, 0400);
48MODULE_PARM_DESC(console_size, "size of kernel console log");
49
a694d1b5
AV
50static ulong ramoops_ftrace_size = MIN_MEM_SIZE;
51module_param_named(ftrace_size, ramoops_ftrace_size, ulong, 0400);
52MODULE_PARM_DESC(ftrace_size, "size of ftrace log");
53
56d611a0
MS
54static ulong mem_address;
55module_param(mem_address, ulong, 0400);
56MODULE_PARM_DESC(mem_address,
57 "start of reserved RAM used to store oops/panic logs");
58
59static ulong mem_size;
60module_param(mem_size, ulong, 0400);
61MODULE_PARM_DESC(mem_size,
62 "size of reserved RAM used to store oops/panic logs");
63
027bc8b0
TL
64static unsigned int mem_type;
65module_param(mem_type, uint, 0600);
66MODULE_PARM_DESC(mem_type,
67 "set to 1 to try to use unbuffered memory (default 0)");
68
56d611a0
MS
69static int dump_oops = 1;
70module_param(dump_oops, int, 0600);
71MODULE_PARM_DESC(dump_oops,
72 "set to 1 to dump oopses, 0 to only dump panics (default 1)");
73
39eb7e97
AV
74static int ramoops_ecc;
75module_param_named(ecc, ramoops_ecc, int, 0600);
76MODULE_PARM_DESC(ramoops_ecc,
5ca5d4e6
AV
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)");
39eb7e97 80
9ba80d99 81struct ramoops_context {
896fc1f0 82 struct persistent_ram_zone **przs;
b5d38e9b 83 struct persistent_ram_zone *cprz;
a694d1b5 84 struct persistent_ram_zone *fprz;
56d611a0
MS
85 phys_addr_t phys_addr;
86 unsigned long size;
027bc8b0 87 unsigned int memtype;
9ba80d99 88 size_t record_size;
b5d38e9b 89 size_t console_size;
a694d1b5 90 size_t ftrace_size;
6b4d2a27 91 int dump_oops;
c31ad081 92 struct persistent_ram_ecc_info ecc_info;
cac2eb7b
AV
93 unsigned int max_dump_cnt;
94 unsigned int dump_write_cnt;
57fd8353 95 /* _read_cnt need clear on ramoops_pstore_open */
cac2eb7b 96 unsigned int dump_read_cnt;
b5d38e9b 97 unsigned int console_read_cnt;
a694d1b5 98 unsigned int ftrace_read_cnt;
9ba80d99
KC
99 struct pstore_info pstore;
100};
56d611a0 101
13aefd72
MS
102static struct platform_device *dummy;
103static struct ramoops_platform_data *dummy_data;
104
9ba80d99
KC
105static int ramoops_pstore_open(struct pstore_info *psi)
106{
107 struct ramoops_context *cxt = psi->data;
108
cac2eb7b 109 cxt->dump_read_cnt = 0;
b5d38e9b 110 cxt->console_read_cnt = 0;
57fd8353 111 cxt->ftrace_read_cnt = 0;
9ba80d99
KC
112 return 0;
113}
114
755d66b4
AV
115static struct persistent_ram_zone *
116ramoops_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];
b0aa931f
LS
128 if (!prz)
129 return NULL;
755d66b4 130
aa9a4a1e
LS
131 /* Update old/shadowed buffer. */
132 if (update)
755d66b4 133 persistent_ram_save_old(prz);
aa9a4a1e
LS
134
135 if (!persistent_ram_old_size(prz))
136 return NULL;
755d66b4
AV
137
138 *typep = type;
139 *id = i;
140
141 return prz;
142}
143
a28726b4 144static int ramoops_read_kmsg_hdr(char *buffer, struct timespec *time,
3f8f80f0
AB
145 bool *compressed)
146{
147 char data_type;
a28726b4 148 int header_length = 0;
3f8f80f0 149
a28726b4
BZ
150 if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n%n", &time->tv_sec,
151 &time->tv_nsec, &data_type, &header_length) == 3) {
3f8f80f0
AB
152 if (data_type == 'C')
153 *compressed = true;
154 else
155 *compressed = false;
a28726b4
BZ
156 } else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu\n%n",
157 &time->tv_sec, &time->tv_nsec, &header_length) == 2) {
3f8f80f0
AB
158 *compressed = false;
159 } else {
160 time->tv_sec = 0;
161 time->tv_nsec = 0;
162 *compressed = false;
163 }
a28726b4 164 return header_length;
3f8f80f0
AB
165}
166
9ba80d99 167static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
755d4fe4 168 int *count, struct timespec *time,
9a4e1398
AB
169 char **buf, bool *compressed,
170 struct pstore_info *psi)
56d611a0 171{
9ba80d99 172 ssize_t size;
bd08ec33 173 ssize_t ecc_notice_size;
9ba80d99 174 struct ramoops_context *cxt = psi->data;
896fc1f0 175 struct persistent_ram_zone *prz;
a28726b4 176 int header_length;
9ba80d99 177
755d66b4
AV
178 prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt,
179 cxt->max_dump_cnt, id, type,
180 PSTORE_TYPE_DMESG, 1);
b5d38e9b
AV
181 if (!prz)
182 prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt,
183 1, id, type, PSTORE_TYPE_CONSOLE, 0);
a694d1b5
AV
184 if (!prz)
185 prz = ramoops_get_next_prz(&cxt->fprz, &cxt->ftrace_read_cnt,
186 1, id, type, PSTORE_TYPE_FTRACE, 0);
755d66b4
AV
187 if (!prz)
188 return 0;
896fc1f0 189
a28726b4
BZ
190 if (!persistent_ram_old(prz))
191 return 0;
192
896fc1f0 193 size = persistent_ram_old_size(prz);
a28726b4
BZ
194 header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz), time,
195 compressed);
196 size -= header_length;
bd08ec33
AH
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);
9ba80d99
KC
202 if (*buf == NULL)
203 return -ENOMEM;
9ba80d99 204
a28726b4 205 memcpy(*buf, (char *)persistent_ram_old(prz) + header_length, size);
bd08ec33
AH
206 persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1);
207
208 return size + ecc_notice_size;
9ba80d99
KC
209}
210
3f8f80f0
AB
211static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
212 bool compressed)
896fc1f0
AV
213{
214 char *hdr;
1e817fb6 215 struct timespec timestamp;
896fc1f0
AV
216 size_t len;
217
1e817fb6
KC
218 /* Report zeroed timestamp if called before timekeeping has resumed. */
219 if (__getnstimeofday(&timestamp)) {
220 timestamp.tv_sec = 0;
221 timestamp.tv_nsec = 0;
222 }
3f8f80f0
AB
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');
896fc1f0
AV
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
24203036
AV
234static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
235 enum kmsg_dump_reason reason,
236 u64 *id, unsigned int part,
6bbbca73 237 const char *buf,
b3b515bb 238 bool compressed, size_t size,
24203036 239 struct pstore_info *psi)
9ba80d99 240{
9ba80d99 241 struct ramoops_context *cxt = psi->data;
c6289378 242 struct persistent_ram_zone *prz;
896fc1f0 243 size_t hlen;
9ba80d99 244
b5d38e9b
AV
245 if (type == PSTORE_TYPE_CONSOLE) {
246 if (!cxt->cprz)
247 return -ENOMEM;
c2b71132 248 persistent_ram_write(cxt->cprz, buf, size);
b5d38e9b 249 return 0;
a694d1b5
AV
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;
b5d38e9b
AV
255 }
256
9ba80d99
KC
257 if (type != PSTORE_TYPE_DMESG)
258 return -EINVAL;
56d611a0 259
9ba80d99
KC
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 */
fc2d557c 263 if (reason != KMSG_DUMP_OOPS &&
a3dd3323 264 reason != KMSG_DUMP_PANIC)
9ba80d99 265 return -EINVAL;
fc2d557c 266
9ba80d99 267 /* Skip Oopes when configured to do so. */
6b4d2a27 268 if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
9ba80d99
KC
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;
56d611a0 278
c6289378
AH
279 if (!cxt->przs)
280 return -ENOSPC;
281
282 prz = cxt->przs[cxt->dump_write_cnt];
283
3f8f80f0 284 hlen = ramoops_write_kmsg_hdr(prz, compressed);
896fc1f0
AV
285 if (size + hlen > prz->buffer_size)
286 size = prz->buffer_size - hlen;
c2b71132 287 persistent_ram_write(prz, buf, size);
56d611a0 288
cac2eb7b 289 cxt->dump_write_cnt = (cxt->dump_write_cnt + 1) % cxt->max_dump_cnt;
9ba80d99
KC
290
291 return 0;
292}
293
755d4fe4 294static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,
a9efd39c 295 struct timespec time, struct pstore_info *psi)
9ba80d99 296{
9ba80d99 297 struct ramoops_context *cxt = psi->data;
b5d38e9b 298 struct persistent_ram_zone *prz;
9ba80d99 299
b5d38e9b
AV
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;
a694d1b5
AV
309 case PSTORE_TYPE_FTRACE:
310 prz = cxt->fprz;
311 break;
b5d38e9b 312 default:
9ba80d99 313 return -EINVAL;
b5d38e9b 314 }
9ba80d99 315
b5d38e9b
AV
316 persistent_ram_free_old(prz);
317 persistent_ram_zap(prz);
9ba80d99
KC
318
319 return 0;
56d611a0
MS
320}
321
9ba80d99
KC
322static struct ramoops_context oops_cxt = {
323 .pstore = {
324 .owner = THIS_MODULE,
325 .name = "ramoops",
326 .open = ramoops_pstore_open,
327 .read = ramoops_pstore_read,
c2b71132 328 .write_buf = ramoops_pstore_write_buf,
9ba80d99
KC
329 .erase = ramoops_pstore_erase,
330 },
331};
332
f4c5d242
AV
333static void ramoops_free_przs(struct ramoops_context *cxt)
334{
335 int i;
336
34f0ec82 337 cxt->max_dump_cnt = 0;
f4c5d242
AV
338 if (!cxt->przs)
339 return;
340
90b58d96 341 for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++)
f4c5d242
AV
342 persistent_ram_free(cxt->przs[i]);
343 kfree(cxt->przs);
344}
345
f568f6ca
GKH
346static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
347 phys_addr_t *paddr, size_t dump_mem_sz)
f4c5d242
AV
348{
349 int err = -ENOMEM;
350 int i;
351
352 if (!cxt->record_size)
353 return 0;
354
c6289378
AH
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
f4c5d242
AV
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");
34f0ec82 368 goto fail_prz;
f4c5d242
AV
369 }
370
371 for (i = 0; i < cxt->max_dump_cnt; i++) {
372 size_t sz = cxt->record_size;
373
c31ad081 374 cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
027bc8b0
TL
375 &cxt->ecc_info,
376 cxt->memtype);
f4c5d242
AV
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;
387fail_prz:
388 ramoops_free_przs(cxt);
389 return err;
390}
391
f568f6ca
GKH
392static 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)
b5d38e9b
AV
395{
396 if (!sz)
397 return 0;
398
c6289378
AH
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);
b5d38e9b 403 return -ENOMEM;
c6289378 404 }
b5d38e9b 405
027bc8b0 406 *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, cxt->memtype);
b5d38e9b
AV
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
f568f6ca 422static int ramoops_probe(struct platform_device *pdev)
56d611a0 423{
896fc1f0 424 struct device *dev = &pdev->dev;
c3b92ce9 425 struct ramoops_platform_data *pdata = pdev->dev.platform_data;
56d611a0 426 struct ramoops_context *cxt = &oops_cxt;
f4c5d242
AV
427 size_t dump_mem_sz;
428 phys_addr_t paddr;
56d611a0
MS
429 int err = -EINVAL;
430
9ba80d99
KC
431 /* Only a single ramoops area allowed at a time, so fail extra
432 * probes.
433 */
cac2eb7b 434 if (cxt->max_dump_cnt)
9ba80d99
KC
435 goto fail_out;
436
a694d1b5
AV
437 if (!pdata->mem_size || (!pdata->record_size && !pdata->console_size &&
438 !pdata->ftrace_size)) {
b5d38e9b 439 pr_err("The memory size and the record/console size must be "
3e5c4fad 440 "non-zero\n");
9ba80d99 441 goto fail_out;
56d611a0
MS
442 }
443
3bd11cf5 444 if (pdata->record_size && !is_power_of_2(pdata->record_size))
b042e474 445 pdata->record_size = rounddown_pow_of_two(pdata->record_size);
3bd11cf5 446 if (pdata->console_size && !is_power_of_2(pdata->console_size))
b042e474 447 pdata->console_size = rounddown_pow_of_two(pdata->console_size);
3bd11cf5 448 if (pdata->ftrace_size && !is_power_of_2(pdata->ftrace_size))
b042e474 449 pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
56d611a0 450
13aefd72
MS
451 cxt->size = pdata->mem_size;
452 cxt->phys_addr = pdata->mem_address;
027bc8b0 453 cxt->memtype = pdata->mem_type;
3e5c4fad 454 cxt->record_size = pdata->record_size;
b5d38e9b 455 cxt->console_size = pdata->console_size;
a694d1b5 456 cxt->ftrace_size = pdata->ftrace_size;
6b4d2a27 457 cxt->dump_oops = pdata->dump_oops;
c31ad081 458 cxt->ecc_info = pdata->ecc_info;
56d611a0 459
f4c5d242 460 paddr = cxt->phys_addr;
896fc1f0 461
a694d1b5 462 dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size;
f4c5d242 463 err = ramoops_init_przs(dev, cxt, &paddr, dump_mem_sz);
b5d38e9b
AV
464 if (err)
465 goto fail_out;
466
cbe7cbf5
AV
467 err = ramoops_init_prz(dev, cxt, &cxt->cprz, &paddr,
468 cxt->console_size, 0);
b5d38e9b
AV
469 if (err)
470 goto fail_init_cprz;
471
cbe7cbf5
AV
472 err = ramoops_init_prz(dev, cxt, &cxt->fprz, &paddr, cxt->ftrace_size,
473 LINUX_VERSION_CODE);
a694d1b5
AV
474 if (err)
475 goto fail_init_fprz;
476
477 if (!cxt->przs && !cxt->cprz && !cxt->fprz) {
0427193b 478 pr_err("memory size too small, minimum is %zu\n",
a694d1b5
AV
479 cxt->console_size + cxt->record_size +
480 cxt->ftrace_size);
47110b88 481 err = -EINVAL;
b5d38e9b 482 goto fail_cnt;
896fc1f0
AV
483 }
484
9ba80d99 485 cxt->pstore.data = cxt;
b5d38e9b 486 /*
a384f641
AV
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).
b5d38e9b 491 */
a384f641
AV
492 if (cxt->console_size)
493 cxt->pstore.bufsize = 1024; /* LOG_LINE_MAX */
494 cxt->pstore.bufsize = max(cxt->record_size, cxt->pstore.bufsize);
9ba80d99
KC
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");
47110b88 499 err = -ENOMEM;
9ba80d99
KC
500 goto fail_clear;
501 }
502
9ba80d99 503 err = pstore_register(&cxt->pstore);
56d611a0 504 if (err) {
9ba80d99 505 pr_err("registering with pstore failed\n");
896fc1f0 506 goto fail_buf;
56d611a0
MS
507 }
508
c755201e
KC
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
c31ad081 518 pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n",
d109a674 519 cxt->size, (unsigned long long)cxt->phys_addr,
c31ad081 520 cxt->ecc_info.ecc_size, cxt->ecc_info.block_size);
9ba80d99 521
56d611a0
MS
522 return 0;
523
9ba80d99
KC
524fail_buf:
525 kfree(cxt->pstore.buf);
526fail_clear:
527 cxt->pstore.bufsize = 0;
b5d38e9b 528fail_cnt:
a694d1b5
AV
529 kfree(cxt->fprz);
530fail_init_fprz:
b5d38e9b
AV
531 kfree(cxt->cprz);
532fail_init_cprz:
f4c5d242 533 ramoops_free_przs(cxt);
9ba80d99 534fail_out:
56d611a0
MS
535 return err;
536}
537
c3b92ce9 538static int __exit ramoops_remove(struct platform_device *pdev)
56d611a0 539{
9ba80d99
KC
540#if 0
541 /* TODO(kees): We cannot unload ramoops since pstore doesn't support
542 * unregistering yet.
543 */
56d611a0
MS
544 struct ramoops_context *cxt = &oops_cxt;
545
56d611a0
MS
546 iounmap(cxt->virt_addr);
547 release_mem_region(cxt->phys_addr, cxt->size);
cac2eb7b 548 cxt->max_dump_cnt = 0;
9ba80d99
KC
549
550 /* TODO(kees): When pstore supports unregistering, call it here. */
551 kfree(cxt->pstore.buf);
552 cxt->pstore.bufsize = 0;
553
c3b92ce9 554 return 0;
9ba80d99
KC
555#endif
556 return -EBUSY;
56d611a0
MS
557}
558
c3b92ce9 559static struct platform_driver ramoops_driver = {
924d3711 560 .probe = ramoops_probe,
c3b92ce9
KP
561 .remove = __exit_p(ramoops_remove),
562 .driver = {
563 .name = "ramoops",
564 .owner = THIS_MODULE,
565 },
566};
567
924d3711 568static void ramoops_register_dummy(void)
c3b92ce9 569{
924d3711
AV
570 if (!mem_size)
571 return;
572
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;
13aefd72
MS
579 }
580
924d3711
AV
581 dummy_data->mem_size = mem_size;
582 dummy_data->mem_address = mem_address;
027bc8b0 583 dummy_data->mem_type = 0;
924d3711
AV
584 dummy_data->record_size = record_size;
585 dummy_data->console_size = ramoops_console_size;
a694d1b5 586 dummy_data->ftrace_size = ramoops_ftrace_size;
924d3711 587 dummy_data->dump_oops = dump_oops;
5ca5d4e6
AV
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 */
c31ad081 592 dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
924d3711
AV
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 }
600}
601
602static int __init ramoops_init(void)
603{
604 ramoops_register_dummy();
605 return platform_driver_register(&ramoops_driver);
c3b92ce9 606}
924d3711 607postcore_initcall(ramoops_init);
c3b92ce9
KP
608
609static void __exit ramoops_exit(void)
610{
611 platform_driver_unregister(&ramoops_driver);
b4a871bc 612 platform_device_unregister(dummy);
13aefd72 613 kfree(dummy_data);
c3b92ce9 614}
56d611a0
MS
615module_exit(ramoops_exit);
616
617MODULE_LICENSE("GPL");
618MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>");
619MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");