diff options
Diffstat (limited to 'drivers/char/ramoops.c')
| -rw-r--r-- | drivers/char/ramoops.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c index 74f00b5ffa36..1a9f5f6d6ac5 100644 --- a/drivers/char/ramoops.c +++ b/drivers/char/ramoops.c | |||
| @@ -25,11 +25,12 @@ | |||
| 25 | #include <linux/time.h> | 25 | #include <linux/time.h> |
| 26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
| 27 | #include <linux/ioport.h> | 27 | #include <linux/ioport.h> |
| 28 | #include <linux/platform_device.h> | ||
| 29 | #include <linux/ramoops.h> | ||
| 28 | 30 | ||
| 29 | #define RAMOOPS_KERNMSG_HDR "====" | 31 | #define RAMOOPS_KERNMSG_HDR "====" |
| 30 | #define RAMOOPS_HEADER_SIZE (5 + sizeof(struct timeval)) | ||
| 31 | 32 | ||
| 32 | #define RECORD_SIZE 4096 | 33 | #define RECORD_SIZE 4096UL |
| 33 | 34 | ||
| 34 | static ulong mem_address; | 35 | static ulong mem_address; |
| 35 | module_param(mem_address, ulong, 0400); | 36 | module_param(mem_address, ulong, 0400); |
| @@ -63,15 +64,22 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, | |||
| 63 | struct ramoops_context, dump); | 64 | struct ramoops_context, dump); |
| 64 | unsigned long s1_start, s2_start; | 65 | unsigned long s1_start, s2_start; |
| 65 | unsigned long l1_cpy, l2_cpy; | 66 | unsigned long l1_cpy, l2_cpy; |
| 66 | int res; | 67 | int res, hdr_size; |
| 67 | char *buf; | 68 | char *buf, *buf_orig; |
| 68 | struct timeval timestamp; | 69 | struct timeval timestamp; |
| 69 | 70 | ||
| 71 | if (reason != KMSG_DUMP_OOPS && | ||
| 72 | reason != KMSG_DUMP_PANIC && | ||
| 73 | reason != KMSG_DUMP_KEXEC) | ||
| 74 | return; | ||
| 75 | |||
| 70 | /* Only dump oopses if dump_oops is set */ | 76 | /* Only dump oopses if dump_oops is set */ |
| 71 | if (reason == KMSG_DUMP_OOPS && !dump_oops) | 77 | if (reason == KMSG_DUMP_OOPS && !dump_oops) |
| 72 | return; | 78 | return; |
| 73 | 79 | ||
| 74 | buf = (char *)(cxt->virt_addr + (cxt->count * RECORD_SIZE)); | 80 | buf = cxt->virt_addr + (cxt->count * RECORD_SIZE); |
| 81 | buf_orig = buf; | ||
| 82 | |||
| 75 | memset(buf, '\0', RECORD_SIZE); | 83 | memset(buf, '\0', RECORD_SIZE); |
| 76 | res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR); | 84 | res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR); |
| 77 | buf += res; | 85 | buf += res; |
| @@ -79,8 +87,9 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, | |||
| 79 | res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec); | 87 | res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec); |
| 80 | buf += res; | 88 | buf += res; |
| 81 | 89 | ||
| 82 | l2_cpy = min(l2, (unsigned long)(RECORD_SIZE - RAMOOPS_HEADER_SIZE)); | 90 | hdr_size = buf - buf_orig; |
| 83 | l1_cpy = min(l1, (unsigned long)(RECORD_SIZE - RAMOOPS_HEADER_SIZE) - l2_cpy); | 91 | l2_cpy = min(l2, RECORD_SIZE - hdr_size); |
| 92 | l1_cpy = min(l1, RECORD_SIZE - hdr_size - l2_cpy); | ||
| 84 | 93 | ||
| 85 | s2_start = l2 - l2_cpy; | 94 | s2_start = l2 - l2_cpy; |
| 86 | s1_start = l1 - l1_cpy; | 95 | s1_start = l1 - l1_cpy; |
| @@ -91,11 +100,17 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, | |||
| 91 | cxt->count = (cxt->count + 1) % cxt->max_count; | 100 | cxt->count = (cxt->count + 1) % cxt->max_count; |
| 92 | } | 101 | } |
| 93 | 102 | ||
| 94 | static int __init ramoops_init(void) | 103 | static int __init ramoops_probe(struct platform_device *pdev) |
| 95 | { | 104 | { |
| 105 | struct ramoops_platform_data *pdata = pdev->dev.platform_data; | ||
| 96 | struct ramoops_context *cxt = &oops_cxt; | 106 | struct ramoops_context *cxt = &oops_cxt; |
| 97 | int err = -EINVAL; | 107 | int err = -EINVAL; |
| 98 | 108 | ||
| 109 | if (pdata) { | ||
| 110 | mem_size = pdata->mem_size; | ||
| 111 | mem_address = pdata->mem_address; | ||
| 112 | } | ||
| 113 | |||
| 99 | if (!mem_size) { | 114 | if (!mem_size) { |
| 100 | printk(KERN_ERR "ramoops: invalid size specification"); | 115 | printk(KERN_ERR "ramoops: invalid size specification"); |
| 101 | goto fail3; | 116 | goto fail3; |
| @@ -142,7 +157,7 @@ fail3: | |||
| 142 | return err; | 157 | return err; |
| 143 | } | 158 | } |
| 144 | 159 | ||
| 145 | static void __exit ramoops_exit(void) | 160 | static int __exit ramoops_remove(struct platform_device *pdev) |
| 146 | { | 161 | { |
| 147 | struct ramoops_context *cxt = &oops_cxt; | 162 | struct ramoops_context *cxt = &oops_cxt; |
| 148 | 163 | ||
| @@ -151,8 +166,26 @@ static void __exit ramoops_exit(void) | |||
| 151 | 166 | ||
| 152 | iounmap(cxt->virt_addr); | 167 | iounmap(cxt->virt_addr); |
| 153 | release_mem_region(cxt->phys_addr, cxt->size); | 168 | release_mem_region(cxt->phys_addr, cxt->size); |
| 169 | return 0; | ||
| 154 | } | 170 | } |
| 155 | 171 | ||
| 172 | static struct platform_driver ramoops_driver = { | ||
| 173 | .remove = __exit_p(ramoops_remove), | ||
| 174 | .driver = { | ||
| 175 | .name = "ramoops", | ||
| 176 | .owner = THIS_MODULE, | ||
| 177 | }, | ||
| 178 | }; | ||
| 179 | |||
| 180 | static int __init ramoops_init(void) | ||
| 181 | { | ||
| 182 | return platform_driver_probe(&ramoops_driver, ramoops_probe); | ||
| 183 | } | ||
| 184 | |||
| 185 | static void __exit ramoops_exit(void) | ||
| 186 | { | ||
| 187 | platform_driver_unregister(&ramoops_driver); | ||
| 188 | } | ||
| 156 | 189 | ||
| 157 | module_init(ramoops_init); | 190 | module_init(ramoops_init); |
| 158 | module_exit(ramoops_exit); | 191 | module_exit(ramoops_exit); |
