Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp819941rdb; Wed, 6 Dec 2023 00:16:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjgUSG4AzVznh3K5wjf5E5WXwZNsM2wr7cfsm8FuvZ/VMJHCy7+cs0XV37cffk/MoGDJf0 X-Received: by 2002:a17:90a:1910:b0:286:7063:2475 with SMTP id 16-20020a17090a191000b0028670632475mr573360pjg.54.1701850573842; Wed, 06 Dec 2023 00:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850573; cv=none; d=google.com; s=arc-20160816; b=kJpYBVtizXpR8WupD1pSRCI6s0wUT3dnwtAQSEl+qziz/NvvwU91NFtHvCJtKgd/Qk SxR7vO1xc+/sHPvDjJxI40OagTUoaSV51WtO+ozgtsWQVxGmUJBOkOn1FxxJovW4mVw6 9mqSo/E4zYlyREU/TAQ0YTrKsq4wUDe65+Xb1z7U1daKnixFNfE/G+LFbiNS2bgAGQzd rDFHTA0/BNNcu23Hmuum7OJc+q6ZhiDcfjpv5u3IVdjZKGKPbmgjnSDrWDqy9uiM9ZIS nseeqx5KXMpjOzyCCyDEy8MbZZMshDrfzXvhVWbJoEWksDNusVg/aM78IM/Gdt6URy0j 9z8Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WUvnAbLVucWrVWTYlMwApw5nIIzVBjs1iLq+uUd3UhQ=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=B3Pkr+/SgNiX6t+lX/XbIZ6KhesevGRCzkWTnrUf4xCYpsXhzduJPi+VPqYfHNwzlP GIQ/r55X36jz0VrdKztSfL32/UlsFiXubuZza3rHb0I9eNQLzD/ngjidXSTxlxXb9kFG uhSSz5luwoqPWBCtNtuPsQKKYJfjR/zReai9me8y7HA6QM+P0LipQ124UPEezhjrjaDK MmKJ2w55KiLjSuDrCK9PwECuUMANReOb00p6vnXo+fv/UckoPtow/wkf3deq3Lo4vK4Q 3Gg7daE9ysrlgtpKNTvwni6NsO7v575z9YsO9sIwxk+joniIpP8it8DPkeS3MfaoRssY q3xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=B5Dm2yur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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. [23.128.96.33]) by mx.google.com with ESMTPS id h18-20020a17090aa89200b002887be71d7dsi9643pjq.150.2023.12.06.00.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=B5Dm2yur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 6C94B802F945; Wed, 6 Dec 2023 00:16:07 -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 S1377121AbjLFIPs (ORCPT + 99 others); Wed, 6 Dec 2023 03:15:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376904AbjLFIPr (ORCPT ); Wed, 6 Dec 2023 03:15:47 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A64118D; Wed, 6 Dec 2023 00:15:47 -0800 (PST) X-UUID: a54c3126940f11eea33bb35ae8d461a2-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:Message-ID:Date:Subject:CC:To:From; bh=WUvnAbLVucWrVWTYlMwApw5nIIzVBjs1iLq+uUd3UhQ=; b=B5Dm2yurhtaSv/jCmNXeEOPrnvy56R8syrjL8AvDEIyF23WsZ3BkOsI7qUTT9nejrUSNB6GgUmKGYmYtytmdBgxVuBweILpQuPRDUwUbQiKB241w5bFtDEYO49U94CnfIymt7lErIbrMkB73vR+dhSoSZVPp8R8OzfVJZk/Z9G0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:b7cf281d-25b6-47c6-bf23-b3869ffcf60c,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:abefa75,CLOUDID:6a78e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:1,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 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULS X-UUID: a54c3126940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 857388546; Wed, 06 Dec 2023 16:15:41 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n1.mediatek.inc (172.21.101.185) 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:15:40 +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:15:39 +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,00/21] add driver to support secure video decoder Date: Wed, 6 Dec 2023 16:15:17 +0800 Message-ID: <20231206081538.17056-1-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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:16:07 -0800 (PST) The patch series used to enable secure video playback (SVP) on MediaTek hardware in the Linux kernel. Memory Definitions: secure memory - Memory allocated in the TEE (Trusted Execution Environment) which is inaccessible in the REE (Rich Execution Environment, i.e. linux kernel/userspace). secure handle - Integer value which acts as reference to 'secure memory'. Used in communication between TEE and REE to reference 'secure memory'. secure buffer - 'secure memory' that is used to store decrypted, compressed video or for other general purposes in the TEE. secure surface - 'secure memory' that is used to store graphic buffers. Memory Usage in SVP: The overall flow of SVP starts with encrypted video coming in from an outside source into the REE. The REE will then allocate a 'secure buffer' and send the corresponding 'secure handle' along with the encrypted, compressed video data to the TEE. The TEE will then decrypt the video and store the result in the 'secure buffer'. The REE will then allocate a 'secure surface'. The REE will pass the 'secure handles' for both the 'secure buffer' and 'secure surface' into the TEE for video decoding. The video decoder HW will then decode the contents of the 'secure buffer' and place the result in the 'secure surface'. The REE will then attach the 'secure surface' to the overlay plane for rendering of the video. Everything relating to ensuring security of the actual contents of the 'secure buffer' and 'secure surface' is out of scope for the REE and is the responsibility of the TEE. This patch series is consists of four parts. The first is from Jeffrey, adding secure memory flag in v4l2 framework to support request secure buffer. The second and third parts are from John and T.J, adding some heap interfaces, then our kernel users could allocate buffer from special heap. The patch v1 is inside below dmabuf link. https://lore.kernel.org/linux-mediatek/20230911023038.30649-1-yong.wu@mediatek.com/ To avoid confusing, move them into vcodec patchset since we use the new interfaces directly. The fourth part is mediatek decoder driver, adding tee interface to support secure video decoder. --- Changed in v3: - rewrite the cover-letter of this patch series - disable irq for svp mode - rebase the driver based on the latest media stage Changed in v2: - remove setting decoder mode and getting secure handle from decode - add Jeffrey's patch - add John and T.J's patch - getting secure flag with request buffer - fix some comments from patch v1 --- Jeffrey Kardatzke (4): v4l2: add secure memory flags v4l2: handle secure memory flags in queue setup v4l2: verify secure dmabufs are used in secure queue v4l: add documentation for secure memory flag John Stultz (2): dma-heap: Add proper kref handling on dma-buf heaps dma-heap: Provide accessors so that in-kernel drivers can allocate dmabufs from specific heaps T.J. Mercier (1): dma-buf: heaps: Deduplicate docs and adopt common format Yunfei Dong (14): media: mediatek: vcodec: add tee client interface to communiate with optee-os media: mediatek: vcodec: allocate tee share memory media: mediatek: vcodec: send share memory data to optee media: mediatek: vcodec: initialize msg and vsi information media: mediatek: vcodec: add interface to allocate/free secure memory media: mediatek: vcodec: using shared memory as vsi address media: mediatek: vcodec: Add capture format to support one plane memory media: mediatek: vcodec: Add one plane format media: medkatek: vcodec: support one plane capture buffer media: medkatek: vcodec: re-construct h264 driver to support svp mode media: medkatek: vcodec: remove parse nal_info in kernel media: medkatek: vcodec: disable wait interrupt for svp mode media: medkatek: vcodec: support tee decoder media: mediatek: vcodec: move vdec init interface to setup callback .../userspace-api/media/v4l/buffer.rst | 8 +- .../media/v4l/pixfmt-reserved.rst | 8 + drivers/dma-buf/dma-heap.c | 139 +++++-- .../media/common/videobuf2/videobuf2-core.c | 23 ++ .../common/videobuf2/videobuf2-dma-contig.c | 6 + .../media/common/videobuf2/videobuf2-dma-sg.c | 6 + .../media/common/videobuf2/videobuf2-v4l2.c | 34 +- .../media/platform/mediatek/vcodec/Kconfig | 1 + .../mediatek/vcodec/common/mtk_vcodec_util.c | 122 +++++- .../mediatek/vcodec/common/mtk_vcodec_util.h | 3 + .../platform/mediatek/vcodec/decoder/Makefile | 1 + .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 155 ++++--- .../vcodec/decoder/mtk_vcodec_dec_drv.c | 8 + .../vcodec/decoder/mtk_vcodec_dec_drv.h | 7 + .../vcodec/decoder/mtk_vcodec_dec_hw.c | 34 +- .../vcodec/decoder/mtk_vcodec_dec_optee.c | 383 ++++++++++++++++++ .../vcodec/decoder/mtk_vcodec_dec_optee.h | 156 +++++++ .../vcodec/decoder/mtk_vcodec_dec_pm.c | 6 +- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 35 +- .../decoder/vdec/vdec_h264_req_common.c | 11 +- .../decoder/vdec/vdec_h264_req_multi_if.c | 334 +++++++++------ .../mediatek/vcodec/decoder/vdec_drv_if.c | 4 +- .../mediatek/vcodec/decoder/vdec_msg_queue.c | 9 +- .../mediatek/vcodec/decoder/vdec_vpu_if.c | 57 ++- .../mediatek/vcodec/decoder/vdec_vpu_if.h | 4 + drivers/media/v4l2-core/v4l2-common.c | 2 + drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/linux/dma-heap.h | 29 +- include/media/videobuf2-core.h | 8 +- include/uapi/linux/videodev2.h | 3 + 30 files changed, 1296 insertions(+), 301 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c create mode 100644 drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h -- 2.18.0