diff mbox series

[V7,2/2] soc: qcom: aoss: Add debugfs entry

Message ID 1630323451-7160-3-git-send-email-deesin@codeaurora.org (mailing list archive)
State Superseded
Headers show
Series qcom aoss qmp_get and debugfs support patches | expand

Commit Message

Deepak Kumar Singh Aug. 30, 2021, 11:37 a.m. UTC
Some user space clients may require to change power states of various
parts of hardware. Add a debugfs node for qmp so messages can be sent
to aoss from user space.

Signed-off-by: Chris Lew <clew@codeaurora.org>
Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
---
 drivers/soc/qcom/qcom_aoss.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Stephen Boyd Aug. 30, 2021, 11:02 p.m. UTC | #1
Quoting Deepak Kumar Singh (2021-08-30 04:37:31)
> Some user space clients may require to change power states of various
> parts of hardware. Add a debugfs node for qmp so messages can be sent
> to aoss from user space.
>
> Signed-off-by: Chris Lew <clew@codeaurora.org>
> Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
> ---

NAK. We don't want userspace to treat debugfs as an ABI. See
https://lore.kernel.org/r/CAE-0n52YXvTzvK4B3Aggg1fcRyjy=+HzNADP315-J0iJ8bMWUQ@mail.gmail.com
Bjorn Andersson Aug. 30, 2021, 11:18 p.m. UTC | #2
On Mon 30 Aug 06:37 CDT 2021, Deepak Kumar Singh wrote:

> Some user space clients may require to change power states of various
> parts of hardware. Add a debugfs node for qmp so messages can be sent
> to aoss from user space.
> 

I think this could be a useful tool while testing and developing client
drivers or perhaps during bringup of new platforms.

But your new commit message doesn't sound right, given that debugfs
isn't mounted in your production builds.

Regards,
Bjorn

> Signed-off-by: Chris Lew <clew@codeaurora.org>
> Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
> ---
>  drivers/soc/qcom/qcom_aoss.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c
> index bf0a6280..4cd8670 100644
> --- a/drivers/soc/qcom/qcom_aoss.c
> +++ b/drivers/soc/qcom/qcom_aoss.c
> @@ -4,6 +4,7 @@
>   */
>  #include <dt-bindings/power/qcom-aoss-qmp.h>
>  #include <linux/clk-provider.h>
> +#include <linux/debugfs.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
>  #include <linux/mailbox_client.h>
> @@ -86,6 +87,7 @@ struct qmp {
>  	struct clk_hw qdss_clk;
>  	struct genpd_onecell_data pd_data;
>  	struct qmp_cooling_device *cooling_devs;
> +	struct dentry *debugfs_file;
>  };
>  
>  struct qmp_pd {
> @@ -566,6 +568,31 @@ void qmp_put(struct qmp *qmp)
>  }
>  EXPORT_SYMBOL(qmp_put);
>  
> +static ssize_t aoss_dbg_write(struct file *file, const char __user *userstr,
> +			      size_t len, loff_t *pos)
> +{
> +	struct qmp *qmp = file->private_data;
> +	char buf[QMP_MSG_LEN] = {};
> +	int ret;
> +
> +	if (!len || len >= QMP_MSG_LEN)
> +		return -EINVAL;
> +
> +	ret  = copy_from_user(buf, userstr, len);
> +	if (ret) {
> +		return -EFAULT;
> +	}
> +
> +	ret = qmp_send(qmp, buf, QMP_MSG_LEN);
> +
> +	return ret ? ret : len;
> +}
> +
> +static const struct file_operations aoss_dbg_fops = {
> +	.open = simple_open,
> +	.write = aoss_dbg_write,
> +};
> +
>  static int qmp_probe(struct platform_device *pdev)
>  {
>  	struct resource *res;
> @@ -620,6 +647,9 @@ static int qmp_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, qmp);
>  
> +	qmp->debugfs_file = debugfs_create_file("aoss_send_message", 0220, NULL,
> +						qmp, &aoss_dbg_fops);
> +
>  	return 0;
>  
>  err_remove_qdss_clk:
> @@ -636,6 +666,8 @@ static int qmp_remove(struct platform_device *pdev)
>  {
>  	struct qmp *qmp = platform_get_drvdata(pdev);
>  
> +	debugfs_remove(qmp->debugfs_file);
> +
>  	qmp_qdss_clk_remove(qmp);
>  	qmp_pd_remove(qmp);
>  	qmp_cooling_devices_remove(qmp);
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
Deepak Kumar Singh Aug. 31, 2021, 2:33 p.m. UTC | #3
On 8/31/2021 4:48 AM, Bjorn Andersson wrote:
> On Mon 30 Aug 06:37 CDT 2021, Deepak Kumar Singh wrote:
>
>> Some user space clients may require to change power states of various
>> parts of hardware. Add a debugfs node for qmp so messages can be sent
>> to aoss from user space.
>>
> I think this could be a useful tool while testing and developing client
> drivers or perhaps during bringup of new platforms.
>
> But your new commit message doesn't sound right, given that debugfs
> isn't mounted in your production builds.
>
> Regards,
> Bjorn
Updated commit message in V8.
>
>> Signed-off-by: Chris Lew <clew@codeaurora.org>
>> Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
>> ---
>>   drivers/soc/qcom/qcom_aoss.c | 32 ++++++++++++++++++++++++++++++++
>>   1 file changed, 32 insertions(+)
>>
>> diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c
>> index bf0a6280..4cd8670 100644
>> --- a/drivers/soc/qcom/qcom_aoss.c
>> +++ b/drivers/soc/qcom/qcom_aoss.c
>> @@ -4,6 +4,7 @@
>>    */
>>   #include <dt-bindings/power/qcom-aoss-qmp.h>
>>   #include <linux/clk-provider.h>
>> +#include <linux/debugfs.h>
>>   #include <linux/interrupt.h>
>>   #include <linux/io.h>
>>   #include <linux/mailbox_client.h>
>> @@ -86,6 +87,7 @@ struct qmp {
>>   	struct clk_hw qdss_clk;
>>   	struct genpd_onecell_data pd_data;
>>   	struct qmp_cooling_device *cooling_devs;
>> +	struct dentry *debugfs_file;
>>   };
>>   
>>   struct qmp_pd {
>> @@ -566,6 +568,31 @@ void qmp_put(struct qmp *qmp)
>>   }
>>   EXPORT_SYMBOL(qmp_put);
>>   
>> +static ssize_t aoss_dbg_write(struct file *file, const char __user *userstr,
>> +			      size_t len, loff_t *pos)
>> +{
>> +	struct qmp *qmp = file->private_data;
>> +	char buf[QMP_MSG_LEN] = {};
>> +	int ret;
>> +
>> +	if (!len || len >= QMP_MSG_LEN)
>> +		return -EINVAL;
>> +
>> +	ret  = copy_from_user(buf, userstr, len);
>> +	if (ret) {
>> +		return -EFAULT;
>> +	}
>> +
>> +	ret = qmp_send(qmp, buf, QMP_MSG_LEN);
>> +
>> +	return ret ? ret : len;
>> +}
>> +
>> +static const struct file_operations aoss_dbg_fops = {
>> +	.open = simple_open,
>> +	.write = aoss_dbg_write,
>> +};
>> +
>>   static int qmp_probe(struct platform_device *pdev)
>>   {
>>   	struct resource *res;
>> @@ -620,6 +647,9 @@ static int qmp_probe(struct platform_device *pdev)
>>   
>>   	platform_set_drvdata(pdev, qmp);
>>   
>> +	qmp->debugfs_file = debugfs_create_file("aoss_send_message", 0220, NULL,
>> +						qmp, &aoss_dbg_fops);
>> +
>>   	return 0;
>>   
>>   err_remove_qdss_clk:
>> @@ -636,6 +666,8 @@ static int qmp_remove(struct platform_device *pdev)
>>   {
>>   	struct qmp *qmp = platform_get_drvdata(pdev);
>>   
>> +	debugfs_remove(qmp->debugfs_file);
>> +
>>   	qmp_qdss_clk_remove(qmp);
>>   	qmp_pd_remove(qmp);
>>   	qmp_cooling_devices_remove(qmp);
>> -- 
>> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
>> a Linux Foundation Collaborative Project
>>
diff mbox series

Patch

diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c
index bf0a6280..4cd8670 100644
--- a/drivers/soc/qcom/qcom_aoss.c
+++ b/drivers/soc/qcom/qcom_aoss.c
@@ -4,6 +4,7 @@ 
  */
 #include <dt-bindings/power/qcom-aoss-qmp.h>
 #include <linux/clk-provider.h>
+#include <linux/debugfs.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/mailbox_client.h>
@@ -86,6 +87,7 @@  struct qmp {
 	struct clk_hw qdss_clk;
 	struct genpd_onecell_data pd_data;
 	struct qmp_cooling_device *cooling_devs;
+	struct dentry *debugfs_file;
 };
 
 struct qmp_pd {
@@ -566,6 +568,31 @@  void qmp_put(struct qmp *qmp)
 }
 EXPORT_SYMBOL(qmp_put);
 
+static ssize_t aoss_dbg_write(struct file *file, const char __user *userstr,
+			      size_t len, loff_t *pos)
+{
+	struct qmp *qmp = file->private_data;
+	char buf[QMP_MSG_LEN] = {};
+	int ret;
+
+	if (!len || len >= QMP_MSG_LEN)
+		return -EINVAL;
+
+	ret  = copy_from_user(buf, userstr, len);
+	if (ret) {
+		return -EFAULT;
+	}
+
+	ret = qmp_send(qmp, buf, QMP_MSG_LEN);
+
+	return ret ? ret : len;
+}
+
+static const struct file_operations aoss_dbg_fops = {
+	.open = simple_open,
+	.write = aoss_dbg_write,
+};
+
 static int qmp_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -620,6 +647,9 @@  static int qmp_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, qmp);
 
+	qmp->debugfs_file = debugfs_create_file("aoss_send_message", 0220, NULL,
+						qmp, &aoss_dbg_fops);
+
 	return 0;
 
 err_remove_qdss_clk:
@@ -636,6 +666,8 @@  static int qmp_remove(struct platform_device *pdev)
 {
 	struct qmp *qmp = platform_get_drvdata(pdev);
 
+	debugfs_remove(qmp->debugfs_file);
+
 	qmp_qdss_clk_remove(qmp);
 	qmp_pd_remove(qmp);
 	qmp_cooling_devices_remove(qmp);