From patchwork Sat Jul 20 07:15:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 13737684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B937C3DA59 for ; Sat, 20 Jul 2024 07:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bLZB/k6jso90VJO74ijPSPuDokAH3TsIn30+K8soOlI=; b=2CiHqijl2FHhButv/VH1hngsKn HrvZIsYqnFJlkUvrN5Fr4AuZndnVmZYbW/VvFmFUaB+/TFBAtIETAcRHjzVW8gDVzV96aWWjMggT6 ebaBW3wS2Gb21HFJ8NoUqpbBuxhUBmTEwjeDAqe/tE1UGsqWgxQKCwIaOF6OmnYTpyvLKFtIQXh1u pIygnXeDAMpl4t2b4ofie+ECH3Pi/8EBCOPngn6B8ZdffPn1f35YxX0OnehSkv9lJMJtT8QTeQgCP +4Qpd7kcbE5l6bpB09gHqYrxSnEq7ENiw56/d1lZNAHqd4rHBAWoDTQq128wLVFu/u/p6QIRIjgrT 8KYsIXnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sV4Lf-00000004cmJ-02R0; Sat, 20 Jul 2024 07:17:43 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sV4KL-00000004byY-24ZK; Sat, 20 Jul 2024 07:16:23 +0000 X-UUID: f3d308dc466711ef955bff358274dad2-20240720 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=bLZB/k6jso90VJO74ijPSPuDokAH3TsIn30+K8soOlI=; b=TX6MEWIZGCQ78NkRizO7b781o+7DWUyf/YfVsitXW7e2AcoyUhdnC6Z60Gb4o9yxnFbL20mV4PrL6CxEdKkS+ZaRMD4OW1eoBRciVA1X9Pzc4UNojFr4fnHMwf9UaTRYbuQYw082c339eu1LfzyrkulqA/FEcNjQdhjxTd6DN4g=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.40,REQID:2a586403-08df-44ff-b14b-d891a0a262af,IP:0,U RL:0,TC:0,Content:-25,EDM:-25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-50 X-CID-META: VersionHash:ba885a6,CLOUDID:8cc9ad0d-46b0-425a-97d3-4623fe284021,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:1,IP:nil,UR L:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,S PR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f3d308dc466711ef955bff358274dad2-20240720 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1712828354; Sat, 20 Jul 2024 00:16:15 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by MTKMBS09N1.mediatek.inc (172.21.101.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Sat, 20 Jul 2024 15:16:13 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Sat, 20 Jul 2024 15:16:11 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nathan Hebert , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Sebastian Fricke , Tomasz Figa , Mauro Carvalho Chehab , Marek Szyprowski CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Matthias Brugger , , , , , , Subject: [PATCH v7 03/28] media: videobuf2: calculate restricted memory size Date: Sat, 20 Jul 2024 15:15:41 +0800 Message-ID: <20240720071606.27930-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240720071606.27930-1-yunfei.dong@mediatek.com> References: <20240720071606.27930-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240720_001621_587507_5A2CB506 X-CRM114-Status: GOOD ( 13.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Getting the physical address with sg_dma_address for restricted memory, only return the first physical address size since sg may not be physical continuous, then leading to the dmabuf size is small than buf size. Need to bypass continuous checking for restricted memory. Signed-off-by: Yunfei Dong --- .../common/videobuf2/videobuf2-dma-contig.c | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index 3d4fd4ef5310..f0e4652b615f 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -66,6 +66,22 @@ static unsigned long vb2_dc_get_contiguous_size(struct sg_table *sgt) return size; } +/**************************************************/ +/* restricted mem scatterlist table functions */ +/**************************************************/ + +static unsigned long vb2_dc_get_res_mem_contiguous_size(struct sg_table *sgt) +{ + struct scatterlist *s; + unsigned int i; + unsigned long size = 0; + + for_each_sgtable_dma_sg(sgt, s, i) + size += sg_dma_len(s); + + return size; +} + /*********************************************/ /* callbacks for all buffers */ /*********************************************/ @@ -648,10 +664,13 @@ static void *vb2_dc_get_userptr(struct vb2_buffer *vb, struct device *dev, goto fail_sgt_init; } - contig_size = vb2_dc_get_contiguous_size(sgt); + if (buf->vb->vb2_queue->restricted_mem) + contig_size = vb2_dc_get_res_mem_contiguous_size(sgt); + else + contig_size = vb2_dc_get_contiguous_size(sgt); if (contig_size < size) { - pr_err("contiguous mapping is too small %lu/%lu\n", - contig_size, size); + pr_err("contiguous mapping is too small %lu/%lu/%u\n", + contig_size, size, buf->vb->vb2_queue->restricted_mem); ret = -EFAULT; goto fail_map_sg; } @@ -711,10 +730,13 @@ static int vb2_dc_map_dmabuf(void *mem_priv) } /* checking if dmabuf is big enough to store contiguous chunk */ - contig_size = vb2_dc_get_contiguous_size(sgt); + if (buf->vb->vb2_queue->restricted_mem) + contig_size = vb2_dc_get_res_mem_contiguous_size(sgt); + else + contig_size = vb2_dc_get_contiguous_size(sgt); if (contig_size < buf->size) { - pr_err("contiguous chunk is too small %lu/%lu\n", - contig_size, buf->size); + pr_err("contiguous chunk is too small %lu/%lu/%u\n", + contig_size, buf->size, buf->vb->vb2_queue->restricted_mem); dma_buf_unmap_attachment_unlocked(buf->db_attach, sgt, buf->dma_dir); return -EFAULT;