2 * arch/arm/mach-rockchip/last_log.c
4 * Copyright (C) 2011-2014 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_fops = {
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%08x map to 0x%p and copy to 0x%p (version 2.2)\n", virt_to_phys(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 = proc_create("last_log", S_IRUSR, NULL, &last_log_fops);
92 pr_err("failed to create proc entry\n");
95 proc_set_size(entry, LOG_BUF_LEN);
97 #ifndef CONFIG_ANDROID_RAM_CONSOLE
98 proc_symlink("last_kmsg", NULL, "last_log");
104 postcore_initcall(last_log_init);