All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
To: broonie@kernel.org
Cc: gregkh@linuxfoundation.org, patches@opensource.wolfsonmicro.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] regmap: debugfs: Allow writes to cache state settings
Date: Mon, 22 Jun 2015 16:30:34 +0100	[thread overview]
Message-ID: <1434987034-17673-2-git-send-email-rf@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1434987034-17673-1-git-send-email-rf@opensource.wolfsonmicro.com>

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@opensource.wolfsonmicro.com>
---
 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, &regmap_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, &regmap_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/

  reply	other threads:[~2015-06-22 15:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22 15:30 [PATCH 0/1] regmap: debugfs: Allow writes to cache state settings Richard Fitzgerald
2015-06-22 15:30 ` Richard Fitzgerald [this message]
2015-06-22 15:49   ` [PATCH 1/1] " Mark Brown
2015-06-22 16:10     ` Richard Fitzgerald
2015-06-23 10:26       ` Mark Brown
2015-06-22 15:36 ` [PATCH 0/1] " Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434987034-17673-2-git-send-email-rf@opensource.wolfsonmicro.com \
    --to=rf@opensource.wolfsonmicro.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.