From: Gerd Hoffmann <kraxel@redhat.com>
To: linux-rpi-kernel@lists.infradead.org
Cc: mzoran <mzoran@crowfest.net>, Gerd Hoffmann <kraxel@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT
(AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 06/32] arm64: Fix physical to DMA mappings.
Date: Wed, 1 Jun 2016 23:43:15 +0200 [thread overview]
Message-ID: <1464817421-8519-7-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1464817421-8519-1-git-send-email-kraxel@redhat.com>
From: mzoran <mzoran@crowfest.net>
Gets USB and networking to work on Raspberry Pi 3 in 64 bit.
created by mzoran@crowfest.net
[ kraxel: some cleanups ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
arch/arm64/include/asm/dma-mapping.h | 73 ++++++++++++++++++++++++++++++++++--
arch/arm64/include/asm/memory.h | 8 ++++
2 files changed, 77 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h
index 7dbea6c..48e8856 100644
--- a/arch/arm64/include/asm/dma-mapping.h
+++ b/arch/arm64/include/asm/dma-mapping.h
@@ -19,7 +19,11 @@
#ifdef __KERNEL__
#include <linux/types.h>
-#include <linux/vmalloc.h>
+#include <linux/scatterlist.h>
+#include <linux/dma-attrs.h>
+#include <linux/dma-debug.h>
+
+#include <asm/memory.h>
#include <xen/xen.h>
#include <asm/xen/hypervisor.h>
@@ -56,6 +60,54 @@ void arch_teardown_dma_ops(struct device *dev);
#define arch_teardown_dma_ops arch_teardown_dma_ops
#endif
+/*
+ * dma_to_pfn/pfn_to_dma/dma_to_virt/virt_to_dma are architecture private
+ * functions used internally by the DMA-mapping API to provide DMA
+ * addresses. They must not be used by drivers.
+ */
+static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
+{
+ if (dev)
+ pfn -= dev->dma_pfn_offset;
+ return (dma_addr_t)__pfn_to_bus(pfn);
+}
+
+static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
+{
+ unsigned long pfn = __bus_to_pfn(addr);
+
+ if (dev)
+ pfn += dev->dma_pfn_offset;
+
+ return pfn;
+}
+
+static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
+{
+ if (dev) {
+ unsigned long pfn = dma_to_pfn(dev, addr);
+
+ return phys_to_virt(__pfn_to_phys(pfn));
+ }
+
+ return (void *)__bus_to_virt((unsigned long)addr);
+}
+
+static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
+{
+ if (dev)
+ return pfn_to_dma(dev, virt_to_pfn(addr));
+
+ return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
+}
+
+/* The ARM override for dma_max_pfn() */
+static inline unsigned long dma_max_pfn(struct device *dev)
+{
+ return PHYS_PFN_OFFSET + dma_to_pfn(dev, *dev->dma_mask);
+}
+#define dma_max_pfn(dev) dma_max_pfn(dev)
+
/* do not use this function in a driver */
static inline bool is_device_dma_coherent(struct device *dev)
{
@@ -66,20 +118,33 @@ static inline bool is_device_dma_coherent(struct device *dev)
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
{
- return (dma_addr_t)paddr;
+ unsigned int offset = paddr & ~PAGE_MASK;
+ return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
}
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
{
- return (phys_addr_t)dev_addr;
+ unsigned int offset = dev_addr & ~PAGE_MASK;
+ return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
}
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
{
+ u64 limit, mask;
+
if (!dev->dma_mask)
return false;
- return addr + size - 1 <= *dev->dma_mask;
+ mask = *dev->dma_mask;
+
+ limit = (mask + 1) & ~mask;
+ if (limit && size > limit)
+ return false;
+
+ if ((addr | (addr + size - 1)) & ~mask)
+ return false;
+
+ return true;
}
static inline void dma_mark_clean(void *addr, size_t size)
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 72a3025..ab4c65e 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -226,6 +226,14 @@ static inline void *phys_to_virt(phys_addr_t x)
#endif
#endif
+#ifndef __virt_to_bus
+#define __virt_to_bus __virt_to_phys
+#define __bus_to_virt __phys_to_virt
+#define __pfn_to_bus(x) __pfn_to_phys(x)
+#define __bus_to_pfn(x) __phys_to_pfn(x)
+#endif
+
+
#include <asm-generic/memory_model.h>
#endif
--
1.8.3.1
next prev parent reply other threads:[~2016-06-01 21:57 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1464817421-8519-1-git-send-email-kraxel@redhat.com>
2016-06-01 21:43 ` [PATCH 01/32] arm64: Add platform selection for BCM2835 Gerd Hoffmann
2016-06-01 21:49 ` Florian Fainelli
2016-06-02 6:45 ` Gerd Hoffmann
2016-06-02 16:25 ` Ray Jui
2016-06-02 16:48 ` Scott Branden
2016-06-02 17:12 ` Gerd Hoffmann
2016-06-02 17:21 ` Scott Branden
2016-06-02 17:36 ` Florian Fainelli
2016-06-02 17:30 ` Catalin Marinas
2016-06-01 21:43 ` [PATCH 02/32] arm64: Add BCM2835 support to the defconfig Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 03/32] irqchip: bcm2835: Avoid arch/arm-specific handle_IRQ Gerd Hoffmann
2016-06-02 0:50 ` Jason Cooper
2016-06-02 18:06 ` Eric Anholt
2016-06-01 21:43 ` [PATCH 04/32] dt-bindings: Add root properties for Raspberry Pi 3 Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 05/32] ARM: bcm2835: Add devicetree for the " Gerd Hoffmann
2016-06-01 21:43 ` Gerd Hoffmann [this message]
2016-06-02 17:20 ` [PATCH 06/32] arm64: Fix physical to DMA mappings Catalin Marinas
2016-06-01 21:43 ` [PATCH 07/32] ARM: bcm2835: dt: Add the ethernet to the device trees Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 08/32] ARM: bcm2837: " Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 09/32] bcm2837-rpi-3-b.dts for 32bit arm Gerd Hoffmann
2016-06-01 22:00 ` Arnd Bergmann
2016-06-01 22:30 ` Eric Anholt
2016-06-01 22:39 ` Arnd Bergmann
2016-06-02 6:56 ` Gerd Hoffmann
2016-06-02 7:24 ` Arnd Bergmann
2016-06-02 9:14 ` Gerd Hoffmann
2016-06-02 9:53 ` Arnd Bergmann
2016-06-02 15:11 ` Gerd Hoffmann
2016-06-02 15:23 ` Arnd Bergmann
2016-06-01 21:43 ` [PATCH 10/32] don't force serial pins to uart0 Gerd Hoffmann
2016-06-01 22:19 ` Arnd Bergmann
2016-06-02 18:19 ` Eric Anholt
2016-06-01 21:43 ` [PATCH 11/32] ARM: bcm2835: Define standard pinctrl groups in the gpio node Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 12/32] ARM: bcm2835: Replace alt0/i2s_alt[02] with standard groups Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 13/32] bcm2837-rpi-3-b.dts: add gpio Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 14/32] bcm2837-rpi-3-b.dts: vc4 hdmi fixup Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 15/32] ARM: bcm2835: Move the emmc pin group to bcm283x.dtsi Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 16/32] bcm2837-rpi-3-b.dts: move the emmc pin group Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 17/32] ARM: bcm2835: Add a group for mapping pins 48-53 to sdhost Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 18/32] ARM: bcm2835: Move most RPi default pin groups to their devices Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 19/32] bcm2837-rpi-3-b.dts: move " Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 20/32] dt-bindings: Add binding for brcm,bcm2835-sdhost Gerd Hoffmann
2016-06-06 13:12 ` Rob Herring
2016-06-01 21:43 ` [PATCH 21/32] mmc: bcm2835-sdhost: Add new driver for the internal SD controller Gerd Hoffmann
2016-06-01 22:18 ` Arnd Bergmann
2016-06-02 18:12 ` Eric Anholt
2016-06-03 8:42 ` Arnd Bergmann
2016-06-21 12:33 ` Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 22/32] ARM: bcm2835: Include SDHOST in the device tree Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 23/32] ARM: bcm2835: Enable SDHOST by default Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 24/32] i2c: bcm2835: Don't complain on -EPROBE_DEFER from getting our clock Gerd Hoffmann
2016-07-22 7:26 ` Wolfram Sang
2016-06-01 21:43 ` [PATCH 25/32] dt-gpio-fix Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 26/32] enable uart1 on the BT pins Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 27/32] gpio: Add support for the FXL6408 GPIO expander Gerd Hoffmann
2016-06-06 23:50 ` Eric Anholt
2016-06-07 0:02 ` Florian Fainelli
2016-06-08 9:10 ` Linus Walleij
2016-06-09 17:22 ` Eric Anholt
2016-06-01 21:43 ` [PATCH 28/32] i2c: bcm2835: Set up the rising/falling edge delays Gerd Hoffmann
2016-07-22 7:26 ` Wolfram Sang
2016-06-01 21:43 ` [PATCH 29/32] ARM: bcm2835: Use i2c-gpio for the expander, instead Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 30/32] ARM: bcm2835: Add a new EMMC pin group from the downstream tree Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 31/32] enable wireless Gerd Hoffmann
2016-06-01 21:43 ` [PATCH 32/32] mmc: bcm2835: Import bcm2835-mmc and switch to it Gerd Hoffmann
2016-06-02 16:52 ` Stefan Wahren
2016-06-02 18:18 ` Eric Anholt
2016-06-02 19:09 ` Stefan Wahren
2016-06-02 20:03 ` Gerd Hoffmann
2016-06-02 21:40 ` Eric Anholt
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=1464817421-8519-7-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=mzoran@crowfest.net \
--cc=will.deacon@arm.com \
/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;
as well as URLs for NNTP newsgroup(s).