summaryrefstree
path: root/kernel/drivers/rkp/rkp_debug_log.c
blob: 8328e3943ea4794d69db319ff08c15ee82d22a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/highmem.h>
#include <linux/rkp.h>

ssize_t	rkp_log_read(struct file *filep, char __user *buf, size_t size, loff_t *offset)
{
	size_t log_buf_size;
	unsigned long *log_addr = 0;

	if (!strcmp(filep->f_path.dentry->d_iname, "rkp_log")) {
		log_buf_size = RKP_LOG_SIZE;
		log_addr = (unsigned long *)phys_to_virt(RKP_LOG_START);
	} else
		return -1;

	if (*offset >= log_buf_size)
		return -EINVAL;

	if (*offset + size > log_buf_size)
		size = log_buf_size - *offset;

	if (copy_to_user(buf, (const char *)log_addr + (*offset), size))
		return -EFAULT;

	*offset += size;
	return size;
}

static const struct file_operations rkp_proc_fops = {
	.owner		= THIS_MODULE,
	.read		= rkp_log_read,
};

static int __init rkp_log_init(void)
{
	struct proc_dir_entry *entry;

	entry = proc_create("rkp_log", 0644, NULL, &rkp_proc_fops);
	if (!entry) {
		RKP_LOGE("Error creating proc entry\n");
		return -ENOMEM;
	}

	RKP_LOGI("create rkp nodes in /proc\n");
	return 0;
}

static void __exit rkp_log_exit(void)
{
	remove_proc_entry("rkp_log", NULL);
}

module_init(rkp_log_init);
module_exit(rkp_log_exit);