From patchwork Thu Apr 11 18:47:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FF691515 for ; Thu, 11 Apr 2019 18:49:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3044528960 for ; Thu, 11 Apr 2019 18:49:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2482728A07; Thu, 11 Apr 2019 18:49:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDB5A288D3 for ; Thu, 11 Apr 2019 18:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbfDKStE (ORCPT ); Thu, 11 Apr 2019 14:49:04 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:36039 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbfDKStD (ORCPT ); Thu, 11 Apr 2019 14:49:03 -0400 Received: by mail-ed1-f66.google.com with SMTP id u57so5508885edm.3 for ; Thu, 11 Apr 2019 11:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yoJ8L21VfG+7EiXp/r/AWsB982DfY9O3RZBK5Kp8sB8=; b=ZqsZwWNrSw+xqySh9ZjBwb+L6eYpx0X4qksRNIOZU8mg1TOpLf9O0fXmV0r6aHL2fZ 3MfvzFGrJstIHcy1Po8voTQFYh8EpRq1/E82o6IVwvbNi70AX9ZsnmIDFYU6mz9IgKtS dYq2HbKPb0HAXgobjaNdmeDR8NvJmumSeiwwulVBya5cl5NYPDrIwZ2Tv3gVZLFW7Ova tsj1dT55hh6+YaiULDGzVztJQZPedQIn3i7JLnjvyt1OWAKoMUr4a3U/hvmoA6UDpVts xZLLAyc0d3/bS++XMrG4Q+Bewl65uvasxMRMjuBIQJx//ij8nSqueitAqBQHl/yYVNfY 09hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yoJ8L21VfG+7EiXp/r/AWsB982DfY9O3RZBK5Kp8sB8=; b=P4nCrJOMclWDXJ8xKIs/6wyTQznv2ZhZ7H1iQQ/1cVSmmyAMZhUhOhLi80IO0ZXF7y 23ASbVd6X7VgXkKzvQ/h3FheUbwhgu3Sm3dskjh8xr/+r55bhrZujOhiPOQV3ipq24j2 v8b4H+gRoOoAiM2jSiaJxCdgXIqUFMSXj+/SwRurKPSpprFyIBfkpiz/XGlDpTHJXDLd oH1T46PE9NojkDOGUmI8EPmGfLFEAkzTbc1Eeez7OKS4y+Yre7dEyhVEb0+o2UKqE5Xg DWxT13fu2drQVgMt+pElQxMihnXGf+oRXM8ax/nKsq1ykuyU755Rku6jLSmpEKgBz/XZ 2nUg== X-Gm-Message-State: APjAAAXnxxvVSBqNsJqAm5DynpO8VmGewLwbq/Bq93IDsUYPQYIP+7mz GcaI9cgYB5mdjGALsWydtr7wHQ== X-Google-Smtp-Source: APXvYqzhcIOArLgPaFIotHVPB4LMHAtfaoxhteXVLtNCkA9H3EacRfD1/rKtcbt7o0ew6bGKIbXfPg== X-Received: by 2002:a17:906:d1da:: with SMTP id bs26mr28530697ejb.149.1555008542329; Thu, 11 Apr 2019 11:49:02 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:01 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Cc: dima@arista.com, jamessewart@arista.com, murphyt7@tcd.ie, Tom Murphy , Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , Matthias Brugger , Andy Gross , David Brown , Rob Clark , Heiko Stuebner , Marc Zyngier , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org Subject: [PATCH 4/9] iommu/dma-iommu: Add iommu_dma_map_page_coherent Date: Thu, 11 Apr 2019 19:47:33 +0100 Message-Id: <20190411184741.27540-5-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add iommu_dma_map_page_coherent function to allow mapping pages through the dma-iommu api using the dev->coherent_dma_mask mask instead of the dev->dma_mask mask Signed-off-by: Tom Murphy --- drivers/iommu/dma-iommu.c | 25 ++++++++++++++++++++----- include/linux/dma-iommu.h | 3 +++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 613d181e78a9..0128370f8b88 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -663,7 +663,8 @@ int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) } static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, - size_t size, int prot, struct iommu_domain *domain) + size_t size, int prot, struct iommu_domain *domain, + dma_addr_t dma_limit) { struct iommu_dma_cookie *cookie = domain->iova_cookie; size_t iova_off = 0; @@ -674,7 +675,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, size = iova_align(&cookie->iovad, size + iova_off); } - iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); + iova = iommu_dma_alloc_iova(domain, size, dma_limit, dev); if (!iova) return DMA_MAPPING_ERROR; @@ -693,7 +694,19 @@ dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, int prot) { return __iommu_dma_map(dev, page_to_phys(page) + offset, size, prot, - iommu_get_dma_domain(dev)); + iommu_get_dma_domain(dev), dma_get_mask(dev)); +} + +dma_addr_t iommu_dma_map_page_coherent(struct device *dev, struct page *page, + unsigned long offset, size_t size, int prot) +{ + dma_addr_t dma_mask = dev->coherent_dma_mask; + + if (!dma_mask) + dma_mask = dma_get_mask(dev); + + return __iommu_dma_map(dev, page_to_phys(page) + offset, size, prot, + iommu_get_dma_domain(dev), dma_mask); } void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, @@ -883,7 +896,7 @@ dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, { return __iommu_dma_map(dev, phys, size, dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO, - iommu_get_dma_domain(dev)); + iommu_get_dma_domain(dev), dma_get_mask(dev)); } void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, @@ -910,7 +923,9 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, if (!msi_page) return NULL; - iova = __iommu_dma_map(dev, msi_addr, size, prot, domain); + iova = __iommu_dma_map(dev, msi_addr, size, prot, domain, + dma_get_mask(dev)); + if (iova == DMA_MAPPING_ERROR) goto out_free_page; diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index c527ded5c41c..185ff8500841 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -55,6 +55,9 @@ int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, int prot); +dma_addr_t iommu_dma_map_page_coherent(struct device *dev, + struct page *page, unsigned long offset, + size_t size, int prot); int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int prot);