Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp212016rdb; Sun, 28 Jan 2024 22:33:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEB+iO2fWq4uPMnCXgR1UdrqFs/0c9nZwtgIQ70Gz6snaSCeptX9E+5yOIn/B0ARHn9SRgE X-Received: by 2002:a17:90a:b004:b0:290:2492:4420 with SMTP id x4-20020a17090ab00400b0029024924420mr2683361pjq.42.1706510012377; Sun, 28 Jan 2024 22:33:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510012; cv=pass; d=google.com; s=arc-20160816; b=RG/Kvbe1U77nElIyQjZAuo/9/Phd7jhiFWgPkUdTuqPXyZlyh3A8HxT3FvbL97B1C6 RHgRLo3bA512FpcIKHFUcQP0PIJ6JAU7Na04wL87npCIbhWOzV4J63mSdAyIkFGXgCDF ytR0DWPdqQYjq28y1mnz8hZXfXsgN1eZmvJzw7oUHJmfVB5Lpm99dhmX1Zh9v+1WmVvo gylEtMZNgsEnXOWRmZNzwS3P8tmS/fVMhIOkG7FNydmTjcTdCiQdKLSg3N0xyfy7zFhv sRQfwSHCl0f9OHLmss+yWTjmS05vzHmjNawyjIsbj2NQW+mSTmP4EHu5w1W+JcDXBLnP eKeQ== 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=Qsu2a6pWuI9r9UzNG4biPlS5wzwndp0NR6vZ8LjQ+Ww=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=Nl0yDAEiKL7F0DvGbvF+QZ2fQAJjPGtyNQd5C0fzJzPJU+WeQQceUcTlpxNkUZsrkt 0uFgX4FH8F9FghjARY08U8RHVT9z4GEQT5U5Be2NQcAeKXh2jUmyGDmyv/5FWisOZFIK n64TYLGCUBe2WwmTRU5Yc800RC8Y/7UCv9MDfo6Ys02U4/iiGxnLuTz2S56SSifQ3NCs NON9FVcdCxvf9pAJUcI0b8ajwHT1YeEB0nqBhEbz41LlIrtjtMcmxIt6VNWaT8zRT5qc b6vLjbN8wLgoZ0P1RTF5bDSSWRqJRimxRp/wW7lOT1Hzh9rG7X63U2NjYZC42kgTOfHN 4Rrg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hp6c43w4; 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-42246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42246-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e24-20020a17090a9a9800b00290d2d14672si7082781pjp.157.2024.01.28.22.33.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:33:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hp6c43w4; 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-42246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42246-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1936DB2238D for ; Mon, 29 Jan 2024 06:33:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 704C054BFB; Mon, 29 Jan 2024 06:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="hp6c43w4" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 079D25466B; Mon, 29 Jan 2024 06:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509859; cv=none; b=jq9UCSxKulIUmelUj661pu9iKqrw5XaUhN8z6L2Z9MGpH7bfvdOR+Nw0QdiEuZTwoaWOjGTXz2rrUtutDZCiezf/Z8wtx/vI0zgD0uQRyP8UP7f+AbISgBpddu3R1W/Duct8ltAaEmz60N2geZfVEEjw/itBMbFA7Z2Rzhkp/Bk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509859; c=relaxed/simple; bh=US4OZk6dblj+DVk9tUWz4o/lujsEaKBuVPKBXb+6cyE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=twnSJUaTxnQ2lsYPQDRwhOMu1tRyPvDcyJ51zDPYNxs5/gW4tKDxbken/WSGyv32mTAlzRKg9JxpoKIQ5t+4cAHsP4IWGCfMZ7nGUlTHeggCHfvJ6/kLs5jBTdhkpvTi9iPx1T33i961YEGGmw0Xp8jsaZNwmZgAz3JJMxhL5WE= 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=hp6c43w4; arc=none smtp.client-ip=210.61.82.184 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: f24c5f02be6f11eea2298b7352fd921d-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=Qsu2a6pWuI9r9UzNG4biPlS5wzwndp0NR6vZ8LjQ+Ww=; b=hp6c43w4MrRUqhIhLgcfQN1mxo9VF/LYBE9dlBWeimW7UWSnrCLzqjIv49xIeSXciSKrQe+ulN0C4PMa6iz/ojM6/ja1xD4J58nCNjduKypBUCfXzBob4kF0uC5Nkfp2HgqjY7G5W3RO8RsAZ/y1PPtr+n7zBlxtV5PQHEGIXfo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:a681f9ca-e954-4460-bac6-e578edd33c88,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6e16cf4,CLOUDID:9bd041fe-c16b-4159-a099-3b9d0558e447,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: f24c5f02be6f11eea2298b7352fd921d-20240129 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 541821859; Mon, 29 Jan 2024 14:30:51 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) 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:30:49 +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:30:48 +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,10/22] media: mediatek: vcodec: send share memory data to optee Date: Mon, 29 Jan 2024 14:30:13 +0800 Message-ID: <20240129063025.29251-11-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--11.706700-8.000000 X-TMASE-MatchedRID: AyztauQSwYCQG6Uyrf0PKFVN8laWo90MTJDl9FKHbrk1LB46LFAAkotf Mtu9FfbrPcGjGTU7TnemGallF1XuaEDn8NFEhJAcFYJUGv4DL3yH7D1bP/FcOhL6MU7t349b3vY rsfFYjWsgY9Nu1Ql6APqPSFsdX1B029aHfVG01jzJ1E39jKDimGaq8BZOZSelzrexXSWzstSgzz s1FNpEXGOFciOhsJ4zgDLqnrRlXrZ8nn9tnqel2DsAVzN+Ov/sUxeZzrp4VFNLDXTQO5fDMw8XB qf0pq8h28s3Rxggvn20AWWhtDiZ1w== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--11.706700-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 36278F227AA0035C596A6AB2FBA9039AA55ED2785F36B33CF218D7195A0DC8412000:8 X-MTK: N Setting msg and vsi information to shared buffer, then call tee invoke function to send it to optee-os. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_optee.c | 140 ++++++++++++++++++ .../vcodec/decoder/mtk_vcodec_dec_optee.h | 51 +++++++ 2 files changed, 191 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c index 611fb0e56480..f29a8d143fee 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c @@ -241,3 +241,143 @@ void mtk_vcodec_dec_optee_release(struct mtk_vdec_optee_private *optee_private) mutex_unlock(&optee_private->tee_mutex); } EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_release); + +static int mtk_vcodec_dec_optee_fill_shm(struct tee_param *command_params, + struct mtk_vdec_optee_shm_memref *shm_memref, + struct mtk_vdec_optee_data_to_shm *data, + int index, struct device *dev) +{ + if (!data->msg_buf_size[index] || !data->msg_buf[index]) { + pr_err(MTK_DBG_VCODEC_STR "tee invalid buf param: %d.\n", index); + return -EINVAL; + } + + *command_params = (struct tee_param) { + .attr = shm_memref->param_type, + .u.memref = { + .shm = shm_memref->msg_shm, + .size = data->msg_buf_size[index], + .shm_offs = 0, + }, + }; + + if (!shm_memref->copy_to_ta) { + dev_dbg(dev, MTK_DBG_VCODEC_STR "share memref data: 0x%x param_type:%llu.\n", + *((unsigned int *)shm_memref->msg_shm_ca_buf), shm_memref->param_type); + return 0; + } + + memset(shm_memref->msg_shm_ca_buf, 0, shm_memref->msg_shm_size); + memcpy(shm_memref->msg_shm_ca_buf, data->msg_buf[index], data->msg_buf_size[index]); + + dev_dbg(dev, MTK_DBG_VCODEC_STR "share memref data => msg id:0x%x 0x%x param_type:%llu.\n", + *((unsigned int *)data->msg_buf[index]), + *((unsigned int *)shm_memref->msg_shm_ca_buf), + shm_memref->param_type); + + return 0; +} + +void mtk_vcodec_dec_optee_set_data(struct mtk_vdec_optee_data_to_shm *data, + void *buf, int buf_size, + enum mtk_vdec_optee_data_index index) +{ + data->msg_buf[index] = buf; + data->msg_buf_size[index] = buf_size; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_set_data); + +int mtk_vcodec_dec_optee_invokd_cmd(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id, + struct mtk_vdec_optee_data_to_shm *data) +{ + struct device *dev = &optee_private->vcodec_dev->plat_dev->dev; + struct tee_ioctl_invoke_arg trans_args; + struct tee_param command_params[MTK_OPTEE_MAX_TEE_PARAMS]; + struct mtk_vdec_optee_ca_info *ca_info; + struct mtk_vdec_optee_shm_memref *shm_memref; + int ret, index; + + if (hw_id == MTK_VDEC_LAT0) + ca_info = &optee_private->lat_ca; + else + ca_info = &optee_private->core_ca; + + memset(&trans_args, 0, sizeof(trans_args)); + memset(command_params, 0, sizeof(command_params)); + + trans_args = (struct tee_ioctl_invoke_arg) { + .func = ca_info->vdec_session_func, + .session = ca_info->vdec_session_id, + .num_params = MTK_OPTEE_MAX_TEE_PARAMS, + }; + + /* Fill msg command parameters */ + for (index = 0; index < MTK_OPTEE_MAX_TEE_PARAMS; index++) { + shm_memref = &ca_info->shm_memref[index]; + + if (shm_memref->param_type == TEE_IOCTL_PARAM_ATTR_TYPE_NONE || + data->msg_buf_size[index] == 0) + continue; + + dev_dbg(dev, MTK_DBG_VCODEC_STR "tee share memory data size: %d -> %d.\n", + data->msg_buf_size[index], shm_memref->msg_shm_size); + + if (data->msg_buf_size[index] > shm_memref->msg_shm_size) { + dev_err(dev, MTK_DBG_VCODEC_STR "tee buf size big than shm (%d -> %d).\n", + data->msg_buf_size[index], shm_memref->msg_shm_size); + return -EINVAL; + } + + ret = mtk_vcodec_dec_optee_fill_shm(&command_params[index], shm_memref, + data, index, dev); + if (ret) + return ret; + } + + ret = tee_client_invoke_func(optee_private->tee_vdec_ctx, &trans_args, command_params); + if (ret < 0 || trans_args.ret != 0) { + dev_err(dev, MTK_DBG_VCODEC_STR "tee submit command fail: 0x%x 0x%x.\n", + trans_args.ret, ret); + return (ret < 0) ? ret : trans_args.ret; + } + + /* clear all attrs, set all command param to unused */ + for (index = 0; index < MTK_OPTEE_MAX_TEE_PARAMS; index++) { + data->msg_buf[index] = NULL; + data->msg_buf_size[index] = 0; + } + + return 0; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_invokd_cmd); + +void *mtk_vcodec_dec_get_shm_buffer_va(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id, + enum mtk_vdec_optee_data_index data_index) +{ + struct mtk_vdec_optee_ca_info *ca_info; + + if (hw_id == MTK_VDEC_LAT0) + ca_info = &optee_private->lat_ca; + else + ca_info = &optee_private->core_ca; + + return ca_info->shm_memref[data_index].msg_shm_ca_buf; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_get_shm_buffer_va); + +int mtk_vcodec_dec_get_shm_buffer_size(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id, + enum mtk_vdec_optee_data_index data_index) +{ + struct mtk_vdec_optee_ca_info *ca_info; + + if (hw_id == MTK_VDEC_LAT0) + ca_info = &optee_private->lat_ca; + else + ca_info = &optee_private->core_ca; + + return ca_info->shm_memref[data_index].msg_shm_size; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_get_shm_buffer_size); diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h index 24aa63af9887..c24a567ec877 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h @@ -62,6 +62,16 @@ enum mtk_vdec_optee_data_index { OPTEE_MAX_INDEX, }; +/** + * struct mtk_vdec_optee_data_to_shm - shm data used for TA + * @msg_buf: msg information to TA. + * @msg_buf_len: length of msg information. + */ +struct mtk_vdec_optee_data_to_shm { + void *msg_buf[MTK_OPTEE_MAX_TEE_PARAMS]; + int msg_buf_size[MTK_OPTEE_MAX_TEE_PARAMS]; +}; + /** * struct mtk_vdec_optee_private - optee private data * @vcodec_dev: pointer to the mtk_vcodec_dev of the device @@ -102,4 +112,45 @@ int mtk_vcodec_dec_optee_private_init(struct mtk_vcodec_dec_dev *vcodec_dev); */ void mtk_vcodec_dec_optee_release(struct mtk_vdec_optee_private *optee_private); +/** + * mtk_vcodec_dec_optee_set_data - set buffer to share memref. + * @vcodec_dev: normal world data used to init optee share memory + * @buf: normal world buffer address + * @buf_size: buf size + * @data_index: indentify each share memory informaiton + */ +void mtk_vcodec_dec_optee_set_data(struct mtk_vdec_optee_data_to_shm *data, + void *buf, int buf_size, + enum mtk_vdec_optee_data_index data_index); + +/** + * mtk_vcodec_dec_optee_invokd_cmd - send share memory data to optee . + * @optee_private: optee private context + * @hw_id: hardware index + * @data: normal world data used to init optee share memory + */ +int mtk_vcodec_dec_optee_invokd_cmd(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id, + struct mtk_vdec_optee_data_to_shm *data); + +/** + * mtk_vcodec_dec_get_shm_buffer_va - close the communication channels with TA. + * @optee_private: optee private context + * @hw_id: hardware index + * @@data_index: indentify each share memory informaiton + */ +void *mtk_vcodec_dec_get_shm_buffer_va(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id, + enum mtk_vdec_optee_data_index data_index); + +/** + * mtk_vcodec_dec_get_shm_buffer_size - close the communication channels with TA. + * @optee_private: optee private context + * @hw_id: hardware index + * @@data_index: indentify each share memory informaiton + */ +int mtk_vcodec_dec_get_shm_buffer_size(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id, + enum mtk_vdec_optee_data_index data_index); + #endif /* _MTK_VCODEC_FW_OPTEE_H_ */ -- 2.18.0