From patchwork Wed Dec 6 08:15:18 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: 174408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957066vqy; Wed, 6 Dec 2023 00:16:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9DOnRZJH0An3s11ji3qCdmcTClVpIoK0Hwo7pj+FhOPyQcTWiAeA9Z0NPcdoWtSXANfFb X-Received: by 2002:a17:90b:4cc2:b0:286:6cc0:caea with SMTP id nd2-20020a17090b4cc200b002866cc0caeamr521487pjb.97.1701850570296; Wed, 06 Dec 2023 00:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850570; cv=none; d=google.com; s=arc-20160816; b=Y3qqa1ThwrP/avu2P2VyGJLu5TCnPmLjKygzJ81dFH5b/52vqnhry5eBbzRSYKbiSB +LsuRGSer7QVarNj0pQbugP+Gi3YwZ8toJL1/sHPZRqB6US2oMYw/RsGOJ1aEZjNWSgx xY1zGbiNQOaVGSG3c6Yn6Mp/Ovs4Yw9g2C8oYIQcXz+P18gwp8yGLqODgTKkPMZwzihy jdUoBCDoK6LI9I4Jyr8Ml1uLhPRduysSlDuCmUyKetv1t1K0FZoVoLIA6udtww4EmI0s yPRiK1SJhsEscNPJwTbHEzc2pd8pkebeMzlIu8zCkzAbQumgP4cof34mHg2KfR8BDy8G fwPg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Gtxt/C4CIwXGjWvyCwDlPRCsxH6BQ3m1lajwI0U2H/U=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=KmHDm7VKX0n9gjP1tDoayyoAj9sSXxfPgIFqBLo2NwvVKgAKMzkPZL/X+IbYRZbzf4 QmvVTRux4eAr7i4ASk0OAw9S5qxwtwbAk8FjEsyhG/ocDyk/0Lztm9ZnlLDoUCF8id1k WcIjiTOFdDCiSNO5kWD6YIHGgAMS/tQ35D9sfQLuZUeGhONvl5nt2VX4AakboVJ1jesP voF1D8eLThiHTsXvX6P5iiMP9ANdOD3wI+tSx4pC/uI6YaEcySI65NiKopQlDxXhKpsu OHpEmVGsmCQYdK/iwh2B0MP6840W8jecMvKbxJw3Qo+lO2iRaMQCU4aWarzeh07dp7aF 7TNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=IKdLnIG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id gg16-20020a17090b0a1000b002866c405e01si7380324pjb.17.2023.12.06.00.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=IKdLnIG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 76CA982DC602; Wed, 6 Dec 2023 00:16:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377149AbjLFIPu (ORCPT + 99 others); Wed, 6 Dec 2023 03:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376876AbjLFIPr (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 6E3C0D3; Wed, 6 Dec 2023 00:15:50 -0800 (PST) X-UUID: a6618ab6940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Gtxt/C4CIwXGjWvyCwDlPRCsxH6BQ3m1lajwI0U2H/U=; b=IKdLnIG7QRgMwItgumiEt9xwdq5SbopCgrJ6f5g1Kl4amHuhPrhxwKeQuinsmjgLx/MCc1trvmB/uYJBWFbuCgKGDGGgwSZNLiIivCoR5k7psPnkTVW7LnNbdvl3czKNukupwytsRBTVLDPfLyCWMG9n5aSpD0rhKUc6SGILyPc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:84038762-c0ff-40f4-b327-d31c9d9da937,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:182c59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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 X-UUID: a6618ab6940f11eea33bb35ae8d461a2-20231206 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 1042332511; Wed, 06 Dec 2023 16:15:43 +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; Wed, 6 Dec 2023 16:15:41 +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:40 +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,01/21] v4l2: add secure memory flags Date: Wed, 6 Dec 2023 16:15:18 +0800 Message-ID: <20231206081538.17056-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--4.791700-8.000000 X-TMASE-MatchedRID: jAP7Z+txIHYXSulpnju2H4SvKOGqLLPKK2i9pofGVStcU0dNErOD+mlF 7OhYLlctcYKRVYWgduVAw/iJrysrSm+IsUfG75P2joyKzEmtrEeQoBr+SFneJJj9R7obtcgyH5L 2GhBQtff4ei4a6fEfjpynPbWEKM6u8xjBEybW2by3HA8h5a0MOXnL427v8Q461gisw2JKo8lYua /kyrSLKzqKm/4qdbn8gDLqnrRlXrZ8nn9tnqel2MprJP8FBOIa2ntLqnPa1U32O6TmKuehrIU0+ TfNuMYBg5SfNRWImmHKWqep8B//Hg6qbFFxcFTguN8K5GvhTbfHIhLbWKGpxiA2fMrPTSd/T07L PKPPWmXzYaPZALfIbSyZdUr8fx4fMbuyvvGhtIDNwMS8lpRKBQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.791700-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 97FF8B845C51ADA254BD35568E7F9B4AB38BDE9BF69A393FCA1FA0275D045FFC2000:8 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519663896570901 X-GMAIL-MSGID: 1784519663896570901 From: Jeffrey Kardatzke Adds a V4L2 flag which indicates that a queue is using secure dmabufs and the corresponding capability flag. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- include/media/videobuf2-core.h | 8 +++++++- include/uapi/linux/videodev2.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 5557d78b6f20..98eba43661c1 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -518,6 +518,9 @@ struct vb2_buf_ops { * ->finish(). * @non_coherent_mem: when set queue will attempt to allocate buffers using * non-coherent memory. + * @allow_secure_mem: when set user-space can pass the %V4L2_MEMORY_FLAG_SECURE + * flag to indicate the dma bufs are secure. + * @secure_mem: when set queue will verify that the dma bufs are secure. * @lock: pointer to a mutex that protects the &struct vb2_queue. The * driver can set this to a mutex to let the v4l2 core serialize * the queuing ioctls. If the driver wants to handle locking @@ -601,6 +604,8 @@ struct vb2_queue { unsigned int uses_requests:1; unsigned int allow_cache_hints:1; unsigned int non_coherent_mem:1; + unsigned int allow_secure_mem:1; + unsigned int secure_mem:1; struct mutex *lock; void *owner; @@ -770,7 +775,8 @@ void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb); * @q: pointer to &struct vb2_queue with videobuf2 queue. * @memory: memory type, as defined by &enum vb2_memory. * @flags: auxiliary queue/buffer management flags. Currently, the only - * used flag is %V4L2_MEMORY_FLAG_NON_COHERENT. + * used flags are %V4L2_MEMORY_FLAG_NON_COHERENT and + * %V4L2_MEMORY_FLAG_SECURE. * @count: requested buffer count. * * Videobuf2 core helper to implement VIDIOC_REQBUF() operation. It is called diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 68e7ac178cc2..570b11552818 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1026,6 +1026,7 @@ struct v4l2_requestbuffers { }; #define V4L2_MEMORY_FLAG_NON_COHERENT (1 << 0) +#define V4L2_MEMORY_FLAG_SECURE (1 << 1) /* capabilities for struct v4l2_requestbuffers and v4l2_create_buffers */ #define V4L2_BUF_CAP_SUPPORTS_MMAP (1 << 0) @@ -1036,6 +1037,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) +#define V4L2_BUF_CAP_SUPPORTS_SECURE_MEM (1 << 8) /** * struct v4l2_plane - plane info for multi-planar buffers From patchwork Wed Dec 6 08:15:19 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: 174409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957126vqy; Wed, 6 Dec 2023 00:16:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFknO02QXCVogGvzL3zv8A+Vt1GMVJk01gF23G1FdsiZVCwcgknqAhZytLJaVf9bEQuK/JK X-Received: by 2002:a05:6359:6006:b0:170:2f73:bb98 with SMTP id rw6-20020a056359600600b001702f73bb98mr429377rwb.44.1701850579220; Wed, 06 Dec 2023 00:16:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850579; cv=none; d=google.com; s=arc-20160816; b=goMwn29Me3FphRuzsBhGDUsJstPYF/eUzSYtlylE0e5V5pGCMhHWZYxo6uy4fdTXHx L304ujhBUOvBqGCgKQtGPUbq/7WlEm6NVLosT80Q3mge1QjL2yuq3fWoeDWfGiu16ru+ Sy5+RlD73zLKG+ubsACBXBT7oiDxS4lguEK3FGndPNsaNsMlkyahDN2QaKLWFgX01ubE 2CFf2l41+a8AL7e1TfJ1MAes6GyiyOAt4wsyglHKg6zFuxZKEVUNXTWyKoIELHyg/sII rprNXRjqgpfrY+cbI9mHSIgAV2zz3vNEhFRa7MDwH5inspZxW2SExIuIDrehbi8xnBV+ 1SYw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5hNl/ebhPBItzu4pN+YmmtZTsVFNCochFPrIS+vXnfY=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=RRk5aFPQbUZeRaJ2nOb+bOvpvThpYYxUNoCklVfLNhfj8ESAVbRr2iLmX3OprZ9uJ0 NK3fwgVdgrAZm1XhM/guFCTCZkt1tdABXCfHdeoFi5x2WtC6YtZLm8EucQLytwBqQJ2u Az1YbUrzoY8j4qw5jymicxSwAmlZDrQYJkg0Uy8ygbvbX+bVk8faahJ21inrTKjRpgjb gSYgComzJgbHUidb1Y06rBa4KTeqbwRkNPKH8kp9/PPxtqYkvFPQ9pkbK0oPlNxSU4of 6PJxXFQVbGfRf0+77I0IiVRERvCUP+QeHIiK5Zs9acECEd0mP6czARXsx/E1r0DWjzlZ AZFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=gYtRdNvB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id fy22-20020a17090b021600b0028694fc7a61si5572876pjb.13.2023.12.06.00.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=gYtRdNvB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id A405082D7567; Wed, 6 Dec 2023 00:16:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377175AbjLFIPz (ORCPT + 99 others); Wed, 6 Dec 2023 03:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377146AbjLFIPs (ORCPT ); Wed, 6 Dec 2023 03:15:48 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0C41A4; Wed, 6 Dec 2023 00:15:51 -0800 (PST) X-UUID: a6de4e52940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=5hNl/ebhPBItzu4pN+YmmtZTsVFNCochFPrIS+vXnfY=; b=gYtRdNvBnXmhjW2UzxGr6PEiYAfzK9e3J98h0WKmO/dZL+TiRaH+Wzx06KnriWqPpFZcOEZ92KUwFb3uzExjoGXOxCOh1ZnQDVM4off6EfXe2Q4EsK1q6OqLRwbLruflO+RmjgDcErhfkGErhS64cjR4BDgn8cOT0dCaBOuz2lg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:eada1246-6692-4119-9f39-76b9732126cb,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:6d853596-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: a6de4e52940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1271472418; Wed, 06 Dec 2023 16:15:44 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n2.mediatek.inc (172.21.101.187) 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:42 +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:41 +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,02/21] v4l2: handle secure memory flags in queue setup Date: Wed, 6 Dec 2023 16:15:19 +0800 Message-ID: <20231206081538.17056-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519673178064442 X-GMAIL-MSGID: 1784519673178064442 From: Jeffrey Kardatzke Validates the secure memory flags when setting up a queue and ensures the queue has the proper capability. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- .../media/common/videobuf2/videobuf2-core.c | 23 +++++++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 34 +++++++++++++------ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 8c1df829745b..09dc030484be 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -813,6 +813,15 @@ static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem) return true; } +static bool verify_secure_mem_flags(struct vb2_queue *q, bool secure_mem) +{ + if (secure_mem != q->secure_mem) { + dprintk(q, 1, "secure memory model mismatch\n"); + return false; + } + return true; +} + int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count) { @@ -820,6 +829,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int q_num_bufs = vb2_get_num_buffers(q); unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; + bool secure_mem = flags & V4L2_MEMORY_FLAG_SECURE; unsigned int i; int ret = 0; @@ -836,6 +846,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (*count == 0 || q_num_bufs != 0 || (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory) || !verify_coherency_flags(q, non_coherent_mem)) { + bool no_previous_buffers = !q->num_buffers; + /* * We already have buffers allocated, so first check if they * are not in use and can be freed. @@ -854,6 +866,12 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, __vb2_queue_free(q, q_num_bufs); mutex_unlock(&q->mmap_lock); + /* + * Do not allow switching secure buffer mode. + */ + if (!no_previous_buffers && !verify_secure_mem_flags(q, secure_mem)) + return -EINVAL; + /* * In case of REQBUFS(0) return immediately without calling * driver's queue_setup() callback and allocating resources. @@ -882,6 +900,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (ret) return ret; set_queue_coherency(q, non_coherent_mem); + q->secure_mem = secure_mem; /* * Ask the driver how many buffers and planes per buffer it requires. @@ -986,6 +1005,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; unsigned int q_num_bufs = vb2_get_num_buffers(q); + bool secure_mem = flags & V4L2_MEMORY_FLAG_SECURE; bool no_previous_buffers = !q_num_bufs; int ret = 0; @@ -1015,6 +1035,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return ret; q->waiting_for_buffers = !q->is_output; set_queue_coherency(q, non_coherent_mem); + q->secure_mem = secure_mem; } else { if (q->memory != memory) { dprintk(q, 1, "memory model mismatch\n"); @@ -1022,6 +1043,8 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, } if (!verify_coherency_flags(q, non_coherent_mem)) return -EINVAL; + if (!verify_secure_mem_flags(q, secure_mem)) + return -EINVAL; } num_buffers = min(*count, q->max_num_buffers - q_num_bufs); diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 54d572c3b515..0a530830276c 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -686,22 +686,30 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) *caps |= V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS; if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; + if (q->allow_secure_mem && q->io_modes & VB2_DMABUF) + *caps |= V4L2_BUF_CAP_SUPPORTS_SECURE_MEM; } -static void validate_memory_flags(struct vb2_queue *q, +static bool validate_memory_flags(struct vb2_queue *q, int memory, u32 *flags) { + if (*flags & V4L2_MEMORY_FLAG_SECURE && + (!q->allow_secure_mem || memory != V4L2_MEMORY_DMABUF)) { + return false; + } + if (!q->allow_cache_hints || memory != V4L2_MEMORY_MMAP) { /* - * This needs to clear V4L2_MEMORY_FLAG_NON_COHERENT only, - * but in order to avoid bugs we zero out all bits. + * This needs to clear V4L2_MEMORY_FLAG_NON_COHERENT only. */ - *flags = 0; - } else { - /* Clear all unknown flags. */ - *flags &= V4L2_MEMORY_FLAG_NON_COHERENT; + *flags &= ~V4L2_MEMORY_FLAG_NON_COHERENT; } + + /* Clear all unknown flags. */ + *flags &= V4L2_MEMORY_FLAG_NON_COHERENT | V4L2_MEMORY_FLAG_SECURE; + + return true; } int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) @@ -710,7 +718,8 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) u32 flags = req->flags; fill_buf_caps(q, &req->capabilities); - validate_memory_flags(q, req->memory, &flags); + if (!validate_memory_flags(q, req->memory, &flags)) + return -EINVAL; req->flags = flags; return ret ? ret : vb2_core_reqbufs(q, req->memory, req->flags, &req->count); @@ -752,7 +761,8 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) unsigned i; fill_buf_caps(q, &create->capabilities); - validate_memory_flags(q, create->memory, &create->flags); + if (!validate_memory_flags(q, create->memory, &create->flags)) + return -EINVAL; create->index = vb2_get_num_buffers(q); create->max_num_buffers = q->max_num_buffers; create->capabilities |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS; @@ -1007,7 +1017,8 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, u32 flags = p->flags; fill_buf_caps(vdev->queue, &p->capabilities); - validate_memory_flags(vdev->queue, p->memory, &flags); + if (!validate_memory_flags(vdev->queue, p->memory, &flags)) + return -EINVAL; p->flags = flags; if (res) return res; @@ -1031,7 +1042,8 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv, p->index = vdev->queue->num_buffers; fill_buf_caps(vdev->queue, &p->capabilities); - validate_memory_flags(vdev->queue, p->memory, &p->flags); + if (!validate_memory_flags(vdev->queue, p->memory, &p->flags)) + return -EINVAL; /* * If count == 0, then just check if memory and type are valid. * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0. From patchwork Wed Dec 6 08:15:20 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: 174410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957203vqy; Wed, 6 Dec 2023 00:16:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZhG5jZeLElKFpFsdqwb8zM7yyEqrqE2k/e1FipPC8jgdFt3XNAVjx2kXUlqoceQ75x9os X-Received: by 2002:a17:902:684c:b0:1d0:6ffd:837d with SMTP id f12-20020a170902684c00b001d06ffd837dmr169810pln.136.1701850592006; Wed, 06 Dec 2023 00:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850591; cv=none; d=google.com; s=arc-20160816; b=cQFxVPIML3L7JyJNMNS5TqfnUzAvj+Sm81BEmIJLzTZkk8+5XmmQyZ7jA72hVlIntd oo0IFNodoFvG0VNKgPI66xZqu1amldP3Mb7Icmm+vHdmzmzqR0nohzCfoLn2af3KFzEg Zn9/HbSOq5rJiJEOonCk1GzuOqiDf0LYijhres+NGt1wg1x4o+eswHHRkJqiYf7rQOBN 44ftNm+CJmvLEQ8GANvIYlbFiLin6GCpDVzjj9EChaESDphqtt+XCQk85JqSCFPjPEhF tLSZceojYHsXd4qjN8h4qFk5BsgI1HruigEc38PT+iETSsemZ06XDmlaz5geRR81m1oJ QnMQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xbClLI66nLXR6+DrvXNRdDsoO2AywNyP9UvNF0j25Es=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=JHH3uGN4KseWXDlw4qvPHKJn02WBWQX0Q5qpDZiO3D1anrSp4JxBtxQDbLxSI8/WgL oFoDC0I0TqXyo37dZL8tOwWC8Nhw44LoQgKO70fzN7alBEzewXQkDmGrBsZ+4DVkqlcj tIY3WtcICt/YGB5VW2cpF3tGfvSO8hxob34vqxWeNLFQk63dkEH8t2e/7Zqf3QyzlYvp HvlyUTWDcYEJlm6CBWeX8GwUmm3mVYBQFqF1EJYedNuFya4BWf2y/3tODxc9yYdefA45 s5rDujojnUbVlyj0/JY1tSEinziEX3NRXecugbUJIKoVUqAv78YFMiGVn1OrjLcZL/3A MX2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cRW6mP1p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id k8-20020a170902694800b001cfcf3dd310si10758750plt.505.2023.12.06.00.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cRW6mP1p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 6EED3802FA3C; Wed, 6 Dec 2023 00:16:25 -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 S1377195AbjLFIQB (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377151AbjLFIPu (ORCPT ); Wed, 6 Dec 2023 03:15:50 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B46601B5; Wed, 6 Dec 2023 00:15:56 -0800 (PST) X-UUID: a7c3619a940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=xbClLI66nLXR6+DrvXNRdDsoO2AywNyP9UvNF0j25Es=; b=cRW6mP1pz65/Eq+nfYOerOJHYeI/9JkAmywuPWYpfUabXpatevW8XDcBcQgNqsBjATJ+O4ZuMBSCID4LkVllPe92zWIwhucgPeFKsAvOoVcAt1UI0hABGHBZDSRq85feMiBYlF8D0dh+6CZQEEOGgJaxKDr6h7/0GaUIr7JUMMA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:2fb79652-11d7-43fc-9a4f-6b44832471ca,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:abefa75,CLOUDID:20e87773-1bd3-4f48-b671-ada88705968c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: a7c3619a940f11ee8051498923ad61e6-20231206 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1903711512; Wed, 06 Dec 2023 16:15:45 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n2.mediatek.inc (172.21.101.108) 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:44 +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:42 +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,03/21] v4l2: verify secure dmabufs are used in secure queue Date: Wed, 6 Dec 2023 16:15:20 +0800 Message-ID: <20231206081538.17056-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> 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:16:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519686509193285 X-GMAIL-MSGID: 1784519686509193285 From: Jeffrey Kardatzke Verfies in the dmabuf implementations that if the secure memory flag is set for a queue that the dmabuf submitted to the queue is unmappable. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- drivers/media/common/videobuf2/videobuf2-dma-contig.c | 6 ++++++ drivers/media/common/videobuf2/videobuf2-dma-sg.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index 3d4fd4ef5310..ad58ef8dc231 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -710,6 +710,12 @@ static int vb2_dc_map_dmabuf(void *mem_priv) return -EINVAL; } + /* verify the dmabuf is secure if we are in secure mode */ + if (buf->vb->vb2_queue->secure_mem && sg_page(sgt->sgl)) { + pr_err("secure queue requires secure dma_buf"); + return -EINVAL; + } + /* checking if dmabuf is big enough to store contiguous chunk */ contig_size = vb2_dc_get_contiguous_size(sgt); if (contig_size < buf->size) { diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 28f3fdfe23a2..55428c73c380 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -564,6 +564,12 @@ static int vb2_dma_sg_map_dmabuf(void *mem_priv) return -EINVAL; } + /* verify the dmabuf is secure if we are in secure mode */ + if (buf->vb->vb2_queue->secure_mem && !sg_dma_secure(sgt->sgl)) { + pr_err("secure queue requires secure dma_buf"); + return -EINVAL; + } + buf->dma_sgt = sgt; buf->vaddr = NULL; From patchwork Wed Dec 6 08:15:21 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: 174411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957246vqy; Wed, 6 Dec 2023 00:16:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHg+waBrQdJOL5QH6/NcjhifbIOcOEgcEyAZbqSjauhOyE07yX8u8Sc57tiBtXMDV+zIaF3 X-Received: by 2002:a17:902:da91:b0:1d0:6ffd:834c with SMTP id j17-20020a170902da9100b001d06ffd834cmr209756plx.87.1701850599442; Wed, 06 Dec 2023 00:16:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850599; cv=none; d=google.com; s=arc-20160816; b=fdfZpXgGF+5UQaPEdDIHlW2VaXmmXIcfNZW3uZ/PNlW+s3nu+aThevK+iRb8bjZElR qxmHS2xD2Abn9X3neUs4UbgMsXKCyodgCzqs44zVX30kwkb2+uj0tLPqbZfNL8Jt+URz 9Bu/4H77lx6rUdAWiA0sJQSZlFXfXvJMPVySNZ8oQaN7rM1WWsfU30UmLMKUKuSVGXl0 R5olk9oYiKbD/HwWI2udEaAUCg1NWVq3Fb1gSt8Hl/jTJ+ZxZplpb1wr5rAteEP6YtQm Hastk8jREo46UKjtr8j1Y39qVBRR9LgODabQxX2huoh93Umwlsp4aWb7fqCX79YS0zpb E4Hg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=urgImsiByBgrXegm6WMvOjpTwwvXom0xQlrJXyilo6s=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=Z7we8iz7mcZCk5DQX76WVBLinw/8UYAH6U7/pQK29iVDS6FbBQDUYsMI4O3c/BWIIr XCawkdmcr5P6q1o0upJSg0JhFIp0+pHY1vRnNZljYmxvSgWuygtl9Gq2rs4JFCdcupOj p7ePfeJmOPjBnRYFPVtqLFq15DtrzviGkbuE5xMjEK/ifTIyWciYMenmVYdQK38LX3cf 3U6WRqytJ2YCUba+/f4b2x7zjTmIyuLbKFFoNX5v6IRYgdFkJyPDE+5UUb7wjD7FurhH wtv1POAYc4jgVdBh3qNULKBJwyVWDcKIwTx9hcJ4vZ1VFVTL/k7aJ40j9Geqpl7XXQLA IKiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=p0UGmzxW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d5-20020a170903230500b001cffd427123si11023080plh.311.2023.12.06.00.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=p0UGmzxW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id B90ED82217BA; Wed, 6 Dec 2023 00:16:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377165AbjLFIPx (ORCPT + 99 others); Wed, 6 Dec 2023 03:15:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377130AbjLFIPs (ORCPT ); Wed, 6 Dec 2023 03:15:48 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB731B6; Wed, 6 Dec 2023 00:15:53 -0800 (PST) X-UUID: a83f1c40940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=urgImsiByBgrXegm6WMvOjpTwwvXom0xQlrJXyilo6s=; b=p0UGmzxWkJfc7l7bOHoFTAU121adV3QzyXtZn/Yb4Wd/cx55kB51+4E9h14rEvgllseFcLAHKcBn/BWxQpi7t9Ul4Iwezc6GTRgDhMsiY4p+VBM9pfogxse15nCtZRcjsQu3CfuyXJS0bVNFZcqnzg28KjJ/Y5mQeiIuoOyTkgw=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:084f54ed-d3de-44d3-82c6-f9e264a9ad3f,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:fc78e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: a83f1c40940f11eea33bb35ae8d461a2-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 666144678; Wed, 06 Dec 2023 16:15:46 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) 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:45 +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:44 +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,04/21] v4l: add documentation for secure memory flag Date: Wed, 6 Dec 2023 16:15:21 +0800 Message-ID: <20231206081538.17056-5-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--1.856300-8.000000 X-TMASE-MatchedRID: +AidzxpkJ38len1U/pCyeimjEOrcO6AyTJDl9FKHbrkGxREerP+37XVX 4shSYpPIU5vypzAbVDHw2zJ6wUH6fAzyMxeMEX6wFEUknJ/kEl7dB/CxWTRRu3aDLLDbFMGFulx dtyQZLh53HVPe88KdTDg/PKEqtQb3gHAX9tDTTwxXYbvoEL9Fh5eGzU7OKNA+t2s1xSAfRMhnhe wZo9ULByfMiHC5NEpshJVRlkc0uv5GBXoeyrLHXVBo425nomviD2TeXwRpghwOIqZ2uUSDWA== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--1.856300-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 6F2C690914310194B509D2CC4027E85D4837A1E2709D2F4C44AF927E89CD2DFB2000:8 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 morse.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 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519694171347424 X-GMAIL-MSGID: 1784519694171347424 From: Jeffrey Kardatzke Adds documentation for V4L2_MEMORY_FLAG_SECURE. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- Documentation/userspace-api/media/v4l/buffer.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/buffer.rst b/Documentation/userspace-api/media/v4l/buffer.rst index 52bbee81c080..a5a7d1c72d53 100644 --- a/Documentation/userspace-api/media/v4l/buffer.rst +++ b/Documentation/userspace-api/media/v4l/buffer.rst @@ -696,7 +696,7 @@ enum v4l2_memory .. _memory-flags: -Memory Consistency Flags +Memory Flags ------------------------ .. raw:: latex @@ -728,6 +728,12 @@ Memory Consistency Flags only if the buffer is used for :ref:`memory mapping ` I/O and the queue reports the :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS ` capability. + * .. _`V4L2-MEMORY-FLAG-SECURE`: + + - ``V4L2_MEMORY_FLAG_SECURE`` + - 0x00000002 + - DMA bufs passed into the queue will be validated to ensure they were + allocated from a secure dma-heap. .. raw:: latex From patchwork Wed Dec 6 08:15:22 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: 174419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957396vqy; Wed, 6 Dec 2023 00:17:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhBDUDzp66IwRFS8eXp1A7DlhbYzHjQ8V5s73Pox8QBwOjxDfoYU4YFqPIwuRP15drusZw X-Received: by 2002:a05:6e02:1c8d:b0:35d:7f56:17f3 with SMTP id w13-20020a056e021c8d00b0035d7f5617f3mr832380ill.65.1701850622602; Wed, 06 Dec 2023 00:17:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850622; cv=none; d=google.com; s=arc-20160816; b=0LHbSX+gR6hpNigut/bImlOCUUdJ3lDiwco2e3JcnNmMdcPe9IRM8St5Y0TUUO6MMF WnMWj8WB9RQwtAhN6jKiufrW+B7jSutTcSoHtz/ukwvLisDI6vFX3Rp7ZDTQsek7oLvj AUUCClgljYRkorVYgh2dFhHPrLAtzByrSUNhHUkn7WeY9//g7OhlabZhC0jEIF6ma5UE /8iFfE5zw/JlSe4WKDGjpSNeOOrnHcCvmDLGHKbaxpcuWWZfxGxH4gMnN8QnM0SBlcmx 0x9Y/PY3rPYE/WzZ9w4dHlwxfeYTQvXGMEumjtOCL/6w8KSd5UXI2EzTM5l52xyaeoj9 byIA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t55MQIgMEx4p4MEJHDKfM0Ly5GklrK5skqp8MOiYDJY=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=cvnDRLKS6ahFh11TKH+gtWN4i293RrNkWF84A72an1/0mDMYNB4Xvg7EnswIX1jmSB jyzoQBC/DEwvON7h00SyCbA0TwLLtqtRM7MxiAqy8JxRuzm7W5Tx3ClvvI1TTYRc4Kua b+zbv/gm5gAWJhdkKGPH7/1aHtQYXoB/ya9Y5/H6rx/kEG2G2Q4+X+XKhZaGwcyPr+5x IaBX+1H0jS2diX+ZHmgHtQNvD1gnw7Mg7k+6hms5+xhB2RrmbgiVuqe/avAIpcThdSws P/aR9a9jVvbtSBPhk0DbTBBVEgaH6OjvCHN9z7jPwW1l84vdQIDISztGSubNpB4ewy8G bBLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=pcw0zp+4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k20-20020a63d114000000b005c1c5d338a9si11142711pgg.658.2023.12.06.00.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=pcw0zp+4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id D7E8E80AD285; Wed, 6 Dec 2023 00:16:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377214AbjLFIQJ (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377176AbjLFIPz (ORCPT ); Wed, 6 Dec 2023 03:15:55 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A819B1B6; Wed, 6 Dec 2023 00:15:58 -0800 (PST) X-UUID: a9f28c34940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=t55MQIgMEx4p4MEJHDKfM0Ly5GklrK5skqp8MOiYDJY=; b=pcw0zp+4a3KPuJMIEvo9twVvc2JQGSxFoIKEq0rcqMlLZ3nO1DGJPUAJr3XxwlYuXl6oDhnY0YzOU3rYrZo4UeY5zJjTF7mcXV8NoZqdIfFw6LkxitV1XR08ZDYO6Gx3jPysCsmfiBtuDlWO0q1LgsoflXeEq0lVr3gLosn30yY=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:bef016e7-11dd-4c80-b5a2-ea8f5349dbfc,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:1f79e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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 X-UUID: a9f28c34940f11ee8051498923ad61e6-20231206 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1387869461; Wed, 06 Dec 2023 16:15:49 +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; Wed, 6 Dec 2023 16:15:46 +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:45 +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,05/21] dma-buf: heaps: Deduplicate docs and adopt common format Date: Wed, 6 Dec 2023 16:15:22 +0800 Message-ID: <20231206081538.17056-6-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--0.731800-8.000000 X-TMASE-MatchedRID: +2zAcmHD8Q7wUuSygkLx9JD6BbDN9+jOQKuv8uQBDjpU4V1pMvNQR62r pHsK32BkBMhVYRT3oC/ANNz/A2ARw8VLWPBZNJvOhK8o4aoss8pKPIx+MJF9o99RlPzeVuQQOAX Ig5vwe9o0ULOv9iNOM/3selkw4oOREKA/i6/8kSnJ1E/nrJFED+rRJDUyDHkImyiLZetSf8mfop 0ytGwvXiq2rl3dzGQ19+9ZqEp9FTjXPo0z12/ROTwabOz3sXuUEFC9e5y4FdRPp2EJbxyQMRNGO R3mIPS0sgmJnZJxzECAf086W8np7I+ZbND4/NfDqkwQ8MbhzZZpp55fZDlsr34cY/B7JqXaYZ1R 7NXn0MdBmmCXcKyFFJ6oP1a0mRIj X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--0.731800-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 4B3423C156AF46DC64CFAD9D8E3B996C5EEFB905C0D89F76EAF48E07F2C85BE22000:8 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 fry.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 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519718380608966 X-GMAIL-MSGID: 1784519718380608966 From: "T.J. Mercier" The docs for dma_heap_get_name were incorrect, and since they were duplicated in the header they were wrong there too. The docs formatting was inconsistent so I tried to make it more consistent across functions since I'm already in here doing cleanup. Remove multiple unused includes and alphabetize. Signed-off-by: T.J. Mercier Signed-off-by: Yong Wu [Yong: Just add a comment for "priv" to mute build warning] Signed-off-by: Yunfei Dong --- drivers/dma-buf/dma-heap.c | 27 +++++++++++++++------------ include/linux/dma-heap.h | 21 +-------------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 84ae708fafe7..22f6c193db0d 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -7,17 +7,15 @@ */ #include -#include #include #include +#include #include -#include #include -#include #include -#include #include -#include +#include +#include #include #define DEVNAME "dma_heap" @@ -28,9 +26,10 @@ * struct dma_heap - represents a dmabuf heap in the system * @name: used for debugging/device-node name * @ops: ops struct for this heap - * @heap_devt heap device node - * @list list head connecting to list of heaps - * @heap_cdev heap char device + * @priv: private data for this heap + * @heap_devt: heap device node + * @list: list head connecting to list of heaps + * @heap_cdev: heap char device * * Represents a heap of memory from which buffers can be made. */ @@ -193,11 +192,11 @@ static const struct file_operations dma_heap_fops = { }; /** - * dma_heap_get_drvdata() - get per-subdriver data for the heap + * dma_heap_get_drvdata - get per-heap driver data * @heap: DMA-Heap to retrieve private data for * * Returns: - * The per-subdriver data for the heap. + * The per-heap data for the heap. */ void *dma_heap_get_drvdata(struct dma_heap *heap) { @@ -205,8 +204,8 @@ void *dma_heap_get_drvdata(struct dma_heap *heap) } /** - * dma_heap_get_name() - get heap name - * @heap: DMA-Heap to retrieve private data for + * dma_heap_get_name - get heap name + * @heap: DMA-Heap to retrieve the name of * * Returns: * The char* for the heap name. @@ -216,6 +215,10 @@ const char *dma_heap_get_name(struct dma_heap *heap) return heap->name; } +/** + * dma_heap_add - adds a heap to dmabuf heaps + * @exp_info: information needed to register this heap + */ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) { struct dma_heap *heap, *h, *err_ret; diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 0c05561cad6e..fbe86ec889a8 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -9,14 +9,13 @@ #ifndef _DMA_HEAPS_H #define _DMA_HEAPS_H -#include #include struct dma_heap; /** * struct dma_heap_ops - ops to operate on a given heap - * @allocate: allocate dmabuf and return struct dma_buf ptr + * @allocate: allocate dmabuf and return struct dma_buf ptr * * allocate returns dmabuf on success, ERR_PTR(-errno) on error. */ @@ -41,28 +40,10 @@ struct dma_heap_export_info { void *priv; }; -/** - * dma_heap_get_drvdata() - get per-heap driver data - * @heap: DMA-Heap to retrieve private data for - * - * Returns: - * The per-heap data for the heap. - */ void *dma_heap_get_drvdata(struct dma_heap *heap); -/** - * dma_heap_get_name() - get heap name - * @heap: DMA-Heap to retrieve private data for - * - * Returns: - * The char* for the heap name. - */ const char *dma_heap_get_name(struct dma_heap *heap); -/** - * dma_heap_add - adds a heap to dmabuf heaps - * @exp_info: information needed to register this heap - */ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); #endif /* _DMA_HEAPS_H */ From patchwork Wed Dec 6 08:15:23 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: 174413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957266vqy; Wed, 6 Dec 2023 00:16:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqqjImXifxxEKpHZXncPwQCXviwHyqBwYa2bbxqTFQiNF2iJ/KKPoey8XxUbBb48g0MJrx X-Received: by 2002:a17:903:2642:b0:1d0:6ffd:8344 with SMTP id je2-20020a170903264200b001d06ffd8344mr221913plb.79.1701850602607; Wed, 06 Dec 2023 00:16:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850602; cv=none; d=google.com; s=arc-20160816; b=PAY+iebc3z6wOdjfiz79rpjxdFQQjgqpBie43mEYWqmXe+QAQLRYyoaj2CfRPlvEY1 +0mHxZ4fQhwEJHIErv57yWKv6CH8pfFzEK3h+1ZdQ5O/w6uP2pWuC73MjR21up0JfgPP 8oSWBQRFtMIQ9SFS/hiFYnBK3GXHTewXDxdfWTgb6y1gaWNtN4vDHLiysJBffYpYv/UT uuDnQb7Bp+1pXVBPPv8eXZXm/C7XSbnO5ghheTS14Ysl4X1OXxWSBCY+g1El36feRqh7 claPYc2d/XBWDAipKhIpHxWFnyfoB/P6Ix63KJgkb6vDEkbq2+AMOFcEcSAlxuJJgClb Ubtg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VBRSF4YwZCz5T0Zk1nE7YVf8B1quLvMs45dUf37h/JQ=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=lj9U/BfuvaIO5Q+CT+2vI3x9UsZ29OplC/mFzDTgiPEH5kmtg8nBAAY7z99KtcS/NX si/qgVF/I3yHgSQgq1vV17xQcjMxUPZE9fOti13BopTvK/i4J0AbRywXEU3ryb8Qm1oC 392F6gQSFpHZ+pcN8wOyRODgAgkZqoQU2/xQqTclQ8hy3DaIngk/dZ5lfymQ6LvZT0R1 HopKgiiHB+DThvKAwd2M07gI8dsFDx4OfKnlyqFZXn15AG6pI/x2Qh4E0OEVzW/y2AuA VHEvxCArMgTr96SkDSUaU2/3xHmuJt4iyqe5qnuK0gZpf8Ef0CT4UdIk/d4wZKnlokRv lsXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=jqeH0PWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y13-20020a170902ed4d00b001d0d15b9c7dsi1511307plb.563.2023.12.06.00.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=jqeH0PWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id B23BB80A91AA; Wed, 6 Dec 2023 00:16:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377202AbjLFIQE (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377154AbjLFIPv (ORCPT ); Wed, 6 Dec 2023 03:15:51 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AABB18D; Wed, 6 Dec 2023 00:15:56 -0800 (PST) X-UUID: a9c3360a940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=VBRSF4YwZCz5T0Zk1nE7YVf8B1quLvMs45dUf37h/JQ=; b=jqeH0PWAhJQkx1ElyiTCWuIRacLx8zIcruZCsZI6BrjSvKUKolQRdAMlI4PD2qv0b6Q7i7n6qyD7kD/5oH/bTCNwYbkD4lYbRHCYLb69Abx5RkpdcKOKfuSjhTrkWwJz+9srfONvygxAboepKI46Bz2girWKG7Drc9UpY0COW9U=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:1e3b4d56-d87a-469c-93e0-9a3910b12513,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:abefa75,CLOUDID:f8853596-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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 X-UUID: a9c3360a940f11ee8051498923ad61e6-20231206 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1398791214; Wed, 06 Dec 2023 16:15:48 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) 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:48 +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:46 +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,06/21] dma-heap: Add proper kref handling on dma-buf heaps Date: Wed, 6 Dec 2023 16:15:23 +0800 Message-ID: <20231206081538.17056-7-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--5.336200-8.000000 X-TMASE-MatchedRID: iSQL5szRvdGRKhTVQwgiGPOS+SRxjgFwsuIso71Vk6Is/uUAk6xP7Nn7 b/+Y15IvCPnYMmIYXkdgHnELoaUKtjWBtSWZ+bE64RtSDjG+z7Cb/LTS0T1K1su87Zav+1yuHtb BWB6gIuZsCaY7uWwO5cTKrSvo7uRnHxPMjOKY7A8LbigRnpKlKTpcQTtiHDgW1Goz9/hRq2NY0d SVkkN0n9h7mEPyUSdSJob0wcgRQbbjIeVQlZnKgEMMprcbiest X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.336200-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 5010E22F10B7D1AE6619BD01F84AB1588F6513761E7A90256C147E451EBB1D9C2000:8 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RDNS_NONE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:22 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519697364972299 X-GMAIL-MSGID: 1784519697364972299 From: John Stultz Add proper refcounting on the dma_heap structure. While existing heaps are built-in, we may eventually have heaps loaded from modules, and we'll need to be able to properly handle the references to the heaps Signed-off-by: John Stultz Signed-off-by: T.J. Mercier Signed-off-by: Yong Wu [Yong: Just add comment for "minor" and "refcount"] Signed-off-by: Yunfei Dong --- drivers/dma-buf/dma-heap.c | 29 +++++++++++++++++++++++++++++ include/linux/dma-heap.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 22f6c193db0d..97025ee8500f 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ * @heap_devt: heap device node * @list: list head connecting to list of heaps * @heap_cdev: heap char device + * @refcount: reference counter for this heap device * * Represents a heap of memory from which buffers can be made. */ @@ -40,6 +42,7 @@ struct dma_heap { dev_t heap_devt; struct list_head list; struct cdev heap_cdev; + struct kref refcount; }; static LIST_HEAD(heap_list); @@ -240,6 +243,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) if (!heap) return ERR_PTR(-ENOMEM); + kref_init(&heap->refcount); heap->name = exp_info->name; heap->ops = exp_info->ops; heap->priv = exp_info->priv; @@ -304,6 +308,31 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) return err_ret; } +static void dma_heap_release(struct kref *ref) +{ + struct dma_heap *heap = container_of(ref, struct dma_heap, refcount); + unsigned int minor = MINOR(heap->heap_devt); + + mutex_lock(&heap_list_lock); + list_del(&heap->list); + mutex_unlock(&heap_list_lock); + + device_destroy(dma_heap_class, heap->heap_devt); + cdev_del(&heap->heap_cdev); + xa_erase(&dma_heap_minors, minor); + + kfree(heap); +} + +/** + * dma_heap_put - drops a reference to a dmabuf heap, potentially freeing it + * @heap: DMA-Heap whose reference count to decrement + */ +void dma_heap_put(struct dma_heap *heap) +{ + kref_put(&heap->refcount, dma_heap_release); +} + static char *dma_heap_devnode(const struct device *dev, umode_t *mode) { return kasprintf(GFP_KERNEL, "dma_heap/%s", dev_name(dev)); diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index fbe86ec889a8..d57593f8a1bc 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -46,4 +46,6 @@ const char *dma_heap_get_name(struct dma_heap *heap); struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); +void dma_heap_put(struct dma_heap *heap); + #endif /* _DMA_HEAPS_H */ From patchwork Wed Dec 6 08:15:24 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: 174412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957261vqy; Wed, 6 Dec 2023 00:16:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHO3WKN527Ylun6qHjzirSTCUD+V7i+ZQ+Cvbor4Ix+JZ1NbM16yomSondgx8afL3pC+cB2 X-Received: by 2002:a05:6a20:1444:b0:18b:ca68:4e9a with SMTP id a4-20020a056a20144400b0018bca684e9amr3681643pzi.28.1701850601945; Wed, 06 Dec 2023 00:16:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850601; cv=none; d=google.com; s=arc-20160816; b=pjA15hNW7XW7mWN9q7ytF+MH/5JI40YtpkkvjC04fmfKrZVx62jcyHNN9d7M3joHkc Z86MCfcgI1TMgqcIyV77CGz8i4M+spyqkk9ckSuZUT6O/xPgPAj7YkXj3LV1IY2gKnhr tU/phQnyg6ygFZHh3jzG9dphDmlFbxej+AoR1Kt7ogCF/ykIqw79CUH375H9tb8ieRCR ZElmIuCMl5ao/rELPVJz8DuhNY18ZVGdvxSuOagKhMR8l0msGv9QyHKW54PMfWHr6BwB +Ef7uk7cTr/XW2PHSJKWAW1LhnZXrpu9mzKwFst03+AJUUjRIDGmJDPdoON0UMiIwYYN f0LA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JWJt5f3OFXku7W6faTUM0+bKsbswJle1HktQEF2gUcM=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=VRPW26c0T3MXNtrWcM0UBMcBFOWxbM+OCmOJdlX0d/UG4HA6S/OR/jj7eIagrEKier X3Dl1LhJLpV4TJgXYNKFlYPnUO7UlVcQ8J7LtPyWVFpsfQZpyE7Y09ygM8TyCnfUd0Vw hSpKqVxZeVI9olIbwRBsnpoptXOXrq2qLsaqZgtWGmqs4mZulMNicJDlRPB/B//A/Gj5 cOVi/cbCK5wf8uEwMHe41vnW6V7nwP88gVSYM7yldEjnC++bw1YFDVU78wftC0TkNyMS iqRGBZM+drIWDKPYD1CSNYQZ1ubu4G/atbo+FErdBSJRo1CLF0rgIOrtO1LHsZ0/KUvK HSmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=qmsJEcf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q19-20020a632a13000000b005af44ed3148si7298068pgq.367.2023.12.06.00.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=qmsJEcf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 1563280A30FF; Wed, 6 Dec 2023 00:16:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377172AbjLFIP6 (ORCPT + 99 others); Wed, 6 Dec 2023 03:15:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376904AbjLFIPt (ORCPT ); Wed, 6 Dec 2023 03:15:49 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF4D6D40; Wed, 6 Dec 2023 00:15:54 -0800 (PST) X-UUID: aaf104a8940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=JWJt5f3OFXku7W6faTUM0+bKsbswJle1HktQEF2gUcM=; b=qmsJEcf1gcxXVZKE52TZontudTa1ALajZiU+nHrEtGomaYMQcxMtnDdtXlxsc5IFBEeYO/6JmfzHZNmDRYBo3JuSOHnbYgKwHC7wTdqQLWtnoYWIkk2/ExzPtTeQHPJULOI5kWODWrNLiJCZ94EUUtfEAHzm4cSFAxNZaRiTV+w=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:48aaea10-6c14-4b9a-afcd-ef4c32c6129a,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:abefa75,CLOUDID:84e87773-1bd3-4f48-b671-ada88705968c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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 X-UUID: aaf104a8940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 407284346; Wed, 06 Dec 2023 16:15:50 +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; Wed, 6 Dec 2023 16:15: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; Wed, 6 Dec 2023 16:15:48 +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,07/21] dma-heap: Provide accessors so that in-kernel drivers can allocate dmabufs from specific heaps Date: Wed, 6 Dec 2023 16:15:24 +0800 Message-ID: <20231206081538.17056-8-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--7.817000-8.000000 X-TMASE-MatchedRID: qPZlTxuLTeftt0HEL3BUV4lD2T5imTkJ2qBSQHAh8pg0QmmUihPzrFJS 0b8z/9TB8AyWk2NFMNbijpjet3oGSJCoy9iDotiwNNHZMWDTEbe4UO5+xwKkcStjI02a+7m1J7o vlkPXpS3VaZR68ynk9lCRaYaDm6fHBCaQyxlaPkG3D7EeeyZCMzGZtPrBBPZrEvoxTu3fj1tEe5 BdjBKTALjfysYMcGyRGce8edCRlYkmcsJib2IjaaOuVibdZNTv7yWPaQc4INQOkJQR4QWbsG+3c txX3zZNo2jEjZ+uot1HVle6mAl0da+/EguYor8cFEUknJ/kEl7dB/CxWTRRu9bFCwAgdKkSZVhc Zw1+0o4U24haPFkSUhqL6AAGbHEsKH3Be5ENxfV32uEPMy/F85RMZUCEHkRt X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--7.817000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: EB500FF3E1D7DEEA103A36D1DC445ABF71A2717DCC195B612B7AC5653DC6DC132000:8 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519696727007211 X-GMAIL-MSGID: 1784519696727007211 From: John Stultz This allows drivers who don't want to create their own DMA-BUF exporter to be able to allocate DMA-BUFs directly from existing DMA-BUF Heaps. There is some concern that the premise of DMA-BUF heaps is that userland knows better about what type of heap memory is needed for a pipeline, so it would likely be best for drivers to import and fill DMA-BUFs allocated by userland instead of allocating one themselves, but this is still up for debate. Signed-off-by: John Stultz Signed-off-by: T.J. Mercier Signed-off-by: Yong Wu [Yong: Fix the checkpatch alignment warning] Signed-off-by: Yunfei Dong --- drivers/dma-buf/dma-heap.c | 83 ++++++++++++++++++++++++++++++-------- include/linux/dma-heap.h | 6 +++ 2 files changed, 73 insertions(+), 16 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 97025ee8500f..6efe833a4b10 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -51,12 +51,24 @@ static dev_t dma_heap_devt; static struct class *dma_heap_class; static DEFINE_XARRAY_ALLOC(dma_heap_minors); -static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, - unsigned int fd_flags, - unsigned int heap_flags) +/** + * dma_heap_buffer_alloc - Allocate dma-buf from a dma_heap + * @heap: DMA-Heap to allocate from + * @len: size to allocate in bytes + * @fd_flags: flags to set on returned dma-buf fd + * @heap_flags: flags to pass to the dma heap + * + * This is for internal dma-buf allocations only. Free returned buffers with dma_buf_put(). + */ +struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, + unsigned int fd_flags, + unsigned int heap_flags) { - struct dma_buf *dmabuf; - int fd; + if (fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) + return ERR_PTR(-EINVAL); + + if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) + return ERR_PTR(-EINVAL); /* * Allocations from all heaps have to begin @@ -64,9 +76,20 @@ static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, */ len = PAGE_ALIGN(len); if (!len) - return -EINVAL; + return ERR_PTR(-EINVAL); + + return heap->ops->allocate(heap, len, fd_flags, heap_flags); +} +EXPORT_SYMBOL_GPL(dma_heap_buffer_alloc); - dmabuf = heap->ops->allocate(heap, len, fd_flags, heap_flags); +static int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len, + unsigned int fd_flags, + unsigned int heap_flags) +{ + struct dma_buf *dmabuf; + int fd; + + dmabuf = dma_heap_buffer_alloc(heap, len, fd_flags, heap_flags); if (IS_ERR(dmabuf)) return PTR_ERR(dmabuf); @@ -104,15 +127,9 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data) if (heap_allocation->fd) return -EINVAL; - if (heap_allocation->fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) - return -EINVAL; - - if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) - return -EINVAL; - - fd = dma_heap_buffer_alloc(heap, heap_allocation->len, - heap_allocation->fd_flags, - heap_allocation->heap_flags); + fd = dma_heap_bufferfd_alloc(heap, heap_allocation->len, + heap_allocation->fd_flags, + heap_allocation->heap_flags); if (fd < 0) return fd; @@ -205,6 +222,7 @@ void *dma_heap_get_drvdata(struct dma_heap *heap) { return heap->priv; } +EXPORT_SYMBOL_GPL(dma_heap_get_drvdata); /** * dma_heap_get_name - get heap name @@ -217,6 +235,7 @@ const char *dma_heap_get_name(struct dma_heap *heap) { return heap->name; } +EXPORT_SYMBOL_GPL(dma_heap_get_name); /** * dma_heap_add - adds a heap to dmabuf heaps @@ -307,6 +326,37 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) kfree(heap); return err_ret; } +EXPORT_SYMBOL_GPL(dma_heap_add); + +/** + * dma_heap_find - get the heap registered with the specified name + * @name: Name of the DMA-Heap to find + * + * Returns: + * The DMA-Heap with the provided name. + * + * NOTE: DMA-Heaps returned from this function MUST be released using + * dma_heap_put() when the user is done to enable the heap to be unloaded. + */ +struct dma_heap *dma_heap_find(const char *name) +{ + struct dma_heap *h; + + mutex_lock(&heap_list_lock); + list_for_each_entry(h, &heap_list, list) { + if (!kref_get_unless_zero(&h->refcount)) + continue; + + if (!strcmp(h->name, name)) { + mutex_unlock(&heap_list_lock); + return h; + } + dma_heap_put(h); + } + mutex_unlock(&heap_list_lock); + return NULL; +} +EXPORT_SYMBOL_GPL(dma_heap_find); static void dma_heap_release(struct kref *ref) { @@ -332,6 +382,7 @@ void dma_heap_put(struct dma_heap *heap) { kref_put(&heap->refcount, dma_heap_release); } +EXPORT_SYMBOL_GPL(dma_heap_put); static char *dma_heap_devnode(const struct device *dev, umode_t *mode) { diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index d57593f8a1bc..3cbf9bff2346 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -46,6 +46,12 @@ const char *dma_heap_get_name(struct dma_heap *heap); struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); +struct dma_heap *dma_heap_find(const char *name); + void dma_heap_put(struct dma_heap *heap); +struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, + unsigned int fd_flags, + unsigned int heap_flags); + #endif /* _DMA_HEAPS_H */ From patchwork Wed Dec 6 08:15:25 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: 174424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957633vqy; Wed, 6 Dec 2023 00:17:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHm6GQNzQsq9R/73R6YyzCwPKGyqzsxeuvLdBBZfVCj9beHdvTBi62/YhpmSRzghZTPsmuw X-Received: by 2002:a05:6358:9047:b0:16f:ebce:8126 with SMTP id f7-20020a056358904700b0016febce8126mr797524rwf.19.1701850654850; Wed, 06 Dec 2023 00:17:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850654; cv=none; d=google.com; s=arc-20160816; b=vVrKZBhCVffwlmnlaCwr/vJE3E/l8ksLkgVb5IhsY8gWPMSVSy/9lLf2WE9/Dr53RV QMr0gJFMkxIEYbw6twOTY1Wo5v8ZU1CJ40W5fq+p503iI0mQ757+aZH6AHiq/vByAiEF rYLC0MZkHqIGU50B52XZmVAF9EmdlVSF398+VLKqa2OQNOiX2LJj3xq5UrGmoJIdMKO8 2oyUxD/sNQHW0cnWbT/UCo+XQiKxzC71AaeJtI/6q4um4+kJc8xJnDqh13Tf7CeRkjtf W3gksp1su7J6Ed8nokRMlot3A6S7nhNrVgpSS6+tVZe5iZlPuCNQW0jZhJzqfDeAsYMP 1TbQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BNphP3hoQiB7tFeVmX2lWwuA+pAIdScaxFYuwh+hJz8=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=JJU4stiiDP0B/6sOtlGjafGnmfOSziUadpWe0tbZGCZ6t7x8oCo2+rl5gyMsa8COSy NP/RCJXe+IfoIX0Sq/0Cg99I1IwifMHc0020yOM0fGsG9rsl+vHHwfpm4UHESIuuBcTq OkQHLsAJeXjlk3GXU+ms3F7WNlnA6GuEuU4GZkQ0ngDENuTdxtSVEXCXgkA4jP0lcwiL varRi6G41kXLK5ZyDZJhOkW966zTGxRQQRaJzlsRsTLaCxRGysU+c62WkZA8j0s/PLu2 iT8CpphXjR950mtgjhYQDuZhmGoH9CiQHi2thp2cSlpducsyqd3Q/SS/CRwKtw0/QhWV takA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NvkOno5n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bj6-20020a056a02018600b0057884435a71si11577378pgb.396.2023.12.06.00.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NvkOno5n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 88A6882DC63E; Wed, 6 Dec 2023 00:17:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377222AbjLFIQM (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377177AbjLFIPz (ORCPT ); Wed, 6 Dec 2023 03:15:55 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AA0DD44; Wed, 6 Dec 2023 00:15:58 -0800 (PST) X-UUID: abb04250940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=BNphP3hoQiB7tFeVmX2lWwuA+pAIdScaxFYuwh+hJz8=; b=NvkOno5nF3pbBvhFVSD28XWYziLqz0uP2xMRKWx0+/eANDIOM/Lz3msHHd2bYQdDnP1E5wmhFvdclJZ/d4K3UmLggrLGCj11WgXfCsZoMNgmO0w0Gy3aceJv/wQ1YY56rm3iEZfY8di7FYQiqOgwZTPE3+pH6ramqW4xaSEDBKs=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:4195c932-651b-423e-89fc-a5e0ca443710,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:abefa75,CLOUDID:c72c59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: abb04250940f11ee8051498923ad61e6-20231206 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 331965211; Wed, 06 Dec 2023 16:15:52 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n1.mediatek.inc (172.21.101.193) 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:50 +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:49 +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,08/21] media: mediatek: vcodec: add tee client interface to communiate with optee-os Date: Wed, 6 Dec 2023 16:15:25 +0800 Message-ID: <20231206081538.17056-9-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:17:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519752168166861 X-GMAIL-MSGID: 1784519752168166861 Open tee context to initialize the environment in order to communication with optee-os, then open tee session as the communication pipeline for lat and core to send data for hardware decode. Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/decoder/Makefile | 1 + .../vcodec/decoder/mtk_vcodec_dec_drv.h | 5 + .../vcodec/decoder/mtk_vcodec_dec_optee.c | 165 ++++++++++++++++++ .../vcodec/decoder/mtk_vcodec_dec_optee.h | 73 ++++++++ 4 files changed, 244 insertions(+) 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 diff --git a/drivers/media/platform/mediatek/vcodec/decoder/Makefile b/drivers/media/platform/mediatek/vcodec/decoder/Makefile index 904cd22def84..1624933dfd5e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/Makefile +++ b/drivers/media/platform/mediatek/vcodec/decoder/Makefile @@ -21,5 +21,6 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ mtk_vcodec_dec_stateful.o \ mtk_vcodec_dec_stateless.o \ mtk_vcodec_dec_pm.o \ + mtk_vcodec_dec_optee.o \ mtk-vcodec-dec-hw-y := mtk_vcodec_dec_hw.o diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h index 849b89dd205c..b1a2107f2a1e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h @@ -11,6 +11,7 @@ #include "../common/mtk_vcodec_dbgfs.h" #include "../common/mtk_vcodec_fw_priv.h" #include "../common/mtk_vcodec_util.h" +#include "mtk_vcodec_dec_optee.h" #include "vdec_msg_queue.h" #define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec" @@ -261,6 +262,8 @@ struct mtk_vcodec_dec_ctx { * @dbgfs: debug log related information * * @chip_name: used to distinguish platforms and select the correct codec configuration values + * + * @optee_private: optee private data */ struct mtk_vcodec_dec_dev { struct v4l2_device v4l2_dev; @@ -303,6 +306,8 @@ struct mtk_vcodec_dec_dev { struct mtk_vcodec_dbgfs dbgfs; enum mtk_vcodec_dec_chip_name chip_name; + + struct mtk_vdec_optee_private *optee_private; }; static inline struct mtk_vcodec_dec_ctx *fh_to_dec_ctx(struct v4l2_fh *fh) 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 new file mode 100644 index 000000000000..38d9c1c1785a --- /dev/null +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2023 MediaTek Inc. + * Author: Yunfei Dong + */ + +#include "mtk_vcodec_dec_drv.h" +#include "mtk_vcodec_dec_optee.h" + +/* + * Randomly generated, and must correspond to the GUID on the TA side. + */ +static const uuid_t mtk_vdec_lat_uuid = + UUID_INIT(0xBC50D971, 0xD4C9, 0x42C4, + 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x90); + +static const uuid_t mtk_vdec_core_uuid = + UUID_INIT(0xBC50D971, 0xD4C9, 0x42C4, + 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x91); + +/* + * Check whether this driver supports decoder TA in the TEE instance, + * represented by the params (ver/data) of this function. + */ +static int mtk_vcodec_dec_optee_match(struct tee_ioctl_version_data *ver_data, const void *not_used) +{ + if (ver_data->impl_id == TEE_IMPL_ID_OPTEE) + return 1; + else + return 0; +} + +int mtk_vcodec_dec_optee_private_init(struct mtk_vcodec_dec_dev *vcodec_dev) +{ + vcodec_dev->optee_private = devm_kzalloc(&vcodec_dev->plat_dev->dev, + sizeof(*vcodec_dev->optee_private), + GFP_KERNEL); + if (!vcodec_dev->optee_private) + return -ENOMEM; + + vcodec_dev->optee_private->vcodec_dev = vcodec_dev; + + atomic_set(&vcodec_dev->optee_private->tee_active_cnt, 0); + mutex_init(&vcodec_dev->optee_private->tee_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_private_init); + +static int mtk_vcodec_dec_optee_init_hw_info(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hardware_index) +{ + struct device *dev = &optee_private->vcodec_dev->plat_dev->dev; + struct tee_ioctl_open_session_arg session_arg; + struct mtk_vdec_optee_ca_info *ca_info; + int err = 0, session_func; + + /* Open lat and core session with vdec TA. */ + switch (hardware_index) { + case MTK_VDEC_LAT0: + export_uuid(session_arg.uuid, &mtk_vdec_lat_uuid); + session_func = MTK_VDEC_OPTEE_TA_LAT_SUBMIT_COMMAND; + ca_info = &optee_private->lat_ca; + break; + case MTK_VDEC_CORE: + export_uuid(session_arg.uuid, &mtk_vdec_core_uuid); + session_func = MTK_VDEC_OPTEE_TA_CORE_SUBMIT_COMMAND; + ca_info = &optee_private->core_ca; + break; + default: + return -EINVAL; + } + + session_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC; + session_arg.num_params = 0; + + err = tee_client_open_session(optee_private->tee_vdec_ctx, &session_arg, NULL); + if (err < 0 || session_arg.ret != 0) { + dev_err(dev, MTK_DBG_VCODEC_STR "open vdec tee session fail hw_id:%d err:%x.\n", + hardware_index, session_arg.ret); + return -EINVAL; + } + ca_info->vdec_session_id = session_arg.session; + ca_info->hw_id = hardware_index; + ca_info->vdec_session_func = session_func; + + dev_dbg(dev, MTK_DBG_VCODEC_STR "open vdec tee session hw_id:%d session_id=%x.\n", + hardware_index, ca_info->vdec_session_id); + + return err; +} + +static void mtk_vcodec_dec_optee_deinit_hw_info(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id) +{ + 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; + + tee_client_close_session(optee_private->tee_vdec_ctx, ca_info->vdec_session_id); +} + +int mtk_vcodec_dec_optee_open(struct mtk_vdec_optee_private *optee_private) +{ + struct device *dev = &optee_private->vcodec_dev->plat_dev->dev; + int ret; + + mutex_lock(&optee_private->tee_mutex); + if (atomic_inc_return(&optee_private->tee_active_cnt) > 1) { + mutex_unlock(&optee_private->tee_mutex); + dev_dbg(dev, MTK_DBG_VCODEC_STR "already init vdec optee private data!\n"); + return 0; + } + + /* Open context with TEE driver */ + optee_private->tee_vdec_ctx = tee_client_open_context(NULL, mtk_vcodec_dec_optee_match, + NULL, NULL); + if (IS_ERR(optee_private->tee_vdec_ctx)) { + dev_err(dev, MTK_DBG_VCODEC_STR "optee vdec tee context failed.\n"); + ret = PTR_ERR(optee_private->tee_vdec_ctx); + goto err_ctx_open; + } + + ret = mtk_vcodec_dec_optee_init_hw_info(optee_private, MTK_VDEC_LAT0); + if (ret < 0) + goto err_lat_init; + + if (IS_VDEC_LAT_ARCH(optee_private->vcodec_dev->vdec_pdata->hw_arch)) { + ret = mtk_vcodec_dec_optee_init_hw_info(optee_private, MTK_VDEC_CORE); + if (ret < 0) + goto err_core_init; + } + + mutex_unlock(&optee_private->tee_mutex); + return 0; +err_core_init: + mtk_vcodec_dec_optee_deinit_hw_info(optee_private, MTK_VDEC_LAT0); +err_lat_init: + tee_client_close_context(optee_private->tee_vdec_ctx); +err_ctx_open: + + mutex_unlock(&optee_private->tee_mutex); + return ret; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_open); + +void mtk_vcodec_dec_optee_release(struct mtk_vdec_optee_private *optee_private) +{ + mutex_lock(&optee_private->tee_mutex); + if (!atomic_dec_and_test(&optee_private->tee_active_cnt)) { + mutex_unlock(&optee_private->tee_mutex); + return; + } + + mtk_vcodec_dec_optee_deinit_hw_info(optee_private, MTK_VDEC_LAT0); + if (IS_VDEC_LAT_ARCH(optee_private->vcodec_dev->vdec_pdata->hw_arch)) + mtk_vcodec_dec_optee_deinit_hw_info(optee_private, MTK_VDEC_CORE); + + tee_client_close_context(optee_private->tee_vdec_ctx); + mutex_unlock(&optee_private->tee_mutex); +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_release); 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 new file mode 100644 index 000000000000..8b1dca49331e --- /dev/null +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2023 MediaTek Inc. + * Author: Yunfei Dong + */ + +#ifndef _MTK_VCODEC_DEC_OPTEE_H_ +#define _MTK_VCODEC_DEC_OPTEE_H_ + +#include +#include + +#include "mtk_vcodec_dec_drv.h" + +/* The TA ID implemented in this TA */ +#define MTK_VDEC_OPTEE_TA_LAT_SUBMIT_COMMAND (0x10) +#define MTK_VDEC_OPTEE_TA_CORE_SUBMIT_COMMAND (0x20) + +#define MTK_OPTEE_MAX_TEE_PARAMS 4 + +/** + * struct mtk_vdec_optee_ca_info - ca related param + * @vdec_session_id: optee TA session identifier. + * @hw_id: hardware index. + * @vdec_session_func: trusted application function id used specific to the TA. + */ +struct mtk_vdec_optee_ca_info { + u32 vdec_session_id; + enum mtk_vdec_hw_id hw_id; + u32 vdec_session_func; +}; + +/** + * struct mtk_vdec_optee_private - optee private data + * @vcodec_dev: pointer to the mtk_vcodec_dev of the device + * @tee_vdec_ctx: decoder TEE context handler. + * @lat_ca: lat hardware information used to communicate with TA. + * @core_ca: core hardware information used to communicate with TA. + * + * @tee_active_cnt: used to mark whether need to init optee + * @tee_mutex: mutex lock used for optee + */ +struct mtk_vdec_optee_private { + struct mtk_vcodec_dec_dev *vcodec_dev; + struct tee_context *tee_vdec_ctx; + + struct mtk_vdec_optee_ca_info lat_ca; + struct mtk_vdec_optee_ca_info core_ca; + + atomic_t tee_active_cnt; + /* mutext used to lock optee open and release information. */ + struct mutex tee_mutex; +}; + +/** + * mtk_vcodec_dec_optee_open - setup the communication channels with TA. + * @optee_private: optee private context + */ +int mtk_vcodec_dec_optee_open(struct mtk_vdec_optee_private *optee_private); + +/** + * mtk_vcodec_dec_optee_private_init - init optee parameters. + * @vcodec_dev: pointer to the mtk_vcodec_dev of the device + */ +int mtk_vcodec_dec_optee_private_init(struct mtk_vcodec_dec_dev *vcodec_dev); + +/** + * mtk_vcodec_dec_optee_release - close the communication channels with TA. + * @optee_private: optee private context + */ +void mtk_vcodec_dec_optee_release(struct mtk_vdec_optee_private *optee_private); + +#endif /* _MTK_VCODEC_FW_OPTEE_H_ */ From patchwork Wed Dec 6 08:15:26 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: 174415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957311vqy; Wed, 6 Dec 2023 00:16:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVkSy2oTnuY8zWVry/5+ugcLKL9y/GU3fBbotTj/VZ5P0hiuvgk5k9OTvNd0jwmM9ICaVr X-Received: by 2002:a17:90b:4b8e:b0:286:9b50:b98 with SMTP id lr14-20020a17090b4b8e00b002869b500b98mr747068pjb.5.1701850607528; Wed, 06 Dec 2023 00:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850607; cv=none; d=google.com; s=arc-20160816; b=hODKWMZ2Psb6EiLicnx4kYHmQ/6WZ5IXy13Iw/+Bsz54xxn/ufJ0AFDncPDVd0AM8L 8my5sXoVZeONwXuwY2MAGDnRxEaTuaYsqnK4PIOvccYLUSnmezh1BZSAeLsbK8//OFJ/ 6oeNvZsaPA3slIenkbJ2b8YvlHikjnf1c8fTdxdhNo64xdy3FF89PedvIWA6uvIegN5q z2b/tOQOaC3b2BHKEm7wmMSS07Qfu8BUVOFoWiEd/XEwGp2iP96uqCc/nKYP+RtOgpK6 qHiL/42wHvQtgzIVdY5tNwb2FcvyMmaLmP9Jfd79AVOfz8EaFltaMFWOor6ARCBnnLeL e2Ow== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DMqBb8ywjQ0rZOsEH87m6D0Csn8bNMMs2dmXkp7WJNQ=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=aQEXTCK9BK/upR65xVFLWkAdGFZNp0u3wm36IqHwJSxDYEBCqf32Zg2n5Ornkt9Dd5 H/PBr6HsPvChVHLckOJIcuM70IkG1ww7jEQ0WMVYjkju1zI0vw2y4B7OqUztl7H+MUPk q48cNQyLSj7ZW6jhtT+QyDv1/H7ZAgBaBmjG56gVUENIcXl1mC5Rf82wfb4LDJhKx89L a8Q53/ayI8uC3yLD1F+mnHP2PvhIx2UAVMjHWCR6oO7+UuSB6FmLD6gO9Ys04/xo6bq/ W+fWQsHWFm2/vPE59gI+1fWkGlX6BuKTViyvBKczsZQ6H+s31YtUiysgO3tLGuPi+P97 +gug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=suUdqM84; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s20-20020a170902b19400b001d0a6c4e2d4si4742251plr.610.2023.12.06.00.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=suUdqM84; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 4D60180BD535; Wed, 6 Dec 2023 00:16:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377245AbjLFIQZ (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377191AbjLFIP4 (ORCPT ); Wed, 6 Dec 2023 03:15:56 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FF94D51; Wed, 6 Dec 2023 00:16:00 -0800 (PST) X-UUID: ac822db0940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=DMqBb8ywjQ0rZOsEH87m6D0Csn8bNMMs2dmXkp7WJNQ=; b=suUdqM844XPz+3d51w7mqblLxLtywKOgUZYKmkvxOXiKzpC4tU9p08y0jNq4O/rdLk8uWbaq6EYduY3yIvTs55IBgESqyDyvZ37cRFkUPCpuyTFOeAMQSiDWrVbGpQCJSKoXr0Z+NVArgmn7qLd2pSr+k6wk/eLSE6oafP6wiQs=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:05ea089b-f07d-435d-a503-df301c288166,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:abefa75,CLOUDID:4679e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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 X-UUID: ac822db0940f11ee8051498923ad61e6-20231206 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1809783144; Wed, 06 Dec 2023 16:15:53 +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; Wed, 6 Dec 2023 16:15:51 +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:50 +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,09/21] media: mediatek: vcodec: allocate tee share memory Date: Wed, 6 Dec 2023 16:15:26 +0800 Message-ID: <20231206081538.17056-10-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--8.400800-8.000000 X-TMASE-MatchedRID: +Xe+hmBfvL5A5/DRRISQHAPZZctd3P4BK2i9pofGVSuYBF1C0J2QPotf Mtu9FfbrPcGjGTU7TndXUz+XcOBhEYYCBZzro74fDB+ErBr0bAO2McZY43zJ423D6f6IpbLIyo3 1HV/erwydBDUJwKypkLvrVFvaS3pv9A9EfhuU0xx1e7Xbb6Im2pRy1HDTPOXaW+jwVKpqvlI9yB u1TZGrQeLzNWBegCW2wgn7iDBesS3CttcwYNipX9TGCNBptnYun5DLLJVJV30sBvUgh06xuAKG4 aT8V85fCMu1t+UdIjdWXGvUUmKP2w== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.400800-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: CE10DDF852BA61A8626F5852BC8342D41FA6139D30802DEEE943852D838DAF8B2000:8 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519702728975405 X-GMAIL-MSGID: 1784519702728975405 Allocate two share memory for each lat and core hardware used to share information with optee-os. Msg buffer used to send ipi command and get ack command with optee-os, data buffer used to store vsi information which used for hardware decode. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_optee.c | 80 ++++++++++++++++++- .../vcodec/decoder/mtk_vcodec_dec_optee.h | 32 ++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) 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 38d9c1c1785a..611fb0e56480 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 @@ -47,13 +47,69 @@ int mtk_vcodec_dec_optee_private_init(struct mtk_vcodec_dec_dev *vcodec_dev) } EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_private_init); +static void mtk_vcodec_dec_optee_deinit_memref(struct mtk_vdec_optee_ca_info *ca_info, + enum mtk_vdec_optee_data_index data_index) +{ + tee_shm_free(ca_info->shm_memref[data_index].msg_shm); +} + +static int mtk_vcodec_dec_optee_init_memref(struct tee_context *tee_vdec_ctx, + struct mtk_vdec_optee_ca_info *ca_info, + enum mtk_vdec_optee_data_index data_index) +{ + struct mtk_vdec_optee_shm_memref *shm_memref; + int alloc_size = 0, err = 0; + u64 shm_param_type = 0; + bool copy_buffer; + + switch (data_index) { + case OPTEE_MSG_INDEX: + shm_param_type = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT; + alloc_size = MTK_VDEC_OPTEE_MSG_SIZE; + copy_buffer = true; + break; + case OPTEE_DATA_INDEX: + shm_param_type = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT; + alloc_size = MTK_VDEC_OPTEE_HW_SIZE; + copy_buffer = false; + break; + default: + pr_err(MTK_DBG_VCODEC_STR "tee invalid data_index: %d.\n", data_index); + return -EINVAL; + } + + shm_memref = &ca_info->shm_memref[data_index]; + + /* Allocate dynamic shared memory with decoder TA */ + shm_memref->msg_shm_size = alloc_size; + shm_memref->param_type = shm_param_type; + shm_memref->copy_to_ta = copy_buffer; + shm_memref->msg_shm = tee_shm_alloc_kernel_buf(tee_vdec_ctx, shm_memref->msg_shm_size); + if (IS_ERR(shm_memref->msg_shm)) { + pr_err(MTK_DBG_VCODEC_STR "tee alloc buf fail: data_index:%d.\n", data_index); + return -ENOMEM; + } + + shm_memref->msg_shm_ca_buf = tee_shm_get_va(shm_memref->msg_shm, 0); + if (IS_ERR(shm_memref->msg_shm_ca_buf)) { + pr_err(MTK_DBG_VCODEC_STR "tee get shm va fail: data_index:%d.\n", data_index); + err = PTR_ERR(shm_memref->msg_shm_ca_buf); + goto err_get_msg_va; + } + + return err; +err_get_msg_va: + tee_shm_free(shm_memref->msg_shm); + return err; +} + static int mtk_vcodec_dec_optee_init_hw_info(struct mtk_vdec_optee_private *optee_private, enum mtk_vdec_hw_id hardware_index) { struct device *dev = &optee_private->vcodec_dev->plat_dev->dev; struct tee_ioctl_open_session_arg session_arg; struct mtk_vdec_optee_ca_info *ca_info; - int err = 0, session_func; + int err, i, j, session_func; /* Open lat and core session with vdec TA. */ switch (hardware_index) { @@ -87,6 +143,24 @@ static int mtk_vcodec_dec_optee_init_hw_info(struct mtk_vdec_optee_private *opte dev_dbg(dev, MTK_DBG_VCODEC_STR "open vdec tee session hw_id:%d session_id=%x.\n", hardware_index, ca_info->vdec_session_id); + /* Allocate dynamic shared memory with decoder TA */ + for (i = 0; i < OPTEE_MAX_INDEX; i++) { + err = mtk_vcodec_dec_optee_init_memref(optee_private->tee_vdec_ctx, ca_info, i); + if (err) { + dev_err(dev, MTK_DBG_VCODEC_STR "init vdec memref failed: %d.\n", i); + goto err_init_memref; + } + } + + return err; +err_init_memref: + if (i != 0) { + for (j = 0; j < i; j++) + mtk_vcodec_dec_optee_deinit_memref(ca_info, j); + } + + tee_client_close_session(optee_private->tee_vdec_ctx, ca_info->vdec_session_id); + return err; } @@ -94,12 +168,16 @@ static void mtk_vcodec_dec_optee_deinit_hw_info(struct mtk_vdec_optee_private *o enum mtk_vdec_hw_id hw_id) { struct mtk_vdec_optee_ca_info *ca_info; + int i; if (hw_id == MTK_VDEC_LAT0) ca_info = &optee_private->lat_ca; else ca_info = &optee_private->core_ca; + for (i = 0; i < OPTEE_MAX_INDEX; i++) + mtk_vcodec_dec_optee_deinit_memref(ca_info, i); + tee_client_close_session(optee_private->tee_vdec_ctx, ca_info->vdec_session_id); } 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 8b1dca49331e..24aa63af9887 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 @@ -18,16 +18,48 @@ #define MTK_OPTEE_MAX_TEE_PARAMS 4 +#define MTK_VDEC_OPTEE_MSG_SIZE 128 +#define MTK_VDEC_OPTEE_HW_SIZE (8 * SZ_1K) + +/** + * struct mtk_vdec_optee_shm_memref - share memory reference params + * @msg_shm: message shared with TA in TEE. + * @msg_shm_ca_buf: ca buffer. + * + * @msg_shm_size: share message size. + * @param_type: each tee param types. + * @copy_to_ta: need to copy data from ca to share memory. + */ +struct mtk_vdec_optee_shm_memref { + struct tee_shm *msg_shm; + u8 *msg_shm_ca_buf; + + u32 msg_shm_size; + u64 param_type; + bool copy_to_ta; +}; + /** * struct mtk_vdec_optee_ca_info - ca related param * @vdec_session_id: optee TA session identifier. * @hw_id: hardware index. * @vdec_session_func: trusted application function id used specific to the TA. + * @shm_memref: share memory reference params. */ struct mtk_vdec_optee_ca_info { u32 vdec_session_id; enum mtk_vdec_hw_id hw_id; u32 vdec_session_func; + struct mtk_vdec_optee_shm_memref shm_memref[MTK_OPTEE_MAX_TEE_PARAMS]; +}; + +/* + * enum mtk_vdec_optee_data_index - used to indentify each share memory information + */ +enum mtk_vdec_optee_data_index { + OPTEE_MSG_INDEX = 0, + OPTEE_DATA_INDEX, + OPTEE_MAX_INDEX, }; /** From patchwork Wed Dec 6 08:15:27 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: 174423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957623vqy; Wed, 6 Dec 2023 00:17:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRbEXoErS1JUirm67LnXg9Kgb+Ekn4DkZZLUP61Nb4c3Fl65MyLwbjzlgjeQDDO6oSL/va X-Received: by 2002:a05:6358:8a3:b0:16d:bec8:654f with SMTP id m35-20020a05635808a300b0016dbec8654fmr854298rwj.1.1701850654035; Wed, 06 Dec 2023 00:17:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850653; cv=none; d=google.com; s=arc-20160816; b=PKFgLR1K5YLlHztdEr8OweqQCcY+LYid4QoHCk5G2JO6wxz7ae9GU9UDmClonZ3AyI yyf5lK53xxZh9YOGgSzhnWulVuWHVoH6UQj2vxB5NJn+10qC/irpK+vy8v7Cocox/bat /IKluKmO3A0ifM9DyDKVBk+oAPt5m7V0q5xoxqADMOhUnKctoh6xyZ2jB/+Kb2Y8JK4l jgVjzqFBDZsmohfGO9n/MLpemgAWxsW8TEvmGETTJK+lj8A+nkd7CKJ7ATBKgfDOgPPH oxbRULwdAObAxJ3fKGNZDBtvoIgPPgqNtCrrJIK8tv9xOF3BIWMcgtVXxmqKWmbr9aDz XSlA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Qsu2a6pWuI9r9UzNG4biPlS5wzwndp0NR6vZ8LjQ+Ww=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=E6DBoWyObwaF/27S7yuyM1ZQ8vSiAW1SDTOk4yuJdCqNT0kq6sIHLlu8OWHVmz410f gLFLNrR7lQKeSECI6g33DgBOU4Zi3+tF4UMGVnIicI9tB1a6nuySys6O0sSJNlrokVIk jAxnlbzP4xg+7JpY+Ue0GUlPF6gRrXLsZmEpjb3P3yZaGbnNGPQncVQN8LbFkFnEt/FS UZkhsXxOE9bPzcT7hCL1mG/fyIvy2ey/GkU4Xkw1ktzktGLdLzULLc1ktfflRZlEQBG7 fnvtlqXmVnVwhBMlxh2FWdV43orBkgtNO8yLLaZ5jj+nbvc3u9+iuV6M72CLej5SMhI1 Bv3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=aNkzMuFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bs192-20020a6328c9000000b005c20241fdf2si11002275pgb.49.2023.12.06.00.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=aNkzMuFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 1481982DC63A; Wed, 6 Dec 2023 00:17:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377177AbjLFIQP (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377188AbjLFIP4 (ORCPT ); Wed, 6 Dec 2023 03:15:56 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C84ED40; Wed, 6 Dec 2023 00:15:59 -0800 (PST) X-UUID: ad2748f4940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Qsu2a6pWuI9r9UzNG4biPlS5wzwndp0NR6vZ8LjQ+Ww=; b=aNkzMuFt+xyj75croYNm+uUFJ9lKo86WpCLal75hPs5Q0EOQ6PLaG57a7unZ1KWahYLRGiJWyIu5by/4zwbhMLuFLbVucFMlehBC6flgNp0fwVygXLlYrFCpM52gtFZYmqS/ll0OqE6dQUeq/xHhIN1RkACpmbjgQhtKCxcy6lg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:1eafc663-658d-4d73-96a7-86d0e864a1c1,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:d02c59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: ad2748f4940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 366926902; Wed, 06 Dec 2023 16:15:54 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n1.mediatek.inc (172.21.101.193) 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:53 +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:52 +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,10/21] media: mediatek: vcodec: send share memory data to optee Date: Wed, 6 Dec 2023 16:15:27 +0800 Message-ID: <20231206081538.17056-11-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:17:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519751549998057 X-GMAIL-MSGID: 1784519751549998057 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_ */ From patchwork Wed Dec 6 08:15:28 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: 174416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957325vqy; Wed, 6 Dec 2023 00:16:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEBS80uI0jn8hfXhjQlRuaLBS5h6BSPJi1h0XiZTlgZHguUmbrMeXaeOOpgwfFQRVd6LLP X-Received: by 2002:a92:d2d2:0:b0:35d:6b27:aa6f with SMTP id w18-20020a92d2d2000000b0035d6b27aa6fmr794881ilg.4.1701850611038; Wed, 06 Dec 2023 00:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850611; cv=none; d=google.com; s=arc-20160816; b=hlvXh/MyQwXrVgzbzhBPtKPK3KzIeyKU3BQO/EXp7RAoF0i1PgmsXAJKtMAP1SOSCS COj4yeGkBRtmGBPRLA12KuN1rJdQi9AazjRfUhWwQT8SYjRbyrSms6J/Y7a/d1aWxBQq j4OwwwLnYGKSPCQ2l+ub/hJqO16HXzVZ7qHNAVAdaXU0itl9538I7Dshtssvfu+oAlJz hvwVyXXdgOrukfYCkfGfogtODgbj0jpqjqWx2RHMGvtMgtOsCEpvXHW1e/eTrAYDZUkD JSEhV4OCcZRyif1KQsxU8vZ4i89T9eCO4iyvlsz7rrDtw80XK9aMWCkn2e4XKq9uBwCu 2urQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9iSSK3aCMn3USGH6OeE2/3/hdEQJKNChvSI8XpPt0hI=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=IpHHxVX5vYD0EdcApYlgIBrYnPR6sWXeZg6P0iimE2vjwcwSbUBcJLwWT5Ko7cJK7B XUAYSzTQ33N6ZGEEczS2pNa7DrzwdVlINJNVjutQaEjMF7WpJSm7acfBRQb9CIBWQKtY Q/57bRDsB3smVdAY4kkdwACHf/G194qyj4Pmfey38Cu5k2VTxumAPQQ86IyPXv7hpqP7 4IiDJGVLJAzC3rm+d24zuA2FPQTCti7l+d1nZgCDv0/dYii/4G7efVAXizyeAXjn5QKR HNeUU3vYH/ven+uOB89JZDyUE4OP9IhGcHxhOI2rFJrJJPy8JjpPqenc+396lR7QiYlw wZEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=kD2OWiYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z21-20020a630a55000000b005bdbe64cc26si11006612pgk.535.2023.12.06.00.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=kD2OWiYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id F2E2E802CFEC; Wed, 6 Dec 2023 00:16:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377209AbjLFIQb (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377181AbjLFIQM (ORCPT ); Wed, 6 Dec 2023 03:16:12 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1A7E18D; Wed, 6 Dec 2023 00:16:03 -0800 (PST) X-UUID: ae1be184940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=9iSSK3aCMn3USGH6OeE2/3/hdEQJKNChvSI8XpPt0hI=; b=kD2OWiYmYRpoVL2ICWr3NUKs3DBmkfwbD9pwRDi0xsCYLlDNPQdOFaAzRl/fAa9e+HFI5WJJpWgRZWjeDMEwKQ6jO5AQYmS3AFQUbtbVN2oZDCdxcTTtBRkW8ma1FabmeOn31avMX38v49STWeAMBHn6HEQ5OJsIkVFzUUh6eZQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:bd7de911-606d-4638-9d0d-453c074cbf1a,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:abefa75,CLOUDID:b7e87773-1bd3-4f48-b671-ada88705968c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: ae1be184940f11ee8051498923ad61e6-20231206 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 504411420; Wed, 06 Dec 2023 16:15:56 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) 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:54 +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:53 +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,11/21] media: mediatek: vcodec: initialize msg and vsi information Date: Wed, 6 Dec 2023 16:15:28 +0800 Message-ID: <20231206081538.17056-12-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--8.774500-8.000000 X-TMASE-MatchedRID: jC5X9J9XZ3oiRWw1gHaWSxuZoNKc6pl+MJlSCRpjLV32MjGUf5GHsWb6 PphVtfZgVkkQSrH2rvhtS1CTbpfjUP/Js/ghYmSK7spMO3HwKCARWG8HyxfLI7lmMfLNiukaG/k B0flY/cWGe+0MUSZloS2Rxuw/iP4W2HzzjwqZ3wJPuMJi/ZAk8V3HHpZF/7mw/RM/+SKR6qe25B ylI3cMJL1QsHlkpLKtihP7kE5hi1yxP8oxx7elnqngbqTYC4GHfS0Ip2eEHnz3IzXlXlpamPoLR 4+zsDTtIAmDJ33CtzyiELxJofS438QP+HUm8MfQsqrYSToICJNpYEssH22PmfNWhMFTXr/W X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.774500-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: D8C33EF720B5545E0DD5663B3336768C28B3C073E19819F8C276C55AC8EA34262000:8 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RDNS_NONE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519706009255750 X-GMAIL-MSGID: 1784519706009255750 Need to initialize msg and vsi information before sending to optee-os, then calling optee invoke command to send the information to optee-os. For the optee communication interface is different with scp, using flag to separate them. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 + .../mediatek/vcodec/decoder/vdec_vpu_if.c | 49 ++++++++++++++++--- .../mediatek/vcodec/decoder/vdec_vpu_if.h | 4 ++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h index b1a2107f2a1e..47eca245dc07 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h @@ -175,6 +175,7 @@ struct mtk_vcodec_dec_pdata { * @vpu_inst: vpu instance pointer. * * @is_10bit_bitstream: set to true if it's 10bit bitstream + * @is_secure_playback: Secure Video Playback (SVP) mode */ struct mtk_vcodec_dec_ctx { enum mtk_instance_type type; @@ -220,6 +221,7 @@ struct mtk_vcodec_dec_ctx { void *vpu_inst; bool is_10bit_bitstream; + bool is_secure_playback; }; /** diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c index 82e57ae983d5..5336769a3fb5 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c @@ -148,7 +148,10 @@ static void vpu_dec_ipi_handler(void *data, unsigned int len, void *priv) static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len) { - int err, id, msgid; + struct mtk_vdec_optee_data_to_shm *optee_data; + int data_size, id, hw_id, msgid; + void *ack_msg, *data_msg; + int err; msgid = *(uint32_t *)msg; mtk_vdec_debug(vpu->ctx, "id=%X", msgid); @@ -158,16 +161,46 @@ static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len) if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE) { if (msgid == AP_IPIMSG_DEC_CORE || - msgid == AP_IPIMSG_DEC_CORE_END) + msgid == AP_IPIMSG_DEC_CORE_END) { + optee_data = &vpu->core_optee_info; id = vpu->core_id; - else + } else { + optee_data = &vpu->lat_optee_info; id = vpu->id; + } } else { + optee_data = &vpu->lat_optee_info; id = vpu->id; } - err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, id, msg, - len, 2000); + if (!vpu->ctx->is_secure_playback) { + err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, id, msg, len, 2000); + } else { + hw_id = (id == SCP_IPI_VDEC_LAT) ? MTK_VDEC_LAT0 : MTK_VDEC_CORE; + + mtk_vcodec_dec_optee_set_data(optee_data, msg, len, OPTEE_MSG_INDEX); + + /* There is no need to copy the data (VSI) message to shared memory, + * but we still need to set the buffer size to a non-zero value. + */ + if (msgid == AP_IPIMSG_DEC_CORE || msgid == AP_IPIMSG_DEC_START) { + data_msg = mtk_vcodec_dec_get_shm_buffer_va(vpu->ctx->dev->optee_private, + hw_id, OPTEE_DATA_INDEX); + data_size = mtk_vcodec_dec_get_shm_buffer_size(vpu->ctx->dev->optee_private, + hw_id, OPTEE_DATA_INDEX); + mtk_vcodec_dec_optee_set_data(optee_data, data_msg, data_size, + OPTEE_DATA_INDEX); + } + + err = mtk_vcodec_dec_optee_invokd_cmd(vpu->ctx->dev->optee_private, + hw_id, optee_data); + vpu->failure = err; + + ack_msg = mtk_vcodec_dec_get_shm_buffer_va(vpu->ctx->dev->optee_private, hw_id, + OPTEE_MSG_INDEX); + vpu_dec_ipi_handler(ack_msg, 0, vpu->ctx->dev); + } + if (err) { mtk_vdec_err(vpu->ctx, "send fail vpu_id=%d msg_id=%X status=%d", id, msgid, err); @@ -213,7 +246,11 @@ int vpu_dec_init(struct vdec_vpu_inst *vpu) return err; } - if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE) { + /* Using tee interface to communicate with optee os directly for SVP mode, + * fw ipi interface is used for normal playback. + */ + if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE && + !vpu->ctx->is_secure_playback) { err = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->core_id, vpu->handler, "vdec", vpu->ctx->dev); diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h index fbb3f34a73f0..946e5abcc7d3 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h @@ -28,6 +28,8 @@ struct mtk_vcodec_dec_ctx; * @codec_type : use codec type to separate different codecs * @capture_type: used capture type to separate different capture format * @fb_sz : frame buffer size of each plane + * @lat_optee_info : used to send msg to optee shm buffer + * @core_optee_info : used to send msg to optee shm buffer */ struct vdec_vpu_inst { int id; @@ -44,6 +46,8 @@ struct vdec_vpu_inst { unsigned int codec_type; unsigned int capture_type; unsigned int fb_sz[2]; + struct mtk_vdec_optee_data_to_shm lat_optee_info; + struct mtk_vdec_optee_data_to_shm core_optee_info; }; /** From patchwork Wed Dec 6 08:15:29 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: 174414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957297vqy; Wed, 6 Dec 2023 00:16:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IH36/If0QqlbLhPbGRoc6bf77gyve8ohlRuz+Yt6toiihDNeZwgb2hudT6cBmcplStpJOsI X-Received: by 2002:a17:902:7d97:b0:1d0:706d:c738 with SMTP id a23-20020a1709027d9700b001d0706dc738mr611679plm.135.1701850606004; Wed, 06 Dec 2023 00:16:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850605; cv=none; d=google.com; s=arc-20160816; b=MVp4mKEcOozeagj/3+OJph38vCEElNhkukbv9GJrP8IqjcQLAJRag1zGpB5Grt2WcT 4fQI81jJ8GPHsI0Z/42cEmSOaLhh2t9c6VCwhEeSluZ1JltwDcfoor6IKScDHHjwxM+w ojybuj7NvO3g6N5SO3Jy184TiCdMyIgIFdgQM4EYK79u0KSbT5LAWguX/RG+n3qfrDPh QvRNSLPohGophLFHk4ZL2t7MXWCgOfS7HhXlcxWmfL/XoFpzH1D7KFNvMYoVbKcpZ/ix qw5bTtfeBQ250Arfpr9aAXCdmO7d3uiOwtPAu2NL3cDDsXNppv6PouHxthOl+TbJ+Vcu vbwQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AEOnbt4r9fsU1FaBhQrHBhHtJ6EFlT2KKfJtqxzhvuE=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=MASCNd/B0kUWSPaviDKKtUNSwWP3XOkfnMHuYb2YIATZBA8XH8hCv89JxzRs82UJ+p zFo/nvT4v6N8ADj4fa4gkgP9Wf6YEdO2HH+UfnOUo8JZ/Svy84KAR2qzi3nSbDJcaYiV VQ9fBJopq1YWeE8mxYIH4zMQObzy+YhA88v7FiSUMhqn8YqRYarrPspVcAK30VuPVUd8 83XEP1MoDifHXO/CzgsEAgIwM07MMO8A6I68xihCeIhi1WstJHzT3n9FC67yTWAyRYKH dJBg2CcJMYRy2kBBLsomVQb26+Q2VNUtGpwjWcJvl0sZ1l8CQU5Rk3uRmjXGkD5PbKD/ ov+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=ApxelhEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t6-20020a1709028c8600b001cfa22e6bd7si10910823plo.179.2023.12.06.00.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=ApxelhEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id ED26C802D1DA; Wed, 6 Dec 2023 00:16:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377261AbjLFIQ1 (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377209AbjLFIQF (ORCPT ); Wed, 6 Dec 2023 03:16:05 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 892D4D65; Wed, 6 Dec 2023 00:16:02 -0800 (PST) X-UUID: aeb51048940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=AEOnbt4r9fsU1FaBhQrHBhHtJ6EFlT2KKfJtqxzhvuE=; b=ApxelhEIPVXx9gy07iAqk1R61gZSGLQQ8Og37yQSVzXxlMiC+4Ain1BmhVa1dA7iPHvRgmBqZiWuzAhC/HNSYxn4WxIYP7F4dOnzy+6c/M8b1sI5GM2uaXGFVwyV3XfcPa50YAV7Onrw5140ILCsswbpDrxkRnVbtFOCN0gKIIM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:87bc9a72-6506-47bf-bbda-7b20a6963e2a,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:abefa75,CLOUDID:c2e87773-1bd3-4f48-b671-ada88705968c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: aeb51048940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1038099776; Wed, 06 Dec 2023 16:15:57 +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:55 +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:54 +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,12/21] media: mediatek: vcodec: add interface to allocate/free secure memory Date: Wed, 6 Dec 2023 16:15:29 +0800 Message-ID: <20231206081538.17056-13-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519700846028148 X-GMAIL-MSGID: 1784519700846028148 Need to call dma heap interface to allocate/free secure memory when playing secure video. Signed-off-by: Yunfei Dong --- .../media/platform/mediatek/vcodec/Kconfig | 1 + .../mediatek/vcodec/common/mtk_vcodec_util.c | 122 +++++++++++++++++- .../mediatek/vcodec/common/mtk_vcodec_util.h | 3 + 3 files changed, 123 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/Kconfig b/drivers/media/platform/mediatek/vcodec/Kconfig index bc8292232530..707865703e61 100644 --- a/drivers/media/platform/mediatek/vcodec/Kconfig +++ b/drivers/media/platform/mediatek/vcodec/Kconfig @@ -17,6 +17,7 @@ config VIDEO_MEDIATEK_VCODEC depends on VIDEO_MEDIATEK_VPU || !VIDEO_MEDIATEK_VPU depends on MTK_SCP || !MTK_SCP depends on MTK_SMI || (COMPILE_TEST && MTK_SMI=n) + depends on DMABUF_HEAPS select VIDEOBUF2_DMA_CONTIG select V4L2_MEM2MEM_DEV select VIDEO_MEDIATEK_VCODEC_VPU if VIDEO_MEDIATEK_VPU diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c index 9ce34a3b5ee6..2c44747f77a0 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c @@ -5,9 +5,11 @@ * Tiffany Lin */ +#include #include #include #include +#include #include "../decoder/mtk_vcodec_dec_drv.h" #include "../encoder/mtk_vcodec_enc_drv.h" @@ -45,7 +47,7 @@ int mtk_vcodec_write_vdecsys(struct mtk_vcodec_dec_ctx *ctx, unsigned int reg, } EXPORT_SYMBOL(mtk_vcodec_write_vdecsys); -int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) +static int mtk_vcodec_mem_alloc_nor(void *priv, struct mtk_vcodec_mem *mem) { enum mtk_instance_type inst_type = *((unsigned int *)priv); struct platform_device *plat_dev; @@ -76,9 +78,71 @@ int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) return 0; } -EXPORT_SYMBOL(mtk_vcodec_mem_alloc); -void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) +static int mtk_vcodec_mem_alloc_sec(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_mem *mem) +{ + struct device *dev = &ctx->dev->plat_dev->dev; + struct dma_buf *dma_buffer; + struct dma_heap *vdec_heap; + struct dma_buf_attachment *attach; + struct sg_table *sgt; + unsigned long size = mem->size; + int ret = 0; + + if (!size) + return -EINVAL; + + vdec_heap = dma_heap_find("mtk_svp"); + if (!vdec_heap) { + mtk_v4l2_vdec_err(ctx, "dma heap find failed!"); + return -EPERM; + } + + dma_buffer = dma_heap_buffer_alloc(vdec_heap, size, DMA_HEAP_VALID_FD_FLAGS, + DMA_HEAP_VALID_HEAP_FLAGS); + if (IS_ERR_OR_NULL(dma_buffer)) { + mtk_v4l2_vdec_err(ctx, "dma heap alloc size=0x%lx failed!", size); + return PTR_ERR(dma_buffer); + } + + attach = dma_buf_attach(dma_buffer, dev); + if (IS_ERR_OR_NULL(attach)) { + mtk_v4l2_vdec_err(ctx, "dma attach size=0x%lx failed!", size); + ret = PTR_ERR(attach); + goto err_attach; + } + + sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); + if (IS_ERR_OR_NULL(sgt)) { + mtk_v4l2_vdec_err(ctx, "dma map attach size=0x%lx failed!", size); + ret = PTR_ERR(sgt); + goto err_sgt; + } + + mem->va = dma_buffer; + mem->dma_addr = (dma_addr_t)sg_dma_address((sgt)->sgl); + + if (!mem->va || !mem->dma_addr) { + mtk_v4l2_vdec_err(ctx, "dma buffer size=0x%lx failed!", size); + ret = -EPERM; + goto err_addr; + } + + mem->attach = attach; + mem->sgt = sgt; + + return 0; +err_addr: + dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL); +err_sgt: + dma_buf_detach(dma_buffer, attach); +err_attach: + dma_buf_put(dma_buffer); + + return ret; +} + +static void mtk_vcodec_mem_free_nor(void *priv, struct mtk_vcodec_mem *mem) { enum mtk_instance_type inst_type = *((unsigned int *)priv); struct platform_device *plat_dev; @@ -111,6 +175,57 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) mem->dma_addr = 0; mem->size = 0; } + +static void mtk_vcodec_mem_free_sec(struct mtk_vcodec_mem *mem) +{ + if (mem->sgt) + dma_buf_unmap_attachment(mem->attach, mem->sgt, DMA_BIDIRECTIONAL); + dma_buf_detach((struct dma_buf *)mem->va, mem->attach); + dma_buf_put((struct dma_buf *)mem->va); + + mem->attach = NULL; + mem->sgt = NULL; + mem->va = NULL; + mem->dma_addr = 0; + mem->size = 0; +} + +int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) +{ + enum mtk_instance_type inst_type = *((unsigned int *)priv); + int ret; + + if (inst_type == MTK_INST_DECODER) { + struct mtk_vcodec_dec_ctx *dec_ctx = priv; + + if (dec_ctx->is_secure_playback) { + ret = mtk_vcodec_mem_alloc_sec(dec_ctx, mem); + goto alloc_end; + } + } + + ret = mtk_vcodec_mem_alloc_nor(priv, mem); +alloc_end: + + return ret; +} +EXPORT_SYMBOL(mtk_vcodec_mem_alloc); + +void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) +{ + enum mtk_instance_type inst_type = *((unsigned int *)priv); + + if (inst_type == MTK_INST_DECODER) { + struct mtk_vcodec_dec_ctx *dec_ctx = priv; + + if (dec_ctx->is_secure_playback) { + mtk_vcodec_mem_free_sec(mem); + return; + } + } + + mtk_vcodec_mem_free_nor(priv, mem); +} EXPORT_SYMBOL(mtk_vcodec_mem_free); void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx) @@ -172,3 +287,4 @@ EXPORT_SYMBOL(mtk_vcodec_get_curr_ctx); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Mediatek video codec driver"); +MODULE_IMPORT_NS(DMA_BUF); diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h index 85f615cdd4d3..22078e757ed0 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h @@ -18,6 +18,9 @@ struct mtk_vcodec_mem { size_t size; void *va; dma_addr_t dma_addr; + + struct dma_buf_attachment *attach; + struct sg_table *sgt; }; struct mtk_vcodec_fb { From patchwork Wed Dec 6 08:15:30 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: 174417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957367vqy; Wed, 6 Dec 2023 00:16:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjcrEOwTLkhEJzAcirTuuIXUNAeWqqtnaAHAhv2yart7hbvMqa4elUFSF4XM2lyYZpHhJM X-Received: by 2002:a05:6a20:6aaf:b0:18f:97c:384c with SMTP id bi47-20020a056a206aaf00b0018f097c384cmr744710pzb.38.1701850617353; Wed, 06 Dec 2023 00:16:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850617; cv=none; d=google.com; s=arc-20160816; b=YEXa1X2lxruCfBhFGxlR495gBZblZ9vUaj4qSrAiPL7Mm+uXDnvluCx9WGOxG9mm51 usqaxCpCtp+8IxDBxJOCdui7NTV+tm/Wl3+m8J3jXL8bsdRWe1Wfr3qB0mf8bT8daVH3 nYdwIXMbX8pSI0Y11plF5EYg0WxME5DKy/mX4sjvUSzczlej01ZKk030Y/N2uHhgrQpZ HtMukOhd0J4xxV7vGJQZ5t88MiyCvd7yz9PVBWzgJjWJZNZJX/X/VtQ5xP2AnszBN1Ue gYPxgETgiKDzpbtsXV7uG6Qji7s0lqfMDWVphZLeATKNM3K4yrf+9ZALXymC2Eaxm7Pg N/xQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qwM6JgCEYya6p3UBStFyf78I7pEgy/IRsIjn5bFayA8=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=LzS68eNCkjj79lzCUdtiTO6Z2u+ZTGUzi1fvf3hQ5dFhXmr9ru8Kl7sjbO1SBeRqxG FjYz8oykIA88mGRAw3IVkLY4W3keuwWsXB/P47D1SjiBeCZwoUi9sGpjbO9c7KF/1qot aWNBGDTTEWalS4lU/NBr/mJH+JPoWsuJlW4OAeXBxvRm5F56pu7nH8EQqRHGWYbjKdRW l+IJBm+cSG0AySZUaJ71hnRFB4RzZTzRpm+SBv3qyy90G+VD9qICWfK/h7IB/3KevPhC 1HsKS53TrVIhStqDHNNSzQyRz+8mOKTddUsnT+UnwO9+FzH8OBo+T4krjT7xipkAXsre SUHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UpS4MwPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t5-20020a654085000000b005c14c9b2d90si10940289pgp.59.2023.12.06.00.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:16:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UpS4MwPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 12106802C8CD; Wed, 6 Dec 2023 00:16:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377289AbjLFIQn (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377240AbjLFIQY (ORCPT ); Wed, 6 Dec 2023 03:16:24 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86C7CD7F; Wed, 6 Dec 2023 00:16:05 -0800 (PST) X-UUID: afb9a9c2940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=qwM6JgCEYya6p3UBStFyf78I7pEgy/IRsIjn5bFayA8=; b=UpS4MwPCrTgr8so1iPSs6ETNkyQbOECFFLr/OZ4RsiMyHfXw4Jykce1v9SJvSAQEahExwKWr3BTkmuJO9hP2yMgTil9XSENYGmK3XocuP1eLYAMYwOO9yM2iZyh69HOfDpO3rse221kDkpbFt7a0rYcRz93NATQYHGsEMVe2sU0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:34538b0b-e017-48e8-866e-6f717085dd47,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:abefa75,CLOUDID:202d59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: afb9a9c2940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1652442288; Wed, 06 Dec 2023 16:15:58 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) 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:57 +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:55 +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,13/21] media: mediatek: vcodec: using shared memory as vsi address Date: Wed, 6 Dec 2023 16:15:30 +0800 Message-ID: <20231206081538.17056-14-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--4.493000-8.000000 X-TMASE-MatchedRID: 6iG0MA7tSw80Z9sXcK7F6QPZZctd3P4BK2i9pofGVSsKogmGusPLb/BY Ro06eVj3M+9E78FP+k6T5In082VlTzMbZlaZZohC58dk5sbwmyhfyi4Yas3gTZsoi2XrUn/Jn6K dMrRsL14qtq5d3cxkNffvWahKfRU4AumCAeBuR1xMqLLbzYMQRd0KPfBv8Xir/XSCcwEXK+jh1k GrZWNDBzSiBaGGOg0fgo86WtAe84CuRIEUgg/8OmjX2K24W1FBaaeeX2Q5bK9+HGPweyal2mGdU ezV59DHQZpgl3CshRSeqD9WtJkSIw== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.493000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: B9D2536B59FDE817DAD4CE04CA2020A5C4E1FC7F020BCD7AB93D5022871515542000:8 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519712497244018 X-GMAIL-MSGID: 1784519712497244018 The vsi buffer is allocated by tee share memory for svp mode, need to use the share memory as the vsi address to store vsi data. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/vdec/vdec_h264_req_multi_if.c | 9 +++++++-- .../media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 0e741e0dc8ba..4967e0f0984d 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -417,8 +417,13 @@ static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx) vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi), VCODEC_DEC_ALIGNED_64); inst->vsi = inst->vpu.vsi; - inst->vsi_core = - (struct vdec_h264_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); + if (ctx->is_secure_playback) + inst->vsi_core = + mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE, + OPTEE_DATA_INDEX); + else + inst->vsi_core = + (struct vdec_h264_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); inst->resolution_changed = true; inst->realloc_mv_buf = true; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c index 5336769a3fb5..5c31641e9abe 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c @@ -18,8 +18,12 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg) /* mapping VPU address to kernel virtual address */ /* the content in vsi is initialized to 0 in VPU */ - vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler, - msg->vpu_inst_addr); + if (vpu->ctx->is_secure_playback) + vpu->vsi = mtk_vcodec_dec_get_shm_buffer_va(vpu->ctx->dev->optee_private, + MTK_VDEC_LAT0, OPTEE_DATA_INDEX); + else + vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler, + msg->vpu_inst_addr); vpu->inst_addr = msg->vpu_inst_addr; mtk_vdec_debug(vpu->ctx, "- vpu_inst_addr = 0x%x", vpu->inst_addr); From patchwork Wed Dec 6 08:15:31 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: 174418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957387vqy; Wed, 6 Dec 2023 00:17:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjr5xMZke8Up9RO3xON+1mEtI69S29teflOlhUyGm78xv8i8j0INnCTfHdxjAIKgOAAl5P X-Received: by 2002:a17:902:7c03:b0:1d0:c888:d11d with SMTP id x3-20020a1709027c0300b001d0c888d11dmr692649pll.29.1701850620804; Wed, 06 Dec 2023 00:17:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850620; cv=none; d=google.com; s=arc-20160816; b=Q4cG3e6d3t60TsZoUH+jrk9WzQATCprzNkFMnfji0PqYALmuYcFhCkz8mQQG/NiYM3 09lhzVeoqkYnxwg8VgwlkN4HdIjbSSa9ciuL1IxoO//vYDA3Xj5ELqP9ueT4awR+PqAu W9Y4Jyvr6g4ApGfZsJ9yWG0LCnQTYvHDdt0dkssgHjAqsvOwKPJ+p484muGaSZvtOwvy NXj2z9dAUe1EqHXJV0aMIeSZkyWmYkVdOPJpd20vq79tQ7Xfm8Q3qubrHTmurEzv+m7g hEgQL7VSHgVsbvk6Z3/ajEFoJbItgdHN+Qc0h3JjHLA9j5OeXQKFAu7ZhKLG6kNMX7P7 3ObA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xjZznbL1NylUSHGjnzUc/3L2alctepBGGHVp/cf6Fds=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=Bp6gQk/4dW4CbpgmIc/+13CFDtT606gKUXW+0b5xtEi44zo4MoXNESV9DGRPs4rJhL CKh4/markE+CGZYQkPDSJj1d5hR02z9cG2gyaN8V/mYf+SsKJ/sMcW5jacb8tXowEbdg J3FnmKh0MTgRJXde+Rdb2Yxz/4baeF8c+iksqaY3fhGVDAUNJWCGWqpTJeMSqOSmy4iw i6EnVMXn+kj1dEgcSPNqfGr3d8QTqBsBZ89AHSVlXFxkXVpz6j3JtasVtZ0zoMIK2oB5 9iJMf/zQ14Ih6uwJK199Qe06t6zvDMpGn2iw66jvFz92p2f5HW1pxaRtn5jnKKrRptid Yagg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=tYGGQlzo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p6-20020a170902b08600b001cfda41729esi10852359plr.364.2023.12.06.00.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=tYGGQlzo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 032F9802C8D5; Wed, 6 Dec 2023 00:16:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377316AbjLFIQs (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377207AbjLFIQZ (ORCPT ); Wed, 6 Dec 2023 03:16:25 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6E5810D1; Wed, 6 Dec 2023 00:16:06 -0800 (PST) X-UUID: b04ff7c4940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=xjZznbL1NylUSHGjnzUc/3L2alctepBGGHVp/cf6Fds=; b=tYGGQlzoZsb+YrR34KYD6G7AAOHT2knbBspiV5qt/y7laz5JM24RSrf9vuy5KqaImQg34fVN97w4v4Q2fWOOpJw+bVwzEXBAdmWxkBzIJB2lTgXaBeBEQk2TQLzaA8mPeMrDWFHBhGP6LhaVMZCrw1wWZso3zdgPkQ5pCLwhWNk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:c562728f-e5b0-46c3-af86-63522ba3e34c,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:abefa75,CLOUDID:e1e87773-1bd3-4f48-b671-ada88705968c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b04ff7c4940f11ee8051498923ad61e6-20231206 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1929821831; Wed, 06 Dec 2023 16:15:59 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n2.mediatek.inc (172.21.101.187) 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:58 +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:57 +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,14/21] media: mediatek: vcodec: Add capture format to support one plane memory Date: Wed, 6 Dec 2023 16:15:31 +0800 Message-ID: <20231206081538.17056-15-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RDNS_NONE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:16:59 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519716286888889 X-GMAIL-MSGID: 1784519716286888889 Define one uncompressed capture format V4L2_PIX_FMT_MS21 in order to support one plane memory. The buffer size is luma + chroma, luma is stored at the start and chrome is stored at the end. Signed-off-by: Yunfei Dong --- Documentation/userspace-api/media/v4l/pixfmt-reserved.rst | 8 ++++++++ drivers/media/v4l2-core/v4l2-common.c | 2 ++ drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 4 files changed, 12 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst b/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst index 886ba7b08d6b..6ec899649d50 100644 --- a/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst +++ b/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst @@ -295,6 +295,14 @@ please make a proposal on the linux-media mailing list. - Compressed format used by Nuvoton NPCM video driver. This format is defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4 Hextile Encoding). + * .. _V4L2-PIX-FMT-MS21: + + - ``V4L2_PIX_FMT_MS21`` + - 'MS21' + - This format has one plane, luma and chroma are stored in a contiguous + memory. Luma pixel in 16x32 tiles at the start, chroma pixel in 16x16 + tiles at the end. The image height must be aligned with 32 and the image + width must be aligned with 16. .. raw:: latex \normalsize diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index e9e7e70fa24e..85aa3319cbc6 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -269,6 +269,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, { .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, + { .format = V4L2_PIX_FMT_MS21, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, /* YUV planar formats */ { .format = V4L2_PIX_FMT_NV12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 33076af4dfdb..26ffe4d1c28f 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1511,6 +1511,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_PIX_FMT_MT2110T: descr = "Mediatek 10bit Tile Mode"; break; case V4L2_PIX_FMT_MT2110R: descr = "Mediatek 10bit Raster Mode"; break; case V4L2_PIX_FMT_HEXTILE: descr = "Hextile Compressed Format"; break; + case V4L2_PIX_FMT_MS21: descr = "Mediatek One Plane Format"; break; default: if (fmt->description[0]) return; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 570b11552818..6be0d0e35077 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -798,6 +798,7 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_MM21 v4l2_fourcc('M', 'M', '2', '1') /* Mediatek 8-bit block mode, two non-contiguous planes */ #define V4L2_PIX_FMT_MT2110T v4l2_fourcc('M', 'T', '2', 'T') /* Mediatek 10-bit block tile mode */ #define V4L2_PIX_FMT_MT2110R v4l2_fourcc('M', 'T', '2', 'R') /* Mediatek 10-bit block raster mode */ +#define V4L2_PIX_FMT_MS21 v4l2_fourcc('M', 'S', '2', '1') /* Mediatek 8-bit block mode with one plane */ #define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* Intel Planar Greyscale 10-bit and Depth 16-bit */ #define V4L2_PIX_FMT_CNF4 v4l2_fourcc('C', 'N', 'F', '4') /* Intel 4-bit packed depth confidence information */ #define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* BTTV 8-bit dithered RGB */ From patchwork Wed Dec 6 08:15:32 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: 174420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957402vqy; Wed, 6 Dec 2023 00:17:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUtyGG0CfTHQuvNwuG4OLD9O5UT1I6wjfpA+bZZ7gjAHY2FW/jyoeFJLL2EYeJ7rHCYfHF X-Received: by 2002:a05:6359:6609:b0:170:17eb:9c45 with SMTP id sm9-20020a056359660900b0017017eb9c45mr610692rwb.38.1701850623610; Wed, 06 Dec 2023 00:17:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850623; cv=none; d=google.com; s=arc-20160816; b=ZfDfg2D5Cwpz5vaWMBn9oRe2XJr4f+HdgKfbKmV4Fp+uqSseKlHUZjYEWpSIOHlJrn FBeAeQ6/FXhvVCPcvSvYRMBAggMQSxfaVprjmlOTpCBuAXzi1eouZTg9ZH05+6x4JBjq aJ/NFGGccx6icjr6x7XVMkxzqxpOSAtdmn+rT5RcM4BDg7yhNTkrX3SCA9HiZddJQ1f9 u0XpHmUK93hOYq4oinu02EPEZq6Uk1narVPwpzdYr1nx6AVzim713tF1aAxYljTuQQAv B1dLElSu2hLdGj3llxeH96UZ42Koy6zCApM0EJ63jiiEDlMg0mUKRXccsNBNMbTlTy+l yakA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RIQoT27GcYuuJ+QhfUoHjqOEFRPYloQJzRhu1bfSFyk=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=c0KYVbOHRUDp8X9+5rqEMdPpw6rbcorpN8ljJ+SonaGT26NgMW8ot3PdMO9j/Dh+ya WLI4mkJcUjp8pjtQW7oZptMmz/xqqk7hrDroaq+bgVaged0ApUgkJN9ltvuT8By7R4FJ lZGW0azxRHIX93Fa4mBAcJRKyoiZ8WVfkEvJiS3RuuN6pZUhQFse2t+rIDm34P2uQh/G x9JJMzi+yvwWBgPMCkguyNJRHaBw6UBKddA8+txfmfcj0ftjLUhKF2vsg15/6VJycmvN iSVcZpBrmaMlCxoBXqzJoDniTQV49DcGxUkBzHA8tygnLjaRQJcXOiPVGYxAFVGaq1nc H5ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=oxr1C9at; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ca39-20020a056a0206a700b005c200b11ba7si3592668pgb.763.2023.12.06.00.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=oxr1C9at; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7415A802C8DC; Wed, 6 Dec 2023 00:17:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377164AbjLFIQw (ORCPT + 99 others); Wed, 6 Dec 2023 03:16:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377258AbjLFIQ1 (ORCPT ); Wed, 6 Dec 2023 03:16:27 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 847A510F0; Wed, 6 Dec 2023 00:16:08 -0800 (PST) X-UUID: b112f742940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=RIQoT27GcYuuJ+QhfUoHjqOEFRPYloQJzRhu1bfSFyk=; b=oxr1C9atSLG/729/pZTsXF5qDsniUcJlNeW60CFm0iEYho/uixPsrXysjZTChaOL2Fn3NsNKtZcKk/1vUVmveNZfFoHCVTNcOEoXxmCUlqEmHWAHRfoPRyJgMHOc7LOYbKLE/Jzll8ECGaKZC85KGFHk3sB4A38ENMUcLXgEaB4=; X-CID-CACHE: Type:Local,Time:202312061616+08,HitQuantity:1 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:6e2d1dce-8ea0-4708-b22a-21d35f2c7e6a,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:8b79e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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 X-UUID: b112f742940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1018701023; Wed, 06 Dec 2023 16:16:01 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n2.mediatek.inc (172.21.101.108) 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:59 +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:58 +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,15/21] media: mediatek: vcodec: Add one plane format Date: Wed, 6 Dec 2023 16:15:32 +0800 Message-ID: <20231206081538.17056-16-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:17:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519719861194523 X-GMAIL-MSGID: 1784519719861194523 Adding capture formats to support V4L2_PIX_FMT_MS21. This format has one plane and only be used for secure video playback at current period. Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c | 4 +++- .../mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c | 9 ++++++++- 2 files changed, 11 insertions(+), 2 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 ba742f0e391d..604fdc8ee3ce 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -49,7 +49,9 @@ static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_dec_ctx *ctx, int format_inde num_frame_count++; } - if (num_frame_count == 1 || (!ctx->is_10bit_bitstream && fmt->fourcc == V4L2_PIX_FMT_MM21)) + if ((!ctx->is_10bit_bitstream && fmt->fourcc == V4L2_PIX_FMT_MM21) || + (ctx->is_secure_playback && fmt->fourcc == V4L2_PIX_FMT_MS21) || + num_frame_count == 1) return true; q_data = &ctx->q_data[MTK_Q_DATA_SRC]; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c index d54b3833790d..cc42c942eb8a 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -229,7 +229,7 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { #define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[9]; +static struct mtk_video_fmt mtk_video_formats[10]; static struct mtk_video_fmt default_out_format; static struct mtk_video_fmt default_cap_format; @@ -770,6 +770,11 @@ static void mtk_vcodec_add_formats(unsigned int fourcc, mtk_video_formats[count_formats].type = MTK_FMT_FRAME; mtk_video_formats[count_formats].num_planes = 2; break; + case V4L2_PIX_FMT_MS21: + mtk_video_formats[count_formats].fourcc = fourcc; + mtk_video_formats[count_formats].type = MTK_FMT_FRAME; + mtk_video_formats[count_formats].num_planes = 1; + break; default: mtk_v4l2_vdec_err(ctx, "Can not add unsupported format type"); return; @@ -798,6 +803,8 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_dec_ctx *ctx) cap_format_count++; } if (ctx->dev->dec_capability & MTK_VDEC_FORMAT_MM21) { + mtk_vcodec_add_formats(V4L2_PIX_FMT_MS21, ctx); + cap_format_count++; mtk_vcodec_add_formats(V4L2_PIX_FMT_MM21, ctx); cap_format_count++; } From patchwork Wed Dec 6 08:15:33 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: 174421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957475vqy; Wed, 6 Dec 2023 00:17:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+G6U6rsZhk4hvxyESZVebWxtN6qFYf2RAKjPBoeEzvGRPSp0Q05sG/hmUbJ9W+uiy7YKV X-Received: by 2002:a05:6a00:1950:b0:6ce:57f2:45fa with SMTP id s16-20020a056a00195000b006ce57f245famr290320pfk.49.1701850634846; Wed, 06 Dec 2023 00:17:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850634; cv=none; d=google.com; s=arc-20160816; b=mXSvohFdeljSA6FPp/sSvzRX+nCbcAHDhn1+QF0ZqbK5p0cf/b4K1P2YIPUAslA9ad 9bhorg0s538tHfOkfgqUskk6j4qsqhd1csTLYosQRx40ptlqLHM55PzeijqZwy3SZm1Z CLBOmA5bvYLwYAJixYPweMO24kmp4afhlUraOhyJFwJrr7W2LBA9TVl4jEFGzYmqy2FS 8+q9C5mGsCMmqz2ACNPZ0jV+wf6mLY7IPn06AT5ghtZgrj3wqhKwJRh4kd/R1EcYvtJZ UnYOPxnqfZZ0u4m6ysylM/JpSDeuotK1AmVqPxTMrtpSwHy54rjKbsga6kB+YSe4TBUc 08rA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lPwo9LNvB2FbQZZUU/VdB7YQJTuTNN5gXoP5cMTC8VQ=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=b6pJpgkMsn1EZKvI7DgsUF7lF8quoPqWyas5YQT1gs1i5Xbpk5OcdduFzWJnOlmXFc 2wYuBMdpmZXfIBHbtEWQmVwFRT/XNRiAup1EwGby3FiIar38mkvnxGxagM5HiwqjtGw+ g0Y3xSj18ikoj+G4iWDJWfIo9eVIUBdxmUCJnpk3ikxcEmsAZVyH4SxQsQX/cG42v/fd 2wcPq9t9AXZQwT5fUL/YtSB7ZfbQQju7wD5a//f85l1S7JUI7HjzfKFY8YH/vlC6ue3+ yWenllMhC4ku64A5yEm4VSkgcv0urN7FXTf2QU4G7yKGTjJgI+Q2kVzQmzfcuNumC7RI vyEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="XTrpao/X"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b2-20020a056a00114200b0068fcf194dacsi11181825pfm.92.2023.12.06.00.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="XTrpao/X"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id D82BD802C8F6; Wed, 6 Dec 2023 00:17:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377173AbjLFIRC (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377264AbjLFIQ1 (ORCPT ); Wed, 6 Dec 2023 03:16:27 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88FB410FB; Wed, 6 Dec 2023 00:16:09 -0800 (PST) X-UUID: b18fc312940f11eea33bb35ae8d461a2-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=lPwo9LNvB2FbQZZUU/VdB7YQJTuTNN5gXoP5cMTC8VQ=; b=XTrpao/XBs1eOkC0/C1qzb58VfaR5neZGTjghzAIlKPdLNrBVDo0l9UHolMgkfMsJJGfOfGgbByvTrVTcG2ACJrYfhSbQnuPhqjRgYk8IwGD1iLkpRJNqSgs8OmaYoc5pzhzixB+6V7j+Ppt+qRcnHomlQYLfx6cmooLLLqWcxQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:09c72963-5583-4a9d-8c4d-6f43397696e4,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:abefa75,CLOUDID:b979e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_ULN,TF_CID_SPAM_SNR X-UUID: b18fc312940f11eea33bb35ae8d461a2-20231206 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 817340102; Wed, 06 Dec 2023 16:16:01 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n2.mediatek.inc (172.21.101.187) 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:16:01 +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:59 +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,16/21] media: medkatek: vcodec: support one plane capture buffer Date: Wed, 6 Dec 2023 16:15:33 +0800 Message-ID: <20231206081538.17056-17-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:17:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519731271302991 X-GMAIL-MSGID: 1784519731271302991 The capture buffer has two planes for format MM21, but user space only allocate secure memory for plane[0], and the size is Y data + uv data. The driver need to support one plane decoder for svp mode. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 7 ++++- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 26 ++++++++++--------- .../decoder/vdec/vdec_h264_req_common.c | 11 +++----- .../mediatek/vcodec/decoder/vdec_drv_if.c | 4 +-- 4 files changed, 26 insertions(+), 22 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 604fdc8ee3ce..ab922e8d2d37 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -653,7 +653,12 @@ static int vidioc_vdec_g_fmt(struct file *file, void *priv, * So we just return picinfo yet, and update picinfo in * stop_streaming hook function */ - q_data->sizeimage[0] = ctx->picinfo.fb_sz[0]; + + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) + 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->sizeimage[1] = ctx->picinfo.fb_sz[1]; q_data->bytesperline[0] = ctx->last_decoded_picinfo.buf_w; q_data->bytesperline[1] = ctx->last_decoded_picinfo.buf_w; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c index cc42c942eb8a..707ed57a412e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -285,14 +285,14 @@ static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx) framebuf = container_of(vb2_v4l2, struct mtk_video_dec_buf, m2m_buf.vb); pfb = &framebuf->frame_buffer; - pfb->base_y.va = vb2_plane_vaddr(dst_buf, 0); + if (!ctx->is_secure_playback) + pfb->base_y.va = vb2_plane_vaddr(dst_buf, 0); pfb->base_y.dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0); pfb->base_y.size = ctx->q_data[MTK_Q_DATA_DST].sizeimage[0]; - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2 && !ctx->is_secure_playback) { pfb->base_c.va = vb2_plane_vaddr(dst_buf, 1); - pfb->base_c.dma_addr = - vb2_dma_contig_plane_dma_addr(dst_buf, 1); + pfb->base_c.dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 1); pfb->base_c.size = ctx->q_data[MTK_Q_DATA_DST].sizeimage[1]; } mtk_v4l2_vdec_dbg(1, ctx, @@ -339,16 +339,18 @@ static void mtk_vdec_worker(struct work_struct *work) mtk_v4l2_vdec_dbg(3, ctx, "[%d] (%d) id=%d, vb=%p", ctx->id, vb2_src->vb2_queue->type, vb2_src->index, vb2_src); - bs_src->va = vb2_plane_vaddr(vb2_src, 0); - bs_src->dma_addr = vb2_dma_contig_plane_dma_addr(vb2_src, 0); - bs_src->size = (size_t)vb2_src->planes[0].bytesused; - if (!bs_src->va) { - v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); - mtk_v4l2_vdec_err(ctx, "[%d] id=%d source buffer is NULL", ctx->id, - vb2_src->index); - return; + if (!ctx->is_secure_playback) { + bs_src->va = vb2_plane_vaddr(vb2_src, 0); + if (!bs_src->va) { + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); + mtk_v4l2_vdec_err(ctx, "[%d] id=%d source buffer is NULL", ctx->id, + vb2_src->index); + return; + } } + bs_src->dma_addr = vb2_dma_contig_plane_dma_addr(vb2_src, 0); + bs_src->size = (size_t)vb2_src->planes[0].bytesused; mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p", ctx->id, bs_src->va, &bs_src->dma_addr, bs_src->size, vb2_src); /* Apply request controls. */ diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c index 5ca20d75dc8e..2a57e689ec07 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c @@ -79,15 +79,12 @@ void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx, vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); h264_dpb_info[index].field = vb2_v4l2->field; - h264_dpb_info[index].y_dma_addr = - vb2_dma_contig_plane_dma_addr(vb, 0); + h264_dpb_info[index].y_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0); if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) + h264_dpb_info[index].c_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 1); + else if (!ctx->is_secure_playback) h264_dpb_info[index].c_dma_addr = - vb2_dma_contig_plane_dma_addr(vb, 1); - else - h264_dpb_info[index].c_dma_addr = - h264_dpb_info[index].y_dma_addr + - ctx->picinfo.fb_sz[0]; + h264_dpb_info[index].y_dma_addr + ctx->picinfo.fb_sz[0]; } } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c index d0b459b1603f..fb3e4f75ed93 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c @@ -73,14 +73,14 @@ int vdec_if_decode(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_mem *bs, { int ret = 0; - if (bs) { + if (bs && !ctx->is_secure_playback) { if ((bs->dma_addr & 63) != 0) { mtk_v4l2_vdec_err(ctx, "bs dma_addr should 64 byte align"); return -EINVAL; } } - if (fb) { + if (fb && !ctx->is_secure_playback) { if (((fb->base_y.dma_addr & 511) != 0) || ((fb->base_c.dma_addr & 511) != 0)) { mtk_v4l2_vdec_err(ctx, "frame buffer dma_addr should 512 byte align"); From patchwork Wed Dec 6 08:15:34 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: 174422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957537vqy; Wed, 6 Dec 2023 00:17:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/Hjfvq4g/CcS8e0iEcRN0SFXU1zgLE2fCpCkXwq//KfPtl3hw93/PCRah9EZGk8sHTrNI X-Received: by 2002:a05:6a00:1d8b:b0:6ce:2732:1e08 with SMTP id z11-20020a056a001d8b00b006ce27321e08mr321965pfw.66.1701850642576; Wed, 06 Dec 2023 00:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850642; cv=none; d=google.com; s=arc-20160816; b=CMl3O8/OjS0pzaVo3fmC9wm6bdR7/HTXT2Eyk3pNLsQnzyxRolG6DN9dHp2T/c4/fr adrVSeXnfn0fp79N1hNeVKV4BIrzUcCZl7cam5dmQjrMzueXFmWsLOb7K0ho7F69VO5o k9OcugzoWGPTT7BlbaRlge6YSL0R7qOzWphyWrJ7TSVAGO6g8ZxHRyc8YC+bTIzT4nlL p9Ccz1G2KHFdj5nMmFqJASVViniLoOzaGvc6XtSLMquKvMt4IIYgxPHZ2CWkFFiW23ar Dljet/0/SZZjLsfSRGYKK1hDkzbTW8LIJ4ootTRtRw7Sog4x8T3fYA6QdoZUwswMthLl U/hg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oCz9ePgPpwTLEOdOqoCI8QwgUoj21cKcR2CQD3pJoR8=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=fBrgh7KphKxam2r2jbvgGi07ODhdDGhuQWKW9DxCnFykP6cUPsvEvTzIdDBmmESMhE L4kSUKjE/xBJyVisRKzvElphROijh0BLvdsYzZG/xwWD7aj0c6opW2XN8d2A3bTCHIy1 BTM/9jpPj1HHJgLz2ZkRy/FSDeu16+h90y0OgCfpX3VHTp6B5hhKx9/FBpWDFB1JbVH3 zlG+igKXAzsAwmEtqgShpv/bu0FzQdHM8wRbSh7WbWWkzG6oBa+r6KnP4V7VMhdKvmKj e6AIU7NRef0848Tl5qBRbxcaA/WPDtxIp/yBf1M2Wrk6Ptaa85nDG/gBG3zY8FwCF04G DUnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=VCcfQpVK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w189-20020a6362c6000000b005c65c11ad09si7136883pgb.768.2023.12.06.00.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=VCcfQpVK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 96451802C7C8; Wed, 6 Dec 2023 00:17:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377238AbjLFIRF (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377181AbjLFIQk (ORCPT ); Wed, 6 Dec 2023 03:16:40 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B0BF1700; Wed, 6 Dec 2023 00:16:09 -0800 (PST) X-UUID: b2e0d634940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=oCz9ePgPpwTLEOdOqoCI8QwgUoj21cKcR2CQD3pJoR8=; b=VCcfQpVK5VPjVQWoyNdGRuIUOC3PMYzuIhhEb50dDzdJX/ZdROQdI+y43VoWC8xrGyfOe4YnMRf3Sj+kgTJRW5taT+iyWWgQU1g+7OM7WUriqaVoXJfQSYHnXyELAqTKVKAuPNmkYzDXlXo4pW5gG+ZidpwHHMLLu8jksf/NV+s=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:53ae1536-5d19-40b7-afe0-dcecd1bdc353,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:e379e060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b2e0d634940f11ee8051498923ad61e6-20231206 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 1883150388; Wed, 06 Dec 2023 16:16:04 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) 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:16:02 +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:16:01 +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,17/21] media: medkatek: vcodec: re-construct h264 driver to support svp mode Date: Wed, 6 Dec 2023 16:15:34 +0800 Message-ID: <20231206081538.17056-18-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--11.311700-8.000000 X-TMASE-MatchedRID: FJaYFT2kkHwXSulpnju2HwwfhKwa9GwD6Jlwb2gbuk6na6U74e0+qJkC erFMaabiEcE+LOiKuIu00IswV/oVHJslyqXPRrNnSHCU59h5KrFYN1akkye0qJgWnaLDiGghOco 6p+CZZ/zwYKShJdlqCUioj2M+ndA7tRrZmY+hVK3il2r2x2PwtbmnDa2zGPi0+5+93dPb6/fCLK ePGo1T5AS2A89iNQ91+tVFsxWM0w7pHzzvfxlA9RafLXbshfoguoYFb0nRiqOJoFTGeLN6N6Slr iOVWJAtOIV7JqnSnzv0Gf9hc2iLRFxxDx5qbkR9FEUknJ/kEl6tIWznhjjBtfoLR4+zsDTtgUic vJ4MChlTCeUN7Nj+3B7G0UqBFij2hJ5J51UZG4Vc4GWekD6dzFPg5iEtbTkD X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--11.311700-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 6C6143AC752B926E2C399ECF815F982DDF64EE5EE67E12C725066F933913A7DB2000:8 X-MTK: N X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RDNS_NONE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:17:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519739387687927 X-GMAIL-MSGID: 1784519739387687927 Need secure buffer size to convert secure handle to secure pa in optee-os, re-construct the vsi struct to store each secure buffer size. Separate svp and normal wait interrupt condition for svp mode waiting hardware interrupt in optee-os. Signed-off-by: Yunfei Dong --- .../decoder/vdec/vdec_h264_req_multi_if.c | 261 +++++++++++------- .../mediatek/vcodec/decoder/vdec_msg_queue.c | 9 +- 2 files changed, 168 insertions(+), 102 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 4967e0f0984d..a1a68487131c 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -60,14 +60,36 @@ struct vdec_h264_slice_lat_dec_param { * @crc: Used to check whether hardware's status is right */ struct vdec_h264_slice_info { + u64 wdma_end_addr_offset; u16 nal_info; u16 timeout; - u32 bs_buf_size; - u64 bs_buf_addr; - u64 y_fb_dma; - u64 c_fb_dma; u64 vdec_fb_va; u32 crc[8]; + u32 reserved; +}; + +/* + * struct vdec_h264_slice_mem - memory address and size + */ +struct vdec_h264_slice_mem { + union { + u64 buf; + u64 dma_addr; + }; + union { + size_t size; + u64 dma_addr_end; + }; +}; + +/** + * struct vdec_h264_slice_fb - frame buffer for decoding + * @y: current y buffer address info + * @c: current c buffer address info + */ +struct vdec_h264_slice_fb { + struct vdec_h264_slice_mem y; + struct vdec_h264_slice_mem c; }; /** @@ -92,18 +114,16 @@ struct vdec_h264_slice_info { */ struct vdec_h264_slice_vsi { /* LAT dec addr */ - u64 wdma_err_addr; - u64 wdma_start_addr; - u64 wdma_end_addr; - u64 slice_bc_start_addr; - u64 slice_bc_end_addr; - u64 row_info_start_addr; - u64 row_info_end_addr; - u64 trans_start; - u64 trans_end; - u64 wdma_end_addr_offset; + struct vdec_h264_slice_mem bs; + struct vdec_h264_slice_fb fb; - u64 mv_buf_dma[H264_MAX_MV_NUM]; + struct vdec_h264_slice_mem ube; + struct vdec_h264_slice_mem trans; + struct vdec_h264_slice_mem row_info; + struct vdec_h264_slice_mem err_map; + struct vdec_h264_slice_mem slice_bc; + + struct vdec_h264_slice_mem mv_buf_dma[H264_MAX_MV_NUM]; struct vdec_h264_slice_info dec; struct vdec_h264_slice_lat_dec_param h264_slice_params; }; @@ -392,6 +412,100 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, cr->left, cr->top, cr->width, cr->height); } +static void vdec_h264_slice_setup_lat_buffer(struct vdec_h264_slice_inst *inst, + struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf) +{ + struct mtk_vcodec_mem *mem; + int i; + + inst->vsi->bs.dma_addr = (u64)bs->dma_addr; + inst->vsi->bs.size = bs->size; + + for (i = 0; i < H264_MAX_MV_NUM; i++) { + mem = &inst->mv_buf[i]; + inst->vsi->mv_buf_dma[i].dma_addr = mem->dma_addr; + inst->vsi->mv_buf_dma[i].size = mem->size; + } + inst->vsi->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + inst->vsi->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + + inst->vsi->row_info.dma_addr = 0; + inst->vsi->row_info.size = 0; + + inst->vsi->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + inst->vsi->err_map.size = lat_buf->wdma_err_addr.size; + + inst->vsi->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr; + inst->vsi->slice_bc.size = lat_buf->slice_bc_addr.size; + + inst->vsi->trans.dma_addr_end = inst->ctx->msg_queue.wdma_rptr_addr; + inst->vsi->trans.dma_addr = inst->ctx->msg_queue.wdma_wptr_addr; +} + +static int vdec_h264_slice_setup_core_buffer(struct vdec_h264_slice_inst *inst, + struct vdec_h264_slice_share_info *share_info, + struct vdec_lat_buf *lat_buf) +{ + struct mtk_vcodec_mem *mem; + struct mtk_vcodec_dec_ctx *ctx = inst->ctx; + struct vb2_v4l2_buffer *vb2_v4l2; + struct vdec_fb *fb; + u64 y_fb_dma, c_fb_dma = 0; + int i; + + fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx); + if (!fb) { + mtk_vdec_err(ctx, "fb buffer is NULL"); + return -EBUSY; + } + + y_fb_dma = (u64)fb->base_y.dma_addr; + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) + c_fb_dma = + y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; + else + c_fb_dma = (u64)fb->base_c.dma_addr; + } + + mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma); + + inst->vsi_core->fb.y.dma_addr = y_fb_dma; + inst->vsi_core->fb.y.size = ctx->picinfo.fb_sz[0]; + inst->vsi_core->fb.c.dma_addr = c_fb_dma; + inst->vsi_core->fb.c.size = ctx->picinfo.fb_sz[1]; + + inst->vsi_core->dec.vdec_fb_va = (unsigned long)fb; + inst->vsi_core->dec.nal_info = share_info->nal_info; + + inst->vsi_core->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + inst->vsi_core->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + + inst->vsi_core->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + inst->vsi_core->err_map.size = lat_buf->wdma_err_addr.size; + + inst->vsi_core->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr; + inst->vsi_core->slice_bc.size = lat_buf->slice_bc_addr.size; + + inst->vsi_core->row_info.dma_addr = 0; + inst->vsi_core->row_info.size = 0; + + inst->vsi_core->trans.dma_addr = share_info->trans_start; + inst->vsi_core->trans.dma_addr_end = share_info->trans_end; + + for (i = 0; i < H264_MAX_MV_NUM; i++) { + mem = &inst->mv_buf[i]; + inst->vsi_core->mv_buf_dma[i].dma_addr = mem->dma_addr; + inst->vsi_core->mv_buf_dma[i].size = mem->size; + } + + vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); + v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true); + + return 0; +} + static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx) { struct vdec_h264_slice_inst *inst; @@ -457,64 +571,22 @@ static void vdec_h264_slice_deinit(void *h_vdec) static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) { - struct vdec_fb *fb; - u64 vdec_fb_va; - u64 y_fb_dma, c_fb_dma; - int err, timeout, i; + int err, timeout; struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx; struct vdec_h264_slice_inst *inst = ctx->drv_handle; - struct vb2_v4l2_buffer *vb2_v4l2; struct vdec_h264_slice_share_info *share_info = lat_buf->private_data; - struct mtk_vcodec_mem *mem; struct vdec_vpu_inst *vpu = &inst->vpu; mtk_vdec_debug(ctx, "[h264-core] vdec_h264 core decode"); memcpy(&inst->vsi_core->h264_slice_params, &share_info->h264_slice_params, sizeof(share_info->h264_slice_params)); - fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx); - if (!fb) { - err = -EBUSY; - mtk_vdec_err(ctx, "fb buffer is NULL"); + err = vdec_h264_slice_setup_core_buffer(inst, share_info, lat_buf); + if (err) goto vdec_dec_end; - } - - vdec_fb_va = (unsigned long)fb; - y_fb_dma = (u64)fb->base_y.dma_addr; - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) - c_fb_dma = - y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; - else - c_fb_dma = (u64)fb->base_c.dma_addr; - - mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma); - - inst->vsi_core->dec.y_fb_dma = y_fb_dma; - inst->vsi_core->dec.c_fb_dma = c_fb_dma; - inst->vsi_core->dec.vdec_fb_va = vdec_fb_va; - inst->vsi_core->dec.nal_info = share_info->nal_info; - inst->vsi_core->wdma_start_addr = - lat_buf->ctx->msg_queue.wdma_addr.dma_addr; - inst->vsi_core->wdma_end_addr = - lat_buf->ctx->msg_queue.wdma_addr.dma_addr + - lat_buf->ctx->msg_queue.wdma_addr.size; - inst->vsi_core->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr; - inst->vsi_core->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr; - inst->vsi_core->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr + - lat_buf->slice_bc_addr.size; - inst->vsi_core->trans_start = share_info->trans_start; - inst->vsi_core->trans_end = share_info->trans_end; - for (i = 0; i < H264_MAX_MV_NUM; i++) { - mem = &inst->mv_buf[i]; - inst->vsi_core->mv_buf_dma[i] = mem->dma_addr; - } - - vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); - v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true); vdec_h264_slice_fill_decode_reflist(inst, &inst->vsi_core->h264_slice_params, share_info); - err = vpu_dec_core(vpu); if (err) { mtk_vdec_err(ctx, "core decode err=%d", err); @@ -573,12 +645,11 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_h264_slice_inst *inst = h_vdec; struct vdec_vpu_inst *vpu = &inst->vpu; struct mtk_video_dec_buf *src_buf_info; - int nal_start_idx, err, timeout = 0, i; + int nal_start_idx, err, timeout = 0; unsigned int data[2]; struct vdec_lat_buf *lat_buf; struct vdec_h264_slice_share_info *share_info; unsigned char *buf; - struct mtk_vcodec_mem *mem; if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx, vdec_h264_slice_core_decode, @@ -617,11 +688,9 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, if (err) goto err_free_fb_out; - vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size, - &share_info->h264_slice_params.pps); - - inst->vsi->dec.bs_buf_addr = (uint64_t)bs->dma_addr; - inst->vsi->dec.bs_buf_size = bs->size; + if (!inst->ctx->is_secure_playback) + vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size, + &share_info->h264_slice_params.pps); *res_chg = inst->resolution_changed; if (inst->resolution_changed) { @@ -634,38 +703,27 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, } inst->resolution_changed = false; } - for (i = 0; i < H264_MAX_MV_NUM; i++) { - mem = &inst->mv_buf[i]; - inst->vsi->mv_buf_dma[i] = mem->dma_addr; - } - inst->vsi->wdma_start_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; - inst->vsi->wdma_end_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr + - lat_buf->ctx->msg_queue.wdma_addr.size; - inst->vsi->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr; - inst->vsi->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr; - inst->vsi->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr + - lat_buf->slice_bc_addr.size; - - inst->vsi->trans_end = inst->ctx->msg_queue.wdma_rptr_addr; - inst->vsi->trans_start = inst->ctx->msg_queue.wdma_wptr_addr; - mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%llx) err:0x%llx", - inst->vsi->wdma_start_addr, - inst->vsi->wdma_end_addr, - inst->vsi->wdma_err_addr); - - mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%llx) rprt((0x%llx 0x%llx))", - inst->vsi->slice_bc_start_addr, - inst->vsi->slice_bc_end_addr, - inst->vsi->trans_start, - inst->vsi->trans_end); + + vdec_h264_slice_setup_lat_buffer(inst, bs, lat_buf); + mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%lx) err:0x%llx", + inst->vsi->ube.dma_addr, (unsigned long)inst->vsi->ube.size, + inst->vsi->err_map.dma_addr); + + mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%lx) rprt((0x%llx 0x%llx))", + inst->vsi->slice_bc.dma_addr, (unsigned long)inst->vsi->slice_bc.size, + inst->vsi->trans.dma_addr, inst->vsi->trans.dma_addr_end); err = vpu_dec_start(vpu, data, 2); if (err) { mtk_vdec_debug(inst->ctx, "lat decode err: %d", err); goto err_free_fb_out; } - share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + - inst->vsi->wdma_end_addr_offset; + if (inst->ctx->is_secure_playback) + share_info->trans_end = inst->vsi->dec.wdma_end_addr_offset; + else + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + inst->vsi->dec.wdma_end_addr_offset; + share_info->trans_start = inst->ctx->msg_queue.wdma_wptr_addr; share_info->nal_info = inst->vsi->dec.nal_info; @@ -691,8 +749,11 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, return -EINVAL; } - share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + - inst->vsi->wdma_end_addr_offset; + if (inst->ctx->is_secure_playback) + share_info->trans_end = inst->vsi->dec.wdma_end_addr_offset; + else + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + inst->vsi->dec.wdma_end_addr_offset; vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue, share_info->trans_end); if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) { @@ -737,10 +798,10 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs mtk_vdec_debug(inst->ctx, "[h264-dec] [%d] y_dma=%llx c_dma=%llx", inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma); - inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr; - inst->vsi_ctx.dec.bs_buf_size = bs->size; - inst->vsi_ctx.dec.y_fb_dma = y_fb_dma; - inst->vsi_ctx.dec.c_fb_dma = c_fb_dma; + inst->vsi_ctx.bs.dma_addr = (u64)bs->dma_addr; + inst->vsi_ctx.bs.size = bs->size; + inst->vsi_ctx.fb.y.dma_addr = y_fb_dma; + inst->vsi_ctx.fb.c.dma_addr = c_fb_dma; inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, @@ -770,7 +831,7 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs for (i = 0; i < H264_MAX_MV_NUM; i++) { mem = &inst->mv_buf[i]; - inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr; + inst->vsi_ctx.mv_buf_dma[i].dma_addr = mem->dma_addr; } } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c index f283c4703dc6..c1310176ae05 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c @@ -308,8 +308,13 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, msg_queue->wdma_addr.size = 0; return -ENOMEM; } - msg_queue->wdma_rptr_addr = msg_queue->wdma_addr.dma_addr; - msg_queue->wdma_wptr_addr = msg_queue->wdma_addr.dma_addr; + if (ctx->is_secure_playback) { + msg_queue->wdma_rptr_addr = 0; + msg_queue->wdma_wptr_addr = 0; + } else { + msg_queue->wdma_rptr_addr = msg_queue->wdma_addr.dma_addr; + msg_queue->wdma_wptr_addr = msg_queue->wdma_addr.dma_addr; + } msg_queue->empty_lat_buf.ctx = ctx; msg_queue->empty_lat_buf.core_decode = NULL; From patchwork Wed Dec 6 08:15:35 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: 174425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957747vqy; Wed, 6 Dec 2023 00:17:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfWzqK1Mt62EuRTx0I/DhVUNaUsjM5aWXFRDMPNiUW3z9WuAlqoI7X9PHMAlEpmCuu/OjV X-Received: by 2002:a17:902:d487:b0:1d0:6b95:9c09 with SMTP id c7-20020a170902d48700b001d06b959c09mr223915plg.10.1701850674535; Wed, 06 Dec 2023 00:17:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850674; cv=none; d=google.com; s=arc-20160816; b=di9znz6vBInianGOkfYe7OGkwv2wMhiWCUHj+C5VOgekfWSdTmuYOolpOaw8YhTmZJ nfqqIeDbtuMLngBEGYGIp13wFF1dAfIhXz/l6TkZkcxh7quQazf+Aq/s2L33Csu4Rsb4 zMbi9R5RFcW5lGyOm75WC8OKIn5Q0aQ/LMHm6hRmUzJSqPf0h49M3yzOPVZembkKWYay eTYgxAEPZNOepXWglRrLNdKuRUT00EkNatx1fEekZcflVnH94u6KhpD6eGh7xwYmz7Uv T3frUz7ZQXnoIlq9y9rDi7aTorQZ0Aixa67avCae667v3GGW8BtyKwcq4WTBQCTToM5q t1Sg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tDdbTuWdtMHx44dMsP7Vdfz0hNjFshKJXaC0iWiaF9M=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=sE+b6+/AIZlZ3bp6qa2SzMxKe9QH8n89e+gXPGfQ3N593LlHFFN0dr4AF72OLa1QGm K/A5vHa0aoCXDaAwLYso8KmljrDtJ//cKpxDYYdyTnryUPloX3SwzWhDP8grcBLIAey1 z8K5SG/f9HNELEUGpQE9HOUmdG0pn4wNWuLTi3wjxEndZ5XgrKxxRPED3AkDO+9HcgKS 3y7v/WPFunGC5sB4xRrW2kfSewHtGJidsY5DaLaq/eLb77YYieznFFlYVGqDCOYhzS/A 80abT5ne04MKVGiaFyCXouY06BX4Rkb4imnrU+PWgT6qqnVKxJ9zA+acq6tW3hZRT828 0grQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=tyj2qJQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l5-20020a170903120500b001cfbd3f38e0si11418678plh.359.2023.12.06.00.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:17:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=tyj2qJQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id A338C80BEF3B; Wed, 6 Dec 2023 00:17:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377213AbjLFIRY (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377310AbjLFIQq (ORCPT ); Wed, 6 Dec 2023 03:16:46 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B57FD1990; Wed, 6 Dec 2023 00:16:15 -0800 (PST) X-UUID: b4e4b522940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=tDdbTuWdtMHx44dMsP7Vdfz0hNjFshKJXaC0iWiaF9M=; b=tyj2qJQdi8MEareVbbF8tB1RL1cHU/t1DOrgY9onyug4AZw8cEIgn5mwoT/uxeY4llRmTwdnxbrQvTU0oM3fxRiJlknDv4xAurL3qOr8hTbTdi8jNebCPxc2W0Ec/XvZm9WZLOQQ3dy/hfpJwqRXk667ZxvNl4Dc4ILBFqFv+OU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:06d802e5-77fa-4ca3-b3d8-dee0f8a9cbd8,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:abefa75,CLOUDID:862d59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b4e4b522940f11ee8051498923ad61e6-20231206 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1021699209; Wed, 06 Dec 2023 16:16:07 +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; Wed, 6 Dec 2023 16:16:03 +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:16:02 +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,18/21] media: medkatek: vcodec: remove parse nal_info in kernel Date: Wed, 6 Dec 2023 16:15:35 +0800 Message-ID: <20231206081538.17056-19-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--3.507800-8.000000 X-TMASE-MatchedRID: Gu65HUftg+NNlZ1zEcyAYwPZZctd3P4B7f6JAS2hKPjANHjiWWI+7XVX 4shSYpPIKuucQMr5Le3XJhQ9fMGheSV6fVT+kLJ6UiOWIqwRnLOcgz9a61Hb4bj4Vle8ifDUo8W MkQWv6iUoTQl7wNH8PuTCMddcL/gjymsk/wUE4hqhz7yVilwuBQOAJexy8+Wp/nZOtPmUF/1ovg 09TtYtBSp22WX6RI5lGNQKzv3BgiUTc8wc7CUnBzkrv3sDJUzElJhz6PZ4B/2lp9Vz/lePmPNho 9kAt8htLJl1Svx/Hh8xu7K+8aG0gLDxBQ/q2QPNQwymtxuJ6y0= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--3.507800-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 3DC9A3FF2E1A4E342371F41195989FBF334E4B7A26F69BBACF6DD6DB3EEFCECA2000:8 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:17:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519772949681925 X-GMAIL-MSGID: 1784519772949681925 The hardware can parse syntax to get nal_info, needn't to use cpu. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/vdec/vdec_h264_req_multi_if.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index a1a68487131c..2dfb3043493e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -645,11 +645,10 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_h264_slice_inst *inst = h_vdec; struct vdec_vpu_inst *vpu = &inst->vpu; struct mtk_video_dec_buf *src_buf_info; - int nal_start_idx, err, timeout = 0; + int err, timeout = 0; unsigned int data[2]; struct vdec_lat_buf *lat_buf; struct vdec_h264_slice_share_info *share_info; - unsigned char *buf; if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx, vdec_h264_slice_core_decode, @@ -673,14 +672,6 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, share_info = lat_buf->private_data; src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer); - buf = (unsigned char *)bs->va; - nal_start_idx = mtk_vdec_h264_find_start_code(buf, bs->size); - if (nal_start_idx < 0) { - err = -EINVAL; - goto err_free_fb_out; - } - - inst->vsi->dec.nal_info = buf[nal_start_idx]; lat_buf->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, true); @@ -689,7 +680,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, goto err_free_fb_out; if (!inst->ctx->is_secure_playback) - vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size, + vdec_h264_insert_startcode(inst->ctx->dev, bs->va, &bs->size, &share_info->h264_slice_params.pps); *res_chg = inst->resolution_changed; From patchwork Wed Dec 6 08:15:36 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: 174427 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957897vqy; Wed, 6 Dec 2023 00:18:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj4AequPNfsB2f+5NO1a1BOPsI8ATBNZfPgc1RAIdTF4UpONp6eXxNspfbf+YwFbg+DJn7 X-Received: by 2002:a05:6a00:21cb:b0:68f:b015:ea99 with SMTP id t11-20020a056a0021cb00b0068fb015ea99mr736001pfj.10.1701850696311; Wed, 06 Dec 2023 00:18:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850696; cv=none; d=google.com; s=arc-20160816; b=rFnAndkMl+7ckBk9KfuafXmeB140gNF49jUrx1YZZWJsl2kSpJbVb1gv+vX31UvIT/ X0XeVHjRxgbjG86ZPJyQxqa4+45dVnVBNiJwlN/I7vkriQqbfNrM1bpIdfKVD0Zy1ViA PTHf9I8stC9f7b4/i3/qkMVLbxmy84uBVslor9FytgpC5GSuJD9mfJpgYNPBsfucWE7+ EhzfqTrG43J3mUIObiseeH6micOhKC7RY/6X0KExAKKGWTZ3a4BjtEHOOaEKsUWlsESc AzYsi4PmdDYJ9J+/4nDsa6r1Fvi/rKdasoN1KNeH8cUedj/vNm2kBSQ97anb8fOMnU8J ebLA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oUOfVeRKnJ1zcg5WgLZGiIN5J1sZ37QJ5q0Qif+5X/Q=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=ZLH/9u6+ooHJHs6BjAVdcJ32FMec1gECuJJjXfEDF+PHWGzy2xarMybcUfkm3BlHH+ rrJXDFOD4hNpuCavWHe4iGVM46HXQrvel8OArSDo8mtonHpZlglTIHyO3rK7oh93IhPr kleSv6Ql7Y3NlJwqwLcriLjhZiyZsU+BjaRjMEH8gaxn6Jr9o5DC9wB4uu20Qqby3NYP ptj+hl2vmNdi8viXTWKpmWbUJKWFxAB4xbP4oy1lRQLxM/SO5graM/XfcUZp1utH9JM7 Zfan4bnk3aqVN2M4bL8raEbi9uHaP/q9+GuNmz5Wzd5LAQJPbfQJiKWWknRGfUqV5lqQ B54w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=ckww2BIz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id y6-20020a63fa06000000b005be0fa4ea26si6509368pgh.603.2023.12.06.00.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:18:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=ckww2BIz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 8D71380BA66E; Wed, 6 Dec 2023 00:18:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377363AbjLFIR2 (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377225AbjLFIQs (ORCPT ); Wed, 6 Dec 2023 03:16:48 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF8E19AB; Wed, 6 Dec 2023 00:16:17 -0800 (PST) X-UUID: b44d2342940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=oUOfVeRKnJ1zcg5WgLZGiIN5J1sZ37QJ5q0Qif+5X/Q=; b=ckww2BIzOiTl0/6YD/tqTg+XjO+zyrhjgV8LfrTw6OBOn804q+gUeKudviy8hIvOCHZrgQcFm8sfkgeRbzsP+kY2z8rCjQ99CBFI4vLIXowJGjXXeJ+sCOKFhcnoINhPMSShI6RT7Iqae/o0BImftKaBubraH9iIX1/12wJ5eAE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:b9359682-2a90-4534-b2d4-f493192a0ea2,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:137ae060-c89d-4129-91cb-8ebfae4653fc,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b44d2342940f11ee8051498923ad61e6-20231206 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1359399713; Wed, 06 Dec 2023 16:16:06 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n2.mediatek.inc (172.21.101.108) 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:16:05 +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:16:03 +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,19/21] media: medkatek: vcodec: disable wait interrupt for svp mode Date: Wed, 6 Dec 2023 16:15:36 +0800 Message-ID: <20231206081538.17056-20-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:18:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519796046732270 X-GMAIL-MSGID: 1784519796046732270 Waiting interrupt in optee-os for svp mode, need to disable it in kernel in case of interrupt is cleaned. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_hw.c | 34 +++++------ .../vcodec/decoder/mtk_vcodec_dec_pm.c | 6 +- .../decoder/vdec/vdec_h264_req_multi_if.c | 57 +++++++++++-------- 3 files changed, 54 insertions(+), 43 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c index 881d5de41e05..1982c088c6da 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c @@ -72,26 +72,28 @@ static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void *priv) ctx = mtk_vcodec_get_curr_ctx(dev->main_dev, dev->hw_idx); - /* check if HW active or not */ - cg_status = readl(dev->reg_base[VDEC_HW_SYS] + VDEC_HW_ACTIVE_ADDR); - if (cg_status & VDEC_HW_ACTIVE_MASK) { - mtk_v4l2_vdec_err(ctx, "vdec active is not 0x0 (0x%08x)", cg_status); - return IRQ_HANDLED; - } + if (!ctx->is_secure_playback) { + /* check if HW active or not */ + cg_status = readl(dev->reg_base[VDEC_HW_SYS] + VDEC_HW_ACTIVE_ADDR); + if (cg_status & VDEC_HW_ACTIVE_MASK) { + mtk_v4l2_vdec_err(ctx, "vdec active is not 0x0 (0x%08x)", cg_status); + return IRQ_HANDLED; + } - dec_done_status = readl(vdec_misc_addr); - if ((dec_done_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) != - MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) - return IRQ_HANDLED; + dec_done_status = readl(vdec_misc_addr); + if ((dec_done_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) != + MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) + return IRQ_HANDLED; - /* clear interrupt */ - writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr); - writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr); + /* clear interrupt */ + writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr); + writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr); - wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx); + wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx); - mtk_v4l2_vdec_dbg(3, ctx, "wake up ctx %d, dec_done_status=%x", - ctx->id, dec_done_status); + mtk_v4l2_vdec_dbg(3, ctx, "wake up ctx %d, dec_done_status=%x", + ctx->id, dec_done_status); + } return IRQ_HANDLED; } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c index aefd3e9e3061..a94eda936f16 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c @@ -238,7 +238,8 @@ void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx) mtk_vcodec_dec_child_dev_on(ctx->dev, MTK_VDEC_LAT0); mtk_vcodec_dec_child_dev_on(ctx->dev, hw_idx); - mtk_vcodec_dec_enable_irq(ctx->dev, hw_idx); + if (!ctx->is_secure_playback) + mtk_vcodec_dec_enable_irq(ctx->dev, hw_idx); if (IS_VDEC_INNER_RACING(ctx->dev->dec_capability)) mtk_vcodec_load_racing_info(ctx); @@ -250,7 +251,8 @@ void mtk_vcodec_dec_disable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx) if (IS_VDEC_INNER_RACING(ctx->dev->dec_capability)) mtk_vcodec_record_racing_info(ctx); - mtk_vcodec_dec_disable_irq(ctx->dev, hw_idx); + if (!ctx->is_secure_playback) + mtk_vcodec_dec_disable_irq(ctx->dev, hw_idx); mtk_vcodec_dec_child_dev_off(ctx->dev, hw_idx); if (IS_VDEC_LAT_ARCH(ctx->dev->vdec_pdata->hw_arch) && diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 2dfb3043493e..3e2270399b6c 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -593,14 +593,16 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) goto vdec_dec_end; } - /* wait decoder done interrupt */ - timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); - if (timeout) - mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt); - inst->vsi_core->dec.timeout = !!timeout; - - vpu_dec_core_end(vpu); + if (!ctx->is_secure_playback) { + /* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); + if (timeout) + mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt); + inst->vsi_core->dec.timeout = !!timeout; + + vpu_dec_core_end(vpu); + } mtk_vdec_debug(ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", ctx->decoded_frame_cnt, inst->vsi_core->dec.crc[0], inst->vsi_core->dec.crc[1], @@ -724,14 +726,16 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf); } - /* wait decoder done interrupt */ - timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0); - if (timeout) - mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num); - inst->vsi->dec.timeout = !!timeout; + if (!inst->ctx->is_secure_playback) { + /* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0); + if (timeout) + mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num); + inst->vsi->dec.timeout = !!timeout; - err = vpu_dec_end(vpu); + err = vpu_dec_end(vpu); + } if (err == SLICE_HEADER_FULL || err == TRANS_BUFFER_FULL) { if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf); @@ -831,16 +835,19 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs if (err) goto err_free_fb_out; - /* wait decoder done interrupt */ - err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); - if (err) - mtk_vdec_err(inst->ctx, "decode timeout: pic_%d", inst->ctx->decoded_frame_cnt); - - inst->vsi->dec.timeout = !!err; - err = vpu_dec_end(vpu); - if (err) - goto err_free_fb_out; + if (!inst->ctx->is_secure_playback) { + /* wait decoder done interrupt */ + err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); + if (err) + mtk_vdec_err(inst->ctx, "decode timeout: pic_%d", + inst->ctx->decoded_frame_cnt); + + inst->vsi->dec.timeout = !!err; + err = vpu_dec_end(vpu); + if (err) + goto err_free_fb_out; + } memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx)); mtk_vdec_debug(inst->ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", From patchwork Wed Dec 6 08:15:37 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: 174428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957904vqy; Wed, 6 Dec 2023 00:18:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsh39AucMTva1SwRiZYOZ0LEa31H6i+zEskm5yoYVtcUIBSr48i8JvllStumaC/V+3eg6i X-Received: by 2002:a17:903:187:b0:1cf:d2c5:ae87 with SMTP id z7-20020a170903018700b001cfd2c5ae87mr387276plg.11.1701850697141; Wed, 06 Dec 2023 00:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850697; cv=none; d=google.com; s=arc-20160816; b=Tadco5D8yRT0SqYRwb33rg2EKGh9IrJb+DOzwakfKR22Qpoya16/jd6/7/k5ydtw0f Fp1ly+sU1NvIZoEbVzQrMq0+CJdmx1j9uJHBgJHlCH+KK8i/hTGNcxPEBjDxyJtIyCU3 4f7M7JKQihb+5FxcwgRVqid1lPw8V/q788s+W+zUJx0lqjKAP2h12TGGtKAj7RQCXwqH GaKHm1IrYrsxwR/FP/57VnVnP6cBmdnxm3lyTZ4g+C9H1Mvf90Vhc+E3pSAbsoITwNfC jZblmnmYjYlQsU/+jLge+huL3jrpxGjcNsGe0yOxf31TeP4ywzPUAAOrhZHX1fQgQq4x eSrw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kC7KzWLgDHvbqhzMWnc/8P0WK0I0J12Fa3NbbNqI088=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=G8FukdDoAHEptDA6a05m9PDYnQTHMx1ZZfp+ml57xl23/9Z64GmlOPsZtLd3ElMGwJ sJf/6nWZsl8M7p41D3DZDcyUuxqjTkrS1Ta5AGl1E1Es7vxx6INIjEk2p2ovd7m1quRr L/Nk6KO29h+foofWUDs+cpfSAisuMQH740T0OtesaG+QwwLu8RSxGnvTlv/MWTR3rOz9 VwqkBKMn2xBeVoMIfSvZbcvx48txaz82wXPvkh5OmgZwOl1StwFJJiERCx2sMW5VIgic 05asCQ6D5AkMYndLQ+lGW2tQHI1WgluKYniWvHR7667jKkKAz6R72P4BHk/dg4ct3OiZ uBIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=DRgY0xCz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id l16-20020a170903245000b001d044978d7esi5130029pls.598.2023.12.06.00.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=DRgY0xCz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id C09D380BD525; Wed, 6 Dec 2023 00:18:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377361AbjLFIRZ (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377315AbjLFIQr (ORCPT ); Wed, 6 Dec 2023 03:16:47 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5576E199E; Wed, 6 Dec 2023 00:16:16 -0800 (PST) X-UUID: b4edff10940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=kC7KzWLgDHvbqhzMWnc/8P0WK0I0J12Fa3NbbNqI088=; b=DRgY0xCz2XKjDEUTrQLh5nBlVtY87KqKA/vZ1ToLL9WmUItuVnxQpasK9nM0ldv7Y/kkWe5z8ag7jL/1fjbHBBqG3P3bIhs3ng3zEoSWUoWC6qXg8HVJ9JFvqzplyKrOTg5L7QrdC6tBAnpXG4WiegqyYhI5kXm7S9pGqrZhUzc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:0b6040a7-3dbc-4ac0-bb21-ed69f2d0860c,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:abefa75,CLOUDID:bf863596-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b4edff10940f11ee8051498923ad61e6-20231206 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 991676486; Wed, 06 Dec 2023 16:16:07 +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; Wed, 6 Dec 2023 16:16:06 +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:16:05 +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,20/21] media: medkatek: vcodec: support tee decoder Date: Wed, 6 Dec 2023 16:15:37 +0800 Message-ID: <20231206081538.17056-21-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10-3.006200-8.000000 X-TMASE-MatchedRID: WVKpczY/zoTtAxjyNphE0new7fOv9rv4Kx5ICGp/WtF6unVYJJS8BvlY oV6p/cSxF8u8dQXnFzmAbmfpXu2gQmUlOh2o2oTOFYJUGv4DL3yt4laWdJbsDBL6MU7t349bW9o SzMAtdLLi8zVgXoAltsIJ+4gwXrEtwrbXMGDYqV+HuSUEBMGDjCgTieNKzl0v+c+7T33Au3DNuA ezS6+buStXMlZOFFSrjrE02BmFeIfvcrH62iIKGAXWfB7vcPOFv+VreHCTJr8xLORmmfnUyqMnT JRI0XInfXwUEm1ouDzLDYxFC1/7rjCBQDy1BJSc7ndUHUMmXu5+3BndfXUhXQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10-3.006200-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 2E252DE02EC8D4257050ACF60994A700FF1332821D343220C9073F792B30A9112000:8 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:18:09 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519796396534889 X-GMAIL-MSGID: 1784519796396534889 Initialize tee private data to support secure decoder. Release tee related information for each instance when decoder done. Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c index f47c98faf068..08e7d250487b 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c @@ -310,6 +310,9 @@ static int fops_vcodec_release(struct file *file) v4l2_fh_exit(&ctx->fh); v4l2_ctrl_handler_free(&ctx->ctrl_hdl); + if (ctx->is_secure_playback) + mtk_vcodec_dec_optee_release(dev->optee_private); + mtk_vcodec_dbgfs_remove(dev, ctx->id); list_del_init(&ctx->list); kfree(ctx); @@ -466,6 +469,11 @@ static int mtk_vcodec_probe(struct platform_device *pdev) atomic_set(&dev->dec_active_cnt, 0); memset(dev->vdec_racing_info, 0, sizeof(dev->vdec_racing_info)); mutex_init(&dev->dec_racing_info_mutex); + ret = mtk_vcodec_dec_optee_private_init(dev); + if (ret) { + dev_err(&pdev->dev, "Failed to init svp private."); + goto err_reg_cont; + } ret = video_register_device(vfd_dec, VFL_TYPE_VIDEO, -1); if (ret) { From patchwork Wed Dec 6 08:15:38 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: 174426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3957879vqy; Wed, 6 Dec 2023 00:18:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKfZBejrHRAGn3ytlJ+IR0MQBZs7E4RE5iftT4DpjodMiLQyAdypWJpQdNH5oN4IiuY1Y8 X-Received: by 2002:a92:c5aa:0:b0:35d:53e9:c15c with SMTP id r10-20020a92c5aa000000b0035d53e9c15cmr669847ilt.18.1701850693906; Wed, 06 Dec 2023 00:18:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850693; cv=none; d=google.com; s=arc-20160816; b=utkdB+TZXXBdKdSosfwaX5OwUbrCq/S6rAi6hoI52awaMBngxQTrJL3OPy5g0vXlcR XZjHtQM05q0rvYCcsL6N7or3whCH9MUBCVfWBAGg8Gf9MNwBJLkJZN0V2scFIbP2opig LvciZPrwUdFGE5zDuRZsi0TUsT0sPMXV2YJaYCKEILkkAsKsmkIDnwDODjZkcvmLjxVc VTXXECPtvzeGKS6AyU8MlGeOHyGSbXVvdDwfPPs/a6yJDk+R1NwXDolv9J7L1ZxyTpmr 1Rqb/0w/Wc4RHIWNm6fpLf4Id2RCISyzmCqF4b5yEJjIpbcOpzg8EZPyUACM7c8NQbYY Sddw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fkKb5yQu6eO4lpu8D+KYAkmtnU9wVZAoaiHbbjuUHtM=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=jBrCBZC1gMQDzBlLQzpL1A4k3Hf9ysX/tpaLpGIE9WBldqXXv0UBSFIubttnj9xrJk FmJYfruCqTcixVc+p/m2ZLdVSppiQKZzzrhYfT6E4A/UmxOGb9LGatRU5uzuv1GoeJGM kkBj0c89QyIya5Q4k2pYbXWGviJZGC6slIfCG4YIP/YforQtztavn/I7iEVps8hYvR7h E75iqa1oYUneF+qTyE59pRmoIkl7wvjOEFi4wUbsJtcmSt99lc/P/1s4Tm6ZITS/iU6m 50GA0zxoF2Eg3lI8bxZtK1Lst4KaaHf7C9V6R/uWn2/haP0ODEj4p28FL6uJ3vJG08qE i3Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=nLsq66PV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id i19-20020a63d453000000b0059beadab759si11229419pgj.652.2023.12.06.00.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:18:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=nLsq66PV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 DB641802F952; Wed, 6 Dec 2023 00:18:02 -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 S1377171AbjLFIRk (ORCPT + 99 others); Wed, 6 Dec 2023 03:17:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377339AbjLFIQv (ORCPT ); Wed, 6 Dec 2023 03:16:51 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F1719B6; Wed, 6 Dec 2023 00:16:18 -0800 (PST) X-UUID: b6228a86940f11ee8051498923ad61e6-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:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=fkKb5yQu6eO4lpu8D+KYAkmtnU9wVZAoaiHbbjuUHtM=; b=nLsq66PVRaWr2fSoiq+WhRgjwDW/rCwuZlwIs5JLYggoaTzVhLQwjADw2bVPm9YPggr8dyI7dkWziTzXUoLtKiH9f8xuDSyUrB7rFT67CJ3ejRTZE97QdI0HuLuSrHb/GynFDsCLDUDlKq6q6t0AJZk20kUFccye8rgpYnKM/X8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.34,REQID:31d90100-0b0f-4061-9618-e2e446142fba,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:abefa75,CLOUDID:b02d59fd-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b6228a86940f11ee8051498923ad61e6-20231206 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1117160729; Wed, 06 Dec 2023 16:16:09 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) 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:16:07 +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:16:06 +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,21/21] media: mediatek: vcodec: move vdec init interface to setup callback Date: Wed, 6 Dec 2023 16:15:38 +0800 Message-ID: <20231206081538.17056-22-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206081538.17056-1-yunfei.dong@mediatek.com> References: <20231206081538.17056-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--3.356300-8.000000 X-TMASE-MatchedRID: EDRXIQlfXt//ybP4IWJkikKcYi5Qw/RVFpw9gj8mywrfUZT83lbkENro EGQiudNyiYTHezvcK04K3OrJWcpBViwmW5mXIeVjzfqlpbtmcWi50iD18ixmy/gnJH5vm2+gZ2X jE62VgUUxZUOt0FF52sKXwA+sRKv1Gj8XjDB40G5Na4UOfkJSNH0tCKdnhB589yM15V5aWpj6C0 ePs7A07fhmFHnZFzVqMy6bDKK4NkHdcJT5YYQWyMMV4WK4hhsonPk1U1ip1fFxAqP9WRFBCYAqt ckHv8VFsP9RRQG7ErZPWfegSDaC08hohL0hluIT8jae4OD13tAV7Mc+rowcVKtX/F0pBwVJjSV5 hDFby7ZnIxZyJs78kg== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--3.356300-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 3A487E5DD73C21F27353616BBD3FB3362469D0F8B1A852A975DAB46E5A1DDCBF2000:8 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:18:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784519793141494332 X-GMAIL-MSGID: 1784519793141494332 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 | 144 ++++++++++++------ 1 file changed, 94 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 ab922e8d2d37..3639beac20cb 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,74 @@ 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); + } + + 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 { + if (ctx->is_secure_playback) + ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = + ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + 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, q_data->fmt->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]); + return 0; +} + static int vidioc_vdec_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) { @@ -479,17 +547,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 +560,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 +745,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 +754,25 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, return -EINVAL; } + if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + 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 (vq->secure_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->secure_mem; + mtk_v4l2_vdec_dbg(1, ctx, "Getting secure decoder mode:%d", + ctx->is_secure_playback); + } + } + if (*nplanes) { if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { if (*nplanes != q_data->fmt->num_planes) @@ -980,6 +1022,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_secure_mem = 1; ret = vb2_queue_init(src_vq); if (ret) { @@ -996,6 +1039,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_secure_mem = 1; ret = vb2_queue_init(dst_vq); if (ret)