mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Denis Orlov <denorl2009@gmail.com>
To: barebox@lists.infradead.org
Cc: Denis Orlov <denorl2009@gmail.com>
Subject: [PATCH 2/2] dma: use virt/phys conversions when no dma_offset is specified
Date: Fri, 10 Feb 2023 17:39:24 +0300	[thread overview]
Message-ID: <20230210143924.915149-3-denorl2009@gmail.com> (raw)
In-Reply-To: <20230210143924.915149-1-denorl2009@gmail.com>

The code was assuming that in such cases we can just use cpu addresses
as physical ones. This is incorrect on MIPS, the only platform that has
its own virt_to_phys/phys_to_virt functions defined.
This fixes issues with DMA mappings on MIPS, with e1000 PCI ethernet
card now working on Malta in QEMU.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 drivers/dma/map.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/dma/map.c b/drivers/dma/map.c
index a00abf6421..13dbf2840f 100644
--- a/drivers/dma/map.c
+++ b/drivers/dma/map.c
@@ -3,25 +3,20 @@
 
 #include <dma.h>
 
-static inline dma_addr_t cpu_to_dma(struct device *dev,
-				    unsigned long cpu_addr)
+static inline dma_addr_t cpu_to_dma(struct device *dev, void *cpu_addr)
 {
-	dma_addr_t dma_addr = cpu_addr;
+	if (dev && dev->dma_offset)
+		return (unsigned long)cpu_addr - dev->dma_offset;
 
-	if (dev)
-		dma_addr -= dev->dma_offset;
-
-	return dma_addr;
+	return virt_to_phys(cpu_addr);
 }
 
-static inline unsigned long dma_to_cpu(struct device *dev, dma_addr_t addr)
+static inline void *dma_to_cpu(struct device *dev, dma_addr_t addr)
 {
-	unsigned long cpu_addr = addr;
-
-	if (dev)
-		cpu_addr += dev->dma_offset;
+	if (dev && dev->dma_offset)
+		return (void *)(addr + dev->dma_offset);
 
-	return cpu_addr;
+	return phys_to_virt(addr);
 }
 
 dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
@@ -31,13 +26,13 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
 
 	dma_sync_single_for_device(addr, size, dir);
 
-	return cpu_to_dma(dev, addr);
+	return cpu_to_dma(dev, ptr);
 }
 
 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
 		      enum dma_data_direction dir)
 {
-	unsigned long addr = dma_to_cpu(dev, dma_addr);
+	unsigned long addr = (unsigned long)dma_to_cpu(dev, dma_addr);
 
 	dma_sync_single_for_cpu(addr, size, dir);
 }
-- 
2.30.2




  parent reply	other threads:[~2023-02-10 14:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10 14:39 [PATCH 0/2] make e1000 work on MIPS Denis Orlov
2023-02-10 14:39 ` [PATCH 1/2] net: e1000: properly map dma allocations Denis Orlov
2023-02-10 14:39 ` Denis Orlov [this message]
2023-02-13  9:00 ` [PATCH 0/2] make e1000 work on MIPS Sascha Hauer

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=20230210143924.915149-3-denorl2009@gmail.com \
    --to=denorl2009@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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