Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7337740imu; Thu, 31 Jan 2019 08:34:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN6ny5fzk9h8FBKz6nS1bKM/aEZtJ7ZRpuEUlhY0CGgrA/sIHRqyODyZoJeoX5RuaUL1B1pe X-Received: by 2002:a62:be0c:: with SMTP id l12mr34621934pff.51.1548952472526; Thu, 31 Jan 2019 08:34:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548952472; cv=none; d=google.com; s=arc-20160816; b=tMsW3TpkzrMlJaynKP7jvVafLdmTCJRMN/wUrGSlRNSHtUYRp5kcBEhDMv0zsHkGlk fQIwyt8QiX4GsIlY5NzilbGbCvbbdjbzQnHuQS0dtKkm4W/qgH6d5p6Qlf7gupLP1IqM ekAPl6d75oV8KMVWc4hxLGblRd0IequZU4WQfohs37paX3eTOC4CWTS20d2GxwLLHQh5 0K9Zh/odVwbY4caRGKc09aooX/2wT4eTracGzGE0pEol8e4wkBdaPNu/nv7gkBTa7L2M U0joSbOv/s7WW7uF5Mvxytqz+Sc30Bro8HaG1nwUJsmjt7dLL2L9lgIfQt0HQ4YbSzqO WHRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=FN7EfqyTAudcuYS7Wn4eO4XyT+lXzsqlbfhxv51gjrw=; b=spc8PsJMu3IIoK0IyFvn/+clo9qh6ipemEfxActAuFxLsjy1EUVxqSJ/JiIX04LExY HLiKqbRtZZsBt/czz5Y7Bdp7kXW6BCi0R3NeU+Ve7HNoDQ4O5rWlxmM67nQg5IGrw4B5 KBmLCrKCe7bOwa0fw+TR4bdxtMYUJ/i+lJW5CTbCfaLraKk6Qi7JiO8Ly+X/0WkMcw81 CZ7Ld63N5bLweXAFr6235y6b7fvRUgoprOE5Wis3+CouIEPujc3tkJXkYOPc4nf9P2Rm X3vR2piLWIuY9ba6towSXH+ngZBLfHGqIVk1JgIIyxpkcjE7VHZaNqqM/TRVtpXAGw1A P27Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 206si4525643pga.240.2019.01.31.08.34.17; Thu, 31 Jan 2019 08:34:32 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388543AbfAaQeH (ORCPT + 99 others); Thu, 31 Jan 2019 11:34:07 -0500 Received: from 8bytes.org ([81.169.241.247]:36368 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388217AbfAaQeG (ORCPT ); Thu, 31 Jan 2019 11:34:06 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 2212428C; Thu, 31 Jan 2019 17:34:05 +0100 (CET) From: Joerg Roedel To: "Michael S . Tsirkin" , Jason Wang , Konrad Rzeszutek Wilk , Christoph Hellwig Cc: Jens Axboe , virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, jfehlig@suse.com, jon.grimm@amd.com, brijesh.singh@amd.com, joro@8bytes.org, jroedel@suse.de, Thomas.Lendacky@amd.com Subject: [PATCH 3/5] dma: Introduce dma_max_mapping_size() Date: Thu, 31 Jan 2019 17:34:01 +0100 Message-Id: <20190131163403.11363-4-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190131163403.11363-1-joro@8bytes.org> References: <20190131163403.11363-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel The function returns the maximum size that can be mapped using DMA-API functions. The patch also adds the implementation for direct DMA and a new dma_map_ops pointer so that other implementations can expose their limit. Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Christoph Hellwig Signed-off-by: Joerg Roedel --- Documentation/DMA-API.txt | 8 ++++++++ include/linux/dma-mapping.h | 8 ++++++++ kernel/dma/direct.c | 11 +++++++++++ kernel/dma/mapping.c | 14 ++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt index e133ccd60228..acfe3d0f78d1 100644 --- a/Documentation/DMA-API.txt +++ b/Documentation/DMA-API.txt @@ -195,6 +195,14 @@ Requesting the required mask does not alter the current mask. If you wish to take advantage of it, you should issue a dma_set_mask() call to set the mask to the value returned. +:: + + size_t + dma_direct_max_mapping_size(struct device *dev); + +Returns the maximum size of a mapping for the device. The size parameter +of the mapping functions like dma_map_single(), dma_map_page() and +others should not be larger than the returned value. Part Id - Streaming DMA mappings -------------------------------- diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f6ded992c183..5b21f14802e1 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -130,6 +130,7 @@ struct dma_map_ops { enum dma_data_direction direction); int (*dma_supported)(struct device *dev, u64 mask); u64 (*get_required_mask)(struct device *dev); + size_t (*max_mapping_size)(struct device *dev); }; #define DMA_MAPPING_ERROR (~(dma_addr_t)0) @@ -257,6 +258,8 @@ static inline void dma_direct_sync_sg_for_cpu(struct device *dev, } #endif +size_t dma_direct_max_mapping_size(struct device *dev); + #ifdef CONFIG_HAS_DMA #include @@ -460,6 +463,7 @@ int dma_supported(struct device *dev, u64 mask); int dma_set_mask(struct device *dev, u64 mask); int dma_set_coherent_mask(struct device *dev, u64 mask); u64 dma_get_required_mask(struct device *dev); +size_t dma_max_mapping_size(struct device *dev); #else /* CONFIG_HAS_DMA */ static inline dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page, size_t offset, size_t size, @@ -561,6 +565,10 @@ static inline u64 dma_get_required_mask(struct device *dev) { return 0; } +static inline size_t dma_max_mapping_size(struct device *dev) +{ + return 0; +} #endif /* CONFIG_HAS_DMA */ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 355d16acee6d..6310ad01f915 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -380,3 +380,14 @@ int dma_direct_supported(struct device *dev, u64 mask) */ return mask >= __phys_to_dma(dev, min_mask); } + +size_t dma_direct_max_mapping_size(struct device *dev) +{ + size_t size = SIZE_MAX; + + /* If SWIOTLB is active, use its maximum mapping size */ + if (is_swiotlb_active()) + size = swiotlb_max_mapping_size(dev); + + return size; +} diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index a11006b6d8e8..5753008ab286 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -357,3 +357,17 @@ void dma_cache_sync(struct device *dev, void *vaddr, size_t size, ops->cache_sync(dev, vaddr, size, dir); } EXPORT_SYMBOL(dma_cache_sync); + +size_t dma_max_mapping_size(struct device *dev) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + size_t size = SIZE_MAX; + + if (dma_is_direct(ops)) + size = dma_direct_max_mapping_size(dev); + else if (ops && ops->max_mapping_size) + size = ops->max_mapping_size(dev); + + return size; +} +EXPORT_SYMBOL_GPL(dma_max_mapping_size); -- 2.17.1