2 * arch/arm/mach-rk29/last_log.c
4 * Copyright (C) 2011 ROCKCHIP, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #define pr_fmt(fmt) "last_log: " fmt
12 #include <linux/kernel.h>
13 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/proc_fs.h>
17 #include <linux/vmalloc.h>
18 #include <asm/uaccess.h>
21 #define LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
22 #define LOG_BUF_PAGE_ORDER (CONFIG_LOG_BUF_SHIFT - PAGE_SHIFT)
23 static char last_log_buf[LOG_BUF_LEN];
24 extern void __init switch_log_buf(char *new_log_buf, unsigned size);
26 char *last_log_get(unsigned *size)
32 static ssize_t last_log_read(struct file *file, char __user *buf,
33 size_t len, loff_t *offset)
38 if (pos >= LOG_BUF_LEN)
41 count = min(len, (size_t)(LOG_BUF_LEN - pos));
42 if (copy_to_user(buf, &last_log_buf[pos], count))
49 static const struct file_operations last_log_file_ops = {
51 .read = last_log_read,
54 static void * __init last_log_vmap(phys_addr_t start, unsigned int page_count)
56 struct page *pages[page_count + 1];
59 for (i = 0; i < page_count; i++) {
60 phys_addr_t addr = start + i * PAGE_SIZE;
61 pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
63 pages[page_count] = pfn_to_page(start >> PAGE_SHIFT);
64 return vmap(pages, page_count + 1, VM_MAP, pgprot_noncached(PAGE_KERNEL));
67 static int __init last_log_init(void)
69 char *log_buf, *new_log_buf;
70 struct proc_dir_entry *entry;
72 log_buf = (char *)__get_free_pages(GFP_KERNEL, LOG_BUF_PAGE_ORDER);
74 pr_err("failed to __get_free_pages(%d)\n", LOG_BUF_PAGE_ORDER);
78 new_log_buf = last_log_vmap(virt_to_phys(log_buf), 1 << LOG_BUF_PAGE_ORDER);
80 pr_err("failed to map %d pages at 0x%08x\n", 1 << LOG_BUF_PAGE_ORDER, virt_to_phys(log_buf));
84 pr_info("0x%p map to 0x%p and copy to 0x%p (version 2.1)\n", log_buf, new_log_buf, last_log_buf);
86 memcpy(last_log_buf, new_log_buf, LOG_BUF_LEN);
87 memset(new_log_buf, 0, LOG_BUF_LEN);
88 switch_log_buf(new_log_buf, LOG_BUF_LEN);
90 entry = create_proc_entry("last_log", S_IFREG | S_IRUGO, NULL);
92 pr_err("failed to create proc entry\n");
96 entry->proc_fops = &last_log_file_ops;
97 entry->size = LOG_BUF_LEN;
99 #ifndef CONFIG_ANDROID_RAM_CONSOLE
100 proc_symlink("last_kmsg", NULL, "last_log");
106 postcore_initcall(last_log_init);