Skip to contentSkip to conversation

Add Amlogic video decoder driver

PATCH Superseded Maxime Jourdan 4 participants 12 messages May 14, 2019 – May 27, 2019

Subsystems (4)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add Amlogic video decoder driver

Hi everyone,

[V6] Good news, the firmware situation is resolved. We have received a redistributable license from Amlogic and the firmwares have been merged in linux-firmware[5].

[V5] It's been a while since the last patch series regarding the Amlogic video decoder. Unfortunately, the firmware licensing situation is still on hold as we await communication from Amlogic. As such, we do not have the firmwares in linux-firmware yet.
I decided to push the V5 anyway, as changes were starting to pile up.

This patch series adds support for the Amlogic video decoder, as well as the corresponding dt bindings for GXBB/GXL/GXM chips.

It features decoding for the following formats:
- MPEG 1
- MPEG 2

The following formats will be added in future patches:
- MJPEG
- MPEG 4 (incl. Xvid, H.263)
- H.264
- HEVC (incl. 10-bit)
- VP9 (incl. 10-bit)

The code was made in such a way to allow easy inclusion of those formats in the future.

The decoder is single instance.

Files:
- vdec.c handles the V4L2 M2M logic
- esparser.c manages the hardware bitstream parser
- vdec_helpers.c provides helpers to DONE the dst buffers as well as various common code used by the codecs
- vdec_1.c manages the VDEC_1 block of the vdec IP
- vdec_ctrls.c handles the V4L2 controls exposed by the driver
- codec_mpeg12.c enables decoding for MPEG 1/2.
- vdec_platform.c links codec units with vdec units
(e.g vdec_1 with codec_mpeg12) and lists all the available src/dst formats and requirements (max width/height, etc.), per compatible chip.

It was tested primarily with ffmpeg's v4l2-m2m implementation. For instance:

$ ffmpeg -c:v mpeg2_v4l2m2m -i sample_mpeg2.mkv -f rawvideo out.nv12

The v4l2-compliance results are available below the patch diff.

Changes since v5 [4]:
- Rebased against media_tree (fixes conflict with platform/meson/Makefile following the meson CEC driver updates)

Changes since v4 [3]:
- Updated for 5.1:
- cropcap -> g_pixelaspect
- dma_zalloc_coherent -> dma_alloc_coherent
- enum_framesizes: changed from STEPWISE to CONTINUOUS, as suggested by Hans
- Reintroduced support for CREATE_BUFS. It was a driver bug where I wasn't accounting for the amount of buffers created this way (only buffers created via REQBUFS were).
- Added the patch introducing V4L2_FMT_FLAG_FIXED_RESOLUTION to the V4L2 framework, needed as MPEG2 on Amlogic hardware only supports a fixed resolution during a decode session.
- Added support for events and V4L2_EVENT_SOURCE_CHANGE, as it is now checked by v4l2-compliance for stateful decoders. I was planning on introducing this for codecs that actually use it (H264, HEVC..), but it doesn't hurt to have this in the initial commit.
- Added support for controls, mainly V4L2_CID_MIN_BUFFERS_FOR_CAPTURE

Changes since v3 [2]:
- strlcpy -> strscpy
- queue_setup: account for existing buffers when clamping *num_buffers
- removed support for CREATE_BUFS. This caused issues with gstreamer and allowed userspace to alloc more buffers than the decoder can handle in its fixed list. So for now we just disable it and only allow allocating via REQBUFS.
- rebased & tested with 4.20-rc1

Changes since v2 [1]:
- Override capture queue's min_buffers_needed in queue_setup
The HW needs the full buffer list to be available when doing start_streaming
- Fix the draining sequence
The blob that we write to the ESPARSER to trigger drain is codec-dependent. The one that was sent in v1 is specific to H.264 and isn't guaranteed to trigger drain for MPEG2. For the latter, a simple MPEG2 EOS code should be sent to the ESPARSER instead.
- Slight enhancements to the way we do vififo offset<=>timestamp matching

Changes since v1 [0]:
- use named interrupts in the bindings
- rewrite description in the bindings doc
- don't include the dts changes in the patch series
- fill the vb2 queues locks
- fill the video_device lock
- use helpers for wait_prepare and wait_finish vb2_ops
- remove unnecessary usleep in between esparser writes. Extensive testing of every codec on GXBB/GXL didn't reveal
any fails without it, so just remove it.
- compile v4l2_compliance inside the git repo
- Check for plane number/plane size to pass the latest v4l2-compliance test
- Moved the single instance check (returning -EBUSY) to start/stop streaming The check was previously in queue_setup but there was no great location to clear it except for .close().
- Slight rework of the way CAPTURE frames are timestamped for better accuracy
- Implement PAR reporting via VIDIOC_CROPCAP

[5] https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/commit/?id=e04cc56d0e6b6ff05924ff88fdba1a438ee7d3c8
[4] https://patchwork.kernel.org/cover/10879959/
[3] https://patchwork.kernel.org/cover/10669875/
[2] https://lore.kernel.org/patchwork/cover/993093/
[1] https://patchwork.kernel.org/cover/10595803/
[0] https://patchwork.kernel.org/cover/10583391/

Maxime Jourdan (4):
dt-bindings: media: add Amlogic Video Decoder Bindings
media: videodev2: add V4L2_FMT_FLAG_FIXED_RESOLUTION
media: meson: add v4l2 m2m video decoder driver
MAINTAINERS: Add meson video decoder

 .../bindings/media/amlogic,vdec.txt           |   71 ++
 .../media/uapi/v4l/vidioc-enum-fmt.rst        |    6 +
 MAINTAINERS                                   |    8 +
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 include/uapi/linux/videodev2.h                |    5 +-
 22 files changed, 3085 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/amlogic,vdec.txt
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h
root@libretech-cc:~# v4l2-compliance -d /dev/video0 
v4l2-compliance SHA: 40fd5611c5176137c80616f6ee93b36f0d88f2d5, 64 bits

Compliance test for meson-vdec device /dev/video0:

Driver Info:

        Driver name      : meson-vdec
        Card type        : Amlogic Video Decoder
        Bus info         : platform:meson-vdec
        Driver version   : 5.1.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
Detected Stateful Decoder

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 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

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

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Total for meson-vdec device /dev/video0: 44, Succeeded: 44, Failed: 0, Warnings: 0

Signature · 1 line
2.21.0
#1 lore raw

PATCH v6 1/4 dt-bindings: media: add Amlogic Video Decoder Bindings

Add documentation for the meson vdec dts node.

---
 .../bindings/media/amlogic,vdec.txt           | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/amlogic,vdec.txt
Documentation/devicetree/bindings/media/amlogic,vdec.txt new file +71 -0
new file mode 100644
index 000000000000..aabdd01bcf32
@@ -0,0 +1,71 @@
+Amlogic Video Decoder
+================================
+
+The video decoding IP lies within the DOS memory region,
+except for the hardware bitstream parser that makes use of an undocumented
+region.
+
+It makes use of the following blocks:
+
+- ESPARSER is a bitstream parser that outputs to a VIFIFO. Further VDEC blocks
+then feed from this VIFIFO.
+- VDEC_1 can decode MPEG-1, MPEG-2, MPEG-4 part 2, MJPEG, H.263, H.264, VC-1.
+- VDEC_HEVC can decode HEVC and VP9.
+
+Both VDEC_1 and VDEC_HEVC share the "vdec" IRQ and as such cannot run
+concurrently.
+
+Device Tree Bindings:
+---------------------
+
+VDEC: Video Decoder
+--------------------------
+
+Required properties:
+- compatible: value should be different for each SoC family as :
+	- GXBB (S905) : "amlogic,gxbb-vdec"
+	- GXL (S905X, S905D) : "amlogic,gxl-vdec"
+	- GXM (S912) : "amlogic,gxm-vdec"
+- reg: base address and size of he following memory-mapped regions :
+	- dos
+	- esparser
+- reg-names: should contain the names of the previous memory regions
+- interrupts: should contain the following IRQs:
+	- vdec
+	- esparser
+- interrupt-names: should contain the names of the previous interrupts
+- amlogic,ao-sysctrl: should point to the AOBUS sysctrl node
+- amlogic,canvas: should point to a canvas provider node
+- clocks: should contain the following clocks :
+	- dos_parser
+	- dos
+	- vdec_1
+	- vdec_hevc
+- clock-names: should contain the names of the previous clocks
+- resets: should contain the parser reset
+- reset-names: should be "esparser"
+
+Example:
+
+vdec: video-decoder@c8820000 {
+	compatible = "amlogic,gxbb-vdec";
+	reg = <0x0 0xc8820000 0x0 0x10000>,
+	      <0x0 0xc110a580 0x0 0xe4>;
+	reg-names = "dos", "esparser";
+
+	interrupts = <GIC_SPI 44 IRQ_TYPE_EDGE_RISING>,
+		     <GIC_SPI 32 IRQ_TYPE_EDGE_RISING>;
+	interrupt-names = "vdec", "esparser";
+
+	amlogic,ao-sysctrl = <&sysctrl_AO>;
+	amlogic,canvas = <&canvas>;
+
+	clocks = <&clkc CLKID_DOS_PARSER>,
+		 <&clkc CLKID_DOS>,
+		 <&clkc CLKID_VDEC_1>,
+		 <&clkc CLKID_VDEC_HEVC>;
+	clock-names = "dos_parser", "dos", "vdec_1", "vdec_hevc";
+
+	resets = <&reset RESET_PARSER>;
+	reset-names = "esparser";
+};
Signature · 1 line
2.21.0
reviewer Reviewed-by on v6 1/4
#2 lore raw

Re: [PATCH v6 1/4] dt-bindings: media: add Amlogic Video Decoder Bindings

Hi Maxime,

Quoted 2 lines · Maxime Jourdan

Add documentation for the meson vdec dts node.

thank you for working on this!

Quoted 2 lines

[...]

Documentation/devicetree/bindings/media/amlogic,vdec.txt line 36

Quoted 13 lines
Documentation/devicetree/bindings/media/amlogic,vdec.txt new file +13 -0
+Required properties:
+- compatible: value should be different for each SoC family as :
+       - GXBB (S905) : "amlogic,gxbb-vdec"
+       - GXL (S905X, S905D) : "amlogic,gxl-vdec"
+       - GXM (S912) : "amlogic,gxm-vdec"
+- reg: base address and size of he following memory-mapped regions :
+       - dos
+       - esparser
+- reg-names: should contain the names of the previous memory regions
+- interrupts: should contain the following IRQs:
+       - vdec
+       - esparser
+- interrupt-names: should contain the names of the previous interrupts

Maxime already mentioned in the RFC version that there may be more interrupts in the future. I'm fine with adding the missing ones on demand

Quoted 1 line

+- amlogic,ao-sysctrl: should point to the AOBUS sysctrl node

my goal is to remove this property at some point and replace it with references to the power-domains.
however, we don't have a power-domain driver for this yet (it's somewhere on my TODO-list - it involves splitting the current meson-gx-pwrc-vpu into two separate drivers, so we need to do it carefully so we don't break HDMI support)

Regards
Martin

#3 lore raw

PATCH v6 2/4 media: videodev2: add V4L2_FMT_FLAG_FIXED_RESOLUTION

In reply to Maxime Jourdan

When a v4l2 driver exposes V4L2_EVENT_SOURCE_CHANGE, some (usually OUTPUT) formats may not be able to trigger this event.

For instance, MPEG2 on Amlogic hardware does not support resolution switching on the fly, and a decode session must operate at a set resolution defined before the decoding start.

Add a enum_fmt format flag to tag those specific formats.

---
 Documentation/media/uapi/v4l/vidioc-enum-fmt.rst | 6 ++++++
 include/uapi/linux/videodev2.h                   | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)
Documentation/media/uapi/v4l/vidioc-enum-fmt.rst +6 -0
index 822d6730e7d2..b11448a1848b 100644
@@ -127,6 +127,12 @@ one until ``EINVAL`` is returned.
       - This format is not native to the device but emulated through
 	software (usually libv4l2), where possible try to use a native
 	format instead for better performance.
+    * - ``V4L2_FMT_FLAG_FIXED_RESOLUTION``
+      - 0x0004
+      - Dynamic resolution switching is not supported for this format,
+        even if the event ``V4L2_EVENT_SOURCE_CHANGE`` is supported by
+        the device.
+
 
 
 Return Value
include/uapi/linux/videodev2.h +3 -2
index 1050a75fb7ef..9b0a7f82dd92 100644
@@ -768,8 +768,9 @@ struct v4l2_fmtdesc {
 	__u32		    reserved[4];
 };
 
-#define V4L2_FMT_FLAG_COMPRESSED 0x0001
-#define V4L2_FMT_FLAG_EMULATED   0x0002
+#define V4L2_FMT_FLAG_COMPRESSED	0x0001
+#define V4L2_FMT_FLAG_EMULATED		0x0002
+#define V4L2_FMT_FLAG_FIXED_RESOLUTION	0x0004
 
 	/* Frame Size and frame rate enumeration */
 /*
Signature · 1 line
2.21.0
#4 lore raw

PATCH v6 3/4 media: meson: add v4l2 m2m video decoder driver

In reply to Maxime Jourdan

Amlogic SoCs feature a powerful video decoder unit able to decode many formats, with a performance of usually up to 4k60.

This is a driver for this IP that is based around the v4l2 m2m framework.

It features decoding for:
- MPEG 1
- MPEG 2

Supported SoCs are: GXBB (S905), GXL (S905X/W/D), GXM (S912)

There is also a hardware bitstream parser (ESPARSER) that is handled here.

---
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 18 files changed, 2997 insertions(+)
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h
drivers/media/platform/Kconfig +10 -0
index 011c1c2fcf19..3469279c4c24 100644
@@ -501,6 +501,16 @@ config VIDEO_QCOM_VENUS
 	  on various Qualcomm SoCs.
 	  To compile this driver as a module choose m here.
 
+config VIDEO_MESON_VDEC
+	tristate "Amlogic video decoder driver"
+	depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
+	depends on ARCH_MESON || COMPILE_TEST
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_MEM2MEM_DEV
+	select MESON_CANVAS
+	help
+	Support for the video decoder found in gxbb/gxl/gxm chips.
+
 endif # V4L_MEM2MEM_DRIVERS
 
 # TI VIDEO PORT Helper Modules
drivers/media/platform/meson/Makefile +1 -0
index f611c23c3718..c75668b6bda3 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_VIDEO_MESON_AO_CEC)	+= ao-cec.o
 obj-$(CONFIG_VIDEO_MESON_G12A_AO_CEC)	+= ao-cec-g12a.o
+obj-$(CONFIG_VIDEO_MESON_VDEC)		+= vdec/
drivers/media/platform/meson/vdec/Makefile new file +8 -0
new file mode 100644
index 000000000000..eba86083aadb
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for Amlogic meson video decoder driver
+
+meson-vdec-objs = esparser.o vdec.o vdec_ctrls.o vdec_helpers.o vdec_platform.o
+meson-vdec-objs += vdec_1.o
+meson-vdec-objs += codec_mpeg12.o
+
+obj-$(CONFIG_VIDEO_MESON_VDEC) += meson-vdec.o
drivers/media/platform/meson/vdec/codec_mpeg12.c new file +209 -0

209 lines not on this page · raw message

drivers/media/platform/meson/vdec/codec_mpeg12.h new file +14 -0
new file mode 100644
index 000000000000..43cab5f39ca0
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#ifndef __MESON_VDEC_CODEC_MPEG12_H_
+#define __MESON_VDEC_CODEC_MPEG12_H_
+
+#include "vdec.h"
+
+extern struct amvdec_codec_ops codec_mpeg12_ops;
+
+#endif
drivers/media/platform/meson/vdec/dos_regs.h new file +98 -0

98 lines not on this page · raw message

drivers/media/platform/meson/vdec/esparser.c new file +323 -0

323 lines not on this page · raw message

drivers/media/platform/meson/vdec/esparser.h new file +32 -0
new file mode 100644
index 000000000000..ff51fe7fda66
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#ifndef __MESON_VDEC_ESPARSER_H_
+#define __MESON_VDEC_ESPARSER_H_
+
+#include <linux/platform_device.h>
+
+#include "vdec.h"
+
+int esparser_init(struct platform_device *pdev, struct amvdec_core *core);
+int esparser_power_up(struct amvdec_session *sess);
+
+/**
+ * esparser_queue_eos() - write End Of Stream sequence to the ESPARSER
+ *
+ * @core vdec core struct
+ */
+int esparser_queue_eos(struct amvdec_core *core, const u8 *data, u32 len);
+
+/**
+ * esparser_queue_all_src() - work handler that writes as many src buffers
+ * as possible to the ESPARSER
+ */
+void esparser_queue_all_src(struct work_struct *work);
+
+#define ESPARSER_MIN_PACKET_SIZE SZ_4K
+
+#endif
drivers/media/platform/meson/vdec/vdec.c new file +1071 -0

1,071 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec.h new file +265 -0

265 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec_1.c new file +229 -0

229 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec_1.h new file +14 -0
new file mode 100644
index 000000000000..042d930c40d7
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#ifndef __MESON_VDEC_VDEC_1_H_
+#define __MESON_VDEC_VDEC_1_H_
+
+#include "vdec.h"
+
+extern struct amvdec_ops vdec_1_ops;
+
+#endif
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +51 -0

51 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec_ctrls.h new file +14 -0
new file mode 100644
index 000000000000..91bf0aabc17e
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#ifndef __MESON_VDEC_CTRLS_H_
+#define __MESON_VDEC_CTRLS_H_
+
+#include "vdec.h"
+
+int amvdec_init_ctrls(struct v4l2_ctrl_handler *ctrl_handler);
+
+#endif
drivers/media/platform/meson/vdec/vdec_helpers.c new file +441 -0

441 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec_helpers.h new file +80 -0

80 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec_platform.c new file +107 -0

107 lines not on this page · raw message

drivers/media/platform/meson/vdec/vdec_platform.h new file +30 -0
new file mode 100644
index 000000000000..f6025326db1d
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#ifndef __MESON_VDEC_PLATFORM_H_
+#define __MESON_VDEC_PLATFORM_H_
+
+#include "vdec.h"
+
+struct amvdec_format;
+
+enum vdec_revision {
+	VDEC_REVISION_GXBB,
+	VDEC_REVISION_GXL,
+	VDEC_REVISION_GXM,
+};
+
+struct vdec_platform {
+	const struct amvdec_format *formats;
+	const u32 num_formats;
+	enum vdec_revision revision;
+};
+
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.21.0

Part of the diff is not shown here. View the raw message.

#5 lore raw

Re: [PATCH v6 3/4] media: meson: add v4l2 m2m video decoder driver

Hi Maxime,

First a high-level comment: I think this driver should go to staging. Once we finalize the stateful decoder spec, and we've updated the v4l2-compliance test, then this needs to be tested against that and only if it passes can it be moved out of staging.

It is just a bit too soon to have this in mainline at this time.

One other comment below:

Quoted 52 lines · Maxime Jourdan

Amlogic SoCs feature a powerful video decoder unit able to decode many formats, with a performance of usually up to 4k60.

This is a driver for this IP that is based around the v4l2 m2m framework.

It features decoding for:
- MPEG 1
- MPEG 2

Supported SoCs are: GXBB (S905), GXL (S905X/W/D), GXM (S912)

There is also a hardware bitstream parser (ESPARSER) that is handled here.

---
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 18 files changed, 2997 insertions(+)
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h

<snip>

Quoted 37 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +31 -0
new file mode 100644
index 000000000000..d5d6b1b97aa5
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#include "vdec_ctrls.h"
+
+static int vdec_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct amvdec_session *sess =
+	      container_of(ctrl->handler, struct amvdec_session, ctrl_handler);
+
+	switch (ctrl->id) {
+	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+		ctrl->val = sess->dpb_size;
+		break;
+	default:
+		return -EINVAL;
+	};
+
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops vdec_ctrl_ops = {
+	.g_volatile_ctrl = vdec_op_g_volatile_ctrl,
+};
+
+int amvdec_init_ctrls(struct v4l2_ctrl_handler *ctrl_handler)
+{
+	int ret;

drivers/media/platform/meson/vdec/vdec_ctrls.c line 41

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+	struct v4l2_ctrl *ctrl;
+
+	ret = v4l2_ctrl_handler_init(ctrl_handler, 1);
+	if (ret)
+		return ret;
+
+	ctrl = v4l2_ctrl_new_std(ctrl_handler, &vdec_ctrl_ops,
+		V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 32, 1, 1);
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;

Why is this volatile? That makes little sense.

drivers/media/platform/meson/vdec/vdec_ctrls.c line 51

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+
+	ret = ctrl_handler->error;
+	if (ret) {
+		v4l2_ctrl_handler_free(ctrl_handler);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(amvdec_init_ctrls);

<snip>

Regards,

Hans

#6 lore raw

Re: [PATCH v6 3/4] media: meson: add v4l2 m2m video decoder driver

Hi Hans,

Quoted 6 lines · Hans Verkuil

Hi Maxime,

First a high-level comment: I think this driver should go to staging. Once we finalize the stateful decoder spec, and we've updated the v4l2-compliance test, then this needs to be tested against that and only if it passes can it be moved out of staging.

I don't understand the reason since other stateful codecs are already mainline and doesn't match the in-discussion stateful decoder spec either.

Neil

Quoted 128 lines

It is just a bit too soon to have this in mainline at this time.

One other comment below:

Quoted 52 lines · Maxime Jourdan

Amlogic SoCs feature a powerful video decoder unit able to decode many formats, with a performance of usually up to 4k60.

This is a driver for this IP that is based around the v4l2 m2m framework.

It features decoding for:
- MPEG 1
- MPEG 2

Supported SoCs are: GXBB (S905), GXL (S905X/W/D), GXM (S912)

There is also a hardware bitstream parser (ESPARSER) that is handled here.

---
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 18 files changed, 2997 insertions(+)
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h

<snip>

Quoted 37 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +31 -0
new file mode 100644
index 000000000000..d5d6b1b97aa5
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#include "vdec_ctrls.h"
+
+static int vdec_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct amvdec_session *sess =
+	      container_of(ctrl->handler, struct amvdec_session, ctrl_handler);
+
+	switch (ctrl->id) {
+	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+		ctrl->val = sess->dpb_size;
+		break;
+	default:
+		return -EINVAL;
+	};
+
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops vdec_ctrl_ops = {
+	.g_volatile_ctrl = vdec_op_g_volatile_ctrl,
+};
+
+int amvdec_init_ctrls(struct v4l2_ctrl_handler *ctrl_handler)
+{
+	int ret;

drivers/media/platform/meson/vdec/vdec_ctrls.c line 41

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+	struct v4l2_ctrl *ctrl;
+
+	ret = v4l2_ctrl_handler_init(ctrl_handler, 1);
+	if (ret)
+		return ret;
+
+	ctrl = v4l2_ctrl_new_std(ctrl_handler, &vdec_ctrl_ops,
+		V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 32, 1, 1);
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;

Why is this volatile? That makes little sense.

drivers/media/platform/meson/vdec/vdec_ctrls.c line 51

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+
+	ret = ctrl_handler->error;
+	if (ret) {
+		v4l2_ctrl_handler_free(ctrl_handler);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(amvdec_init_ctrls);

<snip>

Regards,

Hans

#7 lore raw

Re: [PATCH v6 3/4] media: meson: add v4l2 m2m video decoder driver

Quoted 5 lines · Neil Armstrong

Hi Hans,

Quoted 2 lines · Hans Verkuil

Hi Maxime,

Quoted 7 lines
Quoted 4 lines

First a high-level comment: I think this driver should go to staging. Once we finalize the stateful decoder spec, and we've updated the v4l2-compliance test, then this needs to be tested against that and only if it passes can it be moved out of staging.

I don't understand the reason since other stateful codecs are already mainline and doesn't match the in-discussion stateful decoder spec either.

With new drivers we should do better: I don't want to add such drivers without them being fully tested for API compliance.

There is a bit too much variation in existing drivers and the main reason for that was lack of compliance testing. We're close to having a proper spec and proper compliance tests, but as long as that's not finalized I want to keep new codec drivers in staging.

Once the compliance tests are available, then we have an objective way of checking if a codec driver is following the spec.

Existing codec drivers in mainline will also have to be checked, for that matter.

Regards,

Hans

Quoted 132 lines

Neil

Quoted 128 lines

It is just a bit too soon to have this in mainline at this time.

One other comment below:

Quoted 52 lines · Maxime Jourdan

Amlogic SoCs feature a powerful video decoder unit able to decode many formats, with a performance of usually up to 4k60.

This is a driver for this IP that is based around the v4l2 m2m framework.

It features decoding for:
- MPEG 1
- MPEG 2

Supported SoCs are: GXBB (S905), GXL (S905X/W/D), GXM (S912)

There is also a hardware bitstream parser (ESPARSER) that is handled here.

---
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 18 files changed, 2997 insertions(+)
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h

<snip>

Quoted 37 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +31 -0
new file mode 100644
index 000000000000..d5d6b1b97aa5
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#include "vdec_ctrls.h"
+
+static int vdec_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct amvdec_session *sess =
+	      container_of(ctrl->handler, struct amvdec_session, ctrl_handler);
+
+	switch (ctrl->id) {
+	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+		ctrl->val = sess->dpb_size;
+		break;
+	default:
+		return -EINVAL;
+	};
+
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops vdec_ctrl_ops = {
+	.g_volatile_ctrl = vdec_op_g_volatile_ctrl,
+};
+
+int amvdec_init_ctrls(struct v4l2_ctrl_handler *ctrl_handler)
+{
+	int ret;

drivers/media/platform/meson/vdec/vdec_ctrls.c line 41

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+	struct v4l2_ctrl *ctrl;
+
+	ret = v4l2_ctrl_handler_init(ctrl_handler, 1);
+	if (ret)
+		return ret;
+
+	ctrl = v4l2_ctrl_new_std(ctrl_handler, &vdec_ctrl_ops,
+		V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 32, 1, 1);
+	if (ctrl)
+		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;

Why is this volatile? That makes little sense.

drivers/media/platform/meson/vdec/vdec_ctrls.c line 51

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+
+	ret = ctrl_handler->error;
+	if (ret) {
+		v4l2_ctrl_handler_free(ctrl_handler);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(amvdec_init_ctrls);

<snip>

Regards,

Hans

#8 lore raw

Re: [PATCH v6 3/4] media: meson: add v4l2 m2m video decoder driver

In reply to Hans Verkuil

Hi Hans,

Quoted 8 lines · Hans Verkuil

Hi Maxime,

First a high-level comment: I think this driver should go to staging. Once we finalize the stateful decoder spec, and we've updated the v4l2-compliance test, then this needs to be tested against that and only if it passes can it be moved out of staging.

I chose to send the driver supporting only MPEG2 for now as it keeps it "to the point", but as it turns out it's one of the few formats on Amlogic that can't fully respect the spec at the moment because of the lack of support for V4L2_EVENT_SOURCE_CHANGE, thus the patch in the series that adds a new flag V4L2_FMT_FLAG_FIXED_RESOLUTION. It basically requires userspace to set the format (i.e coded resolution) since the driver/fw can't probe it.
At the moment, this is described in the v3 spec like this:

Quoted 5 lines

1. Set the coded format on ``OUTPUT`` via :c:func:VIDIOC_S_FMT

* **Required fields:**

Quoted 10 lines
    ``type``
        a ``V4L2_BUF_TYPE_*`` enum appropriate for ``OUTPUT``

    ``pixelformat``
        a coded pixel format

    ``width``, ``height``
        required only if cannot be parsed from the stream for the given
        coded format; optional otherwise - set to zero to ignore

But MPEG2 being a format where the coded resolution is inside the bitstream, this is purely an Amlogic issue where the firmware doesn't extend the capability to do this.

Here's a proposal: if I were to resend the driver supporting only H264 and conforming to the spec, would you be considering it for inclusion in the main tree ? Does your current iteration of v4l2-compliance support testing stateful decoders with H264 bitstreams ?

Quoted 101 lines

It is just a bit too soon to have this in mainline at this time.

One other comment below:

Quoted 52 lines · Maxime Jourdan

Amlogic SoCs feature a powerful video decoder unit able to decode many formats, with a performance of usually up to 4k60.

This is a driver for this IP that is based around the v4l2 m2m framework.

It features decoding for:
- MPEG 1
- MPEG 2

Supported SoCs are: GXBB (S905), GXL (S905X/W/D), GXM (S912)

There is also a hardware bitstream parser (ESPARSER) that is handled here.

---
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 18 files changed, 2997 insertions(+)
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h

<snip>

Quoted 41 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +35 -0
new file mode 100644
index 000000000000..d5d6b1b97aa5
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#include "vdec_ctrls.h"
+
+static int vdec_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+     struct amvdec_session *sess =
+           container_of(ctrl->handler, struct amvdec_session, ctrl_handler);
+
+     switch (ctrl->id) {
+     case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+             ctrl->val = sess->dpb_size;
+             break;
+     default:
+             return -EINVAL;
+     };
+
+     return 0;
+}
+
+static const struct v4l2_ctrl_ops vdec_ctrl_ops = {
+     .g_volatile_ctrl = vdec_op_g_volatile_ctrl,
+};
+
+int amvdec_init_ctrls(struct v4l2_ctrl_handler *ctrl_handler)
+{
+     int ret;
+     struct v4l2_ctrl *ctrl;
+
+     ret = v4l2_ctrl_handler_init(ctrl_handler, 1);
+     if (ret)
Quoted 9 lines

drivers/media/platform/meson/vdec/vdec_ctrls.c line 41

Quoted 6 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +6 -0
+             return ret;
+
+     ctrl = v4l2_ctrl_new_std(ctrl_handler, &vdec_ctrl_ops,
+             V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 32, 1, 1);
+     if (ctrl)
+             ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;

Why is this volatile? That makes little sense.

I copied this over from other stateful decoders, they all used volatile so it didn't cross my mind too much.

It seems that there are 2 cases:
- the control is actually volatile, e.g its value is read from firmware.
- the control is not really volatile, e.g its value is set by the driver

My driver falls in the second case. Is the correct way to deal with that to use v4l2_ctrl_s_ctrl() and remove the volatile flag ?

Regards,
Maxime

Quoted 16 lines

drivers/media/platform/meson/vdec/vdec_ctrls.c line 51

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+
+     ret = ctrl_handler->error;
+     if (ret) {
+             v4l2_ctrl_handler_free(ctrl_handler);
+             return ret;
+     }
+
+     return 0;
+}
+EXPORT_SYMBOL_GPL(amvdec_init_ctrls);

<snip>

Regards,

Hans

#9 lore raw

Re: [PATCH v6 3/4] media: meson: add v4l2 m2m video decoder driver

Quoted 36 lines · Maxime Jourdan

Hi Hans,

Quoted 8 lines · Hans Verkuil

Hi Maxime,

First a high-level comment: I think this driver should go to staging. Once we finalize the stateful decoder spec, and we've updated the v4l2-compliance test, then this needs to be tested against that and only if it passes can it be moved out of staging.

I chose to send the driver supporting only MPEG2 for now as it keeps it "to the point", but as it turns out it's one of the few formats on Amlogic that can't fully respect the spec at the moment because of the lack of support for V4L2_EVENT_SOURCE_CHANGE, thus the patch in the series that adds a new flag V4L2_FMT_FLAG_FIXED_RESOLUTION. It basically requires userspace to set the format (i.e coded resolution) since the driver/fw can't probe it.
At the moment, this is described in the v3 spec like this:

Quoted 5 lines

1. Set the coded format on ``OUTPUT`` via :c:func:VIDIOC_S_FMT

* **Required fields:**

Quoted 10 lines
    ``type``
        a ``V4L2_BUF_TYPE_*`` enum appropriate for ``OUTPUT``

    ``pixelformat``
        a coded pixel format

    ``width``, ``height``
        required only if cannot be parsed from the stream for the given
        coded format; optional otherwise - set to zero to ignore
Quoted 8 lines

But MPEG2 being a format where the coded resolution is inside the bitstream, this is purely an Amlogic issue where the firmware doesn't extend the capability to do this.

Here's a proposal: if I were to resend the driver supporting only H264 and conforming to the spec, would you be considering it for inclusion in the main tree ? Does your current iteration of v4l2-compliance support testing stateful decoders with H264 bitstreams ?

The core problem is that the spec isn't finalized yet. The v3 spec you refer to above is old already since there are various changes planned.

If you want to test your driver with a v4l2-compliance that is likely to be close to the final version of the spec, then you can use this branch:

https://git.linuxtv.org/hverkuil/v4l-utils.git/log/?h=vicodec

You can test with:

v4l2-compliance -s --stream-from <file>

I wouldn't be too worried about keeping it in staging. Having it there will already be very nice indeed. Just add a TODO file that states that you are waiting for the final version of the stateful decoder spec and the corresponding compliance tests.

The V4L2_FMT_FLAG_FIXED_RESOLUTION isn't a blocker. That flag makes sense, and so it has nothing to do with keeping this driver in staging.

Regards,

Hans

Quoted 142 lines
Quoted 102 lines

It is just a bit too soon to have this in mainline at this time.

One other comment below:

Quoted 52 lines · Maxime Jourdan

Amlogic SoCs feature a powerful video decoder unit able to decode many formats, with a performance of usually up to 4k60.

This is a driver for this IP that is based around the v4l2 m2m framework.

It features decoding for:
- MPEG 1
- MPEG 2

Supported SoCs are: GXBB (S905), GXL (S905X/W/D), GXM (S912)

There is also a hardware bitstream parser (ESPARSER) that is handled here.

---
 drivers/media/platform/Kconfig                |   10 +
 drivers/media/platform/meson/Makefile         |    1 +
 drivers/media/platform/meson/vdec/Makefile    |    8 +
 .../media/platform/meson/vdec/codec_mpeg12.c  |  209 ++++
 .../media/platform/meson/vdec/codec_mpeg12.h  |   14 +
 drivers/media/platform/meson/vdec/dos_regs.h  |   98 ++
 drivers/media/platform/meson/vdec/esparser.c  |  323 +++++
 drivers/media/platform/meson/vdec/esparser.h  |   32 +
 drivers/media/platform/meson/vdec/vdec.c      | 1071 +++++++++++++++++
 drivers/media/platform/meson/vdec/vdec.h      |  265 ++++
 drivers/media/platform/meson/vdec/vdec_1.c    |  229 ++++
 drivers/media/platform/meson/vdec/vdec_1.h    |   14 +
 .../media/platform/meson/vdec/vdec_ctrls.c    |   51 +
 .../media/platform/meson/vdec/vdec_ctrls.h    |   14 +
 .../media/platform/meson/vdec/vdec_helpers.c  |  441 +++++++
 .../media/platform/meson/vdec/vdec_helpers.h  |   80 ++
 .../media/platform/meson/vdec/vdec_platform.c |  107 ++
 .../media/platform/meson/vdec/vdec_platform.h |   30 +
 18 files changed, 2997 insertions(+)
 create mode 100644 drivers/media/platform/meson/vdec/Makefile
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.c
 create mode 100644 drivers/media/platform/meson/vdec/codec_mpeg12.h
 create mode 100644 drivers/media/platform/meson/vdec/dos_regs.h
 create mode 100644 drivers/media/platform/meson/vdec/esparser.c
 create mode 100644 drivers/media/platform/meson/vdec/esparser.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_1.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_ctrls.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_helpers.h
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.c
 create mode 100644 drivers/media/platform/meson/vdec/vdec_platform.h

<snip>

Quoted 41 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +35 -0
new file mode 100644
index 000000000000..d5d6b1b97aa5
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 BayLibre, SAS
+ * Author: Maxime Jourdan <[email protected]>
+ */
+
+#include "vdec_ctrls.h"
+
+static int vdec_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
+{
+     struct amvdec_session *sess =
+           container_of(ctrl->handler, struct amvdec_session, ctrl_handler);
+
+     switch (ctrl->id) {
+     case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+             ctrl->val = sess->dpb_size;
+             break;
+     default:
+             return -EINVAL;
+     };
+
+     return 0;
+}
+
+static const struct v4l2_ctrl_ops vdec_ctrl_ops = {
+     .g_volatile_ctrl = vdec_op_g_volatile_ctrl,
+};
+
+int amvdec_init_ctrls(struct v4l2_ctrl_handler *ctrl_handler)
+{
+     int ret;
+     struct v4l2_ctrl *ctrl;
+
+     ret = v4l2_ctrl_handler_init(ctrl_handler, 1);
+     if (ret)
Quoted 9 lines

drivers/media/platform/meson/vdec/vdec_ctrls.c line 41

Quoted 6 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +6 -0
+             return ret;
+
+     ctrl = v4l2_ctrl_new_std(ctrl_handler, &vdec_ctrl_ops,
+             V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 32, 1, 1);
+     if (ctrl)
+             ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;

Why is this volatile? That makes little sense.

I copied this over from other stateful decoders, they all used volatile so it didn't cross my mind too much.

It seems that there are 2 cases:
- the control is actually volatile, e.g its value is read from firmware.
- the control is not really volatile, e.g its value is set by the driver

My driver falls in the second case. Is the correct way to deal with that to use v4l2_ctrl_s_ctrl() and remove the volatile flag ?

Regards,
Maxime

Quoted 16 lines

drivers/media/platform/meson/vdec/vdec_ctrls.c line 51

Quoted 10 lines
drivers/media/platform/meson/vdec/vdec_ctrls.c new file +10 -0
+
+     ret = ctrl_handler->error;
+     if (ret) {
+             v4l2_ctrl_handler_free(ctrl_handler);
+             return ret;
+     }
+
+     return 0;
+}
+EXPORT_SYMBOL_GPL(amvdec_init_ctrls);

<snip>

Regards,

Hans

#10 lore raw

Re: [PATCH v6 3/4] media: meson: add v4l2 m2m video decoder driver

Quoted 60 lines · Hans Verkuil
Quoted 36 lines · Maxime Jourdan

Hi Hans,

Quoted 8 lines · Hans Verkuil

Hi Maxime,

First a high-level comment: I think this driver should go to staging. Once we finalize the stateful decoder spec, and we've updated the v4l2-compliance test, then this needs to be tested against that and only if it passes can it be moved out of staging.

I chose to send the driver supporting only MPEG2 for now as it keeps it "to the point", but as it turns out it's one of the few formats on Amlogic that can't fully respect the spec at the moment because of the lack of support for V4L2_EVENT_SOURCE_CHANGE, thus the patch in the series that adds a new flag V4L2_FMT_FLAG_FIXED_RESOLUTION. It basically requires userspace to set the format (i.e coded resolution) since the driver/fw can't probe it.
At the moment, this is described in the v3 spec like this:

Quoted 5 lines

1. Set the coded format on ``OUTPUT`` via :c:func:VIDIOC_S_FMT

* **Required fields:**

Quoted 10 lines
    ``type``
        a ``V4L2_BUF_TYPE_*`` enum appropriate for ``OUTPUT``

    ``pixelformat``
        a coded pixel format

    ``width``, ``height``
        required only if cannot be parsed from the stream for the given
        coded format; optional otherwise - set to zero to ignore
Quoted 8 lines

But MPEG2 being a format where the coded resolution is inside the bitstream, this is purely an Amlogic issue where the firmware doesn't extend the capability to do this.

Here's a proposal: if I were to resend the driver supporting only H264 and conforming to the spec, would you be considering it for inclusion in the main tree ? Does your current iteration of v4l2-compliance support testing stateful decoders with H264 bitstreams ?

The core problem is that the spec isn't finalized yet. The v3 spec you refer to above is old already since there are various changes planned.

If you want to test your driver with a v4l2-compliance that is likely to be close to the final version of the spec, then you can use this branch:

https://git.linuxtv.org/hverkuil/v4l-utils.git/log/?h=vicodec

You can test with:

v4l2-compliance -s --stream-from <file>

Quoted 8 lines

I wouldn't be too worried about keeping it in staging. Having it there will already be very nice indeed. Just add a TODO file that states that you are waiting for the final version of the stateful decoder spec and the corresponding compliance tests.

The V4L2_FMT_FLAG_FIXED_RESOLUTION isn't a blocker. That flag makes sense, and so it has nothing to do with keeping this driver in staging.

Okay, I understand. I will send a v7 with the driver in staging+TODO+MAINTAINERS update.

Regards,
Maxime

Quoted 4 lines

Regards,

Hans

<snip>

#11 lore raw

PATCH v6 4/4 MAINTAINERS: Add meson video decoder

In reply to Maxime Jourdan

Add an entry for the meson video decoder for amlogic SoCs.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 878588cfb453..87c1e469ed63 100644
@@ -10057,6 +10057,14 @@ S:	Maintained
 F:	drivers/mtd/nand/raw/meson_*
 F:	Documentation/devicetree/bindings/mtd/amlogic,meson-nand.txt
 
+MESON VIDEO DECODER DRIVER FOR AMLOGIC SOCS
+M:	Maxime Jourdan <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Supported
+F:	drivers/media/platform/meson/vdec/
+T:	git git://linuxtv.org/media_tree.git
+
 METHODE UDPU SUPPORT
 M:	Vladimir Vid <[email protected]>
 S:	Maintained
Signature · 1 line
2.21.0