Module Name:    src
Committed By:   riastradh
Date:           Wed May 11 02:28:34 UTC 2016

Modified Files:
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device:
            nouveau_engine_device_base.c
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo:
            nouveau_engine_fifo_base.c

Log Message:
Use bus_space_subregion to get fifo channels out of mmio registers.

Evidently it is not enough to just map them separately.  Ran out of
time to investigate why, last time I poked at this and confirmed this
change works.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
    
src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c
cvs rdiff -u -r1.4 -r1.5 \
    
src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c:1.10 src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c:1.11
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c:1.10	Wed Apr 13 08:50:51 2016
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c	Wed May 11 02:28:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_engine_device_base.c,v 1.10 2016/04/13 08:50:51 riastradh Exp $	*/
+/*	$NetBSD: nouveau_engine_device_base.c,v 1.11 2016/05/11 02:28:33 riastradh Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_device_base.c,v 1.10 2016/04/13 08:50:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_device_base.c,v 1.11 2016/05/11 02:28:33 riastradh Exp $");
 
 #include <core/object.h>
 #include <core/device.h>
@@ -297,12 +297,6 @@ nouveau_devobj_ctor(struct nouveau_objec
 #ifdef __NetBSD__
 	if (!(args->disable & NV_DEVICE_DISABLE_MMIO) &&
 	    !nv_subdev(device)->mmiosz) {
-		/*
-		 * Map only through PRAMIN -- don't map the command
-		 * FIFO MMIO regions, which start at NV_FIFO_OFFSET =
-		 * 0x800000 and are mapped separately.
-		 */
-		mmio_size = MIN(mmio_size, 0x800000);
 		/* XXX errno NetBSD->Linux */
 		ret = -bus_space_map(mmiot, mmio_base, mmio_size, 0, &mmioh);
 		if (ret) {

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c:1.4 src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c:1.5
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c:1.4	Wed Feb 10 17:10:47 2016
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c	Wed May 11 02:28:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_engine_fifo_base.c,v 1.4 2016/02/10 17:10:47 riastradh Exp $	*/
+/*	$NetBSD: nouveau_engine_fifo_base.c,v 1.5 2016/05/11 02:28:33 riastradh Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_fifo_base.c,v 1.4 2016/02/10 17:10:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_fifo_base.c,v 1.5 2016/05/11 02:28:33 riastradh Exp $");
 
 #include <core/client.h>
 #include <core/object.h>
@@ -92,13 +92,68 @@ nouveau_fifo_channel_create_(struct nouv
 
 	/* map fifo control registers */
 #ifdef __NetBSD__
-	chan->bst = nv_device_resource_tag(device, bar);
-	/* XXX errno NetBSD->Linux */
-	ret = -bus_space_map(chan->bst, nv_device_resource_start(device, bar) +
-	    addr + (chan->chid * size), size, 0, &chan->bsh);
-	if (ret)
-		return ret;
-	chan->mapped = true;
+	if (bar == 0) {
+		/*
+		 * We already map BAR 0 in the engine device base, so
+		 * grab a subregion of that.
+		 */
+		bus_space_tag_t mmiot = nv_subdev(device)->mmiot;
+		bus_space_handle_t mmioh = nv_subdev(device)->mmioh;
+		bus_size_t mmiosz = nv_subdev(device)->mmiosz;
+
+		/* Check whether it lies inside the region.  */
+		if (mmiosz < addr ||
+		    mmiosz - addr < chan->chid*size ||
+		    mmiosz - addr - chan->chid*size < size) {
+			ret = EIO;
+			nv_error(priv, "fifo channel out of range:"
+			    " addr 0x%"PRIxMAX
+			    " chid 0x%"PRIxMAX" size 0x%"PRIxMAX
+			    " mmiosz 0x%"PRIxMAX"\n",
+			    (uintmax_t)addr,
+			    (uintmax_t)chan->chid, (uintmax_t)size,
+			    (uintmax_t)mmiosz);
+			return ret;
+		}
+
+		/* Grab a subregion.  */
+		/* XXX errno NetBSD->Linux */
+		ret = -bus_space_subregion(mmiot, mmioh,
+		    (addr + chan->chid*size), size, &chan->bsh);
+		if (ret) {
+			nv_error(priv, "bus_space_subregion failed: %d\n",
+			    ret);
+			return ret;
+		}
+
+		/* Success!  No need to unmap a subregion.  */
+		chan->mapped = false;
+		chan->bst = mmiot;
+	} else {
+		chan->bst = nv_device_resource_tag(device, bar);
+		/* XXX errno NetBSD->Linux */
+		ret = -bus_space_map(chan->bst,
+		    (nv_device_resource_start(device, bar) +
+			addr + (chan->chid * size)),
+		    size, 0, &chan->bsh);
+		if (ret) {
+			nv_error(priv, "failed to map fifo channel:"
+			    " bar %d addr %"PRIxMAX" + %"PRIxMAX
+			    " + (%"PRIxMAX" * %"PRIxMAX") = %"PRIxMAX
+			    " size %"PRIxMAX": %d\n",
+			    bar,
+			    (uintmax_t)nv_device_resource_start(device, bar),
+			    (uintmax_t)addr,
+			    (uintmax_t)chan->chid,
+			    (uintmax_t)size,
+			    (uintmax_t)(nv_device_resource_start(device, bar) +
+				addr + (chan->chid * size)),
+			    (uintmax_t)size,
+			    ret);
+			return ret;
+		}
+		chan->mapped = true;
+	}
 #else
 	chan->user = ioremap(nv_device_resource_start(device, bar) + addr +
 			     (chan->chid * size), size);

Reply via email to