Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jun 2017 18:27:05 +0000 (UTC)
From:      Zbigniew Bodek <zbb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320199 - head/sys/arm/mv
Message-ID:  <201706211827.v5LIR5vg065868@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zbb
Date: Wed Jun 21 18:27:05 2017
New Revision: 320199
URL: https://svnweb.freebsd.org/changeset/base/320199

Log:
  Create root DMA tag and fix MBUS windows on DMA coherent platforms
  
  Armada 38x SoCs, in order to work properly in IO-coherent mode,
  requires an update of the MBUS windows attributesd.
  
  This patch also configures nexus coherent dma tag, because all
  busses and children devices have to inherit this setting in runtime.
  The latter has to be executed as a sysinit (SI_SUB_DRIVERS type),
  so that bus_dma_tag_create() can be executed properly.
  
  Submitted by: Michal Mazur <mkm@semihalf.com>
   	      Marcin Wojtas <mw@semihalf.com>
  Obtained from: Semihalf
  Sponsored by: Stormshield
  Reviewed by: ian
  Differential revision: https://reviews.freebsd.org/D11203

Modified:
  head/sys/arm/mv/mv_common.c
  head/sys/arm/mv/mv_machdep.c

Modified: head/sys/arm/mv/mv_common.c
==============================================================================
--- head/sys/arm/mv/mv_common.c	Wed Jun 21 18:25:35 2017	(r320198)
+++ head/sys/arm/mv/mv_common.c	Wed Jun 21 18:27:05 2017	(r320199)
@@ -128,6 +128,7 @@ static uint32_t dev_mask = 0;
 static int cpu_wins_no = 0;
 static int eth_port = 0;
 static int usb_port = 0;
+static boolean_t platform_io_coherent = false;
 
 static struct decode_win cpu_win_tbl[MAX_CPU_WIN];
 
@@ -1064,7 +1065,7 @@ ddr_size(int i)
 uint32_t
 ddr_attr(int i)
 {
-	uint32_t dev, rev;
+	uint32_t dev, rev, attr;
 
 	soc_id(&dev, &rev);
 	if (dev == MV_DEV_88RC8180)
@@ -1072,10 +1073,14 @@ ddr_attr(int i)
 	if (dev == MV_DEV_88F6781)
 		return (0);
 
-	return (i == 0 ? 0xe :
+	attr = (i == 0 ? 0xe :
 	    (i == 1 ? 0xd :
 	    (i == 2 ? 0xb :
 	    (i == 3 ? 0x7 : 0xff))));
+	if (platform_io_coherent)
+		attr |= 0x10;
+
+	return (attr);
 }
 
 uint32_t
@@ -2478,6 +2483,10 @@ fdt_win_setup(void)
 	node = OF_finddevice("/");
 	if (node == -1)
 		panic("fdt_win_setup: no root node");
+
+	/* Allow for coherent transactions on the A38x MBUS */
+	if (ofw_bus_node_is_compatible(node, "marvell,armada380"))
+		platform_io_coherent = true;
 
 	/*
 	 * Traverse through all children of root and simple-bus nodes.

Modified: head/sys/arm/mv/mv_machdep.c
==============================================================================
--- head/sys/arm/mv/mv_machdep.c	Wed Jun 21 18:25:35 2017	(r320198)
+++ head/sys/arm/mv/mv_machdep.c	Wed Jun 21 18:27:05 2017	(r320199)
@@ -46,10 +46,13 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/bus.h>
 #include <sys/devmap.h>
+#include <sys/kernel.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
 
+#include <arm/arm/nexusvar.h>
+
 #include <machine/bus.h>
 #include <machine/fdt.h>
 #include <machine/machdep.h>
@@ -86,6 +89,39 @@ int armada38x_mbus_optimization(void);
 #define MPP_PINS_PER_REG	8
 #define MPP_SEL(pin,func)	(((func) & 0xf) <<		\
     (((pin) % MPP_PINS_PER_REG) * 4))
+
+static void
+mv_busdma_tag_init(void *arg __unused)
+{
+	phandle_t node;
+	bus_dma_tag_t dmat;
+
+	/*
+	 * If this platform has coherent DMA, create the parent DMA tag to pass
+	 * down the coherent flag to all busses and devices on the platform,
+	 * otherwise return without doing anything. By default create tag
+	 * for all A38x-based platforms only.
+	 */
+	if ((node = OF_finddevice("/")) == -1)
+		return;
+	if (ofw_bus_node_is_compatible(node, "marvell,armada380") == 0)
+		return;
+
+	bus_dma_tag_create(NULL,	/* No parent tag */
+	    1, 0,			/* alignment, bounds */
+	    BUS_SPACE_MAXADDR,		/* lowaddr */
+	    BUS_SPACE_MAXADDR,		/* highaddr */
+	    NULL, NULL,			/* filter, filterarg */
+	    BUS_SPACE_MAXSIZE,		/* maxsize */
+	    BUS_SPACE_UNRESTRICTED,	/* nsegments */
+	    BUS_SPACE_MAXSIZE,		/* maxsegsize */
+	    BUS_DMA_COHERENT,		/* flags */
+	    NULL, NULL,			/* lockfunc, lockarg */
+	    &dmat);
+
+	nexus_set_dma_tag(dmat);
+}
+SYSINIT(mv_busdma_tag, SI_SUB_DRIVERS, SI_ORDER_ANY, mv_busdma_tag_init, NULL);
 
 static int
 platform_mpp_init(void)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706211827.v5LIR5vg065868>