2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) Samsung Electronics, 2014
18 * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
23 #include <linux/slab.h>
24 #include <linux/debugfs.h>
25 #include <linux/uaccess.h>
26 #include <master/swap_debugfs.h>
30 static int do_write_cmd(const char *buf, size_t count)
36 name = kmalloc(count, GFP_KERNEL);
40 n = sscanf(buf, "%lx %s", &offset, name);
46 ret = wsp_set_addr(name, offset);
53 /* ============================================================================
54 * === DEBUGFS FOR ENABLE ===
55 * ============================================================================
57 static ssize_t write_cmd(struct file *file, const char __user *user_buf,
58 size_t count, loff_t *ppos)
60 enum { max_count = 1024 };
64 if (count > max_count)
67 buf = kmalloc(count + 1, GFP_KERNEL);
71 if (copy_from_user(buf, user_buf, count)) {
77 ret = do_write_cmd(buf, count);
81 return ret ? ret : count;
84 static const struct file_operations fops_cmd = {
86 .llseek = default_llseek,
92 /* ============================================================================
93 * === DEBUGFS FOR ENABLE ===
94 * ============================================================================
96 static ssize_t read_enabled(struct file *file, char __user *user_buf,
97 size_t count, loff_t *ppos)
101 buf[0] = wsp_get_mode() == WSP_OFF ? '0' : '1';
104 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
107 static ssize_t write_enabled(struct file *file, const char __user *user_buf,
108 size_t count, loff_t *ppos)
114 buf_size = min(count, (sizeof(buf) - 1));
115 if (copy_from_user(buf, user_buf, buf_size))
118 buf[buf_size] = '\0';
121 ret = wsp_set_mode(WSP_ON);
124 ret = wsp_set_mode(WSP_OFF);
136 static const struct file_operations fops_enabled = {
137 .read = read_enabled,
138 .write = write_enabled,
139 .llseek = default_llseek,
143 static struct dentry *wsp_dir;
145 void wsp_debugfs_exit(void)
148 debugfs_remove_recursive(wsp_dir);
153 int wsp_debugfs_init(void)
155 struct dentry *dentry;
157 dentry = swap_debugfs_getdir();
161 wsp_dir = debugfs_create_dir("wsp", dentry);
165 dentry = debugfs_create_file("enabled", 0600, wsp_dir, NULL,
170 dentry = debugfs_create_file("cmd", 0600, wsp_dir, NULL, &fops_cmd);