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: 10896683 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 9EF0F1805 for ; Thu, 11 Apr 2019 18:50:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F248287DB for ; Thu, 11 Apr 2019 18:50:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E41128D1B; Thu, 11 Apr 2019 18:50:07 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BC20287DB for ; Thu, 11 Apr 2019 18:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3yINTe8z3AWpIpVt83S78GEnSgXmj/etD1X2qZ4hedE=; b=gEi+prRsvyP7l/C+eeZirxcmuS UuSEkGRp8TEY3SEU6okVe7LpR2V6FxwuKG5C5w9bcsQg3vO04WEypCWuBAD04yodYf3Tk1xyjh2aJ G1eGPS5uaPyoHn0c1wCaxsZZP0YHdcB69DE99/fTFsvnJPrBY4FfdDATKj2kVUcWq9rQfiJroYwGq yKuPEAwVy8iUSEbbkYa2JUEt7m8aul40QRvdLhrpmk31B+dd5WTQBcpbfNiNVrZj6hhfwOyiA8SD7 DLdVMeA0D6c1qBch6spXtoWfJ9GTxP/ibLXLYmWAPbEEMwGMijAzKjCoMSwxD06b7udqoq80jBnRV kZ4VeTVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEels-0003K1-Dl; Thu, 11 Apr 2019 18:50:00 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEekx-0002Id-Mk for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:21 +0000 Received: by mail-ed1-x543.google.com with SMTP id s39so6160115edb.2 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=V94lFLtSMqLikazQGdHFIPGTGVd4z8pl/8vK67I9diTcBAFKMyzjqzTPtP9E4UgO1B T8ZMnYWL5w4txxAajif5nnuMk01iUEMBu4mTzASm11Mjb48VGLviHnNgvZInaQEebQxm xHxzUhnk7IG/rTD0TSKzAFEHzA0VH6OadkLZS5Ix0Y86CdrIWXwAsOEZsGAJAVBeiFa1 peXiqsBNUatvHY3MSFP9pa42AtYkbX/pC58uVXRCCyNbvw/MDTR7t+JaHdrewHFXbMXa 8qIjJKOBniK3pshudF3ay0uuFwx+6ceubxqe1kxfz8y1xPd223g9K/j9bkXQj37g2SZz xodA== X-Gm-Message-State: APjAAAWWwImeGtKP9hWZdh/gTX+reg+bvF5uN4xs0MCofWODnTt+Xbdt NhOgfcpt2a/LdSzDo3BPB8np4Q== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114903_991919_E5928D3F X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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);