Enable two hardware jpeg encoder for MT8195
Subsystems (4)
v10 cover Enable two hardware jpeg encoder for MT8195
From: kyrie wu <[email protected]>
This series adds support for multi hardware jpeg encoding, by first adding use of_platform_populate to manage each hardware information:
interrupt, clock, register bases and power. Secondly add encoding work queue to deal with the encoding requestsof multi-hardware at the same time. Lastly, add output picture reorder function interface to eliminate the out of order images.
This series has been tested with MT8195 Gstreamer. Encoding worked for this chip.
Patches 1 Adds jpeg encoder dt-bindings for mt8195
Patches 2 jpeg encoder builds two module for using Multi-HW, export some functions to make them visible by other modules.
Patches 3 use devm_of_platform_populate to manage multi-hardware.
Patch 4 add jpeg encoding timeout function to judge hardware timeout.
Patch 5 add encoding work queue to deal with multi-hardware encoding at the same time.
Patch 6 add output picture reorder function to order images.
Patch 7 add stop cmd function to deal with EOS operation.
---
This series patches dependent on:media_stage tree:
[1]
https://git.linuxtv.org/media_stage.git/commit/?id=b3627647f9ea7473d10fb08a95fd7c4133a17ca4
patch1 new jpegenc dt-bindings included files
[2] MM IOMMU binding:
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
[3] MT8195 power domain:
https://patchwork.kernel.org/project/linux-mediatek/list/?series=580579
Changes compared with v9:
- some modifications for patch v9's review comments.
Changes compared with v8:
- some modifications for patch v8's review comments.
- add stop cmd function.
Changes compared with v7:
- some modifications for patch v6's review comments.
Changes compared with v6:
- new yaml file for mt8195 jpeg encoder.
- some modifications for patch v5's review comments.
Changes compared with v5:
- use of_platform_populate to replace component framework to manage multi-hardware in patch 2.
Changes compared with v4:
- No change compaered with v4
Changes compared with v3:
- Structure patches for consistency, non-backward compatible and do not break any existing functionality
Changes compared with v2:
- Split the last two patches into several patches
to enhance readability
- Correct some syntax errors
- Explain why the component framework is used
Changes compared with v1:
- Add jpeg encoder dt-bindings for MT8195
- Use component framework to manage jpegenc HW
- Add jpegenc output pic reorder function interface
kyrie wu (7):
dt-bindings: mediatek: Add mediatek, mt8195-jpgenc compatible
mtk-jpegenc: export jpeg encoder functions
mtk-jpegenc: manage jpegenc multi-hardware
mtk-jpegenc: add jpegenc timeout func interface
mtk-jpegenc: add jpeg encode worker interface
mtk-jpegenc: add output pic reorder interface
mtk-jpegenc: add stop cmd interface for jpgenc
.../media/mediatek,mt8195-jpegenc.yaml | 154 ++++++++++ drivers/media/platform/mediatek/jpeg/Makefile | 11 +- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 290 +++++++++++++++--- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 82 ++++- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 1 + .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.h | 3 +- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 253 +++++++++++++++ 7 files changed, 743 insertions(+), 51 deletions(-) create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
Signature · 1 line
2.18.0
PATCH v10 1/7 dt-bindings: mediatek: Add mediatek, mt8195-jpgenc compatible
From: kyrie wu <[email protected]>
Add mediatek,mt8195-jpgenc compatible to binding document.
--- .../media/mediatek,mt8195-jpegenc.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml new file +154 -0
@@ -0,0 +1,154 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/mediatek,mt8195-jpegenc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek JPEG Encoder Device Tree Bindings + +maintainers: + - kyrie wu <[email protected]> + +description: |- + MediaTek JPEG Encoder is the JPEG encode hardware present in MediaTek SoCs + +properties: + compatible: + items: + - const: mediatek,mt8195-jpgenc + + mediatek,jpegenc-multi-core: + type: boolean + description: | + Indicates whether the jpeg encoder has multiple cores or not. + + power-domains: + maxItems: 1 + + iommus: + maxItems: 4 + description: | + Points to the respective IOMMU block with master port as argument, see + Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details. + Ports are according to the HW. + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + ranges: true + +# Required child node: +patternProperties: + "^jpgenc@[0-9a-f]+$": + type: object + description: | + The jpeg encoder hardware device node which should be added as subnodes to + the main jpeg node. + + properties: + compatible: + const: mediatek,mt8195-jpgenc-hw + + reg: + maxItems: 1 + + hw_id: + description: | + MT8195 encoding hardware id value. MT8195 has two encoding hardwares, + which is represented by this parameter. + + iommus: + minItems: 1 + maxItems: 32 + description: | + List of the hardware port in respective IOMMU block for current Socs. + Refer to bindings/iommu/mediatek,iommu.yaml. + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: jpgenc + + power-domains: + maxItems: 1 + + required: + - compatible + - reg + - hw_id + - iommus + - interrupts + - clocks + - clock-names + - power-domains + + additionalProperties: false + +required: + - compatible + - power-domains + - iommus + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/memory/mt8195-memory-port.h> + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/clock/mt8195-clk.h> + #include <dt-bindings/power/mt8195-power.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + jpgenc_master { + compatible = "mediatek,mt8195-jpgenc"; + mediatek,jpegenc-multi-core; + power-domains = <&spm MT8195_POWER_DOMAIN_VENC_CORE1>; + iommus = <&iommu_vpp M4U_PORT_L20_JPGENC_Y_RDMA>, + <&iommu_vpp M4U_PORT_L20_JPGENC_C_RDMA>, + <&iommu_vpp M4U_PORT_L20_JPGENC_Q_TABLE>, + <&iommu_vpp M4U_PORT_L20_JPGENC_BSDMA>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + jpgenc@1a030000 { + compatible = "mediatek,mt8195-jpgenc-hw"; + reg = <0 0x1a030000 0 0x10000>; + hw_id = <0>; + iommus = <&iommu_vdo M4U_PORT_L19_JPGENC_Y_RDMA>, + <&iommu_vdo M4U_PORT_L19_JPGENC_C_RDMA>, + <&iommu_vdo M4U_PORT_L19_JPGENC_Q_TABLE>, + <&iommu_vdo M4U_PORT_L19_JPGENC_BSDMA>; + interrupts = <GIC_SPI 342 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&vencsys CLK_VENC_JPGENC>; + clock-names = "jpgenc"; + power-domains = <&spm MT8195_POWER_DOMAIN_VENC>; + }; + + jpgenc@1b030000 { + compatible = "mediatek,mt8195-jpgenc-hw"; + reg = <0 0x1b030000 0 0x10000>; + hw_id = <1>; + iommus = <&iommu_vpp M4U_PORT_L20_JPGENC_Y_RDMA>, + <&iommu_vpp M4U_PORT_L20_JPGENC_C_RDMA>, + <&iommu_vpp M4U_PORT_L20_JPGENC_Q_TABLE>, + <&iommu_vpp M4U_PORT_L20_JPGENC_BSDMA>; + interrupts = <GIC_SPI 347 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&vencsys_core1 CLK_VENC_CORE1_JPGENC>; + clock-names = "jpgenc"; + power-domains = <&spm MT8195_POWER_DOMAIN_VENC_CORE1>; + }; + }; + };
Signature · 1 line
2.18.0
Rob Herring
maintainerRe: [V10,1/7] dt-bindings: mediatek: Add mediatek, mt8195-jpgenc compatible
Quoted 3 lines · Irui Wang
From: kyrie wu <[email protected]>
Add mediatek,mt8195-jpgenc compatible to binding document.
Same comments as the decoder.
Quoted 2 lines
Signed-off-by kyrie wu <[email protected]>
Also, this needs your S-o-b too.
Quoted 4 lines
--- .../media/mediatek,mt8195-jpegenc.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
PATCH v10 2/7 mtk-jpegenc: export jpeg encoder functions
In reply to Irui WangFrom: kyrie wu <[email protected]>
mtk jpeg encoder is built as a module, export some functions to make them visible by other modules.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +7 -0
@@ -36,12 +36,14 @@ void mtk_jpeg_enc_reset(void __iomem *base)writel (JPEG_ENC_RESET_BIT , base +JPEG_ENC_RSTB );writel (0 , base +JPEG_ENC_CODEC_SEL ); } +EXPORT_SYMBOL_GPL (mtk_jpeg_enc_reset);u32 mtk_jpeg_enc_get_file_size (void __iomem *base) {return readl (base +JPEG_ENC_DMA_ADDR0 ) -readl (base +JPEG_ENC_DST_ADDR0 ); } +EXPORT_SYMBOL_GPL (mtk_jpeg_enc_get_file_size);void mtk_jpeg_enc_start (void __iomem *base) {
@@ -51,6 +53,7 @@ void mtk_jpeg_enc_start(void __iomem *base) value |=JPEG_ENC_CTRL_INT_EN_BIT |JPEG_ENC_CTRL_ENABLE_BIT ;writel (value, base +JPEG_ENC_CTRL ); } +EXPORT_SYMBOL_GPL (mtk_jpeg_enc_start);void mtk_jpeg_set_enc_src (struct mtk_jpeg_ctx *ctx,void __iomem *base,struct vb2_buffer *src_buf)
@@ -67,6 +70,7 @@ void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx, void __iomem *base,writel (dma_addr, base +JPEG_ENC_SRC_CHROMA_ADDR ); } } +EXPORT_SYMBOL_GPL (mtk_jpeg_set_enc_src);void mtk_jpeg_set_enc_dst (struct mtk_jpeg_ctx *ctx,void __iomem *base,struct vb2_buffer *dst_buf)
@@ -86,6 +90,7 @@ void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx, void __iomem *base,writel (dma_addr & ~0xf , base +JPEG_ENC_DST_ADDR0 );writel ((dma_addr + size) & ~0xf , base +JPEG_ENC_STALL_ADDR0 ); } +EXPORT_SYMBOL_GPL (mtk_jpeg_set_enc_dst);void mtk_jpeg_set_enc_params (struct mtk_jpeg_ctx *ctx,void __iomem *base) {
@@ -152,3 +157,5 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base)writel (ctx->restart_interval, base +JPEG_ENC_RST_MCU_NUM ); } +EXPORT_SYMBOL_GPL (mtk_jpeg_set_enc_params); +
Signature · 1 line
2.18.0
PATCH v10 3/7 mtk-jpegenc: manage jpegenc multi-hardware
In reply to Irui WangFrom: kyrie wu <[email protected]>
manage each hardware information, including irq/clk/power. the hardware includes HW0 and HW1.
--- drivers/media/platform/mediatek/jpeg/Makefile | 11 +- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 77 ++++++--- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 38 +++++ .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 160 ++++++++++++++++++ 4 files changed, 261 insertions(+), 25 deletions(-)
drivers/media/platform/mediatek/jpeg/Makefile +7 -4
@@ -1,6 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only -mtk_jpeg-objs := mtk_jpeg_core.o \ +obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o \ + mtk-jpeg-enc-hw.o + +mtk_jpeg-y := mtk_jpeg_core.o \ mtk_jpeg_dec_hw.o \ - mtk_jpeg_dec_parse.o \ - mtk_jpeg_enc_hw.o -obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o + mtk_jpeg_dec_parse.o + +mtk-jpeg-enc-hw-y := mtk_jpeg_enc_hw.o
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +56 -21
110 lines not on this page · raw message
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +38 -0
@@ -9,6 +9,7 @@#ifndef _MTK_JPEG_CORE_H#define _MTK_JPEG_CORE_H +#include <linux/clk.h> #include <linux/interrupt.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h>
@@ -74,6 +75,39 @@ struct mtk_jpeg_variant {u32 cap_q_default_fourcc; }; +enum mtk_jpegenc_hw_id { +MTK_JPEGENC_HW0 , +MTK_JPEGENC_HW1 , +MTK_JPEGENC_HW_MAX , +}; + +/** +* struct mtk_vcodec_clk - Structure used to store vcodec clock information +*/ +struct mtk_jpegenc_clk { +struct clk_bulk_data *clks; +int clk_num; +}; + +/** +* struct mtk_jpegenc_comp_dev - JPEG COREX abstraction +* @dev: JPEG device +* @plat_dev: platform device data +* @reg_base: JPEG registers mapping +* @master_dev: mtk_jpeg_dev device +* @pm: mtk_jpegenc_pm +* @jpegenc_irq: jpeg encode irq num +*/ +struct mtk_jpegenc_comp_dev { +struct device *dev; +struct platform_device *plat_dev; +void __iomem *reg_base; +struct mtk_jpeg_dev *master_dev; +struct mtk_jpegenc_clk venc_clk; +int jpegenc_irq; +int hw_id; +}; +/** * struct mtk_jpeg_dev - JPEG IP abstraction * @lock: the mutex protecting this structure
@@ -100,6 +134,10 @@ struct mtk_jpeg_dev {void __iomem *reg_base;struct delayed_work job_timeout_work;const struct mtk_jpeg_variant *variant; + +void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX ]; +struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX ]; +bool is_jpgenc_multihw; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +160 -0
180 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v10 4/7 mtk-jpegenc: add jpegenc timeout func interface
In reply to Irui WangFrom: kyrie wu <[email protected]>
Generalizes jpegenc timeout func interfaces to handle HW timeout.
--- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 8 ++++++ .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +8 -0
@@ -75,6 +75,12 @@ struct mtk_jpeg_variant {u32 cap_q_default_fourcc; }; +struct mtk_jpeg_hw_param { +struct vb2_v4l2_buffer *src_buffer; +struct vb2_v4l2_buffer *dst_buffer; +struct mtk_jpeg_ctx *curr_ctx; +}; +enum mtk_jpegenc_hw_id {MTK_JPEGENC_HW0 ,MTK_JPEGENC_HW1 ,
@@ -106,6 +112,8 @@ struct mtk_jpegenc_comp_dev {struct mtk_jpegenc_clk venc_clk;int jpegenc_irq;int hw_id; +struct delayed_work job_timeout_work; +struct mtk_jpeg_hw_param hw_param; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +25 -0
@@ -185,6 +185,26 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base) }EXPORT_SYMBOL_GPL (mtk_jpeg_set_enc_params); +static void mtk_jpegenc_timeout_work (struct work_struct *work) +{ +struct delayed_work *dly_work =to_delayed_work (work); +struct mtk_jpegenc_comp_dev *cjpeg = +container_of (dly_work, + struct mtk_jpegenc_comp_dev, + job_timeout_work); +enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ; +struct vb2_v4l2_buffer *src_buf, *dst_buf; + + src_buf = cjpeg->hw_param.src_buffer; + dst_buf = cjpeg->hw_param.dst_buffer; +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); + +mtk_jpeg_enc_reset (cjpeg->reg_base); +clk_disable_unprepare (cjpeg->venc_clk.clks->clk); +pm_runtime_put (cjpeg->dev); +v4l2_m2m_buf_done (src_buf, buf_state); +} +static irqreturn_t mtk_jpegenc_hw_irq_handler (int irq,void *priv) {struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -196,6 +216,8 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)struct mtk_jpegenc_comp_dev *jpeg = priv;struct mtk_jpeg_dev *master_jpeg = jpeg->master_dev; +cancel_delayed_work (&jpeg->job_timeout_work); + irq_status =readl (jpeg->reg_base +JPEG_ENC_INT_STS ) &JPEG_ENC_INT_STATUS_MASK_ALLIRQ ;if (irq_status)
@@ -272,6 +294,9 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) dev->plat_dev = pdev; dev->dev = &pdev->dev; +INIT_DELAYED_WORK (&dev->job_timeout_work, + mtk_jpegenc_timeout_work); + jpegenc_clk = &dev->venc_clk; jpegenc_clk->clk_num = devm_clk_bulk_get_all(&pdev->dev,
Signature · 1 line
2.18.0
PATCH v10 5/7 mtk-jpegenc: add jpeg encode worker interface
In reply to Irui WangFrom: kyrie wu <[email protected]>
Add jpeg encoding worker to ensure that two HWs
run in parallel in MT8195.
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 208 ++++++++++++++++-- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 30 ++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 39 +++- 3 files changed, 240 insertions(+), 37 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +189 -19
@@ -105,10 +105,18 @@ static struct mtk_jpeg_fmt mtk_jpeg_dec_formats[] = {#define MTK_JPEG_ENC_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_enc_formats)#define MTK_JPEG_DEC_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_dec_formats) +enum { +MTK_JPEG_BUF_FLAGS_INIT =0 , +MTK_JPEG_BUF_FLAGS_LAST_FRAME =1 , +}; +struct mtk_jpeg_src_buf { +u32 frame_num;struct vb2_v4l2_buffer b;struct list_head list;struct mtk_jpeg_dec_param dec_param; + +struct mtk_jpeg_ctx *curr_ctx; };static int debug;
@@ -907,38 +915,134 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,return 0 ; } -static void mtk_jpeg_enc_device_run (void *priv) +static int mtk_jpegenc_get_hw (struct mtk_jpeg_ctx *ctx) { -struct mtk_jpeg_ctx *ctx = priv; +struct mtk_jpegenc_comp_dev *comp_jpeg;struct mtk_jpeg_dev *jpeg = ctx->jpeg; -struct vb2_v4l2_buffer *src_buf, *dst_buf; +unsigned long flags; +int hw_id =-1 ; +int i; + +spin_lock_irqsave (&jpeg->hw_lock, flags); +for (i =0 ; i <MTK_JPEGENC_HW_MAX ; i++) { + comp_jpeg = jpeg->enc_hw_dev[i]; +if (comp_jpeg->hw_state ==MTK_JPEG_HW_IDLE ) { + hw_id = i; + comp_jpeg->hw_state =MTK_JPEG_HW_BUSY ; +break ; + } + } +spin_unlock_irqrestore (&jpeg->hw_lock, flags); + +return hw_id; +} + +static int mtk_jpegenc_set_hw_param (struct mtk_jpeg_ctx *ctx, +int hw_id, +struct vb2_v4l2_buffer *src_buf, +struct vb2_v4l2_buffer *dst_buf) +{ +struct mtk_jpegenc_comp_dev *jpeg = ctx->jpeg->enc_hw_dev[hw_id]; + + jpeg->hw_param.curr_ctx = ctx; + jpeg->hw_param.src_buffer = src_buf; + jpeg->hw_param.dst_buffer = dst_buf; + +return 0 ; +} + +static int mtk_jpegenc_put_hw (struct mtk_jpeg_dev *jpeg,int hw_id) +{ +unsigned long flags; + +spin_lock_irqsave (&jpeg->hw_lock, flags); + jpeg->enc_hw_dev[hw_id]->hw_state =MTK_JPEG_HW_IDLE ; +spin_unlock_irqrestore (&jpeg->hw_lock, flags); + +return 0 ; +} + +static void mtk_jpegenc_worker (struct work_struct *work) +{ +struct mtk_jpegenc_comp_dev *comp_jpeg[MTK_JPEGENC_HW_MAX ];enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ; +struct mtk_jpeg_src_buf *jpeg_dst_buf; +struct vb2_v4l2_buffer *src_buf, *dst_buf; +int ret, i, hw_id =0 ;unsigned long flags; -int ret; +struct mtk_jpeg_ctx *ctx =container_of (work, + struct mtk_jpeg_ctx, + jpeg_work); +struct mtk_jpeg_dev *jpeg = ctx->jpeg; + +for (i =0 ; i <MTK_JPEGENC_HW_MAX ; i++) + comp_jpeg[i] = jpeg->enc_hw_dev[i]; + +retry_select: + hw_id =mtk_jpegenc_get_hw (ctx); +if (hw_id <0 ) { + ret =wait_event_interruptible (jpeg->enc_hw_wq, +atomic_read (&jpeg->enchw_rdy) >0 ); +if (ret !=0 ) { +dev_err (jpeg->dev,"%s : %d, all HW are busy\n" , + __func__, __LINE__); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); +return ; + } + + goto retry_select; + } + +atomic_dec (&jpeg->enchw_rdy); src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); +if (!src_buf) + goto getbuf_fail; + dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx); +if (!dst_buf) + goto getbuf_fail; - ret =pm_runtime_resume_and_get (jpeg->dev); -if (ret <0 ) +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); + +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); + +mtk_jpegenc_set_hw_param (ctx, hw_id, src_buf, dst_buf); + ret =pm_runtime_get_sync (comp_jpeg[hw_id]->dev); +if (ret <0 ) { +dev_err (jpeg->dev,"%s : %d, pm_runtime_get_sync fail !!!\n" , + __func__, __LINE__); goto enc_end; + } -schedule_delayed_work (&jpeg->job_timeout_work, -msecs_to_jiffies (MTK_JPEG_HW_TIMEOUT_MSEC )); + ret =clk_prepare_enable (comp_jpeg[hw_id]->venc_clk.clks->clk); +if (ret) { +dev_err (jpeg->dev,"%s : %d, jpegenc clk_prepare_enable fail\n" , + __func__, __LINE__); + goto enc_end; + } -spin_lock_irqsave (&jpeg->hw_lock, flags); +schedule_delayed_work (&comp_jpeg[hw_id]->job_timeout_work, +msecs_to_jiffies (MTK_JPEG_HW_TIMEOUT_MSEC )); -/* -* Resetting the hardware every frame is to ensure that all the -* registers are cleared. This is a hardware requirement. -*/ -mtk_jpeg_enc_reset (jpeg->reg_base); +spin_lock_irqsave (&comp_jpeg[hw_id]->hw_lock, flags); + jpeg_dst_buf =mtk_jpeg_vb2_to_srcbuf (&dst_buf->vb2_buf); + jpeg_dst_buf->curr_ctx = ctx; + jpeg_dst_buf->frame_num = ctx->total_frame_num; + ctx->total_frame_num++; +mtk_jpeg_enc_reset (comp_jpeg[hw_id]->reg_base); +mtk_jpeg_set_enc_dst (ctx, + comp_jpeg[hw_id]->reg_base, + &dst_buf->vb2_buf); +mtk_jpeg_set_enc_src (ctx, + comp_jpeg[hw_id]->reg_base, + &src_buf->vb2_buf); +mtk_jpeg_set_enc_params (ctx, comp_jpeg[hw_id]->reg_base); +mtk_jpeg_enc_start (comp_jpeg[hw_id]->reg_base); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); +spin_unlock_irqrestore (&comp_jpeg[hw_id]->hw_lock, flags); -mtk_jpeg_set_enc_src (ctx, jpeg->reg_base, &src_buf->vb2_buf); -mtk_jpeg_set_enc_dst (ctx, jpeg->reg_base, &dst_buf->vb2_buf); -mtk_jpeg_set_enc_params (ctx, jpeg->reg_base); -mtk_jpeg_enc_start (jpeg->reg_base); -spin_unlock_irqrestore (&jpeg->hw_lock, flags);return ; enc_end:
@@ -946,9 +1050,58 @@ static void mtk_jpeg_enc_device_run(void *priv)v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state); +getbuf_fail: +atomic_inc (&jpeg->enchw_rdy); +mtk_jpegenc_put_hw (jpeg, hw_id);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } +static void mtk_jpeg_enc_device_run (void *priv) +{ +struct mtk_jpeg_ctx *ctx = priv; +struct mtk_jpeg_dev *jpeg = ctx->jpeg; +struct vb2_v4l2_buffer *src_buf, *dst_buf; +enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ; +unsigned long flags; +int ret; + +if (!jpeg->is_jpgenc_multihw) { + src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); + dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx); + + ret =pm_runtime_resume_and_get (jpeg->dev); +if (ret <0 ) + goto enc_end; + +schedule_delayed_work (&jpeg->job_timeout_work, +msecs_to_jiffies (MTK_JPEG_HW_TIMEOUT_MSEC )); + +spin_lock_irqsave (&jpeg->hw_lock, flags); + +/* +* Resetting the hardware every frame is to ensure that all the +* registers are cleared. This is a hardware requirement. +*/ +mtk_jpeg_enc_reset (jpeg->reg_base); + +mtk_jpeg_set_enc_src (ctx, jpeg->reg_base, &src_buf->vb2_buf); +mtk_jpeg_set_enc_dst (ctx, jpeg->reg_base, &dst_buf->vb2_buf); +mtk_jpeg_set_enc_params (ctx, jpeg->reg_base); +mtk_jpeg_enc_start (jpeg->reg_base); +spin_unlock_irqrestore (&jpeg->hw_lock, flags); +return ; + +enc_end: +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_buf_done (src_buf, buf_state); +v4l2_m2m_buf_done (dst_buf, buf_state); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); + }else { +queue_work (jpeg->workqueue, &ctx->jpeg_work); + } +} +static void mtk_jpeg_dec_device_run (void *priv) {struct mtk_jpeg_ctx *ctx = priv;
@@ -1211,6 +1364,9 @@ static int mtk_jpeg_open(struct file *file) goto free; } +if (jpeg->is_jpgenc_multihw) +INIT_WORK (&ctx->jpeg_work, mtk_jpegenc_worker); +v4l2_fh_init (&ctx->fh, vfd); file->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh);
@@ -1355,6 +1511,18 @@ static int mtk_jpeg_probe(struct platform_device *pdev)dev_err (&pdev->dev,"Failed to init clk\n" ); goto err_clk_init; } + }else { +if (of_property_read_bool (pdev->dev.of_node, +"mediatek,jpegenc-multi-core" )) { +init_waitqueue_head (&jpeg->enc_hw_wq); + jpeg->workqueue =alloc_ordered_workqueue (MTK_JPEG_NAME , +WQ_MEM_RECLAIM + |WQ_FREEZABLE ); +if (!jpeg->workqueue) { + ret = -EINVAL ; + goto err_alloc_workqueue; + } + } } ret =v4l2_device_register (&pdev->dev, &jpeg->v4l2_dev);
@@ -1423,6 +1591,8 @@ static int mtk_jpeg_probe(struct platform_device *pdev) err_clk_init: +err_alloc_workqueue: + err_req_irq:return ret;
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +24 -6
@@ -75,6 +75,11 @@ struct mtk_jpeg_variant {u32 cap_q_default_fourcc; }; +enum mtk_jpeg_hw_state { +MTK_JPEG_HW_IDLE =0 , +MTK_JPEG_HW_BUSY =1 , +}; +struct mtk_jpeg_hw_param {struct vb2_v4l2_buffer *src_buffer;struct vb2_v4l2_buffer *dst_buffer;
@@ -97,12 +102,17 @@ struct mtk_jpegenc_clk {/** * struct mtk_jpegenc_comp_dev - JPEG COREX abstraction -* @dev: JPEG device -* @plat_dev: platform device data -* @reg_base: JPEG registers mapping -* @master_dev: mtk_jpeg_dev device -* @pm: mtk_jpegenc_pm -* @jpegenc_irq: jpeg encode irq num +* @dev: JPEG device +* @plat_dev: platform device data +* @reg_base: JPEG registers mapping +* @master_dev: mtk_jpeg_dev device +* @venc_clk: mtk_jpegenc_clk +* @jpegenc_irq: jpeg encode irq num +* @job_timeout_work: handle jpeg encode work +* @hw_param: record hw param +* @hw_rdy: record hw ready +* @hw_state: record hw state +* @hw_lock: spinlock protecting the hw device resource */ struct mtk_jpegenc_comp_dev {struct device *dev;
@@ -114,6 +124,9 @@ struct mtk_jpegenc_comp_dev {int hw_id;struct delayed_work job_timeout_work;struct mtk_jpeg_hw_param hw_param; +enum mtk_jpeg_hw_state hw_state; +//spinlock protecting the hw device resource +spinlock_t hw_lock; };/**
@@ -146,6 +159,8 @@ struct mtk_jpeg_dev {void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX ];struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX ];bool is_jpgenc_multihw; +wait_queue_head_t enc_hw_wq; +atomic_t enchw_rdy; };/**
@@ -204,6 +219,9 @@ struct mtk_jpeg_ctx {u8 enc_quality;u8 restart_interval;struct v4l2_ctrl_handler ctrl_hdl; + +struct work_struct jpeg_work; + u32 total_frame_num; };#endif /* _MTK_JPEG_CORE_H */
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +27 -12
@@ -192,6 +192,7 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)container_of (dly_work, struct mtk_jpegenc_comp_dev, job_timeout_work); +struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ;struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -202,6 +203,9 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)mtk_jpeg_enc_reset (cjpeg->reg_base);clk_disable_unprepare (cjpeg->venc_clk.clks->clk);pm_runtime_put (cjpeg->dev); + cjpeg->hw_state =MTK_JPEG_HW_IDLE ; +atomic_inc (&master_jpeg->enchw_rdy); +wake_up (&master_jpeg->enc_hw_wq);v4l2_m2m_buf_done (src_buf, buf_state); }
@@ -218,30 +222,37 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)cancel_delayed_work (&jpeg->job_timeout_work); + ctx = jpeg->hw_param.curr_ctx; + src_buf = jpeg->hw_param.src_buffer; + dst_buf = jpeg->hw_param.dst_buffer; +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); + irq_status =readl (jpeg->reg_base +JPEG_ENC_INT_STS ) &JPEG_ENC_INT_STATUS_MASK_ALLIRQ ;if (irq_status)writel (0 , jpeg->reg_base +JPEG_ENC_INT_STS ); -if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) -return IRQ_NONE ; - - ctx =v4l2_m2m_get_curr_priv (master_jpeg->m2m_dev); -if (!ctx) { -v4l2_err (&master_jpeg->v4l2_dev,"Context is NULL\n" ); -return IRQ_HANDLED ; +if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) { +dev_err (jpeg->dev," Not JPEG_ENC_INT_STATUS_DONE\n" ); + goto irq_handled; } - src_buf =v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); - dst_buf =v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); - result_size =mtk_jpeg_enc_get_file_size (jpeg->reg_base);vb2_set_plane_payload (&dst_buf->vb2_buf,0 , result_size); + +irq_handled: buf_state =VB2_BUF_STATE_DONE ;v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state); -v4l2_m2m_job_finish (master_jpeg->m2m_dev, ctx->fh.m2m_ctx);pm_runtime_put (ctx->jpeg->dev); +clk_disable_unprepare (jpeg->venc_clk.clks->clk); +if (!list_empty (&ctx->fh.m2m_ctx->out_q_ctx.rdy_queue) || + !list_empty (&ctx->fh.m2m_ctx->cap_q_ctx.rdy_queue)) { +queue_work (master_jpeg->workqueue, &ctx->jpeg_work); + } + + jpeg->hw_state =MTK_JPEG_HW_IDLE ; +wake_up (&master_jpeg->enc_hw_wq); +atomic_inc (&master_jpeg->enchw_rdy);return IRQ_HANDLED ; }
@@ -294,6 +305,10 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) dev->plat_dev = pdev; dev->dev = &pdev->dev; +atomic_set (&master_dev->enchw_rdy,MTK_JPEGENC_HW_MAX ); +spin_lock_init (&dev->hw_lock); + dev->hw_state =MTK_JPEG_HW_IDLE ; +INIT_DELAYED_WORK (&dev->job_timeout_work, mtk_jpegenc_timeout_work);
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [V10,5/7] mtk-jpegenc: add jpeg encode worker interface
Il 27/06/22 04:56, Irui Wang ha scritto:
Quoted 16 lines
From: kyrie wu <[email protected]>
Add jpeg encoding worker to ensure that two HWs
run in parallel in MT8195.Signed-off-by kyrie wu <[email protected]>--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 208 ++++++++++++++++-- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 30 ++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 39 +++- 3 files changed, 240 insertions(+), 37 deletions(-)drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +0
-0
..snip..
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static void mtk_jpeg_enc_device_run(void *priv) · line 1060
Quoted 12 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +5
-0@@ -946,9 +1050,58 @@ static void mtk_jpeg_enc_device_run(void *priv)v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state); +getbuf_fail: +atomic_inc (&jpeg->enchw_rdy); +mtk_jpegenc_put_hw (jpeg, hw_id);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } +static void mtk_jpeg_enc_device_run (void *priv) +{
That's not really the best thing to do here... if we're managing multi-core hardware, this function would be a one-liner and we would never see variable jpeg->is_jpgenc_multihw changing during runtime.
At this point, we can reduce checks and improve human readability by simply having two separated functions for single-core vs multi-core...
static void mtk_jpeg_singlecore_enc_dev_run(void *priv) { .... blah .... }
and
static void mtk_jpeg_multicore_enc_dev_run(void *priv)
{
struct mtk_jpeg_ctx *ctx = priv;
queue_work(ctx->jpeg->workqueue, &ctx->jpeg_work);
}Also because we're defining .m2m_ops into mt8195_jpegenc_drvdata, so it's going to be as trivial as defining a new m2m_ops for it:
static const struct v4l2_m2m_ops mtk_jpeg_multicore_enc_m2m_ops = {
.device_run = mtk_jpeg_multicore_enc_dev_run,
};
Please fix that :-)
Quoted 58 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +47
-0+struct mtk_jpeg_ctx *ctx = priv; +struct mtk_jpeg_dev *jpeg = ctx->jpeg; +struct vb2_v4l2_buffer *src_buf, *dst_buf; +enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ; +unsigned long flags; +int ret; + +if (!jpeg->is_jpgenc_multihw) { + src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); + dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx); + + ret =pm_runtime_resume_and_get (jpeg->dev); +if (ret <0 ) + goto enc_end; + +schedule_delayed_work (&jpeg->job_timeout_work, +msecs_to_jiffies (MTK_JPEG_HW_TIMEOUT_MSEC )); + +spin_lock_irqsave (&jpeg->hw_lock, flags); + +/* +* Resetting the hardware every frame is to ensure that all the +* registers are cleared. This is a hardware requirement. +*/ +mtk_jpeg_enc_reset (jpeg->reg_base); + +mtk_jpeg_set_enc_src (ctx, jpeg->reg_base, &src_buf->vb2_buf); +mtk_jpeg_set_enc_dst (ctx, jpeg->reg_base, &dst_buf->vb2_buf); +mtk_jpeg_set_enc_params (ctx, jpeg->reg_base); +mtk_jpeg_enc_start (jpeg->reg_base); +spin_unlock_irqrestore (&jpeg->hw_lock, flags); +return ; + +enc_end: +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_buf_done (src_buf, buf_state); +v4l2_m2m_buf_done (dst_buf, buf_state); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); + }else { +queue_work (jpeg->workqueue, &ctx->jpeg_work); + } +} +static void mtk_jpeg_dec_device_run (void *priv) {struct mtk_jpeg_ctx *ctx = priv;@@ -1211,6 +1364,9 @@ static int mtk_jpeg_open(struct file *file) goto free; } +if (jpeg->is_jpgenc_multihw) +INIT_WORK (&ctx->jpeg_work, mtk_jpegenc_worker); +v4l2_fh_init (&ctx->fh, vfd); file->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static int mtk_jpeg_probe(struct platform_device *pdev) · line 1516
Quoted 6 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +3
-0@@ -1355,6 +1511,18 @@ static int mtk_jpeg_probe(struct platform_device *pdev)dev_err (&pdev->dev,"Failed to init clk\n" ); goto err_clk_init; } + }else { +if (of_property_read_bool (pdev->dev.of_node, +"mediatek,jpegenc-multi-core" )) {
This check is redundant (and will be wrong in the jpegdec series): you're entering this branch only if (jpeg->is_jpgenc_multihw), and this is initialized a little earlier when reading the very same devicetree property.
So, for this series, remove the redundant check; for the jpegdec series, don't recheck with of_property_read_bool, but check for if (jpeg->is_jpgenc_multihw) and then theck for if (jpeg->is_jpgdec_multihw).
Quoted 13 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +9
-0+init_waitqueue_head (&jpeg->enc_hw_wq); + jpeg->workqueue =alloc_ordered_workqueue (MTK_JPEG_NAME , +WQ_MEM_RECLAIM + |WQ_FREEZABLE ); +if (!jpeg->workqueue) { + ret = -EINVAL ; + goto err_alloc_workqueue; + } + } } ret =v4l2_device_register (&pdev->dev, &jpeg->v4l2_dev);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static int mtk_jpeg_probe(struct platform_device *pdev) · line 1595
Quoted 5 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +2
-0@@ -1423,6 +1591,8 @@ static int mtk_jpeg_probe(struct platform_device *pdev) err_clk_init: +err_alloc_workqueue: +
You aren't doing anything at all here, so this label is not required. Remove it.
Quoted 106 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +0
-0err_req_irq:return ret;drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +24
-6@@ -75,6 +75,11 @@ struct mtk_jpeg_variant {u32 cap_q_default_fourcc; }; +enum mtk_jpeg_hw_state { +MTK_JPEG_HW_IDLE =0 , +MTK_JPEG_HW_BUSY =1 , +}; +struct mtk_jpeg_hw_param {struct vb2_v4l2_buffer *src_buffer;struct vb2_v4l2_buffer *dst_buffer;@@ -97,12 +102,17 @@ struct mtk_jpegenc_clk {/** * struct mtk_jpegenc_comp_dev - JPEG COREX abstraction -* @dev: JPEG device -* @plat_dev: platform device data -* @reg_base: JPEG registers mapping -* @master_dev: mtk_jpeg_dev device -* @pm: mtk_jpegenc_pm -* @jpegenc_irq: jpeg encode irq num +* @dev: JPEG device +* @plat_dev: platform device data +* @reg_base: JPEG registers mapping +* @master_dev: mtk_jpeg_dev device +* @venc_clk: mtk_jpegenc_clk +* @jpegenc_irq: jpeg encode irq num +* @job_timeout_work: handle jpeg encode work +* @hw_param: record hw param +* @hw_rdy: record hw ready +* @hw_state: record hw state +* @hw_lock: spinlock protecting the hw device resource */ struct mtk_jpegenc_comp_dev {struct device *dev;@@ -114,6 +124,9 @@ struct mtk_jpegenc_comp_dev {int hw_id;struct delayed_work job_timeout_work;struct mtk_jpeg_hw_param hw_param; +enum mtk_jpeg_hw_state hw_state; +//spinlock protecting the hw device resource +spinlock_t hw_lock; };/** @@ -146,6 +159,8 @@ struct mtk_jpeg_dev {void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX ];struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX ];bool is_jpgenc_multihw; +wait_queue_head_t enc_hw_wq; +atomic_t enchw_rdy; };/** @@ -204,6 +219,9 @@ struct mtk_jpeg_ctx {u8 enc_quality;u8 restart_interval;struct v4l2_ctrl_handler ctrl_hdl; + +struct work_struct jpeg_work; + u32 total_frame_num; };#endif /* _MTK_JPEG_CORE_H */ drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +9
-0@@ -192,6 +192,7 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)container_of (dly_work, struct mtk_jpegenc_comp_dev, job_timeout_work); +struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ;struct vb2_v4l2_buffer *src_buf, *dst_buf;@@ -202,6 +203,9 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)mtk_jpeg_enc_reset (cjpeg->reg_base);clk_disable_unprepare (cjpeg->venc_clk.clks->clk);pm_runtime_put (cjpeg->dev); + cjpeg->hw_state =MTK_JPEG_HW_IDLE ; +atomic_inc (&master_jpeg->enchw_rdy); +wake_up (&master_jpeg->enc_hw_wq);v4l2_m2m_buf_done (src_buf, buf_state); }@@ -218,30 +222,37 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)cancel_delayed_work (&jpeg->job_timeout_work); + ctx = jpeg->hw_param.curr_ctx; + src_buf = jpeg->hw_param.src_buffer; + dst_buf = jpeg->hw_param.dst_buffer; +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); + irq_status =readl (jpeg->reg_base +JPEG_ENC_INT_STS ) &JPEG_ENC_INT_STATUS_MASK_ALLIRQ ;if (irq_status)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) · line 235
Quoted 10 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +2
-7writel (0 , jpeg->reg_base +JPEG_ENC_INT_STS ); -if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) -return IRQ_NONE ; - - ctx =v4l2_m2m_get_curr_priv (master_jpeg->m2m_dev); -if (!ctx) { -v4l2_err (&master_jpeg->v4l2_dev,"Context is NULL\n" ); -return IRQ_HANDLED ; +if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) { +dev_err (jpeg->dev," Not JPEG_ENC_INT_STATUS_DONE\n" );
Please be more descriptive in error messages. Also, should this really be a dev_err?!?
Quoted 39 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +16
-5+ goto irq_handled; } - src_buf =v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); - dst_buf =v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); - result_size =mtk_jpeg_enc_get_file_size (jpeg->reg_base);vb2_set_plane_payload (&dst_buf->vb2_buf,0 , result_size); + +irq_handled: buf_state =VB2_BUF_STATE_DONE ;v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state); -v4l2_m2m_job_finish (master_jpeg->m2m_dev, ctx->fh.m2m_ctx);pm_runtime_put (ctx->jpeg->dev); +clk_disable_unprepare (jpeg->venc_clk.clks->clk); +if (!list_empty (&ctx->fh.m2m_ctx->out_q_ctx.rdy_queue) || + !list_empty (&ctx->fh.m2m_ctx->cap_q_ctx.rdy_queue)) { +queue_work (master_jpeg->workqueue, &ctx->jpeg_work); + } + + jpeg->hw_state =MTK_JPEG_HW_IDLE ; +wake_up (&master_jpeg->enc_hw_wq); +atomic_inc (&master_jpeg->enchw_rdy);return IRQ_HANDLED ; }@@ -294,6 +305,10 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) dev->plat_dev = pdev; dev->dev = &pdev->dev; +atomic_set (&master_dev->enchw_rdy,MTK_JPEGENC_HW_MAX ); +spin_lock_init (&dev->hw_lock); + dev->hw_state =MTK_JPEG_HW_IDLE ; +INIT_DELAYED_WORK (&dev->job_timeout_work, mtk_jpegenc_timeout_work);
Re: [V10,5/7] mtk-jpegenc: add jpeg encode worker interface
Quoted 62 lines · AngeloGioacchino Del Regno
Il 27/06/22 04:56, Irui Wang ha scritto:
Quoted 18 lines
From: kyrie wu <[email protected]>
Add jpeg encoding worker to ensure that two HWs
run in parallel in MT8195.Signed-off-by kyrie wu <[email protected]>--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 208 ++++++++++++++++-- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 30 ++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 39 +++- 3 files changed, 240 insertions(+), 37 deletions(-)drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +0
-0..snip..
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static void mtk_jpeg_enc_device_run(void · line 1061
Quoted 13 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +5
-0@@ -946,9 +1050,58 @@ static void mtk_jpeg_enc_device_run(void *priv)v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state); +getbuf_fail: +atomic_inc (&jpeg->enchw_rdy); +mtk_jpegenc_put_hw (jpeg, hw_id);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } +static void mtk_jpeg_enc_device_run (void *priv) +{That's not really the best thing to do here... if we're managing multi-core
hardware, this function would be a one-liner and we would never see variablejpeg->is_jpgenc_multihwchanging during runtime.At this point, we can reduce checks and improve human readability by simply
having two separated functions for single-core vs multi-core...static void
mtk_jpeg_singlecore_enc_dev_run(void *priv){ .... blah .... }and
static void
mtk_jpeg_multicore_enc_dev_run(void *priv){ struct mtk_jpeg_ctx *ctx = priv; queue_work(ctx->jpeg->workqueue, &ctx->jpeg_work); }Also because we're defining
.m2m_opsintomt8195_jpegenc_drvdata, so it's
going to be as trivial as defining a newm2m_opsfor it:
Quoted 7 lines
static const struct
v4l2_m2m_opsmtk_jpeg_multicore_enc_m2m_ops= {.device_run =
mtk_jpeg_multicore_enc_dev_run,};
Please fix that :-)
Hello Angelo,
Thanks for your kind guidances, I will take your suggestion to fix it.
Kyrie.
Quoted 79 lines
Quoted 64 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +22
-0+struct mtk_jpeg_ctx *ctx = priv; +struct mtk_jpeg_dev *jpeg = ctx->jpeg; +struct vb2_v4l2_buffer *src_buf, *dst_buf; +enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ; +unsigned long flags; +int ret; + +if (!jpeg->is_jpgenc_multihw) { + src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); + dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx); + + ret =pm_runtime_resume_and_get (jpeg->dev); +if (ret <0 ) + goto enc_end; + +schedule_delayed_work (&jpeg->job_timeout_work, +msecs_to_jiffies (MTK_JPEG_HW_TIME OUT_MSEC)); + +spin_lock_irqsave (&jpeg->hw_lock, flags); + +/* +* Resetting the hardware every frame is to ensure that all the
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-0+* registers are cleared. This is a hardware requirement.
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4
-0+*/ +mtk_jpeg_enc_reset (jpeg->reg_base); + + mtk_jpeg_set_enc_src(ctx, jpeg->reg_base, &src_buf-Quoted 1 line
vb2_buf);drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-0+ mtk_jpeg_set_enc_dst(ctx, jpeg->reg_base, &dst_buf-Quoted 1 line
vb2_buf);drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +19
-0+mtk_jpeg_set_enc_params (ctx, jpeg->reg_base); +mtk_jpeg_enc_start (jpeg->reg_base); +spin_unlock_irqrestore (&jpeg->hw_lock, flags); +return ; + +enc_end: +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_buf_done (src_buf, buf_state); +v4l2_m2m_buf_done (dst_buf, buf_state); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); + }else { +queue_work (jpeg->workqueue, &ctx->jpeg_work); + } +} +static void mtk_jpeg_dec_device_run (void *priv) {struct mtk_jpeg_ctx *ctx = priv;@@ -1211,6 +1364,9 @@ static int mtk_jpeg_open(struct file *file) goto free; } +if (jpeg->is_jpgenc_multihw) +INIT_WORK (&ctx->jpeg_work, mtk_jpegenc_worker); +v4l2_fh_init (&ctx->fh, vfd); file->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh);drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static int mtk_jpeg_probe(struct · line 1518
Quoted 8 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +3
-0@@ -1355,6 +1511,18 @@ static int mtk_jpeg_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to init clk\n"); goto err_clk_init; } + }else { +if (of_property_read_bool (pdev->dev.of_node, +"mediatek,jpegenc-multi- core")) {This check is redundant (and will be wrong in the jpegdec series):
you're entering
this branch onlyif (jpeg->is_jpgenc_multihw), and this is initialized a little
earlier when reading the very same devicetree property.
Quoted 5 lines
So, for this series, remove the redundant check; for the jpegdec series, don't
recheck withof_property_read_bool, but check for `if (jpeg-Quoted 1 line
is_jpgenc_multihw)`
and then theck for
if (jpeg->is_jpgdec_multihw).
This check will be removed, and I will take a new operations. thanks.
Quoted 19 lines
Quoted 19 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +2
-0+init_waitqueue_head (&jpeg->enc_hw_wq); + jpeg->workqueue =alloc_ordered_workqueue(MTK_JPEG_NAME,
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-0+WQ_ME
M_RECLAIMdrivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-0+ |
WQ_FREEZABLE);drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +5
-0+if (!jpeg->workqueue) { + ret = -EINVAL ; + goto err_alloc_workqueue; + } + } } ret =v4l2_device_register (&pdev->dev, &jpeg->v4l2_dev);@@ -1423,6 +1591,8 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
Quoted 7 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static int mtk_jpeg_probe(struct platform_device *pdev) · line 1595
Quoted 4 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +2
-0err_clk_init: +err_alloc_workqueue: +You aren't doing anything at all here, so this label is not required. Remove it.
OK, thanks.
Quoted 119 lines
Quoted 119 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +0
-0err_req_irq:return ret;
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +16
-6@@ -75,6 +75,11 @@ struct mtk_jpeg_variant {u32 cap_q_default_fourcc; }; +enum mtk_jpeg_hw_state { +MTK_JPEG_HW_IDLE =0 , +MTK_JPEG_HW_BUSY =1 , +}; +struct mtk_jpeg_hw_param {struct vb2_v4l2_buffer *src_buffer;struct vb2_v4l2_buffer *dst_buffer;@@ -97,12 +102,17 @@ struct mtk_jpegenc_clk {/** * struct mtk_jpegenc_comp_dev - JPEG COREX abstraction -* @dev: JPEG device -* @plat_dev: platform device data -* @reg_base: JPEG registers mapping -* @master_dev: mtk_jpeg_dev device -* @pm: mtk_jpegenc_pm -* @jpegenc_irq: jpeg encode irq num +* @dev: JPEG device +* @plat_dev: platform device data +* @reg_base: JPEG registers mapping +* @master_dev: mtk_jpeg_dev device +* @venc_clk: mtk_jpegenc_clk +* @jpegenc_irq: jpeg encode irq num +* @job_timeout_work: handle jpeg encode work +* @hw_param: record hw param +* @hw_rdy: record hw ready +* @hw_state: record hw state +* @hw_lock: spinlock protecting the hw device resource
*/
structmtk_jpegenc_comp_dev{
struct device *dev;drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +8
-0@@ -114,6 +124,9 @@ struct mtk_jpegenc_comp_dev {int hw_id;struct delayed_work job_timeout_work;struct mtk_jpeg_hw_param hw_param; +enum mtk_jpeg_hw_state hw_state; +//spinlock protecting the hw device resource +spinlock_t hw_lock; };/** @@ -146,6 +159,8 @@ struct mtk_jpeg_dev {void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX ];struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX ];bool is_jpgenc_multihw; +wait_queue_head_t enc_hw_wq; +atomic_t enchw_rdy; };/** @@ -204,6 +219,9 @@ struct mtk_jpeg_ctx {u8 enc_quality;u8 restart_interval;struct v4l2_ctrl_handler ctrl_hdl; + +struct work_struct jpeg_work; + u32 total_frame_num; };#endif /* _MTK_JPEG_CORE_H */ drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +9
-5@@ -192,6 +192,7 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)container_of (dly_work ,struct mtk_jpegenc_comp_dev ,job_timeout_work ); +struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ;struct vb2_v4l2_buffer *src_buf, *dst_buf;@@ -202,6 +203,9 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work) mtk_jpeg_enc_reset(cjpeg->reg_base);clk_disable_unprepare (cjpeg->venc_clk.clks->clk);pm_runtime_put (cjpeg->dev); + cjpeg->hw_state =MTK_JPEG_HW_IDLE ; +atomic_inc (&master_jpeg->enchw_rdy); +wake_up (&master_jpeg->enc_hw_wq);v4l2_m2m_buf_done (src_buf, buf_state); }@@ -218,30 +222,37 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) cancel_delayed_work(&jpeg->job_timeout_work); + ctx = jpeg->hw_param.curr_ctx; + src_buf = jpeg->hw_param.src_buffer; + dst_buf = jpeg->hw_param.dst_buffer; +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); + irq_status =readl (jpeg->reg_base +JPEG_ENC_INT_STS ) &JPEG_ENC_INT_STATUS_MASK_ALLIRQ ;if (irq_status)writel (0 , jpeg->reg_base +JPEG_ENC_INT_STS ); -if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) -return IRQ_NONE ; - - ctx =v4l2_m2m_get_curr_priv (master_jpeg->m2m_dev); -if (!ctx) {
Quoted 8 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) · line 235
Quoted 4 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +2
-2-v4l2_err (&master_jpeg->v4l2_dev,"Context is NULL\n" ); -return IRQ_HANDLED ; +if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) { +dev_err (jpeg->dev," Not JPEG_ENC_INT_STATUS_DONE\n" );Please be more descriptive in error messages. Also, should this really be
adev_err?!?
maybe dev_warn is right, I will fix it.
Quoted 43 lines
Quoted 41 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +12
-5+ goto irq_handled; } - src_buf =v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); - dst_buf =v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); - result_size =mtk_jpeg_enc_get_file_size (jpeg->reg_base);vb2_set_plane_payload (&dst_buf->vb2_buf,0 , result_size); + +irq_handled: buf_state =VB2_BUF_STATE_DONE ;v4l2_m2m_buf_done (src_buf, buf_state);v4l2_m2m_buf_done (dst_buf, buf_state); -v4l2_m2m_job_finish (master_jpeg->m2m_dev, ctx->fh.m2m_ctx);pm_runtime_put (ctx->jpeg->dev); +clk_disable_unprepare (jpeg->venc_clk.clks->clk); +if (!list_empty (&ctx->fh.m2m_ctx->out_q_ctx.rdy_queue) || + !list_empty (&ctx->fh.m2m_ctx->cap_q_ctx.rdy_queue)) { +queue_work (master_jpeg->workqueue, &ctx->jpeg_work); + } + + jpeg->hw_state =MTK_JPEG_HW_IDLE ; +wake_up (&master_jpeg->enc_hw_wq); +atomic_inc (&master_jpeg->enchw_rdy);return IRQ_HANDLED ;}drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +4
-0@@ -294,6 +305,10 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) dev->plat_dev = pdev; dev->dev = &pdev->dev; +atomic_set (&master_dev->enchw_rdy,MTK_JPEGENC_HW_MAX ); +spin_lock_init (&dev->hw_lock); + dev->hw_state =MTK_JPEG_HW_IDLE ; +INIT_DELAYED_WORK (&dev->job_timeout_work, mtk_jpegenc_timeout_work);
AngeloGioacchino Del Regno
maintainerRe: [V10,5/7] mtk-jpegenc: add jpeg encode worker interface
Il 14/07/22 10:51, kyrie.wu ha scritto:
Quoted 23 lines · AngeloGioacchino Del Regno
Quoted 22 lines
Il 27/06/22 04:56, Irui Wang ha scritto:
Quoted 18 lines
From: kyrie wu <[email protected]>
Add jpeg encoding worker to ensure that two HWs
run in parallel in MT8195.Signed-off-by kyrie wu <[email protected]>--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 208 ++++++++++++++++-- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 30 ++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 39 +++- 3 files changed, 240 insertions(+), 37 deletions(-)drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +0
-0..snip..
..snip..
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +5
-5@@ -218,30 +222,37 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) cancel_delayed_work(&jpeg->job_timeout_work); + ctx = jpeg->hw_param.curr_ctx; + src_buf = jpeg->hw_param.src_buffer; + dst_buf = jpeg->hw_param.dst_buffer; +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); + irq_status =readl (jpeg->reg_base +JPEG_ENC_INT_STS ) &JPEG_ENC_INT_STATUS_MASK_ALLIRQ ;if (irq_status)writel (0 , jpeg->reg_base +JPEG_ENC_INT_STS ); -if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) -return IRQ_NONE ; - - ctx =v4l2_m2m_get_curr_priv (master_jpeg->m2m_dev); -if (!ctx) {Quoted 8 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static irqreturn_t · line 236
Quoted 4 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +2
-2-v4l2_err (&master_jpeg->v4l2_dev,"Context is NULL\n" ); -return IRQ_HANDLED ; +if (!(irq_status &JPEG_ENC_INT_STATUS_DONE )) { +dev_err (jpeg->dev," Not JPEG_ENC_INT_STATUS_DONE\n" );Please be more descriptive in error messages. Also, should this really be
adev_err?!?
Quoted 2 lines
maybe
dev_warnis right, I will fix it.
I think that v4l2_err() would be more appropriate.
Regards,
Angelo
PATCH v10 6/7 mtk-jpegenc: add output pic reorder interface
In reply to Irui WangFrom: kyrie wu <[email protected]>
There are two HWs in mt8195. Since the two HWs run in parallel, it is necessary to reorder the output images to ensure that the order is consistent with the input images.
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 11 +---- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 18 ++++++- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 1 + .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.h | 3 +- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 48 ++++++++++++++++++- 5 files changed, 68 insertions(+), 13 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +2 -9
@@ -110,15 +110,6 @@ enum { MTK_JPEG_BUF_FLAGS_LAST_FRAME = 1, }; -struct mtk_jpeg_src_buf { -u32 frame_num; -struct vb2_v4l2_buffer b; -struct list_head list; -struct mtk_jpeg_dec_param dec_param; - -struct mtk_jpeg_ctx *curr_ctx; -}; -static int debug;module_param (debug, int,0644 );
@@ -1367,6 +1358,8 @@ static int mtk_jpeg_open(struct file *file)if (jpeg->is_jpgenc_multihw)INIT_WORK (&ctx->jpeg_work, mtk_jpegenc_worker); +INIT_LIST_HEAD (&ctx->dst_done_queue); +spin_lock_init (&ctx->done_queue_lock);v4l2_fh_init (&ctx->fh, vfd); file->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +16 -2
@@ -14,10 +14,11 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-fh.h> +#include <media/videobuf2-v4l2.h> -#define MTK_JPEG_NAME "mtk-jpeg" +#include "mtk_jpeg_dec_hw.h" -#define MTK_JPEG_COMP_MAX 3 +#define MTK_JPEG_NAME "mtk-jpeg"#define MTK_JPEG_FMT_FLAG_OUTPUT BIT(0)#define MTK_JPEG_FMT_FLAG_CAPTURE BIT(1)
@@ -75,6 +76,15 @@ struct mtk_jpeg_variant {u32 cap_q_default_fourcc; }; +struct mtk_jpeg_src_buf { +u32 frame_num; +struct vb2_v4l2_buffer b; +struct list_head list; +struct mtk_jpeg_dec_param dec_param; + +struct mtk_jpeg_ctx *curr_ctx; +}; +enum mtk_jpeg_hw_state {MTK_JPEG_HW_IDLE =0 ,MTK_JPEG_HW_BUSY =1 ,
@@ -222,6 +232,10 @@ struct mtk_jpeg_ctx {struct work_struct jpeg_work;u32 total_frame_num; +struct list_head dst_done_queue; +//spinlock protecting the encode done buffer +spinlock_t done_queue_lock; + u32 last_done_frame_num; };#endif /* _MTK_JPEG_CORE_H */
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +1 -0
@@ -9,6 +9,7 @@#include <linux/kernel.h> #include <media/videobuf2-core.h> +#include "mtk_jpeg_core.h" #include "mtk_jpeg_dec_hw.h" #define MTK_JPEG_DUNUM_MASK (val) (((val) - 1) & 0x3)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.h +2 -1
@@ -11,9 +11,10 @@#include <media/videobuf2-core.h> -#include "mtk_jpeg_core.h" #include "mtk_jpeg_dec_reg.h" +#define MTK_JPEG_COMP_MAX 3 +enum {MTK_JPEG_DEC_RESULT_EOF_DONE =0 ,MTK_JPEG_DEC_RESULT_PAUSE =1 ,
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +47 -1
66 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v10 7/7 mtk-jpegenc: add stop cmd interface for jpgenc
In reply to Irui WangFrom: kyrie wu <[email protected]>
Add stop cmd interface for jpgenc to stop stream
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4 -0
@@ -612,6 +612,9 @@ static const struct v4l2_ioctl_ops mtk_jpeg_enc_ioctl_ops = { .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, + + .vidioc_encoder_cmd = v4l2_m2m_ioctl_encoder_cmd, + .vidioc_try_encoder_cmd = v4l2_m2m_ioctl_try_encoder_cmd, };static const struct v4l2_ioctl_ops mtk_jpeg_dec_ioctl_ops = {
@@ -1381,6 +1384,7 @@ static int mtk_jpeg_open(struct file *file) }else {v4l2_ctrl_handler_init (&ctx->ctrl_hdl,0 ); } +mtk_jpeg_set_default_params (ctx);mutex_unlock (&jpeg->lock);return 0 ;
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerIl 27/06/22 04:56, Irui Wang ha scritto:
Quoted 9 lines
From: kyrie wu <[email protected]>
This series adds support for multi hardware jpeg encoding, by first adding use
of_platform_populateto manage each hardware information:
interrupt, clock, register bases and power. Secondly add encoding work queue to deal with the encoding requestsof multi-hardware at the same time. Lastly, add output picture reorder function interface to eliminate the out of order images.
Quoted 3 lines
This series has been tested with MT8195 Gstreamer. Encoding worked for this chip.
Hello Irui,
Unfortunately, I can't reproduce your successful test with gstreamer: when I try to encode a jpeg with videotestsrc input, I get a kernel panic.
To reproduce this behavior, please run the following:
gst-launch-1.0 videotestsrc ! v4l2jpegenc ! filesink location=hwenctest.jpg
Here's the panic log:
[ 342.567211] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000108
[ 342.576014] Mem abort info:
[ 342.578805] ESR = 0x0000000096000004
[ 342.582552] EC = 0x25: DABT (current EL), IL = 32 bits
[ 342.587863] SET = 0, FnV = 0
[ 342.590919] EA = 0, S1PTW = 0
[ 342.594062] FSC = 0x04: level 0 translation fault
[ 342.598941] Data abort info:
[ 342.601826] ISV = 0, ISS = 0x00000004
[ 342.605668] CM = 0, WnR = 0
[ 342.608643] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000119029000
[ 342.615094] [0000000000000108] pgd=0000000000000000, p4d=0000000000000000
[ 342.621907] Internal error: Oops: 96000004 [#1] SMP
[ 342.626800] Modules linked in: cdc_ether usbnet r8152 af_alg qrtr mt7921e mt7921_common mt76_connac_lib mt76 mac80211 btusb btrtl btintel btmtk btbcm bluetooth cfg80211 mtk_vcodec_dec_hw uvcvideo snd_sof_mt8195 ecdh_generic mtk_vcodec_dec ecc mtk_adsp_common videobuf2_vmalloc snd_sof_xtensa_dsp rfkill snd_sof_of v4l2_vp9 panfrost mtk_jpeg snd_sof v4l2_h264 mtk_jpeg_enc_hw 8021q mtk_vcodec_common cros_ec_sensors gpu_sched cros_ec_lid_angle mtk_jpeg_dec_hw hid_multitouch snd_sof_utils cros_ec_sensors_core crct10dif_ce garp cros_usbpd_logger sbs_battery mrp stp llc ipmi_devintf ipmi_msghandler fuse ipv6
[ 342.680332] CPU: 3 PID: 180 Comm: kworker/u16:6 Tainted: G W 5.19.0-rc3-next-20220622+ #814
[ 342.689982] Hardware name: MediaTek Tomato (rev2) board (DT)
[ 342.695637] Workqueue: mtk-jpeg mtk_jpegenc_worker [mtk_jpeg]
[ 342.701402] pstate: 604000c9 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 342.708360] pc : mtk_jpegenc_worker+0x6c/0x3e0 [mtk_jpeg]
[ 342.713763] lr : mtk_jpegenc_worker+0x64/0x3e0 [mtk_jpeg]
[ 342.719166] sp : ffff8000093cbcd0
[ 342.722478] x29: ffff8000093cbcd0 x28: ffffb1f341cdb000 x27: ffff6089885d0505
[ 342.729618] x26: ffffb1f341ce1ee0 x25: ffffb1f341d0a2d0 x24: ffff60899078d000
[ 342.736758] x23: ffffb1f2e869c590 x22: ffff608990785458 x21: ffff60898a0ea120
[ 342.743898] x20: ffff60898a0ea080 x19: ffff60898a0ea080 x18: 0000000000000000
[ 342.751038] x17: 0000000000000000 x16: ffffb1f3405a58c0 x15: 0000aaaac092a3d0
[ 342.758178] x14: 0000000000000000 x13: 0000000000000c5f x12: 071c71c71c71c71c
[ 342.765318] x11: 0000000000000c5f x10: 00000000000027a0 x9 : ffffb1f33f32ce9c
[ 342.772458] x8 : fefefefefefefeff x7 : 0000000000000018 x6 : ffffb1f2e8699804
[ 342.779597] x5 : 0000000000000000 x4 : 0000000000000001 x3 : ffff608985d3c570
[ 342.786737] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000
[ 342.793876] Call trace:
[ 342.796319] mtk_jpegenc_worker+0x6c/0x3e0 [mtk_jpeg]
[ 342.801376] process_one_work+0x294/0x664
[ 342.805392] worker_thread+0x7c/0x45c
[ 342.809055] kthread+0x104/0x110
[ 342.812283] ret_from_fork+0x10/0x20
[ 342.815863] Code: aa1503e0 9400037e f9415662 aa0003e1 (b9410840)
[ 342.821956] ---[ end trace 0000000000000000 ]---
Regards,
Angelo
AngeloGioacchino Del Regno
maintainerIl 05/07/22 14:56, AngeloGioacchino Del Regno ha scritto:
Quoted 14 lines
Il 27/06/22 04:56, Irui Wang ha scritto:
Quoted 9 lines
From: kyrie wu <[email protected]>
This series adds support for multi hardware jpeg encoding, by first adding use
of_platform_populateto manage each hardware information:
interrupt, clock, register bases and power. Secondly add encoding work queue to deal with the encoding requestsof multi-hardware at the same time. Lastly, add output picture reorder function interface to eliminate the out of order images.Quoted 3 lines
This series has been tested with MT8195 Gstreamer. Encoding worked for this chip.
Quoted 10 lines
Hello Irui,
Unfortunately, I can't reproduce your successful test with gstreamer: when I try to encode a jpeg with videotestsrc input, I get a kernel panic.
To reproduce this behavior, please run the following:
gst-launch-1.0 videotestsrc ! v4l2jpegenc ! filesink location=hwenctest.jpg
Adding context: I've just discovered that this issue is due to a little overlook in the probe function, which I've pointed out in the review for the specific patch that's introducing the typo.
After fixing a one-liner, there's no more kernel panic, but another issue was discovered regarding runtime PM:
[ 184.309766] mtk-jpeg soc:jpgenc_master: Runtime PM usage count underflow!
[ 184.317970] mtk-jpeg soc:jpgenc_master: Runtime PM usage count underflow!
[ 184.326128] mtk-jpeg soc:jpgenc_master: Runtime PM usage count underflow!
Quoted 83 lines
Here's the panic log:
[ 342.567211] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000108
[ 342.576014] Mem abort info:
[ 342.578805] ESR =
0x0000000096000004[ 342.582552] EC =
0x25: DABT (current EL), IL = 32 bits[ 342.587863] SET = 0, FnV = 0
[ 342.590919] EA = 0, S1PTW = 0
[ 342.594062] FSC =
0x04: level 0 translation fault[ 342.598941] Data abort info:
[ 342.601826] ISV = 0, ISS =
0x00000004[ 342.605668] CM = 0, WnR = 0
[ 342.608643] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000119029000
[ 342.615094] [0000000000000108] pgd=0000000000000000, p4d=0000000000000000
[ 342.621907] Internal error: Oops: 96000004 [#1] SMP
[ 342.626800] Modules linked in:
cdc_etherusbnet r8152af_algqrtr mt7921emt7921_commonmt76_connac_libmt76 mac80211 btusb btrtl btintel btmtk btbcm bluetooth cfg80211mtk_vcodec_dec_hwuvcvideosnd_sof_mt8195ecdh_genericmtk_vcodec_dececcmtk_adsp_commonvideobuf2_vmallocsnd_sof_xtensa_dsprfkillsnd_sof_ofv4l2_vp9panfrostmtk_jpegsnd_sofv4l2_h264mtk_jpeg_enc_hw8021qmtk_vcodec_commoncros_ec_sensorsgpu_schedcros_ec_lid_anglemtk_jpeg_dec_hwhid_multitouchsnd_sof_utilscros_ec_sensors_corecrct10dif_cegarpcros_usbpd_loggersbs_batterymrp stp llcipmi_devintfipmi_msghandlerfuse ipv6[ 342.680332] CPU: 3 PID: 180 Comm: kworker/u16:6 Tainted: G W 5.19.0-rc3-next-20220622+ #814
[ 342.689982] Hardware name: MediaTek Tomato (rev2) board (DT)
[ 342.695637] Workqueue: mtk-jpeg
mtk_jpegenc_worker[mtk_jpeg][ 342.701402] pstate:
604000c9(nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)[ 342.708360] pc :
mtk_jpegenc_worker+0x6c/0x3e0[mtk_jpeg][ 342.713763] lr :
mtk_jpegenc_worker+0x64/0x3e0[mtk_jpeg][ 342.719166] sp :
ffff8000093cbcd0[ 342.722478] x29:
ffff8000093cbcd0x28:ffffb1f341cdb000x27:ffff6089885d0505[ 342.729618] x26:
ffffb1f341ce1ee0x25:ffffb1f341d0a2d0x24:ffff60899078d000[ 342.736758] x23:
ffffb1f2e869c590x22:ffff608990785458x21:ffff60898a0ea120[ 342.743898] x20:
ffff60898a0ea080x19:ffff60898a0ea080x18: 0000000000000000[ 342.751038] x17: 0000000000000000 x16:
ffffb1f3405a58c0x15:0000aaaac092a3d0[ 342.758178] x14: 0000000000000000 x13:
0000000000000c5fx12:071c71c71c71c71c[ 342.765318] x11:
0000000000000c5fx10:00000000000027a0x9 :ffffb1f33f32ce9c[ 342.772458] x8 : fefefefefefefeff x7 : 0000000000000018 x6 :
ffffb1f2e8699804[ 342.779597] x5 : 0000000000000000 x4 : 0000000000000001 x3 :
ffff608985d3c570[ 342.786737] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000
[ 342.793876] Call trace:
[ 342.796319]
mtk_jpegenc_worker+0x6c/0x3e0[mtk_jpeg][ 342.801376]
process_one_work+0x294/0x664[ 342.805392]
worker_thread+0x7c/0x45c[ 342.809055]
kthread+0x104/0x110[ 342.812283]
ret_from_fork+0x10/0x20[ 342.815863] Code:
aa1503e09400037ef9415662aa0003e1(b9410840)[ 342.821956] ---[ end trace 0000000000000000 ]---
Regards,
Angelo
Quoted 134 lines · AngeloGioacchino Del Regno
Il 27/06/22 04:56, Irui Wang ha scritto:
Quoted 10 lines
From: kyrie wu <[email protected]>
This series adds support for multi hardware jpeg encoding, by first adding use
of_platform_populateto manage each hardware information:
interrupt, clock, register bases and power. Secondly add encoding work queue to deal with the encoding requestsof multi-hardware at the same time. Lastly, add output picture reorder function interface to eliminate the out of order images.Quoted 3 lines
This series has been tested with MT8195 Gstreamer. Encoding worked for this chip.
Hello Irui,
Unfortunately, I can't reproduce your successful test with gstreamer:
when
I try to encode a jpeg with videotestsrc input, I get a kernel panic.To reproduce this behavior, please run the following:
gst-launch-1.0 videotestsrc ! v4l2jpegenc ! filesink location=hwenctest.jpg
Here's the panic log:
[ 342.567211] Unable to handle kernel NULL pointer dereference atvirtual address
0000000000000108[ 342.576014] Mem abort info:[ 342.578805] ESR = 0x0000000096000004[ 342.582552] EC = 0x25: DABT (current EL), IL = 32 bits[ 342.587863] SET = 0, FnV = 0[ 342.590919] EA = 0, S1PTW = 0[ 342.594062] FSC = 0x04: level 0 translation fault[ 342.598941] Data abort info:[ 342.601826] ISV = 0, ISS = 0x00000004[ 342.605668] CM = 0, WnR = 0[ 342.608643] user pgtable: 4k pages, 48-bit VAs,pgdp=0000000119029000
[ 342.615094] [0000000000000108] pgd=0000000000000000,p4d=0000000000000000
[ 342.621907] Internal error: Oops: 96000004 [#1] SMP[ 342.626800] Modules linked in: cdc_ether usbnet r8152 af_alg qrtrmt7921e
mt7921_commonmt76_connac_libmt76 mac80211 btusb btrtl btintel btmtk btbcm
bluetooth cfg80211mtk_vcodec_dec_hwuvcvideosnd_sof_mt8195ecdh_genericmtk_vcodec_dececcmtk_adsp_commonvideobuf2_vmallocsnd_sof_xtensa_dsprfkillsnd_sof_ofv4l2_vp9panfrostmtk_jpegsnd_sofv4l2_h264mtk_jpeg_enc_hw8021qmtk_vcodec_commoncros_ec_sensorsgpu_schedcros_ec_lid_anglemtk_jpeg_dec_hwhid_multitouchsnd_sof_utilscros_ec_sensors_corecrct10dif_cegarpcros_usbpd_loggersbs_batterymrp stp llcipmi_devintfipmi_msghandlerfuse ipv6[ 342.680332] CPU: 3 PID: 180 Comm: kworker/u16:6 Tainted:G W
5.19.0-rc3-next-20220622+ #814[ 342.689982] Hardware name: MediaTek Tomato (rev2) board (DT)[ 342.695637] Workqueue: mtk-jpeg mtk_jpegenc_worker [mtk_jpeg][ 342.701402] pstate: 604000c9 (nZCv daIF +PAN -UAO -TCO -DIT -SSBSBTYPE=--)
[ 342.708360] pc : mtk_jpegenc_worker+0x6c/0x3e0 [mtk_jpeg][ 342.713763] lr : mtk_jpegenc_worker+0x64/0x3e0 [mtk_jpeg][ 342.719166] sp : ffff8000093cbcd0[ 342.722478] x29: ffff8000093cbcd0 x28: ffffb1f341cdb000 x27:
ffff6089885d0505[ 342.729618] x26: ffffb1f341ce1ee0 x25: ffffb1f341d0a2d0 x24:
ffff60899078d000[ 342.736758] x23: ffffb1f2e869c590 x22: ffff608990785458 x21:
ffff60898a0ea120[ 342.743898] x20: ffff60898a0ea080 x19: ffff60898a0ea080 x18:0000000000000000
[ 342.751038] x17: 0000000000000000 x16: ffffb1f3405a58c0 x15:
0000aaaac092a3d0[ 342.758178] x14: 0000000000000000 x13: 0000000000000c5f x12:
071c71c71c71c71c[ 342.765318] x11: 0000000000000c5f x10: 00000000000027a0 x9 :
ffffb1f33f32ce9c[ 342.772458] x8 : fefefefefefefeff x7 : 0000000000000018 x6 :
ffffb1f2e8699804[ 342.779597] x5 : 0000000000000000 x4 : 0000000000000001 x3 :
ffff608985d3c570[ 342.786737] x2 : 0000000000000000 x1 : 0000000000000000 x0 :0000000000000000
[ 342.793876] Call trace:[ 342.796319] mtk_jpegenc_worker+0x6c/0x3e0 [mtk_jpeg][ 342.801376] process_one_work+0x294/0x664[ 342.805392] worker_thread+0x7c/0x45c[ 342.809055] kthread+0x104/0x110[ 342.812283] ret_from_fork+0x10/0x20
Quoted 7 lines
[ 342.815863] Code: aa1503e0 9400037e f9415662 aa0003e1 (b9410840)[ 342.821956] ---[ end trace 0000000000000000 ]---Regards,
Angelo
Hi Angelo,
This issue is fixed, and I will supply a new version. Thanks.
Regards.