From patchwork Mon Nov 6 12:04:03 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: 741679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A1A5C4332F for ; Mon, 6 Nov 2023 12:04:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbjKFMEi (ORCPT ); Mon, 6 Nov 2023 07:04:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjKFMEh (ORCPT ); Mon, 6 Nov 2023 07:04:37 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39950DB; Mon, 6 Nov 2023 04:04:32 -0800 (PST) X-UUID: a2ecaa9e7c9c11ee8051498923ad61e6-20231106 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=xaXSYYp/R/Yb59Wdv7tahHP4Ng033IFyHb7NA8pgCLk=; b=WaoOShaHmylv9HtgnJK2dNAjzZtYqMfQjiwIhDO9jumxvmvjD6jTfY2Ij9Z0S1BeYTk8Abw/KoLFacsJZPIDdvKiwo1/1sNKRIpy/mspQ8hQ5RbSnTgnnQq8CrEUT7XlAvfvdp6q5IQsgpQOe2qo/wzOrhsfNUyaAqPS5CAwyoY=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:7c558346-52ca-4f99-8584-01740e761014, 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:364b77b, CLOUDID:d3475472-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: a2ecaa9e7c9c11ee8051498923ad61e6-20231106 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 1694378906; Mon, 06 Nov 2023 20:04:28 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 6 Nov 2023 20:04:26 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:25 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , "Steve Cho" , Yunfei Dong , , , , , , Subject: [PATCH v2,01/21] v4l2: add secure memory flags Date: Mon, 6 Nov 2023 20:04:03 +0800 Message-ID: <20231106120423.23364-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-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.729000-8.000000 X-TMASE-MatchedRID: 1EkN8wfBE2kXSulpnju2H4SvKOGqLLPKK2i9pofGVStcU0dNErOD+mlF 7OhYLlctcYKRVYWgduVAw/iJrysrSm+IsUfG75P2joyKzEmtrEeQoBr+SFneJJj9R7obtcgyH5L 2GhBQtff4ei4a6fEfjpynPbWEKM6u8xjBEybW2by3HA8h5a0MOXnL427v8Q461gisw2JKo8k86a y9NNiI8eLzNWBegCW2wgn7iDBesS0nRE+fI6etksezPriNOMMa5evK5QqVTFyJjYpg0md7nwGuY jlJhX2RTAsYtPFcm2AFxhhkRSbhgvVEcnBy2ijPFj2h5F4GY+ndddgV66Y3YYSVUZZHNLr+RgV6 Hsqyx11QaONuZ6Jr4g9k3l8EaYIcDiKmdrlEg1g= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--3.729000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 9864FE8686BDE13139414B2CB77751A0FE1C12DDB68367C23E2FAB1D8E76EF7F2000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 4b6a9d2ea372..f6333d8fa617 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 @@ -598,6 +601,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; @@ -766,7 +771,8 @@ void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, 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 c3d4e490ce7c..4bf8d392d5a5 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) @@ -1035,6 +1036,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4) #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_SECURE_MEM (1 << 7) /** * struct v4l2_plane - plane info for multi-planar buffers From patchwork Mon Nov 6 12:04:04 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: 741677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61782C4167D for ; Mon, 6 Nov 2023 12:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbjKFMEo (ORCPT ); Mon, 6 Nov 2023 07:04:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231552AbjKFMEi (ORCPT ); Mon, 6 Nov 2023 07:04:38 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 038F5FA; Mon, 6 Nov 2023 04:04:34 -0800 (PST) X-UUID: a32277287c9c11eea33bb35ae8d461a2-20231106 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=H1hzDIVX/uYFlZAzRgT3yZuD5V71PO6DoLhIHHVMUSc=; b=ijohy3niSJqp0SCjVCC2M92MXFrSltXjf/HllXvAxHRT849cCnMT59bcE4+U6Kn2jqXZLwPXUfq4zDB7rahxmGjRGqqqbC9tnpQZqTnzyrk3trbSS+HDt0Vnhq07zaFAaEkGzK0BP5oC+v5gOMwtJC0OxRF9FpdfsbuMzFXJvOg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:3b9cefca-cf2f-4757-aae4-b6d1afb0e7c8, 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:364b77b, CLOUDID:87b7bc5f-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: a32277287c9c11eea33bb35ae8d461a2-20231106 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 313314417; Mon, 06 Nov 2023 20:04:28 +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; Mon, 6 Nov 2023 20:04:27 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:26 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2,02/21] v4l2: handle secure memory flags in queue setup Date: Mon, 6 Nov 2023 20:04:04 +0800 Message-ID: <20231106120423.23364-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 | 25 ++++++++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 33 ++++++++++++------- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 27aee92f3eea..7ee68f5533ba 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -744,12 +744,22 @@ 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) { unsigned int num_buffers, allocated_buffers, num_planes = 0; 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; @@ -766,6 +776,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (*count == 0 || q->num_buffers != 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. @@ -784,6 +796,14 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, __vb2_queue_free(q, q->num_buffers); 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. @@ -807,6 +827,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, q->memory = memory; mutex_unlock(&q->mmap_lock); set_queue_coherency(q, non_coherent_mem); + q->secure_mem = secure_mem; /* * Ask the driver how many buffers and planes per buffer it requires. @@ -910,6 +931,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int num_planes = 0, num_buffers, allocated_buffers; unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; + bool secure_mem = flags & V4L2_MEMORY_FLAG_SECURE; bool no_previous_buffers = !q->num_buffers; int ret; @@ -933,6 +955,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, mutex_unlock(&q->mmap_lock); 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"); @@ -940,6 +963,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, VB2_MAX_FRAME - q->num_buffers); diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index c7a54d82a55e..966ce74e26b3 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -685,26 +685,33 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) *caps |= V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF; if (q->allow_cache_hints && q->io_modes & VB2_MMAP) *caps |= V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS; + if (q->allow_secure_mem && q->io_modes & VB2_DMABUF) + *caps |= V4L2_BUF_CAP_SUPPORTS_SECURE_MEM; #ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; #endif } -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) @@ -713,7 +720,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); @@ -748,7 +756,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 = q->num_buffers; if (create->count == 0) return ret != -EBUSY ? ret : 0; @@ -986,7 +995,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; @@ -1010,7 +1020,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 Mon Nov 6 12:04:05 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: 741678 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A840C41535 for ; Mon, 6 Nov 2023 12:04:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231566AbjKFMEk (ORCPT ); Mon, 6 Nov 2023 07:04:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjKFMEh (ORCPT ); Mon, 6 Nov 2023 07:04:37 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 110A9F3; Mon, 6 Nov 2023 04:04:33 -0800 (PST) X-UUID: a329aa3e7c9c11eea33bb35ae8d461a2-20231106 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=SJGeA12WiLnNkJjDM4Bu4l4+AsmnaXmsLaJAMHHfmeP68M47E0O0b86Blf95P30SEe6upgdGYnOy9CSbI8KhSreSkj0W+cIW3RigA1RzpCOR55aa0PlkU6SvZfDhFupaVtIpLMKFa+BndO9Qs3Bmkm3EoHQXpBCCoj2ZsAJDeVk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:44ed1aec-4500-4434-85bf-d85a14359533, 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:364b77b, CLOUDID:d8475472-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: a329aa3e7c9c11eea33bb35ae8d461a2-20231106 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 922411925; Mon, 06 Nov 2023 20:04:28 +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; Mon, 6 Nov 2023 20:04:28 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:27 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2, 03/21] v4l2: verify secure dmabufs are used in secure queue Date: Mon, 6 Nov 2023 20:04:05 +0800 Message-ID: <20231106120423.23364-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Mon Nov 6 12:04:09 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: 741676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1DC8C4708E for ; Mon, 6 Nov 2023 12:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231645AbjKFMEu (ORCPT ); Mon, 6 Nov 2023 07:04:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231596AbjKFMEo (ORCPT ); Mon, 6 Nov 2023 07:04:44 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D425C107; Mon, 6 Nov 2023 04:04:40 -0800 (PST) X-UUID: a6cdab907c9c11ee8051498923ad61e6-20231106 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=bRR6vUTuGihRNoN3bg0kjV/Qse27I1T4xVT7HHW00VGd/BWboOighxyMRdobqHyM5Pt8mXzbXkimu3OGYQ+g1iZZGidljDbwBtRrIZY+i7gBPk6R2ReNB7REJkYzCFmqNlimhg/CqYHDraOhPvQYMSbJjHSQZLIYYuvo5bqUd/U=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:bb9d6c07-b458-459d-8f06-f43d3971ac51, 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:364b77b, CLOUDID:f62035fc-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: a6cdab907c9c11ee8051498923ad61e6-20231106 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 1383963647; Mon, 06 Nov 2023 20:04:35 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N2.mediatek.inc (172.21.101.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 6 Nov 2023 20:04:33 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:32 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , "Steve Cho" , Yunfei Dong , , , , , , Subject: [PATCH v2,07/21] dma-heap: Provide accessors so that in-kernel drivers can allocate dmabufs from specific heaps Date: Mon, 6 Nov 2023 20:04:09 +0800 Message-ID: <20231106120423.23364-8-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-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: 173cC0PKvpvtt0HEL3BUV4lD2T5imTkJ2qBSQHAh8pg0QmmUihPzrFJS 0b8z/9TB8AyWk2NFMNbijpjet3oGSJCoy9iDotiwNNHZMWDTEbe4UO5+xwKkcStjI02a+7m1J7o vlkPXpS3VaZR68ynk9lCRaYaDm6fHBCaQyxlaPkG3D7EeeyZCMzGZtPrBBPZrEvoxTu3fj1tEe5 BdjBKTALjfysYMcGyRGce8edCRlYkmcsJib2IjaaOuVibdZNTv7yWPaQc4INQOkJQR4QWbsG+3c txX3zZNo2jEjZ+uot1HVle6mAl0da+/EguYor8cFEUknJ/kEl7dB/CxWTRRu4as+d5/8j56CqkU I6VLHbp1IjXaXB8Mtq8az9DCJcKSIUrN7T23diALxcqOxVsmNQ== 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: 6C58B4693251C7073F5DB3015C87B19E715D3ED85626D74341004547E9F02B962000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Mon Nov 6 12:04:10 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: 741673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97356C4167B for ; Mon, 6 Nov 2023 12:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231655AbjKFMFC (ORCPT ); Mon, 6 Nov 2023 07:05:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbjKFMEw (ORCPT ); Mon, 6 Nov 2023 07:04:52 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0322CDF; Mon, 6 Nov 2023 04:04:43 -0800 (PST) X-UUID: a84779427c9c11eea33bb35ae8d461a2-20231106 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=KxIbGqFlysglH5kHHcHmU7i2GT2Cu+bAx81hk7mcBxg=; b=gTGGL61CLCLtz/TdeQDF8frczo4N658B3fkczZE96cQQQA/PrkBLN0uSNn0+bBR6l8mxARTFXPGsCdHZpTyZr2rjZhxqLigPjP592UhTviSf7ePGzE1zseX0nwHZQQMTXHlBoMJshkweus0LbJAiS93F1x8hWNExIb4UKMd3f2M=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:98d3e511-7d08-4228-a910-e0237d4d8d35, 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:364b77b, CLOUDID:dbb7bc5f-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: a84779427c9c11eea33bb35ae8d461a2-20231106 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 545090691; Mon, 06 Nov 2023 20:04:37 +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; Mon, 6 Nov 2023 20:04:34 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:33 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2, 08/21] media: mediatek: vcodec: add tee client interface to communiate with optee-os Date: Mon, 6 Nov 2023 20:04:10 +0800 Message-ID: <20231106120423.23364-9-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 7e36b2c69b7d..7a320d1e37e8 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" @@ -249,6 +250,8 @@ struct mtk_vcodec_dec_ctx { * @vdec_racing_info: record register value * @dec_racing_info_mutex: mutex lock used for inner racing mode * @dbgfs: debug log related information + * + * @optee_private: optee private data */ struct mtk_vcodec_dec_dev { struct v4l2_device v4l2_dev; @@ -289,6 +292,8 @@ struct mtk_vcodec_dec_dev { /* Protects access to vdec_racing_info data */ struct mutex dec_racing_info_mutex; struct mtk_vcodec_dbgfs dbgfs; + + 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 Mon Nov 6 12:04:11 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: 741674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 254BBC4167D for ; Mon, 6 Nov 2023 12:04:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbjKFME5 (ORCPT ); Mon, 6 Nov 2023 07:04:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbjKFMEp (ORCPT ); Mon, 6 Nov 2023 07:04:45 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C8010B; Mon, 6 Nov 2023 04:04:41 -0800 (PST) X-UUID: a80d41d27c9c11ee8051498923ad61e6-20231106 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=mhz2jhSVYJPJqfKv/riWDXJn5M0lOpTzY0/kvYfJrGBz0A1m3OI0RbnbB7AreLPI9GvHOph1+SusGZLS2gdBAS2zaL76KsX/pPxfnKTGrrWyeCShncxTVGW21KoQEwYwefz/PpU1yX8teBi1GfvbLoGh8C/F9hOMpj3/hE/jgLY=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:e81ac08f-ac29-4f0f-93f4-6b2301278d79, 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:364b77b, CLOUDID:c9b7bc5f-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: a80d41d27c9c11ee8051498923ad61e6-20231106 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 1226637884; Mon, 06 Nov 2023 20:04:37 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 6 Nov 2023 20:04:35 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:34 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , "Steve Cho" , Yunfei Dong , , , , , , Subject: [PATCH v2,09/21] media: mediatek: vcodec: allocate tee share memory Date: Mon, 6 Nov 2023 20:04:11 +0800 Message-ID: <20231106120423.23364-10-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-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: TTrQ0Rwak8xA5/DRRISQHAPZZctd3P4BK2i9pofGVSuYBF1C0J2QPotf Mtu9FfbrPcGjGTU7TndXUz+XcOBhEYYCBZzro74fDB+ErBr0bAO2McZY43zJ423D6f6IpbLIyo3 1HV/erwydBDUJwKypkLvrVFvaS3pv9A9EfhuU0xx1e7Xbb6Im2pRy1HDTPOXaW+jwVKpqvlI9yB u1TZGrQeLzNWBegCW2wgn7iDBesS15zdAzex5xZqre0w1snPFv0u8FMYg9F/E8Ov8beXpQc96Iy B3d7It8jwYmA8M2eveUTGVAhB5EbQ== 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: DA5CAEAD549328FCD0BB70966155E99437B7B0F85D269E83EBD1E13CEA6066AE2000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Mon Nov 6 12:04:12 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: 741675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 224B9C41535 for ; Mon, 6 Nov 2023 12:04:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbjKFMEx (ORCPT ); Mon, 6 Nov 2023 07:04:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjKFMEq (ORCPT ); Mon, 6 Nov 2023 07:04:46 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A59A112; Mon, 6 Nov 2023 04:04:41 -0800 (PST) X-UUID: a89f50e07c9c11eea33bb35ae8d461a2-20231106 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=vEN7OWmt6l1aEw/GDs0vtLXkYJKlNhli3KPnbjVOW5wiWiNtokgbOkRXlKhorZXeUdnBSeuE7biJVWK0P8TBk0rapDttjLTtuDvvUdR418qbGRPykj9mX55jz7ifeysc1C2X1So8U/uP5u0aYcNtC5r08jHaEBBEWV44XCRaEnM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:2f5a47f1-8990-4390-a785-b7220995f726, 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:364b77b, CLOUDID:062135fc-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: a89f50e07c9c11eea33bb35ae8d461a2-20231106 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 494470811; Mon, 06 Nov 2023 20:04:38 +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; Mon, 6 Nov 2023 20:04:36 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 6 Nov 2023 20:04:35 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , "Steve Cho" , Yunfei Dong , , , , , , Subject: [PATCH v2,10/21] media: mediatek: vcodec: send share memory data to optee Date: Mon, 6 Nov 2023 20:04:12 +0800 Message-ID: <20231106120423.23364-11-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-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.706700-8.000000 X-TMASE-MatchedRID: AyztauQSwYCQG6Uyrf0PKFVN8laWo90MTJDl9FKHbrk1LB46LFAAkotf Mtu9FfbrPcGjGTU7TnemGallF1XuaEDn8NFEhJAcFYJUGv4DL3yH7D1bP/FcOhL6MU7t349b3vY rsfFYjWsgY9Nu1Ql6APqPSFsdX1B029aHfVG01jzJ1E39jKDimGaq8BZOZSelzrexXSWzstSgzz s1FNpEXGOFciOhsJ4zgDLqnrRlXrZ8nn9tnqel2DsAVzN+Ov/sUxeZzrp4VFNLDXTQO5fDMw8XB qf0pq8h28s3Rxggvn20AWWhtDiZ1w== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--11.706700-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: B226EEAB293C5859ED1CEB3687AA787DD40EC414615EA2E82061F2D8813798A82000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Mon Nov 6 12:04:16 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: 741672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F291CC4167D for ; Mon, 6 Nov 2023 12:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231638AbjKFMF1 (ORCPT ); Mon, 6 Nov 2023 07:05:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231552AbjKFME7 (ORCPT ); Mon, 6 Nov 2023 07:04:59 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81224D6F; Mon, 6 Nov 2023 04:04:48 -0800 (PST) X-UUID: ab476aee7c9c11ee8051498923ad61e6-20231106 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=TFBQNbpnU5wKtmzWlaei4zeDRLOjYlHcsyr9f1Sc+z4=; b=Ux5lh24PhwXLyv2YP2qORYrGp9/TLHzYHYYVNIUGyYmySDVO6fAVPPTTxQmtG/t04alTFzbfolxFJbm36irquMUDCiV+7pNzrQb7EhJ7gVRq6l3gH9NJumkXabJVGoJ0hbPFsYiDLaM6+JnRUPFjfqp8xs3UBW2GUuXEdalLQ8s=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:942dc67e-4297-4beb-9a5c-de28f57732a9, 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:364b77b, CLOUDID:482135fc-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: ab476aee7c9c11ee8051498923ad61e6-20231106 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 544970752; Mon, 06 Nov 2023 20:04:42 +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; Mon, 6 Nov 2023 20:04: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; Mon, 6 Nov 2023 20:04:40 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2,14/21] media: mediatek: vcodec: Add capture format to support one plane memory Date: Mon, 6 Nov 2023 20:04:16 +0800 Message-ID: <20231106120423.23364-15-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 3a4b15a98e02..8213e5c290e7 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -266,6 +266,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 9b1de54ce379..1adfec19b876 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 4bf8d392d5a5..48cfd6f6776a 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 Mon Nov 6 12:04:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WXVuZmVpIERvbmcgKOiRo+S6kemjnik=?= X-Patchwork-Id: 741670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0CAFC4167D for ; Mon, 6 Nov 2023 12:05:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbjKFMFo (ORCPT ); Mon, 6 Nov 2023 07:05:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231684AbjKFMFG (ORCPT ); Mon, 6 Nov 2023 07:05:06 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208F7DB; Mon, 6 Nov 2023 04:04:50 -0800 (PST) X-UUID: abf0956a7c9c11ee8051498923ad61e6-20231106 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=11cm6mkMOeKy8KRZ5/JdXgNCQ+O8tHBs6aQAfH5nRTE=; b=shIXUA817u7X6lvlb0A5I4mF/bzpZ+sy3T3nJwzLPuwOn7b75OELuZyT4OOpD5sFO2dYTlzlMH8A/WD32OhYwpSLQ7NJ/rLeY2KacHxl21ZSiTbvrR1028SIaJX+/+Rhl2zp/HJKwJ15Bip7krUK7i73f2y95Eh8ZQjoTi0WY3I=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:74a8e5b3-4402-454b-8fbb-fbaf5e9d7de1, 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:364b77b, CLOUDID:82485472-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: abf0956a7c9c11ee8051498923ad61e6-20231106 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 203291914; Mon, 06 Nov 2023 20:04:43 +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; Mon, 6 Nov 2023 20:04: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; Mon, 6 Nov 2023 20:04:41 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2,15/21] media: mediatek: vcodec: Add one plane format Date: Mon, 6 Nov 2023 20:04:17 +0800 Message-ID: <20231106120423.23364-16-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 91ed576d6821..1c6ecaa0c874 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 e29c9c58f3da..0f9cd5abd025 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 @@ -200,7 +200,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; @@ -604,6 +604,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; @@ -632,6 +637,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 Mon Nov 6 12:04: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: 741671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07614C4332F for ; Mon, 6 Nov 2023 12:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231792AbjKFMFk (ORCPT ); Mon, 6 Nov 2023 07:05:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjKFMFG (ORCPT ); Mon, 6 Nov 2023 07:05:06 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56515D6B; Mon, 6 Nov 2023 04:04:52 -0800 (PST) X-UUID: adc62d147c9c11eea33bb35ae8d461a2-20231106 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=LJ+HYexBqfopbIwUBMNf+w5+bPwWSJMO8HVnVXCT+y1Fc2V8eoAtF/hDev3DTCaQO+YhxfIVjzRp5Ne8frww5Hd1fzHd6dhvthy7Q+QqTaCGVdskj2GRPofFdysSWBTCcF7izjyr5Go0Ztsd73cl5NEeXKWQOsu2gTTlu8JrqqU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:06711c2b-587b-4e8f-bdde-c2885bc9fb98, 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:364b77b, CLOUDID:8e485472-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: adc62d147c9c11eea33bb35ae8d461a2-20231106 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 646622998; Mon, 06 Nov 2023 20:04:46 +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; Mon, 6 Nov 2023 20:04: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; Mon, 6 Nov 2023 20:04:44 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2,18/21] media: medkatek: vcodec: remove parse nal_info in kernel Date: Mon, 6 Nov 2023 20:04:20 +0800 Message-ID: <20231106120423.23364-19-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Mon Nov 6 12:04: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: 741669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5196FC41535 for ; Mon, 6 Nov 2023 12:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbjKFMGC (ORCPT ); Mon, 6 Nov 2023 07:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231802AbjKFMFZ (ORCPT ); Mon, 6 Nov 2023 07:05:25 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A3410EF; Mon, 6 Nov 2023 04:04:53 -0800 (PST) X-UUID: aeabf7187c9c11ee8051498923ad61e6-20231106 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=vk/aLiaXZ0o3UQ6PiFFLCT/a4mk5UwMANXijj0JOuQo=; b=ZGRTltl81GIaxZh/H+cSjVinZ0aYpxDsypLyRPi/AhduWsYZScwbYQdPS50sh5p/gqFJVBA5rscieHXIu5uSEZwTcF/mzwXjMyemioH1oRlzVnHPGV3Sct2z4VJTi+jMCnNgkNhqTGVB+uFeVYJRLoibqulgI9DRQOY/AokAu7Q=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33, REQID:59e8fc2b-86b0-4dd1-863d-fb5d86b28509, 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:364b77b, CLOUDID:ae485472-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: aeabf7187c9c11ee8051498923ad61e6-20231106 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 1192884147; Mon, 06 Nov 2023 20:04:48 +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; Mon, 6 Nov 2023 20:04: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; Mon, 6 Nov 2023 20:04:45 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , "T . J . Mercier" , John Stultz , Yong Wu , =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Pr?= =?utf-8?q?ado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v2, 19/21] media: medkatek: vcodec: disable wait interrupt for svp mode Date: Mon, 6 Nov 2023 20:04:21 +0800 Message-ID: <20231106120423.23364-20-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231106120423.23364-1-yunfei.dong@mediatek.com> References: <20231106120423.23364-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 +++++------ .../decoder/vdec/vdec_h264_req_multi_if.c | 57 +++++++++++-------- 2 files changed, 50 insertions(+), 41 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/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",