linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sh: use dma_to_phys() instead of dev->dma_pfn_offset
@ 2019-10-11 16:51 Nicolas Saenz Julienne
  2019-10-15  7:43 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2019-10-11 16:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: hch, Nicolas Saenz Julienne, Yoshinori Sato, Rich Felker,
	linux-sh

It's more explicit and lets dma-direct handle the specifics of how to
translate addresses.

On top of that get rid of warnings as, since the introduction of commit
6fa1d28e38c ("sh: use generic dma_noncoherent_ops"), it's impossible for
the dev to be NULL.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---

NOTE: this was only compile tested.

 arch/sh/kernel/dma-coherent.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/sh/kernel/dma-coherent.c b/arch/sh/kernel/dma-coherent.c
index b17514619b7e..f6618ed01a42 100644
--- a/arch/sh/kernel/dma-coherent.c
+++ b/arch/sh/kernel/dma-coherent.c
@@ -4,6 +4,7 @@
  */
 #include <linux/mm.h>
 #include <linux/init.h>
+#include <linux/dma-direct.h>
 #include <linux/dma-noncoherent.h>
 #include <linux/module.h>
 #include <asm/cacheflush.h>
@@ -36,9 +37,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
 
 	split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order);
 
-	*dma_handle = virt_to_phys(ret);
-	if (!WARN_ON(!dev))
-		*dma_handle -= PFN_PHYS(dev->dma_pfn_offset);
+	*dma_handle = phys_to_dma(dev, virt_to_phys(ret));
 
 	return ret_nocache;
 }
@@ -47,12 +46,9 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr,
 		dma_addr_t dma_handle, unsigned long attrs)
 {
 	int order = get_order(size);
-	unsigned long pfn = (dma_handle >> PAGE_SHIFT);
+	unsigned long pfn = __phys_to_pfn(dma_to_phys(dev, dma_handle));
 	int k;
 
-	if (!WARN_ON(!dev))
-		pfn += dev->dma_pfn_offset;
-
 	for (k = 0; k < (1 << order); k++)
 		__free_pages(pfn_to_page(pfn + k), 0);
 
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sh: use dma_to_phys() instead of dev->dma_pfn_offset
  2019-10-11 16:51 [PATCH] sh: use dma_to_phys() instead of dev->dma_pfn_offset Nicolas Saenz Julienne
@ 2019-10-15  7:43 ` Christoph Hellwig
  2019-10-15  8:05   ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2019-10-15  7:43 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: linux-kernel, hch, Yoshinori Sato, Rich Felker, linux-sh

On Fri, Oct 11, 2019 at 06:51:29PM +0200, Nicolas Saenz Julienne wrote:
> It's more explicit and lets dma-direct handle the specifics of how to
> translate addresses.
> 
> On top of that get rid of warnings as, since the introduction of commit
> 6fa1d28e38c ("sh: use generic dma_noncoherent_ops"), it's impossible for
> the dev to be NULL.

This looks ok, but the real answer is to switch sh to the generic
dma remapping code.  I've been trying to get this included for about
a year now, but never managed to get a reply from the sh maintainers.

Here is the last one:

http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/sh-dma-remap

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sh: use dma_to_phys() instead of dev->dma_pfn_offset
  2019-10-15  7:43 ` Christoph Hellwig
@ 2019-10-15  8:05   ` Nicolas Saenz Julienne
  2019-10-15  9:49     ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2019-10-15  8:05 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel, Yoshinori Sato, Rich Felker, linux-sh

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

On Tue, 2019-10-15 at 00:43 -0700, Christoph Hellwig wrote:
> On Fri, Oct 11, 2019 at 06:51:29PM +0200, Nicolas Saenz Julienne wrote:
> > It's more explicit and lets dma-direct handle the specifics of how to
> > translate addresses.
> > 
> > On top of that get rid of warnings as, since the introduction of commit
> > 6fa1d28e38c ("sh: use generic dma_noncoherent_ops"), it's impossible for
> > the dev to be NULL.
> 
> This looks ok, but the real answer is to switch sh to the generic
> dma remapping code.  I've been trying to get this included for about
> a year now, but never managed to get a reply from the sh maintainers.

I see, well I guess this one will get ignored too :)

> Here is the last one:
> 
> http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/sh-dma-remap

I'd be happy with your series too.

In case you're wondering why I want this: I'm interested in supporting multiple
dma-ranges in DT. So I was looking at the amount of work needed to centralize
usage of dev->dma_pfn_offset. This one patch seemed trivial enough to send
right away.

Regards,
Nicolas


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sh: use dma_to_phys() instead of dev->dma_pfn_offset
  2019-10-15  8:05   ` Nicolas Saenz Julienne
@ 2019-10-15  9:49     ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2019-10-15  9:49 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: Christoph Hellwig, linux-kernel, Yoshinori Sato, Rich Felker,
	linux-sh

On Tue, Oct 15, 2019 at 10:05:52AM +0200, Nicolas Saenz Julienne wrote:
> I see, well I guess this one will get ignored too :)
> 
> > Here is the last one:
> > 
> > http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/sh-dma-remap
> 
> I'd be happy with your series too.

Let's see if we can make any progress this merge window..

> In case you're wondering why I want this: I'm interested in supporting multiple
> dma-ranges in DT. So I was looking at the amount of work needed to centralize
> usage of dev->dma_pfn_offset. This one patch seemed trivial enough to send
> right away.

Sounds useful, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-15  9:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-11 16:51 [PATCH] sh: use dma_to_phys() instead of dev->dma_pfn_offset Nicolas Saenz Julienne
2019-10-15  7:43 ` Christoph Hellwig
2019-10-15  8:05   ` Nicolas Saenz Julienne
2019-10-15  9:49     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).