[PATCH v2 04/13] media: iris: size QC08C buffers to fit field-coded pictures

From: Dmitry Baryshkov

Date: Fri Dec 04 2026 - 13:25:16 EST


Decoding interlaced content faults in the IOMMU: the firmware writes past
the end of a reconstruction (DPB) buffer. iris_yuv_buffer_size_qc08c()
lays a UBWC NV12 buffer out as one frame, but for field pictures the
hardware stores the two fields separately, each with its planes and
metadata aligned on its own, which takes more space at most sizes.

Size the buffer as the downstream driver does for both directions: up to
1920x1088, take the larger two-field layout, otherwise one frame.

Fixes: cfd71b14b0d6 ("media: iris: Add support for QC08C format for decoder")
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxxxxxxxx>
---
drivers/media/platform/qcom/iris/iris_buffer.c | 53 +++++++++++++++++---------
1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/drivers/media/platform/qcom/iris/iris_buffer.c b/drivers/media/platform/qcom/iris/iris_buffer.c
index eb8de60c1177..b5588fd8997e 100644
--- a/drivers/media/platform/qcom/iris/iris_buffer.c
+++ b/drivers/media/platform/qcom/iris/iris_buffer.c
@@ -228,40 +228,55 @@ static u32 iris_yuv_buffer_size_p010(struct iris_inst *inst)
*
* Note: All the alignments are hardware requirements.
*/
-static u32 iris_yuv_buffer_size_qc08c(struct iris_inst *inst)
+static u32 iris_yuv_planes_size_qc08c(u32 width, u32 height)
{
u32 y_plane, uv_plane, y_stride, uv_stride;
u32 uv_meta_stride, uv_meta_plane;
u32 y_meta_stride, y_meta_plane;
- struct v4l2_format *f = NULL;
+ u32 uv_height = DIV_ROUND_UP(height, 2);

- if (inst->domain == DECODER)
- f = inst->fmt_dst;
- else
- f = inst->fmt_src;
-
- y_meta_stride = ALIGN(DIV_ROUND_UP(f->fmt.pix_mp.width, META_STRIDE_ALIGNED >> 1),
+ y_meta_stride = ALIGN(DIV_ROUND_UP(width, META_STRIDE_ALIGNED >> 1),
META_STRIDE_ALIGNED);
- y_meta_plane = y_meta_stride * ALIGN(DIV_ROUND_UP(f->fmt.pix_mp.height,
- META_SCANLINE_ALIGNED >> 1),
+ y_meta_plane = y_meta_stride * ALIGN(DIV_ROUND_UP(height, META_SCANLINE_ALIGNED >> 1),
META_SCANLINE_ALIGNED);
y_meta_plane = ALIGN(y_meta_plane, PIXELS_4K);

- y_stride = ALIGN(f->fmt.pix_mp.width, Y_STRIDE_ALIGN);
- y_plane = ALIGN(y_stride * ALIGN(f->fmt.pix_mp.height, Y_SCANLINE_ALIGN), PIXELS_4K);
+ y_stride = ALIGN(width, Y_STRIDE_ALIGN);
+ y_plane = ALIGN(y_stride * ALIGN(height, Y_SCANLINE_ALIGN), PIXELS_4K);

- uv_meta_stride = ALIGN(DIV_ROUND_UP(f->fmt.pix_mp.width / 2, META_STRIDE_ALIGNED >> 2),
+ uv_meta_stride = ALIGN(DIV_ROUND_UP(width / 2, META_STRIDE_ALIGNED >> 2),
META_STRIDE_ALIGNED);
- uv_meta_plane = uv_meta_stride * ALIGN(DIV_ROUND_UP(f->fmt.pix_mp.height / 2,
- META_SCANLINE_ALIGNED >> 1),
+ uv_meta_plane = uv_meta_stride * ALIGN(DIV_ROUND_UP(uv_height, META_SCANLINE_ALIGNED >> 1),
META_SCANLINE_ALIGNED);
uv_meta_plane = ALIGN(uv_meta_plane, PIXELS_4K);

- uv_stride = ALIGN(f->fmt.pix_mp.width, UV_STRIDE_ALIGN);
- uv_plane = ALIGN(uv_stride * ALIGN(f->fmt.pix_mp.height / 2, UV_SCANLINE_ALIGN_QC08C),
- PIXELS_4K);
+ uv_stride = ALIGN(width, UV_STRIDE_ALIGN);
+ uv_plane = ALIGN(uv_stride * ALIGN(uv_height, UV_SCANLINE_ALIGN_QC08C), PIXELS_4K);

- return ALIGN(y_meta_plane + y_plane + uv_meta_plane + uv_plane, PIXELS_4K);
+ return y_meta_plane + y_plane + uv_meta_plane + uv_plane;
+}
+
+static u32 iris_yuv_buffer_size_qc08c(struct iris_inst *inst)
+{
+ struct v4l2_format *f;
+ u32 width, height;
+
+ if (inst->domain == DECODER)
+ f = inst->fmt_dst;
+ else
+ f = inst->fmt_src;
+
+ width = f->fmt.pix_mp.width;
+ height = f->fmt.pix_mp.height;
+
+ /*
+ * Up to 1080p the buffer must also fit two separately aligned fields,
+ * which is larger than one frame.
+ */
+ if (width <= 1920 && height <= 1920 && width * height <= 1920 * 1088)
+ return 2 * iris_yuv_planes_size_qc08c(width, DIV_ROUND_UP(height, 2));
+
+ return iris_yuv_planes_size_qc08c(width, height);
}

/*

--
2.47.3