2011-11-30 11:18:14 +00:00
|
|
|
/* drivers/android/ram_console.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Google, Inc.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2, as published by the Free Software Foundation, and
|
|
|
|
* may be copied, distributed, and modified under those terms.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/io.h>
|
2012-03-08 01:34:32 +00:00
|
|
|
#include "persistent_ram.h"
|
2011-10-25 21:31:58 +00:00
|
|
|
#include "ram_console.h"
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:34 +00:00
|
|
|
static struct persistent_ram_zone *ram_console_zone;
|
2012-03-08 01:34:29 +00:00
|
|
|
static const char *bootinfo;
|
|
|
|
static size_t bootinfo_size;
|
2011-11-30 11:18:14 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ram_console_write(struct console *console, const char *s, unsigned int count)
|
|
|
|
{
|
2012-03-08 01:34:32 +00:00
|
|
|
struct persistent_ram_zone *prz = console->data;
|
|
|
|
persistent_ram_write(prz, s, count);
|
2011-11-30 11:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct console ram_console = {
|
|
|
|
.name = "ram",
|
|
|
|
.write = ram_console_write,
|
2012-03-08 01:34:28 +00:00
|
|
|
.flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME,
|
2011-11-30 11:18:14 +00:00
|
|
|
.index = -1,
|
|
|
|
};
|
|
|
|
|
2009-09-17 21:27:41 +00:00
|
|
|
void ram_console_enable_console(int enabled)
|
|
|
|
{
|
|
|
|
if (enabled)
|
|
|
|
ram_console.flags |= CON_ENABLED;
|
|
|
|
else
|
|
|
|
ram_console.flags &= ~CON_ENABLED;
|
|
|
|
}
|
|
|
|
|
2012-03-08 19:41:14 +00:00
|
|
|
static int __init ram_console_probe(struct platform_device *pdev)
|
2011-11-30 11:18:14 +00:00
|
|
|
{
|
2011-10-25 21:31:58 +00:00
|
|
|
struct ram_console_platform_data *pdata = pdev->dev.platform_data;
|
2012-03-08 01:34:34 +00:00
|
|
|
struct persistent_ram_zone *prz;
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:34 +00:00
|
|
|
prz = persistent_ram_init_ringbuffer(&pdev->dev, true);
|
|
|
|
if (IS_ERR(prz))
|
|
|
|
return PTR_ERR(prz);
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:32 +00:00
|
|
|
|
2012-03-08 01:34:29 +00:00
|
|
|
if (pdata) {
|
|
|
|
bootinfo = kstrdup(pdata->bootinfo, GFP_KERNEL);
|
|
|
|
if (bootinfo)
|
|
|
|
bootinfo_size = strlen(bootinfo);
|
|
|
|
}
|
2011-10-25 21:31:58 +00:00
|
|
|
|
2012-03-08 01:34:34 +00:00
|
|
|
ram_console_zone = prz;
|
|
|
|
ram_console.data = prz;
|
2012-03-08 01:34:32 +00:00
|
|
|
|
|
|
|
register_console(&ram_console);
|
|
|
|
|
2012-03-08 01:34:34 +00:00
|
|
|
return 0;
|
2011-11-30 11:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver ram_console_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ram_console",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ram_console_module_init(void)
|
|
|
|
{
|
2012-03-08 19:41:14 +00:00
|
|
|
return platform_driver_probe(&ram_console_driver, ram_console_probe);
|
2011-11-30 11:18:14 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 23:38:14 +00:00
|
|
|
#ifndef CONFIG_PRINTK
|
|
|
|
#define dmesg_restrict 0
|
|
|
|
#endif
|
|
|
|
|
2011-11-30 11:18:14 +00:00
|
|
|
static ssize_t ram_console_read_old(struct file *file, char __user *buf,
|
|
|
|
size_t len, loff_t *offset)
|
|
|
|
{
|
|
|
|
loff_t pos = *offset;
|
|
|
|
ssize_t count;
|
2012-03-08 01:34:34 +00:00
|
|
|
struct persistent_ram_zone *prz = ram_console_zone;
|
2012-03-08 01:34:32 +00:00
|
|
|
size_t old_log_size = persistent_ram_old_size(prz);
|
|
|
|
const char *old_log = persistent_ram_old(prz);
|
2012-03-08 01:34:29 +00:00
|
|
|
char *str;
|
|
|
|
int ret;
|
|
|
|
|
2012-03-08 01:34:38 +00:00
|
|
|
if (dmesg_restrict && !capable(CAP_SYSLOG))
|
|
|
|
return -EPERM;
|
|
|
|
|
2012-03-08 01:34:29 +00:00
|
|
|
/* Main last_kmsg log */
|
2012-03-08 01:34:32 +00:00
|
|
|
if (pos < old_log_size) {
|
|
|
|
count = min(len, (size_t)(old_log_size - pos));
|
|
|
|
if (copy_to_user(buf, old_log + pos, count))
|
2012-03-08 01:34:29 +00:00
|
|
|
return -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:29 +00:00
|
|
|
/* ECC correction notice */
|
2012-03-08 01:34:32 +00:00
|
|
|
pos -= old_log_size;
|
|
|
|
count = persistent_ram_ecc_string(prz, NULL, 0);
|
2012-03-08 01:34:29 +00:00
|
|
|
if (pos < count) {
|
|
|
|
str = kmalloc(count, GFP_KERNEL);
|
|
|
|
if (!str)
|
|
|
|
return -ENOMEM;
|
2012-03-08 01:34:32 +00:00
|
|
|
persistent_ram_ecc_string(prz, str, count + 1);
|
2012-03-08 01:34:29 +00:00
|
|
|
count = min(len, (size_t)(count - pos));
|
|
|
|
ret = copy_to_user(buf, str + pos, count);
|
|
|
|
kfree(str);
|
|
|
|
if (ret)
|
|
|
|
return -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:29 +00:00
|
|
|
/* Boot info passed through pdata */
|
|
|
|
pos -= count;
|
|
|
|
if (pos < bootinfo_size) {
|
|
|
|
count = min(len, (size_t)(bootinfo_size - pos));
|
|
|
|
if (copy_to_user(buf, bootinfo + pos, count))
|
|
|
|
return -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|
|
|
|
return 0;
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:29 +00:00
|
|
|
out:
|
2011-11-30 11:18:14 +00:00
|
|
|
*offset += count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations ram_console_file_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = ram_console_read_old,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ram_console_late_init(void)
|
|
|
|
{
|
|
|
|
struct proc_dir_entry *entry;
|
2012-03-08 01:34:34 +00:00
|
|
|
struct persistent_ram_zone *prz = ram_console_zone;
|
2011-11-30 11:18:14 +00:00
|
|
|
|
2012-03-08 01:34:37 +00:00
|
|
|
if (!prz)
|
|
|
|
return 0;
|
|
|
|
|
2012-03-08 01:34:32 +00:00
|
|
|
if (persistent_ram_old_size(prz) == 0)
|
2011-11-30 11:18:14 +00:00
|
|
|
return 0;
|
2012-03-08 01:34:32 +00:00
|
|
|
|
2011-11-30 11:18:14 +00:00
|
|
|
entry = create_proc_entry("last_kmsg", S_IFREG | S_IRUGO, NULL);
|
|
|
|
if (!entry) {
|
|
|
|
printk(KERN_ERR "ram_console: failed to create proc entry\n");
|
2012-03-08 01:34:32 +00:00
|
|
|
persistent_ram_free_old(prz);
|
2011-11-30 11:18:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->proc_fops = &ram_console_file_ops;
|
2012-03-08 01:34:32 +00:00
|
|
|
entry->size = persistent_ram_old_size(prz) +
|
|
|
|
persistent_ram_ecc_string(prz, NULL, 0) +
|
|
|
|
bootinfo_size;
|
|
|
|
|
2011-11-30 11:18:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
late_initcall(ram_console_late_init);
|
2012-03-08 01:34:32 +00:00
|
|
|
postcore_initcall(ram_console_module_init);
|