mtk_vcodec_fw_vpu.c (2950B)
1// SPDX-License-Identifier: GPL-2.0 2 3#include "mtk_vcodec_fw_priv.h" 4#include "mtk_vcodec_util.h" 5#include "mtk_vcodec_drv.h" 6 7static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw) 8{ 9 return vpu_load_firmware(fw->pdev); 10} 11 12static unsigned int mtk_vcodec_vpu_get_vdec_capa(struct mtk_vcodec_fw *fw) 13{ 14 return vpu_get_vdec_hw_capa(fw->pdev); 15} 16 17static unsigned int mtk_vcodec_vpu_get_venc_capa(struct mtk_vcodec_fw *fw) 18{ 19 return vpu_get_venc_hw_capa(fw->pdev); 20} 21 22static void *mtk_vcodec_vpu_map_dm_addr(struct mtk_vcodec_fw *fw, 23 u32 dtcm_dmem_addr) 24{ 25 return vpu_mapping_dm_addr(fw->pdev, dtcm_dmem_addr); 26} 27 28static int mtk_vcodec_vpu_set_ipi_register(struct mtk_vcodec_fw *fw, int id, 29 mtk_vcodec_ipi_handler handler, 30 const char *name, void *priv) 31{ 32 /* 33 * The handler we receive takes a void * as its first argument. We 34 * cannot change this because it needs to be passed down to the rproc 35 * subsystem when SCP is used. VPU takes a const argument, which is 36 * more constrained, so the conversion below is safe. 37 */ 38 ipi_handler_t handler_const = (ipi_handler_t)handler; 39 40 return vpu_ipi_register(fw->pdev, id, handler_const, name, priv); 41} 42 43static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf, 44 unsigned int len, unsigned int wait) 45{ 46 return vpu_ipi_send(fw->pdev, id, buf, len); 47} 48 49static void mtk_vcodec_vpu_release(struct mtk_vcodec_fw *fw) 50{ 51 put_device(&fw->pdev->dev); 52} 53 54static void mtk_vcodec_vpu_reset_handler(void *priv) 55{ 56 struct mtk_vcodec_dev *dev = priv; 57 struct mtk_vcodec_ctx *ctx; 58 59 mtk_v4l2_err("Watchdog timeout!!"); 60 61 mutex_lock(&dev->dev_mutex); 62 list_for_each_entry(ctx, &dev->ctx_list, list) { 63 ctx->state = MTK_STATE_ABORT; 64 mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ABORT", 65 ctx->id); 66 } 67 mutex_unlock(&dev->dev_mutex); 68} 69 70static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = { 71 .load_firmware = mtk_vcodec_vpu_load_firmware, 72 .get_vdec_capa = mtk_vcodec_vpu_get_vdec_capa, 73 .get_venc_capa = mtk_vcodec_vpu_get_venc_capa, 74 .map_dm_addr = mtk_vcodec_vpu_map_dm_addr, 75 .ipi_register = mtk_vcodec_vpu_set_ipi_register, 76 .ipi_send = mtk_vcodec_vpu_ipi_send, 77 .release = mtk_vcodec_vpu_release, 78}; 79 80struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(struct mtk_vcodec_dev *dev, 81 enum mtk_vcodec_fw_use fw_use) 82{ 83 struct platform_device *fw_pdev; 84 struct mtk_vcodec_fw *fw; 85 enum rst_id rst_id; 86 87 switch (fw_use) { 88 case ENCODER: 89 rst_id = VPU_RST_ENC; 90 break; 91 case DECODER: 92 default: 93 rst_id = VPU_RST_DEC; 94 break; 95 } 96 97 fw_pdev = vpu_get_plat_device(dev->plat_dev); 98 if (!fw_pdev) { 99 mtk_v4l2_err("firmware device is not ready"); 100 return ERR_PTR(-EINVAL); 101 } 102 vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_handler, dev, rst_id); 103 104 fw = devm_kzalloc(&dev->plat_dev->dev, sizeof(*fw), GFP_KERNEL); 105 if (!fw) 106 return ERR_PTR(-ENOMEM); 107 fw->type = VPU; 108 fw->ops = &mtk_vcodec_vpu_msg; 109 fw->pdev = fw_pdev; 110 111 return fw; 112}