From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Jim Quinlan <james.quinlan@broadcom.com>, Christoph Hellwig <hch@lst.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
Rich Felker <dalias@libc.org>,
"open list:SUPERH" <linux-sh@vger.kernel.org>,
David Airlie <airlied@linux.ie>,
"open list:PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS"
<linux-pci@vger.kernel.org>, Hanjun Guo <guohanjun@huawei.com>,
"open list:REMOTE PROCESSOR \(REMOTEPROC\) SUBSYSTEM"
<linux-remoteproc@vger.kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Julien Grall <julien.grall@arm.com>,
"H. Peter Anvin" <hpa@zytor.com>, Will Deacon <will@kernel.org>,
Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
"open list:STAGING SUBSYSTEM" <devel@driverdev.osuosl.org>,
Wolfram Sang <wsa@kernel.org>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Frank Rowand <frowand.list@gmail.com>,
Joerg Roedel <joro@8bytes.org>,
"maintainer:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)"
<x86@kernel.org>, Russell King <linux@armlinux.org.uk>,
"open list:ACPI FOR ARM64 \(ACPI/arm64\)"
<linux-acpi@vger.kernel.org>, Chen-Yu Tsai <wens@csie.org>,
Ingo Molnar <mingo@redhat.com>,
"maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE"
<bcm-kernel-feedback-list@broadcom.com>,
Alan Stern <stern@rowland.harvard.edu>,
David Kershner <david.kershner@unisys.com>,
Len Brown <lenb@kernel.org>, Ohad Ben-Cohen <ohad@wizery.com>,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE"
<devicetree@vger.kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Dan Williams <dan.j.williams@intel.com>,
Rob Herring <robh+dt@kernel.org>, Borislav Petkov <bp@alien8.de>,
"open list:DRM DRIVERS FOR ALLWINNER A10"
<dri-devel@lists.freedesktop.org>,
Yong Deng <yong.deng@magewell.com>,
Santosh Shilimkar <ssantosh@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
Saravana Kannan <saravanak@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Oliver Neukum <oneukum@suse.com>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
open list <linux-kernel@vger.kernel.org>,
Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
"open list:IOMMU DRIVERS" <iommu@lists.linux-foundation.org>,
Mark Brown <broonie@kernel.org>,
Stefano Stabellini <sstabellini@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
"open list:ALLWINNER A10 CSI DRIVER"
<linux-media@vger.kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
"open list:USB SUBSYSTEM" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH v3 09/13] device core: Introduce multiple dma pfn offsets
Date: Fri, 05 Jun 2020 19:27:16 +0200 [thread overview]
Message-ID: <f7278849ee08211a6446d7a5a8ffc163751b34bc.camel@suse.de> (raw)
In-Reply-To: <CA+-6iNzutM0jfyHTOVZMn8_-MqHwJMAyoQTGMbU3vPnJKd8USA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 4410 bytes --]
Hi Christoph,
a question arouse, is there a real value to dealing with PFNs (as opposed to
real addresses) in the core DMA code/structures? I see that in some cases it
eases interacting with mm, but the overwhelming usage of say,
dev->dma_pfn_offset, involves shifting it.
Hi Jim,
On Thu, 2020-06-04 at 14:01 -0400, Jim Quinlan wrote:
> Hi Nicolas,
[...]
> > I understand the need for dev to be around, devm_*() is key. But also it's
> > important to keep the functions on purpose. And if of_dma_get_range() starts
> > setting ranges it calls, for the very least, for a function rename. Although
> > I'd rather split the parsing and setting of ranges as mentioned earlier.
> > That
> > said, I get that's a more drastic move.
>
> I agree with you. I could do this from device.c:
>
> of_dma_get_num_ranges(..., &num_ranges); /* new function */
> r = devm_kcalloc(dev, num_ranges + 1, sizeof(*r), GFP_KERNEL);
> of_dma_get_range(np, &dma_addr, &paddr, &size, r, num_ranges);
>
> The problem here is that there could be four ranges, all with
> offset=0. My current code would optimize this case out but the above
> would have us holding useless memory and looping through the four
> ranges on every dma <=> phys conversion only to add 0.
Point taken. Ultimately it's setting the device's dma ranges in
of_dma_get_range() that was really bothering me, so if we have to pass the
device pointer for allocations, be it.
> > Talking about drastic moves. How about getting rid of the concept of
> > dma_pfn_offset for drivers altogether. Let them provide
> > dma_pfn_offset_regions
> > (even when there is only one). I feel it's conceptually nicer, as you'd be
> > dealing only in one currency, so to speak, and you'd centralize the bus DMA
> > ranges setter function which is always easier to maintain.
> Do you agree that we have to somehow hang this info on the struct
> device structure? Because in the dma2phys() and phys2dma() all you
> have is the dev parameter. I don't see how this can be done w/o
> involving dev.
Sorry I didn't make myself clear here. What bothers me is having two functions
setting the same device parameter trough different means, I'd be happy to get
rid of attach_uniform_dma_pfn_offset(), and always use the same function to set
a device's bus dma regions. Something the likes of this comes to mind:
dma_attach_pfn_offset_region(struct device *dev, struct dma_pfn_offset_regions *r)
We could maybe use some helper macros for the linear case. But that's the gist
of it.
Also, it goes hand in hand with the comment below. Why having a special case
for non sparse DMA offsets in struct dma_pfn_offset_regions? The way I see it,
in this case, code simplicity is more interesting than a small optimization.
> > I'd go as far as not creating a special case for uniform offsets. Let just
> > set
> > cpu_end and dma_end to -1 so we always get a match. It's slightly more
> > compute
> > heavy, but I don't think it's worth the optimization.
> Well, there are two subcases here. One where we do know the bounds
> and one where we do not. I suppose for the latter I could have the
> drivers calling it with begin=0 and end=~(dma_addr_t)0. Let me give
> this some thought...
>
> > Just my two cents :)
>
> Worth much more than $0.02 IMO :-)
BTW, would you consider renaming the DMA offset struct to something simpler
like, struct bus_dma_region? It complements 'dev->bus_dma_limit' better IMO.
> BTW, I tried putting the "if (dev->dma_pfn_offset_map)" clause inside
> the inline functions but the problem is that it slows the fastpath;
> consider the following code from dma-direct.h
>
> if (dev->dma_pfn_offset_map) {
> unsigned long dma_pfn_offset =
dma_pfn_offset_from_phys_addr(dev, paddr);
>
> dev_addr -= ((dma_addr_t)dma_pfn_offset << PAGE_SHIFT);
> }
> return dev_addr;
>
> becomes
>
> unsigned long dma_pfn_offset = dma_pfn_offset_from_phys_addr(dev,
paddr);
>
> dev_addr -= ((dma_addr_t)dma_pfn_offset << PAGE_SHIFT);
> return dev_addr;
>
> So those configurations that have no dma_pfn_offsets are doing an
> unnecessary shift and add.
Fair enough. Still not a huge difference, but I see the value being the most
common case.
Regards,
Nicolas
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-06-07 19:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-03 19:20 [PATCH v3 00/13] PCI: brcmstb: enable PCIe for STB chips Jim Quinlan
2020-06-03 19:20 ` [PATCH v3 09/13] device core: Introduce multiple dma pfn offsets Jim Quinlan
2020-06-04 11:04 ` Dan Carpenter
2020-06-04 13:48 ` Jim Quinlan
2020-06-04 14:18 ` Dan Carpenter
2020-06-04 14:43 ` Jim Quinlan
2020-06-04 13:53 ` Nicolas Saenz Julienne
2020-06-04 14:35 ` Jim Quinlan
2020-06-04 15:05 ` Andy Shevchenko
2020-06-04 16:28 ` Jim Quinlan
2020-06-04 16:52 ` Nicolas Saenz Julienne
2020-06-04 18:01 ` Jim Quinlan
2020-06-05 17:27 ` Nicolas Saenz Julienne [this message]
2020-06-05 20:41 ` Jim Quinlan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f7278849ee08211a6446d7a5a8ffc163751b34bc.camel@suse.de \
--to=nsaenzjulienne@suse.de \
--cc=airlied@linux.ie \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bhelgaas@google.com \
--cc=bjorn.andersson@linaro.org \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=dalias@libc.org \
--cc=dan.j.williams@intel.com \
--cc=david.kershner@unisys.com \
--cc=devel@driverdev.osuosl.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=frowand.list@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=guohanjun@huawei.com \
--cc=hch@lst.de \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux-foundation.org \
--cc=james.quinlan@broadcom.com \
--cc=joro@8bytes.org \
--cc=julien.grall@arm.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lorenzo.pieralisi@arm.com \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=mingo@redhat.com \
--cc=ohad@wizery.com \
--cc=oneukum@suse.com \
--cc=paul.kocialkowski@bootlin.com \
--cc=rjw@rjwysocki.net \
--cc=robh+dt@kernel.org \
--cc=robin.murphy@arm.com \
--cc=saravanak@google.com \
--cc=ssantosh@kernel.org \
--cc=sstabellini@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=sudeep.holla@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=tglx@linutronix.de \
--cc=ulf.hansson@linaro.org \
--cc=wens@csie.org \
--cc=will@kernel.org \
--cc=wsa@kernel.org \
--cc=x86@kernel.org \
--cc=yong.deng@magewell.com \
--cc=ysato@users.sourceforge.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox