Skip to contentSkip to conversation

media: rkisp1: fix grey format iommu page faults

PATCH In review Dafna Hirschfeld 3 participants 7 messages Dec 7, 2021 – Jan 31, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: rkisp1: fix grey format iommu page faults

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

 .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----
 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +21 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
 		.fourcc = V4L2_PIX_FMT_GREY,
 		.uv_swap = 0,
 		.write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-		.output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+		.output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
 		.mbus = MEDIA_BUS_FMT_YUYV8_2X8,
 	},
 	/* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
 		rkisp1_write(cap->rkisp1,
 			     buff_addr[RKISP1_PLANE_Y],
 			     cap->config->mi.y_base_ad_init);
-		rkisp1_write(cap->rkisp1,
-			     buff_addr[RKISP1_PLANE_CB],
-			     cap->config->mi.cb_base_ad_init);
-		rkisp1_write(cap->rkisp1,
-			     buff_addr[RKISP1_PLANE_CR],
-			     cap->config->mi.cr_base_ad_init);
+		/*
+		 * In order to support grey format we capture
+		 * YUV422 planar format from the camera and
+		 * set the U and V planes to the dummy buffer
+		 */
+		if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+			rkisp1_write(cap->rkisp1,
+				     cap->buf.dummy.dma_addr,
+				     cap->config->mi.cb_base_ad_init);
+			rkisp1_write(cap->rkisp1,
+				     cap->buf.dummy.dma_addr,
+				     cap->config->mi.cr_base_ad_init);
+		} else {
+			rkisp1_write(cap->rkisp1,
+				     buff_addr[RKISP1_PLANE_CB],
+				     cap->config->mi.cb_base_ad_init);
+			rkisp1_write(cap->rkisp1,
+				     buff_addr[RKISP1_PLANE_CR],
+				     cap->config->mi.cr_base_ad_init);
+		}
 	} else {
 		/*
 		 * Use the dummy space allocated by dma_alloc_coherent to
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw

Hi Dafna,

Quoting Dafna Hirschfeld (2021-12-07 11:59:23)

Quoted 47 lines

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

 .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----
 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
                .fourcc = V4L2_PIX_FMT_GREY,
                .uv_swap = 0,
                .write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
                .mbus = MEDIA_BUS_FMT_YUYV8_2X8,
        },
        /* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
                rkisp1_write(cap->rkisp1,
                             buff_addr[RKISP1_PLANE_Y],
                             cap->config->mi.y_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CB],
-                            cap->config->mi.cb_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CR],
-                            cap->config->mi.cr_base_ad_init);
+               /*
+                * In order to support grey format we capture
+                * YUV422 planar format from the camera and
+                * set the U and V planes to the dummy buffer
+                */
+               if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c static void rkisp1_set_next_buf(struct rkisp1_capture *cap) · line 654

Quoted 10 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +9 -0
+                                    cap->config->mi.cr_base_ad_init);
+               } else {
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CB],
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CR],
+                                    cap->config->mi.cr_base_ad_init);
+               }
        } else {

Looking at this function, I think I would have initialised a local array of addresses (either to zero, or to the dummy address?) to then set values when appropriate, and reduce the number of calls to rkisp1_write() to a single set of three after the processing.

It might make the function simpler, and more readable, but it's more effort, and this does look like it will solve the greyscale format issue as discussed in earlier threads so I'd leave it up to you if you want to refactor.

Quoted 5 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +0 -0
                /*
                 * Use the dummy space allocated by dma_alloc_coherent to
Signature · 1 line
2.17.1
#2 lore raw
Quoted 66 lines · Kieran Bingham

Hi Dafna,

Quoting Dafna Hirschfeld (2021-12-07 11:59:23)

Quoted 47 lines

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

  .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----
  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
                 .fourcc = V4L2_PIX_FMT_GREY,
                 .uv_swap = 0,
                 .write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
                 .mbus = MEDIA_BUS_FMT_YUYV8_2X8,
         },
         /* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
                 rkisp1_write(cap->rkisp1,
                              buff_addr[RKISP1_PLANE_Y],
                              cap->config->mi.y_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CB],
-                            cap->config->mi.cb_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CR],
-                            cap->config->mi.cr_base_ad_init);
+               /*
+                * In order to support grey format we capture
+                * YUV422 planar format from the camera and
+                * set the U and V planes to the dummy buffer
+                */
+               if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c static void rkisp1_set_next_buf(struct rkisp1_capture *cap) · line 654

Quoted 10 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +9 -0
+                                    cap->config->mi.cr_base_ad_init);
+               } else {
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CB],
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CR],
+                                    cap->config->mi.cr_base_ad_init);
+               }
         } else {

Looking at this function, I think I would have initialised a local array of addresses (either to zero, or to the dummy address?) to then set values when appropriate, and reduce the number of calls to rkisp1_write() to a single set of three after the processing.

Quoted 4 lines

It might make the function simpler, and more readable, but it's more effort, and this does look like it will solve the greyscale format issue as discussed in earlier threads so I'd leave it up to you if you want to refactor.

Hi,
Yes, I'll do that.
Interestingly I found out that the patch causing the iommu page fault is

https://www.spinics.net/lists/linux-media/msg176089.html

Before that patch there are no iommu page faults but the video is corrupted.

I can't explain how I didn't find it before, I clearly remember testing the grey format.

Thanks,
Dafna

Quoted 9 lines
Quoted 5 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +0 -0
                 /*
                  * Use the dummy space allocated by dma_alloc_coherent to
Signature · 1 line
2.17.1
maintainer
#3 lore raw

Hi Dafna,

Quoted 74 lines · Dafna Hirschfeld
Quoted 64 lines · Kieran Bingham

Quoting Dafna Hirschfeld (2021-12-07 11:59:23)

Quoted 47 lines

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

  .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----
  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
                 .fourcc = V4L2_PIX_FMT_GREY,
                 .uv_swap = 0,
                 .write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
                 .mbus = MEDIA_BUS_FMT_YUYV8_2X8,
         },
         /* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
                 rkisp1_write(cap->rkisp1,
                              buff_addr[RKISP1_PLANE_Y],
                              cap->config->mi.y_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CB],
-                            cap->config->mi.cb_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CR],
-                            cap->config->mi.cr_base_ad_init);
+               /*
+                * In order to support grey format we capture
+                * YUV422 planar format from the camera and
+                * set the U and V planes to the dummy buffer
+                */
+               if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c static void rkisp1_set_next_buf(struct rkisp1_capture *cap) · line 654

Quoted 10 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +9 -0
+                                    cap->config->mi.cr_base_ad_init);
+               } else {
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CB],
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CR],
+                                    cap->config->mi.cr_base_ad_init);
+               }
         } else {

Looking at this function, I think I would have initialised a local array of addresses (either to zero, or to the dummy address?) to then set values when appropriate, and reduce the number of calls to rkisp1_write() to a single set of three after the processing.

Quoted 4 lines

It might make the function simpler, and more readable, but it's more effort, and this does look like it will solve the greyscale format issue as discussed in earlier threads so I'd leave it up to you if you want to refactor.

Hi,
Yes, I'll do that.
Interestingly I found out that the patch causing the iommu page fault is

Quoted 5 lines

https://www.spinics.net/lists/linux-media/msg176089.html

Before that patch there are no iommu page faults but the video is corrupted.

I can't explain how I didn't find it before, I clearly remember testing the grey format.

It seems really weird indeed.

Are you getting IOMMU faults on both the main and self paths ?

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +0 -0
                 /*
                  * Use the dummy space allocated by dma_alloc_coherent to
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw
Quoted 79 lines · Laurent Pinchart

Hi Dafna,

Quoted 76 lines · Dafna Hirschfeld
Quoted 64 lines · Kieran Bingham

Quoting Dafna Hirschfeld (2021-12-07 11:59:23)

Quoted 47 lines

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

   .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----
   1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
                  .fourcc = V4L2_PIX_FMT_GREY,
                  .uv_swap = 0,
                  .write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
                  .mbus = MEDIA_BUS_FMT_YUYV8_2X8,
          },
          /* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
                  rkisp1_write(cap->rkisp1,
                               buff_addr[RKISP1_PLANE_Y],
                               cap->config->mi.y_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CB],
-                            cap->config->mi.cb_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CR],
-                            cap->config->mi.cr_base_ad_init);
+               /*
+                * In order to support grey format we capture
+                * YUV422 planar format from the camera and
+                * set the U and V planes to the dummy buffer
+                */
+               if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c static void rkisp1_set_next_buf(struct rkisp1_capture *cap) · line 654

Quoted 10 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +9 -0
+                                    cap->config->mi.cr_base_ad_init);
+               } else {
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CB],
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CR],
+                                    cap->config->mi.cr_base_ad_init);
+               }
          } else {

Looking at this function, I think I would have initialised a local array of addresses (either to zero, or to the dummy address?) to then set values when appropriate, and reduce the number of calls to rkisp1_write() to a single set of three after the processing.

Quoted 4 lines

It might make the function simpler, and more readable, but it's more effort, and this does look like it will solve the greyscale format issue as discussed in earlier threads so I'd leave it up to you if you want to refactor.

Hi,
Yes, I'll do that.
Interestingly I found out that the patch causing the iommu page fault is

https://www.spinics.net/lists/linux-media/msg176089.html

Quoted 7 lines
Quoted 3 lines

Before that patch there are no iommu page faults but the video is corrupted.

I can't explain how I didn't find it before, I clearly remember testing the grey format.

It seems really weird indeed.

Are you getting IOMMU faults on both the main and self paths ?

Yes, both pathes. I get the page faults when checking out to this commit. Maybe when I tested back then, the iommu was somehow disabled?

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +0 -0
                  /*
                   * Use the dummy space allocated by dma_alloc_coherent to
#5 lore raw
Quoted 84 lines · Dafna Hirschfeld
Quoted 81 lines · Laurent Pinchart

Hi Dafna,

Quoted 78 lines · Dafna Hirschfeld
Quoted 64 lines · Kieran Bingham

Quoting Dafna Hirschfeld (2021-12-07 11:59:23)

Quoted 47 lines

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

   .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----

   1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
                   .fourcc = V4L2_PIX_FMT_GREY,
                   .uv_swap = 0,
                   .write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
                   .mbus = MEDIA_BUS_FMT_YUYV8_2X8,
           },
           /* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
                   rkisp1_write(cap->rkisp1,
                                buff_addr[RKISP1_PLANE_Y],
                                cap->config->mi.y_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CB],
-                            cap->config->mi.cb_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CR],
-                            cap->config->mi.cr_base_ad_init);
+               /*
+                * In order to support grey format we capture
+                * YUV422 planar format from the camera and
+                * set the U and V planes to the dummy buffer
+                */
+               if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c static void rkisp1_set_next_buf(struct rkisp1_capture *cap) · line 654

Quoted 10 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +9 -0
+                                    cap->config->mi.cr_base_ad_init);
+               } else {
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CB],
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CR],
+                                    cap->config->mi.cr_base_ad_init);
+               }
           } else {

Looking at this function, I think I would have initialised a local array of addresses (either to zero, or to the dummy address?) to then set values when appropriate, and reduce the number of calls to rkisp1_write() to a single set of three after the processing.

Quoted 4 lines

It might make the function simpler, and more readable, but it's more effort, and this does look like it will solve the greyscale format issue as discussed in earlier threads so I'd leave it up to you if you want to refactor.

Hi,
Yes, I'll do that.
Interestingly I found out that the patch causing the iommu page fault is

https://www.spinics.net/lists/linux-media/msg176089.html

Before that patch there are no iommu page faults but the video is corrupted.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I can't explain how I didn't find it before, I clearly remember testing the grey format.

It seems really weird indeed.

Are you getting IOMMU faults on both the main and self paths ?

Yes, both pathes. I get the page faults when checking out to this commit. Maybe when I tested back then, the iommu was somehow disabled?

I see now that it works "fine" if CONFIG_ROCKCHIP_IOMMU is turned off, so it might be that I tested without iommu, though it is set in arch/arm64/configs/defconfig

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +0 -0
                   /*
                    * Use the dummy space allocated by dma_alloc_coherent to
#6 lore raw
Quoted 91 lines · Dafna Hirschfeld
Quoted 88 lines · Dafna Hirschfeld
Quoted 85 lines · Laurent Pinchart

Hi Dafna,

Quoted 74 lines · Dafna Hirschfeld
Quoted 64 lines · Kieran Bingham

Quoting Dafna Hirschfeld (2021-12-07 11:59:23)

Quoted 47 lines

Currently capturing grey format produces page faults on both selfpath and mainpath. To support greyscale we can capture YUV422 planar format and configure the U, V buffers to the dummy buffer.

---
This is v2 of the patch "media: rkisp1: remove support for V4L2_PIX_FMT_GREY" In v1 I removed the grey format. In this version it is 'fixed'

   .../platform/rockchip/rkisp1/rkisp1-capture.c | 28 ++++++++++++++-----

   1 file changed, 21 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +12 -7
index 768987d5f2dd..8e982dd0c740 100644
@@ -249,7 +249,7 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
                   .fourcc = V4L2_PIX_FMT_GREY,
                   .uv_swap = 0,
                   .write_format = RKISP1_MI_CTRL_SP_WRITE_PLA,
-               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV400,
+               .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
                   .mbus = MEDIA_BUS_FMT_YUYV8_2X8,
           },
           /* rgb */
@@ -631,12 +631,26 @@ static void rkisp1_set_next_buf(struct rkisp1_capture *cap)
                   rkisp1_write(cap->rkisp1,
                                buff_addr[RKISP1_PLANE_Y],
                                cap->config->mi.y_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CB],
-                            cap->config->mi.cb_base_ad_init);
-               rkisp1_write(cap->rkisp1,
-                            buff_addr[RKISP1_PLANE_CR],
-                            cap->config->mi.cr_base_ad_init);
+               /*
+                * In order to support grey format we capture
+                * YUV422 planar format from the camera and
+                * set the U and V planes to the dummy buffer
+                */
+               if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) {
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    cap->buf.dummy.dma_addr,

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c static void rkisp1_set_next_buf(struct rkisp1_capture *cap) · line 654

Quoted 10 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +9 -0
+                                    cap->config->mi.cr_base_ad_init);
+               } else {
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CB],
+                                    cap->config->mi.cb_base_ad_init);
+                       rkisp1_write(cap->rkisp1,
+                                    buff_addr[RKISP1_PLANE_CR],
+                                    cap->config->mi.cr_base_ad_init);
+               }
           } else {

Looking at this function, I think I would have initialised a local array of addresses (either to zero, or to the dummy address?) to then set values when appropriate, and reduce the number of calls to rkisp1_write() to a single set of three after the processing.

Quoted 4 lines

It might make the function simpler, and more readable, but it's more effort, and this does look like it will solve the greyscale format issue as discussed in earlier threads so I'd leave it up to you if you want to refactor.

Hi,
Yes, I'll do that.
Interestingly I found out that the patch causing the iommu page fault is

Quoted 5 lines

https://www.spinics.net/lists/linux-media/msg176089.html

Before that patch there are no iommu page faults but the video is corrupted.

I can't explain how I didn't find it before, I clearly remember testing the grey format.

It seems really weird indeed.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Are you getting IOMMU faults on both the main and self paths ?

Yes, both pathes. I get the page faults when checking out to this commit. Maybe when I tested back then, the iommu was somehow disabled?

I see now that it works "fine" if CONFIG_ROCKCHIP_IOMMU is turned off, so it might be that I tested without iommu, though it is set in arch/arm64/configs/defconfig

I have a script that iterates all supported formats and stream them. I see that when running the script, streaming gray format succeed, but when testing grey format alone I get those page faults. I guess somehow buffers happen to be mapped when running the script so it misses the faults.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +0 -0
                   /*
                    * Use the dummy space allocated by dma_alloc_coherent to