Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-21 Thread Ben Levinsky
Hi Mathieu

-Original Message-
From: Mathieu Poirier 
Date: Wednesday, March 17, 2021 at 9:27 AM
To: Ben Levinsky 
Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek , "Ed T. Mooring" 
Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

On Mon, Mar 15, 2021 at 09:32:40PM +, Ben Levinsky wrote:
> 
> 
> -Original Message-
> From: Mathieu Poirier 
> Date: Monday, March 15, 2021 at 10:37 AM
> To: Ben Levinsky 
> Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek , "Ed T. Mooring" 
> Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc 
driver
> 
> On Thu, Mar 11, 2021 at 11:49:13PM +, Ben Levinsky wrote:
> > Hi Mathieu
> > 
> > -Original Message-
> > From: Mathieu Poirier 
> > Date: Tuesday, March 9, 2021 at 8:53 AM
> > To: Ben Levinsky 
> > Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek 
> > Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 
remoteproc driver
> > 
> > [...]
> > 
> > > +
> > > +/**
> > > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > > + *  this is called for each individual R5 
core to
> > > + *  set up mailbox, Xilinx platform manager 
unique ID,
> > > + *  add to rproc core
> > > + *
> > > + * @pdev: domain platform device for current R5 core
> > > + * @node: pointer of the device node for current R5 core
> > > + * @rpu_mode: mode to configure RPU, split or lockstep
> > > + *
> > > + * Return: 0 for success, negative value for failure.
> > > + */
> > > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct 
platform_device *pdev,
> > > +struct 
device_node *node,
> > > +enum 
rpu_oper_mode rpu_mode)
> > > +{
> > > + int ret, num_banks;
> > > + struct device *dev = &pdev->dev;
> > > + struct rproc *rproc_ptr;
> > > + struct zynqmp_r5_rproc *z_rproc;
> > > + struct device_node *r5_node;
> > > +
> > > + /* Allocate remoteproc instance */
> > > + rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
&zynqmp_r5_rproc_ops,
> > > +  NULL, sizeof(struct 
zynqmp_r5_rproc));
> > > + if (!rproc_ptr) {
> > > + ret = -ENOMEM;
> > > + goto error;
> > > + }
> > > +
> > > + rproc_ptr->auto_boot = false;
> > > + z_rproc = rproc_ptr->priv;
> > > + z_rproc->rproc = rproc_ptr;
> > > + r5_node = z_rproc->rproc->dev.parent->of_node;
> > > +
> > > + /* Set up DMA mask */
> > > + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> > > + if (ret)
> > > + goto error;
> > > +
> > > + /* Get R5 power domain node */
> > > + ret = of_property_read_u32(node, "power-domain", 
&z_rproc->pnode_id);
> > > + if (ret)
> > > + goto error;
> > > +
> > > + ret = r5_set_mode(z_rproc, rpu_mode);
> > > + if (ret)
> > > + goto error;
> > > +
> > > + if (of_property_read_bool(node, "mboxes")) {
> > > + ret = zynqmp_r5_setup_mbox(z_rproc, node);
  

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-19 Thread Ben Levinsky


-Original Message-
From: Mathieu Poirier 
Date: Wednesday, March 17, 2021 at 9:27 AM
To: Ben Levinsky 
Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek , "Ed T. Mooring" 
Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

On Mon, Mar 15, 2021 at 09:32:40PM +, Ben Levinsky wrote:
> 
> 
> -Original Message-
> From: Mathieu Poirier 
> Date: Monday, March 15, 2021 at 10:37 AM
> To: Ben Levinsky 
> Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek , "Ed T. Mooring" 
> Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc 
driver
> 
> On Thu, Mar 11, 2021 at 11:49:13PM +, Ben Levinsky wrote:
> > Hi Mathieu
> > 
> > -Original Message-
> > From: Mathieu Poirier 
> > Date: Tuesday, March 9, 2021 at 8:53 AM
> > To: Ben Levinsky 
> > Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek 
> > Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 
remoteproc driver
> > 
> > [...]
> > 
> > > +
> > > +/**
> > > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > > + *  this is called for each individual R5 
core to
> > > + *  set up mailbox, Xilinx platform manager 
unique ID,
> > > + *  add to rproc core
> > > + *
> > > + * @pdev: domain platform device for current R5 core
> > > + * @node: pointer of the device node for current R5 core
> > > + * @rpu_mode: mode to configure RPU, split or lockstep
> > > + *
> > > + * Return: 0 for success, negative value for failure.
> > > + */
> > > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct 
platform_device *pdev,
> > > +struct 
device_node *node,
> > > +enum 
rpu_oper_mode rpu_mode)
> > > +{
> > > + int ret, num_banks;
> > > + struct device *dev = &pdev->dev;
> > > + struct rproc *rproc_ptr;
> > > + struct zynqmp_r5_rproc *z_rproc;
> > > + struct device_node *r5_node;
> > > +
> > > + /* Allocate remoteproc instance */
> > > + rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
&zynqmp_r5_rproc_ops,
> > > +  NULL, sizeof(struct 
zynqmp_r5_rproc));
> > > + if (!rproc_ptr) {
> > > + ret = -ENOMEM;
> > > + goto error;
> > > + }
> > > +
> > > + rproc_ptr->auto_boot = false;
> > > + z_rproc = rproc_ptr->priv;
> > > + z_rproc->rproc = rproc_ptr;
> > > + r5_node = z_rproc->rproc->dev.parent->of_node;
> > > +
> > > + /* Set up DMA mask */
> > > + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> > > + if (ret)
> > > + goto error;
> > > +
> > > + /* Get R5 power domain node */
> > > + ret = of_property_read_u32(node, "power-domain", 
&z_rproc->pnode_id);
> > > + if (ret)
> > > + goto error;
> > > +
> > > + ret = r5_set_mode(z_rproc, rpu_mode);
> > > + if (ret)
> > > + goto error;
> > > +
> > > + if (of_property_read_bool(node, "mboxes")) {
> > > + ret = zynqmp_r5_setup_mbox(z_rproc, node);
  

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-17 Thread Mathieu Poirier
On Mon, Mar 15, 2021 at 09:32:40PM +, Ben Levinsky wrote:
> 
> 
> -Original Message-
> From: Mathieu Poirier 
> Date: Monday, March 15, 2021 at 10:37 AM
> To: Ben Levinsky 
> Cc: "devicet...@vger.kernel.org" , 
> "linux-remotep...@vger.kernel.org" , 
> "linux-kernel@vger.kernel.org" , 
> "linux-arm-ker...@lists.infradead.org" 
> , Michal Simek , 
> "Ed T. Mooring" 
> Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc 
> driver
> 
> On Thu, Mar 11, 2021 at 11:49:13PM +, Ben Levinsky wrote:
> > Hi Mathieu
> > 
> > -Original Message-
> > From: Mathieu Poirier 
> > Date: Tuesday, March 9, 2021 at 8:53 AM
> > To: Ben Levinsky 
> > Cc: "devicet...@vger.kernel.org" , 
> "linux-remotep...@vger.kernel.org" , 
> "linux-kernel@vger.kernel.org" , 
> "linux-arm-ker...@lists.infradead.org" 
> , Michal Simek 
> > Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 
> remoteproc driver
> > 
> > [...]
> > 
> > > +
> > > +/**
> > > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > > + *  this is called for each individual R5 
> core to
> > > + *  set up mailbox, Xilinx platform manager 
> unique ID,
> > > + *  add to rproc core
> > > + *
> > > + * @pdev: domain platform device for current R5 core
> > > + * @node: pointer of the device node for current R5 core
> > > + * @rpu_mode: mode to configure RPU, split or lockstep
> > > + *
> > > + * Return: 0 for success, negative value for failure.
> > > + */
> > > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct 
> platform_device *pdev,
> > > +struct device_node *node,
> > > +enum rpu_oper_mode 
> rpu_mode)
> > > +{
> > > + int ret, num_banks;
> > > + struct device *dev = &pdev->dev;
> > > + struct rproc *rproc_ptr;
> > > + struct zynqmp_r5_rproc *z_rproc;
> > > + struct device_node *r5_node;
> > > +
> > > + /* Allocate remoteproc instance */
> > > + rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
> &zynqmp_r5_rproc_ops,
> > > +  NULL, sizeof(struct 
> zynqmp_r5_rproc));
> > > + if (!rproc_ptr) {
> > > + ret = -ENOMEM;
> > > + goto error;
> > > + }
> > > +
> > > + rproc_ptr->auto_boot = false;
> > > + z_rproc = rproc_ptr->priv;
> > > + z_rproc->rproc = rproc_ptr;
> > > + r5_node = z_rproc->rproc->dev.parent->of_node;
> > > +
> > > + /* Set up DMA mask */
> > > + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> > > + if (ret)
> > > + goto error;
> > > +
> > > + /* Get R5 power domain node */
> > > + ret = of_property_read_u32(node, "power-domain", 
> &z_rproc->pnode_id);
> > > + if (ret)
> > > + goto error;
> > > +
> > > + ret = r5_set_mode(z_rproc, rpu_mode);
> > > + if (ret)
> > > + goto error;
> > > +
> > > + if (of_property_read_bool(node, "mboxes")) {
> > > + ret = zynqmp_r5_setup_mbox(z_rproc, node);
> > > + if (ret)
> > > + goto error;
> > > + }
> > > +
> > > + /* go through TCM banks for r5 node */
> > > + num_banks = of_count_phandle_with_args(r5_node, BANK_LIST_PROP, 
> NULL);
> > > + if (num_banks <= 0) {
> > > + dev_err(dev, "need to specify TCM banks\n");
> > > + ret = -EINVAL;
> > > + goto error;
> > > + }
> > > +
> > > + if (num_banks > NUM_SRAMS) {
> > > + dev_err(dev, "max number of srams is %d. given: %d 
> \r\n",
> > &g

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-17 Thread Mathieu Poirier
[...]

> > > +/*
> > > + * zynqmp_r5_remoteproc_probe
> > > + *
> > > + * @pdev: domain platform device for R5 cluster
> > > + *
> > > + * called when driver is probed, for each R5 core specified in 
> DT,
> > > + * setup as needed to do remoteproc-related operations
> > > + *
> > > + * Return: 0 for success, negative value for failure.
> > > + */
> > > +static int zynqmp_r5_remoteproc_probe(struct platform_device 
> *pdev)
> > > +{
> > > + int ret, core_count;
> > > + struct device *dev = &pdev->dev;
> > > + struct device_node *nc;
> > > + enum rpu_oper_mode rpu_mode = PM_RPU_MODE_LOCKSTEP;
> > > + struct list_head *cluster; /* list to track each core's rproc */
> > > + struct zynqmp_r5_rproc *z_rproc;
> > > + struct platform_device *child_pdev;
> > > + struct list_head *pos;
> > > +
> > > + ret = of_property_read_u32(dev->of_node, "xlnx,cluster-mode", 
> &rpu_mode);
> > > + if (ret < 0 || (rpu_mode != PM_RPU_MODE_LOCKSTEP &&
> > > + rpu_mode != PM_RPU_MODE_SPLIT)) {
> > > + dev_err(dev, "invalid cluster mode: ret %d mode %x\n",
> > > + ret, rpu_mode);
> > > + return ret;
> > > + }
> > > +
> > > + dev_dbg(dev, "RPU configuration: %s\n",
> > > + rpu_mode == PM_RPU_MODE_LOCKSTEP ? "lockstep" : 
> "split");
> > > +
> > > + /*
> > > +  * if 2 RPUs provided but one is lockstep, then we have an
> > > +  * invalid configuration.
> > > +  */
> > > +
> > > + core_count = of_get_available_child_count(dev->of_node);
> > > + if ((rpu_mode == PM_RPU_MODE_LOCKSTEP && core_count != 1) ||
> > > + core_count > MAX_RPROCS)
> > > + return -EINVAL;
> > > +
> > > + cluster = devm_kzalloc(dev, sizeof(*cluster), GFP_KERNEL);
> > > + if (!cluster)
> > > + return -ENOMEM;
> > > + INIT_LIST_HEAD(cluster);
> > > +
> > > + ret = devm_of_platform_populate(dev);
> > > + if (ret) {
> > > + dev_err(dev, "devm_of_platform_populate failed, ret = 
> %d\n", ret);
> > > + return ret;
> > > + }
> > > +
> > > + /* probe each individual r5 core's remoteproc-related info */
> > > + for_each_available_child_of_node(dev->of_node, nc) {
> > > + child_pdev = of_find_device_by_node(nc);
> > 
> > The device reference needs to be dropped after use, as described in 
> the function
> > documentation.
> > 
> > I'm out of time - I will continue tomorrow.
> > 
> > Mathieu
> > 
> > 
> > [Ben] By this do you mean that for each platform_device should have a 
> call like
> > platform_set_drvdata(child_pdev, NULL); if it fails? or 
> something else?
> 
> Have another read at the documentation and look at how other people have 
> used
> it.  You may already be aware but Bootlin's kernel cross-reference tool is
> really good for that.
> 
> https://elixir.bootlin.com/linux/v5.12-rc3/source
> 
> If I understand what you are saying I will add calls for 
> put_device(child_pdev) in error handling and at end of the loop.

That's one part of it.  But what will happen if there is no errors to deal with?
Where will the reference to child_pdev->dev be dropped?

> 
> 


Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-15 Thread Ben Levinsky


-Original Message-
From: Mathieu Poirier 
Date: Monday, March 15, 2021 at 10:26 AM
To: Ben Levinsky 
Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek , "Ed T. Mooring" 
Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

> > +
> > +static void zynqmp_r5_cleanup_mbox(struct zynqmp_r5_rproc *z_rproc)
> > +{
> > +   mbox_free_channel(z_rproc->tx_chan);
> > +   mbox_free_channel(z_rproc->rx_chan);
> > +}
> > +
> > +/**
> > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > + *this is called for each individual R5 core to
> > + *set up mailbox, Xilinx platform manager unique 
ID,
> > + *add to rproc core
> 
> The above has changed since last time, which makes it harder for me to
> review your work.  From hereon please change only the things I point 
out so that
> we keep the same goal posts from one revision to the other.
> 
> The tabulation needs to be fixed:  
> 
> * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> *
> * This is called for each individual R5 core to set up 
mailbox, Xilinx
> * platform manager unique ID, add to rproc core.
> 
> The description is also broken.
> 
> [Ben] Ok. How is the following:
> /**   
 
>  * zynqmp_r5_probe - Probes ZynqMP R5 processor device node   
 
>  *
 
>  * This is called for each individual R5 core to set up mailbox, Xilinx   
 
>  * platform manager unique ID, collect SRAM information and wire in   
 
>  * driver-specific data to to rproc core. 
 
>  *
 
>  * @pdev: domain platform device for current R5 core  
 
>  * @node: pointer of the device node for current R5 core  
 
>  * @rpu_mode: mode to configure RPU, split or lockstep
 
>  *
 
>  * Return: 0 for success, negative value for failure. 
 

Much better

>  */   
 
> static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct platform_device 
*pdev,   
>struct device_node *node,  
 
>enum rpu_oper_mode 
rpu_mode) 
> 
> 
> > + *
> > + * @pdev: domain platform device for current R5 core
> > + * @node: pointer of the device node for current R5 core
> > + * @rpu_mode: mode to configure RPU, split or lockstep
> > + *
> > + * Return: 0 for success, negative value for failure.
> > + */
> > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct 
platform_device *pdev,
> > +  struct device_node *node,
> > +  enum rpu_oper_mode 
rpu_mode)
> > +{
> > +   int ret, num_banks;
> > +   struct device *dev = &pdev->dev;
> > +   struct rproc *rproc_ptr;
> > +   struct zynqmp_r5_rproc *z_rproc;
> > +   struct device_node *r5_node;
> > +
> > +   /* Allocate remoteproc instance */
> > +   rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
&zynqmp_r5_rproc_ops,
> > +NULL, sizeof(struct 
zynqmp_r5_rproc));
> > +   if (!rproc_ptr) {
> > +   ret = -ENOMEM;
> > +   goto error;
> > +   }
> > +
> > +   rproc_ptr->auto_boot = false;
> > +   z_rproc = rproc_ptr->priv;
> > +   z_rproc->rproc = rproc_ptr;
> > +   r5_node = z_rproc->rproc->dev.parent->of_node;
> > +
> > +   /* Set up DMA mask */
> > +   ret = dma_set_coherent_mask(dev, DM

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-15 Thread Ben Levinsky


-Original Message-
From: Mathieu Poirier 
Date: Monday, March 15, 2021 at 10:37 AM
To: Ben Levinsky 
Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek , "Ed T. Mooring" 
Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

On Thu, Mar 11, 2021 at 11:49:13PM +, Ben Levinsky wrote:
> Hi Mathieu
> 
> -Original Message-
> From: Mathieu Poirier 
> Date: Tuesday, March 9, 2021 at 8:53 AM
> To: Ben Levinsky 
> Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek 
> Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc 
driver
> 
> [...]
> 
> > +
> > +/**
> > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > + *this is called for each individual R5 core to
> > + *set up mailbox, Xilinx platform manager unique 
ID,
> > + *add to rproc core
> > + *
> > + * @pdev: domain platform device for current R5 core
> > + * @node: pointer of the device node for current R5 core
> > + * @rpu_mode: mode to configure RPU, split or lockstep
> > + *
> > + * Return: 0 for success, negative value for failure.
> > + */
> > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct 
platform_device *pdev,
> > +  struct device_node *node,
> > +  enum rpu_oper_mode 
rpu_mode)
> > +{
> > +   int ret, num_banks;
> > +   struct device *dev = &pdev->dev;
> > +   struct rproc *rproc_ptr;
> > +   struct zynqmp_r5_rproc *z_rproc;
> > +   struct device_node *r5_node;
> > +
> > +   /* Allocate remoteproc instance */
> > +   rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
&zynqmp_r5_rproc_ops,
> > +NULL, sizeof(struct 
zynqmp_r5_rproc));
> > +   if (!rproc_ptr) {
> > +   ret = -ENOMEM;
> > +   goto error;
> > +   }
> > +
> > +   rproc_ptr->auto_boot = false;
> > +   z_rproc = rproc_ptr->priv;
> > +   z_rproc->rproc = rproc_ptr;
> > +   r5_node = z_rproc->rproc->dev.parent->of_node;
> > +
> > +   /* Set up DMA mask */
> > +   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> > +   if (ret)
> > +   goto error;
> > +
> > +   /* Get R5 power domain node */
> > +   ret = of_property_read_u32(node, "power-domain", 
&z_rproc->pnode_id);
> > +   if (ret)
> > +   goto error;
> > +
> > +   ret = r5_set_mode(z_rproc, rpu_mode);
> > +   if (ret)
> > +   goto error;
> > +
> > +   if (of_property_read_bool(node, "mboxes")) {
> > +   ret = zynqmp_r5_setup_mbox(z_rproc, node);
> > +   if (ret)
> > +   goto error;
> > +   }
> > +
> > +   /* go through TCM banks for r5 node */
> > +   num_banks = of_count_phandle_with_args(r5_node, BANK_LIST_PROP, 
NULL);
> > +   if (num_banks <= 0) {
> > +   dev_err(dev, "need to specify TCM banks\n");
> > +   ret = -EINVAL;
> > +   goto error;
> > +   }
> > +
> > +   if (num_banks > NUM_SRAMS) {
> > +   dev_err(dev, "max number of srams is %d. given: %d 
\r\n",
> > +   NUM_SRAMS, num_banks);
> > +   ret = -EINVAL;
> > +   goto error;
> > +   }
> > +
> > +   /* construct collection of srams used by the current R5 core */
> > +   for (; num_banks; num_banks--) {
> > +   struct resource rsc;
> > +   struct device_node *dt_node;
> > +   resource_size_t size;
> > +   int i;
> > +
 

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-15 Thread Mathieu Poirier
On Thu, Mar 11, 2021 at 11:49:13PM +, Ben Levinsky wrote:
> Hi Mathieu
> 
> -Original Message-
> From: Mathieu Poirier 
> Date: Tuesday, March 9, 2021 at 8:53 AM
> To: Ben Levinsky 
> Cc: "devicet...@vger.kernel.org" , 
> "linux-remotep...@vger.kernel.org" , 
> "linux-kernel@vger.kernel.org" , 
> "linux-arm-ker...@lists.infradead.org" 
> , Michal Simek 
> Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc 
> driver
> 
> [...]
> 
> > +
> > +/**
> > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > + *this is called for each individual R5 core to
> > + *set up mailbox, Xilinx platform manager unique 
> ID,
> > + *add to rproc core
> > + *
> > + * @pdev: domain platform device for current R5 core
> > + * @node: pointer of the device node for current R5 core
> > + * @rpu_mode: mode to configure RPU, split or lockstep
> > + *
> > + * Return: 0 for success, negative value for failure.
> > + */
> > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct platform_device 
> *pdev,
> > +  struct device_node *node,
> > +  enum rpu_oper_mode 
> rpu_mode)
> > +{
> > +   int ret, num_banks;
> > +   struct device *dev = &pdev->dev;
> > +   struct rproc *rproc_ptr;
> > +   struct zynqmp_r5_rproc *z_rproc;
> > +   struct device_node *r5_node;
> > +
> > +   /* Allocate remoteproc instance */
> > +   rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
> &zynqmp_r5_rproc_ops,
> > +NULL, sizeof(struct 
> zynqmp_r5_rproc));
> > +   if (!rproc_ptr) {
> > +   ret = -ENOMEM;
> > +   goto error;
> > +   }
> > +
> > +   rproc_ptr->auto_boot = false;
> > +   z_rproc = rproc_ptr->priv;
> > +   z_rproc->rproc = rproc_ptr;
> > +   r5_node = z_rproc->rproc->dev.parent->of_node;
> > +
> > +   /* Set up DMA mask */
> > +   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> > +   if (ret)
> > +   goto error;
> > +
> > +   /* Get R5 power domain node */
> > +   ret = of_property_read_u32(node, "power-domain", 
> &z_rproc->pnode_id);
> > +   if (ret)
> > +   goto error;
> > +
> > +   ret = r5_set_mode(z_rproc, rpu_mode);
> > +   if (ret)
> > +   goto error;
> > +
> > +   if (of_property_read_bool(node, "mboxes")) {
> > +   ret = zynqmp_r5_setup_mbox(z_rproc, node);
> > +   if (ret)
> > +   goto error;
> > +   }
> > +
> > +   /* go through TCM banks for r5 node */
> > +   num_banks = of_count_phandle_with_args(r5_node, BANK_LIST_PROP, 
> NULL);
> > +   if (num_banks <= 0) {
> > +   dev_err(dev, "need to specify TCM banks\n");
> > +   ret = -EINVAL;
> > +   goto error;
> > +   }
> > +
> > +   if (num_banks > NUM_SRAMS) {
> > +   dev_err(dev, "max number of srams is %d. given: %d 
> \r\n",
> > +   NUM_SRAMS, num_banks);
> > +   ret = -EINVAL;
> > +   goto error;
> > +   }
> > +
> > +   /* construct collection of srams used by the current R5 core */
> > +   for (; num_banks; num_banks--) {
> > +   struct resource rsc;
> > +   struct device_node *dt_node;
> > +   resource_size_t size;
> > +   int i;
> > +
> > +   dt_node = of_parse_phandle(r5_node, BANK_LIST_PROP, i);
> 
> Variable @i is not initialised but it is used as an index to retrieve a 
> handle
> to the sram banks.  That code _should_ have failed frequently or at least 
> have
> yielded abnormal results often enough to be noticed.  Why wasn't it the 
> case?
> 
> I will stop here for the moment.
> 
> [Ben]
> Yes this should be initialized. The reason this got through is that as i 
> defaults to 0 and the 0th bank housed the required data. the case where SRAMS 
> that can be written to, 0xFFE2 in this case of split mode and on R5-0, 
> was not caught.
> 

Here @i is a variable allocated on the stack and as such it is garanteed to be
garbage on initialisation - it will do anything but default to 0.


> Instead of i I will use 
> 
> sram_node = of_parse_phandle(node, BANK_LIST_PROP,
>   
>  num_banks - 1); 

Do you have to start with the last bank?  If memory serves me well it isn't the
case in the previous revisions.  Why not go back to the implementation you had
in V25?  



Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-15 Thread Mathieu Poirier
> > +
> > +static void zynqmp_r5_cleanup_mbox(struct zynqmp_r5_rproc *z_rproc)
> > +{
> > +   mbox_free_channel(z_rproc->tx_chan);
> > +   mbox_free_channel(z_rproc->rx_chan);
> > +}
> > +
> > +/**
> > + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> > + *this is called for each individual R5 core to
> > + *set up mailbox, Xilinx platform manager unique 
> ID,
> > + *add to rproc core
> 
> The above has changed since last time, which makes it harder for me to
> review your work.  From hereon please change only the things I point out 
> so that
> we keep the same goal posts from one revision to the other.
> 
> The tabulation needs to be fixed:  
> 
> * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> *
> * This is called for each individual R5 core to set up mailbox, 
> Xilinx
> * platform manager unique ID, add to rproc core.
> 
> The description is also broken.
> 
> [Ben] Ok. How is the following:
> /**   
>  
>  * zynqmp_r5_probe - Probes ZynqMP R5 processor device node   
>  
>  *
>  
>  * This is called for each individual R5 core to set up mailbox, Xilinx   
>  
>  * platform manager unique ID, collect SRAM information and wire in   
>  
>  * driver-specific data to to rproc core. 
>  
>  *
>  
>  * @pdev: domain platform device for current R5 core  
>  
>  * @node: pointer of the device node for current R5 core  
>  
>  * @rpu_mode: mode to configure RPU, split or lockstep
>  
>  *
>  
>  * Return: 0 for success, negative value for failure. 
>  

Much better

>  */   
>  
> static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct platform_device *pdev,  
>  
>struct device_node *node,  
>  
>enum rpu_oper_mode rpu_mode) 
> 
> 
> > + *
> > + * @pdev: domain platform device for current R5 core
> > + * @node: pointer of the device node for current R5 core
> > + * @rpu_mode: mode to configure RPU, split or lockstep
> > + *
> > + * Return: 0 for success, negative value for failure.
> > + */
> > +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct platform_device 
> *pdev,
> > +  struct device_node *node,
> > +  enum rpu_oper_mode 
> rpu_mode)
> > +{
> > +   int ret, num_banks;
> > +   struct device *dev = &pdev->dev;
> > +   struct rproc *rproc_ptr;
> > +   struct zynqmp_r5_rproc *z_rproc;
> > +   struct device_node *r5_node;
> > +
> > +   /* Allocate remoteproc instance */
> > +   rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), 
> &zynqmp_r5_rproc_ops,
> > +NULL, sizeof(struct 
> zynqmp_r5_rproc));
> > +   if (!rproc_ptr) {
> > +   ret = -ENOMEM;
> > +   goto error;
> > +   }
> > +
> > +   rproc_ptr->auto_boot = false;
> > +   z_rproc = rproc_ptr->priv;
> > +   z_rproc->rproc = rproc_ptr;
> > +   r5_node = z_rproc->rproc->dev.parent->of_node;
> > +
> > +   /* Set up DMA mask */
> > +   ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> > +   if (ret)
> > +   goto error;
> > +
> > +   /* Get R5 power domain node */
> > +   ret = of_property_read_u32(node, "power-domain", 
> &z_rproc->pnode_id);
> > +   if (ret)
> > +   goto error;
> > +
> > +   ret = r5_set_mode(z_rproc, rpu_mode);
> > +   if (ret)
> > +   goto error;
> > +
> > +   if (of_property_read_bool(node, "mboxes")) {
> > +   ret = zynqmp_r5_setup_mbox(z_rproc, node);
> > +   if (ret)
> > +   goto error;
> > +   }
> > +
> > +   /* go through TCM banks for r5 node */
> > +   num_banks = of_count_phandle_with_args(r5_node, BANK_LIST_PROP, 
> NULL);
> 
> Shouldn't this be @node instead of @r5_node?
> 
> [Ben]  Yes this should and will be node.
> 
> > +   if (num_banks <= 0) {
> > +   dev_err(dev, "need to specify TC

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-11 Thread Ben Levinsky
Hi Mathieu

-Original Message-
From: Mathieu Poirier 
Date: Tuesday, March 9, 2021 at 8:53 AM
To: Ben Levinsky 
Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek 
Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

[...]

> +
> +/**
> + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> + *  this is called for each individual R5 core to
> + *  set up mailbox, Xilinx platform manager unique 
ID,
> + *  add to rproc core
> + *
> + * @pdev: domain platform device for current R5 core
> + * @node: pointer of the device node for current R5 core
> + * @rpu_mode: mode to configure RPU, split or lockstep
> + *
> + * Return: 0 for success, negative value for failure.
> + */
> +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct platform_device 
*pdev,
> +struct device_node *node,
> +enum rpu_oper_mode rpu_mode)
> +{
> + int ret, num_banks;
> + struct device *dev = &pdev->dev;
> + struct rproc *rproc_ptr;
> + struct zynqmp_r5_rproc *z_rproc;
> + struct device_node *r5_node;
> +
> + /* Allocate remoteproc instance */
> + rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), &zynqmp_r5_rproc_ops,
> +  NULL, sizeof(struct zynqmp_r5_rproc));
> + if (!rproc_ptr) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> + rproc_ptr->auto_boot = false;
> + z_rproc = rproc_ptr->priv;
> + z_rproc->rproc = rproc_ptr;
> + r5_node = z_rproc->rproc->dev.parent->of_node;
> +
> + /* Set up DMA mask */
> + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> + if (ret)
> + goto error;
> +
> + /* Get R5 power domain node */
> + ret = of_property_read_u32(node, "power-domain", &z_rproc->pnode_id);
> + if (ret)
> + goto error;
> +
> + ret = r5_set_mode(z_rproc, rpu_mode);
> + if (ret)
> + goto error;
> +
> + if (of_property_read_bool(node, "mboxes")) {
> + ret = zynqmp_r5_setup_mbox(z_rproc, node);
> + if (ret)
> + goto error;
> + }
> +
> + /* go through TCM banks for r5 node */
> + num_banks = of_count_phandle_with_args(r5_node, BANK_LIST_PROP, NULL);
> + if (num_banks <= 0) {
> + dev_err(dev, "need to specify TCM banks\n");
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + if (num_banks > NUM_SRAMS) {
> + dev_err(dev, "max number of srams is %d. given: %d \r\n",
> + NUM_SRAMS, num_banks);
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + /* construct collection of srams used by the current R5 core */
> + for (; num_banks; num_banks--) {
> + struct resource rsc;
> + struct device_node *dt_node;
> + resource_size_t size;
> + int i;
> +
> + dt_node = of_parse_phandle(r5_node, BANK_LIST_PROP, i);

Variable @i is not initialised but it is used as an index to retrieve a 
handle
to the sram banks.  That code _should_ have failed frequently or at least 
have
yielded abnormal results often enough to be noticed.  Why wasn't it the 
case?

I will stop here for the moment.

[Ben]
Yes this should be initialized. The reason this got through is that as i 
defaults to 0 and the 0th bank housed the required data. the case where SRAMS 
that can be written to, 0xFFE2 in this case of split mode and on R5-0, was 
not caught.

Instead of i I will use 

sram_node = of_parse_phandle(node, BANK_LIST_PROP,  
 num_banks - 1); 


sram_node is the var name given in the function called by probe to collect the 
SRAM information.



If there is other feedback please let me know

Thanks
Ben


> + if (!dt_node) {
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + ret = of_address_to_resource(dt_node, 0, &rsc);
> + if (ret < 0) {
> + of_node_put(dt_node);
> + goto error;
> + }
> +
> + of_node_put(dt_node);
> +

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-11 Thread Ben Levinsky
Hi Mathieu 

Thanks for the feedback. I responded inline

-Original Message-
From: Mathieu Poirier 
Date: Monday, March 8, 2021 at 11:00 AM
To: Ben Levinsky 
Cc: "devicet...@vger.kernel.org" , 
"linux-remotep...@vger.kernel.org" , 
"linux-kernel@vger.kernel.org" , 
"linux-arm-ker...@lists.infradead.org" , 
Michal Simek 
Subject: Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

On Tue, Feb 23, 2021 at 07:44:47AM -0800, Ben Levinsky wrote:
> R5 is included in Xilinx Zynq UltraScale MPSoC so by adding this
> remoteproc driver, we can boot the R5 sub-system in two different
> configurations -
>   * Split
>   * Lockstep
> 
> The Xilinx R5 Remoteproc Driver boots the R5's via calls to the Xilinx
> Platform Management Unit that handles the R5 configuration, memory access
> and R5 lifecycle management. The interface to this manager is done in this
> driver via zynqmp_pm_* function calls.
> 
> Signed-off-by: Wendy Liang 
> Signed-off-by: Michal Simek 
> Signed-off-by: Ed Mooring 
> Signed-off-by: Jason Wu 
> Signed-off-by: Ben Levinsky 
> ---
>  drivers/remoteproc/Kconfig|   8 +
>  drivers/remoteproc/Makefile   |   1 +
>  drivers/remoteproc/zynqmp_r5_remoteproc.c | 954 ++
>  3 files changed, 963 insertions(+)
>  create mode 100644 drivers/remoteproc/zynqmp_r5_remoteproc.c
> 
> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
> index c6659dfea7c7..c2fe54b1d94f 100644
> --- a/drivers/remoteproc/Kconfig
> +++ b/drivers/remoteproc/Kconfig
> @@ -275,6 +275,14 @@ config TI_K3_DSP_REMOTEPROC
> It's safe to say N here if you're not interested in utilizing
> the DSP slave processors.
>  
> +config ZYNQMP_R5_REMOTEPROC
> + tristate "ZynqMP R5 remoteproc support"
> + depends on PM && ARCH_ZYNQMP
> + select RPMSG_VIRTIO
> + select ZYNQMP_IPI_MBOX
> + help
> +   Say y or m here to support ZynqMP R5 remote processors via the remote
> +   processor framework.
>  endif # REMOTEPROC
>  
>  endmenu
> diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
> index 3dfa28e6c701..ef1abff654c2 100644
> --- a/drivers/remoteproc/Makefile
> +++ b/drivers/remoteproc/Makefile
> @@ -33,3 +33,4 @@ obj-$(CONFIG_ST_REMOTEPROC) += 
st_remoteproc.o
>  obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o
>  obj-$(CONFIG_STM32_RPROC)+= stm32_rproc.o
>  obj-$(CONFIG_TI_K3_DSP_REMOTEPROC)   += ti_k3_dsp_remoteproc.o
> +obj-$(CONFIG_ZYNQMP_R5_REMOTEPROC)   += zynqmp_r5_remoteproc.o
> diff --git a/drivers/remoteproc/zynqmp_r5_remoteproc.c 
b/drivers/remoteproc/zynqmp_r5_remoteproc.c
> new file mode 100644
> index ..4bcff2daceaf
> --- /dev/null
> +++ b/drivers/remoteproc/zynqmp_r5_remoteproc.c
> @@ -0,0 +1,954 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Zynq R5 Remote Processor driver
> + *
> + * Based on origin OMAP and Zynq Remote Processor driver
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "remoteproc_internal.h"
> +
> +#define MAX_RPROCS   2 /* Support up to 2 RPU */
> +#define MAX_MEM_PNODES   4 /* Max power nodes for one RPU memory 
instance */
> +
> +#define BANK_LIST_PROP   "sram"
> +#define DDR_LIST_PROP"memory-region"
> +
> +/* IPI buffer MAX length */
> +#define IPI_BUF_LEN_MAX  32U
> +/* RX mailbox client buffer max length */
> +#define RX_MBOX_CLIENT_BUF_MAX   (IPI_BUF_LEN_MAX + \
> +  sizeof(struct zynqmp_ipi_message))
> +
> +/*
> + * Map each Xilinx on-chip SRAM  Bank address to their own respective
> + * pm_node_id.
> + *
> + * size can differ based on R5 cluster configuration so record from
> + * device tree in zynqmp_r5_probe.
> + */
> +struct sram_addr_data {
> + phys_addr_t addr;
> + enum pm_node_id id;
> + resource_size_t size;
> +};
> +
> +#define NUM_SRAMS 4U
> +static const struct sram_addr_data zynqmp_banks[NUM_SRAMS] = {
> + {0xffe0UL, NODE_TCM_0_A, 0},
> + {0xffe2UL, NODE_T

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-09 Thread Mathieu Poirier
[...]

> +
> +/**
> + * zynqmp_r5_probe - Probes ZynqMP R5 processor device node
> + *  this is called for each individual R5 core to
> + *  set up mailbox, Xilinx platform manager unique ID,
> + *  add to rproc core
> + *
> + * @pdev: domain platform device for current R5 core
> + * @node: pointer of the device node for current R5 core
> + * @rpu_mode: mode to configure RPU, split or lockstep
> + *
> + * Return: 0 for success, negative value for failure.
> + */
> +static struct zynqmp_r5_rproc *zynqmp_r5_probe(struct platform_device *pdev,
> +struct device_node *node,
> +enum rpu_oper_mode rpu_mode)
> +{
> + int ret, num_banks;
> + struct device *dev = &pdev->dev;
> + struct rproc *rproc_ptr;
> + struct zynqmp_r5_rproc *z_rproc;
> + struct device_node *r5_node;
> +
> + /* Allocate remoteproc instance */
> + rproc_ptr = devm_rproc_alloc(dev, dev_name(dev), &zynqmp_r5_rproc_ops,
> +  NULL, sizeof(struct zynqmp_r5_rproc));
> + if (!rproc_ptr) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> + rproc_ptr->auto_boot = false;
> + z_rproc = rproc_ptr->priv;
> + z_rproc->rproc = rproc_ptr;
> + r5_node = z_rproc->rproc->dev.parent->of_node;
> +
> + /* Set up DMA mask */
> + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> + if (ret)
> + goto error;
> +
> + /* Get R5 power domain node */
> + ret = of_property_read_u32(node, "power-domain", &z_rproc->pnode_id);
> + if (ret)
> + goto error;
> +
> + ret = r5_set_mode(z_rproc, rpu_mode);
> + if (ret)
> + goto error;
> +
> + if (of_property_read_bool(node, "mboxes")) {
> + ret = zynqmp_r5_setup_mbox(z_rproc, node);
> + if (ret)
> + goto error;
> + }
> +
> + /* go through TCM banks for r5 node */
> + num_banks = of_count_phandle_with_args(r5_node, BANK_LIST_PROP, NULL);
> + if (num_banks <= 0) {
> + dev_err(dev, "need to specify TCM banks\n");
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + if (num_banks > NUM_SRAMS) {
> + dev_err(dev, "max number of srams is %d. given: %d \r\n",
> + NUM_SRAMS, num_banks);
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + /* construct collection of srams used by the current R5 core */
> + for (; num_banks; num_banks--) {
> + struct resource rsc;
> + struct device_node *dt_node;
> + resource_size_t size;
> + int i;
> +
> + dt_node = of_parse_phandle(r5_node, BANK_LIST_PROP, i);

Variable @i is not initialised but it is used as an index to retrieve a handle
to the sram banks.  That code _should_ have failed frequently or at least have
yielded abnormal results often enough to be noticed.  Why wasn't it the case?

I will stop here for the moment.

> + if (!dt_node) {
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + ret = of_address_to_resource(dt_node, 0, &rsc);
> + if (ret < 0) {
> + of_node_put(dt_node);
> + goto error;
> + }
> +
> + of_node_put(dt_node);
> + size = resource_size(&rsc);
> +
> + /*
> +  * Find corresponding Xilinx platform management ID.
> +  * The bank information is used in prepare/unprepare and
> +  * parse_fw.
> +  */
> + for (i = 0; i < NUM_SRAMS; i++) {
> + if (rsc.start == zynqmp_banks[i].addr) {
> + z_rproc->srams[i].addr = rsc.start;
> + z_rproc->srams[i].size = size;
> + z_rproc->srams[i].id = zynqmp_banks[i].id;
> + break;
> + }
> + }
> +
> + if (i == NUM_SRAMS) {
> + dev_err(dev, "sram %llx is not valid.\n", rsc.start);
> + ret = -EINVAL;
> + goto error;
> + }
> + }
> +
> + /* Add R5 remoteproc */
> + ret = devm_rproc_add(dev, rproc_ptr);
> + if (ret) {
> + zynqmp_r5_cleanup_mbox(z_rproc);
> + goto error;
> + }
> +
> + return z_rproc;
> +error:
> + return ERR_PTR(ret);
> +}
> +
> +/*
> + * zynqmp_r5_remoteproc_probe
> + *
> + * @pdev: domain platform device for R5 cluster
> + *
> + * called when driver is probed, for each R5 core specified in DT,
> + * setup as needed to do remoteproc-related operations
> + *
> + * Return: 0 for success, negative value for failure.
> + */
> +static int zynqmp_r5_remoteproc_probe(struct platform_device *pdev)
> +

Re: [PATCH v26 5/5] remoteproc: Add initial zynqmp R5 remoteproc driver

2021-03-08 Thread Mathieu Poirier
On Tue, Feb 23, 2021 at 07:44:47AM -0800, Ben Levinsky wrote:
> R5 is included in Xilinx Zynq UltraScale MPSoC so by adding this
> remoteproc driver, we can boot the R5 sub-system in two different
> configurations -
>   * Split
>   * Lockstep
> 
> The Xilinx R5 Remoteproc Driver boots the R5's via calls to the Xilinx
> Platform Management Unit that handles the R5 configuration, memory access
> and R5 lifecycle management. The interface to this manager is done in this
> driver via zynqmp_pm_* function calls.
> 
> Signed-off-by: Wendy Liang 
> Signed-off-by: Michal Simek 
> Signed-off-by: Ed Mooring 
> Signed-off-by: Jason Wu 
> Signed-off-by: Ben Levinsky 
> ---
>  drivers/remoteproc/Kconfig|   8 +
>  drivers/remoteproc/Makefile   |   1 +
>  drivers/remoteproc/zynqmp_r5_remoteproc.c | 954 ++
>  3 files changed, 963 insertions(+)
>  create mode 100644 drivers/remoteproc/zynqmp_r5_remoteproc.c
> 
> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
> index c6659dfea7c7..c2fe54b1d94f 100644
> --- a/drivers/remoteproc/Kconfig
> +++ b/drivers/remoteproc/Kconfig
> @@ -275,6 +275,14 @@ config TI_K3_DSP_REMOTEPROC
> It's safe to say N here if you're not interested in utilizing
> the DSP slave processors.
>  
> +config ZYNQMP_R5_REMOTEPROC
> + tristate "ZynqMP R5 remoteproc support"
> + depends on PM && ARCH_ZYNQMP
> + select RPMSG_VIRTIO
> + select ZYNQMP_IPI_MBOX
> + help
> +   Say y or m here to support ZynqMP R5 remote processors via the remote
> +   processor framework.
>  endif # REMOTEPROC
>  
>  endmenu
> diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
> index 3dfa28e6c701..ef1abff654c2 100644
> --- a/drivers/remoteproc/Makefile
> +++ b/drivers/remoteproc/Makefile
> @@ -33,3 +33,4 @@ obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o
>  obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o
>  obj-$(CONFIG_STM32_RPROC)+= stm32_rproc.o
>  obj-$(CONFIG_TI_K3_DSP_REMOTEPROC)   += ti_k3_dsp_remoteproc.o
> +obj-$(CONFIG_ZYNQMP_R5_REMOTEPROC)   += zynqmp_r5_remoteproc.o
> diff --git a/drivers/remoteproc/zynqmp_r5_remoteproc.c 
> b/drivers/remoteproc/zynqmp_r5_remoteproc.c
> new file mode 100644
> index ..4bcff2daceaf
> --- /dev/null
> +++ b/drivers/remoteproc/zynqmp_r5_remoteproc.c
> @@ -0,0 +1,954 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Zynq R5 Remote Processor driver
> + *
> + * Based on origin OMAP and Zynq Remote Processor driver
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "remoteproc_internal.h"
> +
> +#define MAX_RPROCS   2 /* Support up to 2 RPU */
> +#define MAX_MEM_PNODES   4 /* Max power nodes for one RPU memory 
> instance */
> +
> +#define BANK_LIST_PROP   "sram"
> +#define DDR_LIST_PROP"memory-region"
> +
> +/* IPI buffer MAX length */
> +#define IPI_BUF_LEN_MAX  32U
> +/* RX mailbox client buffer max length */
> +#define RX_MBOX_CLIENT_BUF_MAX   (IPI_BUF_LEN_MAX + \
> +  sizeof(struct zynqmp_ipi_message))
> +
> +/*
> + * Map each Xilinx on-chip SRAM  Bank address to their own respective
> + * pm_node_id.
> + *
> + * size can differ based on R5 cluster configuration so record from
> + * device tree in zynqmp_r5_probe.
> + */
> +struct sram_addr_data {
> + phys_addr_t addr;
> + enum pm_node_id id;
> + resource_size_t size;
> +};
> +
> +#define NUM_SRAMS 4U
> +static const struct sram_addr_data zynqmp_banks[NUM_SRAMS] = {
> + {0xffe0UL, NODE_TCM_0_A, 0},
> + {0xffe2UL, NODE_TCM_0_B, 0},
> + {0xffe9UL, NODE_TCM_1_A, 0},
> + {0xffebUL, NODE_TCM_1_B, 0},
> +};
> +
> +/**
> + * struct zynqmp_r5_rproc - ZynqMP R5 core structure
> + *
> + * @rx_mc_buf: rx mailbox client buffer to save the rx message
> + * @srams : srams Xilinx mgmt IDs for srams that will be used by R5 core.
> + * @tx_mc: tx mailbox client
> + * @rx_mc: rx mailbox client
> + * @mbox_work: mbox_work for the RPU remoteproc
> + * @tx_mc_skbs: socket buffers for tx mailbox client
> + * @rproc: rproc handle
> + * @tx_chan: tx mailbox channel
> + * @rx_chan: rx mailbox channel
> + * @pnode_id: RPU CPU power domain id
> + * @elem: linked list item
> + */
> +struct zynqmp_r5_rproc {
> + unsigned char rx_mc_buf[RX_MBOX_CLIENT_BUF_MAX];
> + struct sram_addr_data srams[NUM_SRAMS];
> + struct mbox_client tx_mc;
> + struct mbox_client rx_mc;
> + struct work_struct mbox_work;
> + struct sk_buff_head tx_mc_skbs;
> + struct rproc *rproc;
> + struct mbox_chan *tx_chan;
> + struct mbox_chan *rx_chan;
> + u32 pnode_id;
> + struct list_head elem;
> +};
> +
> +/*
> + * r5_set_mode
> + * @z_rproc: Remote processor private data
> + * @rpu_mode: mode specified by device tree to co