summaryrefslogtreecommitdiff
path: root/fs/proc/sprd_debug/proc_sprd_debug_frame.c
blob: 8551a4ac768c387b1c6673ef781418fd19eecbab (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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/seq_file.h>
#include <linux/debugfs.h>
#include <linux/mm.h>
#include <linux/stat.h>

enum sprd_debug_type{
	SCHE,
	MEM,
	COMM,
	TIMER,
	IRQ,
	IO,
	CPU,
	MISC,
	TYPE_COUNT
};

struct sprd_debug_dir {
	char *name;
	struct dentry *debugfs_entry;
};

struct sprd_debug_dir sprd_debug_dir_table[TYPE_COUNT] = {
	{.name = "sche", .debugfs_entry = NULL},
	{.name = "mem", .debugfs_entry = NULL},
	{.name = "comm", .debugfs_entry = NULL},
	{.name = "timer", .debugfs_entry = NULL},
	{.name = "irq", .debugfs_entry = NULL},
	{.name = "io", .debugfs_entry = NULL},
	{.name = "cpu", .debugfs_entry = NULL},
	{.name = "misc", .debugfs_entry = NULL},
};

struct sprd_debug_entry {
	enum sprd_debug_type type;
	char *name;
	mode_t mode;
	struct file_operations *fop;
};

#define NOD(TYPE, NAME, MODE, FOP) {  	\
	.type = TYPE,			\
	.name = NAME,			\
	.mode = MODE,			\
	.fop = FOP}

#ifdef CONFIG_SPRD_DEBUG_PHYMEM_INFO
extern struct file_operations phymem_dist_proc_fops;
extern struct file_operations phymem_pages_proc_fops;
extern struct file_operations phymem_map_proc_fops;
#endif

#ifdef CONFIG_SPRD_DEBUG_USRPROCMEM_INFO
extern struct file_operations user_process_meminfo_fops;
#endif

#ifdef CONFIG_SPRD_DEBUG_SCHED_LOG
extern struct file_operations scheinfo_proc_fops;
extern struct file_operations scheinfo_num_proc_fops;
extern struct file_operations irqinfo_proc_fops;
extern struct file_operations irqinfo_num_proc_fops;
extern struct file_operations last_regs_info_proc_fops;
extern struct file_operations userstack_info_proc_fops;
#endif

#ifdef CONFIG_SPRD_DEBUG_CPU_RATE
extern struct file_operations proc_cpu_usage_fops;
#endif

static struct sprd_debug_entry sprd_debug_array[] = {
#ifdef CONFIG_SPRD_DEBUG_PHYMEM_INFO
	NOD(MEM,   "phymemdist", 0, &phymem_dist_proc_fops),
	NOD(MEM,   "phymempages", 0, &phymem_pages_proc_fops),
	NOD(MEM,   "phymemmap", 0, &phymem_map_proc_fops),
#endif

#ifdef CONFIG_SPRD_DEBUG_USRPROCMEM_INFO
	NOD(MEM,   "userprocmem", 0, &user_process_meminfo_fops),
	NOD(MEM,   "userthreadstack", 0, &userstack_info_proc_fops),
#endif

#ifdef CONFIG_SPRD_DEBUG_SCHED_LOG
	NOD(SCHE,  "schedlog", 0444 , &scheinfo_proc_fops),
	NOD(SCHE,  "schedlog_num", 0, &scheinfo_num_proc_fops),
	NOD(IRQ,   "irqlog", 0, &irqinfo_proc_fops),
	NOD(IRQ,   "irqlog_num", 0, &irqinfo_num_proc_fops),
	NOD(IO,    "last_regs", 0, &last_regs_info_proc_fops),
#endif

#ifdef CONFIG_SPRD_DEBUG_CPU_RATE
	NOD(CPU,    "cpu_usage", 0444, &proc_cpu_usage_fops),
#endif
};

static struct dentry *debugfs_sprd_debug_root;

static void _sprd_entry_create(struct sprd_debug_entry *psprd_debug)
{
	if ((psprd_debug->name != NULL) && (psprd_debug->fop != NULL))
		debugfs_create_file(psprd_debug->name, psprd_debug->mode,
					sprd_debug_dir_table[psprd_debug->type].debugfs_entry, NULL, psprd_debug->fop);
}

static void _sprd_debug_init(void)
{
	int i;
	int num = sizeof(sprd_debug_array) / sizeof(struct sprd_debug_entry);

	for (i = 0; i < num; i++)
		_sprd_entry_create(&sprd_debug_array[i]);

}

static void _sprd_dir_init(void)
{
	int i;

	debugfs_sprd_debug_root = debugfs_create_dir("sprd_debug", NULL);
	for (i = 0; i < TYPE_COUNT; i++)
		sprd_debug_dir_table[i].debugfs_entry =  debugfs_create_dir(sprd_debug_dir_table[i].name, debugfs_sprd_debug_root);
}

static int _sprd_debug_module_init(void)
{
	_sprd_dir_init();
	_sprd_debug_init();
	return 0;
}

module_init(_sprd_debug_module_init);