[PATCH v15, 12/19] media: mtk-vcodec: Add new interface to lock different hardware

2021-12-16 Thread Yunfei Dong
For add new hardware, not only need to lock lat hardware, also
need to lock core hardware in case of different instance start
to decoder at the same time.

Signed-off-by: Yunfei Dong 
Reviewed-by: AngeloGioacchino Del Regno 

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 4 ++--
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 5 +++--
 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
index 2b334a8a81c6..130ecef2e766 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -105,12 +105,12 @@ static int vidioc_decoder_cmd(struct file *file, void 
*priv,
 
 void mtk_vdec_unlock(struct mtk_vcodec_ctx *ctx)
 {
-   mutex_unlock(>dev->dec_mutex);
+   mutex_unlock(>dev->dec_mutex[ctx->hw_id]);
 }
 
 void mtk_vdec_lock(struct mtk_vcodec_ctx *ctx)
 {
-   mutex_lock(>dev->dec_mutex);
+   mutex_lock(>dev->dec_mutex[ctx->hw_id]);
 }
 
 void mtk_vcodec_dec_release(struct mtk_vcodec_ctx *ctx)
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 64359cf692f5..471b8c6ba7f2 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -279,7 +279,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
struct video_device *vfd_dec;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
-   int ret;
+   int i, ret;
 
dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -311,7 +311,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_dec_pm;
}
 
-   mutex_init(>dec_mutex);
+   for (i = 0; i < MTK_VDEC_HW_MAX; i++)
+   mutex_init(>dec_mutex[i]);
mutex_init(>dev_mutex);
spin_lock_init(>irqlock);
 
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index adc5998ed424..517515ee9ac4 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -500,7 +500,7 @@ struct mtk_vcodec_dev {
int dec_irq;
int enc_irq;
 
-   struct mutex dec_mutex;
+   struct mutex dec_mutex[MTK_VDEC_HW_MAX];
struct mutex enc_mutex;
 
struct mtk_vcodec_pm pm;
-- 
2.25.1



[PATCH v15, 15/19] dt-bindings: media: mtk-vcodec: Adds decoder dt-bindings for mt8192

2021-12-16 Thread Yunfei Dong
Adds decoder dt-bindings for mt8192.

Reviewed-by: Rob Herring 
Signed-off-by: Yunfei Dong 
---
 .../media/mediatek,vcodec-subdev-decoder.yaml | 265 ++
 1 file changed, 265 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml

diff --git 
a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml 
b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
new file mode 100644
index ..d587fc3e39fb
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
@@ -0,0 +1,265 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/media/mediatek,vcodec-subdev-decoder.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: Mediatek Video Decode Accelerator With Multi Hardware
+
+maintainers:
+  - Yunfei Dong 
+
+description: |
+  Mediatek Video Decode is the video decode hardware present in Mediatek
+  SoCs which supports high resolution decoding functionalities. Required
+  parent and child device node.
+
+  About the Decoder Hardware Block Diagram, please check below:
+
++-++
+| ||
+| input -> lat HW -> lat buffer --|--> lat buffer -> core HW -> output |
+|||   | || |
++||---+-||-+
+  lat workqueue   |  core workqueue 

+
-||-||--
+ || ||  
+ \/ \/
+   +--+
+   |enable/disable|
+   |   clk powerirqiommu  |
+   | (lat/lat soc/core0/core1)|
+   +--+
+
+  As above, there are parent and child devices, child mean each hardware. The 
child device
+  controls the information of each hardware independent which include 
clk/power/irq.
+
+  There are two workqueues in parent device: lat workqueue and core workqueue. 
They are used
+  to lat and core hardware deocder. Lat workqueue need to get input bitstream 
and lat buffer,
+  then enable lat to decode, writing the result to lat buffer, dislabe 
hardware when lat decode
+  done. Core workqueue need to get lat buffer and output buffer, then enable 
core to decode,
+  writing the result to output buffer, disable hardware when core decode done. 
These two
+  hardwares will decode each frame cyclically.
+
+  For the smi common may not the same for each hardware, can't combine all 
hardware in one node,
+  or leading to iommu fault when access dram data.
+
+properties:
+  compatible:
+const: mediatek,mt8192-vcodec-dec
+
+  reg:
+maxItems: 1
+
+  iommus:
+minItems: 1
+maxItems: 32
+description: |
+  List of the hardware port in respective IOMMU block for current Socs.
+  Refer to bindings/iommu/mediatek,iommu.yaml.
+
+  mediatek,scp:
+$ref: /schemas/types.yaml#/definitions/phandle
+maxItems: 1
+description: |
+  The node of system control processor (SCP), using
+  the remoteproc & rpmsg framework.
+
+  dma-ranges:
+maxItems: 1
+description: |
+  Describes the physical address space of IOMMU maps to memory.
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 1
+
+  ranges: true
+
+# Required child node:
+patternProperties:
+  '^vcodec-lat@[0-9a-f]+$':
+type: object
+
+properties:
+  compatible:
+const: mediatek,mtk-vcodec-lat
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  iommus:
+minItems: 1
+maxItems: 32
+description: |
+  List of the hardware port in respective IOMMU block for current Socs.
+  Refer to bindings/iommu/mediatek,iommu.yaml.
+
+  clocks:
+maxItems: 5
+
+  clock-names:
+items:
+  - const: sel
+  - const: soc-vdec
+  - const: soc-lat
+  - const: vdec
+  - const: top
+
+  assigned-clocks:
+maxItems: 1
+
+  assigned-clock-parents:
+maxItems: 1
+
+  power-domains:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - iommus
+  - clocks
+  - clock-names
+  - assigned-clocks
+  - assigned-clock-parents
+  - power-domains
+
+additionalProperties: false
+
+  '^vcodec-core@[0-9a-f]+$':
+type: object
+
+properties:
+  compatible:
+const: 

[PATCH v15, 13/19] media: mtk-vcodec: Add work queue for core hardware decode

2021-12-16 Thread Yunfei Dong
Add work queue to process core hardware information.
First, get lat_buf from message queue, then call core
hardware of each codec(H264/VP9/AV1) to decode, finally
puts lat_buf back to the message.

Reviewed-by: Steve Cho 
Signed-off-by: Yunfei Dong 
---
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  | 16 +++-
 .../platform/mtk-vcodec/mtk_vcodec_drv.h  |  3 ++
 .../platform/mtk-vcodec/vdec_msg_queue.c  | 41 ---
 .../platform/mtk-vcodec/vdec_msg_queue.h  |  8 ++--
 4 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 471b8c6ba7f2..10215ccc85f7 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -311,6 +311,17 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_dec_pm;
}
 
+   if (IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch)) {
+   vdec_msg_queue_init_ctx(>msg_queue_core_ctx, 
MTK_VDEC_CORE);
+   dev->core_workqueue = alloc_ordered_workqueue("core-decoder",
+   WQ_MEM_RECLAIM | WQ_FREEZABLE);
+   if (!dev->core_workqueue) {
+   mtk_v4l2_err("Failed to create core workqueue");
+   ret = -EINVAL;
+   goto err_res;
+   }
+   }
+
for (i = 0; i < MTK_VDEC_HW_MAX; i++)
mutex_init(>dec_mutex[i]);
mutex_init(>dev_mutex);
@@ -322,7 +333,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
ret = v4l2_device_register(>dev, >v4l2_dev);
if (ret) {
mtk_v4l2_err("v4l2_device_register err=%d", ret);
-   goto err_res;
+   goto err_core_workq;
}
 
init_waitqueue_head(>queue);
@@ -423,6 +434,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
video_unregister_device(vfd_dec);
 err_dec_alloc:
v4l2_device_unregister(>v4l2_dev);
+err_core_workq:
+   if (IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch))
+   destroy_workqueue(dev->core_workqueue);
 err_res:
mtk_vcodec_release_dec_pm(>pm);
 err_dec_pm:
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 517515ee9ac4..3fc747cea5c9 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -27,6 +27,7 @@
 #define MTK_VCODEC_MAX_PLANES  3
 #define MTK_V4L2_BENCHMARK 0
 #define WAIT_INTR_TIMEOUT_MS   1000
+#define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
 
 /*
  * enum mtk_hw_reg_idx - MTK hw register base index
@@ -464,6 +465,7 @@ struct mtk_vcodec_enc_pdata {
  * @dec_capability: used to identify decode capability, ex: 4k
  * @enc_capability: used to identify encode capability
  *
+ * @core_workqueue: queue used for core hardware decode
  * @msg_queue_core_ctx: msg queue context used for core workqueue
  *
  * @subdev_dev: subdev hardware device
@@ -507,6 +509,7 @@ struct mtk_vcodec_dev {
unsigned int dec_capability;
unsigned int enc_capability;
 
+   struct workqueue_struct *core_workqueue;
struct vdec_msg_queue_ctx msg_queue_core_ctx;
 
void *subdev_dev[MTK_VDEC_HW_MAX];
diff --git a/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c 
b/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
index 913aefa67618..24f1d03df9f1 100644
--- a/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
@@ -68,6 +68,9 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, 
struct vdec_lat_buf
 
if (msg_ctx->hardware_index != MTK_VDEC_CORE)
wake_up_all(_ctx->ready_to_use);
+   else
+   queue_work(buf->ctx->dev->core_workqueue,
+   >ctx->msg_queue.core_work);
 
mtk_v4l2_debug(3, "enqueue buf type: %d addr: 0x%p num: %d",
msg_ctx->hardware_index, buf, msg_ctx->ready_num);
@@ -169,8 +172,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue 
*msg_queue)
return false;
 }
 
-void vdec_msg_queue_deinit(
-   struct vdec_msg_queue *msg_queue,
+void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,
struct mtk_vcodec_ctx *ctx)
 {
struct vdec_lat_buf *lat_buf;
@@ -196,10 +198,36 @@ void vdec_msg_queue_deinit(
}
 }
 
-int vdec_msg_queue_init(
-   struct vdec_msg_queue *msg_queue,
-   struct mtk_vcodec_ctx *ctx,
-   core_decode_cb_t core_decode,
+static void vdec_msg_queue_core_work(struct work_struct *work)
+{
+   struct vdec_msg_queue *msg_queue =
+   container_of(work, struct vdec_msg_queue, core_work);
+   struct mtk_vcodec_ctx *ctx =
+   container_of(msg_queue, struct mtk_vcodec_ctx, msg_queue);
+   

[PATCH v15, 11/19] media: mtk-vcodec: Generalize power and clock on/off interfaces

2021-12-16 Thread Yunfei Dong
Generalizes power and clock on/off interfaces to support different hardware.

Reviewed-by: AngeloGioacchino Del Regno 

Signed-off-by: Yunfei Dong 
---
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  6 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_hw.c   |  2 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_hw.h   |  4 +
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   | 76 +--
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.h   |  8 +-
 .../platform/mtk-vcodec/mtk_vcodec_drv.h  |  2 +
 .../platform/mtk-vcodec/mtk_vcodec_util.c | 59 +++---
 .../platform/mtk-vcodec/mtk_vcodec_util.h |  8 +-
 .../media/platform/mtk-vcodec/vdec_drv_if.c   | 21 ++---
 9 files changed, 146 insertions(+), 40 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 9802e5cc535f..64359cf692f5 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -46,7 +46,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void 
*priv)
void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC] +
VDEC_IRQ_CFG_REG;
 
-   ctx = mtk_vcodec_get_curr_ctx(dev);
+   ctx = mtk_vcodec_get_curr_ctx(dev, MTK_VDEC_CORE);
 
/* check if HW active or not */
cg_status = readl(dev->reg_base[0]);
@@ -193,7 +193,7 @@ static int fops_vcodec_open(struct file *file)
mtk_vcodec_dec_set_default_params(ctx);
 
if (v4l2_fh_is_singular(>fh)) {
-   ret = mtk_vcodec_dec_pw_on(>pm);
+   ret = mtk_vcodec_dec_pw_on(dev, MTK_VDEC_LAT0);
if (ret < 0)
goto err_load_fw;
/*
@@ -253,7 +253,7 @@ static int fops_vcodec_release(struct file *file)
mtk_vcodec_dec_release(ctx);
 
if (v4l2_fh_is_singular(>fh))
-   mtk_vcodec_dec_pw_off(>pm);
+   mtk_vcodec_dec_pw_off(dev, MTK_VDEC_LAT0);
v4l2_fh_del(>fh);
v4l2_fh_exit(>fh);
v4l2_ctrl_handler_free(>ctrl_hdl);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
index b149c3058995..643cee119b60 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
@@ -65,7 +65,7 @@ static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void 
*priv)
void __iomem *vdec_misc_addr = dev->reg_base[VDEC_HW_MISC] +
VDEC_IRQ_CFG_REG;
 
-   ctx = mtk_vcodec_get_curr_ctx(dev->main_dev);
+   ctx = mtk_vcodec_get_curr_ctx(dev->main_dev, dev->hw_idx);
 
/* check if HW active or not */
cg_status = readl(dev->reg_base[VDEC_HW_SYS]);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h
index 0db0c8c310da..c0cd0cdab9ee 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h
@@ -32,6 +32,8 @@ enum mtk_vdec_hw_reg_idx {
  * @main_dev: main device
  * @reg_base: Mapped address of MTK Vcodec registers.
  *
+ * @curr_ctx: the context that is waiting for codec hardware
+ *
  * @dec_irq: decoder irq resource
  * @pm: power management control
  * @hw_idx: each hardware index
@@ -41,6 +43,8 @@ struct mtk_vdec_hw_dev {
struct mtk_vcodec_dev *main_dev;
void __iomem *reg_base[VDEC_HW_MAX];
 
+   struct mtk_vcodec_ctx *curr_ctx;
+
int dec_irq;
struct mtk_vcodec_pm pm;
int hw_idx;
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index 221cf60e9fbf..4cf03d38d141 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -5,11 +5,13 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+#include "mtk_vcodec_dec_hw.h"
 #include "mtk_vcodec_dec_pm.h"
 #include "mtk_vcodec_util.h"
 
@@ -86,10 +88,23 @@ void mtk_vcodec_release_dec_pm(struct mtk_vcodec_pm *pm)
 }
 EXPORT_SYMBOL_GPL(mtk_vcodec_release_dec_pm);
 
-int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
+int mtk_vcodec_dec_pw_on(struct mtk_vcodec_dev *vdec_dev, int hw_idx)
 {
+   struct mtk_vdec_hw_dev *subdev_dev;
+   struct mtk_vcodec_pm *pm;
int ret;
 
+   if (vdec_dev->vdec_pdata->is_subdev_supported) {
+   subdev_dev = mtk_vcodec_get_hw_dev(vdec_dev, hw_idx);
+   if (!subdev_dev) {
+   mtk_v4l2_err("Failed to get hw dev\n");
+   return -EINVAL;
+   }
+   pm = _dev->pm;
+   } else {
+   pm = _dev->pm;
+   }
+
ret = pm_runtime_resume_and_get(pm->dev);
if (ret)
mtk_v4l2_err("pm_runtime_resume_and_get 

[PATCH v15, 07/19] dt-bindings: media: mtk-vcodec: Separate video encoder and decoder dt-bindings

2021-12-16 Thread Yunfei Dong
Separate decoder and encoder document for the dts are big difference.

Reviewed-by: Rob Herring
Signed-off-by: Yunfei Dong 
---
 .../media/mediatek,vcodec-decoder.yaml| 176 +
 .../media/mediatek,vcodec-encoder.yaml| 187 ++
 .../bindings/media/mediatek-vcodec.txt| 131 
 3 files changed, 363 insertions(+), 131 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/media/mediatek,vcodec-decoder.yaml
 create mode 100644 
Documentation/devicetree/bindings/media/mediatek,vcodec-encoder.yaml
 delete mode 100644 Documentation/devicetree/bindings/media/mediatek-vcodec.txt

diff --git 
a/Documentation/devicetree/bindings/media/mediatek,vcodec-decoder.yaml 
b/Documentation/devicetree/bindings/media/mediatek,vcodec-decoder.yaml
new file mode 100644
index ..df1d677098fd
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-decoder.yaml
@@ -0,0 +1,176 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/mediatek,vcodec-decoder.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek Video Decode Accelerator
+
+maintainers:
+  - Yunfei Dong 
+
+description: |+
+  Mediatek Video Decode is the video decode hardware present in Mediatek
+  SoCs which supports high resolution decoding functionalities.
+
+properties:
+  compatible:
+enum:
+  - mediatek,mt8173-vcodec-dec
+  - mediatek,mt8183-vcodec-dec
+
+  reg:
+maxItems: 12
+
+  interrupts:
+maxItems: 1
+
+  clocks:
+maxItems: 8
+
+  clock-names:
+items:
+  - const: vcodecpll
+  - const: univpll_d2
+  - const: clk_cci400_sel
+  - const: vdec_sel
+  - const: vdecpll
+  - const: vencpll
+  - const: venc_lt_sel
+  - const: vdec_bus_clk_src
+
+  assigned-clocks: true
+
+  assigned-clock-parents: true
+
+  assigned-clock-rates: true
+
+  power-domains:
+maxItems: 1
+
+  iommus:
+minItems: 1
+maxItems: 32
+description: |
+  List of the hardware port in respective IOMMU block for current Socs.
+  Refer to bindings/iommu/mediatek,iommu.yaml.
+
+  dma-ranges:
+maxItems: 1
+description: |
+  Describes the physical address space of IOMMU maps to memory.
+
+  mediatek,larb:
+$ref: /schemas/types.yaml#/definitions/phandle
+maxItems: 1
+description: |
+  Must contain the local arbiters in the current Socs.
+
+  mediatek,vpu:
+$ref: /schemas/types.yaml#/definitions/phandle
+maxItems: 1
+description:
+  Describes point to vpu.
+
+  mediatek,scp:
+$ref: /schemas/types.yaml#/definitions/phandle
+maxItems: 1
+description:
+  Describes point to scp.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - iommus
+  - assigned-clocks
+  - assigned-clock-parents
+
+allOf:
+  - if:
+  properties:
+compatible:
+  contains:
+enum:
+  - mediatek,mt8183-vcodec-dec
+
+then:
+  required:
+- mediatek,scp
+
+  - if:
+  properties:
+compatible:
+  contains:
+enum:
+  - mediatek,mt8173-vcodec-dec
+
+then:
+  required:
+- mediatek,vpu
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+#include 
+#include 
+#include 
+#include 
+
+vcodec_dec: vcodec@1600 {
+  compatible = "mediatek,mt8173-vcodec-dec";
+  reg = <0x1600 0x100>,   /*VDEC_SYS*/
+  <0x1602 0x1000>,  /*VDEC_MISC*/
+  <0x16021000 0x800>,   /*VDEC_LD*/
+  <0x16021800 0x800>,   /*VDEC_TOP*/
+  <0x16022000 0x1000>,  /*VDEC_CM*/
+  <0x16023000 0x1000>,  /*VDEC_AD*/
+  <0x16024000 0x1000>,  /*VDEC_AV*/
+  <0x16025000 0x1000>,  /*VDEC_PP*/
+  <0x16026800 0x800>,   /*VP8_VD*/
+  <0x16027000 0x800>,   /*VP6_VD*/
+  <0x16027800 0x800>,   /*VP8_VL*/
+  <0x16028400 0x400>;   /*VP9_VD*/
+  interrupts = ;
+  mediatek,larb = <>;
+  iommus = < M4U_PORT_HW_VDEC_MC_EXT>,
+ < M4U_PORT_HW_VDEC_PP_EXT>,
+ < M4U_PORT_HW_VDEC_AVC_MV_EXT>,
+ < M4U_PORT_HW_VDEC_PRED_RD_EXT>,
+ < M4U_PORT_HW_VDEC_PRED_WR_EXT>,
+ < M4U_PORT_HW_VDEC_UFO_EXT>,
+ < M4U_PORT_HW_VDEC_VLD_EXT>,
+ < M4U_PORT_HW_VDEC_VLD2_EXT>;
+  mediatek,vpu = <>;
+  power-domains = < MT8173_POWER_DOMAIN_VDEC>;
+  clocks = < CLK_APMIXED_VCODECPLL>,
+ < CLK_TOP_UNIVPLL_D2>,
+ < CLK_TOP_CCI400_SEL>,
+ < CLK_TOP_VDEC_SEL>,
+ < CLK_TOP_VCODECPLL>,
+ < CLK_APMIXED_VENCPLL>,
+ < CLK_TOP_VENC_LT_SEL>,
+ < CLK_TOP_VCODECPLL_370P5>;
+  clock-names = "vcodecpll",
+  "univpll_d2",
+  "clk_cci400_sel",
+  "vdec_sel",
+  "vdecpll",
+ 

[PATCH v15, 17/19] media: mtk-vcodec: Use codec type to separate different hardware

2021-12-16 Thread Yunfei Dong
There is just one core thread, in order to separate different
hardware, using codec type to separeate it in scp driver.

Signed-off-by: Yunfei Dong 
Reviewed-by: AngeloGioacchino Del Regno 

---
 .../media/platform/mtk-vcodec/vdec_ipi_msg.h  | 12 ---
 .../media/platform/mtk-vcodec/vdec_vpu_if.c   | 34 ---
 .../media/platform/mtk-vcodec/vdec_vpu_if.h   |  4 +++
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h 
b/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
index 9d8079c4f976..5daca8d52ebb 100644
--- a/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
+++ b/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
@@ -35,6 +35,8 @@ enum vdec_ipi_msgid {
  * @msg_id : vdec_ipi_msgid
  * @vpu_inst_addr : VPU decoder instance address. Used if ABI version < 2.
  * @inst_id : instance ID. Used if the ABI version >= 2.
+ * @codec_type : codec fourcc
+ * @reserved   : reserved param
  */
 struct vdec_ap_ipi_cmd {
uint32_t msg_id;
@@ -42,6 +44,8 @@ struct vdec_ap_ipi_cmd {
uint32_t vpu_inst_addr;
uint32_t inst_id;
};
+   uint32_t codec_type;
+   uint32_t reserved;
 };
 
 /**
@@ -59,12 +63,12 @@ struct vdec_vpu_ipi_ack {
 /**
  * struct vdec_ap_ipi_init - for AP_IPIMSG_DEC_INIT
  * @msg_id : AP_IPIMSG_DEC_INIT
- * @reserved   : Reserved field
+ * @codec_type : codec fourcc
  * @ap_inst_addr   : AP video decoder instance address
  */
 struct vdec_ap_ipi_init {
uint32_t msg_id;
-   uint32_t reserved;
+   uint32_t codec_type;
uint64_t ap_inst_addr;
 };
 
@@ -77,7 +81,7 @@ struct vdec_ap_ipi_init {
  * H264 decoder [0]:buf_sz [1]:nal_start
  * VP8 decoder  [0]:width/height
  * VP9 decoder  [0]:profile, [1][2] width/height
- * @reserved   : Reserved field
+ * @codec_type : codec fourcc
  */
 struct vdec_ap_ipi_dec_start {
uint32_t msg_id;
@@ -86,7 +90,7 @@ struct vdec_ap_ipi_dec_start {
uint32_t inst_id;
};
uint32_t data[3];
-   uint32_t reserved;
+   uint32_t codec_type;
 };
 
 /**
diff --git a/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c 
b/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
index bfd8e87dceff..c84fac52fe26 100644
--- a/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
@@ -100,18 +100,29 @@ static void vpu_dec_ipi_handler(void *data, unsigned int 
len, void *priv)
 
 static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len)
 {
-   int err;
+   int err, id, msgid;
 
-   mtk_vcodec_debug(vpu, "id=%X", *(uint32_t *)msg);
+   msgid = *(uint32_t *)msg;
+   mtk_vcodec_debug(vpu, "id=%X", msgid);
 
vpu->failure = 0;
vpu->signaled = 0;
 
-   err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, vpu->id, msg,
+   if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE) {
+   if (msgid == AP_IPIMSG_DEC_CORE ||
+   msgid == AP_IPIMSG_DEC_CORE_END)
+   id = vpu->core_id;
+   else
+   id = vpu->id;
+   } else {
+   id = vpu->id;
+   }
+
+   err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, id, msg,
 len, 2000);
if (err) {
mtk_vcodec_err(vpu, "send fail vpu_id=%d msg_id=%X status=%d",
-  vpu->id, *(uint32_t *)msg, err);
+  id, msgid, err);
return err;
}
 
@@ -131,6 +142,7 @@ static int vcodec_send_ap_ipi(struct vdec_vpu_inst *vpu, 
unsigned int msg_id)
msg.vpu_inst_addr = vpu->inst_addr;
else
msg.inst_id = vpu->inst_id;
+   msg.codec_type = vpu->codec_type;
 
err = vcodec_vpu_send_msg(vpu, , sizeof(msg));
mtk_vcodec_debug(vpu, "- id=%X ret=%d", msg_id, err);
@@ -149,14 +161,25 @@ int vpu_dec_init(struct vdec_vpu_inst *vpu)
 
err = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->id,
 vpu->handler, "vdec", NULL);
-   if (err != 0) {
+   if (err) {
mtk_vcodec_err(vpu, "vpu_ipi_register fail status=%d", err);
return err;
}
 
+   if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE) {
+   err = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler,
+vpu->core_id, vpu->handler,
+"vdec", NULL);
+   if (err) {
+   mtk_vcodec_err(vpu, "vpu_ipi_register core fail 
status=%d", err);
+   return err;
+   }
+   }
+
memset(, 0, sizeof(msg));
msg.msg_id = AP_IPIMSG_DEC_INIT;
msg.ap_inst_addr = (unsigned long)vpu;
+   msg.codec_type = vpu->codec_type;
 

[PATCH v15, 14/19] media: mtk-vcodec: Support 34bits dma address for vdec

2021-12-16 Thread Yunfei Dong
Use the dma_set_mask_and_coherent helper to set vdec
DMA bit mask to support 34bits iova space(16GB) that
the mt8192 iommu HW support.

Whole the iova range separate to 0~4G/4G~8G/8G~12G/12G~16G,
regarding which iova range VDEC actually locate, it
depends on the dma-ranges property of vdec dtsi node.

Reviewed-by: AngeloGioacchino Del Regno 

Signed-off-by: Yunfei Dong 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 10215ccc85f7..1c2b96b4930b 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -322,6 +322,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
}
}
 
+   if (of_get_property(pdev->dev.of_node, "dma-ranges", NULL)) {
+   ret = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(34));
+   if (ret) {
+   mtk_v4l2_err("Failed to set mask");
+   goto err_core_workq;
+   }
+   }
+
for (i = 0; i < MTK_VDEC_HW_MAX; i++)
mutex_init(>dec_mutex[i]);
mutex_init(>dev_mutex);
-- 
2.25.1



[PATCH v15, 08/19] media: mtk-vcodec: Use pure single core for MT8183

2021-12-16 Thread Yunfei Dong
Separates different architecture for hardware: pure_sin_core
and lat_sin_core. MT8183 is pure single core. Uses .hw_arch to
distinguish.

Reviewed-by: AngeloGioacchino Del Regno 

Signed-off-by: Yunfei Dong 
---
 .../platform/mtk-vcodec/mtk_vcodec_dec_stateful.c  |  1 +
 .../platform/mtk-vcodec/mtk_vcodec_dec_stateless.c |  2 ++
 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 10 ++
 3 files changed, 13 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
index c7f9259ad094..04ca43c77e5f 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
@@ -626,4 +626,5 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = {
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
.is_subdev_supported = false,
+   .hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
 };
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
index 3294c8957ae5..23d997ac114d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
@@ -357,6 +357,7 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = {
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
.is_subdev_supported = false,
+   .hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
 };
 
 /* This platform data is used for one lat and one core architecture. */
@@ -375,4 +376,5 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = {
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
.is_subdev_supported = true,
+   .hw_arch = MTK_VDEC_LAT_SINGLE_CORE,
 };
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 7f97fbf0f073..6d07bf997cc1 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -324,6 +324,14 @@ enum mtk_chip {
MTK_MT8195,
 };
 
+/**
+ * struct mtk_vdec_hw_arch - Used to separate different hardware architecture
+ */
+enum mtk_vdec_hw_arch {
+   MTK_VDEC_PURE_SINGLE_CORE,
+   MTK_VDEC_LAT_SINGLE_CORE,
+};
+
 /**
  * struct mtk_vcodec_dec_pdata - compatible data for each IC
  * @init_vdec_params: init vdec params
@@ -342,6 +350,7 @@ enum mtk_chip {
  * @num_framesizes: count of video decoder frame sizes
  *
  * @chip: chip this decoder is compatible with
+ * @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core
  *
  * @is_subdev_supported: whether support parent-node architecture(subdev)
  * @uses_stateless_api: whether the decoder uses the stateless API with 
requests
@@ -364,6 +373,7 @@ struct mtk_vcodec_dec_pdata {
const int num_framesizes;
 
enum mtk_chip chip;
+   enum mtk_vdec_hw_arch hw_arch;
 
bool is_subdev_supported;
bool uses_stateless_api;
-- 
2.25.1



[PATCH v15, 09/19] media: mtk-vcodec: Add irq interface for multi hardware

2021-12-16 Thread Yunfei Dong
Adds irq interface for multi hardware.

Reviewed-by: AngeloGioacchino Del Regno 

Signed-off-by: Yunfei Dong 
---
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  | 33 ---
 .../platform/mtk-vcodec/mtk_vcodec_dec_hw.c   |  2 +-
 .../platform/mtk-vcodec/mtk_vcodec_drv.h  | 25 ++
 .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c  |  4 +--
 .../platform/mtk-vcodec/mtk_vcodec_intr.c | 27 +++
 .../platform/mtk-vcodec/mtk_vcodec_intr.h |  4 +--
 .../platform/mtk-vcodec/vdec/vdec_h264_if.c   |  2 +-
 .../mtk-vcodec/vdec/vdec_h264_req_if.c|  2 +-
 .../platform/mtk-vcodec/vdec/vdec_vp8_if.c|  2 +-
 .../platform/mtk-vcodec/vdec/vdec_vp9_if.c|  2 +-
 .../platform/mtk-vcodec/venc/venc_h264_if.c   |  2 +-
 .../platform/mtk-vcodec/venc/venc_vp8_if.c|  2 +-
 12 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index f03f99108929..9802e5cc535f 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -24,6 +24,19 @@
 #include "mtk_vcodec_util.h"
 #include "mtk_vcodec_fw.h"
 
+static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev)
+{
+   switch (dev->vdec_pdata->hw_arch) {
+   case MTK_VDEC_PURE_SINGLE_CORE:
+   return MTK_VDEC_ONE_CORE;
+   case MTK_VDEC_LAT_SINGLE_CORE:
+   return MTK_VDEC_ONE_LAT_ONE_CORE;
+   default:
+   mtk_v4l2_err("hw arch %d not supported", 
dev->vdec_pdata->hw_arch);
+   return MTK_VDEC_NO_HW;
+   }
+}
+
 static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
 {
struct mtk_vcodec_dev *dev = priv;
@@ -55,7 +68,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void 
*priv)
writel((readl(vdec_misc_addr) & ~VDEC_IRQ_CLR),
dev->reg_base[VDEC_MISC] + VDEC_IRQ_CFG_REG);
 
-   wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
+   wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);
 
mtk_v4l2_debug(3,
"mtk_vcodec_dec_irq_handler :wake up ctx %d, 
dec_done_status=%x",
@@ -128,7 +141,7 @@ static int fops_vcodec_open(struct file *file)
 {
struct mtk_vcodec_dev *dev = video_drvdata(file);
struct mtk_vcodec_ctx *ctx = NULL;
-   int ret = 0;
+   int ret = 0, i, hw_count;
struct vb2_queue *src_vq;
 
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -142,14 +155,24 @@ static int fops_vcodec_open(struct file *file)
v4l2_fh_add(>fh);
INIT_LIST_HEAD(>list);
ctx->dev = dev;
-   init_waitqueue_head(>queue);
-   mutex_init(>lock);
+   if (ctx->dev->vdec_pdata->is_subdev_supported) {
+   hw_count = mtk_vcodec_get_hw_count(dev);
+   if (!hw_count || !dev->subdev_prob_done) {
+   ret = -EINVAL;
+   goto err_ctrls_setup;
+   }
 
-   if (dev->vdec_pdata->is_subdev_supported && dev->subdev_prob_done) {
ret = dev->subdev_prob_done(dev);
if (ret)
goto err_ctrls_setup;
+
+   for (i = 0; i < hw_count; i++)
+   init_waitqueue_head(>queue[i]);
+   } else {
+   init_waitqueue_head(>queue[0]);
}
+   mutex_init(>lock);
+
ctx->type = MTK_INST_DECODER;
ret = dev->vdec_pdata->ctrls_setup(ctx);
if (ret) {
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
index b6703b444827..b149c3058995 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
@@ -84,7 +84,7 @@ static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void 
*priv)
writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr);
writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr);
 
-   wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
+   wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx);
 
mtk_v4l2_debug(3, "wake up ctx %d, dec_done_status=%x",
ctx->id, dec_done_status);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 6d07bf997cc1..f62752fbab8c 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -104,6 +104,16 @@ enum mtk_vdec_hw_id {
MTK_VDEC_HW_MAX,
 };
 
+/**
+ * struct mtk_vdec_hw_count - Supported hardware count
+ */
+enum mtk_vdec_hw_count {
+   MTK_VDEC_NO_HW = 0,
+   MTK_VDEC_ONE_CORE,
+   MTK_VDEC_ONE_LAT_ONE_CORE,
+   MTK_VDEC_MAX_HW_COUNT,
+};
+
 /*
  * struct mtk_video_fmt - Structure used to store information about 
pixelformats
  */
@@ -293,9 +303,9 @@ struct mtk_vcodec_ctx {
struct vdec_pic_info picinfo;

[PATCH v15, 04/19] media: mtk-vcodec: export decoder pm functions

2021-12-16 Thread Yunfei Dong
When mtk vcodec decoder is build as a module, we need to export
mtk-vcodec-dec pm functions to make them visible by the other components.

Reviewed-by: AngeloGioacchino Del Regno 

Reviewed-by: Benjamin Gaignard 
Signed-off-by: Yunfei Dong 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index 20bd157a855c..221cf60e9fbf 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -77,12 +77,14 @@ int mtk_vcodec_init_dec_pm(struct platform_device *pdev,
put_device(pm->larbvdec);
return ret;
 }
+EXPORT_SYMBOL_GPL(mtk_vcodec_init_dec_pm);
 
 void mtk_vcodec_release_dec_pm(struct mtk_vcodec_pm *pm)
 {
pm_runtime_disable(pm->dev);
put_device(pm->larbvdec);
 }
+EXPORT_SYMBOL_GPL(mtk_vcodec_release_dec_pm);
 
 int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 {
@@ -94,6 +96,7 @@ int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(mtk_vcodec_dec_pw_on);
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
 {
@@ -103,6 +106,7 @@ void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
if (ret)
mtk_v4l2_err("pm_runtime_put_sync fail %d", ret);
 }
+EXPORT_SYMBOL_GPL(mtk_vcodec_dec_pw_off);
 
 void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm)
 {
@@ -129,6 +133,7 @@ void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm)
for (i -= 1; i >= 0; i--)
clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
 }
+EXPORT_SYMBOL_GPL(mtk_vcodec_dec_clock_on);
 
 void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
 {
@@ -139,3 +144,4 @@ void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
for (i = dec_clk->clk_num - 1; i >= 0; i--)
clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
 }
+EXPORT_SYMBOL_GPL(mtk_vcodec_dec_clock_off);
-- 
2.25.1



[PATCH v15, 10/19] media: mtk-vcodec: Add msg queue feature for lat and core architecture

2021-12-16 Thread Yunfei Dong
For lat and core architecture, lat thread will send message to core
thread when lat decode done. Core hardware will use the message
from lat to decode, then free message to lat thread when decode done.

Signed-off-by: Yunfei Dong 
---
 drivers/media/platform/mtk-vcodec/Makefile|   1 +
 .../platform/mtk-vcodec/mtk_vcodec_drv.h  |   9 +
 .../platform/mtk-vcodec/vdec_msg_queue.c  | 260 ++
 .../platform/mtk-vcodec/vdec_msg_queue.h  | 143 ++
 4 files changed, 413 insertions(+)
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_msg_queue.h

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index c61bfb179bcc..359619653a0e 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -12,6 +12,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
mtk_vcodec_dec_drv.o \
vdec_drv_if.o \
vdec_vpu_if.o \
+   vdec_msg_queue.o \
mtk_vcodec_dec.o \
mtk_vcodec_dec_stateful.o \
mtk_vcodec_dec_stateless.o \
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index f62752fbab8c..cbd602b7ecbb 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -15,7 +15,9 @@
 #include 
 #include 
 #include 
+
 #include "mtk_vcodec_util.h"
+#include "vdec_msg_queue.h"
 
 #define MTK_VCODEC_DRV_NAME"mtk_vcodec_drv"
 #define MTK_VCODEC_DEC_NAME"mtk-vcodec-dec"
@@ -282,6 +284,8 @@ struct vdec_pic_info {
  * @decoded_frame_cnt: number of decoded frames
  * @lock: protect variables accessed by V4L2 threads and worker thread such as
  *   mtk_video_dec_buf.
+ *
+ * @msg_queue: msg queue used to store lat buffer information.
  */
 struct mtk_vcodec_ctx {
enum mtk_instance_type type;
@@ -325,6 +329,7 @@ struct mtk_vcodec_ctx {
int decoded_frame_cnt;
struct mutex lock;
 
+   struct vdec_msg_queue msg_queue;
 };
 
 enum mtk_chip {
@@ -457,6 +462,8 @@ struct mtk_vcodec_enc_pdata {
  * @dec_capability: used to identify decode capability, ex: 4k
  * @enc_capability: used to identify encode capability
  *
+ * @msg_queue_core_ctx: msg queue context used for core workqueue
+ *
  * @subdev_dev: subdev hardware device
  * @subdev_prob_done: check whether all used hw device is prob done
  * @subdev_bitmap: used to record hardware is ready or not
@@ -498,6 +505,8 @@ struct mtk_vcodec_dev {
unsigned int dec_capability;
unsigned int enc_capability;
 
+   struct vdec_msg_queue_ctx msg_queue_core_ctx;
+
void *subdev_dev[MTK_VDEC_HW_MAX];
int (*subdev_prob_done)(struct mtk_vcodec_dev *vdec_dev);
DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX);
diff --git a/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c 
b/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
new file mode 100644
index ..913aefa67618
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Yunfei Dong 
+ */
+
+#include 
+#include 
+#include 
+
+#include "mtk_vcodec_dec_pm.h"
+#include "mtk_vcodec_drv.h"
+#include "vdec_msg_queue.h"
+
+#define VDEC_MSG_QUEUE_TIMEOUT_MS 1500
+
+/* the size used to store lat slice header information */
+#define VDEC_LAT_SLICE_HEADER_SZ(640 * SZ_1K)
+
+/* the size used to store avc error information */
+#define VDEC_ERR_MAP_SZ_AVC (17 * SZ_1K)
+
+/* core will read the trans buffer which decoded by lat to decode again.
+ * The trans buffer size of FHD and 4K bitstreams are different.
+ */
+static int vde_msg_queue_get_trans_size(int width, int height)
+{
+   if (width > 1920 || height > 1088)
+   return 30 * SZ_1M;
+   else
+   return 6 * SZ_1M;
+}
+
+void vdec_msg_queue_init_ctx(struct vdec_msg_queue_ctx *ctx, int 
hardware_index)
+{
+   init_waitqueue_head(>ready_to_use);
+   INIT_LIST_HEAD(>ready_queue);
+   spin_lock_init(>ready_lock);
+   ctx->ready_num = 0;
+   ctx->hardware_index = hardware_index;
+}
+
+static struct list_head *vdec_get_buf_list(int hardware_index, struct 
vdec_lat_buf *buf)
+{
+   switch (hardware_index) {
+   case MTK_VDEC_CORE:
+   return >core_list;
+   case MTK_VDEC_LAT0:
+   return >lat_list;
+   default:
+   return NULL;
+   }
+}
+
+int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct 
vdec_lat_buf *buf)
+{
+   struct list_head *head;
+
+   head = vdec_get_buf_list(msg_ctx->hardware_index, buf);
+   if (!head) {
+   mtk_v4l2_err("fail to qbuf: %d",msg_ctx->hardware_index);
+   return -EINVAL;
+   }
+
+   

[PATCH v15, 06/19] media: mtk-vcodec: Add to support multi hardware decode

2021-12-16 Thread Yunfei Dong
There are more than two hardwares for decoder: LAT0, LAT1 and CORE. In order to
manage these hardwares, register each hardware as independent platform device
for the larbs are different.

Each hardware module controls its own information which includes 
interrupt/power/
clocks/registers.

Calling of_platform_populate in parent device, and use subdev_bitmap to record
whether the hardwares are registered.

Reviewed-by: Steve Cho 
Signed-off-by: Yunfei Dong 
---
 drivers/media/platform/mtk-vcodec/Makefile|   5 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  85 +---
 .../platform/mtk-vcodec/mtk_vcodec_dec_hw.c   | 198 ++
 .../platform/mtk-vcodec/mtk_vcodec_dec_hw.h   |  49 +
 .../mtk-vcodec/mtk_vcodec_dec_stateful.c  |   1 +
 .../mtk-vcodec/mtk_vcodec_dec_stateless.c |   3 +
 .../platform/mtk-vcodec/mtk_vcodec_drv.h  |  21 ++
 7 files changed, 330 insertions(+), 32 deletions(-)
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index ca8e9e7a9c4e..c61bfb179bcc 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -2,7 +2,8 @@
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \
   mtk-vcodec-enc.o \
-  mtk-vcodec-common.o
+  mtk-vcodec-common.o \
+  mtk-vcodec-dec-hw.o
 
 mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
vdec/vdec_vp8_if.o \
@@ -16,6 +17,8 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
mtk_vcodec_dec_stateless.o \
mtk_vcodec_dec_pm.o \
 
+mtk-vcodec-dec-hw-y := mtk_vcodec_dec_hw.o
+
 mtk-vcodec-enc-y := venc/venc_vp8_if.o \
venc/venc_h264_if.o \
mtk_vcodec_enc.o \
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index c17927f79e22..f03f99108929 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -18,16 +18,12 @@
 
 #include "mtk_vcodec_drv.h"
 #include "mtk_vcodec_dec.h"
+#include "mtk_vcodec_dec_hw.h"
 #include "mtk_vcodec_dec_pm.h"
 #include "mtk_vcodec_intr.h"
 #include "mtk_vcodec_util.h"
 #include "mtk_vcodec_fw.h"
 
-#define VDEC_HW_ACTIVE 0x10
-#define VDEC_IRQ_CFG   0x11
-#define VDEC_IRQ_CLR   0x10
-#define VDEC_IRQ_CFG_REG   0xa4
-
 static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
 {
struct mtk_vcodec_dev *dev = priv;
@@ -92,6 +88,42 @@ static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev 
*dev)
return 0;
 }
 
+static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dev *dev)
+{
+   struct platform_device *pdev = dev->plat_dev;
+   int ret;
+
+   ret = mtk_vcodec_get_reg_bases(dev);
+   if (ret)
+   return ret;
+
+   if (dev->vdec_pdata->is_subdev_supported)
+   return 0;
+
+   dev->dec_irq = platform_get_irq(pdev, 0);
+   if (dev->dec_irq < 0) {
+   dev_err(>dev, "failed to get irq number");
+   return dev->dec_irq;
+   }
+
+   irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN);
+   ret = devm_request_irq(>dev, dev->dec_irq,
+   mtk_vcodec_dec_irq_handler, 0, pdev->name, dev);
+   if (ret) {
+   dev_err(>dev, "failed to install dev->dec_irq %d (%d)",
+   dev->dec_irq, ret);
+   return ret;
+   }
+
+   ret = mtk_vcodec_init_dec_pm(pdev, >pm);
+   if (ret < 0) {
+   dev_err(>dev, "failed to get mt vcodec clock source");
+   return ret;
+   }
+
+   return 0;
+}
+
 static int fops_vcodec_open(struct file *file)
 {
struct mtk_vcodec_dev *dev = video_drvdata(file);
@@ -113,6 +145,11 @@ static int fops_vcodec_open(struct file *file)
init_waitqueue_head(>queue);
mutex_init(>lock);
 
+   if (dev->vdec_pdata->is_subdev_supported && dev->subdev_prob_done) {
+   ret = dev->subdev_prob_done(dev);
+   if (ret)
+   goto err_ctrls_setup;
+   }
ctx->type = MTK_INST_DECODER;
ret = dev->vdec_pdata->ctrls_setup(ctx);
if (ret) {
@@ -217,7 +254,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 {
struct mtk_vcodec_dev *dev;
struct video_device *vfd_dec;
-   struct resource *res;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
int ret;
@@ -246,32 +282,10 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
if (IS_ERR(dev->fw_handler))
return PTR_ERR(dev->fw_handler);
 
-   ret = 

[PATCH v15, 03/19] media: mtk-vcodec: Refactor vcodec pm interface

2021-12-16 Thread Yunfei Dong
Using the needed params for pm init/release function and remove unused
param mtkdev in 'struct mtk_vcodec_pm'.

Reviewed-by: Tzung-Bi Shih 
Reviewed-by: AngeloGioacchino Del Regno 

Reviewed-by: Steve Cho 
Signed-off-by: Yunfei Dong 
---
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  6 ++---
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   | 22 ---
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.h   |  5 +++--
 .../platform/mtk-vcodec/mtk_vcodec_drv.h  |  1 -
 .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c   |  1 -
 5 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index e5f6e400a587..af235fa4c487 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -246,7 +246,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
if (IS_ERR(dev->fw_handler))
return PTR_ERR(dev->fw_handler);
 
-   ret = mtk_vcodec_init_dec_pm(dev);
+   ret = mtk_vcodec_init_dec_pm(dev->plat_dev, >pm);
if (ret < 0) {
dev_err(>dev, "Failed to get mt vcodec clock source");
goto err_dec_pm;
@@ -377,7 +377,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
 err_dec_alloc:
v4l2_device_unregister(>v4l2_dev);
 err_res:
-   mtk_vcodec_release_dec_pm(dev);
+   mtk_vcodec_release_dec_pm(>pm);
 err_dec_pm:
mtk_vcodec_fw_release(dev->fw_handler);
return ret;
@@ -416,7 +416,7 @@ static int mtk_vcodec_dec_remove(struct platform_device 
*pdev)
video_unregister_device(dev->vfd_dec);
 
v4l2_device_unregister(>v4l2_dev);
-   mtk_vcodec_release_dec_pm(dev);
+   mtk_vcodec_release_dec_pm(>pm);
mtk_vcodec_fw_release(dev->fw_handler);
return 0;
 }
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index 6038db96f71c..20bd157a855c 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -13,18 +13,15 @@
 #include "mtk_vcodec_dec_pm.h"
 #include "mtk_vcodec_util.h"
 
-int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
+int mtk_vcodec_init_dec_pm(struct platform_device *pdev,
+   struct mtk_vcodec_pm *pm)
 {
struct device_node *node;
-   struct platform_device *pdev;
-   struct mtk_vcodec_pm *pm;
+   struct platform_device *larb_pdev;
struct mtk_vcodec_clk *dec_clk;
struct mtk_vcodec_clk_info *clk_info;
int i = 0, ret = 0;
 
-   pdev = mtkdev->plat_dev;
-   pm = >pm;
-   pm->mtkdev = mtkdev;
dec_clk = >vdec_clk;
node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
if (!node) {
@@ -32,13 +29,12 @@ int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
return -1;
}
 
-   pdev = of_find_device_by_node(node);
+   larb_pdev = of_find_device_by_node(node);
of_node_put(node);
-   if (WARN_ON(!pdev)) {
+   if (WARN_ON(!larb_pdev)) {
return -1;
}
-   pm->larbvdec = >dev;
-   pdev = mtkdev->plat_dev;
+   pm->larbvdec = _pdev->dev;
pm->dev = >dev;
 
dec_clk->clk_num =
@@ -82,10 +78,10 @@ int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
return ret;
 }
 
-void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev)
+void mtk_vcodec_release_dec_pm(struct mtk_vcodec_pm *pm)
 {
-   pm_runtime_disable(dev->pm.dev);
-   put_device(dev->pm.larbvdec);
+   pm_runtime_disable(pm->dev);
+   put_device(pm->larbvdec);
 }
 
 int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h
index 280aeaefdb65..a3df6aef6cb9 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h
@@ -9,8 +9,9 @@
 
 #include "mtk_vcodec_drv.h"
 
-int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *dev);
-void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev);
+int mtk_vcodec_init_dec_pm(struct platform_device *pdev,
+   struct mtk_vcodec_pm *pm);
+void mtk_vcodec_release_dec_pm(struct mtk_vcodec_pm *pm);
 
 int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 1d2370608d0d..0fa9d85114b9 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -195,7 +195,6 @@ struct mtk_vcodec_pm {
struct mtk_vcodec_clk   venc_clk;
struct device   *larbvenc;
struct device   *dev;
-   struct mtk_vcodec_dev   *mtkdev;
 

[PATCH v15, 00/19] Support multi hardware decode using of_platform_populate

2021-12-16 Thread Yunfei Dong
This series adds support for multi hardware decode into mtk-vcodec, by first 
adding use
of_platform_populate to manage each hardware information: interrupt, clock, 
register
bases and power. Secondly add core work queue to deal with core hardware 
message,
at the same time, add msg queue for different hardware share messages. Lastly, 
the
architecture of different specs are not the same, using specs type to separate 
them.

This series has been tested with both MT8183 and MT8173. Decoding was working 
for both chips.

Patches 1~3 rewrite get register bases and power on/off interface.
Patches 4 export decoder pm interfaces.
Patches 5 add to support 8192.
Patch 6 support multi hardware.
Patch 7 separate video encoder and decoder document
Patch 8-17 add interfaces to support core hardware.
Patch 18-19 remove mtk_vcodec_release_dec/enc_pm interfaces.
---
changes compared with v13:
- rebase to latest media stage.

changes compared with v13:
- change some function position in case of ko dependency for patch 15.
- add reviewed-by for patch 06/13/15.

changes compared with v12:
- fix comments from rob for patch 15.
- fix comments from steve for 06 and 13.

changes compared with v11:
- fix comments from AngeloGioacchino for patch 09~11/19.
- fix comments from steve for patch 03/19.

changes compared with v10:
- fix comments from tzung-bi for patch 06/19.
- add more detail information for hardware block diagram 15/19

changes compared with v9:
- need not to build ko, just export pm interfaces for patch 04/19.
- fix comments for patch 06/19

changes compared with v8:
- add new patch 18~19 to remove mtk_vcodec_release_de/enc_pm interfaces.
- fix spelling mistakes for patch 17/19
- fix yaml comments for patch 15/19

Changes compared with v7:
- add new patch 4 to build decoder pm file as module
- add new patch 5 to support 8192
- fix comments for patch 6/17
- change some logic for using work queue instead of create thread for core 
hardware decode for patch 10/17
- using work queue for hardware decode instead of create thread for patch 13/17
- add returen value for patch 14/17
- fix yaml check fail 15/17

Changes compared with v6:
- Use of_platform_populate to manage multi hardware, not component framework 
for patch 4/15
- Re-write dtsi document for hardware architecture changed for patch 13/15 -The 
dtsi will write like below in patch 13/15:
vcodec_dec: vcodec_dec@1600 {
compatible = "mediatek,mt8192-vcodec-dec";
#address-cells = <2>;
#size-cells = <2>;
ranges;
reg = <0 0x1600 0 0x1000>;  /* VDEC_SYS */
mediatek,scp = <>;
iommus = < M4U_PORT_L4_VDEC_MC_EXT>;
dma-ranges = <0x1 0x0 0x0 0x4000 0x0 0xfff0>;
vcodec_lat {
compatible = "mediatek,mtk-vcodec-lat";
reg = <0 0x1601 0 0x800>;   /* VDEC_MISC */
reg-name = "reg-misc";
interrupts = ;
iommus = < M4U_PORT_L5_VDEC_LAT0_VLD_EXT>,
 < M4U_PORT_L5_VDEC_LAT0_VLD2_EXT>,
 < M4U_PORT_L5_VDEC_LAT0_AVC_MV_EXT>,
 < M4U_PORT_L5_VDEC_LAT0_PRED_RD_EXT>,
 < M4U_PORT_L5_VDEC_LAT0_TILE_EXT>,
 < M4U_PORT_L5_VDEC_LAT0_WDMA_EXT>,
 < M4U_PORT_L5_VDEC_LAT0_RG_CTRL_DMA_EXT>,
 < M4U_PORT_L5_VDEC_UFO_ENC_EXT>;
clocks = < CLK_TOP_VDEC_SEL>,
 <_soc CLK_VDEC_SOC_VDEC>,
 <_soc CLK_VDEC_SOC_LAT>,
 <_soc CLK_VDEC_SOC_LARB1>,
 < CLK_TOP_MAINPLL_D4>;
clock-names = "vdec-sel", "vdec-soc-vdec", "vdec-soc-lat",
  "vdec-vdec", "vdec-top";
assigned-clocks = < CLK_TOP_VDEC_SEL>;
assigned-clock-parents = < CLK_TOP_MAINPLL_D4>;
power-domains = < MT8192_POWER_DOMAIN_VDEC>;
};

vcodec_core {
compatible = "mediatek,mtk-vcodec-core";
reg = <0 0x16025000 0 0x1000>;  /* VDEC_CORE_MISC */
reg-names = "reg-misc";
interrupts = ;
iommus = < M4U_PORT_L4_VDEC_MC_EXT>,
 < M4U_PORT_L4_VDEC_UFO_EXT>,
 < M4U_PORT_L4_VDEC_PP_EXT>,
 < M4U_PORT_L4_VDEC_PRED_RD_EXT>,
 < M4U_PORT_L4_VDEC_PRED_WR_EXT>,
 < M4U_PORT_L4_VDEC_PPWRAP_EXT>,
 < M4U_PORT_L4_VDEC_TILE_EXT>,
 < M4U_PORT_L4_VDEC_VLD_EXT>,
 < M4U_PORT_L4_VDEC_VLD2_EXT>,
 < M4U_PORT_L4_VDEC_AVC_MV_EXT>,
 < M4U_PORT_L4_VDEC_RG_CTRL_DMA_EXT>;
clocks = < CLK_TOP_VDEC_SEL>,
 < CLK_VDEC_VDEC>,
 < CLK_VDEC_LAT>,
 < CLK_VDEC_LARB1>,
 < CLK_TOP_MAINPLL_D4>;
clock-names = "vdec-sel", "vdec-soc-vdec", "vdec-soc-lat",
  "vdec-vdec", "vdec-top";
assigned-clocks = < CLK_TOP_VDEC_SEL>;

[PATCH v15, 05/19] media: mtk-vcodec: Support MT8192

2021-12-16 Thread Yunfei Dong
From: Yunfei Dong 

Adds MT8192's compatible "mediatek,mt8192-vcodec-dec".
Adds MT8192's device private data mtk_lat_sig_core_pdata.

Reviewed-by: AngeloGioacchino Del Regno 

Signed-off-by: Yunfei Dong 
---
 .../media/platform/mtk-vcodec/mtk_vcodec_dec.h   |  1 +
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c |  4 
 .../mtk-vcodec/mtk_vcodec_dec_stateless.c| 16 
 3 files changed, 21 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
index e08886a600a3..66cd6d2242c3 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
@@ -68,6 +68,7 @@ extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops;
 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;
 
 
 /*
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index af235fa4c487..c17927f79e22 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -392,6 +392,10 @@ static const struct of_device_id mtk_vcodec_match[] = {
.compatible = "mediatek,mt8183-vcodec-dec",
.data = _vdec_8183_pdata,
},
+   {
+   .compatible = "mediatek,mt8192-vcodec-dec",
+   .data = _lat_sig_core_pdata,
+   },
{},
 };
 
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
index 3d9f47555884..183cd67a334a 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
@@ -357,3 +357,19 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = {
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
 };
+
+const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = {
+   .chip = MTK_MT8192,
+   .init_vdec_params = mtk_init_vdec_params,
+   .ctrls_setup = mtk_vcodec_dec_ctrls_setup,
+   .vdec_vb2_ops = _vdec_request_vb2_ops,
+   .vdec_formats = mtk_video_formats,
+   .num_formats = NUM_FORMATS,
+   .default_out_fmt = _video_formats[DEFAULT_OUT_FMT_IDX],
+   .default_cap_fmt = _video_formats[DEFAULT_CAP_FMT_IDX],
+   .vdec_framesizes = mtk_vdec_framesizes,
+   .num_framesizes = NUM_SUPPORTED_FRAMESIZE,
+   .uses_stateless_api = true,
+   .worker = mtk_vdec_worker,
+   .flush_decoder = mtk_vdec_flush_decoder,
+};
-- 
2.25.1



[PATCH v15, 02/19] media: mtk-vcodec: Align vcodec wake up interrupt interface

2021-12-16 Thread Yunfei Dong
Vdec and venc can use the same function to wake up interrupt event.

Reviewed-by: Tzung-Bi Shih 
Reviewed-by: AngeloGioacchino Del Regno 

Reviewed-by: Steve Cho 
Signed-off-by: Yunfei Dong 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 9 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 8 
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 8 
 3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index e1a82e233971..e5f6e400a587 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -28,13 +28,6 @@
 #define VDEC_IRQ_CLR   0x10
 #define VDEC_IRQ_CFG_REG   0xa4
 
-/* Wake up context wait_queue */
-static void wake_up_ctx(struct mtk_vcodec_ctx *ctx)
-{
-   ctx->int_cond = 1;
-   wake_up_interruptible(>queue);
-}
-
 static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
 {
struct mtk_vcodec_dev *dev = priv;
@@ -66,7 +59,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void 
*priv)
writel((readl(vdec_misc_addr) & ~VDEC_IRQ_CLR),
dev->reg_base[VDEC_MISC] + VDEC_IRQ_CFG_REG);
 
-   wake_up_ctx(ctx);
+   wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
 
mtk_v4l2_debug(3,
"mtk_vcodec_dec_irq_handler :wake up ctx %d, 
dec_done_status=%x",
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 581522177308..1d2370608d0d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -473,4 +473,12 @@ static inline struct mtk_vcodec_ctx *ctrl_to_ctx(struct 
v4l2_ctrl *ctrl)
return container_of(ctrl->handler, struct mtk_vcodec_ctx, ctrl_hdl);
 }
 
+/* Wake up context wait_queue */
+static inline void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason)
+{
+   ctx->int_cond = 1;
+   ctx->int_type = reason;
+   wake_up_interruptible(>queue);
+}
+
 #endif /* _MTK_VCODEC_DRV_H_ */
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index aeaecb8d416e..027546108f44 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -62,14 +62,6 @@ static const struct mtk_video_fmt 
mtk_video_formats_capture_vp8[] =  {
},
 };
 
-/* Wake up context wait_queue */
-static void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason)
-{
-   ctx->int_cond = 1;
-   ctx->int_type = reason;
-   wake_up_interruptible(>queue);
-}
-
 static void clean_irq_status(unsigned int irq_status, void __iomem *addr)
 {
if (irq_status & MTK_VENC_IRQ_STATUS_PAUSE)
-- 
2.25.1



[PATCH v15, 01/19] media: mtk-vcodec: Get numbers of register bases from DT

2021-12-16 Thread Yunfei Dong
Different platforms may have different numbers of register bases. Gets the
numbers of register bases from dts (sizeof(u32) * 4 bytes for each).

Reviewed-by: Tzung-Bi Shih
Signed-off-by: Yunfei Dong 
---
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  | 37 ++-
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 40c39e1e596b..e1a82e233971 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -75,6 +75,30 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void 
*priv)
return IRQ_HANDLED;
 }
 
+static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev)
+{
+   struct platform_device *pdev = dev->plat_dev;
+   int reg_num, i;
+
+   /* Sizeof(u32) * 4 bytes for each register base. */
+   reg_num = of_property_count_elems_of_size(pdev->dev.of_node, "reg",
+   sizeof(u32) * 4);
+   if (reg_num <= 0 || reg_num > NUM_MAX_VDEC_REG_BASE) {
+   dev_err(>dev, "Invalid register property size: %d\n", 
reg_num);
+   return -EINVAL;
+   }
+
+   for (i = 0; i < reg_num; i++) {
+   dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i);
+   if (IS_ERR(dev->reg_base[i]))
+   return PTR_ERR(dev->reg_base[i]);
+
+   mtk_v4l2_debug(2, "reg[%d] base=%p", i, dev->reg_base[i]);
+   }
+
+   return 0;
+}
+
 static int fops_vcodec_open(struct file *file)
 {
struct mtk_vcodec_dev *dev = video_drvdata(file);
@@ -203,7 +227,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
struct resource *res;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
-   int i, ret;
+   int ret;
 
dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -235,14 +259,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_dec_pm;
}
 
-   for (i = 0; i < NUM_MAX_VDEC_REG_BASE; i++) {
-   dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i);
-   if (IS_ERR((__force void *)dev->reg_base[i])) {
-   ret = PTR_ERR((__force void *)dev->reg_base[i]);
-   goto err_res;
-   }
-   mtk_v4l2_debug(2, "reg[%d] base=%p", i, dev->reg_base[i]);
-   }
+   ret = mtk_vcodec_get_reg_bases(dev);
+   if (ret)
+   goto err_res;
 
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (res == NULL) {
-- 
2.25.1



[PATCH] drm/tegra: vic: Handle tegra_drm_alloc() failure

2021-12-16 Thread Thierry Reding
From: Thierry Reding 

This function can return one of several errors in an ERR_PTR()-encoded
pointer, so make sure to propogate those on failure.

Suggested-by: Robin Murphy 
Signed-off-by: Thierry Reding 
---
 drivers/gpu/drm/tegra/vic.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c
index c5f4d2b13c43..7d2b719ed8d1 100644
--- a/drivers/gpu/drm/tegra/vic.c
+++ b/drivers/gpu/drm/tegra/vic.c
@@ -237,6 +237,8 @@ static int vic_load_firmware(struct vic *vic)
return -ENOMEM;
} else {
virt = tegra_drm_alloc(tegra, size, );
+   if (IS_ERR(virt))
+   return PTR_ERR(virt);
}
 
vic->falcon.firmware.virt = virt;
-- 
2.34.1



Re: [PATCH v2 03/11] drm/tegra: vic: Fix DMA API misuse

2021-12-16 Thread Thierry Reding
On Fri, Dec 10, 2021 at 05:54:44PM +, Robin Murphy wrote:
> Upon failure, dma_alloc_coherent() returns NULL. If that does happen,
> passing some uninitialised stack contents to dma_mapping_error() - which
> belongs to a different API in the first place - has precious little
> chance of detecting it.
> 
> Also include the correct header, because the fragile transitive
> inclusion currently providing it is going to break soon.
> 
> Fixes: 20e7dce255e9 ("drm/tegra: Remove memory allocation from Falcon 
> library")
> CC: Thierry Reding 
> CC: Mikko Perttunen 
> CC: dri-devel@lists.freedesktop.org
> Signed-off-by: Robin Murphy 
> 
> ---
> 
> It also doesn't appear to handle failure of the tegra_drm_alloc() path
> either, but that's a loose thread I have no desire to pull on... ;)
> 
> v2: Resend as part of the series, originally posted separately here:
> 
> https://lore.kernel.org/dri-devel/2703882439344010e33bf21ecd63cf9e5e6dc00d.1637781007.git.robin.mur...@arm.com/
> 
>  drivers/gpu/drm/tegra/vic.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)

Applied, thanks. I've also fixed up the missing failure handling for
tegra_drm_alloc(), which was actually quite trivial to do.

Thierry


signature.asc
Description: PGP signature


Re: [PATCH v2 02/11] gpu: host1x: Add missing DMA API include

2021-12-16 Thread Thierry Reding
On Fri, Dec 10, 2021 at 05:54:43PM +, Robin Murphy wrote:
> Host1x seems to be relying on picking up dma-mapping.h transitively from
> iova.h, which has no reason to include it in the first place. Fix the
> former issue before we totally break things by fixing the latter one.
> 
> CC: Thierry Reding 
> CC: Mikko Perttunen 
> CC: dri-devel@lists.freedesktop.org
> Signed-off-by: Robin Murphy 
> ---
> 
> v2: No change
> 
>  drivers/gpu/host1x/bus.c | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks.

Thierry


signature.asc
Description: PGP signature


Re: [Intel-gfx] [PATCH] drm/i915/guc: Check for wedged before doing stuff

2021-12-16 Thread Tvrtko Ursulin




On 15/12/2021 22:45, john.c.harri...@intel.com wrote:

From: John Harrison 

A fault injection probe test hit a BUG_ON in a GuC error path. It
showed that the GuC code could potentially attempt to do many things
when the device is actually wedged. So, add a check in to prevent that.

Signed-off-by: John Harrison 
---
  drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c 
b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
index 9739da6f..88f002c4d41b 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
@@ -1350,7 +1350,8 @@ submission_disabled(struct intel_guc *guc)
struct i915_sched_engine * const sched_engine = guc->sched_engine;
  
  	return unlikely(!sched_engine ||

-   !__tasklet_is_enabled(_engine->tasklet));
+   !__tasklet_is_enabled(_engine->tasklet) ||
+   test_bit(I915_WEDGED, _to_gt(guc)->reset.flags));


Or intel_gt_is_wedged ?

Regards,

Tvrtko


  }
  
  static void disable_submission(struct intel_guc *guc)




Re: [PATCH v4 2/3] drm/vc4: plane: Add support for DRM_FORMAT_P030

2021-12-16 Thread Maxime Ripard
Hi Thomas,

Thanks for your review

On Wed, Dec 15, 2021 at 04:11:50PM +0100, Thomas Zimmermann wrote:
> Hi,
> 
> I have a number of comments below. But if you want, you can add
> 
> Acked-by: Thomas Zimmermann 

Thanks :)

> Am 15.12.21 um 10:17 schrieb Maxime Ripard:
> > From: Dave Stevenson 
> > 
> > The P030 format, used with the DRM_FORMAT_MOD_BROADCOM_SAND128 modifier,
> > is a format output by the video decoder on the BCM2711.
> > 
> > Add native support to the KMS planes for that format.
> > 
> > Signed-off-by: Dave Stevenson 
> > Signed-off-by: Maxime Ripard 
> > ---
> >   drivers/gpu/drm/vc4/vc4_plane.c | 127 
> >   1 file changed, 96 insertions(+), 31 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vc4/vc4_plane.c 
> > b/drivers/gpu/drm/vc4/vc4_plane.c
> > index ac761c683663..022cd12f561e 100644
> > --- a/drivers/gpu/drm/vc4/vc4_plane.c
> > +++ b/drivers/gpu/drm/vc4/vc4_plane.c
> > @@ -33,6 +33,7 @@ static const struct hvs_format {
> > u32 hvs; /* HVS_FORMAT_* */
> > u32 pixel_order;
> > u32 pixel_order_hvs5;
> > +   bool hvs5_only;
> >   } hvs_formats[] = {
> > {
> > .drm = DRM_FORMAT_XRGB,
> > @@ -128,6 +129,12 @@ static const struct hvs_format {
> > .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_2PLANE,
> > .pixel_order = HVS_PIXEL_ORDER_XYCRCB,
> > },
> > +   {
> > +   .drm = DRM_FORMAT_P030,
> > +   .hvs = HVS_PIXEL_FORMAT_YCBCR_10BIT,
> > +   .pixel_order = HVS_PIXEL_ORDER_XYCBCR,
> > +   .hvs5_only = true,
> > +   },
> >   };
> >   static const struct hvs_format *vc4_get_hvs_format(u32 drm_format)
> > @@ -762,47 +769,90 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
> > case DRM_FORMAT_MOD_BROADCOM_SAND128:
> > case DRM_FORMAT_MOD_BROADCOM_SAND256: {
> > uint32_t param = fourcc_mod_broadcom_param(fb->modifier);
> > -   u32 tile_w, tile, x_off, pix_per_tile;
> > -
> > -   hvs_format = HVS_PIXEL_FORMAT_H264;
> > -
> > -   switch (base_format_mod) {
> > -   case DRM_FORMAT_MOD_BROADCOM_SAND64:
> > -   tiling = SCALER_CTL0_TILING_64B;
> > -   tile_w = 64;
> > -   break;
> > -   case DRM_FORMAT_MOD_BROADCOM_SAND128:
> > -   tiling = SCALER_CTL0_TILING_128B;
> > -   tile_w = 128;
> > -   break;
> > -   case DRM_FORMAT_MOD_BROADCOM_SAND256:
> > -   tiling = SCALER_CTL0_TILING_256B_OR_T;
> > -   tile_w = 256;
> > -   break;
> > -   default:
> > -   break;
> > -   }
> > if (param > SCALER_TILE_HEIGHT_MASK) {
> > -   DRM_DEBUG_KMS("SAND height too large (%d)\n", param);
> > +   DRM_DEBUG_KMS("SAND height too large (%d)\n",
> > + param);
> 
> Should be good for the 100-character limit.
> 
> > return -EINVAL;
> > }
> > -   pix_per_tile = tile_w / fb->format->cpp[0];
> > -   tile = vc4_state->src_x / pix_per_tile;
> > -   x_off = vc4_state->src_x % pix_per_tile;
> > +   if (fb->format->format == DRM_FORMAT_P030) {
> > +   hvs_format = HVS_PIXEL_FORMAT_YCBCR_10BIT;
> > +   tiling = SCALER_CTL0_TILING_128B;
> > +   } else {
> > +   hvs_format = HVS_PIXEL_FORMAT_H264;
> > +
> > +   switch (base_format_mod) {
> > +   case DRM_FORMAT_MOD_BROADCOM_SAND64:
> > +   tiling = SCALER_CTL0_TILING_64B;
> > +   break;
> > +   case DRM_FORMAT_MOD_BROADCOM_SAND128:
> > +   tiling = SCALER_CTL0_TILING_128B;
> > +   break;
> > +   case DRM_FORMAT_MOD_BROADCOM_SAND256:
> > +   tiling = SCALER_CTL0_TILING_256B_OR_T;
> > +   break;
> > +   default:
> > +   return -EINVAL;
> 
> It's not atomic modesetting? I'm asking because the code returns errno codes
> in several places.

This is atomic modesetting, but we're allowed to return an error at this
point :)

The function name is a bit confusing but it's mostly due to how the
hardware operates. We don't have the usual register set for the
composition but instead we have a list of hardware descriptors that will
describe the next frame.

The driver builds it here, at atomic_check time, and then copy it to the
hardware at atomic_commit time. So even though it's called
vc4_plane_mode_set, and does the operations needed to setup the
composition properly, we're still in atomic_check at this point.

> > +   }
> > +   }
> > /* Adjust the base pointer to the first pixel to be scanned
> >  * out.
> > +*
> > +* For 

Re: [PATCH 6/7] drm/amdgpu: Ensure kunmap is called on error

2021-12-16 Thread Christian König

Am 15.12.21 um 22:09 schrieb Ira Weiny:

On Tue, Dec 14, 2021 at 08:09:29AM +0100, Christian König wrote:

Am 14.12.21 um 04:37 schrieb Ira Weiny:

On Mon, Dec 13, 2021 at 09:37:32PM +0100, Christian König wrote:

Am 11.12.21 um 00:24 schrieb ira.we...@intel.com:

From: Ira Weiny 

The default case leaves the buffer object mapped in error.

Add amdgpu_bo_kunmap() to that case to ensure the mapping is cleaned up.

Mhm, good catch. But why do you want to do this in the first place?

I'm not sure I understand the question.

Any mapping of memory should be paired with an unmapping when no longer needed.
And this is supported by the call to amdgpu_bo_kunmap() in the other
non-default cases.

Do you believe the mapping is not needed?

No, the unmapping is not needed here. See the function amdgpu_bo_kmap(), it
either creates the mapping or return the cached pointer.

Ah I missed that.  Thanks.


A call to amdgpu_bo_kunmap() is only done in a few places where we know that
the created mapping most likely won't be needed any more. If that's not done
the mapping is automatically destroyed when the BO is moved or freed up.

I mean good bug fix, but you seem to see this as some kind of prerequisite
to some follow up work converting TTM to use kmap_local() which most likely
won't work in the first place.

Sure.  I see now that it is more complicated than I thought but I never thought
of this as a strict prerequisite.  Just something I found while trying to
figure out how this works.

How much of a speed up is it to maintain the ttm_bo_map_kmap map type?


Good question. I don't really know.

This used to be pretty important for older drivers since there the 
kernel needs to kmap individual pages and patch them up before sending 
the command stream to the hardware.


It most likely doesn't matter for modern hardware.


Could this all be done with vmap and just remove the kmap stuff?


Maybe, but I wouldn't bet on it and I don't really want to touch any of 
the old drivers to figure that out.


Christian.



Ira


Regards,
Christian.


Ira


Christian.


Signed-off-by: Ira Weiny 

---
NOTE: It seems like this function could use a fair bit of refactoring
but this is the easiest way to fix the actual bug.
---
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 1 +
1 file changed, 1 insertion(+)
nice
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index 6f8de11a17f1..b3ffd0f6b35f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -889,6 +889,7 @@ static int amdgpu_uvd_cs_msg(struct amdgpu_uvd_cs_ctx *ctx,
return 0;
default:
+   amdgpu_bo_kunmap(bo);
DRM_ERROR("Illegal UVD message type (%d)!\n", msg_type);
}




[PULL] drm-misc-fixes

2021-12-16 Thread Maxime Ripard
Hi Dave, Daniel,

Here's this week drm-misc-fixes PR.

Note that dim pull-request was stalling when generating the email, so I
had to send this with git request-pull, hence the odd tag name and the
format slightly different.

Maxime

The following changes since commit b19926d4f3a660a8b76e5d989ffd1168e619a5c4:

  drm/syncobj: Deal with signalled fences in drm_syncobj_find_fence. 
(2021-12-08 17:19:48 +0100)

are available in the Git repository at:

  ssh://git.freedesktop.org/git/drm/drm-misc tags/drm-misc-fixes-2021-12-16-1

for you to fetch changes up to fea3fdf975dd9f3e5248afaab8fe023db313f005:

  drm/ast: potential dereference of null pointer (2021-12-14 09:18:28 +0100)


One null pointer dereference fix for ast, a pixel clock unit fix for
simpledrm and a user-space regression revert for fb-helper


Alejandro Concepcion-Rodriguez (1):
  drm: simpledrm: fix wrong unit with pixel clock

Javier Martinez Canillas (1):
  Revert "drm/fb-helper: improve DRM fbdev emulation device names"

Jiasheng Jiang (1):
  drm/ast: potential dereference of null pointer

 drivers/gpu/drm/ast/ast_mode.c   | 5 -
 drivers/gpu/drm/drm_fb_helper.c  | 8 +++-
 drivers/gpu/drm/tiny/simpledrm.c | 2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)


signature.asc
Description: PGP signature


Re: [PATCH 11/60] drm/gud: Add support for the nomodeset kernel parameter

2021-12-16 Thread Thomas Zimmermann

Hi

Am 15.12.21 um 22:37 schrieb Noralf Trønnes:



Den 15.12.2021 01.59, skrev Javier Martinez Canillas:

According to disable Documentation/admin-guide/kernel-parameters.txt, this
parameter can be used to disable kernel modesetting.

DRM drivers will not perform display-mode changes or accelerated rendering
and only the systewm system framebuffer will be available if it was set-up.

But only a few DRM drivers currently check for nomodeset, make this driver
to also support the command line parameter.

Signed-off-by: Javier Martinez Canillas 
---



I don't understand why this is applicable to USB drivers, there's no way
the firmware can setup a framebuffer and continue pushing pixels over
USB when Linux has been given control over the USB bus?

The same argument goes for the SPI drivers in drm/tiny/ as well.


The intended semantics of the option is to disable every display output 
except for the buffer provided by the firmware.


With USB it still would still disable the driver. That's useful if only 
for debugging. There are also systems with hard-wired USB displays where 
one cannot just unplug the adapter.


Admittedly, USB graphics is a bit of an odd use case, but neither is it 
too far fetched IMHO.


Best regards
Thomas



Noralf.


  drivers/gpu/drm/gud/gud_drv.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
index 3f9d4b9a1e3d..4d253d249512 100644
--- a/drivers/gpu/drm/gud/gud_drv.c
+++ b/drivers/gpu/drm/gud/gud_drv.c
@@ -446,6 +446,9 @@ static int gud_probe(struct usb_interface *intf, const 
struct usb_device_id *id)
u32 *formats;
int ret, i;
  
+	if (drm_firmware_drivers_only())

+   return -ENODEV;
+
ret = usb_find_bulk_out_endpoint(intf->cur_altsetting, _out);
if (ret)
return ret;



--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev


OpenPGP_signature
Description: OpenPGP digital signature


Re: [PATCH] drm/amdgpu: fix mismatch warning between the prototype and function name

2021-12-16 Thread Christian König

Am 16.12.21 um 05:39 schrieb Huang Rui:

Fix the typo to align with the prototype and function name.

All warnings (new ones prefixed by >>):


drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c:631: warning: expecting

prototype for amdgpu_fence_clear_job_fences(). Prototype was for
amdgpu_fence_driver_clear_job_fences() instead

Reported-by: kernel test robot 
Signed-off-by: Huang Rui 


Reviewed-by: Christian König 


---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index db41d16838b9..9afd11ca2709 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -622,7 +622,7 @@ void amdgpu_fence_driver_hw_init(struct amdgpu_device *adev)
  }
  
  /**

- * amdgpu_fence_clear_job_fences - clear job embedded fences of ring
+ * amdgpu_fence_driver_clear_job_fences - clear job embedded fences of ring
   *
   * @ring: fence of the ring to be cleared
   *




Re: 回复: Re: [PATCH] drm/amdgpu: fixup bad vram size on gmc v8

2021-12-16 Thread Christian König

Hi Zongmin,

that strongly sounds like the ASIC is not correctly initialized when 
trying to read the register.


What board and environment are you using this GPU with? Is that a normal 
x86 system?


Regards,
Christian.

Am 16.12.21 um 04:11 schrieb 周宗敏:


1.

the problematic boards that I have tested is [AMD/ATI] Lexa PRO
[Radeon RX 550/550X] ;  and the vbios version : 113-RXF9310-C09-BT

2.

When an exception occurs I can see the following changes in the
values of vram size get from RREG32(mmCONFIG_MEMSIZE) ,

it seems to have garbage in the upper 16 bits

image.png


3.

and then I can also see some dmesg like below:

when vram size register have garbage,we may see error message like
below:

amdgpu :09:00.0: VRAM: 4286582784M 0x00F4 -
0x000FF8F4 (4286582784M used)

the correct message should like below:

amdgpu :09:00.0: VRAM: 4096M 0x00F4 -
0x00F4 (4096M used)


if you have any problems,please send me mail.

thanks very much.




*主 题:*Re: [PATCH] drm/amdgpu: fixup bad vram size on gmc v8
*日 期:*2021-12-16 04:23
*发件人:*Alex Deucher
*收件人:*Zongmin Zhou


On Wed, Dec 15, 2021 at 10:31 AM Zongmin Zhouwrote:
>
> Some boards(like RX550) seem to have garbage in the upper
> 16 bits of the vram size register.  Check for
> this and clamp the size properly.  Fixes
> boards reporting bogus amounts of vram.
>
> after add this patch,the maximum GPU VRAM size is 64GB,
> otherwise only 64GB vram size will be used.

Can you provide some examples of problematic boards and possibly a
vbios image from the problematic board?  What values are you seeing?
It would be nice to see what the boards are reporting and whether the
lower 16 bits are actually correct or if it is some other issue.  This
register is undefined until the asic has been initialized.  The vbios
programs it as part of it's asic init sequence (either via vesa/gop or
the OS driver).

Alex


>
> Signed-off-by: Zongmin Zhou
> ---
>  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 13 ++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

> index 492ebed2915b..63b890f1e8af 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> @@ -515,10 +515,10 @@ static void gmc_v8_0_mc_program(struct 
amdgpu_device *adev)

>  static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
>  {
>         int r;
> +       u32 tmp;
>
>         adev->gmc.vram_width = amdgpu_atombios_get_vram_width(adev);
>         if (!adev->gmc.vram_width) {
> -               u32 tmp;
>                 int chansize, numchan;
>
>                 /* Get VRAM informations */
> @@ -562,8 +562,15 @@ static int gmc_v8_0_mc_init(struct 
amdgpu_device *adev)

>                 adev->gmc.vram_width = numchan * chansize;
>         }
>         /* size in MB on si */
> -       adev->gmc.mc_vram_size = RREG32(mmCONFIG_MEMSIZE) * 1024ULL 
* 1024ULL;
> -       adev->gmc.real_vram_size = RREG32(mmCONFIG_MEMSIZE) * 
1024ULL * 1024ULL;

> +       tmp = RREG32(mmCONFIG_MEMSIZE);
> +       /* some boards may have garbage in the upper 16 bits */
> +       if (tmp & 0x) {
> +               DRM_INFO("Probable bad vram size: 0x%08x\n", tmp);
> +               if (tmp & 0x)
> +                       tmp &= 0x;
> +       }
> +       adev->gmc.mc_vram_size = tmp * 1024ULL * 1024ULL;
> +       adev->gmc.real_vram_size = adev->gmc.mc_vram_size;
>
>         if (!(adev->flags & AMD_IS_APU)) {
>                 r = amdgpu_device_resize_fb_bar(adev);
> --
> 2.25.1
>
>
> No virus found
>                 Checked by Hillstone Network AntiVirus





<    1   2   3