From patchwork Mon Jan 29 06:30:04 2024 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: 193271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp391824dyb; Sun, 28 Jan 2024 22:31:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/xxNy3w9iyPXODfhkjOUdpYkAhWQbTXsu2N7bbAyYfDktFto+s0xB8hKeqLsyjXWWQXUt X-Received: by 2002:a17:906:cf8f:b0:a30:c104:3a9c with SMTP id um15-20020a170906cf8f00b00a30c1043a9cmr6658298ejb.13.1706509915894; Sun, 28 Jan 2024 22:31:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509915; cv=pass; d=google.com; s=arc-20160816; b=NNqP0MSXg0zcBLAW1icXIfbDbg6lSbhjpNkHC8CdVOGbAiDWeMTgp0Nh33WPq95YRt Wzd0hjV3AQG+6xakr5NMUHVE7GBEVabgkq93SCUAFk3C3zBpftom4RBivoOyOL8Sp+Fp aVZ7pZsQeeGbzlOcZelNH7Z/v3SvMFAp7pzlrm0x17ykAysjb09BX5DkYesDIoesY9B8 jkxGG4EsGzYkAK5mjYBgLrwDGIlztteTZtd7BrKiHWhmh7CH29SixhjuFZ7/+RZzqdpW 3N9ZRvxfyS7O/nAzjO0Z7D+cjdoqwRkygQWMV0K6I9tL3tkP+qGTbPZTT4U0KpqrDgYk 9L2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ks8HEFFM+Bita0r2YqnY0e2OF7bLuHGY/XucvXvt/5M=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=zQr2fn4PBTGlds5W5r6MV2DN7wQd0AtuLA+XMMGiqAPLbL4R4dQ1a3VPBgSD/3Wszj ryUucIV98W8dhRcd+BYixDkE5DCk+Tlrb3vRVz2CHPudpQkn0goikm6j09Xgbj4J1H5A q/TIOCzEhIJgorY9tDar96+uIvuEPfl8z8cGTYx/mZ2UAl+OUfizNJOoSlsXSqkOGV4/ 78cAXIl5+5c/boCIugfAm1bQURs7bqvavIbZK8rSaVQvUf8zWRcSXH1YCFeW+x0LOUlr 7HLnEygQGB8k1z1N11UXFw6LK74FLtgJ1Xx8svRiR0JMOb8ch8uEloYBV0m3A35rRnSB GWIg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=rC7CSzJz; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42236-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42236-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l17-20020a170906079100b00a317ba1e9a9si3065424ejc.503.2024.01.28.22.31.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:31:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42236-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=rC7CSzJz; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42236-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42236-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5671B1F2187D for ; Mon, 29 Jan 2024 06:31:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F303524A7; Mon, 29 Jan 2024 06:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="rC7CSzJz" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 955754C628; Mon, 29 Jan 2024 06:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509849; cv=none; b=iJRRj8zmdCpJDWhmkrosevkWDYL0mYUGrFs6WgpXY1wIe+nrPJ0JcQrPSacDgGN9/Lhs3JAlKJZOpcLQsXVqXrqPXQt4w3lJDC73vd6xzP43izvSfPYzC4Z8GTUycke4iRGNTPl3unzA9ulXdJ4qofMl7QtLyVt7FcFzBNAa6jY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509849; c=relaxed/simple; bh=xGSuhvCBRDMEgDMwpAUMTgN3awbgVqgrTMiiH+gM0b8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UHhW+YVZNjY3ktV/376V6WxEnja4lvV01MJlbiJrCwqaTeZeR6YDewESJGu+TI6lstohMiIL8mRrpGsRWn1ey79xHQPYe89/38x39l29FwJ7u6dqBkzZ+hXwOwJZ+eenhSIPsXRb266wMQYEQvYbfMv88UxTJ2tTdk9kBgqyfLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=rC7CSzJz; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: eb034a62be6f11ee9e680517dc993faa-20240129 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=ks8HEFFM+Bita0r2YqnY0e2OF7bLuHGY/XucvXvt/5M=; b=rC7CSzJzNC1ArM4nYD97m29F0aGXFq92DQ5DDdJtbho6hQRKy81VEhadHZiknB02IiEJhoc381lZDT4qLHDpOEaYVWnuuSAlwEokwK8HdXy/H+y+0WNdvccoQl723F5g2I7xLxcO1c+TgxH3bGLcawUfAbxcMuPwLtXWTdhSYGA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:7f957b61-6f8a-4168-ab5d-a99195d6723e,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:6e16cf4,CLOUDID:4cb5c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: eb034a62be6f11ee9e680517dc993faa-20240129 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 757566817; Mon, 29 Jan 2024 14:30:38 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30:37 +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, 29 Jan 2024 14:30:36 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,01/22] v4l2: add restricted memory flags Date: Mon, 29 Jan 2024 14:30:04 +0800 Message-ID: <20240129063025.29251-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405341645826226 X-GMAIL-MSGID: 1789405341645826226 From: Jeffrey Kardatzke Adds a V4L2 flag which indicates that a queue is using restricted 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 56719a26a46c..047d4798e423 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_restricted_mem: when set user-space can pass the %V4L2_MEMORY_FLAG_RESTRICTED + * flag to indicate the dma bufs are restricted. + * @restricted_mem: when set queue will verify that the dma bufs are restricted. * @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 @@ -604,6 +607,8 @@ struct vb2_queue { unsigned int uses_requests:1; unsigned int allow_cache_hints:1; unsigned int non_coherent_mem:1; + unsigned int allow_restricted_mem:1; + unsigned int restricted_mem:1; struct mutex *lock; void *owner; @@ -773,7 +778,8 @@ void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb); * @q: pointer to &struct vb2_queue with videobuf2 queue. * @memory: memory type, as defined by &enum vb2_memory. * @flags: auxiliary queue/buffer management flags. Currently, the only - * used flag is %V4L2_MEMORY_FLAG_NON_COHERENT. + * used flags are %V4L2_MEMORY_FLAG_NON_COHERENT and + * %V4L2_MEMORY_FLAG_RESTRICTED. * @count: requested buffer count. * * Videobuf2 core helper to implement VIDIOC_REQBUF() operation. It is called diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 68e7ac178cc2..3e3f8d4b7c81 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_RESTRICTED (1 << 1) /* capabilities for struct v4l2_requestbuffers and v4l2_create_buffers */ #define V4L2_BUF_CAP_SUPPORTS_MMAP (1 << 0) @@ -1036,6 +1037,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) +#define V4L2_BUF_CAP_SUPPORTS_RESTRICTED_MEM (1 << 8) /** * struct v4l2_plane - plane info for multi-planar buffers From patchwork Mon Jan 29 06:30:05 2024 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: 193277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392257dyb; Sun, 28 Jan 2024 22:33:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGluUREsRdnoE0xubdLA6kNmy2F4zmyJb9aWV2GSGs9ZzGtG2RtVkwjwJ9ff+weGVoquSPh X-Received: by 2002:a5b:b09:0:b0:dc2:2424:1cd2 with SMTP id z9-20020a5b0b09000000b00dc224241cd2mr1466679ybp.95.1706509991821; Sun, 28 Jan 2024 22:33:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509991; cv=pass; d=google.com; s=arc-20160816; b=g4nTTJPXNJ6NDQWZGR6dfcq7c5gmFK3O4N8QMfZjFq+KJmFgVhUBXOJ6UdNWBTJ6As z1JYo2fwPBSYXy+LVcAOEAINEw1wJx1GWTIQKQzQKO9/lsRAsDXQ6hcfk1+uFwB5omiP gxx/dlJo5ix/t2uubOrlJjST1Y9ErU0iZUJYsdoeGPlaCQsggrTR3bvKVxPxtacsDK57 12v2tBQqMKDhVMG0OYkkpxvpYq7A4sq7Oq8uIpCKLHFRQRu7fJJ7ZOF23nmuzjNe4+3R 6SwhOMzMUgNcQqHSvuKsMKJ0Gl3xwSu5lM4pUweF+iZoQBL9VwLUPLhYPiUGHmcN0VaH mQyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BD29QZW6/FDb7FZtrvhAxAS5CCjAP62wNXiOAvvLw5I=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=mkc77o8lshhuUZtVWkO9GKi4HHyGhKEXxvsjbRHAZhuC9lkhFwecCLQ0PfjhbzbqR4 oPgcgiw3AC22rd4qmgxi+7aZayevuyzN3WaSdorTb/OzjqN2q6M7pmnB3iPxM2u99pF6 w0MlNOuAYkoIZV1D6M3iT/ZCupX8iZFedPbSm4AC9lKTqz3OsvG1yoZk2icSTXPEA/gT zKqTm8xX5HnOH4r/Fb9UY5w9V4KaJ26PFlFPSW4Y4aPjptoDbhld8syYCnif2VM0UPRA TwC4mgahfsh5deMENbG+AsSSBFHNAwvO32z6C8yebkKGIzFb+H9rmzAmeMkniT/CEdTv 6EFg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=LD+6dD3I; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42240-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42240-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p20-20020a639514000000b005d832f7486esi4675670pgd.228.2024.01.28.22.33.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:33:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42240-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=LD+6dD3I; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42240-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42240-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F093E28168F for ; Mon, 29 Jan 2024 06:32:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDFAC5465C; Mon, 29 Jan 2024 06:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="LD+6dD3I" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D1274D599; Mon, 29 Jan 2024 06:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509852; cv=none; b=lHPcB3KFF0z+kbYOMENpEtVXR4TGdzGOQoE5CUzV5fFZOwup5ELNi4jmkw1n7Ycc8vmOSPs+cUolMF1k7nOXPCJ9PK7kkmYlBgKApLOJxUI6susy1pOhuZWgXZICtNIHbyyyr4/9rS1xsMqBnA9101jfi67paHHQFjJlOtP83fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509852; c=relaxed/simple; bh=B2BbMbPzqwowimew9zJAjA/tTXytJajNYxTUH+gmpT8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tfuvlJewh0u9M/dvA6MGPU+M0tBNFhL6vzQhGbYTg8gV+xv6Bkze+Au8jEzL8bn1QoO9dd3MbVsZ+YW5JlOZAJ5/O7B5nMGY2+yce/EfGN/MSQ5PSD3fYp1WVLMtiVz0VHxkCMdnOzLkN5Ecgvz6J5UZmLCCTDUeD1oB5CFgrBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=LD+6dD3I; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: eb6c3b58be6f11ee9e680517dc993faa-20240129 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=BD29QZW6/FDb7FZtrvhAxAS5CCjAP62wNXiOAvvLw5I=; b=LD+6dD3I0dp1/S9SwTmkafuXqR2ff5p7CQUJ6PKzk/a9+FxrEE4+bwIyvTwmPrY3J6xSMCNS75yEskCAP0ZjgnEysYvrze/7n5c4d4YvOlPmnnJsaz+4j3p8RBKTxjr4GKjN4MPUpVxMvNlyHmdLSa4rM3oCVnjdbNmX7gz1MwM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:e00845e5-6348-4a93-b871-3692684fce89,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:6e16cf4,CLOUDID:a6a85c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: eb6c3b58be6f11ee9e680517dc993faa-20240129 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 521927469; Mon, 29 Jan 2024 14:30:39 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30:38 +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, 29 Jan 2024 14:30:37 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,02/22] v4l2: handle restricted memory flags in queue setup Date: Mon, 29 Jan 2024 14:30:05 +0800 Message-ID: <20240129063025.29251-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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--6.647000-8.000000 X-TMASE-MatchedRID: D0Pm2dEMlxOWHmpvkeKJB57tR0mnRAg1TJDl9FKHbrk1LB46LFAAkq/H ZLCMsEf9UVB7I/2CDSABbn1cvMDZHaEAqPOtlpvtjtK7dC6UBnnbKTxp3+WtIMj0QMA/92m24ft l+EKh+CByQYB2WJEWjc4upQc4xGVCue4A1S8vO3qUa50su1E7W7l8khgtUner0rKJ/e4C60yEIt GBZvH9STFmRUjzEp4LgDLqnrRlXrZ8nn9tnqel2LI7zVffJqTzY1SQaZlBkE5q9KgCqgNquvdVF r8ODUj71JdaDtUEfQfhx+G8+x+UoX7cGd19dSFd X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--6.647000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: DF0AFB3E5D025F6365231BC54E73BDE096F68A18030DC6CC188FCD1EB7D572242000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405421126496619 X-GMAIL-MSGID: 1789405421126496619 From: Jeffrey Kardatzke Validates the restricted 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 | 21 +++++++++++++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 41a832dd1426..7f5fd9ec9117 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -813,6 +813,15 @@ static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem) return true; } +static bool verify_restricted_mem_flags(struct vb2_queue *q, bool restricted_mem) +{ + if (restricted_mem != q->restricted_mem) { + dprintk(q, 1, "restricted memory model mismatch\n"); + return false; + } + return true; +} + int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count) { @@ -820,6 +829,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int q_num_bufs = vb2_get_num_buffers(q); unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; + bool restricted_mem = flags & V4L2_MEMORY_FLAG_RESTRICTED; unsigned int i; int ret = 0; @@ -862,6 +872,9 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, return 0; } + if (restricted_mem && (!q->allow_restricted_mem || memory != V4L2_MEMORY_DMABUF)) + return -EINVAL; + /* * Make sure the requested values and current defaults are sane. */ @@ -882,6 +895,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (ret) return ret; set_queue_coherency(q, non_coherent_mem); + q->restricted_mem = restricted_mem; /* * Ask the driver how many buffers and planes per buffer it requires. @@ -986,6 +1000,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; unsigned int q_num_bufs = vb2_get_num_buffers(q); + bool restricted_mem = flags & V4L2_MEMORY_FLAG_RESTRICTED; bool no_previous_buffers = !q_num_bufs; int ret = 0; @@ -994,6 +1009,9 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return -ENOBUFS; } + if (restricted_mem && (!q->allow_restricted_mem || memory != V4L2_MEMORY_DMABUF)) + return -EINVAL; + if (no_previous_buffers) { if (q->waiting_in_dqbuf && *count) { dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); @@ -1015,6 +1033,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return ret; q->waiting_for_buffers = !q->is_output; set_queue_coherency(q, non_coherent_mem); + q->restricted_mem = restricted_mem; } else { if (q->memory != memory) { dprintk(q, 1, "memory model mismatch\n"); @@ -1022,6 +1041,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_restricted_mem_flags(q, restricted_mem)) + return -EINVAL; } num_buffers = min(*count, q->max_num_buffers - q_num_bufs); diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 54d572c3b515..e825b1e2e22f 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -686,6 +686,8 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) *caps |= V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS; if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; + if (q->allow_restricted_mem && q->io_modes & VB2_DMABUF) + *caps |= V4L2_BUF_CAP_SUPPORTS_RESTRICTED_MEM; } static void validate_memory_flags(struct vb2_queue *q, @@ -700,7 +702,7 @@ static void validate_memory_flags(struct vb2_queue *q, *flags = 0; } else { /* Clear all unknown flags. */ - *flags &= V4L2_MEMORY_FLAG_NON_COHERENT; + *flags &= V4L2_MEMORY_FLAG_NON_COHERENT | V4L2_MEMORY_FLAG_RESTRICTED; } } From patchwork Mon Jan 29 06:30:06 2024 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: 193274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp391978dyb; Sun, 28 Jan 2024 22:32:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEleoo9fQ1hS6o7RZA7Fuq5YMQBjUYZWLiqS0cQPnqh6y8td2eCpTg3eu3cNyJ5ey4rf33e X-Received: by 2002:a17:906:a119:b0:a35:cb41:33e0 with SMTP id t25-20020a170906a11900b00a35cb4133e0mr703234ejy.27.1706509946961; Sun, 28 Jan 2024 22:32:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509946; cv=pass; d=google.com; s=arc-20160816; b=MdOCW1Wi8hkrhDubHKpKQ/Lv60VLCIaOt4yvOk/XW3nWXBoVAbNb2bu+FWmW7yXtjm jruagqIrKG51OyfVeyEPjlKeAxFkIaPOG/5+qIwO0l3Xn34GWLeXgyMXpJMhQML2pPo9 Bx7wZ80elXzUueF/0QvqNKUM//8qjFH8DhlIxRxlyLSVwDpJpka1Dpgv31tKt1r7uftL ovBRaSoo7GA611sw6Ee2bu0VxKa6kVKZC0VM7WTtqrWS7Z+OAU/pPLBz9hlyl4hR9O7n iehKL7YQPreBYdvQNM/DhHiKKTUVf+xJ31hekiKkXXLhGjSPozA3OzNAe2H+Tk5wWLaJ jtOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iRfjJ9YWROks75IUMtZC2wrUKi1suXGk03fbJUFbyt0=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=ol5g2iP7JiPv/sVsKl9tVDzGFShPzU4YWTFS3O59FrHqLGhixhaU1jO339SUXa0nhH Km0Ng28ljtxEWzhudLNfRHZqJD+TCBbkbZb8AuD0/9m+pcAIAoi4+Bi2ICSL0I3l/i7b FLGpIrkMxtBEccNo+cBNWE0A2W0JXgJa/0R8tKoraozJn0iXyro6dHpsNLmROtC17GXi Brr/rTHfG/r3PXyfhXmM8Z+9pXzMZYjl3c914Zbj+6BhRXp4X0G1nqWAgBxEmOK2YXkj QcgzOQCb3qpJPCJtF8mv3cSUh1cf4As1ITLpMgEln4EHnLPyjbUJ874gucB4UfSH5JfG STtw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=jhkTa5bB; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42238-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42238-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s14-20020a1709066c8e00b00a35a2453d0dsi908099ejr.169.2024.01.28.22.32.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:32:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42238-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=jhkTa5bB; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42238-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42238-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 956BA1F2303C for ; Mon, 29 Jan 2024 06:32:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 367A0537F1; Mon, 29 Jan 2024 06:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="jhkTa5bB" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0E3D4CE02; Mon, 29 Jan 2024 06:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509851; cv=none; b=XF6omy+l7RbNq2vZ9g+LsiwzadBX82KJW0SbFOsBDa10LWKYd1wgujZt+CrlipkRKTGVfutEQA3X5xR3dSifJQV7r9p4WWX7ycGjFw5L/RSAz54m0MTcQpyFpg4dCeh5w8FyMrV2bTsaa3Aosw1IdieVQaG7GecGv/uXNO5q17c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509851; c=relaxed/simple; bh=9w2g6Gq7+Vgz14KR9HnQQihLeCCf4NtwnAbBqhhkmRM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HXawG8Ii/ZQ/qmHXI/oLkksNIrERm5q2A9x6YciBvtW02CY+R0R+KtmY9QyXXtY/gHJtz6feEv0pCXI/33diTa7hWa5jv5ybsw7roQguATpoCWfO5BF1bYof7SepaV+y9P/2daiW6MHCCK+exKcqEQd8+yckR1kQmWCY63JpuxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=jhkTa5bB; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: edf4142cbe6f11eea2298b7352fd921d-20240129 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=iRfjJ9YWROks75IUMtZC2wrUKi1suXGk03fbJUFbyt0=; b=jhkTa5bBLiYUT3wpEltBxfzcWPuTQQZYVqddzaf9asJdWmMcexNnkzGzCmHJqKWIzWSQxBOVUfhdMicHCknFw6ecI1RAoTomn2is7LHQtJgekjkE1ZtA2Lo6HW2V877F/BsOqusz6vAkJ+Cfu6vXriNcO0HJT9lNCgFAU1VnBUE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:fb4fdc5f-960c-4c64-89c6-9a1053dcc4b8,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:6e16cf4,CLOUDID:7ed4dc7f-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: edf4142cbe6f11eea2298b7352fd921d-20240129 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 902818360; Mon, 29 Jan 2024 14:30:43 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30:40 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:38 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,03/22] v4l2: verify restricted dmabufs are used in restricted queue Date: Mon, 29 Jan 2024 14:30:06 +0800 Message-ID: <20240129063025.29251-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.360000-8.000000 X-TMASE-MatchedRID: vT/skvKLwFh/+iNkyaz33x+WEMjoO9WWTJDl9FKHbrn8dcjERAe6XpPD bikkMnICYUA4QKGgNJ2/QAgXHCg/RXdWNVeH9NKPSEQN/D/3cG4k9Lf/qe8xx9VU7IWeAUCLMCm LSFOvZt1yylwV7Bc73YAy6p60ZV62fJ5/bZ6npdiyO81X3yak88kZdO1mPd6HHujJdWgMIOuuBc q5ylGQImmWoby5Y3Os7MRn2aF6FKR+3BndfXUhXQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.360000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: DF28679987472B888EA7E9A1D6228B4E0BCD01647BD0B2DD86B95E8C06EC4EB42000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405374251193503 X-GMAIL-MSGID: 1789405374251193503 From: Jeffrey Kardatzke Verfies in the dmabuf implementations that if the restricted 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 | 8 ++++++++ drivers/media/common/videobuf2/videobuf2-dma-sg.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index 3d4fd4ef5310..f953570fef27 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -710,6 +710,14 @@ static int vb2_dc_map_dmabuf(void *mem_priv) return -EINVAL; } + /* Verify the dmabuf is restricted if we are in restricted mode, this is done + * by validating there is no page entry for the dmabuf. + */ + if (buf->vb->vb2_queue->restricted_mem && sg_page(sgt->sgl)) { + pr_err("restricted queue requires restricted 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 6975a71d740f..f87bd3f40b9b 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -570,6 +570,14 @@ static int vb2_dma_sg_map_dmabuf(void *mem_priv) return -EINVAL; } + /* Verify the dmabuf is restricted if we are in restricted mode, this is done + * by validating there is no page entry for the dmabuf. + */ + if (buf->vb->vb2_queue->restricted_mem && !sg_page(sgt->sgl)) { + pr_err("restricted queue requires restricted dma_buf"); + return -EINVAL; + } + buf->dma_sgt = sgt; buf->vaddr = NULL; From patchwork Mon Jan 29 06:30:07 2024 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: 193273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp391872dyb; Sun, 28 Jan 2024 22:32:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzDxwO6vWsCIYfv7Fk6KlAsAYc+pX69ixZk2xcSLROE6iCQYYe5CaVce30b3O9imL+9dsY X-Received: by 2002:a17:906:f0c9:b0:a35:e4e4:a5f6 with SMTP id dk9-20020a170906f0c900b00a35e4e4a5f6mr219712ejb.37.1706509923535; Sun, 28 Jan 2024 22:32:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509923; cv=pass; d=google.com; s=arc-20160816; b=wvneB3NrOjql115BNM/gfAjJekmUfA0ma8ku2G8CgDOYiVOGq+o5Jlhr6ANV3Ns91M bAR7pjciEFyDG7jBAdSqp7BJwkUswyaJMfGXUsJfLXuIdLheide6bnVZD0GmSfad/xES VgmlFgk0xUmBvlAewv+VAr91Hq5XxkEoBQv3EKH2ek1TN5qsFH1pYTzS52cBbDa3SrZ9 YQPJaM6m2YtDvgTywv4La15KeXhdmijzm/VWz4fg7KJwX/mtBHjWNDjD9weTwTZP/BW3 YCWJ12S5+NpemnALUsTdUEU4ceApxfJFcuJTRPH/WhN7HKag//yNg5XrtGSGftPkoLIG HQww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=khLeNmeFr4dEE7zUUulOnX9v44u9sQtomfWBa91taAk=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=o/4kwWxI7s6LXWNFL8RzRyYD3WqlrjoVfbzBYEjZYlssmgo9QfynQGBViYJPRa9bkn L3nUdxh1Tym91xZnmaCDGk8g4ZjBkZ7tx7o7PUjKQK0MgaXzs4kIqSt+BVU7MUv8xcjf XE1DVsRUs02So8s5pbHv8LgRp8q1uqFarnaTEgCRDrF88ssdHXK3C0Lpq1xHncQ7a0R7 3+z7wk/NeDvq2W3YQZJFFZWT7eegYmsghjIJ0dbf8Tm725V1xB40K1YlIJo6F8fENnuT sNIOCSzPxn7zdUT2xzp8Ekmo+0GGBlYBy7b2vybUZjGW9azh3OexzH+kma4WJh4JA4XJ +rEg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=mIlsVpIt; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42237-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42237-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qk16-20020a170906d9d000b00a3180d48956si3109563ejb.813.2024.01.28.22.32.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:32:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42237-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=mIlsVpIt; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42237-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42237-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 209401F21506 for ; Mon, 29 Jan 2024 06:32:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0208C524C7; Mon, 29 Jan 2024 06:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="mIlsVpIt" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB7471E885; Mon, 29 Jan 2024 06:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509850; cv=none; b=t4zSZNQJ12jAEhZxEuml/cqYc96EfnDPoK0pl4seQLeJMjoa2CmpQxQc4IApPM0Fol2is+B+9FrzbmtXckNQ7574rwEiLm8DKbN0s6vbQVteS3NPeHq/m3f57FfUOaOKsGnk3EP/gX6myBZUHbNtVxEqPId4daQvflU4vAtCutk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509850; c=relaxed/simple; bh=XynYdGnX4LVogsTrobOmVXzhFMegfGTunvcV5uxbo38=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h97SuGuK4cp0edJZuYbllQbfGQl2KoJInp3vgKRuGSc492D0YWwMffHIGqvn7oubpSTXI486+RCPnVW5XFXUGBuBnua0FJQSEev+MuNH6KwBJMftWebc6KH27IAUYAqW2sEra0hp28dykzj2n0PZCSrFcnO5qEWtTKGg7K/kuzg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=mIlsVpIt; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: ed6240babe6f11ee9e680517dc993faa-20240129 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=khLeNmeFr4dEE7zUUulOnX9v44u9sQtomfWBa91taAk=; b=mIlsVpIt8O3m6cIA2cqfWHDuDtavMub8L5qyq7Sd6+axb6xrS3hsYUt0XyrtjpcNi0mCCrOkk3xwEP1GoIxOPIB15bn6sK+dI+GUfK11GG5TMv2mFKCvKgm16K7MWtMiftiMWVjkU+zmk3SSeTWEKVrIR4FohNy2Gn8jlg3ww08=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:32b165f5-2a90-4003-9091-9190f5539130,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:6e16cf4,CLOUDID:e4a85c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: ed6240babe6f11ee9e680517dc993faa-20240129 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 531033874; Mon, 29 Jan 2024 14:30:42 +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, 29 Jan 2024 14:30: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, 29 Jan 2024 14:30:40 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,04/22] v4l: add documentation for restricted memory flag Date: Mon, 29 Jan 2024 14:30:07 +0800 Message-ID: <20240129063025.29251-5-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405349468589166 X-GMAIL-MSGID: 1789405349468589166 From: Jeffrey Kardatzke Adds documentation for V4L2_MEMORY_FLAG_RESTRICTED. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- Documentation/userspace-api/media/v4l/buffer.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/buffer.rst b/Documentation/userspace-api/media/v4l/buffer.rst index 52bbee81c080..807e43bfed2b 100644 --- a/Documentation/userspace-api/media/v4l/buffer.rst +++ b/Documentation/userspace-api/media/v4l/buffer.rst @@ -696,7 +696,7 @@ enum v4l2_memory .. _memory-flags: -Memory Consistency Flags +Memory Flags ------------------------ .. raw:: latex @@ -728,6 +728,14 @@ Memory Consistency Flags only if the buffer is used for :ref:`memory mapping ` I/O and the queue reports the :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS ` capability. + * .. _`V4L2-MEMORY-FLAG-RESTRICTED`: + + - ``V4L2_MEMORY_FLAG_RESTRICTED`` + - 0x00000002 + - The queued buffers are expected to be in restricted memory. If not, an + error will be returned. This flag can only be used with ``V4L2_MEMORY_DMABUF``. + Typically restricted buffers are allocated using a restricted dma-heap. This flag + can only be specified if the ``V4L2_BUF_CAP_SUPPORTS_RESTRICTED_MEM`` is set. .. raw:: latex From patchwork Mon Jan 29 06:30:08 2024 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: 193272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp391854dyb; Sun, 28 Jan 2024 22:32:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKsXFvr0lYmw2TROEu9w1pY1lvMFigTLKgqC4m4Y9GEQMMACbNwYThXE9CvyyD/B1vxhJe X-Received: by 2002:a17:906:c40a:b0:a35:a9e8:b281 with SMTP id u10-20020a170906c40a00b00a35a9e8b281mr1408853ejz.69.1706509921299; Sun, 28 Jan 2024 22:32:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509921; cv=pass; d=google.com; s=arc-20160816; b=ol0mnxbUe7eBVJVXDMKEzGNMrnbxux1ppJ4xUJ00Sk2CAHjws0tfWbOaD/Au8D7X3v gmtX81CtojHXciqWPWGhx/HOCeLXLCckn/w9K4oUxxw6ZwQj/t9mTqocJOXRvUmmyBey 6+n5zidUC2ZdneBQc1AW2y7MseFxchZE5zr91ckoGqzP/Mkuou/8eHygtGtQkEtFjUF/ Bw9uUIubLhgHlFk6g8X58BHr1ObG+PqgH30RT3+gTKIW83iLjgX3YaMTuLCsY1SacUkK GLBOZGIROTr+imUqT38AGj1FBkl7NNHMMiuvrLJuxGyvIcZWFO8sDO+ohC/E4OD/o1NM b6sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=t55MQIgMEx4p4MEJHDKfM0Ly5GklrK5skqp8MOiYDJY=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=rhp1D8aGHEXQQ3HEggDH0o9kiSovl97WOaZIXi+Aaws8MiI3gHRkSmGtYjVTo+FzF3 rjyD5DeNqFF+u4DmhoCT2x2MZARBTfab55QsP640SV1aHJYppJgPUsvUxw9Yo0oWcWx1 CBJIVz4JRGyx3OP83D5UHGAi6Gx1XKwSL2zQw7EZYLZ8Shq6Z/Bm4H5nE4FAifnH5C/M l34bCM2FrbCAiQZKQZzOqC10H+UYDS/3FffiHYqhPm12yDuq3BNTJzE7Sklu8Fv8CPnW 8LVXIZjxSNMrKlA+rd+Uo17vxP0kFB6qfjB+tAbysW6ROTRyKuQOe1Z6Wn6ZlSX04KdY hGeQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=nsMAojc3; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42235-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42235-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x4-20020a170906b08400b00a3178e6cfb6si3274793ejy.855.2024.01.28.22.32.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:32:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42235-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=nsMAojc3; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42235-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42235-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B48B61F21DD9 for ; Mon, 29 Jan 2024 06:32:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3FB6524BB; Mon, 29 Jan 2024 06:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="nsMAojc3" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 955A64C62A; Mon, 29 Jan 2024 06:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509849; cv=none; b=SiLAqIarATMgp5hxz05OvXaDy4zeBPOEmSCSAUBcKIouvKmhkNdBW6WI5jUCJ64iIUgfZqgftctbp5Jfeo+KkiV6YigmyR1TeOHviXqbcHHoPED7ecHgxH/JHoVG3M/m5KbjU3VHAaGapEu4vbio7ESTc/i7cC0fs8QCOT6bZNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509849; c=relaxed/simple; bh=46GL8lQxhxXq7eTTBb1iqE1WvpIw/qQaTALShXQhrG8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KhDdd9EhHRZzuAuZZ3TqbGuLL6JUXKLsbzV29iClj2GbVClF2DUkt6xTn8Wm1eqpT7ZaQw/s+gMjuyD0Rn8amNS9dVHLsS5naNKMTR7Rt/YD5G8LciLrEIl/UQ5fdHIsRzQtPSv2RWEMNo3vgZVmRVBtR3Jk7rF/WUwsHpXFBZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=nsMAojc3; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: edef23b8be6f11ee9e680517dc993faa-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=t55MQIgMEx4p4MEJHDKfM0Ly5GklrK5skqp8MOiYDJY=; b=nsMAojc3zvfX8AWckFbQEgNGexLQRSeqkTU9sR2rwM9+6g4bLb7cnqgEh8sCj1SdqZ8Isvqg2nhgXPyKWIXJncVa1ACwaIdq8neaKUyUInDHUfoXmJYfcEEZg0uymtlQIJToc7akjfi4FYyRNFY9X7FSpAYYtakyesWCZ6rf/hs=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:83d65bb9-247a-4308-b946-32da1ba55329,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:6e16cf4,CLOUDID:46d041fe-c16b-4159-a099-3b9d0558e447,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: edef23b8be6f11ee9e680517dc993faa-20240129 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 202787571; Mon, 29 Jan 2024 14:30:43 +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, 29 Jan 2024 14:30: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, 29 Jan 2024 14:30:41 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,05/22] dma-buf: heaps: Deduplicate docs and adopt common format Date: Mon, 29 Jan 2024 14:30:08 +0800 Message-ID: <20240129063025.29251-6-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--0.731800-8.000000 X-TMASE-MatchedRID: GYgQ58L2uffwUuSygkLx9JD6BbDN9+jOQKuv8uQBDjpU4V1pMvNQR62r pHsK32BkBMhVYRT3oC/ANNz/A2ARw8VLWPBZNJvOhK8o4aoss8pKPIx+MJF9o99RlPzeVuQQOAX Ig5vwe9o0ULOv9iNOM/3selkw4oOREKA/i6/8kSnJ1E/nrJFED+rRJDUyDHkImyiLZetSf8mfop 0ytGwvXiq2rl3dzGQ1QGS24C8okcg0UY6Al+suVXSZFwtvGzSUYEcjocHIsGbUhAPo58/N5Abir iIhLLAmJFn06LXnxqMiuXMsUHSiaoBc61l++Ol20ADcYxDUMBTzYaPZALfIbSyZdUr8fx4fMbuy vvGhtICw8QUP6tkDzUMMprcbiest X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--0.731800-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 2AD739A2F45B7AC91481DBC1F64F2FB2F11C0453C01E071DB8E9D62C2158336F2000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405347412467252 X-GMAIL-MSGID: 1789405347412467252 From: "T.J. Mercier" The docs for dma_heap_get_name were incorrect, and since they were duplicated in the header they were wrong there too. The docs formatting was inconsistent so I tried to make it more consistent across functions since I'm already in here doing cleanup. Remove multiple unused includes and alphabetize. Signed-off-by: T.J. Mercier Signed-off-by: Yong Wu [Yong: Just add a comment for "priv" to mute build warning] Signed-off-by: Yunfei Dong --- drivers/dma-buf/dma-heap.c | 27 +++++++++++++++------------ include/linux/dma-heap.h | 21 +-------------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 84ae708fafe7..22f6c193db0d 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -7,17 +7,15 @@ */ #include -#include #include #include +#include #include -#include #include -#include #include -#include #include -#include +#include +#include #include #define DEVNAME "dma_heap" @@ -28,9 +26,10 @@ * struct dma_heap - represents a dmabuf heap in the system * @name: used for debugging/device-node name * @ops: ops struct for this heap - * @heap_devt heap device node - * @list list head connecting to list of heaps - * @heap_cdev heap char device + * @priv: private data for this heap + * @heap_devt: heap device node + * @list: list head connecting to list of heaps + * @heap_cdev: heap char device * * Represents a heap of memory from which buffers can be made. */ @@ -193,11 +192,11 @@ static const struct file_operations dma_heap_fops = { }; /** - * dma_heap_get_drvdata() - get per-subdriver data for the heap + * dma_heap_get_drvdata - get per-heap driver data * @heap: DMA-Heap to retrieve private data for * * Returns: - * The per-subdriver data for the heap. + * The per-heap data for the heap. */ void *dma_heap_get_drvdata(struct dma_heap *heap) { @@ -205,8 +204,8 @@ void *dma_heap_get_drvdata(struct dma_heap *heap) } /** - * dma_heap_get_name() - get heap name - * @heap: DMA-Heap to retrieve private data for + * dma_heap_get_name - get heap name + * @heap: DMA-Heap to retrieve the name of * * Returns: * The char* for the heap name. @@ -216,6 +215,10 @@ const char *dma_heap_get_name(struct dma_heap *heap) return heap->name; } +/** + * dma_heap_add - adds a heap to dmabuf heaps + * @exp_info: information needed to register this heap + */ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) { struct dma_heap *heap, *h, *err_ret; diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 0c05561cad6e..fbe86ec889a8 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -9,14 +9,13 @@ #ifndef _DMA_HEAPS_H #define _DMA_HEAPS_H -#include #include struct dma_heap; /** * struct dma_heap_ops - ops to operate on a given heap - * @allocate: allocate dmabuf and return struct dma_buf ptr + * @allocate: allocate dmabuf and return struct dma_buf ptr * * allocate returns dmabuf on success, ERR_PTR(-errno) on error. */ @@ -41,28 +40,10 @@ struct dma_heap_export_info { void *priv; }; -/** - * dma_heap_get_drvdata() - get per-heap driver data - * @heap: DMA-Heap to retrieve private data for - * - * Returns: - * The per-heap data for the heap. - */ void *dma_heap_get_drvdata(struct dma_heap *heap); -/** - * dma_heap_get_name() - get heap name - * @heap: DMA-Heap to retrieve private data for - * - * Returns: - * The char* for the heap name. - */ const char *dma_heap_get_name(struct dma_heap *heap); -/** - * dma_heap_add - adds a heap to dmabuf heaps - * @exp_info: information needed to register this heap - */ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); #endif /* _DMA_HEAPS_H */ From patchwork Mon Jan 29 06:30:09 2024 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: 193275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392162dyb; Sun, 28 Jan 2024 22:32:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4mnYf2J7hGatSWJK3X/fHjedUdl/mLqtPkUVjwKeJ91J0xxIhMOQqaRKD5KTx8B8aZWR2 X-Received: by 2002:a05:622a:1745:b0:42a:6ed8:a9b4 with SMTP id l5-20020a05622a174500b0042a6ed8a9b4mr6876610qtk.71.1706509977470; Sun, 28 Jan 2024 22:32:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509977; cv=pass; d=google.com; s=arc-20160816; b=U6dU7x0XBOJMC9fXfFtls0s23R9S92/LsI9qvxzuMga1n5b6QDX/ljh5SYsLPFjCMF mq8my7T1fjkC+YtYEHFeseTRiCDVggYt4SGcM3hlB8HhDdkZ/dUCH6Fh3aNR4DnkYy3G 87bNVZ5Yn7vtno5gdLrmT66ywWbww9fygZqoiv7raOt46voeDIrOj+hvMkNam3gBn8Pd KMU5v4wr3sMq5ePFabZ9rrGAIL1g36g4q040l5CV/ce2aeT/tpmrGGZYG1pqFHAls2sS GQR459pqqqsK7eaEqWEgqHtlvPaDZMeN1Wsr5YPDhYvbL/seGFt5CVR/pI8KtJUTdnay CpCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VBRSF4YwZCz5T0Zk1nE7YVf8B1quLvMs45dUf37h/JQ=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=o7FznUk7YwVae0wFrrhkd/nFdAxEoMonjGOObBv3Pj8m0xApU6+ui7ygMAA4v1fRXN 90cmJjmK2staD4SyKnCVNkT3JouJGWG4UUbqQ70SXe2itG58lfFTMxWOi1uaiPNq2tkB wfciaMmJsgchFEPDOLia5/tll2UgJx+/O0lPAXCVH/svKd0uBp+uQPYUSig4jMrD/IJW sgJ7Qgo0eO0ZwFDgSJIR6pJ0XMFpKxe7rxK6CNX8dRz8w2gMVBcCWX1ew+0rOd5Vd/6Y VYZFs0GjhmwRhUdj//qohQ+YRQdNo3Iw6QHGmq2V5uyzh7mk2DIHGWTYE+Xqxb6nwFnB Wonw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=OMBdsH8L; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42241-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42241-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x26-20020a05620a099a00b00783e08c89efsi5281949qkx.710.2024.01.28.22.32.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:32:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42241-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=OMBdsH8L; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42241-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42241-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 376BF1C22AD8 for ; Mon, 29 Jan 2024 06:32:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95C1B54746; Mon, 29 Jan 2024 06:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="OMBdsH8L" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E26064E1DC; Mon, 29 Jan 2024 06:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509853; cv=none; b=plB9gsPskeTwUrLKZZ2ILqAlolRWcbjkHZH6Ljfnc8uOrfmctqJ9epOQwYd8KKcbgaQjJCLuH6pG6kRVpfC1RrEI3re+4Yj7cel+eIdKiG/XnDrF/5o/c+BadOwkb2Xj44tQy4vDMnN3dVA9bdgcjYyaNjYFS8eHpfQF5B5xFJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509853; c=relaxed/simple; bh=YmGSlmvsC6y8Pg4I3syRhSxSRjKdGNAUmRqX5TOnbAs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XdM64N0JmEDP+XMDvIoqRClwNDY9qt3y5rNFv4DNT6zK8cg8CiCAc6f7cE0b/0nXnOyZ2nyuScf7prbfqaJE2BbULlul6XrlxXfZCNhhJke2+qP2RavCrx1xC2hOAI4CHfihlkAyH4ezH8Jj/bkUTwG+09VGvBnSlvmATVUHqxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=OMBdsH8L; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: eed795d0be6f11eea2298b7352fd921d-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=VBRSF4YwZCz5T0Zk1nE7YVf8B1quLvMs45dUf37h/JQ=; b=OMBdsH8LvgJFk4uHD47/XD/hQyXmcP1yXYobnaQuM+gxqhjUKSE+f3yFO6tv7G273MKUX08ko7njJ+f7CxPwPLbCRgGpMAugaN3D5XfP82ckC7WSKxt89VyZLMRGgv4MbnCkjxjpC+eauFXMXWiiQLI9dqWevPRl+EecxYApd8M=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:6d561463-008a-4c56-bc1b-29aa5dd3f193,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:6e16cf4,CLOUDID:d9b5c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: eed795d0be6f11eea2298b7352fd921d-20240129 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 812860472; Mon, 29 Jan 2024 14:30:45 +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, 29 Jan 2024 14:30:44 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:42 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,06/22] dma-heap: Add proper kref handling on dma-buf heaps Date: Mon, 29 Jan 2024 14:30:09 +0800 Message-ID: <20240129063025.29251-7-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405405895017869 X-GMAIL-MSGID: 1789405405895017869 From: John Stultz Add proper refcounting on the dma_heap structure. While existing heaps are built-in, we may eventually have heaps loaded from modules, and we'll need to be able to properly handle the references to the heaps Signed-off-by: John Stultz Signed-off-by: T.J. Mercier Signed-off-by: Yong Wu [Yong: Just add comment for "minor" and "refcount"] Signed-off-by: Yunfei Dong --- drivers/dma-buf/dma-heap.c | 29 +++++++++++++++++++++++++++++ include/linux/dma-heap.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 22f6c193db0d..97025ee8500f 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ * @heap_devt: heap device node * @list: list head connecting to list of heaps * @heap_cdev: heap char device + * @refcount: reference counter for this heap device * * Represents a heap of memory from which buffers can be made. */ @@ -40,6 +42,7 @@ struct dma_heap { dev_t heap_devt; struct list_head list; struct cdev heap_cdev; + struct kref refcount; }; static LIST_HEAD(heap_list); @@ -240,6 +243,7 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) if (!heap) return ERR_PTR(-ENOMEM); + kref_init(&heap->refcount); heap->name = exp_info->name; heap->ops = exp_info->ops; heap->priv = exp_info->priv; @@ -304,6 +308,31 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) return err_ret; } +static void dma_heap_release(struct kref *ref) +{ + struct dma_heap *heap = container_of(ref, struct dma_heap, refcount); + unsigned int minor = MINOR(heap->heap_devt); + + mutex_lock(&heap_list_lock); + list_del(&heap->list); + mutex_unlock(&heap_list_lock); + + device_destroy(dma_heap_class, heap->heap_devt); + cdev_del(&heap->heap_cdev); + xa_erase(&dma_heap_minors, minor); + + kfree(heap); +} + +/** + * dma_heap_put - drops a reference to a dmabuf heap, potentially freeing it + * @heap: DMA-Heap whose reference count to decrement + */ +void dma_heap_put(struct dma_heap *heap) +{ + kref_put(&heap->refcount, dma_heap_release); +} + static char *dma_heap_devnode(const struct device *dev, umode_t *mode) { return kasprintf(GFP_KERNEL, "dma_heap/%s", dev_name(dev)); diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index fbe86ec889a8..d57593f8a1bc 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -46,4 +46,6 @@ const char *dma_heap_get_name(struct dma_heap *heap); struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info); +void dma_heap_put(struct dma_heap *heap); + #endif /* _DMA_HEAPS_H */ From patchwork Mon Jan 29 06:30:10 2024 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: 193276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392208dyb; Sun, 28 Jan 2024 22:33:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRi3oDsmm0ncL1QVMnpdyXNffg+O8WP37N8QE343wGD6ycizVWnRKlZvlDQJ+VA/tDx4Xz X-Received: by 2002:ac8:57cb:0:b0:42a:960d:e6a0 with SMTP id w11-20020ac857cb000000b0042a960de6a0mr4456700qta.115.1706509984788; Sun, 28 Jan 2024 22:33:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509984; cv=pass; d=google.com; s=arc-20160816; b=aAJfVgbqOn8vu+1umCWuGlfJStftNOmc409nZSDwbmTvE+awZ9GNyoOapk+j/KrMYM FUPWtLbJWtZjaxxsIaqALv+otKuDJWgti9L9snVKA2eSyPk+a5MFbOxIGVmhJr9kUVva xHPzwbXxQb4T9cQqFOPp8CD1jOXmckVNMvMA4QnsSzCIvWRlsiub6UAQGnUKmon9jKF7 R6GLJPGCeh9vZxldnH9x1n1M14pxk5p7TtFNmDOEUEBdyxzf/5DBPcm9q5mxsKcOjgdG GmZ9iZ9rUZ/YTRrbjvgSv/YJQjFzNX7pwFDlSjX0K/B/x/bAUyu6vrhSj8Rr+6OjlMM0 Uh0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JWJt5f3OFXku7W6faTUM0+bKsbswJle1HktQEF2gUcM=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=fOVrnsRtvDOap+eu+GtIogacqqNsqe8PdGri4ro/cUWSUJD0YjzkDtux6rIip0OLam dJQR1Ia7MTiCsXRYdqEx4GENQWLjXt82MZxvk3QwYtZPTQwH6vbB/t9K7cAw0g8C9+hn 80RKrvD7trISTnH9HVA/XUqfxPplrZEbOHVQub+G7vzuBnYrG7zWXJ9enbRC0drNIyyy V4ua7Qc8m/dCnYY81TkSDruVmITZmPWYBWH8/aOpYjdJ3PGy+a4Q6CpF0V4oF5izdl4x a/+TRpVnIg1gVlzrVT5t8N96CtKa/wimpTg8G+fsHchYZkXJoXomopZVlQY0UY4OWheI wY5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=GEmZUfsa; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42242-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42242-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p19-20020a05622a00d300b0042a890c1e56si5369917qtw.233.2024.01.28.22.33.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:33:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42242-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=GEmZUfsa; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42242-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42242-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 85CDA1C22565 for ; Mon, 29 Jan 2024 06:33:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44AB84CE02; Mon, 29 Jan 2024 06:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="GEmZUfsa" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 744354D5AC; Mon, 29 Jan 2024 06:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509853; cv=none; b=eEKEwTGYxMkTaaW2TZyf8SAEmmHMKTuVV/dvytfCx+adWnt0FnHuzgRTKYQLOsmgTJL2xrDhZcl2JC/QjPezhCH2JfsjcqP3URNGjm/qweowlMF7rnzvvr+8LZoezRh+YvbqlwYFeT6+ceybH6Nmxz+kn2csL1D7Lz66Pj6xQZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509853; c=relaxed/simple; bh=OFBrZ5G6KahLW+2WGIB0G4F3uNyjoIQj7ICnIoaBi1I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CqmGL/OYqKw+f4bt92XkFkXV19JHizayphg77ZTj1MZ5F7gwrCIE4D8KOcZh/KRCGkfG6b7DmvRFuK3Z1JvkoOzkxWPy03U5478ymdWHaQYTl79NZkLJ/XuZxfaLVZ7BzBML90VlJn92/r2eHJ+X6b/8h+tgSnd3wbcoXJ4+8DQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=GEmZUfsa; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: efcbb16abe6f11ee9e680517dc993faa-20240129 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=GEmZUfsabgdW7N7fB5qxDZ472JDENF+98O5G8i9+TmpoyHZ1aqqMwEAFApkq8SymZipF9/4uaEUEg32R2AZh86RzTM1Pj1Thq7FHNihGty3p14JYo2zihSfNWiEp+NHwJSHs27F3CvByZ91L0i998+tCGYZzieSSrMEfx6suLqA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:3ff2015f-04f5-4702-bc58-541da023cfb5,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:6e16cf4,CLOUDID:feb5c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: efcbb16abe6f11ee9e680517dc993faa-20240129 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1566165229; Mon, 29 Jan 2024 14:30: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, 29 Jan 2024 14:30: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, 29 Jan 2024 14:30:44 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,07/22] dma-heap: Provide accessors so that in-kernel drivers can allocate dmabufs from specific heaps Date: Mon, 29 Jan 2024 14:30:10 +0800 Message-ID: <20240129063025.29251-8-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405413981323291 X-GMAIL-MSGID: 1789405413981323291 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 Jan 29 06:30:11 2024 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: 193278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392366dyb; Sun, 28 Jan 2024 22:33:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIvFzGudWHvKLgqDnXClM7EZ2VpFlA3tz+iFEMueaMUmPqx78wxiwvXbIXLEdCWTVGOBAB X-Received: by 2002:a62:e415:0:b0:6dd:e2b9:d4a with SMTP id r21-20020a62e415000000b006dde2b90d4amr5295682pfh.26.1706510018376; Sun, 28 Jan 2024 22:33:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510018; cv=pass; d=google.com; s=arc-20160816; b=F8DrV5Z/rIrMztxQlf5sUxs8n8g5GIEFBZyrfLlBIJV5kM1pMbtpw1YBWOMiVcj91U U2JQEUCQP21+y1HNLXVfLSyPyKCfepgtTf5CrGS5AmMP4g7DPDjWhAuDzVsqbuvz2x68 Mq09oHtNGivlW5/p0WJO6fCxZQKbc9rlGE6uqpgxl+jdb9sKzd1hPzgAUOKc7RQRK0ct ZJjwDv2yNL3NLbEhq2cWzJlpJnZlBE3hXTAWhctRRbxKezsHkImcLORdCKx+ztKyVXqE YLDjdFpiA6chyXzRF8LnPYqzHIIju1wV5mYXpczzB5h9MKgjxwUjvAsxve8wCtueh6jN VLWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BNphP3hoQiB7tFeVmX2lWwuA+pAIdScaxFYuwh+hJz8=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=D9ZS5eo/TsL0Ctxs+IgRF4lpXkqkTm99i+Ql5C8LLxm9/xddQXOJzmfOB0zwFqe54l QuOKXKVggZHwd8JZOtphpx0f78es+WRFG9gsJgSnFnK8x/PNzkMWjd1WkyWeRvrHl5AZ qhKQ9ylbzLJOWEl420MODYaIiszQGqUDktxTfIXgdlVU3ijBk+ngXVOgTx6x8dGMCpuD 66Qj3PTLr394wfHQ8mSEs41J70BZWbE5TZTADc7tGVVHqViH+p3Tzuaqblew/5FdHWGU EofvV1YSwW0nQeqAbsG35GWiqgpoIcc/9g0XeevvaA66MGPtZWWk4YOECSUoIUsZMOUi CiqQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=bgG1vGvz; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42243-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42243-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lm10-20020a056a003c8a00b006ddc3620a09si4578372pfb.71.2024.01.28.22.33.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42243-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=bgG1vGvz; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42243-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42243-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7AED8284CC9 for ; Mon, 29 Jan 2024 06:33:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BE4D54BE7; Mon, 29 Jan 2024 06:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="bgG1vGvz" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76E9A4EB4C; Mon, 29 Jan 2024 06:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509854; cv=none; b=ic0JWr97rS/h8r00D5d12kKcMBxY6YkHQzh0OTH94jW8An3Abk5iFyecOkOWCyIFLwRqKTw75zPhCNkyMT+vJRw4no+rw+PIf8+kD2LjqZRzNtqCUbxFjqVTqsbRWZ5ByZG//UeCgyhl8XY+2NHw2GweVphy+Ny+k0BuIJmKwUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509854; c=relaxed/simple; bh=zTzj1QAP9OGZXnJLhuDtjSw2vEdrKVz7joj7BEvs+eQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BeptZfiJJg5gL9PAgwcmJT009NpHZN/o64Yyxhkk6qBZnrtiVLA77V2GUUKg+RK/qsqa7y0oeUiHeDVco31Jn/M1l/4oFplkWs3MMZdH8EnErHcuboDUydwU7k47E0Vh1+ocZOH5awocg97hGvqDd3WajdJOmH/Wg0PkvbQmMdY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=bgG1vGvz; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f02aa0b2be6f11ee9e680517dc993faa-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=BNphP3hoQiB7tFeVmX2lWwuA+pAIdScaxFYuwh+hJz8=; b=bgG1vGvzPcU9bnLCZYS7IqR31dL2Qq3GfMupDIJ3YweC5UTNCcs5rnWbQUEyo7COYLFfqaNMO3rsgT28mTMMTD1uOszeMxx/hmS9ohEWqceGok5lJrNC5Q4sxDLR8RotRy2OYkQeI1YU/sKX96hIk1vawFKsXrIz7DgConGtNxo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:2ac3f9aa-ae08-40a9-965d-24febc483752,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:6e16cf4,CLOUDID:01b6c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f02aa0b2be6f11ee9e680517dc993faa-20240129 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 748983309; Mon, 29 Jan 2024 14:30:47 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30: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, 29 Jan 2024 14:30:45 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,08/22] media: mediatek: vcodec: add tee client interface to communiate with optee-os Date: Mon, 29 Jan 2024 14:30:11 +0800 Message-ID: <20240129063025.29251-9-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.182900-8.000000 X-TMASE-MatchedRID: h25bOtMXAgrRhEyb9f1sjh+WEMjoO9WWWjWsWQUWzVr4JkeQZhmPNQVj /b97sBMuYCR1tL+r3keNF021kuf9VDa9BTI9OTwhRnmgWPGIUuPUqhJbkmLVe1vym/gvSH4iOAX Ig5vwe9q+8mjGjS5MxLL0CwDGT5MlADAYgCjdKFt7sw7yO+Y9LDfwU1OWX2USFlx2nWQqI6wrfc YgIq43/xaxmhrgB4zxWkQMsFTnQAIpDniSMR+7FRIMDPFEv6UxWDdWpJMntKgvM0Gdq0fzqYW1T JKdBGEt8izX0ZvrybM5lZtQHwAjALCuDuYv1cxai/b+LxU2p45dymZBcuGGREYvSDWdWaRhHSGE Z3gt1f6T4MVfZK1pgdJHai6GfGFVHxPMjOKY7A8LbigRnpKlKWxlRJiH4397Ks6J5sOq1z03iRP db7zQOK08hSN7m9AkYJa+xgWS4dU9Uay6eLVvQw== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--7.182900-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: DBC1DCB82A3174B82008E65B3252F90CD9081605170505AADAE7EAF46F25183A2000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405448986748731 X-GMAIL-MSGID: 1789405448986748731 Open tee context to initialize the environment in order to communication with optee-os, then open tee session as the communication pipeline for lat and core to send data for hardware decode. Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/decoder/Makefile | 1 + .../vcodec/decoder/mtk_vcodec_dec_drv.h | 5 + .../vcodec/decoder/mtk_vcodec_dec_optee.c | 165 ++++++++++++++++++ .../vcodec/decoder/mtk_vcodec_dec_optee.h | 73 ++++++++ 4 files changed, 244 insertions(+) create mode 100644 drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c create mode 100644 drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h diff --git a/drivers/media/platform/mediatek/vcodec/decoder/Makefile b/drivers/media/platform/mediatek/vcodec/decoder/Makefile index 904cd22def84..1624933dfd5e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/Makefile +++ b/drivers/media/platform/mediatek/vcodec/decoder/Makefile @@ -21,5 +21,6 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ mtk_vcodec_dec_stateful.o \ mtk_vcodec_dec_stateless.o \ mtk_vcodec_dec_pm.o \ + mtk_vcodec_dec_optee.o \ mtk-vcodec-dec-hw-y := mtk_vcodec_dec_hw.o diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h index 849b89dd205c..b1a2107f2a1e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h @@ -11,6 +11,7 @@ #include "../common/mtk_vcodec_dbgfs.h" #include "../common/mtk_vcodec_fw_priv.h" #include "../common/mtk_vcodec_util.h" +#include "mtk_vcodec_dec_optee.h" #include "vdec_msg_queue.h" #define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec" @@ -261,6 +262,8 @@ struct mtk_vcodec_dec_ctx { * @dbgfs: debug log related information * * @chip_name: used to distinguish platforms and select the correct codec configuration values + * + * @optee_private: optee private data */ struct mtk_vcodec_dec_dev { struct v4l2_device v4l2_dev; @@ -303,6 +306,8 @@ struct mtk_vcodec_dec_dev { struct mtk_vcodec_dbgfs dbgfs; enum mtk_vcodec_dec_chip_name chip_name; + + struct mtk_vdec_optee_private *optee_private; }; static inline struct mtk_vcodec_dec_ctx *fh_to_dec_ctx(struct v4l2_fh *fh) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c new file mode 100644 index 000000000000..38d9c1c1785a --- /dev/null +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2023 MediaTek Inc. + * Author: Yunfei Dong + */ + +#include "mtk_vcodec_dec_drv.h" +#include "mtk_vcodec_dec_optee.h" + +/* + * Randomly generated, and must correspond to the GUID on the TA side. + */ +static const uuid_t mtk_vdec_lat_uuid = + UUID_INIT(0xBC50D971, 0xD4C9, 0x42C4, + 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x90); + +static const uuid_t mtk_vdec_core_uuid = + UUID_INIT(0xBC50D971, 0xD4C9, 0x42C4, + 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x91); + +/* + * Check whether this driver supports decoder TA in the TEE instance, + * represented by the params (ver/data) of this function. + */ +static int mtk_vcodec_dec_optee_match(struct tee_ioctl_version_data *ver_data, const void *not_used) +{ + if (ver_data->impl_id == TEE_IMPL_ID_OPTEE) + return 1; + else + return 0; +} + +int mtk_vcodec_dec_optee_private_init(struct mtk_vcodec_dec_dev *vcodec_dev) +{ + vcodec_dev->optee_private = devm_kzalloc(&vcodec_dev->plat_dev->dev, + sizeof(*vcodec_dev->optee_private), + GFP_KERNEL); + if (!vcodec_dev->optee_private) + return -ENOMEM; + + vcodec_dev->optee_private->vcodec_dev = vcodec_dev; + + atomic_set(&vcodec_dev->optee_private->tee_active_cnt, 0); + mutex_init(&vcodec_dev->optee_private->tee_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_private_init); + +static int mtk_vcodec_dec_optee_init_hw_info(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hardware_index) +{ + struct device *dev = &optee_private->vcodec_dev->plat_dev->dev; + struct tee_ioctl_open_session_arg session_arg; + struct mtk_vdec_optee_ca_info *ca_info; + int err = 0, session_func; + + /* Open lat and core session with vdec TA. */ + switch (hardware_index) { + case MTK_VDEC_LAT0: + export_uuid(session_arg.uuid, &mtk_vdec_lat_uuid); + session_func = MTK_VDEC_OPTEE_TA_LAT_SUBMIT_COMMAND; + ca_info = &optee_private->lat_ca; + break; + case MTK_VDEC_CORE: + export_uuid(session_arg.uuid, &mtk_vdec_core_uuid); + session_func = MTK_VDEC_OPTEE_TA_CORE_SUBMIT_COMMAND; + ca_info = &optee_private->core_ca; + break; + default: + return -EINVAL; + } + + session_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC; + session_arg.num_params = 0; + + err = tee_client_open_session(optee_private->tee_vdec_ctx, &session_arg, NULL); + if (err < 0 || session_arg.ret != 0) { + dev_err(dev, MTK_DBG_VCODEC_STR "open vdec tee session fail hw_id:%d err:%x.\n", + hardware_index, session_arg.ret); + return -EINVAL; + } + ca_info->vdec_session_id = session_arg.session; + ca_info->hw_id = hardware_index; + ca_info->vdec_session_func = session_func; + + dev_dbg(dev, MTK_DBG_VCODEC_STR "open vdec tee session hw_id:%d session_id=%x.\n", + hardware_index, ca_info->vdec_session_id); + + return err; +} + +static void mtk_vcodec_dec_optee_deinit_hw_info(struct mtk_vdec_optee_private *optee_private, + enum mtk_vdec_hw_id hw_id) +{ + struct mtk_vdec_optee_ca_info *ca_info; + + if (hw_id == MTK_VDEC_LAT0) + ca_info = &optee_private->lat_ca; + else + ca_info = &optee_private->core_ca; + + tee_client_close_session(optee_private->tee_vdec_ctx, ca_info->vdec_session_id); +} + +int mtk_vcodec_dec_optee_open(struct mtk_vdec_optee_private *optee_private) +{ + struct device *dev = &optee_private->vcodec_dev->plat_dev->dev; + int ret; + + mutex_lock(&optee_private->tee_mutex); + if (atomic_inc_return(&optee_private->tee_active_cnt) > 1) { + mutex_unlock(&optee_private->tee_mutex); + dev_dbg(dev, MTK_DBG_VCODEC_STR "already init vdec optee private data!\n"); + return 0; + } + + /* Open context with TEE driver */ + optee_private->tee_vdec_ctx = tee_client_open_context(NULL, mtk_vcodec_dec_optee_match, + NULL, NULL); + if (IS_ERR(optee_private->tee_vdec_ctx)) { + dev_err(dev, MTK_DBG_VCODEC_STR "optee vdec tee context failed.\n"); + ret = PTR_ERR(optee_private->tee_vdec_ctx); + goto err_ctx_open; + } + + ret = mtk_vcodec_dec_optee_init_hw_info(optee_private, MTK_VDEC_LAT0); + if (ret < 0) + goto err_lat_init; + + if (IS_VDEC_LAT_ARCH(optee_private->vcodec_dev->vdec_pdata->hw_arch)) { + ret = mtk_vcodec_dec_optee_init_hw_info(optee_private, MTK_VDEC_CORE); + if (ret < 0) + goto err_core_init; + } + + mutex_unlock(&optee_private->tee_mutex); + return 0; +err_core_init: + mtk_vcodec_dec_optee_deinit_hw_info(optee_private, MTK_VDEC_LAT0); +err_lat_init: + tee_client_close_context(optee_private->tee_vdec_ctx); +err_ctx_open: + + mutex_unlock(&optee_private->tee_mutex); + return ret; +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_open); + +void mtk_vcodec_dec_optee_release(struct mtk_vdec_optee_private *optee_private) +{ + mutex_lock(&optee_private->tee_mutex); + if (!atomic_dec_and_test(&optee_private->tee_active_cnt)) { + mutex_unlock(&optee_private->tee_mutex); + return; + } + + mtk_vcodec_dec_optee_deinit_hw_info(optee_private, MTK_VDEC_LAT0); + if (IS_VDEC_LAT_ARCH(optee_private->vcodec_dev->vdec_pdata->hw_arch)) + mtk_vcodec_dec_optee_deinit_hw_info(optee_private, MTK_VDEC_CORE); + + tee_client_close_context(optee_private->tee_vdec_ctx); + mutex_unlock(&optee_private->tee_mutex); +} +EXPORT_SYMBOL_GPL(mtk_vcodec_dec_optee_release); diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h new file mode 100644 index 000000000000..8b1dca49331e --- /dev/null +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_optee.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2023 MediaTek Inc. + * Author: Yunfei Dong + */ + +#ifndef _MTK_VCODEC_DEC_OPTEE_H_ +#define _MTK_VCODEC_DEC_OPTEE_H_ + +#include +#include + +#include "mtk_vcodec_dec_drv.h" + +/* The TA ID implemented in this TA */ +#define MTK_VDEC_OPTEE_TA_LAT_SUBMIT_COMMAND (0x10) +#define MTK_VDEC_OPTEE_TA_CORE_SUBMIT_COMMAND (0x20) + +#define MTK_OPTEE_MAX_TEE_PARAMS 4 + +/** + * struct mtk_vdec_optee_ca_info - ca related param + * @vdec_session_id: optee TA session identifier. + * @hw_id: hardware index. + * @vdec_session_func: trusted application function id used specific to the TA. + */ +struct mtk_vdec_optee_ca_info { + u32 vdec_session_id; + enum mtk_vdec_hw_id hw_id; + u32 vdec_session_func; +}; + +/** + * struct mtk_vdec_optee_private - optee private data + * @vcodec_dev: pointer to the mtk_vcodec_dev of the device + * @tee_vdec_ctx: decoder TEE context handler. + * @lat_ca: lat hardware information used to communicate with TA. + * @core_ca: core hardware information used to communicate with TA. + * + * @tee_active_cnt: used to mark whether need to init optee + * @tee_mutex: mutex lock used for optee + */ +struct mtk_vdec_optee_private { + struct mtk_vcodec_dec_dev *vcodec_dev; + struct tee_context *tee_vdec_ctx; + + struct mtk_vdec_optee_ca_info lat_ca; + struct mtk_vdec_optee_ca_info core_ca; + + atomic_t tee_active_cnt; + /* mutext used to lock optee open and release information. */ + struct mutex tee_mutex; +}; + +/** + * mtk_vcodec_dec_optee_open - setup the communication channels with TA. + * @optee_private: optee private context + */ +int mtk_vcodec_dec_optee_open(struct mtk_vdec_optee_private *optee_private); + +/** + * mtk_vcodec_dec_optee_private_init - init optee parameters. + * @vcodec_dev: pointer to the mtk_vcodec_dev of the device + */ +int mtk_vcodec_dec_optee_private_init(struct mtk_vcodec_dec_dev *vcodec_dev); + +/** + * mtk_vcodec_dec_optee_release - close the communication channels with TA. + * @optee_private: optee private context + */ +void mtk_vcodec_dec_optee_release(struct mtk_vdec_optee_private *optee_private); + +#endif /* _MTK_VCODEC_FW_OPTEE_H_ */ From patchwork Mon Jan 29 06:30:12 2024 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: 193279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392421dyb; Sun, 28 Jan 2024 22:33:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFn3tBfyjxQOOju6vyp0BcuIpiNpjTq1con+vosIxuQmngPVZRUBM2I2GMcjGWsroSabIp X-Received: by 2002:a17:906:6816:b0:a35:83be:548b with SMTP id k22-20020a170906681600b00a3583be548bmr2246165ejr.68.1706510027503; Sun, 28 Jan 2024 22:33:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510027; cv=pass; d=google.com; s=arc-20160816; b=srHGGV2hVU1sUcItP7c6sApOZs/mCSATBhoATQnzZASb3LWe8dNCaG/P6zsg62xhjm FwTXjHSYzxVM0wFwq7/KpBhA77TLOwHxMroaaSZ3oRH1LivhjxAYZxESPqIFssVHs1h8 ycqNXJqAq8HjKZYlG/gkPfhQkiGP1m281rq30E+JBlbURIeR1JC+TdQKc3H1iLwswIL4 Dw5sMRgcdqloR4TKXSay59RWaf5fgdzSlebE365vyXkhx1kDgnL8Qhe2tWA30ysXv8+a WJXPtcev7UimMh9yNWJ9sSzsSWsF5rHnU2R53hCqJ1NdC0bP5eyEY5YkPvap7x3bOAVq 2WmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DMqBb8ywjQ0rZOsEH87m6D0Csn8bNMMs2dmXkp7WJNQ=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=ess/92X1Dv2UALIISX8SE+wSOZwtcp0nj7VeS27w5y1idkDH7aqOnO4rRM7hDRc7i+ usLJOEn18RBP+g1VAGjDhh+NlEt3dCPMoajdW+EfeP10anpUeLpbkdTVTkLwYJaSC071 sMGEHfmR3KPCo9kdeYY6iXkc5+zz/YQSpl27SN7NVxU5woHomCaCvWb2df4ihs3bED/K THYHI6MhNZK1+/YXNj3OIxCucPH69JED7Fjh6ev8WcldUFSb2uUokjdgtRjDZsky8kal EqJPXr8HIVCT7UdpMDRkaFTIwUL94M5g+OM1FRy0FHsthqu6yhiAhxaNBsnldFxGYika zR7w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UbtULTIZ; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42244-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42244-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qk16-20020a170906d9d000b00a3180d48956si3109563ejb.813.2024.01.28.22.33.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:33:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42244-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UbtULTIZ; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42244-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42244-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EFEE81F23044 for ; Mon, 29 Jan 2024 06:33:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DE9A54FB1; Mon, 29 Jan 2024 06:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="UbtULTIZ" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBFCA53E02; Mon, 29 Jan 2024 06:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509858; cv=none; b=U29xTfpso4q0wqRvxqIst8OuYfumKfEh9jREmVFkIdEdbbcPVQBmYXlxozrx/53kdLoSpVnsUznEXr7Fez8enTvZqFyz8vXLfdQ1x2UmTvRU11U4gU1xoBhCJW248FFjhSqxSrpukv5xbBn28qVuq3Mu45ffKzRsT9k8og7DncE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509858; c=relaxed/simple; bh=r+MGwvL4q6Qvyg0qb3J+JTFqxlzuh4lgzAvGnmLJPAU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TCc+q4qqYjhjKyQe7pkbx8zh6M9i00bxTWZIbo7IwpOOHzieIrQXDDSXj6i0qbfmhetPB65PQTth2gPXR+/biq1O3MkArP6bRoGepTOq0jA6EJBUz3czp8OiX0gfg/hsVGkwas5gBKS1iqgkaTaDdl8uZxRfRwYdYYWpt+38yTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=UbtULTIZ; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f17f1ed4be6f11eea2298b7352fd921d-20240129 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=UbtULTIZp53p53V3pjJslR3EdXlNFBsRNAkSydbRSSDyVdBepWDAbqGJD6+dnQFHRPx3eBxHpK1Rth+reLEsWir56VE+aCPqxA1e2yMF4K6at9BeZ8IfxLd1nUW2gaZ7DfdyVKFUJVKdR5tneD1Iqx2WmhqkUcGwz26X0kMpYrc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:ba7383a9-3c29-46f3-a374-d363901b848a,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:6e16cf4,CLOUDID:30a95c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f17f1ed4be6f11eea2298b7352fd921d-20240129 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1912731382; Mon, 29 Jan 2024 14:30:49 +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, 29 Jan 2024 14:30:48 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:46 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,09/22] media: mediatek: vcodec: allocate tee share memory Date: Mon, 29 Jan 2024 14:30:12 +0800 Message-ID: <20240129063025.29251-10-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: CAF33697948F636DC0B3C42444CBC459E7B69D5846104ADA4473D333C2EE6E0F2000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405458761455773 X-GMAIL-MSGID: 1789405458761455773 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 Jan 29 06:30:13 2024 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: 193281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392543dyb; Sun, 28 Jan 2024 22:34:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtANB9v8L2b6QhpRnLiqE3wSZZTuQwAjvnAlQt6N1kBWC+/smTfqaHQJvXAnjL5sbcnI1j X-Received: by 2002:ac8:5b84:0:b0:42a:9aa9:2d2c with SMTP id a4-20020ac85b84000000b0042a9aa92d2cmr3736763qta.64.1706510046428; Sun, 28 Jan 2024 22:34:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510046; cv=pass; d=google.com; s=arc-20160816; b=LKOI+BCwmkJKKDNEqptfOmy1gZ01Fz+qIUh0jWDHZQN7D9s9ZmEnJAg03b19CMtywL xgh83WSnxbGMwPxCkswCeqm/equU2t0iykf0Q14psxz/QqGHD1FoZ2/7eZE/BCethku2 5M/C6VeQ/AjOXxhKWe8wAkCuVNv9WwFf1jGP8t27jLSLRs1VJOtsE73kk17zLe5znCeh R5ncIwKDZCpZPwGZD5Bu88XIEt4X2CuWb3wYgPEnlXce7uGWn/gTv1fo7KFFYswrtSZq OntOtYqbjjCRIgHP68KRbIJQ/nMvarpIMDA0U9hYtKqthgJcjzTxfLaiZakVks/QN00s z9zw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Qsu2a6pWuI9r9UzNG4biPlS5wzwndp0NR6vZ8LjQ+Ww=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=Nl0yDAEiKL7F0DvGbvF+QZ2fQAJjPGtyNQd5C0fzJzPJU+WeQQceUcTlpxNkUZsrkt 0uFgX4FH8F9FghjARY08U8RHVT9z4GEQT5U5Be2NQcAeKXh2jUmyGDmyv/5FWisOZFIK n64TYLGCUBe2WwmTRU5Yc800RC8Y/7UCv9MDfo6Ys02U4/iiGxnLuTz2S56SSifQ3NCs NON9FVcdCxvf9pAJUcI0b8ajwHT1YeEB0nqBhEbz41LlIrtjtMcmxIt6VNWaT8zRT5qc b6vLjbN8wLgoZ0P1RTF5bDSSWRqJRimxRp/wW7lOT1Hzh9rG7X63U2NjYZC42kgTOfHN 4Rrg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hp6c43w4; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42246-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42246-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x9-20020ac85f09000000b0042a72043aa1si6709618qta.719.2024.01.28.22.34.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:34:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42246-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hp6c43w4; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42246-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42246-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D97E1C22691 for ; Mon, 29 Jan 2024 06:34:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B02BE55789; Mon, 29 Jan 2024 06:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="hp6c43w4" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 079D25466B; Mon, 29 Jan 2024 06:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509859; cv=none; b=jq9UCSxKulIUmelUj661pu9iKqrw5XaUhN8z6L2Z9MGpH7bfvdOR+Nw0QdiEuZTwoaWOjGTXz2rrUtutDZCiezf/Z8wtx/vI0zgD0uQRyP8UP7f+AbISgBpddu3R1W/Duct8ltAaEmz60N2geZfVEEjw/itBMbFA7Z2Rzhkp/Bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509859; c=relaxed/simple; bh=US4OZk6dblj+DVk9tUWz4o/lujsEaKBuVPKBXb+6cyE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=twnSJUaTxnQ2lsYPQDRwhOMu1tRyPvDcyJ51zDPYNxs5/gW4tKDxbken/WSGyv32mTAlzRKg9JxpoKIQ5t+4cAHsP4IWGCfMZ7nGUlTHeggCHfvJ6/kLs5jBTdhkpvTi9iPx1T33i961YEGGmw0Xp8jsaZNwmZgAz3JJMxhL5WE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=hp6c43w4; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f24c5f02be6f11eea2298b7352fd921d-20240129 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=hp6c43w4MrRUqhIhLgcfQN1mxo9VF/LYBE9dlBWeimW7UWSnrCLzqjIv49xIeSXciSKrQe+ulN0C4PMa6iz/ojM6/ja1xD4J58nCNjduKypBUCfXzBob4kF0uC5Nkfp2HgqjY7G5W3RO8RsAZ/y1PPtr+n7zBlxtV5PQHEGIXfo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:a681f9ca-e954-4460-bac6-e578edd33c88,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:6e16cf4,CLOUDID:9bd041fe-c16b-4159-a099-3b9d0558e447,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f24c5f02be6f11eea2298b7352fd921d-20240129 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 541821859; Mon, 29 Jan 2024 14:30:51 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30:49 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:48 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,10/22] media: mediatek: vcodec: send share memory data to optee Date: Mon, 29 Jan 2024 14:30:13 +0800 Message-ID: <20240129063025.29251-11-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: 36278F227AA0035C596A6AB2FBA9039AA55ED2785F36B33CF218D7195A0DC8412000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405478678695307 X-GMAIL-MSGID: 1789405478678695307 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 Jan 29 06:30:14 2024 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: 193282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392626dyb; Sun, 28 Jan 2024 22:34:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHh7VtM29W8VCyOrfr25cEV8jvrEN+rc9VNDi0P6ZJYGFmAWaYXuY1st28pMqvSqqOG92dh X-Received: by 2002:a05:6358:f10:b0:176:56b9:d4e1 with SMTP id b16-20020a0563580f1000b0017656b9d4e1mr985080rwj.23.1706510061704; Sun, 28 Jan 2024 22:34:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510061; cv=pass; d=google.com; s=arc-20160816; b=gIHXWYHTBHgAEKLuHpGyuBO7Hg1zoKxM7/AAr8/6AfSNAQZJ3+ysI4WGPAQWMoeBo+ DDkrfxrI4s6XFT2LheyZhPLD9pUFWDmHLpQFt8IAEPq4/eJ7L6AAy0pi6FLv4ebFnqw2 ET3p87rU5tXbmFjFdiMWIrBD85yZLJMN9RQyW6dSG8zzXS/1Zy4X4lOciNJKHbESUfYu BWIlvtvLvb15bL86hS/bTImpeNLAE11OpxQFG6FNBQphzhEsMert55g9QJtMGL/hnUSM xQLBHTamqUAqTU1xIujRA+YhyZXcM5UpI+nHeU9Bx9o/diNs4h00wHY0bGK0VdLCeXq3 V5Eg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9iSSK3aCMn3USGH6OeE2/3/hdEQJKNChvSI8XpPt0hI=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=AMk5cN8LwyTa9lmVM35Uk0k8innZFqKoTAv451QItwrED0Yzk8nlIM45fwZQCHSRIs M8CJ4c7UVUPDA/jRWHzJpDxalf/enLNBmEJFdWjr2kAFKWxYQy1+u9ZH1+dOYe8gdt2J 0F05RC2ehCMneZ3aDRH0oJ3lhz/RbwqCICHjtgU6djUpqnwdx7h70H/6WJq0Q7hLNp+U vKhtjBCgepbb4J+HM1Uq/pxhfGKAHmikWZtjd/6KVfYyy0MHEldjPhnfeVflK4qXfhHX oBu/5lhHK9n28iWDSL543hSvsynNDLstj+52S5x5V1GURggscrP7XcgxW0na6a1zBngt sB+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=TJRnS9KT; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42247-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42247-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u10-20020a056a00098a00b006dbbcb47d98si5263665pfg.299.2024.01.28.22.34.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:34:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42247-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=TJRnS9KT; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42247-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42247-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 89E1A2811FD for ; Mon, 29 Jan 2024 06:34:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E9DD55C35; Mon, 29 Jan 2024 06:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="TJRnS9KT" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1F5954BC9; Mon, 29 Jan 2024 06:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509860; cv=none; b=d3jDwoRWLEC/tpwZp0270WoYrfbwFTdlxrKAIVUhXSn6Lakm3CTX14Pfxwu3U+TREi0kytR5Z6LSYGKiXp4Rfv3hHDV7FGrsIgDJ7AmgfhYa50AUxdRR/S6g6oEW+NRiskLhkljUbyoQqD9EE/ULl0CuyCSFUqDpf91yFqwLqzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509860; c=relaxed/simple; bh=2oowgPSKX5Gc93+gAGcZNfQkbJZArqEicpr3GYddEC8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XrV9gSUF9PfyIoUOXPi42XSSG0/9SsHa6PR/ESe/K6emkJ3Jde9oY0f/mh7N1iQ+NOkq6ZHJY9144vFBkFu3460US2kp9EMSAVwXQ/zhERPcXo4kgEeCfaLS2TONrylO4HN8xw6DeVhQpQVFi0KQn6zgCi8q/sIgv26NsK8hwis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=TJRnS9KT; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f2b0c83ebe6f11eea2298b7352fd921d-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=9iSSK3aCMn3USGH6OeE2/3/hdEQJKNChvSI8XpPt0hI=; b=TJRnS9KTwZVUSU0sJ+xGUL8zVFAmsjQ9TX4dXq7eWujOVzi0NwtFTtn8CnMXfdfXXL7vcAnxsNMuVXr9no05M1Fl40ukjdmQXZOTYokPUd+RE6ODy0I1z3l0wyM3M2zmZ+k4p5hH/z0D9iSrxWjQy2d+++/PGz3mS9GmsM2AWV8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:a9b17daa-f0c7-473a-b085-dff1e69c134f,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:6e16cf4,CLOUDID:eed4dc7f-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f2b0c83ebe6f11eea2298b7352fd921d-20240129 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 200198750; Mon, 29 Jan 2024 14:30:51 +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, 29 Jan 2024 14:30:50 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:49 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,11/22] media: mediatek: vcodec: initialize msg and vsi information Date: Mon, 29 Jan 2024 14:30:14 +0800 Message-ID: <20240129063025.29251-12-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405494344519892 X-GMAIL-MSGID: 1789405494344519892 Need to initialize msg and vsi information before sending to optee-os, then calling optee invoke command to send the information to optee-os. For the optee communication interface is different with scp, using flag to separate them. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 + .../mediatek/vcodec/decoder/vdec_vpu_if.c | 49 ++++++++++++++++--- .../mediatek/vcodec/decoder/vdec_vpu_if.h | 4 ++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h index b1a2107f2a1e..47eca245dc07 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h @@ -175,6 +175,7 @@ struct mtk_vcodec_dec_pdata { * @vpu_inst: vpu instance pointer. * * @is_10bit_bitstream: set to true if it's 10bit bitstream + * @is_secure_playback: Secure Video Playback (SVP) mode */ struct mtk_vcodec_dec_ctx { enum mtk_instance_type type; @@ -220,6 +221,7 @@ struct mtk_vcodec_dec_ctx { void *vpu_inst; bool is_10bit_bitstream; + bool is_secure_playback; }; /** diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c index 82e57ae983d5..5336769a3fb5 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c @@ -148,7 +148,10 @@ static void vpu_dec_ipi_handler(void *data, unsigned int len, void *priv) static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len) { - int err, id, msgid; + struct mtk_vdec_optee_data_to_shm *optee_data; + int data_size, id, hw_id, msgid; + void *ack_msg, *data_msg; + int err; msgid = *(uint32_t *)msg; mtk_vdec_debug(vpu->ctx, "id=%X", msgid); @@ -158,16 +161,46 @@ static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len) if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE) { if (msgid == AP_IPIMSG_DEC_CORE || - msgid == AP_IPIMSG_DEC_CORE_END) + msgid == AP_IPIMSG_DEC_CORE_END) { + optee_data = &vpu->core_optee_info; id = vpu->core_id; - else + } else { + optee_data = &vpu->lat_optee_info; id = vpu->id; + } } else { + optee_data = &vpu->lat_optee_info; id = vpu->id; } - err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, id, msg, - len, 2000); + if (!vpu->ctx->is_secure_playback) { + err = mtk_vcodec_fw_ipi_send(vpu->ctx->dev->fw_handler, id, msg, len, 2000); + } else { + hw_id = (id == SCP_IPI_VDEC_LAT) ? MTK_VDEC_LAT0 : MTK_VDEC_CORE; + + mtk_vcodec_dec_optee_set_data(optee_data, msg, len, OPTEE_MSG_INDEX); + + /* There is no need to copy the data (VSI) message to shared memory, + * but we still need to set the buffer size to a non-zero value. + */ + if (msgid == AP_IPIMSG_DEC_CORE || msgid == AP_IPIMSG_DEC_START) { + data_msg = mtk_vcodec_dec_get_shm_buffer_va(vpu->ctx->dev->optee_private, + hw_id, OPTEE_DATA_INDEX); + data_size = mtk_vcodec_dec_get_shm_buffer_size(vpu->ctx->dev->optee_private, + hw_id, OPTEE_DATA_INDEX); + mtk_vcodec_dec_optee_set_data(optee_data, data_msg, data_size, + OPTEE_DATA_INDEX); + } + + err = mtk_vcodec_dec_optee_invokd_cmd(vpu->ctx->dev->optee_private, + hw_id, optee_data); + vpu->failure = err; + + ack_msg = mtk_vcodec_dec_get_shm_buffer_va(vpu->ctx->dev->optee_private, hw_id, + OPTEE_MSG_INDEX); + vpu_dec_ipi_handler(ack_msg, 0, vpu->ctx->dev); + } + if (err) { mtk_vdec_err(vpu->ctx, "send fail vpu_id=%d msg_id=%X status=%d", id, msgid, err); @@ -213,7 +246,11 @@ int vpu_dec_init(struct vdec_vpu_inst *vpu) return err; } - if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE) { + /* Using tee interface to communicate with optee os directly for SVP mode, + * fw ipi interface is used for normal playback. + */ + if (vpu->ctx->dev->vdec_pdata->hw_arch == MTK_VDEC_LAT_SINGLE_CORE && + !vpu->ctx->is_secure_playback) { err = mtk_vcodec_fw_ipi_register(vpu->ctx->dev->fw_handler, vpu->core_id, vpu->handler, "vdec", vpu->ctx->dev); diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h index fbb3f34a73f0..946e5abcc7d3 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.h @@ -28,6 +28,8 @@ struct mtk_vcodec_dec_ctx; * @codec_type : use codec type to separate different codecs * @capture_type: used capture type to separate different capture format * @fb_sz : frame buffer size of each plane + * @lat_optee_info : used to send msg to optee shm buffer + * @core_optee_info : used to send msg to optee shm buffer */ struct vdec_vpu_inst { int id; @@ -44,6 +46,8 @@ struct vdec_vpu_inst { unsigned int codec_type; unsigned int capture_type; unsigned int fb_sz[2]; + struct mtk_vdec_optee_data_to_shm lat_optee_info; + struct mtk_vdec_optee_data_to_shm core_optee_info; }; /** From patchwork Mon Jan 29 06:30:15 2024 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: 193280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392454dyb; Sun, 28 Jan 2024 22:33:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+Q6M9Aiq+LAjj6zGCoYom3snphxGtysC5nHipQv72hH2ilPU4TBGFAiyrvMOGBZv0JoMg X-Received: by 2002:ac8:59c2:0:b0:42a:87e6:c5cc with SMTP id f2-20020ac859c2000000b0042a87e6c5ccmr6422302qtf.70.1706510030764; Sun, 28 Jan 2024 22:33:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510030; cv=pass; d=google.com; s=arc-20160816; b=aSv5iiiQwZmcsgXjDRxXrppywyVOO/29O54VXfHlK3jz29DaW0n7JcAkQFogthWow1 DIF2EA8pc0fkPOJqUGA2LZxQ63T2uLdJHpnkrtKO7Gh0eUvvWiADsbmsVHalbsezBV2q MRK2S2//0oDEQLRkLcRl3u5DkYfPGPFDWX4blGW/mQN8ZCN2XOkEtSLlPrTJJL4kOPI7 1YRieEWxxuJqzJNWyT3Zvt7LjXOZktaz54bptk3PFYqTDz/z0k2kQDPpXjiiJBUyWdqH WwNSytOrxrVPKToPacBIf6iO4IeBiYEaAIIEvR0qYi1yABJz+yosx0ClkmitfuxMWorv ZTZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UPVHcc8KSPfm1YMszvxilcNFOHjhFpWP3tum1Ff3QE8=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=O2vApOfqGvibGvchC5Z4XTTm8NHZ5LPrS8bP5wDa+bVI7KYq+fKWp+SNYEDfkeetL4 /QzGB3Y6L4vnsMB6m/gLwRjkco3KMr4aQWHLT4yERyIyLb1GdcX2WjwTnxGCrtIj+GKk LzAlwtBaFAyp0RZw0RGlOfesArz2n+g4B+V9CVsCfz1cjyDHqJTBauc1swOI4HAcaXXs DB662p5cS2h7Qmx01RnmntjD+HGX6WfWeaxrzV014AjVw7kDir0a/EwlBOfriKbARyi6 4DcRwh+smcb7hNrPYvN6jL4ODLHbcQ25bX0XfNFF/bXk5ZqYwgcUS6jf5hoj7FOl7tu4 ZoYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=clgLIUTD; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42245-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42245-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e1-20020a05622a110100b00428254553e7si6928405qty.764.2024.01.28.22.33.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:33:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42245-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=clgLIUTD; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42245-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42245-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 804B91C220C2 for ; Mon, 29 Jan 2024 06:33:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76AAA54FBA; Mon, 29 Jan 2024 06:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="clgLIUTD" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 499EE53E39; Mon, 29 Jan 2024 06:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509858; cv=none; b=ulAN6n5+K5L0f/uHeaHDhRl52C7OoZ/VuWTx+oz2fYoJTocF+JFk3z08KrsF7GXPkMIlZoAP87ar719RGMKUPYsppkZxzykpAxu5dLdo8pF41Xo3SSHmRUVUgeY/0T455Udt11nBEboRIQgbX2pxlR5Nd19efftGDfsaptWlkVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509858; c=relaxed/simple; bh=WYqw2+v1w6j/CLPP1uoWZPZl5XwGU5t+rOoBnsQYqg4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j6m8DqhdLC9BElaJQNRyDrGm8R3bnQiesBJB6q8ERzB/DWDaljjRPOQvLNF2E0fVMh3N6czHnhJLaItEcqjNhGglfkKiFwvPmOuO6nORiQ3ogq9AzH3hNtu7Yw59fGy6GwNd+KEhwd8/oqghtEpdSj0S18C1lcX7dw3NujWjPkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=clgLIUTD; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f3c454d4be6f11ee9e680517dc993faa-20240129 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=UPVHcc8KSPfm1YMszvxilcNFOHjhFpWP3tum1Ff3QE8=; b=clgLIUTDmoE7Sir/ZTAJzt6KLVf0pb6zkSIfMC0/1VGSw2000DP3YZEg/ox8Sbziu80edPrR8+Eu+OE90z0odIeDttqmFvTkNtCF8DWizdc0Y0xtOi92dZYIzNZb9HnEpCfuelm0t7rgPbwofiC6MtVl2qJtaYh8r8EK5St6ur4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:fa9fcc87-b5ba-4f02-a0ab-d3a4576207c6,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:6e16cf4,CLOUDID:44b6c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f3c454d4be6f11ee9e680517dc993faa-20240129 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 68555300; Mon, 29 Jan 2024 14:30:53 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30:52 +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, 29 Jan 2024 14:30:50 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,12/22] media: mediatek: vcodec: add interface to allocate/free secure memory Date: Mon, 29 Jan 2024 14:30:15 +0800 Message-ID: <20240129063025.29251-13-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405461917775423 X-GMAIL-MSGID: 1789405461917775423 Need to call dma heap interface to allocate/free secure memory when playing secure video. Signed-off-by: Yunfei Dong --- .../media/platform/mediatek/vcodec/Kconfig | 1 + .../mediatek/vcodec/common/mtk_vcodec_util.c | 122 +++++++++++++++++- .../mediatek/vcodec/common/mtk_vcodec_util.h | 3 + 3 files changed, 123 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/Kconfig b/drivers/media/platform/mediatek/vcodec/Kconfig index bc8292232530..707865703e61 100644 --- a/drivers/media/platform/mediatek/vcodec/Kconfig +++ b/drivers/media/platform/mediatek/vcodec/Kconfig @@ -17,6 +17,7 @@ config VIDEO_MEDIATEK_VCODEC depends on VIDEO_MEDIATEK_VPU || !VIDEO_MEDIATEK_VPU depends on MTK_SCP || !MTK_SCP depends on MTK_SMI || (COMPILE_TEST && MTK_SMI=n) + depends on DMABUF_HEAPS select VIDEOBUF2_DMA_CONTIG select V4L2_MEM2MEM_DEV select VIDEO_MEDIATEK_VCODEC_VPU if VIDEO_MEDIATEK_VPU diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c index 9ce34a3b5ee6..5cb7c347322b 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c @@ -5,9 +5,11 @@ * Tiffany Lin */ +#include #include #include #include +#include #include "../decoder/mtk_vcodec_dec_drv.h" #include "../encoder/mtk_vcodec_enc_drv.h" @@ -45,7 +47,7 @@ int mtk_vcodec_write_vdecsys(struct mtk_vcodec_dec_ctx *ctx, unsigned int reg, } EXPORT_SYMBOL(mtk_vcodec_write_vdecsys); -int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) +static int mtk_vcodec_mem_alloc_nor(void *priv, struct mtk_vcodec_mem *mem) { enum mtk_instance_type inst_type = *((unsigned int *)priv); struct platform_device *plat_dev; @@ -76,9 +78,71 @@ int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) return 0; } -EXPORT_SYMBOL(mtk_vcodec_mem_alloc); -void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) +static int mtk_vcodec_mem_alloc_sec(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_mem *mem) +{ + struct device *dev = &ctx->dev->plat_dev->dev; + struct dma_buf *dma_buffer; + struct dma_heap *vdec_heap; + struct dma_buf_attachment *attach; + struct sg_table *sgt; + unsigned long size = mem->size; + int ret = 0; + + if (!size) + return -EINVAL; + + vdec_heap = dma_heap_find("restricted_mtk_cm"); + if (!vdec_heap) { + mtk_v4l2_vdec_err(ctx, "dma heap find failed!"); + return -EPERM; + } + + dma_buffer = dma_heap_buffer_alloc(vdec_heap, size, DMA_HEAP_VALID_FD_FLAGS, + DMA_HEAP_VALID_HEAP_FLAGS); + if (IS_ERR_OR_NULL(dma_buffer)) { + mtk_v4l2_vdec_err(ctx, "dma heap alloc size=0x%lx failed!", size); + return PTR_ERR(dma_buffer); + } + + attach = dma_buf_attach(dma_buffer, dev); + if (IS_ERR_OR_NULL(attach)) { + mtk_v4l2_vdec_err(ctx, "dma attach size=0x%lx failed!", size); + ret = PTR_ERR(attach); + goto err_attach; + } + + sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); + if (IS_ERR_OR_NULL(sgt)) { + mtk_v4l2_vdec_err(ctx, "dma map attach size=0x%lx failed!", size); + ret = PTR_ERR(sgt); + goto err_sgt; + } + + mem->va = dma_buffer; + mem->dma_addr = (dma_addr_t)sg_dma_address((sgt)->sgl); + + if (!mem->va || !mem->dma_addr) { + mtk_v4l2_vdec_err(ctx, "dma buffer size=0x%lx failed!", size); + ret = -EPERM; + goto err_addr; + } + + mem->attach = attach; + mem->sgt = sgt; + + return 0; +err_addr: + dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL); +err_sgt: + dma_buf_detach(dma_buffer, attach); +err_attach: + dma_buf_put(dma_buffer); + + return ret; +} + +static void mtk_vcodec_mem_free_nor(void *priv, struct mtk_vcodec_mem *mem) { enum mtk_instance_type inst_type = *((unsigned int *)priv); struct platform_device *plat_dev; @@ -111,6 +175,57 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) mem->dma_addr = 0; mem->size = 0; } + +static void mtk_vcodec_mem_free_sec(struct mtk_vcodec_mem *mem) +{ + if (mem->sgt) + dma_buf_unmap_attachment(mem->attach, mem->sgt, DMA_BIDIRECTIONAL); + dma_buf_detach((struct dma_buf *)mem->va, mem->attach); + dma_buf_put((struct dma_buf *)mem->va); + + mem->attach = NULL; + mem->sgt = NULL; + mem->va = NULL; + mem->dma_addr = 0; + mem->size = 0; +} + +int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) +{ + enum mtk_instance_type inst_type = *((unsigned int *)priv); + int ret; + + if (inst_type == MTK_INST_DECODER) { + struct mtk_vcodec_dec_ctx *dec_ctx = priv; + + if (dec_ctx->is_secure_playback) { + ret = mtk_vcodec_mem_alloc_sec(dec_ctx, mem); + goto alloc_end; + } + } + + ret = mtk_vcodec_mem_alloc_nor(priv, mem); +alloc_end: + + return ret; +} +EXPORT_SYMBOL(mtk_vcodec_mem_alloc); + +void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) +{ + enum mtk_instance_type inst_type = *((unsigned int *)priv); + + if (inst_type == MTK_INST_DECODER) { + struct mtk_vcodec_dec_ctx *dec_ctx = priv; + + if (dec_ctx->is_secure_playback) { + mtk_vcodec_mem_free_sec(mem); + return; + } + } + + mtk_vcodec_mem_free_nor(priv, mem); +} EXPORT_SYMBOL(mtk_vcodec_mem_free); void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx) @@ -172,3 +287,4 @@ EXPORT_SYMBOL(mtk_vcodec_get_curr_ctx); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Mediatek video codec driver"); +MODULE_IMPORT_NS(DMA_BUF); diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h index 85f615cdd4d3..22078e757ed0 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h @@ -18,6 +18,9 @@ struct mtk_vcodec_mem { size_t size; void *va; dma_addr_t dma_addr; + + struct dma_buf_attachment *attach; + struct sg_table *sgt; }; struct mtk_vcodec_fb { From patchwork Mon Jan 29 06:30:16 2024 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: 193283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392710dyb; Sun, 28 Jan 2024 22:34:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIoQNkooWkACZeYsiW4FxyKAZ1EH2FH8yWtesc9D0WRZWpfx+cU/fpD46eJHc+BOP6idkJ X-Received: by 2002:a05:620a:3193:b0:783:e148:bd95 with SMTP id bi19-20020a05620a319300b00783e148bd95mr5140760qkb.17.1706510078518; Sun, 28 Jan 2024 22:34:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510078; cv=pass; d=google.com; s=arc-20160816; b=NwXb3rLFh8v0XgTFGX9riDvMmVpodaQQc85v+wtQKXESh9r3t3LvopQy+eYGCa92NZ 8EE6dLlhhkr3zhykBELhDHOVyEtZfNs3iBiu8ns0j3CFIZtqHScDKrHhB/NGPQ0INEfD DmH2pJARonLGFWetHOulGoY2IkVYKctKJNufXis8192AvJsS45BFyqS3zsEKkJXX/vKC QPIVmUdYk80COy1xqkxAaOsJxH9wIu334Ww+vuSo/tSnpsoGC/KFU+TcyIWEOvZ1MDWa skgQmYqKFDrd7qXcxkE/krDpLywC/FfEsarYsYMn7fENST75rsGZFc+Otkv1mFF1Jjyz cCPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qwM6JgCEYya6p3UBStFyf78I7pEgy/IRsIjn5bFayA8=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=SVn6MUNGPlcvquuP487mJxaNpJhLNp4/OilV89AM7zY9AWck0cNA9ojV62LBRBAEx7 dKwU3mbe/4+Rl7UaMtYkv9QGmoGdMm8zkM6OeEiWl/jAjXL94EXwq+ljGBt9F+GzjHHR qYvUcwYn4Kg1Id+AIgAQR5jKw8C3t0cM/28PdmG3flOfrVWuJqbWt5glHoAz+PQXxMZp MvA/+Jxm4CUBTDWNa8LaoddRHLT4ue6VhDyPJCYe8CxGyUTb0AE4+o46tkkDOKpizvjA wG488siVkZycKhY0dZkY2pYVlj9MQmxhsgeecJIrGbkLSHUn9O7Mt702jTLKFYwPlnRY SQ6A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="LcN/nM0F"; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42249-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42249-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b11-20020a05620a118b00b00783f7abe678si2514547qkk.586.2024.01.28.22.34.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:34:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42249-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="LcN/nM0F"; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42249-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42249-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 420991C231E1 for ; Mon, 29 Jan 2024 06:34:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6D3A55E6F; Mon, 29 Jan 2024 06:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="LcN/nM0F" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79A754CE1F; Mon, 29 Jan 2024 06:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509863; cv=none; b=a52VaU32urFCdslbeSsZegA6MKmwer5XoTeIcnHgGCKZVE7zFp/Vpr0ZKk0jCriNn7WOhGPTMaTuiLHe0R/pe0XVy1DRROcdzNnfDTauSl9HXWUEBLwnq8EZz1El6EtTNw7UWjvvzNzyEPjIEoimYveqSO5CV+aAQ9+sFWmLBaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509863; c=relaxed/simple; bh=y/nyQj2kntIuwTU5xzdfn4O39Ygv5fVYnQ0ECw51UZw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KOlOV3pv57Bls/s0LbkMAhCRcMhpELnvEy91JuqtTFgzPBOTtFicEzzU6fSCfSNPTo+btdE8M9h5qlACisjIH6m+H3lNvl+VYKiAWAACQovzsTb/DywSKuf1RO/7qKSKSPUnLEjpdtbBh0ilX9W+40/xk7x9t3RAnbaCvjiJnCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=LcN/nM0F; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f4c40d7abe6f11eea2298b7352fd921d-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=qwM6JgCEYya6p3UBStFyf78I7pEgy/IRsIjn5bFayA8=; b=LcN/nM0FmxRKJqWNMGrPyW7AbjOtLomOmrULzGbemFGiPoo8XuPee4qyIMKY3j4ESc0q5oORJvor0BinlOp/3kktbBdKODgw0uTx657rE3QvoPp2uTWT4AExlr/r0+wTI4WxIcFoW9adReqOKqJ7Upkk4jYepRvnX5ewKo2dsHs=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:4b51447d-91a9-4fa1-97df-7cfe45bdc986,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:6e16cf4,CLOUDID:68b6c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f4c40d7abe6f11eea2298b7352fd921d-20240129 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1674703031; Mon, 29 Jan 2024 14:30:55 +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, 29 Jan 2024 14:30:53 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:52 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,13/22] media: mediatek: vcodec: using shared memory as vsi address Date: Mon, 29 Jan 2024 14:30:16 +0800 Message-ID: <20240129063025.29251-14-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--4.493000-8.000000 X-TMASE-MatchedRID: TPKnaArzlb40Z9sXcK7F6QPZZctd3P4BK2i9pofGVSsKogmGusPLb/BY Ro06eVj3M+9E78FP+k6T5In082VlTzMbZlaZZohC58dk5sbwmyhfyi4Yas3gTZsoi2XrUn/Jn6K dMrRsL14qtq5d3cxkNd9Yv5wIp3lSt60hkI2pQ2CK7F3rMBgxv9NV+Z1yWVO7LpxXk6BRcsulY5 wiqJsM8FAMrTQJzVe/7D3+NuuC+kMY6u4FG2zDe9AA3GMQ1DAU82Gj2QC3yG0smXVK/H8eHzG7s r7xobSAsPEFD+rZA81DDKa3G4nrLQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.493000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: DE5F7330BA944F9881531F1855C1EA253BCD020889D1166FFA72075456AC79682000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405512267328067 X-GMAIL-MSGID: 1789405512267328067 The vsi buffer is allocated by tee share memory for svp mode, need to use the share memory as the vsi address to store vsi data. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/vdec/vdec_h264_req_multi_if.c | 9 +++++++-- .../media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 0e741e0dc8ba..4967e0f0984d 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -417,8 +417,13 @@ static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx) vsi_size = round_up(sizeof(struct vdec_h264_slice_vsi), VCODEC_DEC_ALIGNED_64); inst->vsi = inst->vpu.vsi; - inst->vsi_core = - (struct vdec_h264_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); + if (ctx->is_secure_playback) + inst->vsi_core = + mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE, + OPTEE_DATA_INDEX); + else + inst->vsi_core = + (struct vdec_h264_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); inst->resolution_changed = true; inst->realloc_mv_buf = true; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c index 5336769a3fb5..5c31641e9abe 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c @@ -18,8 +18,12 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg) /* mapping VPU address to kernel virtual address */ /* the content in vsi is initialized to 0 in VPU */ - vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler, - msg->vpu_inst_addr); + if (vpu->ctx->is_secure_playback) + vpu->vsi = mtk_vcodec_dec_get_shm_buffer_va(vpu->ctx->dev->optee_private, + MTK_VDEC_LAT0, OPTEE_DATA_INDEX); + else + vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler, + msg->vpu_inst_addr); vpu->inst_addr = msg->vpu_inst_addr; mtk_vdec_debug(vpu->ctx, "- vpu_inst_addr = 0x%x", vpu->inst_addr); From patchwork Mon Jan 29 06:30:17 2024 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: 193284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392714dyb; Sun, 28 Jan 2024 22:34:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFB/9yQlQHzFYzOMd2KMEKnayAb/0SY0RPKs5zbLYuEWcqPRmqTZO4VjjmelggA1z6wgCI X-Received: by 2002:a05:620a:4784:b0:783:dcee:77fe with SMTP id dt4-20020a05620a478400b00783dcee77femr5472599qkb.14.1706510079004; Sun, 28 Jan 2024 22:34:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510078; cv=pass; d=google.com; s=arc-20160816; b=ukaGZwFhJAW1ZFw43o5F+A/4U4EhvToUCFfBqt+eAtzWmTzO7se4jqWNI+N2rNZUWP E1XKRFtnTXGT19V5JG6ctS4bmcGrwxaxEeGgPkjSRYhVw1KvX1nzCFvIDuRJpgfLf0j0 X8S27z24E9YHpVIoPXJWfAFISzCXzhFmmlFMxo4xQZUQYKrYA+Bu7DxKvbIyKtwm8FRW 0gq8RreIHk6UAwCV5R5b952D8DpWLcO8eyT4Xkh/u6WuRZTu6qtldIL3sG1Dj6LwWiK7 hiSd4mTUJawMkMW5VQU4swAlYvE8DvAXhLLhAFaHMJmcSfUXqumZ5qE7E190hztm/m0E zZ4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=51VI1JkKQncCrOrUDLV94zJpq+Ll7EawPvLUuMJPvV4=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=P73FkW/UapTZjkO6cRFNBj46Z7p8zSdMKWtogdHXuZ6gxC9hCN1h6jh7J7GOayfnf9 uEQ81w/prnF4a1CB3ZgsHBPGvLGTn75RBHsl1TnxuQIbheKGN8fzJUqFX1St0crGjB0F K9M5wSTpdLxXKlSQRkNorxlLGD/A3mN8HUU5r9HXbAGh3tw6duu17MaW5ALNK8ezQEMC srk3nQqFklluDZcmuK/0J2YMkL3qodzLJIYfXyA5/qRbZOoQlD36Aeb0xtrPKJRs6cef HT8uYP7XqMOOb6x2iYwr2Ij/tztmwKwyWwtH2BAaNeJReP0z6giqsAAuQPg00cv7Fawg 4SYg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=pKDBtsTp; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42248-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42248-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x5-20020a05620a258500b00783ab5f86adsi7470588qko.265.2024.01.28.22.34.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:34:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42248-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=pKDBtsTp; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42248-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42248-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B902C1C22616 for ; Mon, 29 Jan 2024 06:34:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E36BB55E74; Mon, 29 Jan 2024 06:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="pKDBtsTp" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21CAD54F92; Mon, 29 Jan 2024 06:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509863; cv=none; b=MZa2p2G8G5IJsXl+nsloP+8LmzG9PFmgEMDfgL72RU9nz18Jo97jaLvGNKECy8IggLFqaGECl0XNo/d/eTvU2eFLT+c2ssLYVaZ3+TwgDNnI1NgN+GX3w/ukK0MEfpkmU54ZK1uE/hSB0qX9BW+GWwXCzxsh+1L/YIotid12LSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509863; c=relaxed/simple; bh=7T/zY2N/pch9MWNXDPUoohEbYacdECTWjMgbNRUQsZI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m9Hp2bd+Cc9z+SopnmjyuOBD8zjPlQfktFN6Oj0qqd6IyLkBeLbGIicGrp8wFyi14djTjoocD/+RI5Zz5YWyQdx2hOlNehygLF1Q0pVGkhmeVM4ISPQtuMrj/O0FiDEJ8jTkeBvzTfO6mvsfHR/4Yp8FFD+/RxhJHh6ECF5fYQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=pKDBtsTp; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f555ba54be6f11eea2298b7352fd921d-20240129 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=51VI1JkKQncCrOrUDLV94zJpq+Ll7EawPvLUuMJPvV4=; b=pKDBtsTpLu8enx7QlG+wDlwtB+pvA8hI5G1//CTtSubNqf/lUYhd9Qg0jY2Rs6nNLIS0Jrkw/Um7gy/JKGPsOK3otCTiOj2nUHg1y7jp9DsYRS8qGJFJrgAilXPqziZHwfFZTy6fMJEOiWkv8qEXt1oZZsNM4EEonKWp42A6Tys=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:bfaaba1b-68da-4f38-a778-8ad8686754ff,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:6e16cf4,CLOUDID:12d5dc7f-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f555ba54be6f11eea2298b7352fd921d-20240129 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 766245453; Mon, 29 Jan 2024 14:30:56 +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, 29 Jan 2024 14:30:54 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:53 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,14/22] media: mediatek: vcodec: Add capture format to support one plane memory Date: Mon, 29 Jan 2024 14:30:17 +0800 Message-ID: <20240129063025.29251-15-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405512607743086 X-GMAIL-MSGID: 1789405512607743086 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 273d83de2a87..315b906ed730 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -269,6 +269,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, { .format = V4L2_PIX_FMT_MT2110R, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 2, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, + { .format = V4L2_PIX_FMT_MS21, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 8, 0, 0 }, .block_h = { 32, 16, 0, 0 }}, /* YUV planar formats */ { .format = V4L2_PIX_FMT_NV12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 33076af4dfdb..c38b12511bdb 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 3e3f8d4b7c81..53a3c908fcba 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 Jan 29 06:30:18 2024 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: 193285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp392915dyb; Sun, 28 Jan 2024 22:35:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtDl9LnoT40c/OAFApTNlzxbP2AL4yZu9a4TfUf/UKYSNpIbamHZXHc7yirYE+P/5pJVA9 X-Received: by 2002:ac8:59c2:0:b0:42a:739d:a337 with SMTP id f2-20020ac859c2000000b0042a739da337mr6125625qtf.38.1706510122099; Sun, 28 Jan 2024 22:35:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510122; cv=pass; d=google.com; s=arc-20160816; b=gnvND54G0CKqqGu8193tjU/Z1bUpjULGEfuTVJpE++lukKwNL6nGn6JRYoALH+oj9M TEyB6cvaGJr01m3dC+Q61EGuPDgbnyiOiEj7DGCSBYo+E7U8cjwI6tLPHXIk/BtihyCq ZUgQ8hTDDsDO86iCPMVcFgl/jpm7VHj/qrWUbC6BuBj0QAtPKnX4YEbRA/0n+Jx1oEnH KPb4O9msnPU5qRwK7mkhaXfFItB+KD4IGbqlfJ08FbyeJGwbiTfoOrxx+dOeEI0EdBM7 xcV/OCsg3hnVNZyhzraYpOS1r2xOJOR70JgTDSTZrg3phpp3SbShzO8v/58DqVHcDX83 INCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RIQoT27GcYuuJ+QhfUoHjqOEFRPYloQJzRhu1bfSFyk=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=vz8JhyzSrckY9XGC8G4Ea/wBu2CotjuYUYtVQ7uK/6li88Sa+sUTTYt56xB+koUJGG qGEPoVRfw1u/bmde0UoMcVuZFMLqRfkesto/Z2Kv14mPfpoK9CuPmJ4yQQ6OprGelsUk 4SQuhAcbf3T+25Ua1PauRpzR53OyGEU4QIJ2UjRjINd1h5TeO3pU+YWK9ZCfP8MTmjPP 3TcIU6mNs9i9w8/uJw+TQTg9iY8y7tcczEDGXvohFsygnZt1v+GuO8+84aIJDxE7j/Wj Ph+GP6DIeDMMHf/+1h0KM8VoJT8iwsjw7SPf9EHvBGaIPFcU0X8IAhfe1TaRPAK9OvIN ea2g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=RBt2SaF4; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42251-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42251-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jv23-20020a05622aa09700b0042a8c12730fsi4405793qtb.89.2024.01.28.22.35.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:35:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42251-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=RBt2SaF4; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42251-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42251-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 378B41C23256 for ; Mon, 29 Jan 2024 06:35:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3650C56B8E; Mon, 29 Jan 2024 06:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="RBt2SaF4" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7BD155C3F; Mon, 29 Jan 2024 06:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509866; cv=none; b=SZ6YaIh3RSWQiYM0Akg9pe0nDP3Lwt45srNOTZf8k+7V953gMUyad/RxTTCL79IdIBrOhHdciMvY67dF1GLxgBSSWfmVmMnRzqM0F2petIhaC7s+yoRrcabKAanIDplOyQIvvHMJN9e6crso2L/i+MTXcGYtJLeK+YZHMrSQENw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509866; c=relaxed/simple; bh=CYznYMOomAPrga0MglS3xCj/dcAECK1NBl6/8hXKQOs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mBzGKOmf504GvkepdPxIeKQrn/39tcRNS2y0FJwErET+9Uw53oyLyD4SU6sPPM4a7MnNc6Rj7vcwAVNW11jGAoRJwPr7CGXW4rbv33zHC9AZchfpzdytqUJHHWsAWcQEuFWBrkT47RrYNt5JAxgOGbKR5xrJ7UHtHVRavB1xoQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=RBt2SaF4; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f6451cfcbe6f11eea2298b7352fd921d-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=RIQoT27GcYuuJ+QhfUoHjqOEFRPYloQJzRhu1bfSFyk=; b=RBt2SaF43ekmbOxBB5pVQBCiupegyT8L1GQTa7sXa68eyIOLOjaQe4fxQGhDU1WIONcMczBLnmMMl8N3w/XR3+9LSgoBESKBUMWos6v2bMczGsSDo5PWHkcTXG3/xB0+l33SURo6RGcLnN6O0Fg8UZj+6Ps1tfj1UFJnICVDfGM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:5e8cd2b6-4756-43c9-9a50-e2e15ea17989,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:6e16cf4,CLOUDID:9aa95c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f6451cfcbe6f11eea2298b7352fd921d-20240129 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 111755880; Mon, 29 Jan 2024 14:30:57 +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, 29 Jan 2024 14:30:56 +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, 29 Jan 2024 14:30:54 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,15/22] media: mediatek: vcodec: Add one plane format Date: Mon, 29 Jan 2024 14:30:18 +0800 Message-ID: <20240129063025.29251-16-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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--6.687000-8.000000 X-TMASE-MatchedRID: SJCrnFkDoFv1f6EBkUtKacu00lnG8+PWqQ9UezeTkThjHFhWIf8DgWb6 PphVtfZg1Bh8AQwURElq7k1NHAqvK9pkOfaFflnAdXu122+iJtqH7D1bP/FcOvHFoBcOsKezcam vz988laL3cuxjGnQlwIAy6p60ZV62SwOSQ/fMiOrdB/CxWTRRu25FeHtsUoHuAcFKPL0sGcRPy5 a1EU1tr466zVpODusNRGNNTyZV6iJoBmTSwRxjXg== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--6.687000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 69ADA67086B33733C482C43682C906382C2EE46B253CA828B12F16EF60EE0EEF2000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405557836623864 X-GMAIL-MSGID: 1789405557836623864 Adding capture formats to support V4L2_PIX_FMT_MS21. This format has one plane and only be used for secure video playback at current period. Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c | 4 +++- .../mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c index ba742f0e391d..604fdc8ee3ce 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -49,7 +49,9 @@ static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_dec_ctx *ctx, int format_inde num_frame_count++; } - if (num_frame_count == 1 || (!ctx->is_10bit_bitstream && fmt->fourcc == V4L2_PIX_FMT_MM21)) + if ((!ctx->is_10bit_bitstream && fmt->fourcc == V4L2_PIX_FMT_MM21) || + (ctx->is_secure_playback && fmt->fourcc == V4L2_PIX_FMT_MS21) || + num_frame_count == 1) return true; q_data = &ctx->q_data[MTK_Q_DATA_SRC]; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c index d54b3833790d..cc42c942eb8a 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -229,7 +229,7 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { #define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[9]; +static struct mtk_video_fmt mtk_video_formats[10]; static struct mtk_video_fmt default_out_format; static struct mtk_video_fmt default_cap_format; @@ -770,6 +770,11 @@ static void mtk_vcodec_add_formats(unsigned int fourcc, mtk_video_formats[count_formats].type = MTK_FMT_FRAME; mtk_video_formats[count_formats].num_planes = 2; break; + case V4L2_PIX_FMT_MS21: + mtk_video_formats[count_formats].fourcc = fourcc; + mtk_video_formats[count_formats].type = MTK_FMT_FRAME; + mtk_video_formats[count_formats].num_planes = 1; + break; default: mtk_v4l2_vdec_err(ctx, "Can not add unsupported format type"); return; @@ -798,6 +803,8 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_dec_ctx *ctx) cap_format_count++; } if (ctx->dev->dec_capability & MTK_VDEC_FORMAT_MM21) { + mtk_vcodec_add_formats(V4L2_PIX_FMT_MS21, ctx); + cap_format_count++; mtk_vcodec_add_formats(V4L2_PIX_FMT_MM21, ctx); cap_format_count++; } From patchwork Mon Jan 29 06:30:19 2024 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: 193287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393069dyb; Sun, 28 Jan 2024 22:35:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDS1zVZTIyEuKASMQ4U3iPCqQyN7VSE7P8+aBphjQQhO2QnJO2B9dFdjZFTE40bCbQWIUd X-Received: by 2002:a05:6358:d394:b0:178:7880:a52c with SMTP id mp20-20020a056358d39400b001787880a52cmr158048rwb.34.1706510159398; Sun, 28 Jan 2024 22:35:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510159; cv=pass; d=google.com; s=arc-20160816; b=JR31HLDBp2osQMFOdAPk6UtC9iE5+cmsKbo5A8lxRlSXlj770L9qbRJhv+JuWF4UGx WPyc6c14QSCESPNKMo0L5yjiwEPU4bWdsEXRny81WCoKPv/bWOjkszD93ySarpXJTIkI /9YMmgFJ1gBT87v8PT4+iqppS1JiTJvsj3fCly+U+4c8+khAUpV+RGA9lEmumrUFVOIK 6Twt6gXK7OiqhDezU7nWCmqfgpsdcs+967D/y9IjCz7CIrfv684mDcMzr6Zq12d1cQYy aLn13G2UYpAGG2G3YzQhkamMu4ihBNUxfrpX1oMg/nfEUO838C0hCtiIWoLnqbI1tS9O GG9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Cg9rhVDIUdOGy9/6TLSBnMKtmzezqEQOEQF3unbi4u8=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=d0ySXAbqQ4+gdDFxMN7UwYWHpm6U3EzQnqgrU2pQtLHq4Nw1xv2l79u6USNCwl8z/p leJqy3AFYdEkBl5JXvaMk+OBtRqG0Q0qk3isyNU+QnuYUdWpWkDSB/7BejE83P3yFFOC CsRYHT7R6PTgxhI3bENkeXRyjxAP9G8AQus4GLh5mNOZz0GX/SunTp3Wz5moKm7lBrKN /JfrIToE+ytYNwEII+IkoTJXiZm2/VOYjgqSllX2cpZZ4tyHwNbOgLTB1oG48Shv+a1Y ZP+FOzRmDyZOZobP4eZA8JkV3yUCVufSCPDFhfNS/s1s8VYNKZAfKqY8S5Z5NW2ITnR3 43CA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UrPGzwAg; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42250-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42250-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h7-20020a17090aa88700b0028bc1118b64si7254930pjq.66.2024.01.28.22.35.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:35:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42250-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=UrPGzwAg; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42250-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42250-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id ED98AB22F3C for ; Mon, 29 Jan 2024 06:35:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77C5556748; Mon, 29 Jan 2024 06:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="UrPGzwAg" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4999155780; Mon, 29 Jan 2024 06:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509865; cv=none; b=A8+7qmvw1u19ZtLalW4boU9MOq5QXnJbBI8XAaT2YhYkULA2/aEaCzC/LWNVefNtDsg+ilDGZXMFm70ugioQ9ubGCmW1oxbaT01P+IaL5+3UkWbQ1ooL3hZykECFqVtCLuW0b4HC6SJxmy8mDsv3S4o3FVHvNuR1Q3+sZkA4cgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509865; c=relaxed/simple; bh=eIM8Q/xzmdqYu+7En/WYcJOSOwwQSsbkWpRqxWYQBqE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bffuq19jtOZyi/6sMlANuHCdBZA8R9QNLEZh1kmHoxLl0wEjuqx05LJKhQ5q3tTBvYftbd5ALN+AOA+95dgUsvHkAsfs7cswR8PV81tklESh//eQuAoAAH30fs4wHq300kPBSbmXWMhd3LjJjAboroyYwIvAwmq5IMdGLChxi2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=UrPGzwAg; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f708a94cbe6f11ee9e680517dc993faa-20240129 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=Cg9rhVDIUdOGy9/6TLSBnMKtmzezqEQOEQF3unbi4u8=; b=UrPGzwAgdAxvRVdFstriWFh0ZO0NP3M985fqXB+u9bDe4Bx5A/mShSGf2gcUkyK1VkKzC1h3qCjrx5BqAuBzNPP+kUBN2Hn6/0z0n1uTmIxNXOjzXmeLqyeUqsUCGbC38HJ3zG27X02B02MwpxotSWlW2EzS2qBjUnLQzULoJMg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:e86e98fd-196f-4206-a83c-500989dc1a04,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:6e16cf4,CLOUDID:92a95c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES :1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: f708a94cbe6f11ee9e680517dc993faa-20240129 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 1070610159; Mon, 29 Jan 2024 14:30:59 +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, 29 Jan 2024 14:30:57 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:56 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,16/22] media: mediatek: vcodec: support one plane capture buffer Date: Mon, 29 Jan 2024 14:30:19 +0800 Message-ID: <20240129063025.29251-17-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.238200-8.000000 X-TMASE-MatchedRID: IdwiQWGfGmyON+GapO42vQI0yP/uoH+Dh+w9Wz/xXDr7efdnqtsaE5kC erFMaabilTJXKqh1ne29cOdjc/43lUMpVZZsZyZGHPYwOJi6PLmBHKTJ+sfXGfNhzIgXtFJVJkA T6PZqtWG0gVrq9RizuWF6wLzbAtAr7U4NkBX42MYQ9/tMNQ4aiuWNJG9IamrcGM7yl/HgfuBLbT Uf+O4SvG0xs/kJ5jkfbhGQTDKMjW9sQJ9Z3jpPTZ4CIKY/Hg3AGdQnQSTrKGPEQdG7H66TyMdRT 5TQAJnA56FLyMh+oymI9bcjcLbWqxAoGrvafT2017miKbd1tCqeqD9WtJkSIw== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.238200-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: C2A0D557D206DC74E4C049EF483DD9C943FB0F938B741967A4F6ACCA7EFFA2032000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405596800317645 X-GMAIL-MSGID: 1789405596800317645 The capture buffer has two planes for format MM21, but user space only allocate secure memory for plane[0], and the size is Y data + uv data. The driver need to support one plane decoder for svp mode. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 7 ++++- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 26 ++++++++++--------- .../decoder/vdec/vdec_h264_req_common.c | 18 ++++++------- .../mediatek/vcodec/decoder/vdec_drv_if.c | 4 +-- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c index 604fdc8ee3ce..5d876a31e566 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -653,7 +653,12 @@ static int vidioc_vdec_g_fmt(struct file *file, void *priv, * So we just return picinfo yet, and update picinfo in * stop_streaming hook function */ - q_data->sizeimage[0] = ctx->picinfo.fb_sz[0]; + + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1 || ctx->is_secure_playback) + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + else + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0]; + q_data->sizeimage[1] = ctx->picinfo.fb_sz[1]; q_data->bytesperline[0] = ctx->last_decoded_picinfo.buf_w; q_data->bytesperline[1] = ctx->last_decoded_picinfo.buf_w; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c index cc42c942eb8a..707ed57a412e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -285,14 +285,14 @@ static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx) framebuf = container_of(vb2_v4l2, struct mtk_video_dec_buf, m2m_buf.vb); pfb = &framebuf->frame_buffer; - pfb->base_y.va = vb2_plane_vaddr(dst_buf, 0); + if (!ctx->is_secure_playback) + pfb->base_y.va = vb2_plane_vaddr(dst_buf, 0); pfb->base_y.dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0); pfb->base_y.size = ctx->q_data[MTK_Q_DATA_DST].sizeimage[0]; - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2 && !ctx->is_secure_playback) { pfb->base_c.va = vb2_plane_vaddr(dst_buf, 1); - pfb->base_c.dma_addr = - vb2_dma_contig_plane_dma_addr(dst_buf, 1); + pfb->base_c.dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 1); pfb->base_c.size = ctx->q_data[MTK_Q_DATA_DST].sizeimage[1]; } mtk_v4l2_vdec_dbg(1, ctx, @@ -339,16 +339,18 @@ static void mtk_vdec_worker(struct work_struct *work) mtk_v4l2_vdec_dbg(3, ctx, "[%d] (%d) id=%d, vb=%p", ctx->id, vb2_src->vb2_queue->type, vb2_src->index, vb2_src); - bs_src->va = vb2_plane_vaddr(vb2_src, 0); - bs_src->dma_addr = vb2_dma_contig_plane_dma_addr(vb2_src, 0); - bs_src->size = (size_t)vb2_src->planes[0].bytesused; - if (!bs_src->va) { - v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); - mtk_v4l2_vdec_err(ctx, "[%d] id=%d source buffer is NULL", ctx->id, - vb2_src->index); - return; + if (!ctx->is_secure_playback) { + bs_src->va = vb2_plane_vaddr(vb2_src, 0); + if (!bs_src->va) { + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); + mtk_v4l2_vdec_err(ctx, "[%d] id=%d source buffer is NULL", ctx->id, + vb2_src->index); + return; + } } + bs_src->dma_addr = vb2_dma_contig_plane_dma_addr(vb2_src, 0); + bs_src->size = (size_t)vb2_src->planes[0].bytesused; mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p", ctx->id, bs_src->va, &bs_src->dma_addr, bs_src->size, vb2_src); /* Apply request controls. */ diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c index 5ca20d75dc8e..5e0d55218363 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.c @@ -79,15 +79,15 @@ void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx, vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); h264_dpb_info[index].field = vb2_v4l2->field; - h264_dpb_info[index].y_dma_addr = - vb2_dma_contig_plane_dma_addr(vb, 0); - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) - h264_dpb_info[index].c_dma_addr = - vb2_dma_contig_plane_dma_addr(vb, 1); - else - h264_dpb_info[index].c_dma_addr = - h264_dpb_info[index].y_dma_addr + - ctx->picinfo.fb_sz[0]; + h264_dpb_info[index].y_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0); + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) + h264_dpb_info[index].c_dma_addr = + vb2_dma_contig_plane_dma_addr(vb, 1); + else + h264_dpb_info[index].c_dma_addr = + h264_dpb_info[index].y_dma_addr + ctx->picinfo.fb_sz[0]; + } } } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c index d0b459b1603f..fb3e4f75ed93 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_drv_if.c @@ -73,14 +73,14 @@ int vdec_if_decode(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_mem *bs, { int ret = 0; - if (bs) { + if (bs && !ctx->is_secure_playback) { if ((bs->dma_addr & 63) != 0) { mtk_v4l2_vdec_err(ctx, "bs dma_addr should 64 byte align"); return -EINVAL; } } - if (fb) { + if (fb && !ctx->is_secure_playback) { if (((fb->base_y.dma_addr & 511) != 0) || ((fb->base_c.dma_addr & 511) != 0)) { mtk_v4l2_vdec_err(ctx, "frame buffer dma_addr should 512 byte align"); From patchwork Mon Jan 29 06:30:20 2024 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: 193289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393098dyb; Sun, 28 Jan 2024 22:36:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVk8/YW5KTdQXBO98TT6SNTEuN19khjUIqeQhW/M5wkIUW6C3cSgJk7/BxFX0IjbRIBYZd X-Received: by 2002:a25:9012:0:b0:dc6:5114:f878 with SMTP id s18-20020a259012000000b00dc65114f878mr2048769ybl.12.1706510167197; Sun, 28 Jan 2024 22:36:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510167; cv=pass; d=google.com; s=arc-20160816; b=xxZ6EYJIgz5DkFjE/yJqhJvejEyhZiobjYdLhMD5FMNE1NifiOy7r0amHCtnZ1cVHr /v2Tzzi316+kn33/jHTFcTQG1gF24S03JvM6DbYqFKqtx8fyXeCjwmrqiaGqjiFY6Ngg fa+/Ka8Lq3wlTdbY7xADgihukshOa3k96yNgyy9fGNu2K1HDg+F8sJ9E6M4JEt+vdTWO kYTpV22mjrhzpOWzg/qKjFy/6ke1VuRPkrNDNsVzNHzQLExJ7UrGvb/DxyI+egl90QCz ZhFSVvVM8jvIh17yp47tOy+sJ8SZXf+84ys1LlCVvPvp+p5Knsp504TofMTsKoOgWdyX MaPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oCz9ePgPpwTLEOdOqoCI8QwgUoj21cKcR2CQD3pJoR8=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=uMTD+FSIMN5uaQJPp8Qz61blbYE7H5WpZo1Tn23Uh/COwD3sjHwuoD4kXz6fXNweic rghCEf3fdGazQ1R71wPnKT73u/Mvh8CaiNasdFK0SxWhw+F0IpTXR2BEIZNwIFfL8mvr DhwiKdSQBFssqCUev10EALrgV/O2J/vMz6+sq6oqqZd20XsQInmWBespYlyQ19Q6y30Z jQ+L8+EBT5RmdCo032ETO+RRWWXh+J10yOgkAAtsMwQh/hv5MQbopTjQf3rqdxEx3zLN 6UcwkNTVwCQegfl//suhgW9uyPldIgCr3NiWXoi/8t0S3+6J7WH7D7tmdF8P8UQ/o9tS MsUA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=IQu0Q6h1; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42252-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42252-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ck27-20020a056a02091b00b005c680fbab22si5283662pgb.509.2024.01.28.22.36.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:36:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42252-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=IQu0Q6h1; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42252-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42252-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D159B281AE2 for ; Mon, 29 Jan 2024 06:36:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0407B58AA6; Mon, 29 Jan 2024 06:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="IQu0Q6h1" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D23E155E57; Mon, 29 Jan 2024 06:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509868; cv=none; b=QvDfwvShkvC9PMAgRIEwFyKqEUCH3+QEDrlkvm+gkE6kS3qmQ7CoEP1MMSOGXwex2jruuurufp/q28+vEW/ouTz2lRJ9IgX4IY0BC4zQyhj1GA4kSRTmJf2h2tmBwJgwkls+oZ+h4pCSrrqh5jwyzFzQ6Mk3LpNYMlnvBY9A/8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509868; c=relaxed/simple; bh=8FRwZNRXhFXBiDEOf3249mShrkGmajgmGLGTApW0M+0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V0nEuQz7h5DyGMXcNec6+/j1oUaRSP0DF6fMMF8Laf7m0gWfCIQl2Q9H190lfZyV5i4hJeXV5bG8V7uRUmAShdQwoO/1nrY2wd5ZL1aZ2hwRSi7kxILCJRsD3RYraGlsszhnUFjU2Y3us7iDKKl4NZlAgWnloXSHH7sAbEygNvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=IQu0Q6h1; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f7bc6dd8be6f11ee9e680517dc993faa-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=oCz9ePgPpwTLEOdOqoCI8QwgUoj21cKcR2CQD3pJoR8=; b=IQu0Q6h1QMSuGrc6yD4qZSGyPlaJr/kIqpSsCWGNC3M4BpGt7zAGA9ysY4bR8w3OTU2lJK85YOOHrN4k+7RXzvPKm9EMdzO178wifxyzLF5w7v6F6a+pdOVuDvq1oCAVAoLp6SXTF05LFhXuI7hhQQ7k6haeDd+NqarzM/0I+MU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:da3b0b73-ea4d-46f3-9368-2183a5566e99,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:6e16cf4,CLOUDID:b6b6c38e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f7bc6dd8be6f11ee9e680517dc993faa-20240129 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 279262230; Mon, 29 Jan 2024 14:31:00 +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, 29 Jan 2024 14:30:58 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:57 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,17/22] media: mediatek: vcodec: re-construct h264 driver to support svp mode Date: Mon, 29 Jan 2024 14:30:20 +0800 Message-ID: <20240129063025.29251-18-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405604987469940 X-GMAIL-MSGID: 1789405604987469940 Need secure buffer size to convert secure handle to secure pa in optee-os, re-construct the vsi struct to store each secure buffer size. Separate svp and normal wait interrupt condition for svp mode waiting hardware interrupt in optee-os. Signed-off-by: Yunfei Dong --- .../decoder/vdec/vdec_h264_req_multi_if.c | 261 +++++++++++------- .../mediatek/vcodec/decoder/vdec_msg_queue.c | 9 +- 2 files changed, 168 insertions(+), 102 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 4967e0f0984d..a1a68487131c 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -60,14 +60,36 @@ struct vdec_h264_slice_lat_dec_param { * @crc: Used to check whether hardware's status is right */ struct vdec_h264_slice_info { + u64 wdma_end_addr_offset; u16 nal_info; u16 timeout; - u32 bs_buf_size; - u64 bs_buf_addr; - u64 y_fb_dma; - u64 c_fb_dma; u64 vdec_fb_va; u32 crc[8]; + u32 reserved; +}; + +/* + * struct vdec_h264_slice_mem - memory address and size + */ +struct vdec_h264_slice_mem { + union { + u64 buf; + u64 dma_addr; + }; + union { + size_t size; + u64 dma_addr_end; + }; +}; + +/** + * struct vdec_h264_slice_fb - frame buffer for decoding + * @y: current y buffer address info + * @c: current c buffer address info + */ +struct vdec_h264_slice_fb { + struct vdec_h264_slice_mem y; + struct vdec_h264_slice_mem c; }; /** @@ -92,18 +114,16 @@ struct vdec_h264_slice_info { */ struct vdec_h264_slice_vsi { /* LAT dec addr */ - u64 wdma_err_addr; - u64 wdma_start_addr; - u64 wdma_end_addr; - u64 slice_bc_start_addr; - u64 slice_bc_end_addr; - u64 row_info_start_addr; - u64 row_info_end_addr; - u64 trans_start; - u64 trans_end; - u64 wdma_end_addr_offset; + struct vdec_h264_slice_mem bs; + struct vdec_h264_slice_fb fb; - u64 mv_buf_dma[H264_MAX_MV_NUM]; + struct vdec_h264_slice_mem ube; + struct vdec_h264_slice_mem trans; + struct vdec_h264_slice_mem row_info; + struct vdec_h264_slice_mem err_map; + struct vdec_h264_slice_mem slice_bc; + + struct vdec_h264_slice_mem mv_buf_dma[H264_MAX_MV_NUM]; struct vdec_h264_slice_info dec; struct vdec_h264_slice_lat_dec_param h264_slice_params; }; @@ -392,6 +412,100 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, cr->left, cr->top, cr->width, cr->height); } +static void vdec_h264_slice_setup_lat_buffer(struct vdec_h264_slice_inst *inst, + struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf) +{ + struct mtk_vcodec_mem *mem; + int i; + + inst->vsi->bs.dma_addr = (u64)bs->dma_addr; + inst->vsi->bs.size = bs->size; + + for (i = 0; i < H264_MAX_MV_NUM; i++) { + mem = &inst->mv_buf[i]; + inst->vsi->mv_buf_dma[i].dma_addr = mem->dma_addr; + inst->vsi->mv_buf_dma[i].size = mem->size; + } + inst->vsi->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + inst->vsi->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + + inst->vsi->row_info.dma_addr = 0; + inst->vsi->row_info.size = 0; + + inst->vsi->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + inst->vsi->err_map.size = lat_buf->wdma_err_addr.size; + + inst->vsi->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr; + inst->vsi->slice_bc.size = lat_buf->slice_bc_addr.size; + + inst->vsi->trans.dma_addr_end = inst->ctx->msg_queue.wdma_rptr_addr; + inst->vsi->trans.dma_addr = inst->ctx->msg_queue.wdma_wptr_addr; +} + +static int vdec_h264_slice_setup_core_buffer(struct vdec_h264_slice_inst *inst, + struct vdec_h264_slice_share_info *share_info, + struct vdec_lat_buf *lat_buf) +{ + struct mtk_vcodec_mem *mem; + struct mtk_vcodec_dec_ctx *ctx = inst->ctx; + struct vb2_v4l2_buffer *vb2_v4l2; + struct vdec_fb *fb; + u64 y_fb_dma, c_fb_dma = 0; + int i; + + fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx); + if (!fb) { + mtk_vdec_err(ctx, "fb buffer is NULL"); + return -EBUSY; + } + + y_fb_dma = (u64)fb->base_y.dma_addr; + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) + c_fb_dma = + y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; + else + c_fb_dma = (u64)fb->base_c.dma_addr; + } + + mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma); + + inst->vsi_core->fb.y.dma_addr = y_fb_dma; + inst->vsi_core->fb.y.size = ctx->picinfo.fb_sz[0]; + inst->vsi_core->fb.c.dma_addr = c_fb_dma; + inst->vsi_core->fb.c.size = ctx->picinfo.fb_sz[1]; + + inst->vsi_core->dec.vdec_fb_va = (unsigned long)fb; + inst->vsi_core->dec.nal_info = share_info->nal_info; + + inst->vsi_core->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + inst->vsi_core->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + + inst->vsi_core->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + inst->vsi_core->err_map.size = lat_buf->wdma_err_addr.size; + + inst->vsi_core->slice_bc.dma_addr = lat_buf->slice_bc_addr.dma_addr; + inst->vsi_core->slice_bc.size = lat_buf->slice_bc_addr.size; + + inst->vsi_core->row_info.dma_addr = 0; + inst->vsi_core->row_info.size = 0; + + inst->vsi_core->trans.dma_addr = share_info->trans_start; + inst->vsi_core->trans.dma_addr_end = share_info->trans_end; + + for (i = 0; i < H264_MAX_MV_NUM; i++) { + mem = &inst->mv_buf[i]; + inst->vsi_core->mv_buf_dma[i].dma_addr = mem->dma_addr; + inst->vsi_core->mv_buf_dma[i].size = mem->size; + } + + vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); + v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true); + + return 0; +} + static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx) { struct vdec_h264_slice_inst *inst; @@ -457,64 +571,22 @@ static void vdec_h264_slice_deinit(void *h_vdec) static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) { - struct vdec_fb *fb; - u64 vdec_fb_va; - u64 y_fb_dma, c_fb_dma; - int err, timeout, i; + int err, timeout; struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx; struct vdec_h264_slice_inst *inst = ctx->drv_handle; - struct vb2_v4l2_buffer *vb2_v4l2; struct vdec_h264_slice_share_info *share_info = lat_buf->private_data; - struct mtk_vcodec_mem *mem; struct vdec_vpu_inst *vpu = &inst->vpu; mtk_vdec_debug(ctx, "[h264-core] vdec_h264 core decode"); memcpy(&inst->vsi_core->h264_slice_params, &share_info->h264_slice_params, sizeof(share_info->h264_slice_params)); - fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx); - if (!fb) { - err = -EBUSY; - mtk_vdec_err(ctx, "fb buffer is NULL"); + err = vdec_h264_slice_setup_core_buffer(inst, share_info, lat_buf); + if (err) goto vdec_dec_end; - } - - vdec_fb_va = (unsigned long)fb; - y_fb_dma = (u64)fb->base_y.dma_addr; - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) - c_fb_dma = - y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; - else - c_fb_dma = (u64)fb->base_c.dma_addr; - - mtk_vdec_debug(ctx, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma); - - inst->vsi_core->dec.y_fb_dma = y_fb_dma; - inst->vsi_core->dec.c_fb_dma = c_fb_dma; - inst->vsi_core->dec.vdec_fb_va = vdec_fb_va; - inst->vsi_core->dec.nal_info = share_info->nal_info; - inst->vsi_core->wdma_start_addr = - lat_buf->ctx->msg_queue.wdma_addr.dma_addr; - inst->vsi_core->wdma_end_addr = - lat_buf->ctx->msg_queue.wdma_addr.dma_addr + - lat_buf->ctx->msg_queue.wdma_addr.size; - inst->vsi_core->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr; - inst->vsi_core->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr; - inst->vsi_core->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr + - lat_buf->slice_bc_addr.size; - inst->vsi_core->trans_start = share_info->trans_start; - inst->vsi_core->trans_end = share_info->trans_end; - for (i = 0; i < H264_MAX_MV_NUM; i++) { - mem = &inst->mv_buf[i]; - inst->vsi_core->mv_buf_dma[i] = mem->dma_addr; - } - - vb2_v4l2 = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); - v4l2_m2m_buf_copy_metadata(&lat_buf->ts_info, vb2_v4l2, true); vdec_h264_slice_fill_decode_reflist(inst, &inst->vsi_core->h264_slice_params, share_info); - err = vpu_dec_core(vpu); if (err) { mtk_vdec_err(ctx, "core decode err=%d", err); @@ -573,12 +645,11 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_h264_slice_inst *inst = h_vdec; struct vdec_vpu_inst *vpu = &inst->vpu; struct mtk_video_dec_buf *src_buf_info; - int nal_start_idx, err, timeout = 0, i; + int nal_start_idx, err, timeout = 0; unsigned int data[2]; struct vdec_lat_buf *lat_buf; struct vdec_h264_slice_share_info *share_info; unsigned char *buf; - struct mtk_vcodec_mem *mem; if (vdec_msg_queue_init(&inst->ctx->msg_queue, inst->ctx, vdec_h264_slice_core_decode, @@ -617,11 +688,9 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, if (err) goto err_free_fb_out; - vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size, - &share_info->h264_slice_params.pps); - - inst->vsi->dec.bs_buf_addr = (uint64_t)bs->dma_addr; - inst->vsi->dec.bs_buf_size = bs->size; + if (!inst->ctx->is_secure_playback) + vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size, + &share_info->h264_slice_params.pps); *res_chg = inst->resolution_changed; if (inst->resolution_changed) { @@ -634,38 +703,27 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, } inst->resolution_changed = false; } - for (i = 0; i < H264_MAX_MV_NUM; i++) { - mem = &inst->mv_buf[i]; - inst->vsi->mv_buf_dma[i] = mem->dma_addr; - } - inst->vsi->wdma_start_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; - inst->vsi->wdma_end_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr + - lat_buf->ctx->msg_queue.wdma_addr.size; - inst->vsi->wdma_err_addr = lat_buf->wdma_err_addr.dma_addr; - inst->vsi->slice_bc_start_addr = lat_buf->slice_bc_addr.dma_addr; - inst->vsi->slice_bc_end_addr = lat_buf->slice_bc_addr.dma_addr + - lat_buf->slice_bc_addr.size; - - inst->vsi->trans_end = inst->ctx->msg_queue.wdma_rptr_addr; - inst->vsi->trans_start = inst->ctx->msg_queue.wdma_wptr_addr; - mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%llx) err:0x%llx", - inst->vsi->wdma_start_addr, - inst->vsi->wdma_end_addr, - inst->vsi->wdma_err_addr); - - mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%llx) rprt((0x%llx 0x%llx))", - inst->vsi->slice_bc_start_addr, - inst->vsi->slice_bc_end_addr, - inst->vsi->trans_start, - inst->vsi->trans_end); + + vdec_h264_slice_setup_lat_buffer(inst, bs, lat_buf); + mtk_vdec_debug(inst->ctx, "lat:trans(0x%llx 0x%lx) err:0x%llx", + inst->vsi->ube.dma_addr, (unsigned long)inst->vsi->ube.size, + inst->vsi->err_map.dma_addr); + + mtk_vdec_debug(inst->ctx, "slice(0x%llx 0x%lx) rprt((0x%llx 0x%llx))", + inst->vsi->slice_bc.dma_addr, (unsigned long)inst->vsi->slice_bc.size, + inst->vsi->trans.dma_addr, inst->vsi->trans.dma_addr_end); err = vpu_dec_start(vpu, data, 2); if (err) { mtk_vdec_debug(inst->ctx, "lat decode err: %d", err); goto err_free_fb_out; } - share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + - inst->vsi->wdma_end_addr_offset; + if (inst->ctx->is_secure_playback) + share_info->trans_end = inst->vsi->dec.wdma_end_addr_offset; + else + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + inst->vsi->dec.wdma_end_addr_offset; + share_info->trans_start = inst->ctx->msg_queue.wdma_wptr_addr; share_info->nal_info = inst->vsi->dec.nal_info; @@ -691,8 +749,11 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, return -EINVAL; } - share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + - inst->vsi->wdma_end_addr_offset; + if (inst->ctx->is_secure_playback) + share_info->trans_end = inst->vsi->dec.wdma_end_addr_offset; + else + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + inst->vsi->dec.wdma_end_addr_offset; vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue, share_info->trans_end); if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) { @@ -737,10 +798,10 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs mtk_vdec_debug(inst->ctx, "[h264-dec] [%d] y_dma=%llx c_dma=%llx", inst->ctx->decoded_frame_cnt, y_fb_dma, c_fb_dma); - inst->vsi_ctx.dec.bs_buf_addr = (u64)bs->dma_addr; - inst->vsi_ctx.dec.bs_buf_size = bs->size; - inst->vsi_ctx.dec.y_fb_dma = y_fb_dma; - inst->vsi_ctx.dec.c_fb_dma = c_fb_dma; + inst->vsi_ctx.bs.dma_addr = (u64)bs->dma_addr; + inst->vsi_ctx.bs.size = bs->size; + inst->vsi_ctx.fb.y.dma_addr = y_fb_dma; + inst->vsi_ctx.fb.c.dma_addr = c_fb_dma; inst->vsi_ctx.dec.vdec_fb_va = (u64)(uintptr_t)fb; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, @@ -770,7 +831,7 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs for (i = 0; i < H264_MAX_MV_NUM; i++) { mem = &inst->mv_buf[i]; - inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr; + inst->vsi_ctx.mv_buf_dma[i].dma_addr = mem->dma_addr; } } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c index f283c4703dc6..c1310176ae05 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.c @@ -308,8 +308,13 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, msg_queue->wdma_addr.size = 0; return -ENOMEM; } - msg_queue->wdma_rptr_addr = msg_queue->wdma_addr.dma_addr; - msg_queue->wdma_wptr_addr = msg_queue->wdma_addr.dma_addr; + if (ctx->is_secure_playback) { + msg_queue->wdma_rptr_addr = 0; + msg_queue->wdma_wptr_addr = 0; + } else { + msg_queue->wdma_rptr_addr = msg_queue->wdma_addr.dma_addr; + msg_queue->wdma_wptr_addr = msg_queue->wdma_addr.dma_addr; + } msg_queue->empty_lat_buf.ctx = ctx; msg_queue->empty_lat_buf.core_decode = NULL; From patchwork Mon Jan 29 06:30:21 2024 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: 193286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393031dyb; Sun, 28 Jan 2024 22:35:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSnQrbLX2kEP0tuZoDHKEj4oxNXVFLxYSzBeT7VNETW8WjKABG1QbpcYadARMbSFHHrOON X-Received: by 2002:ac8:5e0e:0:b0:42a:a95a:afcd with SMTP id h14-20020ac85e0e000000b0042aa95aafcdmr618524qtx.50.1706510149132; Sun, 28 Jan 2024 22:35:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510149; cv=pass; d=google.com; s=arc-20160816; b=M1tQr3ONmbXr0OmVRu1IOt5Xfqg8GfwZDKz+X79KDafGqiverRT1wGKDN60XWE4wK/ JUz7pYfGk3Lm2Euyo7aU1fDXuKQgSPJnaPytERkK12tNNhf9mj59OYd3Jwuwa16D2MRu crDBCbmUSeoyqzv3G9ANgfAbaoW4KfYQ2493bu17t1uUL7E31Z6yr9+4cfYkNyDGDew5 QBzJ675iJ8+Fa73My299BjtfHJBqPud1E6B5yPv59qi6so+9j6a9rmINqxoqJxI2FNyZ u3iWi6vPNB8U2wWvSqyQpPBxXi5TGGLRCechGqD5x9YDD/h3BXTXtq+dIDyBuopklCz/ kvKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tDdbTuWdtMHx44dMsP7Vdfz0hNjFshKJXaC0iWiaF9M=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=BXNeddLofxQ4GTKdhx/3preRFlnZGfqVgy46tJkvaHLgE7og3kbXdxqujbAyrHxO0D JaMH98In8ypdjgYEqkgSgb+/IC1TCyxoEY3b6Kd29TFSSQu3bCA18oAhidXkX7gp/FKr BdMvSDbt06TYSpWYYehIjYpIQHSHpq0OJj4CPdrUJucsXWqP/8n7c4V93QdU8ksSANWT bb+YfhzqmC13/9MNRBfW+vnGlJ16NxCfGU2zhsWOQ8+nBVeY9PN9JWZpZ5J1X5q8vv4k 5eIPx78d9NLdrjW3/DKRPbsa2zP5NZw/UDT72ronfWmGxW51DofQPXtohoBf6RUDG33J PpBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=kAwNqxGO; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42254-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42254-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i19-20020ac85e53000000b00429a50c4264si6963154qtx.619.2024.01.28.22.35.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:35:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42254-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=kAwNqxGO; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42254-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42254-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E71C01C20E7A for ; Mon, 29 Jan 2024 06:35:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A34D58132; Mon, 29 Jan 2024 06:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="kAwNqxGO" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C2DF56445; Mon, 29 Jan 2024 06:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509869; cv=none; b=IQ3ipYXrsclQOzrllhcAFd1L36Sdyppd+kri655WkXtDdJnI4kI2i5VJ/YYKzjC5gKHdx8UQWNEDlf1yaI8IWvRxgyA6JpyLcePjwGZhLzbVX0iuYhX6eFk7JatRcEBjBz0ZPJs0OoRLf19sfvAz9cl/ABEnBos2ZKe7NVSsAg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509869; c=relaxed/simple; bh=WiIjUCF8+rFVH1JAGZb99ANWCjBV8LC91Gu6iOjZLds=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JAHnRP6Z46zrLyBXHJm5LT94hAcvuSjdKRdt/Sy1pzGScS6yG0bNq3NO0t+mNeorQTV1Ri3pai2lDC9132hxDW2lmuXdbLW0l6vh2ZR/nxIEcerNf5pWe1eZqjpwKe6bcomfYDLM8WwHSm7CKJqJ+AYausYH5LMunFS1tI3be+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=kAwNqxGO; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f8849be6be6f11eea2298b7352fd921d-20240129 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=kAwNqxGO6H/jjheOphrZ1Ne6f7lx1t1CPZngkccM0nw41xTalJqmQ1z1U1l1MuufggpOPx3Uvhj2LppBcPjUByp2WA1iqtSsEw4SY3HnQZEZY2auiSAOSw3LYujNnVGGwP/26SZqb/OXsxiM8T8u8aqEv5PB8Xiafw7U4pXPvj8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:2c19284c-04cb-4681-8e21-7f01cae06b5d,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:6e16cf4,CLOUDID:2ed141fe-c16b-4159-a099-3b9d0558e447,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f8849be6be6f11eea2298b7352fd921d-20240129 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 487120532; Mon, 29 Jan 2024 14:31:01 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:31:00 +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, 29 Jan 2024 14:30:58 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,18/22] media: mediatek: vcodec: remove parse nal_info in kernel Date: Mon, 29 Jan 2024 14:30:21 +0800 Message-ID: <20240129063025.29251-19-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405585718668914 X-GMAIL-MSGID: 1789405585718668914 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 Jan 29 06:30:22 2024 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: 193291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393183dyb; Sun, 28 Jan 2024 22:36:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFacDi9l+/KBnDKfNNdMy40v3JM1w6GnbKrVow/8V396QUqgR6j14EQLKCPJ9DbhH0GbvrY X-Received: by 2002:a05:6359:3097:b0:175:5bd4:f418 with SMTP id rg23-20020a056359309700b001755bd4f418mr3746854rwb.65.1706510182614; Sun, 28 Jan 2024 22:36:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510182; cv=pass; d=google.com; s=arc-20160816; b=pfZtaaOKoMyp2wcF8PD0jiPJJe4YMvyhxVJ11IjnWs0GyRa+7KmLWIq4JUcuIiN4Ch mAncIp5lPzdGsP7MvqYekYTM30gSXI1Z6BWbFYGLDFd1fG+NJNKZDKn6kKzXK3WNsVpr jthLuwwgMEqO9T840TSmWEs+0jOFTgx2/V2h8RBDn4BuITKGvdcbQdlN32MhLGJ+c8TL S5hanre8blSBnTKr4A5abkWFMptjBixcnxjpnfDgn2wauDp8JVzPOnWXjseJZ4q4vsfX wnUUVJQd5+vZbrIrgDKnRSvRcX6vorwRfFrkMu1+Erju0Grh3yFgSco3l3hJG88GawyO FReg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oUOfVeRKnJ1zcg5WgLZGiIN5J1sZ37QJ5q0Qif+5X/Q=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=s2jLfkADwCXFR+d68J7fhzqKpuZ31qz4rGEIYgkJHsqHI4b0x+JDtNVvJ04BRjDf3r YGVbfoqxjUjE6KAcjU7vibHepCT15Md7mKMtCf9BnWgqM08IRg+Vw+tCyBDTqAdiUvjp 6EdFi/mEeqRdC3zjyhEAhjdLHlZ4FSd5GtVpC8/uFr1nVBNX0BUctKxvU+2ALBPSByaA skR42wNSIKCL5OY7AqG8nBMRwVM5TuP95F1q+GZtVe6Toh4C19V4P/Vc90hiQPOX0kPE /kBw9vtrpvBC9nsZ5CO6OgzXCVVfw/4FD8p1RZB/W8ELZL5VkORF5FJ1Kma0gzrbEkkt n3fw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cF8FVmcf; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42253-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42253-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h5-20020a170902f2c500b001d8d6953f54si1612459plc.631.2024.01.28.22.36.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:36:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42253-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cF8FVmcf; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42253-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42253-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 55FEDB21002 for ; Mon, 29 Jan 2024 06:35:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C598C58208; Mon, 29 Jan 2024 06:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="cF8FVmcf" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C3A755E6B; Mon, 29 Jan 2024 06:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509868; cv=none; b=Pn66L8IkuiRkZQNZkrUUT1LM45qLOWedmWjfsebnj1GQoXE1mNG5aVNZXgkUEer4a3LS989ruPZhQSk8GWOguZykzjI0sKRITtZWtBcBXVpqBWbX+Lrv9DVWs6gJt2M6Ny1t9Y27/Ln19CIoD6AJeXpQVQ5Yj8drHvw2FijVexI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509868; c=relaxed/simple; bh=duZ1EMWWCjNLSJH5EAw7vR/rJE0u6uqMpJJitWa/xBg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vwtojj5Cr2fj3SLJDc/nsGFXdlTx2r1dJaV8HTcHG58hjdJwar09PSx4NsrDcs/pcqR9Nn5xtWufy77ESWzkeeX0eKh72IVY3tN5wxND3TvQThfWUm4pQQSXV5zrGNPTU3Uc3mUay6EPQ9j4W5WciCwNTluqXv6UvoTYPhjtMXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=cF8FVmcf; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f955a1aabe6f11ee9e680517dc993faa-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=oUOfVeRKnJ1zcg5WgLZGiIN5J1sZ37QJ5q0Qif+5X/Q=; b=cF8FVmcfDWfPnEAcbu2EoVsm/qnj32RM2gkMkI4hVV2uDy1IduRhpul4/voEAl/zjJrXR/zben79OPKwMqaZEAupVemvfpFjJSTuCDBroZ8AFwZfuVl4TjUcIB4GV7KEN44Z02B99Gm4eh3DiC1yfDMkDXGwXGHyY3RctymRU3Q=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:52e90b94-7fba-474d-b1ee-99576c99795b,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:6e16cf4,CLOUDID:2ad141fe-c16b-4159-a099-3b9d0558e447,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f955a1aabe6f11ee9e680517dc993faa-20240129 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 800635704; Mon, 29 Jan 2024 14:31:02 +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, 29 Jan 2024 14:31:01 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:31:00 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,19/22] media: mediatek: vcodec: disable wait interrupt for svp mode Date: Mon, 29 Jan 2024 14:30:22 +0800 Message-ID: <20240129063025.29251-20-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405621372896598 X-GMAIL-MSGID: 1789405621372896598 Waiting interrupt in optee-os for svp mode, need to disable it in kernel in case of interrupt is cleaned. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_hw.c | 34 +++++------ .../vcodec/decoder/mtk_vcodec_dec_pm.c | 6 +- .../decoder/vdec/vdec_h264_req_multi_if.c | 57 +++++++++++-------- 3 files changed, 54 insertions(+), 43 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c index 881d5de41e05..1982c088c6da 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_hw.c @@ -72,26 +72,28 @@ static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void *priv) ctx = mtk_vcodec_get_curr_ctx(dev->main_dev, dev->hw_idx); - /* check if HW active or not */ - cg_status = readl(dev->reg_base[VDEC_HW_SYS] + VDEC_HW_ACTIVE_ADDR); - if (cg_status & VDEC_HW_ACTIVE_MASK) { - mtk_v4l2_vdec_err(ctx, "vdec active is not 0x0 (0x%08x)", cg_status); - return IRQ_HANDLED; - } + if (!ctx->is_secure_playback) { + /* check if HW active or not */ + cg_status = readl(dev->reg_base[VDEC_HW_SYS] + VDEC_HW_ACTIVE_ADDR); + if (cg_status & VDEC_HW_ACTIVE_MASK) { + mtk_v4l2_vdec_err(ctx, "vdec active is not 0x0 (0x%08x)", cg_status); + return IRQ_HANDLED; + } - dec_done_status = readl(vdec_misc_addr); - if ((dec_done_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) != - MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) - return IRQ_HANDLED; + dec_done_status = readl(vdec_misc_addr); + if ((dec_done_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) != + MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) + return IRQ_HANDLED; - /* clear interrupt */ - writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr); - writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr); + /* clear interrupt */ + writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr); + writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr); - wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx); + wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx); - mtk_v4l2_vdec_dbg(3, ctx, "wake up ctx %d, dec_done_status=%x", - ctx->id, dec_done_status); + mtk_v4l2_vdec_dbg(3, ctx, "wake up ctx %d, dec_done_status=%x", + ctx->id, dec_done_status); + } return IRQ_HANDLED; } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c index aefd3e9e3061..a94eda936f16 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_pm.c @@ -238,7 +238,8 @@ void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx) mtk_vcodec_dec_child_dev_on(ctx->dev, MTK_VDEC_LAT0); mtk_vcodec_dec_child_dev_on(ctx->dev, hw_idx); - mtk_vcodec_dec_enable_irq(ctx->dev, hw_idx); + if (!ctx->is_secure_playback) + mtk_vcodec_dec_enable_irq(ctx->dev, hw_idx); if (IS_VDEC_INNER_RACING(ctx->dev->dec_capability)) mtk_vcodec_load_racing_info(ctx); @@ -250,7 +251,8 @@ void mtk_vcodec_dec_disable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx) if (IS_VDEC_INNER_RACING(ctx->dev->dec_capability)) mtk_vcodec_record_racing_info(ctx); - mtk_vcodec_dec_disable_irq(ctx->dev, hw_idx); + if (!ctx->is_secure_playback) + mtk_vcodec_dec_disable_irq(ctx->dev, hw_idx); mtk_vcodec_dec_child_dev_off(ctx->dev, hw_idx); if (IS_VDEC_LAT_ARCH(ctx->dev->vdec_pdata->hw_arch) && diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 2dfb3043493e..3e2270399b6c 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -593,14 +593,16 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) goto vdec_dec_end; } - /* wait decoder done interrupt */ - timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); - if (timeout) - mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt); - inst->vsi_core->dec.timeout = !!timeout; - - vpu_dec_core_end(vpu); + if (!ctx->is_secure_playback) { + /* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); + if (timeout) + mtk_vdec_err(ctx, "core decode timeout: pic_%d", ctx->decoded_frame_cnt); + inst->vsi_core->dec.timeout = !!timeout; + + vpu_dec_core_end(vpu); + } mtk_vdec_debug(ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", ctx->decoded_frame_cnt, inst->vsi_core->dec.crc[0], inst->vsi_core->dec.crc[1], @@ -724,14 +726,16 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf); } - /* wait decoder done interrupt */ - timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0); - if (timeout) - mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num); - inst->vsi->dec.timeout = !!timeout; + if (!inst->ctx->is_secure_playback) { + /* wait decoder done interrupt */ + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0); + if (timeout) + mtk_vdec_err(inst->ctx, "lat decode timeout: pic_%d", inst->slice_dec_num); + inst->vsi->dec.timeout = !!timeout; - err = vpu_dec_end(vpu); + err = vpu_dec_end(vpu); + } if (err == SLICE_HEADER_FULL || err == TRANS_BUFFER_FULL) { if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf); @@ -831,16 +835,19 @@ static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs if (err) goto err_free_fb_out; - /* wait decoder done interrupt */ - err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); - if (err) - mtk_vdec_err(inst->ctx, "decode timeout: pic_%d", inst->ctx->decoded_frame_cnt); - - inst->vsi->dec.timeout = !!err; - err = vpu_dec_end(vpu); - if (err) - goto err_free_fb_out; + if (!inst->ctx->is_secure_playback) { + /* wait decoder done interrupt */ + err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_CORE); + if (err) + mtk_vdec_err(inst->ctx, "decode timeout: pic_%d", + inst->ctx->decoded_frame_cnt); + + inst->vsi->dec.timeout = !!err; + err = vpu_dec_end(vpu); + if (err) + goto err_free_fb_out; + } memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx)); mtk_vdec_debug(inst->ctx, "pic[%d] crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", From patchwork Mon Jan 29 06:30:23 2024 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: 193288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393088dyb; Sun, 28 Jan 2024 22:36:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNcXooMVTEDyIYAyf3HM6ztmk+kXKk81+vq4TdVSBrZh8KE8isGhp5J68vt49/dlmCYjQ6 X-Received: by 2002:a17:90b:388f:b0:295:29d8:2570 with SMTP id mu15-20020a17090b388f00b0029529d82570mr1175244pjb.8.1706510164503; Sun, 28 Jan 2024 22:36:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510164; cv=pass; d=google.com; s=arc-20160816; b=rZY2aKfiftaEFKnwRFE5NDZt7vKKJJtWL+R7lqb8Dii6ioWT6MVbXmrWxaNVmV5KTT 23PiBkiMia3AuILxv4+VbAFQ7/a0RY5q3BJLBkQ2GHbT1nNqT4sZvJNvBR8lPlPy7wxk Gd6N76+THQ1FLV72f+FiDdENQq5v0xt8Rz1mf3oM2zwpAYXo0KEojikqRi4O6sHRkCXF UI+Vno71ryDc0PqioHCoRLhuIPWGb2l7zbxvbCk4A7ybFn/NXsOZhBQatW0ShOWUgGvo 0iqNaMz7JIQ7komjp52oOMWpV0RICe91uGjjyt58f8/NQn3XLM/5Rw/6V0zhklYGgCOv 9GzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kC7KzWLgDHvbqhzMWnc/8P0WK0I0J12Fa3NbbNqI088=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=P8CSXEXT5BdLj3oK+1ZVGZ1Fr61nZPk1WjOqV/DhJhAm3Zqsps1enMnW/qX7f2Vg+T t6BFl81ZcAdoPyw8BTtIbwWuo8eRXpmIn8Ku5MUsKBnn77WjuqyOZ4pAZYIOHxkCXPPB C1B/FGc7479VdoGWAYhgSArgL8rUqL6MkykYa5eksXtsiJ3q2q2sBPJz1u2aucbEk86z t7YuvC6Ws/AyJ8WNs7ULo0KPoO5oPEUQ4hMxHBL230tS3rNXx4vLMIQhKJ9ApHu9px3f laXDMpdem5bfci9IFnzEp82yYpDkekWD/T/iyXrn8svQHXgQ6IlryVkvwOZtr/FIarEu I4dA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=HnisB5Y3; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42255-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42255-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lb15-20020a17090b4a4f00b002958c8f513bsi188724pjb.40.2024.01.28.22.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:36:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42255-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=HnisB5Y3; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42255-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42255-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4704B2812DF for ; Mon, 29 Jan 2024 06:36:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D212058AA5; Mon, 29 Jan 2024 06:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="HnisB5Y3" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB6EB56461; Mon, 29 Jan 2024 06:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509870; cv=none; b=VVnq/TjxH59HRyq8okHA1ZtLVYyeIFx2YVPYRZ2cNerL8nyp4RaLqoq6p56MR8of5SqLROkxcUmCopazL3/8oiRzmxXsM5+XyczFCdFa/mTUXcQ/f0WsiZk91ADbUEVpnzRnKm6+h7CvCJclNfdMDaIlk4bJyzud5zGfZAXRXXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509870; c=relaxed/simple; bh=huiD7USOrdWu9NopWmVGEcrOlYp+dwqjiEDlssjdViU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EaKi6B9j0Dvlw+7UljxLgOetT1LcBt8BlHnWsNdt3uRHrJOMGPBMVAurU43AoDJyadlV66KZpsOLsuHCvfWI8zIYzBHeJlzIKcE0OrqvR5T/nqLeQUod33+pdCreWrpBrzrfGXSTDBNrfd9FXHBb2BiMIX6kZR2NB8xNjRrJe/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=HnisB5Y3; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f99da7b6be6f11eea2298b7352fd921d-20240129 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=kC7KzWLgDHvbqhzMWnc/8P0WK0I0J12Fa3NbbNqI088=; b=HnisB5Y3YujX0dYJ5G4wTIht/qYjcKfhdp7/iM3HAt86p6MqP7ph7gLg8dGtt7RiaUnIfNi2lLZZW8MjRG837ymxqkdWIw8Udx+8hi5CTMgWzR6ZhrVTFFEbShtXHPsJEs2OtAW5nknpjC+SlJAlKCcqeZJgP1IdhfNebEsFwwI=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:76f735b0-8a53-47a3-802f-4b27768c9f2d,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:6e16cf4,CLOUDID:bfa95c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f99da7b6be6f11eea2298b7352fd921d-20240129 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 456716777; Mon, 29 Jan 2024 14:31:03 +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, 29 Jan 2024 14:31:02 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:31:01 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,20/22] media: mediatek: vcodec: support tee decoder Date: Mon, 29 Jan 2024 14:30:23 +0800 Message-ID: <20240129063025.29251-21-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405602516161671 X-GMAIL-MSGID: 1789405602516161671 Initialize tee private data to support secure decoder. Release tee related information for each instance when decoder done. Signed-off-by: Yunfei Dong --- .../platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c index f47c98faf068..08e7d250487b 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c @@ -310,6 +310,9 @@ static int fops_vcodec_release(struct file *file) v4l2_fh_exit(&ctx->fh); v4l2_ctrl_handler_free(&ctx->ctrl_hdl); + if (ctx->is_secure_playback) + mtk_vcodec_dec_optee_release(dev->optee_private); + mtk_vcodec_dbgfs_remove(dev, ctx->id); list_del_init(&ctx->list); kfree(ctx); @@ -466,6 +469,11 @@ static int mtk_vcodec_probe(struct platform_device *pdev) atomic_set(&dev->dec_active_cnt, 0); memset(dev->vdec_racing_info, 0, sizeof(dev->vdec_racing_info)); mutex_init(&dev->dec_racing_info_mutex); + ret = mtk_vcodec_dec_optee_private_init(dev); + if (ret) { + dev_err(&pdev->dev, "Failed to init svp private."); + goto err_reg_cont; + } ret = video_register_device(vfd_dec, VFL_TYPE_VIDEO, -1); if (ret) { From patchwork Mon Jan 29 06:30:24 2024 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: 193290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393170dyb; Sun, 28 Jan 2024 22:36:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFO856igO7CUQMugpOBF1ekSPw5bxXeMzxpp0I/OCry6HpoUgwDszrlkCsZzm/SKG3YBGJ X-Received: by 2002:a05:622a:15d5:b0:42a:a2f7:1df0 with SMTP id d21-20020a05622a15d500b0042aa2f71df0mr2111775qty.117.1706510181027; Sun, 28 Jan 2024 22:36:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510181; cv=pass; d=google.com; s=arc-20160816; b=WbWSn9Jy4d4zMBz4hNwGuBrYXOg5doKH11PAAQ1Z2kHlawfk3SsgDyYMvDSAjRCP1b NXerMaKRn6fwuCrmFJfgmf5hZezkvPqvqz5/Q7iJNY5yC8lWTtJCQSvzXyQ2XhKIZIRG Cw8ofX77om+06fXhwsGNoqi55YAxCXCfT9fncSoLH0ytZMMSwPSIBYR33eEGhZ6M2OsP s9CqmMbv+zJQN++vJf2NcwjpTkyBRl3WU9DPjmUXSDXReR5ifz/vfySeGmnJl1hE8ubH snXnp/+I+pxlupTOwtL6GictlOPJHW9snae3jrMITV2l5QtUOYYCCkMxmNJPxKGpeGhO lhEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ijVPGmUw8t6PtBg62F66I+NN1svYCFCRnEKk8itKJeo=; fh=Jm1zUP85NkLhaS8mFbLRiIHu8uZd7NKlphUk8mYvM1c=; b=FpyXKW3AVx7OQpwkjFjRrPg/wcP1U4AqCLVGqNxH0+vFhPrJPOOyPu0l6cxPeslMgU XBxzQY5qgz34Bpi98uO/mjoT5bcsK9tJnOauuod6auxIqvkz7pXFYR+sQLQOsKr2YT0i z7wo5w3Vgya4PHVo78OOpsVlUvp+URWJPEd/GUDgT5CkoLoEa7AwbJpx5SPy1U3raH0I NjQGRE96wYhVWsqxXdaRkHFuzXTsH+Hr0mTIjmONXyX2njc4SINTPJM3ALS7M3TzyAPg E6+Z2WTarRPJ7CZfnyAtU6WUhi+IdmfGwMnaGEX4pxw+MaMvrc2/2b2sThcQ373Z1Oo+ raog== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cwqTKFJZ; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42256-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42256-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 15-20020ac8570f000000b0042aa83194fdsi836014qtw.595.2024.01.28.22.36.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42256-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cwqTKFJZ; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42256-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42256-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 915861C21DE8 for ; Mon, 29 Jan 2024 06:36:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E52B058AC6; Mon, 29 Jan 2024 06:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="cwqTKFJZ" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7C7F56778; Mon, 29 Jan 2024 06:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509871; cv=none; b=maru0XC9w8L2p1N7oR/+HykGgTre4lCSeFxTnflGZsk0FtWZyDguqIi8oiVI6SF+n6WUligFZBB+WDkrkp0/KzlwSIvhgyElwr4ZaCTkjMS4761u0uzBoXbZyquJIl86lvYVn95dZfvpgTj0FAjABGhEsjF/L1MQRN5bS2+iFrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509871; c=relaxed/simple; bh=inBLM8TJCHYgnGGeWzdc6zcfEAOZFKJFGVfnJZ/r8Io=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DPPzIgGhvRNvOPB4VMuLxcXYYJDbCe4PaZQKnJs6I0zZBvGOBXOf6ENhy5EAHfQbzSCJ9idSMzC8/2/K0i/mXJ1LYVEpfbh6IjRFRzHw9P1rGC/JmpZBygfAmYck1xfdFAhgjuexBGAORv3+/wBJS9uK5PnybBaFvxjcxh4Bo6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=cwqTKFJZ; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: faf4dd78be6f11eea2298b7352fd921d-20240129 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=ijVPGmUw8t6PtBg62F66I+NN1svYCFCRnEKk8itKJeo=; b=cwqTKFJZMC1Cp2PSR/TCWWNPMnu96w9BzdEx8+M1T5sCucSYrztEPauzCwqwsLXdJLfncnggAuEOmoeBzAJMQqp/jokoehzhNOQagGbn10jix7GTiQvYwXwL/UY7hFgV2kUGvsyOTZVzDSjqviBmlq3fLgYaESDkoMxs6SEYrfQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:1e301a45-fe5a-4ab7-b7a4-46d569841bfe,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:6e16cf4,CLOUDID:7ad5dc7f-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: faf4dd78be6f11eea2298b7352fd921d-20240129 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 436302087; Mon, 29 Jan 2024 14:31:05 +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, 29 Jan 2024 14:31:04 +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, 29 Jan 2024 14:31:02 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,21/22] media: mediatek: vcodec: move vdec init interface to setup callback Date: Mon, 29 Jan 2024 14:30:24 +0800 Message-ID: <20240129063025.29251-22-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405619740867606 X-GMAIL-MSGID: 1789405619740867606 Getting secure video playback (svp) flag when request output buffer, then calling init interface to init svp parameters in optee-os. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 139 +++++++++++------- 1 file changed, 89 insertions(+), 50 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c index 5d876a31e566..667005ff49c0 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -184,6 +184,69 @@ void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_dec_ctx *ctx) q_data->bytesperline[1] = q_data->coded_width; } +static int mtk_vcodec_dec_init_pic_info(struct mtk_vcodec_dec_ctx *ctx, enum v4l2_buf_type type) +{ + const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata; + struct mtk_q_data *q_data; + int ret; + + if (!ctx->current_codec) + return 0; + + if (V4L2_TYPE_IS_OUTPUT(type) && ctx->state == MTK_STATE_FREE) { + q_data = mtk_vdec_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); + if (!q_data) + return -EINVAL; + + ret = vdec_if_init(ctx, q_data->fmt->fourcc); + if (ret) { + mtk_v4l2_vdec_err(ctx, "[%d]: vdec_if_init() fail ret=%d", + ctx->id, ret); + return -EINVAL; + } + ctx->state = MTK_STATE_INIT; + } + + if (!dec_pdata->uses_stateless_api) + return 0; + + /* + * If get pic info fail, need to use the default pic info params, or + * v4l2-compliance will fail + */ + ret = vdec_if_get_param(ctx, GET_PARAM_PIC_INFO, &ctx->picinfo); + if (ret) + mtk_v4l2_vdec_err(ctx, "[%d]Error!! Get GET_PARAM_PICTURE_INFO Fail", + ctx->id); + + q_data = mtk_vdec_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); + if (q_data->fmt->num_planes == 1) { + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + q_data->bytesperline[0] = ctx->picinfo.buf_w; + } else { + if (ctx->is_secure_playback) + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0] + ctx->picinfo.fb_sz[1]; + else + q_data->sizeimage[0] = ctx->picinfo.fb_sz[0]; + + q_data->bytesperline[0] = ctx->picinfo.buf_w; + q_data->sizeimage[1] = ctx->picinfo.fb_sz[1]; + q_data->bytesperline[1] = ctx->picinfo.buf_w; + } + + q_data->coded_width = ctx->picinfo.buf_w; + q_data->coded_height = ctx->picinfo.buf_h; + + ctx->last_decoded_picinfo = ctx->picinfo; + mtk_v4l2_vdec_dbg(2, ctx, + "[%d] init() plane:%d wxh=%dx%d pic wxh=%dx%d sz=0x%x_0x%x", + ctx->id, q_data->fmt->num_planes, + ctx->picinfo.buf_w, ctx->picinfo.buf_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + q_data->sizeimage[0], q_data->sizeimage[1]); + return 0; +} + static int vidioc_vdec_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) { @@ -479,17 +542,7 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, ctx->ycbcr_enc = pix_mp->ycbcr_enc; ctx->quantization = pix_mp->quantization; ctx->xfer_func = pix_mp->xfer_func; - ctx->current_codec = fmt->fourcc; - if (ctx->state == MTK_STATE_FREE) { - ret = vdec_if_init(ctx, q_data->fmt->fourcc); - if (ret) { - mtk_v4l2_vdec_err(ctx, "[%d]: vdec_if_init() fail ret=%d", - ctx->id, ret); - return -EINVAL; - } - ctx->state = MTK_STATE_INIT; - } } else { ctx->capture_fourcc = fmt->fourcc; } @@ -502,46 +555,11 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, ctx->picinfo.pic_w = pix_mp->width; ctx->picinfo.pic_h = pix_mp->height; - /* - * If get pic info fail, need to use the default pic info params, or - * v4l2-compliance will fail - */ - ret = vdec_if_get_param(ctx, GET_PARAM_PIC_INFO, &ctx->picinfo); - if (ret) { - mtk_v4l2_vdec_err(ctx, "[%d]Error!! Get GET_PARAM_PICTURE_INFO Fail", - ctx->id); - } - - ctx->last_decoded_picinfo = ctx->picinfo; - - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) { - ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = - ctx->picinfo.fb_sz[0] + - ctx->picinfo.fb_sz[1]; - ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = - ctx->picinfo.buf_w; - } else { - ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] = - ctx->picinfo.fb_sz[0]; - ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] = - ctx->picinfo.buf_w; - ctx->q_data[MTK_Q_DATA_DST].sizeimage[1] = - ctx->picinfo.fb_sz[1]; - ctx->q_data[MTK_Q_DATA_DST].bytesperline[1] = - ctx->picinfo.buf_w; - } - - ctx->q_data[MTK_Q_DATA_DST].coded_width = ctx->picinfo.buf_w; - ctx->q_data[MTK_Q_DATA_DST].coded_height = ctx->picinfo.buf_h; - mtk_v4l2_vdec_dbg(2, ctx, - "[%d] init() plane:%d wxh=%dx%d pic wxh=%dx%d sz=0x%x_0x%x", - ctx->id, pix_mp->num_planes, - ctx->picinfo.buf_w, ctx->picinfo.buf_h, - ctx->picinfo.pic_w, ctx->picinfo.pic_h, - ctx->q_data[MTK_Q_DATA_DST].sizeimage[0], - ctx->q_data[MTK_Q_DATA_DST].sizeimage[1]); + if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) + ret = mtk_vcodec_dec_init_pic_info(ctx, f->type); } - return 0; + + return ret; } static int vidioc_enum_framesizes(struct file *file, void *priv, @@ -722,7 +740,7 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, { struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vq); struct mtk_q_data *q_data; - unsigned int i; + unsigned int i, ret; q_data = mtk_vdec_get_q_data(ctx, vq->type); @@ -731,6 +749,25 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, return -EINVAL; } + if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + if (vq->restricted_mem && !ctx->is_secure_playback) { + ret = mtk_vcodec_dec_optee_open(ctx->dev->optee_private); + if (ret) { + mtk_v4l2_vdec_err(ctx, "Failed to open decoder optee os"); + return ret; + } + ctx->is_secure_playback = vq->restricted_mem; + mtk_v4l2_vdec_dbg(1, ctx, "Getting secure decoder mode:%d", + ctx->is_secure_playback); + } + + ret = mtk_vcodec_dec_init_pic_info(ctx, vq->type); + if (ret) { + mtk_v4l2_vdec_err(ctx, "Failed to init picture information"); + return ret; + } + } + if (*nplanes) { if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { if (*nplanes != q_data->fmt->num_planes) @@ -980,6 +1017,7 @@ int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq, src_vq->lock = &ctx->dev->dev_mutex; src_vq->dev = &ctx->dev->plat_dev->dev; src_vq->allow_cache_hints = 1; + src_vq->allow_restricted_mem = 1; ret = vb2_queue_init(src_vq); if (ret) { @@ -996,6 +1034,7 @@ int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->lock = &ctx->dev->dev_mutex; dst_vq->dev = &ctx->dev->plat_dev->dev; dst_vq->allow_cache_hints = 1; + dst_vq->allow_restricted_mem = 1; ret = vb2_queue_init(dst_vq); if (ret) From patchwork Mon Jan 29 06:30:25 2024 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: 193292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp393287dyb; Sun, 28 Jan 2024 22:36:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+jIUc4yCc3s/RJzukTGK6ZWdJPB5gke4Oo7IVFDAf2KXOG+4HCQizKGFRR1jykLwLqedA X-Received: by 2002:a05:6359:4c1d:b0:176:8248:a219 with SMTP id kj29-20020a0563594c1d00b001768248a219mr3142414rwc.8.1706510201756; Sun, 28 Jan 2024 22:36:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706510201; cv=pass; d=google.com; s=arc-20160816; b=MmTu63I28yJyJmL6XScvBiI6fK8czpaatgZJiXTcdtU0hz6a2GBMebEqVigidLTpe8 Cf6eLvjue94BMlj68vU7pYN0UphKjqxBzdhkuVN1cUuZMm4U6Mlb7F4dFD2uE2Y0pD9i m0jdjO4BAxOWv0aeaQS13nLxbr0LWYlRrBaX6rNkP6oArgXrjROLfyo6SZXnGtPLduu2 8U6k6446hT2VQfbHkZFqavDmgRhOSFpelGYRN2DdDylb92j/aWc3PaMnTIth8x0b4c6y xPUt7tOw/eII2DS/nmjDT3MIOdXWLsdVb63uq3F1CVoF6By+5TkoRZg6X3+SH3/GVGAv hIVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PmOOl2O3YzoSfT/A/8Z58sBZCN9D2jNsNyNSD5AkJgw=; fh=wcqrfUTA4c9nkJHA4kqbuH5WL/x/W2/AFDhttE+DJkw=; b=dqNRyeDw4geU4lLdmMWRLQpm6ZN+mfHolGwbrhLVNwF26XxHrPtLze4Z9mNKFgqJwz +/ESkAH0psKwG2aAKkysVQsKUdxBdQGq4vztCACqZgUM256YxKDHZ9vijwL6JMaVLA2p buLNsEWUvjGCVTtOgR5/dOK90dWf0QabiZ0xwkxsrE8hikLmgYS+esbQo+BUnUD+//w4 uC2oMwkcLxJXMYWcxJF8Udf7i1bRy1j0cXKmMq0ICw84C/LrFV+E2p/z2sOIOCxmoE8O HFBKhmAh25VROydOQ9ytKKYQxiSFrLIjucQhJMsKi6GBK+maXCotJ0FsOyxHAlPkaPI6 NjHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=b2a1vxbM; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42257-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42257-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u19-20020a63b553000000b005d80a51e1c0si4883130pgo.851.2024.01.28.22.36.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42257-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=b2a1vxbM; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-42257-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42257-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7482FB2249D for ; Mon, 29 Jan 2024 06:36:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C1935914A; Mon, 29 Jan 2024 06:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="b2a1vxbM" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50B5658108; Mon, 29 Jan 2024 06:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509874; cv=none; b=ZAkbryEP/Qjf17AZRGp1lS30xIZ+7R1PwucAurlKQcHNeCdm0cq2wtczxXEE66t7OY5xBz0KZi3ZRo1Hq/vnjaqKJMI53ajits0nppxRpseMr1UddmPGJc4X6X9y0qf8NoKqa9BGMyNBLlZ7tzZpx7QlMp/d4uhmnedjuMVhOVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509874; c=relaxed/simple; bh=/6+O2DvCvaRrnJB9bxhSwFGAlKjPZTOCA3qHJa3WTII=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tz09AUnRBOXzQTTuZqGvClocJZ8h+61nPTSUtQqhT5HtTTK8eitVBY6qF6m0197ZLwnmYm4c3q61xfuXNN/2hkq2qLVghkoNL+tdb452+xL/GEYAQaIu65YC4xkPlIF8COhqkK4x5sH+vIgrbojkykYMA08kfTVOMRpjLCefvmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=b2a1vxbM; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: fb7ebf0cbe6f11ee9e680517dc993faa-20240129 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=PmOOl2O3YzoSfT/A/8Z58sBZCN9D2jNsNyNSD5AkJgw=; b=b2a1vxbMcKc44uA7bW7WJni0TO6cmCbmA4eHlJkGUgYI+tsgulVaaNfFF2B8B6+x7tvYeOXMa6s3ssoT7LPqVdYg94/62KcPCKFWReFgnrwd+F8/bYxTxidjHRLApEvMbEJ6pp69xx7GCISGiSpYzp5rz5VACo49ufQ9KQAfQso=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:668d8314-dcc7-40e0-b915-626f897365a5,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:6e16cf4,CLOUDID:22aa5c83-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: fb7ebf0cbe6f11ee9e680517dc993faa-20240129 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 2113761936; Mon, 29 Jan 2024 14:31:06 +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, 29 Jan 2024 14:31:05 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:31:04 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Chen-Yu Tsai , Yong Wu , "Hsin-Yi Wang" , Fritz Koenig , "Daniel Vetter" , Steve Cho , Yunfei Dong , Sumit Semwal , "Brian Starkey" , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,22/22] media: mediatek: vcodec: support hevc svp for mt8188 Date: Mon, 29 Jan 2024 14:30:25 +0800 Message-ID: <20240129063025.29251-23-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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--9.969000-8.000000 X-TMASE-MatchedRID: NfE/lF/5OguvVT6bfkFW/gI0yP/uoH+DHgnyJJNAX/iHlDUCu0I+XO2V VVLUIzQwThbvLLI8RvOmGallF1XuaCGlT4FPpKFRpKSqN+Z3dp7bKTxp3+WtIDb9TB28UbkiqOl iuKBSJDcMHdYgr1Lbr4LbE+EfcVAHf/ojZMms99/huXUWQoMQt8SgMQYKGHsJ2CEUkv53/lWjxY yRBa/qJcFwgTvxipFajoczmuoPCq1C0yBL+I+hsS03ud7wGfVKfkZ3WdlbJT6mLGqhwSLJ4MsRe kXH5xNr X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--9.969000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: B9D33A707E9575B1CF97B30D67B728600DC2FBF1A68ECC4E7A8DF3EE4B5888EA2000:8 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789405641286735848 X-GMAIL-MSGID: 1789405641286735848 Change hevc driver to support secure video playback(svp) for mt8188. Need to map shared memory with optee interface and wait interrupt in optee-os. Signed-off-by: Yunfei Dong --- .../decoder/vdec/vdec_hevc_req_multi_if.c | 89 +++++++++++-------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c index 06ed47df693b..8bf4bc13ae2d 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c @@ -415,11 +415,14 @@ static void vdec_hevc_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx, hevc_dpb_info[index].field = dpb->field_pic; hevc_dpb_info[index].y_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0); - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) - hevc_dpb_info[index].c_dma_addr = vb2_dma_contig_plane_dma_addr(vb, 1); - else - hevc_dpb_info[index].c_dma_addr = - hevc_dpb_info[index].y_dma_addr + ctx->picinfo.fb_sz[0]; + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2) + hevc_dpb_info[index].c_dma_addr = + vb2_dma_contig_plane_dma_addr(vb, 1); + else + hevc_dpb_info[index].c_dma_addr = + hevc_dpb_info[index].y_dma_addr + ctx->picinfo.fb_sz[0]; + } } } @@ -800,7 +803,7 @@ static int vdec_hevc_slice_setup_core_buffer(struct vdec_hevc_slice_inst *inst, struct mtk_vcodec_dec_ctx *ctx = inst->ctx; struct vb2_v4l2_buffer *vb2_v4l2; struct vdec_fb *fb; - u64 y_fb_dma, c_fb_dma; + u64 y_fb_dma, c_fb_dma = 0; int i; fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx); @@ -810,18 +813,20 @@ static int vdec_hevc_slice_setup_core_buffer(struct vdec_hevc_slice_inst *inst, } y_fb_dma = (u64)fb->base_y.dma_addr; - if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) - c_fb_dma = - y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; - else - c_fb_dma = (u64)fb->base_c.dma_addr; + if (!ctx->is_secure_playback) { + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1) + c_fb_dma = + y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h; + else + c_fb_dma = (u64)fb->base_c.dma_addr; + } mtk_vdec_debug(inst->ctx, "[hevc-core] y/c addr = 0x%llx 0x%llx", y_fb_dma, c_fb_dma); inst->vsi_core->fb.y.dma_addr = y_fb_dma; inst->vsi_core->fb.y.size = ctx->picinfo.fb_sz[0]; inst->vsi_core->fb.c.dma_addr = c_fb_dma; - inst->vsi_core->fb.y.size = ctx->picinfo.fb_sz[1]; + inst->vsi_core->fb.c.size = ctx->picinfo.fb_sz[1]; inst->vsi_core->dec.vdec_fb_va = (unsigned long)fb; @@ -878,8 +883,13 @@ static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx) vsi_size = round_up(sizeof(struct vdec_hevc_slice_vsi), VCODEC_DEC_ALIGNED_64); inst->vsi = inst->vpu.vsi; - inst->vsi_core = - (struct vdec_hevc_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); + if (ctx->is_secure_playback) + inst->vsi_core = + mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE, + OPTEE_DATA_INDEX); + else + inst->vsi_core = + (struct vdec_hevc_slice_vsi *)(((char *)inst->vpu.vsi) + vsi_size); inst->resolution_changed = true; inst->realloc_mv_buf = true; @@ -944,21 +954,22 @@ static int vdec_hevc_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; + if (!vpu->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, + vpu_dec_core_end(vpu); + } + mtk_vdec_debug(ctx, "pic[%d] svp:%d crc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", + ctx->decoded_frame_cnt, ctx->is_secure_playback, inst->vsi_core->dec.crc[0], inst->vsi_core->dec.crc[1], inst->vsi_core->dec.crc[2], inst->vsi_core->dec.crc[3], inst->vsi_core->dec.crc[4], inst->vsi_core->dec.crc[5], inst->vsi_core->dec.crc[6], inst->vsi_core->dec.crc[7]); - vdec_dec_end: vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->trans.dma_addr_end); ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->src_buf_req); @@ -1015,14 +1026,17 @@ static int vdec_hevc_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); @@ -1031,8 +1045,11 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, return -EINVAL; } - share_info->trans.dma_addr_end = inst->ctx->msg_queue.wdma_addr.dma_addr + - inst->vsi->dec.wdma_end_addr_offset; + if (inst->ctx->is_secure_playback) + share_info->trans.dma_addr_end = inst->vsi->dec.wdma_end_addr_offset; + else + share_info->trans.dma_addr_end = inst->ctx->msg_queue.wdma_addr.dma_addr + + inst->vsi->dec.wdma_end_addr_offset; vdec_msg_queue_update_ube_wptr(&lat_buf->ctx->msg_queue, share_info->trans.dma_addr_end); if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability)) { @@ -1040,8 +1057,10 @@ static int vdec_hevc_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, sizeof(share_info->hevc_slice_params)); vdec_msg_queue_qbuf(&inst->ctx->msg_queue.core_ctx, lat_buf); } - mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x 0x%x", inst->slice_dec_num, - inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], inst->vsi->dec.crc[2]); + + mtk_vdec_debug(inst->ctx, "dec num: %d lat crc: 0x%x 0x%x 0x%x 0x%x size:%d", + inst->slice_dec_num, inst->vsi->dec.crc[0], inst->vsi->dec.crc[1], + inst->vsi->dec.crc[2], inst->vsi->dec.crc[3], (unsigned int)bs->size); inst->slice_dec_num++; return 0;