Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4409662imu; Tue, 29 Jan 2019 00:44:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN5q+gd8QduQp3BM7Ne+aIFCJqxkHkMJccgOrEGmpRVTI9hR22TbL8PpFbsGavgQoBtKwwH1 X-Received: by 2002:a17:902:7791:: with SMTP id o17mr24819654pll.60.1548751467932; Tue, 29 Jan 2019 00:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548751467; cv=none; d=google.com; s=arc-20160816; b=W0XUn5yjupR+/gQmGyd9gA/XrEqzTo7dlGpmSsj6RMfqqljrd1IT6dS/eeuwuLw7xZ 2aWdMzQUz6kdwBlqa+cGoxI0bIS86fhZdj3rTXmD4G/VVnCgX0XEm0JZoogl7XS5yYbf Mgs26HrcziYKT9EyAC5OcmB4zdmA2ct0Y88SCOdF/TvdzHwiftG9pUVsOYe6Xo/h2uP4 jAu/iVCFz76u3Lk2hgRvBMCZ7ixEeh04WC0uY8zfcBrVSKQqjfKYnF2/XZ2x7myqdgQx KoiXQ6CO6eAsAx7NHiQz1iqCre4C3q4CaXciWl2LaDU/qQbgd5NBc2mPT7iDoAQrmYZi xWcg== 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=Xuv4RHDBdid9tcPzInV2Z6h8mqaMV1kln0He2sBE6s8=; b=lBhg8aqY5uHzvZoOctbDzYbXeJaSmJX2L7QcYNDllZOE8A7GV6uYYliuQBLFJpw5+S KF2Djm6xAZCjmUbUCRFxRCRj4PZGq+C4IYsbWrPL0+ZNW88SWKlL6imcJsIBNb5eno0k hHWKprnaFzE6Vd1ESrdTVviH3FwjD6fftFzrjqfEz2rIC/YuVboZKpYhkDyTW5+dB/Rj 7lfpYUI8UW8+OP8pkujAqlX114frXjf5yFBVr//wyTwOoq8Q/3+n2BPhSaord8AsyFIr joGHA57SfKJOLL+n7mcGFBFbhZ21MH6Uwaxb9rP/WI8VrK4LFHIAuVe/MJM0uQ21vXe8 NLvQ== 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 r14si35006594pgk.75.2019.01.29.00.44.12; Tue, 29 Jan 2019 00:44:27 -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 S1727586AbfA2Inu (ORCPT + 99 others); Tue, 29 Jan 2019 03:43:50 -0500 Received: from 8bytes.org ([81.169.241.247]:35574 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727205AbfA2Inr (ORCPT ); Tue, 29 Jan 2019 03:43:47 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id B908439C; Tue, 29 Jan 2019 09:43:44 +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 Subject: [PATCH 3/5] dma: Introduce dma_max_mapping_size() Date: Tue, 29 Jan 2019 09:43:40 +0100 Message-Id: <20190129084342.26030-4-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190129084342.26030-1-joro@8bytes.org> References: <20190129084342.26030-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 Signed-off-by: Joerg Roedel --- Documentation/DMA-API.txt | 8 ++++++++ include/linux/dma-mapping.h | 16 ++++++++++++++++ kernel/dma/direct.c | 11 +++++++++++ 3 files changed, 35 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..a3ca8a71a704 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 @@ -440,6 +443,19 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) return 0; } +static inline 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; +} + void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs); void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, 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; +} -- 2.17.1