Re: [U-Boot] [PATCH v2 02/26] remoteproc: ops: Add elf section size as input parameter to device_to_virt api

2019-10-12 Thread Tom Rini
On Wed, Sep 04, 2019 at 04:01:27PM +0530, Lokesh Vutla wrote:

> Introduce a new parameter "size" that accepts size of the region to
> remoteproc ops callback device_to_virt(). This can enforce more checks
> on the region that device_to_virt() is dealing with.
> 
> Signed-off-by: Lokesh Vutla 
> Tested-by: Fabien Dessenne 
> Reviewed-by: Fabien Dessenne 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 02/26] remoteproc: ops: Add elf section size as input parameter to device_to_virt api

2019-09-04 Thread Fabien DESSENNE
Hi Lokesh


I have successfully tested this patch for stm32_copro.

BR

Fabien



On 04/09/2019 12:31 PM, Lokesh Vutla wrote:
> Introduce a new parameter "size" that accepts size of the region to
> remoteproc ops callback device_to_virt(). This can enforce more checks
> on the region that device_to_virt() is dealing with.
>
> Signed-off-by: Lokesh Vutla 

Tested-by: Fabien Dessenne 

Reviewed-by: Fabien Dessenne 

> ---
>   drivers/remoteproc/rproc-elf-loader.c |  3 ++-
>   drivers/remoteproc/sandbox_testproc.c |  4 +++-
>   drivers/remoteproc/stm32_copro.c  | 12 ++--
>   include/remoteproc.h  |  3 ++-
>   4 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/remoteproc/rproc-elf-loader.c 
> b/drivers/remoteproc/rproc-elf-loader.c
> index 67937a7595..7574ba3fb3 100644
> --- a/drivers/remoteproc/rproc-elf-loader.c
> +++ b/drivers/remoteproc/rproc-elf-loader.c
> @@ -86,7 +86,8 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned 
> long addr)
>   continue;
>   
>   if (ops->device_to_virt)
> - dst = ops->device_to_virt(dev, (ulong)dst);
> + dst = ops->device_to_virt(dev, (ulong)dst,
> +   phdr->p_memsz);
>   
>   dev_dbg(dev, "Loading phdr %i to 0x%p (%i bytes)\n",
>   i, dst, phdr->p_filesz);
> diff --git a/drivers/remoteproc/sandbox_testproc.c 
> b/drivers/remoteproc/sandbox_testproc.c
> index 5f35119ab7..49c4dd 100644
> --- a/drivers/remoteproc/sandbox_testproc.c
> +++ b/drivers/remoteproc/sandbox_testproc.c
> @@ -306,9 +306,11 @@ static int sandbox_testproc_ping(struct udevice *dev)
>* sandbox_testproc_device_to_virt() - Convert device address to virtual 
> address
>* @dev:device to operate upon
>* @da: device address
> + * @size:Size of the memory region @da is pointing to
>* @return converted virtual address
>*/
> -static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da)
> +static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da,
> +  ulong size)
>   {
>   u64 paddr;
>   
> diff --git a/drivers/remoteproc/stm32_copro.c 
> b/drivers/remoteproc/stm32_copro.c
> index ad941f67e8..71895daf9c 100644
> --- a/drivers/remoteproc/stm32_copro.c
> +++ b/drivers/remoteproc/stm32_copro.c
> @@ -107,11 +107,13 @@ static int stm32_copro_set_hold_boot(struct udevice 
> *dev, bool hold)
>* stm32_copro_device_to_virt() - Convert device address to virtual address
>* @dev:corresponding STM32 remote processor device
>* @da: device address
> + * @size:Size of the memory region @da is pointing to
>* @return converted virtual address
>*/
> -static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da)
> +static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da,
> + ulong size)
>   {
> - fdt32_t in_addr = cpu_to_be32(da);
> + fdt32_t in_addr = cpu_to_be32(da), end_addr;
>   u64 paddr;
>   
>   paddr = dev_translate_dma_address(dev, _addr);
> @@ -120,6 +122,12 @@ static void *stm32_copro_device_to_virt(struct udevice 
> *dev, ulong da)
>   return NULL;
>   }
>   
> + end_addr = cpu_to_be32(da + size - 1);
> + if (dev_translate_dma_address(dev, _addr) == OF_BAD_ADDR) {
> + dev_err(dev, "Unable to convert address %ld\n", da + size - 1);
> + return NULL;
> + }
> +
>   return phys_to_virt(paddr);
>   }
>   
> diff --git a/include/remoteproc.h b/include/remoteproc.h
> index 4987194905..dbff1ce3cf 100644
> --- a/include/remoteproc.h
> +++ b/include/remoteproc.h
> @@ -122,9 +122,10 @@ struct dm_rproc_ops {
>*
>* @dev:Remote proc device
>* @da: Device address
> +  * @size:   Size of the memory region @da is pointing to
>* @return virtual address.
>*/
> - void * (*device_to_virt)(struct udevice *dev, ulong da);
> + void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size);
>   };
>   
>   /* Accessor */
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 02/26] remoteproc: ops: Add elf section size as input parameter to device_to_virt api

2019-09-04 Thread Lokesh Vutla
Introduce a new parameter "size" that accepts size of the region to
remoteproc ops callback device_to_virt(). This can enforce more checks
on the region that device_to_virt() is dealing with.

Signed-off-by: Lokesh Vutla 
---
 drivers/remoteproc/rproc-elf-loader.c |  3 ++-
 drivers/remoteproc/sandbox_testproc.c |  4 +++-
 drivers/remoteproc/stm32_copro.c  | 12 ++--
 include/remoteproc.h  |  3 ++-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/remoteproc/rproc-elf-loader.c 
b/drivers/remoteproc/rproc-elf-loader.c
index 67937a7595..7574ba3fb3 100644
--- a/drivers/remoteproc/rproc-elf-loader.c
+++ b/drivers/remoteproc/rproc-elf-loader.c
@@ -86,7 +86,8 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long 
addr)
continue;
 
if (ops->device_to_virt)
-   dst = ops->device_to_virt(dev, (ulong)dst);
+   dst = ops->device_to_virt(dev, (ulong)dst,
+ phdr->p_memsz);
 
dev_dbg(dev, "Loading phdr %i to 0x%p (%i bytes)\n",
i, dst, phdr->p_filesz);
diff --git a/drivers/remoteproc/sandbox_testproc.c 
b/drivers/remoteproc/sandbox_testproc.c
index 5f35119ab7..49c4dd 100644
--- a/drivers/remoteproc/sandbox_testproc.c
+++ b/drivers/remoteproc/sandbox_testproc.c
@@ -306,9 +306,11 @@ static int sandbox_testproc_ping(struct udevice *dev)
  * sandbox_testproc_device_to_virt() - Convert device address to virtual 
address
  * @dev:   device to operate upon
  * @da:device address
+ * @size:  Size of the memory region @da is pointing to
  * @return converted virtual address
  */
-static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da)
+static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da,
+ulong size)
 {
u64 paddr;
 
diff --git a/drivers/remoteproc/stm32_copro.c b/drivers/remoteproc/stm32_copro.c
index ad941f67e8..71895daf9c 100644
--- a/drivers/remoteproc/stm32_copro.c
+++ b/drivers/remoteproc/stm32_copro.c
@@ -107,11 +107,13 @@ static int stm32_copro_set_hold_boot(struct udevice *dev, 
bool hold)
  * stm32_copro_device_to_virt() - Convert device address to virtual address
  * @dev:   corresponding STM32 remote processor device
  * @da:device address
+ * @size:  Size of the memory region @da is pointing to
  * @return converted virtual address
  */
-static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da)
+static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da,
+   ulong size)
 {
-   fdt32_t in_addr = cpu_to_be32(da);
+   fdt32_t in_addr = cpu_to_be32(da), end_addr;
u64 paddr;
 
paddr = dev_translate_dma_address(dev, _addr);
@@ -120,6 +122,12 @@ static void *stm32_copro_device_to_virt(struct udevice 
*dev, ulong da)
return NULL;
}
 
+   end_addr = cpu_to_be32(da + size - 1);
+   if (dev_translate_dma_address(dev, _addr) == OF_BAD_ADDR) {
+   dev_err(dev, "Unable to convert address %ld\n", da + size - 1);
+   return NULL;
+   }
+
return phys_to_virt(paddr);
 }
 
diff --git a/include/remoteproc.h b/include/remoteproc.h
index 4987194905..dbff1ce3cf 100644
--- a/include/remoteproc.h
+++ b/include/remoteproc.h
@@ -122,9 +122,10 @@ struct dm_rproc_ops {
 *
 * @dev:Remote proc device
 * @da: Device address
+* @size:   Size of the memory region @da is pointing to
 * @return virtual address.
 */
-   void * (*device_to_virt)(struct udevice *dev, ulong da);
+   void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size);
 };
 
 /* Accessor */
-- 
2.22.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot