From 2a5c7900192660ff21ea4ba63bfd706af60b113a Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sun, 29 Nov 2015 23:53:34 +0100
Subject: [PATCH 04/55] kernel/drm: nouveau changes so far. :)

---
 sys/conf/files                                |  22 +-
 sys/conf/kern.pre.mk                          |   2 +-
 sys/config/LINT64                             |   1 +
 sys/dev/drm/include/acpi/button.h             |  57 +++
 sys/dev/drm/include/asm/io.h                  |   7 +
 sys/dev/drm/include/drm/drmP.h                |   1 +
 sys/dev/drm/include/drm/i2c/ch7006.h          |  86 +++++
 sys/dev/drm/include/drm/i2c/sil164.h          |  63 ++++
 sys/dev/drm/include/linux/bitops.h            |   7 +
 sys/dev/drm/include/linux/compiler.h          |   2 +
 sys/dev/drm/include/linux/dma-attrs.h         |  50 +++
 sys/dev/drm/include/linux/dma-buf.h           |  35 ++
 sys/dev/drm/include/linux/fb.h                |   9 +
 sys/dev/drm/include/linux/fence.h             |   2 +
 sys/dev/drm/include/linux/gfp.h               |   1 +
 sys/dev/drm/include/linux/hwmon-sysfs.h       |  35 ++
 sys/dev/drm/include/linux/hwmon.h             |  35 ++
 sys/dev/drm/include/linux/i2c.h               |  13 +
 sys/dev/drm/include/linux/init.h              |  35 ++
 sys/dev/drm/include/linux/kernel.h            |   1 +
 sys/dev/drm/include/linux/list.h              |   9 +-
 sys/dev/drm/include/linux/lockdep.h           |   2 +
 sys/dev/drm/include/linux/mod_devicetable.h   |   2 +
 sys/dev/drm/include/linux/mutex.h             |   3 +
 sys/dev/drm/include/linux/page.h              |  53 +++
 sys/dev/drm/include/linux/platform_device.h   |  35 ++
 sys/dev/drm/include/linux/pm_runtime.h        |  86 +++++
 sys/dev/drm/include/linux/power_supply.h      |  41 ++
 sys/dev/drm/include/linux/printk.h            |   1 +
 sys/dev/drm/include/linux/rbtree.h            |   5 +
 sys/dev/drm/include/linux/rcupdate.h          |  35 ++
 sys/dev/drm/include/linux/reboot.h            |  49 +++
 sys/dev/drm/include/linux/rwlock.h            |  47 +++
 sys/dev/drm/include/linux/screen_info.h       |  35 ++
 sys/dev/drm/include/linux/slab.h              |   3 +
 sys/dev/drm/include/linux/spinlock.h          |   4 +
 sys/dev/drm/include/linux/stat.h              |  37 ++
 sys/dev/drm/include/linux/static_key.h        |   1 +
 sys/dev/drm/include/linux/string.h            |  20 +
 sys/dev/drm/include/linux/swiotlb.h           |  35 ++
 sys/dev/drm/include/linux/sysrq.h             |  49 +++
 sys/dev/drm/include/linux/tracepoint.h        |  35 ++
 sys/dev/drm/include/linux/tty.h               |  35 ++
 sys/dev/drm/include/linux/vgaarb.h            |  49 +++
 sys/dev/drm/include/linux/workqueue.h         |   7 +
 sys/dev/drm/include/trace/define_trace.h      | 118 ++++++
 sys/dev/drm/include/trace/events/fence.h      |  35 ++
 sys/dev/drm/include/uapi_drm/nouveau_drm.h    | 150 ++++++++
 sys/dev/drm/nouveau/NOTES                     |   9 +
 .../nouveau/core/core/nouveau_core_client.c   |   4 +-
 .../nouveau/core/core/nouveau_core_engctx.c   |   2 +-
 .../nouveau/core/core/nouveau_core_ioctl.c    |   6 +-
 .../drm/nouveau/core/core/nouveau_core_mm.c   |   4 +-
 .../nouveau/core/core/nouveau_core_notify.c   |   6 +-
 .../nouveau/core/core/nouveau_core_printk.c   |   8 +-
 .../engine/copy/nouveau_engine_copy_nva3.c    |   2 +-
 .../engine/crypt/nouveau_engine_crypt_nv84.c  |   2 +-
 .../engine/crypt/nouveau_engine_crypt_nv98.c  |   2 +-
 .../device/nouveau_engine_device_base.c       |  12 +-
 .../device/nouveau_engine_device_ctrl.c       |   4 +-
 .../engine/disp/nouveau_engine_disp_nv50.c    |  14 +-
 .../dmaobj/nouveau_engine_dmaobj_base.c       |   2 +-
 .../engine/fifo/nouveau_engine_fifo_base.c    |   2 +-
 .../engine/fifo/nouveau_engine_fifo_nv04.c    |   4 +-
 .../engine/fifo/nouveau_engine_fifo_nv10.c    |   2 +-
 .../engine/fifo/nouveau_engine_fifo_nv17.c    |   2 +-
 .../engine/fifo/nouveau_engine_fifo_nv40.c    |   2 +-
 .../engine/fifo/nouveau_engine_fifo_nv50.c    |   4 +-
 .../engine/fifo/nouveau_engine_fifo_nv84.c    |   4 +-
 .../engine/fifo/nouveau_engine_fifo_nvc0.c    |  16 +-
 .../engine/fifo/nouveau_engine_fifo_nve0.c    |  18 +-
 .../graph/nouveau_engine_graph_ctxgm107.c     |   2 +-
 .../graph/nouveau_engine_graph_ctxnv40.c      |   2 +-
 .../graph/nouveau_engine_graph_ctxnv50.c      |   2 +-
 .../graph/nouveau_engine_graph_ctxnvc0.c      |   2 +-
 .../graph/nouveau_engine_graph_ctxnvd7.c      |   2 +-
 .../engine/graph/nouveau_engine_graph_gm107.c |   2 +-
 .../engine/graph/nouveau_engine_graph_nv04.c  |   2 +-
 .../engine/graph/nouveau_engine_graph_nv10.c  |   2 +-
 .../engine/graph/nouveau_engine_graph_nv50.c  |   8 +-
 .../engine/graph/nouveau_engine_graph_nvc0.c  |  18 +-
 .../core/engine/nouveau_engine_falcon.c       |  18 +-
 .../core/engine/nouveau_engine_xtensa.c       |  10 +-
 .../perfmon/nouveau_engine_perfmon_base.c     |  10 +-
 .../drm/nouveau/core/include/core/device.h    |   4 +-
 .../drm/nouveau/core/include/core/engine.h    |   2 +-
 sys/dev/drm/nouveau/core/include/core/event.h |   4 +-
 .../drm/nouveau/core/include/core/namedb.h    |   2 +-
 .../drm/nouveau/core/include/core/object.h    |  12 +-
 .../drm/nouveau/core/include/core/subdev.h    |   2 +-
 .../drm/nouveau/core/include/engine/fifo.h    |   2 +-
 sys/dev/drm/nouveau/core/include/subdev/i2c.h |  16 +-
 sys/dev/drm/nouveau/core/os.h                 |   9 +-
 .../core/subdev/bar/nouveau_subdev_bar_base.c |   2 +-
 .../subdev/bar/nouveau_subdev_bar_gk20a.c     |   2 +-
 .../core/subdev/bar/nouveau_subdev_bar_nv50.c |   2 +-
 .../core/subdev/bar/nouveau_subdev_bar_nvc0.c |   2 +-
 .../subdev/bios/nouveau_subdev_bios_base.c    |  20 +-
 .../subdev/bios/nouveau_subdev_bios_init.c    |  12 +-
 .../core/subdev/bus/nouveau_subdev_bus_hwsq.c |   2 +-
 .../subdev/clock/nouveau_subdev_clock_base.c  |  10 +-
 .../subdev/clock/nouveau_subdev_clock_nv50.c  |   2 +-
 .../core/subdev/fb/nouveau_subdev_fb_nv50.c   |   4 +-
 .../subdev/fb/nouveau_subdev_fb_ramgk20a.c    |   2 +-
 .../subdev/fb/nouveau_subdev_fb_ramnv1a.c     |  10 +-
 .../subdev/gpio/nouveau_subdev_gpio_nve0.c    |   2 +-
 .../subdev/i2c/nouveau_subdev_i2c_anx9805.c   |   8 +-
 .../core/subdev/i2c/nouveau_subdev_i2c_aux.c  |   2 +-
 .../core/subdev/i2c/nouveau_subdev_i2c_base.c |   2 +-
 .../core/subdev/i2c/nouveau_subdev_i2c_nv94.c |   2 +-
 .../instmem/nouveau_subdev_instmem_nv50.c     |   2 +-
 .../core/subdev/mc/nouveau_subdev_mc_base.c   |   4 +-
 .../core/subdev/mxm/nouveau_subdev_mxm_base.c |   8 +-
 .../core/subdev/mxm/nouveau_subdev_mxm_nv50.c |   2 +-
 .../therm/nouveau_subdev_therm_fantog.c       |   2 +-
 .../subdev/therm/nouveau_subdev_therm_temp.c  |   2 +-
 sys/dev/drm/nouveau/core/subdev/therm/priv.h  |   6 +-
 .../subdev/timer/nouveau_subdev_timer_nv04.c  |   2 +-
 sys/dev/drm/nouveau/core/subdev/timer/nv04.h  |   2 +-
 .../core/subdev/vm/nouveau_subdev_vm_nv41.c   |   2 +-
 .../core/subdev/vm/nouveau_subdev_vm_nv44.c   |   2 +-
 .../dispnv04/nouveau_dispnv04_cursor.c        |   4 +
 .../nouveau/dispnv04/nouveau_dispnv04_hw.c    |   2 +-
 .../dispnv04/nouveau_dispnv04_overlay.c       |   4 +
 sys/dev/drm/nouveau/nouveau_abi16.c           |   6 +-
 sys/dev/drm/nouveau/nouveau_acpi.c            |   2 +-
 sys/dev/drm/nouveau/nouveau_agp.c             |   2 +-
 sys/dev/drm/nouveau/nouveau_bios.h            |   2 +-
 sys/dev/drm/nouveau/nouveau_bo.c              |   9 +-
 sys/dev/drm/nouveau/nouveau_bo.h              |   2 +
 sys/dev/drm/nouveau/nouveau_display.c         |  22 +-
 sys/dev/drm/nouveau/nouveau_drm.c             |  27 +-
 sys/dev/drm/nouveau/nouveau_drm.h             |  10 +-
 sys/dev/drm/nouveau/nouveau_fbcon.c           |   2 +-
 sys/dev/drm/nouveau/nouveau_fence.c           |   4 +-
 sys/dev/drm/nouveau/nouveau_fence.h           |   2 +-
 sys/dev/drm/nouveau/nouveau_gem.c             |  18 +-
 sys/dev/drm/nouveau/nouveau_hwmon.c           |  36 +-
 sys/dev/drm/nouveau/nouveau_nv10_fence.c      |   2 +-
 sys/dev/drm/nouveau/nouveau_nv50_display.c    |  16 +-
 sys/dev/drm/nouveau/nouveau_nvif.c            |   2 +-
 sys/dev/drm/nouveau/nouveau_platform.c        |   3 +-
 sys/dev/drm/nouveau/nouveau_prime.c           |   2 +
 sys/dev/drm/nouveau/nouveau_sgdma.c           |   1 +
 sys/dev/drm/nouveau/nouveau_sysfs.c           |   2 +-
 sys/dev/drm/nouveau/nouveau_ttm.c             |   4 +-
 sys/dev/drm/nouveau/nouveau_usif.c            |  12 +-
 sys/dev/drm/nouveau/nv10_fence.h              |   2 +-
 sys/dev/drm/nouveau/nvif/list.h               | 353 ------------------
 .../drm/nouveau/nvif/nouveau_nvif_notify.c    |   8 +-
 .../drm/nouveau/nvif/nouveau_nvif_object.c    |   6 +-
 sys/libkern/strcspn.c                         |  72 ++++
 sys/sys/libkern.h                             |  13 +
 153 files changed, 1844 insertions(+), 637 deletions(-)
 create mode 100644 sys/dev/drm/include/acpi/button.h
 create mode 100644 sys/dev/drm/include/drm/i2c/ch7006.h
 create mode 100644 sys/dev/drm/include/drm/i2c/sil164.h
 create mode 100644 sys/dev/drm/include/linux/dma-attrs.h
 create mode 100644 sys/dev/drm/include/linux/dma-buf.h
 create mode 100644 sys/dev/drm/include/linux/hwmon-sysfs.h
 create mode 100644 sys/dev/drm/include/linux/hwmon.h
 create mode 100644 sys/dev/drm/include/linux/init.h
 create mode 100644 sys/dev/drm/include/linux/page.h
 create mode 100644 sys/dev/drm/include/linux/platform_device.h
 create mode 100644 sys/dev/drm/include/linux/pm_runtime.h
 create mode 100644 sys/dev/drm/include/linux/power_supply.h
 create mode 100644 sys/dev/drm/include/linux/rcupdate.h
 create mode 100644 sys/dev/drm/include/linux/reboot.h
 create mode 100644 sys/dev/drm/include/linux/rwlock.h
 create mode 100644 sys/dev/drm/include/linux/screen_info.h
 create mode 100644 sys/dev/drm/include/linux/stat.h
 create mode 100644 sys/dev/drm/include/linux/static_key.h
 create mode 100644 sys/dev/drm/include/linux/swiotlb.h
 create mode 100644 sys/dev/drm/include/linux/sysrq.h
 create mode 100644 sys/dev/drm/include/linux/tracepoint.h
 create mode 100644 sys/dev/drm/include/linux/tty.h
 create mode 100644 sys/dev/drm/include/linux/vgaarb.h
 create mode 100644 sys/dev/drm/include/trace/define_trace.h
 create mode 100644 sys/dev/drm/include/trace/events/fence.h
 create mode 100644 sys/dev/drm/include/uapi_drm/nouveau_drm.h
 create mode 100644 sys/dev/drm/nouveau/NOTES
 delete mode 100644 sys/dev/drm/nouveau/nvif/list.h
 create mode 100644 sys/libkern/strcspn.c

diff --git a/sys/conf/files b/sys/conf/files
index aef805a80d..b34307a0c7 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1998,6 +1998,7 @@ libkern/strtol.c			standard
 libkern/strtoq.c			standard
 libkern/strtoul.c			standard
 libkern/strtouq.c			standard
+libkern/strcspn.c			standard
 #libkern/stack_protector.c		standard
 libiconv/iconv.c			optional libiconv
 libiconv/iconv_converter_if.m		optional libiconv
@@ -2361,7 +2362,7 @@ dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_nv50.c		optional nouveau drm
 dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_nv94.c		optional nouveau drm
 dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_nvc0.c		optional nouveau drm
 dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_base.c		optional nouveau drm
-dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_gk20a.c		optional nouveau drm
+#dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_gk20a.c		optional nouveau drm
 dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv04.c		optional nouveau drm
 dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv40.c		optional nouveau drm
 dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv50.c		optional nouveau drm
@@ -2516,36 +2517,41 @@ dev/drm/nouveau/dispnv04/nouveau_dispnv04_tvmodesnv17.c		optional nouveau drm
 dev/drm/nouveau/dispnv04/nouveau_dispnv04_tvnv04.c		optional nouveau drm
 dev/drm/nouveau/dispnv04/nouveau_dispnv04_tvnv17.c		optional nouveau drm
 dev/drm/nouveau/nouveau_abi16.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_acpi.c		optional nouveau drm
 dev/drm/nouveau/nouveau_agp.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_backlight.c	optional nouveau drm
 dev/drm/nouveau/nouveau_bios.c		optional nouveau drm
 dev/drm/nouveau/nouveau_bo.c		optional nouveau drm
 dev/drm/nouveau/nouveau_chan.c		optional nouveau drm
 dev/drm/nouveau/nouveau_connector.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_debugfs.c		optional nouveau drm
 dev/drm/nouveau/nouveau_display.c		optional nouveau drm
 dev/drm/nouveau/nouveau_dma.c		optional nouveau drm
 dev/drm/nouveau/nouveau_dp.c		optional nouveau drm
 dev/drm/nouveau/nouveau_drm.c		optional nouveau drm
-dev/drm/nouveau/nouveau_fbcon.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_fbcon.c		optional nouveau drm
 dev/drm/nouveau/nouveau_fence.c		optional nouveau drm
 dev/drm/nouveau/nouveau_gem.c		optional nouveau drm
 dev/drm/nouveau/nouveau_hwmon.c		optional nouveau drm
-dev/drm/nouveau/nouveau_nv04_fbcon.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_ioc32.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_nv04_fbcon.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nv04_fence.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nv10_fence.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nv17_fence.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nv50_display.c		optional nouveau drm
-dev/drm/nouveau/nouveau_nv50_fbcon.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_nv50_fbcon.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nv50_fence.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nv84_fence.c		optional nouveau drm
-dev/drm/nouveau/nouveau_nvc0_fbcon.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_nvc0_fbcon.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nvc0_fence.c		optional nouveau drm
 dev/drm/nouveau/nouveau_nvif.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_platform.c	optional nouveau drm
 dev/drm/nouveau/nouveau_prime.c		optional nouveau drm
 dev/drm/nouveau/nouveau_sgdma.c		optional nouveau drm
-dev/drm/nouveau/nouveau_sysfs.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_sysfs.c		optional nouveau drm
 dev/drm/nouveau/nouveau_ttm.c		optional nouveau drm
-dev/drm/nouveau/nouveau_usif.c		optional nouveau drm
-dev/drm/nouveau/nouveau_vga.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_usif.c		optional nouveau drm
+#dev/drm/nouveau/nouveau_vga.c		optional nouveau drm
 dev/drm/nouveau/nvif/nouveau_nvif_client.c		optional nouveau drm
 dev/drm/nouveau/nvif/nouveau_nvif_device.c		optional nouveau drm
 dev/drm/nouveau/nvif/nouveau_nvif_notify.c		optional nouveau drm
diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk
index 84b8b9484c..7f02502788 100644
--- a/sys/conf/kern.pre.mk
+++ b/sys/conf/kern.pre.mk
@@ -58,7 +58,7 @@ INCLUDES+= -I${.OBJDIR} -I"$S/${OSACPI_MI_DIR}" -I"$S/${ACPICA_DIR}/include"
 INCLUDES+= -I$S/dev/netif/ath/ath_hal -I$S/contrib/dev/ath/ath_hal
 
 # Same thing for drm includes
-INCLUDES+= -I$S/dev/drm/include
+INCLUDES+= -I$S/dev/drm/include -I$S/dev/drm/include/drm -I $S/dev/drm/nouveau -I$S/dev/drm/nouveau/core -I$S/dev/drm/nouveau/core/include
 
 COPTS=	${INCLUDES} ${IDENT} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
 CFLAGS=	${COPTFLAGS} ${KCFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
diff --git a/sys/config/LINT64 b/sys/config/LINT64
index 4b884c283e..44226213e3 100644
--- a/sys/config/LINT64
+++ b/sys/config/LINT64
@@ -2127,6 +2127,7 @@ device		drm
 
 # For testing and debugging.
 device		"i915"
+device		nouveau
 device		radeon
 
 options 	DRM_DEBUG
diff --git a/sys/dev/drm/include/acpi/button.h b/sys/dev/drm/include/acpi/button.h
new file mode 100644
index 0000000000..df0b5c3a34
--- /dev/null
+++ b/sys/dev/drm/include/acpi/button.h
@@ -0,0 +1,57 @@
+/*	$NetBSD: button.h,v 1.2 2014/03/18 18:20:42 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _DRM2_COMPAT_ACPI_BUTTON_H_
+#define _DRM2_COMPAT_ACPI_BUTTON_H_
+
+struct notifier_block;
+
+/* XXX This obviously needs a real implementation...  */
+
+static inline int
+acpi_lid_notifier_register(struct notifier_block *notifier)
+{
+	return 0;
+}
+
+static inline int
+acpi_lid_notifier_unregister(struct notifier_block *notifier)
+{
+	return 0;
+}
+
+static inline int
+acpi_lid_open(void)
+{
+	return 1;
+}
+
+#endif  /* _DRM2_COMPAT_ACPI_BUTTON_H_ */
diff --git a/sys/dev/drm/include/asm/io.h b/sys/dev/drm/include/asm/io.h
index 60fc3ef047..379b26ead6 100644
--- a/sys/dev/drm/include/asm/io.h
+++ b/sys/dev/drm/include/asm/io.h
@@ -81,6 +81,13 @@ writeq(u64 value, volatile void __iomem *addr)
 		*(volatile uint32_t *)((char *)addr) = data;	\
 	} while (0)
 
+#undef writew
+static inline void
+writew(uint16_t b, void *addr)
+{
+        *(volatile uint16_t *)addr = b;
+}
+
 #include <linux/vmalloc.h>
 
 /* ioremap function family: map bus addresses into CPU space */
diff --git a/sys/dev/drm/include/drm/drmP.h b/sys/dev/drm/include/drm/drmP.h
index 0a1072c940..b9dc733e61 100644
--- a/sys/dev/drm/include/drm/drmP.h
+++ b/sys/dev/drm/include/drm/drmP.h
@@ -98,6 +98,7 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/scatterlist.h>
+#include <linux/stat.h>
 #include <linux/timer.h>
 #include <asm/io.h>
 #include <linux/seq_file.h>
diff --git a/sys/dev/drm/include/drm/i2c/ch7006.h b/sys/dev/drm/include/drm/i2c/ch7006.h
new file mode 100644
index 0000000000..8390b437a1
--- /dev/null
+++ b/sys/dev/drm/include/drm/i2c/ch7006.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2009 Francisco Jerez.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __DRM_I2C_CH7006_H__
+#define __DRM_I2C_CH7006_H__
+
+/**
+ * struct ch7006_encoder_params
+ *
+ * Describes how the ch7006 is wired up with the GPU. It should be
+ * used as the @params parameter of its @set_config method.
+ *
+ * See "http://www.chrontel.com/pdf/7006.pdf" for their precise
+ * meaning.
+ */
+struct ch7006_encoder_params {
+	enum {
+		CH7006_FORMAT_RGB16 = 0,
+		CH7006_FORMAT_YCrCb24m16,
+		CH7006_FORMAT_RGB24m16,
+		CH7006_FORMAT_RGB15,
+		CH7006_FORMAT_RGB24m12C,
+		CH7006_FORMAT_RGB24m12I,
+		CH7006_FORMAT_RGB24m8,
+		CH7006_FORMAT_RGB16m8,
+		CH7006_FORMAT_RGB15m8,
+		CH7006_FORMAT_YCrCb24m8,
+	} input_format;
+
+	enum {
+		CH7006_CLOCK_SLAVE = 0,
+		CH7006_CLOCK_MASTER,
+	} clock_mode;
+
+	enum {
+		CH7006_CLOCK_EDGE_NEG = 0,
+		CH7006_CLOCK_EDGE_POS,
+	} clock_edge;
+
+	int xcm, pcm;
+
+	enum {
+		CH7006_SYNC_SLAVE = 0,
+		CH7006_SYNC_MASTER,
+	} sync_direction;
+
+	enum {
+		CH7006_SYNC_SEPARATED = 0,
+		CH7006_SYNC_EMBEDDED,
+	} sync_encoding;
+
+	enum {
+		CH7006_POUT_1_8V = 0,
+		CH7006_POUT_3_3V,
+	} pout_level;
+
+	enum {
+		CH7006_ACTIVE_HSYNC = 0,
+		CH7006_ACTIVE_DSTART,
+	} active_detect;
+};
+
+#endif
diff --git a/sys/dev/drm/include/drm/i2c/sil164.h b/sys/dev/drm/include/drm/i2c/sil164.h
new file mode 100644
index 0000000000..205e27384c
--- /dev/null
+++ b/sys/dev/drm/include/drm/i2c/sil164.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2010 Francisco Jerez.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __DRM_I2C_SIL164_H__
+#define __DRM_I2C_SIL164_H__
+
+/**
+ * struct sil164_encoder_params
+ *
+ * Describes how the sil164 is connected to the GPU. It should be used
+ * as the @params parameter of its @set_config method.
+ *
+ * See "http://www.siliconimage.com/docs/SiI-DS-0021-E-164.pdf".
+ */
+struct sil164_encoder_params {
+	enum {
+		SIL164_INPUT_EDGE_FALLING = 0,
+		SIL164_INPUT_EDGE_RISING
+	} input_edge;
+
+	enum {
+		SIL164_INPUT_WIDTH_12BIT = 0,
+		SIL164_INPUT_WIDTH_24BIT
+	} input_width;
+
+	enum {
+		SIL164_INPUT_SINGLE_EDGE = 0,
+		SIL164_INPUT_DUAL_EDGE
+	} input_dual;
+
+	enum {
+		SIL164_PLL_FILTER_ON = 0,
+		SIL164_PLL_FILTER_OFF,
+	} pll_filter;
+
+	int input_skew; /** < Allowed range [-4, 3], use 0 for no de-skew. */
+	int duallink_skew; /** < Allowed range [-4, 3]. */
+};
+
+#endif
diff --git a/sys/dev/drm/include/linux/bitops.h b/sys/dev/drm/include/linux/bitops.h
index 634e9fe473..1eddaf9ee3 100644
--- a/sys/dev/drm/include/linux/bitops.h
+++ b/sys/dev/drm/include/linux/bitops.h
@@ -66,6 +66,13 @@ __flsl(long mask)
 	return (flsl(mask) - 1);
 }
 
+#ifdef __LP64__
+static inline int
+__ffs64(long mask)
+{
+	return (flsl(mask) - 1);
+}
+#endif
 
 #define	ffz(mask)	__ffs(~(mask))
 
diff --git a/sys/dev/drm/include/linux/compiler.h b/sys/dev/drm/include/linux/compiler.h
index 5c373b68b2..af9c875d08 100644
--- a/sys/dev/drm/include/linux/compiler.h
+++ b/sys/dev/drm/include/linux/compiler.h
@@ -39,6 +39,7 @@
 #define __force
 #define __nocast
 #define __iomem
+#define __rcu
 #define __chk_user_ptr(x)		0
 #define __chk_io_ptr(x)			0
 #define __builtin_warning(x, y...)	(1)
@@ -57,6 +58,7 @@
 #define	__attribute_const__		__attribute__((__const__))
 #undef __always_inline
 #define	__always_inline			inline
+#define noinline			__noinline
 
 #define	likely(x)			__builtin_expect(!!(x), 1)
 #define	unlikely(x)			__builtin_expect(!!(x), 0)
diff --git a/sys/dev/drm/include/linux/dma-attrs.h b/sys/dev/drm/include/linux/dma-attrs.h
new file mode 100644
index 0000000000..e28535897b
--- /dev/null
+++ b/sys/dev/drm/include/linux/dma-attrs.h
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/ofed/include/linux/dma-attrs.h 289644 2015-10-20 19:08:26Z hselasky $
+ */
+#ifndef	_LINUX_DMA_ATTR_H_
+#define	_LINUX_DMA_ATTR_H_
+
+enum dma_attr { DMA_ATTR_WRITE_BARRIER, DMA_ATTR_WEAK_ORDERING, DMA_ATTR_MAX, };
+
+#define __DMA_ATTRS_LONGS BITS_TO_LONGS(DMA_ATTR_MAX)
+
+struct dma_attrs {
+	unsigned long flags;
+};
+ 
+#define DEFINE_DMA_ATTRS(x) struct dma_attrs x = { }
+
+static inline void
+init_dma_attrs(struct dma_attrs *attrs)
+{
+	attrs->flags = 0;
+}
+
+#endif	/* _LINUX_DMA_ATTR_H_ */
diff --git a/sys/dev/drm/include/linux/dma-buf.h b/sys/dev/drm/include/linux/dma-buf.h
new file mode 100644
index 0000000000..56ef9e08fb
--- /dev/null
+++ b/sys/dev/drm/include/linux/dma-buf.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: dma-buf.h,v 1.2 2014/03/18 18:20:43 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_DMA_BUF_H_
+#define _LINUX_DMA_BUF_H_
+
+#endif  /* _LINUX_DMA_BUF_H_ */
diff --git a/sys/dev/drm/include/linux/fb.h b/sys/dev/drm/include/linux/fb.h
index 3802ec42c9..80ed315dc6 100644
--- a/sys/dev/drm/include/linux/fb.h
+++ b/sys/dev/drm/include/linux/fb.h
@@ -38,6 +38,15 @@
 
 #define	KHZ2PICOS(a)	(1000000000UL/(a))
 
+struct fb_copyarea{
+};
+
+struct fb_fillrect {
+};
+
+struct fb_image {
+};
+
 extern int fb_get_options(const char *name, char **option);
 
 #define FBINFO_STATE_RUNNING	0
diff --git a/sys/dev/drm/include/linux/fence.h b/sys/dev/drm/include/linux/fence.h
index a60b2086c1..5360fc93da 100644
--- a/sys/dev/drm/include/linux/fence.h
+++ b/sys/dev/drm/include/linux/fence.h
@@ -27,4 +27,6 @@
 #ifndef _LINUX_FENCE_H_
 #define _LINUX_FENCE_H_
 
+struct fence { };
+
 #endif	/* _LINUX_FENCE_H_ */
diff --git a/sys/dev/drm/include/linux/gfp.h b/sys/dev/drm/include/linux/gfp.h
index f5118b4759..3cc44c3fdd 100644
--- a/sys/dev/drm/include/linux/gfp.h
+++ b/sys/dev/drm/include/linux/gfp.h
@@ -34,6 +34,7 @@
 #define GFP_ATOMIC	M_NOWAIT
 #define GFP_KERNEL	M_WAITOK
 #define GFP_TEMPORARY	M_WAITOK
+#define __GFP_NOWARN	0
 #define __GFP_ZERO	M_ZERO
 
 #define GFP_DMA32	0x10000	/* XXX: MUST NOT collide with the M_XXX definitions */
diff --git a/sys/dev/drm/include/linux/hwmon-sysfs.h b/sys/dev/drm/include/linux/hwmon-sysfs.h
new file mode 100644
index 0000000000..0fea811445
--- /dev/null
+++ b/sys/dev/drm/include/linux/hwmon-sysfs.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: hwmon-sysfs.h,v 1.1 2014/07/16 20:59:58 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef	_LINUX_HWMON_SYSFS_H_
+#define	_LINUX_HWMON_SYSFS_H_
+
+#endif	/* _LINUX_HWMON_SYSFS_H_ */
diff --git a/sys/dev/drm/include/linux/hwmon.h b/sys/dev/drm/include/linux/hwmon.h
new file mode 100644
index 0000000000..9a32454b50
--- /dev/null
+++ b/sys/dev/drm/include/linux/hwmon.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: hwmon.h,v 1.1 2014/07/16 20:59:58 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef	_LINUX_HWMON_H_
+#define	_LINUX_HWMON_H_
+
+#endif	/* _LINUX_HWMON_H_ */
diff --git a/sys/dev/drm/include/linux/i2c.h b/sys/dev/drm/include/linux/i2c.h
index 5cb881b85f..193731ecba 100644
--- a/sys/dev/drm/include/linux/i2c.h
+++ b/sys/dev/drm/include/linux/i2c.h
@@ -62,4 +62,17 @@ struct i2c_algorithm {
 extern int i2c_add_adapter(struct i2c_adapter *);
 extern void i2c_del_adapter(struct i2c_adapter *);
 
+struct i2c_board_info {
+	char		type[I2C_NAME_SIZE];
+	unsigned short	flags;
+	unsigned short	addr;
+	void		*platform_data;
+//	struct dev_archdata	*archdata;
+	struct device_node *of_node;
+//	struct acpi_dev_node acpi_node;
+	int		irq;
+};
+#define I2C_BOARD_INFO(dev_type, dev_addr) \
+	.type = dev_type, .addr = (dev_addr)
+
 #endif	/* _LINUX_I2C_H_ */
diff --git a/sys/dev/drm/include/linux/init.h b/sys/dev/drm/include/linux/init.h
new file mode 100644
index 0000000000..6847a4b771
--- /dev/null
+++ b/sys/dev/drm/include/linux/init.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_INIT_H
+#define _LINUX_INIT_H
+
+#endif /* _LINUX_INIT_H */
diff --git a/sys/dev/drm/include/linux/kernel.h b/sys/dev/drm/include/linux/kernel.h
index 8197c769d5..7d8fa9f7a9 100644
--- a/sys/dev/drm/include/linux/kernel.h
+++ b/sys/dev/drm/include/linux/kernel.h
@@ -62,6 +62,7 @@
 
 #define	simple_strtoul	strtoul
 #define	simple_strtol	strtol
+#define	kstrtol(a,b,c)	({*(c) = strtol(a,0,b);})
 
 #define min(x, y)			((x) < (y) ? (x) : (y))
 #define max(x, y)			((x) > (y) ? (x) : (y))
diff --git a/sys/dev/drm/include/linux/list.h b/sys/dev/drm/include/linux/list.h
index e4588ba5cf..d1b87268cd 100644
--- a/sys/dev/drm/include/linux/list.h
+++ b/sys/dev/drm/include/linux/list.h
@@ -159,7 +159,10 @@ list_del_init(struct list_head *entry)
 #define list_next_entry(ptr, member)					\
 	list_entry(((ptr)->member.next), typeof(*(ptr)), member)
 
-#define	list_for_each(p, head)						\
+#define list_prev_entry(ptr, member) 					\
+	list_entry(((ptr)->member.prev), typeof(*(ptr)), member)
+
+#define	list_for_each(p, head)					\
 	for (p = (head)->next; p != (head); p = p->next)
 
 #define	list_for_each_safe(p, n, head)					\
@@ -178,6 +181,10 @@ list_del_init(struct list_head *entry)
 	for (p = list_next_entry((p), field); &p->field != (h);		\
 	    p = list_next_entry((p), field))
 
+#define list_for_each_entry_continue_reverse(p, h, field)		\
+	for (p = list_prev_entry((p), field); &p->field != (h);		\
+	    p = list_prev_entry((p), field))
+
 #define list_for_each_entry_safe_from(pos, n, head, member) 			\
 	for (n = list_entry(pos->member.next, typeof(*pos), member);		\
 	     &pos->member != (head);						\
diff --git a/sys/dev/drm/include/linux/lockdep.h b/sys/dev/drm/include/linux/lockdep.h
index 67fda0cda7..3e19ee2bd1 100644
--- a/sys/dev/drm/include/linux/lockdep.h
+++ b/sys/dev/drm/include/linux/lockdep.h
@@ -27,6 +27,8 @@
 #ifndef _LINUX_LOCKDEP_H_
 #define _LINUX_LOCKDEP_H_
 
+struct lock_class_key { };
+
 static inline void
 lockdep_assert_held(struct lock *l)
 {
diff --git a/sys/dev/drm/include/linux/mod_devicetable.h b/sys/dev/drm/include/linux/mod_devicetable.h
index 974658c088..7dd52112f0 100644
--- a/sys/dev/drm/include/linux/mod_devicetable.h
+++ b/sys/dev/drm/include/linux/mod_devicetable.h
@@ -48,4 +48,6 @@ struct dmi_system_id {
 
 int dmi_check_system(const struct dmi_system_id *);
 
+#define I2C_NAME_SIZE	20
+
 #endif	/* _LINUX_MOD_DEVICETABLE_H_ */
diff --git a/sys/dev/drm/include/linux/mutex.h b/sys/dev/drm/include/linux/mutex.h
index 8bbb90d6a6..81c638fe63 100644
--- a/sys/dev/drm/include/linux/mutex.h
+++ b/sys/dev/drm/include/linux/mutex.h
@@ -30,6 +30,9 @@
 #include <sys/lock.h>
 #include <linux/lockdep.h>
 
+#define __mutex_init(lock, name, key)	lockinit((lock), (name), 0, LK_EXCLUSIVE);
+#define mutex_init(lock)		__mutex_init((lock), #lock, NULL)
+
 #define mutex_is_locked(lock)	(lockcount(lock) != 0)
 
 #define mutex_lock(lock)	lockmgr(lock, LK_EXCLUSIVE)
diff --git a/sys/dev/drm/include/linux/page.h b/sys/dev/drm/include/linux/page.h
new file mode 100644
index 0000000000..622b4dec92
--- /dev/null
+++ b/sys/dev/drm/include/linux/page.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/ofed/include/linux/page.h 289644 2015-10-20 19:08:26Z hselasky $
+ */
+#ifndef	_LINUX_PAGE_H_
+#define _LINUX_PAGE_H_
+
+#include <linux/types.h>
+
+#include <sys/param.h>
+
+#include <machine/atomic.h>
+#include <vm/vm.h>
+#include <vm/vm_page.h>
+
+#define page	vm_page
+
+#define	virt_to_page(x)	PHYS_TO_VM_PAGE(vtophys((x)))
+
+#define	clear_page(page)		memset((page), 0, PAGE_SIZE)
+#define	pgprot_noncached(prot)		VM_MEMATTR_UNCACHEABLE
+#define	pgprot_writecombine(prot)	VM_MEMATTR_WRITE_COMBINING
+
+#undef	PAGE_MASK
+#define	PAGE_MASK	(~(PAGE_SIZE-1))
+
+#endif	/* _LINUX_PAGE_H_ */
diff --git a/sys/dev/drm/include/linux/platform_device.h b/sys/dev/drm/include/linux/platform_device.h
new file mode 100644
index 0000000000..7a31afdb6a
--- /dev/null
+++ b/sys/dev/drm/include/linux/platform_device.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_PLATFORM_DEVICE_H_
+#define _LINUX_PLATFORM_DEVICE_H_
+
+#endif  /* _LINUX_PLATFORM_DEVICE_H_ */
diff --git a/sys/dev/drm/include/linux/pm_runtime.h b/sys/dev/drm/include/linux/pm_runtime.h
new file mode 100644
index 0000000000..019e5af2bd
--- /dev/null
+++ b/sys/dev/drm/include/linux/pm_runtime.h
@@ -0,0 +1,86 @@
+/*	$NetBSD: pm_runtime.h,v 1.3 2014/08/23 08:03:33 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_PM_RUNTIME_H_
+#define _LINUX_PM_RUNTIME_H_
+
+#include <sys/cdefs.h>
+
+struct device;
+
+static inline void
+pm_runtime_allow(struct device *dev __unused)
+{
+}
+
+static inline void
+pm_runtime_disable(struct device *dev __unused)
+{
+}
+
+static inline int
+pm_runtime_get_sync(struct device *dev __unused)
+{
+	return 0;
+}
+
+static inline void
+pm_runtime_mark_last_busy(struct device *dev __unused)
+{
+}
+
+static inline void
+pm_runtime_put(struct device *dev __unused)
+{
+}
+
+static inline void
+pm_runtime_put_autosuspend(struct device *dev __unused)
+{
+}
+
+static inline void
+pm_runtime_set_active(struct device *dev __unused)
+{
+}
+
+static inline void
+pm_runtime_set_autosuspend_delay(struct device *dev __unused,
+    unsigned ms __unused)
+{
+}
+
+static inline void
+pm_runtime_use_autosuspend(struct device *dev __unused)
+{
+}
+
+#endif  /* _LINUX_PM_RUNTIME_H_ */
diff --git a/sys/dev/drm/include/linux/power_supply.h b/sys/dev/drm/include/linux/power_supply.h
new file mode 100644
index 0000000000..8057d48b29
--- /dev/null
+++ b/sys/dev/drm/include/linux/power_supply.h
@@ -0,0 +1,41 @@
+/*	$NetBSD: power_supply.h,v 1.1 2014/07/16 20:59:58 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_POWER_SUPPLY_H_
+#define _LINUX_POWER_SUPPLY_H_
+
+static inline int
+power_supply_is_system_supplied(void)
+{
+	return 1;
+}
+
+#endif	/* _LINUX_POWER_SUPPLY_H_ */
diff --git a/sys/dev/drm/include/linux/printk.h b/sys/dev/drm/include/linux/printk.h
index 226e8a98c0..796f1a765a 100644
--- a/sys/dev/drm/include/linux/printk.h
+++ b/sys/dev/drm/include/linux/printk.h
@@ -105,6 +105,7 @@ struct va_format {
 	}					\
 } while (0)
 
+#define vprintk	kvprintf
 enum {
 	DUMP_PREFIX_NONE,
 	DUMP_PREFIX_ADDRESS,
diff --git a/sys/dev/drm/include/linux/rbtree.h b/sys/dev/drm/include/linux/rbtree.h
index 864feb3b0b..7cfd9f13c5 100644
--- a/sys/dev/drm/include/linux/rbtree.h
+++ b/sys/dev/drm/include/linux/rbtree.h
@@ -25,10 +25,15 @@
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/ofed/include/linux/rbtree.h 289644 2015-10-20 19:08:26Z hselasky $
  */
 #ifndef	_LINUX_RBTREE_H_
 #define	_LINUX_RBTREE_H_
 
+#ifndef __DragonFly__
+#include <sys/stddef.h>
+#endif
 #include <sys/tree.h>
 
 struct rb_node {
diff --git a/sys/dev/drm/include/linux/rcupdate.h b/sys/dev/drm/include/linux/rcupdate.h
new file mode 100644
index 0000000000..c56845d701
--- /dev/null
+++ b/sys/dev/drm/include/linux/rcupdate.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: rcupdate.h,v 1.2 2014/03/18 18:20:43 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_RCUPDATE_H_
+#define _LINUX_RCUPDATE_H_
+
+#endif  /* _LINUX_RCUPDATE_H_ */
diff --git a/sys/dev/drm/include/linux/reboot.h b/sys/dev/drm/include/linux/reboot.h
new file mode 100644
index 0000000000..ec367ed30c
--- /dev/null
+++ b/sys/dev/drm/include/linux/reboot.h
@@ -0,0 +1,49 @@
+/*	$NetBSD: reboot.h,v 1.2 2015/03/06 01:43:07 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef	_LINUX_REBOOT_H_
+#define	_LINUX_REBOOT_H_
+
+#include <sys/types.h>
+#include <sys/reboot.h>
+
+/* XXX Implement this by posting a CRITICAL-OVER envsys event?  */
+static inline int
+orderly_poweroff(bool force __unused)
+{
+
+	ksignal(initproc, SIGUSR2);
+
+	return 0;
+}
+
+
+#endif	/* _LINUX_REBOOT_H_ */
diff --git a/sys/dev/drm/include/linux/rwlock.h b/sys/dev/drm/include/linux/rwlock.h
new file mode 100644
index 0000000000..6759b19f65
--- /dev/null
+++ b/sys/dev/drm/include/linux/rwlock.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef	_LINUX_RWLOCK_H_
+#define	_LINUX_RWLOCK_H_
+
+#include <sys/lock.h>
+
+#define	rwlock_init(_l)		lockinit((_l), "DRM rwlock", 0, LK_CANRECURSE)
+#define	read_lock(_l)		lockmgr((_l), LK_EXCLUSIVE)
+#define	write_lock(_l)		read_lock(_l)
+#define	read_unlock(_l)		lockmgr((_l), LK_RELEASE)
+#define	write_unlock(_l)	read_unlock(_l)
+#define	read_lock_irq(_l)	lockmgr((_l), LK_EXCLUSIVE)
+#define	write_lock_irq(_l)	read_lock_irq(_l)
+#define	read_unlock_irq(_l)	lockmgr((_l), LK_RELEASE)
+#define	write_unlock_irq(_l)	read_unlock_irq(_l)
+
+#endif /* _LINUX_RWLOCK_H */
diff --git a/sys/dev/drm/include/linux/screen_info.h b/sys/dev/drm/include/linux/screen_info.h
new file mode 100644
index 0000000000..67cf45a878
--- /dev/null
+++ b/sys/dev/drm/include/linux/screen_info.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: screen_info.h,v 1.1 2014/08/06 13:53:12 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_SCREEN_INFO_H_
+#define _LINUX_SCREEN_INFO_H_
+
+#endif  /* _LINUX_SCREEN_INFO_H_ */
diff --git a/sys/dev/drm/include/linux/slab.h b/sys/dev/drm/include/linux/slab.h
index adcbd7d8ed..3981b83e02 100644
--- a/sys/dev/drm/include/linux/slab.h
+++ b/sys/dev/drm/include/linux/slab.h
@@ -40,5 +40,8 @@ MALLOC_DECLARE(M_DRM);
 } while (0)
 
 #define kcalloc(n, size, flags)	kzalloc((n) * (size), flags)
+#define vmalloc(size)		kmalloc(size, M_DRM, GFP_KERNEL)
+#define vfree(ptr)		kfree(ptr)
+#define vzalloc(size)		kzalloc(size, GFP_KERNEL);
 
 #endif	/* _LINUX_SLAB_H_ */
diff --git a/sys/dev/drm/include/linux/spinlock.h b/sys/dev/drm/include/linux/spinlock.h
index c1a3b32889..9c4768cecb 100644
--- a/sys/dev/drm/include/linux/spinlock.h
+++ b/sys/dev/drm/include/linux/spinlock.h
@@ -31,8 +31,12 @@
 #include <sys/lock.h>
 
 #include <linux/irqflags.h>
+#include <linux/rwlock.h>
 #include <asm/barrier.h>
 
+#define spin_lock_init(x)	spin_init(x, "DRM spinlock")
+#define spin_lock_irqsave(x, f)	{ (void)f; spin_lock(x); }
+#define spin_unlock_irqrestore(x, f) { (void)f; spin_unlock(x); }
 #define spin_is_locked(x)	spin_held(x)
 
 #define assert_spin_locked(x)	KKASSERT(lockcountnb(x))
diff --git a/sys/dev/drm/include/linux/stat.h b/sys/dev/drm/include/linux/stat.h
new file mode 100644
index 0000000000..60de6b9f1b
--- /dev/null
+++ b/sys/dev/drm/include/linux/stat.h
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_STAT_H
+#define _LINUX_STAT_H
+
+#define S_IRUGO	(S_IRUSR | S_IRGRP | S_IROTH)
+
+#endif /* _LINUX_STAT_H */
diff --git a/sys/dev/drm/include/linux/static_key.h b/sys/dev/drm/include/linux/static_key.h
new file mode 100644
index 0000000000..27bd3f8a08
--- /dev/null
+++ b/sys/dev/drm/include/linux/static_key.h
@@ -0,0 +1 @@
+#include <linux/jump_label.h>
diff --git a/sys/dev/drm/include/linux/string.h b/sys/dev/drm/include/linux/string.h
index 2cdde6e597..d3b02887d9 100644
--- a/sys/dev/drm/include/linux/string.h
+++ b/sys/dev/drm/include/linux/string.h
@@ -64,4 +64,24 @@ kmemdup(const void *src, size_t len, gfp_t gfp)
 	return (dst);
 }
 
+static inline char *
+kstrndup(const char *src, size_t maxlen, gfp_t gfp)
+{
+	char *dst;
+	size_t len;
+
+	if (src == NULL)
+		return NULL;
+
+	len = strnlen(src, maxlen);
+	dst = kmalloc(len + 1, M_DRM, gfp);
+	if (dst == NULL)
+		return NULL;
+
+	memcpy(dst, src, len);
+	dst[len] = '\0';
+
+	return dst;
+}
+
 #endif	/* _LINUX_STRING_H_ */
diff --git a/sys/dev/drm/include/linux/swiotlb.h b/sys/dev/drm/include/linux/swiotlb.h
new file mode 100644
index 0000000000..f3d02945a4
--- /dev/null
+++ b/sys/dev/drm/include/linux/swiotlb.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: swiotlb.h,v 1.1 2014/07/16 20:59:58 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_SWIOTLB_H_
+#define _LINUX_SWIOTLB_H_
+
+#endif  /* _LINUX_SWIOTLB_H_ */
diff --git a/sys/dev/drm/include/linux/sysrq.h b/sys/dev/drm/include/linux/sysrq.h
new file mode 100644
index 0000000000..ca782f5074
--- /dev/null
+++ b/sys/dev/drm/include/linux/sysrq.h
@@ -0,0 +1,49 @@
+/*	$NetBSD: sysrq.h,v 1.2 2014/03/18 18:20:43 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_SYSRQ_H_
+#define _LINUX_SYSRQ_H_
+
+struct sysrq_key_op {
+	char sko_blahdittyblahblah;
+};
+
+static inline void
+register_sysrq_key(char key __unused, struct sysrq_key_op *op __unused)
+{
+}
+
+static inline void
+unregister_sysrq_key(char key __unused, struct sysrq_key_op *op __unused)
+{
+}
+
+#endif  /* _LINUX_SYSRQ_H_ */
diff --git a/sys/dev/drm/include/linux/tracepoint.h b/sys/dev/drm/include/linux/tracepoint.h
new file mode 100644
index 0000000000..8df5b437d9
--- /dev/null
+++ b/sys/dev/drm/include/linux/tracepoint.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_TRACEPOINT_H
+#define _LINUX_TRACEPOINT_H
+
+#endif /* _LINUX_TRACEPOINT_H */
diff --git a/sys/dev/drm/include/linux/tty.h b/sys/dev/drm/include/linux/tty.h
new file mode 100644
index 0000000000..58d7f3e753
--- /dev/null
+++ b/sys/dev/drm/include/linux/tty.h
@@ -0,0 +1,35 @@
+/*	$NetBSD: tty.h,v 1.2 2014/03/18 18:20:43 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_TTY_H_
+#define _LINUX_TTY_H_
+
+#endif  /* _LINUX_TTY_H_ */
diff --git a/sys/dev/drm/include/linux/vgaarb.h b/sys/dev/drm/include/linux/vgaarb.h
new file mode 100644
index 0000000000..6c110dabe7
--- /dev/null
+++ b/sys/dev/drm/include/linux/vgaarb.h
@@ -0,0 +1,49 @@
+/*	$NetBSD: vgaarb.h,v 1.3 2015/02/25 21:55:30 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_VGAARB_H_
+#define _LINUX_VGAARB_H_
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/stdbool.h>
+
+struct pci_dev;
+
+static inline int
+vga_client_register(struct pci_dev *pdev __unused, void *cookie __unused,
+    void (*irq_set_state)(void *, bool) __unused,
+    unsigned int (*set_vga_decode)(void *, bool) __unused)
+{
+	return -ENOSYS;
+}
+
+#endif  /* _LINUX_VGAARB_H_ */
diff --git a/sys/dev/drm/include/linux/workqueue.h b/sys/dev/drm/include/linux/workqueue.h
index 4c2f598cf4..989375e002 100644
--- a/sys/dev/drm/include/linux/workqueue.h
+++ b/sys/dev/drm/include/linux/workqueue.h
@@ -195,6 +195,13 @@ flush_taskqueue(struct taskqueue *tq)
 	PRELE(curproc);
 }
 
+static inline int
+flush_work(struct work_struct *work)
+{
+	taskqueue_drain(work->taskqueue, &work->work_task);
+	return 0;
+}
+
 static inline int
 cancel_work_sync(struct work_struct *work)
 {
diff --git a/sys/dev/drm/include/trace/define_trace.h b/sys/dev/drm/include/trace/define_trace.h
new file mode 100644
index 0000000000..02e1003568
--- /dev/null
+++ b/sys/dev/drm/include/trace/define_trace.h
@@ -0,0 +1,118 @@
+/*
+ * Trace files that want to automate creation of all tracepoints defined
+ * in their file should include this file. The following are macros that the
+ * trace file may define:
+ *
+ * TRACE_SYSTEM defines the system the tracepoint is for
+ *
+ * TRACE_INCLUDE_FILE if the file name is something other than TRACE_SYSTEM.h
+ *     This macro may be defined to tell define_trace.h what file to include.
+ *     Note, leave off the ".h".
+ *
+ * TRACE_INCLUDE_PATH if the path is something other than core kernel include/trace
+ *     then this macro can define the path to use. Note, the path is relative to
+ *     define_trace.h, not the file including it. Full path names for out of tree
+ *     modules must be used.
+ */
+
+#ifdef CREATE_TRACE_POINTS
+
+/* Prevent recursion */
+#undef CREATE_TRACE_POINTS
+
+#include <linux/stringify.h>
+
+#undef TRACE_EVENT
+#define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
+	DEFINE_TRACE(name)
+
+#undef TRACE_EVENT_CONDITION
+#define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
+	TRACE_EVENT(name,						\
+		PARAMS(proto),						\
+		PARAMS(args),						\
+		PARAMS(tstruct),					\
+		PARAMS(assign),						\
+		PARAMS(print))
+
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_FN(name, reg, unreg)
+
+#undef DEFINE_EVENT
+#define DEFINE_EVENT(template, name, proto, args) \
+	DEFINE_TRACE(name)
+
+#undef DEFINE_EVENT_FN
+#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
+	DEFINE_TRACE_FN(name, reg, unreg)
+
+#undef DEFINE_EVENT_PRINT
+#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
+	DEFINE_TRACE(name)
+
+#undef DEFINE_EVENT_CONDITION
+#define DEFINE_EVENT_CONDITION(template, name, proto, args, cond) \
+	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
+
+#undef DECLARE_TRACE
+#define DECLARE_TRACE(name, proto, args)	\
+	DEFINE_TRACE(name)
+
+#undef TRACE_INCLUDE
+#undef __TRACE_INCLUDE
+
+#ifndef TRACE_INCLUDE_FILE
+# define TRACE_INCLUDE_FILE TRACE_SYSTEM
+# define UNDEF_TRACE_INCLUDE_FILE
+#endif
+
+#ifndef TRACE_INCLUDE_PATH
+# define __TRACE_INCLUDE(system) <trace/events/system.h>
+# define UNDEF_TRACE_INCLUDE_PATH
+#else
+# define __TRACE_INCLUDE(system) __stringify(TRACE_INCLUDE_PATH/system.h)
+#endif
+
+# define TRACE_INCLUDE(system) __TRACE_INCLUDE(system)
+
+/* Let the trace headers be reread */
+#define TRACE_HEADER_MULTI_READ
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
+/* Make all open coded DECLARE_TRACE nops */
+#undef DECLARE_TRACE
+#define DECLARE_TRACE(name, proto, args)
+
+#ifdef CONFIG_EVENT_TRACING
+#include <trace/ftrace.h>
+#endif
+
+#undef TRACE_EVENT
+#undef TRACE_EVENT_FN
+#undef TRACE_EVENT_CONDITION
+#undef DECLARE_EVENT_CLASS
+#undef DEFINE_EVENT
+#undef DEFINE_EVENT_FN
+#undef DEFINE_EVENT_PRINT
+#undef DEFINE_EVENT_CONDITION
+#undef TRACE_HEADER_MULTI_READ
+#undef DECLARE_TRACE
+
+/* Only undef what we defined in this file */
+#ifdef UNDEF_TRACE_INCLUDE_FILE
+# undef TRACE_INCLUDE_FILE
+# undef UNDEF_TRACE_INCLUDE_FILE
+#endif
+
+#ifdef UNDEF_TRACE_INCLUDE_PATH
+# undef TRACE_INCLUDE_PATH
+# undef UNDEF_TRACE_INCLUDE_PATH
+#endif
+
+/* We may be processing more files */
+#define CREATE_TRACE_POINTS
+
+#endif /* CREATE_TRACE_POINTS */
diff --git a/sys/dev/drm/include/trace/events/fence.h b/sys/dev/drm/include/trace/events/fence.h
new file mode 100644
index 0000000000..d05e4a8214
--- /dev/null
+++ b/sys/dev/drm/include/trace/events/fence.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _TRACE_FENCE_H
+#define _TRACE_FENCE_H
+
+#endif /* _TRACE_FENCE_H */
diff --git a/sys/dev/drm/include/uapi_drm/nouveau_drm.h b/sys/dev/drm/include/uapi_drm/nouveau_drm.h
new file mode 100644
index 0000000000..5507eead58
--- /dev/null
+++ b/sys/dev/drm/include/uapi_drm/nouveau_drm.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2005 Stephane Marchesin.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __NOUVEAU_DRM_H__
+#define __NOUVEAU_DRM_H__
+
+#define DRM_NOUVEAU_EVENT_NVIF                                       0x80000000
+
+/* reserved object handles when using deprecated object APIs - these
+ * are here so that libdrm can allow interoperability with the new
+ * object APIs
+ */
+#define NOUVEAU_ABI16_CLIENT   0xffffffff
+#define NOUVEAU_ABI16_DEVICE   0xdddddddd
+#define NOUVEAU_ABI16_CHAN(n) (0xcccc0000 | (n))
+
+#define NOUVEAU_GEM_DOMAIN_CPU       (1 << 0)
+#define NOUVEAU_GEM_DOMAIN_VRAM      (1 << 1)
+#define NOUVEAU_GEM_DOMAIN_GART      (1 << 2)
+#define NOUVEAU_GEM_DOMAIN_MAPPABLE  (1 << 3)
+#define NOUVEAU_GEM_DOMAIN_COHERENT  (1 << 4)
+
+#define NOUVEAU_GEM_TILE_COMP        0x00030000 /* nv50-only */
+#define NOUVEAU_GEM_TILE_LAYOUT_MASK 0x0000ff00
+#define NOUVEAU_GEM_TILE_16BPP       0x00000001
+#define NOUVEAU_GEM_TILE_32BPP       0x00000002
+#define NOUVEAU_GEM_TILE_ZETA        0x00000004
+#define NOUVEAU_GEM_TILE_NONCONTIG   0x00000008
+
+struct drm_nouveau_gem_info {
+	uint32_t handle;
+	uint32_t domain;
+	uint64_t size;
+	uint64_t offset;
+	uint64_t map_handle;
+	uint32_t tile_mode;
+	uint32_t tile_flags;
+};
+
+struct drm_nouveau_gem_new {
+	struct drm_nouveau_gem_info info;
+	uint32_t channel_hint;
+	uint32_t align;
+};
+
+#define NOUVEAU_GEM_MAX_BUFFERS 1024
+struct drm_nouveau_gem_pushbuf_bo_presumed {
+	uint32_t valid;
+	uint32_t domain;
+	uint64_t offset;
+};
+
+struct drm_nouveau_gem_pushbuf_bo {
+	uint64_t user_priv;
+	uint32_t handle;
+	uint32_t read_domains;
+	uint32_t write_domains;
+	uint32_t valid_domains;
+	struct drm_nouveau_gem_pushbuf_bo_presumed presumed;
+};
+
+#define NOUVEAU_GEM_RELOC_LOW  (1 << 0)
+#define NOUVEAU_GEM_RELOC_HIGH (1 << 1)
+#define NOUVEAU_GEM_RELOC_OR   (1 << 2)
+#define NOUVEAU_GEM_MAX_RELOCS 1024
+struct drm_nouveau_gem_pushbuf_reloc {
+	uint32_t reloc_bo_index;
+	uint32_t reloc_bo_offset;
+	uint32_t bo_index;
+	uint32_t flags;
+	uint32_t data;
+	uint32_t vor;
+	uint32_t tor;
+};
+
+#define NOUVEAU_GEM_MAX_PUSH 512
+struct drm_nouveau_gem_pushbuf_push {
+	uint32_t bo_index;
+	uint32_t pad;
+	uint64_t offset;
+	uint64_t length;
+};
+
+struct drm_nouveau_gem_pushbuf {
+	uint32_t channel;
+	uint32_t nr_buffers;
+	uint64_t buffers;
+	uint32_t nr_relocs;
+	uint32_t nr_push;
+	uint64_t relocs;
+	uint64_t push;
+	uint32_t suffix0;
+	uint32_t suffix1;
+	uint64_t vram_available;
+	uint64_t gart_available;
+};
+
+#define NOUVEAU_GEM_CPU_PREP_NOWAIT                                  0x00000001
+#define NOUVEAU_GEM_CPU_PREP_WRITE                                   0x00000004
+struct drm_nouveau_gem_cpu_prep {
+	uint32_t handle;
+	uint32_t flags;
+};
+
+struct drm_nouveau_gem_cpu_fini {
+	uint32_t handle;
+};
+
+#define DRM_NOUVEAU_GETPARAM           0x00 /* deprecated */
+#define DRM_NOUVEAU_SETPARAM           0x01 /* deprecated */
+#define DRM_NOUVEAU_CHANNEL_ALLOC      0x02 /* deprecated */
+#define DRM_NOUVEAU_CHANNEL_FREE       0x03 /* deprecated */
+#define DRM_NOUVEAU_GROBJ_ALLOC        0x04 /* deprecated */
+#define DRM_NOUVEAU_NOTIFIEROBJ_ALLOC  0x05 /* deprecated */
+#define DRM_NOUVEAU_GPUOBJ_FREE        0x06 /* deprecated */
+#define DRM_NOUVEAU_NVIF               0x07
+#define DRM_NOUVEAU_GEM_NEW            0x40
+#define DRM_NOUVEAU_GEM_PUSHBUF        0x41
+#define DRM_NOUVEAU_GEM_CPU_PREP       0x42
+#define DRM_NOUVEAU_GEM_CPU_FINI       0x43
+#define DRM_NOUVEAU_GEM_INFO           0x44
+
+#define DRM_IOCTL_NOUVEAU_GEM_NEW            DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_NEW, struct drm_nouveau_gem_new)
+#define DRM_IOCTL_NOUVEAU_GEM_PUSHBUF        DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_PUSHBUF, struct drm_nouveau_gem_pushbuf)
+#define DRM_IOCTL_NOUVEAU_GEM_CPU_PREP       DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_CPU_PREP, struct drm_nouveau_gem_cpu_prep)
+#define DRM_IOCTL_NOUVEAU_GEM_CPU_FINI       DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_CPU_FINI, struct drm_nouveau_gem_cpu_fini)
+#define DRM_IOCTL_NOUVEAU_GEM_INFO           DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_INFO, struct drm_nouveau_gem_info)
+
+#endif /* __NOUVEAU_DRM_H__ */
diff --git a/sys/dev/drm/nouveau/NOTES b/sys/dev/drm/nouveau/NOTES
new file mode 100644
index 0000000000..3af22cdcdf
--- /dev/null
+++ b/sys/dev/drm/nouveau/NOTES
@@ -0,0 +1,9 @@
+softc ~= struct nouveau_drm in dev/drm/nouveau/nouveau_drm.h
+      drm_device *dev
+      pci_dev *hdmi_device
+
+struct nouveau_device in dev/drm/nouveau/core/include/core/device.h
+       pci_dev *pdev
+
+struct pci_dev in dev/drm/include/linux/pci.h
+       struct device *dev
diff --git a/sys/dev/drm/nouveau/core/core/nouveau_core_client.c b/sys/dev/drm/nouveau/core/core/nouveau_core_client.c
index 68bf067681..139adb3a2c 100644
--- a/sys/dev/drm/nouveau/core/core/nouveau_core_client.c
+++ b/sys/dev/drm/nouveau/core/core/nouveau_core_client.c
@@ -116,7 +116,7 @@ nvkm_client_notify_new(struct nouveau_client *client,
 	nv_ioctl(client, "notify new size %d\n", size);
 	if (nvif_unpack(req->v0, 0, 0, true)) {
 		nv_ioctl(client, "notify new vers %d reply %d route %02x "
-				 "token %llx\n", req->v0.version,
+				 "token %lx\n", req->v0.version,
 			 req->v0.reply, req->v0.route, req->v0.token);
 		notify->version = req->v0.version;
 		notify->size = sizeof(notify->rep.v0);
@@ -229,7 +229,7 @@ nouveau_client_create_(const char *name, u64 devname, const char *cfg,
 	atomic_set(&nv_object(client)->usecount, 2);
 
 	nouveau_object_ref(device, &client->device);
-	snprintf(client->name, sizeof(client->name), "%s", name);
+	ksnprintf(client->name, sizeof(client->name), "%s", name);
 	client->debug = nouveau_dbgopt(dbg, "CLIENT");
 	return 0;
 }
diff --git a/sys/dev/drm/nouveau/core/core/nouveau_core_engctx.c b/sys/dev/drm/nouveau/core/core/nouveau_core_engctx.c
index 84c71fad2b..8a59c1b998 100644
--- a/sys/dev/drm/nouveau/core/core/nouveau_core_engctx.c
+++ b/sys/dev/drm/nouveau/core/core/nouveau_core_engctx.c
@@ -227,7 +227,7 @@ struct nouveau_object *
 nouveau_engctx_get(struct nouveau_engine *engine, u64 addr)
 {
 	struct nouveau_engctx *engctx;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 	spin_lock_irqsave(&engine->lock, flags);
 	list_for_each_entry(engctx, &engine->contexts, head) {
diff --git a/sys/dev/drm/nouveau/core/core/nouveau_core_ioctl.c b/sys/dev/drm/nouveau/core/core/nouveau_core_ioctl.c
index f7e19bfb48..9a2409317f 100644
--- a/sys/dev/drm/nouveau/core/core/nouveau_core_ioctl.c
+++ b/sys/dev/drm/nouveau/core/core/nouveau_core_ioctl.c
@@ -107,7 +107,7 @@ nvkm_ioctl_new(struct nouveau_handle *parent, void *data, u32 size)
 		return ret;
 
 	nv_ioctl(client, "new vers %d handle %08x class %08x "
-			 "route %02x token %llx\n",
+			 "route %02x token %lx\n",
 		args->v0.version, _handle, _oclass,
 		args->v0.route, args->v0.token);
 
@@ -234,7 +234,7 @@ nvkm_ioctl_rd(struct nouveau_handle *handle, void *data, u32 size)
 
 	nv_ioctl(object, "rd size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
-		nv_ioctl(object, "rd vers %d size %d addr %016llx\n",
+		nv_ioctl(object, "rd vers %d size %d addr %016lx\n",
 			args->v0.version, args->v0.size, args->v0.addr);
 		switch (args->v0.size) {
 		case 1:
@@ -276,7 +276,7 @@ nvkm_ioctl_wr(struct nouveau_handle *handle, void *data, u32 size)
 
 	nv_ioctl(object, "wr size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
-		nv_ioctl(object, "wr vers %d size %d addr %016llx data %08x\n",
+		nv_ioctl(object, "wr vers %d size %d addr %016lx data %08x\n",
 			 args->v0.version, args->v0.size, args->v0.addr,
 			 args->v0.data);
 		switch (args->v0.size) {
diff --git a/sys/dev/drm/nouveau/core/core/nouveau_core_mm.c b/sys/dev/drm/nouveau/core/core/nouveau_core_mm.c
index 7a4e0891c5..816b6d3ae8 100644
--- a/sys/dev/drm/nouveau/core/core/nouveau_core_mm.c
+++ b/sys/dev/drm/nouveau/core/core/nouveau_core_mm.c
@@ -74,7 +74,7 @@ region_head(struct nouveau_mm *mm, struct nouveau_mm_node *a, u32 size)
 	if (a->length == size)
 		return a;
 
-	b = kmalloc(sizeof(*b), GFP_KERNEL);
+	b = kmalloc(sizeof(*b), M_DRM, GFP_KERNEL);
 	if (unlikely(b == NULL))
 		return NULL;
 
@@ -142,7 +142,7 @@ region_tail(struct nouveau_mm *mm, struct nouveau_mm_node *a, u32 size)
 	if (a->length == size)
 		return a;
 
-	b = kmalloc(sizeof(*b), GFP_KERNEL);
+	b = kmalloc(sizeof(*b), M_DRM, GFP_KERNEL);
 	if (unlikely(b == NULL))
 		return NULL;
 
diff --git a/sys/dev/drm/nouveau/core/core/nouveau_core_notify.c b/sys/dev/drm/nouveau/core/core/nouveau_core_notify.c
index 76adb81bde..76d99654b1 100644
--- a/sys/dev/drm/nouveau/core/core/nouveau_core_notify.c
+++ b/sys/dev/drm/nouveau/core/core/nouveau_core_notify.c
@@ -110,7 +110,7 @@ nvkm_notify_send(struct nvkm_notify *notify, void *data, u32 size)
 	spin_unlock_irqrestore(&event->refs_lock, flags);
 
 	if (test_bit(NVKM_NOTIFY_WORK, &notify->flags)) {
-		memcpy((void *)notify->data, data, size);
+		memcpy(__DECONST(void *, notify->data), data, size);
 		schedule_work(&notify->work);
 	} else {
 		notify->data = data;
@@ -128,7 +128,7 @@ nvkm_notify_fini(struct nvkm_notify *notify)
 		spin_lock_irqsave(&notify->event->list_lock, flags);
 		list_del(&notify->head);
 		spin_unlock_irqrestore(&notify->event->list_lock, flags);
-		kfree((void *)notify->data);
+		kfree(__DECONST(void *, notify->data));
 		notify->event = NULL;
 	}
 }
@@ -150,7 +150,7 @@ nvkm_notify_init(struct nvkm_event *event, int (*func)(struct nvkm_notify *),
 			if (ret = 0, work) {
 				INIT_WORK(&notify->work, nvkm_notify_work);
 				set_bit(NVKM_NOTIFY_WORK, &notify->flags);
-				notify->data = kmalloc(reply, GFP_KERNEL);
+				notify->data = kmalloc(reply, M_DRM, GFP_KERNEL);
 				if (!notify->data)
 					ret = -ENOMEM;
 			}
diff --git a/sys/dev/drm/nouveau/core/core/nouveau_core_printk.c b/sys/dev/drm/nouveau/core/core/nouveau_core_printk.c
index 03e0060b13..2ed4b32195 100644
--- a/sys/dev/drm/nouveau/core/core/nouveau_core_printk.c
+++ b/sys/dev/drm/nouveau/core/core/nouveau_core_printk.c
@@ -65,7 +65,7 @@ nv_printk_(struct nouveau_object *object, int level, const char *fmt, ...)
 		char obuf[64], *ofmt = "";
 
 		if (object->engine) {
-			snprintf(obuf, sizeof(obuf), "[0x%08x][%p]",
+			ksnprintf(obuf, sizeof(obuf), "[0x%08x][%p]",
 				 nv_hclass(object), object);
 			ofmt = obuf;
 			subdev = object->engine;
@@ -78,7 +78,7 @@ nv_printk_(struct nouveau_object *object, int level, const char *fmt, ...)
 		if (level > nv_subdev(subdev)->debug)
 			return;
 
-		snprintf(mfmt, sizeof(mfmt), "%snouveau %c[%8s][%s]%s %s", pfx,
+		ksnprintf(mfmt, sizeof(mfmt), "%snouveau %c[%8s][%s]%s %s", pfx,
 			 name[level], nv_subdev(subdev)->name,
 			 nv_device(device)->name, ofmt, fmt);
 	} else
@@ -86,10 +86,10 @@ nv_printk_(struct nouveau_object *object, int level, const char *fmt, ...)
 		if (level > nv_client(object)->debug)
 			return;
 
-		snprintf(mfmt, sizeof(mfmt), "%snouveau %c[%8s] %s", pfx,
+		ksnprintf(mfmt, sizeof(mfmt), "%snouveau %c[%8s] %s", pfx,
 			 name[level], nv_client(object)->name, fmt);
 	} else {
-		snprintf(mfmt, sizeof(mfmt), "%snouveau: %s", pfx, fmt);
+		ksnprintf(mfmt, sizeof(mfmt), "%snouveau: %s", pfx, fmt);
 	}
 
 	va_start(args, fmt);
diff --git a/sys/dev/drm/nouveau/core/engine/copy/nouveau_engine_copy_nva3.c b/sys/dev/drm/nouveau/core/engine/copy/nouveau_engine_copy_nva3.c
index abb410ef09..aa7d4fb0cd 100644
--- a/sys/dev/drm/nouveau/core/engine/copy/nouveau_engine_copy_nva3.c
+++ b/sys/dev/drm/nouveau/core/engine/copy/nouveau_engine_copy_nva3.c
@@ -101,7 +101,7 @@ nva3_copy_intr(struct nouveau_subdev *subdev)
 	if (stat & 0x00000040) {
 		nv_error(falcon, "DISPATCH_ERROR [");
 		nouveau_enum_print(nva3_copy_isr_error_name, ssta);
-		pr_cont("] ch %d [0x%010llx %s] subc %d mthd 0x%04x data 0x%08x\n",
+		pr_cont("] ch %d [0x%010lx %s] subc %d mthd 0x%04x data 0x%08x\n",
 		       chid, inst << 12, nouveau_client_name(engctx), subc,
 		       mthd, data);
 		nv_wo32(falcon, 0x004, 0x00000040);
diff --git a/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv84.c b/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv84.c
index ea5c42f317..0adb3ef56c 100644
--- a/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv84.c
+++ b/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv84.c
@@ -128,7 +128,7 @@ nv84_crypt_intr(struct nouveau_subdev *subdev)
 	if (stat) {
 		nv_error(priv, "%s", "");
 		nouveau_bitfield_print(nv84_crypt_intr_mask, stat);
-		pr_cont(" ch %d [0x%010llx %s] mthd 0x%04x data 0x%08x\n",
+		pr_cont(" ch %d [0x%010lx %s] mthd 0x%04x data 0x%08x\n",
 		       chid, (u64)inst << 12, nouveau_client_name(engctx),
 		       mthd, data);
 	}
diff --git a/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv98.c b/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv98.c
index 5571c09534..d994d82b9a 100644
--- a/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv98.c
+++ b/sys/dev/drm/nouveau/core/engine/crypt/nouveau_engine_crypt_nv98.c
@@ -102,7 +102,7 @@ nv98_crypt_intr(struct nouveau_subdev *subdev)
 	if (stat & 0x00000040) {
 		nv_error(priv, "DISPATCH_ERROR [");
 		nouveau_enum_print(nv98_crypt_isr_error_name, ssta);
-		pr_cont("] ch %d [0x%010llx %s] subc %d mthd 0x%04x data 0x%08x\n",
+		pr_cont("] ch %d [0x%010lx %s] subc %d mthd 0x%04x data 0x%08x\n",
 		       chid, (u64)inst << 12, nouveau_client_name(engctx),
 		       subc, mthd, data);
 		nv_wr32(priv, 0x087004, 0x00000040);
diff --git a/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_base.c b/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_base.c
index 8928f7981d..2ee4dce6e0 100644
--- a/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_base.c
+++ b/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_base.c
@@ -36,7 +36,7 @@
 #include "acpi.h"
 
 static DEFINE_MUTEX(nv_devices_mutex);
-static LIST_HEAD(nv_devices);
+static LINUX_LIST_HEAD(nv_devices);
 
 struct nouveau_device *
 nouveau_device_find(u64 name)
@@ -108,10 +108,10 @@ nouveau_devobj_info(struct nouveau_object *object, void *data, u32 size)
 		break;
 	default:
 		if (device->pdev) {
-			if (pci_find_capability(device->pdev, PCI_CAP_ID_AGP))
+			if (pci_find_extcap(device->pdev->dev, PCIY_AGP, NULL) == 0)
 				args->v0.platform = NV_DEVICE_INFO_V0_AGP;
 			else
-			if (pci_is_pcie(device->pdev))
+			if (pci_find_extcap(device->pdev->dev, PCIY_EXPRESS, NULL) == 0)
 				args->v0.platform = NV_DEVICE_INFO_V0_PCIE;
 			else
 				args->v0.platform = NV_DEVICE_INFO_V0_PCI;
@@ -290,8 +290,8 @@ nouveau_devobj_ctor(struct nouveau_object *parent,
 
 	nv_ioctl(parent, "create device size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
-		nv_ioctl(parent, "create device v%d device %016llx "
-				 "disable %016llx debug0 %016llx\n",
+		nv_ioctl(parent, "create device v%d device %016lx "
+				 "disable %016lx debug0 %016lx\n",
 			 args->v0.version, args->v0.device,
 			 args->v0.disable, args->v0.debug0);
 	} else
@@ -347,7 +347,7 @@ nouveau_devobj_ctor(struct nouveau_object *parent,
 		/* read boot0 and strapping information */
 		boot0 = ioread32_native(map + 0x000000);
 		strap = ioread32_native(map + 0x101000);
-		iounmap(map);
+		iounmap(map, 102000);
 
 		/* determine chipset and derive architecture from it */
 		if ((boot0 & 0x1f000000) > 0) {
diff --git a/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_ctrl.c b/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_ctrl.c
index e34101a349..7c7d2dfc3e 100644
--- a/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_ctrl.c
+++ b/sys/dev/drm/nouveau/core/engine/device/nouveau_engine_device_ctrl.c
@@ -124,8 +124,8 @@ nouveau_control_mthd_pstate_attr(struct nouveau_object *object,
 		hi = lo;
 	}
 
-	snprintf(args->v0.name, sizeof(args->v0.name), "%s", domain->mname);
-	snprintf(args->v0.unit, sizeof(args->v0.unit), "MHz");
+	ksnprintf(args->v0.name, sizeof(args->v0.name), "%s", domain->mname);
+	ksnprintf(args->v0.unit, sizeof(args->v0.unit), "MHz");
 	args->v0.min = lo / domain->mdiv;
 	args->v0.max = hi / domain->mdiv;
 
diff --git a/sys/dev/drm/nouveau/core/engine/disp/nouveau_engine_disp_nv50.c b/sys/dev/drm/nouveau/core/engine/disp/nouveau_engine_disp_nv50.c
index f8cbb51213..0deeaea5af 100644
--- a/sys/dev/drm/nouveau/core/engine/disp/nouveau_engine_disp_nv50.c
+++ b/sys/dev/drm/nouveau/core/engine/disp/nouveau_engine_disp_nv50.c
@@ -258,9 +258,9 @@ nv50_disp_mthd_list(struct nv50_disp_priv *priv, int debug, u32 base, int c,
 			char mods[16];
 
 			if (prev != next)
-				snprintf(mods, sizeof(mods), "-> 0x%08x", next);
+				ksnprintf(mods, sizeof(mods), "-> 0x%08x", next);
 			else
-				snprintf(mods, sizeof(mods), "%13c", ' ');
+				ksnprintf(mods, sizeof(mods), "%13c", ' ');
 
 			nv_printk_(disp, debug, "\t0x%04x: 0x%08x %s%s%s\n",
 				   mthd, prev, mods, name ? " // " : "",
@@ -289,13 +289,13 @@ nv50_disp_mthd_chan(struct nv50_disp_priv *priv, int debug, int head,
 			char cname_[16], sname_[16];
 
 			if (chan->addr) {
-				snprintf(cname_, sizeof(cname_), "%s %d",
+				ksnprintf(cname_, sizeof(cname_), "%s %d",
 					 chan->name, head);
 				cname = cname_;
 			}
 
 			if (chan->data[i].nr > 1) {
-				snprintf(sname_, sizeof(sname_), " - %s %d",
+				ksnprintf(sname_, sizeof(sname_), " - %s %d",
 					 chan->data[i].name, j);
 				sname = sname_;
 			}
@@ -914,7 +914,7 @@ nv50_disp_base_mthd(struct nouveau_object *object, u32 mthd,
 	struct nv50_disp_priv *priv = (void *)object->engine;
 	struct nvkm_output *outp = NULL;
 	struct nvkm_output *temp;
-	u16 type, mask = 0;
+	u16 type = 0, mask = 0;
 	int head, ret;
 
 	if (mthd != NV50_DISP_MTHD)
@@ -1262,11 +1262,11 @@ nv50_disp_intr_error(struct nv50_disp_priv *priv, int chid)
 
 	et = nouveau_enum_find(nv50_disp_intr_error_type, type);
 	if (!et)
-		snprintf(etunk, sizeof(etunk), "UNK%02X", type);
+		ksnprintf(etunk, sizeof(etunk), "UNK%02X", type);
 
 	ec = nouveau_enum_find(nv50_disp_intr_error_code, code);
 	if (!ec)
-		snprintf(ecunk, sizeof(ecunk), "UNK%02X", code);
+		ksnprintf(ecunk, sizeof(ecunk), "UNK%02X", code);
 
 	nv_error(priv, "%s [%s] chid %d mthd 0x%04x data 0x%08x\n",
 		 et ? et->name : etunk, ec ? ec->name : ecunk,
diff --git a/sys/dev/drm/nouveau/core/engine/dmaobj/nouveau_engine_dmaobj_base.c b/sys/dev/drm/nouveau/core/engine/dmaobj/nouveau_engine_dmaobj_base.c
index e1500f77a5..416773f8d8 100644
--- a/sys/dev/drm/nouveau/core/engine/dmaobj/nouveau_engine_dmaobj_base.c
+++ b/sys/dev/drm/nouveau/core/engine/dmaobj/nouveau_engine_dmaobj_base.c
@@ -80,7 +80,7 @@ nvkm_dmaobj_create_(struct nouveau_object *parent,
 	nv_ioctl(parent, "create dma size %d\n", *psize);
 	if (nvif_unpack(args->v0, 0, 0, true)) {
 		nv_ioctl(parent, "create dma vers %d target %d access %d "
-				 "start %016llx limit %016llx\n",
+				 "start %016lx limit %016lx\n",
 			 args->v0.version, args->v0.target, args->v0.access,
 			 args->v0.start, args->v0.limit);
 		dmaobj->target = args->v0.target;
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c
index 0f999fc45a..ff4f74ace2 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_base.c
@@ -118,7 +118,7 @@ nouveau_fifo_channel_destroy(struct nouveau_fifo_chan *chan)
 	unsigned long flags;
 
 	if (chan->user)
-		iounmap(chan->user);
+		iounmap(chan->user, chan->size);
 
 	spin_lock_irqsave(&priv->lock, flags);
 	priv->channel[chan->chid] = NULL;
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv04.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv04.c
index 5ae6a43893..a842b2a0d5 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv04.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv04.c
@@ -128,7 +128,7 @@ nv04_fifo_chan_ctor(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel dma size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
-				 "offset %016llx\n", args->v0.version,
+				 "offset %016lx\n", args->v0.version,
 			 args->v0.pushbuf, args->v0.offset);
 	} else
 		return ret;
@@ -308,7 +308,7 @@ nv04_fifo_pause(struct nouveau_fifo *pfifo, unsigned long *pflags)
 __acquires(priv->base.lock)
 {
 	struct nv04_fifo_priv *priv = (void *)pfifo;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 	spin_lock_irqsave(&priv->base.lock, flags);
 	*pflags = flags;
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv10.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv10.c
index 2a32add51c..f9e1ce7f76 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv10.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv10.c
@@ -70,7 +70,7 @@ nv10_fifo_chan_ctor(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel dma size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
-				 "offset %016llx\n", args->v0.version,
+				 "offset %016lx\n", args->v0.version,
 			 args->v0.pushbuf, args->v0.offset);
 	} else
 		return ret;
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv17.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv17.c
index 12d76c8adb..340cd2c521 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv17.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv17.c
@@ -75,7 +75,7 @@ nv17_fifo_chan_ctor(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel dma size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
-				 "offset %016llx\n", args->v0.version,
+				 "offset %016lx\n", args->v0.version,
 			 args->v0.pushbuf, args->v0.offset);
 	} else
 		return ret;
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv40.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv40.c
index 9f49c3a24d..4ab691a6a3 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv40.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv40.c
@@ -193,7 +193,7 @@ nv40_fifo_chan_ctor(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel dma size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
-				 "offset %016llx\n", args->v0.version,
+				 "offset %016lx\n", args->v0.version,
 			 args->v0.pushbuf, args->v0.offset);
 	} else
 		return ret;
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv50.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv50.c
index 5d1e86bc24..359323f515 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv50.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv50.c
@@ -206,7 +206,7 @@ nv50_fifo_chan_ctor_dma(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel dma size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
-				 "offset %016llx\n", args->v0.version,
+				 "offset %016lx\n", args->v0.version,
 			 args->v0.pushbuf, args->v0.offset);
 	} else
 		return ret;
@@ -269,7 +269,7 @@ nv50_fifo_chan_ctor_ind(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel gpfifo size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel gpfifo vers %d pushbuf %08x "
-				 "ioffset %016llx ilength %08x\n",
+				 "ioffset %016lx ilength %08x\n",
 			 args->v0.version, args->v0.pushbuf, args->v0.ioffset,
 			 args->v0.ilength);
 	} else
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv84.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv84.c
index 1f42996b35..061aa5f533 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv84.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nv84.c
@@ -172,7 +172,7 @@ nv84_fifo_chan_ctor_dma(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel dma size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
-				 "offset %016llx\n", args->v0.version,
+				 "offset %016lx\n", args->v0.version,
 			 args->v0.pushbuf, args->v0.offset);
 	} else
 		return ret;
@@ -244,7 +244,7 @@ nv84_fifo_chan_ctor_ind(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel gpfifo size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel gpfifo vers %d pushbuf %08x "
-				 "ioffset %016llx ilength %08x\n",
+				 "ioffset %016lx ilength %08x\n",
 			 args->v0.version, args->v0.pushbuf, args->v0.ioffset,
 			 args->v0.ilength);
 	} else
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nvc0.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nvc0.c
index 1fe1f8fbda..8e1f73e971 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nvc0.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nvc0.c
@@ -201,7 +201,7 @@ nvc0_fifo_chan_ctor(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel gpfifo size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel gpfifo vers %d pushbuf %08x "
-				 "ioffset %016llx ilength %08x\n",
+				 "ioffset %016lx ilength %08x\n",
 			 args->v0.version, args->v0.pushbuf, args->v0.ioffset,
 			 args->v0.ilength);
 	} else
@@ -529,7 +529,7 @@ nvc0_fifo_intr_sched(struct nvc0_fifo_priv *priv)
 
 	en = nouveau_enum_find(nvc0_fifo_sched_reason, code);
 	if (!en)
-		snprintf(enunk, sizeof(enunk), "UNK%02x", code);
+		ksnprintf(enunk, sizeof(enunk), "UNK%02x", code);
 
 	nv_error(priv, "SCHED_ERROR [ %s ]\n", en ? en->name : enunk);
 
@@ -623,7 +623,7 @@ nvc0_fifo_intr_fault(struct nvc0_fifo_priv *priv, int unit)
 
 	er = nouveau_enum_find(nvc0_fifo_fault_reason, reason);
 	if (!er)
-		snprintf(erunk, sizeof(erunk), "UNK%02X", reason);
+		ksnprintf(erunk, sizeof(erunk), "UNK%02X", reason);
 
 	eu = nouveau_enum_find(nvc0_fifo_fault_engine, unit);
 	if (eu) {
@@ -644,21 +644,21 @@ nvc0_fifo_intr_fault(struct nvc0_fifo_priv *priv, int unit)
 			break;
 		}
 	} else {
-		snprintf(euunk, sizeof(euunk), "UNK%02x", unit);
+		ksnprintf(euunk, sizeof(euunk), "UNK%02x", unit);
 	}
 
 	if (hub) {
 		ec = nouveau_enum_find(nvc0_fifo_fault_hubclient, client);
 	} else {
 		ec = nouveau_enum_find(nvc0_fifo_fault_gpcclient, client);
-		snprintf(gpcid, sizeof(gpcid), "%d", gpc);
+		ksnprintf(gpcid, sizeof(gpcid), "%d", gpc);
 	}
 
 	if (!ec)
-		snprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
+		ksnprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
 
-	nv_error(priv, "%s fault at 0x%010llx [%s] from %s/%s%s%s%s on "
-		       "channel 0x%010llx [%s]\n", write ? "write" : "read",
+	nv_error(priv, "%s fault at 0x%010lx [%s] from %s/%s%s%s%s on "
+		       "channel 0x%010lx [%s]\n", write ? "write" : "read",
 		 (u64)vahi << 32 | valo, er ? er->name : erunk,
 		 eu ? eu->name : euunk, hub ? "" : "GPC", gpcid, hub ? "" : "/",
 		 ec ? ec->name : ecunk, (u64)inst << 12,
diff --git a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nve0.c b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nve0.c
index d2f0fd39c1..076719264b 100644
--- a/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nve0.c
+++ b/sys/dev/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nve0.c
@@ -230,7 +230,7 @@ nve0_fifo_chan_ctor(struct nouveau_object *parent,
 	nv_ioctl(parent, "create channel gpfifo size %d\n", size);
 	if (nvif_unpack(args->v0, 0, 0, false)) {
 		nv_ioctl(parent, "create channel gpfifo vers %d pushbuf %08x "
-				 "ioffset %016llx ilength %08x engine %08x\n",
+				 "ioffset %016lx ilength %08x engine %08x\n",
 			 args->v0.version, args->v0.pushbuf, args->v0.ioffset,
 			 args->v0.ilength, args->v0.engine);
 	} else
@@ -534,7 +534,7 @@ nve0_fifo_intr_bind(struct nve0_fifo_priv *priv)
 
 	en = nouveau_enum_find(nve0_fifo_bind_reason, code);
 	if (!en)
-		snprintf(enunk, sizeof(enunk), "UNK%02x", code);
+		ksnprintf(enunk, sizeof(enunk), "UNK%02x", code);
 
 	nv_error(priv, "BIND_ERROR [ %s ]\n", en ? en->name : enunk);
 }
@@ -583,7 +583,7 @@ nve0_fifo_intr_sched(struct nve0_fifo_priv *priv)
 
 	en = nouveau_enum_find(nve0_fifo_sched_reason, code);
 	if (!en)
-		snprintf(enunk, sizeof(enunk), "UNK%02x", code);
+		ksnprintf(enunk, sizeof(enunk), "UNK%02x", code);
 
 	nv_error(priv, "SCHED_ERROR [ %s ]\n", en ? en->name : enunk);
 
@@ -738,7 +738,7 @@ nve0_fifo_intr_fault(struct nve0_fifo_priv *priv, int unit)
 
 	er = nouveau_enum_find(nve0_fifo_fault_reason, reason);
 	if (!er)
-		snprintf(erunk, sizeof(erunk), "UNK%02X", reason);
+		ksnprintf(erunk, sizeof(erunk), "UNK%02X", reason);
 
 	eu = nouveau_enum_find(nve0_fifo_fault_engine, unit);
 	if (eu) {
@@ -759,21 +759,21 @@ nve0_fifo_intr_fault(struct nve0_fifo_priv *priv, int unit)
 			break;
 		}
 	} else {
-		snprintf(euunk, sizeof(euunk), "UNK%02x", unit);
+		ksnprintf(euunk, sizeof(euunk), "UNK%02x", unit);
 	}
 
 	if (hub) {
 		ec = nouveau_enum_find(nve0_fifo_fault_hubclient, client);
 	} else {
 		ec = nouveau_enum_find(nve0_fifo_fault_gpcclient, client);
-		snprintf(gpcid, sizeof(gpcid), "%d", gpc);
+		ksnprintf(gpcid, sizeof(gpcid), "%d", gpc);
 	}
 
 	if (!ec)
-		snprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
+		ksnprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
 
-	nv_error(priv, "%s fault at 0x%010llx [%s] from %s/%s%s%s%s on "
-		       "channel 0x%010llx [%s]\n", write ? "write" : "read",
+	nv_error(priv, "%s fault at 0x%010lx [%s] from %s/%s%s%s%s on "
+		       "channel 0x%010lx [%s]\n", write ? "write" : "read",
 		 (u64)vahi << 32 | valo, er ? er->name : erunk,
 		 eu ? eu->name : euunk, hub ? "" : "GPC", gpcid, hub ? "" : "/",
 		 ec ? ec->name : ecunk, (u64)inst << 12,
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxgm107.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxgm107.c
index 62e918b9fa..179c7429cd 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxgm107.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxgm107.c
@@ -894,7 +894,7 @@ static void
 gm107_grctx_generate_attrib(struct nvc0_grctx *info)
 {
 	struct nvc0_graph_priv *priv = info->priv;
-	const struct nvc0_grctx_oclass *impl = (void *)nvc0_grctx_impl(priv);
+	const struct nvc0_grctx_oclass *impl = nvc0_grctx_impl(priv);
 	const u32  alpha = impl->alpha_nr;
 	const u32 attrib = impl->attrib_nr;
 	const u32   size = 0x20 * (impl->attrib_nr_max + impl->alpha_nr_max);
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv40.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv40.c
index 7bbb1e1b7a..c32d79165b 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv40.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv40.c
@@ -672,7 +672,7 @@ nv40_grctx_fill(struct nouveau_device *device, struct nouveau_gpuobj *mem)
 int
 nv40_grctx_init(struct nouveau_device *device, u32 *size)
 {
-	u32 *ctxprog = kmalloc(256 * 4, GFP_KERNEL), i;
+	u32 *ctxprog = kmalloc(256 * 4, M_DRM, GFP_KERNEL), i;
 	struct nouveau_grctx ctx = {
 		.device = device,
 		.mode = NOUVEAU_GRCTX_PROG,
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv50.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv50.c
index 552fdbd45e..592bc7a723 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv50.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnv50.c
@@ -265,7 +265,7 @@ nv50_grctx_fill(struct nouveau_device *device, struct nouveau_gpuobj *mem)
 int
 nv50_grctx_init(struct nouveau_device *device, u32 *size)
 {
-	u32 *ctxprog = kmalloc(512 * 4, GFP_KERNEL), i;
+	u32 *ctxprog = kmalloc(512 * 4, M_DRM, GFP_KERNEL), i;
 	struct nouveau_grctx ctx = {
 		.device = device,
 		.mode = NOUVEAU_GRCTX_PROG,
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvc0.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvc0.c
index b8e5fe60a1..d84e48ac3c 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvc0.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvc0.c
@@ -1343,7 +1343,7 @@ nvc0_grctx_generate(struct nvc0_graph_priv *priv)
 		goto done;
 	}
 
-	priv->data = kmalloc(priv->size, GFP_KERNEL);
+	priv->data = kmalloc(priv->size, M_DRM, GFP_KERNEL);
 	if (priv->data) {
 		for (i = 0; i < priv->size; i += 4)
 			priv->data[i / 4] = nv_ro32(chan, 0x80000 + i);
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvd7.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvd7.c
index fcf534fd9e..0f8c0b8d1b 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvd7.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_ctxnvd7.c
@@ -214,7 +214,7 @@ nvd7_grctx_generate_attrib(struct nvc0_grctx *info)
 	}
 }
 
-void
+static void
 nvd7_grctx_generate_main(struct nvc0_graph_priv *priv, struct nvc0_grctx *info)
 {
 	struct nvc0_grctx_oclass *oclass = (void *)nv_engine(priv)->cclass;
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_gm107.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_gm107.c
index 4bdbdab2fd..8b266c4635 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_gm107.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_gm107.c
@@ -318,7 +318,7 @@ gm107_graph_init_bios(struct nvc0_graph_priv *priv)
 	}
 }
 
-int
+static int
 gm107_graph_init(struct nouveau_object *object)
 {
 	struct nvc0_graph_oclass *oclass = (void *)object->oclass;
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv04.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv04.c
index f70e2f67a4..cb5e7c3f5e 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv04.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv04.c
@@ -354,7 +354,7 @@ nv04_graph_ctx_regs[] = {
 struct nv04_graph_priv {
 	struct nouveau_graph base;
 	struct nv04_graph_chan *chan[16];
-	spinlock_t lock;
+	struct spinlock lock;
 };
 
 struct nv04_graph_chan {
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv10.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv10.c
index 2b12b09683..730d3088ff 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv10.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv10.c
@@ -392,7 +392,7 @@ static int nv17_graph_ctx_regs[] = {
 struct nv10_graph_priv {
 	struct nouveau_graph base;
 	struct nv10_graph_chan *chan[32];
-	spinlock_t lock;
+	struct spinlock lock;
 };
 
 struct nv10_graph_chan {
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv50.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv50.c
index 38e0aa26f1..e976b6d90b 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv50.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nv50.c
@@ -39,7 +39,7 @@
 
 struct nv50_graph_priv {
 	struct nouveau_graph base;
-	spinlock_t lock;
+	struct spinlock lock;
 	u32 size;
 };
 
@@ -615,7 +615,7 @@ nv50_graph_trap_handler(struct nv50_graph_priv *priv, u32 display,
 			nv_error(priv, "TRAP DISPATCH_FAULT\n");
 			if (display && (addr & 0x80000000)) {
 				nv_error(priv,
-					 "ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x%08x 400808 0x%08x 400848 0x%08x\n",
+					 "ch %d [0x%010lx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x%08x 400808 0x%08x 400848 0x%08x\n",
 					 chid, inst,
 					 nouveau_client_name(engctx), subc,
 					 class, mthd, datah, datal, addr, r848);
@@ -640,7 +640,7 @@ nv50_graph_trap_handler(struct nv50_graph_priv *priv, u32 display,
 			nv_error(priv, "TRAP DISPATCH_QUERY\n");
 			if (display && (addr & 0x80000000)) {
 				nv_error(priv,
-					 "ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x 40084c 0x%08x\n",
+					 "ch %d [0x%010lx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x 40084c 0x%08x\n",
 					 chid, inst,
 					 nouveau_client_name(engctx), subc,
 					 class, mthd, data, addr);
@@ -844,7 +844,7 @@ nv50_graph_intr(struct nouveau_subdev *subdev)
 			pr_cont("\n");
 		}
 		nv_error(priv,
-			 "ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
+			 "ch %d [0x%010lx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
 			 chid, (u64)inst << 12, nouveau_client_name(engctx),
 			 subc, class, mthd, data);
 	}
diff --git a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nvc0.c b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nvc0.c
index 30fd1dc64f..95726443db 100644
--- a/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nvc0.c
+++ b/sys/dev/drm/nouveau/core/engine/graph/nouveau_engine_graph_nvc0.c
@@ -1096,7 +1096,7 @@ nvc0_graph_intr(struct nouveau_subdev *subdev)
 		handle = nouveau_handle_get_class(engctx, class);
 		if (!handle || nv_call(handle->object, mthd, data)) {
 			nv_error(priv,
-				 "ILLEGAL_MTHD ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
+				 "ILLEGAL_MTHD ch %d [0x%010lx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
 				 chid, inst << 12, nouveau_client_name(engctx),
 				 subc, class, mthd, data);
 		}
@@ -1107,7 +1107,7 @@ nvc0_graph_intr(struct nouveau_subdev *subdev)
 
 	if (stat & 0x00000020) {
 		nv_error(priv,
-			 "ILLEGAL_CLASS ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
+			 "ILLEGAL_CLASS ch %d [0x%010lx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
 			 chid, inst << 12, nouveau_client_name(engctx), subc,
 			 class, mthd, data);
 		nv_wr32(priv, 0x400100, 0x00000020);
@@ -1117,7 +1117,7 @@ nvc0_graph_intr(struct nouveau_subdev *subdev)
 	if (stat & 0x00100000) {
 		nv_error(priv, "DATA_ERROR [");
 		nouveau_enum_print(nv50_data_error_names, code);
-		pr_cont("] ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
+		pr_cont("] ch %d [0x%010lx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
 			chid, inst << 12, nouveau_client_name(engctx), subc,
 			class, mthd, data);
 		nv_wr32(priv, 0x400100, 0x00100000);
@@ -1125,7 +1125,7 @@ nvc0_graph_intr(struct nouveau_subdev *subdev)
 	}
 
 	if (stat & 0x00200000) {
-		nv_error(priv, "TRAP ch %d [0x%010llx %s]\n", chid, inst << 12,
+		nv_error(priv, "TRAP ch %d [0x%010lx %s]\n", chid, inst << 12,
 			 nouveau_client_name(engctx));
 		nvc0_graph_trap_intr(priv);
 		nv_wr32(priv, 0x400100, 0x00200000);
@@ -1147,7 +1147,7 @@ nvc0_graph_intr(struct nouveau_subdev *subdev)
 	nouveau_engctx_put(engctx);
 }
 
-void
+static void
 nvc0_graph_init_fw(struct nvc0_graph_priv *priv, u32 fuc_base,
 		   struct nvc0_graph_fuc *code, struct nvc0_graph_fuc *data)
 {
@@ -1482,7 +1482,7 @@ nvc0_graph_dtor_fw(struct nvc0_graph_fuc *fuc)
 	fuc->data = NULL;
 }
 
-int
+static int
 nvc0_graph_ctor_fw(struct nvc0_graph_priv *priv, const char *fwname,
 		   struct nvc0_graph_fuc *fuc)
 {
@@ -1491,10 +1491,10 @@ nvc0_graph_ctor_fw(struct nvc0_graph_priv *priv, const char *fwname,
 	char f[32];
 	int ret;
 
-	snprintf(f, sizeof(f), "nouveau/nv%02x_%s", device->chipset, fwname);
+	ksnprintf(f, sizeof(f), "nouveau/nv%02x_%s", device->chipset, fwname);
 	ret = request_firmware(&fw, f, nv_device_base(device));
 	if (ret) {
-		snprintf(f, sizeof(f), "nouveau/%s", fwname);
+		ksnprintf(f, sizeof(f), "nouveau/%s", fwname);
 		ret = request_firmware(&fw, f, nv_device_base(device));
 		if (ret) {
 			nv_error(priv, "failed to load %s\n", fwname);
@@ -1502,7 +1502,7 @@ nvc0_graph_ctor_fw(struct nvc0_graph_priv *priv, const char *fwname,
 		}
 	}
 
-	fuc->size = fw->size;
+	fuc->size = fw->datasize;
 	fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
 	release_firmware(fw);
 	return (fuc->data != NULL) ? 0 : -ENOMEM;
diff --git a/sys/dev/drm/nouveau/core/engine/nouveau_engine_falcon.c b/sys/dev/drm/nouveau/core/engine/nouveau_engine_falcon.c
index 2914646c87..48c0a1d581 100644
--- a/sys/dev/drm/nouveau/core/engine/nouveau_engine_falcon.c
+++ b/sys/dev/drm/nouveau/core/engine/nouveau_engine_falcon.c
@@ -116,13 +116,13 @@ _nouveau_falcon_init(struct nouveau_object *object)
 	 * locate a "self-bootstrapping" firmware image for the engine
 	 */
 	if (!falcon->code.data) {
-		snprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03x",
+		ksnprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03x",
 			 device->chipset, falcon->addr >> 12);
 
 		ret = request_firmware(&fw, name, nv_device_base(device));
 		if (ret == 0) {
-			falcon->code.data = vmemdup(fw->data, fw->size);
-			falcon->code.size = fw->size;
+			falcon->code.data = vmemdup(fw->data, fw->datasize);
+			falcon->code.size = fw->datasize;
 			falcon->data.data = NULL;
 			falcon->data.size = 0;
 			release_firmware(fw);
@@ -135,7 +135,7 @@ _nouveau_falcon_init(struct nouveau_object *object)
 	 * images for the engine
 	 */
 	if (!falcon->code.data) {
-		snprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03xd",
+		ksnprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03xd",
 			 device->chipset, falcon->addr >> 12);
 
 		ret = request_firmware(&fw, name, nv_device_base(device));
@@ -144,13 +144,13 @@ _nouveau_falcon_init(struct nouveau_object *object)
 			return ret;
 		}
 
-		falcon->data.data = vmemdup(fw->data, fw->size);
-		falcon->data.size = fw->size;
+		falcon->data.data = vmemdup(fw->data, fw->datasize);
+		falcon->data.size = fw->datasize;
 		release_firmware(fw);
 		if (!falcon->data.data)
 			return -ENOMEM;
 
-		snprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03xc",
+		ksnprintf(name, sizeof(name), "nouveau/nv%02x_fuc%03xc",
 			 device->chipset, falcon->addr >> 12);
 
 		ret = request_firmware(&fw, name, nv_device_base(device));
@@ -159,8 +159,8 @@ _nouveau_falcon_init(struct nouveau_object *object)
 			return ret;
 		}
 
-		falcon->code.data = vmemdup(fw->data, fw->size);
-		falcon->code.size = fw->size;
+		falcon->code.data = vmemdup(fw->data, fw->datasize);
+		falcon->code.size = fw->datasize;
 		release_firmware(fw);
 		if (!falcon->code.data)
 			return -ENOMEM;
diff --git a/sys/dev/drm/nouveau/core/engine/nouveau_engine_xtensa.c b/sys/dev/drm/nouveau/core/engine/nouveau_engine_xtensa.c
index 92384759d2..da746210f7 100644
--- a/sys/dev/drm/nouveau/core/engine/nouveau_engine_xtensa.c
+++ b/sys/dev/drm/nouveau/core/engine/nouveau_engine_xtensa.c
@@ -109,7 +109,7 @@ _nouveau_xtensa_init(struct nouveau_object *object)
 		return ret;
 
 	if (!xtensa->gpu_fw) {
-		snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
+		ksnprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
 			 xtensa->addr >> 12);
 
 		ret = request_firmware(&fw, name, nv_device_base(device));
@@ -118,7 +118,7 @@ _nouveau_xtensa_init(struct nouveau_object *object)
 			return ret;
 		}
 
-		if (fw->size > 0x40000) {
+		if (fw->datasize > 0x40000) {
 			nv_warn(xtensa, "firmware %s too large\n", name);
 			release_firmware(fw);
 			return -EINVAL;
@@ -131,11 +131,11 @@ _nouveau_xtensa_init(struct nouveau_object *object)
 			return ret;
 		}
 
-		nv_debug(xtensa, "Loading firmware to address: 0x%llx\n",
+		nv_debug(xtensa, "Loading firmware to address: 0x%lx\n",
 			 xtensa->gpu_fw->addr);
 
-		for (i = 0; i < fw->size / 4; i++)
-			nv_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i));
+		for (i = 0; i < fw->datasize / 4; i++)
+			nv_wo32(xtensa->gpu_fw, i * 4, *((const u32 *)fw->data + i));
 		release_firmware(fw);
 	}
 
diff --git a/sys/dev/drm/nouveau/core/engine/perfmon/nouveau_engine_perfmon_base.c b/sys/dev/drm/nouveau/core/engine/perfmon/nouveau_engine_perfmon_base.c
index 63013812f7..7ce842414a 100644
--- a/sys/dev/drm/nouveau/core/engine/perfmon/nouveau_engine_perfmon_base.c
+++ b/sys/dev/drm/nouveau/core/engine/perfmon/nouveau_engine_perfmon_base.c
@@ -49,7 +49,7 @@ nouveau_perfsig_find_(struct nouveau_perfdom *dom, const char *name, u32 size)
 		}
 	} else {
 		for (i = 0; i < dom->signal_nr; i++) {
-			snprintf(path, sizeof(path), "/%s/%02x", dom->name, i);
+			ksnprintf(path, sizeof(path), "/%s/%02x", dom->name, i);
 			if (!strncmp(name, path, size))
 				return &dom->signal[i];
 		}
@@ -58,7 +58,7 @@ nouveau_perfsig_find_(struct nouveau_perfdom *dom, const char *name, u32 size)
 	return NULL;
 }
 
-struct nouveau_perfsig *
+static struct nouveau_perfsig *
 nouveau_perfsig_find(struct nouveau_perfmon *ppm, const char *name, u32 size,
 		     struct nouveau_perfdom **pdom)
 {
@@ -139,7 +139,7 @@ nouveau_perfctr_query(struct nouveau_object *object, void *data, u32 size)
 
 	if (si >= 0) {
 		if (raw || !(name = dom->signal[si].name)) {
-			snprintf(args->v0.name, sizeof(args->v0.name),
+			ksnprintf(args->v0.name, sizeof(args->v0.name),
 				 "/%s/%02x", dom->name, si);
 		} else {
 			strncpy(args->v0.name, name, sizeof(args->v0.name));
@@ -405,11 +405,11 @@ nouveau_perfdom_new(struct nouveau_perfmon *ppm, const char *name, u32 mask,
 				return -ENOMEM;
 
 			if (mask) {
-				snprintf(dom->name, sizeof(dom->name),
+				ksnprintf(dom->name, sizeof(dom->name),
 					 "%s/%02x/%02x", name, i,
 					 (int)(sdom - spec));
 			} else {
-				snprintf(dom->name, sizeof(dom->name),
+				ksnprintf(dom->name, sizeof(dom->name),
 					 "%s/%02x", name, (int)(sdom - spec));
 			}
 
diff --git a/sys/dev/drm/nouveau/core/include/core/device.h b/sys/dev/drm/nouveau/core/include/core/device.h
index 8743766454..96b4ada11d 100644
--- a/sys/dev/drm/nouveau/core/include/core/device.h
+++ b/sys/dev/drm/nouveau/core/include/core/device.h
@@ -160,8 +160,8 @@ nv_device_is_pci(struct nouveau_device *device)
 static inline struct device *
 nv_device_base(struct nouveau_device *device)
 {
-	return nv_device_is_pci(device) ? &device->pdev->dev :
-					  &device->platformdev->dev;
+	return nv_device_is_pci(device) ? device->pdev->dev :
+					  device->pdev->dev;
 }
 
 resource_size_t
diff --git a/sys/dev/drm/nouveau/core/include/core/engine.h b/sys/dev/drm/nouveau/core/include/core/engine.h
index 666d06de77..b1d7dd3292 100644
--- a/sys/dev/drm/nouveau/core/include/core/engine.h
+++ b/sys/dev/drm/nouveau/core/include/core/engine.h
@@ -13,7 +13,7 @@ struct nouveau_engine {
 	struct nouveau_oclass *sclass;
 
 	struct list_head contexts;
-	spinlock_t lock;
+	struct spinlock lock;
 
 	void (*tile_prog)(struct nouveau_engine *, int region);
 	int  (*tlb_flush)(struct nouveau_engine *);
diff --git a/sys/dev/drm/nouveau/core/include/core/event.h b/sys/dev/drm/nouveau/core/include/core/event.h
index 51e55d0333..aa5802a3f9 100644
--- a/sys/dev/drm/nouveau/core/include/core/event.h
+++ b/sys/dev/drm/nouveau/core/include/core/event.h
@@ -16,8 +16,8 @@ struct nvkm_event {
 	int types_nr;
 	int index_nr;
 
-	spinlock_t refs_lock;
-	spinlock_t list_lock;
+	struct spinlock refs_lock;
+	struct spinlock list_lock;
 	struct list_head list;
 	int *refs;
 };
diff --git a/sys/dev/drm/nouveau/core/include/core/namedb.h b/sys/dev/drm/nouveau/core/include/core/namedb.h
index f5b5fd8e1f..51b6121db0 100644
--- a/sys/dev/drm/nouveau/core/include/core/namedb.h
+++ b/sys/dev/drm/nouveau/core/include/core/namedb.h
@@ -7,7 +7,7 @@ struct nouveau_handle;
 
 struct nouveau_namedb {
 	struct nouveau_parent base;
-	rwlock_t lock;
+	struct lock lock;
 	struct list_head list;
 };
 
diff --git a/sys/dev/drm/nouveau/core/include/core/object.h b/sys/dev/drm/nouveau/core/include/core/object.h
index d7039482d6..c9dd0448a5 100644
--- a/sys/dev/drm/nouveau/core/include/core/object.h
+++ b/sys/dev/drm/nouveau/core/include/core/object.h
@@ -140,7 +140,7 @@ static inline u8
 nv_ro08(void *obj, u64 addr)
 {
 	u8 data = nv_ofuncs(obj)->rd08(obj, addr);
-	nv_spam(obj, "nv_ro08 0x%08llx 0x%02x\n", addr, data);
+	nv_spam(obj, "nv_ro08 0x%08lx 0x%02x\n", addr, data);
 	return data;
 }
 
@@ -148,7 +148,7 @@ static inline u16
 nv_ro16(void *obj, u64 addr)
 {
 	u16 data = nv_ofuncs(obj)->rd16(obj, addr);
-	nv_spam(obj, "nv_ro16 0x%08llx 0x%04x\n", addr, data);
+	nv_spam(obj, "nv_ro16 0x%08lx 0x%04x\n", addr, data);
 	return data;
 }
 
@@ -156,28 +156,28 @@ static inline u32
 nv_ro32(void *obj, u64 addr)
 {
 	u32 data = nv_ofuncs(obj)->rd32(obj, addr);
-	nv_spam(obj, "nv_ro32 0x%08llx 0x%08x\n", addr, data);
+	nv_spam(obj, "nv_ro32 0x%08lx 0x%08x\n", addr, data);
 	return data;
 }
 
 static inline void
 nv_wo08(void *obj, u64 addr, u8 data)
 {
-	nv_spam(obj, "nv_wo08 0x%08llx 0x%02x\n", addr, data);
+	nv_spam(obj, "nv_wo08 0x%08lx 0x%02x\n", addr, data);
 	nv_ofuncs(obj)->wr08(obj, addr, data);
 }
 
 static inline void
 nv_wo16(void *obj, u64 addr, u16 data)
 {
-	nv_spam(obj, "nv_wo16 0x%08llx 0x%04x\n", addr, data);
+	nv_spam(obj, "nv_wo16 0x%08lx 0x%04x\n", addr, data);
 	nv_ofuncs(obj)->wr16(obj, addr, data);
 }
 
 static inline void
 nv_wo32(void *obj, u64 addr, u32 data)
 {
-	nv_spam(obj, "nv_wo32 0x%08llx 0x%08x\n", addr, data);
+	nv_spam(obj, "nv_wo32 0x%08lx 0x%08x\n", addr, data);
 	nv_ofuncs(obj)->wr32(obj, addr, data);
 }
 
diff --git a/sys/dev/drm/nouveau/core/include/core/subdev.h b/sys/dev/drm/nouveau/core/include/core/subdev.h
index e9632e9316..16d5d856c2 100644
--- a/sys/dev/drm/nouveau/core/include/core/subdev.h
+++ b/sys/dev/drm/nouveau/core/include/core/subdev.h
@@ -8,7 +8,7 @@
 
 struct nouveau_subdev {
 	struct nouveau_object base;
-	struct mutex mutex;
+	struct lock mutex;
 	const char *name;
 	void __iomem *mmio;
 	u32 debug;
diff --git a/sys/dev/drm/nouveau/core/include/engine/fifo.h b/sys/dev/drm/nouveau/core/include/engine/fifo.h
index e5e4d930b2..7cbbaf2e69 100644
--- a/sys/dev/drm/nouveau/core/include/engine/fifo.h
+++ b/sys/dev/drm/nouveau/core/include/engine/fifo.h
@@ -73,7 +73,7 @@ struct nouveau_fifo {
 	struct nvkm_event uevent; /* async user trigger */
 
 	struct nouveau_object **channel;
-	spinlock_t lock;
+	struct spinlock lock;
 	u16 min;
 	u16 max;
 
diff --git a/sys/dev/drm/nouveau/core/include/subdev/i2c.h b/sys/dev/drm/nouveau/core/include/subdev/i2c.h
index 1b937c2c25..9a6ee28d59 100644
--- a/sys/dev/drm/nouveau/core/include/subdev/i2c.h
+++ b/sys/dev/drm/nouveau/core/include/subdev/i2c.h
@@ -31,7 +31,7 @@ struct nvkm_i2c_ntfy_rep {
 struct nouveau_i2c_port {
 	struct nouveau_object base;
 	struct i2c_adapter adapter;
-	struct mutex mutex;
+	struct lock mutex;
 
 	struct list_head head;
 	u8  index;
@@ -95,12 +95,12 @@ nv_rdi2cr(struct nouveau_i2c_port *port, u8 addr, u8 reg)
 {
 	u8 val;
 	struct i2c_msg msgs[] = {
-		{ .addr = addr, .flags = 0, .len = 1, .buf = &reg },
-		{ .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = &val },
+		{ .slave = addr << 1, .flags = 0, .len = 1, .buf = &reg },
+		{ .slave = addr << 1, .flags = I2C_M_RD, .len = 1, .buf = &val },
 	};
 
-	int ret = i2c_transfer(&port->adapter, msgs, 2);
-	if (ret != 2)
+	int ret = iicbus_transfer(&port->adapter, msgs, 2);
+	if (ret != 0)
 		return -EIO;
 
 	return val;
@@ -111,11 +111,11 @@ nv_wri2cr(struct nouveau_i2c_port *port, u8 addr, u8 reg, u8 val)
 {
 	u8 buf[2] = { reg, val };
 	struct i2c_msg msgs[] = {
-		{ .addr = addr, .flags = 0, .len = 2, .buf = buf },
+		{ .slave = addr << 1, .flags = 0, .len = 2, .buf = buf },
 	};
 
-	int ret = i2c_transfer(&port->adapter, msgs, 1);
-	if (ret != 1)
+	int ret = iicbus_transfer(&port->adapter, msgs, 1);
+	if (ret != 0)
 		return -EIO;
 
 	return 0;
diff --git a/sys/dev/drm/nouveau/core/os.h b/sys/dev/drm/nouveau/core/os.h
index ccfa21d72d..0cb9630990 100644
--- a/sys/dev/drm/nouveau/core/os.h
+++ b/sys/dev/drm/nouveau/core/os.h
@@ -1,6 +1,11 @@
 #ifndef __NOUVEAU_OS_H__
 #define __NOUVEAU_OS_H__
 
+#ifdef __DragonFly__
+#include <drm/drmP.h>
+#define CONFIG_NOUVEAU_DEBUG 0
+#define CONFIG_NOUVEAU_DEBUG_DEFAULT 0
+#endif
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/mutex.h>
@@ -14,7 +19,7 @@
 #include <linux/i2c-algo-bit.h>
 #include <linux/delay.h>
 #include <linux/io-mapping.h>
-#include <linux/acpi.h>
+#include <contrib/dev/acpica/source/include/acpi.h>
 #include <linux/vmalloc.h>
 #include <linux/dmi.h>
 #include <linux/reboot.h>
@@ -22,7 +27,9 @@
 #include <linux/log2.h>
 #include <linux/pm_runtime.h>
 #include <linux/power_supply.h>
+#ifndef __DragonFly__
 #include <linux/clk.h>
+#endif
 
 #include <asm/unaligned.h>
 
diff --git a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c
index 8bcbdf39cf..92c2578a11 100644
--- a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c
+++ b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_base.c
@@ -54,7 +54,7 @@ nouveau_barobj_ctor(struct nouveau_object *parent,
 	if (ret)
 		return ret;
 
-	barobj->iomem = bar->iomem + (u32)barobj->vma.offset;
+	barobj->iomem = (char *)bar->iomem + (u32)barobj->vma.offset;
 	return 0;
 }
 
diff --git a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_gk20a.c b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_gk20a.c
index bf877af9d3..8a9a175672 100644
--- a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_gk20a.c
+++ b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_gk20a.c
@@ -24,7 +24,7 @@
 
 #include "priv.h"
 
-int
+static int
 gk20a_bar_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
 	       struct nouveau_oclass *oclass, void *data, u32 size,
 	       struct nouveau_object **pobject)
diff --git a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nv50.c b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nv50.c
index f748ba49df..e5e00da93e 100644
--- a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nv50.c
+++ b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nv50.c
@@ -32,7 +32,7 @@
 
 struct nv50_bar_priv {
 	struct nouveau_bar base;
-	spinlock_t lock;
+	struct spinlock lock;
 	struct nouveau_gpuobj *mem;
 	struct nouveau_gpuobj *pad;
 	struct nouveau_gpuobj *pgd;
diff --git a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nvc0.c b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nvc0.c
index 05a278bab2..c324e5cc8d 100644
--- a/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nvc0.c
+++ b/sys/dev/drm/nouveau/core/subdev/bar/nouveau_subdev_bar_nvc0.c
@@ -38,7 +38,7 @@ struct nvc0_bar_priv_vm {
 
 struct nvc0_bar_priv {
 	struct nouveau_bar base;
-	spinlock_t lock;
+	struct spinlock lock;
 	struct nvc0_bar_priv_vm bar[2];
 };
 
diff --git a/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_base.c b/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_base.c
index d45704a2c2..a8faaa7db9 100644
--- a/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_base.c
+++ b/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_base.c
@@ -74,7 +74,7 @@ nouveau_bios_shadow_of(struct nouveau_bios *bios)
 	data = of_get_property(dn, "NVDA,BMP", &size);
 	if (data && size) {
 		bios->size = size;
-		bios->data = kmalloc(bios->size, GFP_KERNEL);
+		bios->data = kmalloc(bios->size, M_DRM, GFP_KERNEL);
 		if (bios->data)
 			memcpy(bios->data, data, size);
 	}
@@ -127,7 +127,7 @@ nouveau_bios_shadow_pramin(struct nouveau_bios *bios)
 	if (!bios->size)
 		goto out;
 
-	bios->data = kmalloc(bios->size, GFP_KERNEL);
+	bios->data = kmalloc(bios->size, M_DRM, GFP_KERNEL);
 	if (bios->data) {
 		for (i = 0; i < bios->size; i++)
 			nv_wo08(bios, i, nv_rd08(bios, 0x700000 + i));
@@ -182,7 +182,7 @@ nouveau_bios_shadow_prom(struct nouveau_bios *bios)
 	if (!bios->size)
 		goto out;
 
-	bios->data = kmalloc(bios->size, GFP_KERNEL);
+	bios->data = kmalloc(bios->size, M_DRM, GFP_KERNEL);
 	if (!bios->data)
 		goto out;
 
@@ -231,7 +231,7 @@ nouveau_bios_shadow_acpi(struct nouveau_bios *bios)
 	}
 
 	bios->size = 0;
-	bios->data = kmalloc(4096, GFP_KERNEL);
+	bios->data = kmalloc(4096, M_DRM, GFP_KERNEL);
 	if (bios->data) {
 		if (nouveau_acpi_get_bios_chunk(bios->data, 0, 4096) == 4096)
 			bios->size = bios->data[2] * 512;
@@ -241,7 +241,7 @@ nouveau_bios_shadow_acpi(struct nouveau_bios *bios)
 	if (!bios->size)
 		return;
 
-	bios->data = kmalloc(bios->size, GFP_KERNEL);
+	bios->data = kmalloc(bios->size, M_DRM, GFP_KERNEL);
 	if (bios->data) {
 		/* disobey the acpi spec - much faster on at least w530 ... */
 		ret = nouveau_acpi_get_bios_chunk(bios->data, 0, bios->size);
@@ -267,7 +267,7 @@ nouveau_bios_shadow_pci(struct nouveau_bios *bios)
 	if (!pci_enable_rom(pdev)) {
 		void __iomem *rom = pci_map_rom(pdev, &size);
 		if (rom && size) {
-			bios->data = kmalloc(size, GFP_KERNEL);
+			bios->data = kmalloc(size, M_DRM, GFP_KERNEL);
 			if (bios->data) {
 				memcpy_fromio(bios->data, rom, size);
 				bios->size = size;
@@ -288,7 +288,7 @@ nouveau_bios_shadow_platform(struct nouveau_bios *bios)
 
 	void __iomem *rom = pci_platform_rom(pdev, &size);
 	if (rom && size) {
-		bios->data = kmalloc(size, GFP_KERNEL);
+		bios->data = kmalloc(size, M_DRM, GFP_KERNEL);
 		if (bios->data) {
 			memcpy_fromio(bios->data, rom, size);
 			bios->size = size;
@@ -364,10 +364,10 @@ nouveau_bios_shadow(struct nouveau_bios *bios)
 		} while ((++mthd)->shadow);
 
 		/* attempt to load firmware image */
-		ret = request_firmware(&fw, source, &nv_device(bios)->pdev->dev);
+		ret = request_firmware(&fw, source, nv_device(bios)->pdev->dev);
 		if (ret == 0) {
-			bios->size = fw->size;
-			bios->data = kmemdup(fw->data, fw->size, GFP_KERNEL);
+			bios->size = fw->datasize;
+			bios->data = kmemdup(fw->data, fw->datasize, GFP_KERNEL);
 			release_firmware(fw);
 
 			nv_info(bios, "image: %s\n", source);
diff --git a/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_init.c b/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_init.c
index 626380f9e4..d92525a260 100644
--- a/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_init.c
+++ b/sys/dev/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_init.c
@@ -1002,11 +1002,11 @@ init_zm_i2c(struct nvbios_init *init)
 	if (init_exec(init)) {
 		struct nouveau_i2c_port *port = init_i2c(init, index);
 		struct i2c_msg msg = {
-			.addr = addr, .flags = 0, .len = count, .buf = data,
+			.slave = addr << 1, .flags = 0, .len = count, .buf = data,
 		};
 		int ret;
 
-		if (port && (ret = i2c_transfer(&port->adapter, &msg, 1)) != 1)
+		if (port && (ret = iicbus_transfer(&port->adapter, &msg, 1)) != 0)
 			warn("i2c wr failed, %d\n", ret);
 	}
 }
@@ -2001,13 +2001,13 @@ init_i2c_long_if(struct nvbios_init *init)
 		u8 i[2] = { reghi, reglo };
 		u8 o[1] = {};
 		struct i2c_msg msg[] = {
-			{ .addr = addr, .flags = 0, .len = 2, .buf = i },
-			{ .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = o }
+			{ .slave = addr << 1, .flags = 0, .len = 2, .buf = i },
+			{ .slave = addr << 1, .flags = I2C_M_RD, .len = 1, .buf = o }
 		};
 		int ret;
 
-		ret = i2c_transfer(&port->adapter, msg, 2);
-		if (ret == 2 && ((o[0] & mask) == data))
+		ret = iicbus_transfer(&port->adapter, msg, 2);
+		if (ret == 0 && ((o[0] & mask) == data))
 			return;
 	}
 
diff --git a/sys/dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_hwsq.c b/sys/dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_hwsq.c
index f757470e22..6ef18a42ba 100644
--- a/sys/dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_hwsq.c
+++ b/sys/dev/drm/nouveau/core/subdev/bus/nouveau_subdev_bus_hwsq.c
@@ -47,7 +47,7 @@ nouveau_hwsq_init(struct nouveau_bus *pbus, struct nouveau_hwsq **phwsq)
 {
 	struct nouveau_hwsq *hwsq;
 
-	hwsq = *phwsq = kmalloc(sizeof(*hwsq), GFP_KERNEL);
+	hwsq = *phwsq = kmalloc(sizeof(*hwsq), M_DRM, GFP_KERNEL);
 	if (hwsq) {
 		hwsq->pbus = pbus;
 		hwsq->addr = ~0;
diff --git a/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_base.c b/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_base.c
index a276a71129..c49c5e1622 100644
--- a/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_base.c
+++ b/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_base.c
@@ -258,7 +258,7 @@ nouveau_pstate_info(struct nouveau_clock *clk, struct nouveau_pstate *pstate)
 	int i = -1;
 
 	if (pstate->pstate != 0xff)
-		snprintf(name, sizeof(name), "%02x", pstate->pstate);
+		ksnprintf(name, sizeof(name), "%02x", pstate->pstate);
 
 	while ((++clock)->name != nv_clk_src_max) {
 		u32 lo = pstate->base.domain[clock->name];
@@ -278,10 +278,10 @@ nouveau_pstate_info(struct nouveau_clock *clk, struct nouveau_pstate *pstate)
 			lo /= clock->mdiv;
 			hi /= clock->mdiv;
 			if (lo == hi) {
-				snprintf(info[i], sizeof(info[i]), "%s %d MHz",
+				ksnprintf(info[i], sizeof(info[i]), "%s %d MHz",
 					 clock->mname, lo);
 			} else {
-				snprintf(info[i], sizeof(info[i]),
+				ksnprintf(info[i], sizeof(info[i]),
 					 "%s %d-%d MHz", clock->mname, lo, hi);
 			}
 		}
@@ -405,13 +405,13 @@ nouveau_clock_nstate(struct nouveau_clock *clk, const char *mode, int arglen)
 		char save = mode[arglen];
 		long v;
 
-		((char *)mode)[arglen] = '\0';
+		(__DECONST(char *, mode))[arglen] = '\0';
 		if (!kstrtol(mode, 0, &v)) {
 			ret = nouveau_clock_ustate_update(clk, v);
 			if (ret < 0)
 				ret = 1;
 		}
-		((char *)mode)[arglen] = save;
+		(__DECONST(char *, mode))[arglen] = save;
 	}
 
 	return ret - 2;
diff --git a/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv50.c b/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv50.c
index 5070ebc260..61d7577373 100644
--- a/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv50.c
+++ b/sys/dev/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv50.c
@@ -54,7 +54,7 @@ read_pll_src(struct nv50_clock_priv *priv, u32 base)
 	struct nouveau_clock *clk = &priv->base;
 	u32 coef, ref = clk->read(clk, nv_clk_src_crystal);
 	u32 rsel = nv_rd32(priv, 0x00e18c);
-	int P, N, M, id;
+	int P, N, M, id = 0;
 
 	switch (nv_device(priv)->chipset) {
 	case 0x50:
diff --git a/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_nv50.c b/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_nv50.c
index 4150b0d10a..3fa911c46f 100644
--- a/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_nv50.c
+++ b/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_nv50.c
@@ -132,7 +132,7 @@ static const struct nouveau_enum vm_engine[] = {
 	{}
 };
 
-static const struct nouveau_enum vm_fault[] = {
+static const struct nouveau_enum _vm_fault[] = {
 	{ 0x00000000, "PT_NOT_PRESENT", NULL },
 	{ 0x00000001, "PT_TOO_SHORT", NULL },
 	{ 0x00000002, "PAGE_NOT_PRESENT", NULL },
@@ -227,7 +227,7 @@ nv50_fb_intr(struct nouveau_subdev *subdev)
 		pr_cont("%02x", st3);
 
 	pr_cont(" reason: ");
-	en = nouveau_enum_find(vm_fault, st1);
+	en = nouveau_enum_find(_vm_fault, st1);
 	if (en)
 		pr_cont("%s\n", en->name);
 	else
diff --git a/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramgk20a.c b/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramgk20a.c
index 4d77d75e46..6bc4865d60 100644
--- a/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramgk20a.c
+++ b/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramgk20a.c
@@ -59,7 +59,7 @@ gk20a_ram_get(struct nouveau_fb *pfb, u64 size, u32 align, u32 ncmin,
 	u32 npages, order;
 	int i;
 
-	nv_debug(pfb, "%s: size: %llx align: %x, ncmin: %x\n", __func__, size,
+	nv_debug(pfb, "%s: size: %lx align: %x, ncmin: %x\n", __func__, size,
 		 align, ncmin);
 
 	npages = size >> PAGE_SHIFT;
diff --git a/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramnv1a.c b/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramnv1a.c
index d0caddfb9d..8ad42a5022 100644
--- a/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramnv1a.c
+++ b/sys/dev/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_ramnv1a.c
@@ -31,12 +31,12 @@ nv1a_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,
 {
 	struct nouveau_fb *pfb = nouveau_fb(parent);
 	struct nouveau_ram *ram;
-	struct pci_dev *bridge;
+	struct pci_dev bridge;
 	u32 mem, mib;
 	int ret;
 
-	bridge = pci_get_bus_and_slot(0, PCI_DEVFN(0, 1));
-	if (!bridge) {
+	bridge.dev = pci_find_dbsf(0, 0, 0, 0);
+	if (!bridge.dev) {
 		nv_fatal(pfb, "no bridge device\n");
 		return -ENODEV;
 	}
@@ -47,10 +47,10 @@ nv1a_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,
 		return ret;
 
 	if (nv_device(pfb)->chipset == 0x1a) {
-		pci_read_config_dword(bridge, 0x7c, &mem);
+		pci_read_config_dword(&bridge, 0x7c, &mem);
 		mib = ((mem >> 6) & 31) + 1;
 	} else {
-		pci_read_config_dword(bridge, 0x84, &mem);
+		pci_read_config_dword(&bridge, 0x84, &mem);
 		mib = ((mem >> 4) & 127) + 1;
 	}
 
diff --git a/sys/dev/drm/nouveau/core/subdev/gpio/nouveau_subdev_gpio_nve0.c b/sys/dev/drm/nouveau/core/subdev/gpio/nouveau_subdev_gpio_nve0.c
index e1145b48c7..06842c473a 100644
--- a/sys/dev/drm/nouveau/core/subdev/gpio/nouveau_subdev_gpio_nve0.c
+++ b/sys/dev/drm/nouveau/core/subdev/gpio/nouveau_subdev_gpio_nve0.c
@@ -37,7 +37,7 @@ nve0_gpio_intr_stat(struct nouveau_gpio *gpio, u32 *hi, u32 *lo)
 	nv_wr32(gpio, 0x00dc80, intr1);
 }
 
-void
+static void
 nve0_gpio_intr_mask(struct nouveau_gpio *gpio, u32 type, u32 mask, u32 data)
 {
 	u32 inte0 = nv_rd32(gpio, 0x00dc08);
diff --git a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_anx9805.c b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_anx9805.c
index 2c2731a6cf..cdbadc0a39 100644
--- a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_anx9805.c
+++ b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_anx9805.c
@@ -184,8 +184,8 @@ anx9805_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	mdelay(5);
 
 	while (cnt--) {
-		if ( (msg->flags & I2C_M_RD) && msg->addr == 0x50) {
-			nv_wri2cr(mast, port->addr, 0x40, msg->addr << 1);
+		if ( (msg->flags & I2C_M_RD) && msg->slave == 0x50) {
+			nv_wri2cr(mast, port->addr, 0x40, msg->slave << 1);
 			nv_wri2cr(mast, port->addr, 0x41, seg);
 			nv_wri2cr(mast, port->addr, 0x42, off);
 			nv_wri2cr(mast, port->addr, 0x44, msg->len);
@@ -202,10 +202,10 @@ anx9805_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 			}
 		} else
 		if (!(msg->flags & I2C_M_RD)) {
-			if (msg->addr == 0x50 && msg->len == 0x01) {
+			if (msg->slave == 0x50 && msg->len == 0x01) {
 				off = msg->buf[0];
 			} else
-			if (msg->addr == 0x30 && msg->len == 0x01) {
+			if (msg->slave == 0x30 && msg->len == 0x01) {
 				seg = msg->buf[0];
 			} else
 				goto done;
diff --git a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_aux.c b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_aux.c
index 02eb42be2e..3347ae5401 100644
--- a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_aux.c
+++ b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_aux.c
@@ -85,7 +85,7 @@ aux_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 			if (mcnt || remaining > 16)
 				cmd |= 4; /* MOT */
 
-			ret = port->func->aux(port, true, cmd, msg->addr, ptr, cnt);
+			ret = port->func->aux(port, true, cmd, msg->slave, ptr, cnt);
 			if (ret < 0) {
 				i2c->release(port);
 				return ret;
diff --git a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_base.c b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_base.c
index a652cafde3..1718ef3761 100644
--- a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_base.c
+++ b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_base.c
@@ -126,7 +126,7 @@ nouveau_i2c_port_create_(struct nouveau_object *parent,
 	if (ret)
 		return ret;
 
-	snprintf(port->adapter.name, sizeof(port->adapter.name),
+	ksnprintf(port->adapter.name, sizeof(port->adapter.name),
 		 "nouveau-%s-%d", device->name, index);
 	port->adapter.owner = THIS_MODULE;
 	port->adapter.dev.parent = nv_device_base(device);
diff --git a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_nv94.c b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_nv94.c
index f59c3a2554..936279eb07 100644
--- a/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_nv94.c
+++ b/sys/dev/drm/nouveau/core/subdev/i2c/nouveau_subdev_i2c_nv94.c
@@ -98,7 +98,7 @@ auxch_init(struct nouveau_i2c *aux, int ch)
 	return 0;
 }
 
-int
+static int
 nv94_aux(struct nouveau_i2c_port *base, bool retry,
 	 u8 type, u32 addr, u8 *data, u8 size)
 {
diff --git a/sys/dev/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv50.c b/sys/dev/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv50.c
index 7cb3b098a0..1821d54040 100644
--- a/sys/dev/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv50.c
+++ b/sys/dev/drm/nouveau/core/subdev/instmem/nouveau_subdev_instmem_nv50.c
@@ -29,7 +29,7 @@
 
 struct nv50_instmem_priv {
 	struct nouveau_instmem base;
-	spinlock_t lock;
+	struct spinlock lock;
 	u64 addr;
 };
 
diff --git a/sys/dev/drm/nouveau/core/subdev/mc/nouveau_subdev_mc_base.c b/sys/dev/drm/nouveau/core/subdev/mc/nouveau_subdev_mc_base.c
index ca7cee3a31..1a40edce0c 100644
--- a/sys/dev/drm/nouveau/core/subdev/mc/nouveau_subdev_mc_base.c
+++ b/sys/dev/drm/nouveau/core/subdev/mc/nouveau_subdev_mc_base.c
@@ -74,7 +74,9 @@ nouveau_mc_intr(int irq, void *arg)
 	}
 
 	nv_wr32(pmc, 0x000140, 0x00000001);
-	return intr ? IRQ_HANDLED : IRQ_NONE;
+	if (intr)
+		return IRQ_HANDLED;
+	return IRQ_NONE;
 }
 
 int
diff --git a/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_base.c b/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_base.c
index 51fcf79604..0289d30c2c 100644
--- a/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_base.c
+++ b/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_base.c
@@ -36,11 +36,11 @@ mxm_shadow_rom_fetch(struct nouveau_i2c_port *i2c, u8 addr,
 		     u8 offset, u8 size, u8 *data)
 {
 	struct i2c_msg msgs[] = {
-		{ .addr = addr, .flags = 0, .len = 1, .buf = &offset },
-		{ .addr = addr, .flags = I2C_M_RD, .len = size, .buf = data, },
+		{ .slave = addr << 1, .flags = 0, .len = 1, .buf = &offset },
+		{ .slave = addr << 1, .flags = I2C_M_RD, .len = size, .buf = data, },
 	};
 
-	return i2c_transfer(&i2c->adapter, msgs, 2) == 2;
+	return iicbus_transfer(&i2c->adapter, msgs, 2) == 0;
 }
 
 static bool
@@ -66,7 +66,7 @@ mxm_shadow_rom(struct nouveau_mxm *mxm, u8 version)
 
 	mxm->mxms = mxms;
 	size = mxms_headerlen(mxm) + mxms_structlen(mxm);
-	mxm->mxms = kmalloc(size, GFP_KERNEL);
+	mxm->mxms = kmalloc(size, M_DRM, GFP_KERNEL);
 
 	if (mxm->mxms &&
 	    mxm_shadow_rom_fetch(port, addr, 0, size, mxm->mxms))
diff --git a/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_nv50.c b/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_nv50.c
index fcaabe8456..bf2519e78a 100644
--- a/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_nv50.c
+++ b/sys/dev/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_nv50.c
@@ -184,7 +184,7 @@ mxm_show_unmatched(struct nouveau_mxm *mxm, u8 *data, void *info)
 {
 	u64 desc = *(u64 *)data;
 	if ((desc & 0xf0) != 0xf0)
-	nv_info(mxm, "unmatched output device 0x%016llx\n", desc);
+	nv_info(mxm, "unmatched output device 0x%016lx\n", desc);
 	return true;
 }
 
diff --git a/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_fantog.c b/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_fantog.c
index f69dab11f7..32c6c53151 100644
--- a/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_fantog.c
+++ b/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_fantog.c
@@ -33,7 +33,7 @@
 struct nouveau_fantog_priv {
 	struct nouveau_fan base;
 	struct nouveau_alarm alarm;
-	spinlock_t lock;
+	struct spinlock lock;
 	u32 period_us;
 	u32 percent;
 	struct dcb_gpio_func func;
diff --git a/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_temp.c b/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_temp.c
index 6212537b90..b9036e1ea5 100644
--- a/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_temp.c
+++ b/sys/dev/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_temp.c
@@ -129,7 +129,7 @@ void nouveau_therm_sensor_event(struct nouveau_therm *therm,
 		if (active) {
 			struct work_struct *work;
 
-			work = kmalloc(sizeof(*work), GFP_ATOMIC);
+			work = kmalloc(sizeof(*work), M_DRM, GFP_ATOMIC);
 			if (work) {
 				INIT_WORK(work, nv_poweroff_work);
 				schedule_work(work);
diff --git a/sys/dev/drm/nouveau/core/subdev/therm/priv.h b/sys/dev/drm/nouveau/core/subdev/therm/priv.h
index 916fca5c78..ceffd7fc26 100644
--- a/sys/dev/drm/nouveau/core/subdev/therm/priv.h
+++ b/sys/dev/drm/nouveau/core/subdev/therm/priv.h
@@ -41,7 +41,7 @@ struct nouveau_fan {
 	struct nvbios_perf_fan perf;
 
 	struct nouveau_alarm alarm;
-	spinlock_t lock;
+	struct spinlock lock;
 	int percent;
 
 	int (*get)(struct nouveau_therm *therm);
@@ -73,7 +73,7 @@ struct nouveau_therm_priv {
 
 	/* automatic thermal management */
 	struct nouveau_alarm alarm;
-	spinlock_t lock;
+	struct spinlock lock;
 	struct nouveau_therm_trip_point *last_trip;
 	int mode;
 	int cstate;
@@ -87,7 +87,7 @@ struct nouveau_therm_priv {
 
 	/* alarms priv */
 	struct {
-		spinlock_t alarm_program_lock;
+		struct spinlock alarm_program_lock;
 		struct nouveau_alarm therm_poll_alarm;
 		enum nouveau_therm_thrs_state alarm_state[NOUVEAU_THERM_THRS_NR];
 		void (*program_alarms)(struct nouveau_therm *);
diff --git a/sys/dev/drm/nouveau/core/subdev/timer/nouveau_subdev_timer_nv04.c b/sys/dev/drm/nouveau/core/subdev/timer/nouveau_subdev_timer_nv04.c
index 240ed0b983..86b6bd0086 100644
--- a/sys/dev/drm/nouveau/core/subdev/timer/nouveau_subdev_timer_nv04.c
+++ b/sys/dev/drm/nouveau/core/subdev/timer/nouveau_subdev_timer_nv04.c
@@ -44,7 +44,7 @@ nv04_timer_alarm_trigger(struct nouveau_timer *ptimer)
 	struct nv04_timer_priv *priv = (void *)ptimer;
 	struct nouveau_alarm *alarm, *atemp;
 	unsigned long flags;
-	LIST_HEAD(exec);
+	LINUX_LIST_HEAD(exec);
 
 	/* move any due alarms off the pending list */
 	spin_lock_irqsave(&priv->lock, flags);
diff --git a/sys/dev/drm/nouveau/core/subdev/timer/nv04.h b/sys/dev/drm/nouveau/core/subdev/timer/nv04.h
index 4bc152697c..03a7c3962e 100644
--- a/sys/dev/drm/nouveau/core/subdev/timer/nv04.h
+++ b/sys/dev/drm/nouveau/core/subdev/timer/nv04.h
@@ -14,7 +14,7 @@
 struct nv04_timer_priv {
 	struct nouveau_timer base;
 	struct list_head alarms;
-	spinlock_t lock;
+	struct spinlock lock;
 	u64 suspend_time;
 };
 
diff --git a/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv41.c b/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv41.c
index 064c762628..18578b4131 100644
--- a/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv41.c
+++ b/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv41.c
@@ -92,7 +92,7 @@ nv41_vmmgr_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
 	struct nv04_vmmgr_priv *priv;
 	int ret;
 
-	if (pci_find_capability(device->pdev, PCI_CAP_ID_AGP) ||
+	if (pci_find_extcap(device->pdev->dev, PCIY_AGP, NULL) == 0 ||
 	    !nouveau_boolopt(device->cfgopt, "NvPCIE", true)) {
 		return nouveau_object_ctor(parent, engine, &nv04_vmmgr_oclass,
 					   data, size, pobject);
diff --git a/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv44.c b/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv44.c
index fae1f67d59..1238d3cc6c 100644
--- a/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv44.c
+++ b/sys/dev/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv44.c
@@ -163,7 +163,7 @@ nv44_vmmgr_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
 	struct nv04_vmmgr_priv *priv;
 	int ret;
 
-	if (pci_find_capability(device->pdev, PCI_CAP_ID_AGP) ||
+	if (pci_find_extcap(device->pdev->dev, PCIY_AGP, NULL) == 0 ||
 	    !nouveau_boolopt(device->cfgopt, "NvPCIE", true)) {
 		return nouveau_object_ctor(parent, engine, &nv04_vmmgr_oclass,
 					   data, size, pobject);
diff --git a/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_cursor.c b/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_cursor.c
index 4e61173c33..59429e0453 100644
--- a/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_cursor.c
+++ b/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_cursor.c
@@ -1,5 +1,9 @@
 #include <drm/drmP.h>
+#ifdef __DragonFly__
+#include <uapi_drm/drm_mode.h>
+#else
 #include <drm/drm_mode.h>
+#endif
 #include "nouveau_drm.h"
 #include "nouveau_reg.h"
 #include "nouveau_crtc.h"
diff --git a/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_hw.c b/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_hw.c
index 3d4c193007..561192636b 100644
--- a/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_hw.c
+++ b/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_hw.c
@@ -362,7 +362,7 @@ nouveau_hw_save_vga_fonts(struct drm_device *dev, bool save)
 		NVBlankScreen(dev, 1, false);
 	NVBlankScreen(dev, 0, false);
 
-	iounmap(iovram);
+	iounmap(iovram, 65536);
 }
 
 /*
diff --git a/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_overlay.c b/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_overlay.c
index b36afcbbc8..0cb6434d6f 100644
--- a/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_overlay.c
+++ b/sys/dev/drm/nouveau/dispnv04/nouveau_dispnv04_overlay.c
@@ -25,7 +25,11 @@
 
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
+#ifdef __DragonFly__
+#include <uapi_drm/drm_fourcc.h>
+#else
 #include <drm/drm_fourcc.h>
+#endif
 
 #include "nouveau_drm.h"
 
diff --git a/sys/dev/drm/nouveau/nouveau_abi16.c b/sys/dev/drm/nouveau/nouveau_abi16.c
index 615714c172..34732482d5 100644
--- a/sys/dev/drm/nouveau/nouveau_abi16.c
+++ b/sys/dev/drm/nouveau/nouveau_abi16.c
@@ -188,10 +188,10 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
 		if (!nv_device_is_pci(nvkm_device(device)))
 			getparam->value = 3;
 		else
-		if (drm_pci_device_is_agp(dev))
+		if (drm_device_is_agp(dev))
 			getparam->value = 0;
 		else
-		if (!pci_is_pcie(dev->pdev))
+		if (!drm_device_is_pcie(dev))
 			getparam->value = 1;
 		else
 			getparam->value = 2;
@@ -218,7 +218,7 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
 		getparam->value = graph->units ? graph->units(graph) : 0;
 		break;
 	default:
-		NV_PRINTK(debug, cli, "unknown parameter %lld\n", getparam->param);
+		NV_PRINTK(debug, cli, "unknown parameter %lu\n", getparam->param);
 		return -EINVAL;
 	}
 
diff --git a/sys/dev/drm/nouveau/nouveau_acpi.c b/sys/dev/drm/nouveau/nouveau_acpi.c
index 622424692b..7f15040e50 100644
--- a/sys/dev/drm/nouveau/nouveau_acpi.c
+++ b/sys/dev/drm/nouveau/nouveau_acpi.c
@@ -1,5 +1,5 @@
 #include <linux/pci.h>
-#include <linux/acpi.h>
+#include <contrib/dev/acpica/source/include/acpi.h>
 #include <linux/slab.h>
 #include <linux/mxm-wmi.h>
 #include <linux/vga_switcheroo.h>
diff --git a/sys/dev/drm/nouveau/nouveau_agp.c b/sys/dev/drm/nouveau/nouveau_agp.c
index 1f6f6ba684..542ce74fde 100644
--- a/sys/dev/drm/nouveau/nouveau_agp.c
+++ b/sys/dev/drm/nouveau/nouveau_agp.c
@@ -73,7 +73,7 @@ nouveau_agp_enabled(struct nouveau_drm *drm)
 {
 	struct drm_device *dev = drm->dev;
 
-	if (!dev->pdev || !drm_pci_device_is_agp(dev) || !dev->agp)
+	if (!dev->pdev || !drm_device_is_agp(dev) || !dev->agp)
 		return false;
 
 	if (drm->agp.stat == UNKNOWN) {
diff --git a/sys/dev/drm/nouveau/nouveau_bios.h b/sys/dev/drm/nouveau/nouveau_bios.h
index 0067586eb0..d982e38fe3 100644
--- a/sys/dev/drm/nouveau/nouveau_bios.h
+++ b/sys/dev/drm/nouveau/nouveau_bios.h
@@ -92,7 +92,7 @@ struct nvbios {
 	uint8_t digital_min_front_porch;
 	bool fp_no_ddc;
 
-	spinlock_t lock;
+	struct spinlock lock;
 
 	bool execute;
 
diff --git a/sys/dev/drm/nouveau/nouveau_bo.c b/sys/dev/drm/nouveau/nouveau_bo.c
index 01da508625..6f1d5d3834 100644
--- a/sys/dev/drm/nouveau/nouveau_bo.c
+++ b/sys/dev/drm/nouveau/nouveau_bo.c
@@ -27,6 +27,7 @@
  *	    Jeremy Kolb  <jkolb@brandeis.edu>
  */
 
+#include <drm/drmP.h>
 #include <linux/dma-mapping.h>
 #include <linux/swiotlb.h>
 
@@ -1197,9 +1198,9 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr,
 	}
 
 	/* Fallback to software copy. */
-	spin_lock(&bo->bdev->fence_lock);
+	lockmgr(&bo->bdev->fence_lock, LK_EXCLUSIVE);
 	ret = ttm_bo_wait(bo, true, intr, no_wait_gpu);
-	spin_unlock(&bo->bdev->fence_lock);
+	lockmgr(&bo->bdev->fence_lock, LK_RELEASE);
 	if (ret == 0)
 		ret = ttm_bo_move_memcpy(bo, evict, no_wait_gpu, new_mem);
 
@@ -1441,10 +1442,10 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)
 	struct nouveau_fence *new_fence = nouveau_fence_ref(fence);
 	struct nouveau_fence *old_fence = NULL;
 
-	spin_lock(&nvbo->bo.bdev->fence_lock);
+	lockmgr(&nvbo->bo.bdev->fence_lock, LK_EXCLUSIVE);
 	old_fence = nvbo->bo.sync_obj;
 	nvbo->bo.sync_obj = new_fence;
-	spin_unlock(&nvbo->bo.bdev->fence_lock);
+	lockmgr(&nvbo->bo.bdev->fence_lock, LK_RELEASE);
 
 	nouveau_fence_unref(&old_fence);
 }
diff --git a/sys/dev/drm/nouveau/nouveau_bo.h b/sys/dev/drm/nouveau/nouveau_bo.h
index ff17c1f432..00035c7188 100644
--- a/sys/dev/drm/nouveau/nouveau_bo.h
+++ b/sys/dev/drm/nouveau/nouveau_bo.h
@@ -1,6 +1,8 @@
 #ifndef __NOUVEAU_BO_H__
 #define __NOUVEAU_BO_H__
 
+#include <drm/drm_gem.h>
+
 struct nouveau_channel;
 struct nouveau_fence;
 struct nouveau_vma;
diff --git a/sys/dev/drm/nouveau/nouveau_display.c b/sys/dev/drm/nouveau/nouveau_display.c
index 4a21b2b06c..cbfd9ca222 100644
--- a/sys/dev/drm/nouveau/nouveau_display.c
+++ b/sys/dev/drm/nouveau/nouveau_display.c
@@ -91,7 +91,7 @@ calc(int blanks, int blanke, int total, int line)
 	return line;
 }
 
-int
+static int
 nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos,
 				ktime_t *stime, ktime_t *etime)
 {
@@ -648,13 +648,12 @@ nouveau_page_flip_emit(struct nouveau_channel *chan,
 	struct nouveau_fence_chan *fctx = chan->fence;
 	struct nouveau_drm *drm = chan->drm;
 	struct drm_device *dev = drm->dev;
-	unsigned long flags;
 	int ret;
 
 	/* Queue it to the pending list */
-	spin_lock_irqsave(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_EXCLUSIVE);
 	list_add_tail(&s->head, &fctx->flip);
-	spin_unlock_irqrestore(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_RELEASE);
 
 	/* Synchronize with the old framebuffer */
 	ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan);
@@ -679,9 +678,9 @@ nouveau_page_flip_emit(struct nouveau_channel *chan,
 
 	return 0;
 fail:
-	spin_lock_irqsave(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_EXCLUSIVE);
 	list_del(&s->head);
-	spin_unlock_irqrestore(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_RELEASE);
 	return ret;
 }
 
@@ -718,9 +717,9 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
 	mutex_lock(&cli->mutex);
 
 	/* synchronise rendering channel with the kernel's channel */
-	spin_lock(&new_bo->bo.bdev->fence_lock);
+	lockmgr(&new_bo->bo.bdev->fence_lock, LK_EXCLUSIVE);
 	fence = nouveau_fence_ref(new_bo->bo.sync_obj);
-	spin_unlock(&new_bo->bo.bdev->fence_lock);
+	lockmgr(&new_bo->bo.bdev->fence_lock, LK_RELEASE);
 	ret = nouveau_fence_sync(fence, chan);
 	nouveau_fence_unref(&fence);
 	if (ret)
@@ -801,14 +800,13 @@ nouveau_finish_page_flip(struct nouveau_channel *chan,
 	struct nouveau_drm *drm = chan->drm;
 	struct drm_device *dev = drm->dev;
 	struct nouveau_page_flip_state *s;
-	unsigned long flags;
 	int crtcid = -1;
 
-	spin_lock_irqsave(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_EXCLUSIVE);
 
 	if (list_empty(&fctx->flip)) {
 		NV_ERROR(drm, "unexpected pageflip\n");
-		spin_unlock_irqrestore(&dev->event_lock, flags);
+		lockmgr(&dev->event_lock, LK_RELEASE);
 		return -EINVAL;
 	}
 
@@ -829,7 +827,7 @@ nouveau_finish_page_flip(struct nouveau_channel *chan,
 		*ps = *s;
 	kfree(s);
 
-	spin_unlock_irqrestore(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_RELEASE);
 	return 0;
 }
 
diff --git a/sys/dev/drm/nouveau/nouveau_drm.c b/sys/dev/drm/nouveau/nouveau_drm.c
index 3ed32dd903..cee1c47c82 100644
--- a/sys/dev/drm/nouveau/nouveau_drm.c
+++ b/sys/dev/drm/nouveau/nouveau_drm.c
@@ -278,6 +278,7 @@ nouveau_accel_init(struct nouveau_drm *drm)
 	nouveau_bo_move_init(drm);
 }
 
+#ifndef __DragonFly__
 static int nouveau_drm_probe(struct pci_dev *pdev,
 			     const struct pci_device_id *pent)
 {
@@ -330,6 +331,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 
 	return 0;
 }
+#endif
 
 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
 
@@ -386,7 +388,7 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags)
 	/* make sure AGP controller is in a consistent state before we
 	 * (possibly) execute vbios init tables (see nouveau_agp.h)
 	 */
-	if (pdev && drm_pci_device_is_agp(dev) && dev->agp) {
+	if (pdev && drm_device_is_agp(dev) && dev->agp) {
 		const u64 enables = NV_DEVICE_V0_DISABLE_IDENTIFY |
 				    NV_DEVICE_V0_DISABLE_MMIO;
 		/* dummy device object, doesn't init anything, but allows
@@ -532,6 +534,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
 }
 EXPORT_SYMBOL(nouveau_drm_device_remove);
 
+#ifndef __DragonFly__
 static void
 nouveau_drm_remove(struct pci_dev *pdev)
 {
@@ -539,6 +542,7 @@ nouveau_drm_remove(struct pci_dev *pdev)
 
 	nouveau_drm_device_remove(dev);
 }
+#endif
 
 static int
 nouveau_do_suspend(struct drm_device *dev, bool runtime)
@@ -624,7 +628,7 @@ int nouveau_pmops_suspend(struct device *dev)
 	if (ret)
 		return ret;
 
-	pci_save_state(pdev);
+	pci_save_state(pdev->dev);
 	pci_disable_device(pdev);
 	pci_ignore_hotplug(pdev);
 	pci_set_power_state(pdev, PCI_D3hot);
@@ -676,7 +680,7 @@ int nouveau_pmops_resume(struct device *dev)
 		return 0;
 
 	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
+	pci_restore_state(pdev->dev);
 	ret = pci_enable_device(pdev);
 	if (ret)
 		return ret;
@@ -685,6 +689,7 @@ int nouveau_pmops_resume(struct device *dev)
 	return nouveau_do_resume(drm_dev, false);
 }
 
+#ifndef __DragonFly__
 static int nouveau_pmops_freeze(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -698,6 +703,7 @@ static int nouveau_pmops_thaw(struct device *dev)
 	struct drm_device *drm_dev = pci_get_drvdata(pdev);
 	return nouveau_do_resume(drm_dev, false);
 }
+#endif
 
 
 static int
@@ -714,7 +720,7 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
 		return ret;
 
 	get_task_comm(tmpname, current);
-	snprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid));
+	ksnprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid));
 
 	ret = nouveau_cli_create(nouveau_name(dev), name, sizeof(*cli),
 			(void **)&cli);
@@ -815,6 +821,7 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	return ret;
 }
 
+#ifndef __DragonFly__
 static const struct file_operations
 nouveau_driver_fops = {
 	.owner = THIS_MODULE,
@@ -829,6 +836,7 @@ nouveau_driver_fops = {
 #endif
 	.llseek = noop_llseek,
 };
+#endif
 
 static struct drm_driver
 driver = {
@@ -856,6 +864,7 @@ driver = {
 
 	.ioctls = nouveau_ioctls,
 	.num_ioctls = ARRAY_SIZE(nouveau_ioctls),
+#ifndef __DragonFly__
 	.fops = &nouveau_driver_fops,
 
 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
@@ -869,6 +878,7 @@ driver = {
 	.gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table,
 	.gem_prime_vmap = nouveau_gem_prime_vmap,
 	.gem_prime_vunmap = nouveau_gem_prime_vunmap,
+#endif
 
 	.gem_free_object = nouveau_gem_object_del,
 	.gem_open_object = nouveau_gem_object_open,
@@ -890,6 +900,7 @@ driver = {
 	.patchlevel = DRIVER_PATCHLEVEL,
 };
 
+#ifndef __DragonFly__
 static struct pci_device_id
 nouveau_drm_pci_table[] = {
 	{
@@ -928,7 +939,7 @@ static int nouveau_pmops_runtime_suspend(struct device *dev)
 	vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_OFF);
 	nouveau_switcheroo_optimus_dsm();
 	ret = nouveau_do_suspend(drm_dev, true);
-	pci_save_state(pdev);
+	pci_save_state(pdev->dev);
 	pci_disable_device(pdev);
 	pci_set_power_state(pdev, PCI_D3cold);
 	drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
@@ -946,7 +957,7 @@ static int nouveau_pmops_runtime_resume(struct device *dev)
 		return -EINVAL;
 
 	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
+	pci_restore_state(pdev->dev);
 	ret = pci_enable_device(pdev);
 	if (ret)
 		return ret;
@@ -1022,6 +1033,7 @@ nouveau_drm_pci_driver = {
 	.remove = nouveau_drm_remove,
 	.driver.pm = &nouveau_pm_ops,
 };
+#endif
 
 struct drm_device *
 nouveau_platform_device_create_(struct platform_device *pdev, int size,
@@ -1059,6 +1071,7 @@ err_free:
 }
 EXPORT_SYMBOL(nouveau_platform_device_create_);
 
+#ifndef __DragonFly__
 static int __init
 nouveau_drm_init(void)
 {
@@ -1090,6 +1103,6 @@ module_init(nouveau_drm_init);
 module_exit(nouveau_drm_exit);
 
 MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table);
+#endif
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/sys/dev/drm/nouveau/nouveau_drm.h b/sys/dev/drm/nouveau/nouveau_drm.h
index b02b02452c..1f968177cb 100644
--- a/sys/dev/drm/nouveau/nouveau_drm.h
+++ b/sys/dev/drm/nouveau/nouveau_drm.h
@@ -40,7 +40,11 @@
 #include <drm/ttm/ttm_module.h>
 #include <drm/ttm/ttm_page_alloc.h>
 
+#ifdef __DragonFly__
+#include <uapi_drm/nouveau_drm.h>
+#else
 #include "uapi/drm/nouveau_drm.h"
+#endif
 
 struct nouveau_channel;
 struct platform_device;
@@ -80,7 +84,7 @@ struct nouveau_cli {
 	struct nvif_client base;
 	struct nouveau_vm *vm; /*XXX*/
 	struct list_head head;
-	struct mutex mutex;
+	struct lock mutex;
 	void *abi16;
 	struct list_head objects;
 	struct list_head notifys;
@@ -148,7 +152,7 @@ struct nouveau_drm {
 	/* nv10-nv40 tiling regions */
 	struct {
 		struct nouveau_drm_tile reg[15];
-		spinlock_t lock;
+		struct spinlock lock;
 	} tile;
 
 	/* modesetting */
@@ -163,7 +167,9 @@ struct nouveau_drm {
 	/* display power reference */
 	bool have_disp_power_ref;
 
+#if 0	/* PM_TODO */
 	struct dev_pm_domain vga_pm_domain;
+#endif
 	struct pci_dev *hdmi_device;
 };
 
diff --git a/sys/dev/drm/nouveau/nouveau_fbcon.c b/sys/dev/drm/nouveau/nouveau_fbcon.c
index 49fe6075cc..2b4ffca22f 100644
--- a/sys/dev/drm/nouveau/nouveau_fbcon.c
+++ b/sys/dev/drm/nouveau/nouveau_fbcon.c
@@ -24,6 +24,7 @@
  *     David Airlie
  */
 
+#include <drm/drmP.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -38,7 +39,6 @@
 #include <linux/vga_switcheroo.h>
 #include <linux/console.h>
 
-#include <drm/drmP.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_fb_helper.h>
diff --git a/sys/dev/drm/nouveau/nouveau_fence.c b/sys/dev/drm/nouveau/nouveau_fence.c
index 0a93114158..f2127adcd0 100644
--- a/sys/dev/drm/nouveau/nouveau_fence.c
+++ b/sys/dev/drm/nouveau/nouveau_fence.c
@@ -98,7 +98,7 @@ nouveau_fence_work(struct nouveau_fence *fence,
 	}
 
 	fctx = chan->fence;
-	work = kmalloc(sizeof(*work), GFP_KERNEL);
+	work = kmalloc(sizeof(*work), M_DRM, GFP_KERNEL);
 	if (!work) {
 		WARN_ON(nouveau_fence_wait(fence, false, false));
 		func(data);
@@ -270,7 +270,7 @@ nouveau_fence_wait(struct nouveau_fence *fence, bool lazy, bool intr)
 				sleep_time = NSEC_PER_MSEC;
 		}
 
-		if (intr && signal_pending(current)) {
+		if (intr && signal_pending(curthread->td_lwp)) {
 			ret = -ERESTARTSYS;
 			break;
 		}
diff --git a/sys/dev/drm/nouveau/nouveau_fence.h b/sys/dev/drm/nouveau/nouveau_fence.h
index c57bb61da5..12675188cc 100644
--- a/sys/dev/drm/nouveau/nouveau_fence.h
+++ b/sys/dev/drm/nouveau/nouveau_fence.h
@@ -38,7 +38,7 @@ struct nouveau_fence_chan {
 	int  (*emit32)(struct nouveau_channel *, u64, u32);
 	int  (*sync32)(struct nouveau_channel *, u64, u32);
 
-	spinlock_t lock;
+	struct spinlock lock;
 	u32 sequence;
 };
 
diff --git a/sys/dev/drm/nouveau/nouveau_gem.c b/sys/dev/drm/nouveau/nouveau_gem.c
index 292a677bfe..86e86f87a5 100644
--- a/sys/dev/drm/nouveau/nouveau_gem.c
+++ b/sys/dev/drm/nouveau/nouveau_gem.c
@@ -103,9 +103,9 @@ nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma)
 	list_del(&vma->head);
 
 	if (mapped) {
-		spin_lock(&nvbo->bo.bdev->fence_lock);
+		lockmgr(&nvbo->bo.bdev->fence_lock, LK_EXCLUSIVE);
 		fence = nouveau_fence_ref(nvbo->bo.sync_obj);
-		spin_unlock(&nvbo->bo.bdev->fence_lock);
+		lockmgr(&nvbo->bo.bdev->fence_lock, LK_RELEASE);
 	}
 
 	if (fence) {
@@ -433,9 +433,9 @@ validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo)
 	struct nouveau_fence *fence = NULL;
 	int ret = 0;
 
-	spin_lock(&nvbo->bo.bdev->fence_lock);
+	lockmgr(&nvbo->bo.bdev->fence_lock, LK_EXCLUSIVE);
 	fence = nouveau_fence_ref(nvbo->bo.sync_obj);
-	spin_unlock(&nvbo->bo.bdev->fence_lock);
+	lockmgr(&nvbo->bo.bdev->fence_lock, LK_RELEASE);
 
 	if (fence) {
 		ret = nouveau_fence_sync(fence, chan);
@@ -577,7 +577,7 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 
 	size *= nmemb;
 
-	mem = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
+	mem = kmalloc(size, M_DRM, GFP_KERNEL | __GFP_NOWARN);
 	if (!mem)
 		mem = vmalloc(size);
 	if (!mem)
@@ -659,9 +659,9 @@ nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
 				data |= r->vor;
 		}
 
-		spin_lock(&nvbo->bo.bdev->fence_lock);
+		lockmgr(&nvbo->bo.bdev->fence_lock, LK_EXCLUSIVE);
 		ret = ttm_bo_wait(&nvbo->bo, false, false, false);
-		spin_unlock(&nvbo->bo.bdev->fence_lock);
+		lockmgr(&nvbo->bo.bdev->fence_lock, LK_RELEASE);
 		if (ret) {
 			NV_PRINTK(error, cli, "reloc wait_idle failed: %d\n", ret);
 			break;
@@ -891,9 +891,9 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
 		return -ENOENT;
 	nvbo = nouveau_gem_object(gem);
 
-	spin_lock(&nvbo->bo.bdev->fence_lock);
+	lockmgr(&nvbo->bo.bdev->fence_lock, LK_EXCLUSIVE);
 	ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
-	spin_unlock(&nvbo->bo.bdev->fence_lock);
+	lockmgr(&nvbo->bo.bdev->fence_lock, LK_RELEASE);
 	drm_gem_object_unreference_unlocked(gem);
 	return ret;
 }
diff --git a/sys/dev/drm/nouveau/nouveau_hwmon.c b/sys/dev/drm/nouveau/nouveau_hwmon.c
index afb36d66e7..b870a07565 100644
--- a/sys/dev/drm/nouveau/nouveau_hwmon.c
+++ b/sys/dev/drm/nouveau/nouveau_hwmon.c
@@ -23,7 +23,7 @@
  */
 
 #ifdef CONFIG_ACPI
-#include <linux/acpi.h>
+#include <contrib/dev/acpica/source/include/acpi.h>
 #endif
 #include <linux/power_supply.h>
 #include <linux/hwmon.h>
@@ -46,7 +46,7 @@ nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
 	if (temp < 0)
 		return temp;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000);
+	return ksnprintf(buf, PAGE_SIZE, "%d\n", temp * 1000);
 }
 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
 						  NULL, 0);
@@ -55,7 +55,7 @@ static ssize_t
 nouveau_hwmon_show_temp1_auto_point1_pwm(struct device *d,
 					 struct device_attribute *a, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%d\n", 100);
+	return ksnprintf(buf, PAGE_SIZE, "%d\n", 100);
 }
 static SENSOR_DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO,
 			  nouveau_hwmon_show_temp1_auto_point1_pwm, NULL, 0);
@@ -68,7 +68,7 @@ nouveau_hwmon_temp1_auto_point1_temp(struct device *d,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	      therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST) * 1000);
 }
 static ssize_t
@@ -101,7 +101,7 @@ nouveau_hwmon_temp1_auto_point1_temp_hyst(struct device *d,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	 therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_FAN_BOOST_HYST) * 1000);
 }
 static ssize_t
@@ -133,7 +133,7 @@ nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf)
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	       therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK) * 1000);
 }
 static ssize_t
@@ -164,7 +164,7 @@ nouveau_hwmon_max_temp_hyst(struct device *d, struct device_attribute *a,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	  therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK_HYST) * 1000);
 }
 static ssize_t
@@ -196,7 +196,7 @@ nouveau_hwmon_critical_temp(struct device *d, struct device_attribute *a,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	       therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_CRITICAL) * 1000);
 }
 static ssize_t
@@ -229,7 +229,7 @@ nouveau_hwmon_critical_temp_hyst(struct device *d, struct device_attribute *a,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	  therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_CRITICAL_HYST) * 1000);
 }
 static ssize_t
@@ -262,7 +262,7 @@ nouveau_hwmon_emergency_temp(struct device *d, struct device_attribute *a,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	       therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_SHUTDOWN) * 1000);
 }
 static ssize_t
@@ -295,7 +295,7 @@ nouveau_hwmon_emergency_temp_hyst(struct device *d, struct device_attribute *a,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
+	return ksnprintf(buf, PAGE_SIZE, "%d\n",
 	  therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_SHUTDOWN_HYST) * 1000);
 }
 static ssize_t
@@ -326,7 +326,7 @@ static ssize_t nouveau_hwmon_show_name(struct device *dev,
 				      struct device_attribute *attr,
 				      char *buf)
 {
-	return sprintf(buf, "nouveau\n");
+	return ksprintf(buf, "nouveau\n");
 }
 static SENSOR_DEVICE_ATTR(name, S_IRUGO, nouveau_hwmon_show_name, NULL, 0);
 
@@ -334,7 +334,7 @@ static ssize_t nouveau_hwmon_show_update_rate(struct device *dev,
 				      struct device_attribute *attr,
 				      char *buf)
 {
-	return sprintf(buf, "1000\n");
+	return ksprintf(buf, "1000\n");
 }
 static SENSOR_DEVICE_ATTR(update_rate, S_IRUGO,
 						nouveau_hwmon_show_update_rate,
@@ -348,7 +348,7 @@ nouveau_hwmon_show_fan1_input(struct device *d, struct device_attribute *attr,
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_therm *therm = nvkm_therm(&drm->device);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", therm->fan_sense(therm));
+	return ksnprintf(buf, PAGE_SIZE, "%d\n", therm->fan_sense(therm));
 }
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, nouveau_hwmon_show_fan1_input,
 			  NULL, 0);
@@ -366,7 +366,7 @@ nouveau_hwmon_get_pwm1_enable(struct device *d,
 	if (ret < 0)
 		return ret;
 
-	return sprintf(buf, "%i\n", ret);
+	return ksprintf(buf, "%i\n", ret);
 }
 
 static ssize_t
@@ -405,7 +405,7 @@ nouveau_hwmon_get_pwm1(struct device *d, struct device_attribute *a, char *buf)
 	if (ret < 0)
 		return ret;
 
-	return sprintf(buf, "%i\n", ret);
+	return ksprintf(buf, "%i\n", ret);
 }
 
 static ssize_t
@@ -445,7 +445,7 @@ nouveau_hwmon_get_pwm1_min(struct device *d,
 	if (ret < 0)
 		return ret;
 
-	return sprintf(buf, "%i\n", ret);
+	return ksprintf(buf, "%i\n", ret);
 }
 
 static ssize_t
@@ -485,7 +485,7 @@ nouveau_hwmon_get_pwm1_max(struct device *d,
 	if (ret < 0)
 		return ret;
 
-	return sprintf(buf, "%i\n", ret);
+	return ksprintf(buf, "%i\n", ret);
 }
 
 static ssize_t
diff --git a/sys/dev/drm/nouveau/nouveau_nv10_fence.c b/sys/dev/drm/nouveau/nouveau_nv10_fence.c
index 4faaf0acf5..90455745b1 100644
--- a/sys/dev/drm/nouveau/nouveau_nv10_fence.c
+++ b/sys/dev/drm/nouveau/nouveau_nv10_fence.c
@@ -66,7 +66,7 @@ nv10_fence_context_del(struct nouveau_channel *chan)
 	kfree(fctx);
 }
 
-int
+static int
 nv10_fence_context_new(struct nouveau_channel *chan)
 {
 	struct nv10_fence_chan *fctx;
diff --git a/sys/dev/drm/nouveau/nouveau_nv50_display.c b/sys/dev/drm/nouveau/nouveau_nv50_display.c
index 03949eaa62..6ca6ac0248 100644
--- a/sys/dev/drm/nouveau/nouveau_nv50_display.c
+++ b/sys/dev/drm/nouveau/nouveau_nv50_display.c
@@ -22,9 +22,9 @@
  * Authors: Ben Skeggs
  */
 
+#include <drm/drmP.h>
 #include <linux/dma-mapping.h>
 
-#include <drm/drmP.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_dp_helper.h>
 
@@ -173,7 +173,7 @@ struct nv50_dmac {
 	/* Protects against concurrent pushbuf access to this channel, lock is
 	 * grabbed by evo_wait (if the pushbuf reservation is successful) and
 	 * dropped again by evo_kick. */
-	struct mutex lock;
+	struct lock lock;
 };
 
 static void
@@ -1189,13 +1189,13 @@ nv50_crtc_lut_load(struct drm_crtc *crtc)
 		u16 b = nv_crtc->lut.b[i] >> 2;
 
 		if (disp->disp->oclass < GF110_DISP) {
-			writew(r + 0x0000, lut + (i * 0x08) + 0);
-			writew(g + 0x0000, lut + (i * 0x08) + 2);
-			writew(b + 0x0000, lut + (i * 0x08) + 4);
+			writew(r + 0x0000, (char *)lut + (i * 0x08) + 0);
+			writew(g + 0x0000, (char *)lut + (i * 0x08) + 2);
+			writew(b + 0x0000, (char *)lut + (i * 0x08) + 4);
 		} else {
-			writew(r + 0x6000, lut + (i * 0x20) + 0);
-			writew(g + 0x6000, lut + (i * 0x20) + 2);
-			writew(b + 0x6000, lut + (i * 0x20) + 4);
+			writew(r + 0x6000, (char *)lut + (i * 0x20) + 0);
+			writew(g + 0x6000, (char *)lut + (i * 0x20) + 2);
+			writew(b + 0x6000, (char *)lut + (i * 0x20) + 4);
 		}
 	}
 }
diff --git a/sys/dev/drm/nouveau/nouveau_nvif.c b/sys/dev/drm/nouveau/nouveau_nvif.c
index 47ca886237..f20bb7a2a4 100644
--- a/sys/dev/drm/nouveau/nouveau_nvif.c
+++ b/sys/dev/drm/nouveau/nouveau_nvif.c
@@ -42,7 +42,7 @@
 static void
 nvkm_client_unmap(void *priv, void *ptr, u32 size)
 {
-	iounmap(ptr);
+	iounmap(ptr, size);
 }
 
 static void *
diff --git a/sys/dev/drm/nouveau/nouveau_platform.c b/sys/dev/drm/nouveau/nouveau_platform.c
index 246a824c16..779d31c1c8 100644
--- a/sys/dev/drm/nouveau/nouveau_platform.c
+++ b/sys/dev/drm/nouveau/nouveau_platform.c
@@ -20,7 +20,9 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#ifndef __DragonFly__
 #include <linux/clk.h>
+#endif
 #include <linux/io.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -180,4 +182,3 @@ module_platform_driver(nouveau_platform_driver);
 
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/sys/dev/drm/nouveau/nouveau_prime.c b/sys/dev/drm/nouveau/nouveau_prime.c
index 1f51008e4d..5cf819e79e 100644
--- a/sys/dev/drm/nouveau/nouveau_prime.c
+++ b/sys/dev/drm/nouveau/nouveau_prime.c
@@ -27,6 +27,7 @@
 #include "nouveau_drm.h"
 #include "nouveau_gem.h"
 
+#ifndef __DragonFly__
 struct sg_table *nouveau_gem_prime_get_sg_table(struct drm_gem_object *obj)
 {
 	struct nouveau_bo *nvbo = nouveau_gem_object(obj);
@@ -109,3 +110,4 @@ struct reservation_object *nouveau_gem_prime_res_obj(struct drm_gem_object *obj)
 
 	return nvbo->bo.resv;
 }
+#endif
diff --git a/sys/dev/drm/nouveau/nouveau_sgdma.c b/sys/dev/drm/nouveau/nouveau_sgdma.c
index 01707e7dea..830b9d6b1f 100644
--- a/sys/dev/drm/nouveau/nouveau_sgdma.c
+++ b/sys/dev/drm/nouveau/nouveau_sgdma.c
@@ -1,3 +1,4 @@
+#include <drm/drmP.h>
 #include <linux/pagemap.h>
 #include <linux/slab.h>
 
diff --git a/sys/dev/drm/nouveau/nouveau_sysfs.c b/sys/dev/drm/nouveau/nouveau_sysfs.c
index 3c6962d15b..ebd93d616c 100644
--- a/sys/dev/drm/nouveau/nouveau_sysfs.c
+++ b/sys/dev/drm/nouveau/nouveau_sysfs.c
@@ -39,7 +39,7 @@ drm_device(struct device *d)
 }
 
 #define snappendf(p,r,f,a...) do {                                             \
-	snprintf(p, r, f, ##a);                                                \
+	ksnprintf(p, r, f, ##a);                                               \
 	r -= strlen(p);                                                        \
 	p += strlen(p);                                                        \
 } while(0)
diff --git a/sys/dev/drm/nouveau/nouveau_ttm.c b/sys/dev/drm/nouveau/nouveau_ttm.c
index 53874b76b0..06498d9dde 100644
--- a/sys/dev/drm/nouveau/nouveau_ttm.c
+++ b/sys/dev/drm/nouveau/nouveau_ttm.c
@@ -110,7 +110,7 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
 
 	mutex_lock(&nv_subdev(pfb)->mutex);
 	list_for_each_entry(r, &mm->nodes, nl_entry) {
-		printk(KERN_DEBUG "%s %d: 0x%010llx 0x%010llx\n",
+		printk(KERN_DEBUG "%s %d: 0x%010lx 0x%010lx\n",
 		       prefix, r->type, ((u64)r->offset << 12),
 		       (((u64)r->offset + r->length) << 12));
 
@@ -120,7 +120,7 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
 	}
 	mutex_unlock(&nv_subdev(pfb)->mutex);
 
-	printk(KERN_DEBUG "%s  total: 0x%010llx free: 0x%010llx\n",
+	printk(KERN_DEBUG "%s  total: 0x%010lx free: 0x%010lx\n",
 	       prefix, (u64)total << 12, (u64)free << 12);
 	printk(KERN_DEBUG "%s  block: 0x%08x\n",
 	       prefix, mm->block_size << 12);
diff --git a/sys/dev/drm/nouveau/nouveau_usif.c b/sys/dev/drm/nouveau/nouveau_usif.c
index cb1182d7e8..d56b587e0e 100644
--- a/sys/dev/drm/nouveau/nouveau_usif.c
+++ b/sys/dev/drm/nouveau/nouveau_usif.c
@@ -106,13 +106,13 @@ usif_notify(const void *header, u32 length, const void *data, u32 size)
 		break;
 	}
 
-	spin_lock_irqsave(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_EXCLUSIVE);
 	if (!WARN_ON(filp->event_space < ntfy->p->e.base.length)) {
 		list_add_tail(&ntfy->p->base.link, &filp->event_list);
 		filp->event_space -= ntfy->p->e.base.length;
 	}
 	wake_up_interruptible(&filp->event_wait);
-	spin_unlock_irqrestore(&dev->event_lock, flags);
+	lockmgr(&dev->event_lock, LK_RELEASE);
 	atomic_set(&ntfy->enabled, 0);
 	return NVIF_NOTIFY_DROP;
 }
@@ -138,7 +138,7 @@ usif_notify_new(struct drm_file *f, void *data, u32 size, void *argv, u32 argc)
 		return ret;
 	req = data;
 
-	if (!(ntfy = kmalloc(sizeof(*ntfy), GFP_KERNEL)))
+	if (!(ntfy = kmalloc(sizeof(*ntfy), M_DRM, GFP_KERNEL)))
 		return -ENOMEM;
 	atomic_set(&ntfy->enabled, 0);
 
@@ -204,7 +204,7 @@ usif_notify_get(struct drm_file *f, void *data, u32 size, void *argv, u32 argc)
 	if (atomic_xchg(&ntfy->enabled, 1))
 		return 0;
 
-	ntfy->p = kmalloc(sizeof(*ntfy->p) + ntfy->reply, GFP_KERNEL);
+	ntfy->p = kmalloc(sizeof(*ntfy->p) + ntfy->reply, M_DRM, GFP_KERNEL);
 	if (ret = -ENOMEM, !ntfy->p)
 		goto done;
 	ntfy->p->base.event = &ntfy->p->e.base;
@@ -271,7 +271,7 @@ usif_object_new(struct drm_file *f, void *data, u32 size, void *argv, u32 argc)
 	struct usif_object *object;
 	int ret;
 
-	if (!(object = kmalloc(sizeof(*object), GFP_KERNEL)))
+	if (!(object = kmalloc(sizeof(*object), M_DRM, GFP_KERNEL)))
 		return -ENOMEM;
 	list_add(&object->head, &cli->objects);
 
@@ -295,7 +295,7 @@ usif_ioctl(struct drm_file *filp, void __user *user, u32 argc)
 {
 	struct nouveau_cli *cli = nouveau_cli(filp);
 	struct nvif_client *client = &cli->base;
-	void *data = kmalloc(argc, GFP_KERNEL);
+	void *data = kmalloc(argc, M_DRM, GFP_KERNEL);
 	u32   size = argc;
 	union {
 		struct nvif_ioctl_v0 v0;
diff --git a/sys/dev/drm/nouveau/nv10_fence.h b/sys/dev/drm/nouveau/nv10_fence.h
index a87259f398..453ff86bb5 100644
--- a/sys/dev/drm/nouveau/nv10_fence.h
+++ b/sys/dev/drm/nouveau/nv10_fence.h
@@ -13,7 +13,7 @@ struct nv10_fence_chan {
 struct nv10_fence_priv {
 	struct nouveau_fence_priv base;
 	struct nouveau_bo *bo;
-	spinlock_t lock;
+	struct spinlock lock;
 	u32 sequence;
 };
 
diff --git a/sys/dev/drm/nouveau/nvif/list.h b/sys/dev/drm/nouveau/nvif/list.h
deleted file mode 100644
index 8af5d144ec..0000000000
--- a/sys/dev/drm/nouveau/nvif/list.h
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Copyright © 2010 Intel Corporation
- * Copyright © 2010 Francisco Jerez <currojerez@riseup.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- */
-
-/* Modified by Ben Skeggs <bskeggs@redhat.com> to match kernel list APIs */
-
-#ifndef _XORG_LIST_H_
-#define _XORG_LIST_H_
-
-/**
- * @file Classic doubly-link circular list implementation.
- * For real usage examples of the linked list, see the file test/list.c
- *
- * Example:
- * We need to keep a list of struct foo in the parent struct bar, i.e. what
- * we want is something like this.
- *
- *     struct bar {
- *          ...
- *          struct foo *list_of_foos; -----> struct foo {}, struct foo {}, struct foo{}
- *          ...
- *     }
- *
- * We need one list head in bar and a list element in all list_of_foos (both are of
- * data type 'struct list_head').
- *
- *     struct bar {
- *          ...
- *          struct list_head list_of_foos;
- *          ...
- *     }
- *
- *     struct foo {
- *          ...
- *          struct list_head entry;
- *          ...
- *     }
- *
- * Now we initialize the list head:
- *
- *     struct bar bar;
- *     ...
- *     INIT_LIST_HEAD(&bar.list_of_foos);
- *
- * Then we create the first element and add it to this list:
- *
- *     struct foo *foo = malloc(...);
- *     ....
- *     list_add(&foo->entry, &bar.list_of_foos);
- *
- * Repeat the above for each element you want to add to the list. Deleting
- * works with the element itself.
- *      list_del(&foo->entry);
- *      free(foo);
- *
- * Note: calling list_del(&bar.list_of_foos) will set bar.list_of_foos to an empty
- * list again.
- *
- * Looping through the list requires a 'struct foo' as iterator and the
- * name of the field the subnodes use.
- *
- * struct foo *iterator;
- * list_for_each_entry(iterator, &bar.list_of_foos, entry) {
- *      if (iterator->something == ...)
- *             ...
- * }
- *
- * Note: You must not call list_del() on the iterator if you continue the
- * loop. You need to run the safe for-each loop instead:
- *
- * struct foo *iterator, *next;
- * list_for_each_entry_safe(iterator, next, &bar.list_of_foos, entry) {
- *      if (...)
- *              list_del(&iterator->entry);
- * }
- *
- */
-
-/**
- * The linkage struct for list nodes. This struct must be part of your
- * to-be-linked struct. struct list_head is required for both the head of the
- * list and for each list node.
- *
- * Position and name of the struct list_head field is irrelevant.
- * There are no requirements that elements of a list are of the same type.
- * There are no requirements for a list head, any struct list_head can be a list
- * head.
- */
-struct list_head {
-    struct list_head *next, *prev;
-};
-
-/**
- * Initialize the list as an empty list.
- *
- * Example:
- * INIT_LIST_HEAD(&bar->list_of_foos);
- *
- * @param The list to initialized.
- */
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
-
-#define LIST_HEAD(name) \
-	struct list_head name = LIST_HEAD_INIT(name)
-
-static inline void
-INIT_LIST_HEAD(struct list_head *list)
-{
-    list->next = list->prev = list;
-}
-
-static inline void
-__list_add(struct list_head *entry,
-                struct list_head *prev, struct list_head *next)
-{
-    next->prev = entry;
-    entry->next = next;
-    entry->prev = prev;
-    prev->next = entry;
-}
-
-/**
- * Insert a new element after the given list head. The new element does not
- * need to be initialised as empty list.
- * The list changes from:
- *      head → some element → ...
- * to
- *      head → new element → older element → ...
- *
- * Example:
- * struct foo *newfoo = malloc(...);
- * list_add(&newfoo->entry, &bar->list_of_foos);
- *
- * @param entry The new element to prepend to the list.
- * @param head The existing list.
- */
-static inline void
-list_add(struct list_head *entry, struct list_head *head)
-{
-    __list_add(entry, head, head->next);
-}
-
-/**
- * Append a new element to the end of the list given with this list head.
- *
- * The list changes from:
- *      head → some element → ... → lastelement
- * to
- *      head → some element → ... → lastelement → new element
- *
- * Example:
- * struct foo *newfoo = malloc(...);
- * list_add_tail(&newfoo->entry, &bar->list_of_foos);
- *
- * @param entry The new element to prepend to the list.
- * @param head The existing list.
- */
-static inline void
-list_add_tail(struct list_head *entry, struct list_head *head)
-{
-    __list_add(entry, head->prev, head);
-}
-
-static inline void
-__list_del(struct list_head *prev, struct list_head *next)
-{
-    next->prev = prev;
-    prev->next = next;
-}
-
-/**
- * Remove the element from the list it is in. Using this function will reset
- * the pointers to/from this element so it is removed from the list. It does
- * NOT free the element itself or manipulate it otherwise.
- *
- * Using list_del on a pure list head (like in the example at the top of
- * this file) will NOT remove the first element from
- * the list but rather reset the list as empty list.
- *
- * Example:
- * list_del(&foo->entry);
- *
- * @param entry The element to remove.
- */
-static inline void
-list_del(struct list_head *entry)
-{
-    __list_del(entry->prev, entry->next);
-}
-
-static inline void
-list_del_init(struct list_head *entry)
-{
-    __list_del(entry->prev, entry->next);
-    INIT_LIST_HEAD(entry);
-}
-
-static inline void list_move_tail(struct list_head *list,
-				  struct list_head *head)
-{
-	__list_del(list->prev, list->next);
-	list_add_tail(list, head);
-}
-
-/**
- * Check if the list is empty.
- *
- * Example:
- * list_empty(&bar->list_of_foos);
- *
- * @return True if the list contains one or more elements or False otherwise.
- */
-static inline bool
-list_empty(struct list_head *head)
-{
-    return head->next == head;
-}
-
-/**
- * Returns a pointer to the container of this list element.
- *
- * Example:
- * struct foo* f;
- * f = container_of(&foo->entry, struct foo, entry);
- * assert(f == foo);
- *
- * @param ptr Pointer to the struct list_head.
- * @param type Data type of the list element.
- * @param member Member name of the struct list_head field in the list element.
- * @return A pointer to the data struct containing the list head.
- */
-#ifndef container_of
-#define container_of(ptr, type, member) \
-    (type *)((char *)(ptr) - (char *) &((type *)0)->member)
-#endif
-
-/**
- * Alias of container_of
- */
-#define list_entry(ptr, type, member) \
-    container_of(ptr, type, member)
-
-/**
- * Retrieve the first list entry for the given list pointer.
- *
- * Example:
- * struct foo *first;
- * first = list_first_entry(&bar->list_of_foos, struct foo, list_of_foos);
- *
- * @param ptr The list head
- * @param type Data type of the list element to retrieve
- * @param member Member name of the struct list_head field in the list element.
- * @return A pointer to the first list element.
- */
-#define list_first_entry(ptr, type, member) \
-    list_entry((ptr)->next, type, member)
-
-/**
- * Retrieve the last list entry for the given listpointer.
- *
- * Example:
- * struct foo *first;
- * first = list_last_entry(&bar->list_of_foos, struct foo, list_of_foos);
- *
- * @param ptr The list head
- * @param type Data type of the list element to retrieve
- * @param member Member name of the struct list_head field in the list element.
- * @return A pointer to the last list element.
- */
-#define list_last_entry(ptr, type, member) \
-    list_entry((ptr)->prev, type, member)
-
-#define __container_of(ptr, sample, member)				\
-    (void *)container_of((ptr), typeof(*(sample)), member)
-
-/**
- * Loop through the list given by head and set pos to struct in the list.
- *
- * Example:
- * struct foo *iterator;
- * list_for_each_entry(iterator, &bar->list_of_foos, entry) {
- *      [modify iterator]
- * }
- *
- * This macro is not safe for node deletion. Use list_for_each_entry_safe
- * instead.
- *
- * @param pos Iterator variable of the type of the list elements.
- * @param head List head
- * @param member Member name of the struct list_head in the list elements.
- *
- */
-#define list_for_each_entry(pos, head, member)				\
-    for (pos = __container_of((head)->next, pos, member);		\
-	 &pos->member != (head);					\
-	 pos = __container_of(pos->member.next, pos, member))
-
-/**
- * Loop through the list, keeping a backup pointer to the element. This
- * macro allows for the deletion of a list element while looping through the
- * list.
- *
- * See list_for_each_entry for more details.
- */
-#define list_for_each_entry_safe(pos, tmp, head, member)		\
-    for (pos = __container_of((head)->next, pos, member),		\
-	 tmp = __container_of(pos->member.next, pos, member);		\
-	 &pos->member != (head);					\
-	 pos = tmp, tmp = __container_of(pos->member.next, tmp, member))
-
-
-#define list_for_each_entry_reverse(pos, head, member)			\
-	for (pos = __container_of((head)->prev, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = __container_of(pos->member.prev, pos, member))
-
-#define list_for_each_entry_continue(pos, head, member)			\
-	for (pos = __container_of(pos->member.next, pos, member);	\
-	     &pos->member != (head);					\
-	     pos = __container_of(pos->member.next, pos, member))
-
-#define list_for_each_entry_continue_reverse(pos, head, member)		\
-	for (pos = __container_of(pos->member.prev, pos, member);	\
-	     &pos->member != (head);					\
-	     pos = __container_of(pos->member.prev, pos, member))
-
-#define list_for_each_entry_from(pos, head, member)			\
-	for (;								\
-	     &pos->member != (head);					\
-	     pos = __container_of(pos->member.next, pos, member))
-
-#endif
diff --git a/sys/dev/drm/nouveau/nvif/nouveau_nvif_notify.c b/sys/dev/drm/nouveau/nvif/nouveau_nvif_notify.c
index 0898c31552..3cf875d944 100644
--- a/sys/dev/drm/nouveau/nvif/nouveau_nvif_notify.c
+++ b/sys/dev/drm/nouveau/nvif/nouveau_nvif_notify.c
@@ -128,7 +128,7 @@ nvif_notify(const void *header, u32 length, const void *data, u32 size)
 		if (!WARN_ON(notify->size != size)) {
 			atomic_inc(&notify->putcnt);
 			if (test_bit(NVIF_NOTIFY_WORK, &notify->flags)) {
-				memcpy((void *)notify->data, data, size);
+				memcpy(__DECONST(void *, notify->data), data, size);
 				schedule_work(&notify->work);
 				return NVIF_NOTIFY_DROP;
 			}
@@ -157,7 +157,7 @@ nvif_notify_fini(struct nvif_notify *notify)
 		ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
 		if (ret == 0) {
 			nvif_object_ref(NULL, &notify->object);
-			kfree((void *)notify->data);
+			kfree(__DECONST(void *, notify->data));
 		}
 	}
 	return ret;
@@ -186,12 +186,12 @@ nvif_notify_init(struct nvif_object *object, void (*dtor)(struct nvif_notify *),
 	if (work) {
 		INIT_WORK(&notify->work, nvif_notify_work);
 		set_bit(NVIF_NOTIFY_WORK, &notify->flags);
-		notify->data = kmalloc(notify->size, GFP_KERNEL);
+		notify->data = kmalloc(notify->size, M_DRM, GFP_KERNEL);
 		if (!notify->data)
 			goto done;
 	}
 
-	if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))
+	if (!(args = kmalloc(sizeof(*args) + size, M_DRM, GFP_KERNEL)))
 		goto done;
 	args->ioctl.version = 0;
 	args->ioctl.type = NVIF_IOCTL_V0_NTFY_NEW;
diff --git a/sys/dev/drm/nouveau/nvif/nouveau_nvif_object.c b/sys/dev/drm/nouveau/nvif/nouveau_nvif_object.c
index dd85b56f6a..f2880fb62d 100644
--- a/sys/dev/drm/nouveau/nvif/nouveau_nvif_object.c
+++ b/sys/dev/drm/nouveau/nvif/nouveau_nvif_object.c
@@ -60,7 +60,7 @@ nvif_object_sclass(struct nvif_object *object, u32 *oclass, int count)
 	u32 size = count * sizeof(args->sclass.oclass[0]);
 	int ret;
 
-	if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))
+	if (!(args = kmalloc(sizeof(*args) + size, M_DRM, GFP_KERNEL)))
 		return -ENOMEM;
 	args->ioctl.version = 0;
 	args->ioctl.type = NVIF_IOCTL_V0_SCLASS;
@@ -123,7 +123,7 @@ nvif_object_mthd(struct nvif_object *object, u32 mthd, void *data, u32 size)
 	int ret;
 
 	if (sizeof(*args) + size > sizeof(stack)) {
-		if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))
+		if (!(args = kmalloc(sizeof(*args) + size, M_DRM, GFP_KERNEL)))
 			return -ENOMEM;
 	} else {
 		args = (void *)stack;
@@ -235,7 +235,7 @@ nvif_object_init(struct nvif_object *parent, void (*dtor)(struct nvif_object *),
 	object->map.size = 0;
 
 	if (object->parent) {
-		if (!(ctor = kmalloc(sizeof(*ctor) + size, GFP_KERNEL))) {
+		if (!(ctor = kmalloc(sizeof(*ctor) + size, M_DRM, GFP_KERNEL))) {
 			nvif_object_fini(object);
 			return -ENOMEM;
 		}
diff --git a/sys/libkern/strcspn.c b/sys/libkern/strcspn.c
new file mode 100644
index 0000000000..c90b4c513b
--- /dev/null
+++ b/sys/libkern/strcspn.c
@@ -0,0 +1,72 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/sys/libkern/strcspn.c 181748 2008-08-15 04:07:22Z kmacy $");
+
+#include <sys/libkern.h>
+#include <sys/types.h>
+#include <sys/limits.h>
+
+#define	IDX(c)	((u_char)(c) / LONG_BIT)
+#define	BIT(c)	((u_long)1 << ((u_char)(c) % LONG_BIT))
+
+size_t 
+strcspn(const char * __restrict s, const char * __restrict charset) 
+{
+	/*
+	 * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to
+	 * generate better code.  Without them, gcc gets a little confused.
+	 */
+	const char *s1;
+	u_long bit;
+	u_long tbl[(UCHAR_MAX + 1) / LONG_BIT];
+	int idx;
+
+	if(*s == '\0')
+		return (0);
+
+#if LONG_BIT == 64	/* always better to unroll on 64-bit architectures */
+	tbl[0] = 1;
+	tbl[3] = tbl[2] = tbl[1] = 0;
+#else
+	for (tbl[0] = idx = 1; idx < sizeof(tbl) / sizeof(tbl[0]); idx++)
+		tbl[idx] = 0;
+#endif
+	for (; *charset != '\0'; charset++) {
+		idx = IDX(*charset);
+		bit = BIT(*charset);
+		tbl[idx] |= bit;
+	}
+
+	for(s1 = s; ; s1++) {
+		idx = IDX(*s1);
+		bit = BIT(*s1);
+		if ((tbl[idx] & bit) != 0)
+			break;
+	}
+	return (s1 - s);
+}
diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h
index b06300bf28..e5a2a03be3 100644
--- a/sys/sys/libkern.h
+++ b/sys/sys/libkern.h
@@ -122,6 +122,7 @@ int	 skpc(int, int, char *);
 void	 skrandom(u_long);
 char	*strcat(char * __restrict, const char * __restrict);
 char	*strncat(char * __restrict, const char * __restrict, size_t);
+<<<<<<< HEAD
 int	 strcmp(const char *, const char *);
 int	 strcasecmp(const char *, const char *);
 char	*strcpy(char * __restrict, const char * __restrict);
@@ -131,6 +132,18 @@ size_t	 strlen(const char *);
 int	 strncmp(const char *, const char *, size_t);
 int	 strncasecmp(const char *, const char *, size_t);
 char	*strncpy(char * __restrict, const char * __restrict, size_t);
+=======
+int	 strcmp (const char *, const char *);
+int	 strcasecmp (const char *, const char *);
+char	*strcpy (char * __restrict, const char * __restrict);
+size_t	 strcspn(const char * __restrict, const char * __restrict) __pure;
+size_t   strlcat (char *, const char *, size_t);
+size_t   strlcpy (char *, const char *, size_t);
+size_t	 strlen (const char *);
+int	 strncmp (const char *, const char *, size_t);
+int	 strncasecmp (const char *, const char *, size_t);
+char	*strncpy (char * __restrict, const char * __restrict, size_t);
+>>>>>>> kernel/drm: nouveau changes so far. :)
 size_t	 strnlen(const char *, size_t);
 char	*strsep(char **, const char *);
 char	*strstr(const char *, const char *);
-- 
2.23.0

