Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp247923lqo; Thu, 16 May 2024 05:26:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpBKvSSLUhU/57VbJ6LRGb8UTgyVCUkTrMbKlFS3iZPnJrzdtCPxliBrHURLNwpNGL/5ZVa2hZYAw6oz8RCbFUypAQUGVYKZlRuZNruA== X-Google-Smtp-Source: AGHT+IF13y5geK7GnSdvPx7HgVWor/iWsZrT23wEBj2hLINGqEC5kGBMGFvzXFXb1fE0GJ2K6iKZ X-Received: by 2002:a05:6871:296:b0:244:ee0e:c810 with SMTP id 586e51a60fabf-244ee0f9073mr12086561fac.27.1715862403486; Thu, 16 May 2024 05:26:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715862403; cv=pass; d=google.com; s=arc-20160816; b=X5ThODimmILJIcw2nrzChZuF/UBoQcGmOXmYuCzyvNSb57PKXb91DSNggLtOsECYvV 2TDauKzerKQgbenMjAg/YAOHBYv7CFk8ZUfX6Ym1z264AD/YRXSFnwdDb5ezo8sTQ6VQ CpR9LDV4Dvn8LUxkqCMHVs0cIHLx/rrjPEs3e3lndt8GLYZ6YZJel5RKojN3QX+DGYpm 87Zb7qdO3Hk2T0sKGBQyx4U+/tfcHoanFaKaJvFUKdiweREdnR3OruIhPEJsHPkZqoPV OsBpb3IhORFM2WAAfudzQoe2+eB06htHYTnseJ9z4mMbu7KFgQ9fnHCLFAC/pKmxbsKu TM5w== 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=PI5LYWDFa3Xh+ULRsBJwWNpeA7k6/6wT5lC8UfUZeuQ=; fh=+3keNzaSOvsaq+BXFM2IqKmKMiZV6QsxTCb//k4Cpek=; b=xkT0+jaoMQgiQZamjG3R8dJdRV8GaDOHBAzxLTaD4TZSrF6Ebkfw6FaQVR0V6bWems xBzMZo4r8CY4a4YggJs19W2vHwIPMqVeHoM//9aXKJTsD7iMDoL9AKJT9nRdzvTwMzu8 Y5oKv+CuwxZ3oW7im++6OtYp+LArKkZYYZbgFmn6VaRCHWpX5zgl0y53gdRhL85K5M+N nsijfDwK4cU3L6dbamjBlgAeRx0zJ+P+FWJW2mHrrDP4itU0hETmcRZHxkt67DqbFSgl BDzis5aQy/valbzTG/UCz8TxmB8a1Zvwo+0decj0TBzZtjya1D/uXWlTJlK7KejZL4po mHdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Mj5HQDxA; 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-181015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181015-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df56c5630si161355541cf.623.2024.05.16.05.26.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 05:26:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Mj5HQDxA; 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-181015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181015-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2A62B1C21B46 for ; Thu, 16 May 2024 12:26:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01A56154C1C; Thu, 16 May 2024 12:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Mj5HQDxA" 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 B486015442B; Thu, 16 May 2024 12:21:44 +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=1715862106; cv=none; b=KbwvIWP6tOcwH9JAyYkxCc50mpcdbcbp9+leBV/Hp7oVF/DHN7ucvLK4R6TrMDNn/BWK7CWgC4hoQH6kxIxVXgBPtSzAQrnbWzwW5jDJIsEbo3VeM+FEokENcEmD8ncGew/723n0SKkLoGRstHhwpxlu82ig2EAB/SA1c+gXXu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715862106; c=relaxed/simple; bh=POoqwJAaQxn3x22ZMBVxXsOd70NLG3WdeA3iAjCHt/0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DFu6taa+PRTd/G9P5l+eG+xAu/tGH/+gHUca0FG40KHWc2itZTONxvrzmwUsuoWyoalBO1EtQa1f2s9aM0d9+r8ZDTew9SrZ/uEYoobIuq7WqtvUSZ+En8hpIu/rwdfN4zu3y/5aGlnwerTqFADe/Z/ko6cYbCeBeHbRHXslqB0= 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=Mj5HQDxA; 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: d8dc2a98137e11efb92737409a0e9459-20240516 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=PI5LYWDFa3Xh+ULRsBJwWNpeA7k6/6wT5lC8UfUZeuQ=; b=Mj5HQDxAZuTmimUaj9h2WGgpo4hkYVULv6MkhNwk3rVeTZOZ9/Z82cKbRlhb3DwDf9F6R1o++CS7Lh9vhdGFan+zH6yiTybXaW6oiNKCywvkzciXmr+nFEMia4hAI+zV8qZqHsUsIq6Y59+qpGbSA+RUjDa75qOda7wMcVck8C4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:a302eb41-b323-4d6b-a386-4b4652cf7ad8,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:82c5f88,CLOUDID:d509f083-4f93-4875-95e7-8c66ea833d57,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: d8dc2a98137e11efb92737409a0e9459-20240516 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1850721524; Thu, 16 May 2024 20:21:39 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) 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; Thu, 16 May 2024 20:21:37 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 16 May 2024 20:21:36 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Nathan Hebert , "Nicolas Dufresne" , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Sebastian Fricke , Tomasz Figa , "Mauro Carvalho Chehab" , Marek Szyprowski 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 v6,21/24] media: mediatek: vcodec: move vdec init interface to setup callback Date: Thu, 16 May 2024 20:20:59 +0800 Message-ID: <20240516122102.16379-22-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240516122102.16379-1-yunfei.dong@mediatek.com> References: <20240516122102.16379-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--2.649900-8.000000 X-TMASE-MatchedRID: EBQtjOxmn4r/ybP4IWJkikKcYi5Qw/RVFpw9gj8mywrfUZT83lbkENro EGQiudNyiYTHezvcK04K3OrJWcpBViwmW5mXIeVjzfqlpbtmcWi50iD18ixmy/gnJH5vm2+gZ2X jE62VgUUNgIab5TqX5hvy10omRZrhqjvsBy5CHDuOjIrMSa2sR70cSmFxPxCimyiLZetSf8mfop 0ytGwvXiq2rl3dzGQ19+9ZqEp9FTjz9DKxlKhCG78gWoFlzzLGVZuVZ7f7lWbhEkeoeIwg0B4sl satWGExKPNRvKIrtUNV4kc3YJMsq7Wgo76YKbQ9kPqqsVd3Lntpp55fZDlsr34cY/B7JqXaYZ1R 7NXn0MdBmmCXcKyFFJ6oP1a0mRIj X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--2.649900-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 648045179CC978A1303ED8D0794BE0745A7CE4E02B214625B79144D032F58A3B2000:8 X-MTK: N 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 | 139 +++++++++++------- 1 file changed, 89 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 ebe21064616c..a07b6ba0ea82 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,69 @@ 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); + + q_data = mtk_vdec_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); + if (q_data->fmt->num_planes == 1) { + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + q_data->bytesperline[0] = ctx->picinfo.buf_w; + } else { + if (ctx->is_secure_playback) + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + else + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0]; + + q_data->bytesperline[0] = ctx->picinfo.buf_w; + q_data->sizeimage[1] = ctx->picinfo.fb_sz[1]; + q_data->bytesperline[1] = ctx->picinfo.buf_w; + } + + q_data->coded_width = ctx->picinfo.buf_w; + q_data->coded_height = ctx->picinfo.buf_h; + + ctx->last_decoded_picinfo = ctx->picinfo; + 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, + q_data->sizeimage[0], q_data->sizeimage[1]); + return 0; +} + static int vidioc_vdec_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) { @@ -479,17 +542,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 +555,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 +740,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 +749,25 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, return -EINVAL; } + if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + if (vq->restricted_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->restricted_mem; + mtk_v4l2_vdec_dbg(1, ctx, "Getting secure decoder mode:%d", + ctx->is_secure_playback); + } + + 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 (*nplanes) { if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { if (*nplanes != q_data->fmt->num_planes) @@ -980,6 +1017,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_restricted_mem = 1; ret = vb2_queue_init(src_vq); if (ret) { @@ -996,6 +1034,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_restricted_mem = 1; ret = vb2_queue_init(dst_vq); if (ret) -- 2.25.1