From: Kevin Cernekee <cernekee@gmail.com>
To: ralf@linux-mips.org
Cc: f.fainelli@gmail.com, tglx@linutronix.de, jason@lakedaemon.net,
jogo@openwrt.org, arnd@arndb.de, computersforpeace@gmail.com,
linux-mips@linux-mips.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH V5 15/23] MIPS: BMIPS: Rewrite DMA code to use "dma-ranges" property
Date: Fri, 12 Dec 2014 14:07:06 -0800 [thread overview]
Message-ID: <1418422034-17099-16-git-send-email-cernekee@gmail.com> (raw)
In-Reply-To: <1418422034-17099-1-git-send-email-cernekee@gmail.com>
This is a more standardized way of handling DMA remapping, and it is
suitable for the memory map found on BCM3384.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
arch/mips/bmips/dma.c | 100 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 68 insertions(+), 32 deletions(-)
diff --git a/arch/mips/bmips/dma.c b/arch/mips/bmips/dma.c
index ea42012..04790f4 100644
--- a/arch/mips/bmips/dma.c
+++ b/arch/mips/bmips/dma.c
@@ -6,76 +6,112 @@
* Copyright (C) 2014 Kevin Cernekee <cernekee@gmail.com>
*/
+#define pr_fmt(fmt) "bmips-dma: " fmt
+
#include <linux/device.h>
#include <linux/dma-direction.h>
#include <linux/dma-mapping.h>
#include <linux/init.h>
-#include <linux/mm.h>
+#include <linux/io.h>
#include <linux/of.h>
-#include <linux/pci.h>
+#include <linux/printk.h>
+#include <linux/slab.h>
#include <linux/types.h>
#include <dma-coherence.h>
/*
- * BCM3384 has configurable address translation windows which allow the
+ * BCM338x has configurable address translation windows which allow the
* peripherals' DMA addresses to be different from the Zephyr-visible
* physical addresses. e.g. usb_dma_addr = zephyr_pa ^ 0x08000000
*
- * If our DT "memory" node has a "dma-xor-mask" property we will enable this
- * translation using the provided offset.
+ * If the "brcm,ubus" node has a "dma-ranges" property we will enable this
+ * translation globally using the provided information. This implements a
+ * very limited subset of "dma-ranges" support and it will probably be
+ * replaced by a more generic version later.
*/
-static u32 bcm3384_dma_xor_mask;
-static u32 bcm3384_dma_xor_limit = 0xffffffff;
-/*
- * PCI collapses the memory hole at 0x10000000 - 0x1fffffff.
- * On systems with a dma-xor-mask, this range is guaranteed to live above
- * the dma-xor-limit.
- */
-#define BCM3384_MEM_HOLE_PA 0x10000000
-#define BCM3384_MEM_HOLE_SIZE 0x10000000
+struct bmips_dma_range {
+ u32 child_addr;
+ u32 parent_addr;
+ u32 size;
+};
-static dma_addr_t bcm3384_phys_to_dma(struct device *dev, phys_addr_t pa)
+static struct bmips_dma_range *bmips_dma_ranges;
+
+#define FLUSH_RAC 0x100
+
+static dma_addr_t bmips_phys_to_dma(struct device *dev, phys_addr_t pa)
{
- if (dev && dev_is_pci(dev) &&
- pa >= (BCM3384_MEM_HOLE_PA + BCM3384_MEM_HOLE_SIZE))
- return pa - BCM3384_MEM_HOLE_SIZE;
- if (pa <= bcm3384_dma_xor_limit)
- return pa ^ bcm3384_dma_xor_mask;
+ struct bmips_dma_range *r;
+
+ for (r = bmips_dma_ranges; r && r->size; r++) {
+ if (pa >= r->child_addr &&
+ pa < (r->child_addr + r->size))
+ return pa - r->child_addr + r->parent_addr;
+ }
return pa;
}
dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t size)
{
- return bcm3384_phys_to_dma(dev, virt_to_phys(addr));
+ return bmips_phys_to_dma(dev, virt_to_phys(addr));
}
dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page)
{
- return bcm3384_phys_to_dma(dev, page_to_phys(page));
+ return bmips_phys_to_dma(dev, page_to_phys(page));
}
unsigned long plat_dma_addr_to_phys(struct device *dev, dma_addr_t dma_addr)
{
- if (dev && dev_is_pci(dev) &&
- dma_addr >= BCM3384_MEM_HOLE_PA)
- return dma_addr + BCM3384_MEM_HOLE_SIZE;
- if ((dma_addr ^ bcm3384_dma_xor_mask) <= bcm3384_dma_xor_limit)
- return dma_addr ^ bcm3384_dma_xor_mask;
+ struct bmips_dma_range *r;
+
+ for (r = bmips_dma_ranges; r && r->size; r++) {
+ if (dma_addr >= r->parent_addr &&
+ dma_addr < (r->parent_addr + r->size))
+ return dma_addr - r->parent_addr + r->child_addr;
+ }
return dma_addr;
}
-static int __init bcm3384_init_dma_xor(void)
+static int __init bmips_init_dma_ranges(void)
{
- struct device_node *np = of_find_node_by_type(NULL, "memory");
+ struct device_node *np =
+ of_find_compatible_node(NULL, NULL, "brcm,ubus");
+ const __be32 *data;
+ struct bmips_dma_range *r;
+ int len;
if (!np)
return 0;
- of_property_read_u32(np, "dma-xor-mask", &bcm3384_dma_xor_mask);
- of_property_read_u32(np, "dma-xor-limit", &bcm3384_dma_xor_limit);
+ data = of_get_property(np, "dma-ranges", &len);
+ if (!data)
+ goto out_good;
+
+ len /= sizeof(*data) * 3;
+ if (!len)
+ goto out_bad;
+
+ /* add a dummy (zero) entry at the end as a sentinel */
+ bmips_dma_ranges = kzalloc(sizeof(struct bmips_dma_range) * (len + 1),
+ GFP_KERNEL);
+ if (!bmips_dma_ranges)
+ goto out_bad;
+ for (r = bmips_dma_ranges; len; len--, r++) {
+ r->child_addr = be32_to_cpup(data++);
+ r->parent_addr = be32_to_cpup(data++);
+ r->size = be32_to_cpup(data++);
+ }
+
+out_good:
of_node_put(np);
return 0;
+
+out_bad:
+ pr_err("error parsing dma-ranges property\n");
+ of_node_put(np);
+ return -EINVAL;
}
-arch_initcall(bcm3384_init_dma_xor);
+arch_initcall(bmips_init_dma_ranges);
--
2.1.1
next prev parent reply other threads:[~2014-12-12 22:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-12 22:06 [PATCH V5 00/23] Generic BMIPS kernel Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 01/23] MIPS: bcm3384: Fix outdated use of mips_cpu_intc_init() Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 02/23] MIPS: Create a common <asm/mach-generic/war.h> Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 03/23] MIPS: bcm3384: Rename "bcm3384" target to "bmips" Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 04/23] irqchip: Update docs regarding irq_domain_add_tree() Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 05/23] irqchip: brcmstb-l2: don't clear wakeable interrupts at init time Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 06/23] irqchip: bcm7120-l2: Refactor driver for arbitrary IRQEN/IRQSTAT offsets Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 07/23] irqchip: bcm7120-l2: Split STB-specific logic into its own function Kevin Cernekee
2014-12-12 22:06 ` [PATCH V5 08/23] irqchip: bcm7120-l2: Add support for BCM3380-style controllers Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 09/23] irqchip: Add new driver for BCM7038-style level 1 interrupt controllers Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 10/23] MIPS: Let __dt_register_buses accept a single bus type Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 11/23] MIPS: Fall back to the generic restart notifier Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 12/23] MIPS: Reorder MIPS_L1_CACHE_SHIFT priorities Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 13/23] MIPS: BMIPS: Flush the readahead cache after DMA Kevin Cernekee
[not found] ` <1418422034-17099-14-git-send-email-cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-15 9:43 ` Jonas Gorski
[not found] ` <CAOiHx=nX9jJEFZmkA-1fWj47whq85wj-ZgUxnZBwpAYDUfAO4w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-20 1:39 ` Kevin Cernekee
[not found] ` <CAJiQ=7AZdwCX6bmLD1B4TzfmKriE3HVEEa5zP3WRnENZjGS-hA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-20 12:44 ` Jonas Gorski
[not found] ` <CAOiHx=m9RzU5n2fjJcph6u=avUAEZJYw0-mBCSMRzDJvSD5CFA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-20 17:28 ` Kevin Cernekee
2014-12-21 10:56 ` Florian Fainelli
2014-12-12 22:07 ` [PATCH V5 14/23] MIPS: BMIPS: Document the firmware->kernel DTB interface Kevin Cernekee
2014-12-12 22:07 ` Kevin Cernekee [this message]
2014-12-12 22:07 ` [PATCH V5 16/23] MIPS: BMIPS: Remove bogus bus name Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 17/23] MIPS: BMIPS: Add quirks for several Broadcom platforms Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 18/23] MIPS: BMIPS: Delete the irqchip driver from irq.c Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 19/23] MIPS: BMIPS: Use a non-default FIXADDR_TOP setting Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 20/23] MIPS: BMIPS: Enable additional peripheral and CPU support in defconfig Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 21/23] MIPS: BMIPS: Refresh BCM3384 DTS files Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 22/23] MIPS: BMIPS: Update DT bindings to reflect new SoC support Kevin Cernekee
2014-12-12 22:07 ` [PATCH V5 23/23] MIPS: BMIPS: Add DTS files for several platforms Kevin Cernekee
[not found] ` <1418422034-17099-1-git-send-email-cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-15 9:58 ` [PATCH V5 00/23] Generic BMIPS kernel Arnd Bergmann
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=1418422034-17099-16-git-send-email-cernekee@gmail.com \
--to=cernekee@gmail.com \
--cc=arnd@arndb.de \
--cc=computersforpeace@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=jason@lakedaemon.net \
--cc=jogo@openwrt.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=tglx@linutronix.de \
/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).