Re: [PATCH v6 4/4] remoteproc: zynqmp: parse TCM from device tree

2023-10-19 Thread kernel test robot
Hi Tanmay,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a7d272979d3a89b117ca2c547dc8a465c4f28635]

url:
https://github.com/intel-lab-lkp/linux/commits/Tanmay-Shah/dt-bindings-remoteproc-add-Tightly-Coupled-Memory-TCM-bindings/20231017-120805
base:   a7d272979d3a89b117ca2c547dc8a465c4f28635
patch link:
https://lore.kernel.org/r/20231013042229.3954527-5-tanmay.shah%40amd.com
patch subject: [PATCH v6 4/4] remoteproc: zynqmp: parse TCM from device tree
config: arm64-randconfig-002-20231019 
(https://download.01.org/0day-ci/archive/20231019/202310191806.njlsejwm-...@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20231019/202310191806.njlsejwm-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202310191806.njlsejwm-...@intel.com/

All warnings (new ones prefixed by >>):

   drivers/remoteproc/xlnx_r5_remoteproc.c: In function 
'zynqmp_r5_get_tcm_node_from_dt':
>> drivers/remoteproc/xlnx_r5_remoteproc.c:1162:28: warning: array subscript 
>> 'struct mem_bank_data[0]' is partly outside array bounds of 'unsigned 
>> char[8]' [-Warray-bounds=]
1162 | tcm->da = (u32)abs_addr;
 |^~
   In file included from include/linux/dma-mapping.h:8,
from drivers/remoteproc/xlnx_r5_remoteproc.c:8:
   In function 'devm_kzalloc',
   inlined from 'zynqmp_r5_get_tcm_node_from_dt' at 
drivers/remoteproc/xlnx_r5_remoteproc.c:1143:10:
   include/linux/device.h:314:16: note: object of size 8 allocated by 
'devm_kmalloc'
 314 | return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
 |^
   drivers/remoteproc/xlnx_r5_remoteproc.c: In function 
'zynqmp_r5_get_tcm_node_from_dt':
   drivers/remoteproc/xlnx_r5_remoteproc.c:1163:28: warning: array subscript 
'struct mem_bank_data[0]' is partly outside array bounds of 'unsigned char[8]' 
[-Warray-bounds=]
1163 | tcm->size = (u32)size;
 |^~
   In function 'devm_kzalloc',
   inlined from 'zynqmp_r5_get_tcm_node_from_dt' at 
drivers/remoteproc/xlnx_r5_remoteproc.c:1143:10:
   include/linux/device.h:314:16: note: object of size 8 allocated by 
'devm_kmalloc'
 314 | return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
 |^
   drivers/remoteproc/xlnx_r5_remoteproc.c: In function 
'zynqmp_r5_get_tcm_node_from_dt':
   drivers/remoteproc/xlnx_r5_remoteproc.c:1172:28: warning: array subscript 
'struct mem_bank_data[0]' is partly outside array bounds of 'unsigned char[8]' 
[-Warray-bounds=]
1172 | tcm->addr = (u32)res->start;
 |^~
   In function 'devm_kzalloc',
   inlined from 'zynqmp_r5_get_tcm_node_from_dt' at 
drivers/remoteproc/xlnx_r5_remoteproc.c:1143:10:
   include/linux/device.h:314:16: note: object of size 8 allocated by 
'devm_kmalloc'
 314 | return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
 |^
   drivers/remoteproc/xlnx_r5_remoteproc.c: In function 
'zynqmp_r5_get_tcm_node_from_dt':
   drivers/remoteproc/xlnx_r5_remoteproc.c:1173:28: warning: array subscript 
'struct mem_bank_data[0]' is partly outside array bounds of 'unsigned char[8]' 
[-Warray-bounds=]
1173 | tcm->bank_name = (char *)res->name;
 |^~
   In function 'devm_kzalloc',
   inlined from 'zynqmp_r5_get_tcm_node_from_dt' at 
drivers/remoteproc/xlnx_r5_remoteproc.c:1143:10:
   include/linux/device.h:314:16: note: object of size 8 allocated by 
'devm_kmalloc'
 314 | return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
 |^
   In file included from include/linux/device.h:17:
   drivers/remoteproc/xlnx_r5_remoteproc.c: In function 
'zynqmp_r5_get_tcm_node_from_dt':
   drivers/remoteproc/xlnx_r5_remoteproc.c:1174:74: warning: array subscript 
'struct mem_bank_data[0]' is partly outside array bounds of 'unsigned char[8]' 
[-Warray-bounds=]
1174 | res = devm_request_mem_region(dev, 
tcm->addr, tcm->size,
 |  
^~
   include/linux/ioport.h:306:63: note: in definition of macro 
'devm_request_mem_region'
 306 | __devm_request_region(dev, _resource, (start), (n), 
(name))
 |   ^
   In function 'devm_kzalloc',
   inlined f

[PATCH v6 4/4] remoteproc: zynqmp: parse TCM from device tree

2023-10-12 Thread Tanmay Shah
ZynqMP TCM information is fixed in driver. Now ZynqMP TCM information
is available in device-tree. Parse TCM information in driver
as per new bindings.

Signed-off-by: Tanmay Shah 
---

Changes in v6:
  - Missing . at the end of the commit message
  - remove redundant initialization of variables
  - remove fail_tcm label and relevant code to free memory
acquired using devm_* API. As this will be freed when device free it
  - add extra check to see if "reg" property is supported or not

 drivers/remoteproc/xlnx_r5_remoteproc.c | 106 ++--
 1 file changed, 98 insertions(+), 8 deletions(-)

diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c 
b/drivers/remoteproc/xlnx_r5_remoteproc.c
index 04e95d880184..8c3575970c1d 100644
--- a/drivers/remoteproc/xlnx_r5_remoteproc.c
+++ b/drivers/remoteproc/xlnx_r5_remoteproc.c
@@ -75,8 +75,8 @@ struct mbox_info {
 };
 
 /*
- * Hardcoded TCM bank values. This will be removed once TCM bindings are
- * accepted for system-dt specifications and upstreamed in linux kernel
+ * Hardcoded TCM bank values. This will stay in driver to maintain backward
+ * compatibility with device-tree that does not have TCM information.
  */
 static const struct mem_bank_data zynqmp_tcm_banks_split[] = {
{0xffe0UL, 0x0, 0x1UL, PD_R5_0_ATCM, "atcm0"}, /* TCM 64KB each 
*/
@@ -613,7 +613,8 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc)
 bank_name);
if (!rproc_mem) {
ret = -ENOMEM;
-   zynqmp_pm_release_node(pm_domain_id);
+   if (pm_domain_id)
+   zynqmp_pm_release_node(pm_domain_id);
goto release_tcm_split;
}
 
@@ -626,7 +627,8 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc)
/* If failed, Turn off all TCM banks turned on before */
for (i--; i >= 0; i--) {
pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id;
-   zynqmp_pm_release_node(pm_domain_id);
+   if (pm_domain_id)
+   zynqmp_pm_release_node(pm_domain_id);
}
return ret;
 }
@@ -940,6 +942,8 @@ static int zynqmp_r5_add_pm_domains(struct rproc *rproc)
}
}
 
+   return 0;
+
 fail_add_pm_domains_lockstep:
while (j >= 1) {
if (r5_core->pm_dev_link2 && 
!IS_ERR_OR_NULL(r5_core->pm_dev_link2[j]))
@@ -1102,6 +1106,83 @@ static struct zynqmp_r5_core 
*zynqmp_r5_add_rproc_core(struct device *cdev)
return ERR_PTR(ret);
 }
 
+static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
+{
+   struct zynqmp_r5_core *r5_core;
+   int i, j, tcm_bank_count, ret;
+   struct platform_device *cpdev;
+   struct mem_bank_data *tcm;
+   struct device_node *np;
+   struct resource *res;
+   u64 abs_addr, size;
+   struct device *dev;
+
+   for (i = 0; i < cluster->core_count; i++) {
+   r5_core = cluster->r5_cores[i];
+   dev = r5_core->dev;
+   np = dev_of_node(dev);
+
+   /* we have address cell 2 and size cell as 2 */
+   ret = of_property_count_elems_of_size(np, "reg",
+ 4 * sizeof(u32));
+   if (ret <= 0) {
+   dev_err(dev, "can't get reg property err %d\n", ret);
+   return -EINVAL;
+   }
+
+   tcm_bank_count = ret;
+
+   r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count,
+ sizeof(struct mem_bank_data 
*),
+ GFP_KERNEL);
+   if (!r5_core->tcm_banks)
+   ret = -ENOMEM;
+
+   r5_core->tcm_bank_count = tcm_bank_count;
+   for (j = 0; j < tcm_bank_count; j++) {
+   tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data *),
+  GFP_KERNEL);
+   if (!tcm)
+   return -ENOMEM;
+
+   r5_core->tcm_banks[j] = tcm;
+
+   /* get tcm address without translation */
+   ret = of_property_read_reg(np, j, _addr, );
+   if (ret) {
+   dev_err(dev, "failed to get reg property\n");
+   return ret;
+   }
+
+   /*
+* remote processor can address only 32 bits
+* so convert 64-bits into 32-bits. This will discard
+* any unwanted upper 32-bits.
+*/
+   tcm->da = (u32)abs_addr;
+   tcm->size = (u32)size;
+
+   cpdev = to_platform_device(dev);
+