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