Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp212859rdb; Sun, 28 Jan 2024 22:36:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgLxH5vV1q7KY8Rp/QxOJbjLWASfZIlHFda+DHUfO0rVKn58RF7IyKdEVk3rsAottGM2ZG X-Received: by 2002:a67:c982:0:b0:46b:5db3:705 with SMTP id y2-20020a67c982000000b0046b5db30705mr344839vsk.7.1706510179686; Sun, 28 Jan 2024 22:36:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510179; cv=pass; d=google.com; s=arc-20160816; b=ZWZPFwQkU2XZBB7C8aAdinyTpYyF54PaZrw9X9tnLq/oeAbgKb3J0Qd96wV18Ge1lV mOgj70jeWnAThe6vqjAGimRZ2JpdDGpnW4DPsORjPib6EzbEybtTPJywPMvoZwp9wDEn esEq17XYedpTlelqy+U/HAEw0spLR+NM951MScOainpMvJGShzKEyN2F2kbqmnUm7oH/ XKzvWCMiSLq1hA6HMwzmTB8RumxKZOfRPICey0bnv0wz/Jft13hChWfpv0jDShMq8eoC qN7dA6UdvE0IFoTPrxfsUdzKjon67PmtEeFJpbHnTfP+tIXN8J0Qcx1y+HPxgyRCcRus Wm+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PmOOl2O3YzoSfT/A/8Z58sBZCN9D2jNsNyNSD5AkJgw=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=dqNRyeDw4geU4lLdmMWRLQpm6ZN+mfHolGwbrhLVNwF26XxHrPtLze4Z9mNKFgqJwz +/ESkAH0psKwG2aAKkysVQsKUdxBdQGq4vztCACqZgUM256YxKDHZ9vijwL6JMaVLA2p buLNsEWUvjGCVTtOgR5/dOK90dWf0QabiZ0xwkxsrE8hikLmgYS+esbQo+BUnUD+//w4 uC2oMwkcLxJXMYWcxJF8Udf7i1bRy1j0cXKmMq0ICw84C/LrFV+E2p/z2sOIOCxmoE8O HFBKhmAh25VROydOQ9ytKKYQxiSFrLIjucQhJMsKi6GBK+maXCotJ0FsOyxHAlPkaPI6 NjHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=b2a1vxbM; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z2-20020a17090a6d0200b00290d27a0d8dsi7273749pjj.137.2024.01.28.22.36.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:36:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=b2a1vxbM; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4BF6F281396 for ; Mon, 29 Jan 2024 06:36:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAD7D4EB41; Mon, 29 Jan 2024 06:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="b2a1vxbM" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50B5658108; Mon, 29 Jan 2024 06:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509874; cv=none; b=ZAkbryEP/Qjf17AZRGp1lS30xIZ+7R1PwucAurlKQcHNeCdm0cq2wtczxXEE66t7OY5xBz0KZi3ZRo1Hq/vnjaqKJMI53ajits0nppxRpseMr1UddmPGJc4X6X9y0qf8NoKqa9BGMyNBLlZ7tzZpx7QlMp/d4uhmnedjuMVhOVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509874; c=relaxed/simple; bh=/6+O2DvCvaRrnJB9bxhSwFGAlKjPZTOCA3qHJa3WTII=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tz09AUnRBOXzQTTuZqGvClocJZ8h+61nPTSUtQqhT5HtTTK8eitVBY6qF6m0197ZLwnmYm4c3q61xfuXNN/2hkq2qLVghkoNL+tdb452+xL/GEYAQaIu65YC4xkPlIF8COhqkK4x5sH+vIgrbojkykYMA08kfTVOMRpjLCefvmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=b2a1vxbM; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: fb7ebf0cbe6f11ee9e680517dc993faa-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=PmOOl2O3YzoSfT/A/8Z58sBZCN9D2jNsNyNSD5AkJgw=; b=b2a1vxbMcKc44uA7bW7WJni0TO6cmCbmA4eHlJkGUgYI+tsgulVaaNfFF2B8B6+x7tvYeOXMa6s3ssoT7LPqVdYg94/62KcPCKFWReFgnrwd+F8/bYxTxidjHRLApEvMbEJ6pp69xx7GCISGiSpYzp5rz5VACo49ufQ9KQAfQso=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:668d8314-dcc7-40e0-b915-626f897365a5,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:6e16cf4,CLOUDID:22aa5c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: fb7ebf0cbe6f11ee9e680517dc993faa-20240129 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2113761936; Mon, 29 Jan 2024 14:31:06 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:31:05 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:31:04 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?UTF-8?q?Christian=20K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,22/22] media: mediatek: vcodec: support hevc svp for mt8188 Date: Mon, 29 Jan 2024 14:30:25 +0800 Message-ID: <20240129063025.29251-23-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--9.969000-8.000000 X-TMASE-MatchedRID: NfE/lF/5OguvVT6bfkFW/gI0yP/uoH+DHgnyJJNAX/iHlDUCu0I+XO2V VVLUIzQwThbvLLI8RvOmGallF1XuaCGlT4FPpKFRpKSqN+Z3dp7bKTxp3+WtIDb9TB28UbkiqOl iuKBSJDcMHdYgr1Lbr4LbE+EfcVAHf/ojZMms99/huXUWQoMQt8SgMQYKGHsJ2CEUkv53/lWjxY yRBa/qJcFwgTvxipFajoczmuoPCq1C0yBL+I+hsS03ud7wGfVKfkZ3WdlbJT6mLGqhwSLJ4MsRe kXH5xNr X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--9.969000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: B9D33A707E9575B1CF97B30D67B728600DC2FBF1A68ECC4E7A8DF3EE4B5888EA2000:8 X-MTK: N Change hevc driver to support secure video playback(svp) for mt8188. Need to map shared memory with optee interface and wait interrupt in optee-os. Signed-off-by: Yunfei Dong --- .../decoder/vdec/vdec_hevc_req_multi_if.c | 89 +++++++++++-------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c index 06ed47df693b..8bf4bc13ae2d 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c @@ -415,11 +415,14 @@ static void vdec_hevc_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx, hevc_dpb_info[index].field = dpb->field_pic; hevc_dpb_info[index].y_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0); - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) - hevc_dpb_info[index].c_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 1); - else - hevc_dpb_info[index].c_dma_addr = - hevc_dpb_info[index].y_dma_addr + ctx->picinfo.fb_sz[0]; + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) + hevc_dpb_info[index].c_dma_addr = + vb2_dma_contig_plane_dma_addr(vb, 1); + else + hevc_dpb_info[index].c_dma_addr = + hevc_dpb_info[index].y_dma_addr + ctx->picinfo.fb_sz[0]; + } } } @@ -800,7 +803,7 @@ static int vdec_hevc_slice_setup_core_buffer(struct vdec_hevc_slice_inst *inst, struct mtk_vcodec_dec_ctx *ctx = inst->ctx; struct vb2_v4l2_buffer *vb2_v4l2; struct vdec_fb *fb; - u64 y_fb_dma, c_fb_dma; + u64 y_fb_dma, c_fb_dma = 0; int i; fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx); @@ -810,18 +813,20 @@ static int vdec_hevc_slice_setup_core_buffer(struct vdec_hevc_slice_inst *inst, } y_fb_dma = (u64)fb->base_y.dma_addr; - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) - c_fb_dma = - y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; - else - c_fb_dma = (u64)fb->base_c.dma_addr; + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) + c_fb_dma = + y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; + else + c_fb_dma = (u64)fb->base_c.dma_addr; + } mtk_vdec_debug(inst->ctx, "[hevc-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma); inst->vsi_core->fb.y.dma_addr = y_fb_dma; inst->vsi_core->fb.y.size = ctx->picinfo.fb_sz[0]; inst->vsi_core->fb.c.dma_addr = c_fb_dma; - inst->vsi_core->fb.y.size = ctx->picinfo.fb_sz[1]; + inst->vsi_core->fb.c.size = ctx->picinfo.fb_sz[1]; inst->vsi_core->dec.vdec_fb_va = (unsigned long)fb; @@ -878,8 +883,13 @@ static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx) vsi_size = round_up(sizeof(struct vdec_hevc_slice_vsi), VCODEC_DEC_ALIGNED_64); inst->vsi = inst->vpu.vsi; - inst->vsi_core = - (struct vdec_hevc_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); + if (ctx->is_secure_playback) + inst->vsi_core = + mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE, + OPTEE_DATA_INDEX); + else + inst->vsi_core = + (struct vdec_hevc_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); inst->resolution_changed = true; inst->realloc_mv_buf = true; @@ -944,21 +954,22 @@ static int vdec_hevc_slice_core_decode(struct vdec_lat_buf *lat_buf) goto vdec_dec_end; } - /* wait decoder done interrupt */ - timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); - if (timeout) - mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt); - inst->vsi_core->dec.timeout = !!timeout; + if (!vpu->ctx->is_secure_playback) { + /* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); + if (timeout) + mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt); + inst->vsi_core->dec.timeout = !!timeout; - vpu_dec_core_end(vpu); - mtk_vdec_debug(ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", - ctx->decoded_frame_cnt, + vpu_dec_core_end(vpu); + } + mtk_vdec_debug(ctx, "pic[%d] svp:%d crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", + ctx->decoded_frame_cnt, ctx->is_secure_playback, inst->vsi_core->dec.crc[0], inst->vsi_core->dec.crc[1], inst->vsi_core->dec.crc[2], inst->vsi_core->dec.crc[3], inst->vsi_core->dec.crc[4], inst->vsi_core->dec.crc[5], inst->vsi_core->dec.crc[6], inst->vsi_core->dec.crc[7]); - vdec_dec_end: vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->trans.dma_addr_end); ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->src_buf_req); @@ -1015,14 +1026,17 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf); } - /* wait decoder done interrupt */ - timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0); - if (timeout) - mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num); - inst->vsi->dec.timeout = !!timeout; + if (!inst->ctx->is_secure_playback) { + /* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0); + if (timeout) + mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num); + inst->vsi->dec.timeout = !!timeout; + + err = vpu_dec_end(vpu); + } - err = vpu_dec_end(vpu); if (err == SLICE_HEADER_FULL || err == TRANS_BUFFER_FULL) { if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf); @@ -1031,8 +1045,11 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, return -EINVAL; } - share_info->trans.dma_addr_end = inst->ctx->msg_queue.wdma_addr.dma_addr + - inst->vsi->dec.wdma_end_addr_offset; + if (inst->ctx->is_secure_playback) + share_info->trans.dma_addr_end = inst->vsi->dec.wdma_end_addr_offset; + else + share_info->trans.dma_addr_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + inst->vsi->dec.wdma_end_addr_offset; vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue, share_info->trans.dma_addr_end); if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) { @@ -1040,8 +1057,10 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, sizeof(share_info->hevc_slice_params)); vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf); } - mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x 0x%x", inst->slice_dec_num, - inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], inst->vsi->dec.crc[2]); + + mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x 0x%x 0x%x size:%d", + inst->slice_dec_num, inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], + inst->vsi->dec.crc[2], inst->vsi->dec.crc[3], (unsigned int)bs->size); inst->slice_dec_num++; return 0; -- 2.18.0