Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * MTD Oops/Panic logger |
| 3 | * |
| 4 | * Copyright (C) 2007 Nokia Corporation. All rights reserved. |
| 5 | * |
| 6 | * Author: Richard Purdie <rpurdie@openedhand.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/console.h> |
| 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/workqueue.h> |
| 29 | #include <linux/sched.h> |
| 30 | #include <linux/wait.h> |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 31 | #include <linux/spinlock.h> |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 32 | #include <linux/mtd/mtd.h> |
| 33 | |
| 34 | #define OOPS_PAGE_SIZE 4096 |
| 35 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 36 | struct mtdoops_context { |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 37 | int mtd_index; |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 38 | struct work_struct work_erase; |
| 39 | struct work_struct work_write; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 40 | struct mtd_info *mtd; |
| 41 | int oops_pages; |
| 42 | int nextpage; |
| 43 | int nextcount; |
| 44 | |
| 45 | void *oops_buf; |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 46 | |
| 47 | /* writecount and disabling ready are spin lock protected */ |
| 48 | spinlock_t writecount_lock; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 49 | int ready; |
| 50 | int writecount; |
| 51 | } oops_cxt; |
| 52 | |
| 53 | static void mtdoops_erase_callback(struct erase_info *done) |
| 54 | { |
| 55 | wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv; |
| 56 | wake_up(wait_q); |
| 57 | } |
| 58 | |
| 59 | static int mtdoops_erase_block(struct mtd_info *mtd, int offset) |
| 60 | { |
| 61 | struct erase_info erase; |
| 62 | DECLARE_WAITQUEUE(wait, current); |
| 63 | wait_queue_head_t wait_q; |
| 64 | int ret; |
| 65 | |
| 66 | init_waitqueue_head(&wait_q); |
| 67 | erase.mtd = mtd; |
| 68 | erase.callback = mtdoops_erase_callback; |
| 69 | erase.addr = offset; |
| 70 | if (mtd->erasesize < OOPS_PAGE_SIZE) |
| 71 | erase.len = OOPS_PAGE_SIZE; |
| 72 | else |
| 73 | erase.len = mtd->erasesize; |
| 74 | erase.priv = (u_long)&wait_q; |
| 75 | |
| 76 | set_current_state(TASK_INTERRUPTIBLE); |
| 77 | add_wait_queue(&wait_q, &wait); |
| 78 | |
| 79 | ret = mtd->erase(mtd, &erase); |
| 80 | if (ret) { |
| 81 | set_current_state(TASK_RUNNING); |
| 82 | remove_wait_queue(&wait_q, &wait); |
| 83 | printk (KERN_WARNING "mtdoops: erase of region [0x%x, 0x%x] " |
| 84 | "on \"%s\" failed\n", |
| 85 | erase.addr, erase.len, mtd->name); |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | schedule(); /* Wait for erase to finish. */ |
| 90 | remove_wait_queue(&wait_q, &wait); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 95 | static void mtdoops_inc_counter(struct mtdoops_context *cxt) |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 96 | { |
| 97 | struct mtd_info *mtd = cxt->mtd; |
| 98 | size_t retlen; |
| 99 | u32 count; |
| 100 | int ret; |
| 101 | |
| 102 | cxt->nextpage++; |
| 103 | if (cxt->nextpage > cxt->oops_pages) |
| 104 | cxt->nextpage = 0; |
| 105 | cxt->nextcount++; |
| 106 | if (cxt->nextcount == 0xffffffff) |
| 107 | cxt->nextcount = 0; |
| 108 | |
| 109 | ret = mtd->read(mtd, cxt->nextpage * OOPS_PAGE_SIZE, 4, |
| 110 | &retlen, (u_char *) &count); |
Richard Purdie | 2986bd2 | 2008-01-29 11:27:09 +0000 | [diff] [blame] | 111 | if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) { |
Andrew Morton | 68d09b1 | 2007-08-10 14:01:31 -0700 | [diff] [blame] | 112 | printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)" |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 113 | ", err %d.\n", cxt->nextpage * OOPS_PAGE_SIZE, |
| 114 | retlen, ret); |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 115 | schedule_work(&cxt->work_erase); |
| 116 | return; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* See if we need to erase the next block */ |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 120 | if (count != 0xffffffff) { |
| 121 | schedule_work(&cxt->work_erase); |
| 122 | return; |
| 123 | } |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 124 | |
| 125 | printk(KERN_DEBUG "mtdoops: Ready %d, %d (no erase)\n", |
| 126 | cxt->nextpage, cxt->nextcount); |
| 127 | cxt->ready = 1; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 130 | /* Scheduled work - when we can't proceed without erasing a block */ |
| 131 | static void mtdoops_workfunc_erase(struct work_struct *work) |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 132 | { |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 133 | struct mtdoops_context *cxt = |
| 134 | container_of(work, struct mtdoops_context, work_erase); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 135 | struct mtd_info *mtd = cxt->mtd; |
| 136 | int i = 0, j, ret, mod; |
| 137 | |
| 138 | /* We were unregistered */ |
| 139 | if (!mtd) |
| 140 | return; |
| 141 | |
| 142 | mod = (cxt->nextpage * OOPS_PAGE_SIZE) % mtd->erasesize; |
| 143 | if (mod != 0) { |
| 144 | cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / OOPS_PAGE_SIZE); |
| 145 | if (cxt->nextpage > cxt->oops_pages) |
| 146 | cxt->nextpage = 0; |
| 147 | } |
| 148 | |
Richard Purdie | 2986bd2 | 2008-01-29 11:27:09 +0000 | [diff] [blame] | 149 | while (mtd->block_isbad) { |
| 150 | ret = mtd->block_isbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE); |
| 151 | if (!ret) |
| 152 | break; |
| 153 | if (ret < 0) { |
| 154 | printk(KERN_ERR "mtdoops: block_isbad failed, aborting.\n"); |
| 155 | return; |
| 156 | } |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 157 | badblock: |
| 158 | printk(KERN_WARNING "mtdoops: Bad block at %08x\n", |
| 159 | cxt->nextpage * OOPS_PAGE_SIZE); |
| 160 | i++; |
| 161 | cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE); |
| 162 | if (cxt->nextpage > cxt->oops_pages) |
| 163 | cxt->nextpage = 0; |
| 164 | if (i == (cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE))) { |
| 165 | printk(KERN_ERR "mtdoops: All blocks bad!\n"); |
| 166 | return; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | for (j = 0, ret = -1; (j < 3) && (ret < 0); j++) |
| 171 | ret = mtdoops_erase_block(mtd, cxt->nextpage * OOPS_PAGE_SIZE); |
| 172 | |
Richard Purdie | 2986bd2 | 2008-01-29 11:27:09 +0000 | [diff] [blame] | 173 | if (ret >= 0) { |
| 174 | printk(KERN_DEBUG "mtdoops: Ready %d, %d \n", cxt->nextpage, cxt->nextcount); |
| 175 | cxt->ready = 1; |
| 176 | return; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Richard Purdie | 2986bd2 | 2008-01-29 11:27:09 +0000 | [diff] [blame] | 179 | if (mtd->block_markbad && (ret == -EIO)) { |
| 180 | ret = mtd->block_markbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE); |
| 181 | if (ret < 0) { |
| 182 | printk(KERN_ERR "mtdoops: block_markbad failed, aborting.\n"); |
| 183 | return; |
| 184 | } |
| 185 | } |
| 186 | goto badblock; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 189 | static void mtdoops_workfunc_write(struct work_struct *work) |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 190 | { |
| 191 | struct mtdoops_context *cxt = |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 192 | container_of(work, struct mtdoops_context, work_write); |
| 193 | struct mtd_info *mtd = cxt->mtd; |
| 194 | size_t retlen; |
| 195 | int ret; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 196 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 197 | if (cxt->writecount < OOPS_PAGE_SIZE) |
| 198 | memset(cxt->oops_buf + cxt->writecount, 0xff, |
| 199 | OOPS_PAGE_SIZE - cxt->writecount); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 200 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 201 | ret = mtd->write(mtd, cxt->nextpage * OOPS_PAGE_SIZE, |
| 202 | OOPS_PAGE_SIZE, &retlen, cxt->oops_buf); |
| 203 | |
| 204 | cxt->writecount = 0; |
| 205 | |
| 206 | if ((retlen != OOPS_PAGE_SIZE) || (ret < 0)) |
| 207 | printk(KERN_ERR "mtdoops: Write failure at %d (%td of %d written), err %d.\n", |
| 208 | cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret); |
| 209 | |
| 210 | mtdoops_inc_counter(cxt); |
| 211 | } |
| 212 | |
| 213 | static void find_next_position(struct mtdoops_context *cxt) |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 214 | { |
| 215 | struct mtd_info *mtd = cxt->mtd; |
Richard Purdie | 2986bd2 | 2008-01-29 11:27:09 +0000 | [diff] [blame] | 216 | int ret, page, maxpos = 0; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 217 | u32 count, maxcount = 0xffffffff; |
| 218 | size_t retlen; |
| 219 | |
| 220 | for (page = 0; page < cxt->oops_pages; page++) { |
Richard Purdie | 2986bd2 | 2008-01-29 11:27:09 +0000 | [diff] [blame] | 221 | ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 4, &retlen, (u_char *) &count); |
| 222 | if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) { |
| 223 | printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)" |
| 224 | ", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret); |
| 225 | continue; |
| 226 | } |
| 227 | |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 228 | if (count == 0xffffffff) |
| 229 | continue; |
| 230 | if (maxcount == 0xffffffff) { |
| 231 | maxcount = count; |
| 232 | maxpos = page; |
| 233 | } else if ((count < 0x40000000) && (maxcount > 0xc0000000)) { |
| 234 | maxcount = count; |
| 235 | maxpos = page; |
| 236 | } else if ((count > maxcount) && (count < 0xc0000000)) { |
| 237 | maxcount = count; |
| 238 | maxpos = page; |
| 239 | } else if ((count > maxcount) && (count > 0xc0000000) |
| 240 | && (maxcount > 0x80000000)) { |
| 241 | maxcount = count; |
| 242 | maxpos = page; |
| 243 | } |
| 244 | } |
| 245 | if (maxcount == 0xffffffff) { |
| 246 | cxt->nextpage = 0; |
| 247 | cxt->nextcount = 1; |
| 248 | cxt->ready = 1; |
| 249 | printk(KERN_DEBUG "mtdoops: Ready %d, %d (first init)\n", |
| 250 | cxt->nextpage, cxt->nextcount); |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 251 | return; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | cxt->nextpage = maxpos; |
| 255 | cxt->nextcount = maxcount; |
| 256 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 257 | mtdoops_inc_counter(cxt); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
| 261 | static void mtdoops_notify_add(struct mtd_info *mtd) |
| 262 | { |
| 263 | struct mtdoops_context *cxt = &oops_cxt; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 264 | |
| 265 | if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0) |
| 266 | return; |
| 267 | |
| 268 | if (mtd->size < (mtd->erasesize * 2)) { |
| 269 | printk(KERN_ERR "MTD partition %d not big enough for mtdoops\n", |
| 270 | mtd->index); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | cxt->mtd = mtd; |
| 275 | cxt->oops_pages = mtd->size / OOPS_PAGE_SIZE; |
| 276 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 277 | find_next_position(cxt); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 278 | |
| 279 | printk(KERN_DEBUG "mtdoops: Attached to MTD device %d\n", mtd->index); |
| 280 | } |
| 281 | |
| 282 | static void mtdoops_notify_remove(struct mtd_info *mtd) |
| 283 | { |
| 284 | struct mtdoops_context *cxt = &oops_cxt; |
| 285 | |
| 286 | if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0) |
| 287 | return; |
| 288 | |
| 289 | cxt->mtd = NULL; |
| 290 | flush_scheduled_work(); |
| 291 | } |
| 292 | |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 293 | static void mtdoops_console_sync(void) |
| 294 | { |
| 295 | struct mtdoops_context *cxt = &oops_cxt; |
| 296 | struct mtd_info *mtd = cxt->mtd; |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 297 | unsigned long flags; |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 298 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 299 | if (!cxt->ready || !mtd || cxt->writecount == 0) |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 300 | return; |
| 301 | |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 302 | /* |
| 303 | * Once ready is 0 and we've held the lock no further writes to the |
| 304 | * buffer will happen |
| 305 | */ |
| 306 | spin_lock_irqsave(&cxt->writecount_lock, flags); |
| 307 | if (!cxt->ready) { |
| 308 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); |
| 309 | return; |
| 310 | } |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 311 | cxt->ready = 0; |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 312 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 313 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 314 | schedule_work(&cxt->work_write); |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 315 | } |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 316 | |
| 317 | static void |
| 318 | mtdoops_console_write(struct console *co, const char *s, unsigned int count) |
| 319 | { |
| 320 | struct mtdoops_context *cxt = co->data; |
| 321 | struct mtd_info *mtd = cxt->mtd; |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 322 | unsigned long flags; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 323 | |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 324 | if (!oops_in_progress) { |
| 325 | mtdoops_console_sync(); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 326 | return; |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 329 | if (!cxt->ready || !mtd) |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 330 | return; |
| 331 | |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 332 | /* Locking on writecount ensures sequential writes to the buffer */ |
| 333 | spin_lock_irqsave(&cxt->writecount_lock, flags); |
| 334 | |
| 335 | /* Check ready status didn't change whilst waiting for the lock */ |
| 336 | if (!cxt->ready) |
| 337 | return; |
| 338 | |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 339 | if (cxt->writecount == 0) { |
| 340 | u32 *stamp = cxt->oops_buf; |
| 341 | *stamp = cxt->nextcount; |
| 342 | cxt->writecount = 4; |
| 343 | } |
| 344 | |
| 345 | if ((count + cxt->writecount) > OOPS_PAGE_SIZE) |
| 346 | count = OOPS_PAGE_SIZE - cxt->writecount; |
| 347 | |
Peter Korsgaard | 235d620 | 2007-11-06 11:56:02 +0100 | [diff] [blame] | 348 | memcpy(cxt->oops_buf + cxt->writecount, s, count); |
| 349 | cxt->writecount += count; |
Richard Purdie | 47c152b | 2008-01-29 10:21:56 +0000 | [diff] [blame^] | 350 | |
| 351 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); |
| 352 | |
| 353 | if (cxt->writecount == OOPS_PAGE_SIZE) |
| 354 | mtdoops_console_sync(); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static int __init mtdoops_console_setup(struct console *co, char *options) |
| 358 | { |
| 359 | struct mtdoops_context *cxt = co->data; |
| 360 | |
| 361 | if (cxt->mtd_index != -1) |
| 362 | return -EBUSY; |
| 363 | if (co->index == -1) |
| 364 | return -EINVAL; |
| 365 | |
| 366 | cxt->mtd_index = co->index; |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static struct mtd_notifier mtdoops_notifier = { |
| 371 | .add = mtdoops_notify_add, |
| 372 | .remove = mtdoops_notify_remove, |
| 373 | }; |
| 374 | |
| 375 | static struct console mtdoops_console = { |
| 376 | .name = "ttyMTD", |
| 377 | .write = mtdoops_console_write, |
| 378 | .setup = mtdoops_console_setup, |
Richard Purdie | 8691a72 | 2007-07-10 20:33:54 +0100 | [diff] [blame] | 379 | .unblank = mtdoops_console_sync, |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 380 | .flags = CON_PRINTBUFFER, |
| 381 | .index = -1, |
| 382 | .data = &oops_cxt, |
| 383 | }; |
| 384 | |
| 385 | static int __init mtdoops_console_init(void) |
| 386 | { |
| 387 | struct mtdoops_context *cxt = &oops_cxt; |
| 388 | |
| 389 | cxt->mtd_index = -1; |
| 390 | cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE); |
| 391 | |
| 392 | if (!cxt->oops_buf) { |
| 393 | printk(KERN_ERR "Failed to allocate oops buffer workspace\n"); |
| 394 | return -ENOMEM; |
| 395 | } |
| 396 | |
Richard Purdie | 6ce0a856 | 2008-01-29 11:27:11 +0000 | [diff] [blame] | 397 | INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); |
| 398 | INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); |
Richard Purdie | 4b23aff | 2007-05-29 13:31:42 +0100 | [diff] [blame] | 399 | |
| 400 | register_console(&mtdoops_console); |
| 401 | register_mtd_user(&mtdoops_notifier); |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static void __exit mtdoops_console_exit(void) |
| 406 | { |
| 407 | struct mtdoops_context *cxt = &oops_cxt; |
| 408 | |
| 409 | unregister_mtd_user(&mtdoops_notifier); |
| 410 | unregister_console(&mtdoops_console); |
| 411 | vfree(cxt->oops_buf); |
| 412 | } |
| 413 | |
| 414 | |
| 415 | subsys_initcall(mtdoops_console_init); |
| 416 | module_exit(mtdoops_console_exit); |
| 417 | |
| 418 | MODULE_LICENSE("GPL"); |
| 419 | MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); |
| 420 | MODULE_DESCRIPTION("MTD Oops/Panic console logger/driver"); |