aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorArve Hjønnevåg <arve@android.com>2008-12-19 21:12:11 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-01-06 16:52:42 -0500
commitadc567e8a9c25f08e91eb18b83bdaa5ff9705919 (patch)
treedb9a88803e67755b404f617da7a01d6d8b2f37ff /drivers
parent875f194c48ddae3797f8d61e98aacd8a8ecef927 (diff)
Staging: android: add ram_console driver
Doesn't quite link properly under all configurations, and it has way too many different build options, but it's a start. Signed-off-by: Arve Hjønnevåg <arve@android.com> Signed-off-by: Brian Swetland <swetland@google.com> Cc: Robert Love <rlove@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/android/Kconfig58
-rw-r--r--drivers/staging/android/Makefile1
-rw-r--r--drivers/staging/android/ram_console.c395
3 files changed, 454 insertions, 0 deletions
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index c8899581545e..7728b84bf07c 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -14,4 +14,62 @@ config ANDROID_LOGGER
14 tristate "Android log driver" 14 tristate "Android log driver"
15 default n 15 default n
16 16
17config ANDROID_RAM_CONSOLE
18 bool "Android RAM buffer console"
19 default n
20
21config ANDROID_RAM_CONSOLE_ENABLE_VERBOSE
22 bool "Enable verbose console messages on Android RAM console"
23 default y
24 depends on ANDROID_RAM_CONSOLE
25
26menuconfig ANDROID_RAM_CONSOLE_ERROR_CORRECTION
27 bool "Android RAM Console Enable error correction"
28 default n
29 depends on ANDROID_RAM_CONSOLE
30 select REED_SOLOMON
31 select REED_SOLOMON_ENC8
32 select REED_SOLOMON_DEC8
33
34if ANDROID_RAM_CONSOLE_ERROR_CORRECTION
35
36config ANDROID_RAM_CONSOLE_ERROR_CORRECTION_DATA_SIZE
37 int "Android RAM Console Data data size"
38 default 128
39 help
40 Must be a power of 2.
41
42config ANDROID_RAM_CONSOLE_ERROR_CORRECTION_ECC_SIZE
43 int "Android RAM Console ECC size"
44 default 16
45
46config ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE
47 int "Android RAM Console Symbol size"
48 default 8
49
50config ANDROID_RAM_CONSOLE_ERROR_CORRECTION_POLYNOMIAL
51 hex "Android RAM Console Polynomial"
52 default 0x19 if (ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE = 4)
53 default 0x29 if (ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE = 5)
54 default 0x61 if (ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE = 6)
55 default 0x89 if (ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE = 7)
56 default 0x11d if (ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE = 8)
57
58endif # ANDROID_RAM_CONSOLE_ERROR_CORRECTION
59
60config ANDROID_RAM_CONSOLE_EARLY_INIT
61 bool "Start Android RAM console early"
62 default n
63 depends on ANDROID_RAM_CONSOLE
64
65config ANDROID_RAM_CONSOLE_EARLY_ADDR
66 hex "Android RAM console virtual address"
67 default 0
68 depends on ANDROID_RAM_CONSOLE_EARLY_INIT
69
70config ANDROID_RAM_CONSOLE_EARLY_SIZE
71 hex "Android RAM console buffer size"
72 default 0
73 depends on ANDROID_RAM_CONSOLE_EARLY_INIT
74
17endmenu 75endmenu
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index b354b5d90143..357abd73142a 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_ANDROID) += android.o 1obj-$(CONFIG_ANDROID) += android.o
2obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o 2obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o
3obj-$(CONFIG_ANDROID_LOGGER) += logger.o 3obj-$(CONFIG_ANDROID_LOGGER) += logger.o
4obj-$(CONFIG_ANDROID_RAM_CONSOLE) += ram_console.o
diff --git a/drivers/staging/android/ram_console.c b/drivers/staging/android/ram_console.c
new file mode 100644
index 000000000000..bf006857a87a
--- /dev/null
+++ b/drivers/staging/android/ram_console.c
@@ -0,0 +1,395 @@
1/* drivers/android/ram_console.c
2 *
3 * Copyright (C) 2007-2008 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <linux/console.h>
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/proc_fs.h>
21#include <linux/string.h>
22#include <linux/uaccess.h>
23#include <asm/io.h>
24
25#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
26#include <linux/rslib.h>
27#endif
28
29struct ram_console_buffer {
30 uint32_t sig;
31 uint32_t start;
32 uint32_t size;
33 uint8_t data[0];
34};
35
36#define RAM_CONSOLE_SIG (0x43474244) /* DBGC */
37
38#ifdef CONFIG_ANDROID_RAM_CONSOLE_EARLY_INIT
39static char __initdata
40 ram_console_old_log_init_buffer[CONFIG_ANDROID_RAM_CONSOLE_EARLY_SIZE];
41#endif
42static char *ram_console_old_log;
43static size_t ram_console_old_log_size;
44
45static struct ram_console_buffer *ram_console_buffer;
46static size_t ram_console_buffer_size;
47#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
48static char *ram_console_par_buffer;
49static struct rs_control *ram_console_rs_decoder;
50static int ram_console_corrected_bytes;
51static int ram_console_bad_blocks;
52#define ECC_BLOCK_SIZE CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION_DATA_SIZE
53#define ECC_SIZE CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION_ECC_SIZE
54#define ECC_SYMSIZE CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION_SYMBOL_SIZE
55#define ECC_POLY CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION_POLYNOMIAL
56#endif
57
58#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
59static void ram_console_encode_rs8(uint8_t *data, size_t len, uint8_t *ecc)
60{
61 int i;
62 uint16_t par[ECC_SIZE];
63 /* Initialize the parity buffer */
64 memset(par, 0, sizeof(par));
65 encode_rs8(ram_console_rs_decoder, data, len, par, 0);
66 for (i = 0; i < ECC_SIZE; i++)
67 ecc[i] = par[i];
68}
69
70static int ram_console_decode_rs8(void *data, size_t len, uint8_t *ecc)
71{
72 int i;
73 uint16_t par[ECC_SIZE];
74 for (i = 0; i < ECC_SIZE; i++)
75 par[i] = ecc[i];
76 return decode_rs8(ram_console_rs_decoder, data, par, len,
77 NULL, 0, NULL, 0, NULL);
78}
79#endif
80
81static void ram_console_update(const char *s, unsigned int count)
82{
83 struct ram_console_buffer *buffer = ram_console_buffer;
84#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
85 uint8_t *buffer_end = buffer->data + ram_console_buffer_size;
86 uint8_t *block;
87 uint8_t *par;
88 int size = ECC_BLOCK_SIZE;
89#endif
90 memcpy(buffer->data + buffer->start, s, count);
91#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
92 block = buffer->data + (buffer->start & ~(ECC_BLOCK_SIZE - 1));
93 par = ram_console_par_buffer +
94 (buffer->start / ECC_BLOCK_SIZE) * ECC_SIZE;
95 do {
96 if (block + ECC_BLOCK_SIZE > buffer_end)
97 size = buffer_end - block;
98 ram_console_encode_rs8(block, size, par);
99 block += ECC_BLOCK_SIZE;
100 par += ECC_SIZE;
101 } while (block < buffer->data + buffer->start + count);
102#endif
103}
104
105static void ram_console_update_header(void)
106{
107#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
108 struct ram_console_buffer *buffer = ram_console_buffer;
109 uint8_t *par;
110 par = ram_console_par_buffer +
111 DIV_ROUND_UP(ram_console_buffer_size, ECC_BLOCK_SIZE) * ECC_SIZE;
112 ram_console_encode_rs8((uint8_t *)buffer, sizeof(*buffer), par);
113#endif
114}
115
116static void
117ram_console_write(struct console *console, const char *s, unsigned int count)
118{
119 int rem;
120 struct ram_console_buffer *buffer = ram_console_buffer;
121
122 if (count > ram_console_buffer_size) {
123 s += count - ram_console_buffer_size;
124 count = ram_console_buffer_size;
125 }
126 rem = ram_console_buffer_size - buffer->start;
127 if (rem < count) {
128 ram_console_update(s, rem);
129 s += rem;
130 count -= rem;
131 buffer->start = 0;
132 buffer->size = ram_console_buffer_size;
133 }
134 ram_console_update(s, count);
135
136 buffer->start += count;
137 if (buffer->size < ram_console_buffer_size)
138 buffer->size += count;
139 ram_console_update_header();
140}
141
142static struct console ram_console = {
143 .name = "ram",
144 .write = ram_console_write,
145 .flags = CON_PRINTBUFFER | CON_ENABLED,
146 .index = -1,
147};
148
149static void __init
150ram_console_save_old(struct ram_console_buffer *buffer, char *dest)
151{
152 size_t old_log_size = buffer->size;
153#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
154 uint8_t *block;
155 uint8_t *par;
156 char strbuf[80];
157 int strbuf_len;
158
159 block = buffer->data;
160 par = ram_console_par_buffer;
161 while (block < buffer->data + buffer->size) {
162 int numerr;
163 int size = ECC_BLOCK_SIZE;
164 if (block + size > buffer->data + ram_console_buffer_size)
165 size = buffer->data + ram_console_buffer_size - block;
166 numerr = ram_console_decode_rs8(block, size, par);
167 if (numerr > 0) {
168#if 0
169 printk(KERN_INFO "ram_console: error in block %p, %d\n",
170 block, numerr);
171#endif
172 ram_console_corrected_bytes += numerr;
173 } else if (numerr < 0) {
174#if 0
175 printk(KERN_INFO "ram_console: uncorrectable error in "
176 "block %p\n", block);
177#endif
178 ram_console_bad_blocks++;
179 }
180 block += ECC_BLOCK_SIZE;
181 par += ECC_SIZE;
182 }
183 if (ram_console_corrected_bytes || ram_console_bad_blocks)
184 strbuf_len = snprintf(strbuf, sizeof(strbuf),
185 "\n%d Corrected bytes, %d unrecoverable blocks\n",
186 ram_console_corrected_bytes, ram_console_bad_blocks);
187 else
188 strbuf_len = snprintf(strbuf, sizeof(strbuf),
189 "\nNo errors detected\n");
190 if (strbuf_len >= sizeof(strbuf))
191 strbuf_len = sizeof(strbuf) - 1;
192 old_log_size += strbuf_len;
193#endif
194
195 if (dest == NULL) {
196 dest = kmalloc(old_log_size, GFP_KERNEL);
197 if (dest == NULL) {
198 printk(KERN_ERR
199 "ram_console: failed to allocate buffer\n");
200 return;
201 }
202 }
203
204 ram_console_old_log = dest;
205 ram_console_old_log_size = old_log_size;
206 memcpy(ram_console_old_log,
207 &buffer->data[buffer->start], buffer->size - buffer->start);
208 memcpy(ram_console_old_log + buffer->size - buffer->start,
209 &buffer->data[0], buffer->start);
210#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
211 memcpy(ram_console_old_log + old_log_size - strbuf_len,
212 strbuf, strbuf_len);
213#endif
214}
215
216static int __init ram_console_init(struct ram_console_buffer *buffer,
217 size_t buffer_size, char *old_buf)
218{
219#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
220 int numerr;
221 uint8_t *par;
222#endif
223 ram_console_buffer = buffer;
224 ram_console_buffer_size =
225 buffer_size - sizeof(struct ram_console_buffer);
226
227#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
228 ram_console_buffer_size -= (DIV_ROUND_UP(ram_console_buffer_size,
229 ECC_BLOCK_SIZE) + 1) * ECC_SIZE;
230 ram_console_par_buffer = buffer->data + ram_console_buffer_size;
231
232
233 /* first consecutive root is 0
234 * primitive element to generate roots = 1
235 */
236 ram_console_rs_decoder = init_rs(ECC_SYMSIZE, ECC_POLY, 0, 1, ECC_SIZE);
237 if (ram_console_rs_decoder == NULL) {
238 printk(KERN_INFO "ram_console: init_rs failed\n");
239 return 0;
240 }
241
242 ram_console_corrected_bytes = 0;
243 ram_console_bad_blocks = 0;
244
245 par = ram_console_par_buffer +
246 DIV_ROUND_UP(ram_console_buffer_size, ECC_BLOCK_SIZE) * ECC_SIZE;
247
248 numerr = ram_console_decode_rs8(buffer, sizeof(*buffer), par);
249 if (numerr > 0) {
250 printk(KERN_INFO "ram_console: error in header, %d\n", numerr);
251 ram_console_corrected_bytes += numerr;
252 } else if (numerr < 0) {
253 printk(KERN_INFO
254 "ram_console: uncorrectable error in header\n");
255 ram_console_bad_blocks++;
256 }
257#endif
258
259 if (buffer->sig == RAM_CONSOLE_SIG) {
260 if (buffer->size > ram_console_buffer_size
261 || buffer->start > buffer->size)
262 printk(KERN_INFO "ram_console: found existing invalid "
263 "buffer, size %d, start %d\n",
264 buffer->size, buffer->start);
265 else {
266 printk(KERN_INFO "ram_console: found existing buffer, "
267 "size %d, start %d\n",
268 buffer->size, buffer->start);
269 ram_console_save_old(buffer, old_buf);
270 }
271 } else {
272 printk(KERN_INFO "ram_console: no valid data in buffer "
273 "(sig = 0x%08x)\n", buffer->sig);
274 }
275
276 buffer->sig = RAM_CONSOLE_SIG;
277 buffer->start = 0;
278 buffer->size = 0;
279
280 register_console(&ram_console);
281#ifdef CONFIG_ANDROID_RAM_CONSOLE_ENABLE_VERBOSE
282 console_verbose();
283#endif
284 return 0;
285}
286
287#ifdef CONFIG_ANDROID_RAM_CONSOLE_EARLY_INIT
288static int __init ram_console_early_init(void)
289{
290 return ram_console_init((struct ram_console_buffer *)
291 CONFIG_ANDROID_RAM_CONSOLE_EARLY_ADDR,
292 CONFIG_ANDROID_RAM_CONSOLE_EARLY_SIZE,
293 ram_console_old_log_init_buffer);
294}
295#else
296static int ram_console_driver_probe(struct platform_device *pdev)
297{
298 struct resource *res = pdev->resource;
299 size_t start;
300 size_t buffer_size;
301 void *buffer;
302
303 if (res == NULL || pdev->num_resources != 1 ||
304 !(res->flags & IORESOURCE_MEM)) {
305 printk(KERN_ERR "ram_console: invalid resource, %p %d flags "
306 "%lx\n", res, pdev->num_resources, res ? res->flags : 0);
307 return -ENXIO;
308 }
309 buffer_size = res->end - res->start + 1;
310 start = res->start;
311 printk(KERN_INFO "ram_console: got buffer at %x, size %x\n",
312 start, buffer_size);
313 buffer = ioremap(res->start, buffer_size);
314 if (buffer == NULL) {
315 printk(KERN_ERR "ram_console: failed to map memory\n");
316 return -ENOMEM;
317 }
318
319 return ram_console_init(buffer, buffer_size, NULL/* allocate */);
320}
321
322static struct platform_driver ram_console_driver = {
323 .probe = ram_console_driver_probe,
324 .driver = {
325 .name = "ram_console",
326 },
327};
328
329static int __init ram_console_module_init(void)
330{
331 int err;
332 err = platform_driver_register(&ram_console_driver);
333 return err;
334}
335#endif
336
337static ssize_t ram_console_read_old(struct file *file, char __user *buf,
338 size_t len, loff_t *offset)
339{
340 loff_t pos = *offset;
341 ssize_t count;
342
343 if (pos >= ram_console_old_log_size)
344 return 0;
345
346 count = min(len, (size_t)(ram_console_old_log_size - pos));
347 if (copy_to_user(buf, ram_console_old_log + pos, count))
348 return -EFAULT;
349
350 *offset += count;
351 return count;
352}
353
354static struct file_operations ram_console_file_ops = {
355 .owner = THIS_MODULE,
356 .read = ram_console_read_old,
357};
358
359static int __init ram_console_late_init(void)
360{
361 struct proc_dir_entry *entry;
362
363 if (ram_console_old_log == NULL)
364 return 0;
365#ifdef CONFIG_ANDROID_RAM_CONSOLE_EARLY_INIT
366 ram_console_old_log = kmalloc(ram_console_old_log_size, GFP_KERNEL);
367 if (ram_console_old_log == NULL) {
368 printk(KERN_ERR
369 "ram_console: failed to allocate buffer for old log\n");
370 ram_console_old_log_size = 0;
371 return 0;
372 }
373 memcpy(ram_console_old_log,
374 ram_console_old_log_init_buffer, ram_console_old_log_size);
375#endif
376 entry = create_proc_entry("last_kmsg", S_IFREG | S_IRUGO, NULL);
377 if (!entry) {
378 printk(KERN_ERR "ram_console: failed to create proc entry\n");
379 kfree(ram_console_old_log);
380 ram_console_old_log = NULL;
381 return 0;
382 }
383
384 entry->proc_fops = &ram_console_file_ops;
385 entry->size = ram_console_old_log_size;
386 return 0;
387}
388
389#ifdef CONFIG_ANDROID_RAM_CONSOLE_EARLY_INIT
390console_initcall(ram_console_early_init);
391#else
392module_init(ram_console_module_init);
393#endif
394late_initcall(ram_console_late_init);
395