Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp820941rdb; Wed, 6 Dec 2023 00:18:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzrP1AAK+ZTcOLirApw8u8WVZ1zxlVDhfZhzDeW26gZp+ILvT9pEMkL1mlssR6YaVdYtzR X-Received: by 2002:a17:90a:d916:b0:286:6cc1:867b with SMTP id c22-20020a17090ad91600b002866cc1867bmr283069pjv.96.1701850709757; Wed, 06 Dec 2023 00:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850709; cv=none; d=google.com; s=arc-20160816; b=yavDNfmCnutLWsBI6ig+L/tV++27jRO3JTDWe2/eA1MfkuVmHJfnhw3q7QHn+RIwCr FFRClnIN3Bjh2qWDbwVgISGvXJfXePNQxcNjEy+S5qR+hIagkJGfgErmltArCas5mLjy SNPB0kG42lGpan11jaM6devM2ymeMyyMy6fihDYKH7RrINQRaSFer/7nblWmOkIJScqH WZw2hTSXfQS9cWH8CuW/vw/UluJmlbbgqy68g7aKERzv0jdLAjKOvNFaep7XSUwafdD0 pw4gbaRaafVGtJRYiRxzAlaBNkzD7tGa4E4JIdDeDYb899sTQfYJm8JBp+6wKqerk+xM nXXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fkKb5yQu6eO4lpu8D+KYAkmtnU9wVZAoaiHbbjuUHtM=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=jBrCBZC1gMQDzBlLQzpL1A4k3Hf9ysX/tpaLpGIE9WBldqXXv0UBSFIubttnj9xrJk FmJYfruCqTcixVc+p/m2ZLdVSppiQKZzzrhYfT6E4A/UmxOGb9LGatRU5uzuv1GoeJGM kkBj0c89QyIya5Q4k2pYbXWGviJZGC6slIfCG4YIP/YforQtztavn/I7iEVps8hYvR7h E75iqa1oYUneF+qTyE59pRmoIkl7wvjOEFi4wUbsJtcmSt99lc/P/1s4Tm6ZITS/iU6m 50GA0zxoF2Eg3lI8bxZtK1Lst4KaaHf7C9V6R/uWn2/haP0ODEj4p28FL6uJ3vJG08qE i3Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=nLsq66PV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id pi11-20020a17090b1e4b00b002869a5326ddsi5660512pjb.75.2023.12.06.00.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:18:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=nLsq66PV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 16120802FA32; Wed, 6 Dec 2023 00:18:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377171AbjLFIRk (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377339AbjLFIQv (ORCPT ); Wed, 6 Dec 2023 03:16:51 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F1719B6; Wed, 6 Dec 2023 00:16:18 -0800 (PST) X-UUID: b6228a86940f11ee8051498923ad61e6-20231206 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=fkKb5yQu6eO4lpu8D+KYAkmtnU9wVZAoaiHbbjuUHtM=; b=nLsq66PVRaWr2fSoiq+WhRgjwDW/rCwuZlwIs5JLYggoaTzVhLQwjADw2bVPm9YPggr8dyI7dkWziTzXUoLtKiH9f8xuDSyUrB7rFT67CJ3ejRTZE97QdI0HuLuSrHb/GynFDsCLDUDlKq6q6t0AJZk20kUFccye8rgpYnKM/X8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:31d90100-0b0f-4061-9618-e2e446142fba,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:abefa75,CLOUDID:b02d59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File: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: b6228a86940f11ee8051498923ad61e6-20231206 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1117160729; Wed, 06 Dec 2023 16:16:09 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 6 Dec 2023 16:16:07 +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; Wed, 6 Dec 2023 16:16:06 +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 v3,21/21] media: mediatek: vcodec: move vdec init interface to setup callback Date: Wed, 6 Dec 2023 16:15:38 +0800 Message-ID: <20231206081538.17056-22-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> 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--3.356300-8.000000 X-TMASE-MatchedRID: EDRXIQlfXt//ybP4IWJkikKcYi5Qw/RVFpw9gj8mywrfUZT83lbkENro EGQiudNyiYTHezvcK04K3OrJWcpBViwmW5mXIeVjzfqlpbtmcWi50iD18ixmy/gnJH5vm2+gZ2X jE62VgUUxZUOt0FF52sKXwA+sRKv1Gj8XjDB40G5Na4UOfkJSNH0tCKdnhB589yM15V5aWpj6C0 ePs7A07fhmFHnZFzVqMy6bDKK4NkHdcJT5YYQWyMMV4WK4hhsonPk1U1ip1fFxAqP9WRFBCYAqt ckHv8VFsP9RRQG7ErZPWfegSDaC08hohL0hluIT8jae4OD13tAV7Mc+rowcVKtX/F0pBwVJjSV5 hDFby7ZnIxZyJs78kg== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--3.356300-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 3A487E5DD73C21F27353616BBD3FB3362469D0F8B1A852A975DAB46E5A1DDCBF2000:8 X-MTK: N X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:18:22 -0800 (PST) Getting secure video playback (svp) flag when request output buffer, then calling init interface to init svp parameters in optee-os. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 144 ++++++++++++------ 1 file changed, 94 insertions(+), 50 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c index ab922e8d2d37..3639beac20cb 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -184,6 +184,74 @@ void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_dec_ctx *ctx) q_data->bytesperline[1] = q_data->coded_width; } +static int mtk_vcodec_dec_init_pic_info(struct mtk_vcodec_dec_ctx *ctx, enum v4l2_buf_type type) +{ + const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata; + struct mtk_q_data *q_data; + int ret; + + if (!ctx->current_codec) + return 0; + + if (V4L2_TYPE_IS_OUTPUT(type) && ctx->state == MTK_STATE_FREE) { + q_data = mtk_vdec_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); + if (!q_data) + return -EINVAL; + + ret = vdec_if_init(ctx, q_data->fmt->fourcc); + if (ret) { + mtk_v4l2_vdec_err(ctx, "[%d]: vdec_if_init() fail ret=%d", + ctx->id, ret); + return -EINVAL; + } + ctx->state = MTK_STATE_INIT; + } + + if (!dec_pdata->uses_stateless_api) + return 0; + + /* + * If get pic info fail, need to use the default pic info params, or + * v4l2-compliance will fail + */ + ret = vdec_if_get_param(ctx, GET_PARAM_PIC_INFO, &ctx->picinfo); + if (ret) { + mtk_v4l2_vdec_err(ctx, "[%d]Error!! Get GET_PARAM_PICTURE_INFO Fail", + ctx->id); + } + + ctx->last_decoded_picinfo = ctx->picinfo; + + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) { + ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = + ctx->picinfo.fb_sz[0] + + ctx->picinfo.fb_sz[1]; + ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = + ctx->picinfo.buf_w; + } else { + if (ctx->is_secure_playback) + ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = + ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + else + ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = ctx->picinfo.fb_sz[0]; + + ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = ctx->picinfo.buf_w; + ctx->q_data[MTK_Q_DATA_DST].sizeimage[1] = ctx->picinfo.fb_sz[1]; + ctx->q_data[MTK_Q_DATA_DST].bytesperline[1] = ctx->picinfo.buf_w; + } + + ctx->q_data[MTK_Q_DATA_DST].coded_width = ctx->picinfo.buf_w; + ctx->q_data[MTK_Q_DATA_DST].coded_height = ctx->picinfo.buf_h; + mtk_v4l2_vdec_dbg(2, ctx, + "[%d] init() plane:%d wxh=%dx%d pic wxh=%dx%d sz=0x%x_0x%x", + ctx->id, q_data->fmt->num_planes, + ctx->picinfo.buf_w, ctx->picinfo.buf_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->q_data[MTK_Q_DATA_DST].sizeimage[0], + ctx->q_data[MTK_Q_DATA_DST].sizeimage[1]); + return 0; +} + static int vidioc_vdec_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) { @@ -479,17 +547,7 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, ctx->ycbcr_enc = pix_mp->ycbcr_enc; ctx->quantization = pix_mp->quantization; ctx->xfer_func = pix_mp->xfer_func; - ctx->current_codec = fmt->fourcc; - if (ctx->state == MTK_STATE_FREE) { - ret = vdec_if_init(ctx, q_data->fmt->fourcc); - if (ret) { - mtk_v4l2_vdec_err(ctx, "[%d]: vdec_if_init() fail ret=%d", - ctx->id, ret); - return -EINVAL; - } - ctx->state = MTK_STATE_INIT; - } } else { ctx->capture_fourcc = fmt->fourcc; } @@ -502,46 +560,11 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, ctx->picinfo.pic_w = pix_mp->width; ctx->picinfo.pic_h = pix_mp->height; - /* - * If get pic info fail, need to use the default pic info params, or - * v4l2-compliance will fail - */ - ret = vdec_if_get_param(ctx, GET_PARAM_PIC_INFO, &ctx->picinfo); - if (ret) { - mtk_v4l2_vdec_err(ctx, "[%d]Error!! Get GET_PARAM_PICTURE_INFO Fail", - ctx->id); - } - - ctx->last_decoded_picinfo = ctx->picinfo; - - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) { - ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = - ctx->picinfo.fb_sz[0] + - ctx->picinfo.fb_sz[1]; - ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = - ctx->picinfo.buf_w; - } else { - ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = - ctx->picinfo.fb_sz[0]; - ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = - ctx->picinfo.buf_w; - ctx->q_data[MTK_Q_DATA_DST].sizeimage[1] = - ctx->picinfo.fb_sz[1]; - ctx->q_data[MTK_Q_DATA_DST].bytesperline[1] = - ctx->picinfo.buf_w; - } - - ctx->q_data[MTK_Q_DATA_DST].coded_width = ctx->picinfo.buf_w; - ctx->q_data[MTK_Q_DATA_DST].coded_height = ctx->picinfo.buf_h; - mtk_v4l2_vdec_dbg(2, ctx, - "[%d] init() plane:%d wxh=%dx%d pic wxh=%dx%d sz=0x%x_0x%x", - ctx->id, pix_mp->num_planes, - ctx->picinfo.buf_w, ctx->picinfo.buf_h, - ctx->picinfo.pic_w, ctx->picinfo.pic_h, - ctx->q_data[MTK_Q_DATA_DST].sizeimage[0], - ctx->q_data[MTK_Q_DATA_DST].sizeimage[1]); + if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) + ret = mtk_vcodec_dec_init_pic_info(ctx, f->type); } - return 0; + + return ret; } static int vidioc_enum_framesizes(struct file *file, void *priv, @@ -722,7 +745,7 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, { struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vq); struct mtk_q_data *q_data; - unsigned int i; + unsigned int i, ret; q_data = mtk_vdec_get_q_data(ctx, vq->type); @@ -731,6 +754,25 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, return -EINVAL; } + if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + ret = mtk_vcodec_dec_init_pic_info(ctx, vq->type); + if (ret) { + mtk_v4l2_vdec_err(ctx, "Failed to init picture information"); + return ret; + } + + if (vq->secure_mem && !ctx->is_secure_playback) { + ret = mtk_vcodec_dec_optee_open(ctx->dev->optee_private); + if (ret) { + mtk_v4l2_vdec_err(ctx, "Failed to open decoder optee os"); + return ret; + } + ctx->is_secure_playback = vq->secure_mem; + mtk_v4l2_vdec_dbg(1, ctx, "Getting secure decoder mode:%d", + ctx->is_secure_playback); + } + } + if (*nplanes) { if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { if (*nplanes != q_data->fmt->num_planes) @@ -980,6 +1022,7 @@ int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq, src_vq->lock = &ctx->dev->dev_mutex; src_vq->dev = &ctx->dev->plat_dev->dev; src_vq->allow_cache_hints = 1; + src_vq->allow_secure_mem = 1; ret = vb2_queue_init(src_vq); if (ret) { @@ -996,6 +1039,7 @@ int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->lock = &ctx->dev->dev_mutex; dst_vq->dev = &ctx->dev->plat_dev->dev; dst_vq->allow_cache_hints = 1; + dst_vq->allow_secure_mem = 1; ret = vb2_queue_init(dst_vq); if (ret) -- 2.18.0