From patchwork Wed Dec 6 08:15:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 17604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957034vqy; Wed, 6 Dec 2023 00:16:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt9bldIvE7rwwPhqj2hDZDuTxCxS/bjS1vdTLJojDxD1FWx2dIjMIoLYy4CZZH+q0PDkGe X-Received: by 2002:a05:6a20:a105:b0:187:e9c4:32e4 with SMTP id q5-20020a056a20a10500b00187e9c432e4mr687141pzk.13.1701850563099; Wed, 06 Dec 2023 00:16:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850563; cv=none; d=google.com; s=arc-20160816; b=TWU+gL6DseREoFYKc1G6/xrmqygGqc8vY2pEjwmi5/ln6ESesaLs6+NtOEptkY6Aca UsjIExOMygdNjaIctrg+lB2rwX+s4xiRvBHrBzCdbsN+VWIX0Bgki8/K2epBjvA1xLgZ 02X7itor5BpZGbkDXXOpWUmZz38knblGEnf13ffxTXZugADEOD3a0lPp65DVL2eVioeO tbpyp5mWONN8CaHH+cc/WE7a+D5LosFGj/l3cvh2N3w+IUY1I5aishD7yXnwBHZAA4d6 YZh+PRioE2d57ts/2dEmOJp0RcpJbzmqxFZQa4kcrUXdt10WqJQOWaele2BEWvCyCQ/A w8Mg== 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 Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id lt13-20020a17090b354d00b002867a1cb538si1982351pjb.10.2023.12.06.00.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:03 -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 CD5F4802FA33; Wed, 6 Dec 2023 00:15:56 -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_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , 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_K=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 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:15:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519656329807548 X-GMAIL-MSGID: 1784519656329807548 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