All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-05-12  3:46 ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Firstly, add mt8186 compatible and private data, then add document for
compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
architecture, need to add new interface for h264 hardware decoder.

Patche 1 add mt8186 compatible and private data.
Patche 2 add mt8186 compatible document.
Patche 3 add h264 single core driver.
---
This patch depends on "support for MT8192 decoder"[1]

[1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
---
changed with v3:
- fix __iomem not reasonable, align share memory to dram.
changed with v2:
- fix sparse and smatch check fail for patch 3
changed with v1:
- rebase driver to the latest media_stage.
---
Yunfei Dong (3):
  dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
    mt8186
  media: mediatek: vcodec: Support MT8186
  media: mediatek: vcodec: add h264 decoder driver for mt8186

 .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
 .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 5 files changed, 203 insertions(+), 2 deletions(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-05-12  3:46 ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Firstly, add mt8186 compatible and private data, then add document for
compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
architecture, need to add new interface for h264 hardware decoder.

Patche 1 add mt8186 compatible and private data.
Patche 2 add mt8186 compatible document.
Patche 3 add h264 single core driver.
---
This patch depends on "support for MT8192 decoder"[1]

[1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
---
changed with v3:
- fix __iomem not reasonable, align share memory to dram.
changed with v2:
- fix sparse and smatch check fail for patch 3
changed with v1:
- rebase driver to the latest media_stage.
---
Yunfei Dong (3):
  dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
    mt8186
  media: mediatek: vcodec: Support MT8186
  media: mediatek: vcodec: add h264 decoder driver for mt8186

 .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
 .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 5 files changed, 203 insertions(+), 2 deletions(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-05-12  3:46 ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Firstly, add mt8186 compatible and private data, then add document for
compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
architecture, need to add new interface for h264 hardware decoder.

Patche 1 add mt8186 compatible and private data.
Patche 2 add mt8186 compatible document.
Patche 3 add h264 single core driver.
---
This patch depends on "support for MT8192 decoder"[1]

[1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
---
changed with v3:
- fix __iomem not reasonable, align share memory to dram.
changed with v2:
- fix sparse and smatch check fail for patch 3
changed with v1:
- rebase driver to the latest media_stage.
---
Yunfei Dong (3):
  dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
    mt8186
  media: mediatek: vcodec: Support MT8186
  media: mediatek: vcodec: add h264 decoder driver for mt8186

 .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
 .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 5 files changed, 203 insertions(+), 2 deletions(-)

-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-05-12  3:46 ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Firstly, add mt8186 compatible and private data, then add document for
compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
architecture, need to add new interface for h264 hardware decoder.

Patche 1 add mt8186 compatible and private data.
Patche 2 add mt8186 compatible document.
Patche 3 add h264 single core driver.
---
This patch depends on "support for MT8192 decoder"[1]

[1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
---
changed with v3:
- fix __iomem not reasonable, align share memory to dram.
changed with v2:
- fix sparse and smatch check fail for patch 3
changed with v1:
- rebase driver to the latest media_stage.
---
Yunfei Dong (3):
  dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
    mt8186
  media: mediatek: vcodec: Support MT8186
  media: mediatek: vcodec: add h264 decoder driver for mt8186

 .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
 .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 5 files changed, 203 insertions(+), 2 deletions(-)

-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v4, 1/3] dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for mt8186
  2022-05-12  3:46 ` Yunfei Dong
  (?)
  (?)
@ 2022-05-12  3:46   ` Yunfei Dong
  -1 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Adds decoder dt-bindings for mt8186.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../bindings/media/mediatek,vcodec-subdev-decoder.yaml        | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
index d587fc3e39fb..6415c9f29130 100644
--- a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
@@ -47,7 +47,9 @@ description: |
 
 properties:
   compatible:
-    const: mediatek,mt8192-vcodec-dec
+    enum:
+      - mediatek,mt8192-vcodec-dec
+      - mediatek,mt8186-vcodec-dec
 
   reg:
     maxItems: 1
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 1/3] dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for mt8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adds decoder dt-bindings for mt8186.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../bindings/media/mediatek,vcodec-subdev-decoder.yaml        | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
index d587fc3e39fb..6415c9f29130 100644
--- a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
@@ -47,7 +47,9 @@ description: |
 
 properties:
   compatible:
-    const: mediatek,mt8192-vcodec-dec
+    enum:
+      - mediatek,mt8192-vcodec-dec
+      - mediatek,mt8186-vcodec-dec
 
   reg:
     maxItems: 1
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 1/3] dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for mt8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adds decoder dt-bindings for mt8186.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../bindings/media/mediatek,vcodec-subdev-decoder.yaml        | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
index d587fc3e39fb..6415c9f29130 100644
--- a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
@@ -47,7 +47,9 @@ description: |
 
 properties:
   compatible:
-    const: mediatek,mt8192-vcodec-dec
+    enum:
+      - mediatek,mt8192-vcodec-dec
+      - mediatek,mt8186-vcodec-dec
 
   reg:
     maxItems: 1
-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 1/3] dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for mt8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adds decoder dt-bindings for mt8186.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../bindings/media/mediatek,vcodec-subdev-decoder.yaml        | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
index d587fc3e39fb..6415c9f29130 100644
--- a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
@@ -47,7 +47,9 @@ description: |
 
 properties:
   compatible:
-    const: mediatek,mt8192-vcodec-dec
+    enum:
+      - mediatek,mt8192-vcodec-dec
+      - mediatek,mt8186-vcodec-dec
 
   reg:
     maxItems: 1
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 2/3] media: mediatek: vcodec: Support MT8186
  2022-05-12  3:46 ` Yunfei Dong
  (?)
  (?)
@ 2022-05-12  3:46   ` Yunfei Dong
  -1 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Adds MT8186's compatible "mediatek,mt8186-vcodec-dec".
Adds MT8186's device private data mtk_vdec_single_core_pdata.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |  1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |  4 ++++
 .../vcodec/mtk_vcodec_dec_stateless.c         | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
index 66cd6d2242c3..4572f92826f2 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
@@ -69,6 +69,7 @@ extern const struct media_device_ops mtk_vcodec_media_ops;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata;
+extern const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata;
 
 
 /*
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index 5da4572c5b14..b417a6ab2176 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -458,6 +458,10 @@ static const struct of_device_id mtk_vcodec_match[] = {
 		.compatible = "mediatek,mt8192-vcodec-dec",
 		.data = &mtk_lat_sig_core_pdata,
 	},
+	{
+		.compatible = "mediatek,mt8186-vcodec-dec",
+		.data = &mtk_vdec_single_core_pdata,
+	},
 	{},
 };
 
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index f1a77f0a8a81..16d55785d84b 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -491,3 +491,22 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = {
 	.is_subdev_supported = true,
 	.hw_arch = MTK_VDEC_LAT_SINGLE_CORE,
 };
+
+const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata = {
+	.init_vdec_params = mtk_init_vdec_params,
+	.ctrls_setup = mtk_vcodec_dec_ctrls_setup,
+	.vdec_vb2_ops = &mtk_vdec_request_vb2_ops,
+	.vdec_formats = mtk_video_formats,
+	.num_formats = &num_formats,
+	.default_out_fmt = &default_out_format,
+	.default_cap_fmt = &default_cap_format,
+	.vdec_framesizes = mtk_vdec_framesizes,
+	.num_framesizes = &num_framesizes,
+	.uses_stateless_api = true,
+	.worker = mtk_vdec_worker,
+	.flush_decoder = mtk_vdec_flush_decoder,
+	.cap_to_disp = mtk_vdec_stateless_cap_to_disp,
+	.get_cap_buffer = vdec_get_cap_buffer,
+	.is_subdev_supported = true,
+	.hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
+};
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 2/3] media: mediatek: vcodec: Support MT8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adds MT8186's compatible "mediatek,mt8186-vcodec-dec".
Adds MT8186's device private data mtk_vdec_single_core_pdata.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |  1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |  4 ++++
 .../vcodec/mtk_vcodec_dec_stateless.c         | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
index 66cd6d2242c3..4572f92826f2 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
@@ -69,6 +69,7 @@ extern const struct media_device_ops mtk_vcodec_media_ops;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata;
+extern const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata;
 
 
 /*
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index 5da4572c5b14..b417a6ab2176 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -458,6 +458,10 @@ static const struct of_device_id mtk_vcodec_match[] = {
 		.compatible = "mediatek,mt8192-vcodec-dec",
 		.data = &mtk_lat_sig_core_pdata,
 	},
+	{
+		.compatible = "mediatek,mt8186-vcodec-dec",
+		.data = &mtk_vdec_single_core_pdata,
+	},
 	{},
 };
 
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index f1a77f0a8a81..16d55785d84b 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -491,3 +491,22 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = {
 	.is_subdev_supported = true,
 	.hw_arch = MTK_VDEC_LAT_SINGLE_CORE,
 };
+
+const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata = {
+	.init_vdec_params = mtk_init_vdec_params,
+	.ctrls_setup = mtk_vcodec_dec_ctrls_setup,
+	.vdec_vb2_ops = &mtk_vdec_request_vb2_ops,
+	.vdec_formats = mtk_video_formats,
+	.num_formats = &num_formats,
+	.default_out_fmt = &default_out_format,
+	.default_cap_fmt = &default_cap_format,
+	.vdec_framesizes = mtk_vdec_framesizes,
+	.num_framesizes = &num_framesizes,
+	.uses_stateless_api = true,
+	.worker = mtk_vdec_worker,
+	.flush_decoder = mtk_vdec_flush_decoder,
+	.cap_to_disp = mtk_vdec_stateless_cap_to_disp,
+	.get_cap_buffer = vdec_get_cap_buffer,
+	.is_subdev_supported = true,
+	.hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
+};
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 2/3] media: mediatek: vcodec: Support MT8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adds MT8186's compatible "mediatek,mt8186-vcodec-dec".
Adds MT8186's device private data mtk_vdec_single_core_pdata.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |  1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |  4 ++++
 .../vcodec/mtk_vcodec_dec_stateless.c         | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
index 66cd6d2242c3..4572f92826f2 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
@@ -69,6 +69,7 @@ extern const struct media_device_ops mtk_vcodec_media_ops;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata;
+extern const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata;
 
 
 /*
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index 5da4572c5b14..b417a6ab2176 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -458,6 +458,10 @@ static const struct of_device_id mtk_vcodec_match[] = {
 		.compatible = "mediatek,mt8192-vcodec-dec",
 		.data = &mtk_lat_sig_core_pdata,
 	},
+	{
+		.compatible = "mediatek,mt8186-vcodec-dec",
+		.data = &mtk_vdec_single_core_pdata,
+	},
 	{},
 };
 
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index f1a77f0a8a81..16d55785d84b 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -491,3 +491,22 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = {
 	.is_subdev_supported = true,
 	.hw_arch = MTK_VDEC_LAT_SINGLE_CORE,
 };
+
+const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata = {
+	.init_vdec_params = mtk_init_vdec_params,
+	.ctrls_setup = mtk_vcodec_dec_ctrls_setup,
+	.vdec_vb2_ops = &mtk_vdec_request_vb2_ops,
+	.vdec_formats = mtk_video_formats,
+	.num_formats = &num_formats,
+	.default_out_fmt = &default_out_format,
+	.default_cap_fmt = &default_cap_format,
+	.vdec_framesizes = mtk_vdec_framesizes,
+	.num_framesizes = &num_framesizes,
+	.uses_stateless_api = true,
+	.worker = mtk_vdec_worker,
+	.flush_decoder = mtk_vdec_flush_decoder,
+	.cap_to_disp = mtk_vdec_stateless_cap_to_disp,
+	.get_cap_buffer = vdec_get_cap_buffer,
+	.is_subdev_supported = true,
+	.hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
+};
-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 2/3] media: mediatek: vcodec: Support MT8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Adds MT8186's compatible "mediatek,mt8186-vcodec-dec".
Adds MT8186's device private data mtk_vdec_single_core_pdata.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../platform/mediatek/vcodec/mtk_vcodec_dec.h |  1 +
 .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |  4 ++++
 .../vcodec/mtk_vcodec_dec_stateless.c         | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
index 66cd6d2242c3..4572f92826f2 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
@@ -69,6 +69,7 @@ extern const struct media_device_ops mtk_vcodec_media_ops;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata;
 extern const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata;
+extern const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata;
 
 
 /*
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index 5da4572c5b14..b417a6ab2176 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -458,6 +458,10 @@ static const struct of_device_id mtk_vcodec_match[] = {
 		.compatible = "mediatek,mt8192-vcodec-dec",
 		.data = &mtk_lat_sig_core_pdata,
 	},
+	{
+		.compatible = "mediatek,mt8186-vcodec-dec",
+		.data = &mtk_vdec_single_core_pdata,
+	},
 	{},
 };
 
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index f1a77f0a8a81..16d55785d84b 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -491,3 +491,22 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = {
 	.is_subdev_supported = true,
 	.hw_arch = MTK_VDEC_LAT_SINGLE_CORE,
 };
+
+const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata = {
+	.init_vdec_params = mtk_init_vdec_params,
+	.ctrls_setup = mtk_vcodec_dec_ctrls_setup,
+	.vdec_vb2_ops = &mtk_vdec_request_vb2_ops,
+	.vdec_formats = mtk_video_formats,
+	.num_formats = &num_formats,
+	.default_out_fmt = &default_out_format,
+	.default_cap_fmt = &default_cap_format,
+	.vdec_framesizes = mtk_vdec_framesizes,
+	.num_framesizes = &num_framesizes,
+	.uses_stateless_api = true,
+	.worker = mtk_vdec_worker,
+	.flush_decoder = mtk_vdec_flush_decoder,
+	.cap_to_disp = mtk_vdec_stateless_cap_to_disp,
+	.get_cap_buffer = vdec_get_cap_buffer,
+	.is_subdev_supported = true,
+	.hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
+};
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
  2022-05-12  3:46 ` Yunfei Dong
  (?)
  (?)
@ 2022-05-12  3:46   ` Yunfei Dong
  -1 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Add h264 decode driver to support mt8186. For the architecture
is single core, need to add new interface to decode.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 1 file changed, 176 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index a96f203b5d54..1d9e753cf894 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
  * @vsi:		vsi used for lat
  * @vsi_core:		vsi used for core
  *
+ * @vsi_ctx:		Local VSI data for this decoding context
+ * @h264_slice_param:	the parameters that hardware use to decode
+ *
  * @resolution_changed:resolution changed
  * @realloc_mv_buf:	reallocate mv buffer
  * @cap_num_planes:	number of capture queue plane
@@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
 	struct vdec_h264_slice_vsi *vsi;
 	struct vdec_h264_slice_vsi *vsi_core;
 
+	struct vdec_h264_slice_vsi vsi_ctx;
+	struct vdec_h264_slice_lat_dec_param h264_slice_param;
+
 	unsigned int resolution_changed;
 	unsigned int realloc_mv_buf;
 	unsigned int cap_num_planes;
@@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
 	return 0;
 }
 
+static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
+{
+	const struct v4l2_ctrl_h264_decode_params *dec_params;
+	const struct v4l2_ctrl_h264_sps *sps;
+	const struct v4l2_ctrl_h264_pps *pps;
+	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
+	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
+	struct v4l2_h264_reflist_builder reflist_builder;
+	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
+	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
+	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
+
+	dec_params =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
+	if (IS_ERR(dec_params))
+		return PTR_ERR(dec_params);
+
+	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
+	if (IS_ERR(sps))
+		return PTR_ERR(sps);
+
+	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
+	if (IS_ERR(pps))
+		return PTR_ERR(pps);
+
+	scaling_matrix =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
+	if (IS_ERR(scaling_matrix))
+		return PTR_ERR(scaling_matrix);
+
+	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
+
+	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
+	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
+	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
+
+	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
+	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
+				    slice_param->h264_dpb_info);
+
+	/* Build the reference lists */
+	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
+	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
+
+	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
+	/* Adapt the built lists to the firmware's expectations */
+	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
+	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
+	       sizeof(inst->vsi_ctx.h264_slice_params));
+
+	return 0;
+}
+
 static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
 						struct vdec_h264_slice_lat_dec_param *slice_param,
 						struct vdec_h264_slice_share_info *share_info)
@@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 	return err;
 }
 
+static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+					 struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	struct vdec_vpu_inst *vpu = &inst->vpu;
+	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
+	struct vdec_fb *fb;
+	unsigned char *buf;
+	unsigned int data[2], i;
+	u64 y_fb_dma, c_fb_dma;
+	struct mtk_vcodec_mem *mem;
+	int err, nal_start_idx;
+
+	/* bs NULL means flush decoder */
+	if (!bs)
+		return vpu_dec_reset(vpu);
+
+	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
+	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
+	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
+
+	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
+	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
+	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
+			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
+
+	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
+	inst->vsi_ctx.dec.bs_buf_size = bs->size;
+	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
+	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
+	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
+
+	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
+				   &dst_buf_info->m2m_buf.vb, true);
+	err = get_vdec_sig_decode_parameters(inst);
+	if (err)
+		goto err_free_fb_out;
+
+	buf = (unsigned char *)bs->va;
+	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
+	if (nal_start_idx < 0) {
+		err = -EINVAL;
+		goto err_free_fb_out;
+	}
+	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
+
+	*res_chg = inst->resolution_changed;
+	if (inst->resolution_changed) {
+		mtk_vcodec_debug(inst, "- resolution changed -");
+		if (inst->realloc_mv_buf) {
+			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
+			inst->realloc_mv_buf = false;
+			if (err)
+				goto err_free_fb_out;
+		}
+		inst->resolution_changed = false;
+
+		for (i = 0; i < H264_MAX_MV_NUM; i++) {
+			mem = &inst->mv_buf[i];
+			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
+		}
+	}
+
+	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
+	err = vpu_dec_start(vpu, data, 2);
+	if (err)
+		goto err_free_fb_out;
+
+	/* wait decoder done interrupt */
+	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
+	if (err)
+		mtk_vcodec_err(inst, "decode timeout: pic_%d",
+			       inst->ctx->decoded_frame_cnt);
+
+	inst->vsi->dec.timeout = !!err;
+	err = vpu_dec_end(vpu);
+	if (err)
+		goto err_free_fb_out;
+
+	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
+	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
+			 inst->ctx->decoded_frame_cnt,
+			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
+			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
+			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
+			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
+
+	inst->ctx->decoded_frame_cnt++;
+	return 0;
+
+err_free_fb_out:
+	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
+		       inst->ctx->decoded_frame_cnt, err);
+	return err;
+}
+
+static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+				  struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	int ret;
+
+	if (!h_vdec)
+		return -EINVAL;
+
+	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
+		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
+	else
+		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
+
+	return ret;
+}
+
 static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
 				     void *out)
 {
@@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
 
 const struct vdec_common_if vdec_h264_slice_multi_if = {
 	.init		= vdec_h264_slice_init,
-	.decode		= vdec_h264_slice_lat_decode,
+	.decode		= vdec_h264_slice_decode,
 	.get_param	= vdec_h264_slice_get_param,
 	.deinit		= vdec_h264_slice_deinit,
 };
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Add h264 decode driver to support mt8186. For the architecture
is single core, need to add new interface to decode.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 1 file changed, 176 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index a96f203b5d54..1d9e753cf894 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
  * @vsi:		vsi used for lat
  * @vsi_core:		vsi used for core
  *
+ * @vsi_ctx:		Local VSI data for this decoding context
+ * @h264_slice_param:	the parameters that hardware use to decode
+ *
  * @resolution_changed:resolution changed
  * @realloc_mv_buf:	reallocate mv buffer
  * @cap_num_planes:	number of capture queue plane
@@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
 	struct vdec_h264_slice_vsi *vsi;
 	struct vdec_h264_slice_vsi *vsi_core;
 
+	struct vdec_h264_slice_vsi vsi_ctx;
+	struct vdec_h264_slice_lat_dec_param h264_slice_param;
+
 	unsigned int resolution_changed;
 	unsigned int realloc_mv_buf;
 	unsigned int cap_num_planes;
@@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
 	return 0;
 }
 
+static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
+{
+	const struct v4l2_ctrl_h264_decode_params *dec_params;
+	const struct v4l2_ctrl_h264_sps *sps;
+	const struct v4l2_ctrl_h264_pps *pps;
+	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
+	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
+	struct v4l2_h264_reflist_builder reflist_builder;
+	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
+	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
+	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
+
+	dec_params =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
+	if (IS_ERR(dec_params))
+		return PTR_ERR(dec_params);
+
+	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
+	if (IS_ERR(sps))
+		return PTR_ERR(sps);
+
+	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
+	if (IS_ERR(pps))
+		return PTR_ERR(pps);
+
+	scaling_matrix =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
+	if (IS_ERR(scaling_matrix))
+		return PTR_ERR(scaling_matrix);
+
+	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
+
+	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
+	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
+	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
+
+	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
+	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
+				    slice_param->h264_dpb_info);
+
+	/* Build the reference lists */
+	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
+	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
+
+	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
+	/* Adapt the built lists to the firmware's expectations */
+	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
+	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
+	       sizeof(inst->vsi_ctx.h264_slice_params));
+
+	return 0;
+}
+
 static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
 						struct vdec_h264_slice_lat_dec_param *slice_param,
 						struct vdec_h264_slice_share_info *share_info)
@@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 	return err;
 }
 
+static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+					 struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	struct vdec_vpu_inst *vpu = &inst->vpu;
+	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
+	struct vdec_fb *fb;
+	unsigned char *buf;
+	unsigned int data[2], i;
+	u64 y_fb_dma, c_fb_dma;
+	struct mtk_vcodec_mem *mem;
+	int err, nal_start_idx;
+
+	/* bs NULL means flush decoder */
+	if (!bs)
+		return vpu_dec_reset(vpu);
+
+	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
+	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
+	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
+
+	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
+	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
+	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
+			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
+
+	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
+	inst->vsi_ctx.dec.bs_buf_size = bs->size;
+	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
+	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
+	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
+
+	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
+				   &dst_buf_info->m2m_buf.vb, true);
+	err = get_vdec_sig_decode_parameters(inst);
+	if (err)
+		goto err_free_fb_out;
+
+	buf = (unsigned char *)bs->va;
+	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
+	if (nal_start_idx < 0) {
+		err = -EINVAL;
+		goto err_free_fb_out;
+	}
+	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
+
+	*res_chg = inst->resolution_changed;
+	if (inst->resolution_changed) {
+		mtk_vcodec_debug(inst, "- resolution changed -");
+		if (inst->realloc_mv_buf) {
+			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
+			inst->realloc_mv_buf = false;
+			if (err)
+				goto err_free_fb_out;
+		}
+		inst->resolution_changed = false;
+
+		for (i = 0; i < H264_MAX_MV_NUM; i++) {
+			mem = &inst->mv_buf[i];
+			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
+		}
+	}
+
+	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
+	err = vpu_dec_start(vpu, data, 2);
+	if (err)
+		goto err_free_fb_out;
+
+	/* wait decoder done interrupt */
+	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
+	if (err)
+		mtk_vcodec_err(inst, "decode timeout: pic_%d",
+			       inst->ctx->decoded_frame_cnt);
+
+	inst->vsi->dec.timeout = !!err;
+	err = vpu_dec_end(vpu);
+	if (err)
+		goto err_free_fb_out;
+
+	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
+	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
+			 inst->ctx->decoded_frame_cnt,
+			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
+			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
+			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
+			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
+
+	inst->ctx->decoded_frame_cnt++;
+	return 0;
+
+err_free_fb_out:
+	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
+		       inst->ctx->decoded_frame_cnt, err);
+	return err;
+}
+
+static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+				  struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	int ret;
+
+	if (!h_vdec)
+		return -EINVAL;
+
+	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
+		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
+	else
+		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
+
+	return ret;
+}
+
 static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
 				     void *out)
 {
@@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
 
 const struct vdec_common_if vdec_h264_slice_multi_if = {
 	.init		= vdec_h264_slice_init,
-	.decode		= vdec_h264_slice_lat_decode,
+	.decode		= vdec_h264_slice_decode,
 	.get_param	= vdec_h264_slice_get_param,
 	.deinit		= vdec_h264_slice_deinit,
 };
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Add h264 decode driver to support mt8186. For the architecture
is single core, need to add new interface to decode.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 1 file changed, 176 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index a96f203b5d54..1d9e753cf894 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
  * @vsi:		vsi used for lat
  * @vsi_core:		vsi used for core
  *
+ * @vsi_ctx:		Local VSI data for this decoding context
+ * @h264_slice_param:	the parameters that hardware use to decode
+ *
  * @resolution_changed:resolution changed
  * @realloc_mv_buf:	reallocate mv buffer
  * @cap_num_planes:	number of capture queue plane
@@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
 	struct vdec_h264_slice_vsi *vsi;
 	struct vdec_h264_slice_vsi *vsi_core;
 
+	struct vdec_h264_slice_vsi vsi_ctx;
+	struct vdec_h264_slice_lat_dec_param h264_slice_param;
+
 	unsigned int resolution_changed;
 	unsigned int realloc_mv_buf;
 	unsigned int cap_num_planes;
@@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
 	return 0;
 }
 
+static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
+{
+	const struct v4l2_ctrl_h264_decode_params *dec_params;
+	const struct v4l2_ctrl_h264_sps *sps;
+	const struct v4l2_ctrl_h264_pps *pps;
+	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
+	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
+	struct v4l2_h264_reflist_builder reflist_builder;
+	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
+	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
+	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
+
+	dec_params =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
+	if (IS_ERR(dec_params))
+		return PTR_ERR(dec_params);
+
+	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
+	if (IS_ERR(sps))
+		return PTR_ERR(sps);
+
+	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
+	if (IS_ERR(pps))
+		return PTR_ERR(pps);
+
+	scaling_matrix =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
+	if (IS_ERR(scaling_matrix))
+		return PTR_ERR(scaling_matrix);
+
+	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
+
+	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
+	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
+	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
+
+	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
+	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
+				    slice_param->h264_dpb_info);
+
+	/* Build the reference lists */
+	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
+	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
+
+	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
+	/* Adapt the built lists to the firmware's expectations */
+	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
+	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
+	       sizeof(inst->vsi_ctx.h264_slice_params));
+
+	return 0;
+}
+
 static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
 						struct vdec_h264_slice_lat_dec_param *slice_param,
 						struct vdec_h264_slice_share_info *share_info)
@@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 	return err;
 }
 
+static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+					 struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	struct vdec_vpu_inst *vpu = &inst->vpu;
+	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
+	struct vdec_fb *fb;
+	unsigned char *buf;
+	unsigned int data[2], i;
+	u64 y_fb_dma, c_fb_dma;
+	struct mtk_vcodec_mem *mem;
+	int err, nal_start_idx;
+
+	/* bs NULL means flush decoder */
+	if (!bs)
+		return vpu_dec_reset(vpu);
+
+	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
+	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
+	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
+
+	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
+	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
+	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
+			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
+
+	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
+	inst->vsi_ctx.dec.bs_buf_size = bs->size;
+	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
+	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
+	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
+
+	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
+				   &dst_buf_info->m2m_buf.vb, true);
+	err = get_vdec_sig_decode_parameters(inst);
+	if (err)
+		goto err_free_fb_out;
+
+	buf = (unsigned char *)bs->va;
+	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
+	if (nal_start_idx < 0) {
+		err = -EINVAL;
+		goto err_free_fb_out;
+	}
+	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
+
+	*res_chg = inst->resolution_changed;
+	if (inst->resolution_changed) {
+		mtk_vcodec_debug(inst, "- resolution changed -");
+		if (inst->realloc_mv_buf) {
+			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
+			inst->realloc_mv_buf = false;
+			if (err)
+				goto err_free_fb_out;
+		}
+		inst->resolution_changed = false;
+
+		for (i = 0; i < H264_MAX_MV_NUM; i++) {
+			mem = &inst->mv_buf[i];
+			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
+		}
+	}
+
+	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
+	err = vpu_dec_start(vpu, data, 2);
+	if (err)
+		goto err_free_fb_out;
+
+	/* wait decoder done interrupt */
+	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
+	if (err)
+		mtk_vcodec_err(inst, "decode timeout: pic_%d",
+			       inst->ctx->decoded_frame_cnt);
+
+	inst->vsi->dec.timeout = !!err;
+	err = vpu_dec_end(vpu);
+	if (err)
+		goto err_free_fb_out;
+
+	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
+	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
+			 inst->ctx->decoded_frame_cnt,
+			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
+			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
+			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
+			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
+
+	inst->ctx->decoded_frame_cnt++;
+	return 0;
+
+err_free_fb_out:
+	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
+		       inst->ctx->decoded_frame_cnt, err);
+	return err;
+}
+
+static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+				  struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	int ret;
+
+	if (!h_vdec)
+		return -EINVAL;
+
+	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
+		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
+	else
+		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
+
+	return ret;
+}
+
 static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
 				     void *out)
 {
@@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
 
 const struct vdec_common_if vdec_h264_slice_multi_if = {
 	.init		= vdec_h264_slice_init,
-	.decode		= vdec_h264_slice_lat_decode,
+	.decode		= vdec_h264_slice_decode,
 	.get_param	= vdec_h264_slice_get_param,
 	.deinit		= vdec_h264_slice_deinit,
 };
-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-05-12  3:46   ` Yunfei Dong
  0 siblings, 0 replies; 49+ messages in thread
From: Yunfei Dong @ 2022-05-12  3:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Nicolas Dufresne, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Add h264 decode driver to support mt8186. For the architecture
is single core, need to add new interface to decode.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
 1 file changed, 176 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index a96f203b5d54..1d9e753cf894 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
  * @vsi:		vsi used for lat
  * @vsi_core:		vsi used for core
  *
+ * @vsi_ctx:		Local VSI data for this decoding context
+ * @h264_slice_param:	the parameters that hardware use to decode
+ *
  * @resolution_changed:resolution changed
  * @realloc_mv_buf:	reallocate mv buffer
  * @cap_num_planes:	number of capture queue plane
@@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
 	struct vdec_h264_slice_vsi *vsi;
 	struct vdec_h264_slice_vsi *vsi_core;
 
+	struct vdec_h264_slice_vsi vsi_ctx;
+	struct vdec_h264_slice_lat_dec_param h264_slice_param;
+
 	unsigned int resolution_changed;
 	unsigned int realloc_mv_buf;
 	unsigned int cap_num_planes;
@@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
 	return 0;
 }
 
+static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
+{
+	const struct v4l2_ctrl_h264_decode_params *dec_params;
+	const struct v4l2_ctrl_h264_sps *sps;
+	const struct v4l2_ctrl_h264_pps *pps;
+	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
+	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
+	struct v4l2_h264_reflist_builder reflist_builder;
+	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
+	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
+	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
+
+	dec_params =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
+	if (IS_ERR(dec_params))
+		return PTR_ERR(dec_params);
+
+	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
+	if (IS_ERR(sps))
+		return PTR_ERR(sps);
+
+	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
+	if (IS_ERR(pps))
+		return PTR_ERR(pps);
+
+	scaling_matrix =
+		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
+	if (IS_ERR(scaling_matrix))
+		return PTR_ERR(scaling_matrix);
+
+	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
+
+	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
+	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
+	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
+
+	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
+	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
+				    slice_param->h264_dpb_info);
+
+	/* Build the reference lists */
+	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
+	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
+
+	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
+	/* Adapt the built lists to the firmware's expectations */
+	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
+	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
+	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
+	       sizeof(inst->vsi_ctx.h264_slice_params));
+
+	return 0;
+}
+
 static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
 						struct vdec_h264_slice_lat_dec_param *slice_param,
 						struct vdec_h264_slice_share_info *share_info)
@@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
 	return err;
 }
 
+static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+					 struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	struct vdec_vpu_inst *vpu = &inst->vpu;
+	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
+	struct vdec_fb *fb;
+	unsigned char *buf;
+	unsigned int data[2], i;
+	u64 y_fb_dma, c_fb_dma;
+	struct mtk_vcodec_mem *mem;
+	int err, nal_start_idx;
+
+	/* bs NULL means flush decoder */
+	if (!bs)
+		return vpu_dec_reset(vpu);
+
+	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
+	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
+	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
+
+	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
+	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
+	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
+			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
+
+	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
+	inst->vsi_ctx.dec.bs_buf_size = bs->size;
+	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
+	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
+	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
+
+	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
+				   &dst_buf_info->m2m_buf.vb, true);
+	err = get_vdec_sig_decode_parameters(inst);
+	if (err)
+		goto err_free_fb_out;
+
+	buf = (unsigned char *)bs->va;
+	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
+	if (nal_start_idx < 0) {
+		err = -EINVAL;
+		goto err_free_fb_out;
+	}
+	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
+
+	*res_chg = inst->resolution_changed;
+	if (inst->resolution_changed) {
+		mtk_vcodec_debug(inst, "- resolution changed -");
+		if (inst->realloc_mv_buf) {
+			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
+			inst->realloc_mv_buf = false;
+			if (err)
+				goto err_free_fb_out;
+		}
+		inst->resolution_changed = false;
+
+		for (i = 0; i < H264_MAX_MV_NUM; i++) {
+			mem = &inst->mv_buf[i];
+			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
+		}
+	}
+
+	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
+	err = vpu_dec_start(vpu, data, 2);
+	if (err)
+		goto err_free_fb_out;
+
+	/* wait decoder done interrupt */
+	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
+					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
+	if (err)
+		mtk_vcodec_err(inst, "decode timeout: pic_%d",
+			       inst->ctx->decoded_frame_cnt);
+
+	inst->vsi->dec.timeout = !!err;
+	err = vpu_dec_end(vpu);
+	if (err)
+		goto err_free_fb_out;
+
+	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
+	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
+			 inst->ctx->decoded_frame_cnt,
+			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
+			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
+			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
+			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
+
+	inst->ctx->decoded_frame_cnt++;
+	return 0;
+
+err_free_fb_out:
+	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
+		       inst->ctx->decoded_frame_cnt, err);
+	return err;
+}
+
+static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
+				  struct vdec_fb *unused, bool *res_chg)
+{
+	struct vdec_h264_slice_inst *inst = h_vdec;
+	int ret;
+
+	if (!h_vdec)
+		return -EINVAL;
+
+	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
+		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
+	else
+		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
+
+	return ret;
+}
+
 static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
 				     void *out)
 {
@@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
 
 const struct vdec_common_if vdec_h264_slice_multi_if = {
 	.init		= vdec_h264_slice_init,
-	.decode		= vdec_h264_slice_lat_decode,
+	.decode		= vdec_h264_slice_decode,
 	.get_param	= vdec_h264_slice_get_param,
 	.deinit		= vdec_h264_slice_deinit,
 };
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
  2022-05-12  3:46   ` Yunfei Dong
  (?)
  (?)
@ 2022-06-13 20:08     ` Nicolas Dufresne
  -1 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:08 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Add h264 decode driver to support mt8186. For the architecture
> is single core, need to add new interface to decode.
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  1 file changed, 176 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> index a96f203b5d54..1d9e753cf894 100644
> --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
>   * @vsi:		vsi used for lat
>   * @vsi_core:		vsi used for core
>   *
> + * @vsi_ctx:		Local VSI data for this decoding context
> + * @h264_slice_param:	the parameters that hardware use to decode
> + *
>   * @resolution_changed:resolution changed
>   * @realloc_mv_buf:	reallocate mv buffer
>   * @cap_num_planes:	number of capture queue plane
> @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
>  	struct vdec_h264_slice_vsi *vsi;
>  	struct vdec_h264_slice_vsi *vsi_core;
>  
> +	struct vdec_h264_slice_vsi vsi_ctx;
> +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> +
>  	unsigned int resolution_changed;
>  	unsigned int realloc_mv_buf;
>  	unsigned int cap_num_planes;
> @@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
>  	return 0;
>  }
>  
> +static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
> +{
> +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> +	const struct v4l2_ctrl_h264_sps *sps;
> +	const struct v4l2_ctrl_h264_pps *pps;
> +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
> +	struct v4l2_h264_reflist_builder reflist_builder;
> +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> +
> +	dec_params =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> +	if (IS_ERR(dec_params))
> +		return PTR_ERR(dec_params);
> +
> +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
> +	if (IS_ERR(sps))
> +		return PTR_ERR(sps);
> +
> +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
> +	if (IS_ERR(pps))
> +		return PTR_ERR(pps);
> +
> +	scaling_matrix =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> +	if (IS_ERR(scaling_matrix))
> +		return PTR_ERR(scaling_matrix);
> +
> +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> +
> +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
> +
> +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
> +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
> +				    slice_param->h264_dpb_info);
> +
> +	/* Build the reference lists */
> +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
> +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> +
> +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
> +	/* Adapt the built lists to the firmware's expectations */
> +	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
> +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> +	       sizeof(inst->vsi_ctx.h264_slice_params));

This function looks very redundant across multiple variants, could you try and
make a helper to reduce the duplication ?

> +
> +	return 0;
> +}
> +
>  static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
>  						struct vdec_h264_slice_lat_dec_param *slice_param,
>  						struct vdec_h264_slice_share_info *share_info)
> @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
>  	return err;
>  }
>  
> +static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +					 struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	struct vdec_vpu_inst *vpu = &inst->vpu;
> +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> +	struct vdec_fb *fb;
> +	unsigned char *buf;
> +	unsigned int data[2], i;
> +	u64 y_fb_dma, c_fb_dma;
> +	struct mtk_vcodec_mem *mem;
> +	int err, nal_start_idx;
> +
> +	/* bs NULL means flush decoder */
> +	if (!bs)
> +		return vpu_dec_reset(vpu);
> +
> +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> +	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
> +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
> +
> +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> +			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
> +
> +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> +
> +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> +				   &dst_buf_info->m2m_buf.vb, true);
> +	err = get_vdec_sig_decode_parameters(inst);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	buf = (unsigned char *)bs->va;
> +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> +	if (nal_start_idx < 0) {
> +		err = -EINVAL;
> +		goto err_free_fb_out;
> +	}
> +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> +
> +	*res_chg = inst->resolution_changed;
> +	if (inst->resolution_changed) {
> +		mtk_vcodec_debug(inst, "- resolution changed -");
> +		if (inst->realloc_mv_buf) {
> +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
> +			inst->realloc_mv_buf = false;
> +			if (err)
> +				goto err_free_fb_out;
> +		}
> +		inst->resolution_changed = false;
> +
> +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> +			mem = &inst->mv_buf[i];
> +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> +		}
> +	}
> +
> +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> +	err = vpu_dec_start(vpu, data, 2);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	/* wait decoder done interrupt */
> +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
> +					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
> +	if (err)
> +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> +			       inst->ctx->decoded_frame_cnt);
> +
> +	inst->vsi->dec.timeout = !!err;
> +	err = vpu_dec_end(vpu);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
> +			 inst->ctx->decoded_frame_cnt,
> +			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
> +			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
> +			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
> +			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
> +
> +	inst->ctx->decoded_frame_cnt++;
> +	return 0;
> +
> +err_free_fb_out:
> +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> +		       inst->ctx->decoded_frame_cnt, err);
> +	return err;
> +}
> +
> +static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +				  struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	int ret;
> +
> +	if (!h_vdec)
> +		return -EINVAL;
> +
> +	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
> +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
> +	else
> +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
> +
> +	return ret;
> +}
> +
>  static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
>  				     void *out)
>  {
> @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
>  
>  const struct vdec_common_if vdec_h264_slice_multi_if = {
>  	.init		= vdec_h264_slice_init,
> -	.decode		= vdec_h264_slice_lat_decode,
> +	.decode		= vdec_h264_slice_decode,
>  	.get_param	= vdec_h264_slice_get_param,
>  	.deinit		= vdec_h264_slice_deinit,
>  };


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-13 20:08     ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:08 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Add h264 decode driver to support mt8186. For the architecture
> is single core, need to add new interface to decode.
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  1 file changed, 176 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> index a96f203b5d54..1d9e753cf894 100644
> --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
>   * @vsi:		vsi used for lat
>   * @vsi_core:		vsi used for core
>   *
> + * @vsi_ctx:		Local VSI data for this decoding context
> + * @h264_slice_param:	the parameters that hardware use to decode
> + *
>   * @resolution_changed:resolution changed
>   * @realloc_mv_buf:	reallocate mv buffer
>   * @cap_num_planes:	number of capture queue plane
> @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
>  	struct vdec_h264_slice_vsi *vsi;
>  	struct vdec_h264_slice_vsi *vsi_core;
>  
> +	struct vdec_h264_slice_vsi vsi_ctx;
> +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> +
>  	unsigned int resolution_changed;
>  	unsigned int realloc_mv_buf;
>  	unsigned int cap_num_planes;
> @@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
>  	return 0;
>  }
>  
> +static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
> +{
> +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> +	const struct v4l2_ctrl_h264_sps *sps;
> +	const struct v4l2_ctrl_h264_pps *pps;
> +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
> +	struct v4l2_h264_reflist_builder reflist_builder;
> +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> +
> +	dec_params =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> +	if (IS_ERR(dec_params))
> +		return PTR_ERR(dec_params);
> +
> +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
> +	if (IS_ERR(sps))
> +		return PTR_ERR(sps);
> +
> +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
> +	if (IS_ERR(pps))
> +		return PTR_ERR(pps);
> +
> +	scaling_matrix =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> +	if (IS_ERR(scaling_matrix))
> +		return PTR_ERR(scaling_matrix);
> +
> +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> +
> +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
> +
> +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
> +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
> +				    slice_param->h264_dpb_info);
> +
> +	/* Build the reference lists */
> +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
> +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> +
> +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
> +	/* Adapt the built lists to the firmware's expectations */
> +	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
> +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> +	       sizeof(inst->vsi_ctx.h264_slice_params));

This function looks very redundant across multiple variants, could you try and
make a helper to reduce the duplication ?

> +
> +	return 0;
> +}
> +
>  static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
>  						struct vdec_h264_slice_lat_dec_param *slice_param,
>  						struct vdec_h264_slice_share_info *share_info)
> @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
>  	return err;
>  }
>  
> +static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +					 struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	struct vdec_vpu_inst *vpu = &inst->vpu;
> +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> +	struct vdec_fb *fb;
> +	unsigned char *buf;
> +	unsigned int data[2], i;
> +	u64 y_fb_dma, c_fb_dma;
> +	struct mtk_vcodec_mem *mem;
> +	int err, nal_start_idx;
> +
> +	/* bs NULL means flush decoder */
> +	if (!bs)
> +		return vpu_dec_reset(vpu);
> +
> +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> +	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
> +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
> +
> +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> +			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
> +
> +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> +
> +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> +				   &dst_buf_info->m2m_buf.vb, true);
> +	err = get_vdec_sig_decode_parameters(inst);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	buf = (unsigned char *)bs->va;
> +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> +	if (nal_start_idx < 0) {
> +		err = -EINVAL;
> +		goto err_free_fb_out;
> +	}
> +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> +
> +	*res_chg = inst->resolution_changed;
> +	if (inst->resolution_changed) {
> +		mtk_vcodec_debug(inst, "- resolution changed -");
> +		if (inst->realloc_mv_buf) {
> +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
> +			inst->realloc_mv_buf = false;
> +			if (err)
> +				goto err_free_fb_out;
> +		}
> +		inst->resolution_changed = false;
> +
> +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> +			mem = &inst->mv_buf[i];
> +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> +		}
> +	}
> +
> +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> +	err = vpu_dec_start(vpu, data, 2);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	/* wait decoder done interrupt */
> +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
> +					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
> +	if (err)
> +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> +			       inst->ctx->decoded_frame_cnt);
> +
> +	inst->vsi->dec.timeout = !!err;
> +	err = vpu_dec_end(vpu);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
> +			 inst->ctx->decoded_frame_cnt,
> +			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
> +			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
> +			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
> +			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
> +
> +	inst->ctx->decoded_frame_cnt++;
> +	return 0;
> +
> +err_free_fb_out:
> +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> +		       inst->ctx->decoded_frame_cnt, err);
> +	return err;
> +}
> +
> +static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +				  struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	int ret;
> +
> +	if (!h_vdec)
> +		return -EINVAL;
> +
> +	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
> +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
> +	else
> +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
> +
> +	return ret;
> +}
> +
>  static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
>  				     void *out)
>  {
> @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
>  
>  const struct vdec_common_if vdec_h264_slice_multi_if = {
>  	.init		= vdec_h264_slice_init,
> -	.decode		= vdec_h264_slice_lat_decode,
> +	.decode		= vdec_h264_slice_decode,
>  	.get_param	= vdec_h264_slice_get_param,
>  	.deinit		= vdec_h264_slice_deinit,
>  };


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-13 20:08     ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:08 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Add h264 decode driver to support mt8186. For the architecture
> is single core, need to add new interface to decode.
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  1 file changed, 176 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> index a96f203b5d54..1d9e753cf894 100644
> --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
>   * @vsi:		vsi used for lat
>   * @vsi_core:		vsi used for core
>   *
> + * @vsi_ctx:		Local VSI data for this decoding context
> + * @h264_slice_param:	the parameters that hardware use to decode
> + *
>   * @resolution_changed:resolution changed
>   * @realloc_mv_buf:	reallocate mv buffer
>   * @cap_num_planes:	number of capture queue plane
> @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
>  	struct vdec_h264_slice_vsi *vsi;
>  	struct vdec_h264_slice_vsi *vsi_core;
>  
> +	struct vdec_h264_slice_vsi vsi_ctx;
> +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> +
>  	unsigned int resolution_changed;
>  	unsigned int realloc_mv_buf;
>  	unsigned int cap_num_planes;
> @@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
>  	return 0;
>  }
>  
> +static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
> +{
> +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> +	const struct v4l2_ctrl_h264_sps *sps;
> +	const struct v4l2_ctrl_h264_pps *pps;
> +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
> +	struct v4l2_h264_reflist_builder reflist_builder;
> +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> +
> +	dec_params =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> +	if (IS_ERR(dec_params))
> +		return PTR_ERR(dec_params);
> +
> +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
> +	if (IS_ERR(sps))
> +		return PTR_ERR(sps);
> +
> +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
> +	if (IS_ERR(pps))
> +		return PTR_ERR(pps);
> +
> +	scaling_matrix =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> +	if (IS_ERR(scaling_matrix))
> +		return PTR_ERR(scaling_matrix);
> +
> +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> +
> +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
> +
> +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
> +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
> +				    slice_param->h264_dpb_info);
> +
> +	/* Build the reference lists */
> +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
> +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> +
> +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
> +	/* Adapt the built lists to the firmware's expectations */
> +	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
> +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> +	       sizeof(inst->vsi_ctx.h264_slice_params));

This function looks very redundant across multiple variants, could you try and
make a helper to reduce the duplication ?

> +
> +	return 0;
> +}
> +
>  static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
>  						struct vdec_h264_slice_lat_dec_param *slice_param,
>  						struct vdec_h264_slice_share_info *share_info)
> @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
>  	return err;
>  }
>  
> +static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +					 struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	struct vdec_vpu_inst *vpu = &inst->vpu;
> +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> +	struct vdec_fb *fb;
> +	unsigned char *buf;
> +	unsigned int data[2], i;
> +	u64 y_fb_dma, c_fb_dma;
> +	struct mtk_vcodec_mem *mem;
> +	int err, nal_start_idx;
> +
> +	/* bs NULL means flush decoder */
> +	if (!bs)
> +		return vpu_dec_reset(vpu);
> +
> +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> +	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
> +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
> +
> +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> +			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
> +
> +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> +
> +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> +				   &dst_buf_info->m2m_buf.vb, true);
> +	err = get_vdec_sig_decode_parameters(inst);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	buf = (unsigned char *)bs->va;
> +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> +	if (nal_start_idx < 0) {
> +		err = -EINVAL;
> +		goto err_free_fb_out;
> +	}
> +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> +
> +	*res_chg = inst->resolution_changed;
> +	if (inst->resolution_changed) {
> +		mtk_vcodec_debug(inst, "- resolution changed -");
> +		if (inst->realloc_mv_buf) {
> +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
> +			inst->realloc_mv_buf = false;
> +			if (err)
> +				goto err_free_fb_out;
> +		}
> +		inst->resolution_changed = false;
> +
> +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> +			mem = &inst->mv_buf[i];
> +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> +		}
> +	}
> +
> +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> +	err = vpu_dec_start(vpu, data, 2);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	/* wait decoder done interrupt */
> +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
> +					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
> +	if (err)
> +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> +			       inst->ctx->decoded_frame_cnt);
> +
> +	inst->vsi->dec.timeout = !!err;
> +	err = vpu_dec_end(vpu);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
> +			 inst->ctx->decoded_frame_cnt,
> +			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
> +			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
> +			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
> +			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
> +
> +	inst->ctx->decoded_frame_cnt++;
> +	return 0;
> +
> +err_free_fb_out:
> +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> +		       inst->ctx->decoded_frame_cnt, err);
> +	return err;
> +}
> +
> +static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +				  struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	int ret;
> +
> +	if (!h_vdec)
> +		return -EINVAL;
> +
> +	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
> +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
> +	else
> +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
> +
> +	return ret;
> +}
> +
>  static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
>  				     void *out)
>  {
> @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
>  
>  const struct vdec_common_if vdec_h264_slice_multi_if = {
>  	.init		= vdec_h264_slice_init,
> -	.decode		= vdec_h264_slice_lat_decode,
> +	.decode		= vdec_h264_slice_decode,
>  	.get_param	= vdec_h264_slice_get_param,
>  	.deinit		= vdec_h264_slice_deinit,
>  };


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-13 20:08     ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:08 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Add h264 decode driver to support mt8186. For the architecture
> is single core, need to add new interface to decode.
> 
> Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> ---
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  1 file changed, 176 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> index a96f203b5d54..1d9e753cf894 100644
> --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
> @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
>   * @vsi:		vsi used for lat
>   * @vsi_core:		vsi used for core
>   *
> + * @vsi_ctx:		Local VSI data for this decoding context
> + * @h264_slice_param:	the parameters that hardware use to decode
> + *
>   * @resolution_changed:resolution changed
>   * @realloc_mv_buf:	reallocate mv buffer
>   * @cap_num_planes:	number of capture queue plane
> @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
>  	struct vdec_h264_slice_vsi *vsi;
>  	struct vdec_h264_slice_vsi *vsi_core;
>  
> +	struct vdec_h264_slice_vsi vsi_ctx;
> +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> +
>  	unsigned int resolution_changed;
>  	unsigned int realloc_mv_buf;
>  	unsigned int cap_num_planes;
> @@ -208,6 +214,61 @@ static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *i
>  	return 0;
>  }
>  
> +static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst)
> +{
> +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> +	const struct v4l2_ctrl_h264_sps *sps;
> +	const struct v4l2_ctrl_h264_pps *pps;
> +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst->h264_slice_param;
> +	struct v4l2_h264_reflist_builder reflist_builder;
> +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> +
> +	dec_params =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> +	if (IS_ERR(dec_params))
> +		return PTR_ERR(dec_params);
> +
> +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SPS);
> +	if (IS_ERR(sps))
> +		return PTR_ERR(sps);
> +
> +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_PPS);
> +	if (IS_ERR(pps))
> +		return PTR_ERR(pps);
> +
> +	scaling_matrix =
> +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> +	if (IS_ERR(scaling_matrix))
> +		return PTR_ERR(scaling_matrix);
> +
> +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> +
> +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, scaling_matrix);
> +
> +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params, dec_params, inst->dpb);
> +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param->decode_params,
> +				    slice_param->h264_dpb_info);
> +
> +	/* Build the reference lists */
> +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps, inst->dpb);
> +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> +
> +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist, b1_reflist);
> +	/* Adapt the built lists to the firmware's expectations */
> +	mtk_vdec_h264_fixup_ref_list(p0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b0_reflist, reflist_builder.num_valid);
> +	mtk_vdec_h264_fixup_ref_list(b1_reflist, reflist_builder.num_valid);
> +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> +	       sizeof(inst->vsi_ctx.h264_slice_params));

This function looks very redundant across multiple variants, could you try and
make a helper to reduce the duplication ?

> +
> +	return 0;
> +}
> +
>  static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst,
>  						struct vdec_h264_slice_lat_dec_param *slice_param,
>  						struct vdec_h264_slice_share_info *share_info)
> @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
>  	return err;
>  }
>  
> +static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +					 struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	struct vdec_vpu_inst *vpu = &inst->vpu;
> +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> +	struct vdec_fb *fb;
> +	unsigned char *buf;
> +	unsigned int data[2], i;
> +	u64 y_fb_dma, c_fb_dma;
> +	struct mtk_vcodec_mem *mem;
> +	int err, nal_start_idx;
> +
> +	/* bs NULL means flush decoder */
> +	if (!bs)
> +		return vpu_dec_reset(vpu);
> +
> +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> +	src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
> +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer);
> +
> +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> +			 inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma);
> +
> +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> +
> +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> +				   &dst_buf_info->m2m_buf.vb, true);
> +	err = get_vdec_sig_decode_parameters(inst);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	buf = (unsigned char *)bs->va;
> +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> +	if (nal_start_idx < 0) {
> +		err = -EINVAL;
> +		goto err_free_fb_out;
> +	}
> +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> +
> +	*res_chg = inst->resolution_changed;
> +	if (inst->resolution_changed) {
> +		mtk_vcodec_debug(inst, "- resolution changed -");
> +		if (inst->realloc_mv_buf) {
> +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst->ctx->picinfo);
> +			inst->realloc_mv_buf = false;
> +			if (err)
> +				goto err_free_fb_out;
> +		}
> +		inst->resolution_changed = false;
> +
> +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> +			mem = &inst->mv_buf[i];
> +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> +		}
> +	}
> +
> +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> +	err = vpu_dec_start(vpu, data, 2);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	/* wait decoder done interrupt */
> +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
> +					   WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE);
> +	if (err)
> +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> +			       inst->ctx->decoded_frame_cnt);
> +
> +	inst->vsi->dec.timeout = !!err;
> +	err = vpu_dec_end(vpu);
> +	if (err)
> +		goto err_free_fb_out;
> +
> +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
> +			 inst->ctx->decoded_frame_cnt,
> +			 inst->vsi_ctx.dec.crc[0], inst->vsi_ctx.dec.crc[1],
> +			 inst->vsi_ctx.dec.crc[2], inst->vsi_ctx.dec.crc[3],
> +			 inst->vsi_ctx.dec.crc[4], inst->vsi_ctx.dec.crc[5],
> +			 inst->vsi_ctx.dec.crc[6], inst->vsi_ctx.dec.crc[7]);
> +
> +	inst->ctx->decoded_frame_cnt++;
> +	return 0;
> +
> +err_free_fb_out:
> +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> +		       inst->ctx->decoded_frame_cnt, err);
> +	return err;
> +}
> +
> +static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
> +				  struct vdec_fb *unused, bool *res_chg)
> +{
> +	struct vdec_h264_slice_inst *inst = h_vdec;
> +	int ret;
> +
> +	if (!h_vdec)
> +		return -EINVAL;
> +
> +	if (inst->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_PURE_SINGLE_CORE)
> +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused, res_chg);
> +	else
> +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused, res_chg);
> +
> +	return ret;
> +}
> +
>  static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
>  				     void *out)
>  {
> @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
>  
>  const struct vdec_common_if vdec_h264_slice_multi_if = {
>  	.init		= vdec_h264_slice_init,
> -	.decode		= vdec_h264_slice_lat_decode,
> +	.decode		= vdec_h264_slice_decode,
>  	.get_param	= vdec_h264_slice_get_param,
>  	.deinit		= vdec_h264_slice_deinit,
>  };


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
  2022-05-12  3:46 ` Yunfei Dong
  (?)
  (?)
@ 2022-06-13 20:10   ` Nicolas Dufresne
  -1 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:10 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Firstly, add mt8186 compatible and private data, then add document for
> compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> architecture, need to add new interface for h264 hardware decoder.

Would be nice to take the habit of sharing fluster score for this new HW, I
would expect no less then what the numbers you'd get from running over MT8195 or
92, remains nice to demonstrate that this was tested and document any oops along
the way.
> 
> Patche 1 add mt8186 compatible and private data.
> Patche 2 add mt8186 compatible document.
> Patche 3 add h264 single core driver.
> ---
> This patch depends on "support for MT8192 decoder"[1]
> 
> [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> ---
> changed with v3:
> - fix __iomem not reasonable, align share memory to dram.
> changed with v2:
> - fix sparse and smatch check fail for patch 3
> changed with v1:
> - rebase driver to the latest media_stage.
> ---
> Yunfei Dong (3):
>   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
>     mt8186
>   media: mediatek: vcodec: Support MT8186
>   media: mediatek: vcodec: add h264 decoder driver for mt8186
> 
>  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
>  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
>  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
>  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  5 files changed, 203 insertions(+), 2 deletions(-)
> 


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-13 20:10   ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:10 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Firstly, add mt8186 compatible and private data, then add document for
> compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> architecture, need to add new interface for h264 hardware decoder.

Would be nice to take the habit of sharing fluster score for this new HW, I
would expect no less then what the numbers you'd get from running over MT8195 or
92, remains nice to demonstrate that this was tested and document any oops along
the way.
> 
> Patche 1 add mt8186 compatible and private data.
> Patche 2 add mt8186 compatible document.
> Patche 3 add h264 single core driver.
> ---
> This patch depends on "support for MT8192 decoder"[1]
> 
> [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> ---
> changed with v3:
> - fix __iomem not reasonable, align share memory to dram.
> changed with v2:
> - fix sparse and smatch check fail for patch 3
> changed with v1:
> - rebase driver to the latest media_stage.
> ---
> Yunfei Dong (3):
>   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
>     mt8186
>   media: mediatek: vcodec: Support MT8186
>   media: mediatek: vcodec: add h264 decoder driver for mt8186
> 
>  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
>  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
>  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
>  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  5 files changed, 203 insertions(+), 2 deletions(-)
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-13 20:10   ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:10 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Firstly, add mt8186 compatible and private data, then add document for
> compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> architecture, need to add new interface for h264 hardware decoder.

Would be nice to take the habit of sharing fluster score for this new HW, I
would expect no less then what the numbers you'd get from running over MT8195 or
92, remains nice to demonstrate that this was tested and document any oops along
the way.
> 
> Patche 1 add mt8186 compatible and private data.
> Patche 2 add mt8186 compatible document.
> Patche 3 add h264 single core driver.
> ---
> This patch depends on "support for MT8192 decoder"[1]
> 
> [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> ---
> changed with v3:
> - fix __iomem not reasonable, align share memory to dram.
> changed with v2:
> - fix sparse and smatch check fail for patch 3
> changed with v1:
> - rebase driver to the latest media_stage.
> ---
> Yunfei Dong (3):
>   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
>     mt8186
>   media: mediatek: vcodec: Support MT8186
>   media: mediatek: vcodec: add h264 decoder driver for mt8186
> 
>  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
>  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
>  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
>  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  5 files changed, 203 insertions(+), 2 deletions(-)
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-13 20:10   ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-13 20:10 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> Firstly, add mt8186 compatible and private data, then add document for
> compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> architecture, need to add new interface for h264 hardware decoder.

Would be nice to take the habit of sharing fluster score for this new HW, I
would expect no less then what the numbers you'd get from running over MT8195 or
92, remains nice to demonstrate that this was tested and document any oops along
the way.
> 
> Patche 1 add mt8186 compatible and private data.
> Patche 2 add mt8186 compatible document.
> Patche 3 add h264 single core driver.
> ---
> This patch depends on "support for MT8192 decoder"[1]
> 
> [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> ---
> changed with v3:
> - fix __iomem not reasonable, align share memory to dram.
> changed with v2:
> - fix sparse and smatch check fail for patch 3
> changed with v1:
> - rebase driver to the latest media_stage.
> ---
> Yunfei Dong (3):
>   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
>     mt8186
>   media: mediatek: vcodec: Support MT8186
>   media: mediatek: vcodec: add h264 decoder driver for mt8186
> 
>  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
>  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
>  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
>  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
>  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
>  5 files changed, 203 insertions(+), 2 deletions(-)
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
  2022-06-13 20:10   ` Nicolas Dufresne
  (?)
  (?)
@ 2022-06-14 17:46     ` Nicolas Dufresne
  -1 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-14 17:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new HW, I
> would expect no less then what the numbers you'd get from running over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any oops along
> the way.
> > 
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/

I forgot earlier, but I suppose this will also depends on an scp.img firmware ?
If so, any linux-firmware submission to link to ?

> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-14 17:46     ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-14 17:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new HW, I
> would expect no less then what the numbers you'd get from running over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any oops along
> the way.
> > 
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/

I forgot earlier, but I suppose this will also depends on an scp.img firmware ?
If so, any linux-firmware submission to link to ?

> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-14 17:46     ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-14 17:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new HW, I
> would expect no less then what the numbers you'd get from running over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any oops along
> the way.
> > 
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/

I forgot earlier, but I suppose this will also depends on an scp.img firmware ?
If so, any linux-firmware submission to link to ?

> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-14 17:46     ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-14 17:46 UTC (permalink / raw)
  To: Yunfei Dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new HW, I
> would expect no less then what the numbers you'd get from running over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any oops along
> the way.
> > 
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/

I forgot earlier, but I suppose this will also depends on an scp.img firmware ?
If so, any linux-firmware submission to link to ?

> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177 +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
  2022-06-13 20:08     ` Nicolas Dufresne
  (?)
@ 2022-06-15 11:33       ` yunfei.dong
  -1 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:33 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Add h264 decode driver to support mt8186. For the architecture
> > is single core, need to add new interface to decode.
> > 
> > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > ---
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > +++++++++++++++++-
> >  1 file changed, 176 insertions(+), 1 deletion(-)
> > 
> > diff --git
> > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > index a96f203b5d54..1d9e753cf894 100644
> > ---
> > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > +++
> > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> >   * @vsi:		vsi used for lat
> >   * @vsi_core:		vsi used for core
> >   *
> > + * @vsi_ctx:		Local VSI data for this decoding
> > context
> > + * @h264_slice_param:	the parameters that hardware use to
> > decode
> > + *
> >   * @resolution_changed:resolution changed
> >   * @realloc_mv_buf:	reallocate mv buffer
> >   * @cap_num_planes:	number of capture queue plane
> > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> >  	struct vdec_h264_slice_vsi *vsi;
> >  	struct vdec_h264_slice_vsi *vsi_core;
> >  
> > +	struct vdec_h264_slice_vsi vsi_ctx;
> > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > +
> >  	unsigned int resolution_changed;
> >  	unsigned int realloc_mv_buf;
> >  	unsigned int cap_num_planes;
> > @@ -208,6 +214,61 @@ static int
> > vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst
> > *i
> >  	return 0;
> >  }
> >  
> > +static int get_vdec_sig_decode_parameters(struct
> > vdec_h264_slice_inst *inst)
> > +{
> > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > +	const struct v4l2_ctrl_h264_sps *sps;
> > +	const struct v4l2_ctrl_h264_pps *pps;
> > +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> > +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst-
> > >h264_slice_param;
> > +	struct v4l2_h264_reflist_builder reflist_builder;
> > +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> > +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> > +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> > +
> > +	dec_params =
> > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > +	if (IS_ERR(dec_params))
> > +		return PTR_ERR(dec_params);
> > +
> > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_SPS);
> > +	if (IS_ERR(sps))
> > +		return PTR_ERR(sps);
> > +
> > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_PPS);
> > +	if (IS_ERR(pps))
> > +		return PTR_ERR(pps);
> > +
> > +	scaling_matrix =
> > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > +	if (IS_ERR(scaling_matrix))
> > +		return PTR_ERR(scaling_matrix);
> > +
> > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > +
> > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, 
> > scaling_matrix);
> > +
> > +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params,
> > dec_params, inst->dpb);
> > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > >decode_params,
> > +				    slice_param->h264_dpb_info);
> > +
> > +	/* Build the reference lists */
> > +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params,
> > sps, inst->dpb);
> > +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> > +
> > +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist,
> > b1_reflist);
> > +	/* Adapt the built lists to the firmware's expectations */
> > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > reflist_builder.num_valid);
> > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > reflist_builder.num_valid);
> > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > reflist_builder.num_valid);
> > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> 
> This function looks very redundant across multiple variants, could
> you try and
> make a helper to reduce the duplication ?
> 
At first, I try to add one helper function for single core and lat
decode.

But these two hardware have big differences, need to add many condition
to separate. So just add new function for mt8186 single core
architecture.

Best Regards,
Yunfei Dong
> > +
> > +	return 0;
> > +}
> > +
> >  static void vdec_h264_slice_fill_decode_reflist(struct
> > vdec_h264_slice_inst *inst,
> >  						struct
> > vdec_h264_slice_lat_dec_param *slice_param,
> >  						struct
> > vdec_h264_slice_share_info *share_info)
> > @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void
> > *h_vdec, struct mtk_vcodec_mem *bs,
> >  	return err;
> >  }
> >  
> > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > mtk_vcodec_mem *bs,
> > +					 struct vdec_fb *unused, bool
> > *res_chg)
> > +{
> > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > +	struct vdec_fb *fb;
> > +	unsigned char *buf;
> > +	unsigned int data[2], i;
> > +	u64 y_fb_dma, c_fb_dma;
> > +	struct mtk_vcodec_mem *mem;
> > +	int err, nal_start_idx;
> > +
> > +	/* bs NULL means flush decoder */
> > +	if (!bs)
> > +		return vpu_dec_reset(vpu);
> > +
> > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> > +	src_buf_info = container_of(bs, struct mtk_video_dec_buf,
> > bs_buffer);
> > +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf,
> > frame_buffer);
> > +
> > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> > +			 inst->ctx->decoded_frame_cnt, y_fb_dma,
> > c_fb_dma);
> > +
> > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > +
> > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > +				   &dst_buf_info->m2m_buf.vb, true);
> > +	err = get_vdec_sig_decode_parameters(inst);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	buf = (unsigned char *)bs->va;
> > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> > +	if (nal_start_idx < 0) {
> > +		err = -EINVAL;
> > +		goto err_free_fb_out;
> > +	}
> > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > +
> > +	*res_chg = inst->resolution_changed;
> > +	if (inst->resolution_changed) {
> > +		mtk_vcodec_debug(inst, "- resolution changed -");
> > +		if (inst->realloc_mv_buf) {
> > +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > >ctx->picinfo);
> > +			inst->realloc_mv_buf = false;
> > +			if (err)
> > +				goto err_free_fb_out;
> > +		}
> > +		inst->resolution_changed = false;
> > +
> > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > +			mem = &inst->mv_buf[i];
> > +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> > +		}
> > +	}
> > +
> > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> > +	err = vpu_dec_start(vpu, data, 2);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	/* wait decoder done interrupt */
> > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > MTK_INST_IRQ_RECEIVED,
> > +					   WAIT_INTR_TIMEOUT_MS,
> > MTK_VDEC_CORE);
> > +	if (err)
> > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > +			       inst->ctx->decoded_frame_cnt);
> > +
> > +	inst->vsi->dec.timeout = !!err;
> > +	err = vpu_dec_end(vpu);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x
> > 0x%x 0x%x 0x%x",
> > +			 inst->ctx->decoded_frame_cnt,
> > +			 inst->vsi_ctx.dec.crc[0], inst-
> > >vsi_ctx.dec.crc[1],
> > +			 inst->vsi_ctx.dec.crc[2], inst-
> > >vsi_ctx.dec.crc[3],
> > +			 inst->vsi_ctx.dec.crc[4], inst-
> > >vsi_ctx.dec.crc[5],
> > +			 inst->vsi_ctx.dec.crc[6], inst-
> > >vsi_ctx.dec.crc[7]);
> > +
> > +	inst->ctx->decoded_frame_cnt++;
> > +	return 0;
> > +
> > +err_free_fb_out:
> > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > +		       inst->ctx->decoded_frame_cnt, err);
> > +	return err;
> > +}
> > +
> > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > mtk_vcodec_mem *bs,
> > +				  struct vdec_fb *unused, bool
> > *res_chg)
> > +{
> > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > +	int ret;
> > +
> > +	if (!h_vdec)
> > +		return -EINVAL;
> > +
> > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > MTK_VDEC_PURE_SINGLE_CORE)
> > +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused,
> > res_chg);
> > +	else
> > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
> > res_chg);
> > +
> > +	return ret;
> > +}
> > +
> >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > vdec_get_param_type type,
> >  				     void *out)
> >  {
> > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > *h_vdec, enum vdec_get_param_type type
> >  
> >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> >  	.init		= vdec_h264_slice_init,
> > -	.decode		= vdec_h264_slice_lat_decode,
> > +	.decode		= vdec_h264_slice_decode,
> >  	.get_param	= vdec_h264_slice_get_param,
> >  	.deinit		= vdec_h264_slice_deinit,
> >  };
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-15 11:33       ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:33 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Hi Nicolas,

Thanks for your comments.
On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Add h264 decode driver to support mt8186. For the architecture
> > is single core, need to add new interface to decode.
> > 
> > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > ---
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > +++++++++++++++++-
> >  1 file changed, 176 insertions(+), 1 deletion(-)
> > 
> > diff --git
> > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > index a96f203b5d54..1d9e753cf894 100644
> > ---
> > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > +++
> > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> >   * @vsi:		vsi used for lat
> >   * @vsi_core:		vsi used for core
> >   *
> > + * @vsi_ctx:		Local VSI data for this decoding
> > context
> > + * @h264_slice_param:	the parameters that hardware use to
> > decode
> > + *
> >   * @resolution_changed:resolution changed
> >   * @realloc_mv_buf:	reallocate mv buffer
> >   * @cap_num_planes:	number of capture queue plane
> > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> >  	struct vdec_h264_slice_vsi *vsi;
> >  	struct vdec_h264_slice_vsi *vsi_core;
> >  
> > +	struct vdec_h264_slice_vsi vsi_ctx;
> > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > +
> >  	unsigned int resolution_changed;
> >  	unsigned int realloc_mv_buf;
> >  	unsigned int cap_num_planes;
> > @@ -208,6 +214,61 @@ static int
> > vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst
> > *i
> >  	return 0;
> >  }
> >  
> > +static int get_vdec_sig_decode_parameters(struct
> > vdec_h264_slice_inst *inst)
> > +{
> > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > +	const struct v4l2_ctrl_h264_sps *sps;
> > +	const struct v4l2_ctrl_h264_pps *pps;
> > +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> > +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst-
> > >h264_slice_param;
> > +	struct v4l2_h264_reflist_builder reflist_builder;
> > +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> > +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> > +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> > +
> > +	dec_params =
> > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > +	if (IS_ERR(dec_params))
> > +		return PTR_ERR(dec_params);
> > +
> > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_SPS);
> > +	if (IS_ERR(sps))
> > +		return PTR_ERR(sps);
> > +
> > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_PPS);
> > +	if (IS_ERR(pps))
> > +		return PTR_ERR(pps);
> > +
> > +	scaling_matrix =
> > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > +	if (IS_ERR(scaling_matrix))
> > +		return PTR_ERR(scaling_matrix);
> > +
> > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > +
> > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, 
> > scaling_matrix);
> > +
> > +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params,
> > dec_params, inst->dpb);
> > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > >decode_params,
> > +				    slice_param->h264_dpb_info);
> > +
> > +	/* Build the reference lists */
> > +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params,
> > sps, inst->dpb);
> > +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> > +
> > +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist,
> > b1_reflist);
> > +	/* Adapt the built lists to the firmware's expectations */
> > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > reflist_builder.num_valid);
> > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > reflist_builder.num_valid);
> > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > reflist_builder.num_valid);
> > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> 
> This function looks very redundant across multiple variants, could
> you try and
> make a helper to reduce the duplication ?
> 
At first, I try to add one helper function for single core and lat
decode.

But these two hardware have big differences, need to add many condition
to separate. So just add new function for mt8186 single core
architecture.

Best Regards,
Yunfei Dong
> > +
> > +	return 0;
> > +}
> > +
> >  static void vdec_h264_slice_fill_decode_reflist(struct
> > vdec_h264_slice_inst *inst,
> >  						struct
> > vdec_h264_slice_lat_dec_param *slice_param,
> >  						struct
> > vdec_h264_slice_share_info *share_info)
> > @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void
> > *h_vdec, struct mtk_vcodec_mem *bs,
> >  	return err;
> >  }
> >  
> > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > mtk_vcodec_mem *bs,
> > +					 struct vdec_fb *unused, bool
> > *res_chg)
> > +{
> > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > +	struct vdec_fb *fb;
> > +	unsigned char *buf;
> > +	unsigned int data[2], i;
> > +	u64 y_fb_dma, c_fb_dma;
> > +	struct mtk_vcodec_mem *mem;
> > +	int err, nal_start_idx;
> > +
> > +	/* bs NULL means flush decoder */
> > +	if (!bs)
> > +		return vpu_dec_reset(vpu);
> > +
> > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> > +	src_buf_info = container_of(bs, struct mtk_video_dec_buf,
> > bs_buffer);
> > +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf,
> > frame_buffer);
> > +
> > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> > +			 inst->ctx->decoded_frame_cnt, y_fb_dma,
> > c_fb_dma);
> > +
> > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > +
> > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > +				   &dst_buf_info->m2m_buf.vb, true);
> > +	err = get_vdec_sig_decode_parameters(inst);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	buf = (unsigned char *)bs->va;
> > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> > +	if (nal_start_idx < 0) {
> > +		err = -EINVAL;
> > +		goto err_free_fb_out;
> > +	}
> > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > +
> > +	*res_chg = inst->resolution_changed;
> > +	if (inst->resolution_changed) {
> > +		mtk_vcodec_debug(inst, "- resolution changed -");
> > +		if (inst->realloc_mv_buf) {
> > +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > >ctx->picinfo);
> > +			inst->realloc_mv_buf = false;
> > +			if (err)
> > +				goto err_free_fb_out;
> > +		}
> > +		inst->resolution_changed = false;
> > +
> > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > +			mem = &inst->mv_buf[i];
> > +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> > +		}
> > +	}
> > +
> > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> > +	err = vpu_dec_start(vpu, data, 2);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	/* wait decoder done interrupt */
> > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > MTK_INST_IRQ_RECEIVED,
> > +					   WAIT_INTR_TIMEOUT_MS,
> > MTK_VDEC_CORE);
> > +	if (err)
> > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > +			       inst->ctx->decoded_frame_cnt);
> > +
> > +	inst->vsi->dec.timeout = !!err;
> > +	err = vpu_dec_end(vpu);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x
> > 0x%x 0x%x 0x%x",
> > +			 inst->ctx->decoded_frame_cnt,
> > +			 inst->vsi_ctx.dec.crc[0], inst-
> > >vsi_ctx.dec.crc[1],
> > +			 inst->vsi_ctx.dec.crc[2], inst-
> > >vsi_ctx.dec.crc[3],
> > +			 inst->vsi_ctx.dec.crc[4], inst-
> > >vsi_ctx.dec.crc[5],
> > +			 inst->vsi_ctx.dec.crc[6], inst-
> > >vsi_ctx.dec.crc[7]);
> > +
> > +	inst->ctx->decoded_frame_cnt++;
> > +	return 0;
> > +
> > +err_free_fb_out:
> > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > +		       inst->ctx->decoded_frame_cnt, err);
> > +	return err;
> > +}
> > +
> > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > mtk_vcodec_mem *bs,
> > +				  struct vdec_fb *unused, bool
> > *res_chg)
> > +{
> > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > +	int ret;
> > +
> > +	if (!h_vdec)
> > +		return -EINVAL;
> > +
> > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > MTK_VDEC_PURE_SINGLE_CORE)
> > +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused,
> > res_chg);
> > +	else
> > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
> > res_chg);
> > +
> > +	return ret;
> > +}
> > +
> >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > vdec_get_param_type type,
> >  				     void *out)
> >  {
> > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > *h_vdec, enum vdec_get_param_type type
> >  
> >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> >  	.init		= vdec_h264_slice_init,
> > -	.decode		= vdec_h264_slice_lat_decode,
> > +	.decode		= vdec_h264_slice_decode,
> >  	.get_param	= vdec_h264_slice_get_param,
> >  	.deinit		= vdec_h264_slice_deinit,
> >  };
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-15 11:33       ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:33 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Add h264 decode driver to support mt8186. For the architecture
> > is single core, need to add new interface to decode.
> > 
> > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > ---
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > +++++++++++++++++-
> >  1 file changed, 176 insertions(+), 1 deletion(-)
> > 
> > diff --git
> > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > index a96f203b5d54..1d9e753cf894 100644
> > ---
> > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > +++
> > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > f.c
> > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> >   * @vsi:		vsi used for lat
> >   * @vsi_core:		vsi used for core
> >   *
> > + * @vsi_ctx:		Local VSI data for this decoding
> > context
> > + * @h264_slice_param:	the parameters that hardware use to
> > decode
> > + *
> >   * @resolution_changed:resolution changed
> >   * @realloc_mv_buf:	reallocate mv buffer
> >   * @cap_num_planes:	number of capture queue plane
> > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> >  	struct vdec_h264_slice_vsi *vsi;
> >  	struct vdec_h264_slice_vsi *vsi_core;
> >  
> > +	struct vdec_h264_slice_vsi vsi_ctx;
> > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > +
> >  	unsigned int resolution_changed;
> >  	unsigned int realloc_mv_buf;
> >  	unsigned int cap_num_planes;
> > @@ -208,6 +214,61 @@ static int
> > vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst
> > *i
> >  	return 0;
> >  }
> >  
> > +static int get_vdec_sig_decode_parameters(struct
> > vdec_h264_slice_inst *inst)
> > +{
> > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > +	const struct v4l2_ctrl_h264_sps *sps;
> > +	const struct v4l2_ctrl_h264_pps *pps;
> > +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> > +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst-
> > >h264_slice_param;
> > +	struct v4l2_h264_reflist_builder reflist_builder;
> > +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> > +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> > +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> > +
> > +	dec_params =
> > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > +	if (IS_ERR(dec_params))
> > +		return PTR_ERR(dec_params);
> > +
> > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_SPS);
> > +	if (IS_ERR(sps))
> > +		return PTR_ERR(sps);
> > +
> > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_PPS);
> > +	if (IS_ERR(pps))
> > +		return PTR_ERR(pps);
> > +
> > +	scaling_matrix =
> > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > +	if (IS_ERR(scaling_matrix))
> > +		return PTR_ERR(scaling_matrix);
> > +
> > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > +
> > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, 
> > scaling_matrix);
> > +
> > +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params,
> > dec_params, inst->dpb);
> > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > >decode_params,
> > +				    slice_param->h264_dpb_info);
> > +
> > +	/* Build the reference lists */
> > +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params,
> > sps, inst->dpb);
> > +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> > +
> > +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist,
> > b1_reflist);
> > +	/* Adapt the built lists to the firmware's expectations */
> > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > reflist_builder.num_valid);
> > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > reflist_builder.num_valid);
> > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > reflist_builder.num_valid);
> > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> 
> This function looks very redundant across multiple variants, could
> you try and
> make a helper to reduce the duplication ?
> 
At first, I try to add one helper function for single core and lat
decode.

But these two hardware have big differences, need to add many condition
to separate. So just add new function for mt8186 single core
architecture.

Best Regards,
Yunfei Dong
> > +
> > +	return 0;
> > +}
> > +
> >  static void vdec_h264_slice_fill_decode_reflist(struct
> > vdec_h264_slice_inst *inst,
> >  						struct
> > vdec_h264_slice_lat_dec_param *slice_param,
> >  						struct
> > vdec_h264_slice_share_info *share_info)
> > @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void
> > *h_vdec, struct mtk_vcodec_mem *bs,
> >  	return err;
> >  }
> >  
> > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > mtk_vcodec_mem *bs,
> > +					 struct vdec_fb *unused, bool
> > *res_chg)
> > +{
> > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > +	struct vdec_fb *fb;
> > +	unsigned char *buf;
> > +	unsigned int data[2], i;
> > +	u64 y_fb_dma, c_fb_dma;
> > +	struct mtk_vcodec_mem *mem;
> > +	int err, nal_start_idx;
> > +
> > +	/* bs NULL means flush decoder */
> > +	if (!bs)
> > +		return vpu_dec_reset(vpu);
> > +
> > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> > +	src_buf_info = container_of(bs, struct mtk_video_dec_buf,
> > bs_buffer);
> > +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf,
> > frame_buffer);
> > +
> > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> > +			 inst->ctx->decoded_frame_cnt, y_fb_dma,
> > c_fb_dma);
> > +
> > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > +
> > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > +				   &dst_buf_info->m2m_buf.vb, true);
> > +	err = get_vdec_sig_decode_parameters(inst);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	buf = (unsigned char *)bs->va;
> > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> > +	if (nal_start_idx < 0) {
> > +		err = -EINVAL;
> > +		goto err_free_fb_out;
> > +	}
> > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > +
> > +	*res_chg = inst->resolution_changed;
> > +	if (inst->resolution_changed) {
> > +		mtk_vcodec_debug(inst, "- resolution changed -");
> > +		if (inst->realloc_mv_buf) {
> > +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > >ctx->picinfo);
> > +			inst->realloc_mv_buf = false;
> > +			if (err)
> > +				goto err_free_fb_out;
> > +		}
> > +		inst->resolution_changed = false;
> > +
> > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > +			mem = &inst->mv_buf[i];
> > +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> > +		}
> > +	}
> > +
> > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> > +	err = vpu_dec_start(vpu, data, 2);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	/* wait decoder done interrupt */
> > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > MTK_INST_IRQ_RECEIVED,
> > +					   WAIT_INTR_TIMEOUT_MS,
> > MTK_VDEC_CORE);
> > +	if (err)
> > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > +			       inst->ctx->decoded_frame_cnt);
> > +
> > +	inst->vsi->dec.timeout = !!err;
> > +	err = vpu_dec_end(vpu);
> > +	if (err)
> > +		goto err_free_fb_out;
> > +
> > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x
> > 0x%x 0x%x 0x%x",
> > +			 inst->ctx->decoded_frame_cnt,
> > +			 inst->vsi_ctx.dec.crc[0], inst-
> > >vsi_ctx.dec.crc[1],
> > +			 inst->vsi_ctx.dec.crc[2], inst-
> > >vsi_ctx.dec.crc[3],
> > +			 inst->vsi_ctx.dec.crc[4], inst-
> > >vsi_ctx.dec.crc[5],
> > +			 inst->vsi_ctx.dec.crc[6], inst-
> > >vsi_ctx.dec.crc[7]);
> > +
> > +	inst->ctx->decoded_frame_cnt++;
> > +	return 0;
> > +
> > +err_free_fb_out:
> > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > +		       inst->ctx->decoded_frame_cnt, err);
> > +	return err;
> > +}
> > +
> > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > mtk_vcodec_mem *bs,
> > +				  struct vdec_fb *unused, bool
> > *res_chg)
> > +{
> > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > +	int ret;
> > +
> > +	if (!h_vdec)
> > +		return -EINVAL;
> > +
> > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > MTK_VDEC_PURE_SINGLE_CORE)
> > +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused,
> > res_chg);
> > +	else
> > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
> > res_chg);
> > +
> > +	return ret;
> > +}
> > +
> >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > vdec_get_param_type type,
> >  				     void *out)
> >  {
> > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > *h_vdec, enum vdec_get_param_type type
> >  
> >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> >  	.init		= vdec_h264_slice_init,
> > -	.decode		= vdec_h264_slice_lat_decode,
> > +	.decode		= vdec_h264_slice_decode,
> >  	.get_param	= vdec_h264_slice_get_param,
> >  	.deinit		= vdec_h264_slice_deinit,
> >  };
> 
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
  2022-06-13 20:10   ` Nicolas Dufresne
  (?)
@ 2022-06-15 11:37     ` yunfei.dong
  -1 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:37 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Mon, 2022-06-13 at 16:10 -0400, Nicolas Dufresne wrote:
> > 

> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document
> > for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new
> HW, I
> would expect no less then what the numbers you'd get from running
> over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any
> oops along
> the way.
For we don't setup mt8186 fluster test environment. So not to run
fluster in mt8186. According to our plan, we will do fluster test for
every project begin from mt8188.

When I'm free, we continue to setup the fluster test environment for
mt8186.

Thanks,
Yunfei Dong
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  
> > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-15 11:37     ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:37 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Hi Nicolas,

Thanks for your comments.
On Mon, 2022-06-13 at 16:10 -0400, Nicolas Dufresne wrote:
> > 

> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document
> > for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new
> HW, I
> would expect no less then what the numbers you'd get from running
> over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any
> oops along
> the way.
For we don't setup mt8186 fluster test environment. So not to run
fluster in mt8186. According to our plan, we will do fluster test for
every project begin from mt8188.

When I'm free, we continue to setup the fluster test environment for
mt8186.

Thanks,
Yunfei Dong
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  
> > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-15 11:37     ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:37 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Mon, 2022-06-13 at 16:10 -0400, Nicolas Dufresne wrote:
> > 

> Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > Firstly, add mt8186 compatible and private data, then add document
> > for
> > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > architecture, need to add new interface for h264 hardware decoder.
> 
> Would be nice to take the habit of sharing fluster score for this new
> HW, I
> would expect no less then what the numbers you'd get from running
> over MT8195 or
> 92, remains nice to demonstrate that this was tested and document any
> oops along
> the way.
For we don't setup mt8186 fluster test environment. So not to run
fluster in mt8186. According to our plan, we will do fluster test for
every project begin from mt8188.

When I'm free, we continue to setup the fluster test environment for
mt8186.

Thanks,
Yunfei Dong
> > Patche 1 add mt8186 compatible and private data.
> > Patche 2 add mt8186 compatible document.
> > Patche 3 add h264 single core driver.
> > ---
> > This patch depends on "support for MT8192 decoder"[1]
> > 
> > [1]  
> > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> > ---
> > changed with v3:
> > - fix __iomem not reasonable, align share memory to dram.
> > changed with v2:
> > - fix sparse and smatch check fail for patch 3
> > changed with v1:
> > - rebase driver to the latest media_stage.
> > ---
> > Yunfei Dong (3):
> >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > for
> >     mt8186
> >   media: mediatek: vcodec: Support MT8186
> >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > 
> >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > +++++++++++++++++-
> >  5 files changed, 203 insertions(+), 2 deletions(-)
> > 
> 
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
  2022-06-14 17:46     ` Nicolas Dufresne
  (?)
@ 2022-06-15 11:43       ` yunfei.dong
  -1 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:43 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Tue, 2022-06-14 at 13:46 -0400, Nicolas Dufresne wrote:
> Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add
> > > document for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single
> > > core
> > > architecture, need to add new interface for h264 hardware
> > > decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this
> > new HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document
> > any oops along
> > the way.
> > > 
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> 
> I forgot earlier, but I suppose this will also depends on an scp.img
> firmware ?
> If so, any linux-firmware submission to link to ?
> 
For the tast/cts/gts test are coming to the end, after all ec patches
are merged, I will upstream scp.img

Best Regards,
Yunfei Dong
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-15 11:43       ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:43 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Hi Nicolas,

Thanks for your comments.
On Tue, 2022-06-14 at 13:46 -0400, Nicolas Dufresne wrote:
> Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add
> > > document for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single
> > > core
> > > architecture, need to add new interface for h264 hardware
> > > decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this
> > new HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document
> > any oops along
> > the way.
> > > 
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> 
> I forgot earlier, but I suppose this will also depends on an scp.img
> firmware ?
> If so, any linux-firmware submission to link to ?
> 
For the tast/cts/gts test are coming to the end, after all ec patches
are merged, I will upstream scp.img

Best Regards,
Yunfei Dong
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-15 11:43       ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-15 11:43 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Tue, 2022-06-14 at 13:46 -0400, Nicolas Dufresne wrote:
> Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add
> > > document for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single
> > > core
> > > architecture, need to add new interface for h264 hardware
> > > decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this
> > new HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document
> > any oops along
> > the way.
> > > 
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> 
> I forgot earlier, but I suppose this will also depends on an scp.img
> firmware ?
> If so, any linux-firmware submission to link to ?
> 
For the tast/cts/gts test are coming to the end, after all ec patches
are merged, I will upstream scp.img

Best Regards,
Yunfei Dong
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> 
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
  2022-06-15 11:33       ` yunfei.dong
  (?)
@ 2022-06-21 14:53         ` Nicolas Dufresne
  -1 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-21 14:53 UTC (permalink / raw)
  To: yunfei.dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le mercredi 15 juin 2022 à 19:33 +0800, yunfei.dong@mediatek.com a écrit :
> Hi Nicolas,
> 
> Thanks for your comments.
> On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Add h264 decode driver to support mt8186. For the architecture
> > > is single core, need to add new interface to decode.
> > > 
> > > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > > ---
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  1 file changed, 176 insertions(+), 1 deletion(-)
> > > 
> > > diff --git
> > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > index a96f203b5d54..1d9e753cf894 100644
> > > ---
> > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > +++
> > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> > >   * @vsi:		vsi used for lat
> > >   * @vsi_core:		vsi used for core
> > >   *
> > > + * @vsi_ctx:		Local VSI data for this decoding
> > > context
> > > + * @h264_slice_param:	the parameters that hardware use to
> > > decode
> > > + *
> > >   * @resolution_changed:resolution changed
> > >   * @realloc_mv_buf:	reallocate mv buffer
> > >   * @cap_num_planes:	number of capture queue plane
> > > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> > >  	struct vdec_h264_slice_vsi *vsi;
> > >  	struct vdec_h264_slice_vsi *vsi_core;
> > >  
> > > +	struct vdec_h264_slice_vsi vsi_ctx;
> > > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > > +
> > >  	unsigned int resolution_changed;
> > >  	unsigned int realloc_mv_buf;
> > >  	unsigned int cap_num_planes;
> > > @@ -208,6 +214,61 @@ static int
> > > vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst
> > > *i
> > >  	return 0;
> > >  }
> > >  
> > > +static int get_vdec_sig_decode_parameters(struct
> > > vdec_h264_slice_inst *inst)
> > > +{
> > > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > > +	const struct v4l2_ctrl_h264_sps *sps;
> > > +	const struct v4l2_ctrl_h264_pps *pps;
> > > +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> > > +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst-
> > > > h264_slice_param;
> > > +	struct v4l2_h264_reflist_builder reflist_builder;
> > > +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> > > +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> > > +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> > > +
> > > +	dec_params =
> > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > > +	if (IS_ERR(dec_params))
> > > +		return PTR_ERR(dec_params);
> > > +
> > > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_SPS);
> > > +	if (IS_ERR(sps))
> > > +		return PTR_ERR(sps);
> > > +
> > > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_PPS);
> > > +	if (IS_ERR(pps))
> > > +		return PTR_ERR(pps);
> > > +
> > > +	scaling_matrix =
> > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > > +	if (IS_ERR(scaling_matrix))
> > > +		return PTR_ERR(scaling_matrix);
> > > +
> > > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > > +
> > > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, 
> > > scaling_matrix);
> > > +
> > > +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params,
> > > dec_params, inst->dpb);
> > > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > > > decode_params,
> > > +				    slice_param->h264_dpb_info);
> > > +
> > > +	/* Build the reference lists */
> > > +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params,
> > > sps, inst->dpb);
> > > +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> > > +
> > > +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist,
> > > b1_reflist);
> > > +	/* Adapt the built lists to the firmware's expectations */
> > > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > > reflist_builder.num_valid);
> > > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > > reflist_builder.num_valid);
> > > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > > reflist_builder.num_valid);
> > > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> > 
> > This function looks very redundant across multiple variants, could
> > you try and
> > make a helper to reduce the duplication ?
> > 
> At first, I try to add one helper function for single core and lat
> decode.
> 
> But these two hardware have big differences, need to add many condition
> to separate. So just add new function for mt8186 single core
> architecture.

I still think you could have a very small helper that turns the reflist_builder
incantation (which are fully identical in all SoC), to be one line/call. It was
annoying when I recently had to update this driver for some internal API change.

> 
> Best Regards,
> Yunfei Dong
> > > +
> > > +	return 0;
> > > +}
> > > +
> > >  static void vdec_h264_slice_fill_decode_reflist(struct
> > > vdec_h264_slice_inst *inst,
> > >  						struct
> > > vdec_h264_slice_lat_dec_param *slice_param,
> > >  						struct
> > > vdec_h264_slice_share_info *share_info)
> > > @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void
> > > *h_vdec, struct mtk_vcodec_mem *bs,
> > >  	return err;
> > >  }
> > >  
> > > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > > mtk_vcodec_mem *bs,
> > > +					 struct vdec_fb *unused, bool
> > > *res_chg)
> > > +{
> > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > > +	struct vdec_fb *fb;
> > > +	unsigned char *buf;
> > > +	unsigned int data[2], i;
> > > +	u64 y_fb_dma, c_fb_dma;
> > > +	struct mtk_vcodec_mem *mem;
> > > +	int err, nal_start_idx;
> > > +
> > > +	/* bs NULL means flush decoder */
> > > +	if (!bs)
> > > +		return vpu_dec_reset(vpu);
> > > +
> > > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> > > +	src_buf_info = container_of(bs, struct mtk_video_dec_buf,
> > > bs_buffer);
> > > +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf,
> > > frame_buffer);
> > > +
> > > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> > > +			 inst->ctx->decoded_frame_cnt, y_fb_dma,
> > > c_fb_dma);
> > > +
> > > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > > +
> > > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > > +				   &dst_buf_info->m2m_buf.vb, true);
> > > +	err = get_vdec_sig_decode_parameters(inst);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	buf = (unsigned char *)bs->va;
> > > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> > > +	if (nal_start_idx < 0) {
> > > +		err = -EINVAL;
> > > +		goto err_free_fb_out;
> > > +	}
> > > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > > +
> > > +	*res_chg = inst->resolution_changed;
> > > +	if (inst->resolution_changed) {
> > > +		mtk_vcodec_debug(inst, "- resolution changed -");
> > > +		if (inst->realloc_mv_buf) {
> > > +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > > > ctx->picinfo);
> > > +			inst->realloc_mv_buf = false;
> > > +			if (err)
> > > +				goto err_free_fb_out;
> > > +		}
> > > +		inst->resolution_changed = false;
> > > +
> > > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > > +			mem = &inst->mv_buf[i];
> > > +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> > > +		}
> > > +	}
> > > +
> > > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> > > +	err = vpu_dec_start(vpu, data, 2);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	/* wait decoder done interrupt */
> > > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > > MTK_INST_IRQ_RECEIVED,
> > > +					   WAIT_INTR_TIMEOUT_MS,
> > > MTK_VDEC_CORE);
> > > +	if (err)
> > > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > > +			       inst->ctx->decoded_frame_cnt);
> > > +
> > > +	inst->vsi->dec.timeout = !!err;
> > > +	err = vpu_dec_end(vpu);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> > > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x
> > > 0x%x 0x%x 0x%x",
> > > +			 inst->ctx->decoded_frame_cnt,
> > > +			 inst->vsi_ctx.dec.crc[0], inst-
> > > > vsi_ctx.dec.crc[1],
> > > +			 inst->vsi_ctx.dec.crc[2], inst-
> > > > vsi_ctx.dec.crc[3],
> > > +			 inst->vsi_ctx.dec.crc[4], inst-
> > > > vsi_ctx.dec.crc[5],
> > > +			 inst->vsi_ctx.dec.crc[6], inst-
> > > > vsi_ctx.dec.crc[7]);
> > > +
> > > +	inst->ctx->decoded_frame_cnt++;
> > > +	return 0;
> > > +
> > > +err_free_fb_out:
> > > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > > +		       inst->ctx->decoded_frame_cnt, err);
> > > +	return err;
> > > +}
> > > +
> > > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > > mtk_vcodec_mem *bs,
> > > +				  struct vdec_fb *unused, bool
> > > *res_chg)
> > > +{
> > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > +	int ret;
> > > +
> > > +	if (!h_vdec)
> > > +		return -EINVAL;
> > > +
> > > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > > MTK_VDEC_PURE_SINGLE_CORE)
> > > +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused,
> > > res_chg);
> > > +	else
> > > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
> > > res_chg);
> > > +
> > > +	return ret;
> > > +}
> > > +
> > >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > > vdec_get_param_type type,
> > >  				     void *out)
> > >  {
> > > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > > *h_vdec, enum vdec_get_param_type type
> > >  
> > >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> > >  	.init		= vdec_h264_slice_init,
> > > -	.decode		= vdec_h264_slice_lat_decode,
> > > +	.decode		= vdec_h264_slice_decode,
> > >  	.get_param	= vdec_h264_slice_get_param,
> > >  	.deinit		= vdec_h264_slice_deinit,
> > >  };
> > 
> > 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-21 14:53         ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-21 14:53 UTC (permalink / raw)
  To: yunfei.dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Le mercredi 15 juin 2022 à 19:33 +0800, yunfei.dong@mediatek.com a écrit :
> Hi Nicolas,
> 
> Thanks for your comments.
> On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Add h264 decode driver to support mt8186. For the architecture
> > > is single core, need to add new interface to decode.
> > > 
> > > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > > ---
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  1 file changed, 176 insertions(+), 1 deletion(-)
> > > 
> > > diff --git
> > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > index a96f203b5d54..1d9e753cf894 100644
> > > ---
> > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > +++
> > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> > >   * @vsi:		vsi used for lat
> > >   * @vsi_core:		vsi used for core
> > >   *
> > > + * @vsi_ctx:		Local VSI data for this decoding
> > > context
> > > + * @h264_slice_param:	the parameters that hardware use to
> > > decode
> > > + *
> > >   * @resolution_changed:resolution changed
> > >   * @realloc_mv_buf:	reallocate mv buffer
> > >   * @cap_num_planes:	number of capture queue plane
> > > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> > >  	struct vdec_h264_slice_vsi *vsi;
> > >  	struct vdec_h264_slice_vsi *vsi_core;
> > >  
> > > +	struct vdec_h264_slice_vsi vsi_ctx;
> > > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > > +
> > >  	unsigned int resolution_changed;
> > >  	unsigned int realloc_mv_buf;
> > >  	unsigned int cap_num_planes;
> > > @@ -208,6 +214,61 @@ static int
> > > vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst
> > > *i
> > >  	return 0;
> > >  }
> > >  
> > > +static int get_vdec_sig_decode_parameters(struct
> > > vdec_h264_slice_inst *inst)
> > > +{
> > > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > > +	const struct v4l2_ctrl_h264_sps *sps;
> > > +	const struct v4l2_ctrl_h264_pps *pps;
> > > +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> > > +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst-
> > > > h264_slice_param;
> > > +	struct v4l2_h264_reflist_builder reflist_builder;
> > > +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> > > +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> > > +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> > > +
> > > +	dec_params =
> > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > > +	if (IS_ERR(dec_params))
> > > +		return PTR_ERR(dec_params);
> > > +
> > > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_SPS);
> > > +	if (IS_ERR(sps))
> > > +		return PTR_ERR(sps);
> > > +
> > > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_PPS);
> > > +	if (IS_ERR(pps))
> > > +		return PTR_ERR(pps);
> > > +
> > > +	scaling_matrix =
> > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > > +	if (IS_ERR(scaling_matrix))
> > > +		return PTR_ERR(scaling_matrix);
> > > +
> > > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > > +
> > > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, 
> > > scaling_matrix);
> > > +
> > > +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params,
> > > dec_params, inst->dpb);
> > > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > > > decode_params,
> > > +				    slice_param->h264_dpb_info);
> > > +
> > > +	/* Build the reference lists */
> > > +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params,
> > > sps, inst->dpb);
> > > +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> > > +
> > > +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist,
> > > b1_reflist);
> > > +	/* Adapt the built lists to the firmware's expectations */
> > > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > > reflist_builder.num_valid);
> > > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > > reflist_builder.num_valid);
> > > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > > reflist_builder.num_valid);
> > > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> > 
> > This function looks very redundant across multiple variants, could
> > you try and
> > make a helper to reduce the duplication ?
> > 
> At first, I try to add one helper function for single core and lat
> decode.
> 
> But these two hardware have big differences, need to add many condition
> to separate. So just add new function for mt8186 single core
> architecture.

I still think you could have a very small helper that turns the reflist_builder
incantation (which are fully identical in all SoC), to be one line/call. It was
annoying when I recently had to update this driver for some internal API change.

> 
> Best Regards,
> Yunfei Dong
> > > +
> > > +	return 0;
> > > +}
> > > +
> > >  static void vdec_h264_slice_fill_decode_reflist(struct
> > > vdec_h264_slice_inst *inst,
> > >  						struct
> > > vdec_h264_slice_lat_dec_param *slice_param,
> > >  						struct
> > > vdec_h264_slice_share_info *share_info)
> > > @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void
> > > *h_vdec, struct mtk_vcodec_mem *bs,
> > >  	return err;
> > >  }
> > >  
> > > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > > mtk_vcodec_mem *bs,
> > > +					 struct vdec_fb *unused, bool
> > > *res_chg)
> > > +{
> > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > > +	struct vdec_fb *fb;
> > > +	unsigned char *buf;
> > > +	unsigned int data[2], i;
> > > +	u64 y_fb_dma, c_fb_dma;
> > > +	struct mtk_vcodec_mem *mem;
> > > +	int err, nal_start_idx;
> > > +
> > > +	/* bs NULL means flush decoder */
> > > +	if (!bs)
> > > +		return vpu_dec_reset(vpu);
> > > +
> > > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> > > +	src_buf_info = container_of(bs, struct mtk_video_dec_buf,
> > > bs_buffer);
> > > +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf,
> > > frame_buffer);
> > > +
> > > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> > > +			 inst->ctx->decoded_frame_cnt, y_fb_dma,
> > > c_fb_dma);
> > > +
> > > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > > +
> > > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > > +				   &dst_buf_info->m2m_buf.vb, true);
> > > +	err = get_vdec_sig_decode_parameters(inst);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	buf = (unsigned char *)bs->va;
> > > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> > > +	if (nal_start_idx < 0) {
> > > +		err = -EINVAL;
> > > +		goto err_free_fb_out;
> > > +	}
> > > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > > +
> > > +	*res_chg = inst->resolution_changed;
> > > +	if (inst->resolution_changed) {
> > > +		mtk_vcodec_debug(inst, "- resolution changed -");
> > > +		if (inst->realloc_mv_buf) {
> > > +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > > > ctx->picinfo);
> > > +			inst->realloc_mv_buf = false;
> > > +			if (err)
> > > +				goto err_free_fb_out;
> > > +		}
> > > +		inst->resolution_changed = false;
> > > +
> > > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > > +			mem = &inst->mv_buf[i];
> > > +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> > > +		}
> > > +	}
> > > +
> > > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> > > +	err = vpu_dec_start(vpu, data, 2);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	/* wait decoder done interrupt */
> > > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > > MTK_INST_IRQ_RECEIVED,
> > > +					   WAIT_INTR_TIMEOUT_MS,
> > > MTK_VDEC_CORE);
> > > +	if (err)
> > > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > > +			       inst->ctx->decoded_frame_cnt);
> > > +
> > > +	inst->vsi->dec.timeout = !!err;
> > > +	err = vpu_dec_end(vpu);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> > > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x
> > > 0x%x 0x%x 0x%x",
> > > +			 inst->ctx->decoded_frame_cnt,
> > > +			 inst->vsi_ctx.dec.crc[0], inst-
> > > > vsi_ctx.dec.crc[1],
> > > +			 inst->vsi_ctx.dec.crc[2], inst-
> > > > vsi_ctx.dec.crc[3],
> > > +			 inst->vsi_ctx.dec.crc[4], inst-
> > > > vsi_ctx.dec.crc[5],
> > > +			 inst->vsi_ctx.dec.crc[6], inst-
> > > > vsi_ctx.dec.crc[7]);
> > > +
> > > +	inst->ctx->decoded_frame_cnt++;
> > > +	return 0;
> > > +
> > > +err_free_fb_out:
> > > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > > +		       inst->ctx->decoded_frame_cnt, err);
> > > +	return err;
> > > +}
> > > +
> > > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > > mtk_vcodec_mem *bs,
> > > +				  struct vdec_fb *unused, bool
> > > *res_chg)
> > > +{
> > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > +	int ret;
> > > +
> > > +	if (!h_vdec)
> > > +		return -EINVAL;
> > > +
> > > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > > MTK_VDEC_PURE_SINGLE_CORE)
> > > +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused,
> > > res_chg);
> > > +	else
> > > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
> > > res_chg);
> > > +
> > > +	return ret;
> > > +}
> > > +
> > >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > > vdec_get_param_type type,
> > >  				     void *out)
> > >  {
> > > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > > *h_vdec, enum vdec_get_param_type type
> > >  
> > >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> > >  	.init		= vdec_h264_slice_init,
> > > -	.decode		= vdec_h264_slice_lat_decode,
> > > +	.decode		= vdec_h264_slice_decode,
> > >  	.get_param	= vdec_h264_slice_get_param,
> > >  	.deinit		= vdec_h264_slice_deinit,
> > >  };
> > 
> > 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-21 14:53         ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-21 14:53 UTC (permalink / raw)
  To: yunfei.dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le mercredi 15 juin 2022 à 19:33 +0800, yunfei.dong@mediatek.com a écrit :
> Hi Nicolas,
> 
> Thanks for your comments.
> On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Add h264 decode driver to support mt8186. For the architecture
> > > is single core, need to add new interface to decode.
> > > 
> > > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > > ---
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  1 file changed, 176 insertions(+), 1 deletion(-)
> > > 
> > > diff --git
> > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > index a96f203b5d54..1d9e753cf894 100644
> > > ---
> > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > +++
> > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_i
> > > f.c
> > > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> > >   * @vsi:		vsi used for lat
> > >   * @vsi_core:		vsi used for core
> > >   *
> > > + * @vsi_ctx:		Local VSI data for this decoding
> > > context
> > > + * @h264_slice_param:	the parameters that hardware use to
> > > decode
> > > + *
> > >   * @resolution_changed:resolution changed
> > >   * @realloc_mv_buf:	reallocate mv buffer
> > >   * @cap_num_planes:	number of capture queue plane
> > > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> > >  	struct vdec_h264_slice_vsi *vsi;
> > >  	struct vdec_h264_slice_vsi *vsi_core;
> > >  
> > > +	struct vdec_h264_slice_vsi vsi_ctx;
> > > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > > +
> > >  	unsigned int resolution_changed;
> > >  	unsigned int realloc_mv_buf;
> > >  	unsigned int cap_num_planes;
> > > @@ -208,6 +214,61 @@ static int
> > > vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst
> > > *i
> > >  	return 0;
> > >  }
> > >  
> > > +static int get_vdec_sig_decode_parameters(struct
> > > vdec_h264_slice_inst *inst)
> > > +{
> > > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > > +	const struct v4l2_ctrl_h264_sps *sps;
> > > +	const struct v4l2_ctrl_h264_pps *pps;
> > > +	const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
> > > +	struct vdec_h264_slice_lat_dec_param *slice_param = &inst-
> > > > h264_slice_param;
> > > +	struct v4l2_h264_reflist_builder reflist_builder;
> > > +	u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;
> > > +	u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;
> > > +	u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1;
> > > +
> > > +	dec_params =
> > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > > +	if (IS_ERR(dec_params))
> > > +		return PTR_ERR(dec_params);
> > > +
> > > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_SPS);
> > > +	if (IS_ERR(sps))
> > > +		return PTR_ERR(sps);
> > > +
> > > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_PPS);
> > > +	if (IS_ERR(pps))
> > > +		return PTR_ERR(pps);
> > > +
> > > +	scaling_matrix =
> > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > > +	if (IS_ERR(scaling_matrix))
> > > +		return PTR_ERR(scaling_matrix);
> > > +
> > > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > > +
> > > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param->scaling_matrix, 
> > > scaling_matrix);
> > > +
> > > +	mtk_vdec_h264_copy_decode_params(&slice_param->decode_params,
> > > dec_params, inst->dpb);
> > > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > > > decode_params,
> > > +				    slice_param->h264_dpb_info);
> > > +
> > > +	/* Build the reference lists */
> > > +	v4l2_h264_init_reflist_builder(&reflist_builder, dec_params,
> > > sps, inst->dpb);
> > > +	v4l2_h264_build_p_ref_list(&reflist_builder, p0_reflist);
> > > +
> > > +	v4l2_h264_build_b_ref_lists(&reflist_builder, b0_reflist,
> > > b1_reflist);
> > > +	/* Adapt the built lists to the firmware's expectations */
> > > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > > reflist_builder.num_valid);
> > > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > > reflist_builder.num_valid);
> > > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > > reflist_builder.num_valid);
> > > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> > 
> > This function looks very redundant across multiple variants, could
> > you try and
> > make a helper to reduce the duplication ?
> > 
> At first, I try to add one helper function for single core and lat
> decode.
> 
> But these two hardware have big differences, need to add many condition
> to separate. So just add new function for mt8186 single core
> architecture.

I still think you could have a very small helper that turns the reflist_builder
incantation (which are fully identical in all SoC), to be one line/call. It was
annoying when I recently had to update this driver for some internal API change.

> 
> Best Regards,
> Yunfei Dong
> > > +
> > > +	return 0;
> > > +}
> > > +
> > >  static void vdec_h264_slice_fill_decode_reflist(struct
> > > vdec_h264_slice_inst *inst,
> > >  						struct
> > > vdec_h264_slice_lat_dec_param *slice_param,
> > >  						struct
> > > vdec_h264_slice_share_info *share_info)
> > > @@ -596,6 +657,120 @@ static int vdec_h264_slice_lat_decode(void
> > > *h_vdec, struct mtk_vcodec_mem *bs,
> > >  	return err;
> > >  }
> > >  
> > > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > > mtk_vcodec_mem *bs,
> > > +					 struct vdec_fb *unused, bool
> > > *res_chg)
> > > +{
> > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > > +	struct vdec_fb *fb;
> > > +	unsigned char *buf;
> > > +	unsigned int data[2], i;
> > > +	u64 y_fb_dma, c_fb_dma;
> > > +	struct mtk_vcodec_mem *mem;
> > > +	int err, nal_start_idx;
> > > +
> > > +	/* bs NULL means flush decoder */
> > > +	if (!bs)
> > > +		return vpu_dec_reset(vpu);
> > > +
> > > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst->ctx);
> > > +	src_buf_info = container_of(bs, struct mtk_video_dec_buf,
> > > bs_buffer);
> > > +	dst_buf_info = container_of(fb, struct mtk_video_dec_buf,
> > > frame_buffer);
> > > +
> > > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx c_dma=%llx",
> > > +			 inst->ctx->decoded_frame_cnt, y_fb_dma,
> > > c_fb_dma);
> > > +
> > > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > > +
> > > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > > +				   &dst_buf_info->m2m_buf.vb, true);
> > > +	err = get_vdec_sig_decode_parameters(inst);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	buf = (unsigned char *)bs->va;
> > > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size);
> > > +	if (nal_start_idx < 0) {
> > > +		err = -EINVAL;
> > > +		goto err_free_fb_out;
> > > +	}
> > > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > > +
> > > +	*res_chg = inst->resolution_changed;
> > > +	if (inst->resolution_changed) {
> > > +		mtk_vcodec_debug(inst, "- resolution changed -");
> > > +		if (inst->realloc_mv_buf) {
> > > +			err = vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > > > ctx->picinfo);
> > > +			inst->realloc_mv_buf = false;
> > > +			if (err)
> > > +				goto err_free_fb_out;
> > > +		}
> > > +		inst->resolution_changed = false;
> > > +
> > > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > > +			mem = &inst->mv_buf[i];
> > > +			inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
> > > +		}
> > > +	}
> > > +
> > > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst->vsi_ctx));
> > > +	err = vpu_dec_start(vpu, data, 2);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	/* wait decoder done interrupt */
> > > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > > MTK_INST_IRQ_RECEIVED,
> > > +					   WAIT_INTR_TIMEOUT_MS,
> > > MTK_VDEC_CORE);
> > > +	if (err)
> > > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > > +			       inst->ctx->decoded_frame_cnt);
> > > +
> > > +	inst->vsi->dec.timeout = !!err;
> > > +	err = vpu_dec_end(vpu);
> > > +	if (err)
> > > +		goto err_free_fb_out;
> > > +
> > > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
> > > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x
> > > 0x%x 0x%x 0x%x",
> > > +			 inst->ctx->decoded_frame_cnt,
> > > +			 inst->vsi_ctx.dec.crc[0], inst-
> > > > vsi_ctx.dec.crc[1],
> > > +			 inst->vsi_ctx.dec.crc[2], inst-
> > > > vsi_ctx.dec.crc[3],
> > > +			 inst->vsi_ctx.dec.crc[4], inst-
> > > > vsi_ctx.dec.crc[5],
> > > +			 inst->vsi_ctx.dec.crc[6], inst-
> > > > vsi_ctx.dec.crc[7]);
> > > +
> > > +	inst->ctx->decoded_frame_cnt++;
> > > +	return 0;
> > > +
> > > +err_free_fb_out:
> > > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > > +		       inst->ctx->decoded_frame_cnt, err);
> > > +	return err;
> > > +}
> > > +
> > > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > > mtk_vcodec_mem *bs,
> > > +				  struct vdec_fb *unused, bool
> > > *res_chg)
> > > +{
> > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > +	int ret;
> > > +
> > > +	if (!h_vdec)
> > > +		return -EINVAL;
> > > +
> > > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > > MTK_VDEC_PURE_SINGLE_CORE)
> > > +		ret = vdec_h264_slice_single_decode(h_vdec, bs, unused,
> > > res_chg);
> > > +	else
> > > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs, unused,
> > > res_chg);
> > > +
> > > +	return ret;
> > > +}
> > > +
> > >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > > vdec_get_param_type type,
> > >  				     void *out)
> > >  {
> > > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > > *h_vdec, enum vdec_get_param_type type
> > >  
> > >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> > >  	.init		= vdec_h264_slice_init,
> > > -	.decode		= vdec_h264_slice_lat_decode,
> > > +	.decode		= vdec_h264_slice_decode,
> > >  	.get_param	= vdec_h264_slice_get_param,
> > >  	.deinit		= vdec_h264_slice_deinit,
> > >  };
> > 
> > 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
  2022-06-15 11:37     ` yunfei.dong
  (?)
@ 2022-06-21 14:56       ` Nicolas Dufresne
  -1 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-21 14:56 UTC (permalink / raw)
  To: yunfei.dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le mercredi 15 juin 2022 à 19:37 +0800, yunfei.dong@mediatek.com a écrit :
> Hi Nicolas,
> 
> Thanks for your comments.
> On Mon, 2022-06-13 at 16:10 -0400, Nicolas Dufresne wrote:
> > > 
> 
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add document
> > > for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > > architecture, need to add new interface for h264 hardware decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this new
> > HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document any
> > oops along
> > the way.
> For we don't setup mt8186 fluster test environment. So not to run
> fluster in mt8186. According to our plan, we will do fluster test for
> every project begin from mt8188.
> 
> When I'm free, we continue to setup the fluster test environment for
> mt8186.

I may be able to help here then if needed. Just let me know. Meanwhile, it seems
a bit early to consider merging these patches as they seems to lack the level of
testing we'd normally expect for non-staging driver changes.

regards,
Nicolas

> 
> Thanks,
> Yunfei Dong
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> > 
> > 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-21 14:56       ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-21 14:56 UTC (permalink / raw)
  To: yunfei.dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Le mercredi 15 juin 2022 à 19:37 +0800, yunfei.dong@mediatek.com a écrit :
> Hi Nicolas,
> 
> Thanks for your comments.
> On Mon, 2022-06-13 at 16:10 -0400, Nicolas Dufresne wrote:
> > > 
> 
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add document
> > > for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > > architecture, need to add new interface for h264 hardware decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this new
> > HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document any
> > oops along
> > the way.
> For we don't setup mt8186 fluster test environment. So not to run
> fluster in mt8186. According to our plan, we will do fluster test for
> every project begin from mt8188.
> 
> When I'm free, we continue to setup the fluster test environment for
> mt8186.

I may be able to help here then if needed. Just let me know. Meanwhile, it seems
a bit early to consider merging these patches as they seems to lack the level of
testing we'd normally expect for non-staging driver changes.

regards,
Nicolas

> 
> Thanks,
> Yunfei Dong
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> > 
> > 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-21 14:56       ` Nicolas Dufresne
  0 siblings, 0 replies; 49+ messages in thread
From: Nicolas Dufresne @ 2022-06-21 14:56 UTC (permalink / raw)
  To: yunfei.dong, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Le mercredi 15 juin 2022 à 19:37 +0800, yunfei.dong@mediatek.com a écrit :
> Hi Nicolas,
> 
> Thanks for your comments.
> On Mon, 2022-06-13 at 16:10 -0400, Nicolas Dufresne wrote:
> > > 
> 
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add document
> > > for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single core
> > > architecture, need to add new interface for h264 hardware decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this new
> > HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document any
> > oops along
> > the way.
> For we don't setup mt8186 fluster test environment. So not to run
> fluster in mt8186. According to our plan, we will do fluster test for
> every project begin from mt8188.
> 
> When I'm free, we continue to setup the fluster test environment for
> mt8186.

I may be able to help here then if needed. Just let me know. Meanwhile, it seems
a bit early to consider merging these patches as they seems to lack the level of
testing we'd normally expect for non-staging driver changes.

regards,
Nicolas

> 
> Thanks,
> Yunfei Dong
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> > 
> > 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
  2022-06-14 17:46     ` Nicolas Dufresne
  (?)
@ 2022-06-22  1:42       ` yunfei.dong
  -1 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-22  1:42 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Tue, 2022-06-14 at 13:46 -0400, Nicolas Dufresne wrote:
> Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add
> > > document for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single
> > > core
> > > architecture, need to add new interface for h264 hardware
> > > decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this
> > new HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document
> > any oops along
> > the way.
> > > 
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> 
> I forgot earlier, but I suppose this will also depends on an scp.img
> firmware ?
> If so, any linux-firmware submission to link to ?
> 
Yes, need scp.img to test mt8186.
But not all patches are merged now, we are testing the driver, will
send scp.img in the middle of july.

Best Regards,
Yunfei Dong
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-22  1:42       ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-22  1:42 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Hi Nicolas,

Thanks for your comments.
On Tue, 2022-06-14 at 13:46 -0400, Nicolas Dufresne wrote:
> Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add
> > > document for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single
> > > core
> > > architecture, need to add new interface for h264 hardware
> > > decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this
> > new HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document
> > any oops along
> > the way.
> > > 
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> 
> I forgot earlier, but I suppose this will also depends on an scp.img
> firmware ?
> If so, any linux-firmware submission to link to ?
> 
Yes, need scp.img to test mt8186.
But not all patches are merged now, we are testing the driver, will
send scp.img in the middle of july.

Best Regards,
Yunfei Dong
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 0/3] add h264 decoder driver for mt8186
@ 2022-06-22  1:42       ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-22  1:42 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your comments.
On Tue, 2022-06-14 at 13:46 -0400, Nicolas Dufresne wrote:
> Le lundi 13 juin 2022 à 16:10 -0400, Nicolas Dufresne a écrit :
> > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > Firstly, add mt8186 compatible and private data, then add
> > > document for
> > > compatible "mediatek,mt8186-vcodec-dec". For mt8186 is single
> > > core
> > > architecture, need to add new interface for h264 hardware
> > > decoder.
> > 
> > Would be nice to take the habit of sharing fluster score for this
> > new HW, I
> > would expect no less then what the numbers you'd get from running
> > over MT8195 or
> > 92, remains nice to demonstrate that this was tested and document
> > any oops along
> > the way.
> > > 
> > > Patche 1 add mt8186 compatible and private data.
> > > Patche 2 add mt8186 compatible document.
> > > Patche 3 add h264 single core driver.
> > > ---
> > > This patch depends on "support for MT8192 decoder"[1]
> > > 
> > > [1]  
> > > https://patchwork.kernel.org/project/linux-mediatek/cover/20220512021950.29087-1-yunfei.dong@mediatek.com/
> 
> I forgot earlier, but I suppose this will also depends on an scp.img
> firmware ?
> If so, any linux-firmware submission to link to ?
> 
Yes, need scp.img to test mt8186.
But not all patches are merged now, we are testing the driver, will
send scp.img in the middle of july.

Best Regards,
Yunfei Dong
> > > ---
> > > changed with v3:
> > > - fix __iomem not reasonable, align share memory to dram.
> > > changed with v2:
> > > - fix sparse and smatch check fail for patch 3
> > > changed with v1:
> > > - rebase driver to the latest media_stage.
> > > ---
> > > Yunfei Dong (3):
> > >   dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings
> > > for
> > >     mt8186
> > >   media: mediatek: vcodec: Support MT8186
> > >   media: mediatek: vcodec: add h264 decoder driver for mt8186
> > > 
> > >  .../media/mediatek,vcodec-subdev-decoder.yaml |   4 +-
> > >  .../platform/mediatek/vcodec/mtk_vcodec_dec.h |   1 +
> > >  .../mediatek/vcodec/mtk_vcodec_dec_drv.c      |   4 +
> > >  .../vcodec/mtk_vcodec_dec_stateless.c         |  19 ++
> > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > +++++++++++++++++-
> > >  5 files changed, 203 insertions(+), 2 deletions(-)
> > > 
> 
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
  2022-06-21 14:53         ` Nicolas Dufresne
  (?)
@ 2022-06-22  1:46           ` yunfei.dong
  -1 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-22  1:46 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your suggestion.
On Tue, 2022-06-21 at 10:53 -0400, Nicolas Dufresne wrote:
> > 
> Le mercredi 15 juin 2022 à 19:33 +0800, yunfei.dong@mediatek.com a
> écrit :
> > Hi Nicolas,
> > 
> > Thanks for your comments.
> > On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> > > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > > Add h264 decode driver to support mt8186. For the architecture
> > > > is single core, need to add new interface to decode.
> > > > 
> > > > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > > > ---
> > > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > > +++++++++++++++++-
> > > >  1 file changed, 176 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git
> > > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > index a96f203b5d54..1d9e753cf894 100644
> > > > ---
> > > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > +++
> > > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> > > >   * @vsi:		vsi used for lat
> > > >   * @vsi_core:		vsi used for core
> > > >   *
> > > > + * @vsi_ctx:		Local VSI data for this decoding
> > > > context
> > > > + * @h264_slice_param:	the parameters that hardware use to
> > > > decode
> > > > + *
> > > >   * @resolution_changed:resolution changed
> > > >   * @realloc_mv_buf:	reallocate mv buffer
> > > >   * @cap_num_planes:	number of capture queue plane
> > > > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> > > >  	struct vdec_h264_slice_vsi *vsi;
> > > >  	struct vdec_h264_slice_vsi *vsi_core;
> > > >  
> > > > +	struct vdec_h264_slice_vsi vsi_ctx;
> > > > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > > > +
> > > >  	unsigned int resolution_changed;
> > > >  	unsigned int realloc_mv_buf;
> > > >  	unsigned int cap_num_planes;
> > > > @@ -208,6 +214,61 @@ static int
> > > > vdec_h264_slice_fill_decode_parameters(struct
> > > > vdec_h264_slice_inst
> > > > *i
> > > >  	return 0;
> > > >  }
> > > >  
> > > > +static int get_vdec_sig_decode_parameters(struct
> > > > vdec_h264_slice_inst *inst)
> > > > +{
> > > > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > > > +	const struct v4l2_ctrl_h264_sps *sps;
> > > > +	const struct v4l2_ctrl_h264_pps *pps;
> > > > +	const struct v4l2_ctrl_h264_scaling_matrix
> > > > *scaling_matrix;
> > > > +	struct vdec_h264_slice_lat_dec_param *slice_param =
> > > > &inst-
> > > > > h264_slice_param;
> > > > 
> > > > +	struct v4l2_h264_reflist_builder reflist_builder;
> > > > +	u8 *p0_reflist = slice_param-
> > > > >decode_params.ref_pic_list_p0;
> > > > +	u8 *b0_reflist = slice_param-
> > > > >decode_params.ref_pic_list_b0;
> > > > +	u8 *b1_reflist = slice_param-
> > > > >decode_params.ref_pic_list_b1;
> > > > +
> > > > +	dec_params =
> > > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > > > +	if (IS_ERR(dec_params))
> > > > +		return PTR_ERR(dec_params);
> > > > +
> > > > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_SPS);
> > > > +	if (IS_ERR(sps))
> > > > +		return PTR_ERR(sps);
> > > > +
> > > > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_PPS);
> > > > +	if (IS_ERR(pps))
> > > > +		return PTR_ERR(pps);
> > > > +
> > > > +	scaling_matrix =
> > > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > > > +	if (IS_ERR(scaling_matrix))
> > > > +		return PTR_ERR(scaling_matrix);
> > > > +
> > > > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > > > +
> > > > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > > > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > > > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param-
> > > > >scaling_matrix, 
> > > > scaling_matrix);
> > > > +
> > > > +	mtk_vdec_h264_copy_decode_params(&slice_param-
> > > > >decode_params,
> > > > dec_params, inst->dpb);
> > > > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > > > > decode_params,
> > > > 
> > > > +				    slice_param-
> > > > >h264_dpb_info);
> > > > +
> > > > +	/* Build the reference lists */
> > > > +	v4l2_h264_init_reflist_builder(&reflist_builder,
> > > > dec_params,
> > > > sps, inst->dpb);
> > > > +	v4l2_h264_build_p_ref_list(&reflist_builder,
> > > > p0_reflist);
> > > > +
> > > > +	v4l2_h264_build_b_ref_lists(&reflist_builder,
> > > > b0_reflist,
> > > > b1_reflist);
> > > > +	/* Adapt the built lists to the firmware's expectations
> > > > */
> > > > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > > > reflist_builder.num_valid);
> > > > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > > > reflist_builder.num_valid);
> > > > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > > > reflist_builder.num_valid);
> > > > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > > > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> > > 
> > > This function looks very redundant across multiple variants,
> > > could
> > > you try and
> > > make a helper to reduce the duplication ?
> > > 
> > 
> > At first, I try to add one helper function for single core and lat
> > decode.
> > 
> > But these two hardware have big differences, need to add many
> > condition
> > to separate. So just add new function for mt8186 single core
> > architecture.
> 
> I still think you could have a very small helper that turns the
> reflist_builder
> incantation (which are fully identical in all SoC), to be one
> line/call. It was
> annoying when I recently had to update this driver for some internal
> API change.
> 
I will refactor the driver flow and add one simple helper function.

Best Regards,
Yunfei Dong
> > Best Regards,
> > Yunfei Dong
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > >  static void vdec_h264_slice_fill_decode_reflist(struct
> > > > vdec_h264_slice_inst *inst,
> > > >  						struct
> > > > vdec_h264_slice_lat_dec_param *slice_param,
> > > >  						struct
> > > > vdec_h264_slice_share_info *share_info)
> > > > @@ -596,6 +657,120 @@ static int
> > > > vdec_h264_slice_lat_decode(void
> > > > *h_vdec, struct mtk_vcodec_mem *bs,
> > > >  	return err;
> > > >  }
> > > >  
> > > > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > > > mtk_vcodec_mem *bs,
> > > > +					 struct vdec_fb
> > > > *unused, bool
> > > > *res_chg)
> > > > +{
> > > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > > > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > > > +	struct vdec_fb *fb;
> > > > +	unsigned char *buf;
> > > > +	unsigned int data[2], i;
> > > > +	u64 y_fb_dma, c_fb_dma;
> > > > +	struct mtk_vcodec_mem *mem;
> > > > +	int err, nal_start_idx;
> > > > +
> > > > +	/* bs NULL means flush decoder */
> > > > +	if (!bs)
> > > > +		return vpu_dec_reset(vpu);
> > > > +
> > > > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst-
> > > > >ctx);
> > > > +	src_buf_info = container_of(bs, struct
> > > > mtk_video_dec_buf,
> > > > bs_buffer);
> > > > +	dst_buf_info = container_of(fb, struct
> > > > mtk_video_dec_buf,
> > > > frame_buffer);
> > > > +
> > > > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > > > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > > > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx
> > > > c_dma=%llx",
> > > > +			 inst->ctx->decoded_frame_cnt,
> > > > y_fb_dma,
> > > > c_fb_dma);
> > > > +
> > > > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > > > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > > > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > > > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > > > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > > > +
> > > > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > > > +				   &dst_buf_info->m2m_buf.vb,
> > > > true);
> > > > +	err = get_vdec_sig_decode_parameters(inst);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	buf = (unsigned char *)bs->va;
> > > > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs-
> > > > >size);
> > > > +	if (nal_start_idx < 0) {
> > > > +		err = -EINVAL;
> > > > +		goto err_free_fb_out;
> > > > +	}
> > > > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > > > +
> > > > +	*res_chg = inst->resolution_changed;
> > > > +	if (inst->resolution_changed) {
> > > > +		mtk_vcodec_debug(inst, "- resolution changed
> > > > -");
> > > > +		if (inst->realloc_mv_buf) {
> > > > +			err =
> > > > vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > > > > ctx->picinfo);
> > > > 
> > > > +			inst->realloc_mv_buf = false;
> > > > +			if (err)
> > > > +				goto err_free_fb_out;
> > > > +		}
> > > > +		inst->resolution_changed = false;
> > > > +
> > > > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > > > +			mem = &inst->mv_buf[i];
> > > > +			inst->vsi_ctx.mv_buf_dma[i] = mem-
> > > > >dma_addr;
> > > > +		}
> > > > +	}
> > > > +
> > > > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst-
> > > > >vsi_ctx));
> > > > +	err = vpu_dec_start(vpu, data, 2);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	/* wait decoder done interrupt */
> > > > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > > > MTK_INST_IRQ_RECEIVED,
> > > > +					   WAIT_INTR_TIMEOUT_MS
> > > > ,
> > > > MTK_VDEC_CORE);
> > > > +	if (err)
> > > > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > > > +			       inst->ctx->decoded_frame_cnt);
> > > > +
> > > > +	inst->vsi->dec.timeout = !!err;
> > > > +	err = vpu_dec_end(vpu);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst-
> > > > >vsi_ctx));
> > > > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x
> > > > 0x%x 0x%x
> > > > 0x%x 0x%x 0x%x",
> > > > +			 inst->ctx->decoded_frame_cnt,
> > > > +			 inst->vsi_ctx.dec.crc[0], inst-
> > > > > vsi_ctx.dec.crc[1],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[2], inst-
> > > > > vsi_ctx.dec.crc[3],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[4], inst-
> > > > > vsi_ctx.dec.crc[5],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[6], inst-
> > > > > vsi_ctx.dec.crc[7]);
> > > > 
> > > > +
> > > > +	inst->ctx->decoded_frame_cnt++;
> > > > +	return 0;
> > > > +
> > > > +err_free_fb_out:
> > > > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > > > +		       inst->ctx->decoded_frame_cnt, err);
> > > > +	return err;
> > > > +}
> > > > +
> > > > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > > > mtk_vcodec_mem *bs,
> > > > +				  struct vdec_fb *unused, bool
> > > > *res_chg)
> > > > +{
> > > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > > +	int ret;
> > > > +
> > > > +	if (!h_vdec)
> > > > +		return -EINVAL;
> > > > +
> > > > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > > > MTK_VDEC_PURE_SINGLE_CORE)
> > > > +		ret = vdec_h264_slice_single_decode(h_vdec, bs,
> > > > unused,
> > > > res_chg);
> > > > +	else
> > > > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs,
> > > > unused,
> > > > res_chg);
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > > > vdec_get_param_type type,
> > > >  				     void *out)
> > > >  {
> > > > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > > > *h_vdec, enum vdec_get_param_type type
> > > >  
> > > >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> > > >  	.init		= vdec_h264_slice_init,
> > > > -	.decode		= vdec_h264_slice_lat_decode,
> > > > +	.decode		= vdec_h264_slice_decode,
> > > >  	.get_param	= vdec_h264_slice_get_param,
> > > >  	.deinit		= vdec_h264_slice_deinit,
> > > >  };
> > > 
> > > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-22  1:46           ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-22  1:46 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: Irui Wang, George Sun, Steve Cho, devicetree,
	Project_Global_Chrome_Upstream_Group, linux-kernel, dri-devel,
	Xiaoyong Lu, linux-mediatek, Hsin-Yi Wang, Fritz Koenig,
	linux-arm-kernel, linux-media

Hi Nicolas,

Thanks for your suggestion.
On Tue, 2022-06-21 at 10:53 -0400, Nicolas Dufresne wrote:
> > 
> Le mercredi 15 juin 2022 à 19:33 +0800, yunfei.dong@mediatek.com a
> écrit :
> > Hi Nicolas,
> > 
> > Thanks for your comments.
> > On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> > > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > > Add h264 decode driver to support mt8186. For the architecture
> > > > is single core, need to add new interface to decode.
> > > > 
> > > > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > > > ---
> > > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > > +++++++++++++++++-
> > > >  1 file changed, 176 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git
> > > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > index a96f203b5d54..1d9e753cf894 100644
> > > > ---
> > > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > +++
> > > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> > > >   * @vsi:		vsi used for lat
> > > >   * @vsi_core:		vsi used for core
> > > >   *
> > > > + * @vsi_ctx:		Local VSI data for this decoding
> > > > context
> > > > + * @h264_slice_param:	the parameters that hardware use to
> > > > decode
> > > > + *
> > > >   * @resolution_changed:resolution changed
> > > >   * @realloc_mv_buf:	reallocate mv buffer
> > > >   * @cap_num_planes:	number of capture queue plane
> > > > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> > > >  	struct vdec_h264_slice_vsi *vsi;
> > > >  	struct vdec_h264_slice_vsi *vsi_core;
> > > >  
> > > > +	struct vdec_h264_slice_vsi vsi_ctx;
> > > > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > > > +
> > > >  	unsigned int resolution_changed;
> > > >  	unsigned int realloc_mv_buf;
> > > >  	unsigned int cap_num_planes;
> > > > @@ -208,6 +214,61 @@ static int
> > > > vdec_h264_slice_fill_decode_parameters(struct
> > > > vdec_h264_slice_inst
> > > > *i
> > > >  	return 0;
> > > >  }
> > > >  
> > > > +static int get_vdec_sig_decode_parameters(struct
> > > > vdec_h264_slice_inst *inst)
> > > > +{
> > > > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > > > +	const struct v4l2_ctrl_h264_sps *sps;
> > > > +	const struct v4l2_ctrl_h264_pps *pps;
> > > > +	const struct v4l2_ctrl_h264_scaling_matrix
> > > > *scaling_matrix;
> > > > +	struct vdec_h264_slice_lat_dec_param *slice_param =
> > > > &inst-
> > > > > h264_slice_param;
> > > > 
> > > > +	struct v4l2_h264_reflist_builder reflist_builder;
> > > > +	u8 *p0_reflist = slice_param-
> > > > >decode_params.ref_pic_list_p0;
> > > > +	u8 *b0_reflist = slice_param-
> > > > >decode_params.ref_pic_list_b0;
> > > > +	u8 *b1_reflist = slice_param-
> > > > >decode_params.ref_pic_list_b1;
> > > > +
> > > > +	dec_params =
> > > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > > > +	if (IS_ERR(dec_params))
> > > > +		return PTR_ERR(dec_params);
> > > > +
> > > > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_SPS);
> > > > +	if (IS_ERR(sps))
> > > > +		return PTR_ERR(sps);
> > > > +
> > > > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_PPS);
> > > > +	if (IS_ERR(pps))
> > > > +		return PTR_ERR(pps);
> > > > +
> > > > +	scaling_matrix =
> > > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > > > +	if (IS_ERR(scaling_matrix))
> > > > +		return PTR_ERR(scaling_matrix);
> > > > +
> > > > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > > > +
> > > > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > > > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > > > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param-
> > > > >scaling_matrix, 
> > > > scaling_matrix);
> > > > +
> > > > +	mtk_vdec_h264_copy_decode_params(&slice_param-
> > > > >decode_params,
> > > > dec_params, inst->dpb);
> > > > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > > > > decode_params,
> > > > 
> > > > +				    slice_param-
> > > > >h264_dpb_info);
> > > > +
> > > > +	/* Build the reference lists */
> > > > +	v4l2_h264_init_reflist_builder(&reflist_builder,
> > > > dec_params,
> > > > sps, inst->dpb);
> > > > +	v4l2_h264_build_p_ref_list(&reflist_builder,
> > > > p0_reflist);
> > > > +
> > > > +	v4l2_h264_build_b_ref_lists(&reflist_builder,
> > > > b0_reflist,
> > > > b1_reflist);
> > > > +	/* Adapt the built lists to the firmware's expectations
> > > > */
> > > > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > > > reflist_builder.num_valid);
> > > > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > > > reflist_builder.num_valid);
> > > > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > > > reflist_builder.num_valid);
> > > > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > > > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> > > 
> > > This function looks very redundant across multiple variants,
> > > could
> > > you try and
> > > make a helper to reduce the duplication ?
> > > 
> > 
> > At first, I try to add one helper function for single core and lat
> > decode.
> > 
> > But these two hardware have big differences, need to add many
> > condition
> > to separate. So just add new function for mt8186 single core
> > architecture.
> 
> I still think you could have a very small helper that turns the
> reflist_builder
> incantation (which are fully identical in all SoC), to be one
> line/call. It was
> annoying when I recently had to update this driver for some internal
> API change.
> 
I will refactor the driver flow and add one simple helper function.

Best Regards,
Yunfei Dong
> > Best Regards,
> > Yunfei Dong
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > >  static void vdec_h264_slice_fill_decode_reflist(struct
> > > > vdec_h264_slice_inst *inst,
> > > >  						struct
> > > > vdec_h264_slice_lat_dec_param *slice_param,
> > > >  						struct
> > > > vdec_h264_slice_share_info *share_info)
> > > > @@ -596,6 +657,120 @@ static int
> > > > vdec_h264_slice_lat_decode(void
> > > > *h_vdec, struct mtk_vcodec_mem *bs,
> > > >  	return err;
> > > >  }
> > > >  
> > > > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > > > mtk_vcodec_mem *bs,
> > > > +					 struct vdec_fb
> > > > *unused, bool
> > > > *res_chg)
> > > > +{
> > > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > > > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > > > +	struct vdec_fb *fb;
> > > > +	unsigned char *buf;
> > > > +	unsigned int data[2], i;
> > > > +	u64 y_fb_dma, c_fb_dma;
> > > > +	struct mtk_vcodec_mem *mem;
> > > > +	int err, nal_start_idx;
> > > > +
> > > > +	/* bs NULL means flush decoder */
> > > > +	if (!bs)
> > > > +		return vpu_dec_reset(vpu);
> > > > +
> > > > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst-
> > > > >ctx);
> > > > +	src_buf_info = container_of(bs, struct
> > > > mtk_video_dec_buf,
> > > > bs_buffer);
> > > > +	dst_buf_info = container_of(fb, struct
> > > > mtk_video_dec_buf,
> > > > frame_buffer);
> > > > +
> > > > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > > > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > > > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx
> > > > c_dma=%llx",
> > > > +			 inst->ctx->decoded_frame_cnt,
> > > > y_fb_dma,
> > > > c_fb_dma);
> > > > +
> > > > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > > > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > > > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > > > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > > > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > > > +
> > > > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > > > +				   &dst_buf_info->m2m_buf.vb,
> > > > true);
> > > > +	err = get_vdec_sig_decode_parameters(inst);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	buf = (unsigned char *)bs->va;
> > > > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs-
> > > > >size);
> > > > +	if (nal_start_idx < 0) {
> > > > +		err = -EINVAL;
> > > > +		goto err_free_fb_out;
> > > > +	}
> > > > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > > > +
> > > > +	*res_chg = inst->resolution_changed;
> > > > +	if (inst->resolution_changed) {
> > > > +		mtk_vcodec_debug(inst, "- resolution changed
> > > > -");
> > > > +		if (inst->realloc_mv_buf) {
> > > > +			err =
> > > > vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > > > > ctx->picinfo);
> > > > 
> > > > +			inst->realloc_mv_buf = false;
> > > > +			if (err)
> > > > +				goto err_free_fb_out;
> > > > +		}
> > > > +		inst->resolution_changed = false;
> > > > +
> > > > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > > > +			mem = &inst->mv_buf[i];
> > > > +			inst->vsi_ctx.mv_buf_dma[i] = mem-
> > > > >dma_addr;
> > > > +		}
> > > > +	}
> > > > +
> > > > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst-
> > > > >vsi_ctx));
> > > > +	err = vpu_dec_start(vpu, data, 2);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	/* wait decoder done interrupt */
> > > > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > > > MTK_INST_IRQ_RECEIVED,
> > > > +					   WAIT_INTR_TIMEOUT_MS
> > > > ,
> > > > MTK_VDEC_CORE);
> > > > +	if (err)
> > > > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > > > +			       inst->ctx->decoded_frame_cnt);
> > > > +
> > > > +	inst->vsi->dec.timeout = !!err;
> > > > +	err = vpu_dec_end(vpu);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst-
> > > > >vsi_ctx));
> > > > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x
> > > > 0x%x 0x%x
> > > > 0x%x 0x%x 0x%x",
> > > > +			 inst->ctx->decoded_frame_cnt,
> > > > +			 inst->vsi_ctx.dec.crc[0], inst-
> > > > > vsi_ctx.dec.crc[1],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[2], inst-
> > > > > vsi_ctx.dec.crc[3],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[4], inst-
> > > > > vsi_ctx.dec.crc[5],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[6], inst-
> > > > > vsi_ctx.dec.crc[7]);
> > > > 
> > > > +
> > > > +	inst->ctx->decoded_frame_cnt++;
> > > > +	return 0;
> > > > +
> > > > +err_free_fb_out:
> > > > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > > > +		       inst->ctx->decoded_frame_cnt, err);
> > > > +	return err;
> > > > +}
> > > > +
> > > > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > > > mtk_vcodec_mem *bs,
> > > > +				  struct vdec_fb *unused, bool
> > > > *res_chg)
> > > > +{
> > > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > > +	int ret;
> > > > +
> > > > +	if (!h_vdec)
> > > > +		return -EINVAL;
> > > > +
> > > > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > > > MTK_VDEC_PURE_SINGLE_CORE)
> > > > +		ret = vdec_h264_slice_single_decode(h_vdec, bs,
> > > > unused,
> > > > res_chg);
> > > > +	else
> > > > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs,
> > > > unused,
> > > > res_chg);
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > > > vdec_get_param_type type,
> > > >  				     void *out)
> > > >  {
> > > > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > > > *h_vdec, enum vdec_get_param_type type
> > > >  
> > > >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> > > >  	.init		= vdec_h264_slice_init,
> > > > -	.decode		= vdec_h264_slice_lat_decode,
> > > > +	.decode		= vdec_h264_slice_decode,
> > > >  	.get_param	= vdec_h264_slice_get_param,
> > > >  	.deinit		= vdec_h264_slice_deinit,
> > > >  };
> > > 
> > > 
> 
> 


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186
@ 2022-06-22  1:46           ` yunfei.dong
  0 siblings, 0 replies; 49+ messages in thread
From: yunfei.dong @ 2022-06-22  1:46 UTC (permalink / raw)
  To: Nicolas Dufresne, Alexandre Courbot, Hans Verkuil,
	AngeloGioacchino Del Regno, Benjamin Gaignard, Tiffany Lin,
	Andrew-CT Chen, Mauro Carvalho Chehab, Rob Herring,
	Matthias Brugger, Tomasz Figa
  Cc: George Sun, Xiaoyong Lu, Hsin-Yi Wang, Fritz Koenig,
	Daniel Vetter, dri-devel, Irui Wang, Steve Cho, linux-media,
	devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	Project_Global_Chrome_Upstream_Group

Hi Nicolas,

Thanks for your suggestion.
On Tue, 2022-06-21 at 10:53 -0400, Nicolas Dufresne wrote:
> > 
> Le mercredi 15 juin 2022 à 19:33 +0800, yunfei.dong@mediatek.com a
> écrit :
> > Hi Nicolas,
> > 
> > Thanks for your comments.
> > On Mon, 2022-06-13 at 16:08 -0400, Nicolas Dufresne wrote:
> > > Le jeudi 12 mai 2022 à 11:46 +0800, Yunfei Dong a écrit :
> > > > Add h264 decode driver to support mt8186. For the architecture
> > > > is single core, need to add new interface to decode.
> > > > 
> > > > Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
> > > > ---
> > > >  .../vcodec/vdec/vdec_h264_req_multi_if.c      | 177
> > > > +++++++++++++++++-
> > > >  1 file changed, 176 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git
> > > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > index a96f203b5d54..1d9e753cf894 100644
> > > > ---
> > > > a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > +++
> > > > b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_mul
> > > > ti_i
> > > > f.c
> > > > @@ -140,6 +140,9 @@ struct vdec_h264_slice_share_info {
> > > >   * @vsi:		vsi used for lat
> > > >   * @vsi_core:		vsi used for core
> > > >   *
> > > > + * @vsi_ctx:		Local VSI data for this decoding
> > > > context
> > > > + * @h264_slice_param:	the parameters that hardware use to
> > > > decode
> > > > + *
> > > >   * @resolution_changed:resolution changed
> > > >   * @realloc_mv_buf:	reallocate mv buffer
> > > >   * @cap_num_planes:	number of capture queue plane
> > > > @@ -157,6 +160,9 @@ struct vdec_h264_slice_inst {
> > > >  	struct vdec_h264_slice_vsi *vsi;
> > > >  	struct vdec_h264_slice_vsi *vsi_core;
> > > >  
> > > > +	struct vdec_h264_slice_vsi vsi_ctx;
> > > > +	struct vdec_h264_slice_lat_dec_param h264_slice_param;
> > > > +
> > > >  	unsigned int resolution_changed;
> > > >  	unsigned int realloc_mv_buf;
> > > >  	unsigned int cap_num_planes;
> > > > @@ -208,6 +214,61 @@ static int
> > > > vdec_h264_slice_fill_decode_parameters(struct
> > > > vdec_h264_slice_inst
> > > > *i
> > > >  	return 0;
> > > >  }
> > > >  
> > > > +static int get_vdec_sig_decode_parameters(struct
> > > > vdec_h264_slice_inst *inst)
> > > > +{
> > > > +	const struct v4l2_ctrl_h264_decode_params *dec_params;
> > > > +	const struct v4l2_ctrl_h264_sps *sps;
> > > > +	const struct v4l2_ctrl_h264_pps *pps;
> > > > +	const struct v4l2_ctrl_h264_scaling_matrix
> > > > *scaling_matrix;
> > > > +	struct vdec_h264_slice_lat_dec_param *slice_param =
> > > > &inst-
> > > > > h264_slice_param;
> > > > 
> > > > +	struct v4l2_h264_reflist_builder reflist_builder;
> > > > +	u8 *p0_reflist = slice_param-
> > > > >decode_params.ref_pic_list_p0;
> > > > +	u8 *b0_reflist = slice_param-
> > > > >decode_params.ref_pic_list_b0;
> > > > +	u8 *b1_reflist = slice_param-
> > > > >decode_params.ref_pic_list_b1;
> > > > +
> > > > +	dec_params =
> > > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_DECODE_PARAMS);
> > > > +	if (IS_ERR(dec_params))
> > > > +		return PTR_ERR(dec_params);
> > > > +
> > > > +	sps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_SPS);
> > > > +	if (IS_ERR(sps))
> > > > +		return PTR_ERR(sps);
> > > > +
> > > > +	pps = mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_PPS);
> > > > +	if (IS_ERR(pps))
> > > > +		return PTR_ERR(pps);
> > > > +
> > > > +	scaling_matrix =
> > > > +		mtk_vdec_h264_get_ctrl_ptr(inst->ctx,
> > > > V4L2_CID_STATELESS_H264_SCALING_MATRIX);
> > > > +	if (IS_ERR(scaling_matrix))
> > > > +		return PTR_ERR(scaling_matrix);
> > > > +
> > > > +	mtk_vdec_h264_update_dpb(dec_params, inst->dpb);
> > > > +
> > > > +	mtk_vdec_h264_copy_sps_params(&slice_param->sps, sps);
> > > > +	mtk_vdec_h264_copy_pps_params(&slice_param->pps, pps);
> > > > +	mtk_vdec_h264_copy_scaling_matrix(&slice_param-
> > > > >scaling_matrix, 
> > > > scaling_matrix);
> > > > +
> > > > +	mtk_vdec_h264_copy_decode_params(&slice_param-
> > > > >decode_params,
> > > > dec_params, inst->dpb);
> > > > +	mtk_vdec_h264_fill_dpb_info(inst->ctx, &slice_param-
> > > > > decode_params,
> > > > 
> > > > +				    slice_param-
> > > > >h264_dpb_info);
> > > > +
> > > > +	/* Build the reference lists */
> > > > +	v4l2_h264_init_reflist_builder(&reflist_builder,
> > > > dec_params,
> > > > sps, inst->dpb);
> > > > +	v4l2_h264_build_p_ref_list(&reflist_builder,
> > > > p0_reflist);
> > > > +
> > > > +	v4l2_h264_build_b_ref_lists(&reflist_builder,
> > > > b0_reflist,
> > > > b1_reflist);
> > > > +	/* Adapt the built lists to the firmware's expectations
> > > > */
> > > > +	mtk_vdec_h264_fixup_ref_list(p0_reflist,
> > > > reflist_builder.num_valid);
> > > > +	mtk_vdec_h264_fixup_ref_list(b0_reflist,
> > > > reflist_builder.num_valid);
> > > > +	mtk_vdec_h264_fixup_ref_list(b1_reflist,
> > > > reflist_builder.num_valid);
> > > > +	memcpy(&inst->vsi_ctx.h264_slice_params, slice_param,
> > > > +	       sizeof(inst->vsi_ctx.h264_slice_params));
> > > 
> > > This function looks very redundant across multiple variants,
> > > could
> > > you try and
> > > make a helper to reduce the duplication ?
> > > 
> > 
> > At first, I try to add one helper function for single core and lat
> > decode.
> > 
> > But these two hardware have big differences, need to add many
> > condition
> > to separate. So just add new function for mt8186 single core
> > architecture.
> 
> I still think you could have a very small helper that turns the
> reflist_builder
> incantation (which are fully identical in all SoC), to be one
> line/call. It was
> annoying when I recently had to update this driver for some internal
> API change.
> 
I will refactor the driver flow and add one simple helper function.

Best Regards,
Yunfei Dong
> > Best Regards,
> > Yunfei Dong
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > >  static void vdec_h264_slice_fill_decode_reflist(struct
> > > > vdec_h264_slice_inst *inst,
> > > >  						struct
> > > > vdec_h264_slice_lat_dec_param *slice_param,
> > > >  						struct
> > > > vdec_h264_slice_share_info *share_info)
> > > > @@ -596,6 +657,120 @@ static int
> > > > vdec_h264_slice_lat_decode(void
> > > > *h_vdec, struct mtk_vcodec_mem *bs,
> > > >  	return err;
> > > >  }
> > > >  
> > > > +static int vdec_h264_slice_single_decode(void *h_vdec, struct
> > > > mtk_vcodec_mem *bs,
> > > > +					 struct vdec_fb
> > > > *unused, bool
> > > > *res_chg)
> > > > +{
> > > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > > +	struct vdec_vpu_inst *vpu = &inst->vpu;
> > > > +	struct mtk_video_dec_buf *src_buf_info, *dst_buf_info;
> > > > +	struct vdec_fb *fb;
> > > > +	unsigned char *buf;
> > > > +	unsigned int data[2], i;
> > > > +	u64 y_fb_dma, c_fb_dma;
> > > > +	struct mtk_vcodec_mem *mem;
> > > > +	int err, nal_start_idx;
> > > > +
> > > > +	/* bs NULL means flush decoder */
> > > > +	if (!bs)
> > > > +		return vpu_dec_reset(vpu);
> > > > +
> > > > +	fb = inst->ctx->dev->vdec_pdata->get_cap_buffer(inst-
> > > > >ctx);
> > > > +	src_buf_info = container_of(bs, struct
> > > > mtk_video_dec_buf,
> > > > bs_buffer);
> > > > +	dst_buf_info = container_of(fb, struct
> > > > mtk_video_dec_buf,
> > > > frame_buffer);
> > > > +
> > > > +	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
> > > > +	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
> > > > +	mtk_vcodec_debug(inst, "[h264-dec] [%d] y_dma=%llx
> > > > c_dma=%llx",
> > > > +			 inst->ctx->decoded_frame_cnt,
> > > > y_fb_dma,
> > > > c_fb_dma);
> > > > +
> > > > +	inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr;
> > > > +	inst->vsi_ctx.dec.bs_buf_size = bs->size;
> > > > +	inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;
> > > > +	inst->vsi_ctx.dec.c_fb_dma = c_fb_dma;
> > > > +	inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb;
> > > > +
> > > > +	v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb,
> > > > +				   &dst_buf_info->m2m_buf.vb,
> > > > true);
> > > > +	err = get_vdec_sig_decode_parameters(inst);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	buf = (unsigned char *)bs->va;
> > > > +	nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs-
> > > > >size);
> > > > +	if (nal_start_idx < 0) {
> > > > +		err = -EINVAL;
> > > > +		goto err_free_fb_out;
> > > > +	}
> > > > +	inst->vsi_ctx.dec.nal_info = buf[nal_start_idx];
> > > > +
> > > > +	*res_chg = inst->resolution_changed;
> > > > +	if (inst->resolution_changed) {
> > > > +		mtk_vcodec_debug(inst, "- resolution changed
> > > > -");
> > > > +		if (inst->realloc_mv_buf) {
> > > > +			err =
> > > > vdec_h264_slice_alloc_mv_buf(inst, &inst-
> > > > > ctx->picinfo);
> > > > 
> > > > +			inst->realloc_mv_buf = false;
> > > > +			if (err)
> > > > +				goto err_free_fb_out;
> > > > +		}
> > > > +		inst->resolution_changed = false;
> > > > +
> > > > +		for (i = 0; i < H264_MAX_MV_NUM; i++) {
> > > > +			mem = &inst->mv_buf[i];
> > > > +			inst->vsi_ctx.mv_buf_dma[i] = mem-
> > > > >dma_addr;
> > > > +		}
> > > > +	}
> > > > +
> > > > +	memcpy(inst->vpu.vsi, &inst->vsi_ctx, sizeof(inst-
> > > > >vsi_ctx));
> > > > +	err = vpu_dec_start(vpu, data, 2);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	/* wait decoder done interrupt */
> > > > +	err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
> > > > MTK_INST_IRQ_RECEIVED,
> > > > +					   WAIT_INTR_TIMEOUT_MS
> > > > ,
> > > > MTK_VDEC_CORE);
> > > > +	if (err)
> > > > +		mtk_vcodec_err(inst, "decode timeout: pic_%d",
> > > > +			       inst->ctx->decoded_frame_cnt);
> > > > +
> > > > +	inst->vsi->dec.timeout = !!err;
> > > > +	err = vpu_dec_end(vpu);
> > > > +	if (err)
> > > > +		goto err_free_fb_out;
> > > > +
> > > > +	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst-
> > > > >vsi_ctx));
> > > > +	mtk_vcodec_debug(inst, "pic[%d] crc: 0x%x 0x%x 0x%x
> > > > 0x%x 0x%x
> > > > 0x%x 0x%x 0x%x",
> > > > +			 inst->ctx->decoded_frame_cnt,
> > > > +			 inst->vsi_ctx.dec.crc[0], inst-
> > > > > vsi_ctx.dec.crc[1],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[2], inst-
> > > > > vsi_ctx.dec.crc[3],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[4], inst-
> > > > > vsi_ctx.dec.crc[5],
> > > > 
> > > > +			 inst->vsi_ctx.dec.crc[6], inst-
> > > > > vsi_ctx.dec.crc[7]);
> > > > 
> > > > +
> > > > +	inst->ctx->decoded_frame_cnt++;
> > > > +	return 0;
> > > > +
> > > > +err_free_fb_out:
> > > > +	mtk_vcodec_err(inst, "dec frame number: %d err: %d",
> > > > +		       inst->ctx->decoded_frame_cnt, err);
> > > > +	return err;
> > > > +}
> > > > +
> > > > +static int vdec_h264_slice_decode(void *h_vdec, struct
> > > > mtk_vcodec_mem *bs,
> > > > +				  struct vdec_fb *unused, bool
> > > > *res_chg)
> > > > +{
> > > > +	struct vdec_h264_slice_inst *inst = h_vdec;
> > > > +	int ret;
> > > > +
> > > > +	if (!h_vdec)
> > > > +		return -EINVAL;
> > > > +
> > > > +	if (inst->ctx->dev->vdec_pdata->hw_arch ==
> > > > MTK_VDEC_PURE_SINGLE_CORE)
> > > > +		ret = vdec_h264_slice_single_decode(h_vdec, bs,
> > > > unused,
> > > > res_chg);
> > > > +	else
> > > > +		ret = vdec_h264_slice_lat_decode(h_vdec, bs,
> > > > unused,
> > > > res_chg);
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > >  static int vdec_h264_slice_get_param(void *h_vdec, enum
> > > > vdec_get_param_type type,
> > > >  				     void *out)
> > > >  {
> > > > @@ -620,7 +795,7 @@ static int vdec_h264_slice_get_param(void
> > > > *h_vdec, enum vdec_get_param_type type
> > > >  
> > > >  const struct vdec_common_if vdec_h264_slice_multi_if = {
> > > >  	.init		= vdec_h264_slice_init,
> > > > -	.decode		= vdec_h264_slice_lat_decode,
> > > > +	.decode		= vdec_h264_slice_decode,
> > > >  	.get_param	= vdec_h264_slice_get_param,
> > > >  	.deinit		= vdec_h264_slice_deinit,
> > > >  };
> > > 
> > > 
> 
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2022-06-22  1:49 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12  3:46 [PATCH v4, 0/3] add h264 decoder driver for mt8186 Yunfei Dong
2022-05-12  3:46 ` Yunfei Dong
2022-05-12  3:46 ` Yunfei Dong
2022-05-12  3:46 ` Yunfei Dong
2022-05-12  3:46 ` [PATCH v4, 1/3] dt-bindings: media: mediatek: vcodec: Adds decoder dt-bindings " Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46 ` [PATCH v4, 2/3] media: mediatek: vcodec: Support MT8186 Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46 ` [PATCH v4, 3/3] media: mediatek: vcodec: add h264 decoder driver for mt8186 Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-05-12  3:46   ` Yunfei Dong
2022-06-13 20:08   ` Nicolas Dufresne
2022-06-13 20:08     ` Nicolas Dufresne
2022-06-13 20:08     ` Nicolas Dufresne
2022-06-13 20:08     ` Nicolas Dufresne
2022-06-15 11:33     ` yunfei.dong
2022-06-15 11:33       ` yunfei.dong
2022-06-15 11:33       ` yunfei.dong
2022-06-21 14:53       ` Nicolas Dufresne
2022-06-21 14:53         ` Nicolas Dufresne
2022-06-21 14:53         ` Nicolas Dufresne
2022-06-22  1:46         ` yunfei.dong
2022-06-22  1:46           ` yunfei.dong
2022-06-22  1:46           ` yunfei.dong
2022-06-13 20:10 ` [PATCH v4, 0/3] " Nicolas Dufresne
2022-06-13 20:10   ` Nicolas Dufresne
2022-06-13 20:10   ` Nicolas Dufresne
2022-06-13 20:10   ` Nicolas Dufresne
2022-06-14 17:46   ` Nicolas Dufresne
2022-06-14 17:46     ` Nicolas Dufresne
2022-06-14 17:46     ` Nicolas Dufresne
2022-06-14 17:46     ` Nicolas Dufresne
2022-06-15 11:43     ` yunfei.dong
2022-06-15 11:43       ` yunfei.dong
2022-06-15 11:43       ` yunfei.dong
2022-06-22  1:42     ` yunfei.dong
2022-06-22  1:42       ` yunfei.dong
2022-06-22  1:42       ` yunfei.dong
2022-06-15 11:37   ` yunfei.dong
2022-06-15 11:37     ` yunfei.dong
2022-06-15 11:37     ` yunfei.dong
2022-06-21 14:56     ` Nicolas Dufresne
2022-06-21 14:56       ` Nicolas Dufresne
2022-06-21 14:56       ` Nicolas Dufresne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.