Enable two H264 encoder cores on MT8195
Subsystems (3)
cover Enable two H264 encoder cores on MT8195
MT8195 has two H264 encoder cores, they have their own power-domains, clocks, interrupts, register base. The two H264 encoder cores can work together to achieve higher performance.
This series of patches is to use enable two h264 encoder cores. path[1..2]: use linux component framework to manage encoder hardware, user call "mt8195-vcodec-enc" driver can get the encoder master device, the encoding work is done by the two encoder core device. The hw_mode variable is added to distinguish from old platform, two encoder cores called "FRAME_RACING_MODE".
The hardware mode of two encoder cores work together(overlap, another word called) on MT8195 called "frame_racing_mode", the two encoder power-domains should be power on together while encoding, the encoding process look like this:
VENC Core0 frm#0....frm#2....frm#4
VENC Core1 .frm#1....frm#3....frm#5patch[3..5]: due to the component device, the master device has no power-domains/clocks properties in dtsi, so the power/clock init function can't use for "frame_racing_mode" device in master device probe process, it should be called in component device probe process. Power on the hardware power and clock on demand.
patch[6]: "frame_racing_mode" encoding need a new set of memory buffer for two encoder cores. For compatibility, we should new a encoder driver interface.
patch[7..9]: add "frame_racing_mode" encoding process:
As-Is: Synchronous
VIDIOC_QBUF#0 --> device_run(triger encoder) --> wait encoder IRQ --> encode done with result --> job_finish
VIDIOC_QBUF#1 --> device_run(triger encoder) --> wait encoder IRQ --> encode done with result --> job_finish
...
To-Be: Asynchronous
VIDIOC_QBUF#0 --> device_run(triger encoder core0) --> job_finish ..VIDIOC_QBUF#1 --> device_run(triger encoder core1) --> job_finish (core0 may encode done here, return encode result to client) VIDIOC_QBUF#2 --> device_run(triger encoder core0) --> job_finish
Thers is no "wait encoder IRQ" synchronous call during "frame_racing_mode" encoding process, which can full use the two encoder cores to achieve higher performance.
Irui Wang (9):
dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
media: mtk-vcodec: Use component framework to manage encoder hardware
media: mtk-vcodec: Rewrite venc power manage interface
media: mtk-vcodec: Add venc power on/off interface
media: mtk-vcodec: Rewrite venc clock interface
media: mtk-vcodec: Add new venc drv interface for frame_racing mode
media: mtk-vcodec: Add frame racing mode encode process
media: mtk-vcodec: Return encode result to client
media: mtk-vcodec: Add delayed worker for encode timeout
.../bindings/media/mediatek-vcodec.txt | 2 + drivers/media/platform/mtk-vcodec/Makefile | 2 + .../platform/mtk-vcodec/mtk_vcodec_drv.h | 34 +- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 120 +++- .../platform/mtk-vcodec/mtk_vcodec_enc.h | 10 +- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 204 +++++- .../platform/mtk-vcodec/mtk_vcodec_enc_hw.c | 253 +++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_hw.h | 38 + .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 213 ++++-- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 13 +- .../platform/mtk-vcodec/mtk_vcodec_util.c | 19 + .../platform/mtk-vcodec/mtk_vcodec_util.h | 5 + .../platform/mtk-vcodec/venc/venc_common_if.c | 675 ++++++++++++++++++ .../platform/mtk-vcodec/venc/venc_h264_if.c | 6 +- .../platform/mtk-vcodec/venc/venc_vp8_if.c | 2 +- .../media/platform/mtk-vcodec/venc_drv_if.c | 96 ++- .../media/platform/mtk-vcodec/venc_drv_if.h | 7 + .../media/platform/mtk-vcodec/venc_vpu_if.c | 11 +- .../media/platform/mtk-vcodec/venc_vpu_if.h | 3 +- 19 files changed, 1564 insertions(+), 149 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.h create mode 100644 drivers/media/platform/mtk-vcodec/venc/venc_common_if.c
Signature · 1 line
2.25.1
PATCH 1/9 dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
Enable MT8195 two H.264 venc cores, updates vcodec binding document.
--- Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +2 -0
@@ -11,6 +11,8 @@ Required properties: "mediatek,mt8173-vcodec-dec" for MT8173 decoder. "mediatek,mt8192-vcodec-enc" for MT8192 encoder. "mediatek,mt8195-vcodec-enc" for MT8195 encoder. + "mediatek,mtk-venc-core0" for MT8195 avc core0 device. + "mediatek,mtk-venc-core1" for MT8195 avc core1 device. - reg : Physical base address of the video codec registers and length of memory mapped region. - interrupts : interrupt number to the cpu.
Signature · 1 line
2.25.1
Re: [PATCH 1/9] dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
Quoted 7 lines · Irui Wang
Enable MT8195 two H.264 venc cores, updates vcodec binding document.
Signed-off-by Irui Wang <[email protected]>--- Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 2 ++ 1 file changed, 2 insertions(+)
Re: [PATCH 1/9] dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
In reply to Irui WangHi Irui,
Quoted 13 lines · Irui Wang
Enable MT8195 two H.264 venc cores, updates vcodec binding document.
Signed-off-by Irui Wang <[email protected]>--- Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 2 ++ 1 file changed, 2 insertions(+)Documentation/devicetree/bindings/media/mediatek-vcodec.txt +0
-0
Documentation/devicetree/bindings/media/mediatek-vcodec.txt Required properties: · line 15
Quoted 5 lines
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +2
-0@@ -11,6 +11,8 @@ Required properties: "mediatek,mt8173-vcodec-dec" for MT8173 decoder. "mediatek,mt8192-vcodec-enc" for MT8192 encoder. "mediatek,mt8195-vcodec-enc" for MT8195 encoder. + "mediatek,mtk-venc-core0" for MT8195 avc core0 device. + "mediatek,mtk-venc-core1" for MT8195 avc core1 device.
What is the difference between core0 and core1?
Thanks,
Ezequiel
Re: [PATCH 1/9] dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
Hi,Ezequiel,
Thanks for your reviewing.
Quoted 28 lines · Ezequiel Garcia
Hi Irui,
Quoted 16 lines · Irui Wang
Enable MT8195 two H.264 venc cores, updates vcodec binding document.
Signed-off-by Irui Wang <[email protected]>--- Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 2 ++ 1 file changed, 2 insertions(+)(quoted diff) +0
-0vcodec.txt b/Documentation/devicetree/bindings/media/mediatek- vcodec.txt
indexde961699ba0a..eb2e24c32426100644Documentation/devicetree/bindings/media/mediatek-vcodec.txt Required properties: · line 15
Quoted 5 lines
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +2
-0@@ -11,6 +11,8 @@ Required properties: "mediatek,mt8173-vcodec-dec" for MT8173 decoder. "mediatek,mt8192-vcodec-enc" for MT8192 encoder. "mediatek,mt8195-vcodec-enc" for MT8195 encoder. + "mediatek,mtk-venc-core0" for MT8195 avc core0 device. + "mediatek,mtk-venc-core1" for MT8195 avc core1 device.What is the difference between core0 and core1?
Quoted 2 lines
Thanks,
Ezequiel
Both core0 and core1 are H264 encoder hardware, they have their own hardware register base, used power-domains/clocks/irqs. We can use any of them for H.264 encoding, but the two cores can work together for higher performance, it's called "frame racing", a hardware encoding mode, control flow just like in the commit messages:
core0 frame#0.frame#2.frame#4...
core1 frame#1.frame#3.frame#5...
Thanks
Re: [PATCH 1/9] dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
Quoted 37 lines · Irui Wang (王瑞)
Hi,Ezequiel,
Thanks for your reviewing.
Quoted 28 lines · Ezequiel Garcia
Hi Irui,
Quoted 16 lines · Irui Wang
Enable MT8195 two H.264 venc cores, updates vcodec binding document.
Signed-off-by Irui Wang <[email protected]>--- Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 2 ++ 1 file changed, 2 insertions(+)(quoted diff) +0
-0vcodec.txt b/Documentation/devicetree/bindings/media/mediatek- vcodec.txt
indexde961699ba0a..eb2e24c32426100644Documentation/devicetree/bindings/media/mediatek-vcodec.txt Required properties: · line 15
Quoted 5 lines
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +2
-0@@ -11,6 +11,8 @@ Required properties: "mediatek,mt8173-vcodec-dec" for MT8173 decoder. "mediatek,mt8192-vcodec-enc" for MT8192 encoder. "mediatek,mt8195-vcodec-enc" for MT8195 encoder. + "mediatek,mtk-venc-core0" for MT8195 avc core0 device. + "mediatek,mtk-venc-core1" for MT8195 avc core1 device.What is the difference between core0 and core1?
Quoted 2 lines
Thanks,
Ezequiel
Quoted 9 lines
Both core0 and core1 are H264 encoder hardware, they have their own hardware register base, used power-domains/clocks/irqs. We can use any of them for H.264 encoding, but the two cores can work together for higher performance, it's called "frame racing", a hardware encoding mode, control flow just like in the commit messages:
core0 frame#0.frame#2.frame#4...
core1 frame#1.frame#3.frame#5...
If they are two encoder cores, why do you need different compatible strings?
It would be interesting to see a device tree which shows how this should be used in the real world, but from the looks of it, it seems you don't need a separate compatible.
It seems this series is somewhat related to Yunfei's "[PATCH v5, 00/15] Using component framework to support multi hardware decode", but I don't see a device tree patch either in that series.
Given this is a complex architecture, I don't know if it makes sense to discuss decoder and encoder independently.
If you guys unify the two series, and add the device tree patches for it, or at least for the most complex cases, maybe that will surface the architecture more clearly and come up with an easier solution that doesn't involve
an async framework to pull in the parts together.
Thanks,
Ezequiel
Re: [PATCH 1/9] dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
Quoted 53 lines · Ezequiel Garcia
Quoted 47 lines · Irui Wang (王瑞)
Hi,Ezequiel,
Thanks for your reviewing.
Quoted 31 lines · Ezequiel Garcia
Hi Irui,
Quoted 19 lines · Irui Wang
Enable MT8195 two H.264 venc cores, updates vcodec binding document.
Signed-off-by Irui Wang <[email protected]>---
Documentation/devicetree/bindings/media/mediatek-vcodec.txt|
2 ++1 file changed, 2 insertions(+)(quoted diff) +0
-0vcodec.txt b/Documentation/devicetree/bindings/media/mediatek- vcodec.txt
indexde961699ba0a..eb2e24c32426100644
--- a/Documentation/devicetree/bindings/media/mediatek- vcodec.txt
+++ b/Documentation/devicetree/bindings/media/mediatek- vcodec.txtDocumentation/devicetree/bindings/media/mediatek-vcodec.txt Required properties: · line 15
Quoted 5 lines
Documentation/devicetree/bindings/media/mediatek-vcodec.txt +2
-0@@ -11,6 +11,8 @@ Required properties: "mediatek,mt8173-vcodec-dec" for MT8173 decoder. "mediatek,mt8192-vcodec-enc" for MT8192 encoder. "mediatek,mt8195-vcodec-enc" for MT8195 encoder. + "mediatek,mtk-venc-core0" for MT8195 avc core0 device. + "mediatek,mtk-venc-core1" for MT8195 avc core1 device.What is the difference between core0 and core1?
Quoted 2 lines
Thanks,
EzequielBoth core0 and core1 are H264 encoder hardware, they have their own hardware register base, used power-domains/clocks/irqs. We can use any
of them for H.264 encoding, but the two cores can work together for higher performance, it's called "frame racing", a hardware encoding mode, control flow just like in the commit messages:Quoted 3 lines
core0 frame#0.frame#2.frame#4...
core1 frame#1.frame#3.frame#5...
Quoted 9 lines
If they are two encoder cores, why do you need different compatible strings?
It would be interesting to see a device tree which shows how this should
be used in the real world, but from the looks of it, it seems you don't
need a separate compatible.
We want to use the two cores through one device node, core0 and core1 bind to device "mediatek,mt8195-vcodec-enc", it's feasible to make two cores work by just opening one device, the device tree looks like:
venc {
compatible = "mediatek,mt8195-vcodec-enc"
}venc_core0 {
compatible = "mediatek,mtk-venc-core0"
interrupts = xxxx
clocks = xxxx
power-domains = xxxx
...
}
venc_core1 {
compatible = "mediatek,mtk-venc-core1"
interrupts = xxxx
clocks = xxxx
power-domains = xxxx
...
}
as you can see, node "venc" just has compatible string, it's just used for register "/dev/videoX" device node in probe process. The encoder real hardware device are node "venc_core0" and "venc_core1", bind them to "venc" in probe process.
Quoted 14 lines
It seems this series is somewhat related to Yunfei's "[PATCH v5, 00/15] Using component framework to support multi hardware decode", but I don't see a device tree patch either in that series.
Given this is a complex architecture, I don't know if it makes sense to discuss decoder and encoder independently.
If you guys unify the two series, and add the device tree patches for it,
or at least for the most complex cases, maybe that will surface the architecture more clearly and come up with an easier solution that doesn't involve
an async framework to pull in the parts together.
Quoted 2 lines
Thanks,
Ezequiel
Yes, this series have a similar purpose with Yunfei's patch, he has a requirement for dual cores decoder, mine are dual cores encoder, about the usage of framework component, it can be discussed together.
Thanks
PATCH 2/9 media: mtk-vcodec: Use component framework to manage encoder hardware
In reply to Irui WangThere are two venc cores for H264 inside MT8195, uses component framework to manage each hardware so that the two cores can be used through one venc driver.
Adds new encoder hardware mode to indicate different hardware modes:VENC_SINGLE_CORE_MODE means only one core, the device has its own power/clk/irq, init_pm/request_irq helper can be used.
VENC_FRAME_RACING_MODE means more than one core inside, the core device driver can use the init_pm/request_irq helper to initialize their own power/clk/irq. And the master device doesn't need use these helper anymore.
--- drivers/media/platform/mtk-vcodec/Makefile | 1 + .../platform/mtk-vcodec/mtk_vcodec_drv.h | 22 ++ .../platform/mtk-vcodec/mtk_vcodec_enc.h | 2 + .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 189 +++++++++++++++--- .../platform/mtk-vcodec/mtk_vcodec_enc_hw.c | 179 +++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_hw.h | 36 ++++ 6 files changed, 397 insertions(+), 32 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.h
drivers/media/platform/mtk-vcodec/Makefile +1 -0
@@ -20,6 +20,7 @@ mtk-vcodec-enc-y := venc/venc_vp8_if.o \ mtk_vcodec_enc_pm.o \ venc_drv_if.o \ venc_vpu_if.o \ + mtk_vcodec_enc_hw.o \ mtk-vcodec-common-y := mtk_vcodec_intr.o \
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +22 -0
@@ -8,6 +8,7 @@#ifndef _MTK_VCODEC_DRV_H_#define _MTK_VCODEC_DRV_H_ +#include <linux/component.h> #include <linux/platform_device.h> #include <linux/videodev2.h> #include <media/v4l2-ctrls.h>
@@ -92,6 +93,20 @@ enum mtk_fmt_type { MTK_FMT_FRAME = 2, }; +enum mtk_venc_hw_id { +MTK_VENC_CORE0 =0 , +MTK_VENC_CORE1 =1 , +MTK_VENC_HW_MAX , +}; + +/** +* enmu mtk_venc_hw_mode - Used to indicate different encode mode +*/ +enum mtk_venc_hw_mode { +VENC_SINGLE_CORE_MODE =0 , +VENC_FRAME_RACING_MODE =1 , +}; +/* * struct mtk_video_fmt - Structure used to store information about pixelformats */
@@ -320,6 +335,7 @@ enum mtk_chip {* @output_formats: array of supported output formats * @num_output_formats: number of entries in output_formats * @core_id: stand for h264 or vp8 encode index +* @hw_mode: indicate encode mode */ struct mtk_vcodec_enc_pdata {enum mtk_chip chip;
@@ -332,6 +348,7 @@ struct mtk_vcodec_enc_pdata {const struct mtk_video_fmt *output_formats;size_t num_output_formats;int core_id; +enum mtk_venc_hw_mode hw_mode; };#define MTK_ENC_CTX_IS_EXT (ctx) ((ctx)->dev->venc_pdata->uses_ext)
@@ -372,6 +389,8 @@ struct mtk_vcodec_enc_pdata {* @pm: power management control * @dec_capability: used to identify decode capability, ex: 4k * @enc_capability: used to identify encode capability +* @enc_comp_node: used to store venc component node +* @enc_comp_dev: used to store venc component device */ struct mtk_vcodec_dev {struct v4l2_device v4l2_dev;
@@ -407,6 +426,9 @@ struct mtk_vcodec_dev {struct mtk_vcodec_pm pm;unsigned int dec_capability;unsigned int enc_capability; + +struct device_node *enc_comp_node[MTK_VENC_HW_MAX ]; +void *enc_comp_dev[MTK_VENC_HW_MAX ]; };static inline struct mtk_vcodec_ctx *fh_to_ctx (struct v4l2_fh *fh)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h +2 -0
@@ -21,6 +21,8 @@#define MTK_VENC_IRQ_STATUS_OFFSET 0x05C#define MTK_VENC_IRQ_ACK_OFFSET 0x060 +extern struct platform_driver mtk_venc_comp_driver; +/** * struct mtk_video_enc_buf - Private data related to each VB2 buffer. * @m2m_buf: M2M buffer
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +157 -32
266 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +179 -0
179 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#ifndef _MTK_VCODEC_ENC_HW_H_ +#define _MTK_VCODEC_ENC_HW_H_ + +#include <linux/platform_device.h> +#include "mtk_vcodec_drv.h" + +/* +* struct mtk_venc_comp_dev - driver data +* @plat_dev: platform_device +* @master_dev: master device +* @pm: power management data +* @curr_ctx: the context that is waiting for venc hardware +* @reg_base: mapped address of venc registers +* @irq_status: venc hw irq status +* @enc_irq: venc device irq +* @core id: for venc core id: core#0, core#1... +*/ +struct mtk_venc_comp_dev { +struct platform_device *plat_dev; +struct mtk_vcodec_dev *master_dev; + +struct mtk_vcodec_pm pm; +struct mtk_vcodec_ctx *curr_ctx; + +void __iomem *reg_base; +unsigned int irq_status; +int enc_irq; +int core_id; +}; + +#endif /* _MTK_VCODEC_ENC_HW_H_ */
Signature · 1 line
2.25.1
Re: [PATCH 2/9] media: mtk-vcodec: Use component framework to manage encoder hardware
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c line 79
Quoted 10 lines · Irui Wang
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +10
-0+static struct component_match *mtk_venc_match_add (struct mtk_vcodec_dev *dev) +{ +struct platform_device *pdev = dev->plat_dev; +struct component_match *match =NULL ; +int i; + +for (i =0 ; i <ARRAY_SIZE (mtk_venc_comp_ids); i++) { +enum mtk_venc_hw_id comp_idx; +struct device_node *comp_node; +const struct of_device_id *of_id;
To be neat, prefer to define the variables outside of the loop (i.e. at the beginning of the function).
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c line 88
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +9
-0+ + comp_node =of_find_compatible_node (NULL ,NULL , + mtk_venc_comp_ids[i].compatible); +if (!comp_node) +continue ; + + of_id =of_match_node (mtk_venc_comp_ids, comp_node); +if (!of_id) { +dev_err (&pdev->dev,"Failed to get match node\n" );
Need to call of_node_put() actually, but see comment below.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c line 92
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +4
-0+return ERR_PTR (-EINVAL ); + } + + comp_idx = (enum mtk_venc_hw_id )of_id->data;
For getting the comp_idx, mtk_venc_comp_ids[i].data should be sufficient. If so, of_match_node() can be removed so that the error handling path won't need to call of_node_put().
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c static int mtk_vcodec_probe(struct platform_device *pdev) · line 317
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +1
-0@@ -239,6 +314,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)phandle rproc_phandle;enum mtk_vcodec_fw_type fw_type;int ret; +struct component_match *match =NULL ;
It doesn't need to be initialized.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c static int mtk_vcodec_probe(struct platform_device *pdev) · line 364
Quoted 12 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +6
-6- 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; - } + res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!res) { +dev_err (&pdev->dev,"failed to get irq resource" ); + ret = -ENOENT ; + goto err_res; + }
res is not used. Can be removed in next version or in another patch.
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +0
-0
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c line 10
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +10
-0@@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/pm_runtime.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/of_platform.h> +#include <linux/module.h>
Would be better to maintain an order.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c line 13
Quoted 2 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +2
-0+#include "mtk_vcodec_enc_hw.h" +#include "mtk_vcodec_enc.h"
Would be better to maintain an order.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c line 47
Quoted 12 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +12
-0+static irqreturn_t mtk_enc_comp_irq_handler (int irq,void *priv) +{ +struct mtk_venc_comp_dev *dev = priv; +struct mtk_vcodec_ctx *ctx; +unsigned long flags; +void __iomem *addr; + +spin_lock_irqsave (&dev->master_dev->irqlock, flags); + ctx = dev->curr_ctx; +spin_unlock_irqrestore (&dev->master_dev->irqlock, flags); +if (!ctx) +return IRQ_HANDLED ;
Here is a read lock for the curr_ctx. The patch doesn't contain the write lock part.
I am not sure if the following situation would be happened:
1. curr_ctx is not NULL.
2. mtk_enc_comp_irq_handler() gets the curr_ctx.
3. The curr_ctx has been destroyed somewhere.
4. mtk_enc_comp_irq_handler() finds the ctx is not NULL so that it continues to execute.
5. Something wrong in latter mtk_enc_comp_irq_handler() because the ctx has been destroyed.
Does it make more sense to set curr_ctx to NULL to indicate the ownership has been transferred to mtk_enc_comp_irq_handler()? For example:
spin_lock_irqsave(...);
ctx = dev->curr_ctx;dev->curr_ctx = NULL;spin_unlock_irqrestore(...);
Quoted 8 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +8
-0+static int mtk_venc_comp_bind (struct device *dev, +struct device *master,void *data) +{ +struct mtk_venc_comp_dev *comp_dev =dev_get_drvdata (dev); +struct mtk_vcodec_dev *master_dev = data; +int i; + +for (i =0 ; i <MTK_VENC_HW_MAX ; i++) {
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c line 73
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c new file +10
-0+if (dev->of_node != master_dev->enc_comp_node[i]) +continue ; + +/*add component device by order*/ +if (comp_dev->core_id ==MTK_VENC_CORE0 ) + master_dev->enc_comp_dev[MTK_VENC_CORE0 ] = comp_dev; +else if (comp_dev->core_id ==MTK_VENC_CORE1 ) + master_dev->enc_comp_dev[MTK_VENC_CORE1 ] = comp_dev; +else +return -EINVAL ;
if (comp_dev->core_id < 0 || comp_dev->core_id >= MTK_VENC_HW_MAX)
return -EINVAL;
master_dev->enc_comp_dev[comp_dev->core_id] = comp_dev;
PATCH 3/9 media: mtk-vcodec: Rewrite venc power manage interface
In reply to Irui WangThe args "struct mtk_vcodec_dev *" doesn't appropriate for init/release_enc_pm functions because of component devices. For master device, it has no "pm/clk" properties in dtsi, component devices will init their own "pm/clk" instead. So rewrite the pm interface with args "platform_device *" and "mtk_vcodec_pm*".
--- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 6 ++-- .../platform/mtk-vcodec/mtk_vcodec_enc_hw.c | 13 ++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 31 +++++++------------ .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 5 +-- 4 files changed, 30 insertions(+), 25 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +3 -3
@@ -341,7 +341,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) dev->venc_pdata =of_device_get_match_data (&pdev->dev);if (dev->venc_pdata->hw_mode ==VENC_SINGLE_CORE_MODE ) { - ret =mtk_vcodec_init_enc_pm (dev); + ret =mtk_vcodec_init_enc_pm (dev->plat_dev, &dev->pm);if (ret <0 ) {dev_err (&pdev->dev,"Failed to get mtk vcodec clock source!" ); goto err_enc_pm;
@@ -471,7 +471,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)v4l2_device_unregister (&dev->v4l2_dev); err_res:if (dev->venc_pdata->hw_mode ==VENC_SINGLE_CORE_MODE ) -mtk_vcodec_release_enc_pm (dev); +mtk_vcodec_release_enc_pm (&dev->pm); err_enc_pm:mtk_vcodec_fw_release (dev->fw_handler);return ret;
@@ -568,7 +568,7 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev)v4l2_device_unregister (&dev->v4l2_dev);if (dev->venc_pdata->hw_mode ==VENC_SINGLE_CORE_MODE ) -mtk_vcodec_release_enc_pm (dev); +mtk_vcodec_release_enc_pm (&dev->pm);mtk_vcodec_fw_release (dev->fw_handler);
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c +13 -0
@@ -10,6 +10,7 @@#include <linux/module.h> #include "mtk_vcodec_enc_hw.h" +#include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_enc.h" static void clean_irq_status (unsigned int irq_status,void __iomem *addr)
@@ -105,6 +106,14 @@ static int mtk_venc_comp_probe(struct platform_device *pdev) comp_dev->plat_dev = pdev; + ret =mtk_vcodec_init_enc_pm (pdev, &comp_dev->pm); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to get venc component clock source!" ); +return ret; + } + +pm_runtime_enable (&pdev->dev); + comp_dev->core_id = (enum mtk_venc_hw_id )of_device_get_match_data (&pdev->dev);
@@ -146,11 +155,15 @@ static int mtk_venc_comp_probe(struct platform_device *pdev)return 0 ; err: +mtk_vcodec_release_enc_pm (&comp_dev->pm);return ret; }static int mtk_venc_comp_remove (struct platform_device *pdev) { +struct mtk_venc_comp_dev *comp_dev =platform_get_drvdata (pdev); + +mtk_vcodec_release_enc_pm (&comp_dev->pm);component_del (&pdev->dev, &mtk_venc_component_ops);return 0 ; }
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +11 -20
@@ -13,38 +13,29 @@#include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_util.h" -int mtk_vcodec_init_enc_pm (struct mtk_vcodec_dev *mtkdev) +int mtk_vcodec_init_enc_pm (struct platform_device *pdev, +struct mtk_vcodec_pm *pm) {struct device_node *node; -struct platform_device *pdev; -struct mtk_vcodec_pm *pm; +struct platform_device *larb_pdev;struct mtk_vcodec_clk *enc_clk;struct mtk_vcodec_clk_info *clk_info;int ret =0 , i =0 ; -struct device *dev; - pdev = mtkdev->plat_dev; - pm = &mtkdev->pm; -memset (pm,0 ,sizeof (struct mtk_vcodec_pm )); - pm->mtkdev = mtkdev; - pm->dev = &pdev->dev; - dev = &pdev->dev; - enc_clk = &pm->venc_clk; - - node =of_parse_phandle (dev->of_node,"mediatek,larb" ,0 ); + node =of_parse_phandle (pdev->dev.of_node,"mediatek,larb" ,0 );if (!node) {mtk_v4l2_err ("no mediatek,larb found" );return -ENODEV ; } - pdev =of_find_device_by_node (node); + larb_pdev =of_find_device_by_node (node);of_node_put (node); -if (!pdev) { +if (!larb_pdev) {mtk_v4l2_err ("no mediatek,larb device found" );return -ENODEV ; } - pm->larbvenc = &pdev->dev; - pdev = mtkdev->plat_dev; + pm->larbvenc = &larb_pdev->dev; pm->dev = &pdev->dev; + enc_clk = &pm->venc_clk; enc_clk->clk_num =of_property_count_strings (pdev->dev.of_node,"clock-names" );
@@ -87,10 +78,10 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)return ret; } -void mtk_vcodec_release_enc_pm (struct mtk_vcodec_dev *mtkdev) +void mtk_vcodec_release_enc_pm (struct mtk_vcodec_pm *pm) { -pm_runtime_disable (mtkdev->pm.dev); -put_device (mtkdev->pm.larbvenc); +pm_runtime_disable (pm->dev); +put_device (pm->larbvenc); }
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h +3 -2
@@ -9,8 +9,9 @@#include "mtk_vcodec_drv.h" -int mtk_vcodec_init_enc_pm (struct mtk_vcodec_dev *dev); -void mtk_vcodec_release_enc_pm (struct mtk_vcodec_dev *dev); +int mtk_vcodec_init_enc_pm (struct platform_device *pdev, +struct mtk_vcodec_pm *pm); +void mtk_vcodec_release_enc_pm (struct mtk_vcodec_pm *pm);void mtk_vcodec_enc_clock_on (struct mtk_vcodec_pm *pm);void mtk_vcodec_enc_clock_off (struct mtk_vcodec_pm *pm);
Signature · 1 line
2.25.1
Re: [PATCH 3/9] media: mtk-vcodec: Rewrite venc power manage interface
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c static int mtk_venc_comp_probe(struct platform_device *pdev) · line 115
Quoted 11 lines · Irui Wang
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c +7
-0@@ -105,6 +106,14 @@ static int mtk_venc_comp_probe(struct platform_device *pdev) comp_dev->plat_dev = pdev; + ret =mtk_vcodec_init_enc_pm (pdev, &comp_dev->pm); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to get venc component clock source!" ); +return ret; + } + +pm_runtime_enable (&pdev->dev);
mtk_vcodec_init_enc_pm() and mtk_vcodec_release_enc_pm() is more like a pair. Does it make more sense to call pm_runtime_enable() in mtk_vcodec_init_enc_pm()?
PATCH 4/9 media: mtk-vcodec: Add venc power on/off interface
In reply to Irui WangFrame-racing mode need power on/off all venc available power, pm_runtime_xx helper is not appropriate called directly, add new power on/off interface for it.
--- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 18 +--- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 9 +- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 82 +++++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 4 + 4 files changed, 96 insertions(+), 17 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +2 -16
@@ -16,6 +16,7 @@#include "mtk_vcodec_intr.h" #include "mtk_vcodec_util.h" #include "venc_drv_if.h" +#include "mtk_vcodec_enc_pm.h" #define MTK_VENC_MIN_W 160U#define MTK_VENC_MIN_H 128U
@@ -801,7 +802,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)*/ if ((ctx->state ==MTK_STATE_ABORT ) || (ctx->state ==MTK_STATE_FREE )) { ret = -EIO ; - goto err_start_stream; + goto err_set_param; }/* Do the initialization when both start_streaming have been called */
@@ -813,12 +814,6 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)return 0 ; } - ret =pm_runtime_resume_and_get (&ctx->dev->plat_dev->dev); -if (ret <0 ) { -mtk_v4l2_err ("pm_runtime_resume_and_get fail %d" , ret); - goto err_start_stream; - } -mtk_venc_set_param (ctx, ¶m); ret =venc_if_set_param (ctx,VENC_SET_PARAM_ENC , ¶m);if (ret) {
@@ -845,11 +840,6 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)return 0 ; err_set_param: - ret =pm_runtime_put (&ctx->dev->plat_dev->dev); -if (ret <0 ) -mtk_v4l2_err ("pm_runtime_put fail %d" , ret); - -err_start_stream:for (i =0 ; i < q->num_buffers; ++i) {struct vb2_buffer *buf =vb2_get_buffer (q, i);
@@ -903,10 +893,6 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)if (ret)mtk_v4l2_err ("venc_if_deinit failed=%d" , ret); - ret =pm_runtime_put (&ctx->dev->plat_dev->dev); -if (ret <0 ) -mtk_v4l2_err ("pm_runtime_put fail %d" , ret); - ctx->state =MTK_STATE_FREE ; }
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +8 -1
@@ -253,6 +253,12 @@ static int fops_vcodec_open(struct file *file)mtk_v4l2_debug (0 ,"encoder capability %x" , dev->enc_capability); } + ret =mtk_vcodec_enc_power_on (ctx); +if (ret <0 ) { +mtk_v4l2_err ("encoder power on failed %d" , ret); + goto err_load_fw; + } +mtk_v4l2_debug (2 ,"Create instance [%d]@%p m2m_ctx=%p " , ctx->id, ctx, ctx->m2m_ctx);
@@ -285,11 +291,12 @@ static int fops_vcodec_release(struct file *file)mtk_v4l2_debug (1 ,"[%d] encoder" , ctx->id);mutex_lock (&dev->dev_mutex); +v4l2_m2m_ctx_release (ctx->m2m_ctx);mtk_vcodec_enc_release (ctx);v4l2_fh_del (&ctx->fh);v4l2_fh_exit (&ctx->fh);v4l2_ctrl_handler_free (&ctx->ctrl_hdl); -v4l2_m2m_ctx_release (ctx->m2m_ctx); +mtk_vcodec_enc_power_off (ctx);list_del_init (&ctx->list);kfree (ctx);
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +82 -0
91 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h +4 -0
@@ -16,4 +16,8 @@ void mtk_vcodec_release_enc_pm(struct mtk_vcodec_pm *pm);void mtk_vcodec_enc_clock_on (struct mtk_vcodec_pm *pm);void mtk_vcodec_enc_clock_off (struct mtk_vcodec_pm *pm); +int mtk_venc_enable_comp_hw (struct mtk_vcodec_dev *dev); +int mtk_venc_disable_comp_hw (struct mtk_vcodec_dev *dev); +int mtk_vcodec_enc_power_on (struct mtk_vcodec_ctx *ctx); +int mtk_vcodec_enc_power_off (struct mtk_vcodec_ctx *ctx);#endif /* _MTK_VCODEC_ENC_PM_H_ */
Signature · 1 line
2.25.1
Re: [PATCH 4/9] media: mtk-vcodec: Add venc power on/off interface
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c line 19
Quoted 7 lines · Irui Wang
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +1
-0@@ -16,6 +16,7 @@#include "mtk_vcodec_intr.h" #include "mtk_vcodec_util.h" #include "venc_drv_if.h" +#include "mtk_vcodec_enc_pm.h"
Please try to maintain the order.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c static int fops_vcodec_release(struct file *file) · line 299
Quoted 11 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +2
-1@@ -285,11 +291,12 @@ static int fops_vcodec_release(struct file *file)mtk_v4l2_debug (1 ,"[%d] encoder" , ctx->id);mutex_lock (&dev->dev_mutex); +v4l2_m2m_ctx_release (ctx->m2m_ctx);mtk_vcodec_enc_release (ctx);v4l2_fh_del (&ctx->fh);v4l2_fh_exit (&ctx->fh);v4l2_ctrl_handler_free (&ctx->ctrl_hdl); -v4l2_m2m_ctx_release (ctx->m2m_ctx); +mtk_vcodec_enc_power_off (ctx);
Any reason to move the v4l2_m2m_ctx_release()?
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c line 15
Quoted 7 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +1
-0@@ -12,6 +12,7 @@#include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_util.h" +#include "mtk_vcodec_enc_hw.h"
Please try to maintain the order.
Quoted 7 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +7
-0+int mtk_venc_enable_comp_hw (struct mtk_vcodec_dev *dev) +{ +int i, ret; +struct mtk_venc_comp_dev *venc_comp; + +/* +* frame_racing mode needs power on all available component devices.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) · line 141
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +10
-0+*/ +for (i =0 ; i <MTK_VENC_HW_MAX ; i++) { + venc_comp = (struct mtk_venc_comp_dev *)dev->enc_comp_dev[i]; +if (!venc_comp) +return 0 ; + + ret =mtk_smi_larb_get (venc_comp->pm.larbvenc); +if (ret <0 ) { +mtk_v4l2_err ("power on core[%d] fail %d" , i, ret); + goto pw_err;
The goto statement has extra indent layer.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) · line 161
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +6
-0+int mtk_venc_disable_comp_hw (struct mtk_vcodec_dev *dev) +{ +int i; +struct mtk_venc_comp_dev *venc_comp; + +/*power off all available component device*/
Need extra space between /* */.
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +10
-0+int mtk_vcodec_enc_power_on (struct mtk_vcodec_ctx *ctx) +{ +int ret; +struct mtk_vcodec_dev *dev = ctx->dev; + +if (dev->venc_pdata->hw_mode ==VENC_FRAME_RACING_MODE ) { + ret =mtk_venc_enable_comp_hw (dev); +if (ret <0 ) { +mtk_v4l2_err ("enable venc comp hw fail :%d" , ret); +return ret;
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) · line 192
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +10
-0+ } + }else { + ret =mtk_smi_larb_get (dev->pm.larbvenc); +if (ret <0 ) { +mtk_v4l2_err ("pm_runtime_resume_and_get fail %d" , ret); +return ret; + } + } +return 0 ; +}
It seems the function doesn't need struct mtk_vcodec_ctx.
Does mtk_vcodec_enc_power_on(struct mtk_vcodec_dev* ) make more sense?
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) · line 204
Quoted 11 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +11
-0+int mtk_vcodec_enc_power_off (struct mtk_vcodec_ctx *ctx) +{ +struct mtk_vcodec_dev *dev = ctx->dev; + +if (dev->venc_pdata->hw_mode ==VENC_FRAME_RACING_MODE ) +mtk_venc_disable_comp_hw (dev); +else +mtk_smi_larb_put (dev->pm.larbvenc); + +return 0 ; +}
It seems the function doesn't need struct mtk_vcodec_ctx.
PATCH 5/9 media: mtk-vcodec: Rewrite venc clock interface
In reply to Irui WangFrame-racing mode need enable the specific core's clk, add an another param for clock_on/clock_off interface.
--- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 104 ++++++++++++++---- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 4 +- .../media/platform/mtk-vcodec/venc_drv_if.c | 10 +- 3 files changed, 86 insertions(+), 32 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +82 -22
@@ -86,25 +86,50 @@ void mtk_vcodec_release_enc_pm(struct mtk_vcodec_pm *pm) } -void mtk_vcodec_enc_clock_on (struct mtk_vcodec_pm *pm) +void mtk_vcodec_enc_clock_on (struct mtk_vcodec_dev *dev,int core_id) { -struct mtk_vcodec_clk *enc_clk = &pm->venc_clk; -int ret, i =0 ; +struct mtk_venc_comp_dev *venc; +struct mtk_vcodec_pm *enc_pm; +struct mtk_vcodec_clk *enc_clk; +struct clk *clk; +int ret, i; -for (i =0 ; i < enc_clk->clk_num; i++) { - ret =clk_prepare_enable (enc_clk->clk_info[i].vcodec_clk); -if (ret) { -mtk_v4l2_err ("venc clk_prepare_enable %d %s fail %d" , i, - enc_clk->clk_info[i].clk_name, ret); - goto clkerr; +if (dev->venc_pdata->hw_mode ==VENC_FRAME_RACING_MODE ) { + venc = (struct mtk_venc_comp_dev *)dev->enc_comp_dev[core_id]; + enc_pm = &venc->pm; + enc_clk = &enc_pm->venc_clk; + +for (i =0 ; i < enc_clk->clk_num; i++) { + clk = enc_clk->clk_info[i].vcodec_clk; + ret =clk_enable (clk); +if (ret) { +mtk_v4l2_err ("clk_enable %d %s fail %d" , i, + enc_clk->clk_info[i].clk_name, + ret); + goto comp_clk_err; + } } - } + }else { + enc_pm = &dev->pm; + enc_clk = &enc_pm->venc_clk; - ret =mtk_smi_larb_get (pm->larbvenc); -if (ret) { -mtk_v4l2_err ("mtk_smi_larb_get larb3 fail %d" , ret); - goto clkerr; +for (i =0 ; i < enc_clk->clk_num; i++) { + clk = enc_clk->clk_info[i].vcodec_clk; + ret =clk_prepare_enable (clk); +if (ret) { +mtk_v4l2_err ("clk_prepare_enable %d %s fail %d" , + i, enc_clk->clk_info[i].clk_name, + ret); + goto clkerr; + } + } } + +return ; + +comp_clk_err: +for (i -=1 ; i >=0 ; i--) +clk_disable (enc_clk->clk_info[i].vcodec_clk);return ; clkerr:
@@ -112,20 +137,35 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)clk_disable_unprepare (enc_clk->clk_info[i].vcodec_clk); } -void mtk_vcodec_enc_clock_off (struct mtk_vcodec_pm *pm) +void mtk_vcodec_enc_clock_off (struct mtk_vcodec_dev *dev,int core_id) { -struct mtk_vcodec_clk *enc_clk = &pm->venc_clk; -int i =0 ; +struct mtk_venc_comp_dev *venc; +struct mtk_vcodec_pm *enc_pm; +struct mtk_vcodec_clk *enc_clk; +int i; -mtk_smi_larb_put (pm->larbvenc); -for (i = enc_clk->clk_num -1 ; i >=0 ; i--) -clk_disable_unprepare (enc_clk->clk_info[i].vcodec_clk); +if (dev->venc_pdata->hw_mode ==VENC_FRAME_RACING_MODE ) { + venc = (struct mtk_venc_comp_dev *)dev->enc_comp_dev[core_id]; + enc_pm = &venc->pm; + enc_clk = &enc_pm->venc_clk; + +for (i = enc_clk->clk_num -1 ; i >=0 ; i--) +clk_disable (enc_clk->clk_info[i].vcodec_clk); + }else { + enc_pm = &dev->pm; + enc_clk = &enc_pm->venc_clk; + +for (i = enc_clk->clk_num -1 ; i >=0 ; i--) +clk_disable_unprepare (enc_clk->clk_info[i].vcodec_clk); + } }int mtk_venc_enable_comp_hw (struct mtk_vcodec_dev *dev) {int i, ret;struct mtk_venc_comp_dev *venc_comp; +struct mtk_vcodec_clk *enc_clk; +int j =0 ;/* * frame_racing mode needs power on all available component devices.
@@ -140,23 +180,38 @@ int mtk_venc_enable_comp_hw(struct mtk_vcodec_dev *dev)mtk_v4l2_err ("power on core[%d] fail %d" , i, ret); goto pw_err; } + + enc_clk = &venc_comp->pm.venc_clk; +for (j =0 ; j < enc_clk->clk_num; j++) { + ret =clk_prepare (enc_clk->clk_info[j].vcodec_clk); +if (ret) { +mtk_v4l2_err ("prepare clk [%s] fail %d" , + enc_clk->clk_info[j].clk_name, + ret); + goto pw_err; + } + } }return 0 ; pw_err:for (i -=1 ; i >=0 ; i--) { venc_comp = (struct mtk_venc_comp_dev *)dev->enc_comp_dev[i]; + enc_clk = &venc_comp->pm.venc_clk; + +for (j -=1 ; j >=0 ; j--) +clk_unprepare (enc_clk->clk_info[j].vcodec_clk);mtk_smi_larb_put (venc_comp->pm.larbvenc); } -return ret; }int mtk_venc_disable_comp_hw (struct mtk_vcodec_dev *dev) { -int i; +int i, j;struct mtk_venc_comp_dev *venc_comp; +struct mtk_vcodec_clk *enc_clk;/*power off all available component device*/ for (i =0 ; i <MTK_VENC_HW_MAX ; i++) {
@@ -164,6 +219,11 @@ int mtk_venc_disable_comp_hw(struct mtk_vcodec_dev *dev)if (!venc_comp)return 0 ; + enc_clk = &venc_comp->pm.venc_clk; + +for (j = enc_clk->clk_num -1 ; j >=0 ; j--) +clk_unprepare (enc_clk->clk_info[j].vcodec_clk); +mtk_smi_larb_put (venc_comp->pm.larbvenc); }
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h +2 -2
@@ -13,8 +13,8 @@ int mtk_vcodec_init_enc_pm(struct platform_device *pdev, struct mtk_vcodec_pm *pm);void mtk_vcodec_release_enc_pm (struct mtk_vcodec_pm *pm); -void mtk_vcodec_enc_clock_on (struct mtk_vcodec_pm *pm); -void mtk_vcodec_enc_clock_off (struct mtk_vcodec_pm *pm); +void mtk_vcodec_enc_clock_on (struct mtk_vcodec_dev *dev,int core_id); +void mtk_vcodec_enc_clock_off (struct mtk_vcodec_dev *dev,int core_id);int mtk_venc_enable_comp_hw (struct mtk_vcodec_dev *dev);int mtk_venc_disable_comp_hw (struct mtk_vcodec_dev *dev);
drivers/media/platform/mtk-vcodec/venc_drv_if.c +2 -8
@@ -32,9 +32,7 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) }mtk_venc_lock (ctx); -mtk_vcodec_enc_clock_on (&ctx->dev->pm); ret = ctx->enc_if->init (ctx); -mtk_vcodec_enc_clock_off (&ctx->dev->pm);mtk_venc_unlock (ctx);return ret;
@@ -46,9 +44,7 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx,int ret =0 ;mtk_venc_lock (ctx); -mtk_vcodec_enc_clock_on (&ctx->dev->pm); ret = ctx->enc_if->set_param (ctx->drv_handle, type, in); -mtk_vcodec_enc_clock_off (&ctx->dev->pm);mtk_venc_unlock (ctx);return ret;
@@ -68,10 +64,10 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx, ctx->dev->curr_ctx = ctx;spin_unlock_irqrestore (&ctx->dev->irqlock, flags); -mtk_vcodec_enc_clock_on (&ctx->dev->pm); +mtk_vcodec_enc_clock_on (ctx->dev,0 ); ret = ctx->enc_if->encode (ctx->drv_handle, opt, frm_buf, bs_buf, result); -mtk_vcodec_enc_clock_off (&ctx->dev->pm); +mtk_vcodec_enc_clock_off (ctx->dev,0 );spin_lock_irqsave (&ctx->dev->irqlock, flags); ctx->dev->curr_ctx =NULL ;
@@ -89,9 +85,7 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx)return 0 ;mtk_venc_lock (ctx); -mtk_vcodec_enc_clock_on (&ctx->dev->pm); ret = ctx->enc_if->deinit (ctx->drv_handle); -mtk_vcodec_enc_clock_off (&ctx->dev->pm);mtk_venc_unlock (ctx); ctx->drv_handle =NULL ;
Signature · 1 line
2.25.1
Re: [PATCH 5/9] media: mtk-vcodec: Rewrite venc clock interface
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_release_enc_pm(struct mtk_vcodec_pm *pm) · line 94
Quoted 9 lines · Irui Wang
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +5
-3-void mtk_vcodec_enc_clock_on (struct mtk_vcodec_pm *pm) +void mtk_vcodec_enc_clock_on (struct mtk_vcodec_dev *dev,int core_id) { -struct mtk_vcodec_clk *enc_clk = &pm->venc_clk; -int ret, i =0 ; +struct mtk_venc_comp_dev *venc; +struct mtk_vcodec_pm *enc_pm; +struct mtk_vcodec_clk *enc_clk; +struct clk *clk;
To be neat, remove the extra spaces.
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_release_enc_pm(struct mtk_vcodec_pm *pm) · line 106
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +0
-4- ret =mtk_smi_larb_get (pm->larbvenc); -if (ret) { -mtk_v4l2_err ("mtk_smi_larb_get larb3 fail %d" , ret); - goto clkerr;
I may miss the context but why does it remove mtk_smi_larb_get()?
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) · line 120
Quoted 11 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +5
-4-void mtk_vcodec_enc_clock_off (struct mtk_vcodec_pm *pm) +void mtk_vcodec_enc_clock_off (struct mtk_vcodec_dev *dev,int core_id) { -struct mtk_vcodec_clk *enc_clk = &pm->venc_clk; -int i =0 ; +struct mtk_venc_comp_dev *venc; +struct mtk_vcodec_pm *enc_pm; +struct mtk_vcodec_clk *enc_clk; +int i; -mtk_smi_larb_put (pm->larbvenc);
Same here. Why does it remove mtk_smi_larb_put()?
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) · line 168
Quoted 6 lines
int
mtk_venc_enable_comp_hw(struct mtk_vcodec_dev *dev){drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +2
-0int i, ret;struct mtk_venc_comp_dev *venc_comp; +struct mtk_vcodec_clk *enc_clk; +int j =0 ;
It doesn't need to be initialized. Can inline to "int i, ret;".
PATCH 6/9 media: mtk-vcodec: Add new venc drv interface for frame_racing mode
In reply to Irui WangFrame-racing mode encoding need more venc working buffers, it will break the compatibility if we just add venc_vsi in AP-Kernel but not in firmware, so add a new venc driver interface to distinguish the sigle_core_mode and frame_racing mode.
The new driver interface can be used for different codecs in the future.
--- drivers/media/platform/mtk-vcodec/Makefile | 1 + .../platform/mtk-vcodec/mtk_vcodec_drv.h | 1 + .../platform/mtk-vcodec/mtk_vcodec_util.c | 19 + .../platform/mtk-vcodec/mtk_vcodec_util.h | 4 + .../platform/mtk-vcodec/venc/venc_common_if.c | 629 ++++++++++++++++++ .../media/platform/mtk-vcodec/venc_drv_if.c | 5 +- .../media/platform/mtk-vcodec/venc_drv_if.h | 1 + 7 files changed, 659 insertions(+), 1 deletion(-) create mode 100644 drivers/media/platform/mtk-vcodec/venc/venc_common_if.c
drivers/media/platform/mtk-vcodec/Makefile +1 -0
@@ -15,6 +15,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ mtk-vcodec-enc-y := venc/venc_vp8_if.o \ venc/venc_h264_if.o \ + venc/venc_common_if.o \ mtk_vcodec_enc.o \ mtk_vcodec_enc_drv.o \ mtk_vcodec_enc_pm.o \
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +1 -0
@@ -352,6 +352,7 @@ struct mtk_vcodec_enc_pdata { };#define MTK_ENC_CTX_IS_EXT (ctx) ((ctx)->dev->venc_pdata->uses_ext) +#define MTK_ENC_HW_MODE (ctx) ((ctx)->dev->venc_pdata->hw_mode)/** * struct mtk_vcodec_dev - driver data
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +19 -0
@@ -9,6 +9,7 @@#include "mtk_vcodec_drv.h" #include "mtk_vcodec_util.h" +#include "mtk_vcodec_enc_hw.h" /* For encoder, this will enable logs in venc/*/ bool mtk_vcodec_dbg;
@@ -33,6 +34,24 @@ void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, }EXPORT_SYMBOL (mtk_vcodec_get_reg_addr); +void __iomem *mtk_get_venc_comp_reg_addr (struct mtk_vcodec_ctx *data, +unsigned int hw_id) +{ +struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data; +struct mtk_venc_comp_dev *venc; + +if (!data || hw_id >=MTK_VENC_HW_MAX ) { +mtk_v4l2_err ("Invalid arguments, hw_id=%d" , hw_id); +return NULL ; + } + venc = (struct mtk_venc_comp_dev *)ctx->dev->enc_comp_dev[hw_id]; +if (!venc) +return NULL ; + +return venc->reg_base; +} +EXPORT_SYMBOL (mtk_get_venc_comp_reg_addr); +int mtk_vcodec_mem_alloc (struct mtk_vcodec_ctx *data,struct mtk_vcodec_mem *mem) {
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +4 -0
@@ -75,6 +75,10 @@ extern bool mtk_vcodec_dbg;void __iomem *mtk_vcodec_get_reg_addr (struct mtk_vcodec_ctx *data,unsigned int reg_idx); + +void __iomem *mtk_get_venc_comp_reg_addr (struct mtk_vcodec_ctx *data, +unsigned int hw_id); +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,
drivers/media/platform/mtk-vcodec/venc/venc_common_if.c new file +629 -0
629 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/venc_drv_if.c +4 -1
@@ -25,7 +25,10 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->enc_if = &venc_vp8_if;break ;case V4L2_PIX_FMT_H264 : - ctx->enc_if = &venc_h264_if; +if (MTK_ENC_HW_MODE (ctx) ==VENC_FRAME_RACING_MODE ) + ctx->enc_if = &venc_if; +else + ctx->enc_if = &venc_h264_if;break ;default :return -EINVAL ;
drivers/media/platform/mtk-vcodec/venc_drv_if.h +1 -0
@@ -125,6 +125,7 @@ struct venc_done_result {extern const struct venc_common_if venc_h264_if;extern const struct venc_common_if venc_vp8_if; +extern const struct venc_common_if venc_if;/* * venc_if_init - Create the driver handle
Signature · 1 line
2.25.1
Re: [PATCH 6/9] media: mtk-vcodec: Add new venc drv interface for frame_racing mode
Quoted 7 lines · Irui Wang
Frame-racing mode encoding need more venc working buffers, it will break the compatibility if we just add
venc_vsiin AP-Kernel but not in firmware, so add a new venc driver interface to distinguish thesigle_core_modeandframe_racingmode.The new driver interface can be used for different codecs in the future.
The patch contains more code than the commit message explains that I couldn't understand. Only find some nits.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c line 12
Quoted 7 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +1
-0@@ -9,6 +9,7 @@#include "mtk_vcodec_drv.h" #include "mtk_vcodec_util.h" +#include "mtk_vcodec_enc_hw.h"
Please try to maintain the order.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, · line 40
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +4
-0+void __iomem *mtk_get_venc_comp_reg_addr (struct mtk_vcodec_ctx *data, +unsigned int hw_id) +{ +struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
typeof(ctx) == typeof(data), rename the function argument 'data' to 'ctx'.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +4
-0+static int venc_alloc_work_buf (struct venc_common_inst *inst) +{ +int i; +int ret =0 ;
It doesn't need to be initialized. See comment below.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 3 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +3
-0+mtk_vcodec_debug_leave (inst); + +return ret;
It is more clear if just return 0 here. In the meantime, ret doesn't need to be initialized.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+static unsigned int venc_wait_comp_done (struct venc_common_inst *inst, +unsigned int hw_id) +{ +unsigned int irq_status =0 ; +struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)inst->ctx;
No need to cast.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+static int venc_encode_sps (struct venc_common_inst *inst, +struct mtk_vcodec_mem *bs_buf, +unsigned int *bs_size) +{ +int ret =0 ;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+ *bs_size =venc_read_reg (inst,VENC_PIC_BITSTREAM_BYTE_CNT , +MTK_VENC_CORE0 ); +mtk_vcodec_debug (inst,"bs size %d <-" , *bs_size); + +return ret;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+static int venc_encode_pps (struct venc_common_inst *inst, +struct mtk_vcodec_mem *bs_buf, +unsigned int *bs_size) +{ +int ret =0 ;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+ *bs_size =venc_read_reg (inst,VENC_PIC_BITSTREAM_BYTE_CNT , +MTK_VENC_CORE0 ); +mtk_vcodec_debug (inst,"bs size %d <-" , *bs_size); + +return ret;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+static int venc_encode_header (struct venc_common_inst *inst, +struct mtk_vcodec_mem *bs_buf, +unsigned int *bs_size) +{ +int ret =0 ;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +4
-0+memcpy (bs_buf->va + bs_size_sps, inst->pps_buf.va, bs_size_pps); + *bs_size = bs_size_sps + bs_size_pps; + +return ret;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 7 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +7
-0+static int venc_encode_frame (struct venc_common_inst *inst, +struct venc_frm_buf *frm_buf, +struct mtk_vcodec_mem *bs_buf, +unsigned int *bs_size, +int hw_id) +{ +int ret =0 ;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +5
-0+ ++inst->frm_cnt; +mtk_vcodec_debug (inst,"frm %d bs_size %d key_frm %d <-" , + inst->frm_cnt, *bs_size, inst->vpu_inst.is_key_frm); + +return ret;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 11 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +11
-0+static void h264_encode_filler (struct venc_common_inst *inst,void *buf, +int size) +{ +unsigned char *p = buf; + +if (size <H264_FILLER_MARKER_SIZE ) { +mtk_vcodec_err (inst,"filler size too small %d" , size); +return ; + } + +memcpy (p, h264_filler_marker,ARRAY_SIZE (h264_filler_marker));
Replace ARRAY_SIZE(h264_filler_marker) to H264_FILLER_MARKER_SIZE.
Quoted 9 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +9
-0+static int venc_init (struct mtk_vcodec_ctx *ctx) +{ +int i; +int ret =0 ; +struct venc_common_inst *inst; + + inst =kzalloc (sizeof (*inst),GFP_KERNEL ); +if (!inst) +return -ENOMEM ;
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 10 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +10
-0+ + inst->ctx = ctx; + inst->vpu_inst.ctx = ctx; + inst->vpu_inst.id =SCP_IPI_VENC_H264 ; + +mtk_vcodec_debug_enter (inst); + + ret =vpu_enc_init (&inst->vpu_inst); + + inst->vsi = (struct venc_vsi *)inst->vpu_inst.vsi;
No need to cast.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 8 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +8
-0+static int venc_encode (void *handle, +enum venc_start_opt opt, +struct venc_frm_buf *frm_buf, +struct mtk_vcodec_mem *bs_buf, +struct venc_done_result *result) +{ +int ret; +struct venc_common_inst *inst = (struct venc_common_inst *)handle;
No need to cast.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +6
-0+default : +mtk_vcodec_err (inst,"venc_start_opt %d not supported" , opt); +return -EINVAL ; + } + +return ret;
It is more clear if just return 0 here.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 6 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +6
-0+static int venc_set_param (void *handle, +enum venc_set_param_type type, +struct venc_enc_param *enc_prm) +{ +int ret =0 ; +struct venc_common_inst *inst = (struct venc_common_inst *)handle;
No need to cast.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 3 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +3
-0+static int venc_deinit (void *handle) +{ +int ret =0 ;
Same.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 1 line
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +1
-0+struct venc_common_inst *inst = (struct venc_common_inst *)handle;
No need to cast.
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
Quoted 4 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +4
-0+mtk_vcodec_debug_leave (inst); +kfree (inst); + +return ret;
Same.
PATCH 7/9 media: mtk-vcodec: Add frame racing mode encode process
In reply to Irui WangThe frame_racing mode encoding is try to use the two venc cores:
frame#0 use core#0, frame#1 use core#1, frame#2 use core#0...,
Lock the device and enabe the clock by used core, for sequence header encoding, it always used core#0.
--- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 5 +- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 35 ++++---- .../platform/mtk-vcodec/mtk_vcodec_enc.h | 4 +- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 6 +- .../platform/mtk-vcodec/venc/venc_common_if.c | 6 +- .../platform/mtk-vcodec/venc/venc_h264_if.c | 6 +- .../platform/mtk-vcodec/venc/venc_vp8_if.c | 2 +- .../media/platform/mtk-vcodec/venc_drv_if.c | 85 ++++++++++++++----- .../media/platform/mtk-vcodec/venc_drv_if.h | 4 + .../media/platform/mtk-vcodec/venc_vpu_if.c | 11 ++- .../media/platform/mtk-vcodec/venc_vpu_if.h | 3 +- 11 files changed, 118 insertions(+), 49 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +4 -1
@@ -273,6 +273,7 @@ struct vdec_pic_info {* @decoded_frame_cnt: number of decoded frames * @lock: protect variables accessed by V4L2 threads and worker thread such as * mtk_video_dec_buf. +* @enc_idx: used to record encoded frame count */ struct mtk_vcodec_ctx {enum mtk_instance_type type;
@@ -313,6 +314,8 @@ struct mtk_vcodec_ctx {int decoded_frame_cnt;struct mutex lock; +int hw_id; +int enc_idx; };enum mtk_chip {
@@ -422,7 +425,7 @@ struct mtk_vcodec_dev {int enc_irq;struct mutex dec_mutex; -struct mutex enc_mutex; +struct mutex enc_mutex[MTK_VENC_HW_MAX ];struct mtk_vcodec_pm pm;unsigned int dec_capability;
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +20 -15
@@ -1090,21 +1090,26 @@ static void mtk_venc_worker(struct work_struct *work)if (enc_result.is_key_frm) dst_buf->flags |=V4L2_BUF_FLAG_KEYFRAME ; -if (ret) { -v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); - dst_buf->vb2_buf.planes[0 ].bytesused =0 ; -v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); -mtk_v4l2_err ("venc_if_encode failed=%d" , ret); - }else { -v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_DONE ); - dst_buf->vb2_buf.planes[0 ].bytesused = enc_result.bs_size; -v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); -mtk_v4l2_debug (2 ,"venc_if_encode bs size=%d" , - enc_result.bs_size); +if (ctx->dev->venc_pdata->hw_mode ==VENC_SINGLE_CORE_MODE ) { +if (ret) { +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); + dst_buf->vb2_buf.planes[0 ].bytesused =0 ; +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); +mtk_v4l2_err ("venc_if_encode failed=%d" , ret); + }else { +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_DONE ); + dst_buf->vb2_buf.planes[0 ].bytesused = + enc_result.bs_size; +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_DONE ); +mtk_v4l2_debug (2 ,"venc_if_encode bs size=%d" , + enc_result.bs_size); + } }v4l2_m2m_job_finish (ctx->dev->m2m_dev_enc, ctx->m2m_ctx); + ctx->enc_idx++; +mtk_v4l2_debug (1 ,"<=== src_buf[%d] dst_buf[%d] venc_if_encode ret=%d Size=%u===>" , src_buf->vb2_buf.index, dst_buf->vb2_buf.index, ret, enc_result.bs_size);
@@ -1305,19 +1310,19 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,return vb2_queue_init (dst_vq); } -int mtk_venc_unlock (struct mtk_vcodec_ctx *ctx) +int mtk_venc_unlock (struct mtk_vcodec_ctx *ctx,int core_id) {struct mtk_vcodec_dev *dev = ctx->dev; -mutex_unlock (&dev->enc_mutex); +mutex_unlock (&dev->enc_mutex[core_id]);return 0 ; } -int mtk_venc_lock (struct mtk_vcodec_ctx *ctx) +int mtk_venc_lock (struct mtk_vcodec_ctx *ctx,int core_id) {struct mtk_vcodec_dev *dev = ctx->dev; -mutex_lock (&dev->enc_mutex); +mutex_lock (&dev->enc_mutex[core_id]);return 0 ; }
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h +2 -2
@@ -41,8 +41,8 @@ struct mtk_video_enc_buf {extern const struct v4l2_ioctl_ops mtk_venc_ioctl_ops;extern const struct v4l2_m2m_ops mtk_venc_m2m_ops; -int mtk_venc_unlock (struct mtk_vcodec_ctx *ctx); -int mtk_venc_lock (struct mtk_vcodec_ctx *ctx); +int mtk_venc_unlock (struct mtk_vcodec_ctx *ctx,int core_id); +int mtk_venc_lock (struct mtk_vcodec_ctx *ctx,int core_id);int mtk_vcodec_enc_queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq);void mtk_vcodec_enc_release (struct mtk_vcodec_ctx *ctx);
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +4 -2
@@ -320,7 +320,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)struct resource *res;phandle rproc_phandle;enum mtk_vcodec_fw_type fw_type; -int ret; +int ret, i;struct component_match *match =NULL ; dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL );
@@ -384,7 +384,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) } } -mutex_init (&dev->enc_mutex); +for (i =0 ; i <MTK_VENC_HW_MAX ; i++) +mutex_init (&dev->enc_mutex[i]); +mutex_init (&dev->dev_mutex);spin_lock_init (&dev->irqlock);
drivers/media/platform/mtk-vcodec/venc/venc_common_if.c +3 -3
@@ -300,7 +300,7 @@ static int venc_encode_sps(struct venc_common_inst *inst,mtk_vcodec_debug_enter (inst); ret =vpu_enc_encode (&inst->vpu_inst,VENC_BS_MODE_SPS ,NULL , - bs_buf, bs_size,NULL ); + bs_buf, bs_size,NULL ,MTK_VENC_CORE0 );if (ret)return ret;
@@ -328,7 +328,7 @@ static int venc_encode_pps(struct venc_common_inst *inst,mtk_vcodec_debug_enter (inst); ret =vpu_enc_encode (&inst->vpu_inst,VENC_BS_MODE_PPS ,NULL , - bs_buf, bs_size,NULL ); + bs_buf, bs_size,NULL ,MTK_VENC_CORE0 );if (ret)return ret;
@@ -386,7 +386,7 @@ static int venc_encode_frame(struct venc_common_inst *inst, frame_info.frm_count, frame_info.skip_frm_count, frame_info.frm_type); ret =vpu_enc_encode (&inst->vpu_inst,VENC_BS_MODE_FRAME , frm_buf, - bs_buf, bs_size, &frame_info); + bs_buf, bs_size, &frame_info, hw_id);if (ret)return ret;
drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +3 -3
@@ -368,7 +368,7 @@ static int h264_encode_sps(struct venc_h264_inst *inst,mtk_vcodec_debug_enter (inst); ret =vpu_enc_encode (&inst->vpu_inst,H264_BS_MODE_SPS ,NULL , - bs_buf, bs_size,NULL ); + bs_buf, bs_size,NULL ,MTK_VENC_CORE0 );if (ret)return ret;
@@ -395,7 +395,7 @@ static int h264_encode_pps(struct venc_h264_inst *inst,mtk_vcodec_debug_enter (inst); ret =vpu_enc_encode (&inst->vpu_inst,H264_BS_MODE_PPS ,NULL , - bs_buf, bs_size,NULL ); + bs_buf, bs_size,NULL ,MTK_VENC_CORE0 );if (ret)return ret;
@@ -452,7 +452,7 @@ static int h264_encode_frame(struct venc_h264_inst *inst, frame_info.frm_count, frame_info.skip_frm_count, frame_info.frm_type); ret =vpu_enc_encode (&inst->vpu_inst,H264_BS_MODE_FRAME , frm_buf, - bs_buf, bs_size, &frame_info); + bs_buf, bs_size, &frame_info,MTK_VENC_CORE0 );if (ret)return ret;
drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c +1 -1
@@ -303,7 +303,7 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *inst,mtk_vcodec_debug (inst,"->frm_cnt=%d" , inst->frm_cnt); ret =vpu_enc_encode (&inst->vpu_inst,0 , frm_buf, bs_buf, bs_size, -NULL ); +NULL ,MTK_VENC_CORE0 );if (ret)return ret;
drivers/media/platform/mtk-vcodec/venc_drv_if.c +65 -20
124 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/venc_drv_if.h +4 -0
@@ -168,4 +168,8 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx,struct mtk_vcodec_mem *bs_buf, struct venc_done_result *result); +void venc_encode_prepare (struct mtk_vcodec_ctx *ctx, +enum venc_start_opt opt); +void venc_encode_unprepare (struct mtk_vcodec_ctx *ctx, +enum venc_start_opt opt);#endif /* _VENC_DRV_IF_H_ */
drivers/media/platform/mtk-vcodec/venc_vpu_if.c +10 -1
@@ -226,9 +226,12 @@ int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode,struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, unsigned int *bs_size, - struct venc_frame_info *frame_info) + struct venc_frame_info *frame_info, + int hw_id) { const bool is_ext = MTK_ENC_CTX_IS_EXT(vpu->ctx); +const int hw_mode =MTK_ENC_HW_MODE (vpu->ctx); +size_t msg_size = is_ext ?sizeof (struct venc_ap_ipi_msg_enc_ext ) :sizeof (struct venc_ap_ipi_msg_enc );
@@ -262,6 +265,12 @@ int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, out.data[1 ] = frame_info->skip_frm_count; out.data[2 ] = frame_info->frm_type; } + +if (hw_mode ==VENC_FRAME_RACING_MODE ) { + out.data_item =4 ; + out.data[3 ] = hw_id; + } +if (vpu_enc_send_msg (vpu, &out, msg_size)) {mtk_vcodec_err (vpu,"AP_IPIMSG_ENC_ENCODE %d fail" , bs_mode);
drivers/media/platform/mtk-vcodec/venc_vpu_if.h +2 -1
@@ -46,7 +46,8 @@ int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode,struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, unsigned int *bs_size, - struct venc_frame_info *frame_info); + struct venc_frame_info *frame_info, + int hw_id);int vpu_enc_deinit (struct venc_vpu_inst *vpu);#endif
Signature · 1 line
2.25.1
Re: [PATCH 7/9] media: mtk-vcodec: Add frame racing mode encode process
Quoted 1 line · Irui Wang
The
frame_racingmode encoding is try to use the two venc cores:
s/is try/tries/
Quoted 1 line
frame#0 use core#0, frame#1 use core#1, frame#2 use core#0...,
s/use/uses/g
Quoted 1 line
Lock the device and enabe the clock by used core, for sequence
s/enabe/enable/
Quoted 1 line
header encoding, it always used core#0.
s/used/uses/
Quoted 11 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +1
-0@@ -273,6 +273,7 @@ struct vdec_pic_info {* @decoded_frame_cnt: number of decoded frames * @lock: protect variables accessed by V4L2 threads and worker thread such as * mtk_video_dec_buf. +* @enc_idx: used to record encoded frame count */ struct mtk_vcodec_ctx {enum mtk_instance_type type;
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h struct mtk_vcodec_ctx { · line 318
Quoted 5 lines
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +2
-0@@ -313,6 +314,8 @@ struct mtk_vcodec_ctx {int decoded_frame_cnt;struct mutex lock; +int hw_id; +int enc_idx;
hw_id lacks of kerneldoc which could introduce smatch warning.
drivers/media/platform/mtk-vcodec/venc_drv_if.c line 18
Quoted 7 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-0@@ -15,6 +15,7 @@#include "mtk_vcodec_enc.h" #include "mtk_vcodec_enc_pm.h" +#include "mtk_vcodec_enc_hw.h"
Please try to maintain the order.
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) · line 38
Quoted 6 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-1@@ -34,9 +35,9 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)return -EINVAL ; } -mtk_venc_lock (ctx); +mtk_venc_lock (ctx,0 );
Does it make more sense to use ctx->hw_id instead 0 (even if it is always 0 in the path)?
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) · line 40
Quoted 3 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-1ret = ctx->enc_if->init (ctx); -mtk_venc_unlock (ctx); +mtk_venc_unlock (ctx,0 );
Same.
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_set_param(struct mtk_vcodec_ctx *ctx, · line 50
Quoted 6 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-1@@ -46,9 +47,9 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx, {int ret =0 ; -mtk_venc_lock (ctx); +mtk_venc_lock (ctx,0 );
Same.
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_set_param(struct mtk_vcodec_ctx *ctx, · line 52
Quoted 3 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-1ret = ctx->enc_if->set_param (ctx->drv_handle, type, in); -mtk_venc_unlock (ctx); +mtk_venc_unlock (ctx,0 );
Same.
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_deinit(struct mtk_vcodec_ctx *ctx) · line 79
Quoted 6 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-1@@ -87,11 +76,67 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx)if (!ctx->drv_handle)return 0 ; -mtk_venc_lock (ctx); +mtk_venc_lock (ctx,0 );
Same.
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_deinit(struct mtk_vcodec_ctx *ctx) · line 81
Quoted 3 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +1
-1ret = ctx->enc_if->deinit (ctx->drv_handle); -mtk_venc_unlock (ctx); +mtk_venc_unlock (ctx,0 );
Same.
Quoted 12 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +12
-0+void venc_encode_unprepare (struct mtk_vcodec_ctx *ctx, +enum venc_start_opt opt) +{ +unsigned long flags; +struct mtk_venc_comp_dev *venc; + +/*clock off and unlock after irq done*/ +if (ctx->dev->venc_pdata->hw_mode ==VENC_FRAME_RACING_MODE ) { +if (opt ==VENC_START_OPT_ENCODE_SEQUENCE_HEADER ) { +mtk_vcodec_enc_clock_off (ctx->dev, ctx->hw_id); +spin_lock_irqsave (&ctx->dev->irqlock, flags); + venc = ctx->dev->enc_comp_dev[ctx->hw_id];
drivers/media/platform/mtk-vcodec/venc_drv_if.c int venc_if_deinit(struct mtk_vcodec_ctx *ctx) · line 140
Quoted 10 lines
drivers/media/platform/mtk-vcodec/venc_drv_if.c +10
-0+ venc->curr_ctx =NULL ; +spin_unlock_irqrestore (&ctx->dev->irqlock, flags); +mtk_venc_unlock (ctx, ctx->hw_id); + } + }else { +mtk_vcodec_enc_clock_off (ctx->dev, ctx->hw_id); +spin_lock_irqsave (&ctx->dev->irqlock, flags); + ctx->dev->curr_ctx =NULL ; +spin_unlock_irqrestore (&ctx->dev->irqlock, flags); +mtk_venc_unlock (ctx, ctx->hw_id);
The few statements are identical. Should try to reuse them.
PATCH 8/9 media: mtk-vcodec: Return encode result to client
In reply to Irui WangFor frame-racing mode encoding, there will no sync wait IRQ done function, so the encode result can't return to client in device_run. After device_run called to trigger encoding process, finish it, so another scheduled job can be ran. When encoding done, return the encode result to client in IRQ handler.
--- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 6 ++ .../platform/mtk-vcodec/mtk_vcodec_enc.c | 61 ++++++++++++++++++- .../platform/mtk-vcodec/mtk_vcodec_enc.h | 4 +- .../platform/mtk-vcodec/mtk_vcodec_enc_hw.c | 35 +++++++++++ .../platform/mtk-vcodec/mtk_vcodec_util.h | 1 + .../platform/mtk-vcodec/venc/venc_common_if.c | 9 +++ .../media/platform/mtk-vcodec/venc_drv_if.h | 2 + 7 files changed, 115 insertions(+), 3 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +6 -0
@@ -274,6 +274,9 @@ struct vdec_pic_info {* @lock: protect variables accessed by V4L2 threads and worker thread such as * mtk_video_dec_buf. * @enc_idx: used to record encoded frame count +* @pfrm_buf: used to store current ctx's frame buffer information +* @pbs_buf: used to store current ctx's bitstream buffer information +* @hdr_size: used to store prepend header size */ struct mtk_vcodec_ctx {enum mtk_instance_type type;
@@ -316,6 +319,9 @@ struct mtk_vcodec_ctx {int hw_id;int enc_idx; +struct vb2_v4l2_buffer *pfrm_buf[MTK_VENC_HW_MAX ]; +struct vb2_v4l2_buffer *pbs_buf[MTK_VENC_HW_MAX ]; +unsigned int hdr_size; };enum mtk_chip {
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +59 -2
106 lines not on this page · raw message
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h +3 -1
@@ -48,5 +48,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,void mtk_vcodec_enc_release (struct mtk_vcodec_ctx *ctx);int mtk_vcodec_enc_ctrls_setup (struct mtk_vcodec_ctx *ctx);void mtk_vcodec_enc_set_default_params (struct mtk_vcodec_ctx *ctx); - +void mtk_venc_buf_done (struct mtk_vcodec_ctx *ctx,int core_id, +unsigned int bs_size,bool time_out,bool key_frame); +void mtk_venc_lock_all (struct mtk_vcodec_ctx *ctx);#endif /* _MTK_VCODEC_ENC_H_ */
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c +35 -0
@@ -12,6 +12,17 @@#include "mtk_vcodec_enc_hw.h" #include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_enc.h" +#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098 +#define VENC_PIC_FRM_TYPE 0x0010 +#define VENC_PIC_KEY_FRM 0x2 + +/* Wake up core context wait_queue */ +static void mtk_venc_comp_wake_up_ctx (struct mtk_vcodec_ctx *ctx, +unsigned int hw_id) +{ + ctx->int_cond =1 ; +wake_up_interruptible (&ctx->queue); +}static void clean_irq_status (unsigned int irq_status,void __iomem *addr) {
@@ -40,6 +51,9 @@ static irqreturn_t mtk_enc_comp_irq_handler(int irq, void *priv)struct mtk_vcodec_ctx *ctx;unsigned long flags;void __iomem *addr; +unsigned int bs_size; +unsigned int frm_type; +bool is_key_frame =0 ;spin_lock_irqsave (&dev->master_dev->irqlock, flags); ctx = dev->curr_ctx;
@@ -49,7 +63,28 @@ static irqreturn_t mtk_enc_comp_irq_handler(int irq, void *priv) addr = dev->reg_base +MTK_VENC_IRQ_ACK_OFFSET ; ctx->irq_status =readl (dev->reg_base +MTK_VENC_IRQ_STATUS_OFFSET ); + bs_size =readl (dev->reg_base +VENC_PIC_BITSTREAM_BYTE_CNT ); + frm_type =readl (dev->reg_base +VENC_PIC_FRM_TYPE );clean_irq_status (ctx->irq_status, addr); +if (ctx->irq_status &MTK_VENC_IRQ_STATUS_FRM ) { +if (ctx->hdr_size !=0 ) { + bs_size += ctx->hdr_size; + ctx->hdr_size =0 ; + } +if (frm_type &VENC_PIC_KEY_FRM ) + is_key_frame =1 ; + +mtk_venc_buf_done (ctx, dev->core_id, bs_size,0 , is_key_frame); +mtk_vcodec_enc_clock_off (dev->master_dev, dev->core_id); + +spin_lock_irqsave (&dev->master_dev->irqlock, flags); + dev->curr_ctx =NULL ; +spin_unlock_irqrestore (&dev->master_dev->irqlock, flags); + +mtk_venc_unlock (ctx, dev->core_id); + }else { +mtk_venc_comp_wake_up_ctx (ctx, dev->core_id); + }return IRQ_HANDLED ; }
drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +1 -0
@@ -15,6 +15,7 @@ struct mtk_vcodec_mem {size_t size;void *va;dma_addr_t dma_addr; +void *buf; };struct mtk_vcodec_fb {
drivers/media/platform/mtk-vcodec/venc/venc_common_if.c +9 -0
@@ -481,6 +481,13 @@ static int venc_encode(void *handle,unsigned int bs_size_hdr;unsigned int bs_size_frm; +/* +* the frm_buf and bs_buf need to be recorded into ctx, +* when encoding done, the target buffer can be obtained +*/ + ctx->pfrm_buf[ctx->hw_id] = frm_buf->src_addr; + ctx->pbs_buf[ctx->hw_id] = bs_buf->buf; +if (!inst->prepend_hdr) { ret =venc_encode_frame (inst, frm_buf, bs_buf, &result->bs_size, ctx->hw_id);
@@ -528,6 +535,8 @@ static int venc_encode(void *handle, result->bs_size = hdr_sz + filler_sz + bs_size_frm; + ctx->hdr_size = hdr_sz + filler_sz; +mtk_vcodec_debug (inst,"hdr %d filler %d frame %d bs %d" , hdr_sz, filler_sz, bs_size_frm, result->bs_size);
drivers/media/platform/mtk-vcodec/venc_drv_if.h +2 -0
@@ -108,9 +108,11 @@ struct venc_frame_info {/* * struct venc_frm_buf - frame buffer information used in venc_if_encode() * @fb_addr: plane frame buffer addresses +* @src_addr: vb2_v4l2_buffer src buffer address */ struct venc_frm_buf {struct mtk_vcodec_fb fb_addr[MTK_VCODEC_MAX_PLANES ]; +void *src_addr; };/*
Signature · 1 line
2.25.1
PATCH 9/9 media: mtk-vcodec: Add delayed worker for encode timeout
In reply to Irui WangWhen encoding timeout, a delayed timeout worker is needed because of asynchronous encoding process, restore encoding process in timeout worker.
--- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 12 ++++-- .../platform/mtk-vcodec/mtk_vcodec_enc_hw.c | 26 +++++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_hw.h | 2 + .../platform/mtk-vcodec/venc/venc_common_if.c | 43 +++++++++++++++++-- 4 files changed, 77 insertions(+), 6 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +9 -3
@@ -1340,9 +1340,15 @@ void mtk_venc_buf_done(struct mtk_vcodec_ctx *ctx, int core_id,if (key_frame) dst_vb2_v4l2->flags |=V4L2_BUF_FLAG_KEYFRAME ; -v4l2_m2m_buf_done (src_vb2_v4l2,VB2_BUF_STATE_DONE ); - dst_vb2_v4l2->vb2_buf.planes[0 ].bytesused = bs_size; -v4l2_m2m_buf_done (dst_vb2_v4l2,VB2_BUF_STATE_DONE ); +if (time_out) { +v4l2_m2m_buf_done (src_vb2_v4l2,VB2_BUF_STATE_ERROR ); + dst_vb2_v4l2->vb2_buf.planes[0 ].bytesused =0 ; +v4l2_m2m_buf_done (dst_vb2_v4l2,VB2_BUF_STATE_ERROR ); + }else { +v4l2_m2m_buf_done (src_vb2_v4l2,VB2_BUF_STATE_DONE ); + dst_vb2_v4l2->vb2_buf.planes[0 ].bytesused = bs_size; +v4l2_m2m_buf_done (dst_vb2_v4l2,VB2_BUF_STATE_DONE ); + } } }
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.c +26 -0
@@ -16,6 +16,28 @@#define VENC_PIC_FRM_TYPE 0x0010#define VENC_PIC_KEY_FRM 0x2 +static void mtk_venc_timeout_worker (struct work_struct *work) +{ +struct mtk_venc_comp_dev *dev =container_of (work, + struct mtk_venc_comp_dev, + enc_timeout_worker.work); + +struct mtk_vcodec_ctx *ctx; +unsigned long flags; + +spin_lock_irqsave (&dev->master_dev->irqlock, flags); + ctx = dev->curr_ctx; + +dev_err (&dev->plat_dev->dev,"core: %d timeout\n" , dev->core_id); + +mtk_venc_buf_done (ctx, dev->core_id,0 ,1 ,0 ); + +mtk_vcodec_enc_clock_off (dev->master_dev, dev->core_id); + dev->curr_ctx =NULL ; +spin_unlock_irqrestore (&dev->master_dev->irqlock, flags); + +mtk_venc_unlock (ctx, dev->core_id); +}/* Wake up core context wait_queue */ static void mtk_venc_comp_wake_up_ctx (struct mtk_vcodec_ctx *ctx,unsigned int hw_id)
@@ -67,6 +89,7 @@ static irqreturn_t mtk_enc_comp_irq_handler(int irq, void *priv) frm_type =readl (dev->reg_base +VENC_PIC_FRM_TYPE );clean_irq_status (ctx->irq_status, addr);if (ctx->irq_status &MTK_VENC_IRQ_STATUS_FRM ) { +cancel_delayed_work (&dev->enc_timeout_worker);if (ctx->hdr_size !=0 ) { bs_size += ctx->hdr_size; ctx->hdr_size =0 ;
@@ -182,6 +205,9 @@ static int mtk_venc_comp_probe(struct platform_device *pdev)platform_set_drvdata (pdev, comp_dev); +INIT_DELAYED_WORK (&comp_dev->enc_timeout_worker, + mtk_venc_timeout_worker); + ret =component_add (&pdev->dev, &mtk_venc_component_ops);if (ret) {dev_err (&pdev->dev,"Failed to add component: %d\n" , ret);
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.h +2 -0
@@ -19,6 +19,7 @@* @irq_status: venc hw irq status * @enc_irq: venc device irq * @core id: for venc core id: core#0, core#1... +* @enc_timeout_worker: venc timeout worker */ struct mtk_venc_comp_dev {struct platform_device *plat_dev;
@@ -31,6 +32,7 @@ struct mtk_venc_comp_dev {unsigned int irq_status;int enc_irq;int core_id; + struct delayed_work enc_timeout_worker; };#endif /* _MTK_VCODEC_ENC_HW_H_ */
drivers/media/platform/mtk-vcodec/venc/venc_common_if.c +40 -3
93 lines not on this page · raw message
Signature · 1 line
2.25.1
AngeloGioacchino Del Regno
maintainerIl 16/08/21 12:59, Irui Wang ha scritto:
Quoted 79 lines
MT8195 has two H264 encoder cores, they have their own power-domains, clocks, interrupts, register base. The two H264 encoder cores can work together to achieve higher performance.
This series of patches is to use enable two h264 encoder cores. path[1..2]: use linux component framework to manage encoder hardware, user call "mt8195-vcodec-enc" driver can get the encoder master device, the encoding work is done by the two encoder core device. The
hw_modevariable is added to distinguish from old platform, two encoder cores called "FRAME_RACING_MODE".The hardware mode of two encoder cores work
together(overlap, another word called)on MT8195 called "frame_racing_mode", the two encoder power-domains should be power on together while encoding, the encoding process look like this:VENC Core0 frm#0....frm#2....frm#4 VENC Core1 .frm#1....frm#3....frm#5patch[3..5]: due to the component device, the master device has no power-domains/clocks properties in dtsi, so the power/clock init function can't use for "
frame_racing_mode" device in master device probe process, it should be called in component device probe process. Power on the hardware power and clock on demand.patch[6]: "
frame_racing_mode" encoding need a new set of memory buffer for two encoder cores. For compatibility, we should new a encoder driver interface.patch[7..9]: add "
frame_racing_mode" encoding process:
As-Is: Synchronous
VIDIOC_QBUF#0 -->device_run(triger encoder)--> wait encoder IRQ --> encode done with result -->job_finishVIDIOC_QBUF#1 -->
device_run(triger encoder)--> wait encoder IRQ --> encode done with result -->job_finish
...To-Be: Asynchronous
VIDIOC_QBUF#0 -->device_run(triger encoder core0)-->job_finish..VIDIOC_QBUF#1 -->device_run(triger encoder core1)-->job_finish(core0 may encode done here, return encode result to client) VIDIOC_QBUF#2 -->device_run(triger encoder core0)-->job_finishThers is no "wait encoder IRQ" synchronous call during "
frame_racing_mode" encoding process, which can full use the two encoder cores to achieve higher performance.Irui Wang (9):
dt-bindings: media: mtk-vcodec: Add binding for MT8195 two venc cores
media: mtk-vcodec: Use component framework to manage encoder hardware
media: mtk-vcodec: Rewrite venc power manage interface
media: mtk-vcodec: Add venc power on/off interface
media: mtk-vcodec: Rewrite venc clock interface
media: mtk-vcodec: Add new venc drv interface forframe_racingmode
media: mtk-vcodec: Add frame racing mode encode process
media: mtk-vcodec: Return encode result to client
media: mtk-vcodec: Add delayed worker for encode timeout.../bindings/media/mediatek-vcodec.txt | 2 + drivers/media/platform/mtk-vcodec/Makefile | 2 + .../platform/mtk-vcodec/mtk_vcodec_drv.h | 34 +- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 120 +++- .../platform/mtk-vcodec/mtk_vcodec_enc.h | 10 +- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 204 +++++- .../platform/mtk-vcodec/mtk_vcodec_enc_hw.c | 253 +++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_hw.h | 38 + .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 213 ++++-- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 13 +- .../platform/mtk-vcodec/mtk_vcodec_util.c | 19 + .../platform/mtk-vcodec/mtk_vcodec_util.h | 5 + .../platform/mtk-vcodec/venc/venc_common_if.c | 675 ++++++++++++++++++ .../platform/mtk-vcodec/venc/venc_h264_if.c | 6 +- .../platform/mtk-vcodec/venc/venc_vp8_if.c | 2 +- .../media/platform/mtk-vcodec/venc_drv_if.c | 96 ++- .../media/platform/mtk-vcodec/venc_drv_if.h | 7 + .../media/platform/mtk-vcodec/venc_vpu_if.c | 11 +- .../media/platform/mtk-vcodec/venc_vpu_if.h | 3 +- 19 files changed, 1564 insertions(+), 149 deletions(-)
Quoted 4 lines
create mode 100644
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.ccreate mode 100644drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_hw.hcreate mode 100644drivers/media/platform/mtk-vcodec/venc/venc_common_if.c
Hello Irui,
we have some interest in this series; can you please rebase it over the latest changes that were sent in series [1] [2]?
Also, please follow [2], where of_platform_populate was used in place of the component framework (where applicable and where possible) on this series, as well.
Thanks!
- Angelo
[1]: https://patchwork.kernel.org/project/linux-mediatek/list/?series=579201
[2]: https://patchwork.kernel.org/project/linux-mediatek/list/?series=578467
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek