Module Name:    src
Committed By:   snj
Date:           Fri Apr 15 08:46:42 UTC 2016

Modified Files:
        src/sys/external/bsd/drm2/dist/drm/nouveau [netbsd-7]: nouveau_drm.c
            nouveau_drm.h nouveau_fence.c nouveau_nv10_fence.c
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/core [netbsd-7]:
            nouveau_core_subdev.c
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device 
[netbsd-7]:
            nouveau_engine_device_base.c
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/include/core [netbsd-7]:
            namedb.h
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar [netbsd-7]:
            nouveau_subdev_bar_base.c
        src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem 
[netbsd-7]:
            nouveau_subdev_instmem_nv40.c
        src/sys/external/bsd/drm2/include/linux [netbsd-7]: delay.h spinlock.h
        src/sys/external/bsd/drm2/nouveau [netbsd-7]: files.nouveau
            nouveau_pci.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1157):
        sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c: 
revision 1.3
        
sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c:
 revisions 1.9, 1.10
        sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/namedb.h: 
revision 1.2
        
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c:
 revisions 1.4, 1.5
        
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c:
 revision 1.3
        sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c: revision 1.8
        sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h: revision 1.4
        sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c: revision 1.4
        sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c: revision 
1.3
        sys/external/bsd/drm2/include/linux/delay.h: revision 1.4
        sys/external/bsd/drm2/include/linux/spinlock.h: revision 1.7
        sys/external/bsd/drm2/nouveau/files.nouveau: revision 1.14
        sys/external/bsd/drm2/nouveau/nouveau_pci.c: revision 1.7
Set nouveau to a more reasonable debug level.
Match the compile-time and default run-time settings in Linux.
--
Pass a sensible device state pointer to nouveau suspend/resume ops.
Gives nouveau half a chance of suspending and resuming -- not that it
works on my test laptop yet, but it's a start.
--
Fix bus_space_subregion error branch.
Return error code, not 0 (!), on bus_space_subregion failure.
In answer to `XXX error branch' comment: if nouveau_barobj_ctor
fails, then the caller will call nouveau_barobj_dtor too.  So there's
no leak here.
Unlikely to fix any observed bugs with nouveau -- there's no error
branch in the Linux side here.  But maybe it will catch some other
bug earlier.
--
Map the same mmio size as Linux does.
Unlikely to have practical consequences -- just reduces differences
in behaviour from upstream, to rule them out.
--
Print error code for failure to map PRAMIN BAR.
--
In msleep use mdelay if cold
--
Use only the low 32 bits of the bar object's vma offset as intended.
Should fix PR kern/50372, seen by everyone trying to use nouveau on
amd64 with hardware that uses nv50-style BARs and not nvc0-style
BARs.
--
Destroy the lock before caller frees memory.
--
Destroy spin locks appropriately.
--
Destroy the mutex before free.
--
Provide reader/writer semantics with recursive readers.
--
Exclude VRAM and FIFO regions from MMIO register mapping.
Nouveau maps those separately, and it is not trivial to convert those
mappings to bus_space_subregion.


To generate a diff of this commit:
cvs rdiff -u -r1.2.4.4 -r1.2.4.5 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c
cvs rdiff -u -r1.1.1.1.4.2 -r1.1.1.1.4.3 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h
cvs rdiff -u -r1.2.4.1 -r1.2.4.2 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c
cvs rdiff -u -r1.1.1.1.4.1 -r1.1.1.1.4.2 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c
cvs rdiff -u -r1.2 -r1.2.4.1 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c
cvs rdiff -u -r1.2.4.3 -r1.2.4.4 \
    
src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c
cvs rdiff -u -r1.1.1.1 -r1.1.1.1.4.1 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/namedb.h
cvs rdiff -u -r1.1.1.1.4.1 -r1.1.1.1.4.2 \
    
src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c
cvs rdiff -u -r1.1.1.1.4.1 -r1.1.1.1.4.2 \
    
src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c
cvs rdiff -u -r1.3 -r1.3.2.1 src/sys/external/bsd/drm2/include/linux/delay.h
cvs rdiff -u -r1.3.2.1 -r1.3.2.2 \
    src/sys/external/bsd/drm2/include/linux/spinlock.h
cvs rdiff -u -r1.2.4.4 -r1.2.4.5 \
    src/sys/external/bsd/drm2/nouveau/files.nouveau
cvs rdiff -u -r1.3.2.5 -r1.3.2.6 \
    src/sys/external/bsd/drm2/nouveau/nouveau_pci.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/nouveau_drm.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c:1.2.4.4 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c:1.2.4.5
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c:1.2.4.4	Thu Feb 11 22:52:58 2016
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_drm.c,v 1.2.4.4 2016/02/11 22:52:58 snj Exp $	*/
+/*	$NetBSD: nouveau_drm.c,v 1.2.4.5 2016/04/15 08:46:42 snj Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_drm.c,v 1.2.4.4 2016/02/11 22:52:58 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_drm.c,v 1.2.4.5 2016/04/15 08:46:42 snj Exp $");
 
 #include <linux/console.h>
 #include <linux/module.h>
@@ -612,12 +612,13 @@ fail_display:
 	return ret;
 }
 
-int nouveau_pmops_suspend(struct device *dev)
-{
 #ifdef __NetBSD__
-	struct drm_device *drm_dev = device_private(dev);
-	struct pci_dev *pdev __unused = drm_dev->pdev;
+int nouveau_pmops_suspend(struct drm_device *drm_dev)
 #else
+int nouveau_pmops_suspend(struct device *dev)
+#endif
+{
+#ifndef __NetBSD__
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct drm_device *drm_dev = pci_get_drvdata(pdev);
 #endif
@@ -674,12 +675,13 @@ nouveau_do_resume(struct drm_device *dev
 	return 0;
 }
 
-int nouveau_pmops_resume(struct device *dev)
-{
 #ifdef __NetBSD__
-	struct drm_device *drm_dev = device_private(dev);
-	struct pci_dev *pdev __unused = drm_dev->pdev;
+int nouveau_pmops_resume(struct drm_device *drm_dev)
 #else
+int nouveau_pmops_resume(struct device *dev)
+#endif
+{
+#ifndef __NetBSD__
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct drm_device *drm_dev = pci_get_drvdata(pdev);
 #endif

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h:1.1.1.1.4.2 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h:1.1.1.1.4.3
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h:1.1.1.1.4.2	Thu Feb 11 23:08:41 2016
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.h	Fri Apr 15 08:46:42 2016
@@ -160,8 +160,13 @@ nouveau_dev(struct drm_device *dev)
 	return nv_device(nouveau_drm(dev)->device);
 }
 
+#ifdef __NetBSD__
+int nouveau_pmops_suspend(struct drm_device *);
+int nouveau_pmops_resume(struct drm_device *);
+#else
 int nouveau_pmops_suspend(struct device *);
 int nouveau_pmops_resume(struct device *);
+#endif
 
 #define NV_FATAL(cli, fmt, args...) nv_fatal((cli), fmt, ##args)
 #define NV_ERROR(cli, fmt, args...) nv_error((cli), fmt, ##args)

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c:1.2.4.1 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c:1.2.4.2
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c:1.2.4.1	Sun Sep 21 17:41:52 2014
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_fence.c,v 1.2.4.1 2014/09/21 17:41:52 snj Exp $	*/
+/*	$NetBSD: nouveau_fence.c,v 1.2.4.2 2016/04/15 08:46:42 snj Exp $	*/
 
 /*
  * Copyright (C) 2007 Ben Skeggs.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_fence.c,v 1.2.4.1 2014/09/21 17:41:52 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_fence.c,v 1.2.4.2 2016/04/15 08:46:42 snj Exp $");
 
 #include <drm/drmP.h>
 
@@ -71,6 +71,7 @@ nouveau_fence_context_del(struct nouveau
 		nouveau_fence_signal(fence);
 	}
 	spin_unlock(&fctx->lock);
+	spin_lock_destroy(&fctx->lock);
 }
 
 void

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c:1.1.1.1.4.1 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c:1.1.1.1.4.2
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c:1.1.1.1.4.1	Sun Sep 21 17:41:52 2014
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv10_fence.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_nv10_fence.c,v 1.1.1.1.4.1 2014/09/21 17:41:52 snj Exp $	*/
+/*	$NetBSD: nouveau_nv10_fence.c,v 1.1.1.1.4.2 2016/04/15 08:46:42 snj Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_nv10_fence.c,v 1.1.1.1.4.1 2014/09/21 17:41:52 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_nv10_fence.c,v 1.1.1.1.4.2 2016/04/15 08:46:42 snj Exp $");
 
 #include <core/object.h>
 #include <core/class.h>
@@ -95,6 +95,7 @@ nv10_fence_destroy(struct nouveau_drm *d
 		nouveau_bo_unpin(priv->bo);
 	nouveau_bo_ref(NULL, &priv->bo);
 	drm->fence = NULL;
+	spin_lock_destroy(&priv->lock);
 	kfree(priv);
 }
 

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c:1.2 src/sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c:1.2.4.1
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c:1.2	Wed Aug  6 15:01:33 2014
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/core/nouveau_core_subdev.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_core_subdev.c,v 1.2 2014/08/06 15:01:33 riastradh Exp $	*/
+/*	$NetBSD: nouveau_core_subdev.c,v 1.2.4.1 2016/04/15 08:46:42 snj Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_core_subdev.c,v 1.2 2014/08/06 15:01:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_core_subdev.c,v 1.2.4.1 2016/04/15 08:46:42 snj Exp $");
 
 #include <core/object.h>
 #include <core/subdev.h>
@@ -79,6 +79,7 @@ nouveau_subdev_destroy(struct nouveau_su
 {
 	int subidx = nv_hclass(subdev) & 0xff;
 	nv_device(subdev)->subdev[subidx] = NULL;
+	linux_mutex_destroy(&subdev->mutex);
 	nouveau_object_destroy(&subdev->base);
 }
 

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.2.4.3 src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c:1.2.4.4
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c:1.2.4.3	Thu Feb 11 23:00:30 2016
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_engine_device_base.c,v 1.2.4.3 2016/02/11 23:00:30 snj Exp $	*/
+/*	$NetBSD: nouveau_engine_device_base.c,v 1.2.4.4 2016/04/15 08:46:42 snj 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.2.4.3 2016/02/11 23:00:30 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_device_base.c,v 1.2.4.4 2016/04/15 08:46:42 snj Exp $");
 
 #include <core/object.h>
 #include <core/device.h>
@@ -180,7 +180,7 @@ nouveau_devobj_ctor(struct nouveau_objec
 		if (mmio_size < 0x102000)
 			return -ENOMEM;
 		/* XXX errno NetBSD->Linux */
-		ret = -bus_space_map(mmiot, mmio_base, mmio_size, 0, &mmioh);
+		ret = -bus_space_map(mmiot, mmio_base, 0x102000, 0, &mmioh);
 		if (ret)
 			return ret;
 
@@ -193,7 +193,7 @@ nouveau_devobj_ctor(struct nouveau_objec
 
 		boot0 = bus_space_read_4(mmiot, mmioh, 0x000000);
 		strap = bus_space_read_4(mmiot, mmioh, 0x101000);
-		bus_space_unmap(mmiot, mmioh, mmio_size);
+		bus_space_unmap(mmiot, mmioh, 0x102000);
 #else
 		map = ioremap(mmio_base, 0x102000);
 		if (map == NULL)
@@ -297,6 +297,12 @@ 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/include/core/namedb.h
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/namedb.h:1.1.1.1 src/sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/namedb.h:1.1.1.1.4.1
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/namedb.h:1.1.1.1	Thu Jul 17 01:50:59 2014
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/namedb.h	Fri Apr 15 08:46:42 2016
@@ -28,8 +28,11 @@ nv_namedb(void *obj)
 	nouveau_parent_init(&(p)->base)
 #define nouveau_namedb_fini(p,s)                                               \
 	nouveau_parent_fini(&(p)->base, (s))
-#define nouveau_namedb_destroy(p)                                              \
-	nouveau_parent_destroy(&(p)->base)
+#define nouveau_namedb_destroy(p) do                                           \
+{                                                                              \
+	rwlock_destroy(&(p)->lock);                                            \
+	nouveau_parent_destroy(&(p)->base);                                    \
+} while (0)
 
 int  nouveau_namedb_create_(struct nouveau_object *, struct nouveau_object *,
 			    struct nouveau_oclass *, u32 pclass,

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c:1.1.1.1.4.1 src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c:1.1.1.1.4.2
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c:1.1.1.1.4.1	Sun Sep 21 17:41:52 2014
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_subdev_bar_base.c,v 1.1.1.1.4.1 2014/09/21 17:41:52 snj Exp $	*/
+/*	$NetBSD: nouveau_subdev_bar_base.c,v 1.1.1.1.4.2 2016/04/15 08:46:42 snj Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bar_base.c,v 1.1.1.1.4.1 2014/09/21 17:41:52 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bar_base.c,v 1.1.1.1.4.2 2016/04/15 08:46:42 snj Exp $");
 
 #include <core/object.h>
 
@@ -65,11 +65,21 @@ nouveau_barobj_ctor(struct nouveau_objec
 		return ret;
 
 #ifdef __NetBSD__
+    {
+	/* Yes, truncation is really intended here.  */
+	uint32_t offset = barobj->vma.offset & 0xffffffffUL;
+
+	KASSERTMSG(offset < bar->iomemsz,
+	    "bar object vma exceeds range: %"PRIx32" > %"PRIxMAX,
+	    offset, (uintmax_t)bar->iomemsz);
+
 	barobj->iomemt = bar->iomemt;
-	if (bus_space_subregion(bar->iomemt, bar->iomemh, barobj->vma.offset,
-		bar->iomemsz - barobj->vma.offset, &barobj->iomemh) != 0)
-		/* XXX error branch */
+	/* XXX errno NetBSD->Linux */
+	ret = -bus_space_subregion(bar->iomemt, bar->iomemh, offset,
+	    bar->iomemsz - offset, &barobj->iomemh);
+	if (ret)
 		return ret;
+    }
 #else
 	barobj->iomem = bar->iomem + (u32)barobj->vma.offset;
 #endif

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c:1.1.1.1.4.1 src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c:1.1.1.1.4.2
--- src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c:1.1.1.1.4.1	Sun Sep 21 17:41:53 2014
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv40.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_subdev_instmem_nv40.c,v 1.1.1.1.4.1 2014/09/21 17:41:53 snj Exp $	*/
+/*	$NetBSD: nouveau_subdev_instmem_nv40.c,v 1.1.1.1.4.2 2016/04/15 08:46:42 snj Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_instmem_nv40.c,v 1.1.1.1.4.1 2014/09/21 17:41:53 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_instmem_nv40.c,v 1.1.1.1.4.2 2016/04/15 08:46:42 snj Exp $");
 
 #include <engine/graph/nv40.h>
 
@@ -80,10 +80,12 @@ nv40_instmem_ctor(struct nouveau_object 
 #ifdef __NetBSD__
 	priv->iomemt = nv_device_resource_tag(device, bar);
 	priv->iomemsz = nv_device_resource_len(device, bar);
-	if (bus_space_map(priv->iomemt, nv_device_resource_start(device, bar),
-		priv->iomemsz, 0, &priv->iomemh)) {
+	ret = bus_space_map(priv->iomemt,
+	    nv_device_resource_start(device, bar),
+	    priv->iomemsz, 0, &priv->iomemh);
+	if (ret) {
 		priv->iomemsz = 0;
-		nv_error(priv, "unable to map PRAMIN BAR\n");
+		nv_error(priv, "unable to map PRAMIN BAR: %d\n", ret);
 		return -EFAULT;
 	}
 #else

Index: src/sys/external/bsd/drm2/include/linux/delay.h
diff -u src/sys/external/bsd/drm2/include/linux/delay.h:1.3 src/sys/external/bsd/drm2/include/linux/delay.h:1.3.2.1
--- src/sys/external/bsd/drm2/include/linux/delay.h:1.3	Wed Jul 16 20:56:25 2014
+++ src/sys/external/bsd/drm2/include/linux/delay.h	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: delay.h,v 1.3 2014/07/16 20:56:25 riastradh Exp $	*/
+/*	$NetBSD: delay.h,v 1.3.2.1 2016/04/15 08:46:42 snj Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -66,7 +66,8 @@ mdelay(unsigned int msec)
 static inline void
 msleep(unsigned int msec)
 {
-	if ((hz < 1000) && (msec < (1000/hz)))
+	if (cold ||
+	    ((hz < 1000) && (msec < (1000/hz))))
 		mdelay(msec);
 	else
 		(void)kpause("lnxmslep", false, mstohz(msec), NULL);

Index: src/sys/external/bsd/drm2/include/linux/spinlock.h
diff -u src/sys/external/bsd/drm2/include/linux/spinlock.h:1.3.2.1 src/sys/external/bsd/drm2/include/linux/spinlock.h:1.3.2.2
--- src/sys/external/bsd/drm2/include/linux/spinlock.h:1.3.2.1	Sun Sep 21 17:41:52 2014
+++ src/sys/external/bsd/drm2/include/linux/spinlock.h	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: spinlock.h,v 1.3.2.1 2014/09/21 17:41:52 snj Exp $	*/
+/*	$NetBSD: spinlock.h,v 1.3.2.2 2016/04/15 08:46:42 snj Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,6 +35,8 @@
 #include <sys/cdefs.h>
 #include <sys/mutex.h>
 
+#include <machine/limits.h>
+
 #define	__acquires(lock)	/* XXX lockdep stuff */
 #define	__releases(lock)	/* XXX lockdep stuff */
 
@@ -108,18 +110,71 @@ spin_lock_destroy(spinlock_t *spinlock)
 	KASSERT(mutex_owned(&(spinlock)->sl_lock))
 
 /*
- * Linux rwlocks are reader/writer spin locks.  We implement them as
- * normal spin locks without reader/writer semantics for expedience.
- * If that turns out to not work, adapting to reader/writer semantics
- * shouldn't be too hard.
+ * Stupid reader/writer spin locks.  No attempt to avoid writer
+ * starvation.  Must allow recursive readers.  We use mutex and state
+ * instead of compare-and-swap for expedience and LOCKDEBUG support.
  */
 
-#define	rwlock_t		spinlock_t
-#define	rwlock_init		spin_lock_init
-#define	rwlock_destroy		spin_lock_destroy
-#define	write_lock_irq		spin_lock_irq
-#define	write_unlock_irq	spin_unlock_irq
-#define	read_lock		spin_lock
-#define	read_unlock		spin_unlock
+typedef struct linux_rwlock {
+	kmutex_t	rw_lock;
+	unsigned	rw_nreaders;
+} rwlock_t;
+
+static inline void
+rwlock_init(rwlock_t *rw)
+{
+
+	mutex_init(&rw->rw_lock, MUTEX_DEFAULT, IPL_VM);
+	rw->rw_nreaders = 0;
+}
+
+static inline void
+rwlock_destroy(rwlock_t *rw)
+{
+
+	KASSERTMSG(rw->rw_nreaders == 0,
+	    "rwlock still held by %u readers", rw->rw_nreaders);
+	mutex_destroy(&rw->rw_lock);
+}
+
+static inline void
+write_lock_irq(rwlock_t *rw)
+{
+
+	for (;;) {
+		mutex_spin_enter(&rw->rw_lock);
+		if (rw->rw_nreaders == 0)
+			break;
+		mutex_spin_exit(&rw->rw_lock);
+	}
+}
+
+static inline void
+write_unlock_irq(rwlock_t *rw)
+{
+
+	KASSERT(rw->rw_nreaders == 0);
+	mutex_spin_exit(&rw->rw_lock);
+}
+
+static inline void
+read_lock(rwlock_t *rw)
+{
+
+	mutex_spin_enter(&rw->rw_lock);
+	KASSERT(rw->rw_nreaders < UINT_MAX);
+	rw->rw_nreaders++;
+	mutex_spin_exit(&rw->rw_lock);
+}
+
+static inline void
+read_unlock(rwlock_t *rw)
+{
+
+	mutex_spin_enter(&rw->rw_lock);
+	KASSERT(0 < rw->rw_nreaders);
+	rw->rw_nreaders--;
+	mutex_spin_exit(&rw->rw_lock);
+}
 
 #endif  /* _LINUX_SPINLOCK_H_ */

Index: src/sys/external/bsd/drm2/nouveau/files.nouveau
diff -u src/sys/external/bsd/drm2/nouveau/files.nouveau:1.2.4.4 src/sys/external/bsd/drm2/nouveau/files.nouveau:1.2.4.5
--- src/sys/external/bsd/drm2/nouveau/files.nouveau:1.2.4.4	Thu Feb 11 22:48:22 2016
+++ src/sys/external/bsd/drm2/nouveau/files.nouveau	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: files.nouveau,v 1.2.4.4 2016/02/11 22:48:22 snj Exp $
+#	$NetBSD: files.nouveau,v 1.2.4.5 2016/04/15 08:46:42 snj Exp $
 
 define	nouveaufbbus	{ }
 device	nouveau: drmkms, drmkms_ttm, nouveaufbbus
@@ -19,9 +19,8 @@ makeoptions	nouveau	CPPFLAGS+="-I$S/exte
 makeoptions	nouveau	CPPFLAGS+="-I$S/external/bsd/drm2/dist/drm/nouveau/core/include"
 makeoptions	nouveau	CPPFLAGS+="-I$S/external/bsd/drm2/nouveau"
 
-# XXX DEBUG ALL THE BUGS!
-makeoptions	nouveau	CPPFLAGS+="-DCONFIG_NOUVEAU_DEBUG=1000"
-makeoptions	nouveau	CPPFLAGS+="-DCONFIG_NOUVEAU_DEBUG_DEFAULT=6"
+makeoptions	nouveau	CPPFLAGS+="-DCONFIG_NOUVEAU_DEBUG=5"
+makeoptions	nouveau	CPPFLAGS+="-DCONFIG_NOUVEAU_DEBUG_DEFAULT=3"
 
 # XXX If you find a way to apply the warning flags to all Nouveau
 # sources, please apply it here and remove this stupidly gigantic list!

Index: src/sys/external/bsd/drm2/nouveau/nouveau_pci.c
diff -u src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.3.2.5 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.3.2.6
--- src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.3.2.5	Thu Feb 11 22:55:50 2016
+++ src/sys/external/bsd/drm2/nouveau/nouveau_pci.c	Fri Apr 15 08:46:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_pci.c,v 1.3.2.5 2016/02/11 22:55:50 snj Exp $	*/
+/*	$NetBSD: nouveau_pci.c,v 1.3.2.6 2016/04/15 08:46:42 snj Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.3.2.5 2016/02/11 22:55:50 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.3.2.6 2016/04/15 08:46:42 snj Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -208,15 +208,17 @@ out0:	pmf_device_deregister(self);
 static bool
 nouveau_pci_suspend(device_t self, const pmf_qual_t *qual __unused)
 {
+	struct nouveau_pci_softc *const sc = device_private(self);
 
-	return nouveau_pmops_suspend(self) == 0;
+	return nouveau_pmops_suspend(sc->sc_drm_dev) == 0;
 }
 
 static bool
 nouveau_pci_resume(device_t self, const pmf_qual_t *qual)
 {
+	struct nouveau_pci_softc *const sc = device_private(self);
 
-	return nouveau_pmops_resume(self) == 0;
+	return nouveau_pmops_resume(sc->sc_drm_dev) == 0;
 }
 
 static void

Reply via email to