This source file includes following definitions.
- log_buf_show
- force_reset_show
- cosm_create_debug_dir
- cosm_delete_debug_dir
- cosm_init_debugfs
- cosm_exit_debugfs
1
2
3
4
5
6
7
8
9
10 #include <linux/debugfs.h>
11 #include <linux/slab.h>
12 #include <linux/io.h>
13 #include "cosm_main.h"
14
15
16 static struct dentry *cosm_dbg;
17
18
19
20
21
22
23
24 static int log_buf_show(struct seq_file *s, void *unused)
25 {
26 void __iomem *log_buf_va;
27 int __iomem *log_buf_len_va;
28 struct cosm_device *cdev = s->private;
29 void *kva;
30 int size;
31 u64 aper_offset;
32
33 if (!cdev || !cdev->log_buf_addr || !cdev->log_buf_len)
34 goto done;
35
36 mutex_lock(&cdev->cosm_mutex);
37 switch (cdev->state) {
38 case MIC_BOOTING:
39 case MIC_ONLINE:
40 case MIC_SHUTTING_DOWN:
41 break;
42 default:
43 goto unlock;
44 }
45
46
47
48
49
50 aper_offset = (u64)cdev->log_buf_len - __START_KERNEL_map;
51 log_buf_len_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
52 aper_offset = (u64)cdev->log_buf_addr - __START_KERNEL_map;
53 log_buf_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
54
55 size = ioread32(log_buf_len_va);
56 kva = kmalloc(size, GFP_KERNEL);
57 if (!kva)
58 goto unlock;
59
60 memcpy_fromio(kva, log_buf_va, size);
61 seq_write(s, kva, size);
62 kfree(kva);
63 unlock:
64 mutex_unlock(&cdev->cosm_mutex);
65 done:
66 return 0;
67 }
68
69 DEFINE_SHOW_ATTRIBUTE(log_buf);
70
71
72
73
74
75
76
77 static int force_reset_show(struct seq_file *s, void *pos)
78 {
79 struct cosm_device *cdev = s->private;
80
81 cosm_stop(cdev, true);
82 return 0;
83 }
84
85 DEFINE_SHOW_ATTRIBUTE(force_reset);
86
87 void cosm_create_debug_dir(struct cosm_device *cdev)
88 {
89 char name[16];
90
91 if (!cosm_dbg)
92 return;
93
94 scnprintf(name, sizeof(name), "mic%d", cdev->index);
95 cdev->dbg_dir = debugfs_create_dir(name, cosm_dbg);
96
97 debugfs_create_file("log_buf", 0444, cdev->dbg_dir, cdev,
98 &log_buf_fops);
99 debugfs_create_file("force_reset", 0444, cdev->dbg_dir, cdev,
100 &force_reset_fops);
101 }
102
103 void cosm_delete_debug_dir(struct cosm_device *cdev)
104 {
105 if (!cdev->dbg_dir)
106 return;
107
108 debugfs_remove_recursive(cdev->dbg_dir);
109 }
110
111 void cosm_init_debugfs(void)
112 {
113 cosm_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
114 }
115
116 void cosm_exit_debugfs(void)
117 {
118 debugfs_remove(cosm_dbg);
119 }