linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
@ 2024-01-18  2:31 Bjorn Andersson
  2024-01-19 13:43 ` Andrew Lunn
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Bjorn Andersson @ 2024-01-18  2:31 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio
  Cc: linux-arm-msm, linux-kernel, Andrew Lunn, Stephen Hemminger,
	Bjorn Andersson

In addition to the normal runtime commands, the Always On Processor
(AOP) provides a number of debug commands which can be used during
system debugging for things such as preventing power collapse or placing
floor votes for certain resources. Some of these are documented in the
Robotics RB5 "Debug AOP ADB" linked below.

Provide a debugfs interface for the developer/tester to send some of
these commands to the AOP, which allow the user to override the DDR
frequency, preventing power collapse of cx and ddr, and prevent AOSS
from going to sleep.

Link: https://docs.qualcomm.com/bundle/publicresource/topics/80-88500-3/85_Debugging_AOP_ADB.html
Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
---
Changes in v3:
- Stop passing command string straight from userspace to the firmware
- Format the commands in the driver instead
- Provide a few useful commands
- Link to v2: https://lore.kernel.org/linux-arm-msm/20230811205839.727373-3-quic_bjorande@quicinc.com/
---
 drivers/soc/qcom/qcom_aoss.c | 94 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c
index aff0cfb71482..30c7d59d3424 100644
--- a/drivers/soc/qcom/qcom_aoss.c
+++ b/drivers/soc/qcom/qcom_aoss.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2019, Linaro Ltd
  */
 #include <linux/clk-provider.h>
+#include <linux/debugfs.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/mailbox_client.h>
@@ -44,6 +45,8 @@
 
 #define QMP_NUM_COOLING_RESOURCES	2
 
+#define QMP_DEBUGFS_FILES		4
+
 static bool qmp_cdev_max_state = 1;
 
 struct qmp_cooling_device {
@@ -82,6 +85,8 @@ struct qmp {
 
 	struct clk_hw qdss_clk;
 	struct qmp_cooling_device *cooling_devs;
+	struct dentry *debugfs_root;
+	struct dentry *debugfs_files[QMP_DEBUGFS_FILES];
 };
 
 static void qmp_kick(struct qmp *qmp)
@@ -475,6 +480,91 @@ void qmp_put(struct qmp *qmp)
 }
 EXPORT_SYMBOL_GPL(qmp_put);
 
+struct qmp_debugfs_entry {
+	const char *name;
+	const char *fmt;
+	bool is_bool;
+	const char *true_val;
+	const char *false_val;
+};
+
+static const struct qmp_debugfs_entry qmp_debugfs_entries[QMP_DEBUGFS_FILES] = {
+	{ "ddr_frequency_mhz", "{class: ddr, res: fixed, val: %u}", false },
+	{ "prevent_aoss_sleep", "{class: aoss_slp, res: sleep: %s}", true, "enable", "disable" },
+	{ "prevent_cx_collapse", "{class: cx_mol, res: cx, val: %s}", true, "mol", "off" },
+	{ "prevent_ddr_collapse", "{class: ddr_mol, res: ddr, val: %s}", true, "mol", "off" },
+};
+
+static ssize_t qmp_debugfs_write(struct file *file, const char __user *user_buf,
+				 size_t count, loff_t *pos)
+{
+	const struct qmp_debugfs_entry *entry = NULL;
+	struct qmp *qmp = file->private_data;
+	char buf[QMP_MSG_LEN];
+	unsigned int uint_val;
+	const char *str_val;
+	bool bool_val;
+	int ret;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(qmp->debugfs_files); i++) {
+		if (qmp->debugfs_files[i] == file->f_path.dentry) {
+			entry = &qmp_debugfs_entries[i];
+			break;
+		}
+	}
+	if (WARN_ON(!entry))
+		return -EFAULT;
+
+	if (entry->is_bool) {
+		ret = kstrtobool_from_user(user_buf, count, &bool_val);
+		if (ret)
+			return ret;
+
+		str_val = bool_val ? entry->true_val : entry->false_val;
+
+		ret = snprintf(buf, sizeof(buf), entry->fmt, str_val);
+		if (ret >= sizeof(buf))
+			return -EINVAL;
+	} else {
+		ret = kstrtou32_from_user(user_buf, count, 0, &uint_val);
+		if (ret)
+			return ret;
+
+		ret = snprintf(buf, sizeof(buf), entry->fmt, uint_val);
+		if (ret >= sizeof(buf))
+			return -EINVAL;
+	}
+
+	ret = qmp_send(qmp, buf);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+
+static const struct file_operations qmp_debugfs_fops = {
+	.open = simple_open,
+	.write = qmp_debugfs_write,
+};
+
+static void qmp_debugfs_create(struct qmp *qmp)
+{
+	const struct qmp_debugfs_entry *entry;
+	int i;
+
+	qmp->debugfs_root = debugfs_create_dir("qcom_aoss", NULL);
+
+	for (i = 0; i < ARRAY_SIZE(qmp->debugfs_files); i++) {
+		entry = &qmp_debugfs_entries[i];
+
+		qmp->debugfs_files[i] = debugfs_create_file(entry->name, 0220,
+							    qmp->debugfs_root,
+							    qmp,
+							    &qmp_debugfs_fops);
+	}
+}
+
 static int qmp_probe(struct platform_device *pdev)
 {
 	struct qmp *qmp;
@@ -523,6 +613,8 @@ static int qmp_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, qmp);
 
+	qmp_debugfs_create(qmp);
+
 	return 0;
 
 err_close_qmp:
@@ -537,6 +629,8 @@ static void qmp_remove(struct platform_device *pdev)
 {
 	struct qmp *qmp = platform_get_drvdata(pdev);
 
+	debugfs_remove_recursive(qmp->debugfs_root);
+
 	qmp_qdss_clk_remove(qmp);
 	qmp_cooling_devices_remove(qmp);
 

---
base-commit: 943b9f0ab2cfbaea148dd6ac279957eb08b96904
change-id: 20240117-qcom-aoss-debugfs-v2-5e25b1934e19

Best regards,
-- 
Bjorn Andersson <quic_bjorande@quicinc.com>


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

* Re: [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
  2024-01-18  2:31 [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages Bjorn Andersson
@ 2024-01-19 13:43 ` Andrew Lunn
  2024-01-22 10:44 ` Konrad Dybcio
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2024-01-19 13:43 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Bjorn Andersson, Konrad Dybcio, linux-arm-msm, linux-kernel,
	Stephen Hemminger

> +static void qmp_debugfs_create(struct qmp *qmp)
> +{
> +	const struct qmp_debugfs_entry *entry;
> +	int i;
> +
> +	qmp->debugfs_root = debugfs_create_dir("qcom_aoss", NULL);
> +
> +	for (i = 0; i < ARRAY_SIZE(qmp->debugfs_files); i++) {
> +		entry = &qmp_debugfs_entries[i];
> +
> +		qmp->debugfs_files[i] = debugfs_create_file(entry->name, 0220,

group write? Generally you only want root able to do writes.

However, thanks for reworking this to just support some well defined
commands, rather than binary blobs from user space.

      Andrew

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

* Re: [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
  2024-01-18  2:31 [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages Bjorn Andersson
  2024-01-19 13:43 ` Andrew Lunn
@ 2024-01-22 10:44 ` Konrad Dybcio
  2024-01-23  0:29   ` Bjorn Andersson
  2024-01-27  1:35 ` Chris Lew
  2024-01-28 17:45 ` Bjorn Andersson
  3 siblings, 1 reply; 7+ messages in thread
From: Konrad Dybcio @ 2024-01-22 10:44 UTC (permalink / raw)
  To: Bjorn Andersson, Bjorn Andersson
  Cc: linux-arm-msm, linux-kernel, Andrew Lunn, Stephen Hemminger

On 18.01.2024 03:31, Bjorn Andersson wrote:
> In addition to the normal runtime commands, the Always On Processor
> (AOP) provides a number of debug commands which can be used during
> system debugging for things such as preventing power collapse or placing
> floor votes for certain resources. Some of these are documented in the
> Robotics RB5 "Debug AOP ADB" linked below.
> 
> Provide a debugfs interface for the developer/tester to send some of
> these commands to the AOP, which allow the user to override the DDR
> frequency, preventing power collapse of cx and ddr, and prevent AOSS
> from going to sleep.
> 
> Link: https://docs.qualcomm.com/bundle/publicresource/topics/80-88500-3/85_Debugging_AOP_ADB.html
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> ---

[...]

>  
> +struct qmp_debugfs_entry {
> +	const char *name;
> +	const char *fmt;
> +	bool is_bool;

This can also be const

> +	const char *true_val;
> +	const char *false_val;

All of these strings can be const ptrs to const data

Konrad

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

* Re: [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
  2024-01-22 10:44 ` Konrad Dybcio
@ 2024-01-23  0:29   ` Bjorn Andersson
  2024-01-23 18:37     ` Konrad Dybcio
  0 siblings, 1 reply; 7+ messages in thread
From: Bjorn Andersson @ 2024-01-23  0:29 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Bjorn Andersson, linux-arm-msm, linux-kernel, Andrew Lunn,
	Stephen Hemminger

On Mon, Jan 22, 2024 at 11:44:30AM +0100, Konrad Dybcio wrote:
> On 18.01.2024 03:31, Bjorn Andersson wrote:
> > In addition to the normal runtime commands, the Always On Processor
> > (AOP) provides a number of debug commands which can be used during
> > system debugging for things such as preventing power collapse or placing
> > floor votes for certain resources. Some of these are documented in the
> > Robotics RB5 "Debug AOP ADB" linked below.
> > 
> > Provide a debugfs interface for the developer/tester to send some of
> > these commands to the AOP, which allow the user to override the DDR
> > frequency, preventing power collapse of cx and ddr, and prevent AOSS
> > from going to sleep.
> > 
> > Link: https://docs.qualcomm.com/bundle/publicresource/topics/80-88500-3/85_Debugging_AOP_ADB.html
> > Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> > ---
> 
> [...]
> 
> >  
> > +struct qmp_debugfs_entry {
> > +	const char *name;
> > +	const char *fmt;
> > +	bool is_bool;
> 
> This can also be const
> 
> > +	const char *true_val;
> > +	const char *false_val;
> 
> All of these strings can be const ptrs to const data
> 

These are all const data now, but what would the reason for enforcing it
in the struct definition be?

Regards,
Bjorn

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

* Re: [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
  2024-01-23  0:29   ` Bjorn Andersson
@ 2024-01-23 18:37     ` Konrad Dybcio
  0 siblings, 0 replies; 7+ messages in thread
From: Konrad Dybcio @ 2024-01-23 18:37 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Bjorn Andersson, linux-arm-msm, linux-kernel, Andrew Lunn,
	Stephen Hemminger



On 1/23/24 01:29, Bjorn Andersson wrote:
> On Mon, Jan 22, 2024 at 11:44:30AM +0100, Konrad Dybcio wrote:
>> On 18.01.2024 03:31, Bjorn Andersson wrote:
>>> In addition to the normal runtime commands, the Always On Processor
>>> (AOP) provides a number of debug commands which can be used during
>>> system debugging for things such as preventing power collapse or placing
>>> floor votes for certain resources. Some of these are documented in the
>>> Robotics RB5 "Debug AOP ADB" linked below.
>>>
>>> Provide a debugfs interface for the developer/tester to send some of
>>> these commands to the AOP, which allow the user to override the DDR
>>> frequency, preventing power collapse of cx and ddr, and prevent AOSS
>>> from going to sleep.
>>>
>>> Link: https://docs.qualcomm.com/bundle/publicresource/topics/80-88500-3/85_Debugging_AOP_ADB.html
>>> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
>>> ---
>>
>> [...]
>>
>>>   
>>> +struct qmp_debugfs_entry {
>>> +	const char *name;
>>> +	const char *fmt;
>>> +	bool is_bool;
>>
>> This can also be const
>>
>>> +	const char *true_val;
>>> +	const char *false_val;
>>
>> All of these strings can be const ptrs to const data
>>
> 
> These are all const data now, but what would the reason for enforcing it
> in the struct definition be?

I've just written too much rust lately and I'm simply paranoid
about mutability, it seems ;)

Konrad

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

* Re: [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
  2024-01-18  2:31 [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages Bjorn Andersson
  2024-01-19 13:43 ` Andrew Lunn
  2024-01-22 10:44 ` Konrad Dybcio
@ 2024-01-27  1:35 ` Chris Lew
  2024-01-28 17:45 ` Bjorn Andersson
  3 siblings, 0 replies; 7+ messages in thread
From: Chris Lew @ 2024-01-27  1:35 UTC (permalink / raw)
  To: Bjorn Andersson, Bjorn Andersson, Konrad Dybcio
  Cc: linux-arm-msm, linux-kernel, Andrew Lunn, Stephen Hemminger



On 1/17/2024 6:31 PM, Bjorn Andersson wrote:
> In addition to the normal runtime commands, the Always On Processor
> (AOP) provides a number of debug commands which can be used during
> system debugging for things such as preventing power collapse or placing
> floor votes for certain resources. Some of these are documented in the
> Robotics RB5 "Debug AOP ADB" linked below.
> 
> Provide a debugfs interface for the developer/tester to send some of
> these commands to the AOP, which allow the user to override the DDR
> frequency, preventing power collapse of cx and ddr, and prevent AOSS
> from going to sleep.
> 
> Link: https://docs.qualcomm.com/bundle/publicresource/topics/80-88500-3/85_Debugging_AOP_ADB.html
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> ---
> Changes in v3:
> - Stop passing command string straight from userspace to the firmware
> - Format the commands in the driver instead
> - Provide a few useful commands
> - Link to v2: https://lore.kernel.org/linux-arm-msm/20230811205839.727373-3-quic_bjorande@quicinc.com/
> ---
> +		qmp->debugfs_files[i] = debugfs_create_file(entry->name, 0220,
> +							    qmp->debugfs_root,
> +							    qmp,
> +							    &qmp_debugfs_fops);

With group permissions fixed:

Reviewed-by: Chris Lew <quic_clew@quicinc.com>

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

* Re: [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages
  2024-01-18  2:31 [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages Bjorn Andersson
                   ` (2 preceding siblings ...)
  2024-01-27  1:35 ` Chris Lew
@ 2024-01-28 17:45 ` Bjorn Andersson
  3 siblings, 0 replies; 7+ messages in thread
From: Bjorn Andersson @ 2024-01-28 17:45 UTC (permalink / raw)
  To: Konrad Dybcio, Bjorn Andersson
  Cc: linux-arm-msm, linux-kernel, Andrew Lunn, Stephen Hemminger


On Wed, 17 Jan 2024 18:31:52 -0800, Bjorn Andersson wrote:
> In addition to the normal runtime commands, the Always On Processor
> (AOP) provides a number of debug commands which can be used during
> system debugging for things such as preventing power collapse or placing
> floor votes for certain resources. Some of these are documented in the
> Robotics RB5 "Debug AOP ADB" linked below.
> 
> Provide a debugfs interface for the developer/tester to send some of
> these commands to the AOP, which allow the user to override the DDR
> frequency, preventing power collapse of cx and ddr, and prevent AOSS
> from going to sleep.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: aoss: Add debugfs interface for sending messages
      commit: d51d984c5525aebac0f90356ab1d923541b5cc60

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

end of thread, other threads:[~2024-01-28 17:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18  2:31 [PATCH v3] soc: qcom: aoss: Add debugfs interface for sending messages Bjorn Andersson
2024-01-19 13:43 ` Andrew Lunn
2024-01-22 10:44 ` Konrad Dybcio
2024-01-23  0:29   ` Bjorn Andersson
2024-01-23 18:37     ` Konrad Dybcio
2024-01-27  1:35 ` Chris Lew
2024-01-28 17:45 ` Bjorn Andersson

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).