Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4778380imu; Tue, 15 Jan 2019 05:57:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN6N1y1ENBV7SNAjxmuVa3M4cnBruDPV7nXMmlhPayw7tnXJw0C1h9KUi7w57rdBgUY2v6W7 X-Received: by 2002:a62:6f49:: with SMTP id k70mr4138243pfc.7.1547560650737; Tue, 15 Jan 2019 05:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547560650; cv=none; d=google.com; s=arc-20160816; b=cRIwmn1a3eM0dZhebds3kJXlR5XG+LvMzEmKsooWJfu8NRm88v4bDPDTdHUEZ36RXa XwA6yFEeTA0h4kxMS6eoavD/fB2+QQ+YUCPrk0SufRbJ4jbOHirIOZyza18HOaseSy3C uKN5hRNy8QIGWfWaKNirOAMj3PLLaZDB5lCBWivF0QemDxGSFOFOQFOYE4oJvAalCGDt F+6TZsS8DFDBZdkDECs6KhpskHtlBvQ/Wyw4ESzZvDTCURZaWykT5wnoRWDSY4jZx9gF xIkJZBkwXYFdBwmfN0QghrveVEe3su3aXF2GN34OAR5KpsAOXKnluHO8OhXm6pDxRhuI rc4A== 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=FjyPioxodmIRzngR0HVxAwNcpg2CFRqpvzNCDae8rRk=; b=0EqtDcCU7IO7eAGMVVYLdk18TCg1Opyq6iJmciRLQD13edlsTevdTTDTtOyR9RdLaK lxyeup8sET9fNjq+BBgLcIf+XnXOD3jTdVD1U7vi8VpJ6VA62oONR9/Aj1aR/f7MQSW/ AZ8bgSIRnCEY9ck0f1MyKcYD376+mkye6HRTa+7ic7YMprYf4+bF3uSXXAWgqG9AFg7k fcw0olBf0KKuNeXVOEQEBoFi2TQr9AvaqtiwdnqqzSFIP5EpZu+U3FfT8hyl0TmEtgdb icKftwpeZN+GRYSgwQe+PT6ivG2WSucDieQtrgxza+VpNdabCjzQsDTGjsFJuKqAs0VF NLlA== 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 k20si3323548pfb.215.2019.01.15.05.57.15; Tue, 15 Jan 2019 05:57:30 -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 S1729665AbfAONXC (ORCPT + 99 others); Tue, 15 Jan 2019 08:23:02 -0500 Received: from 8bytes.org ([81.169.241.247]:57774 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729307AbfAONXC (ORCPT ); Tue, 15 Jan 2019 08:23:02 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 60D68433; Tue, 15 Jan 2019 14:23:00 +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 2/3] dma: Introduce dma_max_mapping_size() Date: Tue, 15 Jan 2019 14:22:56 +0100 Message-Id: <20190115132257.6426-3-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190115132257.6426-1-joro@8bytes.org> References: <20190115132257.6426-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. Signed-off-by: Joerg Roedel --- include/linux/dma-mapping.h | 16 ++++++++++++++++ kernel/dma/direct.c | 10 ++++++++++ 2 files changed, 26 insertions(+) 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..84917e1003c4 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -380,3 +380,13 @@ 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) +{ + /* + * Return the minimum of the direct DMA limit and the SWIOTLB limit. + * Since direct DMA has no limit, it is fine to just return the SWIOTLB + * limit. + */ + return swiotlb_max_mapping_size(dev); +} -- 2.17.1