Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp245132lqo; Thu, 16 May 2024 05:21:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUujdUChFRAWJtb/cG3LgjDMUdNXZIt+cZ93eAh45nSbeW+HyVUez69Ykf/JYT2EoMD1W0bZTQ5b2UV2KdXwbqugUoVxtiNBnzfOXy9hg== X-Google-Smtp-Source: AGHT+IE+uzFes0UBakW1TE6B3XrnLzhtjWCHe8QQq5X+rwhmpnhiOmzYmrcxBRwwghG1I4LTf9YM X-Received: by 2002:a05:620a:4481:b0:792:e546:ad71 with SMTP id af79cd13be357-792e546af01mr1145589085a.25.1715862086284; Thu, 16 May 2024 05:21:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715862086; cv=pass; d=google.com; s=arc-20160816; b=b06LLXJXTpAENSv1NJ6Z79CV32vIqOnwW0CYcc+gxCNYmxShFNqbBl0RU7Bwk9cKOI lL0tiZKF1p2duoemskwXHq51QukMeqXWdq4i2rmNXrI7gaPTcAtJK3znCTOB3Er1+xHy F5lK5YBWEmsBwIGY8k3IRjUxzmyTR4TkEhyx9KnEdvMeI3JRALxBuC0Q5Df4LHQWpd2n rShtR2kapQ6shh5hDhIEPYPT/BBNDF1UmVUCqnfaDLd0C+lx5ImqjxBZ5Ye/moH6D+Sh EYvgTv+4Tz5hO890AA9TsGSn4aTvh4y2TtM7DgCHbzVEd2ulAD5bsE9Cmd2T9//irB2F 5qDw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=FxoURd+7DdicAsZp6Obc64kWMKrH1ZdhW0yeI+412bo=; fh=+3keNzaSOvsaq+BXFM2IqKmKMiZV6QsxTCb//k4Cpek=; b=wwee0hW0m23IQtYaIla9qvLmGk0NI5s4Pdhnyf8YA4uj0vuKGyguGeKEAREm1iIoBr iEqvCXX6FqnKcJOCyfSglVvYYmaYYzXapbV51guqTIdG+Pjr+cWFVqSW528MT9RwA7yo gMqEr5Bb2eEeSsx3hkiZj186uNSo9N2djGpwT+zLQKLYmhiAJxK6rUMiT50BC8xXJcsQ ZjNp435tusfyuIVYw7OgwjMT2mch+zoVNOFWaiPHnvXr2ARIJiqAPrgPNFgA059Kq3cD r6ghDzFi6yT8E2xVRRTpXrgknGNlie5JVGzILdZYiUhtjAVtsZMXeBw1gAjr73taGqcs cMMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=oX1rFwxC; 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-180992-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180992-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 af79cd13be357-792bf30a842si1579723385a.302.2024.05.16.05.21.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 05:21:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180992-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=oX1rFwxC; 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-180992-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180992-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 E7C7F1C21B0A for ; Thu, 16 May 2024 12:21:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA398145FF9; Thu, 16 May 2024 12:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="oX1rFwxC" 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 11FA526AD0; Thu, 16 May 2024 12:21:14 +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=1715862077; cv=none; b=sbFG2O1qSjmsA67JfBIjzeg3tYW32D6iFaAZAx3Gksq7ObvnyGcy3xh4uNzJWW7veBgvYN2jGg7UMKSmDtXqE4niMEvTvdOxagorgQQLaJQ5LqjQnwS9h3hPJa4ZrTCuvdeSA333RXE7v/4HXVD+VnjBrr0KPdTXWmSo/UIFS8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715862077; c=relaxed/simple; bh=twsnA19yce/vLQHVoIbxjTMyA1o6jkohi8WPS/DWs88=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Is4Oy9cNuMvcW/kcBVQFI90oG/veTiW4Pv0CMXZFOYXUU/D1pgdKcEhtOBhnT4aV5+9sc1JbacrbjvV0adzdpU17lT9lUP4AjKdcj8UE0avT+uL+HMf9lxaGDhh8SaLYWScMtkDPuDukFlq2OJQm2YIi4MdcaZsQ6tET+apPkAg= 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=oX1rFwxC; 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: c77b1160137e11efb92737409a0e9459-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:Message-ID:Date:Subject:CC:To:From; bh=FxoURd+7DdicAsZp6Obc64kWMKrH1ZdhW0yeI+412bo=; b=oX1rFwxC6xYs8wBbLvjTJ/f/F1sKJxRZWQ22/yjqMQQWT5L6r6a715+QavxAVhYP3PrNR+J+nzJj9Nfk9lxIJlUF9imlOlzDc4wKxIJDLvtr4qBYEKhkGtWaWo2AfLFQasGE0lBCDokXBuAUxb0cBEZI6hz6ejOFn9kzhWSD3lM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:a40e379d-d61c-4694-8506-bcd342458ce5,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:82c5f88,CLOUDID:881fd792-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:1,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 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULS X-UUID: c77b1160137e11efb92737409a0e9459-20240516 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 142435461; Thu, 16 May 2024 20:21:10 +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:07 +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:06 +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,00/24] media: mediatek: add driver to support secure video decoder Date: Thu, 16 May 2024 20:20:38 +0800 Message-ID: <20240516122102.16379-1-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 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.525400-8.000000 X-TMASE-MatchedRID: QITTs0Q4iULtzSKzUmDUVwI0yP/uoH+DHgnyJJNAX/hGL0g1nVmkYTjh cV1z6ih5WiaTAptjMRWkCf2vRV+wnagSz5LfW6gEtgGefYRQNetUNS+xp6iMXWsxtqQk3w552Fx nSUK+m7/6scB2izTfK0mdI2aa3IoLfjm4FmbDbT0zw5Ejs3g1loab/1O/b86BknxabN/DinjEBp jowVhUR9Gzq011f5lgCmjHXhV21s3GHadaRuAOv1z+axQLnAVBnp/1DQXYWrUR34ro7k23nYNaw NhHLl62sC7QIHAmtIQgnvrgPYqDApQxl2LaGeYA7spMO3HwKCAxXH/dlhvLv8NNczdXNJoiFKP4 b2zaNX37+OrNHOBlyuv5q3xJofu6uafWgMhNYLlC4WIP7GtYLLqGBW9J0YqjCgNjqBgJU5MNMop f6MGUQFSwGvCl8Crex941uW1B9Op9wUnSp+FsXh+WEMjoO9WWfS0Ip2eEHnz3IzXlXlpamPoLR4 +zsDTt+GYUedkXNWoXADxe84YEoo7Q0rMD985fLIwZeEGGR5d/AtGCJzTumc2YhbbKlG2xUnF/R Asu5gOkOBPc9OLr6KXB9+VMLv+Q7kVCNKrk7cvyNp7g4PXe0BXsxz6ujBxUq1f8XSkHBUmNJXmE MVvLtmcjFnImzvyS X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--2.525400-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 15170411066990259493C61E6FD2C86217DBACA2787740452B30594821C292B52000:8 X-MTK: N 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/user space). 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 patch set since we use the new interfaces directly. The last part is mediatek video decoder driver, adding tee interface and decoder driver to support secure video playback. This patch set depends on "dma-buf: heaps: Add restricted heap"[1] [1] https://patchwork.kernel.org/project/linux-mediatek/list/?series=853380 --- Changed in v6: - fix review unreasonable logic for patch 2/3/23 - add to support vp9 for patch 24 Changed in v5: - fix merge conflict when rebase to latest media stage for patch 1/2 - change allocate memory type to cma for patch 12 - add to support av1 for patch 23 Changed in v4: - change the driver according to maintainer advice for patch 1/2/3/4 - replace secure with restricted for patch 1/2/3/4 - fix svp decoder error for patch 21 - add to support hevc for patch 22 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 restricted memory flags v4l2: handle restricted memory flags in queue setup v4l2: verify restricted dmabufs are used in restricted queue v4l: add documentation for restricted 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 Xiaoyong Lu (1): media: mediatek: vcodec: support av1 svp decoder for mt8188 Yilong Zhou (1): media: mediatek: vcodec: support vp9 svp decoder for mt8188 Yunfei Dong (15): 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: mediatek: vcodec: support one plane capture buffer media: mediatek: vcodec: re-construct h264 driver to support svp mode media: mediatek: vcodec: remove parse nal_info in kernel media: mediatek: vcodec: disable wait interrupt for svp mode media: mediatek: vcodec: support tee decoder media: mediatek: vcodec: move vdec init interface to setup callback media: mediatek: vcodec: support hevc svp for mt8188 .../userspace-api/media/v4l/buffer.rst | 10 +- .../media/v4l/pixfmt-reserved.rst | 8 + drivers/dma-buf/dma-heap.c | 139 +++++-- .../media/common/videobuf2/videobuf2-core.c | 21 + .../common/videobuf2/videobuf2-dma-contig.c | 8 + .../media/common/videobuf2/videobuf2-dma-sg.c | 8 + .../media/common/videobuf2/videobuf2-v4l2.c | 4 +- .../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 | 150 ++++--- .../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 +- .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 97 +++-- .../decoder/vdec/vdec_h264_req_common.c | 18 +- .../decoder/vdec/vdec_h264_req_multi_if.c | 334 +++++++++------ .../decoder/vdec/vdec_hevc_req_multi_if.c | 89 ++-- .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 91 +++-- .../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 + 33 files changed, 1456 insertions(+), 394 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.25.1