[PATCH 1/1] regmap: debugfs: Allow writes to cache state settings
From: Richard Fitzgerald
Date: Mon Jun 22 2015 - 11:28:13 EST
Allow the user to write the cache_only and cache_bypass settings.
This can be useful for debugging.
Since this can lead to the hardware getting out-of-sync with the
cache, at least for the period that the cache state is forced, the
kernel is tainted and the action is recorded in the kernel log.
When disabling cache_only through debugfs a cache sync will be performed.
Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
---
drivers/base/regmap/regmap-debugfs.c | 135 +++++++++++++++++++++++++++++++++-
1 files changed, 131 insertions(+), 4 deletions(-)
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 5799a0b..4ad6a1a 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -469,6 +469,133 @@ static const struct file_operations regmap_access_fops = {
.llseek = default_llseek,
};
+static ssize_t regmap_bool_read_file(struct file *file,
+ char __user *user_buf,
+ size_t count, loff_t *ppos,
+ bool value)
+{
+ char buf[2];
+
+ buf[0] = value ? 'Y' : 'N';
+ buf[1] = '\n';
+ return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf));
+}
+
+static ssize_t regmap_bool_write_file(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos,
+ bool *value)
+{
+ char buf[32];
+ size_t buf_size;
+
+ buf_size = min(count, (sizeof(buf)-1));
+ if (copy_from_user(buf, user_buf, buf_size))
+ return -EFAULT;
+
+ buf[buf_size] = '\0';
+ if (strtobool(buf, value) != 0)
+ return -EINVAL;
+
+ return count;
+}
+
+static ssize_t regmap_cache_only_read_file(struct file *file,
+ char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct regmap *map = file->private_data;
+
+ return regmap_bool_read_file(file, user_buf, count, ppos,
+ map->cache_only);
+}
+
+static ssize_t regmap_cache_only_write_file(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct regmap *map = file->private_data;
+ ssize_t result;
+ bool enable, require_sync = false;
+ int err;
+
+ result = regmap_bool_write_file(file, user_buf, count, ppos, &enable);
+ if (result < 0)
+ return result;
+
+ map->lock(map->lock_arg);
+
+ if (enable && !map->cache_only) {
+ dev_warn(map->dev, "debugfs cache_only=Y forced\n");
+ add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+ map->cache_only = true;
+ } else if (!enable && map->cache_only) {
+ dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n");
+ map->cache_only = false;
+ require_sync = true;
+ }
+
+ map->unlock(map->lock_arg);
+
+ if (require_sync) {
+ err = regcache_sync(map);
+ if (err)
+ dev_err(map->dev, "Failed to sync cache %d\n", err);
+ }
+
+ return result;
+}
+
+static const struct file_operations regmap_cache_only_fops = {
+ .open = simple_open,
+ .read = regmap_cache_only_read_file,
+ .write = regmap_cache_only_write_file,
+};
+
+static ssize_t regmap_cache_bypass_read_file(struct file *file,
+ char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct regmap *map = file->private_data;
+
+ return regmap_bool_read_file(file, user_buf, count, ppos,
+ map->cache_bypass);
+}
+
+static ssize_t regmap_cache_bypass_write_file(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct regmap *map = file->private_data;
+ ssize_t result;
+ bool enable;
+
+ result = regmap_bool_write_file(file, user_buf, count, ppos, &enable);
+ if (result < 0)
+ return result;
+
+ map->lock(map->lock_arg);
+
+ if (enable && !map->cache_bypass) {
+ dev_warn(map->dev, "debugfs cache_bypass=Y forced\n");
+ add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+ map->cache_bypass = true;
+ } else if (!enable && map->cache_bypass) {
+ dev_warn(map->dev, "debugfs cache_bypass=N forced\n");
+ map->cache_bypass = false;
+ }
+
+ map->unlock(map->lock_arg);
+
+ return result;
+}
+
+static const struct file_operations regmap_cache_bypass_fops = {
+ .open = simple_open,
+ .read = regmap_cache_bypass_read_file,
+ .write = regmap_cache_bypass_write_file,
+};
+
void regmap_debugfs_init(struct regmap *map, const char *name)
{
struct rb_node *next;
@@ -530,12 +657,12 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
}
if (map->cache_type) {
- debugfs_create_bool("cache_only", 0400, map->debugfs,
- &map->cache_only);
+ debugfs_create_file("cache_only", 0600, map->debugfs,
+ map, ®map_cache_only_fops);
debugfs_create_bool("cache_dirty", 0400, map->debugfs,
&map->cache_dirty);
- debugfs_create_bool("cache_bypass", 0400, map->debugfs,
- &map->cache_bypass);
+ debugfs_create_file("cache_bypass", 0600, map->debugfs,
+ map, ®map_cache_bypass_fops);
}
next = rb_first(&map->range_tree);
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at http://www.tux.org/lkml/