2 #include <linux/slab.h>
3 #include <linux/debugfs.h>
4 #include <linux/module.h>
5 #include <asm/uaccess.h>
6 #include <master/swap_debugfs.h>
8 #include "uihv_module.h"
10 static const char UIHV_FOLDER[] = "uihv";
11 static const char UIHV_PATH[] = "path";
12 static const char UIHV_APP_INFO[] = "app_info";
13 static const char UIHV_ENABLE[] = "enable";
15 static struct dentry *uihv_root;
19 /* ===========================================================================
21 * ===========================================================================
25 static ssize_t uihv_path_write(struct file *file, const char __user *buf,
26 size_t len, loff_t *ppos)
31 path = kmalloc(len, GFP_KERNEL);
34 goto uihv_path_write_out;
37 if (copy_from_user(path, buf, len)) {
39 goto uihv_path_write_out;
44 if (uihv_set_handler(path) != 0) {
45 printk(UIHV_PREFIX "Cannot set ui viewer path %s\n", path);
47 goto uihv_path_write_out;
52 printk(UIHV_PREFIX "Set ui viewer path %s\n", path);
60 static const struct file_operations uihv_path_file_ops = {
62 .write = uihv_path_write,
71 * 0x00000d60:/bin/app_sample
73 static int uihv_add_app_info(const char *buf, size_t len)
77 unsigned long main_addr;
78 const char fmt[] = "%%lx:/%%%ds";
81 n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
85 app_path = kmalloc(PATH_MAX, GFP_KERNEL);
89 n = sscanf(buf, fmt_buf, &main_addr, app_path + 1);
96 printk(UIHV_PREFIX "Set ui viewer app path %s, main offset 0x%lx\n", app_path, main_addr);
98 ret = uihv_data_set(app_path, main_addr);
105 static ssize_t write_uihv_app_info(struct file *file,
106 const char __user *user_buf,
107 size_t len, loff_t *ppos)
112 buf = kmalloc(len, GFP_KERNEL);
118 if (copy_from_user(buf, user_buf, len)) {
125 if (uihv_add_app_info(buf, len))
134 static const struct file_operations uihv_app_info_file_ops = {
135 .owner = THIS_MODULE,
136 .write = write_uihv_app_info,
139 static ssize_t write_uihv_enable(struct file *file,
140 const char __user *user_buf,
141 size_t len, loff_t *ppos)
146 buf = kmalloc(len, GFP_KERNEL);
152 if (copy_from_user(buf, user_buf, len)) {
160 ret = uihv_disable();
171 static const struct file_operations uihv_enable_file_ops = {
172 .owner = THIS_MODULE,
173 .write = write_uihv_enable,
176 int uihv_dfs_init(void)
178 struct dentry *swap_dentry, *root, *path, *app_info, *uihv_enable;
182 if (!debugfs_initialized())
186 swap_dentry = swap_debugfs_getdir();
191 root = debugfs_create_dir(UIHV_FOLDER, swap_dentry);
192 if (IS_ERR_OR_NULL(root))
197 path = debugfs_create_file(UIHV_PATH, UIHV_DEFAULT_PERMS, root,
198 NULL, &uihv_path_file_ops);
199 if (IS_ERR_OR_NULL(path)) {
204 app_info = debugfs_create_file(UIHV_APP_INFO, UIHV_DEFAULT_PERMS,
205 root, NULL, &uihv_app_info_file_ops);
206 if (IS_ERR_OR_NULL(app_info)) {
211 uihv_enable = debugfs_create_file(UIHV_ENABLE, UIHV_DEFAULT_PERMS,
212 root, NULL, &uihv_enable_file_ops);
213 if (IS_ERR_OR_NULL(uihv_enable)) {
221 debugfs_remove_recursive(root);
224 printk(UIHV_PREFIX "Debugfs initialization failure: %d\n", ret);
229 void uihv_dfs_exit(void)
232 debugfs_remove_recursive(uihv_root);