Add MT8173 Video Decoder Driver
Subsystems (4)
v3 cover Add MT8173 Video Decoder Driver
==============
Introduction
==============
The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream to V4L2_PIX_FMT_MT21 format.
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add V4L2_PIX_FMT_VP9 definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.
Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
==================
Device interface
==================
In principle the driver bases on v4l2 memory-to-memory framework:
it provides a single video node and each opened file handle gets its own private context with separate buffer queues. Each context consist of 2 buffer queues: OUTPUT (for source buffers, i.e. bitstream) and CAPTURE (for destination buffers, i.e. decoded video frames).
OUTPUT and CAPTURE buffer could be MMAP or DMABUF memory type.VIDIOC_G_CTRL and VIDIOC_G_EXT_CTRLS return V4L2_CID_MIN_BUFFERS_FOR_CAPTURE only when dirver in MTK_STATE_HEADER state, or it will return EAGAIN.
Driver do not support subscribe event for control 'User Controls' for now.
And it default support export DMABUF for other display drivers.
Change in v3:
1. Refine vdec hw clock setting
2. Refine vp9 codec driver
3. Refine v4l2 codec driver
Change in v2:
1. Add documentation for V4L2_PIX_FMT_MT21
2. Remove DRM_FORMAT_MT21
2. Refine code according to review comments
v4l2-compliance test output:
localhost Encode # ./v4l2-compliance -d /dev/video0 Driver Info:
Driver name : mtk-vcodec-dec
Card type : platform:mt8173
Bus info : platform:mt8173 Driver version: 4.4.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
Compliance test for device /dev/video0 (not using libv4l2):
Required ioctls:
test VIDIOC_QUERYCAP: OK
Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: 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_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357): g_ctrl returned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579): g_ext_ctrls returned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
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)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 test VIDIOC_G_FMT: FAIL
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: 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
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500): q.has_expbuf(node) test VIDIOC_EXPBUF: FAIL
Total: 38, Succeeded: 33, Failed: 5, Warnings: 0
Andrew-CT Chen (1):
VPU: mediatek: Add decode support
Tiffany Lin (8):
v4l: add Mediatek compressed video block format DocBook/v4l: Add compressed video formats used on MT8173 codec driver
dt-bindings: Add a binding for Mediatek Video Decoder
vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
vcodec: mediatek: Add Mediatek H264 Video Decoder Driver
vcodec: mediatek: Add Mediatek VP8 Video Decoder Driver
vcodec: mediatek: Add Mediatek VP9 Video Decoder Driver
arm64: dts: mediatek: Add Video Decoder for MT8173
Documentation/DocBook/media/v4l/pixfmt.xml | 6 + .../devicetree/bindings/media/mediatek-vcodec.txt | 57 +- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 44 + drivers/media/platform/mtk-vcodec/Makefile | 15 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1348 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h | 88 ++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 408 ++++++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 206 +++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 28 + drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 88 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.c | 4 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.h | 2 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.c | 31 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.h | 7 +- .../media/platform/mtk-vcodec/vdec/vdec_h264_if.c | 503 ++++++++ .../media/platform/mtk-vcodec/vdec/vdec_vp8_if.c | 630 +++++++++ .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c | 967 ++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_base.h | 56 + drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 117 ++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 101 ++ drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h | 103 ++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.c | 168 +++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.h | 96 ++ drivers/media/platform/mtk-vpu/mtk_vpu.c | 12 + drivers/media/platform/mtk-vpu/mtk_vpu.h | 27 + include/uapi/linux/videodev2.h | 1 + 26 files changed, 5090 insertions(+), 23 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
Signature · 1 line
1.7.9.5
PATCH v3 1/9 VPU: mediatek: Add decode support
From: Andrew-CT Chen <[email protected]>
VPU driver add decode support
--- drivers/media/platform/mtk-vpu/mtk_vpu.c | 12 ++++++++++++ drivers/media/platform/mtk-vpu/mtk_vpu.h | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/media/platform/mtk-vpu/mtk_vpu.c +12 -0
@@ -134,6 +134,8 @@ struct vpu_wdt {* * @signaled: the signal of vpu initialization completed * @fw_ver: VPU firmware version +* @dec_capability: decoder capability which is not used for now and +* the value is reserved for future use * @enc_capability: encoder capability which is not used for now and * the value is reserved for future use * @wq: wait queue for VPU initialization status
@@ -141,6 +143,7 @@ struct vpu_wdt {struct vpu_run {u32 signaled;char fw_ver[VPU_FW_VER_LEN ]; +unsigned int dec_capability;unsigned int enc_capability;wait_queue_head_t wq; };
@@ -415,6 +418,14 @@ int vpu_wdt_reg_handler(struct platform_device *pdev, }EXPORT_SYMBOL_GPL (vpu_wdt_reg_handler); +unsigned int vpu_get_vdec_hw_capa (struct platform_device *pdev) +{ +struct mtk_vpu *vpu =platform_get_drvdata (pdev); + +return vpu->run.dec_capability; +} +EXPORT_SYMBOL_GPL (vpu_get_vdec_hw_capa); +unsigned int vpu_get_venc_hw_capa (struct platform_device *pdev) {struct mtk_vpu *vpu =platform_get_drvdata (pdev);
@@ -600,6 +611,7 @@ static void vpu_init_ipi_handler(void *data, unsigned int len, void *priv) vpu->run.signaled = run->signaled;strncpy (vpu->run.fw_ver, run->fw_ver,VPU_FW_VER_LEN ); + vpu->run.dec_capability = run->dec_capability; vpu->run.enc_capability = run->enc_capability;wake_up_interruptible (&vpu->run.wq); }
drivers/media/platform/mtk-vpu/mtk_vpu.h +27 -0
@@ -37,6 +37,18 @@ typedef void (*ipi_handler_t) (void *data, command to VPU. For other IPI below, AP should send the request to VPU to trigger the interrupt. + * @IPI_VDEC_H264: The interrupt from vpu is to notify kernel to + handle H264 vidoe decoder job, and vice versa. + Decode output format is always MT21 no matter what + the input format is. + * @IPI_VDEC_VP8: The interrupt from is to notify kernel to + handle VP8 video decoder job, and vice versa. + Decode output format is always MT21 no matter what + the input format is. + * @IPI_VDEC_VP9: The interrupt from vpu is to notify kernel to + handle VP9 video decoder job, and vice versa. + Decode output format is always MT21 no matter what + the input format is. * @IPI_VENC_H264: The interrupt from vpu is to notify kernel to handle H264 video encoder job, and vice versa. * @IPI_VENC_VP8: The interrupt fro vpu is to notify kernel to
@@ -46,6 +58,9 @@ typedef void (*ipi_handler_t) (void *data,enum ipi_id {IPI_VPU_INIT =0 , +IPI_VDEC_H264 , +IPI_VDEC_VP8 , +IPI_VDEC_VP9 ,IPI_VENC_H264 ,IPI_VENC_VP8 ,IPI_MAX ,
@@ -55,10 +70,12 @@ enum ipi_id {* enum rst_id - reset id to register reset function for VPU watchdog timeout * * @VPU_RST_ENC: encoder reset id +* @VPU_RST_DEC: decoder reset id * @VPU_RST_MAX: maximum reset id */ enum rst_id {VPU_RST_ENC , +VPU_RST_DEC ,VPU_RST_MAX , };
@@ -125,6 +142,16 @@ struct platform_device *vpu_get_plat_device(struct platform_device *pdev);int vpu_wdt_reg_handler (struct platform_device *pdev,void vpu_wdt_reset_func (void *),void *priv,enum rst_id id); + +/** +* vpu_get_vdec_hw_capa - get video decoder hardware capability +* +* @pdev: VPU platform device +* +* Return: video decoder hardware capability +**/ +unsigned int vpu_get_vdec_hw_capa (struct platform_device *pdev); +/** * vpu_get_venc_hw_capa - get video encoder hardware capability *
Signature · 1 line
1.7.9.5
PATCH v3 2/9 v4l: add Mediatek compressed video block format
Add V4L2_PIX_FMT_MT21 format used on MT8173 driver.
It is compressed format and need MT8173 MDP driver to transfer to other standard format.
--- include/uapi/linux/videodev2.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/videodev2.h +1 -0
@@ -625,6 +625,7 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ')/* Greyscale 8-bit L/R interleaved */ #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I')/* Greyscale 12-bit L/R interleaved */ #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ')/* Depth data 16-bit */ +#define V4L2_PIX_FMT_MT21 v4l2_fourcc('M', 'T', '2', '1')/* Mediatek compressed block mode */ /* SDR formats - used only for Software Defined Radio devices */ #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8')/* IQ u8 */
Signature · 1 line
1.7.9.5
PATCH v3 3/9 DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Add V4L2_PIX_FMT_MT21 documentation
--- Documentation/DocBook/media/v4l/pixfmt.xml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/DocBook/media/v4l/pixfmt.xml +6 -0
@@ -1980,6 +1980,12 @@ array. Anything what's in between the UYVY lines is JPEG data and should be concatenated to form the JPEG stream. </para> </entry> </row> + <row id="V4L2_PIX_FMT_MT21"> + <entry><constant>V4L2_PIX_FMT_MT21</constant></entry> + <entry>'MT21'</entry> + <entry>Compressed two-planar YVU420 format used by Mediatek MT8173 + codec driver.</entry> + </row> </tbody> </tgroup> </table>
Signature · 1 line
1.7.9.5
PATCH v3 4/9 dt-bindings: Add a binding for Mediatek Video Decoder
Add a DT binding documentation of Video Decoder for the MT8173 SoC from Mediatek.
--- .../devicetree/bindings/media/mediatek-vcodec.txt | 57 ++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +53 -4
@@ -1,25 +1,74 @@ Mediatek Video Codec Mediatek Video Codec is the video codec hw present in Mediatek SoCs which -supports high resolution encoding functionalities. +supports high resolution encoding and decoding functionalities. Required properties: - compatible : "mediatek,mt8173-vcodec-enc" for encoder + "mediatek,mt8173-vcodec-dec" for decoder. - reg : Physical base address of the video codec registers and length of memory mapped region. - interrupts : interrupt number to the cpu. - mediatek,larb : must contain the local arbiters in the current Socs. - clocks : list of clock specifiers, corresponding to entries in the clock-names property. -- clock-names: encoder must contain "venc_sel_src", "venc_sel", -- "venc_lt_sel_src", "venc_lt_sel". +- clock-names: encoder must contain "venc_sel_src", "venc_sel",, + "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll", + "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll", + "venc_lt_sel", "vdec_bus_clk_src". - iommus : should point to the respective IOMMU block with master port as argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt for details. - mediatek,vpu : the node of video processor unit + Example: -vcodec_enc: vcodec at 0x18002000 { + +vcodec_dec: vcodec at 16000000 { + compatible = "mediatek,mt8173-vcodec-dec"; + reg = <0 0x16000000 0 0x100>, /*VDEC_SYS*/ + <0 0x16020000 0 0x1000>, /*VDEC_MISC*/ + <0 0x16021000 0 0x800>, /*VDEC_LD*/ + <0 0x16021800 0 0x800>, /*VDEC_TOP*/ + <0 0x16022000 0 0x1000>, /*VDEC_CM*/ + <0 0x16023000 0 0x1000>, /*VDEC_AD*/ + <0 0x16024000 0 0x1000>, /*VDEC_AV*/ + <0 0x16025000 0 0x1000>, /*VDEC_PP*/ + <0 0x16026800 0 0x800>, /*VP8_VD*/ + <0 0x16027000 0 0x800>, /*VP6_VD*/ + <0 0x16027800 0 0x800>, /*VP8_VL*/ + <0 0x16028400 0 0x400>; /*VP9_VD*/ + interrupts = <GIC_SPI 204 IRQ_TYPE_LEVEL_LOW>; + mediatek,larb = <&larb1>; + iommus = <&iommu M4U_PORT_HW_VDEC_MC_EXT>, + <&iommu M4U_PORT_HW_VDEC_PP_EXT>, + <&iommu M4U_PORT_HW_VDEC_AVC_MV_EXT>, + <&iommu M4U_PORT_HW_VDEC_PRED_RD_EXT>, + <&iommu M4U_PORT_HW_VDEC_PRED_WR_EXT>, + <&iommu M4U_PORT_HW_VDEC_UFO_EXT>, + <&iommu M4U_PORT_HW_VDEC_VLD_EXT>, + <&iommu M4U_PORT_HW_VDEC_VLD2_EXT>; + mediatek,vpu = <&vpu>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_VDEC>; + clocks = <&apmixedsys CLK_APMIXED_VCODECPLL>, + <&topckgen CLK_TOP_UNIVPLL_D2>, + <&topckgen CLK_TOP_CCI400_SEL>, + <&topckgen CLK_TOP_VDEC_SEL>, + <&topckgen CLK_TOP_VCODECPLL>, + <&apmixedsys CLK_APMIXED_VENCPLL>, + <&topckgen CLK_TOP_VENC_LT_SEL>, + <&topckgen CLK_TOP_VCODECPLL_370P5>; + clock-names = "vcodecpll", + "univpll_d2", + "clk_cci400_sel", + "vdec_sel", + "vdecpll", + "vencpll", + "venc_lt_sel", + "vdec_bus_clk_src"; + }; + + vcodec_enc: vcodec at 0x18002000 { compatible = "mediatek,mt8173-vcodec-enc"; reg = <0 0x18002000 0 0x1000>, /*VENC_SYS*/ <0 0x19002000 0 0x1000>; /*VENC_LT_SYS*/
Signature · 1 line
1.7.9.5
PATCH v3 5/9 vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
Add v4l2 layer decoder driver for MT8173
--- drivers/media/platform/mtk-vcodec/Makefile | 10 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1348 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h | 88 ++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 408 ++++++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 206 +++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 28 + drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 88 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.c | 4 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.h | 2 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.c | 31 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.h | 7 +- drivers/media/platform/mtk-vcodec/vdec_drv_base.h | 56 + drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 107 ++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 101 ++ drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h | 103 ++ 15 files changed, 2569 insertions(+), 18 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
drivers/media/platform/mtk-vcodec/Makefile +8 -2
@@ -1,7 +1,13 @@ -obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-enc.o mtk-vcodec-common.o - +obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ + mtk-vcodec-enc.o \ + mtk-vcodec-common.o + +mtk-vcodec-dec-y := mtk_vcodec_dec_drv.o \ + vdec_drv_if.o \ + mtk_vcodec_dec.o \ + mtk_vcodec_dec_pm.o \ mtk-vcodec-enc-y := venc/venc_vp8_if.o \
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1348 -0
1,348 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h new file +88 -0
88 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +408 -0
408 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c new file +206 -0
206 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _MTK_VCODEC_DEC_PM_H_ +#define _MTK_VCODEC_DEC_PM_H_ + +#include "mtk_vcodec_drv.h" + +int mtk_vcodec_init_dec_pm (struct mtk_vcodec_dev *dev); +void mtk_vcodec_release_dec_pm (struct mtk_vcodec_dev *dev); + +void mtk_vcodec_dec_pw_on (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_pw_off (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_clock_on (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_clock_off (struct mtk_vcodec_pm *pm); + +#endif /* _MTK_VCODEC_DEC_PM_H_ */
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +81 -7
193 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c +2 -2
@@ -30,8 +30,7 @@ int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command, timeout_jiff =msecs_to_jiffies (timeout_ms); ret =wait_event_interruptible_timeout (*waitqueue, - (ctx->int_cond && - (ctx->int_type == command)), + ctx->int_cond, timeout_jiff);if (!ret) {
@@ -52,3 +51,4 @@ int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command,return status; }EXPORT_SYMBOL (mtk_vcodec_wait_for_done_ctx); +
drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h +1 -1
@@ -16,7 +16,7 @@#define _MTK_VCODEC_INTR_H_#define MTK_INST_IRQ_RECEIVED 0x1 -#define MTK_INST_WORK_THREAD_ABORT_DONE 0x2 +struct mtk_vcodec_ctx ;
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +26 -5
@@ -81,14 +81,35 @@ void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,return ; } -dma_free_coherent (dev, size, mem->va, mem->dma_addr); - mem->va =NULL ; - mem->dma_addr =0 ; - mem->size =0 ; -mtk_v4l2_debug (3 ,"[%d] - va = %p" , ctx->id, mem->va);mtk_v4l2_debug (3 ,"[%d] - dma = 0x%lx" , ctx->id, (unsigned long )mem->dma_addr);mtk_v4l2_debug (3 ,"[%d] size = 0x%lx" , ctx->id, size); + +dma_free_coherent (dev, size, mem->va, mem->dma_addr); + mem->va =NULL ; + mem->dma_addr =0 ; + mem->size =0 ; }EXPORT_SYMBOL (mtk_vcodec_mem_free); + +void mtk_vcodec_set_curr_ctx (struct mtk_vcodec_dev *dev, +struct mtk_vcodec_ctx *ctx) +{ +unsigned long flags; + +spin_lock_irqsave (&dev->irqlock, flags); + dev->curr_ctx = ctx; +spin_unlock_irqrestore (&dev->irqlock, flags); +} + +struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx (struct mtk_vcodec_dev *dev) +{ +unsigned long flags; +struct mtk_vcodec_ctx *ctx; + +spin_lock_irqsave (&dev->irqlock, flags); + ctx = dev->curr_ctx; +spin_unlock_irqrestore (&dev->irqlock, flags); +return ctx; +}
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +6 -1
@@ -1,7 +1,7 @@/* * Copyright (c) 2016 MediaTek Inc. * Author: PC Chen <[email protected]> -* Tiffany Lin <[email protected]> +* Tiffany Lin <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -26,6 +26,7 @@ struct mtk_vcodec_mem { };struct mtk_vcodec_ctx ; +struct mtk_vcodec_dev ;extern int mtk_v4l2_dbg_level;extern bool mtk_vcodec_dbg;
@@ -84,4 +85,8 @@ int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, struct mtk_vcodec_mem *mem);void mtk_vcodec_mem_free (struct mtk_vcodec_ctx *data,struct mtk_vcodec_mem *mem); +void mtk_vcodec_set_curr_ctx (struct mtk_vcodec_dev *dev, +struct mtk_vcodec_ctx *ctx); +struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx (struct mtk_vcodec_dev *dev); +#endif /* _MTK_VCODEC_UTIL_H_ */
drivers/media/platform/mtk-vcodec/vdec_drv_base.h new file +56 -0
56 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_drv_if.c new file +107 -0
107 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_drv_if.h new file +101 -0
101 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 6/9 vcodec: mediatek: Add Mediatek H264 Video Decoder Driver
Add h264 decoder driver for MT8173
--- drivers/media/platform/mtk-vcodec/Makefile | 5 +- .../media/platform/mtk-vcodec/vdec/vdec_h264_if.c | 503 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 4 + drivers/media/platform/mtk-vcodec/vdec_vpu_if.c | 168 +++++++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.h | 96 ++++ 5 files changed, 774 insertions(+), 2 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
drivers/media/platform/mtk-vcodec/Makefile +3 -2
@@ -1,11 +1,12 @@ - obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ mtk-vcodec-enc.o \ mtk-vcodec-common.o -mtk-vcodec-dec-y := mtk_vcodec_dec_drv.o \ +mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ + mtk_vcodec_dec_drv.o \ vdec_drv_if.o \ + vdec_vpu_if.o \ mtk_vcodec_dec.o \ mtk_vcodec_dec_pm.o \
drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c new file +503 -0
503 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_drv_if.c +4 -0
@@ -24,12 +24,16 @@#include "mtk_vcodec_util.h" #include "mtk_vpu.h" +struct vdec_common_if *get_h264_dec_comm_if (void ); +int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc) {int ret =0 ;switch (fourcc) {case V4L2_PIX_FMT_H264 : + ctx->dec_if =get_h264_dec_comm_if (); +break ;case V4L2_PIX_FMT_VP8 :case V4L2_PIX_FMT_VP9 :default :
drivers/media/platform/mtk-vcodec/vdec_vpu_if.c new file +168 -0
168 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_vpu_if.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 7/9 vcodec: mediatek: Add Mediatek VP8 Video Decoder Driver
Add vp8 decoder driver for MT8173
--- drivers/media/platform/mtk-vcodec/Makefile | 1 + .../media/platform/mtk-vcodec/vdec/vdec_vp8_if.c | 630 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 3 + 3 files changed, 634 insertions(+) create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
drivers/media/platform/mtk-vcodec/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ mtk-vcodec-common.o mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ + vdec/vdec_vp8_if.o \ mtk_vcodec_dec_drv.o \ vdec_drv_if.o \ vdec_vpu_if.o \
drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c new file +630 -0
630 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_drv_if.c +3 -0
@@ -25,6 +25,7 @@#include "mtk_vpu.h" struct vdec_common_if *get_h264_dec_comm_if (void ); +struct vdec_common_if *get_vp8_dec_comm_if (void );int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc) {
@@ -35,6 +36,8 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if =get_h264_dec_comm_if ();break ;case V4L2_PIX_FMT_VP8 : + ctx->dec_if =get_vp8_dec_comm_if (); +break ;case V4L2_PIX_FMT_VP9 :default :return -EINVAL ;
Signature · 1 line
1.7.9.5
PATCH v3 8/9 vcodec: mediatek: Add Mediatek VP9 Video Decoder Driver
Add vp9 decoder driver for MT8173
--- drivers/media/platform/mtk-vcodec/Makefile | 1 + .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c | 967 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 3 + 3 files changed, 971 insertions(+) create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
drivers/media/platform/mtk-vcodec/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ + vdec/vdec_vp9_if.o \ mtk_vcodec_dec_drv.o \ vdec_drv_if.o \ vdec_vpu_if.o \
drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c new file +967 -0
967 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/vdec_drv_if.c +3 -0
@@ -26,6 +26,7 @@struct vdec_common_if *get_h264_dec_comm_if (void );struct vdec_common_if *get_vp8_dec_comm_if (void ); +struct vdec_common_if *get_vp9_dec_comm_if (void );int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc) {
@@ -39,6 +40,8 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if =get_vp8_dec_comm_if ();break ;case V4L2_PIX_FMT_VP9 : + ctx->dec_if =get_vp9_dec_comm_if (); +break ;default :return -EINVAL ; }
Signature · 1 line
1.7.9.5
PATCH v3 9/9 arm64: dts: mediatek: Add Video Decoder for MT8173
Add video decoder node for MT8173
--- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +44 -0
@@ -691,6 +691,50 @@ #clock-cells = <1>; }; + vcodec_dec: vcodec at 16000000 { + compatible = "mediatek,mt8173-vcodec-dec"; + reg = <0 0x16000000 0 0x100>, /* VDEC_SYS */ + <0 0x16020000 0 0x1000>, /* VDEC_MISC */ + <0 0x16021000 0 0x800>, /* VDEC_LD */ + <0 0x16021800 0 0x800>, /* VDEC_TOP */ + <0 0x16022000 0 0x1000>, /* VDEC_CM */ + <0 0x16023000 0 0x1000>, /* VDEC_AD */ + <0 0x16024000 0 0x1000>, /* VDEC_AV */ + <0 0x16025000 0 0x1000>, /* VDEC_PP */ + <0 0x16026800 0 0x800>, /* VDEC_HWD */ + <0 0x16027000 0 0x800>, /* VDEC_HWQ */ + <0 0x16027800 0 0x800>, /* VDEC_HWB */ + <0 0x16028400 0 0x400>; /* VDEC_HWG */ + interrupts = <GIC_SPI 204 IRQ_TYPE_LEVEL_LOW>; + mediatek,larb = <&larb1>; + iommus = <&iommu M4U_PORT_HW_VDEC_MC_EXT>, + <&iommu M4U_PORT_HW_VDEC_PP_EXT>, + <&iommu M4U_PORT_HW_VDEC_AVC_MV_EXT>, + <&iommu M4U_PORT_HW_VDEC_PRED_RD_EXT>, + <&iommu M4U_PORT_HW_VDEC_PRED_WR_EXT>, + <&iommu M4U_PORT_HW_VDEC_UFO_EXT>, + <&iommu M4U_PORT_HW_VDEC_VLD_EXT>, + <&iommu M4U_PORT_HW_VDEC_VLD2_EXT>; + mediatek,vpu = <&vpu>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_VDEC>; + clocks = <&apmixedsys CLK_APMIXED_VCODECPLL>, + <&topckgen CLK_TOP_UNIVPLL_D2>, + <&topckgen CLK_TOP_CCI400_SEL>, + <&topckgen CLK_TOP_VDEC_SEL>, + <&topckgen CLK_TOP_VCODECPLL>, + <&apmixedsys CLK_APMIXED_VENCPLL>, + <&topckgen CLK_TOP_VENC_LT_SEL>, + <&topckgen CLK_TOP_VCODECPLL_370P5>; + clock-names = "vcodecpll", + "univpll_d2", + "clk_cci400_sel", + "vdec_sel", + "vdecpll", + "vencpll", + "venc_lt_sel", + "vdec_bus_clk_src"; + }; + larb1: larb at 16010000 { compatible = "mediatek,mt8173-smi-larb"; reg = <0 0x16010000 0 0x1000>;
Signature · 1 line
1.7.9.5
Re: [PATCH v3 5/9] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
In reply to Tiffany LinQuoted 148 lines · Tiffany Lin
Add v4l2 layer decoder driver for MT8173
Signed-off-by Tiffany Lin <[email protected]>--- drivers/media/platform/mtk-vcodec/Makefile | 10 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1348 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h | 88 ++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 408 ++++++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 206 +++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 28 + drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 88 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.c | 4 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.h | 2 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.c | 31 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.h | 7 +- drivers/media/platform/mtk-vcodec/vdec_drv_base.h | 56 + drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 107 ++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 101 ++ drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h | 103 ++ 15 files changed, 2569 insertions(+), 18 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.hdrivers/media/platform/mtk-vcodec/Makefile +8
-2@@ -1,7 +1,13 @@ -obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-enc.o mtk-vcodec-common.o - +obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ + mtk-vcodec-enc.o \ + mtk-vcodec-common.o + +mtk-vcodec-dec-y := mtk_vcodec_dec_drv.o \ + vdec_drv_if.o \ + mtk_vcodec_dec.o \ + mtk_vcodec_dec_pm.o \ mtk-vcodec-enc-y := venc/venc_vp8_if.o \drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +92
-0@@ -0,0 +1,1348 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <media/v4l2-event.h> +#include <media/v4l2-mem2mem.h> +#include <media/videobuf2-dma-contig.h> + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_dec.h" +#include "mtk_vcodec_intr.h" +#include "mtk_vcodec_util.h" +#include "vdec_drv_if.h" +#include "mtk_vcodec_dec_pm.h" + +#define OUT_FMT_IDX 0 +#define CAP_FMT_IDX 3 + +#define MTK_VDEC_MIN_W 64U +#define MTK_VDEC_MIN_H 64U +#define DFT_CFG_WIDTH MTK_VDEC_MIN_W +#define DFT_CFG_HEIGHT MTK_VDEC_MIN_H + +static struct mtk_video_fmt mtk_video_formats[] = { + { + .fourcc =V4L2_PIX_FMT_H264 , + .type =MTK_FMT_DEC , + .num_planes =1 , + }, + { + .fourcc =V4L2_PIX_FMT_VP8 , + .type =MTK_FMT_DEC , + .num_planes =1 , + }, + { + .fourcc =V4L2_PIX_FMT_VP9 , + .type =MTK_FMT_DEC , + .num_planes =1 , + }, + { + .fourcc =V4L2_PIX_FMT_MT21 , + .type =MTK_FMT_FRAME , + .num_planes =2 , + }, +}; + +static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = { + { + .fourcc =V4L2_PIX_FMT_H264 , + .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , +MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, + }, + { + .fourcc =V4L2_PIX_FMT_VP8 , + .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , +MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, + }, + { + .fourcc =V4L2_PIX_FMT_VP9 , + .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , +MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, + }, +}; + +#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes) +#define NUM_FORMATS ARRAY_SIZE(mtk_video_formats) + +static struct mtk_video_fmt *mtk_vdec_find_format (struct v4l2_format *f) +{ +struct mtk_video_fmt *fmt; +unsigned int k; + +for (k =0 ; k <NUM_FORMATS ; k++) { + fmt = &mtk_video_formats[k]; +if (fmt->fourcc == f->fmt.pix_mp.pixelformat) +return fmt; + } + +return NULL ; +} +
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 102
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+static struct mtk_q_data *mtk_vdec_get_q_data (struct mtk_vcodec_ctx *ctx, +enum v4l2_buf_type type) +{ +if (V4L2_TYPE_IS_OUTPUT (type)) +return &ctx->q_data[MTK_Q_DATA_SRC ]; + +return &ctx->q_data[MTK_Q_DATA_DST ]; +} + +/* This function is try to clean all display buffer, the buffer will return in
s/is try/tries/
s/buffer/buffers/ (2 times)
checkpatch should complain about this comment block format ('/*' should be on its own line). Please run checkpatch to double check.
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 104
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +2
-0+* display order. +* Note the buffer return from codec driver may still in driver's reference
s/buffer return/buffers returned/
s/still/still be/
Quoted 36 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +36
-0+* list. +*/ +static struct vb2_buffer *get_display_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct vdec_fb *disp_frame_buffer =NULL ; +struct mtk_video_dec_buf *dstbuf; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); +if (vdec_if_get_param (ctx, +GET_PARAM_DISP_FRAME_BUFFER , + &disp_frame_buffer)) { +mtk_v4l2_err ("[%d]Cannot get param : GET_PARAM_DISP_FRAME_BUFFER" , + ctx->id); +return NULL ; + } + +if (disp_frame_buffer ==NULL ) { +mtk_v4l2_debug (3 ,"No display frame buffer" ); +return NULL ; + } + + dstbuf = container_of(disp_frame_buffer, struct mtk_video_dec_buf, + frame_buffer); +mutex_lock (&ctx->lock); +if (dstbuf->used) { +vb2_set_plane_payload (&dstbuf->vb.vb2_buf,0 , + ctx->picinfo.y_bs_sz); +vb2_set_plane_payload (&dstbuf->vb.vb2_buf,1 , + ctx->picinfo.c_bs_sz); + + dstbuf->ready_to_display = true; + + mtk_v4l2_debug(2, + "[%d]status=%x queue id=%d to done_list %d", + ctx->id, disp_frame_buffer->status, + dstbuf->vb.vb2_buf.index,
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 150
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+ dstbuf->queued_in_vb2); + +v4l2_m2m_buf_done (&dstbuf->vb,VB2_BUF_STATE_DONE ); + ctx->decoded_frame_cnt++; + } +mutex_unlock (&ctx->lock); +return &dstbuf->vb.vb2_buf; +} + +/* This function is try to clean all capture buffers that is not used as
s/is try/tries/
s/is not/are not/
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 151
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1
-0+* reference buffer by codec driver any more
buffers
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 153
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +2
-0+* In this case, we need re-queue buffer to vb2 buffer if user space +* already return this buffer to v4l2 or this buffer is just the output of
returns
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 155
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +2
-0+* previous sps/pps/resolution change decode, or do nothing if user +* space still own this buffer
owns
Quoted 19 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +19
-0+*/ +static struct vb2_buffer *get_free_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct mtk_video_dec_buf *dstbuf; +struct vdec_fb *free_frame_buffer =NULL ; + +if (vdec_if_get_param (ctx, +GET_PARAM_FREE_FRAME_BUFFER , + &free_frame_buffer)) { +mtk_v4l2_err ("[%d] Error!! Cannot get param" , ctx->id); +return NULL ; + } +if (free_frame_buffer ==NULL ) { +mtk_v4l2_debug (3 ," No free frame buffer" ); +return NULL ; + } + +mtk_v4l2_debug (3 ,"[%d] tmp_frame_addr = 0x%p" , + ctx->id, free_frame_buffer);
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 184
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+ + dstbuf = container_of(free_frame_buffer, struct mtk_video_dec_buf, + frame_buffer); + +mutex_lock (&ctx->lock); +if (dstbuf->used) { +if ((dstbuf->queued_in_vb2) && + (dstbuf->queued_in_v4l2) && + (free_frame_buffer->status ==FB_ST_FREE )) { +/* After decode sps/pps or non-display buffer, we dont
don't
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 189
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+* need to return capture buffer to user space, but +* just re-queue this capture buffer to vb2 queue. +* This reduce overheads that dq/q unused capture +* buffer We use queued_in_vb2 to mark this buffer +* is from decode output, not q from user space.
garbled comment. Not sure what is meant here.
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+*/ + mtk_v4l2_debug(2, + "[%d]status=%x queue id=%d to rdy_queue %d", + ctx->id, free_frame_buffer->status, + dstbuf->vb.vb2_buf.index,
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 204
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+ dstbuf->queued_in_vb2); +v4l2_m2m_buf_queue (ctx->m2m_ctx, &dstbuf->vb); + }else if ((dstbuf->queued_in_vb2 == false) && + (dstbuf->queued_in_v4l2 == true)) { +/* If buffer in v4l2 driver but not in vb2 queue yet, +* and we get this buffer from free_list, it means +* that codec driver do not use this buffer as +* reference buffer anymore. We should q buffer to vb2 +* queue, so later work thread could get this buffer +* for decode In this sate, queued_in_vb2 = false
s/sate/case/
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 205
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1
-0+* menas this buffer is not from previous decode output
means
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 216
Quoted 11 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +11
-0+*/ +mtk_v4l2_debug (2 , +"[%d]status=%x queue id=%d to rdy_queue" , + ctx->id, free_frame_buffer->status, + dstbuf->vb.vb2_buf.index); +v4l2_m2m_buf_queue (ctx->m2m_ctx, &dstbuf->vb); + dstbuf->queued_in_vb2 = true; + }else { +/* Codec driver do not need to reference this capture +* buffer and this buffer is not in v4l2 driver. +* Then we dont need to do any thing, just add log when
don't
Quoted 25 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +25
-0+* we need to debug buffer flow. +* When this buffer q from user space, it could +* directly q to vb2 buffer +*/ +mtk_v4l2_debug (3 ,"[%d]status=%x err queue id=%d %d %d" , + ctx->id, free_frame_buffer->status, + dstbuf->vb.vb2_buf.index, + dstbuf->queued_in_vb2, + dstbuf->queued_in_v4l2); + } + dstbuf->used = false; + } +mutex_unlock (&ctx->lock); +return &dstbuf->vb.vb2_buf; +} + +static void clean_display_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct vb2_buffer *framptr; + +do { + framptr =get_display_buffer (ctx); + }while (framptr); +} +
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 251
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+static void clean_free_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct vb2_buffer *framptr; + +do { + framptr =get_free_buffer (ctx); + }while (framptr); +} + +static int mtk_vdec_queue_res_chg_event (struct mtk_vcodec_ctx *ctx)
This can be a void function.
Quoted 134 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +134
-0+{ +static const struct v4l2_event ev_src_ch = { + .type =V4L2_EVENT_SOURCE_CHANGE , + .u.src_change.changes = +V4L2_EVENT_SRC_CH_RESOLUTION , + }; + +mtk_v4l2_debug (1 ,"[%d]" , ctx->id); +v4l2_event_queue_fh (&ctx->fh, &ev_src_ch); + +return 0 ; +} + +static void mtk_vdec_flush_decoder (struct mtk_vcodec_ctx *ctx) +{ +bool res_chg; +int ret =0 ; + + ret =vdec_if_decode (ctx,NULL ,NULL , &res_chg); +if (ret) +mtk_v4l2_err ("DecodeFinal failed, ret=%d" , ret); + +clean_display_buffer (ctx); +clean_free_buffer (ctx); +} + +static void mtk_vdec_pic_info_update (struct mtk_vcodec_ctx *ctx) +{ +unsigned int dpbsize =0 ; +int ret; + +if (vdec_if_get_param (ctx, +GET_PARAM_PIC_INFO , + &ctx->last_decoded_picinfo)) { +mtk_v4l2_err ("[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR" , + ctx->id); +return ; + } + +if (ctx->last_decoded_picinfo.pic_w ==0 || + ctx->last_decoded_picinfo.pic_h ==0 || + ctx->last_decoded_picinfo.buf_w ==0 || + ctx->last_decoded_picinfo.buf_h ==0 ) { +mtk_v4l2_err ("Cannot get correct pic info" ); +return ; + } + +if ((ctx->last_decoded_picinfo.pic_w == ctx->picinfo.pic_w) || + (ctx->last_decoded_picinfo.pic_h == ctx->picinfo.pic_h)) +return ; + +mtk_v4l2_debug (1 , +"[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)" , + ctx->id, ctx->last_decoded_picinfo.pic_w, + ctx->last_decoded_picinfo.pic_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->last_decoded_picinfo.buf_w, + ctx->last_decoded_picinfo.buf_h); + + ret =vdec_if_get_param (ctx,GET_PARAM_DPB_SIZE , &dpbsize); +if (dpbsize ==0 ) +mtk_v4l2_err ("Incorrect dpb size, ret=%d" , ret); + + ctx->dpb_size = dpbsize; +} + +static void mtk_vdec_worker (struct work_struct *work) +{ + struct mtk_vcodec_ctx *ctx = container_of(work, struct mtk_vcodec_ctx, + decode_work); +struct mtk_vcodec_dev *dev = ctx->dev; +struct vb2_buffer *src_buf, *dst_buf; +struct mtk_vcodec_mem buf; +struct vdec_fb *pfb; +bool res_chg = false; +int ret; +struct mtk_video_dec_buf *dst_buf_info, *src_buf_info; +struct vb2_v4l2_buffer *dst_vb2_v4l2, *src_vb2_v4l2; + + src_buf =v4l2_m2m_next_src_buf (ctx->m2m_ctx); +if (src_buf ==NULL ) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_debug (1 ,"[%d] src_buf empty!!" , ctx->id); +return ; + } + + dst_buf =v4l2_m2m_next_dst_buf (ctx->m2m_ctx); +if (dst_buf ==NULL ) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_debug (1 ,"[%d] dst_buf empty!!" , ctx->id); +return ; + } + + src_vb2_v4l2 = container_of(src_buf, struct vb2_v4l2_buffer, vb2_buf); + src_buf_info = container_of(src_vb2_v4l2, struct mtk_video_dec_buf, vb); + + dst_vb2_v4l2 = container_of(dst_buf, struct vb2_v4l2_buffer, vb2_buf); + dst_buf_info = container_of(dst_vb2_v4l2, struct mtk_video_dec_buf, vb); + + buf.va =vb2_plane_vaddr (src_buf,0 ); + buf.dma_addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); + buf.size = (size_t )src_buf->planes[0 ].bytesused; +if (!buf.va) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_err ("[%d] id=%d src_addr is NULL!!" , + ctx->id, src_buf->index); +return ; + } + + pfb = &dst_buf_info->frame_buffer; + pfb->base_y.va =vb2_plane_vaddr (dst_buf,0 ); + pfb->base_y.dma_addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 ); + pfb->base_y.size = ctx->picinfo.y_bs_sz + ctx->picinfo.y_len_sz; + + pfb->base_c.va =vb2_plane_vaddr (dst_buf,1 ); + pfb->base_c.dma_addr =vb2_dma_contig_plane_dma_addr (dst_buf,1 ); + pfb->base_c.size = ctx->picinfo.c_bs_sz + ctx->picinfo.c_len_sz; + pfb->status =0 ; +mtk_v4l2_debug (3 ,"===>[%d] vdec_if_decode() ===>" , ctx->id); +mtk_v4l2_debug (3 ,"[%d] Bitstream VA=%p DMA=%llx Size=0x%lx vb=%p" , + ctx->id, buf.va, (u64 )buf.dma_addr, buf.size, src_buf); + +mtk_v4l2_debug (3 , +"id=%d Framebuf pfb=%p VA=%p Y_DMA=%llx C_DMA=%llx Size=0x%lx" , + dst_buf->index, pfb, + pfb->base_y.va, (u64 )pfb->base_y.dma_addr, + (u64 )pfb->base_c.dma_addr, pfb->base_y.size); + +if (src_buf_info->lastframe) { +/* update src buf status */ + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); + src_buf_info->lastframe = false; +v4l2_m2m_buf_done (&src_buf_info->vb,VB2_BUF_STATE_DONE ); +
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 395
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+/* update dst buf status */ + dst_buf =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx); + dst_buf_info->used = false; + +vdec_if_decode (ctx,NULL ,NULL , &res_chg); +clean_display_buffer (ctx); +vb2_set_plane_payload (&dst_buf_info->vb.vb2_buf,0 ,0 ); +vb2_set_plane_payload (&dst_buf_info->vb.vb2_buf,1 ,0 ); +v4l2_m2m_buf_done (&dst_buf_info->vb,VB2_BUF_STATE_DONE ); +clean_free_buffer (ctx);
Just call v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); here and return.
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1
-0+ }else {
This can now have one less TAB.
Quoted 226 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +226
-0+ dst_buf_info->vb.vb2_buf.timestamp + = src_buf_info->vb.vb2_buf.timestamp; + dst_buf_info->vb.timecode + = src_buf_info->vb.timecode; +mutex_lock (&ctx->lock); + dst_buf_info->used = true; +mutex_unlock (&ctx->lock); + src_buf_info->used = true; + + ret =vdec_if_decode (ctx, &buf, pfb, &res_chg); + +if (ret) { +mtk_v4l2_err ( +" <===[%d], src_buf[%d]%d sz=0x%zx pts=%llu dst_buf[%d] vdec_if_decode() ret=%d res_chg=%d===>" , + ctx->id, + src_buf->index, + src_buf_info->lastframe, + buf.size, + src_buf_info->vb.vb2_buf.timestamp, + dst_buf->index, + ret, res_chg); + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (&src_buf_info->vb, +VB2_BUF_STATE_ERROR ); + }else if (res_chg == false) { +/* we only return src buffer with VB2_BUF_STATE_DONE +* when decode success without resolution change +*/ + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (&src_buf_info->vb, +VB2_BUF_STATE_DONE ); + } + + dst_buf =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx); +clean_display_buffer (ctx); +clean_free_buffer (ctx); + +if (!ret && res_chg) { +mtk_vdec_pic_info_update (ctx); +/* +* On encountering a resolution change in the stream. +* The driver must first process and decode all +* remaining buffers from before the resolution change +* point, so call flush decode here +*/ +mtk_vdec_flush_decoder (ctx); +/* +* After all buffers containing decoded frames from +* before the resolution change point ready to be +* dequeued on the CAPTURE queue, the driver sends a +* V4L2_EVENT_SOURCE_CHANGE event for source change +* type V4L2_EVENT_SRC_CH_RESOLUTION +*/ +mtk_vdec_queue_res_chg_event (ctx); + } + } + +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +} + +void mtk_vdec_unlock (struct mtk_vcodec_ctx *ctx) +{ +mutex_unlock (&ctx->dev->dec_mutex); +} + +void mtk_vdec_lock (struct mtk_vcodec_ctx *ctx) +{ +mutex_lock (&ctx->dev->dec_mutex); +} + +void mtk_vcodec_vdec_release (struct mtk_vcodec_ctx *ctx) +{ +vdec_if_deinit (ctx); + ctx->state =MTK_STATE_FREE ; +} + +void mtk_vcodec_dec_set_default_params (struct mtk_vcodec_ctx *ctx) +{ +struct mtk_q_data *q_data; + + ctx->m2m_ctx->q_lock = &ctx->dev->dev_mutex; + ctx->fh.m2m_ctx = ctx->m2m_ctx; + ctx->fh.ctrl_handler = &ctx->ctrl_hdl; +INIT_WORK (&ctx->decode_work, mtk_vdec_worker); + ctx->colorspace =V4L2_COLORSPACE_REC709 ; + ctx->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + ctx->quantization =V4L2_QUANTIZATION_DEFAULT ; + ctx->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + + q_data = &ctx->q_data[MTK_Q_DATA_SRC ]; +memset (q_data,0 ,sizeof (struct mtk_q_data )); + q_data->visible_width =DFT_CFG_WIDTH ; + q_data->visible_height =DFT_CFG_HEIGHT ; + q_data->fmt = &mtk_video_formats[OUT_FMT_IDX ]; + q_data->field =V4L2_FIELD_NONE ; + + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ] = +DFT_CFG_WIDTH *DFT_CFG_HEIGHT ; + ctx->q_data[MTK_Q_DATA_DST ].bytesperline[0 ] =0 ; + + q_data = &ctx->q_data[MTK_Q_DATA_DST ]; +memset (q_data,0 ,sizeof (struct mtk_q_data )); + q_data->visible_width =DFT_CFG_WIDTH ; + q_data->visible_height =DFT_CFG_HEIGHT ; + q_data->coded_width =DFT_CFG_WIDTH ; + q_data->coded_height =DFT_CFG_HEIGHT ; + q_data->fmt = &mtk_video_formats[CAP_FMT_IDX ]; + q_data->field =V4L2_FIELD_NONE ; + +v4l_bound_align_image (&q_data->coded_width, +MTK_VDEC_MIN_W , +MTK_VDEC_MAX_W ,4 , + &q_data->coded_height, +MTK_VDEC_MIN_H , +MTK_VDEC_MAX_H ,5 ,6 ); + + q_data->sizeimage[0 ] = q_data->coded_width * q_data->coded_height; + q_data->bytesperline[0 ] = q_data->coded_width; + q_data->sizeimage[1 ] = q_data->sizeimage[0 ] /2 ; + q_data->bytesperline[1 ] = q_data->coded_width; +} + +static int vidioc_vdec_qbuf (struct file *file,void *priv, +struct v4l2_buffer *buf) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +struct vb2_queue *vq; +struct vb2_buffer *vb; +struct mtk_video_dec_buf *mtkbuf; +struct vb2_v4l2_buffer *vb2_v4l2; + +if (ctx->state ==MTK_STATE_ABORT ) { +mtk_v4l2_err ("[%d] Call on QBUF after unrecoverable error" , + ctx->id); +return -EIO ; + } + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx, buf->type); + vb = vq->bufs[buf->index]; + vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); + mtkbuf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb); + +if ((buf->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) && + (buf->m.planes[0 ].bytesused ==0 )) { + mtkbuf->lastframe = true; +mtk_v4l2_debug (1 ,"[%d] (%d) id=%d lastframe=%d (%d,%d, %d) vb=%p" , + ctx->id, buf->type, buf->index, + mtkbuf->lastframe, buf->bytesused, + buf->m.planes[0 ].bytesused, buf->length, + vb); + } + +return v4l2_m2m_qbuf (file, ctx->m2m_ctx, buf); +} + +static int vidioc_vdec_dqbuf (struct file *file,void *priv, +struct v4l2_buffer *buf) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); + +if (ctx->state ==MTK_STATE_ABORT ) { +mtk_v4l2_err ("[%d] Call on DQBUF after unrecoverable error" , + ctx->id); +return -EIO ; + } + +return v4l2_m2m_dqbuf (file, ctx->m2m_ctx, buf); +} + +static int vidioc_vdec_querycap (struct file *file,void *priv, +struct v4l2_capability *cap) +{ +strlcpy (cap->driver,MTK_VCODEC_DEC_NAME ,sizeof (cap->driver)); +strlcpy (cap->bus_info,MTK_PLATFORM_STR ,sizeof (cap->bus_info)); +strlcpy (cap->card,MTK_PLATFORM_STR ,sizeof (cap->card)); + +return 0 ; +} + +static int vidioc_vdec_subscribe_evt (struct v4l2_fh *fh, +const struct v4l2_event_subscription *sub) +{ +switch (sub->type) { +case V4L2_EVENT_EOS : +return v4l2_event_subscribe (fh, sub,2 ,NULL ); +case V4L2_EVENT_SOURCE_CHANGE : +return v4l2_src_change_event_subscribe (fh, sub); +default : +return v4l2_ctrl_subscribe_event (fh, sub); + } +} + +static int vidioc_try_fmt_vid_cap_mplane (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct mtk_video_fmt *fmt; + + fmt =mtk_vdec_find_format (f); +if (!fmt) { + f->fmt.pix.pixelformat = mtk_video_formats[CAP_FMT_IDX ].fourcc; + fmt =mtk_vdec_find_format (f); + } + +return 0 ; +} + +static int vidioc_try_fmt_vid_out_mplane (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp; +struct mtk_video_fmt *fmt; + + fmt =mtk_vdec_find_format (f); +if (!fmt) { + f->fmt.pix.pixelformat = mtk_video_formats[OUT_FMT_IDX ].fourcc; + fmt =mtk_vdec_find_format (f); + } + +if (pix_fmt_mp->plane_fmt[0 ].sizeimage ==0 ) { +mtk_v4l2_err ("sizeimage of output format must be given" ); +return -EINVAL ; + } + +return 0 ; +} +
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 632
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+static int vidioc_vdec_g_selection (struct file *file,void *priv, +struct v4l2_selection *s) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); + +if (V4L2_TYPE_IS_OUTPUT (s->type)) +return -EINVAL ; + +if (s->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ;
How does the cropping rectangle relate to the format size? There is no s_selection, so this doesn't make sense.
Alternatively, it could be that you are really returning V4L2_SEL_TGT_COMPOSE_PADDED.
Quoted 307 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +307
-0+ +if (ctx->state <MTK_STATE_HEADER ) +return -EINVAL ; + +if ((ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_H264 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP8 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP9 )) { + +if (vdec_if_get_param (ctx,GET_PARAM_CROP_INFO , &(s->r))) { +mtk_v4l2_debug (2 , +"[%d]Error!! Cannot get param : GET_PARAM_CROP_INFO ERR" , + ctx->id); + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.buf_w; + s->r.height = ctx->picinfo.buf_h; + } +mtk_v4l2_debug (2 ,"Cropping info: l=%d t=%d w=%d h=%d" , + s->r.left, s->r.top, s->r.width, + s->r.height); + }else { + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.pic_w; + s->r.height = ctx->picinfo.pic_h; +mtk_v4l2_debug (2 ,"Cropping info: w=%d h=%d fw=%d fh=%d" , + s->r.width, s->r.height, ctx->picinfo.buf_w, + ctx->picinfo.buf_h); + } +return 0 ; +} + +static int vidioc_vdec_s_fmt (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +struct v4l2_pix_format_mplane *pix_mp; +struct mtk_q_data *q_data; +int ret =0 ; +struct mtk_video_fmt *fmt; +struct vb2_queue *vq; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); + + fmt =mtk_vdec_find_format (f); +if (fmt ==NULL ) { +mtk_v4l2_err ("vidioc_vdec_s_fmt fail" ); +return ret; + } + + pix_mp = &f->fmt.pix_mp; +if ((f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) && +vb2_is_busy (&ctx->m2m_ctx->out_q_ctx.q)) { +mtk_v4l2_err ("out_q_ctx buffers already requested" ); + ret = -EBUSY ; + } + +if ((f->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) && +vb2_is_busy (&ctx->m2m_ctx->cap_q_ctx.q)) { +mtk_v4l2_err ("cap_q_ctx buffers already requested" ); + ret = -EBUSY ; + } + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx, f->type); + + q_data =mtk_vdec_get_q_data (ctx, f->type); +if (!q_data) +return -EINVAL ; + + q_data->fmt = fmt; +if (f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { + q_data->sizeimage[0 ] = pix_mp->plane_fmt[0 ].sizeimage; + pix_mp->plane_fmt[0 ].bytesperline =0 ; + pix_mp->width =0 ; + pix_mp->height =0 ; + +if (ctx->state ==MTK_STATE_FREE ) { + ret =vdec_if_init (ctx, q_data->fmt->fourcc); +if (ret) { +mtk_v4l2_err ("[%d]: vdec_if_init() fail ret=%d" , + ctx->id, ret); +return -EINVAL ; + } + ctx->state =MTK_STATE_INIT ; + } + } + +return 0 ; +} + +static int vidioc_enum_framesizes (struct file *file,void *priv, +struct v4l2_frmsizeenum *fsize) +{ +int i =0 ; +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); + +if (fsize->index !=0 ) +return -EINVAL ; + +for (i =0 ; i <NUM_SUPPORTED_FRAMESIZE ; ++i) { +if (fsize->pixel_format != mtk_vdec_framesizes[i].fourcc) +continue ; + + fsize->type =V4L2_FRMSIZE_TYPE_STEPWISE ; + fsize->stepwise = mtk_vdec_framesizes[i].stepwise; +if (!(ctx->dev->dec_capability & +VCODEC_CAPABILITY_4K_DISABLED )) { +mtk_v4l2_debug (3 ,"4K is enabled" ); + fsize->stepwise.max_width = +VCODEC_DEC_4K_CODED_WIDTH ; + fsize->stepwise.max_height = +VCODEC_DEC_4K_CODED_HEIGHT ; + } +mtk_v4l2_debug (1 ,"%x, %d %d %d %d %d %d" , + ctx->dev->dec_capability, + fsize->stepwise.min_width, + fsize->stepwise.max_width, + fsize->stepwise.step_width, + fsize->stepwise.min_height, + fsize->stepwise.max_height, + fsize->stepwise.step_height); +return 0 ; + } + +return -EINVAL ; +} + +static int vidioc_enum_fmt (struct v4l2_fmtdesc *f,bool output_queue) +{ +struct mtk_video_fmt *fmt; +int i, j =0 ; + +for (i =0 ; i <NUM_FORMATS ; i++) { +if (output_queue && (mtk_video_formats[i].type !=MTK_FMT_DEC )) +continue ; +if (!output_queue && + (mtk_video_formats[i].type !=MTK_FMT_FRAME )) +continue ; + +if (j == f->index) +break ; + ++j; + } + +if (i ==NUM_FORMATS ) +return -EINVAL ; + + fmt = &mtk_video_formats[i]; + f->pixelformat = fmt->fourcc; + +return 0 ; +} + +static int vidioc_vdec_enum_fmt_vid_cap_mplane (struct file *file,void *pirv, +struct v4l2_fmtdesc *f) +{ +return vidioc_enum_fmt (f, false); +} + +static int vidioc_vdec_enum_fmt_vid_out_mplane (struct file *file,void *priv, +struct v4l2_fmtdesc *f) +{ +return vidioc_enum_fmt (f, true); +} + +static int vidioc_vdec_g_fmt (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +struct vb2_queue *vq; +struct mtk_q_data *q_data; + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx, f->type); +if (!vq) { +mtk_v4l2_err ("no vb2 queue for type=%d" , + f->type); +return -EINVAL ; + } + + q_data =mtk_vdec_get_q_data (ctx, f->type); + +if ((f->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) && + (ctx->state >=MTK_STATE_HEADER )) { +/* Until STREAMOFF is called on the CAPTURE queue +* (acknowledging the event), the driver operates as if +* the resolution hasn't changed yet. +* So we just return picinfo yet, and update picinfo in +* stop_streaming hook function +*/ + q_data->sizeimage[0 ] = ctx->picinfo.y_bs_sz + + ctx->picinfo.y_len_sz; + q_data->sizeimage[1 ] = ctx->picinfo.c_bs_sz + + ctx->picinfo.c_len_sz; + q_data->bytesperline[0 ] = ctx->last_decoded_picinfo.buf_w; + q_data->bytesperline[1 ] = ctx->last_decoded_picinfo.buf_w; + q_data->coded_width = ctx->picinfo.buf_w; + q_data->coded_height = ctx->picinfo.buf_h; + +/* +* Width and height are set to the dimensions +* of the movie, the buffer is bigger and +* further processing stages should crop to this +* rectangle. +*/ + pix_mp->width = q_data->coded_width; + pix_mp->height = q_data->coded_height; + pix_mp->field =V4L2_FIELD_NONE ; + +/* +* Set pixelformat to the format in which mt vcodec +* outputs the decoded frame +*/ + pix_mp->num_planes = q_data->fmt->num_planes; + pix_mp->pixelformat = q_data->fmt->fourcc; + pix_mp->plane_fmt[0 ].bytesperline = q_data->bytesperline[0 ]; + pix_mp->plane_fmt[0 ].sizeimage = q_data->sizeimage[0 ]; + pix_mp->plane_fmt[1 ].bytesperline = q_data->bytesperline[1 ]; + pix_mp->plane_fmt[1 ].sizeimage = q_data->sizeimage[1 ]; + + }else if (f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +/* +* This is run on OUTPUT +* The buffer contains compressed image +* so width and height have no meaning. +* Assign value here to pass v4l2-compliance test +*/ + pix_mp->width = q_data->visible_width; + pix_mp->height = q_data->visible_height; + pix_mp->field =V4L2_FIELD_NONE ; + pix_mp->plane_fmt[0 ].bytesperline = q_data->bytesperline[0 ]; + pix_mp->plane_fmt[0 ].sizeimage = q_data->sizeimage[0 ]; + pix_mp->pixelformat = q_data->fmt->fourcc; + pix_mp->num_planes = q_data->fmt->num_planes; + }else { + pix_mp->width = q_data->coded_width; + pix_mp->height = q_data->coded_height; + pix_mp->field =V4L2_FIELD_NONE ; + pix_mp->num_planes = q_data->fmt->num_planes; + pix_mp->pixelformat = q_data->fmt->fourcc; + pix_mp->plane_fmt[0 ].bytesperline = q_data->bytesperline[0 ]; + pix_mp->plane_fmt[0 ].sizeimage = q_data->sizeimage[0 ]; + pix_mp->plane_fmt[1 ].bytesperline = q_data->bytesperline[1 ]; + pix_mp->plane_fmt[1 ].sizeimage = q_data->sizeimage[1 ]; + +mtk_v4l2_debug (1 ,"[%d] state=%d Format could not be read %d, not ready yet!" , + ctx->id, ctx->state, f->type); +return -EINVAL ; + } + +return 0 ; +} + +static int vb2ops_vdec_queue_setup (struct vb2_queue *vq, +unsigned int *nbuffers, +unsigned int *nplanes, +unsigned int sizes[],void *alloc_ctxs[]) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vq); +struct mtk_q_data *q_data; +unsigned int i; + + q_data =mtk_vdec_get_q_data (ctx, vq->type); + +if (q_data ==NULL ) { +mtk_v4l2_err ("vq->type=%d err\n" , vq->type); +return -EINVAL ; + } + +if (*nplanes) { +for (i =0 ; i < *nplanes; i++) { +if (sizes[i] < q_data->sizeimage[i]) +return -EINVAL ; + alloc_ctxs[i] = ctx->dev->alloc_ctx; + } + }else { + +if (vq->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +if (ctx->state <MTK_STATE_HEADER ) { +mtk_v4l2_err ("State not ready" ); +return -EINVAL ; + } +/* +* Output plane count is 2 - one for Y and one for CbCr +*/ + *nplanes =2 ; + }else { + *nplanes =1 ; + } + +for (i =0 ; i < *nplanes; i++) { + sizes[i] = q_data->sizeimage[i]; + alloc_ctxs[i] = ctx->dev->alloc_ctx; + } + } + +mtk_v4l2_debug (1 , +"[%d]\t type = %d, get %d plane(s), %d buffer(s) of size 0x%x 0x%x " , + ctx->id, vq->type, *nplanes, *nbuffers, + sizes[0 ], sizes[1 ]); + +return 0 ; +} + +static int vb2ops_vdec_buf_prepare (struct vb2_buffer *vb) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue);
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 949
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+struct mtk_q_data *q_data; +int i; + +mtk_v4l2_debug (3 ,"[%d] (%d) id=%d" , + ctx->id, vb->vb2_queue->type, vb->index); + + q_data =mtk_vdec_get_q_data (ctx, vb->vb2_queue->type); + +for (i =0 ; i < q_data->fmt->num_planes; i++) { +if (vb2_plane_size (vb, i) > q_data->sizeimage[i]) {
Shouldn't this be < instead of > ?
Quoted 14 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +14
-0+mtk_v4l2_err ("data will not fit into plane %d (%lu < %d)" , + i,vb2_plane_size (vb, i), + q_data->sizeimage[i]); + } + } + +return 0 ; +} + +static void vb2ops_vdec_buf_queue (struct vb2_buffer *vb) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vb2_v4l2 =container_of (vb, + struct vb2_v4l2_buffer, vb2_buf);
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 973
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+struct mtk_video_dec_buf *buf =container_of (vb2_v4l2, + struct mtk_video_dec_buf, vb); + +mtk_v4l2_debug (3 ,"[%d] (%d) id=%d, vb=%p" , + ctx->id, vb->vb2_queue->type, + vb->index, vb); +/* +* check if this buffer is ready to be used after decode +*/ +if (vb->vb2_queue->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) {
Do the 'else' part first and return there.
Then this can be shifted one TAB to the left.
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 982
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +9
-0+struct vb2_buffer *src_buf; +struct mtk_vcodec_mem src_mem; +bool res_chg = false; +int ret =0 ; +unsigned int dpbsize =1 ; + +v4l2_m2m_buf_queue (ctx->m2m_ctx, vb2_v4l2); + +if (ctx->state ==MTK_STATE_INIT ) {
Ditto.
Quoted 86 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +86
-0+ src_buf =v4l2_m2m_next_src_buf (ctx->m2m_ctx); +if (!src_buf) { +mtk_v4l2_err ("No src buffer" ); +return ; + } + + src_mem.va =vb2_plane_vaddr (src_buf,0 ); + src_mem.dma_addr =vb2_dma_contig_plane_dma_addr ( + src_buf, +0 ); + src_mem.size = (size_t )src_buf->planes[0 ].bytesused; +mtk_v4l2_debug (2 , +"[%d] buf id=%d va=%p dma=%llx size=%zu" , + ctx->id, src_buf->index, + src_mem.va, (u64 )src_mem.dma_addr, + src_mem.size); + + ret =vdec_if_decode (ctx, &src_mem,NULL , &res_chg); +if (ret) { +/* fb == NULL menas to parse SPS/PPS header or +* resolution info in src_mem. Decode can fail +* if there is no SPS header or picture info +* in bs +*/ + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (to_vb2_v4l2_buffer (src_buf), +VB2_BUF_STATE_DONE ); +mtk_v4l2_debug (0 ,"[%d] vdec_if_decode() src_buf=%d, size=%zu, fail=%d" , + ctx->id, src_buf->index, + src_mem.size, ret); +return ; + } + +if (vdec_if_get_param (ctx, +GET_PARAM_PIC_INFO , + &ctx->picinfo)) { +mtk_v4l2_err ("[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR" , + ctx->id); +return ; + } + + ctx->last_decoded_picinfo = ctx->picinfo; + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ] = + ctx->picinfo.y_bs_sz + + ctx->picinfo.y_len_sz; + ctx->q_data[MTK_Q_DATA_DST ].bytesperline[0 ] = + ctx->picinfo.buf_w; + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[1 ] = + ctx->picinfo.c_bs_sz + + ctx->picinfo.c_len_sz; + ctx->q_data[MTK_Q_DATA_DST ].bytesperline[1 ] = + ctx->picinfo.buf_w; +mtk_v4l2_debug (2 ,"[%d] vdec_if_init() OK wxh=%dx%d pic wxh=%dx%d sz[0]=0x%x sz[1]=0x%x" , + ctx->id, + ctx->picinfo.buf_w, ctx->picinfo.buf_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ], + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[1 ]); + + ret =vdec_if_get_param (ctx,GET_PARAM_DPB_SIZE , + &dpbsize); +if (dpbsize ==0 ) { +mtk_v4l2_err ("[%d] vdec_if_get_param() GET_PARAM_DPB_SIZE fail=%d" , + ctx->id, ret); + } + ctx->dpb_size = dpbsize; + ctx->state =MTK_STATE_HEADER ; +mtk_v4l2_debug (1 ,"[%d] dpbsize=%d" , ctx->id, + ctx->dpb_size); + }else { +mtk_v4l2_debug (3 ,"[%d] already init driver %d" , + ctx->id, ctx->state); + } + }else { +mutex_lock (&ctx->lock); +if (buf->used == false) { +v4l2_m2m_buf_queue (ctx->m2m_ctx, +to_vb2_v4l2_buffer (vb)); + buf->queued_in_vb2 = true; + buf->queued_in_v4l2 = true; + buf->ready_to_display = false; + }else { + buf->queued_in_vb2 = false; + buf->queued_in_v4l2 = true; + buf->ready_to_display = false; + }
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 1078
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+mutex_unlock (&ctx->lock); + } +} + +static void vb2ops_vdec_buf_finish (struct vb2_buffer *vb) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue); + +if (vb->vb2_queue->type == +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) {
Place this on one line.
Actually, just invert the condition and return. The remainder can then be shifted one TAB to the left.
Quoted 43 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +43
-0+struct vb2_v4l2_buffer *vb2_v4l2; +struct mtk_video_dec_buf *buf; + + vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); + buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb); +mutex_lock (&ctx->lock); + buf->queued_in_v4l2 = false; + buf->queued_in_vb2 = false; +mutex_unlock (&ctx->lock); + } +} + +static int vb2ops_vdec_buf_init (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vb2_v4l2 =container_of (vb, + struct vb2_v4l2_buffer, vb2_buf); +struct mtk_video_dec_buf *buf =container_of (vb2_v4l2, + struct mtk_video_dec_buf, vb); + +if (vb->vb2_queue->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { + buf->used = false; + buf->ready_to_display = false; + buf->queued_in_v4l2 = false; + }else { + buf->lastframe = false; + } + +return 0 ; +} + +static int vb2ops_vdec_start_streaming (struct vb2_queue *q,unsigned int count) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (q); + +if (ctx->state ==MTK_STATE_FLUSH ) + ctx->state =MTK_STATE_HEADER ; + +return 0 ; +} + +static void vb2ops_vdec_stop_streaming (struct vb2_queue *q) +{ +struct vb2_buffer *src_buf =NULL , *dst_buf =NULL ;
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 1131
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (q); + +mtk_v4l2_debug (3 ,"[%d] (%d) state=(%x) ctx->decoded_frame_cnt=%d" , + ctx->id, q->type, ctx->state, ctx->decoded_frame_cnt); + +if (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +while ((src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx))) +v4l2_m2m_buf_done (to_vb2_v4l2_buffer (src_buf), +VB2_BUF_STATE_ERROR ); +
Same trick can be done here.
Quoted 468 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +217
-0+ }else if (q->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +if (ctx->state >=MTK_STATE_HEADER ) { + +/* Until STREAMOFF is called on the CAPTURE queue +* (acknowledging the event), the driver operates +* as if the resolution hasn't changed yet, i.e. +* VIDIOC_G_FMT< etc. return previous resolution. +* So we update picinfo here +*/ + ctx->picinfo = ctx->last_decoded_picinfo; + +mtk_v4l2_debug (2 , +"[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)" , + ctx->id, ctx->last_decoded_picinfo.pic_w, + ctx->last_decoded_picinfo.pic_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->last_decoded_picinfo.buf_w, + ctx->last_decoded_picinfo.buf_h); + +mtk_vdec_flush_decoder (ctx); + } + ctx->state =MTK_STATE_FLUSH ; + +while ((dst_buf =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx))) { +vb2_set_plane_payload (dst_buf,0 ,0 ); +vb2_set_plane_payload (dst_buf,1 ,0 ); +v4l2_m2m_buf_done (to_vb2_v4l2_buffer (dst_buf), +VB2_BUF_STATE_ERROR ); + } + } +} + +static void m2mops_vdec_device_run (void *priv) +{ +struct mtk_vcodec_ctx *ctx = priv; +struct mtk_vcodec_dev *dev = ctx->dev; + +queue_work (dev->decode_workqueue, &ctx->decode_work); +} + +static int m2mops_vdec_job_ready (void *m2m_priv) +{ +struct mtk_vcodec_ctx *ctx = m2m_priv; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); + +if (ctx->state ==MTK_STATE_ABORT ) +return 0 ; + +if ((ctx->last_decoded_picinfo.pic_w != ctx->picinfo.pic_w) || + (ctx->last_decoded_picinfo.pic_h != ctx->picinfo.pic_h)) +return 0 ; + +if (ctx->state !=MTK_STATE_HEADER ) +return 0 ; + +return 1 ; +} + +static void m2mops_vdec_job_abort (void *priv) +{ +struct mtk_vcodec_ctx *ctx = priv; + + ctx->state =MTK_STATE_ABORT ; +} + +static int mtk_vdec_g_v_ctrl (struct v4l2_ctrl *ctrl) +{ +struct mtk_vcodec_ctx *ctx =ctrl_to_ctx (ctrl); +int ret =0 ; + +switch (ctrl->id) { +case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE : +if (ctx->state >=MTK_STATE_HEADER ) { + ctrl->val = ctx->dpb_size; + }else { +mtk_v4l2_err ("Seqinfo not ready" ); + ctrl->val =1 ; + ret = -EAGAIN ; + } +break ; +default : + ret = -EINVAL ; + } +return ret; +} + +static const struct v4l2_ctrl_ops mtk_vcodec_dec_ctrl_ops = { + .g_volatile_ctrl = mtk_vdec_g_v_ctrl, +}; + +int mtk_vcodec_dec_ctrls_setup (struct mtk_vcodec_ctx *ctx) +{ +struct v4l2_ctrl *ctrl; + +v4l2_ctrl_handler_init (&ctx->ctrl_hdl,1 ); + + ctrl =v4l2_ctrl_new_std (&ctx->ctrl_hdl, + &mtk_vcodec_dec_ctrl_ops, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE , +1 ,32 ,1 ,1 ); + ctrl->flags |=V4L2_CTRL_FLAG_VOLATILE ; + +if (ctx->ctrl_hdl.error) { +mtk_v4l2_err ("Adding control failed %d" , + ctx->ctrl_hdl.error); +return ctx->ctrl_hdl.error; + } + +v4l2_ctrl_handler_setup (&ctx->ctrl_hdl); +return 0 ; +} + +static void m2mops_vdec_lock (void *m2m_priv) +{ +struct mtk_vcodec_ctx *ctx = m2m_priv; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); +mutex_lock (&ctx->dev->dev_mutex); +} + +static void m2mops_vdec_unlock (void *m2m_priv) +{ +struct mtk_vcodec_ctx *ctx = m2m_priv; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); +mutex_unlock (&ctx->dev->dev_mutex); +} + +const struct v4l2_m2m_ops mtk_vdec_m2m_ops = { + .device_run = m2mops_vdec_device_run, + .job_ready = m2mops_vdec_job_ready, + .job_abort = m2mops_vdec_job_abort, + .lock = m2mops_vdec_lock, + .unlock = m2mops_vdec_unlock, +}; + +static const struct vb2_ops mtk_vdec_vb2_ops = { + .queue_setup = vb2ops_vdec_queue_setup, + .buf_prepare = vb2ops_vdec_buf_prepare, + .buf_queue = vb2ops_vdec_buf_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .buf_init = vb2ops_vdec_buf_init, + .buf_finish = vb2ops_vdec_buf_finish, + .start_streaming = vb2ops_vdec_start_streaming, + .stop_streaming = vb2ops_vdec_stop_streaming, +}; + +const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops = { + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + + .vidioc_qbuf = vidioc_vdec_qbuf, + .vidioc_dqbuf = vidioc_vdec_dqbuf, + + .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt_vid_cap_mplane, + .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt_vid_out_mplane, + + .vidioc_s_fmt_vid_cap_mplane = vidioc_vdec_s_fmt, + .vidioc_s_fmt_vid_out_mplane = vidioc_vdec_s_fmt, + .vidioc_g_fmt_vid_cap_mplane = vidioc_vdec_g_fmt, + .vidioc_g_fmt_vid_out_mplane = vidioc_vdec_g_fmt, + + .vidioc_enum_fmt_vid_cap_mplane = vidioc_vdec_enum_fmt_vid_cap_mplane, + .vidioc_enum_fmt_vid_out_mplane = vidioc_vdec_enum_fmt_vid_out_mplane, + .vidioc_enum_framesizes = vidioc_enum_framesizes, + + .vidioc_querycap = vidioc_vdec_querycap, + .vidioc_subscribe_event = vidioc_vdec_subscribe_evt, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, + .vidioc_g_selection = vidioc_vdec_g_selection, +}; + +int mtk_vcodec_dec_queue_init (void *priv,struct vb2_queue *src_vq, +struct vb2_queue *dst_vq) +{ +struct mtk_vcodec_ctx *ctx = priv; +int ret =0 ; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); + + src_vq->type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; + src_vq->io_modes =VB2_DMABUF |VB2_MMAP ; + src_vq->drv_priv = ctx; + src_vq->buf_struct_size =sizeof (struct mtk_video_dec_buf ); + src_vq->ops = &mtk_vdec_vb2_ops; + src_vq->mem_ops = &vb2_dma_contig_memops; + src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + src_vq->lock = &ctx->dev->dev_mutex; + + ret =vb2_queue_init (src_vq); +if (ret) { +mtk_v4l2_err ("Failed to initialize videobuf2 queue(output)" ); +return ret; + } + dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; + dst_vq->io_modes =VB2_DMABUF |VB2_MMAP ; + dst_vq->drv_priv = ctx; + dst_vq->buf_struct_size =sizeof (struct mtk_video_dec_buf ); + dst_vq->ops = &mtk_vdec_vb2_ops; + dst_vq->mem_ops = &vb2_dma_contig_memops; + dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + dst_vq->lock = &ctx->dev->dev_mutex; + + ret =vb2_queue_init (dst_vq); +if (ret) { +vb2_queue_release (src_vq); +mtk_v4l2_err ("Failed to initialize videobuf2 queue(capture)" ); + } + +return ret; +} +drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h new file +88
-0@@ -0,0 +1,88 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _MTK_VCODEC_DEC_H_ +#define _MTK_VCODEC_DEC_H_ + +#include <media/videobuf2-core.h> +#include <media/videobuf2-v4l2.h> + +#define VCODEC_CAPABILITY_4K_DISABLED 0x10 +#define VCODEC_DEC_4K_CODED_WIDTH 4096U +#define VCODEC_DEC_4K_CODED_HEIGHT 2304U +#define MTK_VDEC_MAX_W 2048U +#define MTK_VDEC_MAX_H 1088U + +#define MTK_VDEC_IRQ_STATUS_DEC_SUCCESS 0x10000 + +/** +* struct vdec_fb - decoder frame buffer +* @base_y : Y plane memory info +* @base_c : C plane memory info +* @status : frame buffer status (vdec_fb_status) +*/ +struct vdec_fb { +struct mtk_vcodec_mem base_y; +struct mtk_vcodec_mem base_c; +unsigned int status; +}; + +/** +* struct mtk_video_dec_buf - Private data related to each VB2 buffer. +* @b: VB2 buffer +* @list: link list +* @used: Capture buffer contain decoded frame data and keep in +* codec data structure +* @ready_to_display: Capture buffer not display yet +* @queued_in_vb2: Capture buffer is queue in vb2 +* @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2 +* queue yet +* @lastframe: Intput buffer is last buffer - EOS +* @frame_buffer: Decode status, and buffer information of Capture buffer +* +* Note : These status information help us track and debug buffer state +*/ +struct mtk_video_dec_buf { +struct vb2_v4l2_buffer vb; +struct list_head list; + +bool used; +bool ready_to_display; +bool queued_in_vb2; +bool queued_in_v4l2; +bool lastframe; +struct vdec_fb frame_buffer; +}; + +extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops; +extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops; + + +/* +* mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to +* get/release lock before/after access decoder hw. +* mtk_vdec_lock get decoder hw lock and set curr_ctx +* to ctx instance that get lock +*/ +void mtk_vdec_unlock (struct mtk_vcodec_ctx *ctx); +void mtk_vdec_lock (struct mtk_vcodec_ctx *ctx); +int mtk_vcodec_dec_queue_init (void *priv,struct vb2_queue *src_vq, +struct vb2_queue *dst_vq); +void mtk_vcodec_dec_set_default_params (struct mtk_vcodec_ctx *ctx); +void mtk_vcodec_vdec_release (struct mtk_vcodec_ctx *ctx); +int mtk_vcodec_dec_ctrls_setup (struct mtk_vcodec_ctx *ctx); + + +#endif /* _MTK_VCODEC_DEC_H_ */ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +151
-0@@ -0,0 +1,408 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of.h> +#include <media/v4l2-event.h> +#include <media/v4l2-mem2mem.h> +#include <media/videobuf2-dma-contig.h> + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_dec.h" +#include "mtk_vcodec_dec_pm.h" +#include "mtk_vcodec_intr.h" +#include "mtk_vcodec_util.h" +#include "mtk_vpu.h" + +#define VDEC_HW_ACTIVE 0x10 +#define VDEC_IRQ_CFG 0x11 +#define VDEC_IRQ_CLR 0x10 +#define VDEC_IRQ_CFG_REG 0xa4 + +module_param (mtk_v4l2_dbg_level, int,S_IRUGO |S_IWUSR ); +module_param (mtk_vcodec_dbg, bool,S_IRUGO |S_IWUSR ); + +/* Wake up context wait_queue */ +static void wake_up_ctx (struct mtk_vcodec_ctx *ctx) +{ + ctx->int_cond =1 ; +wake_up_interruptible (&ctx->queue); +} + +static irqreturn_t mtk_vcodec_dec_irq_handler (int irq,void *priv) +{ +struct mtk_vcodec_dev *dev = priv; +struct mtk_vcodec_ctx *ctx; +u32 cg_status =0 ; +unsigned int dec_done_status =0 ; +void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC ] + +VDEC_IRQ_CFG_REG ; + + ctx =mtk_vcodec_get_curr_ctx (dev); + +/* check if HW active or not */ + cg_status =readl (dev->reg_base[0 ]); +if ((cg_status &VDEC_HW_ACTIVE ) !=0 ) { +mtk_v4l2_err ("DEC ISR, VDEC active is not 0x0 (0x%08x)" , + cg_status); +return IRQ_HANDLED ; + } + + dec_done_status =readl (vdec_misc_addr); + ctx->irq_status = dec_done_status; +if ((dec_done_status &MTK_VDEC_IRQ_STATUS_DEC_SUCCESS ) != +MTK_VDEC_IRQ_STATUS_DEC_SUCCESS ) +return IRQ_HANDLED ; + +/* clear interrupt */ +writel ((readl (vdec_misc_addr) |VDEC_IRQ_CFG ), + dev->reg_base[VDEC_MISC ] +VDEC_IRQ_CFG_REG ); +writel ((readl (vdec_misc_addr) & ~VDEC_IRQ_CLR ), + dev->reg_base[VDEC_MISC ] +VDEC_IRQ_CFG_REG ); + +wake_up_ctx (ctx); + +mtk_v4l2_debug (3 , +"mtk_vcodec_dec_irq_handler :wake up ctx %d, dec_done_status=%x" , + ctx->id, dec_done_status); + +return IRQ_HANDLED ; +} + +static void mtk_vcodec_dec_reset_handler (void *priv) +{ +struct mtk_vcodec_dev *dev = priv; +struct mtk_vcodec_ctx *ctx; + +mtk_v4l2_err ("Watchdog timeout!!" ); + +mutex_lock (&dev->dev_mutex); +list_for_each_entry (ctx, &dev->ctx_list, list) { + ctx->state =MTK_STATE_ABORT ; +mtk_v4l2_debug (0 ,"[%d] Change to state MTK_STATE_ERROR" , + ctx->id); + } +mutex_unlock (&dev->dev_mutex); +} + +static int fops_vcodec_open (struct file *file) +{ +struct mtk_vcodec_dev *dev =video_drvdata (file); +struct mtk_vcodec_ctx *ctx =NULL ; +int ret =0 ; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + +mutex_lock (&dev->dev_mutex); + ctx->id = dev->id_counter++; +v4l2_fh_init (&ctx->fh,video_devdata (file)); + file->private_data = &ctx->fh; +v4l2_fh_add (&ctx->fh); +INIT_LIST_HEAD (&ctx->list); + ctx->dev = dev; +init_waitqueue_head (&ctx->queue); +mutex_init (&ctx->lock); + + ctx->type =MTK_INST_DECODER ; + ret =mtk_vcodec_dec_ctrls_setup (ctx); +if (ret) { +mtk_v4l2_err ("Failed to setup mt vcodec controls" ); + goto err_ctrls_setup; + } + ctx->m2m_ctx =v4l2_m2m_ctx_init (dev->m2m_dev_dec, ctx, + &mtk_vcodec_dec_queue_init); +if (IS_ERR ((__force void *)ctx->m2m_ctx)) { + ret =PTR_ERR ((__force void *)ctx->m2m_ctx); +mtk_v4l2_err ("Failed to v4l2_m2m_ctx_init() (%d)" , + ret); + goto err_m2m_ctx_init; + } +mtk_vcodec_dec_set_default_params (ctx); + +if (v4l2_fh_is_singular (&ctx->fh)) { +mtk_vcodec_dec_pw_on (&dev->pm); +/* +* vpu_load_firmware checks if it was loaded already and +* does nothing in that case +*/ + ret =vpu_load_firmware (dev->vpu_plat_dev); +if (ret <0 ) { +/* +* Return 0 if downloading firmware successfully, +* otherwise it is failed +*/
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c line 161
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +10
-0+mtk_v4l2_err ("vpu_load_firmware failed!" ); + goto err_load_fw; + } + + dev->dec_capability = +vpu_get_vdec_hw_capa (dev->vpu_plat_dev); +mtk_v4l2_debug (0 ,"decoder capability %x" , dev->dec_capability); + } + + dev->num_instances++;
This field can be dropped since it is no longer used.
Quoted 1,189 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +247
-0+list_add (&ctx->list, &dev->ctx_list); + +mutex_unlock (&dev->dev_mutex); +mtk_v4l2_debug (0 ,"%s decoder [%d]" ,dev_name (&dev->plat_dev->dev), + ctx->id); +return ret; + +/* Deinit when failure occurred */ +err_load_fw: +v4l2_m2m_ctx_release (ctx->m2m_ctx); +err_m2m_ctx_init: +v4l2_ctrl_handler_free (&ctx->ctrl_hdl); +err_ctrls_setup: +v4l2_fh_del (&ctx->fh); +v4l2_fh_exit (&ctx->fh); +kfree (ctx); +mutex_unlock (&dev->dev_mutex); + +return ret; +} + +static int fops_vcodec_release (struct file *file) +{ +struct mtk_vcodec_dev *dev =video_drvdata (file); +struct mtk_vcodec_ctx *ctx =fh_to_ctx (file->private_data); + +mtk_v4l2_debug (0 ,"[%d] decoder" , ctx->id); +mutex_lock (&dev->dev_mutex); + +mtk_vcodec_vdec_release (ctx); +if (v4l2_fh_is_singular (&ctx->fh)) +mtk_vcodec_dec_pw_off (&dev->pm); + +v4l2_fh_del (&ctx->fh); +v4l2_fh_exit (&ctx->fh); +v4l2_ctrl_handler_free (&ctx->ctrl_hdl); +v4l2_m2m_ctx_release (ctx->m2m_ctx); + +list_del_init (&ctx->list); + dev->num_instances--; +kfree (ctx); +mutex_unlock (&dev->dev_mutex); +return 0 ; +} + +static const struct v4l2_file_operations mtk_vcodec_fops = { + .owner =THIS_MODULE , + .open = fops_vcodec_open, + .release = fops_vcodec_release, + .poll = v4l2_m2m_fop_poll, + .unlocked_ioctl = video_ioctl2, + .mmap = v4l2_m2m_fop_mmap, +}; + +static int mtk_vcodec_probe (struct platform_device *pdev) +{ +struct mtk_vcodec_dev *dev; +struct video_device *vfd_dec; +struct resource *res; +int i, ret; +DEFINE_DMA_ATTRS (attrs); + + dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL ); +if (!dev) +return -ENOMEM ; + +INIT_LIST_HEAD (&dev->ctx_list); + dev->plat_dev = pdev; + + dev->vpu_plat_dev =vpu_get_plat_device (dev->plat_dev); +if (dev->vpu_plat_dev ==NULL ) { +mtk_v4l2_err ("[VPU] vpu device in not ready" ); +return -EPROBE_DEFER ; + } + +vpu_wdt_reg_handler (dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler, + dev,VPU_RST_DEC ); + + ret =mtk_vcodec_init_dec_pm (dev); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to get mt vcodec clock source" ); +return ret; + } + +for (i =0 ; i <NUM_MAX_VDEC_REG_BASE ; i++) { + res =platform_get_resource (pdev,IORESOURCE_MEM , i); +if (res ==NULL ) { +dev_err (&pdev->dev,"get memory resource failed." ); + ret = -ENXIO ; + goto err_res; + } + dev->reg_base[i] =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR ((__force void *)dev->reg_base[i])) { +dev_err (&pdev->dev, +"devm_ioremap_resource %d failed." , i); + ret =PTR_ERR ((__force void *)dev->reg_base); + goto err_res; + } +mtk_v4l2_debug (2 ,"reg[%d] base=%p" , i, dev->reg_base[i]); + } + + res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (res ==NULL ) { +dev_err (&pdev->dev,"failed to get irq resource" ); + ret = -ENOENT ; + goto err_res; + } + + dev->dec_irq =platform_get_irq (pdev,0 ); + ret =devm_request_irq (&pdev->dev, dev->dec_irq, + mtk_vcodec_dec_irq_handler,0 , pdev->name, dev); +if (ret) { +dev_err (&pdev->dev,"Failed to install dev->dec_irq %d (%d)" , + dev->dec_irq, + ret); + goto err_res; + } + +disable_irq (dev->dec_irq); +mutex_init (&dev->dec_mutex); +mutex_init (&dev->dev_mutex); +spin_lock_init (&dev->irqlock); + +snprintf (dev->v4l2_dev.name,sizeof (dev->v4l2_dev.name),"%s" , +"[/MTK_V4L2_VDEC]" ); + + ret =v4l2_device_register (&pdev->dev, &dev->v4l2_dev); +if (ret) { +mtk_v4l2_err ("v4l2_device_register err=%d" , ret); + goto err_res; + } + +init_waitqueue_head (&dev->queue); + + vfd_dec =video_device_alloc (); +if (!vfd_dec) { +mtk_v4l2_err ("Failed to allocate video device" ); + ret = -ENOMEM ; + goto err_dec_alloc; + } + vfd_dec->fops = &mtk_vcodec_fops; + vfd_dec->ioctl_ops = &mtk_vdec_ioctl_ops; + vfd_dec->release = video_device_release; + vfd_dec->lock = &dev->dev_mutex; + vfd_dec->v4l2_dev = &dev->v4l2_dev; + vfd_dec->vfl_dir =VFL_DIR_M2M ; + vfd_dec->device_caps =V4L2_CAP_VIDEO_M2M_MPLANE | +V4L2_CAP_STREAMING ; + +snprintf (vfd_dec->name,sizeof (vfd_dec->name),"%s" , +MTK_VCODEC_DEC_NAME ); +video_set_drvdata (vfd_dec, dev); + dev->vfd_dec = vfd_dec; +platform_set_drvdata (pdev, dev); + + dev->alloc_ctx =vb2_dma_contig_init_ctx (&pdev->dev); +if (IS_ERR ((__force void *)dev->alloc_ctx)) { +mtk_v4l2_err ("Failed to alloc vb2 dma context 0" ); + ret =PTR_ERR ((__force void *)dev->alloc_ctx); + goto err_vb2_ctx_init; + } + + dev->m2m_dev_dec =v4l2_m2m_init (&mtk_vdec_m2m_ops); +if (IS_ERR ((__force void *)dev->m2m_dev_dec)) { +mtk_v4l2_err ("Failed to init mem2mem dec device" ); + ret =PTR_ERR ((__force void *)dev->m2m_dev_dec); + goto err_dec_mem_init; + } + + dev->decode_workqueue = +alloc_ordered_workqueue (MTK_VCODEC_DEC_NAME , +WQ_MEM_RECLAIM |WQ_FREEZABLE ); +if (!dev->decode_workqueue) { +mtk_v4l2_err ("Failed to create decode workqueue" ); + ret = -EINVAL ; + goto err_event_workq; + } + + ret =video_register_device (vfd_dec,VFL_TYPE_GRABBER ,0 ); +if (ret) { +mtk_v4l2_err ("Failed to register video device" ); + goto err_dec_reg; + } + +/* Avoid the iommu eat big hunks */ +dma_set_attr (DMA_ATTR_ALLOC_SINGLE_PAGES , &attrs); + +mtk_v4l2_debug (0 ,"decoder registered as /dev/video%d" , + vfd_dec->num); + +return 0 ; + +err_dec_reg: +destroy_workqueue (dev->decode_workqueue); +err_event_workq: +v4l2_m2m_release (dev->m2m_dev_dec); +err_dec_mem_init: +vb2_dma_contig_cleanup_ctx (dev->alloc_ctx); +err_vb2_ctx_init: +video_unregister_device (vfd_dec); +err_dec_alloc: +v4l2_device_unregister (&dev->v4l2_dev); +err_res: +mtk_vcodec_release_dec_pm (dev); +return ret; +} + +static const struct of_device_id mtk_vcodec_match[] = { + {.compatible ="mediatek,mt8173-vcodec-dec" ,}, + {}, +}; + +MODULE_DEVICE_TABLE (of, mtk_vcodec_match); + +static int mtk_vcodec_dec_remove (struct platform_device *pdev) +{ +struct mtk_vcodec_dev *dev =platform_get_drvdata (pdev); + +flush_workqueue (dev->decode_workqueue); +destroy_workqueue (dev->decode_workqueue); +if (dev->m2m_dev_dec) +v4l2_m2m_release (dev->m2m_dev_dec); +if (dev->alloc_ctx) +vb2_dma_contig_cleanup_ctx (dev->alloc_ctx); + +if (dev->vfd_dec) +video_unregister_device (dev->vfd_dec); + +v4l2_device_unregister (&dev->v4l2_dev); +mtk_vcodec_release_dec_pm (dev); +return 0 ; +} + +static struct platform_driver mtk_vcodec_dec_driver = { + .probe = mtk_vcodec_probe, + .remove = mtk_vcodec_dec_remove, + .driver = { + .name =MTK_VCODEC_DEC_NAME , + .owner =THIS_MODULE , + .of_match_table = mtk_vcodec_match, + }, +}; + +module_platform_driver (mtk_vcodec_dec_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Mediatek video codec V4L2 decoder driver" );drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c new file +206
-0@@ -0,0 +1,206 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/clk.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <soc/mediatek/smi.h> + +#include "mtk_vcodec_dec_pm.h" +#include "mtk_vcodec_util.h" +#include "mtk_vpu.h" + +int mtk_vcodec_init_dec_pm (struct mtk_vcodec_dev *mtkdev) +{ +struct device_node *node; +struct platform_device *pdev; +struct device *dev; +struct mtk_vcodec_pm *pm; +int ret =0 ; + + pdev = mtkdev->plat_dev; + pm = &mtkdev->pm; + pm->mtkdev = mtkdev; + dev = &pdev->dev; + node =of_parse_phandle (pdev->dev.of_node,"mediatek,larb" ,0 ); +if (!node) { +mtk_v4l2_err ("of_parse_phandle mediatek,larb fail!" ); +return -1 ; + } + + pdev =of_find_device_by_node (node); +if (WARN_ON (!pdev)) { +of_node_put (node); +return -1 ; + } + pm->larbvdec = &pdev->dev; + + pdev = mtkdev->plat_dev; + pm->dev = &pdev->dev; + + pm->vcodecpll =devm_clk_get (&pdev->dev,"vcodecpll" ); +if (pm->vcodecpll ==NULL ) { +mtk_v4l2_err ("devm_clk_get vcodecpll fail" ); + ret =-1 ; + } + + pm->univpll_d2 =devm_clk_get (&pdev->dev,"univpll_d2" ); +if (pm->univpll_d2 ==NULL ) { +mtk_v4l2_err ("devm_clk_get univpll_d2 fail" ); + ret =-1 ; + } + + pm->clk_cci400_sel =devm_clk_get (&pdev->dev,"clk_cci400_sel" ); +if (pm->clk_cci400_sel ==NULL ) { +mtk_v4l2_err ("devm_clk_get clk_cci400_sel fail" ); + ret =-1 ; + } + + pm->vdec_sel =devm_clk_get (&pdev->dev,"vdec_sel" ); +if (pm->vdec_sel ==NULL ) { +mtk_v4l2_err ("devm_clk_get vdec_sel fail" ); + ret =-1 ; + } + + pm->vdecpll =devm_clk_get (&pdev->dev,"vdecpll" ); +if (pm->vdecpll ==NULL ) { +mtk_v4l2_err ("devm_clk_get vdecpll fail" ); + ret =-1 ; + } + + pm->vencpll =devm_clk_get (&pdev->dev,"vencpll" ); +if (pm->vencpll ==NULL ) { +mtk_v4l2_err ("devm_clk_get vencpll fail" ); + ret =-1 ; + } + + pm->venc_lt_sel =devm_clk_get (&pdev->dev,"venc_lt_sel" ); +if (pm->venc_lt_sel ==NULL ) { +mtk_v4l2_err ("devm_clk_get venc_lt_sel fail" ); + ret =-1 ; + } + + pm->vdec_bus_clk_src =devm_clk_get (&pdev->dev,"vdec_bus_clk_src" ); +if (pm->vdec_bus_clk_src ==NULL ) { +mtk_v4l2_err ("devm_clk_get vdec_bus_clk_src" ); + ret =-1 ; + } + +pm_runtime_enable (&pdev->dev); + +return ret; +} + +void mtk_vcodec_release_dec_pm (struct mtk_vcodec_dev *dev) +{ +pm_runtime_disable (dev->pm.dev); +} + +void mtk_vcodec_dec_pw_on (struct mtk_vcodec_pm *pm) +{ +int ret; + + ret =pm_runtime_get_sync (pm->dev); +if (ret) +mtk_v4l2_err ("pm_runtime_get_sync fail %d" , ret); +} + +void mtk_vcodec_dec_pw_off (struct mtk_vcodec_pm *pm) +{ +int ret; + + ret =pm_runtime_put_sync (pm->dev); +if (ret) +mtk_v4l2_err ("pm_runtime_put_sync fail %d" , ret); +} + +void mtk_vcodec_dec_clock_on (struct mtk_vcodec_pm *pm) +{ +int ret; + + ret =clk_set_rate (pm->vcodecpll,1482 *1000000 ); +if (ret) +mtk_v4l2_err ("clk_set_rate vcodecpll fail %d" , ret); + + ret =clk_set_rate (pm->vencpll,800 *1000000 ); +if (ret) +mtk_v4l2_err ("clk_set_rate vencpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vcodecpll); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vcodecpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vencpll); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vencpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vdec_bus_clk_src); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vdec_bus_clk_src fail %d" , + ret); + + ret =clk_prepare_enable (pm->venc_lt_sel); +if (ret) +mtk_v4l2_err ("clk_prepare_enable venc_lt_sel fail %d" , ret); + + ret =clk_set_parent (pm->venc_lt_sel, pm->vdec_bus_clk_src); +if (ret) +mtk_v4l2_err ("clk_set_parent venc_lt_sel vdec_bus_clk_src fail %d" , + ret); + + ret =clk_prepare_enable (pm->univpll_d2); +if (ret) +mtk_v4l2_err ("clk_prepare_enable univpll_d2 fail %d" , ret); + + ret =clk_prepare_enable (pm->clk_cci400_sel); +if (ret) +mtk_v4l2_err ("clk_prepare_enable clk_cci400_sel fail %d" , ret); + + ret =clk_set_parent (pm->clk_cci400_sel, pm->univpll_d2); +if (ret) +mtk_v4l2_err ("clk_set_parent clk_cci400_sel univpll_d2 fail %d" , + ret); + + ret =clk_prepare_enable (pm->vdecpll); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vdecpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vdec_sel); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vdec_sel fail %d" , ret); + + ret =clk_set_parent (pm->vdec_sel, pm->vdecpll); +if (ret) +mtk_v4l2_err ("clk_set_parent vdec_sel vdecpll fail %d" , ret); + + ret =mtk_smi_larb_get (pm->larbvdec); +if (ret) +mtk_v4l2_err ("mtk_smi_larb_get larbvdec fail %d" , ret); + +} + +void mtk_vcodec_dec_clock_off (struct mtk_vcodec_pm *pm) +{ +mtk_smi_larb_put (pm->larbvdec); +clk_disable_unprepare (pm->vdec_sel); +clk_disable_unprepare (pm->vdecpll); +clk_disable_unprepare (pm->univpll_d2); +clk_disable_unprepare (pm->clk_cci400_sel); +clk_disable_unprepare (pm->venc_lt_sel); +clk_disable_unprepare (pm->vdec_bus_clk_src); +clk_disable_unprepare (pm->vencpll); +clk_disable_unprepare (pm->vcodecpll); +} +drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h new file +28
-0@@ -0,0 +1,28 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _MTK_VCODEC_DEC_PM_H_ +#define _MTK_VCODEC_DEC_PM_H_ + +#include "mtk_vcodec_drv.h" + +int mtk_vcodec_init_dec_pm (struct mtk_vcodec_dev *dev); +void mtk_vcodec_release_dec_pm (struct mtk_vcodec_dev *dev); + +void mtk_vcodec_dec_pw_on (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_pw_off (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_clock_on (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_clock_off (struct mtk_vcodec_pm *pm); + +#endif /* _MTK_VCODEC_DEC_PM_H_ */ drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +81
-7@@ -26,10 +26,10 @@#include "mtk_vcodec_util.h" #define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv" +#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"#define MTK_PLATFORM_STR "platform:mt8173" -#define MTK_VCODEC_MAX_PLANES 3#define MTK_V4L2_BENCHMARK 0#define WAIT_INTR_TIMEOUT_MS 1000@@ -180,6 +180,9 @@ struct mtk_enc_params {* struct mtk_vcodec_pm - Power management data structure */ struct mtk_vcodec_pm { +struct clk *vdec_bus_clk_src; +struct clk *vencpll; +struct clk *vcodecpll;struct clk *univpll_d2;struct clk *clk_cci400_sel;@@ -197,6 +200,32 @@ struct mtk_vcodec_pm { };/** +* struct vdec_pic_info - picture size information +* @pic_w: picture width +* @pic_h: picture height +* @buf_w: picture buffer width (64 aligned up from pic_w) +* @buf_h: picture buffer heiht (64 aligned up from pic_h) +* @y_bs_sz: Y bitstream size +* @c_bs_sz: CbCr bitstream size +* @y_len_sz: additional size required to store decompress information for y +* plane +* @c_len_sz: additional size required to store decompress information for cbcr +* plane +* E.g. suppose picture size is 176x144, +* buffer size will be aligned to 176x160. +*/ +struct vdec_pic_info { +unsigned int pic_w; +unsigned int pic_h; +unsigned int buf_w; +unsigned int buf_h; +unsigned int y_bs_sz; +unsigned int c_bs_sz; +unsigned int y_len_sz; +unsigned int c_len_sz; +}; + +/** * struct mtk_vcodec_ctx - Context (instance) private data. * * @type: type of the instance - decoder or encoder @@ -210,9 +239,12 @@ struct mtk_vcodec_pm {* @state: state of the context * @param_change: indicate encode parameter type * @enc_params: encoding parameters -* @enc_if: hoooked encoder driver interface +* @dec_if: hooked decoder driver interface +* @enc_if: hooked encoder driver interface * @drv_handle: driver handle for specific decode/encode instance * +* @picinfo: store picture info after header parsing +* @dpb_size: store dpb count after header parsing * @int_cond: variable used by the waitqueue * @int_type: type of the last interrupt * @queue: waitqueue that can be used to wait for this context to @@ -220,12 +252,16 @@ struct mtk_vcodec_pm {* @irq_status: irq status * * @ctrl_hdl: handler for v4l2 framework +* @decode_work: worker for the decoding * @encode_work: worker for the encoding +* @last_decoded_picinfo: pic information get from latest decode * * @colorspace: enum v4l2_colorspace; supplemental to pixelformat * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding * @quantization: enum v4l2_quantization, colorspace quantization * @xfer_func: enum v4l2_xfer_func, colorspace transfer function +* @lock: protect variables accessed by V4L2 threads and worker thread such as +* mtk_video_dec_buf. */ struct mtk_vcodec_ctx {enum mtk_instance_type type;@@ -240,21 +276,31 @@ struct mtk_vcodec_ctx {enum mtk_encode_param param_change;struct mtk_enc_params enc_params; +struct vdec_common_if *dec_if;struct venc_common_if *enc_if;unsigned long drv_handle; +struct vdec_pic_info picinfo; +int dpb_size; +int int_cond;int int_type;wait_queue_head_t queue;unsigned int irq_status;struct v4l2_ctrl_handler ctrl_hdl; +struct work_struct decode_work;struct work_struct encode_work; +struct vdec_pic_info last_decoded_picinfo;enum v4l2_colorspace colorspace;enum v4l2_ycbcr_encoding ycbcr_enc;enum v4l2_quantization quantization;enum v4l2_xfer_func xfer_func; + +int decoded_frame_cnt; +struct mutex lock; + };/** @@ -268,25 +314,48 @@ struct mtk_vcodec_ctx {* @alloc_ctx: VB2 allocator context * (for allocations without kernel mapping). * @ctx_list: list of struct mtk_vcodec_ctx -* @irqlock: protect data access by irq handler and work thread -* @curr_ctx: The context that is waiting for codec hardware +* @irqlock: protect data access by irq handler and work thread -- curr_ctx +* @curr_ctx: The context that is waiting for codec hardware. Protected by +* irqlock and dec_mutex or enc_mutex. * * @reg_base: Mapped address of MTK Vcodec registers. * -* @id_counter: used to identify current opened instance +* @id_counter: An integer id given to the next opened instance * @num_instances: counter of active MTK Vcodec instances * * @encode_workqueue: encode work queue * +* @v4l2_dev: V4L2 device to register video devices for. +* @vfd_dec: Video device for decoder +* @vfd_enc: Video device for encoder +* +* @m2m_dev_dec: m2m device for decoder +* @m2m_dev_enc: m2m device for encoder +* @plat_dev: platform device +* @vpu_plat_dev: mtk vpu platform device +* @alloc_ctx:VB2 allocator context +* (for allocations without kernel mapping). +* @ctx_list: list of struct mtk_vcodec_ctx +* @irqlock: protect data access by irq handler and work thread +* @curr_ctx: The context that is waiting for codec hardware +* @reg_base: Mapped address of MTK Vcodec registers. +* +* @instance_mask: used to mark which index id are used +* @num_instances: counter of active MTK Vcodec instances +* +* @decode_workqueue: decode work queue +* @encode_workqueue: encode work queue * @int_cond: used to identify interrupt condition happen * @int_type: used to identify what kind of interrupt condition happen * @dev_mutex: video_device lock * @queue: waitqueue for waiting for completion of device commands * +* @dec_irq: decoder irq resource * @enc_irq: h264 encoder irq resource -* @enc_lt_irq: vp8 encoder irq resource +* @enc_lt_irq: vp8 encoder lt irq resource * -* @enc_mutex: encoder hardware lock. +* @dec_mutex: decoder hardware lock +* @enc_mutex: encoder hardware lock * * @pm: power management control * @dec_capability: used to identify decode capability, ex: 4k @@ -294,8 +363,10 @@ struct mtk_vcodec_ctx {*/ struct mtk_vcodec_dev {struct v4l2_device v4l2_dev; +struct video_device *vfd_dec;struct video_device *vfd_enc; +struct v4l2_m2m_dev *m2m_dev_dec;struct v4l2_m2m_dev *m2m_dev_enc;struct platform_device *plat_dev;struct platform_device *vpu_plat_dev;@@ -308,6 +379,7 @@ struct mtk_vcodec_dev {unsigned long id_counter;int num_instances; +struct workqueue_struct *decode_workqueue;struct workqueue_struct *encode_workqueue;int int_cond;@@ -315,9 +387,11 @@ struct mtk_vcodec_dev {struct mutex dev_mutex;wait_queue_head_t queue; +int dec_irq;int enc_irq;int enc_lt_irq; +struct mutex dec_mutex;struct mutex enc_mutex;struct mtk_vcodec_pm pm;drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c +2
-2@@ -30,8 +30,7 @@ int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command, timeout_jiff =msecs_to_jiffies (timeout_ms); ret =wait_event_interruptible_timeout (*waitqueue, - (ctx->int_cond && - (ctx->int_type == command)), + ctx->int_cond, timeout_jiff);if (!ret) {@@ -52,3 +51,4 @@ int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command,return status; }EXPORT_SYMBOL (mtk_vcodec_wait_for_done_ctx); +drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h +1
-1@@ -16,7 +16,7 @@#define _MTK_VCODEC_INTR_H_#define MTK_INST_IRQ_RECEIVED 0x1 -#define MTK_INST_WORK_THREAD_ABORT_DONE 0x2 +struct mtk_vcodec_ctx ;drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +26
-5@@ -81,14 +81,35 @@ void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,return ; } -dma_free_coherent (dev, size, mem->va, mem->dma_addr); - mem->va =NULL ; - mem->dma_addr =0 ; - mem->size =0 ; -mtk_v4l2_debug (3 ,"[%d] - va = %p" , ctx->id, mem->va);mtk_v4l2_debug (3 ,"[%d] - dma = 0x%lx" , ctx->id, (unsigned long )mem->dma_addr);mtk_v4l2_debug (3 ,"[%d] size = 0x%lx" , ctx->id, size); + +dma_free_coherent (dev, size, mem->va, mem->dma_addr); + mem->va =NULL ; + mem->dma_addr =0 ; + mem->size =0 ; }EXPORT_SYMBOL (mtk_vcodec_mem_free); + +void mtk_vcodec_set_curr_ctx (struct mtk_vcodec_dev *dev, +struct mtk_vcodec_ctx *ctx) +{ +unsigned long flags; + +spin_lock_irqsave (&dev->irqlock, flags); + dev->curr_ctx = ctx; +spin_unlock_irqrestore (&dev->irqlock, flags); +} + +struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx (struct mtk_vcodec_dev *dev) +{ +unsigned long flags; +struct mtk_vcodec_ctx *ctx; + +spin_lock_irqsave (&dev->irqlock, flags); + ctx = dev->curr_ctx; +spin_unlock_irqrestore (&dev->irqlock, flags); +return ctx; +}drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +6
-1@@ -1,7 +1,7 @@/* * Copyright (c) 2016 MediaTek Inc. * Author: PC Chen <[email protected]> -* Tiffany Lin <[email protected]> +* Tiffany Lin <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -26,6 +26,7 @@ struct mtk_vcodec_mem { };struct mtk_vcodec_ctx ; +struct mtk_vcodec_dev ;extern int mtk_v4l2_dbg_level;extern bool mtk_vcodec_dbg;@@ -84,4 +85,8 @@ int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, struct mtk_vcodec_mem *mem);void mtk_vcodec_mem_free (struct mtk_vcodec_ctx *data,struct mtk_vcodec_mem *mem); +void mtk_vcodec_set_curr_ctx (struct mtk_vcodec_dev *dev, +struct mtk_vcodec_ctx *ctx); +struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx (struct mtk_vcodec_dev *dev); +#endif /* _MTK_VCODEC_UTIL_H_ */ drivers/media/platform/mtk-vcodec/vdec_drv_base.h new file +56
-0@@ -0,0 +1,56 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _VDEC_DRV_BASE_ +#define _VDEC_DRV_BASE_ + +#include "mtk_vcodec_drv.h" + +#include "vdec_drv_if.h" + +struct vdec_common_if { +/** +* (*init)() - initialize decode driver +* @ctx : [in] mtk v4l2 context +* @h_vdec : [out] driver handle +*/ +int (*init)(struct mtk_vcodec_ctx *ctx,unsigned long *h_vdec); + +/** +* (*decode)() - trigger decode +* @h_vdec : [in] driver handle +* @bs : [in] input bitstream +* @fb : [in] frame buffer to store decoded frame +* @res_chg : [out] resolution change happen +*/ +int (*decode)(unsigned long h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg); + +/** +* (*get_param)() - get driver's parameter +* @h_vdec : [in] driver handle +* @type : [in] input parameter type +* @out : [out] buffer to store query result +*/ +int (*get_param)(unsigned long h_vdec,enum vdec_get_param_type type, +void *out); + +/** +* (*deinit)() - deinitialize driver. +* @h_vdec : [in] driver handle to be deinit +*/ +void (*deinit)(unsigned long h_vdec); +}; + +#endif drivers/media/platform/mtk-vcodec/vdec_drv_if.c new file +107
-0@@ -0,0 +1,107 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/slab.h> + +#include "vdec_drv_base.h" +#include "vdec_drv_if.h" + +#include "mtk_vcodec_dec_pm.h" +#include "mtk_vcodec_util.h" +#include "mtk_vpu.h" + +int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc) +{ +int ret =0 ; + +switch (fourcc) { +case V4L2_PIX_FMT_H264 : +case V4L2_PIX_FMT_VP8 : +case V4L2_PIX_FMT_VP9 : +default : +return -EINVAL ; + } + +mtk_vdec_lock (ctx); +mtk_vcodec_dec_clock_on (&ctx->dev->pm); + ret = ctx->dec_if->init (ctx, &ctx->drv_handle); +mtk_vcodec_dec_clock_off (&ctx->dev->pm); +mtk_vdec_unlock (ctx); + +return ret; +} + +int vdec_if_decode (struct mtk_vcodec_ctx *ctx,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +int ret =0 ; + +if (bs) { +if ((bs->dma_addr &63 ) !=0 ) { +mtk_v4l2_err ("bs dma_addr should 64 byte align" ); +return -EINVAL ; + } + } + +if (fb) { +if (((fb->base_y.dma_addr &511 ) !=0 ) || + ((fb->base_c.dma_addr &511 ) !=0 )) { +mtk_v4l2_err ("frame buffer dma_addr should 512 byte align" ); +return -EINVAL ; + } + } + +mtk_vdec_lock (ctx); + +mtk_vcodec_set_curr_ctx (ctx->dev, ctx); +mtk_vcodec_dec_clock_on (&ctx->dev->pm); +enable_irq (ctx->dev->dec_irq); + ret = ctx->dec_if->decode (ctx->drv_handle, bs, fb, res_chg); +disable_irq (ctx->dev->dec_irq); +mtk_vcodec_dec_clock_off (&ctx->dev->pm); +mtk_vcodec_set_curr_ctx (ctx->dev,NULL ); + +mtk_vdec_unlock (ctx); + +return ret; +} + +int vdec_if_get_param (struct mtk_vcodec_ctx *ctx,enum vdec_get_param_type type, +void *out) +{ +int ret =0 ; + +mtk_vdec_lock (ctx); + ret = ctx->dec_if->get_param (ctx->drv_handle, type, out); +mtk_vdec_unlock (ctx); + +return ret; +} + +void vdec_if_deinit (struct mtk_vcodec_ctx *ctx) +{ +if (ctx->drv_handle ==0 ) +return ; + +mtk_vdec_lock (ctx); +mtk_vcodec_dec_clock_on (&ctx->dev->pm); + ctx->dec_if->deinit (ctx->drv_handle); +mtk_vcodec_dec_clock_off (&ctx->dev->pm); +mtk_vdec_unlock (ctx); + + ctx->drv_handle =0 ; +}drivers/media/platform/mtk-vcodec/vdec_drv_if.h new file +101
-0@@ -0,0 +1,101 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _VDEC_DRV_IF_H_ +#define _VDEC_DRV_IF_H_ + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_dec.h" +#include "mtk_vcodec_util.h" + + +/** +* struct vdec_fb_status - decoder frame buffer status +* @FB_ST_NORMAL : initial state +* @FB_ST_DISPLAY : frmae buffer is ready to be displayed +* @FB_ST_FREE : frame buffer is not used by decoder any more +*/ +enum vdec_fb_status { +FB_ST_NORMAL =0 , +FB_ST_DISPLAY = (1 <<0 ), +FB_ST_FREE = (1 <<1 ) +}; + +/* For GET_PARAM_DISP_FRAME_BUFFER and GET_PARAM_FREE_FRAME_BUFFER, +* the caller does not own the returned buffer. The buffer will not be +* released before vdec_if_deinit. +* GET_PARAM_DISP_FRAME_BUFFER : get next displayable frame buffer, +* struct vdec_fb** +* GET_PARAM_FREE_FRAME_BUFFER : get non-referenced framebuffer, vdec_fb** +* GET_PARAM_PIC_INFO : get picture info, struct vdec_pic_info* +* GET_PARAM_CROP_INFO : get crop info, struct v4l2_crop* +* GET_PARAM_DPB_SIZE : get dpb size, unsigned int* +*/ +enum vdec_get_param_type { +GET_PARAM_DISP_FRAME_BUFFER , +GET_PARAM_FREE_FRAME_BUFFER , +GET_PARAM_PIC_INFO , +GET_PARAM_CROP_INFO , +GET_PARAM_DPB_SIZE +}; + +/** +* struct vdec_fb_node - decoder frame buffer node +* @list : list to hold this node +* @fb : point to frame buffer (vdec_fb), fb could point to frame buffer and +* working buffer this is for maintain buffers in different state +*/ +struct vdec_fb_node { +struct list_head list; +struct vdec_fb *fb; +}; + +/** +* vdec_if_init() - initialize decode driver +* @ctx : [in] v4l2 context +* @fourcc : [in] video format fourcc, V4L2_PIX_FMT_H264/VP8/VP9.. +*/ +int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc); + +/** +* vdec_if_deinit() - deinitialize decode driver +* @ctx : [in] v4l2 context +* +*/ +void vdec_if_deinit (struct mtk_vcodec_ctx *ctx); + +/** +* vdec_if_decode() - trigger decode +* @ctx : [in] v4l2 context +* @bs : [in] input bitstream +* @fb : [in] frame buffer to store decoded frame, when null menas parse +* header only +* @res_chg : [out] resolution change happens if current bs have different +* picture width/height +* Note: To flush the decoder when reaching EOF, set input bitstream as NULL. +*/ +int vdec_if_decode (struct mtk_vcodec_ctx *ctx,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg); + +/** +* vdec_if_get_param() - get driver's parameter +* @ctx : [in] v4l2 context +* @type : [in] input parameter type +* @out : [out] buffer to store query result +*/ +int vdec_if_get_param (struct mtk_vcodec_ctx *ctx,enum vdec_get_param_type type, +void *out); + +#endif drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h new file +93
-0@@ -0,0 +1,103 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _VDEC_IPI_MSG_H_ +#define _VDEC_IPI_MSG_H_ + +/** +* enum vdec_ipi_msgid - message id between AP and VPU +* @AP_IPIMSG_XXX : AP to VPU cmd message id +* @VPU_IPIMSG_XXX_ACK : VPU ack AP cmd message id +*/ +enum vdec_ipi_msgid { +AP_IPIMSG_DEC_INIT =0xA000 , +AP_IPIMSG_DEC_START =0xA001 , +AP_IPIMSG_DEC_END =0xA002 , +AP_IPIMSG_DEC_DEINIT =0xA003 , +AP_IPIMSG_DEC_RESET =0xA004 , + +VPU_IPIMSG_DEC_INIT_ACK =0xB000 , +VPU_IPIMSG_DEC_START_ACK =0xB001 , +VPU_IPIMSG_DEC_END_ACK =0xB002 , +VPU_IPIMSG_DEC_DEINIT_ACK =0xB003 , +VPU_IPIMSG_DEC_RESET_ACK =0xB004 , +}; + +/** +* struct vdec_ap_ipi_cmd - generic AP to VPU ipi command format +* @msg_id : vdec_ipi_msgid +* @vpu_inst_addr : VPU decoder instance address +*/ +struct vdec_ap_ipi_cmd { +uint32_t msg_id; +uint32_t vpu_inst_addr; +}; + +/** +* struct vdec_vpu_ipi_ack - generic VPU to AP ipi command format +* @msg_id : vdec_ipi_msgid +* @status : VPU exeuction result +* @ap_inst_addr : AP video decoder instance address +*/ +struct vdec_vpu_ipi_ack { +uint32_t msg_id; +int32_t status; +uint64_t ap_inst_addr; +}; + +/** +* struct vdec_ap_ipi_init - for AP_IPIMSG_DEC_INIT +* @msg_id : AP_IPIMSG_DEC_INIT +* @reserved : Reserved field +* @ap_inst_addr : AP video decoder instance address +*/ +struct vdec_ap_ipi_init { +uint32_t msg_id; +uint32_t reserved; +uint64_t ap_inst_addr; +}; + +/** +* struct vdec_ap_ipi_dec_start - for AP_IPIMSG_DEC_START +* @msg_id : AP_IPIMSG_DEC_START +* @vpu_inst_addr : VPU decoder instance address +* @data : Header info +* H264 decoder [0]:buf_sz [1]:nal_start +* VP8 decoder [0]:width/height +* VP9 decoder [0]:profile, [1][2] width/height +* @reserved : Reserved field +*/ +struct vdec_ap_ipi_dec_start { +uint32_t msg_id; +uint32_t vpu_inst_addr; +uint32_t data[3 ]; +uint32_t reserved; +}; + +/** +* struct vdec_vpu_ipi_init_ack - for VPU_IPIMSG_DEC_INIT_ACK +* @msg_id : VPU_IPIMSG_DEC_INIT_ACK +* @status : VPU exeuction result +* @ap_inst_addr : AP vcodec_vpu_inst instance address
drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h line 103
Quoted 10 lines
drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h new file +10
-0+* @vpu_inst_addr : VPU decoder instance address +*/ +struct vdec_vpu_ipi_init_ack { +uint32_t msg_id; +int32_t status; +uint64_t ap_inst_addr; +uint32_t vpu_inst_addr; +}; + +#endif
Regards,
Hans
Re: [PATCH v3 5/9] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
Hi Hans,
Quoted 163 lines · Hans Verkuil
Quoted 148 lines · Tiffany Lin
Add v4l2 layer decoder driver for MT8173
Signed-off-by Tiffany Lin <[email protected]>--- drivers/media/platform/mtk-vcodec/Makefile | 10 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1348 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h | 88 ++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 408 ++++++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 206 +++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 28 + drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 88 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.c | 4 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.h | 2 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.c | 31 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.h | 7 +- drivers/media/platform/mtk-vcodec/vdec_drv_base.h | 56 + drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 107 ++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 101 ++ drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h | 103 ++ 15 files changed, 2569 insertions(+), 18 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.hdrivers/media/platform/mtk-vcodec/Makefile +8
-2@@ -1,7 +1,13 @@ -obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-enc.o mtk-vcodec-common.o - +obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ + mtk-vcodec-enc.o \ + mtk-vcodec-common.o + +mtk-vcodec-dec-y := mtk_vcodec_dec_drv.o \ + vdec_drv_if.o \ + mtk_vcodec_dec.o \ + mtk_vcodec_dec_pm.o \ mtk-vcodec-enc-y := venc/venc_vp8_if.o \drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +92
-0@@ -0,0 +1,1348 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <media/v4l2-event.h> +#include <media/v4l2-mem2mem.h> +#include <media/videobuf2-dma-contig.h> + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_dec.h" +#include "mtk_vcodec_intr.h" +#include "mtk_vcodec_util.h" +#include "vdec_drv_if.h" +#include "mtk_vcodec_dec_pm.h" + +#define OUT_FMT_IDX 0 +#define CAP_FMT_IDX 3 + +#define MTK_VDEC_MIN_W 64U +#define MTK_VDEC_MIN_H 64U +#define DFT_CFG_WIDTH MTK_VDEC_MIN_W +#define DFT_CFG_HEIGHT MTK_VDEC_MIN_H + +static struct mtk_video_fmt mtk_video_formats[] = { + { + .fourcc =V4L2_PIX_FMT_H264 , + .type =MTK_FMT_DEC , + .num_planes =1 , + }, + { + .fourcc =V4L2_PIX_FMT_VP8 , + .type =MTK_FMT_DEC , + .num_planes =1 , + }, + { + .fourcc =V4L2_PIX_FMT_VP9 , + .type =MTK_FMT_DEC , + .num_planes =1 , + }, + { + .fourcc =V4L2_PIX_FMT_MT21 , + .type =MTK_FMT_FRAME , + .num_planes =2 , + }, +}; + +static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = { + { + .fourcc =V4L2_PIX_FMT_H264 , + .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , +MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, + }, + { + .fourcc =V4L2_PIX_FMT_VP8 , + .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , +MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, + }, + { + .fourcc =V4L2_PIX_FMT_VP9 , + .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , +MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, + }, +}; + +#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes) +#define NUM_FORMATS ARRAY_SIZE(mtk_video_formats) + +static struct mtk_video_fmt *mtk_vdec_find_format (struct v4l2_format *f) +{ +struct mtk_video_fmt *fmt; +unsigned int k; + +for (k =0 ; k <NUM_FORMATS ; k++) { + fmt = &mtk_video_formats[k]; +if (fmt->fourcc == f->fmt.pix_mp.pixelformat) +return fmt; + } + +return NULL ; +} +drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 102
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+static struct mtk_q_data *mtk_vdec_get_q_data (struct mtk_vcodec_ctx *ctx, +enum v4l2_buf_type type) +{ +if (V4L2_TYPE_IS_OUTPUT (type)) +return &ctx->q_data[MTK_Q_DATA_SRC ]; + +return &ctx->q_data[MTK_Q_DATA_DST ]; +} + +/* This function is try to clean all display buffer, the buffer will return in s/is try/tries/
s/buffer/buffers/ (2 times)
Quoted 9 lines
checkpatch should complain about this comment block format ('/*' should be on its own line). Please run checkpatch to double check.
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 104
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +2
-0+* display order. +* Note the buffer return from codec driver may still in driver's reference s/buffer return/buffers returned/
s/still/still be/
Will fix this in next version.
Quoted 57 lines
Quoted 36 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +36
-0+* list. +*/ +static struct vb2_buffer *get_display_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct vdec_fb *disp_frame_buffer =NULL ; +struct mtk_video_dec_buf *dstbuf; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); +if (vdec_if_get_param (ctx, +GET_PARAM_DISP_FRAME_BUFFER , + &disp_frame_buffer)) { +mtk_v4l2_err ("[%d]Cannot get param : GET_PARAM_DISP_FRAME_BUFFER" , + ctx->id); +return NULL ; + } + +if (disp_frame_buffer ==NULL ) { +mtk_v4l2_debug (3 ,"No display frame buffer" ); +return NULL ; + } + + dstbuf = container_of(disp_frame_buffer, struct mtk_video_dec_buf, + frame_buffer); +mutex_lock (&ctx->lock); +if (dstbuf->used) { +vb2_set_plane_payload (&dstbuf->vb.vb2_buf,0 , + ctx->picinfo.y_bs_sz); +vb2_set_plane_payload (&dstbuf->vb.vb2_buf,1 , + ctx->picinfo.c_bs_sz); + + dstbuf->ready_to_display = true; + + mtk_v4l2_debug(2, + "[%d]status=%x queue id=%d to done_list %d", + ctx->id, disp_frame_buffer->status, + dstbuf->vb.vb2_buf.index,drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 150
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+ dstbuf->queued_in_vb2); + +v4l2_m2m_buf_done (&dstbuf->vb,VB2_BUF_STATE_DONE ); + ctx->decoded_frame_cnt++; + } +mutex_unlock (&ctx->lock); +return &dstbuf->vb.vb2_buf; +} + +/* This function is try to clean all capture buffers that is not used as s/is try/tries/
s/is not/are not/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 151
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1
-0+* reference buffer by codec driver any more buffers
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 153
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +2
-0+* In this case, we need re-queue buffer to vb2 buffer if user space +* already return this buffer to v4l2 or this buffer is just the output of
Quoted 7 lines
returns
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 155
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +2
-0+* previous sps/pps/resolution change decode, or do nothing if user +* space still own this buffer owns
Will fix this in next version.
Quoted 32 lines
Quoted 19 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +19
-0+*/ +static struct vb2_buffer *get_free_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct mtk_video_dec_buf *dstbuf; +struct vdec_fb *free_frame_buffer =NULL ; + +if (vdec_if_get_param (ctx, +GET_PARAM_FREE_FRAME_BUFFER , + &free_frame_buffer)) { +mtk_v4l2_err ("[%d] Error!! Cannot get param" , ctx->id); +return NULL ; + } +if (free_frame_buffer ==NULL ) { +mtk_v4l2_debug (3 ," No free frame buffer" ); +return NULL ; + } + +mtk_v4l2_debug (3 ,"[%d] tmp_frame_addr = 0x%p" , + ctx->id, free_frame_buffer);drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 184
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+ + dstbuf = container_of(free_frame_buffer, struct mtk_video_dec_buf, + frame_buffer); + +mutex_lock (&ctx->lock); +if (dstbuf->used) { +if ((dstbuf->queued_in_vb2) && + (dstbuf->queued_in_v4l2) && + (free_frame_buffer->status ==FB_ST_FREE )) { +/* After decode sps/pps or non-display buffer, we dont don't
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 189
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+* need to return capture buffer to user space, but +* just re-queue this capture buffer to vb2 queue. +* This reduce overheads that dq/q unused capture +* buffer We use queued_in_vb2 to mark this buffer +* is from decode output, not q from user space. garbled comment. Not sure what is meant here.
Will fix and refine comment in next version
Quoted 18 lines
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+*/ + mtk_v4l2_debug(2, + "[%d]status=%x queue id=%d to rdy_queue %d", + ctx->id, free_frame_buffer->status, + dstbuf->vb.vb2_buf.index,drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 204
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+ dstbuf->queued_in_vb2); +v4l2_m2m_buf_queue (ctx->m2m_ctx, &dstbuf->vb); + }else if ((dstbuf->queued_in_vb2 == false) && + (dstbuf->queued_in_v4l2 == true)) { +/* If buffer in v4l2 driver but not in vb2 queue yet, +* and we get this buffer from free_list, it means +* that codec driver do not use this buffer as +* reference buffer anymore. We should q buffer to vb2 +* queue, so later work thread could get this buffer +* for decode In this sate, queued_in_vb2 = false s/sate/case/
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 205
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1
-0+* menas this buffer is not from previous decode output means
Will fix this in next version.
Quoted 5 lines
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+*/ +mtk_v4l2_debug (2 , +"[%d]status=%x queue id=%d to rdy_queue" , + ctx->id, free_frame_buffer->status, + dstbuf->vb.vb2_buf.index);
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 216
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +6
-0+v4l2_m2m_buf_queue (ctx->m2m_ctx, &dstbuf->vb); + dstbuf->queued_in_vb2 = true; + }else { +/* Codec driver do not need to reference this capture +* buffer and this buffer is not in v4l2 driver. +* Then we dont need to do any thing, just add log when don't
Will fix this in next version.
Quoted 29 lines
Quoted 29 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +29
-0+* we need to debug buffer flow. +* When this buffer q from user space, it could +* directly q to vb2 buffer +*/ +mtk_v4l2_debug (3 ,"[%d]status=%x err queue id=%d %d %d" , + ctx->id, free_frame_buffer->status, + dstbuf->vb.vb2_buf.index, + dstbuf->queued_in_vb2, + dstbuf->queued_in_v4l2); + } + dstbuf->used = false; + } +mutex_unlock (&ctx->lock); +return &dstbuf->vb.vb2_buf; +} + +static void clean_display_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct vb2_buffer *framptr; + +do { + framptr =get_display_buffer (ctx); + }while (framptr); +} + +static void clean_free_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct vb2_buffer *framptr; +
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 251
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +6
-0+do { + framptr =get_free_buffer (ctx); + }while (framptr); +} + +static int mtk_vdec_queue_res_chg_event (struct mtk_vcodec_ctx *ctx)This can be a void function.
Will fix this in next version.
Quoted 148 lines
Quoted 134 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +134
-0+{ +static const struct v4l2_event ev_src_ch = { + .type =V4L2_EVENT_SOURCE_CHANGE , + .u.src_change.changes = +V4L2_EVENT_SRC_CH_RESOLUTION , + }; + +mtk_v4l2_debug (1 ,"[%d]" , ctx->id); +v4l2_event_queue_fh (&ctx->fh, &ev_src_ch); + +return 0 ; +} + +static void mtk_vdec_flush_decoder (struct mtk_vcodec_ctx *ctx) +{ +bool res_chg; +int ret =0 ; + + ret =vdec_if_decode (ctx,NULL ,NULL , &res_chg); +if (ret) +mtk_v4l2_err ("DecodeFinal failed, ret=%d" , ret); + +clean_display_buffer (ctx); +clean_free_buffer (ctx); +} + +static void mtk_vdec_pic_info_update (struct mtk_vcodec_ctx *ctx) +{ +unsigned int dpbsize =0 ; +int ret; + +if (vdec_if_get_param (ctx, +GET_PARAM_PIC_INFO , + &ctx->last_decoded_picinfo)) { +mtk_v4l2_err ("[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR" , + ctx->id); +return ; + } + +if (ctx->last_decoded_picinfo.pic_w ==0 || + ctx->last_decoded_picinfo.pic_h ==0 || + ctx->last_decoded_picinfo.buf_w ==0 || + ctx->last_decoded_picinfo.buf_h ==0 ) { +mtk_v4l2_err ("Cannot get correct pic info" ); +return ; + } + +if ((ctx->last_decoded_picinfo.pic_w == ctx->picinfo.pic_w) || + (ctx->last_decoded_picinfo.pic_h == ctx->picinfo.pic_h)) +return ; + +mtk_v4l2_debug (1 , +"[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)" , + ctx->id, ctx->last_decoded_picinfo.pic_w, + ctx->last_decoded_picinfo.pic_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->last_decoded_picinfo.buf_w, + ctx->last_decoded_picinfo.buf_h); + + ret =vdec_if_get_param (ctx,GET_PARAM_DPB_SIZE , &dpbsize); +if (dpbsize ==0 ) +mtk_v4l2_err ("Incorrect dpb size, ret=%d" , ret); + + ctx->dpb_size = dpbsize; +} + +static void mtk_vdec_worker (struct work_struct *work) +{ + struct mtk_vcodec_ctx *ctx = container_of(work, struct mtk_vcodec_ctx, + decode_work); +struct mtk_vcodec_dev *dev = ctx->dev; +struct vb2_buffer *src_buf, *dst_buf; +struct mtk_vcodec_mem buf; +struct vdec_fb *pfb; +bool res_chg = false; +int ret; +struct mtk_video_dec_buf *dst_buf_info, *src_buf_info; +struct vb2_v4l2_buffer *dst_vb2_v4l2, *src_vb2_v4l2; + + src_buf =v4l2_m2m_next_src_buf (ctx->m2m_ctx); +if (src_buf ==NULL ) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_debug (1 ,"[%d] src_buf empty!!" , ctx->id); +return ; + } + + dst_buf =v4l2_m2m_next_dst_buf (ctx->m2m_ctx); +if (dst_buf ==NULL ) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_debug (1 ,"[%d] dst_buf empty!!" , ctx->id); +return ; + } + + src_vb2_v4l2 = container_of(src_buf, struct vb2_v4l2_buffer, vb2_buf); + src_buf_info = container_of(src_vb2_v4l2, struct mtk_video_dec_buf, vb); + + dst_vb2_v4l2 = container_of(dst_buf, struct vb2_v4l2_buffer, vb2_buf); + dst_buf_info = container_of(dst_vb2_v4l2, struct mtk_video_dec_buf, vb); + + buf.va =vb2_plane_vaddr (src_buf,0 ); + buf.dma_addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); + buf.size = (size_t )src_buf->planes[0 ].bytesused; +if (!buf.va) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_err ("[%d] id=%d src_addr is NULL!!" , + ctx->id, src_buf->index); +return ; + } + + pfb = &dst_buf_info->frame_buffer; + pfb->base_y.va =vb2_plane_vaddr (dst_buf,0 ); + pfb->base_y.dma_addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 ); + pfb->base_y.size = ctx->picinfo.y_bs_sz + ctx->picinfo.y_len_sz; + + pfb->base_c.va =vb2_plane_vaddr (dst_buf,1 ); + pfb->base_c.dma_addr =vb2_dma_contig_plane_dma_addr (dst_buf,1 ); + pfb->base_c.size = ctx->picinfo.c_bs_sz + ctx->picinfo.c_len_sz; + pfb->status =0 ; +mtk_v4l2_debug (3 ,"===>[%d] vdec_if_decode() ===>" , ctx->id); +mtk_v4l2_debug (3 ,"[%d] Bitstream VA=%p DMA=%llx Size=0x%lx vb=%p" , + ctx->id, buf.va, (u64 )buf.dma_addr, buf.size, src_buf); + +mtk_v4l2_debug (3 , +"id=%d Framebuf pfb=%p VA=%p Y_DMA=%llx C_DMA=%llx Size=0x%lx" , + dst_buf->index, pfb, + pfb->base_y.va, (u64 )pfb->base_y.dma_addr, + (u64 )pfb->base_c.dma_addr, pfb->base_y.size); + +if (src_buf_info->lastframe) { +/* update src buf status */ + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); + src_buf_info->lastframe = false; +v4l2_m2m_buf_done (&src_buf_info->vb,VB2_BUF_STATE_DONE ); +drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 395
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+/* update dst buf status */ + dst_buf =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx); + dst_buf_info->used = false; + +vdec_if_decode (ctx,NULL ,NULL , &res_chg); +clean_display_buffer (ctx); +vb2_set_plane_payload (&dst_buf_info->vb.vb2_buf,0 ,0 ); +vb2_set_plane_payload (&dst_buf_info->vb.vb2_buf,1 ,0 ); +v4l2_m2m_buf_done (&dst_buf_info->vb,VB2_BUF_STATE_DONE ); +clean_free_buffer (ctx);Just call
v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); here and return.
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +1
-0+ }else {This can now have one less TAB.
Got it. Will fix this in next version.
Quoted 231 lines
Quoted 231 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +231
-0+ dst_buf_info->vb.vb2_buf.timestamp + = src_buf_info->vb.vb2_buf.timestamp; + dst_buf_info->vb.timecode + = src_buf_info->vb.timecode; +mutex_lock (&ctx->lock); + dst_buf_info->used = true; +mutex_unlock (&ctx->lock); + src_buf_info->used = true; + + ret =vdec_if_decode (ctx, &buf, pfb, &res_chg); + +if (ret) { +mtk_v4l2_err ( +" <===[%d], src_buf[%d]%d sz=0x%zx pts=%llu dst_buf[%d] vdec_if_decode() ret=%d res_chg=%d===>" , + ctx->id, + src_buf->index, + src_buf_info->lastframe, + buf.size, + src_buf_info->vb.vb2_buf.timestamp, + dst_buf->index, + ret, res_chg); + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (&src_buf_info->vb, +VB2_BUF_STATE_ERROR ); + }else if (res_chg == false) { +/* we only return src buffer with VB2_BUF_STATE_DONE +* when decode success without resolution change +*/ + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (&src_buf_info->vb, +VB2_BUF_STATE_DONE ); + } + + dst_buf =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx); +clean_display_buffer (ctx); +clean_free_buffer (ctx); + +if (!ret && res_chg) { +mtk_vdec_pic_info_update (ctx); +/* +* On encountering a resolution change in the stream. +* The driver must first process and decode all +* remaining buffers from before the resolution change +* point, so call flush decode here +*/ +mtk_vdec_flush_decoder (ctx); +/* +* After all buffers containing decoded frames from +* before the resolution change point ready to be +* dequeued on the CAPTURE queue, the driver sends a +* V4L2_EVENT_SOURCE_CHANGE event for source change +* type V4L2_EVENT_SRC_CH_RESOLUTION +*/ +mtk_vdec_queue_res_chg_event (ctx); + } + } + +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +} + +void mtk_vdec_unlock (struct mtk_vcodec_ctx *ctx) +{ +mutex_unlock (&ctx->dev->dec_mutex); +} + +void mtk_vdec_lock (struct mtk_vcodec_ctx *ctx) +{ +mutex_lock (&ctx->dev->dec_mutex); +} + +void mtk_vcodec_vdec_release (struct mtk_vcodec_ctx *ctx) +{ +vdec_if_deinit (ctx); + ctx->state =MTK_STATE_FREE ; +} + +void mtk_vcodec_dec_set_default_params (struct mtk_vcodec_ctx *ctx) +{ +struct mtk_q_data *q_data; + + ctx->m2m_ctx->q_lock = &ctx->dev->dev_mutex; + ctx->fh.m2m_ctx = ctx->m2m_ctx; + ctx->fh.ctrl_handler = &ctx->ctrl_hdl; +INIT_WORK (&ctx->decode_work, mtk_vdec_worker); + ctx->colorspace =V4L2_COLORSPACE_REC709 ; + ctx->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + ctx->quantization =V4L2_QUANTIZATION_DEFAULT ; + ctx->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + + q_data = &ctx->q_data[MTK_Q_DATA_SRC ]; +memset (q_data,0 ,sizeof (struct mtk_q_data )); + q_data->visible_width =DFT_CFG_WIDTH ; + q_data->visible_height =DFT_CFG_HEIGHT ; + q_data->fmt = &mtk_video_formats[OUT_FMT_IDX ]; + q_data->field =V4L2_FIELD_NONE ; + + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ] = +DFT_CFG_WIDTH *DFT_CFG_HEIGHT ; + ctx->q_data[MTK_Q_DATA_DST ].bytesperline[0 ] =0 ; + + q_data = &ctx->q_data[MTK_Q_DATA_DST ]; +memset (q_data,0 ,sizeof (struct mtk_q_data )); + q_data->visible_width =DFT_CFG_WIDTH ; + q_data->visible_height =DFT_CFG_HEIGHT ; + q_data->coded_width =DFT_CFG_WIDTH ; + q_data->coded_height =DFT_CFG_HEIGHT ; + q_data->fmt = &mtk_video_formats[CAP_FMT_IDX ]; + q_data->field =V4L2_FIELD_NONE ; + +v4l_bound_align_image (&q_data->coded_width, +MTK_VDEC_MIN_W , +MTK_VDEC_MAX_W ,4 , + &q_data->coded_height, +MTK_VDEC_MIN_H , +MTK_VDEC_MAX_H ,5 ,6 ); + + q_data->sizeimage[0 ] = q_data->coded_width * q_data->coded_height; + q_data->bytesperline[0 ] = q_data->coded_width; + q_data->sizeimage[1 ] = q_data->sizeimage[0 ] /2 ; + q_data->bytesperline[1 ] = q_data->coded_width; +} + +static int vidioc_vdec_qbuf (struct file *file,void *priv, +struct v4l2_buffer *buf) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +struct vb2_queue *vq; +struct vb2_buffer *vb; +struct mtk_video_dec_buf *mtkbuf; +struct vb2_v4l2_buffer *vb2_v4l2; + +if (ctx->state ==MTK_STATE_ABORT ) { +mtk_v4l2_err ("[%d] Call on QBUF after unrecoverable error" , + ctx->id); +return -EIO ; + } + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx, buf->type); + vb = vq->bufs[buf->index]; + vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); + mtkbuf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb); + +if ((buf->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) && + (buf->m.planes[0 ].bytesused ==0 )) { + mtkbuf->lastframe = true; +mtk_v4l2_debug (1 ,"[%d] (%d) id=%d lastframe=%d (%d,%d, %d) vb=%p" , + ctx->id, buf->type, buf->index, + mtkbuf->lastframe, buf->bytesused, + buf->m.planes[0 ].bytesused, buf->length, + vb); + } + +return v4l2_m2m_qbuf (file, ctx->m2m_ctx, buf); +} + +static int vidioc_vdec_dqbuf (struct file *file,void *priv, +struct v4l2_buffer *buf) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); + +if (ctx->state ==MTK_STATE_ABORT ) { +mtk_v4l2_err ("[%d] Call on DQBUF after unrecoverable error" , + ctx->id); +return -EIO ; + } + +return v4l2_m2m_dqbuf (file, ctx->m2m_ctx, buf); +} + +static int vidioc_vdec_querycap (struct file *file,void *priv, +struct v4l2_capability *cap) +{ +strlcpy (cap->driver,MTK_VCODEC_DEC_NAME ,sizeof (cap->driver)); +strlcpy (cap->bus_info,MTK_PLATFORM_STR ,sizeof (cap->bus_info)); +strlcpy (cap->card,MTK_PLATFORM_STR ,sizeof (cap->card)); + +return 0 ; +} + +static int vidioc_vdec_subscribe_evt (struct v4l2_fh *fh, +const struct v4l2_event_subscription *sub) +{ +switch (sub->type) { +case V4L2_EVENT_EOS : +return v4l2_event_subscribe (fh, sub,2 ,NULL ); +case V4L2_EVENT_SOURCE_CHANGE : +return v4l2_src_change_event_subscribe (fh, sub); +default : +return v4l2_ctrl_subscribe_event (fh, sub); + } +} + +static int vidioc_try_fmt_vid_cap_mplane (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct mtk_video_fmt *fmt; + + fmt =mtk_vdec_find_format (f); +if (!fmt) { + f->fmt.pix.pixelformat = mtk_video_formats[CAP_FMT_IDX ].fourcc; + fmt =mtk_vdec_find_format (f); + } + +return 0 ; +} + +static int vidioc_try_fmt_vid_out_mplane (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp; +struct mtk_video_fmt *fmt; + + fmt =mtk_vdec_find_format (f); +if (!fmt) { + f->fmt.pix.pixelformat = mtk_video_formats[OUT_FMT_IDX ].fourcc; + fmt =mtk_vdec_find_format (f); + } + +if (pix_fmt_mp->plane_fmt[0 ].sizeimage ==0 ) { +mtk_v4l2_err ("sizeimage of output format must be given" ); +return -EINVAL ; + } + +return 0 ; +} + +static int vidioc_vdec_g_selection (struct file *file,void *priv, +struct v4l2_selection *s) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 632
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+if (V4L2_TYPE_IS_OUTPUT (s->type)) +return -EINVAL ; + +if (s->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ;How does the cropping rectangle relate to the format size? There is no
s_selection, so this doesn't make sense.
I want to return encoded crop information or real display region that display driver could know where is padding region.
User space use s_fmt/g_fmt to set/get coded_width and coded_height, and use g_crop to get real display region.
That's why I do not add s_selection.
Quoted 2 lines
Alternatively, it could be that you are really returning
V4L2_SEL_TGT_COMPOSE_PADDED.
V4L2_SEL_TGT_COMPOSE_PADDED means
"The active area and all padding pixels that are inserted or modified by hardware."
But I just want to return active area to user space.
Quoted 311 lines
Quoted 311 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +311
-0+ +if (ctx->state <MTK_STATE_HEADER ) +return -EINVAL ; + +if ((ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_H264 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP8 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP9 )) { + +if (vdec_if_get_param (ctx,GET_PARAM_CROP_INFO , &(s->r))) { +mtk_v4l2_debug (2 , +"[%d]Error!! Cannot get param : GET_PARAM_CROP_INFO ERR" , + ctx->id); + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.buf_w; + s->r.height = ctx->picinfo.buf_h; + } +mtk_v4l2_debug (2 ,"Cropping info: l=%d t=%d w=%d h=%d" , + s->r.left, s->r.top, s->r.width, + s->r.height); + }else { + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.pic_w; + s->r.height = ctx->picinfo.pic_h; +mtk_v4l2_debug (2 ,"Cropping info: w=%d h=%d fw=%d fh=%d" , + s->r.width, s->r.height, ctx->picinfo.buf_w, + ctx->picinfo.buf_h); + } +return 0 ; +} + +static int vidioc_vdec_s_fmt (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +struct v4l2_pix_format_mplane *pix_mp; +struct mtk_q_data *q_data; +int ret =0 ; +struct mtk_video_fmt *fmt; +struct vb2_queue *vq; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); + + fmt =mtk_vdec_find_format (f); +if (fmt ==NULL ) { +mtk_v4l2_err ("vidioc_vdec_s_fmt fail" ); +return ret; + } + + pix_mp = &f->fmt.pix_mp; +if ((f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) && +vb2_is_busy (&ctx->m2m_ctx->out_q_ctx.q)) { +mtk_v4l2_err ("out_q_ctx buffers already requested" ); + ret = -EBUSY ; + } + +if ((f->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) && +vb2_is_busy (&ctx->m2m_ctx->cap_q_ctx.q)) { +mtk_v4l2_err ("cap_q_ctx buffers already requested" ); + ret = -EBUSY ; + } + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx, f->type); + + q_data =mtk_vdec_get_q_data (ctx, f->type); +if (!q_data) +return -EINVAL ; + + q_data->fmt = fmt; +if (f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { + q_data->sizeimage[0 ] = pix_mp->plane_fmt[0 ].sizeimage; + pix_mp->plane_fmt[0 ].bytesperline =0 ; + pix_mp->width =0 ; + pix_mp->height =0 ; + +if (ctx->state ==MTK_STATE_FREE ) { + ret =vdec_if_init (ctx, q_data->fmt->fourcc); +if (ret) { +mtk_v4l2_err ("[%d]: vdec_if_init() fail ret=%d" , + ctx->id, ret); +return -EINVAL ; + } + ctx->state =MTK_STATE_INIT ; + } + } + +return 0 ; +} + +static int vidioc_enum_framesizes (struct file *file,void *priv, +struct v4l2_frmsizeenum *fsize) +{ +int i =0 ; +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); + +if (fsize->index !=0 ) +return -EINVAL ; + +for (i =0 ; i <NUM_SUPPORTED_FRAMESIZE ; ++i) { +if (fsize->pixel_format != mtk_vdec_framesizes[i].fourcc) +continue ; + + fsize->type =V4L2_FRMSIZE_TYPE_STEPWISE ; + fsize->stepwise = mtk_vdec_framesizes[i].stepwise; +if (!(ctx->dev->dec_capability & +VCODEC_CAPABILITY_4K_DISABLED )) { +mtk_v4l2_debug (3 ,"4K is enabled" ); + fsize->stepwise.max_width = +VCODEC_DEC_4K_CODED_WIDTH ; + fsize->stepwise.max_height = +VCODEC_DEC_4K_CODED_HEIGHT ; + } +mtk_v4l2_debug (1 ,"%x, %d %d %d %d %d %d" , + ctx->dev->dec_capability, + fsize->stepwise.min_width, + fsize->stepwise.max_width, + fsize->stepwise.step_width, + fsize->stepwise.min_height, + fsize->stepwise.max_height, + fsize->stepwise.step_height); +return 0 ; + } + +return -EINVAL ; +} + +static int vidioc_enum_fmt (struct v4l2_fmtdesc *f,bool output_queue) +{ +struct mtk_video_fmt *fmt; +int i, j =0 ; + +for (i =0 ; i <NUM_FORMATS ; i++) { +if (output_queue && (mtk_video_formats[i].type !=MTK_FMT_DEC )) +continue ; +if (!output_queue && + (mtk_video_formats[i].type !=MTK_FMT_FRAME )) +continue ; + +if (j == f->index) +break ; + ++j; + } + +if (i ==NUM_FORMATS ) +return -EINVAL ; + + fmt = &mtk_video_formats[i]; + f->pixelformat = fmt->fourcc; + +return 0 ; +} + +static int vidioc_vdec_enum_fmt_vid_cap_mplane (struct file *file,void *pirv, +struct v4l2_fmtdesc *f) +{ +return vidioc_enum_fmt (f, false); +} + +static int vidioc_vdec_enum_fmt_vid_out_mplane (struct file *file,void *priv, +struct v4l2_fmtdesc *f) +{ +return vidioc_enum_fmt (f, true); +} + +static int vidioc_vdec_g_fmt (struct file *file,void *priv, +struct v4l2_format *f) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; +struct vb2_queue *vq; +struct mtk_q_data *q_data; + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx, f->type); +if (!vq) { +mtk_v4l2_err ("no vb2 queue for type=%d" , + f->type); +return -EINVAL ; + } + + q_data =mtk_vdec_get_q_data (ctx, f->type); + +if ((f->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) && + (ctx->state >=MTK_STATE_HEADER )) { +/* Until STREAMOFF is called on the CAPTURE queue +* (acknowledging the event), the driver operates as if +* the resolution hasn't changed yet. +* So we just return picinfo yet, and update picinfo in +* stop_streaming hook function +*/ + q_data->sizeimage[0 ] = ctx->picinfo.y_bs_sz + + ctx->picinfo.y_len_sz; + q_data->sizeimage[1 ] = ctx->picinfo.c_bs_sz + + ctx->picinfo.c_len_sz; + q_data->bytesperline[0 ] = ctx->last_decoded_picinfo.buf_w; + q_data->bytesperline[1 ] = ctx->last_decoded_picinfo.buf_w; + q_data->coded_width = ctx->picinfo.buf_w; + q_data->coded_height = ctx->picinfo.buf_h; + +/* +* Width and height are set to the dimensions +* of the movie, the buffer is bigger and +* further processing stages should crop to this +* rectangle. +*/ + pix_mp->width = q_data->coded_width; + pix_mp->height = q_data->coded_height; + pix_mp->field =V4L2_FIELD_NONE ; + +/* +* Set pixelformat to the format in which mt vcodec +* outputs the decoded frame +*/ + pix_mp->num_planes = q_data->fmt->num_planes; + pix_mp->pixelformat = q_data->fmt->fourcc; + pix_mp->plane_fmt[0 ].bytesperline = q_data->bytesperline[0 ]; + pix_mp->plane_fmt[0 ].sizeimage = q_data->sizeimage[0 ]; + pix_mp->plane_fmt[1 ].bytesperline = q_data->bytesperline[1 ]; + pix_mp->plane_fmt[1 ].sizeimage = q_data->sizeimage[1 ]; + + }else if (f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +/* +* This is run on OUTPUT +* The buffer contains compressed image +* so width and height have no meaning. +* Assign value here to pass v4l2-compliance test +*/ + pix_mp->width = q_data->visible_width; + pix_mp->height = q_data->visible_height; + pix_mp->field =V4L2_FIELD_NONE ; + pix_mp->plane_fmt[0 ].bytesperline = q_data->bytesperline[0 ]; + pix_mp->plane_fmt[0 ].sizeimage = q_data->sizeimage[0 ]; + pix_mp->pixelformat = q_data->fmt->fourcc; + pix_mp->num_planes = q_data->fmt->num_planes; + }else { + pix_mp->width = q_data->coded_width; + pix_mp->height = q_data->coded_height; + pix_mp->field =V4L2_FIELD_NONE ; + pix_mp->num_planes = q_data->fmt->num_planes; + pix_mp->pixelformat = q_data->fmt->fourcc; + pix_mp->plane_fmt[0 ].bytesperline = q_data->bytesperline[0 ]; + pix_mp->plane_fmt[0 ].sizeimage = q_data->sizeimage[0 ]; + pix_mp->plane_fmt[1 ].bytesperline = q_data->bytesperline[1 ]; + pix_mp->plane_fmt[1 ].sizeimage = q_data->sizeimage[1 ]; + +mtk_v4l2_debug (1 ,"[%d] state=%d Format could not be read %d, not ready yet!" , + ctx->id, ctx->state, f->type); +return -EINVAL ; + } + +return 0 ; +} + +static int vb2ops_vdec_queue_setup (struct vb2_queue *vq, +unsigned int *nbuffers, +unsigned int *nplanes, +unsigned int sizes[],void *alloc_ctxs[]) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vq); +struct mtk_q_data *q_data; +unsigned int i; + + q_data =mtk_vdec_get_q_data (ctx, vq->type); + +if (q_data ==NULL ) { +mtk_v4l2_err ("vq->type=%d err\n" , vq->type); +return -EINVAL ; + } + +if (*nplanes) { +for (i =0 ; i < *nplanes; i++) { +if (sizes[i] < q_data->sizeimage[i]) +return -EINVAL ; + alloc_ctxs[i] = ctx->dev->alloc_ctx; + } + }else { + +if (vq->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +if (ctx->state <MTK_STATE_HEADER ) { +mtk_v4l2_err ("State not ready" ); +return -EINVAL ; + } +/* +* Output plane count is 2 - one for Y and one for CbCr +*/ + *nplanes =2 ; + }else { + *nplanes =1 ; + } + +for (i =0 ; i < *nplanes; i++) { + sizes[i] = q_data->sizeimage[i]; + alloc_ctxs[i] = ctx->dev->alloc_ctx; + } + } + +mtk_v4l2_debug (1 , +"[%d]\t type = %d, get %d plane(s), %d buffer(s) of size 0x%x 0x%x " , + ctx->id, vq->type, *nplanes, *nbuffers, + sizes[0 ], sizes[1 ]); + +return 0 ; +} + +static int vb2ops_vdec_buf_prepare (struct vb2_buffer *vb) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue); +struct mtk_q_data *q_data; +int i; + + mtk_v4l2_debug(3, "[%d] (%d) id=%d",
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 949
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +6
-0+ ctx->id, vb->vb2_queue->type, vb->index); + + q_data =mtk_vdec_get_q_data (ctx, vb->vb2_queue->type); + +for (i =0 ; i < q_data->fmt->num_planes; i++) { +if (vb2_plane_size (vb, i) > q_data->sizeimage[i]) {Shouldn't this be < instead of > ?
Yes, will fix this in next version.
Quoted 27 lines
Quoted 14 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +14
-0+mtk_v4l2_err ("data will not fit into plane %d (%lu < %d)" , + i,vb2_plane_size (vb, i), + q_data->sizeimage[i]); + } + } + +return 0 ; +} + +static void vb2ops_vdec_buf_queue (struct vb2_buffer *vb) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue); +struct vb2_v4l2_buffer *vb2_v4l2 =container_of (vb, + struct vb2_v4l2_buffer, vb2_buf);drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 973
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+struct mtk_video_dec_buf *buf =container_of (vb2_v4l2, + struct mtk_video_dec_buf, vb); + +mtk_v4l2_debug (3 ,"[%d] (%d) id=%d, vb=%p" , + ctx->id, vb->vb2_queue->type, + vb->index, vb); +/* +* check if this buffer is ready to be used after decode +*/ +if (vb->vb2_queue->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) {Do the 'else' part first and return there.
Quoted 2 lines
Then this can be shifted one TAB to the left.
Will fix this in next version.
Quoted 12 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 982
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +9
-0+struct vb2_buffer *src_buf; +struct mtk_vcodec_mem src_mem; +bool res_chg = false; +int ret =0 ; +unsigned int dpbsize =1 ; + +v4l2_m2m_buf_queue (ctx->m2m_ctx, vb2_v4l2); + +if (ctx->state ==MTK_STATE_INIT ) {Ditto.
Will fix this in next version.
Quoted 99 lines
Quoted 86 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +86
-0+ src_buf =v4l2_m2m_next_src_buf (ctx->m2m_ctx); +if (!src_buf) { +mtk_v4l2_err ("No src buffer" ); +return ; + } + + src_mem.va =vb2_plane_vaddr (src_buf,0 ); + src_mem.dma_addr =vb2_dma_contig_plane_dma_addr ( + src_buf, +0 ); + src_mem.size = (size_t )src_buf->planes[0 ].bytesused; +mtk_v4l2_debug (2 , +"[%d] buf id=%d va=%p dma=%llx size=%zu" , + ctx->id, src_buf->index, + src_mem.va, (u64 )src_mem.dma_addr, + src_mem.size); + + ret =vdec_if_decode (ctx, &src_mem,NULL , &res_chg); +if (ret) { +/* fb == NULL menas to parse SPS/PPS header or +* resolution info in src_mem. Decode can fail +* if there is no SPS header or picture info +* in bs +*/ + src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (to_vb2_v4l2_buffer (src_buf), +VB2_BUF_STATE_DONE ); +mtk_v4l2_debug (0 ,"[%d] vdec_if_decode() src_buf=%d, size=%zu, fail=%d" , + ctx->id, src_buf->index, + src_mem.size, ret); +return ; + } + +if (vdec_if_get_param (ctx, +GET_PARAM_PIC_INFO , + &ctx->picinfo)) { +mtk_v4l2_err ("[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR" , + ctx->id); +return ; + } + + ctx->last_decoded_picinfo = ctx->picinfo; + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ] = + ctx->picinfo.y_bs_sz + + ctx->picinfo.y_len_sz; + ctx->q_data[MTK_Q_DATA_DST ].bytesperline[0 ] = + ctx->picinfo.buf_w; + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[1 ] = + ctx->picinfo.c_bs_sz + + ctx->picinfo.c_len_sz; + ctx->q_data[MTK_Q_DATA_DST ].bytesperline[1 ] = + ctx->picinfo.buf_w; +mtk_v4l2_debug (2 ,"[%d] vdec_if_init() OK wxh=%dx%d pic wxh=%dx%d sz[0]=0x%x sz[1]=0x%x" , + ctx->id, + ctx->picinfo.buf_w, ctx->picinfo.buf_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ], + ctx->q_data[MTK_Q_DATA_DST ].sizeimage[1 ]); + + ret =vdec_if_get_param (ctx,GET_PARAM_DPB_SIZE , + &dpbsize); +if (dpbsize ==0 ) { +mtk_v4l2_err ("[%d] vdec_if_get_param() GET_PARAM_DPB_SIZE fail=%d" , + ctx->id, ret); + } + ctx->dpb_size = dpbsize; + ctx->state =MTK_STATE_HEADER ; +mtk_v4l2_debug (1 ,"[%d] dpbsize=%d" , ctx->id, + ctx->dpb_size); + }else { +mtk_v4l2_debug (3 ,"[%d] already init driver %d" , + ctx->id, ctx->state); + } + }else { +mutex_lock (&ctx->lock); +if (buf->used == false) { +v4l2_m2m_buf_queue (ctx->m2m_ctx, +to_vb2_v4l2_buffer (vb)); + buf->queued_in_vb2 = true; + buf->queued_in_v4l2 = true; + buf->ready_to_display = false; + }else { + buf->queued_in_vb2 = false; + buf->queued_in_v4l2 = true; + buf->ready_to_display = false; + }drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 1078
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +10
-0+mutex_unlock (&ctx->lock); + } +} + +static void vb2ops_vdec_buf_finish (struct vb2_buffer *vb) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue); + +if (vb->vb2_queue->type == +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) {Place this on one line.
Quoted 3 lines
Actually, just invert the condition and return. The remainder can then be shifted one TAB to the left.
Got it, will fix this in next version.
Quoted 47 lines
Quoted 47 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +47
-0+struct vb2_v4l2_buffer *vb2_v4l2; +struct mtk_video_dec_buf *buf; + + vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); + buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb); +mutex_lock (&ctx->lock); + buf->queued_in_v4l2 = false; + buf->queued_in_vb2 = false; +mutex_unlock (&ctx->lock); + } +} + +static int vb2ops_vdec_buf_init (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vb2_v4l2 =container_of (vb, + struct vb2_v4l2_buffer, vb2_buf); +struct mtk_video_dec_buf *buf =container_of (vb2_v4l2, + struct mtk_video_dec_buf, vb); + +if (vb->vb2_queue->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { + buf->used = false; + buf->ready_to_display = false; + buf->queued_in_v4l2 = false; + }else { + buf->lastframe = false; + } + +return 0 ; +} + +static int vb2ops_vdec_start_streaming (struct vb2_queue *q,unsigned int count) +{ +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (q); + +if (ctx->state ==MTK_STATE_FLUSH ) + ctx->state =MTK_STATE_HEADER ; + +return 0 ; +} + +static void vb2ops_vdec_stop_streaming (struct vb2_queue *q) +{ +struct vb2_buffer *src_buf =NULL , *dst_buf =NULL ; +struct mtk_vcodec_ctx *ctx =vb2_get_drv_priv (q); + +mtk_v4l2_debug (3 ,"[%d] (%d) state=(%x) ctx->decoded_frame_cnt=%d" , + ctx->id, q->type, ctx->state, ctx->decoded_frame_cnt);
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 1131
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +6
-0+ +if (q->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { +while ((src_buf =v4l2_m2m_src_buf_remove (ctx->m2m_ctx))) +v4l2_m2m_buf_done (to_vb2_v4l2_buffer (src_buf), +VB2_BUF_STATE_ERROR ); +Same trick can be done here.
Will fix this in next version.
Quoted 472 lines
Quoted 472 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +217
-0+ }else if (q->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) { +if (ctx->state >=MTK_STATE_HEADER ) { + +/* Until STREAMOFF is called on the CAPTURE queue +* (acknowledging the event), the driver operates +* as if the resolution hasn't changed yet, i.e. +* VIDIOC_G_FMT< etc. return previous resolution. +* So we update picinfo here +*/ + ctx->picinfo = ctx->last_decoded_picinfo; + +mtk_v4l2_debug (2 , +"[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)" , + ctx->id, ctx->last_decoded_picinfo.pic_w, + ctx->last_decoded_picinfo.pic_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->last_decoded_picinfo.buf_w, + ctx->last_decoded_picinfo.buf_h); + +mtk_vdec_flush_decoder (ctx); + } + ctx->state =MTK_STATE_FLUSH ; + +while ((dst_buf =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx))) { +vb2_set_plane_payload (dst_buf,0 ,0 ); +vb2_set_plane_payload (dst_buf,1 ,0 ); +v4l2_m2m_buf_done (to_vb2_v4l2_buffer (dst_buf), +VB2_BUF_STATE_ERROR ); + } + } +} + +static void m2mops_vdec_device_run (void *priv) +{ +struct mtk_vcodec_ctx *ctx = priv; +struct mtk_vcodec_dev *dev = ctx->dev; + +queue_work (dev->decode_workqueue, &ctx->decode_work); +} + +static int m2mops_vdec_job_ready (void *m2m_priv) +{ +struct mtk_vcodec_ctx *ctx = m2m_priv; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); + +if (ctx->state ==MTK_STATE_ABORT ) +return 0 ; + +if ((ctx->last_decoded_picinfo.pic_w != ctx->picinfo.pic_w) || + (ctx->last_decoded_picinfo.pic_h != ctx->picinfo.pic_h)) +return 0 ; + +if (ctx->state !=MTK_STATE_HEADER ) +return 0 ; + +return 1 ; +} + +static void m2mops_vdec_job_abort (void *priv) +{ +struct mtk_vcodec_ctx *ctx = priv; + + ctx->state =MTK_STATE_ABORT ; +} + +static int mtk_vdec_g_v_ctrl (struct v4l2_ctrl *ctrl) +{ +struct mtk_vcodec_ctx *ctx =ctrl_to_ctx (ctrl); +int ret =0 ; + +switch (ctrl->id) { +case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE : +if (ctx->state >=MTK_STATE_HEADER ) { + ctrl->val = ctx->dpb_size; + }else { +mtk_v4l2_err ("Seqinfo not ready" ); + ctrl->val =1 ; + ret = -EAGAIN ; + } +break ; +default : + ret = -EINVAL ; + } +return ret; +} + +static const struct v4l2_ctrl_ops mtk_vcodec_dec_ctrl_ops = { + .g_volatile_ctrl = mtk_vdec_g_v_ctrl, +}; + +int mtk_vcodec_dec_ctrls_setup (struct mtk_vcodec_ctx *ctx) +{ +struct v4l2_ctrl *ctrl; + +v4l2_ctrl_handler_init (&ctx->ctrl_hdl,1 ); + + ctrl =v4l2_ctrl_new_std (&ctx->ctrl_hdl, + &mtk_vcodec_dec_ctrl_ops, +V4L2_CID_MIN_BUFFERS_FOR_CAPTURE , +1 ,32 ,1 ,1 ); + ctrl->flags |=V4L2_CTRL_FLAG_VOLATILE ; + +if (ctx->ctrl_hdl.error) { +mtk_v4l2_err ("Adding control failed %d" , + ctx->ctrl_hdl.error); +return ctx->ctrl_hdl.error; + } + +v4l2_ctrl_handler_setup (&ctx->ctrl_hdl); +return 0 ; +} + +static void m2mops_vdec_lock (void *m2m_priv) +{ +struct mtk_vcodec_ctx *ctx = m2m_priv; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); +mutex_lock (&ctx->dev->dev_mutex); +} + +static void m2mops_vdec_unlock (void *m2m_priv) +{ +struct mtk_vcodec_ctx *ctx = m2m_priv; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); +mutex_unlock (&ctx->dev->dev_mutex); +} + +const struct v4l2_m2m_ops mtk_vdec_m2m_ops = { + .device_run = m2mops_vdec_device_run, + .job_ready = m2mops_vdec_job_ready, + .job_abort = m2mops_vdec_job_abort, + .lock = m2mops_vdec_lock, + .unlock = m2mops_vdec_unlock, +}; + +static const struct vb2_ops mtk_vdec_vb2_ops = { + .queue_setup = vb2ops_vdec_queue_setup, + .buf_prepare = vb2ops_vdec_buf_prepare, + .buf_queue = vb2ops_vdec_buf_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .buf_init = vb2ops_vdec_buf_init, + .buf_finish = vb2ops_vdec_buf_finish, + .start_streaming = vb2ops_vdec_start_streaming, + .stop_streaming = vb2ops_vdec_stop_streaming, +}; + +const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops = { + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + + .vidioc_qbuf = vidioc_vdec_qbuf, + .vidioc_dqbuf = vidioc_vdec_dqbuf, + + .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt_vid_cap_mplane, + .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt_vid_out_mplane, + + .vidioc_s_fmt_vid_cap_mplane = vidioc_vdec_s_fmt, + .vidioc_s_fmt_vid_out_mplane = vidioc_vdec_s_fmt, + .vidioc_g_fmt_vid_cap_mplane = vidioc_vdec_g_fmt, + .vidioc_g_fmt_vid_out_mplane = vidioc_vdec_g_fmt, + + .vidioc_enum_fmt_vid_cap_mplane = vidioc_vdec_enum_fmt_vid_cap_mplane, + .vidioc_enum_fmt_vid_out_mplane = vidioc_vdec_enum_fmt_vid_out_mplane, + .vidioc_enum_framesizes = vidioc_enum_framesizes, + + .vidioc_querycap = vidioc_vdec_querycap, + .vidioc_subscribe_event = vidioc_vdec_subscribe_evt, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, + .vidioc_g_selection = vidioc_vdec_g_selection, +}; + +int mtk_vcodec_dec_queue_init (void *priv,struct vb2_queue *src_vq, +struct vb2_queue *dst_vq) +{ +struct mtk_vcodec_ctx *ctx = priv; +int ret =0 ; + +mtk_v4l2_debug (3 ,"[%d]" , ctx->id); + + src_vq->type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; + src_vq->io_modes =VB2_DMABUF |VB2_MMAP ; + src_vq->drv_priv = ctx; + src_vq->buf_struct_size =sizeof (struct mtk_video_dec_buf ); + src_vq->ops = &mtk_vdec_vb2_ops; + src_vq->mem_ops = &vb2_dma_contig_memops; + src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + src_vq->lock = &ctx->dev->dev_mutex; + + ret =vb2_queue_init (src_vq); +if (ret) { +mtk_v4l2_err ("Failed to initialize videobuf2 queue(output)" ); +return ret; + } + dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; + dst_vq->io_modes =VB2_DMABUF |VB2_MMAP ; + dst_vq->drv_priv = ctx; + dst_vq->buf_struct_size =sizeof (struct mtk_video_dec_buf ); + dst_vq->ops = &mtk_vdec_vb2_ops; + dst_vq->mem_ops = &vb2_dma_contig_memops; + dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; + dst_vq->lock = &ctx->dev->dev_mutex; + + ret =vb2_queue_init (dst_vq); +if (ret) { +vb2_queue_release (src_vq); +mtk_v4l2_err ("Failed to initialize videobuf2 queue(capture)" ); + } + +return ret; +} +drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h new file +88
-0@@ -0,0 +1,88 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _MTK_VCODEC_DEC_H_ +#define _MTK_VCODEC_DEC_H_ + +#include <media/videobuf2-core.h> +#include <media/videobuf2-v4l2.h> + +#define VCODEC_CAPABILITY_4K_DISABLED 0x10 +#define VCODEC_DEC_4K_CODED_WIDTH 4096U +#define VCODEC_DEC_4K_CODED_HEIGHT 2304U +#define MTK_VDEC_MAX_W 2048U +#define MTK_VDEC_MAX_H 1088U + +#define MTK_VDEC_IRQ_STATUS_DEC_SUCCESS 0x10000 + +/** +* struct vdec_fb - decoder frame buffer +* @base_y : Y plane memory info +* @base_c : C plane memory info +* @status : frame buffer status (vdec_fb_status) +*/ +struct vdec_fb { +struct mtk_vcodec_mem base_y; +struct mtk_vcodec_mem base_c; +unsigned int status; +}; + +/** +* struct mtk_video_dec_buf - Private data related to each VB2 buffer. +* @b: VB2 buffer +* @list: link list +* @used: Capture buffer contain decoded frame data and keep in +* codec data structure +* @ready_to_display: Capture buffer not display yet +* @queued_in_vb2: Capture buffer is queue in vb2 +* @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2 +* queue yet +* @lastframe: Intput buffer is last buffer - EOS +* @frame_buffer: Decode status, and buffer information of Capture buffer +* +* Note : These status information help us track and debug buffer state +*/ +struct mtk_video_dec_buf { +struct vb2_v4l2_buffer vb; +struct list_head list; + +bool used; +bool ready_to_display; +bool queued_in_vb2; +bool queued_in_v4l2; +bool lastframe; +struct vdec_fb frame_buffer; +}; + +extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops; +extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops; + + +/* +* mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to +* get/release lock before/after access decoder hw. +* mtk_vdec_lock get decoder hw lock and set curr_ctx +* to ctx instance that get lock +*/ +void mtk_vdec_unlock (struct mtk_vcodec_ctx *ctx); +void mtk_vdec_lock (struct mtk_vcodec_ctx *ctx); +int mtk_vcodec_dec_queue_init (void *priv,struct vb2_queue *src_vq, +struct vb2_queue *dst_vq); +void mtk_vcodec_dec_set_default_params (struct mtk_vcodec_ctx *ctx); +void mtk_vcodec_vdec_release (struct mtk_vcodec_ctx *ctx); +int mtk_vcodec_dec_ctrls_setup (struct mtk_vcodec_ctx *ctx); + + +#endif /* _MTK_VCODEC_DEC_H_ */ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +155
-0@@ -0,0 +1,408 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of.h> +#include <media/v4l2-event.h> +#include <media/v4l2-mem2mem.h> +#include <media/videobuf2-dma-contig.h> + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_dec.h" +#include "mtk_vcodec_dec_pm.h" +#include "mtk_vcodec_intr.h" +#include "mtk_vcodec_util.h" +#include "mtk_vpu.h" + +#define VDEC_HW_ACTIVE 0x10 +#define VDEC_IRQ_CFG 0x11 +#define VDEC_IRQ_CLR 0x10 +#define VDEC_IRQ_CFG_REG 0xa4 + +module_param (mtk_v4l2_dbg_level, int,S_IRUGO |S_IWUSR ); +module_param (mtk_vcodec_dbg, bool,S_IRUGO |S_IWUSR ); + +/* Wake up context wait_queue */ +static void wake_up_ctx (struct mtk_vcodec_ctx *ctx) +{ + ctx->int_cond =1 ; +wake_up_interruptible (&ctx->queue); +} + +static irqreturn_t mtk_vcodec_dec_irq_handler (int irq,void *priv) +{ +struct mtk_vcodec_dev *dev = priv; +struct mtk_vcodec_ctx *ctx; +u32 cg_status =0 ; +unsigned int dec_done_status =0 ; +void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC ] + +VDEC_IRQ_CFG_REG ; + + ctx =mtk_vcodec_get_curr_ctx (dev); + +/* check if HW active or not */ + cg_status =readl (dev->reg_base[0 ]); +if ((cg_status &VDEC_HW_ACTIVE ) !=0 ) { +mtk_v4l2_err ("DEC ISR, VDEC active is not 0x0 (0x%08x)" , + cg_status); +return IRQ_HANDLED ; + } + + dec_done_status =readl (vdec_misc_addr); + ctx->irq_status = dec_done_status; +if ((dec_done_status &MTK_VDEC_IRQ_STATUS_DEC_SUCCESS ) != +MTK_VDEC_IRQ_STATUS_DEC_SUCCESS ) +return IRQ_HANDLED ; + +/* clear interrupt */ +writel ((readl (vdec_misc_addr) |VDEC_IRQ_CFG ), + dev->reg_base[VDEC_MISC ] +VDEC_IRQ_CFG_REG ); +writel ((readl (vdec_misc_addr) & ~VDEC_IRQ_CLR ), + dev->reg_base[VDEC_MISC ] +VDEC_IRQ_CFG_REG ); + +wake_up_ctx (ctx); + +mtk_v4l2_debug (3 , +"mtk_vcodec_dec_irq_handler :wake up ctx %d, dec_done_status=%x" , + ctx->id, dec_done_status); + +return IRQ_HANDLED ; +} + +static void mtk_vcodec_dec_reset_handler (void *priv) +{ +struct mtk_vcodec_dev *dev = priv; +struct mtk_vcodec_ctx *ctx; + +mtk_v4l2_err ("Watchdog timeout!!" ); + +mutex_lock (&dev->dev_mutex); +list_for_each_entry (ctx, &dev->ctx_list, list) { + ctx->state =MTK_STATE_ABORT ; +mtk_v4l2_debug (0 ,"[%d] Change to state MTK_STATE_ERROR" , + ctx->id); + } +mutex_unlock (&dev->dev_mutex); +} + +static int fops_vcodec_open (struct file *file) +{ +struct mtk_vcodec_dev *dev =video_drvdata (file); +struct mtk_vcodec_ctx *ctx =NULL ; +int ret =0 ; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + +mutex_lock (&dev->dev_mutex); + ctx->id = dev->id_counter++; +v4l2_fh_init (&ctx->fh,video_devdata (file)); + file->private_data = &ctx->fh; +v4l2_fh_add (&ctx->fh); +INIT_LIST_HEAD (&ctx->list); + ctx->dev = dev; +init_waitqueue_head (&ctx->queue); +mutex_init (&ctx->lock); + + ctx->type =MTK_INST_DECODER ; + ret =mtk_vcodec_dec_ctrls_setup (ctx); +if (ret) { +mtk_v4l2_err ("Failed to setup mt vcodec controls" ); + goto err_ctrls_setup; + } + ctx->m2m_ctx =v4l2_m2m_ctx_init (dev->m2m_dev_dec, ctx, + &mtk_vcodec_dec_queue_init); +if (IS_ERR ((__force void *)ctx->m2m_ctx)) { + ret =PTR_ERR ((__force void *)ctx->m2m_ctx); +mtk_v4l2_err ("Failed to v4l2_m2m_ctx_init() (%d)" , + ret); + goto err_m2m_ctx_init; + } +mtk_vcodec_dec_set_default_params (ctx); + +if (v4l2_fh_is_singular (&ctx->fh)) { +mtk_vcodec_dec_pw_on (&dev->pm); +/* +* vpu_load_firmware checks if it was loaded already and +* does nothing in that case +*/ + ret =vpu_load_firmware (dev->vpu_plat_dev); +if (ret <0 ) { +/* +* Return 0 if downloading firmware successfully, +* otherwise it is failed +*/ +mtk_v4l2_err ("vpu_load_firmware failed!" ); + goto err_load_fw; + } +
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c line 161
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +6
-0+ dev->dec_capability = +vpu_get_vdec_hw_capa (dev->vpu_plat_dev); +mtk_v4l2_debug (0 ,"decoder capability %x" , dev->dec_capability); + } + + dev->num_instances++;This field can be dropped since it is no longer used.
Will remove this in next version.
best regards,
Tiffany
Quoted 1,203 lines
Quoted 1,189 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c new file +247
-0+list_add (&ctx->list, &dev->ctx_list); + +mutex_unlock (&dev->dev_mutex); +mtk_v4l2_debug (0 ,"%s decoder [%d]" ,dev_name (&dev->plat_dev->dev), + ctx->id); +return ret; + +/* Deinit when failure occurred */ +err_load_fw: +v4l2_m2m_ctx_release (ctx->m2m_ctx); +err_m2m_ctx_init: +v4l2_ctrl_handler_free (&ctx->ctrl_hdl); +err_ctrls_setup: +v4l2_fh_del (&ctx->fh); +v4l2_fh_exit (&ctx->fh); +kfree (ctx); +mutex_unlock (&dev->dev_mutex); + +return ret; +} + +static int fops_vcodec_release (struct file *file) +{ +struct mtk_vcodec_dev *dev =video_drvdata (file); +struct mtk_vcodec_ctx *ctx =fh_to_ctx (file->private_data); + +mtk_v4l2_debug (0 ,"[%d] decoder" , ctx->id); +mutex_lock (&dev->dev_mutex); + +mtk_vcodec_vdec_release (ctx); +if (v4l2_fh_is_singular (&ctx->fh)) +mtk_vcodec_dec_pw_off (&dev->pm); + +v4l2_fh_del (&ctx->fh); +v4l2_fh_exit (&ctx->fh); +v4l2_ctrl_handler_free (&ctx->ctrl_hdl); +v4l2_m2m_ctx_release (ctx->m2m_ctx); + +list_del_init (&ctx->list); + dev->num_instances--; +kfree (ctx); +mutex_unlock (&dev->dev_mutex); +return 0 ; +} + +static const struct v4l2_file_operations mtk_vcodec_fops = { + .owner =THIS_MODULE , + .open = fops_vcodec_open, + .release = fops_vcodec_release, + .poll = v4l2_m2m_fop_poll, + .unlocked_ioctl = video_ioctl2, + .mmap = v4l2_m2m_fop_mmap, +}; + +static int mtk_vcodec_probe (struct platform_device *pdev) +{ +struct mtk_vcodec_dev *dev; +struct video_device *vfd_dec; +struct resource *res; +int i, ret; +DEFINE_DMA_ATTRS (attrs); + + dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL ); +if (!dev) +return -ENOMEM ; + +INIT_LIST_HEAD (&dev->ctx_list); + dev->plat_dev = pdev; + + dev->vpu_plat_dev =vpu_get_plat_device (dev->plat_dev); +if (dev->vpu_plat_dev ==NULL ) { +mtk_v4l2_err ("[VPU] vpu device in not ready" ); +return -EPROBE_DEFER ; + } + +vpu_wdt_reg_handler (dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler, + dev,VPU_RST_DEC ); + + ret =mtk_vcodec_init_dec_pm (dev); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to get mt vcodec clock source" ); +return ret; + } + +for (i =0 ; i <NUM_MAX_VDEC_REG_BASE ; i++) { + res =platform_get_resource (pdev,IORESOURCE_MEM , i); +if (res ==NULL ) { +dev_err (&pdev->dev,"get memory resource failed." ); + ret = -ENXIO ; + goto err_res; + } + dev->reg_base[i] =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR ((__force void *)dev->reg_base[i])) { +dev_err (&pdev->dev, +"devm_ioremap_resource %d failed." , i); + ret =PTR_ERR ((__force void *)dev->reg_base); + goto err_res; + } +mtk_v4l2_debug (2 ,"reg[%d] base=%p" , i, dev->reg_base[i]); + } + + res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (res ==NULL ) { +dev_err (&pdev->dev,"failed to get irq resource" ); + ret = -ENOENT ; + goto err_res; + } + + dev->dec_irq =platform_get_irq (pdev,0 ); + ret =devm_request_irq (&pdev->dev, dev->dec_irq, + mtk_vcodec_dec_irq_handler,0 , pdev->name, dev); +if (ret) { +dev_err (&pdev->dev,"Failed to install dev->dec_irq %d (%d)" , + dev->dec_irq, + ret); + goto err_res; + } + +disable_irq (dev->dec_irq); +mutex_init (&dev->dec_mutex); +mutex_init (&dev->dev_mutex); +spin_lock_init (&dev->irqlock); + +snprintf (dev->v4l2_dev.name,sizeof (dev->v4l2_dev.name),"%s" , +"[/MTK_V4L2_VDEC]" ); + + ret =v4l2_device_register (&pdev->dev, &dev->v4l2_dev); +if (ret) { +mtk_v4l2_err ("v4l2_device_register err=%d" , ret); + goto err_res; + } + +init_waitqueue_head (&dev->queue); + + vfd_dec =video_device_alloc (); +if (!vfd_dec) { +mtk_v4l2_err ("Failed to allocate video device" ); + ret = -ENOMEM ; + goto err_dec_alloc; + } + vfd_dec->fops = &mtk_vcodec_fops; + vfd_dec->ioctl_ops = &mtk_vdec_ioctl_ops; + vfd_dec->release = video_device_release; + vfd_dec->lock = &dev->dev_mutex; + vfd_dec->v4l2_dev = &dev->v4l2_dev; + vfd_dec->vfl_dir =VFL_DIR_M2M ; + vfd_dec->device_caps =V4L2_CAP_VIDEO_M2M_MPLANE | +V4L2_CAP_STREAMING ; + +snprintf (vfd_dec->name,sizeof (vfd_dec->name),"%s" , +MTK_VCODEC_DEC_NAME ); +video_set_drvdata (vfd_dec, dev); + dev->vfd_dec = vfd_dec; +platform_set_drvdata (pdev, dev); + + dev->alloc_ctx =vb2_dma_contig_init_ctx (&pdev->dev); +if (IS_ERR ((__force void *)dev->alloc_ctx)) { +mtk_v4l2_err ("Failed to alloc vb2 dma context 0" ); + ret =PTR_ERR ((__force void *)dev->alloc_ctx); + goto err_vb2_ctx_init; + } + + dev->m2m_dev_dec =v4l2_m2m_init (&mtk_vdec_m2m_ops); +if (IS_ERR ((__force void *)dev->m2m_dev_dec)) { +mtk_v4l2_err ("Failed to init mem2mem dec device" ); + ret =PTR_ERR ((__force void *)dev->m2m_dev_dec); + goto err_dec_mem_init; + } + + dev->decode_workqueue = +alloc_ordered_workqueue (MTK_VCODEC_DEC_NAME , +WQ_MEM_RECLAIM |WQ_FREEZABLE ); +if (!dev->decode_workqueue) { +mtk_v4l2_err ("Failed to create decode workqueue" ); + ret = -EINVAL ; + goto err_event_workq; + } + + ret =video_register_device (vfd_dec,VFL_TYPE_GRABBER ,0 ); +if (ret) { +mtk_v4l2_err ("Failed to register video device" ); + goto err_dec_reg; + } + +/* Avoid the iommu eat big hunks */ +dma_set_attr (DMA_ATTR_ALLOC_SINGLE_PAGES , &attrs); + +mtk_v4l2_debug (0 ,"decoder registered as /dev/video%d" , + vfd_dec->num); + +return 0 ; + +err_dec_reg: +destroy_workqueue (dev->decode_workqueue); +err_event_workq: +v4l2_m2m_release (dev->m2m_dev_dec); +err_dec_mem_init: +vb2_dma_contig_cleanup_ctx (dev->alloc_ctx); +err_vb2_ctx_init: +video_unregister_device (vfd_dec); +err_dec_alloc: +v4l2_device_unregister (&dev->v4l2_dev); +err_res: +mtk_vcodec_release_dec_pm (dev); +return ret; +} + +static const struct of_device_id mtk_vcodec_match[] = { + {.compatible ="mediatek,mt8173-vcodec-dec" ,}, + {}, +}; + +MODULE_DEVICE_TABLE (of, mtk_vcodec_match); + +static int mtk_vcodec_dec_remove (struct platform_device *pdev) +{ +struct mtk_vcodec_dev *dev =platform_get_drvdata (pdev); + +flush_workqueue (dev->decode_workqueue); +destroy_workqueue (dev->decode_workqueue); +if (dev->m2m_dev_dec) +v4l2_m2m_release (dev->m2m_dev_dec); +if (dev->alloc_ctx) +vb2_dma_contig_cleanup_ctx (dev->alloc_ctx); + +if (dev->vfd_dec) +video_unregister_device (dev->vfd_dec); + +v4l2_device_unregister (&dev->v4l2_dev); +mtk_vcodec_release_dec_pm (dev); +return 0 ; +} + +static struct platform_driver mtk_vcodec_dec_driver = { + .probe = mtk_vcodec_probe, + .remove = mtk_vcodec_dec_remove, + .driver = { + .name =MTK_VCODEC_DEC_NAME , + .owner =THIS_MODULE , + .of_match_table = mtk_vcodec_match, + }, +}; + +module_platform_driver (mtk_vcodec_dec_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Mediatek video codec V4L2 decoder driver" );drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c new file +206
-0@@ -0,0 +1,206 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/clk.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <soc/mediatek/smi.h> + +#include "mtk_vcodec_dec_pm.h" +#include "mtk_vcodec_util.h" +#include "mtk_vpu.h" + +int mtk_vcodec_init_dec_pm (struct mtk_vcodec_dev *mtkdev) +{ +struct device_node *node; +struct platform_device *pdev; +struct device *dev; +struct mtk_vcodec_pm *pm; +int ret =0 ; + + pdev = mtkdev->plat_dev; + pm = &mtkdev->pm; + pm->mtkdev = mtkdev; + dev = &pdev->dev; + node =of_parse_phandle (pdev->dev.of_node,"mediatek,larb" ,0 ); +if (!node) { +mtk_v4l2_err ("of_parse_phandle mediatek,larb fail!" ); +return -1 ; + } + + pdev =of_find_device_by_node (node); +if (WARN_ON (!pdev)) { +of_node_put (node); +return -1 ; + } + pm->larbvdec = &pdev->dev; + + pdev = mtkdev->plat_dev; + pm->dev = &pdev->dev; + + pm->vcodecpll =devm_clk_get (&pdev->dev,"vcodecpll" ); +if (pm->vcodecpll ==NULL ) { +mtk_v4l2_err ("devm_clk_get vcodecpll fail" ); + ret =-1 ; + } + + pm->univpll_d2 =devm_clk_get (&pdev->dev,"univpll_d2" ); +if (pm->univpll_d2 ==NULL ) { +mtk_v4l2_err ("devm_clk_get univpll_d2 fail" ); + ret =-1 ; + } + + pm->clk_cci400_sel =devm_clk_get (&pdev->dev,"clk_cci400_sel" ); +if (pm->clk_cci400_sel ==NULL ) { +mtk_v4l2_err ("devm_clk_get clk_cci400_sel fail" ); + ret =-1 ; + } + + pm->vdec_sel =devm_clk_get (&pdev->dev,"vdec_sel" ); +if (pm->vdec_sel ==NULL ) { +mtk_v4l2_err ("devm_clk_get vdec_sel fail" ); + ret =-1 ; + } + + pm->vdecpll =devm_clk_get (&pdev->dev,"vdecpll" ); +if (pm->vdecpll ==NULL ) { +mtk_v4l2_err ("devm_clk_get vdecpll fail" ); + ret =-1 ; + } + + pm->vencpll =devm_clk_get (&pdev->dev,"vencpll" ); +if (pm->vencpll ==NULL ) { +mtk_v4l2_err ("devm_clk_get vencpll fail" ); + ret =-1 ; + } + + pm->venc_lt_sel =devm_clk_get (&pdev->dev,"venc_lt_sel" ); +if (pm->venc_lt_sel ==NULL ) { +mtk_v4l2_err ("devm_clk_get venc_lt_sel fail" ); + ret =-1 ; + } + + pm->vdec_bus_clk_src =devm_clk_get (&pdev->dev,"vdec_bus_clk_src" ); +if (pm->vdec_bus_clk_src ==NULL ) { +mtk_v4l2_err ("devm_clk_get vdec_bus_clk_src" ); + ret =-1 ; + } + +pm_runtime_enable (&pdev->dev); + +return ret; +} + +void mtk_vcodec_release_dec_pm (struct mtk_vcodec_dev *dev) +{ +pm_runtime_disable (dev->pm.dev); +} + +void mtk_vcodec_dec_pw_on (struct mtk_vcodec_pm *pm) +{ +int ret; + + ret =pm_runtime_get_sync (pm->dev); +if (ret) +mtk_v4l2_err ("pm_runtime_get_sync fail %d" , ret); +} + +void mtk_vcodec_dec_pw_off (struct mtk_vcodec_pm *pm) +{ +int ret; + + ret =pm_runtime_put_sync (pm->dev); +if (ret) +mtk_v4l2_err ("pm_runtime_put_sync fail %d" , ret); +} + +void mtk_vcodec_dec_clock_on (struct mtk_vcodec_pm *pm) +{ +int ret; + + ret =clk_set_rate (pm->vcodecpll,1482 *1000000 ); +if (ret) +mtk_v4l2_err ("clk_set_rate vcodecpll fail %d" , ret); + + ret =clk_set_rate (pm->vencpll,800 *1000000 ); +if (ret) +mtk_v4l2_err ("clk_set_rate vencpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vcodecpll); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vcodecpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vencpll); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vencpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vdec_bus_clk_src); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vdec_bus_clk_src fail %d" , + ret); + + ret =clk_prepare_enable (pm->venc_lt_sel); +if (ret) +mtk_v4l2_err ("clk_prepare_enable venc_lt_sel fail %d" , ret); + + ret =clk_set_parent (pm->venc_lt_sel, pm->vdec_bus_clk_src); +if (ret) +mtk_v4l2_err ("clk_set_parent venc_lt_sel vdec_bus_clk_src fail %d" , + ret); + + ret =clk_prepare_enable (pm->univpll_d2); +if (ret) +mtk_v4l2_err ("clk_prepare_enable univpll_d2 fail %d" , ret); + + ret =clk_prepare_enable (pm->clk_cci400_sel); +if (ret) +mtk_v4l2_err ("clk_prepare_enable clk_cci400_sel fail %d" , ret); + + ret =clk_set_parent (pm->clk_cci400_sel, pm->univpll_d2); +if (ret) +mtk_v4l2_err ("clk_set_parent clk_cci400_sel univpll_d2 fail %d" , + ret); + + ret =clk_prepare_enable (pm->vdecpll); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vdecpll fail %d" , ret); + + ret =clk_prepare_enable (pm->vdec_sel); +if (ret) +mtk_v4l2_err ("clk_prepare_enable vdec_sel fail %d" , ret); + + ret =clk_set_parent (pm->vdec_sel, pm->vdecpll); +if (ret) +mtk_v4l2_err ("clk_set_parent vdec_sel vdecpll fail %d" , ret); + + ret =mtk_smi_larb_get (pm->larbvdec); +if (ret) +mtk_v4l2_err ("mtk_smi_larb_get larbvdec fail %d" , ret); + +} + +void mtk_vcodec_dec_clock_off (struct mtk_vcodec_pm *pm) +{ +mtk_smi_larb_put (pm->larbvdec); +clk_disable_unprepare (pm->vdec_sel); +clk_disable_unprepare (pm->vdecpll); +clk_disable_unprepare (pm->univpll_d2); +clk_disable_unprepare (pm->clk_cci400_sel); +clk_disable_unprepare (pm->venc_lt_sel); +clk_disable_unprepare (pm->vdec_bus_clk_src); +clk_disable_unprepare (pm->vencpll); +clk_disable_unprepare (pm->vcodecpll); +} +drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h new file +28
-0@@ -0,0 +1,28 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _MTK_VCODEC_DEC_PM_H_ +#define _MTK_VCODEC_DEC_PM_H_ + +#include "mtk_vcodec_drv.h" + +int mtk_vcodec_init_dec_pm (struct mtk_vcodec_dev *dev); +void mtk_vcodec_release_dec_pm (struct mtk_vcodec_dev *dev); + +void mtk_vcodec_dec_pw_on (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_pw_off (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_clock_on (struct mtk_vcodec_pm *pm); +void mtk_vcodec_dec_clock_off (struct mtk_vcodec_pm *pm); + +#endif /* _MTK_VCODEC_DEC_PM_H_ */ drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +81
-7@@ -26,10 +26,10 @@#include "mtk_vcodec_util.h" #define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv" +#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"#define MTK_PLATFORM_STR "platform:mt8173" -#define MTK_VCODEC_MAX_PLANES 3#define MTK_V4L2_BENCHMARK 0#define WAIT_INTR_TIMEOUT_MS 1000@@ -180,6 +180,9 @@ struct mtk_enc_params {* struct mtk_vcodec_pm - Power management data structure */ struct mtk_vcodec_pm { +struct clk *vdec_bus_clk_src; +struct clk *vencpll; +struct clk *vcodecpll;struct clk *univpll_d2;struct clk *clk_cci400_sel;@@ -197,6 +200,32 @@ struct mtk_vcodec_pm { };/** +* struct vdec_pic_info - picture size information +* @pic_w: picture width +* @pic_h: picture height +* @buf_w: picture buffer width (64 aligned up from pic_w) +* @buf_h: picture buffer heiht (64 aligned up from pic_h) +* @y_bs_sz: Y bitstream size +* @c_bs_sz: CbCr bitstream size +* @y_len_sz: additional size required to store decompress information for y +* plane +* @c_len_sz: additional size required to store decompress information for cbcr +* plane +* E.g. suppose picture size is 176x144, +* buffer size will be aligned to 176x160. +*/ +struct vdec_pic_info { +unsigned int pic_w; +unsigned int pic_h; +unsigned int buf_w; +unsigned int buf_h; +unsigned int y_bs_sz; +unsigned int c_bs_sz; +unsigned int y_len_sz; +unsigned int c_len_sz; +}; + +/** * struct mtk_vcodec_ctx - Context (instance) private data. * * @type: type of the instance - decoder or encoder @@ -210,9 +239,12 @@ struct mtk_vcodec_pm {* @state: state of the context * @param_change: indicate encode parameter type * @enc_params: encoding parameters -* @enc_if: hoooked encoder driver interface +* @dec_if: hooked decoder driver interface +* @enc_if: hooked encoder driver interface * @drv_handle: driver handle for specific decode/encode instance * +* @picinfo: store picture info after header parsing +* @dpb_size: store dpb count after header parsing * @int_cond: variable used by the waitqueue * @int_type: type of the last interrupt * @queue: waitqueue that can be used to wait for this context to @@ -220,12 +252,16 @@ struct mtk_vcodec_pm {* @irq_status: irq status * * @ctrl_hdl: handler for v4l2 framework +* @decode_work: worker for the decoding * @encode_work: worker for the encoding +* @last_decoded_picinfo: pic information get from latest decode * * @colorspace: enum v4l2_colorspace; supplemental to pixelformat * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding * @quantization: enum v4l2_quantization, colorspace quantization * @xfer_func: enum v4l2_xfer_func, colorspace transfer function +* @lock: protect variables accessed by V4L2 threads and worker thread such as +* mtk_video_dec_buf. */ struct mtk_vcodec_ctx {enum mtk_instance_type type;@@ -240,21 +276,31 @@ struct mtk_vcodec_ctx {enum mtk_encode_param param_change;struct mtk_enc_params enc_params; +struct vdec_common_if *dec_if;struct venc_common_if *enc_if;unsigned long drv_handle; +struct vdec_pic_info picinfo; +int dpb_size; +int int_cond;int int_type;wait_queue_head_t queue;unsigned int irq_status;struct v4l2_ctrl_handler ctrl_hdl; +struct work_struct decode_work;struct work_struct encode_work; +struct vdec_pic_info last_decoded_picinfo;enum v4l2_colorspace colorspace;enum v4l2_ycbcr_encoding ycbcr_enc;enum v4l2_quantization quantization;enum v4l2_xfer_func xfer_func; + +int decoded_frame_cnt; +struct mutex lock; + };/** @@ -268,25 +314,48 @@ struct mtk_vcodec_ctx {* @alloc_ctx: VB2 allocator context * (for allocations without kernel mapping). * @ctx_list: list of struct mtk_vcodec_ctx -* @irqlock: protect data access by irq handler and work thread -* @curr_ctx: The context that is waiting for codec hardware +* @irqlock: protect data access by irq handler and work thread -- curr_ctx +* @curr_ctx: The context that is waiting for codec hardware. Protected by +* irqlock and dec_mutex or enc_mutex. * * @reg_base: Mapped address of MTK Vcodec registers. * -* @id_counter: used to identify current opened instance +* @id_counter: An integer id given to the next opened instance * @num_instances: counter of active MTK Vcodec instances * * @encode_workqueue: encode work queue * +* @v4l2_dev: V4L2 device to register video devices for. +* @vfd_dec: Video device for decoder +* @vfd_enc: Video device for encoder +* +* @m2m_dev_dec: m2m device for decoder +* @m2m_dev_enc: m2m device for encoder +* @plat_dev: platform device +* @vpu_plat_dev: mtk vpu platform device +* @alloc_ctx:VB2 allocator context +* (for allocations without kernel mapping). +* @ctx_list: list of struct mtk_vcodec_ctx +* @irqlock: protect data access by irq handler and work thread +* @curr_ctx: The context that is waiting for codec hardware +* @reg_base: Mapped address of MTK Vcodec registers. +* +* @instance_mask: used to mark which index id are used +* @num_instances: counter of active MTK Vcodec instances +* +* @decode_workqueue: decode work queue +* @encode_workqueue: encode work queue * @int_cond: used to identify interrupt condition happen * @int_type: used to identify what kind of interrupt condition happen * @dev_mutex: video_device lock * @queue: waitqueue for waiting for completion of device commands * +* @dec_irq: decoder irq resource * @enc_irq: h264 encoder irq resource -* @enc_lt_irq: vp8 encoder irq resource +* @enc_lt_irq: vp8 encoder lt irq resource * -* @enc_mutex: encoder hardware lock. +* @dec_mutex: decoder hardware lock +* @enc_mutex: encoder hardware lock * * @pm: power management control * @dec_capability: used to identify decode capability, ex: 4k @@ -294,8 +363,10 @@ struct mtk_vcodec_ctx {*/ struct mtk_vcodec_dev {struct v4l2_device v4l2_dev; +struct video_device *vfd_dec;struct video_device *vfd_enc; +struct v4l2_m2m_dev *m2m_dev_dec;struct v4l2_m2m_dev *m2m_dev_enc;struct platform_device *plat_dev;struct platform_device *vpu_plat_dev;@@ -308,6 +379,7 @@ struct mtk_vcodec_dev {unsigned long id_counter;int num_instances; +struct workqueue_struct *decode_workqueue;struct workqueue_struct *encode_workqueue;int int_cond;@@ -315,9 +387,11 @@ struct mtk_vcodec_dev {struct mutex dev_mutex;wait_queue_head_t queue; +int dec_irq;int enc_irq;int enc_lt_irq; +struct mutex dec_mutex;struct mutex enc_mutex;struct mtk_vcodec_pm pm;drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c +2
-2@@ -30,8 +30,7 @@ int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command, timeout_jiff =msecs_to_jiffies (timeout_ms); ret =wait_event_interruptible_timeout (*waitqueue, - (ctx->int_cond && - (ctx->int_type == command)), + ctx->int_cond, timeout_jiff);if (!ret) {@@ -52,3 +51,4 @@ int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command,return status; }EXPORT_SYMBOL (mtk_vcodec_wait_for_done_ctx); +drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h +1
-1@@ -16,7 +16,7 @@#define _MTK_VCODEC_INTR_H_#define MTK_INST_IRQ_RECEIVED 0x1 -#define MTK_INST_WORK_THREAD_ABORT_DONE 0x2 +struct mtk_vcodec_ctx ;drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +26
-5@@ -81,14 +81,35 @@ void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,return ; } -dma_free_coherent (dev, size, mem->va, mem->dma_addr); - mem->va =NULL ; - mem->dma_addr =0 ; - mem->size =0 ; -mtk_v4l2_debug (3 ,"[%d] - va = %p" , ctx->id, mem->va);mtk_v4l2_debug (3 ,"[%d] - dma = 0x%lx" , ctx->id, (unsigned long )mem->dma_addr);mtk_v4l2_debug (3 ,"[%d] size = 0x%lx" , ctx->id, size); + +dma_free_coherent (dev, size, mem->va, mem->dma_addr); + mem->va =NULL ; + mem->dma_addr =0 ; + mem->size =0 ; }EXPORT_SYMBOL (mtk_vcodec_mem_free); + +void mtk_vcodec_set_curr_ctx (struct mtk_vcodec_dev *dev, +struct mtk_vcodec_ctx *ctx) +{ +unsigned long flags; + +spin_lock_irqsave (&dev->irqlock, flags); + dev->curr_ctx = ctx; +spin_unlock_irqrestore (&dev->irqlock, flags); +} + +struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx (struct mtk_vcodec_dev *dev) +{ +unsigned long flags; +struct mtk_vcodec_ctx *ctx; + +spin_lock_irqsave (&dev->irqlock, flags); + ctx = dev->curr_ctx; +spin_unlock_irqrestore (&dev->irqlock, flags); +return ctx; +}drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +6
-1@@ -1,7 +1,7 @@/* * Copyright (c) 2016 MediaTek Inc. * Author: PC Chen <[email protected]> -* Tiffany Lin <[email protected]> +* Tiffany Lin <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -26,6 +26,7 @@ struct mtk_vcodec_mem { };struct mtk_vcodec_ctx ; +struct mtk_vcodec_dev ;extern int mtk_v4l2_dbg_level;extern bool mtk_vcodec_dbg;@@ -84,4 +85,8 @@ int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, struct mtk_vcodec_mem *mem);void mtk_vcodec_mem_free (struct mtk_vcodec_ctx *data,struct mtk_vcodec_mem *mem); +void mtk_vcodec_set_curr_ctx (struct mtk_vcodec_dev *dev, +struct mtk_vcodec_ctx *ctx); +struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx (struct mtk_vcodec_dev *dev); +#endif /* _MTK_VCODEC_UTIL_H_ */ drivers/media/platform/mtk-vcodec/vdec_drv_base.h new file +56
-0@@ -0,0 +1,56 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _VDEC_DRV_BASE_ +#define _VDEC_DRV_BASE_ + +#include "mtk_vcodec_drv.h" + +#include "vdec_drv_if.h" + +struct vdec_common_if { +/** +* (*init)() - initialize decode driver +* @ctx : [in] mtk v4l2 context +* @h_vdec : [out] driver handle +*/ +int (*init)(struct mtk_vcodec_ctx *ctx,unsigned long *h_vdec); + +/** +* (*decode)() - trigger decode +* @h_vdec : [in] driver handle +* @bs : [in] input bitstream +* @fb : [in] frame buffer to store decoded frame +* @res_chg : [out] resolution change happen +*/ +int (*decode)(unsigned long h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg); + +/** +* (*get_param)() - get driver's parameter +* @h_vdec : [in] driver handle +* @type : [in] input parameter type +* @out : [out] buffer to store query result +*/ +int (*get_param)(unsigned long h_vdec,enum vdec_get_param_type type, +void *out); + +/** +* (*deinit)() - deinitialize driver. +* @h_vdec : [in] driver handle to be deinit +*/ +void (*deinit)(unsigned long h_vdec); +}; + +#endif drivers/media/platform/mtk-vcodec/vdec_drv_if.c new file +107
-0@@ -0,0 +1,107 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/slab.h> + +#include "vdec_drv_base.h" +#include "vdec_drv_if.h" + +#include "mtk_vcodec_dec_pm.h" +#include "mtk_vcodec_util.h" +#include "mtk_vpu.h" + +int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc) +{ +int ret =0 ; + +switch (fourcc) { +case V4L2_PIX_FMT_H264 : +case V4L2_PIX_FMT_VP8 : +case V4L2_PIX_FMT_VP9 : +default : +return -EINVAL ; + } + +mtk_vdec_lock (ctx); +mtk_vcodec_dec_clock_on (&ctx->dev->pm); + ret = ctx->dec_if->init (ctx, &ctx->drv_handle); +mtk_vcodec_dec_clock_off (&ctx->dev->pm); +mtk_vdec_unlock (ctx); + +return ret; +} + +int vdec_if_decode (struct mtk_vcodec_ctx *ctx,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +int ret =0 ; + +if (bs) { +if ((bs->dma_addr &63 ) !=0 ) { +mtk_v4l2_err ("bs dma_addr should 64 byte align" ); +return -EINVAL ; + } + } + +if (fb) { +if (((fb->base_y.dma_addr &511 ) !=0 ) || + ((fb->base_c.dma_addr &511 ) !=0 )) { +mtk_v4l2_err ("frame buffer dma_addr should 512 byte align" ); +return -EINVAL ; + } + } + +mtk_vdec_lock (ctx); + +mtk_vcodec_set_curr_ctx (ctx->dev, ctx); +mtk_vcodec_dec_clock_on (&ctx->dev->pm); +enable_irq (ctx->dev->dec_irq); + ret = ctx->dec_if->decode (ctx->drv_handle, bs, fb, res_chg); +disable_irq (ctx->dev->dec_irq); +mtk_vcodec_dec_clock_off (&ctx->dev->pm); +mtk_vcodec_set_curr_ctx (ctx->dev,NULL ); + +mtk_vdec_unlock (ctx); + +return ret; +} + +int vdec_if_get_param (struct mtk_vcodec_ctx *ctx,enum vdec_get_param_type type, +void *out) +{ +int ret =0 ; + +mtk_vdec_lock (ctx); + ret = ctx->dec_if->get_param (ctx->drv_handle, type, out); +mtk_vdec_unlock (ctx); + +return ret; +} + +void vdec_if_deinit (struct mtk_vcodec_ctx *ctx) +{ +if (ctx->drv_handle ==0 ) +return ; + +mtk_vdec_lock (ctx); +mtk_vcodec_dec_clock_on (&ctx->dev->pm); + ctx->dec_if->deinit (ctx->drv_handle); +mtk_vcodec_dec_clock_off (&ctx->dev->pm); +mtk_vdec_unlock (ctx); + + ctx->drv_handle =0 ; +}drivers/media/platform/mtk-vcodec/vdec_drv_if.h new file +101
-0@@ -0,0 +1,101 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* Tiffany Lin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _VDEC_DRV_IF_H_ +#define _VDEC_DRV_IF_H_ + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_dec.h" +#include "mtk_vcodec_util.h" + + +/** +* struct vdec_fb_status - decoder frame buffer status +* @FB_ST_NORMAL : initial state +* @FB_ST_DISPLAY : frmae buffer is ready to be displayed +* @FB_ST_FREE : frame buffer is not used by decoder any more +*/ +enum vdec_fb_status { +FB_ST_NORMAL =0 , +FB_ST_DISPLAY = (1 <<0 ), +FB_ST_FREE = (1 <<1 ) +}; + +/* For GET_PARAM_DISP_FRAME_BUFFER and GET_PARAM_FREE_FRAME_BUFFER, +* the caller does not own the returned buffer. The buffer will not be +* released before vdec_if_deinit. +* GET_PARAM_DISP_FRAME_BUFFER : get next displayable frame buffer, +* struct vdec_fb** +* GET_PARAM_FREE_FRAME_BUFFER : get non-referenced framebuffer, vdec_fb** +* GET_PARAM_PIC_INFO : get picture info, struct vdec_pic_info* +* GET_PARAM_CROP_INFO : get crop info, struct v4l2_crop* +* GET_PARAM_DPB_SIZE : get dpb size, unsigned int* +*/ +enum vdec_get_param_type { +GET_PARAM_DISP_FRAME_BUFFER , +GET_PARAM_FREE_FRAME_BUFFER , +GET_PARAM_PIC_INFO , +GET_PARAM_CROP_INFO , +GET_PARAM_DPB_SIZE +}; + +/** +* struct vdec_fb_node - decoder frame buffer node +* @list : list to hold this node +* @fb : point to frame buffer (vdec_fb), fb could point to frame buffer and +* working buffer this is for maintain buffers in different state +*/ +struct vdec_fb_node { +struct list_head list; +struct vdec_fb *fb; +}; + +/** +* vdec_if_init() - initialize decode driver +* @ctx : [in] v4l2 context +* @fourcc : [in] video format fourcc, V4L2_PIX_FMT_H264/VP8/VP9.. +*/ +int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc); + +/** +* vdec_if_deinit() - deinitialize decode driver +* @ctx : [in] v4l2 context +* +*/ +void vdec_if_deinit (struct mtk_vcodec_ctx *ctx); + +/** +* vdec_if_decode() - trigger decode +* @ctx : [in] v4l2 context +* @bs : [in] input bitstream +* @fb : [in] frame buffer to store decoded frame, when null menas parse +* header only +* @res_chg : [out] resolution change happens if current bs have different +* picture width/height +* Note: To flush the decoder when reaching EOF, set input bitstream as NULL. +*/ +int vdec_if_decode (struct mtk_vcodec_ctx *ctx,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg); + +/** +* vdec_if_get_param() - get driver's parameter +* @ctx : [in] v4l2 context +* @type : [in] input parameter type +* @out : [out] buffer to store query result +*/ +int vdec_if_get_param (struct mtk_vcodec_ctx *ctx,enum vdec_get_param_type type, +void *out); + +#endif drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h new file +93
-0@@ -0,0 +1,103 @@ +/* +* Copyright (c) 2016 MediaTek Inc. +* Author: PC Chen <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _VDEC_IPI_MSG_H_ +#define _VDEC_IPI_MSG_H_ + +/** +* enum vdec_ipi_msgid - message id between AP and VPU +* @AP_IPIMSG_XXX : AP to VPU cmd message id +* @VPU_IPIMSG_XXX_ACK : VPU ack AP cmd message id +*/ +enum vdec_ipi_msgid { +AP_IPIMSG_DEC_INIT =0xA000 , +AP_IPIMSG_DEC_START =0xA001 , +AP_IPIMSG_DEC_END =0xA002 , +AP_IPIMSG_DEC_DEINIT =0xA003 , +AP_IPIMSG_DEC_RESET =0xA004 , + +VPU_IPIMSG_DEC_INIT_ACK =0xB000 , +VPU_IPIMSG_DEC_START_ACK =0xB001 , +VPU_IPIMSG_DEC_END_ACK =0xB002 , +VPU_IPIMSG_DEC_DEINIT_ACK =0xB003 , +VPU_IPIMSG_DEC_RESET_ACK =0xB004 , +}; + +/** +* struct vdec_ap_ipi_cmd - generic AP to VPU ipi command format +* @msg_id : vdec_ipi_msgid +* @vpu_inst_addr : VPU decoder instance address +*/ +struct vdec_ap_ipi_cmd { +uint32_t msg_id; +uint32_t vpu_inst_addr; +}; + +/** +* struct vdec_vpu_ipi_ack - generic VPU to AP ipi command format +* @msg_id : vdec_ipi_msgid +* @status : VPU exeuction result +* @ap_inst_addr : AP video decoder instance address +*/ +struct vdec_vpu_ipi_ack { +uint32_t msg_id; +int32_t status; +uint64_t ap_inst_addr; +}; + +/** +* struct vdec_ap_ipi_init - for AP_IPIMSG_DEC_INIT +* @msg_id : AP_IPIMSG_DEC_INIT +* @reserved : Reserved field +* @ap_inst_addr : AP video decoder instance address +*/ +struct vdec_ap_ipi_init { +uint32_t msg_id; +uint32_t reserved; +uint64_t ap_inst_addr; +}; + +/** +* struct vdec_ap_ipi_dec_start - for AP_IPIMSG_DEC_START +* @msg_id : AP_IPIMSG_DEC_START +* @vpu_inst_addr : VPU decoder instance address +* @data : Header info +* H264 decoder [0]:buf_sz [1]:nal_start +* VP8 decoder [0]:width/height +* VP9 decoder [0]:profile, [1][2] width/height +* @reserved : Reserved field +*/ +struct vdec_ap_ipi_dec_start { +uint32_t msg_id; +uint32_t vpu_inst_addr; +uint32_t data[3 ]; +uint32_t reserved; +}; + +/** +* struct vdec_vpu_ipi_init_ack - for VPU_IPIMSG_DEC_INIT_ACK +* @msg_id : VPU_IPIMSG_DEC_INIT_ACK +* @status : VPU exeuction result +* @ap_inst_addr : AP vcodec_vpu_inst instance address drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h line 103
Quoted 10 lines
drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h new file +10
-0+* @vpu_inst_addr : VPU decoder instance address +*/ +struct vdec_vpu_ipi_init_ack { +uint32_t msg_id; +int32_t status; +uint64_t ap_inst_addr; +uint32_t vpu_inst_addr; +}; + +#endif Regards,
Hans
Re: [PATCH v3 5/9] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
Hi Tiffany,
Quoted 1 line · Tiffany Lin
Hi Hans,
<snip>
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+static int vidioc_vdec_g_selection (struct file *file,void *priv, +struct v4l2_selection *s) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 632
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+if (V4L2_TYPE_IS_OUTPUT (s->type)) +return -EINVAL ; + +if (s->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ;How does the cropping rectangle relate to the format size? There is no
s_selection, so this doesn't make sense.
Quoted 2 lines
I want to return encoded crop information or real display region that display driver could know where is padding region.
Sorry, I don't understand this.
This is a decoder, so based on the bitstream it decodes to a certain width and height. I assume that is what you refer to as coded_width and coded_height?
If so, then what is the 'real display region' and how does it relate to the coded width/height?
This is probably a terminology issue but I need to understand this before I can decide what should be done here.
Regards,
Hans
Quoted 43 lines
User space use s_fmt/g_fmt to set/get
coded_widthandcoded_height, and useg_cropto get real display region.
That's why I do not adds_selection.Quoted 2 lines
Alternatively, it could be that you are really returning
V4L2_SEL_TGT_COMPOSE_PADDED.
V4L2_SEL_TGT_COMPOSE_PADDEDmeans
"The active area and all padding pixels that are inserted or modified by hardware."
But I just want to return active area to user space.Quoted 31 lines
Quoted 31 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +31
-0+ +if (ctx->state <MTK_STATE_HEADER ) +return -EINVAL ; + +if ((ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_H264 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP8 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP9 )) { + +if (vdec_if_get_param (ctx,GET_PARAM_CROP_INFO , &(s->r))) { +mtk_v4l2_debug (2 , +"[%d]Error!! Cannot get param : GET_PARAM_CROP_INFO ERR" , + ctx->id); + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.buf_w; + s->r.height = ctx->picinfo.buf_h; + } +mtk_v4l2_debug (2 ,"Cropping info: l=%d t=%d w=%d h=%d" , + s->r.left, s->r.top, s->r.width, + s->r.height); + }else { + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.pic_w; + s->r.height = ctx->picinfo.pic_h; +mtk_v4l2_debug (2 ,"Cropping info: w=%d h=%d fw=%d fh=%d" , + s->r.width, s->r.height, ctx->picinfo.buf_w, + ctx->picinfo.buf_h); + } +return 0 ; +}
Re: [PATCH v3 5/9] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
Hi Hans,
Quoted 26 lines · Hans Verkuil
Hi Tiffany,
Quoted 1 line · Tiffany Lin
Hi Hans,
<snip>
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+static int vidioc_vdec_g_selection (struct file *file,void *priv, +struct v4l2_selection *s) +{ +struct mtk_vcodec_ctx *ctx =fh_to_ctx (priv); +Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c line 632
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +5
-0+if (V4L2_TYPE_IS_OUTPUT (s->type)) +return -EINVAL ; + +if (s->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ;How does the cropping rectangle relate to the format size? There is no
s_selection, so this doesn't make sense.Quoted 2 lines
I want to return encoded crop information or real display region that display driver could know where is padding region.
Sorry, I don't understand this.
Quoted 9 lines
This is a decoder, so based on the bitstream it decodes to a certain width and height. I assume that is what you refer to as
coded_widthandcoded_height?If so, then what is the 'real display region' and how does it relate to the coded width/height?
This is probably a terminology issue but I need to understand this before I can decide what should be done here.
We define coded_width and coded_height as frame buffer width and height. Coded resolution is stream resolution in pixels aligned to codec format and hardware requirements.
And we assign bytesperline as coded_width.
g_selection is for getting visible resolution for user space. visible resolution - stream resolution of the visible picture, in pixels, to be used for display purposes; must be smaller or equal to coded resolution;
visible height - height for given visible resolution visible width - width for given visible resolution
For my understand, g_fmt should return coded width/height in pix_mp->width, pix_mp->height.
And bytesperline is coded with.g_selection return visible width/height.
Is this understanding correct?
best regards,
Tiffany
Quoted 47 lines
Regards,
Hans
Quoted 43 lines
User space use s_fmt/g_fmt to set/get
coded_widthandcoded_height, and useg_cropto get real display region.
That's why I do not adds_selection.Quoted 2 lines
Alternatively, it could be that you are really returning
V4L2_SEL_TGT_COMPOSE_PADDED.
V4L2_SEL_TGT_COMPOSE_PADDEDmeans
"The active area and all padding pixels that are inserted or modified by hardware."
But I just want to return active area to user space.Quoted 31 lines
Quoted 31 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c new file +31
-0+ +if (ctx->state <MTK_STATE_HEADER ) +return -EINVAL ; + +if ((ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_H264 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP8 ) || + (ctx->q_data[MTK_Q_DATA_SRC ].fmt->fourcc ==V4L2_PIX_FMT_VP9 )) { + +if (vdec_if_get_param (ctx,GET_PARAM_CROP_INFO , &(s->r))) { +mtk_v4l2_debug (2 , +"[%d]Error!! Cannot get param : GET_PARAM_CROP_INFO ERR" , + ctx->id); + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.buf_w; + s->r.height = ctx->picinfo.buf_h; + } +mtk_v4l2_debug (2 ,"Cropping info: l=%d t=%d w=%d h=%d" , + s->r.left, s->r.top, s->r.width, + s->r.height); + }else { + s->r.left =0 ; + s->r.top =0 ; + s->r.width = ctx->picinfo.pic_w; + s->r.height = ctx->picinfo.pic_h; +mtk_v4l2_debug (2 ,"Cropping info: w=%d h=%d fw=%d fh=%d" , + s->r.width, s->r.height, ctx->picinfo.buf_w, + ctx->picinfo.buf_h); + } +return 0 ; +}
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
In reply to Tiffany LinQuoted 12 lines · Tiffany Lin
Add
V4L2_PIX_FMT_MT21documentationSigned-off-by Tiffany Lin <[email protected]>--- Documentation/DocBook/media/v4l/pixfmt.xml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/DocBook/media/v4l/pixfmt.xml +0
-0
Documentation/DocBook/media/v4l/pixfmt.xml array. Anything what's in between the UYVY lines is JPEG data and should be · line 1987
Quoted 8 lines
Documentation/DocBook/media/v4l/pixfmt.xml +5
-0@@ -1980,6 +1980,12 @@ array. Anything what's in between the UYVY lines is JPEG data and should be concatenated to form the JPEG stream. </para> </entry> </row> + <row id="V4L2_PIX_FMT_MT21"> + <entry><constant>V4L2_PIX_FMT_MT21</constant></entry> + <entry>'MT21'</entry> + <entry>Compressed two-planar YVU420 format used by Mediatek MT8173 + codec driver.</entry>
Can you give a few more details? The encoder driver doesn't seem to produce this format, so who is creating this? Where is this format documented?
Regards,
Hans
Quoted 5 lines
Documentation/DocBook/media/v4l/pixfmt.xml +1
-0+ </row> </tbody> </tgroup> </table>
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Hi Hans,
Quoted 8 lines · Hans Verkuil
Quoted 7 lines · Tiffany Lin
Add
V4L2_PIX_FMT_MT21documentationSigned-off-by Tiffany Lin <[email protected]>--- Documentation/DocBook/media/v4l/pixfmt.xml | 6 ++++++ 1 file changed, 6 insertions(+)
Quoted 17 lines
Documentation/DocBook/media/v4l/pixfmt.xml array. Anything what's in between the UYVY lines is JPEG data and should be · line 1987
Quoted 13 lines
Documentation/DocBook/media/v4l/pixfmt.xml +5
-0@@ -1980,6 +1980,12 @@ array. Anything what's in between the UYVY lines is JPEG data and should be concatenated to form the JPEG stream. </para> </entry> </row> + <row id="V4L2_PIX_FMT_MT21"> + <entry><constant>V4L2_PIX_FMT_MT21</constant></entry> + <entry>'MT21'</entry> + <entry>Compressed two-planar YVU420 format used by Mediatek MT8173 + codec driver.</entry>Can you give a few more details? The encoder driver doesn't seem to produce this format, so who is creating this? Where is this format documented?
It can be as input format for encoder, MDP and display drivers in our platform.
This private format is only available in our platform.
So I put it in "Reserved Format Identifiers" sections.
best regards,
Tiffany
Quoted 9 lines
Regards,
Hans
Quoted 5 lines
Documentation/DocBook/media/v4l/pixfmt.xml +1
-0+ </row> </tbody> </tgroup> </table>
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Quoted 27 lines · tiffany lin
Hi Hans,
Quoted 24 lines · Hans Verkuil
Quoted 12 lines · Tiffany Lin
Add
V4L2_PIX_FMT_MT21documentationSigned-off-by Tiffany Lin <[email protected]>--- Documentation/DocBook/media/v4l/pixfmt.xml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/DocBook/media/v4l/pixfmt.xml +0
-0Documentation/DocBook/media/v4l/pixfmt.xml array. Anything what's in between the UYVY lines is JPEG data and should be · line 1987
Quoted 8 lines
Documentation/DocBook/media/v4l/pixfmt.xml +5
-0@@ -1980,6 +1980,12 @@ array. Anything what's in between the UYVY lines is JPEG data and should be concatenated to form the JPEG stream. </para> </entry> </row> + <row id="V4L2_PIX_FMT_MT21"> + <entry><constant>V4L2_PIX_FMT_MT21</constant></entry> + <entry>'MT21'</entry> + <entry>Compressed two-planar YVU420 format used by Mediatek MT8173 + codec driver.</entry>Can you give a few more details? The encoder driver doesn't seem to produce this format, so who is creating this? Where is this format documented?
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany. When do you plan to upstream image processor (mtk-mdp)?
Quoted 3 lines
It can be as input format for encoder, MDP and display drivers in our platform.
I remember display driver can only accept uncompressed MT21. Right? Basically V4L2_PIX_FMT_MT21 is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image processor.
Quoted 22 lines
This private format is only available in our platform. So I put it in "Reserved Format Identifiers" sections.
best regards,
TiffanyQuoted 9 lines
Regards,
Hans
Quoted 5 lines
Documentation/DocBook/media/v4l/pixfmt.xml +1
-0+ </row> </tbody> </tgroup> </table>--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit?:
Quoted 4 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany. When do you plan to upstream image processor (mtk-mdp)?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
It can be as input format for encoder, MDP and display drivers in
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image
processor.
Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea what this pixel format really is. Is that right ?
The main reason why I keep asking, is that we often find similarities between what vendor like to call their proprietary formats. Doing the proper research helps not creating a mess like in Android where you have a lot of formats that all point to the same format. I believe there was the same concern when Samsung wanted to introduce their Z- flip-Z NV12 tile format. In the end they simply provided sufficient documentation so we could document it and implement software converters for test and validation purpose.
regards,
Nicolas
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Le mardi 12 juillet 2016 ? 15:08 -0400, Nicolas Dufresne a ?crit?:
Quoted 19 lines
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit?:
Quoted 5 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany.
When do you plan to upstream image processor (mtk-mdp)?Quoted 1 line
Quoted 8 lines
Quoted 1 line
It can be as input format for encoder, MDP and display drivers in
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image
processor.Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea what this pixel format really is. Is that right ?
Quoted 9 lines
The main reason why I keep asking, is that we often find similarities between what vendor like to call their proprietary formats. Doing the proper research helps not creating a mess like in Android where you have a lot of formats that all point to the same format. I believe there was the same concern when Samsung wanted to introduce their Z- flip-Z NV12 tile format. In the end they simply provided sufficient documentation so we could document it and implement software converters
for test and validation purpose.
Here's the kind of information we want in the documentation.
https://chromium.googlesource.com/chromium/src/media/+/master/base/vide
o_types.h#40
? // MediaTek proprietary format. MT21 is similar to NV21 except the memory ? // layout and pixel layout (swizzles). 12bpp with Y plane followed by a 2x2 ? // interleaved VU plane. Each image contains two buffers -- Y plane and VU ? // plane. Two planes can be non-contiguous in memory. The starting addresses ? // of Y plane and VU plane are 4KB alignment.
? // Suppose image dimension is (width, height). For both Y plane and VU plane:
? // Row pitch = ((width+15)/16) * 16.
? // Plane size = Row pitch * (((height+31)/32)*32)
Now obviously this is incomplete, as the swizzling need to be documented of course.
Quoted 3 lines
regards,
Nicolas
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Quoted 41 lines · Nicolas Dufresne
Le mardi 12 juillet 2016 ? 15:08 -0400, Nicolas Dufresne a ?crit :
Quoted 17 lines
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit :
Quoted 4 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany.
When do you plan to upstream image processor (mtk-mdp)?Quoted 8 lines
Quoted 1 line
It can be as input format for encoder, MDP and display drivers in
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image
processor.Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea what this pixel format really is. Is that right ?
Quoted 9 lines
The main reason why I keep asking, is that we often find similarities between what vendor like to call their proprietary formats. Doing the proper research helps not creating a mess like in Android where you have a lot of formats that all point to the same format. I believe there was the same concern when Samsung wanted to introduce their Z- flip-Z NV12 tile format. In the end they simply provided sufficient documentation so we could document it and implement software converters
for test and validation purpose.Here's the kind of information we want in the documentation.
https://chromium.googlesource.com/chromium/src/media/+/master/base/vide
o_types.h#40// MediaTek proprietary format. MT21 is similar to NV21 except the memory // layout and pixel layout (swizzles). 12bpp with Y plane followed by a 2x2 // interleaved VU plane. Each image contains two buffers -- Y plane and VU // plane. Two planes can be non-contiguous in memory. The starting addresses // of Y plane and VU plane are 4KB alignment. // Suppose image dimension is (width, height). For both Y plane and VU plane: // Row pitch = ((width+15)/16) * 16. // Plane size = Row pitch * (((height+31)/32)*32)
Quoted 1 line
Now obviously this is incomplete, as the swizzling need to be documented of course.
Not sure where that chromium comment came from, but if MT21 really is similar to NV21 (a 4:2:0 format) and has 2x2 downsampled chroma, then the combined VU plane will be half the size of the Y plane.
Maybe that's not relevant to this discussion.
Regards,
Ian
Quoted 7 lines
Quoted 3 lines
regards,
Nicolas--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
In reply to Nicolas DufresneHi Nicolas,
Quoted 44 lines · Nicolas Dufresne
Le mardi 12 juillet 2016 ? 15:08 -0400, Nicolas Dufresne a ?crit :
Quoted 19 lines
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit :
Quoted 5 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany.
When do you plan to upstream image processor (mtk-mdp)?Quoted 1 line
Quoted 8 lines
Quoted 1 line
It can be as input format for encoder, MDP and display drivers in
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image
processor.Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea what this pixel format really is. Is that right ?
Quoted 9 lines
The main reason why I keep asking, is that we often find similarities between what vendor like to call their proprietary formats. Doing the proper research helps not creating a mess like in Android where you have a lot of formats that all point to the same format. I believe there was the same concern when Samsung wanted to introduce their Z- flip-Z NV12 tile format. In the end they simply provided sufficient documentation so we could document it and implement software converters
for test and validation purpose.Here's the kind of information we want in the documentation.
https://chromium.googlesource.com/chromium/src/media/+/master/base/vide
o_types.h#40// MediaTek proprietary format. MT21 is similar to NV21 except the memory // layout and pixel layout (swizzles). 12bpp with Y plane followed by a 2x2 // interleaved VU plane. Each image contains two buffers -- Y plane and VU // plane. Two planes can be non-contiguous in memory. The starting addresses // of Y plane and VU plane are 4KB alignment.
// Suppose image dimension is (width, height). For both Y plane and VU plane:
// Row pitch = ((width+15)/16) * 16.
// Plane size = Row pitch * (((height+31)/32)*32)
Quoted 2 lines
Now obviously this is incomplete, as the swizzling need to be documented of course.
Because it's finally a compressed format from our codec hw, we cannot describe its swizzling.
best regards,
Tiffany
Quoted 3 lines
Quoted 3 lines
regards,
Nicolas
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Le mercredi 13 juillet 2016 ? 10:00 +0800, tiffany lin a ?crit?:
Quoted 62 lines
Hi Nicolas,
Quoted 2 lines · Nicolas Dufresne
Le mardi 12 juillet 2016 ? 15:08 -0400, Nicolas Dufresne a ?crit :
Quoted 1 line
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit
:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Decoder hardware produces MT21 (compressed). Image processor
can
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
convert it to a format that can be input of display driver. Tiffany.
When do you plan to upstream image processor (mtk-mdp)?Quoted 2 lines
?
It can be as input format for encoder, MDP and displaydrivers in
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21.
Right?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and convertedby
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
image
processor.?
Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no ideawhat
Quoted 3 lines
Quoted 3 lines
this pixel format really is. Is that right ?
?
The main reason why I keep asking, is that we often findsimilarities
Quoted 1 line
Quoted 1 line
between what vendor like to call their proprietary formats. Doing
the
Quoted 1 line
Quoted 1 line
proper research helps not creating a mess like in Android where
you
Quoted 1 line
Quoted 1 line
have a lot of formats that all point to the same format. I
believe
Quoted 1 line
Quoted 1 line
there was the same concern when Samsung wanted to introduce their
Z-
Quoted 1 line
Quoted 1 line
flip-Z NV12 tile format. In the end they simply provided
sufficient
Quoted 7 lines
Quoted 3 lines
documentation so we could document it and implement software converters
for test and validation purpose.?
Here's the kind of information we want in the documentation. ?
https://chromium.googlesource.com/chromium/src/media/+/master/base/vide
Quoted 3 lines
o_types.h#40
?
?? // MediaTek proprietary format. MT21 is similar to NV21 exceptthe memory
Quoted 1 line
?? // layout and pixel layout (swizzles). 12bpp with Y plane
followed by a 2x2
Quoted 1 line
?? // interleaved VU plane. Each image contains two buffers -- Y
plane and VU
Quoted 1 line
?? // plane. Two planes can be non-contiguous in memory. The
starting addresses
Quoted 2 lines
?? // of Y plane and VU plane are 4KB alignment.
?? // Suppose image dimension is (width, height). For both Y planeand VU plane:
Quoted 8 lines
Quoted 4 lines
?? // Row pitch = ((width+15)/16) * 16.
?? // Plane size = Row pitch * (((height+31)/32)*32) ?
Now obviously this is incomplete, as the swizzling need to bedocumented of course.
Quoted 1 line
?
Because it's finally a compressed format from our codec hw, we cannot describe its swizzling.
Can you clarify why it cannot be described ? I don't buy any argument that it's impossible to convert without hardware. Intel did document their compressed formats.
Debugging an integration with such format that we have literally decided to no make public is a pain. A lot of decoder got abandoned or never used because of that.
It would be nice to explain the architecture you are suggesting to make this decoder useful. How will userspace application be able to use your decoder. Will the image processor usable outside the display path ? People might want to do transcoding, or other relatively common task that does not imply a display.
regards,
Nicolas
p.s.
A small note to Wu-Cheng, the definition of the DRM format in your Chromium branch is not correct. DRM uses format modifier, such that the format is the family, in your case it's most likely NV21, and the modifier is the compression or tiling algorithm in place (or both as needed).
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
Hi Nicolas,
Quoted 67 lines · Nicolas Dufresne
Le mercredi 13 juillet 2016 ? 10:00 +0800, tiffany lin a ?crit :
Quoted 66 lines
Hi Nicolas,
Quoted 2 lines · Nicolas Dufresne
Le mardi 12 juillet 2016 ? 15:08 -0400, Nicolas Dufresne a ?crit :
Quoted 1 line
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit
:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Decoder hardware produces MT21 (compressed). Image processor
can
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
convert it to a format that can be input of display driver. Tiffany.
When do you plan to upstream image processor (mtk-mdp)?Quoted 2 lines
It can be as input format for encoder, MDP and display
drivers in
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21.
Right?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and convertedby
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
image
processor.Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea
what
Quoted 3 lines
Quoted 3 lines
this pixel format really is. Is that right ?
The main reason why I keep asking, is that we often find
similarities
Quoted 1 line
Quoted 1 line
between what vendor like to call their proprietary formats. Doing
the
Quoted 1 line
Quoted 1 line
proper research helps not creating a mess like in Android where
you
Quoted 1 line
Quoted 1 line
have a lot of formats that all point to the same format. I
believe
Quoted 1 line
Quoted 1 line
there was the same concern when Samsung wanted to introduce their
Z-
Quoted 1 line
Quoted 1 line
flip-Z NV12 tile format. In the end they simply provided
sufficient
Quoted 7 lines
Quoted 3 lines
documentation so we could document it and implement software converters
for test and validation purpose.Here's the kind of information we want in the documentation.
https://chromium.googlesource.com/chromium/src/media/+/master/base/
vide
Quoted 3 lines
o_types.h#40
// MediaTek proprietary format. MT21 is similar to NV21 except
the memory
Quoted 1 line
// layout and pixel layout (swizzles). 12bpp with Y plane
followed by a 2x2
Quoted 1 line
// interleaved VU plane. Each image contains two buffers -- Y
plane and VU
Quoted 1 line
// plane. Two planes can be non-contiguous in memory. The
starting addresses
Quoted 2 lines
// of Y plane and VU plane are 4KB alignment.
// Suppose image dimension is (width, height). For both Y planeand VU plane:
Quoted 4 lines
// Row pitch = ((width+15)/16) * 16.
// Plane size = Row pitch * (((height+31)/32)*32)Now obviously this is incomplete, as the swizzling need to be
Quoted 9 lines
Quoted 4 lines
documented of course.
Quoted 1 line
Because it's finally a compressed format from our codec hw, we cannot describe its swizzling.
Can you clarify why it cannot be described ? I don't buy any argument that it's impossible to convert without hardware. Intel did document their compressed formats.
What's the Intel compressed formats? Could you provide link so we could reference how they provide this information.
Quoted 10 lines
Debugging an integration with such format that we have literally decided to no make public is a pain. A lot of decoder got abandoned or never used because of that.
It would be nice to explain the architecture you are suggesting to make this decoder useful. How will userspace application be able to use your decoder. Will the image processor usable outside the display path ? People might want to do transcoding, or other relatively common task that does not imply a display.
In MT8173 platform, it has MDP driver, it could convert V4L2_PIX_FMT_MT21 to V4L2_PIX_FMT_NV12M or V4L2_PIX_FMT_YUV420M.
MDP is stand alone driver, it is usable outside the display path.
NV12M/YUV420M/MT21 -> MDP -> NV12M/YUV420M
NV12M/NV21M/YUV420M/YVU420M -> mt8173 Encoder -> H264/VP8
H264/VP8/VP9 -> mtk8173 Decoder -> MT21
When encode with MT21 source, the pipeline will be:
MT21 -> MDP driver-> NV12M/NV21M/YUV420M/YVU420M -> Encoder -> H264/VP8
When playback, the pipeline will be:
H264/VP8/VP9 -> Decoder driver -> MT21 -> MDP Driver -> DRM
best regards,
Tiffany
Quoted 9 lines
regards,
Nicolasp.s.
A small note to Wu-Cheng, the definition of the DRM format in your Chromium branch is not correct. DRM uses format modifier, such that the format is the family, in your case it's most likely NV21, and the modifier is the compression or tiling algorithm in place (or both as needed).
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
In reply to Nicolas DufresneQuoted 30 lines · Nicolas Dufresne
Le mardi 12 juillet 2016 ? 15:08 -0400, Nicolas Dufresne a ?crit :
Quoted 19 lines
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit :
Quoted 5 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany.
When do you plan to upstream image processor (mtk-mdp)?Quoted 1 line
Quoted 8 lines
Quoted 1 line
It can be as input format for encoder, MDP and display drivers in
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image
processor.Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea what this pixel format really is. Is that right ?
Quoted 9 lines
The main reason why I keep asking, is that we often find similarities between what vendor like to call their proprietary formats. Doing the proper research helps not creating a mess like in Android where you have a lot of formats that all point to the same format. I believe there was the same concern when Samsung wanted to introduce their Z- flip-Z NV12 tile format. In the end they simply provided sufficient documentation so we could document it and implement software converters
for test and validation purpose.
Quoted 4 lines
Here's the kind of information we want in the documentation.
https://chromium.googlesource.com/chromium/src/media/+/master/base/vide
o_types.h#40
That is the documentation of decompressed MT21. Originally MT21 was meant to be a YUV format and we can map it in CPU to use it. The name was changed to mean a compressed format. The current design is only MTK image processor can convert it. Software cannot decompress it. I'm not sure if we should document
the format inside if we cannot decompress in software. For chromium, I'll update the code to explain MT21 is an opaque compressed format.
Quoted 15 lines
// MediaTek proprietary format. MT21 is similar to NV21 except the memory // layout and pixel layout (swizzles). 12bpp with Y plane followed by a 2x2 // interleaved VU plane. Each image contains two buffers -- Y plane and VU // plane. Two planes can be non-contiguous in memory. The starting addresses // of Y plane and VU plane are 4KB alignment.
// Suppose image dimension is (width, height). For both Y plane and VU plane:
// Row pitch = ((width+15)/16) * 16.
// Plane size = Row pitch * (((height+31)/32)*32)Now obviously this is incomplete, as the swizzling need to be documented of course.
Quoted 3 lines
regards,
Nicolas
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
In reply to Nicolas DufresneHi Nicolas,
Quoted 14 lines · Nicolas Dufresne
Le mardi 12 juillet 2016 ? 16:16 +0800, Wu-Cheng Li (???) a ?crit :
Quoted 4 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany. When do you plan to upstream image processor (mtk-mdp)?
Quoted 1 line
Quoted 8 lines
Quoted 1 line
It can be as input format for encoder, MDP and display drivers in
our
Quoted 1 line
platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image
processor.
Quoted 4 lines
Previously it was described as MediaTek block mode, and now as a MediaTek compressed format. It makes me think you have no idea what this pixel format really is. Is that right ?
That's not right.
Its a compressed format as I document in "[PATCH v3 3/9] DocBook/v4l:
Add compressed video formats used on MT8173 codec driver." In MT8173 platform, when using this format, we need Image Processor to cover it to standard format as wucheng mentioned.
To prevent this ambiguous, I will change it to V4L2_PIX_FMT_M21C, it means its compressed data. Is it ok?
best regards,
Tiffany
Quoted 11 lines
The main reason why I keep asking, is that we often find similarities between what vendor like to call their proprietary formats. Doing the proper research helps not creating a mess like in Android where you have a lot of formats that all point to the same format. I believe there was the same concern when Samsung wanted to introduce their Z- flip-Z NV12 tile format. In the end they simply provided sufficient documentation so we could document it and implement software converters for test and validation purpose.
regards,
Nicolas
Re: [PATCH v3 3/9] DocBook/v4l: Add compressed video formats used on MT8173 codec driver
In reply to Wu-Cheng Li (李務誠)Quoted 28 lines · Wu-Cheng Li (???)
Quoted 27 lines · tiffany lin
Hi Hans,
Quoted 24 lines · Hans Verkuil
Quoted 12 lines · Tiffany Lin
Add
V4L2_PIX_FMT_MT21documentationSigned-off-by Tiffany Lin <[email protected]>--- Documentation/DocBook/media/v4l/pixfmt.xml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/DocBook/media/v4l/pixfmt.xml +0
-0Documentation/DocBook/media/v4l/pixfmt.xml array. Anything what's in between the UYVY lines is JPEG data and should be · line 1987
Quoted 8 lines
Documentation/DocBook/media/v4l/pixfmt.xml +5
-0@@ -1980,6 +1980,12 @@ array. Anything what's in between the UYVY lines is JPEG data and should be concatenated to form the JPEG stream. </para> </entry> </row> + <row id="V4L2_PIX_FMT_MT21"> + <entry><constant>V4L2_PIX_FMT_MT21</constant></entry> + <entry>'MT21'</entry> + <entry>Compressed two-planar YVU420 format used by Mediatek MT8173 + codec driver.</entry>Can you give a few more details? The encoder driver doesn't seem to produce this format, so who is creating this? Where is this format documented?
Quoted 4 lines
Decoder hardware produces MT21 (compressed). Image processor can convert it to a format that can be input of display driver. Tiffany. When do you plan to upstream image processor (mtk-mdp)?
Quoted 1 line
We are working on this. Will upstream soon.
Quoted 6 lines
Quoted 2 lines
It can be as input format for encoder, MDP and display drivers in our platform.
I remember display driver can only accept uncompressed MT21. Right? Basically
V4L2_PIX_FMT_MT21is compressed and is like an opaque format. It's not usable until it's decompressed and converted by image processor.
That's right in MT8173 platform.
best regards,
Tiffany
Quoted 22 lines
Quoted 22 lines
This private format is only available in our platform. So I put it in "Reserved Format Identifiers" sections.
best regards,
TiffanyQuoted 9 lines
Regards,
Hans
Quoted 5 lines
Documentation/DocBook/media/v4l/pixfmt.xml +1
-0+ </row> </tbody> </tgroup> </table>--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:
Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.
Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Regards,
Mauro
Quoted 22 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Quoted 6 lines
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Mauro, are you confusing the decoder and encoder driver? I haven't thoroughly reviewed the decoder driver yet, so there is no pull request for the decoder driver.
The only pull request I made was for the encoder driver.
Regards,
Hans
Quoted 30 lines · Hans Verkuil
Quoted 27 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 23 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs.
Mediatek Video Codec is able to handle video decoding of in a range of formats.This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1]
and patch "CHROMIUM: v4l: AddV4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/
Tiffany. Can you check the license and add the firmware to linux-firmware?
For the information, both encoder and decoder drivers require the firmware to work.
Quoted 19 lines
Quoted 3 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Mauro, are you confusing the decoder and encoder driver? I haven't thoroughly reviewed the decoder driver
yet, so there is no pull request for the decoder driver.The only pull request I made was for the encoder driver.
Regards,
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Mauro,
Quoted 24 lines · Hans Verkuil
Quoted 22 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 18 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Quoted 7 lines
Quoted 6 lines
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?
In
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/README, it mentions that "To submit firmware to this repository, please send either a git binary
diff or preferably a git pull request to: linux-firmware at kernel.org and
also cc: to related mailing lists."
How we made a git pull request to linux-firmware at kernel.org? How we find out related mailing lists?
best regards,
Tiffany
Quoted 8 lines
Mauro, are you confusing the decoder and encoder driver? I haven't thoroughly reviewed the decoder driver yet, so there is no pull request for the decoder driver.
The only pull request I made was for the encoder driver.
Regards,
Hans
Em Tue, 14 Jun 2016 19:08:08 +0800
tiffany lin <[email protected]> escreveu:
Quoted 32 lines
Hi Mauro,
Quoted 28 lines · Hans Verkuil
Quoted 26 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?
Please look at this page:
https://linuxtv.org/wiki/index.php/Development:_How_to_submit_patches#Firmware_submission
The information here can also be useful:
https://www.kernel.org/doc/readme/firmware-README.AddingFirmware
In summary, you need to provide redistribution rights for the firmware blob. You can either submit it to me or directly to linux-firmware. In the latter, please c/c me on such patch.
Thanks!
Mauro
Quoted 23 lines
In
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/README, it mentions that "To submit firmware to this repository, please send either a git binary
diff or preferably a git pull request to: linux-firmware at kernel.org and
also cc: to related mailing lists."How we made a git pull request to linux-firmware at kernel.org? How we find out related mailing lists?
best regards,
TiffanyQuoted 8 lines
Mauro, are you confusing the decoder and encoder driver? I haven't thoroughly reviewed the decoder driver yet, so there is no pull request for the decoder driver.
The only pull request I made was for the encoder driver.
Regards,
Hans
Signature · 2 lines
Thanks, Mauro
Quoted 45 lines · Mauro Carvalho Chehab
Em Tue, 14 Jun 2016 19:08:08 +0800
tiffany lin <[email protected]> escreveu:Quoted 32 lines
Hi Mauro,
Quoted 28 lines · Hans Verkuil
Quoted 26 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?Please look at this page:
https://linuxtv.org/wiki/index.php/Development:_How_to_submit_patches#Firmware_submission
Quoted 6 lines
The information here can also be useful:
https://www.kernel.org/doc/readme/firmware-README.AddingFirmwareIn summary, you need to provide redistribution rights for the firmware blob. You can either submit it to me or directly to linux-firmware. In the latter, please c/c me on such patch.
Tiffany, what is the status of the firmware submission?
Regards,
Hans
+Andrew. Last I heard the license was ready and Andrew was preparing the VPU firmware. Andrew. Is the firmware ready to submit?
Quoted 62 lines · Hans Verkuil
Quoted 45 lines · Mauro Carvalho Chehab
Em Tue, 14 Jun 2016 19:08:08 +0800
tiffany lin <[email protected]> escreveu:Quoted 32 lines
Hi Mauro,
Quoted 28 lines · Hans Verkuil
Quoted 26 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?Please look at this page:
https://linuxtv.org/wiki/index.php/Development:_How_to_submit_patches#Firmware_submissionQuoted 6 lines
The information here can also be useful:
https://www.kernel.org/doc/readme/firmware-README.AddingFirmwareIn summary, you need to provide redistribution rights for the firmware blob. You can either submit it to me or directly to linux-firmware. In the latter, please c/c me on such patch.
Tiffany, what is the status of the firmware submission?
Regards,
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 53 lines · Hans Verkuil
Quoted 45 lines · Mauro Carvalho Chehab
Em Tue, 14 Jun 2016 19:08:08 +0800
tiffany lin <[email protected]> escreveu:Quoted 32 lines
Hi Mauro,
Quoted 28 lines · Hans Verkuil
Quoted 26 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?Please look at this page:
https://linuxtv.org/wiki/index.php/Development:_How_to_submit_patches#Firmware_submissionQuoted 6 lines
The information here can also be useful:
https://www.kernel.org/doc/readme/firmware-README.AddingFirmwareIn summary, you need to provide redistribution rights for the firmware blob. You can either submit it to me or directly to linux-firmware. In the latter, please c/c me on such patch.
Quoted 5 lines
Tiffany, what is the status of the firmware submission?
Regards,
Hans
Hi Hans,
We are working on firmware test to make sure that both decoder and encoder work well. Hopes it can be ready (firmware submission) on July 4 or July 5.
Thanks.
Andrew
Quoted 5 lines
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Quoted 56 lines · andrew-ct chen
Quoted 55 lines · Hans Verkuil
Quoted 45 lines · Mauro Carvalho Chehab
Em Tue, 14 Jun 2016 19:08:08 +0800
tiffany lin <[email protected]> escreveu:Quoted 32 lines
Hi Mauro,
Quoted 28 lines · Hans Verkuil
Quoted 26 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?Please look at this page:
https://linuxtv.org/wiki/index.php/Development:_How_to_submit_patches#Firmware_submissionQuoted 6 lines
The information here can also be useful:
https://www.kernel.org/doc/readme/firmware-README.AddingFirmwareIn summary, you need to provide redistribution rights for the firmware blob. You can either submit it to me or directly to linux-firmware. In the latter, please c/c me on such patch.
Tiffany, what is the status of the firmware submission?
Quoted 8 lines
Quoted 3 lines
Regards,
Hans
Hi Hans,
We are working on firmware test to make sure that both decoder and encoder work well. Hopes it can be ready (firmware submission) on July 4 or July 5.
OK, great! Just wanted to make sure that this work was progressing and not stalled.
Thanks!
Hans
Quoted 68 lines · Hans Verkuil
Quoted 60 lines · andrew-ct chen
Quoted 59 lines · Hans Verkuil
Quoted 45 lines · Mauro Carvalho Chehab
Em Tue, 14 Jun 2016 19:08:08 +0800
tiffany lin <[email protected]> escreveu:Quoted 32 lines
Hi Mauro,
Quoted 28 lines · Hans Verkuil
Quoted 26 lines · Mauro Carvalho Chehab
Em Mon, 30 May 2016 20:29:14 +0800
Tiffany Lin <[email protected]> escreveu:Quoted 10 lines
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.Quoted 8 lines
This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
Hmm... I'm not seeing the firmware for this driver at the linux-firmware tree:
https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/log/Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Nor I'm seeing any pull request for them. Did you send it? I'll only merge the driver upstream after seeing such pull request.
Sorry, I am not familiar with how to upstream firmware.
Do you mean we need to upstream vpu firmware first before merge encoder driver upstream?Please look at this page:
https://linuxtv.org/wiki/index.php/Development:_How_to_submit_patches#Firmware_submissionQuoted 6 lines
The information here can also be useful:
https://www.kernel.org/doc/readme/firmware-README.AddingFirmwareIn summary, you need to provide redistribution rights for the firmware blob. You can either submit it to me or directly to linux-firmware. In the latter, please c/c me on such patch.
Tiffany, what is the status of the firmware submission?
Regards,
Quoted 6 lines
Quoted 1 line
Hans
Hi Hans,
We are working on firmware test to make sure that both decoder and encoder work well. Hopes it can be ready (firmware submission) on July 4 or July 5.
Quoted 5 lines
OK, great! Just wanted to make sure that this work was progressing and not stalled.
Thanks!
Hans
Hi Hans,
We have submitted VPU firmware for encoder as the following link.
http://lists.infradead.org/pipermail/linux-mediatek/2016-July/006082.html
If the series of decoder patches apply, we will update the VPU firmware for decoder support.
Thanks!.
Andrew
Hi Tiffany,
I plan to review this patch series on Friday, but one obvious question is what the reason for these failures is:
Quoted 32 lines
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) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 2 Private Controls: 0Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAIL
testVIDIOC_TRY_FMT: OK (Not Supported)
testVIDIOC_S_FMT: OK (Not Supported)
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Quoted 7 lines
Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)testVIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
If it is due to a bug in v4l2-compliance, then let me know and I'll fix it. If not, then it should be fixed in the driver.
Frankly, it was the presence of these failures that made me think this patch series wasn't final. Before a v4l2 driver can be accepted in the kernel, v4l2-compliance must pass.
Regards,
Hans
Hi Hans,
Quoted 17 lines · Hans Verkuil
Hi Tiffany,
I plan to review this patch series on Friday, but one obvious question is what the reason for these failures is:
Quoted 12 lines
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) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
These fails are because VIDIOC_G_CTRL and VIDIOC_G_EXT_CTRLS return V4L2_CID_MIN_BUFFERS_FOR_CAPTURE only when dirver in MTK_STATE_HEADER state, or it will return EAGAIN.
This could help user space get correct value, not default value that may changed base on media content.
Quoted 2 lines
Quoted 2 lines
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
Driver do not support subscribe event for control 'User Controls' for now.
Do we need to support this?
Quoted 9 lines
Quoted 9 lines
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)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAIL
This is because vidioc_vdec_g_fmt only succeed when context is in MTK_STATE_HEADER state, or user space cannot get correct format data using this function.
Quoted 4 lines
Quoted 4 lines
test
VIDIOC_TRY_FMT: OK (Not Supported) testVIDIOC_S_FMT: OK (Not Supported) testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
Quoted 8 lines
Quoted 8 lines
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)
Our OUTPUT and CAPTURE queue support both VB2_DMABUF and VB2_MMAP, user space can select which to use in runtime.
So our driver default support v4l2_m2m_ioctl_expbuf functionality. In v4l2-compliance test, it will check v4l2_m2m_ioctl_expbuf only valid when node->valid_memorytype is V4L2_MEMORY_MMAP.
So when go through node->valid_memorytype is V4L2_MEMORY_DMABUF, it fail.
best regards,
Tiffany
Quoted 14 lines
Quoted 4 lines
test
VIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
If it is due to a bug in v4l2-compliance, then let me know and I'll fix it. If not, then it should be fixed in the driver.
Frankly, it was the presence of these failures that made me think this patch series wasn't final. Before a v4l2 driver can be accepted in the kernel, v4l2-compliance must pass.
Regards,
Hans
Hi Tiffany,
Quoted 21 lines · tiffany lin
Hi Hans,
Quoted 17 lines · Hans Verkuil
Hi Tiffany,
I plan to review this patch series on Friday, but one obvious question is what the reason for these failures is:
Quoted 12 lines
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) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
Quoted 5 lines
These fails are because
VIDIOC_G_CTRLandVIDIOC_G_EXT_CTRLSreturnV4L2_CID_MIN_BUFFERS_FOR_CAPTUREonly when dirver inMTK_STATE_HEADERstate, or it will return EAGAIN.
This could help user space get correct value, not default value that may changed base on media content.
So this should be improved in v4l2-compliance.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
Driver do not support subscribe event for control 'User Controls' for now.
Do we need to support this?
Let me check: this might be a knock-on effect from the previous error.
Which controls does your driver have? (v4l2-ctl -l)
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
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)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAIL
Quoted 3 lines
This is because
vidioc_vdec_g_fmtonly succeed when context is inMTK_STATE_HEADERstate, or user space cannot get correct format data using this function.
I'll take a look at this as well.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
test
VIDIOC_TRY_FMT: OK (Not Supported) testVIDIOC_S_FMT: OK (Not Supported) testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)
Don't use v4l-utils-1.6: just use the latest master branch. That way you can be certain that the latest fixes are in. Besides, 1.6.0 is really old (almost two years!). If you used the same old version for the encoder driver as well, then please retest that encoder driver!
Quoted 7 lines
Our OUTPUT and CAPTURE queue support both
VB2_DMABUFandVB2_MMAP, user space can select which to use in runtime.
So our driver default supportv4l2_m2m_ioctl_expbuffunctionality. In v4l2-compliance test, it will checkv4l2_m2m_ioctl_expbufonly valid whennode->valid_memorytypeisV4L2_MEMORY_MMAP.
So when go throughnode->valid_memorytypeisV4L2_MEMORY_DMABUF, it fail.
That sounds like a bug. I'll take a look. For all I know, this is fixed in the master branch.
Regards,
Hans
Quoted 23 lines
best regards,
TiffanyQuoted 14 lines
Quoted 4 lines
test
VIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
If it is due to a bug in v4l2-compliance, then let me know and I'll fix it. If not, then it should be fixed in the driver.
Frankly, it was the presence of these failures that made me think this patch series wasn't final. Before a v4l2 driver can be accepted in the kernel, v4l2-compliance must pass.
Regards,
Hans
Quoted 21 lines · tiffany lin
Hi Hans,
Quoted 17 lines · Hans Verkuil
Hi Tiffany,
I plan to review this patch series on Friday, but one obvious question is what the reason for these failures is:
Quoted 12 lines
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) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
Quoted 5 lines
These fails are because
VIDIOC_G_CTRLandVIDIOC_G_EXT_CTRLSreturnV4L2_CID_MIN_BUFFERS_FOR_CAPTUREonly when dirver inMTK_STATE_HEADERstate, or it will return EAGAIN.
This could help user space get correct value, not default value that may changed base on media content.
OK, I really don't like this. I also looked what the s5p-mfc-dec driver does (the only other driver currently implementing this), and that returns -EINVAL.
My proposal would be to change this. If this information isn't known yet, why not just return 0 as the value? The doc would have to be updated and (preferably) also the s5p-mfc-dec driver. I've added Samsung devs to the Cc list, let me know what you think.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
Driver do not support subscribe event for control 'User Controls' for now.
Do we need to support this?
I don't see why this would fail. It's OK to subscribe to such controls, although you'll never get an event.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
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)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAIL
Quoted 3 lines
This is because
vidioc_vdec_g_fmtonly succeed when context is inMTK_STATE_HEADERstate, or user space cannot get correct format data using this function.
Comparing this to s5p-mfc-dec I see that -EINVAL is returned in that case.
I am not opposed to using EAGAIN in s5p-mfc-dec as well. Marek, Kamil, what is your opinion?
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
test
VIDIOC_TRY_FMT: OK (Not Supported) testVIDIOC_S_FMT: OK (Not Supported) testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)Quoted 8 lines
Quoted 8 lines
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)
Quoted 7 lines
Our OUTPUT and CAPTURE queue support both
VB2_DMABUFandVB2_MMAP, user space can select which to use in runtime.
So our driver default supportv4l2_m2m_ioctl_expbuffunctionality. In v4l2-compliance test, it will checkv4l2_m2m_ioctl_expbufonly valid whennode->valid_memorytypeisV4L2_MEMORY_MMAP.
So when go throughnode->valid_memorytypeisV4L2_MEMORY_DMABUF, it fail.
valid_memorytype should have both MMAP and DMABUF flags.
But v4l-utils-1.6.0 is way too old to be certain it isn't some v4l2-compliance bug that has since been fixed.
Regards,
Hans
Quoted 28 lines
best regards,
TiffanyQuoted 8 lines
Quoted 4 lines
test
VIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
If it is due to a bug in v4l2-compliance, then let me know and I'll fix it. If not, then it should be fixed in the driver.
Quoted 6 lines
Frankly, it was the presence of these failures that made me think this patch series wasn't final. Before a v4l2 driver can be accepted in the kernel, v4l2-compliance must pass.
Regards,
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Hans,
Quoted 28 lines · Hans Verkuil
Quoted 21 lines · tiffany lin
Hi Hans,
Quoted 17 lines · Hans Verkuil
Hi Tiffany,
I plan to review this patch series on Friday, but one obvious question is what the reason for these failures is:
Quoted 12 lines
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) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAILQuoted 5 lines
These fails are because
VIDIOC_G_CTRLandVIDIOC_G_EXT_CTRLSreturnV4L2_CID_MIN_BUFFERS_FOR_CAPTUREonly when dirver inMTK_STATE_HEADERstate, or it will return EAGAIN.
This could help user space get correct value, not default value that may changed base on media content.
Quoted 8 lines
OK, I really don't like this. I also looked what the s5p-mfc-dec driver does (the only other driver currently implementing this), and that returns
-EINVAL.My proposal would be to change this. If this information isn't known yet, why not just return 0 as the value? The doc would have to be updated and (preferably) also the s5p-mfc-dec driver. I've added Samsung devs to the Cc list, let me know what you think.
Got it. We will return 0 as the value instead EAGAIN.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
Driver do not support subscribe event for control 'User Controls' for now.
Do we need to support this?I don't see why this would fail. It's OK to subscribe to such controls, although you'll never get an event.
Got it. I will rerun using latest v4l2-compliance test check this.
Quoted 39 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
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)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAILQuoted 3 lines
This is because
vidioc_vdec_g_fmtonly succeed when context is inMTK_STATE_HEADERstate, or user space cannot get correct format data using this function.Comparing this to s5p-mfc-dec I see that
-EINVALis returned in that case.I am not opposed to using EAGAIN in s5p-mfc-dec as well. Marek, Kamil, what is your opinion?
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
test
VIDIOC_TRY_FMT: OK (Not Supported) testVIDIOC_S_FMT: OK (Not Supported) testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)Quoted 8 lines
Quoted 8 lines
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)Quoted 7 lines
Our OUTPUT and CAPTURE queue support both
VB2_DMABUFandVB2_MMAP, user space can select which to use in runtime.
So our driver default supportv4l2_m2m_ioctl_expbuffunctionality. In v4l2-compliance test, it will checkv4l2_m2m_ioctl_expbufonly valid whennode->valid_memorytypeisV4L2_MEMORY_MMAP.
So when go throughnode->valid_memorytypeisV4L2_MEMORY_DMABUF, it fail.
Quoted 5 lines
valid_memorytypeshould have both MMAP and DMABUF flags.But v4l-utils-1.6.0 is way too old to be certain it isn't some v4l2-compliance bug that has since been fixed.
Got it. I will rerun using master branch to check this.
best regards,
Tiffany
Quoted 32 lines
Regards,
Hans
Quoted 28 lines
best regards,
TiffanyQuoted 8 lines
Quoted 4 lines
test
VIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
If it is due to a bug in v4l2-compliance, then let me know and I'll fix it. If not, then it should be fixed in the driver.
Quoted 6 lines
Frankly, it was the presence of these failures that made me think this patch series wasn't final. Before a v4l2 driver can be accepted in the kernel, v4l2-compliance must pass.
Regards,
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Hans,
Quoted 28 lines · Hans Verkuil
Quoted 21 lines · tiffany lin
Hi Hans,
Quoted 17 lines · Hans Verkuil
Hi Tiffany,
I plan to review this patch series on Friday, but one obvious question is what the reason for these failures is:
Quoted 12 lines
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) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAILQuoted 5 lines
These fails are because
VIDIOC_G_CTRLandVIDIOC_G_EXT_CTRLSreturnV4L2_CID_MIN_BUFFERS_FOR_CAPTUREonly when dirver inMTK_STATE_HEADERstate, or it will return EAGAIN.
This could help user space get correct value, not default value that may changed base on media content.
Quoted 8 lines
OK, I really don't like this. I also looked what the s5p-mfc-dec driver does (the only other driver currently implementing this), and that returns
-EINVAL.My proposal would be to change this. If this information isn't known yet, why not just return 0 as the value? The doc would have to be updated and (preferably) also the s5p-mfc-dec driver. I've added Samsung devs to the Cc list, let me know what you think.
We are ok with just return 0 as the value when header not parsed yet We will update decoder with this solution.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
Driver do not support subscribe event for control 'User Controls' for now.
Do we need to support this?I don't see why this would fail. It's OK to subscribe to such controls, although you'll never get an event.
After upgrade to latest v4l-utils,this test pass.
Quoted 39 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
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)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAILQuoted 3 lines
This is because
vidioc_vdec_g_fmtonly succeed when context is inMTK_STATE_HEADERstate, or user space cannot get correct format data using this function.Comparing this to s5p-mfc-dec I see that
-EINVALis returned in that case.I am not opposed to using EAGAIN in s5p-mfc-dec as well. Marek, Kamil, what is your opinion?
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
test
VIDIOC_TRY_FMT: OK (Not Supported) testVIDIOC_S_FMT: OK (Not Supported) testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)Quoted 8 lines
Quoted 8 lines
Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)Quoted 7 lines
Our OUTPUT and CAPTURE queue support both
VB2_DMABUFandVB2_MMAP, user space can select which to use in runtime.
So our driver default supportv4l2_m2m_ioctl_expbuffunctionality. In v4l2-compliance test, it will checkv4l2_m2m_ioctl_expbufonly valid whennode->valid_memorytypeisV4L2_MEMORY_MMAP.
So when go throughnode->valid_memorytypeisV4L2_MEMORY_DMABUF, it fail.
Quoted 4 lines
valid_memorytypeshould have both MMAP and DMABUF flags.But v4l-utils-1.6.0 is way too old to be certain it isn't some v4l2-compliance bug that has since been fixed.
After upgrade to latest v4l-utils, I still see this issue.
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: v4l2-test-buffers.cpp(571): q.has_expbuf(node)
best regards,
Tiffany
Quoted 33 lines
Regards,
Hans
Quoted 28 lines
best regards,
TiffanyQuoted 8 lines
Quoted 4 lines
test
VIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
If it is due to a bug in v4l2-compliance, then let me know and I'll fix it. If not, then it should be fixed in the driver.
Quoted 6 lines
Frankly, it was the presence of these failures that made me think this patch series wasn't final. Before a v4l2 driver can be accepted in the kernel, v4l2-compliance must pass.
Regards,
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Tiffany,
This needs a v4: the DocBook format has been replaced by sphinx, and I also see that the vb2 queue_setup function is out-of-date (the allocation contexts no longer exist).
There were also a lot of comments about the MT21 format. I recommend splitting off the code adding MT21 into separate patches at the end of the patch series. That way if there are more comments it is easy to merge everything but those patches relating to MT21.
Can you also add the patches for the new V4L2_PIX_FMT_VP9 to this patch series? Those needs to be updated as well due to the move to sphinx.
Thanks!
Hans
Quoted 187 lines · Tiffany Lin
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
==================
Device interface
==================In principle the driver bases on v4l2 memory-to-memory framework:
it provides a single video node and each opened file handle gets its own private context with separate buffer queues. Each context consist of 2 buffer queues: OUTPUT (for source buffers, i.e. bitstream) and CAPTURE (for destination buffers, i.e. decoded video frames).
OUTPUT and CAPTURE buffer could be MMAP or DMABUF memory type.VIDIOC_G_CTRLandVIDIOC_G_EXT_CTRLSreturnV4L2_CID_MIN_BUFFERS_FOR_CAPTUREonly when dirver inMTK_STATE_HEADERstate, or it will return EAGAIN.
Driver do not support subscribe event for control 'User Controls' for now.
And it default support export DMABUF for other display drivers.Change in v3:
1. Refine vdec hw clock setting
2. Refine vp9 codec driver
3. Refine v4l2 codec driverChange in v2:
1. Add documentation forV4L2_PIX_FMT_MT21
2. RemoveDRM_FORMAT_MT21
2. Refine code according to review commentsv4l2-compliance test output:
localhost Encode # ./v4l2-compliance -d/dev/video0Driver Info:Driver name : mtk-vcodec-dec Card type : platform:mt8173 Bus info : platform:mt8173Driver version: 4.4.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 FormatCompliance test for device
/dev/video0(not using libv4l2):Required ioctls:
testVIDIOC_QUERYCAP: OKAllow for multiple opens:
test second video open: OK
testVIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OKDebug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) testVIDIOC_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) testVIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) testVIDIOC_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: 0Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_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: 0Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 2 Private Controls: 0Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAIL
testVIDIOC_TRY_FMT: OK (Not Supported)
testVIDIOC_S_FMT: OK (Not Supported)
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)testVIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
Andrew-CT Chen (1):
VPU: mediatek: Add decode supportTiffany Lin (8):
v4l: add Mediatek compressed video block format DocBook/v4l: Add compressed video formats used on MT8173 codec driver
dt-bindings: Add a binding for Mediatek Video Decoder
vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
vcodec: mediatek: Add Mediatek H264 Video Decoder Driver
vcodec: mediatek: Add Mediatek VP8 Video Decoder Driver
vcodec: mediatek: Add Mediatek VP9 Video Decoder Driver
arm64: dts: mediatek: Add Video Decoder for MT8173Documentation/DocBook/media/v4l/pixfmt.xml | 6 + .../devicetree/bindings/media/mediatek-vcodec.txt | 57 +- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 44 + drivers/media/platform/mtk-vcodec/Makefile | 15 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1348 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h | 88 ++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 408 ++++++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 206 +++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 28 + drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 88 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.c | 4 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.h | 2 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.c | 31 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.h | 7 +- .../media/platform/mtk-vcodec/vdec/vdec_h264_if.c | 503 ++++++++ .../media/platform/mtk-vcodec/vdec/vdec_vp8_if.c | 630 +++++++++ .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c | 967 ++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_base.h | 56 + drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 117 ++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 101 ++ drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h | 103 ++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.c | 168 +++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.h | 96 ++ drivers/media/platform/mtk-vpu/mtk_vpu.c | 12 + drivers/media/platform/mtk-vpu/mtk_vpu.h | 27 + include/uapi/linux/videodev2.h | 1 + 26 files changed, 5090 insertions(+), 23 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
Hi Hans,
I upstream v4 on 8/10, I don't know why this version is not shown in
https://patchwork.kernel.org.
But I could see it in other link.
http://www.spinics.net/lists/arm-kernel/msg523095.html
I refine DocBook and vb2 queue_setup function in v4.
For the MT21 format, if I put MT21 into separate patch, this patch series will build fail, I was confused how to fix this issue?
For VP9, I will merge this three patchs to V4L2 Decoder patch series.
* linux-media: [v1,1/3] videodev2.h: add V4L2_PIX_FMT_VP9 format.
- http://patchwork.linuxtv.org/patch/34392/
* linux-media: [v1,3/3] V4L: add VP9 format documentation
- http://patchwork.linuxtv.org/patch/34393/
* linux-media: [v1,2/3] v4l2-ioctl: add VP9 format description.
- http://patchwork.linuxtv.org/patch/34394/
best regards,
Tiffany
Quoted 204 lines · Hans Verkuil
Hi Tiffany,
This needs a v4: the DocBook format has been replaced by sphinx, and I also see that the vb2
queue_setupfunction is out-of-date (the allocation contexts no longer exist).There were also a lot of comments about the MT21 format. I recommend splitting off the code adding MT21 into separate patches at the end of the patch series. That way if there are more comments it is easy to merge everything but those patches relating to MT21.
Can you also add the patches for the new
V4L2_PIX_FMT_VP9to this patch series? Those needs to be updated as well due to the move to sphinx.Thanks!
Hans
Quoted 187 lines · Tiffany Lin
==============
Introduction
==============The purpose of this series is to add the driver for video codec hw embedded in the Mediatek's MT8173 SoCs. Mediatek Video Codec is able to handle video decoding of in a range of formats.
This patch series add Mediatek block format
V4L2_PIX_FMT_MT21, the decoder driver will decoded bitstream toV4L2_PIX_FMT_MT21format.This patch series rely on MTK VPU driver in patch series "Add MT8173 Video Encoder Driver and VPU Driver"[1] and patch "CHROMIUM: v4l: Add
V4L2_PIX_FMT_VP9definition"[2] for VP9 support.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI both have been merged in v4.6-rc1.
[1]https://patchwork.linuxtv.org/patch/33734/ [2]https://chromium-review.googlesource.com/#/c/245241/
==================
Device interface
==================In principle the driver bases on v4l2 memory-to-memory framework:
it provides a single video node and each opened file handle gets its own private context with separate buffer queues. Each context consist of 2 buffer queues: OUTPUT (for source buffers, i.e. bitstream) and CAPTURE (for destination buffers, i.e. decoded video frames).
OUTPUT and CAPTURE buffer could be MMAP or DMABUF memory type.VIDIOC_G_CTRLandVIDIOC_G_EXT_CTRLSreturnV4L2_CID_MIN_BUFFERS_FOR_CAPTUREonly when dirver inMTK_STATE_HEADERstate, or it will return EAGAIN.
Driver do not support subscribe event for control 'User Controls' for now.
And it default support export DMABUF for other display drivers.Change in v3:
1. Refine vdec hw clock setting
2. Refine vp9 codec driver
3. Refine v4l2 codec driverChange in v2:
1. Add documentation forV4L2_PIX_FMT_MT21
2. RemoveDRM_FORMAT_MT21
2. Refine code according to review commentsv4l2-compliance test output:
localhost Encode # ./v4l2-compliance -d/dev/video0Driver Info:Driver name : mtk-vcodec-dec Card type : platform:mt8173 Bus info : platform:mt8173Driver version: 4.4.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 FormatCompliance test for device
/dev/video0(not using libv4l2):Required ioctls:
testVIDIOC_QUERYCAP: OKAllow for multiple opens:
test second video open: OK
testVIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OKDebug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) testVIDIOC_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) testVIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) testVIDIOC_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: 0Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_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: 0Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(357):g_ctrlreturned an error (11) test VIDIOC_G/S_CTRL: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(579):g_ext_ctrlsreturned an error (11) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-controls.cpp(721): subscribe event for control 'User Controls' failed test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 2 Private Controls: 0Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
testVIDIOC_G_FBUF: OK (Not Supported)
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-formats.cpp(405): expected EINVAL, but got 11 when getting format for buftype 9 testVIDIOC_G_FMT: FAIL
testVIDIOC_TRY_FMT: OK (Not Supported)
testVIDIOC_S_FMT: OK (Not Supported)
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
fail: ../../../v4l-utils-1.6.0/utils/v4l2-compliance/v4l2-test-buffers.cpp(500):q.has_expbuf(node)testVIDIOC_EXPBUF: FAILTotal: 38, Succeeded: 33, Failed: 5, Warnings: 0
Andrew-CT Chen (1):
VPU: mediatek: Add decode supportTiffany Lin (8):
v4l: add Mediatek compressed video block format DocBook/v4l: Add compressed video formats used on MT8173 codec driver
dt-bindings: Add a binding for Mediatek Video Decoder
vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver
vcodec: mediatek: Add Mediatek H264 Video Decoder Driver
vcodec: mediatek: Add Mediatek VP8 Video Decoder Driver
vcodec: mediatek: Add Mediatek VP9 Video Decoder Driver
arm64: dts: mediatek: Add Video Decoder for MT8173Documentation/DocBook/media/v4l/pixfmt.xml | 6 + .../devicetree/bindings/media/mediatek-vcodec.txt | 57 +- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 44 + drivers/media/platform/mtk-vcodec/Makefile | 15 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1348 ++++++++++++++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h | 88 ++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 408 ++++++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 206 +++ .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 28 + drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 88 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.c | 4 +- .../media/platform/mtk-vcodec/mtk_vcodec_intr.h | 2 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.c | 31 +- .../media/platform/mtk-vcodec/mtk_vcodec_util.h | 7 +- .../media/platform/mtk-vcodec/vdec/vdec_h264_if.c | 503 ++++++++ .../media/platform/mtk-vcodec/vdec/vdec_vp8_if.c | 630 +++++++++ .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c | 967 ++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_base.h | 56 + drivers/media/platform/mtk-vcodec/vdec_drv_if.c | 117 ++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 101 ++ drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h | 103 ++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.c | 168 +++ drivers/media/platform/mtk-vcodec/vdec_vpu_if.h | 96 ++ drivers/media/platform/mtk-vpu/mtk_vpu.c | 12 + drivers/media/platform/mtk-vpu/mtk_vpu.h | 27 + include/uapi/linux/videodev2.h | 1 + 26 files changed, 5090 insertions(+), 23 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.c create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
Quoted 10 lines · Tiffany Lin
Hi Hans,
I upstream v4 on 8/10, I don't know why this version is not shown in
https://patchwork.kernel.org.
But I could see it in other link.
http://www.spinics.net/lists/arm-kernel/msg523095.html
I refine DocBook and vb2queue_setupfunction in v4.For the MT21 format, if I put MT21 into separate patch, this patch series will build fail, I was confused how to fix this issue?
Just don't implement that pixelformat yet. I.e. everything else can be implemented, just don't add MT21 to the list of pixelformats. Do that in a separate patch at the end.
If that pixelformat isn't exposed, then nobody will use it either :-)
Regards,
Hans
Hi Hans,
Quoted 9 lines · Hans Verkuil
Quoted 8 lines · Tiffany Lin
Hi Hans,
I upstream v4 on 8/10, I don't know why this version is not shown in
https://patchwork.kernel.org.
But I could see it in other link.
http://www.spinics.net/lists/arm-kernel/msg523095.html
I refine DocBook and vb2queue_setupfunction in v4.
Quoted 9 lines
Quoted 2 lines
For the MT21 format, if I put MT21 into separate patch, this patch series will build fail, I was confused how to fix this issue?
Just don't implement that pixelformat yet. I.e. everything else can be implemented, just don't add MT21 to the list of pixelformats. Do that in a separate patch at the end.
If that pixelformat isn't exposed, then nobody will use it either :-)
Got it now.
Thanks a lot.
best regards,
Tiffany
Quoted 3 lines
Regards,
Hans