[PATCH] media: pisp_be: Use clamp() and define max sizes

Jacopo Mondi posted 1 patch 3 months, 1 week ago
drivers/media/platform/raspberrypi/pisp_be/pisp_be.c  | 11 +++++++----
include/uapi/linux/media/raspberrypi/pisp_be_config.h |  9 +++++----
2 files changed, 12 insertions(+), 8 deletions(-)
[PATCH] media: pisp_be: Use clamp() and define max sizes
Posted by Jacopo Mondi 3 months, 1 week ago
Use the clamp() from minmax.h and provide a define for the max size as
they will be used in sequent patches.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 drivers/media/platform/raspberrypi/pisp_be/pisp_be.c  | 11 +++++++----
 include/uapi/linux/media/raspberrypi/pisp_be_config.h |  9 +++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
index 7596ae1f7de6671484d4d351015b234829f642d4..ac5840b4be478ccdd7da9d6d0745649e0c1b2b6f 100644
--- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
+++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
@@ -9,6 +9,7 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/lockdep.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -1114,10 +1115,12 @@ static void pispbe_try_format(struct v4l2_format *f, struct pispbe_node *node)
 	f->fmt.pix_mp.pixelformat = fmt->fourcc;
 	f->fmt.pix_mp.num_planes = fmt->num_planes;
 	f->fmt.pix_mp.field = V4L2_FIELD_NONE;
-	f->fmt.pix_mp.width = max(min(f->fmt.pix_mp.width, 65536u),
-				  PISP_BACK_END_MIN_TILE_WIDTH);
-	f->fmt.pix_mp.height = max(min(f->fmt.pix_mp.height, 65536u),
-				   PISP_BACK_END_MIN_TILE_HEIGHT);
+	f->fmt.pix_mp.width = clamp(f->fmt.pix_mp.width,
+				    PISP_BACK_END_MIN_TILE_WIDTH,
+				    PISP_BACK_END_MAX_TILE_WIDTH);
+	f->fmt.pix_mp.height = clamp(f->fmt.pix_mp.height,
+				     PISP_BACK_END_MIN_TILE_HEIGHT,
+				     PISP_BACK_END_MAX_TILE_HEIGHT);
 
 	/*
 	 * Fill in the actual colour space when the requested one was
diff --git a/include/uapi/linux/media/raspberrypi/pisp_be_config.h b/include/uapi/linux/media/raspberrypi/pisp_be_config.h
index cbeb714f4d61ad53162c0450f2303431a5958040..2ad3b90684d7be80776af75b5c5009f7b677f466 100644
--- a/include/uapi/linux/media/raspberrypi/pisp_be_config.h
+++ b/include/uapi/linux/media/raspberrypi/pisp_be_config.h
@@ -21,10 +21,11 @@
 /* preferred byte alignment for outputs */
 #define PISP_BACK_END_OUTPUT_MAX_ALIGN 64u
 
-/* minimum allowed tile width anywhere in the pipeline */
-#define PISP_BACK_END_MIN_TILE_WIDTH 16u
-/* minimum allowed tile width anywhere in the pipeline */
-#define PISP_BACK_END_MIN_TILE_HEIGHT 16u
+/* minimum allowed tile sizes anywhere in the pipeline */
+#define PISP_BACK_END_MIN_TILE_WIDTH	16u
+#define PISP_BACK_END_MIN_TILE_HEIGHT	16u
+#define PISP_BACK_END_MAX_TILE_WIDTH	65536u
+#define PISP_BACK_END_MAX_TILE_HEIGHT	65536u
 
 #define PISP_BACK_END_NUM_OUTPUTS 2
 #define PISP_BACK_END_HOG_OUTPUT 1

---
base-commit: 35392e855abf7d02ad3b061cbc75c7c7c37f0577
change-id: 20250623-pispbe-clamp-4b33011d0e85

Best regards,
-- 
Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Re: [PATCH] media: pisp_be: Use clamp() and define max sizes
Posted by Stefan Klug 3 months, 1 week ago
Hi Jacopo,

Thank you for the patch. 

Quoting Jacopo Mondi (2025-07-01 10:55:05)
> Use the clamp() from minmax.h and provide a define for the max size as
> they will be used in sequent patches.

nit-picking: I believe either "Use clamp() from" or "Use the clamp() function
from"

> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

> ---
>  drivers/media/platform/raspberrypi/pisp_be/pisp_be.c  | 11 +++++++----
>  include/uapi/linux/media/raspberrypi/pisp_be_config.h |  9 +++++----
>  2 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> index 7596ae1f7de6671484d4d351015b234829f642d4..ac5840b4be478ccdd7da9d6d0745649e0c1b2b6f 100644
> --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> @@ -9,6 +9,7 @@
>  #include <linux/io.h>
>  #include <linux/kernel.h>
>  #include <linux/lockdep.h>
> +#include <linux/minmax.h>
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> @@ -1114,10 +1115,12 @@ static void pispbe_try_format(struct v4l2_format *f, struct pispbe_node *node)
>         f->fmt.pix_mp.pixelformat = fmt->fourcc;
>         f->fmt.pix_mp.num_planes = fmt->num_planes;
>         f->fmt.pix_mp.field = V4L2_FIELD_NONE;
> -       f->fmt.pix_mp.width = max(min(f->fmt.pix_mp.width, 65536u),
> -                                 PISP_BACK_END_MIN_TILE_WIDTH);
> -       f->fmt.pix_mp.height = max(min(f->fmt.pix_mp.height, 65536u),
> -                                  PISP_BACK_END_MIN_TILE_HEIGHT);
> +       f->fmt.pix_mp.width = clamp(f->fmt.pix_mp.width,
> +                                   PISP_BACK_END_MIN_TILE_WIDTH,
> +                                   PISP_BACK_END_MAX_TILE_WIDTH);
> +       f->fmt.pix_mp.height = clamp(f->fmt.pix_mp.height,
> +                                    PISP_BACK_END_MIN_TILE_HEIGHT,
> +                                    PISP_BACK_END_MAX_TILE_HEIGHT);
>  
>         /*
>          * Fill in the actual colour space when the requested one was
> diff --git a/include/uapi/linux/media/raspberrypi/pisp_be_config.h b/include/uapi/linux/media/raspberrypi/pisp_be_config.h
> index cbeb714f4d61ad53162c0450f2303431a5958040..2ad3b90684d7be80776af75b5c5009f7b677f466 100644
> --- a/include/uapi/linux/media/raspberrypi/pisp_be_config.h
> +++ b/include/uapi/linux/media/raspberrypi/pisp_be_config.h
> @@ -21,10 +21,11 @@
>  /* preferred byte alignment for outputs */
>  #define PISP_BACK_END_OUTPUT_MAX_ALIGN 64u
>  
> -/* minimum allowed tile width anywhere in the pipeline */
> -#define PISP_BACK_END_MIN_TILE_WIDTH 16u
> -/* minimum allowed tile width anywhere in the pipeline */
> -#define PISP_BACK_END_MIN_TILE_HEIGHT 16u
> +/* minimum allowed tile sizes anywhere in the pipeline */
> +#define PISP_BACK_END_MIN_TILE_WIDTH   16u
> +#define PISP_BACK_END_MIN_TILE_HEIGHT  16u
> +#define PISP_BACK_END_MAX_TILE_WIDTH   65536u
> +#define PISP_BACK_END_MAX_TILE_HEIGHT  65536u
>  
>  #define PISP_BACK_END_NUM_OUTPUTS 2
>  #define PISP_BACK_END_HOG_OUTPUT 1
> 
> ---
> base-commit: 35392e855abf7d02ad3b061cbc75c7c7c37f0577
> change-id: 20250623-pispbe-clamp-4b33011d0e85
> 
> Best regards,
> -- 
> Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
>
Re: [PATCH] media: pisp_be: Use clamp() and define max sizes
Posted by Dan Scally 3 months, 1 week ago
Hi Jacopo, thanks for the patch

On 01/07/2025 09:55, Jacopo Mondi wrote:
> Use the clamp() from minmax.h and provide a define for the max size as
> they will be used in sequent patches.

s/sequent/subsequent


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>   drivers/media/platform/raspberrypi/pisp_be/pisp_be.c  | 11 +++++++----
>   include/uapi/linux/media/raspberrypi/pisp_be_config.h |  9 +++++----
>   2 files changed, 12 insertions(+), 8 deletions(-)
>
>
> ---
> base-commit: 35392e855abf7d02ad3b061cbc75c7c7c37f0577
> change-id: 20250623-pispbe-clamp-4b33011d0e85
>
> Best regards,
>
> diff --git a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> index 7596ae1f7de6671484d4d351015b234829f642d4..ac5840b4be478ccdd7da9d6d0745649e0c1b2b6f 100644
> --- a/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
> @@ -9,6 +9,7 @@
>   #include <linux/io.h>
>   #include <linux/kernel.h>
>   #include <linux/lockdep.h>
> +#include <linux/minmax.h>
>   #include <linux/module.h>
>   #include <linux/platform_device.h>
>   #include <linux/pm_runtime.h>
> @@ -1114,10 +1115,12 @@ static void pispbe_try_format(struct v4l2_format *f, struct pispbe_node *node)
>   	f->fmt.pix_mp.pixelformat = fmt->fourcc;
>   	f->fmt.pix_mp.num_planes = fmt->num_planes;
>   	f->fmt.pix_mp.field = V4L2_FIELD_NONE;
> -	f->fmt.pix_mp.width = max(min(f->fmt.pix_mp.width, 65536u),
> -				  PISP_BACK_END_MIN_TILE_WIDTH);
> -	f->fmt.pix_mp.height = max(min(f->fmt.pix_mp.height, 65536u),
> -				   PISP_BACK_END_MIN_TILE_HEIGHT);
> +	f->fmt.pix_mp.width = clamp(f->fmt.pix_mp.width,
> +				    PISP_BACK_END_MIN_TILE_WIDTH,
> +				    PISP_BACK_END_MAX_TILE_WIDTH);
> +	f->fmt.pix_mp.height = clamp(f->fmt.pix_mp.height,
> +				     PISP_BACK_END_MIN_TILE_HEIGHT,
> +				     PISP_BACK_END_MAX_TILE_HEIGHT);
>   
>   	/*
>   	 * Fill in the actual colour space when the requested one was
> diff --git a/include/uapi/linux/media/raspberrypi/pisp_be_config.h b/include/uapi/linux/media/raspberrypi/pisp_be_config.h
> index cbeb714f4d61ad53162c0450f2303431a5958040..2ad3b90684d7be80776af75b5c5009f7b677f466 100644
> --- a/include/uapi/linux/media/raspberrypi/pisp_be_config.h
> +++ b/include/uapi/linux/media/raspberrypi/pisp_be_config.h
> @@ -21,10 +21,11 @@
>   /* preferred byte alignment for outputs */
>   #define PISP_BACK_END_OUTPUT_MAX_ALIGN 64u
>   
> -/* minimum allowed tile width anywhere in the pipeline */
> -#define PISP_BACK_END_MIN_TILE_WIDTH 16u
> -/* minimum allowed tile width anywhere in the pipeline */
> -#define PISP_BACK_END_MIN_TILE_HEIGHT 16u
> +/* minimum allowed tile sizes anywhere in the pipeline */
> +#define PISP_BACK_END_MIN_TILE_WIDTH	16u
> +#define PISP_BACK_END_MIN_TILE_HEIGHT	16u
> +#define PISP_BACK_END_MAX_TILE_WIDTH	65536u
> +#define PISP_BACK_END_MAX_TILE_HEIGHT	65536u
>   
>   #define PISP_BACK_END_NUM_OUTPUTS 2
>   #define PISP_BACK_END_HOG_OUTPUT 1