Skip to contentSkip to conversation

staging: media: starfive: Add multiple resolution support

PATCH Superseded Changhuang Liang 3 participants 14 messages Apr 19, 2024 – Aug 23, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: media: starfive: Add multiple resolution support

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add capture driver")
---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +4 -1
index ec5169e7b391..9e853ff2596a 100644
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video *video)
 {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);
 
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);
 	} else if (cap->type == STF_CAPTURE_YUV) {

--
2.25.1

#1 lore raw

Hi, Hans

Quoted 3 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Can you help to review this patch, Thanks for your times.

Regards,
Changhuang

Quoted 38 lines
Fixes e080f339c80a ("media: staging: media: starfive: camss: Add capture

driver")

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +4 -1
index ec5169e7b391..9e853ff2596a 100644
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video
 *video)  {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video
 *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);
 
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);

} else if (cap->type == STF_CAPTURE_YUV) {
--
2.25.1

#2 lore raw
Quoted 7 lines · Changhuang Liang

Hi, Hans

Quoted 3 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Can you help to review this patch, Thanks for your times.

Patch looks OK, it will be part of my next 'various fixes' Pull Request.

Regards,

Hans

Quoted 42 lines

Regards,
Changhuang

Quoted 38 lines
Fixes e080f339c80a ("media: staging: media: starfive: camss: Add capture

driver")

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +4 -1
index ec5169e7b391..9e853ff2596a 100644
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video
 *video)  {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video
 *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);
 
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);

} else if (cap->type == STF_CAPTURE_YUV) {
--
2.25.1

#3 lore raw
In reply to Changhuang Liang

Hi Changhuang,

Thank you for the patch.

Quoted 15 lines · Changhuang Liang

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add capture driver")
---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 180

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video *video)
 {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 184

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 10 lines
drivers/staging/media/starfive/camss/stf-capture.c +2 -1
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);
 	} else if (cap->type == STF_CAPTURE_YUV) {
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Hi, Laurent

Thanks for your comments.

Quoted 44 lines

Hi Changhuang,

Thank you for the patch.

Quoted 17 lines · Changhuang Liang

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add

capture driver")

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video · line 180

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video
 *video)  {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 184

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video

Quoted 5 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video

*video)

Quoted 9 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 5 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -1
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

Ragards,
Changhuang

Quoted 8 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 202

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);
 	} else if (cap->type == STF_CAPTURE_YUV) {

--
Regards,

Laurent Pinchart

#5 lore raw
Quoted 56 lines · Changhuang Liang

Hi, Laurent

Thanks for your comments.

Quoted 45 lines

Hi Changhuang,

Thank you for the patch.

Quoted 17 lines · Changhuang Liang

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add

capture driver")

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video · line 180

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video
 *video)  {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 184

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;
Quoted 7 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
Quoted 6 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -1
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Quoted 2 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);
 	} else if (cap->type == STF_CAPTURE_YUV) {
Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

Hi, Laurent

Quoted 62 lines · Changhuang Liang
Quoted 42 lines

Hi, Laurent

Thanks for your comments.

Quoted 38 lines

Hi Changhuang,

Thank you for the patch.

Quoted 20 lines · Changhuang Liang

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add

capture driver")

Signed-off-by: Changhuang Liang
<[email protected]>

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
index ec5169e7b391..9e853ff2596a 100644
@@ -177,9 +177,12 @@ static void stf_channel_set(struct

stfcamss_video
*video) {

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 180

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 184

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

Quoted 7 lines
Quoted 7 lines
		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct

Quoted 5 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct

stfcamss_video *video)

Quoted 8 lines
Quoted 8 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 5 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -1
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than

expected ?

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

The hardware can confirm the image height by using the VSYNC signal.

Image will transfer when VSYNC is high.

VSYNC time = (width + h_blank) * height;

Regards,
Changhuang

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 202

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);
 	} else if (cap->type == STF_CAPTURE_YUV) {

--
Regards,

Laurent Pinchart

#7 lore raw

Hi Changhuang,

Quoted 59 lines · Changhuang Liang
Quoted 51 lines · Changhuang Liang
Quoted 50 lines
Quoted 49 lines · Changhuang Liang
Quoted 20 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add

capture driver")

Signed-off-by: Changhuang Liang
<[email protected]>

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
index ec5169e7b391..9e853ff2596a 100644
@@ -177,9 +177,12 @@ static void stf_channel_set(struct

stfcamss_video
*video) {

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 180

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 184

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 10 lines
drivers/staging/media/starfive/camss/stf-capture.c +2 -1
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Quoted 7 lines
Quoted 2 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

Quoted 5 lines

The hardware can confirm the image height by using the VSYNC signal.

Image will transfer when VSYNC is high.

VSYNC time = (width + h_blank) * height;

What I'm trying to understand is what happens if the ISP is configured for 1080 lines, but the camera sensor sends more than 1080 lines (the VSYNC signal is active for more than 1080 lines). Where in the driver is the hardware configure with the 1080 lines limit to avoid buffer overflows ?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		stf_syscon_reg_write(stfcamss, VIN_INRT_PIX_CFG, val);
 	} else if (cap->type == STF_CAPTURE_YUV) {
Signature · 3 lines
Regards,

Laurent Pinchart
#8 lore raw

Hi, Laurent

Quoted 71 lines

Hi Changhuang,

Quoted 4 lines · Changhuang Liang
Quoted 4 lines · Changhuang Liang
Quoted 3 lines
Quoted 3 lines · Changhuang Liang
Quoted 2 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not

1920.

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 19 lines
Fixes e080f339c80a ("media: staging: media: starfive: camss:

Add capture driver")

Signed-off-by: Changhuang Liang
<[email protected]>

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c +0 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct

stfcamss_video
*video) {

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 180

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 184

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

const struct v4l2_pix_format *pix =
&video->active_fmt.fmt.pix;

Quoted 2 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
+
 		val = stf_syscon_reg_read(stfcamss,

VIN_CHANNEL_SEL_EN);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct

stfcamss_video *video)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 5 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -1
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than

expected ?

Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

The hardware can confirm the image height by using the VSYNC signal.

Quoted 9 lines
Quoted 3 lines

Image will transfer when VSYNC is high.

VSYNC time = (width + h_blank) * height;

What I'm trying to understand is what happens if the ISP is configured for 1080 lines, but the camera sensor sends more than 1080 lines (the VSYNC signal is active for more than 1080 lines). Where in the driver is the hardware configure with the 1080 lines limit to avoid buffer overflows ?

If is "capture_raw" video device, no image height can be configured. If is "capture_yuv" video device, it will be set by stf_isp_config_crop.

Regards,
Changhuang

#9 lore raw
Quoted 66 lines · Changhuang Liang
Quoted 66 lines · Changhuang Liang
Quoted 65 lines
Quoted 53 lines · Changhuang Liang
Quoted 52 lines
Quoted 51 lines · Changhuang Liang
Quoted 21 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss:

Add capture driver")

Signed-off-by: Changhuang Liang
<[email protected]>

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c +0 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct

stfcamss_video
*video) {

drivers/staging/media/starfive/camss/stf-capture.c

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

const struct v4l2_pix_format *pix =
&video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 10 lines
drivers/staging/media/starfive/camss/stf-capture.c +2 -1
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does
the driver prevent buffer overflows if the sensor sends more data than expected ?

Quoted 7 lines
Quoted 2 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

The hardware can confirm the image height by using the VSYNC signal.

Image will transfer when VSYNC is high.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

VSYNC time = (width + h_blank) * height;

What I'm trying to understand is what happens if the ISP is configured for 1080 lines, but the camera sensor sends more than 1080 lines (the VSYNC signal is active for more than 1080 lines). Where in the driver is the hardware configure with the 1080 lines limit to avoid buffer overflows ?

If is "capture_raw" video device, no image height can be configured.

In that case what happens if the camera sensor sends more lines than expected ? Will the raw video device write past the end of the buffer ? If so, is there a way to guard against that ?

Quoted 1 line

If is "capture_yuv" video device, it will be set by stf_isp_config_crop.

Thank you, that's the information I was looking for.

Signature · 3 lines
Regards,

Laurent Pinchart
#10 lore raw

Hi, Lanrent

Quoted 81 lines · Changhuang Liang
Quoted 3 lines
Quoted 3 lines · Changhuang Liang
Quoted 2 lines
Quoted 2 lines · Changhuang Liang
Quoted 1 line
Quoted 1 line

On Fri, Apr 19, 2024 at 01:19:55AM -0700, Changhuang Liang

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not

1920.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 20 lines
Fixes e080f339c80a ("media: staging: media: starfive: camss:

Add capture driver")

Signed-off-by: Changhuang Liang
<[email protected]>

---
 drivers/staging/media/starfive/camss/stf-capture.c | 5
++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c +0 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct

stfcamss_video
*video) {

drivers/staging/media/starfive/camss/stf-capture.c

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

const struct v4l2_pix_format *pix =
&video->active_fmt.fmt.pix;

Quoted 2 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
+
 		val = stf_syscon_reg_read(stfcamss,

VIN_CHANNEL_SEL_EN);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +0 -0
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct

stfcamss_video *video)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct · line 199

Quoted 5 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -1
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more

data than expected ?

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
Quoted 3 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

The hardware can confirm the image height by using the VSYNC signal.

Image will transfer when VSYNC is high.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

VSYNC time = (width + h_blank) * height;

What I'm trying to understand is what happens if the ISP is configured for
1080 lines, but the camera sensor sends more than 1080 lines (the VSYNC signal is active for more than 1080 lines). Where in the driver is the hardware configure with the 1080 lines limit to avoid buffer

Quoted 6 lines

overflows ?

Quoted 2 lines

If is "capture_raw" video device, no image height can be configured.

In that case what happens if the camera sensor sends more lines than expected ? Will the raw video device write past the end of the buffer ?

Yes, the buffer will overflows, so we will use the software restrictions. Implement .link_validate hooks for the CSI2RX subdev and "capture_raw" video device.

Quoted 6 lines

If so, is there a way to guard against that ?

Quoted 1 line

If is "capture_yuv" video device, it will be set by stf_isp_config_crop.

Thank you, that's the information I was looking for.

Regards,
Changhuang

#11 lore raw
Quoted 70 lines · Changhuang Liang
Quoted 70 lines · Changhuang Liang
Quoted 69 lines
Quoted 68 lines · Changhuang Liang
Quoted 57 lines
Quoted 49 lines · Changhuang Liang
Quoted 48 lines
Quoted 47 lines · Changhuang Liang
Quoted 17 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add capture driver")
---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) { · line 179

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video *video)  {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) { · line 183

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 10 lines
drivers/staging/media/starfive/camss/stf-capture.c +2 -1
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Quoted 7 lines
Quoted 2 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

Quoted 5 lines

The hardware can confirm the image height by using the VSYNC signal.

Image will transfer when VSYNC is high.

VSYNC time = (width + h_blank) * height;

What I'm trying to understand is what happens if the ISP is configured for 1080 lines, but the camera sensor sends more than 1080 lines (the
VSYNC signal is active for more than 1080 lines). Where in the
driver is the hardware configure with the 1080 lines limit to avoid buffer overflows ?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

If is "capture_raw" video device, no image height can be configured.

In that case what happens if the camera sensor sends more lines than expected ? Will the raw video device write past the end of the buffer ?

Yes, the buffer will overflows, so we will use the software restrictions. Implement .link_validate hooks for the CSI2RX subdev and "capture_raw" video device.

Is there an IOMMU in the system that could help preventing buffer overflows to reach system memory ?

Quoted 5 lines
Quoted 5 lines

If so, is there a way to guard against that ?

Quoted 1 line

If is "capture_yuv" video device, it will be set by stf_isp_config_crop.

Thank you, that's the information I was looking for.

Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

Hi, Laurent

Quoted 95 lines · Changhuang Liang
Quoted 2 lines
Quoted 2 lines · Changhuang Liang
Quoted 1 line
Quoted 1 line

On Mon, Aug 12, 2024 at 09:43:47AM +0000, Changhuang Liang

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On Fri, Aug 09, 2024 at 12:12:01PM +0000, Changhuang Liang

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On Fri, Apr 19, 2024 at 01:19:55AM -0700, Changhuang Liang

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Add multiple resolution support for video "capture_raw"

device.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Otherwise it will capture the wrong image data if the width is

not 1920.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Fixes e080f339c80a ("media: staging: media: starfive:

camss: Add capture driver")

Signed-off-by: Changhuang Liang <[email protected]>
---
drivers/staging/media/starfive/camss/stf-capture.c |
5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review static void stf_channel_set(struct

Quoted 9 lines

diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..9e853ff2596a 100644
---
a/drivers/staging/media/starfive/camss/stf-capture.c +++ b/drivers/staging/media/starfive/camss/stf-capture +++ .c

(quoted diff) +0 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct

stfcamss_video *video) {

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Review static void stf_channel_set(struct · line 179

Quoted 3 lines
(quoted diff) +1 -0
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

Review static void stf_channel_set(struct · line 183

Quoted 4 lines
(quoted diff) +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

const struct v4l2_pix_format *pix =
&video->active_fmt.fmt.pix;

Quoted 2 lines
(quoted diff) +1 -0
+
 		val = stf_syscon_reg_read(stfcamss,

VIN_CHANNEL_SEL_EN);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review static void stf_channel_set(struct

Quoted 3 lines
(quoted diff) +0 -0
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct

stfcamss_video *video)

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines

Review static void stf_channel_set(struct · line 199

Quoted 5 lines
(quoted diff) +1 -1
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

What happens if the system expects, for instance, a 1920x1080
RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

The hardware can confirm the image height by using the VSYNC

signal.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

Image will transfer when VSYNC is high.

VSYNC time = (width + h_blank) * height;

What I'm trying to understand is what happens if the ISP is configured for
1080 lines, but the camera sensor sends more than 1080 lines (the VSYNC signal is active for more than 1080 lines). Where in the driver is the hardware configure with the 1080 lines limit to avoid

buffer overflows ?

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

If is "capture_raw" video device, no image height can be configured.

In that case what happens if the camera sensor sends more lines than expected ? Will the raw video device write past the end of the buffer ?

Quoted 7 lines
Quoted 2 lines

Yes, the buffer will overflows, so we will use the software restrictions. Implement .link_validate hooks for the CSI2RX subdev and "capture_raw"

video device.

Is there an IOMMU in the system that could help preventing buffer overflows to reach system memory ?

JH7110 SoC has no IOMMU.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

If so, is there a way to guard against that ?

Quoted 1 line

If is "capture_yuv" video device, it will be set by stf_isp_config_crop.

Thank you, that's the information I was looking for.

--

Regards,
Changhuang

#13 lore raw
Quoted 77 lines · Changhuang Liang
Quoted 77 lines · Changhuang Liang
Quoted 76 lines
Quoted 75 lines · Changhuang Liang
Quoted 64 lines
Quoted 64 lines · Changhuang Liang
Quoted 62 lines
Quoted 49 lines · Changhuang Liang
Quoted 48 lines
Quoted 47 lines · Changhuang Liang
Quoted 17 lines

Add multiple resolution support for video "capture_raw" device. Otherwise it will capture the wrong image data if the width is not 1920.

Fixes e080f339c80a ("media: staging: media: starfive: camss: Add capture driver")
---
 drivers/staging/media/starfive/camss/stf-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..9e853ff2596a 100644

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) { · line 179

Quoted 3 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
@@ -177,9 +177,12 @@ static void stf_channel_set(struct stfcamss_video *video)  {
 	struct stf_capture *cap = to_stf_capture(video);
 	struct stfcamss *stfcamss = cap->video.stfcamss;
+	struct v4l2_pix_format *pix;

This variable can be const as you don't modify the format.

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) { · line 183

Quoted 4 lines
drivers/staging/media/starfive/camss/stf-capture.c +1 -0
 	u32 val;
 
 	if (cap->type == STF_CAPTURE_RAW) {
+		pix = &video->active_fmt.fmt.pix;

And it can be declared and initialized here:

		const struct v4l2_pix_format *pix = &video->active_fmt.fmt.pix;

drivers/staging/media/starfive/camss/stf-capture.c static void stf_channel_set(struct stfcamss_video *video) · line 199

Quoted 10 lines
drivers/staging/media/starfive/camss/stf-capture.c +2 -1
+
 		val = stf_syscon_reg_read(stfcamss, VIN_CHANNEL_SEL_EN);
 		val &= ~U0_VIN_CHANNEL_SEL_MASK;
 		val |= CHANNEL(0);
@@ -193,7 +196,7 @@ static void stf_channel_set(struct stfcamss_video *video)
 		val |= PIXEL_HEIGH_BIT_SEL(0);
 
 		val &= ~U0_VIN_PIX_CNT_END_MASK;
-		val |= PIX_CNT_END(IMAGE_MAX_WIDTH / 4 - 1);
+		val |= PIX_CNT_END(pix->width / 4 - 1);

Is there no need to consider the image height as well ? How does the driver prevent buffer overflows if the sensor sends more data than expected ?

Quoted 7 lines
Quoted 2 lines

Our hardware will confirm a frame of data through vblank signal, so there is no image height configuration.

What happens if the system expects, for instance, a 1920x1080 RAW8 image, and allocates a buffer of of 1920x1080 bytes, but the sensor outputs more lines ? Does the camera hardware in the SoC offer an option to prevent buffer overruns ?

The hardware can confirm the image height by using the VSYNC signal.

Image will transfer when VSYNC is high.

VSYNC time = (width + h_blank) * height;

Quoted 7 lines
Quoted 5 lines

What I'm trying to understand is what happens if the ISP is configured for 1080 lines, but the camera sensor sends more than 1080 lines (the VSYNC signal is active for more than 1080 lines). Where in the driver is the hardware configure with the 1080 lines
limit to avoid buffer overflows ?

If is "capture_raw" video device, no image height can be configured.

In that case what happens if the camera sensor sends more lines than expected ? Will the raw video device write past the end of the buffer ?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Yes, the buffer will overflows, so we will use the software restrictions. Implement .link_validate hooks for the CSI2RX subdev and "capture_raw" video device.

Is there an IOMMU in the system that could help preventing buffer overflows to reach system memory ?

JH7110 SoC has no IOMMU.

Thank you for the information.

Based on this, the best we can do is hoping that the video source will never send more lines than expected. In most cases there will be no issue, but signal glitches or other hardware glitches on the sensor side may cause memory corruption. That sounds like a worrying hardware vulnerability :-(

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

If so, is there a way to guard against that ?

Quoted 1 line

If is "capture_yuv" video device, it will be set by stf_isp_config_crop.

Thank you, that's the information I was looking for.

Signature · 3 lines
Regards,

Laurent Pinchart