media: mtk-vcodec: venc: handle firmware version field
authorAlexandre Courbot <acourbot@chromium.org>
Fri, 21 Aug 2020 10:35:56 +0000 (12:35 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sat, 26 Sep 2020 08:04:39 +0000 (10:04 +0200)
Firmwares for encoders newer than MT8173 will include an ABI version
number in their initialization ack message. Add the capacity to manage
it and make initialization fail if the firmware ABI is of a version that
we don't support.

For MT8173, this ABI version field is reserved and thus undefined ; thus
ignore it on this chip. There should only be one firmware version available
for it anyway.

Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
Acked-by: Tiffany Lin <tiffany.lin@mediatek.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
drivers/media/platform/mtk-vcodec/venc_ipi_msg.h
drivers/media/platform/mtk-vcodec/venc_vpu_if.c

index e92e52c0e601d511218e3d4e5219bb25acef8126..1676c26eb229dd2d1f05f6a1f98b83a220eb923d 100644 (file)
@@ -300,13 +300,21 @@ struct mtk_vcodec_ctx {
 
 };
 
+enum mtk_chip {
+       MTK_MT8173,
+};
+
 /**
  * struct mtk_vcodec_enc_pdata - compatible data for each IC
  *
+ * @chip: chip this encoder is compatible with
+ *
  * @uses_ext: whether the encoder uses the extended firmware messaging format
  * @has_lt_irq: whether the encoder uses the LT irq
  */
 struct mtk_vcodec_enc_pdata {
+       enum mtk_chip chip;
+
        bool uses_ext;
        bool has_lt_irq;
 };
index 6ee3bd5453cb3dcc6260fb21c5c464054c156a9d..fd17724f29f62b577e93491104b8afba53db94b6 100644 (file)
@@ -393,6 +393,7 @@ err_enc_pm:
 }
 
 static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
+       .chip = MTK_MT8173,
        .has_lt_irq = true,
 };
 
index 316f8ecd6b4cf75b0d3a7c98e8ac4e1db043af48..2feb0365179fd1f822105ebcaa9478126dd81217 100644 (file)
@@ -138,16 +138,17 @@ struct venc_vpu_ipi_msg_common {
  * @venc_inst: AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
  * @vpu_inst_addr:     VPU encoder instance addr
  *                     (struct venc_vp8_vsi/venc_h264_vsi *)
- * @reserved:  reserved for future use. vpu is running in 32bit. Without
- *             this reserved field, if kernel run in 64bit. this struct size
- *             will be different between kernel and vpu
+ * @venc_abi_version:  ABI version of the firmware. Kernel can use it to
+ *                     ensure that it is compatible with the firmware.
+ *                     For MT8173 the value of this field is undefined and
+ *                     should not be used.
  */
 struct venc_vpu_ipi_msg_init {
        uint32_t msg_id;
        uint32_t status;
        uint64_t venc_inst;
        uint32_t vpu_inst_addr;
-       uint32_t reserved;
+       uint32_t venc_abi_version;
 };
 
 /**
index 1eb546f606989757ff1ed627ea0e9e6ede0f396e..be6d8790a41e1ef70aba3f97deb340df0eb69175 100644 (file)
@@ -4,6 +4,7 @@
  * Author: PoChun Lin <pochun.lin@mediatek.com>
  */
 
+#include "mtk_vcodec_drv.h"
 #include "mtk_vcodec_fw.h"
 #include "venc_ipi_msg.h"
 #include "venc_vpu_if.h"
@@ -15,6 +16,23 @@ static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data)
        vpu->inst_addr = msg->vpu_inst_addr;
        vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler,
                                             msg->vpu_inst_addr);
+
+       /* Firmware version field value is unspecified on MT8173. */
+       if (vpu->ctx->dev->venc_pdata->chip == MTK_MT8173)
+               return;
+
+       /* Check firmware version. */
+       mtk_vcodec_debug(vpu, "firmware version: 0x%x\n",
+                        msg->venc_abi_version);
+       switch (msg->venc_abi_version) {
+       case 1:
+               break;
+       default:
+               mtk_vcodec_err(vpu, "unhandled firmware version 0x%x\n",
+                              msg->venc_abi_version);
+               vpu->failure = 1;
+               break;
+       }
 }
 
 static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, const void *data)
@@ -35,6 +53,11 @@ static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
        mtk_vcodec_debug(vpu, "msg_id %x inst %p status %d",
                         msg->msg_id, vpu, msg->status);
 
+       vpu->signaled = 1;
+       vpu->failure = (msg->status != VENC_IPI_MSG_STATUS_OK);
+       if (vpu->failure)
+               goto failure;
+
        switch (msg->msg_id) {
        case VPU_IPIMSG_ENC_INIT_DONE:
                handle_enc_init_msg(vpu, data);
@@ -51,9 +74,7 @@ static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
                break;
        }
 
-       vpu->signaled = 1;
-       vpu->failure = (msg->status != VENC_IPI_MSG_STATUS_OK);
-
+failure:
        mtk_vcodec_debug_leave(vpu);
 }