Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2261663ybv; Fri, 14 Feb 2020 14:59:49 -0800 (PST) X-Google-Smtp-Source: APXvYqx5bcW0JPiR4+tIBD+YLO+PLL8X6V1kd88IXu2wQRYVOs27oS03yLBHH5iV2O6ajx8yU11S X-Received: by 2002:aca:37c3:: with SMTP id e186mr3540929oia.155.1581721188935; Fri, 14 Feb 2020 14:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581721188; cv=none; d=google.com; s=arc-20160816; b=XVpcwu+NQd+Ima2u9Nv0BIur8R+wXpodjUk8OwtBHAm4OSlcmxOfvD3q4g6Taej2Fu aQ3dCpXOVkTmpe13WuE2VBFTk/8E/WRExX8rRdMBLQ4b/exQ+BDwwYSsHAG2S27TzE2I q5COBongBdAZPWFDT1tFHARBG/4AT3tdHEBeixIVrMkHiCsb+JDsnlrjn66uG5Izj0f4 tPiT7/WiYplu2l3t+OUvieSPhRO1PZRK4+V8x8qqWr+WjBHAh21mkx0vLCtLbFUI9ld9 JraFWYA0a6U20684/hqp+sQWKKdQrQ5p8kpSjlPIuU2uUN3Fheew96YhqBPWTNv7JZOA DofA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature; bh=Crn3FL1RKeqIe9JQNOwhOeVTSYotuHa65B4DyFHfQgY=; b=y99hEZRHgSHfAb4jAQyXCwZwjGrEDWHHLOrun9/40es2UlQP8FshoSynkMI45v/oWb FXIqDE9ZWhsbN5N4+O8hEYRwRKR5u/DoxiV3pbJNGgW89JtWytoczEuLzAvvXGFh8Rvn +EBBmxtD6WLkBGGjwGgSuecSasAFY7H8spBA1HBnr+ZeDJlSE43D61W8lln26NEkH23/ PlMLyA19cmpIe1BJiTjCt0VNM0V0W4Suy74iUhnK7BYpi1wDc2Z0ohUfXsLv1DoqbM36 eTG0UNh85uTYZvJR5vOzZXHyedPG6MJEhcTtlcxEuHvyEpBr+OPfFNCeJMv1y6VouMWg PjjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=kv3oBTuA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si3626833otp.139.2020.02.14.14.59.36; Fri, 14 Feb 2020 14:59:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=kv3oBTuA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727996AbgBNW6Z (ORCPT + 99 others); Fri, 14 Feb 2020 17:58:25 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:41846 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbgBNW6Z (ORCPT ); Fri, 14 Feb 2020 17:58:25 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1581721104; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=Crn3FL1RKeqIe9JQNOwhOeVTSYotuHa65B4DyFHfQgY=; b=kv3oBTuAyi8JII8n66ggaEQbEzu3ZV8YcQUkTxTt6R9c802IaNnaAfVp/MWMso0XUCdBda8F xc93eyvRk0fXz4WvY23oASxW3cPqfNQOIhHwaI7c2uEbC2W7NSHEkQQG5XZLhAOBhHLlKs2L 4diVjWe0Ru/7uyuH8XvmNYYw6PM= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e472610.7fa756bc0998-smtp-out-n02; Fri, 14 Feb 2020 22:58:24 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 4F1C8C447A0; Fri, 14 Feb 2020 22:58:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from isaacm-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: isaacm) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5692AC4479C; Fri, 14 Feb 2020 22:58:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5692AC4479C Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=isaacm@codeaurora.org From: "Isaac J. Manjarres" To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: Liam Mark , joro@8bytes.org, pratikp@codeaurora.org, kernel-team@android.com, "Isaac J. Manjarres" Subject: [RFC PATCH] iommu/dma: Allow drivers to reserve an iova range Date: Fri, 14 Feb 2020 14:58:16 -0800 Message-Id: <1581721096-16235-1-git-send-email-isaacm@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liam Mark Some devices have a memory map which contains gaps or holes. In order for the device to have as much IOVA space as possible, allow its driver to inform the DMA-IOMMU layer that it should not allocate addresses from these holes. Change-Id: I15bd1d313d889c2572d0eb2adecf6bebde3267f7 Signed-off-by: Isaac J. Manjarres --- drivers/iommu/dma-iommu.c | 28 ++++++++++++++++++++++++++++ include/linux/dma-iommu.h | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index a2e96a5..3b83e1a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -368,6 +368,34 @@ static int iommu_dma_deferred_attach(struct device *dev, return 0; } +/* + * Should be called prior to using dma-apis + */ +int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base, + u64 size) +{ + struct iommu_domain *domain; + struct iommu_dma_cookie *cookie; + struct iova_domain *iovad; + unsigned long pfn_lo, pfn_hi; + + domain = iommu_get_domain_for_dev(dev); + if (!domain || !domain->iova_cookie) + return -EINVAL; + + cookie = domain->iova_cookie; + iovad = &cookie->iovad; + + /* iova will be freed automatically by put_iova_domain() */ + pfn_lo = iova_pfn(iovad, base); + pfn_hi = iova_pfn(iovad, base + size - 1); + if (!reserve_iova(iovad, pfn_lo, pfn_hi)) + return -EINVAL; + + return 0; +} +EXPORT_SYMBOL(iommu_dma_reserve_iova); + /** * dma_info_to_prot - Translate DMA API directions and attributes to IOMMU API * page flags. diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 2112f21..79eef7c 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -37,6 +37,9 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc, void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); +int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base, + u64 size); + #else /* CONFIG_IOMMU_DMA */ struct iommu_domain; @@ -78,5 +81,11 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } +static inline int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base, + u64 size) +{ + return -ENODEV; +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project