From patchwork Thu Apr 11 18:47:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896655 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 4EEB117E0 for ; Thu, 11 Apr 2019 18:49:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 334B3288BB for ; Thu, 11 Apr 2019 18:49:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 267E728CDF; Thu, 11 Apr 2019 18:49:30 +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 C945C288BB for ; Thu, 11 Apr 2019 18:49:29 +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=xDq8I2qSEHdSA2NaYpHv2dWG70/WM7TpmP8301AIgqM=; b=opJzVMoHVLElqYSgh6Iod0vbAW YFZ1D5t1lUL0Eqb2i6N0ChNDrT+m5VIOr5i3pekUMpukRdtIQzoFsFSCu+bzoM4A5hVtE2i3d55hh NPfhQ0Xhz1A8Ni0o44rnyAT7YEV3g/juZ4kP4Ap3293sWfA3KQiaWXyYymmfp7XFXEqWfLhuKtVBE z/mZAjM0ci+rJQBEv9HUjEgWcJtS294DJ5efHjWGHo0UphCcdccGqMooOPCtGeegqJl+8eGHbR5xI N/k/LlpldoW7xOQp1x6P2jgUBSJeM6THij+hXHoZNGxxrzRZaCJc5ST8v+TiRkgQKlCPn3Ul4sg4Z suAHQCgA==; 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 1hEelG-0002hD-RN; Thu, 11 Apr 2019 18:49:22 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEeks-0002BJ-Vi for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:07 +0000 Received: by mail-ed1-x544.google.com with SMTP id w3so6123144edu.10 for ; Thu, 11 Apr 2019 11:48:58 -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=AUkwsqPqLpOQmNdW6Zo0mGf3wmD2BJmU+zJegMbV/Cw=; b=QBMldSGXvc5UwIGLNlY32ptO/VQea8opvEhsRdSzFj4NeN+2G0brH1f/8UVXoDmFzp vgXq8kR+NdanSwtvOTUwpCkm2QCKmWJ4W86KO5tQnP14gTIyY6jfmkyqnM3PIjU1mTrt RDRIQ3bZewU8rrugmcD7S8kRSviGvRiF9zV4bsr6eB83nCXNebkP2SIudff9lbHkRgMS jtauEkPGJgc+fdQv9IWyCVoKtXmY9AvPYOF2tkN2bpTztPvH+bZN2z5g44aD0CJPVIjp Jfs1P1M2x6/FXn9kRoiH7d82Jzo159phG6Ce+OItl5XQo6MoCtkdx/N7GlvqiQu50XsS 3gtw== 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=AUkwsqPqLpOQmNdW6Zo0mGf3wmD2BJmU+zJegMbV/Cw=; b=YBA38p27hb8U/Rp8lh+nn+Rv7RaDMRcnl/1a4PknIbfGlFn/zO0f8LGsdPS+CCAyCw jg2I7OepxbP1Zz/+sxOVmiip2VFoLazrPlUiE16RoUQ/IYjsKxF3RJZCoxRTyjyQWC7D HwO0WN/4hUK8HIzPECi9VsB4WPs7HZ9IJ8tk4JQ0kpg8T/yFeGiH2Za3UDymrEnSMYf/ KhQBotIcCaafgyq+wfqAuhTCuBYFpBLTgXK7iqC7LHUv9EUpEOhFkKktQtIsCqhstzjT 8Iq254v6L16FqXwxVM0w+9rHEcG/uNXuIKYbivurWBpa5kNlaRQAxjCRZo1bAaprAFxE MxIw== X-Gm-Message-State: APjAAAWKoQSUVMRQrgCaGKDOsbBvzuYJ5Sl2KzBjT0Jjl80dPmqv0BAY 4isofcWOcPaNeOOTAzhem4eUhg== X-Google-Smtp-Source: APXvYqzL/CeoYgUz/dL+UCoRPB57kS8k+K0AU3mwSjtkIW0qzE0UGCl3M97UgeKZ/ZqnWNSSEOk5sg== X-Received: by 2002:a17:906:f0f:: with SMTP id z15mr12761935eji.125.1555008537548; Thu, 11 Apr 2019 11:48:57 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:48:57 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 3/9] iommu/dma-iommu: Add iommu_dma_copy_reserved_iova, iommu_dma_apply_resv_region to the dma-iommu api Date: Thu, 11 Apr 2019 19:47:32 +0100 Message-Id: <20190411184741.27540-4-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_114859_464797_CD7D1838 X-CRM114-Status: GOOD ( 14.80 ) 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 To convert the AMD iommu driver to the dma-iommu we need to wrap some of the iova reserve functions. Signed-off-by: Tom Murphy --- drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++ include/linux/dma-iommu.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index cc5da30d6e58..613d181e78a9 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -162,6 +162,33 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) } EXPORT_SYMBOL(iommu_put_dma_cookie); +static struct iova *iommu_dma_reserve_iova(struct iommu_domain *domain, + dma_addr_t iova_lo, dma_addr_t iova_hi) +{ + struct iommu_dma_cookie *cookie = domain->iova_cookie; + struct iova_domain *iovad = &cookie->iovad; + unsigned long order = __ffs(domain->pgsize_bitmap); + + return reserve_iova(iovad, iova_lo >> order, iova_hi >> order); +} + +void iommu_dma_copy_reserved_iova(struct iova_domain *from, + struct iommu_domain *to) +{ + struct iommu_dma_cookie *cookie = to->iova_cookie; + struct iova_domain *to_iovad = &cookie->iovad; + + copy_reserved_iova(from, to_iovad); +} + +void iommu_dma_apply_resv_region(struct device *dev, + struct iommu_domain *domain, struct iommu_resv_region *region) +{ + dma_addr_t end = region->start + region->length - 1; + + WARN_ON_ONCE(iommu_dma_reserve_iova(domain, region->start, end) == NULL); +} + /** * iommu_dma_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index e760dc5d1fa8..c527ded5c41c 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -23,6 +23,7 @@ #ifdef CONFIG_IOMMU_DMA #include #include +#include #include int iommu_dma_init(void); @@ -57,6 +58,12 @@ dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int prot); +/* These are wrappers around some iova functions */ +void iommu_dma_apply_resv_region(struct device *dev, + struct iommu_domain *domain, struct iommu_resv_region *region); +void iommu_dma_copy_reserved_iova(struct iova_domain *from, + struct iommu_domain *to); + /* * Arch code with no special attribute handling may use these * directly as DMA mapping callbacks for simplicity