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> |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 28 | #include <linux/pstore.h> |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 29 | #include <linux/time.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/ioport.h> |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 33 | #include <linux/slab.h> |
Anton Vorontsov | 1894a25 | 2012-05-16 05:43:08 -0700 | [diff] [blame^] | 34 | #include <linux/pstore_ram.h> |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 35 | |
| 36 | #define RAMOOPS_KERNMSG_HDR "====" |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 37 | #define MIN_MEM_SIZE 4096UL |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 38 | |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 39 | static ulong record_size = MIN_MEM_SIZE; |
| 40 | module_param(record_size, ulong, 0400); |
| 41 | MODULE_PARM_DESC(record_size, |
| 42 | "size of each dump done on oops/panic"); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 43 | |
| 44 | static ulong mem_address; |
| 45 | module_param(mem_address, ulong, 0400); |
| 46 | MODULE_PARM_DESC(mem_address, |
| 47 | "start of reserved RAM used to store oops/panic logs"); |
| 48 | |
| 49 | static ulong mem_size; |
| 50 | module_param(mem_size, ulong, 0400); |
| 51 | MODULE_PARM_DESC(mem_size, |
| 52 | "size of reserved RAM used to store oops/panic logs"); |
| 53 | |
| 54 | static int dump_oops = 1; |
| 55 | module_param(dump_oops, int, 0600); |
| 56 | MODULE_PARM_DESC(dump_oops, |
| 57 | "set to 1 to dump oopses, 0 to only dump panics (default 1)"); |
| 58 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 59 | struct ramoops_context { |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 60 | void *virt_addr; |
| 61 | phys_addr_t phys_addr; |
| 62 | unsigned long size; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 63 | size_t record_size; |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 64 | int dump_oops; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 65 | unsigned int count; |
| 66 | unsigned int max_count; |
| 67 | unsigned int read_count; |
| 68 | struct pstore_info pstore; |
| 69 | }; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 70 | |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 71 | static struct platform_device *dummy; |
| 72 | static struct ramoops_platform_data *dummy_data; |
| 73 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 74 | static int ramoops_pstore_open(struct pstore_info *psi) |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 75 | { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 76 | struct ramoops_context *cxt = psi->data; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 77 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 78 | cxt->read_count = 0; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, |
| 83 | struct timespec *time, |
| 84 | char **buf, |
| 85 | struct pstore_info *psi) |
| 86 | { |
| 87 | ssize_t size; |
| 88 | char *rambuf; |
| 89 | struct ramoops_context *cxt = psi->data; |
| 90 | |
| 91 | if (cxt->read_count >= cxt->max_count) |
| 92 | return -EINVAL; |
| 93 | *id = cxt->read_count++; |
| 94 | /* Only supports dmesg output so far. */ |
| 95 | *type = PSTORE_TYPE_DMESG; |
| 96 | /* TODO(kees): Bogus time for the moment. */ |
| 97 | time->tv_sec = 0; |
| 98 | time->tv_nsec = 0; |
| 99 | |
| 100 | rambuf = cxt->virt_addr + (*id * cxt->record_size); |
| 101 | size = strnlen(rambuf, cxt->record_size); |
| 102 | *buf = kmalloc(size, GFP_KERNEL); |
| 103 | if (*buf == NULL) |
| 104 | return -ENOMEM; |
| 105 | memcpy(*buf, rambuf, size); |
| 106 | |
| 107 | return size; |
| 108 | } |
| 109 | |
| 110 | static int ramoops_pstore_write(enum pstore_type_id type, |
| 111 | enum kmsg_dump_reason reason, |
| 112 | u64 *id, |
| 113 | unsigned int part, |
| 114 | size_t size, struct pstore_info *psi) |
| 115 | { |
| 116 | char *buf; |
| 117 | size_t res; |
| 118 | struct timeval timestamp; |
| 119 | struct ramoops_context *cxt = psi->data; |
| 120 | size_t available = cxt->record_size; |
| 121 | |
| 122 | /* Currently ramoops is designed to only store dmesg dumps. */ |
| 123 | if (type != PSTORE_TYPE_DMESG) |
| 124 | return -EINVAL; |
| 125 | |
| 126 | /* Out of the various dmesg dump types, ramoops is currently designed |
| 127 | * to only store crash logs, rather than storing general kernel logs. |
| 128 | */ |
Seiji Aguchi | fc2d557 | 2011-01-12 16:59:29 -0800 | [diff] [blame] | 129 | if (reason != KMSG_DUMP_OOPS && |
WANG Cong | a3dd332 | 2012-01-12 17:20:11 -0800 | [diff] [blame] | 130 | reason != KMSG_DUMP_PANIC) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 131 | return -EINVAL; |
Seiji Aguchi | fc2d557 | 2011-01-12 16:59:29 -0800 | [diff] [blame] | 132 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 133 | /* Skip Oopes when configured to do so. */ |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 134 | if (reason == KMSG_DUMP_OOPS && !cxt->dump_oops) |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 135 | return -EINVAL; |
| 136 | |
| 137 | /* Explicitly only take the first part of any new crash. |
| 138 | * If our buffer is larger than kmsg_bytes, this can never happen, |
| 139 | * and if our buffer is smaller than kmsg_bytes, we don't want the |
| 140 | * report split across multiple records. |
| 141 | */ |
| 142 | if (part != 1) |
| 143 | return -ENOSPC; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 144 | |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 145 | buf = cxt->virt_addr + (cxt->count * cxt->record_size); |
Ahmed S. Darwish | 1873bb8 | 2010-12-25 11:57:09 +0200 | [diff] [blame] | 146 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 147 | res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR); |
| 148 | buf += res; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 149 | available -= res; |
| 150 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 151 | do_gettimeofday(×tamp); |
| 152 | res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec); |
| 153 | buf += res; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 154 | available -= res; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 155 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 156 | if (size > available) |
| 157 | size = available; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 158 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 159 | memcpy(buf, cxt->pstore.buf, size); |
| 160 | memset(buf + size, '\0', available - size); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 161 | |
| 162 | cxt->count = (cxt->count + 1) % cxt->max_count; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 163 | |
| 164 | return 0; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 167 | static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, |
| 168 | struct pstore_info *psi) |
| 169 | { |
| 170 | char *buf; |
| 171 | struct ramoops_context *cxt = psi->data; |
| 172 | |
| 173 | if (id >= cxt->max_count) |
| 174 | return -EINVAL; |
| 175 | |
| 176 | buf = cxt->virt_addr + (id * cxt->record_size); |
| 177 | memset(buf, '\0', cxt->record_size); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static struct ramoops_context oops_cxt = { |
| 183 | .pstore = { |
| 184 | .owner = THIS_MODULE, |
| 185 | .name = "ramoops", |
| 186 | .open = ramoops_pstore_open, |
| 187 | .read = ramoops_pstore_read, |
| 188 | .write = ramoops_pstore_write, |
| 189 | .erase = ramoops_pstore_erase, |
| 190 | }, |
| 191 | }; |
| 192 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 193 | static int __init ramoops_probe(struct platform_device *pdev) |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 194 | { |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 195 | struct ramoops_platform_data *pdata = pdev->dev.platform_data; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 196 | struct ramoops_context *cxt = &oops_cxt; |
| 197 | int err = -EINVAL; |
| 198 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 199 | /* Only a single ramoops area allowed at a time, so fail extra |
| 200 | * probes. |
| 201 | */ |
| 202 | if (cxt->max_count) |
| 203 | goto fail_out; |
| 204 | |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 205 | if (!pdata->mem_size || !pdata->record_size) { |
| 206 | pr_err("The memory size and the record size must be " |
| 207 | "non-zero\n"); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 208 | goto fail_out; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Marco Stornelli | fdb5950 | 2012-01-12 17:20:58 -0800 | [diff] [blame] | 211 | pdata->mem_size = rounddown_pow_of_two(pdata->mem_size); |
| 212 | pdata->record_size = rounddown_pow_of_two(pdata->record_size); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 213 | |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 214 | /* Check for the minimum memory size */ |
| 215 | if (pdata->mem_size < MIN_MEM_SIZE && |
| 216 | pdata->record_size < MIN_MEM_SIZE) { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 217 | pr_err("memory size too small, minimum is %lu\n", |
| 218 | MIN_MEM_SIZE); |
| 219 | goto fail_out; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 222 | if (pdata->mem_size < pdata->record_size) { |
| 223 | pr_err("The memory size must be larger than the " |
| 224 | "records size\n"); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 225 | goto fail_out; |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | cxt->max_count = pdata->mem_size / pdata->record_size; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 229 | cxt->count = 0; |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 230 | cxt->size = pdata->mem_size; |
| 231 | cxt->phys_addr = pdata->mem_address; |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 232 | cxt->record_size = pdata->record_size; |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 233 | cxt->dump_oops = pdata->dump_oops; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 234 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 235 | cxt->pstore.data = cxt; |
| 236 | cxt->pstore.bufsize = cxt->record_size; |
| 237 | cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL); |
| 238 | spin_lock_init(&cxt->pstore.buf_lock); |
| 239 | if (!cxt->pstore.buf) { |
| 240 | pr_err("cannot allocate pstore buffer\n"); |
| 241 | goto fail_clear; |
| 242 | } |
| 243 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 244 | if (!request_mem_region(cxt->phys_addr, cxt->size, "ramoops")) { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 245 | pr_err("request mem region (0x%lx@0x%llx) failed\n", |
Randy Dunlap | d109a67 | 2012-05-03 15:45:03 +1000 | [diff] [blame] | 246 | cxt->size, (unsigned long long)cxt->phys_addr); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 247 | err = -EINVAL; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 248 | goto fail_buf; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | cxt->virt_addr = ioremap(cxt->phys_addr, cxt->size); |
| 252 | if (!cxt->virt_addr) { |
Marco Stornelli | 0169256 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 253 | pr_err("ioremap failed\n"); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 254 | goto fail_mem_region; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 257 | err = pstore_register(&cxt->pstore); |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 258 | if (err) { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 259 | pr_err("registering with pstore failed\n"); |
| 260 | goto fail_iounmap; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Kees Cook | c755201 | 2012-01-12 17:20:59 -0800 | [diff] [blame] | 263 | /* |
| 264 | * Update the module parameter variables as well so they are visible |
| 265 | * through /sys/module/ramoops/parameters/ |
| 266 | */ |
| 267 | mem_size = pdata->mem_size; |
| 268 | mem_address = pdata->mem_address; |
| 269 | record_size = pdata->record_size; |
| 270 | dump_oops = pdata->dump_oops; |
| 271 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 272 | pr_info("attached 0x%lx@0x%llx (%ux0x%zx)\n", |
Randy Dunlap | d109a67 | 2012-05-03 15:45:03 +1000 | [diff] [blame] | 273 | cxt->size, (unsigned long long)cxt->phys_addr, |
| 274 | cxt->max_count, cxt->record_size); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 275 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 276 | return 0; |
| 277 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 278 | fail_iounmap: |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 279 | iounmap(cxt->virt_addr); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 280 | fail_mem_region: |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 281 | release_mem_region(cxt->phys_addr, cxt->size); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 282 | fail_buf: |
| 283 | kfree(cxt->pstore.buf); |
| 284 | fail_clear: |
| 285 | cxt->pstore.bufsize = 0; |
| 286 | cxt->max_count = 0; |
| 287 | fail_out: |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 288 | return err; |
| 289 | } |
| 290 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 291 | static int __exit ramoops_remove(struct platform_device *pdev) |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 292 | { |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 293 | #if 0 |
| 294 | /* TODO(kees): We cannot unload ramoops since pstore doesn't support |
| 295 | * unregistering yet. |
| 296 | */ |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 297 | struct ramoops_context *cxt = &oops_cxt; |
| 298 | |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 299 | iounmap(cxt->virt_addr); |
| 300 | release_mem_region(cxt->phys_addr, cxt->size); |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 301 | cxt->max_count = 0; |
| 302 | |
| 303 | /* TODO(kees): When pstore supports unregistering, call it here. */ |
| 304 | kfree(cxt->pstore.buf); |
| 305 | cxt->pstore.bufsize = 0; |
| 306 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 307 | return 0; |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 308 | #endif |
| 309 | return -EBUSY; |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 312 | static struct platform_driver ramoops_driver = { |
| 313 | .remove = __exit_p(ramoops_remove), |
| 314 | .driver = { |
| 315 | .name = "ramoops", |
| 316 | .owner = THIS_MODULE, |
| 317 | }, |
| 318 | }; |
| 319 | |
| 320 | static int __init ramoops_init(void) |
| 321 | { |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 322 | int ret; |
| 323 | ret = platform_driver_probe(&ramoops_driver, ramoops_probe); |
| 324 | if (ret == -ENODEV) { |
| 325 | /* |
| 326 | * If we didn't find a platform device, we use module parameters |
| 327 | * building platform data on the fly. |
| 328 | */ |
Marco Stornelli | 0169256 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 329 | pr_info("platform device not found, using module parameters\n"); |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 330 | dummy_data = kzalloc(sizeof(struct ramoops_platform_data), |
| 331 | GFP_KERNEL); |
| 332 | if (!dummy_data) |
| 333 | return -ENOMEM; |
| 334 | dummy_data->mem_size = mem_size; |
| 335 | dummy_data->mem_address = mem_address; |
Sergiu Iordache | 3e5c4fa | 2011-07-26 16:08:59 -0700 | [diff] [blame] | 336 | dummy_data->record_size = record_size; |
Sergiu Iordache | 6b4d2a2 | 2011-07-26 16:08:58 -0700 | [diff] [blame] | 337 | dummy_data->dump_oops = dump_oops; |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 338 | dummy = platform_create_bundle(&ramoops_driver, ramoops_probe, |
| 339 | NULL, 0, dummy_data, |
| 340 | sizeof(struct ramoops_platform_data)); |
| 341 | |
| 342 | if (IS_ERR(dummy)) |
| 343 | ret = PTR_ERR(dummy); |
| 344 | else |
| 345 | ret = 0; |
| 346 | } |
| 347 | |
| 348 | return ret; |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void __exit ramoops_exit(void) |
| 352 | { |
| 353 | platform_driver_unregister(&ramoops_driver); |
Marco Stornelli | 13aefd7 | 2011-07-26 16:08:57 -0700 | [diff] [blame] | 354 | kfree(dummy_data); |
Kyungmin Park | c3b92ce | 2010-10-27 15:34:52 -0700 | [diff] [blame] | 355 | } |
Marco Stornelli | 56d611a | 2010-05-26 14:43:54 -0700 | [diff] [blame] | 356 | |
| 357 | module_init(ramoops_init); |
| 358 | module_exit(ramoops_exit); |
| 359 | |
| 360 | MODULE_LICENSE("GPL"); |
| 361 | MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>"); |
| 362 | MODULE_DESCRIPTION("RAM Oops/Panic logger/driver"); |