Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5692940ybg; Tue, 22 Oct 2019 07:05:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfkX+Twz1N6Ob8BIa3iSJ0Fnqv/4+dNA/SP0msSmxalUPYJ66z3Q9YmX8LYMxQeWeTtjYM X-Received: by 2002:a17:906:16d2:: with SMTP id t18mr26929741ejd.28.1571753132026; Tue, 22 Oct 2019 07:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571753132; cv=none; d=google.com; s=arc-20160816; b=SweLGnSI/HX2Gsum5eWkaQOVdNgvGtR9WXOlGlJHmQxnb6IlxmsDCJlHyxjKd5905j WENN4KSejNpnVG6rU0JVcKNubIEYdy4vbkWMOxLQh+C4Yr1elV750EgMSSdk8gjZoZVP lXj5guvGGeHOsex/060ySx6I06H66sihbnpz8NJhKjSt+gEu5eMtgahef72CFWhczO1s ghOeItvPjG4qWu3Fc7rMmidzJpENkhYBudN/LGclqoRuMcSY0YwAD64eNrZ58nmke2DQ Zj/lUVJlDvefguHK356qvNyuYtcDVftVUVVQYF126VSA/3vs6mrdvvZuMWc7gPKHnOyr pPsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=66BeHhjFpc7wTiPuAWBdEMoCtrNgpL956haAUTWVCdE=; b=ilS6Y3g5/iTzsS0l27bjf7eEB78iCpm5qfBGRrX6sXWSmZl0Y21TksFSVbH1Q1X+6h 4+dJ5PBfm4QYfp2PYKn5cYmQpUUR3ipGHlVatyMzEiISk3scs7bZKfaqi7VXNOBoF8OC 493DYyYume/m4iOBh8JM3XgqIcGfiBgXOviNBcIwdmsFUth/OpoEp/PAxq2gcj7cvse5 evvgwUOMv0OEiaEjeSKY/zVWTdO3+sbmpLFnsZxWgGdsiVc5tD6ZBQYMxfTD2E80LIc4 5biQXz9On/Wv8J6m8lo61Oj/RW0Qj1iJiglYa1L6hxrKj8K5eycJwe3by+ldILjrWQAR 4VvQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si10484444ejb.212.2019.10.22.07.04.54; Tue, 22 Oct 2019 07:05:32 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388711AbfJVN0M (ORCPT + 99 others); Tue, 22 Oct 2019 09:26:12 -0400 Received: from [217.140.110.172] ([217.140.110.172]:52688 "EHLO foss.arm.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S2387941AbfJVN0M (ORCPT ); Tue, 22 Oct 2019 09:26:12 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4E4932B; Tue, 22 Oct 2019 06:25:48 -0700 (PDT) Received: from [10.1.197.57] (e110467-lin.cambridge.arm.com [10.1.197.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CE9C23F71F; Tue, 22 Oct 2019 06:25:46 -0700 (PDT) Subject: Re: [RFC PATCH 1/3] dma-mapping: introduce a new dma api dma_addr_to_phys_addr() To: Laurentiu Tudor , "hch@lst.de" , "joro@8bytes.org" , Ioana Ciocoi Radulescu , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "netdev@vger.kernel.org" , Ioana Ciornei Cc: Leo Li , Diana Madalina Craciun , "davem@davemloft.net" , Madalin-cristian Bucur References: <20191022125502.12495-1-laurentiu.tudor@nxp.com> <20191022125502.12495-2-laurentiu.tudor@nxp.com> From: Robin Murphy Message-ID: <62561dca-cdd7-fe01-a0c3-7b5971c96e7e@arm.com> Date: Tue, 22 Oct 2019 14:25:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20191022125502.12495-2-laurentiu.tudor@nxp.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/10/2019 13:55, Laurentiu Tudor wrote: > From: Laurentiu Tudor > > Introduce a new dma map op called dma_addr_to_phys_addr() that converts > a dma address to the physical address backing it up and add wrapper for > it. I'd really love it if there was a name which could encapsulate that this is *only* for extreme special cases of constrained descriptors/pagetable entries/etc. where there's simply no practical way to keep track of a CPU address alongside the DMA address, and the only option is this potentially-arbitrarily-complex operation (I mean, on some systems it may end up taking locks and poking hardware). Either way it's tricky - much as I don't like adding an interface which is ripe for drivers to misuse, I also really don't want hacks like bdf95923086f shoved into other APIs to compensate, so on balance I'd probably consider this proposal ever so slightly the lesser evil. > Signed-off-by: Laurentiu Tudor > --- > include/linux/dma-mapping.h | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > index 4a1c4fca475a..5965d159c9a9 100644 > --- a/include/linux/dma-mapping.h > +++ b/include/linux/dma-mapping.h > @@ -132,6 +132,8 @@ struct dma_map_ops { > u64 (*get_required_mask)(struct device *dev); > size_t (*max_mapping_size)(struct device *dev); > unsigned long (*get_merge_boundary)(struct device *dev); > + phys_addr_t (*dma_addr_to_phys_addr)(struct device *dev, > + dma_addr_t dma_handle); I'd be inclined to name the internal callback something a bit snappier like .get_phys_addr. > }; > > #define DMA_MAPPING_ERROR (~(dma_addr_t)0) > @@ -442,6 +444,19 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) > return 0; > } > > +static inline phys_addr_t dma_addr_to_phys_addr(struct device *dev, > + dma_addr_t dma_handle) > +{ > + const struct dma_map_ops *ops = get_dma_ops(dev); > + > + if (dma_is_direct(ops)) > + return (phys_addr_t)dma_handle; Well that's not right, is it - remember why you had that namespace collision? ;) Robin. > + else if (ops->dma_addr_to_phys_addr) > + return ops->dma_addr_to_phys_addr(dev, dma_handle); > + > + return 0; > +} > + > 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, > @@ -578,6 +593,12 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev) > { > return 0; > } > + > +static inline phys_addr_t dma_addr_to_phys_addr(struct device *dev, > + dma_addr_t dma_handle) > +{ > + return 0; > +} > #endif /* CONFIG_HAS_DMA */ > > static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, >