import OT_8063_20170412 mali driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / ged / src / ged_debugFS.c
1 #include <linux/module.h>
2 #include <linux/slab.h>
3
4 #include <linux/debugfs.h>
5
6 #include "ged_base.h"
7 #include "ged_debugFS.h"
8
9 #define GED_DEBUGFS_DIR_NAME "ged"
10
11 static struct dentry *gpsDebugFSEntryDir = NULL;
12
13 typedef struct _GED_DEBUGFS_PRIV_DATA_
14 {
15 struct seq_operations* psReadOps;
16 GED_ENTRY_WRITE_FUNC* pfnWrite;
17 void* pvData;
18 } GED_DEBUGFS_PRIV_DATA;
19 //-----------------------------------------------------------------------------
20 static int ged_debugFS_open(struct inode *psINode, struct file *psFile)
21 {
22 GED_DEBUGFS_PRIV_DATA *psPrivData = (GED_DEBUGFS_PRIV_DATA *)psINode->i_private;
23 int iResult;
24
25 iResult = seq_open(psFile, psPrivData->psReadOps);
26 if (iResult == 0)
27 {
28 struct seq_file *psSeqFile = psFile->private_data;
29
30 psSeqFile->private = psPrivData->pvData;
31
32 return GED_OK;
33 }
34
35 return GED_ERROR_FAIL;
36 }
37 //-----------------------------------------------------------------------------
38 static ssize_t ged_debugFS_write(
39 struct file* psFile,
40 const char __user* pszBuffer,
41 size_t uiCount,
42 loff_t* puiPosition)
43 {
44 struct inode *psINode = psFile->f_path.dentry->d_inode;
45 GED_DEBUGFS_PRIV_DATA *psPrivData = (GED_DEBUGFS_PRIV_DATA *)psINode->i_private;
46
47 if (psPrivData->pfnWrite == NULL)
48 {
49 return -EIO;
50 }
51
52 return psPrivData->pfnWrite(pszBuffer, uiCount, *puiPosition, psPrivData->pvData);
53 }
54 //-----------------------------------------------------------------------------
55 static const struct file_operations gsGEDDebugFSFileOps =
56 {
57 .owner = THIS_MODULE,
58 .open = ged_debugFS_open,
59 .read = seq_read,
60 .write = ged_debugFS_write,
61 .llseek = seq_lseek,
62 .release = seq_release,
63 };
64 //-----------------------------------------------------------------------------
65 GED_ERROR ged_debugFS_create_entry(
66 const char* pszName,
67 void* pvDir,
68 struct seq_operations* psReadOps,
69 GED_ENTRY_WRITE_FUNC* pfnWrite,
70 void* pvData,
71 struct dentry** ppsEntry)
72 {
73 GED_DEBUGFS_PRIV_DATA* psPrivData;
74 struct dentry* psEntry;
75 umode_t uiMode;
76
77 //assert(gpkDebugFSEntryDir != NULL);
78
79 psPrivData = ged_alloc(sizeof(GED_DEBUGFS_PRIV_DATA));
80 if (psPrivData == NULL)
81 {
82 return GED_ERROR_OOM;
83 }
84
85 psPrivData->psReadOps = psReadOps;
86 psPrivData->pfnWrite = pfnWrite;
87 psPrivData->pvData = pvData;
88
89 uiMode = S_IFREG;
90
91 if (psReadOps != NULL)
92 {
93 uiMode |= S_IRUGO;
94 }
95
96 if (pfnWrite != NULL)
97 {
98 uiMode |= S_IWUSR | S_IWGRP | S_IWOTH;
99 }
100
101 psEntry = debugfs_create_file(pszName,
102 uiMode,
103 (pvDir != NULL) ? (struct dentry *)pvDir : gpsDebugFSEntryDir,
104 psPrivData,
105 &gsGEDDebugFSFileOps);
106 if (IS_ERR(psEntry))
107 {
108 GED_LOGE("Failed to create '%s' debugfs entry\n", pszName);
109 return GED_ERROR_FAIL;
110 }
111
112 *ppsEntry = psEntry;
113
114 return GED_OK;
115 }
116 //-----------------------------------------------------------------------------
117 void ged_debugFS_remove_entry(struct dentry *psEntry)
118 {
119 if (psEntry->d_inode->i_private != NULL)
120 {
121 ged_free(psEntry->d_inode->i_private, sizeof(GED_DEBUGFS_PRIV_DATA));
122 }
123
124 debugfs_remove(psEntry);
125 }
126 //-----------------------------------------------------------------------------
127 GED_ERROR ged_debugFS_create_entry_dir(
128 const char* pszName,
129 struct dentry* psParentDir,
130 struct dentry** ppsDir)
131 {
132 struct dentry *psDir;
133
134 if (pszName == NULL || ppsDir == NULL)
135 {
136 return GED_ERROR_INVALID_PARAMS;
137 }
138
139 psDir = debugfs_create_dir(pszName, (psParentDir) ? psParentDir : gpsDebugFSEntryDir);
140 if (psDir == NULL)
141 {
142 GED_LOGE("Failed to create '%s' debugfs directory\n", pszName);
143 return GED_ERROR_OOM;
144 }
145
146 *ppsDir = psDir;
147
148 return GED_OK;
149 }
150 //-----------------------------------------------------------------------------
151 void ged_debugFS_remove_entry_dir(struct dentry *psDir)
152 {
153 debugfs_remove(psDir);
154 }
155 //-----------------------------------------------------------------------------
156 GED_ERROR ged_debugFS_init(void)
157 {
158 //assert(gpkDebugFSEntryDir == NULL);
159
160 gpsDebugFSEntryDir = debugfs_create_dir(GED_DEBUGFS_DIR_NAME, NULL);
161 if (gpsDebugFSEntryDir == NULL)
162 {
163 GED_LOGE("Failed to create '%s' debugfs root directory\n", GED_DEBUGFS_DIR_NAME);
164 return GED_ERROR_OOM;
165 }
166
167 return GED_OK;
168 }
169 //-----------------------------------------------------------------------------
170 void ged_debugFS_exit(void)
171 {
172 //assert(gpkDebugFSEntryDir != NULL);
173
174 debugfs_remove(gpsDebugFSEntryDir);
175 gpsDebugFSEntryDir = NULL;
176 }
177 //-----------------------------------------------------------------------------
178