linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: Michal Simek <michal.simek@xilinx.com>,
	Jolly Shah <jolly.shah@xilinx.com>,
	ard.biesheuvel@linaro.org, mingo@kernel.org,
	gregkh@linuxfoundation.org, matt@codeblueprint.co.uk,
	sudeep.holla@arm.com, hkallweit1@gmail.com,
	keescook@chromium.org, dmitry.torokhov@gmail.com
Cc: Rajan Vaja <rajan.vaja@xilinx.com>,
	rajanv@xilinx.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/5] firmware: xilinx: Adds new eemi call for reg access
Date: Wed, 18 Dec 2019 15:16:37 +0100	[thread overview]
Message-ID: <123fd714-f395-1b1f-7781-a07dc4cf223c@xilinx.com> (raw)
In-Reply-To: <a75310be-da16-8b8e-90a8-3a15ef8b735d@xilinx.com>

On 18. 12. 19 15:10, Michal Simek wrote:
> On 05. 12. 19 0:29, Jolly Shah wrote:
>> From: Rajan Vaja <rajan.vaja@xilinx.com>
>>
>> This patch adds new EEMI call which is used for CSU/PMU register
>> access from linux.
>>
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
>> Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com>
>> Signed-off-by: Jolly Shah <jolly.shah@xilinx.com>
>> ---
>>  drivers/firmware/xilinx/zynqmp.c     | 183 +++++++++++++++++++++++++++++++++++
>>  include/linux/firmware/xlnx-zynqmp.h |   9 ++
>>  2 files changed, 192 insertions(+)
>>
>> diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
>> index fd3d837..56431ad 100644
>> --- a/drivers/firmware/xilinx/zynqmp.c
>> +++ b/drivers/firmware/xilinx/zynqmp.c
>> @@ -24,6 +24,8 @@
>>  #include <linux/firmware/xlnx-zynqmp.h>
>>  #include "zynqmp-debug.h"
>>  
>> +static unsigned long register_address;
>> +
>>  static const struct zynqmp_eemi_ops *eemi_ops_tbl;
>>  
>>  static const struct mfd_cell firmware_devs[] = {
>> @@ -664,6 +666,26 @@ static int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
>>  				   qos, ack, NULL);
>>  }
>>  
>> +/**
>> + * zynqmp_pm_config_reg_access - PM Config API for Config register access
>> + * @register_access_id:	ID of the requested REGISTER_ACCESS
>> + * @address:		Address of the register to be accessed
>> + * @mask:		Mask to be written to the register
>> + * @value:		Value to be written to the register
>> + * @out:		Returned output value
>> + *
>> + * This function calls REGISTER_ACCESS to configure CSU/PMU registers.
>> + *
>> + * Return:	Returns status, either success or error+reason
>> + */
>> +
>> +static int zynqmp_pm_config_reg_access(u32 register_access_id, u32 address,
>> +				       u32 mask, u32 value, u32 *out)
>> +{
>> +	return zynqmp_pm_invoke_fn(PM_REGISTER_ACCESS, register_access_id,
>> +				   address, mask, value, out);
>> +}
>> +
>>  static const struct zynqmp_eemi_ops eemi_ops = {
>>  	.get_api_version = zynqmp_pm_get_api_version,
>>  	.get_chipid = zynqmp_pm_get_chipid,
>> @@ -687,6 +709,7 @@ static const struct zynqmp_eemi_ops eemi_ops = {
>>  	.set_requirement = zynqmp_pm_set_requirement,
>>  	.fpga_load = zynqmp_pm_fpga_load,
>>  	.fpga_get_status = zynqmp_pm_fpga_get_status,
>> +	.register_access = zynqmp_pm_config_reg_access,
>>  };
>>  
>>  /**
>> @@ -704,6 +727,160 @@ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
>>  }
>>  EXPORT_SYMBOL_GPL(zynqmp_pm_get_eemi_ops);
>>  
>> +/**
>> + * config_reg_store - Write config_reg sysfs attribute
>> + * @kobj:	Kobject structure
>> + * @attr:	Kobject attribute structure
>> + * @buf:	User entered health_status attribute string
>> + * @count:	Buffer size
>> + *
>> + * User-space interface for setting the config register.
>> + *
>> + * To write any CSU/PMU register
>> + * echo <address> <mask> <values> > /sys/firmware/zynqmp/config_reg
>> + * Usage:
>> + * echo 0x345AB234 0xFFFFFFFF 0x1234ABCD > /sys/firmware/zynqmp/config_reg
>> + *
>> + * To Read any CSU/PMU register, write address to the variable like below
>> + * echo <address> > /sys/firmware/zynqmp/config_reg
>> + *
>> + * Return:	count argument if request succeeds, the corresponding error
>> + *		code otherwise
>> + */
>> +static ssize_t config_reg_store(struct kobject *kobj,
>> +				struct kobj_attribute *attr,
>> +				const char *buf, size_t count)
>> +{
>> +	char *kern_buff, *inbuf, *tok;
>> +	unsigned long address, value, mask;
>> +	int ret;
>> +
>> +	kern_buff = kzalloc(count, GFP_KERNEL);
>> +	if (!kern_buff)
>> +		return -ENOMEM;
>> +
>> +	ret = strlcpy(kern_buff, buf, count);
>> +	if (ret < 0) {
>> +		ret = -EFAULT;
>> +		goto err;
>> +	}
> 
> Greg: What's the recommended way how to parse parameters via sysfs?
> I see that kstrndup is used for cloning buffer instead of kzalloc
> followed by strchr and sscanf.
> 
> 
>> +
>> +	inbuf = kern_buff;
>> +
>> +	/* Read the addess */
> 
> typo here.
> 
>> +	tok = strsep(&inbuf, " ");
>> +	if (!tok) {
>> +		ret = -EFAULT;
>> +		goto err;
>> +	}
>> +	ret = kstrtol(tok, 16, &address);
>> +	if (ret) {
>> +		ret = -EFAULT;
>> +		goto err;
>> +	}
>> +	/* Read the write value */
>> +	tok = strsep(&inbuf, " ");
>> +	/*
>> +	 * If parameter provided is only address, then its a read operation.
>> +	 * Store the address in a global variable and retrieve whenever
>> +	 * required.
>> +	 */
>> +	if (!tok) {
>> +		register_address = address;
>> +		goto err;
>> +	}
>> +	register_address = address;
>> +
>> +	ret = kstrtol(tok, 16, &mask);
>> +	if (ret) {
>> +		ret = -EFAULT;
>> +		goto err;
>> +	}
>> +	tok = strsep(&inbuf, " ");
>> +	if (!tok) {
>> +		ret = -EFAULT;
>> +		goto err;
>> +	}
>> +	ret = kstrtol(tok, 16, &value);
>> +	if (!tok) {
>> +		ret = -EFAULT;
>> +		goto err;
>> +	}
>> +	ret = zynqmp_pm_config_reg_access(CONFIG_REG_WRITE, address,
>> +					  mask, value, NULL);
>> +	if (ret)
>> +		pr_err("unable to write value to %lx\n", value);
>> +err:
>> +	kfree(kern_buff);
>> +	if (ret)
>> +		return ret;
>> +	return count;
>> +}
>> +
>> +/**
>> + * config_reg_show - Read config_reg sysfs attribute
>> + * @kobj:	Kobject structure
>> + * @attr:	Kobject attribute structure
>> + * @buf:	User entered health_status attribute string
>> + *
>> + * User-space interface for getting the config register.
>> + *
>> + * To Read any CSU/PMU register, write address to the variable like below
>> + * echo <address> > /sys/firmware/zynqmp/config_reg
>> + *
>> + * Then Read the address using below command
>> + * cat /sys/firmware/zynqmp/config_reg
>> + *
>> + * Return: number of chars written to buf.
>> + */
>> +static ssize_t config_reg_show(struct kobject *kobj,
>> +			       struct kobj_attribute *attr,
>> +			       char *buf)
>> +{
>> +	int ret;
>> +	u32 ret_payload[PAYLOAD_ARG_CNT];
>> +
>> +	ret = zynqmp_pm_config_reg_access(CONFIG_REG_READ, register_address,
>> +					  0, 0, ret_payload);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return sprintf(buf, "0x%x\n", ret_payload[1]);
>> +}
>> +
>> +static struct kobj_attribute zynqmp_attr_config_reg =
>> +					__ATTR_RW(config_reg);
> 
> 
> use DEVICE_ATTR_RW() instead
> 
>> +
>> +static struct attribute *attrs[] = {
>> +	&zynqmp_attr_config_reg.attr,
>> +	NULL,
>> +};
> 
>> +
>> +static const struct attribute_group attr_group = {
>> +	.attrs = attrs,
>> +	NULL,
>> +};
> 
> ATTRIBUTE_GROUPS instead.
> 
>> +
>> +static int zynqmp_pm_sysfs_init(void)
>> +{
>> +	struct kobject *zynqmp_kobj;
>> +	int ret;
>> +
>> +	zynqmp_kobj = kobject_create_and_add("zynqmp", firmware_kobj);
>> +	if (!zynqmp_kobj) {
>> +		pr_err("zynqmp: Firmware kobj add failed.\n");
>> +		return -ENOMEM;
>> +	}
>> +
>> +	ret = sysfs_create_group(zynqmp_kobj, &attr_group);
>> +	if (ret) {
>> +		pr_err("%s() sysfs creation fail with error %d\n",
>> +		       __func__, ret);
> 
> if you fail here you should free kobject_put(zynqmp_kobj);
> 
> 
>> +	}
>> +
>> +	return ret;
>> +}
>> +
>>  static int zynqmp_firmware_probe(struct platform_device *pdev)
>>  {
>>  	struct device *dev = &pdev->dev;
>> @@ -748,6 +925,12 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)
>>  	/* Assign eemi_ops_table */
>>  	eemi_ops_tbl = &eemi_ops;
>>  
>> +	ret = zynqmp_pm_sysfs_init();
>> +	if (ret) {
>> +		pr_err("%s() sysfs init fail with error %d\n", __func__, ret);
>> +		return ret;
>> +	}
>> +
>>  	zynqmp_pm_api_debugfs_init();
>>  
>>  	ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
>> diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
>> index df366f1..55561d0 100644
>> --- a/include/linux/firmware/xlnx-zynqmp.h
>> +++ b/include/linux/firmware/xlnx-zynqmp.h
>> @@ -77,6 +77,8 @@ enum pm_api_id {
>>  	PM_CLOCK_GETRATE,
>>  	PM_CLOCK_SETPARENT,
>>  	PM_CLOCK_GETPARENT,
>> +	/* PM_REGISTER_ACCESS API */
>> +	PM_REGISTER_ACCESS = 52,
>>  };
>>  
>>  /* PMU-FW return status codes */
>> @@ -261,6 +263,11 @@ enum tap_delay_type {
>>  	PM_TAPDELAY_OUTPUT,
>>  };
>>  
>> +enum pm_register_access_id {
>> +	CONFIG_REG_WRITE,
>> +	CONFIG_REG_READ,
>> +};
>> +
>>  /**
>>   * struct zynqmp_pm_query_data - PM query data
>>   * @qid:	query ID
>> @@ -305,6 +312,8 @@ struct zynqmp_eemi_ops {
>>  			       const u32 capabilities,
>>  			       const u32 qos,
>>  			       const enum zynqmp_pm_request_ack ack);
>> +	int (*register_access)(u32 register_access_id, u32 address,
>> +			       u32 mask, u32 value, u32 *out);
>>  };
>>  
>>  int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 arg0, u32 arg1,
>>
> 

One more thing. I am missing sysfs description for these entries.
You are creating this file in 2/5 but files introduced here are not
cover there.

Thanks,
Michal


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-12-18 14:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-04 23:29 [PATCH 0/5] firmware: xilinx: Add xilinx specific sysfs interface Jolly Shah
2019-12-04 23:29 ` [PATCH 1/5] firmware: xilinx: Adds new eemi call for reg access Jolly Shah
2019-12-18 14:10   ` Michal Simek
2019-12-18 14:16     ` Michal Simek [this message]
2019-12-18 14:55   ` Sudeep Holla
2019-12-04 23:29 ` [PATCH 2/5] firmware: xilinx: Add sysfs interface Jolly Shah
2019-12-18 14:21   ` Michal Simek
2019-12-04 23:29 ` [PATCH 3/5] firmware: xilinx: Add system shutdown API interface Jolly Shah
2019-12-18 14:24   ` Michal Simek
2019-12-04 23:29 ` [PATCH 4/5] firmware: xilinx: Add sysfs to set shutdown scope Jolly Shah
2019-12-18 14:25   ` Michal Simek
2019-12-04 23:29 ` [PATCH 5/5] firmware: xilinx: Add sysfs and IOCTL to set boot health status Jolly Shah
2019-12-18 14:28   ` Michal Simek
2019-12-18 14:45 ` [PATCH 0/5] firmware: xilinx: Add xilinx specific sysfs interface Sudeep Holla
2020-01-02 21:01   ` Jolly Shah
2020-01-03 11:31     ` Sudeep Holla

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=123fd714-f395-1b1f-7781-a07dc4cf223c@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkallweit1@gmail.com \
    --cc=jolly.shah@xilinx.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=rajan.vaja@xilinx.com \
    --cc=rajanv@xilinx.com \
    --cc=sudeep.holla@arm.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 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).