Skip to contentSkip to conversation

media: rockchip: Add the IEP2 deinterlacer of RK3568/RK3588

PATCH Superseded Arun Iyengar 2 participants 6 messages Nov 14

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover media: rockchip: Add the IEP2 deinterlacer of RK3568/RK3588

This adds a V4L2 mem2mem driver for IEP2, the deinterlacer of the RK3568 and RK3588 SoCs, with its binding and the RK3588 DT node.

It is based on Rockchip's vendor driver and MPP; the V4L2 part follows Alex Bee's out-of-tree driver for the older IEP and sun8i-di. The older IEP is a different block, so this driver uses iep2 names and leaves the iep ones to Alex's driver.

The OUTPUT sizeimage is 4 KiB larger than the image: the hardware reads past the end of the source (seen in a bob mode), which faults in the IOMMU, and the block retries the read forever. How far it reads is not known; 4 KiB never faulted. So an imported DMABUF of exactly the image size is refused at QBUF.

Tested on an Orange Pi 5 (RK3588S) with a v7.3-based kernel carrying this driver (plus a test-only parameter that shortens the watchdog); on this series' base it is build-tested only.
The posted code ran v4l2-compliance (all three runs), the exact-size DMABUF check and a motion adaptive stream; the other results below are from the version before the last review fixes (size clamp, open error path, Kconfig text).
- v4l2-compliance -s: 59/59, 1 warning (no --expbuf-device); 59/59, 0 warnings with vivid vmalloc and dma-contig exporters
- exact-size DMABUF refused with -EINVAL; field order; timestamps at field rate; payload check; unbind with an open file and while streaming; rebind; s2idle and deep suspend while streaming
- with earlier unposted versions: 72 cases (576i/1080i, NV12/NV16/NV21, TFF/BFF/progressive, all four modes) without IOMMU faults, luma PSNR 35.2-37.2 dB (bob) and 33.2-36.6 dB (motion adaptive), progressive bit-exact; -EBUSY on a rate change while streaming; 1080i motion adaptive at 290 frames/s

Not tested: RK3568 (no board), NV61, DMABUF on CAPTURE, the recovery paths (never triggered).

v4l2-compliance output (no --expbuf-device):

v4l2-compliance 1.33.0-5524, 64 bits, 64-bit time_t v4l2-compliance SHA: d2e89246cefc 2026-10-30 13:45:36

Compliance test for rockchip-iep2 device /dev/video3:

Driver Info:

	Driver name      : rockchip-iep2
	Card type        : Rockchip IEP2 deinterlacer
	Bus info         : platform:fdbb0000.deinterlace
	Driver version   : 7.3.0
	Capabilities     : 0x84204000

Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format

Required ioctls:
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video3 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 2 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OK

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test MMAP (no poll, REQBUFS): OK
test MMAP (select, REQBUFS): OK
test MMAP (epoll, REQBUFS): OK
test MMAP (no poll, CREATE_BUFS): OK
test MMAP (select, CREATE_BUFS): OK
test MMAP (epoll, CREATE_BUFS): OK
test USERPTR (no poll): OK (Not Supported)
test USERPTR (select): OK (Not Supported)
warn: v4l2-test-buffers.cpp(2223): Cannot test DMABUF, specify --expbuf-device
test DMABUF (no poll): OK (Not Supported)
test DMABUF (select): OK (Not Supported)

Total for rockchip-iep2 device /dev/video3: 59, Succeeded: 59, Failed: 0, Warnings: 1

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Arun Iyengar (3):
media: dt-bindings: Add Rockchip IEP2 deinterlacer
media: rockchip: Add IEP2 deinterlacer driver
arm64: dts: rockchip: Add IEP2 deinterlacer to RK3588

 Documentation/admin-guide/media/rockchip-iep2.rst  |   59 +
 Documentation/admin-guide/media/v4l-drivers.rst    |    1 +
 .../bindings/media/rockchip,rk3568-iep2.yaml       |   95 ++
 MAINTAINERS                                        |    9 +
 arch/arm64/boot/dts/rockchip/rk3588-base.dtsi      |   22 +
 drivers/media/platform/rockchip/Kconfig            |    1 +
 drivers/media/platform/rockchip/Makefile           |    1 +
 drivers/media/platform/rockchip/iep2/Kconfig       |   16 +
 drivers/media/platform/rockchip/iep2/Makefile      |    3 +
 drivers/media/platform/rockchip/iep2/iep2-regs.h   |  192 +++
 drivers/media/platform/rockchip/iep2/iep2.c        | 1275 ++++++++++++++++++++
 drivers/media/platform/rockchip/iep2/iep2.h        |  106 ++
 12 files changed, 1780 insertions(+)

---
base-commit: ad6549a46748d00818483b535e5cd2a704685c98
change-id: 20261110-iep2-b9a9c6e77c44

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH 1/3 media: dt-bindings: Add Rockchip IEP2 deinterlacer

Add a binding for the IEP2 deinterlacer of the RK3568 and RK3588 SoCs. It is a different block from the IEP of RK3228/RK3288/RK3328/RK3399, hence "iep2". The RK3588 block falls back to the RK3568 compatible:
the vendor kernel drives both with one compatible ("rockchip,iep-v2") and one driver.

Clock and reset names follow the RGA binding. The resets are optional:
the block has its own soft reset.

---
 .../bindings/media/rockchip,rk3568-iep2.yaml       | 95 ++++++++++++++++++++++
 MAINTAINERS                                        |  7 ++
 2 files changed, 102 insertions(+)
Documentation/devicetree/bindings/media/rockchip,rk3568-iep2.yaml new file +95 -0
new file mode 100644
index 000000000000..0c7666de19f8
@@ -0,0 +1,95 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/rockchip,rk3568-iep2.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Rockchip IEP2 image enhancement processor
+
+maintainers:
+  - Arun Iyengar <[email protected]>
+
+description:
+  Memory to memory video deinterlacer of the Rockchip RK3568 and RK3588
+  SoCs. It has its own IOMMU, with which it shares its interrupt line.
+
+properties:
+  compatible:
+    oneOf:
+      - const: rockchip,rk3568-iep2
+      - items:
+          - const: rockchip,rk3588-iep2
+          - const: rockchip,rk3568-iep2
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: AXI bus clock
+      - description: AHB bus clock
+      - description: Core clock
+
+  clock-names:
+    items:
+      - const: aclk
+      - const: hclk
+      - const: sclk
+
+  resets:
+    items:
+      - description: AXI reset
+      - description: AHB reset
+      - description: Core reset
+
+  reset-names:
+    items:
+      - const: axi
+      - const: ahb
+      - const: core
+
+  power-domains:
+    maxItems: 1
+
+  iommus:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - power-domains
+  - iommus
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/rockchip,rk3588-cru.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/power/rk3588-power.h>
+    #include <dt-bindings/reset/rockchip,rk3588-cru.h>
+
+    bus {
+      #address-cells = <2>;
+      #size-cells = <2>;
+
+      deinterlace@fdbb0000 {
+        compatible = "rockchip,rk3588-iep2", "rockchip,rk3568-iep2";
+        reg = <0x0 0xfdbb0000 0x0 0x500>;
+        interrupts = <GIC_SPI 117 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&cru ACLK_IEP2P0>, <&cru HCLK_IEP2P0>,
+                 <&cru CLK_IEP2P0_CORE>;
+        clock-names = "aclk", "hclk", "sclk";
+        resets = <&cru SRST_A_IEP2P0>, <&cru SRST_H_IEP2P0>,
+                 <&cru SRST_IEP2P0_CORE>;
+        reset-names = "axi", "ahb", "core";
+        power-domains = <&power RK3588_PD_VDPU>;
+        iommus = <&iep_mmu>;
+      };
+    };
MAINTAINERS +7 -0
index f4456f4589a1..b32b7eeb0a9e 100644
@@ -24285,6 +24285,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/rockchip,i2s-tdm.yaml
 F:	sound/soc/rockchip/rockchip_i2s_tdm.*
 
+ROCKCHIP IEP2 DEINTERLACER DRIVER
+M:	Arun Iyengar <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/media/rockchip,rk3568-iep2.yaml
+
 ROCKCHIP ISP V1 DRIVER
 M:	Dafna Hirschfeld <[email protected]>
 M:	Laurent Pinchart <[email protected]>
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/3 media: rockchip: Add IEP2 deinterlacer driver

In reply to Arun Iyengar

Add a V4L2 mem2mem driver for the IEP2 deinterlacer of the RK3568 and RK3588 SoCs.

The register map, programming sequence and default parameters come from the Rockchip vendor kernel (github.com/rockchip-linux/kernel develop-6.1, mpp_iep2.c and rockchip_iep2_regs.h, GPL-2.0+ OR MIT, Ding Wei and Alpha Lin) and the Rockchip MPP library. The V4L2 part follows Alex Bee's out-of-tree driver for the older IEP, a different block that keeps the iep names, and sun8i-di.

V4L2_CID_DEINTERLACING_MODE selects bob or motion adaptive at frame or field rate (see rockchip-iep2.rst). Bob is the default: without look-ahead, motion adaptive is not reliably better.

The IEP2 reads past the end of the source, so the OUTPUT sizeimage has 4 KiB of tail padding. The vendor kernel maps a spare page at the faulting address instead.

The interrupt line is shared with the IOMMU. Since the IEP retries a faulting read forever, a job during which the line fires without IEP status is aborted. Stuck jobs get a soft reset, then a CRU reset; both put the IOMMU in bypass, so it is reprogrammed.

---
 Documentation/admin-guide/media/rockchip-iep2.rst |   59 +
 Documentation/admin-guide/media/v4l-drivers.rst   |    1 +
 MAINTAINERS                                       |    2 +
 drivers/media/platform/rockchip/Kconfig           |    1 +
 drivers/media/platform/rockchip/Makefile          |    1 +
 drivers/media/platform/rockchip/iep2/Kconfig      |   16 +
 drivers/media/platform/rockchip/iep2/Makefile     |    3 +
 drivers/media/platform/rockchip/iep2/iep2-regs.h  |  192 ++++
 drivers/media/platform/rockchip/iep2/iep2.c       | 1275 +++++++++++++++++++++
 drivers/media/platform/rockchip/iep2/iep2.h       |  106 ++
 10 files changed, 1656 insertions(+)
Documentation/admin-guide/media/rockchip-iep2.rst new file +59 -0
new file mode 100644
index 000000000000..5c95a19146d0
@@ -0,0 +1,59 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Rockchip IEP2 deinterlacer driver
+=================================
+
+The rockchip-iep2 driver supports the IEP2 deinterlacer of the Rockchip RK3568
+and RK3588 SoCs as a V4L2 memory to memory device. It is a different block from
+the IEP of older Rockchip SoCs. The OUTPUT queue takes frames with both fields
+interleaved (``V4L2_FIELD_INTERLACED_TB``, ``V4L2_FIELD_INTERLACED_BT`` or
+``V4L2_FIELD_INTERLACED``), the CAPTURE queue returns progressive frames in the
+same pixel format. A mem2mem device has no video standard, so for
+``V4L2_FIELD_INTERLACED`` the driver takes the field order from the height:
+bottom field first below 576 lines (525-line video), top field first
+otherwise. Userspace that knows the order should use
+``V4L2_FIELD_INTERLACED_TB`` or ``V4L2_FIELD_INTERLACED_BT``.
+
+OUTPUT buffers with ``V4L2_FIELD_NONE`` are copied through unchanged. At field
+rate such a buffer still produces one CAPTURE buffer, but it is only processed
+once two CAPTURE buffers are queued.
+
+The driver implements the following control.
+
+``V4L2_CID_DEINTERLACING_MODE (menu)``
+    The video deinterlacing mode. It selects both the algorithm and the output
+    rate. The rate cannot be changed while one of the queues is streaming
+    (``EBUSY``); a change of algorithm at the same rate is accepted at any
+    time.
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 4
+
+    * - ``"Bob, Frame Rate" (0)``
+      - The missing lines are interpolated within one field. One CAPTURE
+        buffer is produced per OUTPUT buffer. This is the default.
+    * - ``"Bob, Field Rate" (1)``
+      - As above for both fields: two CAPTURE buffers are produced per OUTPUT
+        buffer, the temporally first field first (e.g. 50i to 50p).
+    * - ``"Motion Adaptive, Frame Rate" (2)``
+      - Motion-adaptive, motion-compensated interpolation that uses the
+        previous OUTPUT buffer as reference. The first frame of a stream is
+        processed with bob. One CAPTURE buffer is produced per OUTPUT buffer.
+        The driver holds the previous OUTPUT buffer until the next one has
+        been processed, so at least two OUTPUT buffers are needed.
+    * - ``"Motion Adaptive, Field Rate" (3)``
+      - As above for both fields: two CAPTURE buffers are produced per OUTPUT
+        buffer.
+
+Both queues use ``V4L2_BUF_FLAG_TIMESTAMP_COPY``. At field rate both CAPTURE
+buffers of an OUTPUT buffer carry its timestamp; the second one shows the
+field that is half a frame period later.
+
+The hardware reads past the end of the source image, so the ``sizeimage`` of
+the OUTPUT format is 4 KiB larger than the image. Buffers queued on the
+OUTPUT queue, including imported DMABUFs, must have at least that size. The
+payload (``bytesused``) of an OUTPUT buffer must cover at least the image,
+i.e. ``sizeimage`` minus the 4 KiB; a smaller payload is refused with
+``EINVAL`` when the buffer is queued.
Documentation/admin-guide/media/v4l-drivers.rst +1 -0
index 4621eae9fa1e..3d59d5d73fd0 100644
@@ -29,6 +29,7 @@ Video4Linux (V4L) driver-specific documentation
 	rcar-fdp1
 	rkcif
 	rkisp1
+	rockchip-iep2
 	raspberrypi-rp1-cfe
 	saa7134
 	si470x
MAINTAINERS +2 -0
index b32b7eeb0a9e..564d39b2cca9 100644
@@ -24290,7 +24290,9 @@ M:	Arun Iyengar <[email protected]>
 L:	[email protected]
 L:	[email protected]
 S:	Maintained
+F:	Documentation/admin-guide/media/rockchip-iep2.rst
 F:	Documentation/devicetree/bindings/media/rockchip,rk3568-iep2.yaml
+F:	drivers/media/platform/rockchip/iep2/
 
 ROCKCHIP ISP V1 DRIVER
 M:	Dafna Hirschfeld <[email protected]>
drivers/media/platform/rockchip/Kconfig +1 -0
index ba401d32f01b..4f65bd0126de 100644
@@ -2,6 +2,7 @@
 
 comment "Rockchip media platform drivers"
 
+source "drivers/media/platform/rockchip/iep2/Kconfig"
 source "drivers/media/platform/rockchip/rga/Kconfig"
 source "drivers/media/platform/rockchip/rkcif/Kconfig"
 source "drivers/media/platform/rockchip/rkisp1/Kconfig"
drivers/media/platform/rockchip/Makefile +1 -0
index 0e0b2cbbd4bd..c385048ba347 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+obj-y += iep2/
 obj-y += rga/
 obj-y += rkcif/
 obj-y += rkisp1/
drivers/media/platform/rockchip/iep2/Kconfig new file +16 -0
new file mode 100644
index 000000000000..de1e445b3fd8
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config VIDEO_ROCKCHIP_IEP2
+	tristate "Rockchip IEP2 deinterlacer"
+	depends on V4L_MEM2MEM_DRIVERS
+	depends on VIDEO_DEV
+	depends on ARCH_ROCKCHIP || COMPILE_TEST
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_MEM2MEM_DEV
+	help
+	  Support for the IEP2 (image enhancement processor) found in the
+	  Rockchip RK3568 and RK3588 SoCs. It is exposed as a V4L2 memory to
+	  memory device that deinterlaces NV12/NV21/NV16/NV61 frames, using
+	  either intra-field (bob) or motion-adaptive interpolation.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called rockchip-iep2.
drivers/media/platform/rockchip/iep2/Makefile new file +3 -0
new file mode 100644
index 000000000000..f13bb799de54
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_VIDEO_ROCKCHIP_IEP2) += rockchip-iep2.o
+rockchip-iep2-y := iep2.o
drivers/media/platform/rockchip/iep2/iep2-regs.h new file +192 -0

192 lines not on this page · raw message

drivers/media/platform/rockchip/iep2/iep2.c new file +1275 -0

1,275 lines not on this page · raw message

drivers/media/platform/rockchip/iep2/iep2.h new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.55.0
#3 lore raw

Re: [PATCH 2/3] media: rockchip: Add IEP2 deinterlacer driver

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] media: rockchip: iep2: lost frame-done IRQ in iep_irq() when OSD_MAX fires - [Medium] media…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] media: rockchip: iep2: lost frame-done IRQ in iep_irq() when OSD_MAX fires
- [Medium] media: rockchip: iep2: unreleased prev and second dst buf in iep_fail_job()
- [Medium] media: rockchip: iep2: race and use-after-free in iep_remove() on unbind
--

commit 33c094e881e4e76b67c9126fbcce91524e080828
Author: Arun Iyengar <[email protected]>

media: rockchip: Add IEP2 deinterlacer driver

This commit adds a V4L2 mem2mem driver for the Rockchip IEP2 deinterlacer on RK3568 and RK3588 SoCs, supporting bob and motion-adaptive deinterlacing at frame and field rates.

Quoted 5 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +0 -0
new file mode 100644
index 0000000000000..26f5fec02b679

[ ... ]

Quoted 32 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +32 -0
+static void iep_job_done(struct iep_ctx *ctx, enum vb2_buffer_state state)
+{
+	struct iep_dev *iep = ctx->iep;
+	struct vb2_v4l2_buffer *src = ctx->job_src;
+	unsigned int i;
+
+	for (i = 0; i < ctx->job_ndst; i++) {
+		v4l2_m2m_buf_done(ctx->job_dst[i], state);
+		ctx->job_dst[i] = NULL;
+	}
+	ctx->job_ndst = 0;
+	ctx->job_src = NULL;
+
+	if (ctx->prev) {
+		v4l2_m2m_buf_done(ctx->prev, VB2_BUF_STATE_DONE);
+		ctx->prev = NULL;
+	}
+
+	if (src) {
+		if (ctx->job_keep_src && state == VB2_BUF_STATE_DONE)
+			ctx->prev = src;
+		else
+			v4l2_m2m_buf_done(src, state);
+	}
+	ctx->job_keep_src = false;
+
+	pm_runtime_put_autosuspend(iep->dev);
+	v4l2_m2m_job_finish(iep->m2m_dev, ctx->fh.m2m_ctx);
+}
+
+static void iep_fail_job(struct iep_ctx *ctx)
+{

drivers/media/platform/rockchip/iep2/iep2.c line 285

Quoted 10 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +10 -0
+	struct vb2_v4l2_buffer *src, *dst;
+
+	src = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+	dst = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+	if (src)
+		v4l2_m2m_buf_done(src, VB2_BUF_STATE_ERROR);
+	if (dst)
+		v4l2_m2m_buf_done(dst, VB2_BUF_STATE_ERROR);
+	v4l2_m2m_job_finish(ctx->iep->m2m_dev, ctx->fh.m2m_ctx);
+}

[Severity: Medium]
When pm_runtime_resume_and_get() fails in iep_device_run(), does iep_fail_job() leave ctx->prev and the second field-rate CAPTURE buffer queued?

In motion-adaptive mode, failing src without first completing and clearing ctx->prev returns the current OUTPUT buffer ahead of the reference buffer held from the previous frame. In field-rate mode, iep_job_ready() waits for two CAPTURE buffers, so leaving ctx->prev on src_vq->queued_list and the second CAPTURE buffer on dst_vq->queued_list keeps both queues non-empty while no new job can run, causing poll() or blocking VIDIOC_DQBUF to hang even after iep_resume() calls v4l2_m2m_resume().

[ ... ]

Quoted 28 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +28 -0
+static irqreturn_t iep_irq(int irq, void *data)
+{
+	struct iep_dev *iep = data;
+	irqreturn_t ret = IRQ_NONE;
+	u32 status;
+
+	/* Shared with the IOMMU: registers are only accessible during a job */
+	spin_lock(&iep->irq_lock);
+	if (!iep->busy)
+		goto out;
+
+	status = iep_read(iep, IEP2_INT_STS);
+	if (!status) {
+		/* IOMMU fault: the IEP would retry the read forever */
+		if (++iep->foreign_irqs < IEP_MAX_FOREIGN_IRQS)
+			goto out;
+
+		iep_write(iep, IEP2_INT_EN, 0);
+		iep_write(iep, IEP2_CONFIG0, IEP2_ACLK_SRESET_P);
+		iep->busy = false;
+		iep->irq_status = IEP_IRQ_IOMMU_FAULT;
+		ret = IRQ_WAKE_THREAD;
+		goto out;
+	}
+
+	iep_write(iep, IEP2_INT_CLR, 0xffffffff);
+	ret = IRQ_HANDLED;
+

drivers/media/platform/rockchip/iep2/iep2.c line 444

Quoted 10 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +10 -0
+	if (status & IEP2_INT_VALID) {
+		iep->busy = false;
+		iep->irq_status = status;
+		ret = IRQ_WAKE_THREAD;
+	}
+out:
+	spin_unlock(&iep->irq_lock);
+
+	return ret;
+}

[Severity: Medium]
Can writing 0xffffffff to IEP2_INT_CLR drop a frame-done interrupt when IEP2_INT_OSD_MAX fires first?

iep_hw_config() enables IEP2_INT_OSD_MAX in IEP2_INT_EN, but IEP2_INT_VALID only includes IEP2_INT_TIMEOUT, IEP2_INT_BUS_ERROR and IEP2_INT_FRM_DONE. If IEP2_INT_OSD_MAX triggers iep_irq() and IEP2_INT_FRM_DONE asserts between reading IEP2_INT_STS and writing 0xffffffff to IEP2_INT_CLR, the frame-done status is cleared in hardware without waking iep_irq_thread(), stalling the job until the 500 ms watchdog times out and resets the block. Clearing only status (or not enabling IEP2_INT_OSD_MAX) would avoid losing the completion.

[ ... ]

Quoted 9 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +9 -0
+static void iep_remove(struct platform_device *pdev)
+{
+	struct iep_dev *iep = platform_get_drvdata(pdev);
+
+	v4l2_m2m_suspend(iep->m2m_dev);
+	video_unregister_device(&iep->vfd);
+	cancel_delayed_work_sync(&iep->watchdog_work);
+
+	/* Disabling runtime PM drops a pending autosuspend */

drivers/media/platform/rockchip/iep2/iep2.c line 1224

Quoted 10 lines
drivers/media/platform/rockchip/iep2/iep2.c new file +10 -0
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		iep_runtime_suspend(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+
+	if (iep->empty_domain)
+		iommu_domain_free(iep->empty_domain);
+	iep->empty_domain = NULL;
+}

[Severity: Medium]
Can v4l2_m2m_suspend() race with iep_release() and read a freed m2m_ctx?

v4l2_m2m_suspend() (also called from iep_suspend() without iep->mutex) reads m2m_dev->curr_ctx under job_spinlock, drops the spinlock, and waits on curr_ctx->finished:

CPU0 CPU1
iep_remove()
v4l2_m2m_suspend(iep->m2m_dev)

    curr_ctx = m2m_dev->curr_ctx
                                  iep_release()
                                    mutex_lock(&iep->mutex)
                                    v4l2_m2m_ctx_release(ctx->fh.m2m_ctx)
                                      wait_event(m2m_ctx->finished, ...)
                                      /* job finishes */
                                      kfree(m2m_ctx)
    wait_event(curr_ctx->finished,
      !(curr_ctx->job_flags & ...))  <-- use-after-free

In addition, iep_remove() never acquires iep->mutex, so an ioctl that entered __video_do_ioctl() before video_unregister_device() cleared V4L2_FL_REGISTERED can still be running under iep->mutex while iep_remove() disables runtime PM, unprepares clocks, and frees iep->empty_domain.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH 2/3] media: rockchip: Add IEP2 deinterlacer driver

Quoted 3 lines

When pm_runtime_resume_and_get() fails in iep_device_run(), does iep_fail_job() leave ctx->prev and the second field-rate CAPTURE buffer queued?

Yes. v2 returns both.

Quoted 2 lines

Can writing 0xffffffff to IEP2_INT_CLR drop a frame-done interrupt when IEP2_INT_OSD_MAX fires first?

Yes. v2 clears only the bits it read.

Quoted 1 line

Can v4l2_m2m_suspend() race with iep_release() and read a freed m2m_ctx?

From remove(), yes. v2 unregisters the node first, then calls v4l2_m2m_suspend() under the device mutex, which also waits for ioctls in flight. In system suspend, tasks are frozen, so no release can run.

Arun

#5 lore raw

PATCH 3/3 arm64: dts: rockchip: Add IEP2 deinterlacer to RK3588

In reply to Arun Iyengar

Add the IEP2 deinterlacer and its IOMMU to the RK3588 base dtsi. Both share GIC SPI 117 and sit in the VDPU power domain.

Addresses, clocks, resets and the interrupt are taken from the Rockchip BSP rk3588s.dtsi (develop-6.1).

---
 arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +22 -0
index aa69fd3793fd..5297519bd251 100644
@@ -1397,6 +1397,28 @@ vepu121_3_mmu: iommu@fdbac800 {
 		#iommu-cells = <0>;
 	};
 
+	iep: deinterlace@fdbb0000 {
+		compatible = "rockchip,rk3588-iep2", "rockchip,rk3568-iep2";
+		reg = <0x0 0xfdbb0000 0x0 0x500>;
+		interrupts = <GIC_SPI 117 IRQ_TYPE_LEVEL_HIGH 0>;
+		clocks = <&cru ACLK_IEP2P0>, <&cru HCLK_IEP2P0>, <&cru CLK_IEP2P0_CORE>;
+		clock-names = "aclk", "hclk", "sclk";
+		resets = <&cru SRST_A_IEP2P0>, <&cru SRST_H_IEP2P0>, <&cru SRST_IEP2P0_CORE>;
+		reset-names = "axi", "ahb", "core";
+		power-domains = <&power RK3588_PD_VDPU>;
+		iommus = <&iep_mmu>;
+	};
+
+	iep_mmu: iommu@fdbb0800 {
+		compatible = "rockchip,rk3588-iommu", "rockchip,rk3568-iommu";
+		reg = <0x0 0xfdbb0800 0x0 0x100>;
+		interrupts = <GIC_SPI 117 IRQ_TYPE_LEVEL_HIGH 0>;
+		clocks = <&cru ACLK_IEP2P0>, <&cru HCLK_IEP2P0>;
+		clock-names = "aclk", "iface";
+		power-domains = <&power RK3588_PD_VDPU>;
+		#iommu-cells = <0>;
+	};
+
 	vdec0: video-codec@fdc38000 {
 		compatible = "rockchip,rk3588-vdec";
 		reg = <0x0 0xfdc38000 0x0 0x100>,
Signature · 1 line
2.55.0