All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] regmap: debugfs: Allow writes to cache state settings
@ 2015-06-22 15:30 Richard Fitzgerald
  2015-06-22 15:30 ` [PATCH 1/1] " Richard Fitzgerald
  2015-06-22 15:36 ` [PATCH 0/1] " Mark Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2015-06-22 15:30 UTC (permalink / raw)
  To: broonie; +Cc: gregkh, patches, linux-kernel

The was based on broonie/regmap.git for-next

Richard Fitzgerald (1):
  regmap: debugfs: Allow writes to cache state settings

 drivers/base/regmap/regmap-debugfs.c |  135 +++++++++++++++++++++++++++++++++-
 1 files changed, 131 insertions(+), 4 deletions(-)

-- 
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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] regmap: debugfs: Allow writes to cache state settings
  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
  2015-06-22 15:49   ` Mark Brown
  2015-06-22 15:36 ` [PATCH 0/1] " Mark Brown
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Fitzgerald @ 2015-06-22 15:30 UTC (permalink / raw)
  To: broonie; +Cc: gregkh, patches, linux-kernel

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/

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] regmap: debugfs: Allow writes to cache state settings
  2015-06-22 15:30 [PATCH 0/1] regmap: debugfs: Allow writes to cache state settings Richard Fitzgerald
  2015-06-22 15:30 ` [PATCH 1/1] " Richard Fitzgerald
@ 2015-06-22 15:36 ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2015-06-22 15:36 UTC (permalink / raw)
  To: Richard Fitzgerald; +Cc: gregkh, patches, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

On Mon, Jun 22, 2015 at 04:30:33PM +0100, Richard Fitzgerald wrote:
> The was based on broonie/regmap.git for-next
> 
> Richard Fitzgerald (1):
>   regmap: debugfs: Allow writes to cache state settings
> 
>  drivers/base/regmap/regmap-debugfs.c |  135 +++++++++++++++++++++++++++++++++-
>  1 files changed, 131 insertions(+), 4 deletions(-)

Please don't send cover letters for single patches, if there is any
content in them it should be in the changelog or after the --- in the
mail if it's administrative.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] regmap: debugfs: Allow writes to cache state settings
  2015-06-22 15:30 ` [PATCH 1/1] " Richard Fitzgerald
@ 2015-06-22 15:49   ` Mark Brown
  2015-06-22 16:10     ` Richard Fitzgerald
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2015-06-22 15:49 UTC (permalink / raw)
  To: Richard Fitzgerald; +Cc: gregkh, patches, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 867 bytes --]

On Mon, Jun 22, 2015 at 04:30:34PM +0100, Richard Fitzgerald wrote:

This looks basically good but:

> +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)
> +{

Can we not export read/write_file_bool() instead?  For the read this
seems to be an almost cut'n'paste with slight differences that look
like taste changes.  For the write path we can just stash the current
value in the calling functions instead of cut'n'pasting the code.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] regmap: debugfs: Allow writes to cache state settings
  2015-06-22 15:49   ` Mark Brown
@ 2015-06-22 16:10     ` Richard Fitzgerald
  2015-06-23 10:26       ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Fitzgerald @ 2015-06-22 16:10 UTC (permalink / raw)
  To: Mark Brown; +Cc: gregkh, patches, linux-kernel

On Mon, Jun 22, 2015 at 04:49:15PM +0100, Mark Brown wrote:
> On Mon, Jun 22, 2015 at 04:30:34PM +0100, Richard Fitzgerald wrote:
> 
> This looks basically good but:
> 
> > +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)
> > +{
> 
> Can we not export read/write_file_bool() instead?  For the read this
> seems to be an almost cut'n'paste with slight differences that look
> like taste changes.  For the write path we can just stash the current
> value in the calling functions instead of cut'n'pasting the code.

They assume that file->private_data points at the actual bool, and
it doesn't here, which means temporarily patching it around the call.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] regmap: debugfs: Allow writes to cache state settings
  2015-06-22 16:10     ` Richard Fitzgerald
@ 2015-06-23 10:26       ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2015-06-23 10:26 UTC (permalink / raw)
  To: Richard Fitzgerald; +Cc: gregkh, patches, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

On Mon, Jun 22, 2015 at 05:10:44PM +0100, Richard Fitzgerald wrote:
> On Mon, Jun 22, 2015 at 04:49:15PM +0100, Mark Brown wrote:

> > Can we not export read/write_file_bool() instead?  For the read this
> > seems to be an almost cut'n'paste with slight differences that look
> > like taste changes.  For the write path we can just stash the current
> > value in the calling functions instead of cut'n'pasting the code.

> They assume that file->private_data points at the actual bool, and
> it doesn't here, which means temporarily patching it around the call.

Or you could use container_of() in your wrappers for the write path.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-23 10:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 15:30 [PATCH 0/1] regmap: debugfs: Allow writes to cache state settings Richard Fitzgerald
2015-06-22 15:30 ` [PATCH 1/1] " Richard Fitzgerald
2015-06-22 15:49   ` 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

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.