linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: Add support for enabling/disabling clocks from debugfs
@ 2020-06-30  0:30 Mike Tipton
  2020-07-21  2:30 ` Mike Tipton
  2020-07-24  9:06 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Mike Tipton @ 2020-06-30  0:30 UTC (permalink / raw)
  To: sboyd, mturquette; +Cc: linux-clk, linux-kernel, tdas, Mike Tipton

For test and debug purposes, it's often necessary to enable or disable
clocks from shell. Add a new debugfs file (clk_prepare_enable) that
calls clk_prepare_enable() when writing "1" and clk_disable_unprepare()
when writing "0".

This can have security implications, so only support it when the code
has been modified to #define CLOCK_ALLOW_WRITE_DEBUGS.

Signed-off-by: Mike Tipton <mdtipton@codeaurora.org>
---
 drivers/clk/clk.c | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 236923b25543..3640bbc56870 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3034,13 +3034,14 @@ static int clk_dump_show(struct seq_file *s, void *data)
 }
 DEFINE_SHOW_ATTRIBUTE(clk_dump);
 
-#undef CLOCK_ALLOW_WRITE_DEBUGFS
-#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
 /*
- * This can be dangerous, therefore don't provide any real compile time
- * configuration option for this feature.
+ * These features can be dangerous, therefore don't provide any real compile
+ * time configuration option for them.
  * People who want to use this will need to modify the source code directly.
  */
+#undef CLOCK_ALLOW_WRITE_DEBUGFS
+#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
+
 static int clk_rate_set(void *data, u64 val)
 {
 	struct clk_core *core = data;
@@ -3054,6 +3055,31 @@ static int clk_rate_set(void *data, u64 val)
 }
 
 #define clk_rate_mode	0644
+
+static int clk_prepare_enable_set(void *data, u64 val)
+{
+	struct clk_core *core = data;
+	int ret = 0;
+
+	if (val)
+		ret = clk_prepare_enable(core->hw->clk);
+	else
+		clk_disable_unprepare(core->hw->clk);
+
+	return ret;
+}
+
+static int clk_prepare_enable_get(void *data, u64 *val)
+{
+	struct clk_core *core = data;
+
+	*val = core->enable_count && core->prepare_count;
+	return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get,
+			 clk_prepare_enable_set, "%llu\n");
+
 #else
 #define clk_rate_set	NULL
 #define clk_rate_mode	0444
@@ -3231,6 +3257,10 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
 	debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count);
 	debugfs_create_file("clk_duty_cycle", 0444, root, core,
 			    &clk_duty_cycle_fops);
+#ifdef CLOCK_ALLOW_WRITE_DEBUGFS
+	debugfs_create_file("clk_prepare_enable", 0644, root, core,
+			    &clk_prepare_enable_fops);
+#endif
 
 	if (core->num_parents > 0)
 		debugfs_create_file("clk_parent", 0444, root, core,
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

* Re: [PATCH] clk: Add support for enabling/disabling clocks from debugfs
  2020-06-30  0:30 [PATCH] clk: Add support for enabling/disabling clocks from debugfs Mike Tipton
@ 2020-07-21  2:30 ` Mike Tipton
  2020-07-24  9:06 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Tipton @ 2020-07-21  2:30 UTC (permalink / raw)
  To: sboyd, mturquette; +Cc: linux-clk, linux-kernel, tdas

On 6/29/2020 5:30 PM, Mike Tipton wrote:
> For test and debug purposes, it's often necessary to enable or disable
> clocks from shell. Add a new debugfs file (clk_prepare_enable) that
> calls clk_prepare_enable() when writing "1" and clk_disable_unprepare()
> when writing "0".
> 
> This can have security implications, so only support it when the code
> has been modified to #define CLOCK_ALLOW_WRITE_DEBUGS.
> 
> Signed-off-by: Mike Tipton <mdtipton@codeaurora.org>
> ---
>   drivers/clk/clk.c | 38 ++++++++++++++++++++++++++++++++++----
>   1 file changed, 34 insertions(+), 4 deletions(-)
> 

Friendly reminder.

Thanks,
Mike

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

* Re: [PATCH] clk: Add support for enabling/disabling clocks from debugfs
  2020-06-30  0:30 [PATCH] clk: Add support for enabling/disabling clocks from debugfs Mike Tipton
  2020-07-21  2:30 ` Mike Tipton
@ 2020-07-24  9:06 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-07-24  9:06 UTC (permalink / raw)
  To: Mike Tipton, mturquette; +Cc: linux-clk, linux-kernel, tdas, Mike Tipton

Quoting Mike Tipton (2020-06-29 17:30:24)
> For test and debug purposes, it's often necessary to enable or disable
> clocks from shell. Add a new debugfs file (clk_prepare_enable) that
> calls clk_prepare_enable() when writing "1" and clk_disable_unprepare()
> when writing "0".
> 
> This can have security implications, so only support it when the code
> has been modified to #define CLOCK_ALLOW_WRITE_DEBUGS.

DEBUGFS

> 
> Signed-off-by: Mike Tipton <mdtipton@codeaurora.org>
> ---
>  drivers/clk/clk.c | 38 ++++++++++++++++++++++++++++++++++----
>  1 file changed, 34 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 236923b25543..3640bbc56870 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3034,13 +3034,14 @@ static int clk_dump_show(struct seq_file *s, void *data)
>  }
>  DEFINE_SHOW_ATTRIBUTE(clk_dump);
>  
> -#undef CLOCK_ALLOW_WRITE_DEBUGFS
> -#ifdef CLOCK_ALLOW_WRITE_DEBUGFS

This didn't need to change.

>  /*
> - * This can be dangerous, therefore don't provide any real compile time
> - * configuration option for this feature.
> + * These features can be dangerous, therefore don't provide any real compile
> + * time configuration option for them.
>   * People who want to use this will need to modify the source code directly.
>   */
> +#undef CLOCK_ALLOW_WRITE_DEBUGFS
> +#ifdef CLOCK_ALLOW_WRITE_DEBUGFS

So I put it back and dropped your rewording.

> +
>  static int clk_rate_set(void *data, u64 val)
>  {
>         struct clk_core *core = data;
> @@ -3054,6 +3055,31 @@ static int clk_rate_set(void *data, u64 val)
>  }
>  
>  #define clk_rate_mode  0644
> +
> +static int clk_prepare_enable_set(void *data, u64 val)
> +{
> +       struct clk_core *core = data;
> +       int ret = 0;
> +
> +       if (val)
> +               ret = clk_prepare_enable(core->hw->clk);
> +       else
> +               clk_disable_unprepare(core->hw->clk);
> +
> +       return ret;
> +}
> +
> +static int clk_prepare_enable_get(void *data, u64 *val)
> +{
> +       struct clk_core *core = data;
> +
> +       *val = core->enable_count && core->prepare_count;
> +       return 0;
> +}
> +
> +DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get,
> +                        clk_prepare_enable_set, "%llu\n");
> +
>  #else
>  #define clk_rate_set   NULL
>  #define clk_rate_mode  0444
> @@ -3231,6 +3257,10 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
>         debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count);
>         debugfs_create_file("clk_duty_cycle", 0444, root, core,
>                             &clk_duty_cycle_fops);
> +#ifdef CLOCK_ALLOW_WRITE_DEBUGFS

This is ugly but I guess we can't do much.

> +       debugfs_create_file("clk_prepare_enable", 0644, root, core,
> +                           &clk_prepare_enable_fops);
> +#endif
>  

Applied to clk-next.

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

end of thread, other threads:[~2020-07-24  9:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30  0:30 [PATCH] clk: Add support for enabling/disabling clocks from debugfs Mike Tipton
2020-07-21  2:30 ` Mike Tipton
2020-07-24  9:06 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).