From patchwork Wed Jun 5 11:11:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10976659 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 9575A76 for ; Wed, 5 Jun 2019 11:17:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 896272808F for ; Wed, 5 Jun 2019 11:17:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D73928500; Wed, 5 Jun 2019 11:17:00 +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=-7.9 required=2.0 tests=BAYES_00,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 3AB65283C3 for ; Wed, 5 Jun 2019 11:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727443AbfFELQ5 (ORCPT ); Wed, 5 Jun 2019 07:16:57 -0400 Received: from relmlor1.renesas.com ([210.160.252.171]:37256 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727198AbfFELQ4 (ORCPT ); Wed, 5 Jun 2019 07:16:56 -0400 X-IronPort-AV: E=Sophos;i="5.60,550,1549897200"; d="scan'208";a="17883871" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 05 Jun 2019 20:16:52 +0900 Received: from localhost.localdomain (unknown [10.166.17.210]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id E305441BD761; Wed, 5 Jun 2019 20:16:52 +0900 (JST) From: Yoshihiro Shimoda To: ulf.hansson@linaro.org, wsa+renesas@sang-engineering.com, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, joro@8bytes.org Cc: linux-mmc@vger.kernel.org, iommu@lists.linux-foundation.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [RFC PATCH v5 3/8] iommu: add a new capable IOMMU_CAP_MERGING Date: Wed, 5 Jun 2019 20:11:49 +0900 Message-Id: <1559733114-4221-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559733114-4221-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1559733114-4221-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a new capable IOMMU_CAP_MERGING to check whether the IOVA would be contiguous strictly if a device requires and the IOMMU driver has the capable. Signed-off-by: Yoshihiro Shimoda --- drivers/iommu/dma-iommu.c | 26 ++++++++++++++++++++++++-- include/linux/iommu.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 034caae..ecf1a04 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -847,11 +847,16 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, dma_addr_t iova; size_t iova_len = 0; unsigned long mask = dma_get_seg_boundary(dev); - int i; + int i, ret; + bool iova_contiguous = false; if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) iommu_dma_sync_sg_for_device(dev, sg, nents, dir); + if (dma_get_iova_contiguous(dev) && + iommu_capable(dev->bus, IOMMU_CAP_MERGING)) + iova_contiguous = true; + /* * Work out how much IOVA space we need, and align the segments to * IOVA granules for the IOMMU driver to handle. With some clever @@ -867,6 +872,13 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, sg_dma_len(s) = s_length; s->offset -= s_iova_off; s_length = iova_align(iovad, s_length + s_iova_off); + /* + * Check whether the IOVA would be contiguous strictly if + * a device requires and the IOMMU driver has the capable. + */ + if (iova_contiguous && i > 0 && + (s_iova_off || s->length != s_length)) + return 0; s->length = s_length; /* @@ -902,8 +914,18 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, if (iommu_map_sg(domain, iova, sg, nents, prot) < iova_len) goto out_free_iova; - return __finalise_sg(dev, sg, nents, iova); + ret = __finalise_sg(dev, sg, nents, iova); + /* + * Check whether the sg entry is single if a device requires and + * the IOMMU driver has the capable. + */ + if (iova_contiguous && ret != 1) + goto out_unmap_sg; + + return ret; +out_unmap_sg: + iommu_dma_unmap_sg(dev, sg, nents, dir, attrs); out_free_iova: iommu_dma_free_iova(cookie, iova, iova_len); out_restore_sg: diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 91af22a..f971dd3 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -104,6 +104,7 @@ enum iommu_cap { transactions */ IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */ IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */ + IOMMU_CAP_MERGING, /* IOMMU supports segments merging */ }; /*