hc
2023-12-04 f33f61bdb7ca6d5ebe7a78f9d8694b91360279ac
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (c) 2014, STMicroelectronics International N.V.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.
 *
 * 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/kernel.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/uaccess.h>
 
#include "linux/tee_core.h"
#include "tee_debugfs.h"
 
static struct dentry *tee_debugfs_dir;
 
static ssize_t tee_trace_read(struct file *filp, char __user *userbuf,
                 size_t count, loff_t *ppos)
{
   struct tee *tee = filp->private_data;
 
   char buff[258];
   int len = sprintf(buff, "device=%s\n NO LOG AVAILABLE\n", tee->name);
 
   return simple_read_from_buffer(userbuf, count, ppos, buff, len);
}
 
static const struct file_operations log_tee_ops = {
   .read = tee_trace_read,
   .open = simple_open,
   .llseek = generic_file_llseek,
};
 
void tee_create_debug_dir(struct tee *tee)
{
   struct dentry *entry;
   struct device *dev = tee->miscdev.this_device;
 
   if (!tee_debugfs_dir)
       return;
 
   tee->dbg_dir = debugfs_create_dir(dev_name(dev), tee_debugfs_dir);
   if (!tee->dbg_dir)
       goto error_create_file;
 
   entry = debugfs_create_file("log", S_IRUGO, tee->dbg_dir,
                   tee, &log_tee_ops);
   if (!entry)
       goto error_create_file;
 
   return;
 
error_create_file:
   dev_err(dev, "can't create debugfs file\n");
   tee_delete_debug_dir(tee);
}
 
void tee_delete_debug_dir(struct tee *tee)
{
   if (!tee || !tee->dbg_dir)
       return;
 
   debugfs_remove_recursive(tee->dbg_dir);
}
 
void __init tee_init_debugfs(void)
{
   if (debugfs_initialized()) {
       tee_debugfs_dir = debugfs_create_dir("tee", NULL);
       if (IS_ERR(tee_debugfs_dir))
           pr_err("can't create debugfs dir\n");
   }
}
 
void __exit tee_exit_debugfs(void)
{
   if (tee_debugfs_dir)
       debugfs_remove(tee_debugfs_dir);
}