From patchwork Wed May 11 12:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kumar X-Patchwork-Id: 12846976 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 4AC74C433EF for ; Thu, 12 May 2022 03:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=GfgVD6doBQbgWtAl2v6IAlyuAQXQ7j8evEBA80uhLdI=; b=uQL6eoDTVFodDs /+PqJ1W1xn+7V6wJLanQMJEdONYFX3HwjdqyE4Q5TQFfqGBOIrUc2ytDpXnSjBKFWzxevn2CLieuQ M1ZqQ9/t9fl9q9H1CcOlhRUQCUm7j3JWFBuM9v0bSPuDaefre26mamlbBKnjSS8Wjsu4wOMH7a0H7 rStLTn1+7315QG+aJ3Vy3STo9LQmwW7Q90od4QXaP+Zdot6f4YjHFEQx+asrxywcs/+78mp6VcVqD jbtPOWDVU6aaAOHmFR9YcR44dpBugROl6da2cFK8smm5ZSQ/9ITPEypyqzg8zX9tNbkz2mcMEEky6 mOzRD3++FCogexLcGaXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nozgN-009i8x-QO; Thu, 12 May 2022 03:40:07 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nozfq-009hxe-Nm for linux-arm-kernel@lists.infradead.org; Thu, 12 May 2022 03:39:36 +0000 Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220512033932epoutp023e101c593bf50a5d0b3225c2dac832f4~uPnIFlJUY0066800668epoutp02L for ; Thu, 12 May 2022 03:39:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220512033932epoutp023e101c593bf50a5d0b3225c2dac832f4~uPnIFlJUY0066800668epoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1652326772; bh=h69GhjZ5aQZdvqmbJl+5HwMeprWIkkzTRr4CCQEkMTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKTRHIEluYU9doT34m43BIwStkKE1BaRVK3wBktBn/65iQbfubylcpH9UOsztVg79 /KsxNzYCiXs/BAjwRbh9qBFXQ9vFScL7JFSAOt8MPBDQVevV9V3AdlfZMo6b7a5TOO ice86Pbm4sZIpqHmpF656S2ZV39yzRkmqMcYcVVM= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220512033932epcas5p4ede7a161facac8a73dcee0ae0a2962bd~uPnHzgtbp1491014910epcas5p4i; Thu, 12 May 2022 03:39:32 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.175]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4KzHZk2jWWz4x9Pv; Thu, 12 May 2022 03:39:26 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id FF.A6.09762.C618C726; Thu, 12 May 2022 12:39:25 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20220511121439epcas5p493bf4b94c89c8a63fdc0586c89cea8df~uC-malgwA0360503605epcas5p4H; Wed, 11 May 2022 12:14:39 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220511121439epsmtrp232ded29eef6efdabdb915cd61665d55c~uC-mZvp9w1138811388epsmtrp2L; Wed, 11 May 2022 12:14:39 +0000 (GMT) X-AuditID: b6c32a4b-1fdff70000002622-4b-627c816cc608 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 7D.09.08924.FA8AB726; Wed, 11 May 2022 21:14:39 +0900 (KST) Received: from Jaguar.sa.corp.samsungelectronics.net (unknown [107.108.73.139]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220511121438epsmtip29e536aedf6377692454be9516421f599~uC-k4pH6S0609306093epsmtip2r; Wed, 11 May 2022 12:14:38 +0000 (GMT) From: Ajay Kumar To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: alim.akhtar@samsung.com, pankaj.dubey@samsung.com, ajaykumar.rs1989@gmail.com, Marek Szyprowski , Ajay Kumar Subject: [PATCH V2 4/6] iommu: dma-iommu: refactor iommu_dma_alloc_iova() Date: Wed, 11 May 2022 17:45:42 +0530 Message-Id: <20220511121544.5998-5-ajaykumar.rs@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220511121544.5998-1-ajaykumar.rs@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRmVeSWpSXmKPExsWy7bCmpm5uY02Swe1DTBZfT/xmszjw/iCL xYN529gsFuy3tuicvYHdYtPja6wWa4/cZbdYtPULu8XBD09YLVrumDpweTw5OI/JY828NYwe O2fdZffYtKqTz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REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220511121439epcas5p493bf4b94c89c8a63fdc0586c89cea8df References: <20220511121544.5998-1-ajaykumar.rs@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220511_203935_195205_3D558CF3 X-CRM114-Status: GOOD ( 20.48 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Marek Szyprowski Change the parameters passed to iommu_dma_alloc_iova(): the dma_limit can be easily extracted from the parameters of the passed struct device, so replace it with a flags parameter, which can later hold more information about the way the IOVA allocator should do it job. While touching the parameter list, move struct device to the second position to better match the convention of the DMA-mapping related functions. Signed-off-by: Marek Szyprowski Signed-off-by: Ajay Kumar --- drivers/iommu/dma-iommu.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 16218d6a0703..cb235b40303c 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -600,12 +600,16 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent, } } +#define DMA_ALLOC_IOVA_COHERENT BIT(0) + static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, - size_t size, u64 dma_limit, struct device *dev) + struct device *dev, size_t size, unsigned int flags) { struct iommu_dma_cookie *cookie = domain->iova_cookie; struct iova_domain *iovad = &cookie->iovad; unsigned long shift, iova_len, iova = IOVA_BAD_ADDR; + u64 dma_limit = (flags & DMA_ALLOC_IOVA_COHERENT) ? + dev->coherent_dma_mask : dma_get_mask(dev); if (cookie->type == IOMMU_DMA_MSI_COOKIE) { cookie->msi_iova += size; @@ -675,7 +679,7 @@ static void __iommu_dma_unmap(struct device *dev, dma_addr_t dma_addr, } static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, - size_t size, int prot, u64 dma_mask) + size_t size, int prot, unsigned int flags) { struct iommu_domain *domain = iommu_get_dma_domain(dev); struct iommu_dma_cookie *cookie = domain->iova_cookie; @@ -689,7 +693,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, size = iova_align(iovad, size + iova_off); - iova = iommu_dma_alloc_iova(domain, size, dma_mask, dev); + iova = iommu_dma_alloc_iova(domain, dev, size, flags); if (iova == DMA_MAPPING_ERROR) return DMA_MAPPING_ERROR; @@ -800,7 +804,7 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev, return NULL; size = iova_align(iovad, size); - iova = iommu_dma_alloc_iova(domain, size, dev->coherent_dma_mask, dev); + iova = iommu_dma_alloc_iova(domain, dev, size, DMA_ALLOC_IOVA_COHERENT); if (iova == DMA_MAPPING_ERROR) goto out_free_pages; @@ -963,7 +967,7 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, struct iommu_domain *domain = iommu_get_dma_domain(dev); struct iommu_dma_cookie *cookie = domain->iova_cookie; struct iova_domain *iovad = &cookie->iovad; - dma_addr_t iova, dma_mask = dma_get_mask(dev); + dma_addr_t iova; /* * If both the physical buffer start address and size are @@ -1001,7 +1005,7 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) arch_sync_dma_for_device(phys, size, dir); - iova = __iommu_dma_map(dev, phys, size, prot, dma_mask); + iova = __iommu_dma_map(dev, phys, size, prot, 0); if (iova == DMA_MAPPING_ERROR && is_swiotlb_buffer(dev, phys)) swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); return iova; @@ -1205,7 +1209,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, prev = s; } - iova = iommu_dma_alloc_iova(domain, iova_len, dma_get_mask(dev), dev); + iova = iommu_dma_alloc_iova(domain, dev, iova_len, 0); if (iova == DMA_MAPPING_ERROR) { ret = -ENOMEM; goto out_restore_sg; @@ -1264,8 +1268,7 @@ static dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, size_t size, enum dma_data_direction dir, unsigned long attrs) { return __iommu_dma_map(dev, phys, size, - dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO, - dma_get_mask(dev)); + dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO, 0); } static void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, @@ -1375,7 +1378,7 @@ static void *iommu_dma_alloc(struct device *dev, size_t size, return NULL; *handle = __iommu_dma_map(dev, page_to_phys(page), size, ioprot, - dev->coherent_dma_mask); + DMA_ALLOC_IOVA_COHERENT); if (*handle == DMA_MAPPING_ERROR) { __iommu_dma_free(dev, size, cpu_addr); return NULL; @@ -1517,7 +1520,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, if (!msi_page) return NULL; - iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); + iova = iommu_dma_alloc_iova(domain, dev, size, 0); if (iova == DMA_MAPPING_ERROR) goto out_free_page;