diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/Makefile NVIDIA-FreeBSD-x86_64-352.63_df/src/Makefile
--- NVIDIA-FreeBSD-x86_64-352.63/src/Makefile	2015-11-08 05:23:40.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/Makefile	2015-12-05 12:08:38.970927000 +0100
@@ -16,8 +16,8 @@
 include nvidia-sources.mk
 
 SRCS=		${NVIDIA_SOURCES}
-SRCS+=		acpi_if.h bus_if.h device_if.h opt_acpi.h pci_if.h vnode_if.h
-CFLAGS+=	-I. -DNV_VERSION_STRING=\"352.63\"
+SRCS+=		acpi_if.h bus_if.h device_if.h opt_acpi.h pci_if.h
+CFLAGS+=	-I. -DNV_VERSION_STRING=\"352.63\" -I${SYSDIR}/contrib/dev/acpica/source/include
 CFLAGS+=	-D__KERNEL__ -DNVRM  -Wno-unused-function -Wuninitialized -O2  -fno-strict-aliasing -mno-red-zone -mcmodel=kernel -UDEBUG -U_DEBUG -DNDEBUG
 
 OBJS+=		${RMOBJ}
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/cpuopsys.h NVIDIA-FreeBSD-x86_64-352.63_df/src/cpuopsys.h
--- NVIDIA-FreeBSD-x86_64-352.63/src/cpuopsys.h	2015-11-08 05:04:26.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/cpuopsys.h	2015-12-05 12:23:12.883159000 +0100
@@ -62,9 +62,9 @@
 #   define NV_SUNOS
 #endif /* defined(_SUNPRO_C) || defined(__SUNPRO_CC) */
 
-#if defined(__FreeBSD__) && !defined(NV_BSD)
+#if (defined(__FreeBSD__) || defined(__DragonFly__)) && !defined(NV_BSD)
 #   define NV_BSD
-#endif /* defined(__FreeBSD__) */
+#endif /* defined(__FreeBSD__) || defined (__DragonFly__) */
 
 /* XXXar don't define NV_UNIX on MacOSX or vxworks or QNX */
 #if (defined(__unix__) || defined(__unix) ) && !defined(nvmacosx) && !defined(vxworks) && !defined(NV_UNIX) && !defined(__QNX__) && !defined(__QNXNTO__)/* XXX until removed from Makefiles */
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nv-freebsd.h NVIDIA-FreeBSD-x86_64-352.63_df/src/nv-freebsd.h
--- NVIDIA-FreeBSD-x86_64-352.63/src/nv-freebsd.h	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nv-freebsd.h	2015-12-06 14:24:00.755325000 +0100
@@ -21,6 +21,7 @@
 
 #include <sys/param.h>
 
+#ifndef __DragonFly__
 #if __FreeBSD_version >= 1100000
 #error This driver does not support FreeBSD 11.x/-CURRENT!
 #endif
@@ -36,6 +37,7 @@
 #if __FreeBSD_version < 702106
 #error This driver requires FreeBSD 7.3 or later!
 #endif
+#endif
 
 #include <sys/systm.h>
 #include <sys/types.h>
@@ -53,9 +55,7 @@
 #include <sys/sysctl.h>
 
 #include <machine/cpu.h>
-#include <machine/resource.h>
 #include <machine/clock.h>
-#include <machine/bus.h>
 #include <machine/specialreg.h>
 
 #include <sys/conf.h>
@@ -65,7 +65,6 @@
 #include <sys/mman.h>
 #include <sys/file.h>
 #include <sys/poll.h>
-#include <sys/rwlock.h>
 
 #include <sys/syscall.h>
 #include <sys/bus.h>
@@ -82,38 +81,34 @@
 #include <vm/pmap.h>
 #include <vm/vm_map.h>
 #include <vm/vm_pager.h>
-#include <vm/uma.h>
 
-#include <sys/smp.h>
-#include <dev/pci/pcireg.h>
-#include <dev/pci/pcivar.h>
-#include <sys/kdb.h>
+#include <bus/pci/pcireg.h>
+#include <bus/pci/pcivar.h>
 #include <sys/filedesc.h>
 
 #include <sys/priv.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/sx.h>
 #include <sys/condvar.h>
 #include <sys/sglist.h>
 #include <sys/taskqueue.h>
+#include <sys/devfs.h>
 
 #define CURTHREAD curthread
 
-#if __FreeBSD_version >= 800049
+#if __FreeBSD_version >= 800049 || defined(__DragonFly__)
 #define suser(_td) priv_check((_td), PRIV_DRIVER)
 #endif
 
-#if __FreeBSD_version >= 900041
+#if 0 /* __FreeBSD_version >= 900041 */
 #include <sys/capability.h>
-#if __FreeBSD_version < 1000053
+#if 0 /* __FreeBSD_version < 1000053 */
 #define cap_rights_init(rights, cap) (cap)
 #endif
 #else
 #define fget(td, fd, rights, fp) fget(td, fd, fp)
 #endif
 
-#define __NV_ITHREAD() (curthread->td_pflags & TDP_ITHREAD)
+#define __NV_ITHREAD() (curthread->td_flags & TDF_INTTHREAD)
 
 /*
  * The NVIDIA kernel module's malloc identifier, needed for both tracking
@@ -137,7 +132,7 @@
  * from the core driver.
  */
 
-#if __FreeBSD_version >= 900044
+#if __FreeBSD_version >= 900044 || defined(__DragonFly__)
 #define NV_SUPPORT_ACPI
 #else
 #undef NV_SUPPORT_ACPI
@@ -185,8 +180,8 @@
     nv_state_t *nv;
     STAILQ_HEAD(event_queue, nvidia_event) event_queue;
     int event_pending;
-    struct mtx event_mtx;
-    struct selinfo event_rsel;
+    struct lock event_mtx;
+    struct kqinfo event_kq;
 } nvidia_filep_t;
 
 typedef
@@ -237,8 +232,9 @@
 
     uint32_t refcnt;
 
-    struct sx api_sx;
+    struct lock api_sx;
 
+    struct kqinfo kq;
 } nvidia_softc_t;
 
 #define CDEV_CTL_MINOR  255
@@ -286,11 +282,11 @@
 #define __NV_IOC_NR(_cmd)   (((_cmd) >> 0) & 0xff)
 #define __NV_IOC_SIZE(_cmd) (((_cmd) >> 16) & 0x1fff)
 
-extern uma_zone_t nvidia_stack_t_zone;
+MALLOC_DECLARE(M_NVSTACK);
 
 #define NV_UMA_ZONE_ALLOC_STACK(ptr)                             \
     {                                                            \
-        (ptr) = uma_zalloc(nvidia_stack_t_zone, M_WAITOK);       \
+	(ptr) = kmalloc(sizeof(nvidia_stack_t), M_NVSTACK, M_NOWAIT); \
         if ((ptr) != NULL)                                       \
         {                                                        \
             (ptr)->size = sizeof((ptr)->stack);                  \
@@ -300,7 +296,7 @@
 
 #define NV_UMA_ZONE_FREE_STACK(ptr)                              \
     {                                                            \
-        uma_zfree(nvidia_stack_t_zone, (ptr));                   \
+	kfree((ptr), M_NVSTACK);				 \
         (ptr) = NULL;                                            \
     }
 
@@ -368,18 +364,22 @@
         (obj) = NULL;                   \
     }
 
-#if __FreeBSD_version < 1000030
+#if __FreeBSD_version < 1000030 || defined(__DragonFly__)
 #define VM_OBJECT_WLOCK(object) VM_OBJECT_LOCK(object)
 #define VM_OBJECT_WUNLOCK(object) VM_OBJECT_UNLOCK(object)
 #endif
 
-#if __FreeBSD_version < 1000055
+#ifdef __DragonFly__
+#define vm_map_find(map, object, offset, addr, length, \
+	max_addr, find_space, prot, max, cow) \
+  vm_map_find(map, object, NULL, offset, addr, length, PAGE_SIZE, 1, VM_MAPTYPE_NORMAL, prot, max, cow)
+#elif __FreeBSD_version < 1000055
 #define vm_map_find(map, object, offset, addr, length, \
         max_addr, find_space, prot, max, cow) \
   vm_map_find(map, object, offset, addr, length, find_space, prot, max, cow)
 #endif
 
-#if __FreeBSD_version < 1000042
+#if !defined(__DragonFly__) && __FreeBSD_version < 1000042
 #define kmem_arena kernel_map
 #endif
 
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia-sources.mk NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia-sources.mk
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia-sources.mk	2015-11-08 05:23:40.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia-sources.mk	2015-12-05 12:52:11.367429000 +0100
@@ -2,7 +2,7 @@
 NVIDIA_SOURCES += nvidia_ctl.c
 NVIDIA_SOURCES += nvidia_dev.c
 NVIDIA_SOURCES += nvidia_i2c.c
-NVIDIA_SOURCES += nvidia_linux.c
+#NVIDIA_SOURCES += nvidia_linux.c
 NVIDIA_SOURCES += nvidia_os.c
 NVIDIA_SOURCES += nvidia_os_pci.c
 NVIDIA_SOURCES += nvidia_os_registry.c
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_acpi.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_acpi.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_acpi.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_acpi.c	2015-12-05 12:08:57.231392000 +0100
@@ -15,8 +15,8 @@
 
 #if defined(NV_SUPPORT_ACPI)
 
-#include <contrib/dev/acpica/include/acpi.h>
-#include <contrib/dev/acpica/include/accommon.h>
+#include <contrib/dev/acpica/source/include/acpi.h>
+#include <contrib/dev/acpica/source/include/accommon.h>
 #include <dev/acpica/acpivar.h>
 
 static int nvidia_acpi_lookup_bus(device_t dev, device_t *bus)
@@ -208,7 +208,7 @@
     }
 
     *pSize = data_size;
-    free(output.Pointer, M_TEMP);
+    kfree(output.Pointer, M_TEMP);
 
     return rmStatus;
 }
@@ -263,7 +263,7 @@
         rmStatus = NV_ERR_GENERIC;
     }
 
-    free(output.Pointer, M_TEMP);
+    kfree(output.Pointer, M_TEMP);
 
     return rmStatus;
 }
@@ -317,7 +317,7 @@
         rmStatus = NV_ERR_GENERIC;
     }
 
-    free(output.Pointer, M_TEMP);
+    kfree(output.Pointer, M_TEMP);
 
     return rmStatus;
 }
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_ctl.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_ctl.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_ctl.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_ctl.c	2015-12-06 14:12:25.157182000 +0100
@@ -16,16 +16,25 @@
 static d_open_t  nvidia_ctl_open;
 static void nvidia_ctl_dtor(void *arg);
 static d_ioctl_t nvidia_ctl_ioctl;
-static d_poll_t  nvidia_ctl_poll;
+static d_kqfilter_t  nvidia_ctl_kqfilter;
 static d_mmap_single_t nvidia_ctl_mmap_single;
 
-static struct cdevsw nvidia_ctl_cdevsw = {
+static struct dev_ops nvidia_ctl_ops = {
+    { "nvidiactl", 0, D_MPSAFE },
     .d_open =      nvidia_ctl_open,
     .d_ioctl =     nvidia_ctl_ioctl,
-    .d_poll =      nvidia_ctl_poll,
+    .d_kqfilter =  nvidia_ctl_kqfilter,
     .d_mmap_single = nvidia_ctl_mmap_single,
-    .d_name =      "nvidiactl",
-    .d_version =   D_VERSION,
+};
+
+static void nvidia_ctl_filter_detach(struct knote *);
+static int nvidia_ctl_filter_read(struct knote *, long);
+
+static struct filterops nvidia_ctl_filterops = {
+	FILTEROP_ISFD | FILTEROP_MPSAFE,
+	NULL,
+	nvidia_ctl_filter_detach,
+	nvidia_ctl_filter_read
 };
 
 static struct cdev *nvidia_ctl_cdev = NULL;
@@ -33,29 +42,25 @@
 
 static int nvidia_count = 0;
 
-static int nvidia_ctl_open(
-    struct cdev *dev,
-    int oflags,
-    int devtype,
-    d_thread_t *td
-)
+static int nvidia_ctl_open(struct dev_open_args *ap)
 {
+    struct file *fp = ap->a_fp;
     int status;
     nv_state_t *nv = &nvidia_ctl_state;
     struct nvidia_filep *filep;
 
-    filep = malloc(sizeof(nvidia_filep_t), M_NVIDIA, (M_WAITOK | M_ZERO));
+    filep = kmalloc(sizeof(nvidia_filep_t), M_NVIDIA, (M_WAITOK | M_ZERO));
     if (filep == NULL)
         return ENOMEM;
 
-    status = devfs_set_cdevpriv(filep, nvidia_ctl_dtor);
+    status = devfs_set_cdevpriv(fp, filep, nvidia_ctl_dtor);
     if (status != 0) {
-        free(filep, M_NVIDIA);
+        kfree(filep, M_NVIDIA);
         return status;
     }
 
     filep->nv = nv;
-    mtx_init(&filep->event_mtx, "event_mtx", NULL, (MTX_DEF | MTX_RECURSE));
+    lockinit(&filep->event_mtx, "event_mtx", 0, LK_CANRECURSE);
     STAILQ_INIT(&filep->event_queue);
 
     nv_lock_api(nv);
@@ -78,26 +83,23 @@
 
     while ((et = STAILQ_FIRST(&filep->event_queue))) {
         STAILQ_REMOVE(&filep->event_queue, et, nvidia_event, queue);
-        free(et, M_NVIDIA);
+        kfree(et, M_NVIDIA);
     }
-    mtx_destroy(&filep->event_mtx);
+    lockuninit(&filep->event_mtx);
 
-    free(filep, M_NVIDIA);
+    kfree(filep, M_NVIDIA);
 }
 
-static int nvidia_ctl_ioctl(
-    struct cdev *dev,
-    u_long cmd,
-    caddr_t data,
-    int fflag,
-    d_thread_t *td
-)
+static int nvidia_ctl_ioctl(struct dev_ioctl_args *ap)
 {
+    u_long cmd = ap->a_cmd;
+    caddr_t data = ap->a_data;
+    struct file *fp = ap->a_fp;
     int status;
     nv_state_t *nv = &nvidia_ctl_state;
     struct nvidia_filep *filep;
 
-    status = devfs_get_cdevpriv((void **)&filep);
+    status = devfs_get_cdevpriv(fp, (void **)&filep);
     if (status != 0)
         return status;
 
@@ -111,46 +113,72 @@
     return status;
 }
 
-static int nvidia_ctl_poll(
-    struct cdev *dev,
-    int events,
-    d_thread_t *td
-)
+static int nvidia_ctl_kqfilter(struct dev_kqfilter_args *ap)
 {
+    struct knote *kn = ap->a_kn;
+    struct file *fp = ap->a_fp;
     struct nvidia_filep *filep;
-    int status, mask = 0;
+    struct klist *klist;
 
-    status = devfs_get_cdevpriv((void **)&filep);
-    if (status != 0)
-        return 0;
+    ap->a_result = 0;
+
+    switch (kn->kn_filter) {
+    case EVFILT_READ:
+	if (devfs_get_cdevpriv(fp, (void **)&filep))
+	    return EOPNOTSUPP;
+	kn->kn_fop = &nvidia_ctl_filterops;
+	kn->kn_hook = (caddr_t)filep;
+	break;
+    default:
+	ap->a_result = EOPNOTSUPP;
+	return 0;
+    }
+
+    klist = &filep->event_kq.ki_note;
+    knote_insert(klist, kn);
+
+    return 0;
+}
+
+static void
+nvidia_ctl_filter_detach(struct knote *kn)
+{
+    struct nvidia_filep *filep = (struct nvidia_filep *)kn->kn_hook;
+    struct klist *klist;
+
+    klist = &filep->event_kq.ki_note;
+    knote_remove(klist, kn);
+}
+
+static int
+nvidia_ctl_filter_read(struct knote *kn, long hint)
+{
+    struct nvidia_filep *filep = (struct nvidia_filep *)kn->kn_hook;
+    int ret = 0;
 
-    mtx_lock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_EXCLUSIVE);
 
-    if (STAILQ_EMPTY(&filep->event_queue) && !filep->event_pending)
-        selrecord(td, &filep->event_rsel);
-    else {
-        mask = (events & (POLLIN | POLLPRI | POLLRDNORM));
+    if (!STAILQ_EMPTY(&filep->event_queue) || filep->event_pending) {
         filep->event_pending = FALSE;
+	ret = 1;
     }
 
-    mtx_unlock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_RELEASE);
 
-    return mask;
+    return ret;
 }
 
-static int nvidia_ctl_mmap_single(
-    struct cdev *dev,
-    vm_ooffset_t *offset,
-    vm_size_t size,
-    vm_object_t *object,
-    int nprot
-)
+static int nvidia_ctl_mmap_single(struct dev_mmap_single_args *ap)
 {
+    vm_ooffset_t *offset = ap->a_offset;
+    vm_size_t size = ap->a_size;
+    struct vm_object **object = ap->a_object;
+    struct file *fp = ap->a_fp;
     int status;
     struct nvidia_filep *filep;
     nv_state_t *nv;
 
-    status = devfs_get_cdevpriv((void **)&filep);
+    status = devfs_get_cdevpriv(fp, (void **)&filep);
     if (status != 0)
         return status;
     nv = filep->nv;
@@ -165,10 +193,10 @@
 int nvidia_ctl_attach(void)
 {
     if (nvidia_count == 0) {
-        nvidia_ctl_cdev = make_dev(&nvidia_ctl_cdevsw,
+        nvidia_ctl_cdev = make_dev(&nvidia_ctl_ops,
                 CDEV_CTL_MINOR,
                 UID_ROOT, GID_WHEEL, 0666,
-                "%s", nvidia_ctl_cdevsw.d_name);
+                "nvidiactl");
         if (nvidia_ctl_cdev == NULL)
             return ENOMEM;
     }
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_dev.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_dev.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_dev.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_dev.c	2015-12-06 14:13:45.739284000 +0100
@@ -16,43 +16,48 @@
 static d_open_t  nvidia_dev_open;
 static void nvidia_dev_dtor(void *arg);
 static d_ioctl_t nvidia_dev_ioctl;
-static d_poll_t  nvidia_dev_poll;
+static d_kqfilter_t  nvidia_dev_kqfilter;
 static d_mmap_single_t nvidia_dev_mmap_single;
 
-static struct cdevsw nvidia_dev_cdevsw = {
+static struct dev_ops nvidia_dev_ops = {
+    { "nvidia", 0, D_MEM | D_MPSAFE },
     .d_open =      nvidia_dev_open,
     .d_ioctl =     nvidia_dev_ioctl,
-    .d_poll =      nvidia_dev_poll,
+    .d_kqfilter =  nvidia_dev_kqfilter,
     .d_mmap_single = nvidia_dev_mmap_single,
-    .d_name =      "nvidia",
-    .d_version =   D_VERSION,
-    .d_flags =     D_MEM
 };
 
-static int nvidia_dev_open(
-    struct cdev *dev,
-    int oflags,
-    int devtype,
-    d_thread_t *td
-)
+static void nvidia_dev_filter_detach(struct knote *);
+static int nvidia_dev_filter_read(struct knote *, long);
+
+static struct filterops nvidia_dev_filterops = {
+	FILTEROP_ISFD | FILTEROP_MPSAFE,
+	NULL,
+	nvidia_dev_filter_detach,
+	nvidia_dev_filter_read
+};
+
+static int nvidia_dev_open(struct dev_open_args *ap)
 {
+    cdev_t dev = ap->a_head.a_dev;
+    struct file *fp = ap->a_fp;
     int status;
     struct nvidia_softc *sc = dev->si_drv1;
     nv_state_t *nv = sc->nv_state;
     struct nvidia_filep *filep;
 
-    filep = malloc(sizeof(nvidia_filep_t), M_NVIDIA, (M_WAITOK | M_ZERO));
+    filep = kmalloc(sizeof(nvidia_filep_t), M_NVIDIA, (M_WAITOK | M_ZERO));
     if (filep == NULL)
         return ENOMEM;
 
-    status = devfs_set_cdevpriv(filep, nvidia_dev_dtor);
+    status = devfs_set_cdevpriv(fp, filep, nvidia_dev_dtor);
     if (status != 0) {
-        free(filep, M_NVIDIA);
+        kfree(filep, M_NVIDIA);
         return status;
     }
 
     filep->nv = nv;
-    mtx_init(&filep->event_mtx, "event_mtx", NULL, (MTX_DEF | MTX_RECURSE));
+    lockinit(&filep->event_mtx, "event_mtx", 0, LK_CANRECURSE);
     STAILQ_INIT(&filep->event_queue);
 
     nv_lock_api(nv);
@@ -75,26 +80,23 @@
 
     while ((et = STAILQ_FIRST(&filep->event_queue))) {
         STAILQ_REMOVE(&filep->event_queue, et, nvidia_event, queue);
-        free(et, M_NVIDIA);
+        kfree(et, M_NVIDIA);
     }
-    mtx_destroy(&filep->event_mtx);
+    lockuninit(&filep->event_mtx);
 
-    free(filep, M_NVIDIA);
+    kfree(filep, M_NVIDIA);
 }
 
-static int nvidia_dev_ioctl(
-    struct cdev *dev,
-    u_long cmd,
-    caddr_t data,
-    int fflag,
-    d_thread_t *td
-)
+static int nvidia_dev_ioctl(struct dev_ioctl_args *ap)
 {
+    u_long cmd = ap->a_cmd;
+    caddr_t data = ap->a_data;
+    struct file *fp = ap->a_fp;
     int status;
     struct nvidia_filep *filep;
     nv_state_t *nv;
 
-    status = devfs_get_cdevpriv((void **)&filep);
+    status = devfs_get_cdevpriv(fp, (void **)&filep);
     if (status != 0)
         return status;
     nv = filep->nv;
@@ -109,46 +111,72 @@
     return status;
 }
 
-static int nvidia_dev_poll(
-    struct cdev *dev,
-    int events,
-    d_thread_t *td
-)
+static int nvidia_dev_kqfilter(struct dev_kqfilter_args *ap)
 {
+    struct knote *kn = ap->a_kn;
+    struct file *fp = ap->a_fp;
     struct nvidia_filep *filep;
-    int status, mask = 0;
+    struct klist *klist;
 
-    status = devfs_get_cdevpriv((void **)&filep);
-    if (status != 0)
-        return 0;
+    ap->a_result = 0;
+
+    switch (kn->kn_filter) {
+    case EVFILT_READ:
+	if (devfs_get_cdevpriv(fp, (void **)&filep))
+	    return EOPNOTSUPP;
+	kn->kn_fop = &nvidia_dev_filterops;
+	kn->kn_hook = (caddr_t)filep;
+	break;
+    default:
+	ap->a_result = EOPNOTSUPP;
+	return 0;
+    }
+
+    klist = &filep->event_kq.ki_note;
+    knote_insert(klist, kn);
+
+    return 0;
+}
+
+static void
+nvidia_dev_filter_detach(struct knote *kn)
+{
+    struct nvidia_filep *filep = (struct nvidia_filep *)kn->kn_hook;
+    struct klist *klist;
+
+    klist = &filep->event_kq.ki_note;
+    knote_remove(klist, kn);
+}
+
+static int
+nvidia_dev_filter_read(struct knote *kn, long hint)
+{
+    struct nvidia_filep *filep = (struct nvidia_filep *)kn->kn_hook;
+    int ret = 0;
 
-    mtx_lock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_EXCLUSIVE);
 
-    if (STAILQ_EMPTY(&filep->event_queue) && !filep->event_pending)
-        selrecord(td, &filep->event_rsel);
-    else {
-        mask = (events & (POLLIN | POLLPRI | POLLRDNORM));
+    if (!STAILQ_EMPTY(&filep->event_queue) || filep->event_pending) {
         filep->event_pending = FALSE;
+	ret = 1;
     }
 
-    mtx_unlock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_RELEASE);
 
-    return mask;
+    return ret;
 }
 
-static int nvidia_dev_mmap_single(
-    struct cdev *dev,
-    vm_ooffset_t *offset,
-    vm_size_t size,
-    vm_object_t *object,
-    int nprot
-)
+static int nvidia_dev_mmap_single(struct dev_mmap_single_args *ap)
 {
+    vm_ooffset_t *offset = ap->a_offset;
+    vm_size_t size = ap->a_size;
+    struct vm_object **object = ap->a_object;
+    struct file *fp = ap->a_fp;
     int status;
     struct nvidia_filep *filep;
     nv_state_t *nv;
 
-    status = devfs_get_cdevpriv((void **)&filep);
+    status = devfs_get_cdevpriv(fp, (void **)&filep);
     if (status != 0)
         return status;
     nv = filep->nv;
@@ -162,10 +190,10 @@
 
 int nvidia_dev_attach(struct nvidia_softc *sc)
 {
-    sc->cdev = make_dev(&nvidia_dev_cdevsw,
+    sc->cdev = make_dev(&nvidia_dev_ops,
             device_get_unit(sc->dev),
             UID_ROOT, GID_WHEEL, 0666,
-            "%s%d", nvidia_dev_cdevsw.d_name,
+            "nvidia%d",
             device_get_unit(sc->dev));
     if (sc->cdev == NULL)
         return ENOMEM;
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_os.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_os.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_os.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_os.c	2015-12-06 17:37:48.919997000 +0100
@@ -21,14 +21,14 @@
     NvU32 size
 )
 {
-    /* XXX Fix me? (malloc flags) */
-    *address = malloc(size, M_NVIDIA, M_NOWAIT | M_ZERO);
+    /* XXX Fix me? (kmalloc flags) */
+    *address = kmalloc(size, M_NVIDIA, M_NOWAIT | M_ZERO);
     return *address ? NV_OK : NV_ERR_GENERIC;
 }
 
 void NV_API_CALL os_free_mem(void *address)
 {
-    free(address, M_NVIDIA);
+    kfree(address, M_NVIDIA);
 }
 
 #define NV_MSECS_PER_TICK       (1000 / hz)
@@ -62,7 +62,7 @@
 
     if (ticks > 0) {
         do {
-            tsleep((void *)os_delay, PUSER | PCATCH, "delay", ticks);
+            tsleep((void *)os_delay, PCATCH, "delay", ticks);
             getmicrotime(&tv_aux);
             if (NV_TIMERCMP(&tv_aux, &tv_end, <)) {
                 /* tv_aux = tv_end - tv_aux */
@@ -90,7 +90,7 @@
 NvU64 NV_API_CALL os_get_cpu_frequency(void)
 {
     /* round up by 4999 before division by 1000000 in osGetCpuFrequency() */
-    return (tsc_freq + 4999);
+    return (tsc_frequency + 4999);
 }
 
 NvU32 NV_API_CALL os_get_current_process(void)
@@ -103,7 +103,7 @@
     if (__NV_ITHREAD())
         *threadId = 0;
     else
-        *threadId = (NvU64) CURTHREAD->td_tid;
+        *threadId = (NvU64) CURTHREAD->td_lwp->lwp_tid;
 
     return NV_OK;
 }
@@ -330,7 +330,7 @@
 
 void NV_API_CALL out_string(const char *message)
 {
-    printf("%s", message);
+    kprintf("%s", message);
 }
 
 #define MAX_ERROR_STRING 512
@@ -348,9 +348,9 @@
 
     if (debuglevel >= ((cur_debuglevel >> 4) & 3)) {
         va_start(arglist, format);
-        chars_written = vsnprintf(message, sizeof(nv_error_string), format, arglist);
+        chars_written = kvsnprintf(message, sizeof(nv_error_string), format, arglist);
         va_end(arglist);
-        printf("%s", message);
+        kprintf("%s", message);
     }
 
     return chars_written;
@@ -367,7 +367,7 @@
     int chars_written;
 
     va_start(arglist, fmt);
-    chars_written = vsnprintf(buf, size, fmt, arglist);
+    chars_written = kvsnprintf(buf, size, fmt, arglist);
     va_end(arglist);
 
     return chars_written;
@@ -381,10 +381,10 @@
 )
 {
     int l;
-    sprintf(nv_error_string, "NVRM: ");
+    ksprintf(nv_error_string, "NVRM: ");
     l = strlen(nv_error_string);
-    vsnprintf(nv_error_string + l, MAX_ERROR_STRING - l, fmt, ap);
-    printf("%s", nv_error_string);
+    kvsnprintf(nv_error_string + l, MAX_ERROR_STRING - l, fmt, ap);
+    kprintf("%s", nv_error_string);
 }
 
 NvS32 NV_API_CALL os_mem_cmp(
@@ -503,12 +503,12 @@
 
 NvU32 NV_API_CALL os_get_cpu_count(void)
 {
-    return mp_ncpus;
+    return ncpus;
 }
 
 NvU32 NV_API_CALL os_get_cpu_number(void)
 {
-    return curcpu;
+    return mycpuid;
 }
 
 #ifdef NV_USE_WBINVD
@@ -554,20 +554,23 @@
 
 void NV_API_CALL os_flush_cpu_write_combine_buffer(void)
 {
-    smp_rendezvous(NULL, sfence_action_func, NULL, NULL);
+    cpumask_t mask;
+
+    CPUMASK_ASSALLONES(mask);
+    lwkt_cpusync_simple(mask, sfence_action_func, NULL);
     sfence_action_func(NULL);
 }
 
 NV_STATUS NV_API_CALL os_alloc_mutex(void **mutex)
 {
     NV_STATUS status;
-    struct sx *sx;
+    struct lock *sx;
 
-    status = os_alloc_mem((void **)&sx, sizeof(struct sx));
+    status = os_alloc_mem((void **)&sx, sizeof(struct lock));
     if (status != NV_OK)
         return status;
 
-    sx_init(sx, "os.lock_sx");
+    lockinit(sx, "os.lock_sx", 0, LK_CANRECURSE);
     *mutex = (void *)sx;
 
     return NV_OK;
@@ -575,29 +578,29 @@
 
 void NV_API_CALL os_free_mutex(void *mutex)
 {
-    struct sx *sx = mutex;
+    struct lock *sx = mutex;
 
     if (sx != NULL) {
-        sx_destroy(sx);
+        lockuninit(sx);
         os_free_mem(sx);
     }
 }
 
 NV_STATUS NV_API_CALL os_acquire_mutex(void *mutex)
 {
-    struct sx *sx = mutex;
+    struct lock *sx = mutex;
 
     if (__NV_ITHREAD())
         return NV_ERR_INVALID_REQUEST;
 
-    sx_xlock(sx);
+    lockmgr(sx, LK_EXCLUSIVE);
 
     return NV_OK;
 }
 
 NV_STATUS NV_API_CALL os_cond_acquire_mutex(void *mutex)
 {
-    struct sx *sx = mutex;
+    struct lock *sx = mutex;
 
     if (__NV_ITHREAD())
         return NV_ERR_INVALID_REQUEST;
@@ -610,13 +613,13 @@
 
 void NV_API_CALL os_release_mutex(void *mutex)
 {
-    struct sx *sx = mutex;
+    struct lock *sx = mutex;
 
-    sx_xunlock(sx);
+    lockmgr(sx, LK_RELEASE);
 }
 
 struct os_semaphore {
-    struct mtx mutex_mtx;
+    struct lock mutex_mtx;
     struct cv mutex_cv;
     NvS32  count;
     NvS32  limit;
@@ -633,7 +636,7 @@
         return NULL;
     }
 
-    mtx_init(&os_sema->mutex_mtx, "os.sema_mtx", NULL, MTX_DEF);
+    lockinit(&os_sema->mutex_mtx, "os.sema_mtx", 0, 0);
     cv_init(&os_sema->mutex_cv, "os.sema_cv");
 
     os_sema->count = initialValue;
@@ -646,7 +649,7 @@
 {
     struct os_semaphore *os_sema = (struct os_semaphore *)semaphore;
 
-    mtx_destroy(&os_sema->mutex_mtx);
+    lockuninit(&os_sema->mutex_mtx);
     cv_destroy(&os_sema->mutex_cv);
 
     os_free_mem(os_sema);
@@ -656,12 +659,12 @@
 {
     struct os_semaphore *os_sema = (struct os_semaphore *)semaphore;
 
-    mtx_lock(&os_sema->mutex_mtx);
+    lockmgr(&os_sema->mutex_mtx, LK_EXCLUSIVE);
     os_sema->count--;
     if (os_sema->count < 0)
         cv_wait_unlock(&os_sema->mutex_cv, &os_sema->mutex_mtx);
     else
-        mtx_unlock(&os_sema->mutex_mtx);
+        lockmgr(&os_sema->mutex_mtx, LK_RELEASE);
 
     return NV_OK;
 }
@@ -670,12 +673,12 @@
 {
     struct os_semaphore *os_sema = (struct os_semaphore *)semaphore;
 
-    mtx_lock(&os_sema->mutex_mtx);
+    lockmgr(&os_sema->mutex_mtx, LK_EXCLUSIVE);
     if (os_sema->count < 0) {
         cv_signal(&os_sema->mutex_cv);
     }
     os_sema->count++;
-    mtx_unlock(&os_sema->mutex_mtx);
+    lockmgr(&os_sema->mutex_mtx, LK_RELEASE);
 
     return NV_OK;
 }
@@ -740,13 +743,13 @@
 NV_STATUS NV_API_CALL os_alloc_spinlock(void **lock)
 {
     NV_STATUS status;
-    struct mtx *mtx;
+    struct lock *mtx;
 
-    status = os_alloc_mem((void **)&mtx, sizeof(struct mtx));
+    status = os_alloc_mem((void **)&mtx, sizeof(struct lock));
     if (status != NV_OK)
         return status;
 
-    mtx_init(mtx, "os.lock_mtx", NULL, MTX_DEF);
+    lockinit(mtx, "os.lock_mtx", 0, 0);
 
     *lock = (void *)mtx;
 
@@ -755,29 +758,29 @@
 
 void NV_API_CALL os_free_spinlock(void *lock)
 {
-    struct mtx *mtx = lock;
+    struct lock *mtx = lock;
 
     if (mtx != NULL) {
-        mtx_assert(mtx, MA_OWNED);
-        mtx_destroy(mtx);
+	KKASSERT(lockowned(mtx) != 0);
+        lockuninit(mtx);
         os_free_mem(mtx);
     }
 }
 
 NvU64 NV_API_CALL os_acquire_spinlock(void *lock)
 {
-    struct mtx *mtx = lock;
+    struct lock *mtx = lock;
 
-    mtx_lock(mtx);
+    lockmgr(mtx, LK_EXCLUSIVE);
 
     return 0;
 }
 
 void NV_API_CALL os_release_spinlock(void *lock, NvU64 oldIrql)
 {
-    struct mtx *mtx = lock;
+    struct lock *mtx = lock;
 
-    mtx_unlock(mtx);
+    lockmgr(mtx, LK_RELEASE);
 }
 
 NV_STATUS NV_API_CALL os_get_address_space_info(
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_os_registry.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_os_registry.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_os_registry.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_os_registry.c	2015-12-05 12:20:51.679570000 +0100
@@ -30,7 +30,7 @@
     if (sp == NULL)
         return;
 
-    option_string = strdup(new_option_string, M_NVIDIA);
+    option_string = kstrdup(new_option_string, M_NVIDIA);
     ptr = mod = option_string;
 
     while (*ptr != '\0') {
@@ -63,7 +63,7 @@
 
     NV_UMA_ZONE_FREE_STACK(sp);
 
-    free(option_string, M_NVIDIA);
+    kfree(option_string, M_NVIDIA);
 }
 
 #define NV_TUNABLE_MAX_STRLEN 128
@@ -74,17 +74,17 @@
     NvU32 i;
     char *tunable;
 
-    tunable = malloc(NV_TUNABLE_MAX_STRLEN, M_NVIDIA, M_WAITOK);
+    tunable = kmalloc(NV_TUNABLE_MAX_STRLEN, M_NVIDIA, M_WAITOK);
     if (tunable == NULL)
         return;
 
     for (i = 0; (entry = &nv_parms[i])->name != NULL; i++) {
-       snprintf(tunable, NV_TUNABLE_MAX_STRLEN, "hw.nvidia.registry.%s",
+       ksnprintf(tunable, NV_TUNABLE_MAX_STRLEN, "hw.nvidia.registry.%s",
                entry->name);
        TUNABLE_INT_FETCH(tunable, entry->data);
     }
 
-    free(tunable, M_NVIDIA);
+    kfree(tunable, M_NVIDIA);
 }
 
 NV_STATUS os_registry_init(void)
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_pci.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_pci.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_pci.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_pci.c	2015-12-05 13:31:58.748213000 +0100
@@ -78,10 +78,10 @@
     sc = device_get_softc(dev);
 
     /* XXX Revisit! (INTR_FAST) */
-    flags = (INTR_TYPE_AV | INTR_MPSAFE);
+    flags = INTR_MPSAFE;
 
-    status = bus_setup_intr(dev, sc->irq, flags, NULL, nvidia_intr, sc,
-            &sc->irq_ih);
+    status = bus_setup_intr(dev, sc->irq, flags, nvidia_intr, sc,
+            &sc->irq_ih, NULL);
     if (status) {
         device_printf(dev, "NVRM: HW ISR setup failed.\n");
         goto fail;
@@ -271,7 +271,7 @@
     sc = device_get_softc(dev); /* first reference */
     bzero(sc, sizeof(nvidia_softc_t));
 
-    sc->nv_state = malloc(sizeof(nv_state_t), M_NVIDIA, M_WAITOK | M_ZERO);
+    sc->nv_state = kmalloc(sizeof(nv_state_t), M_NVIDIA, M_WAITOK | M_ZERO);
     if (sc->nv_state == NULL)
         return ENOMEM;
 
@@ -316,7 +316,7 @@
 
     NV_UMA_ZONE_ALLOC_STACK(sp);
     if (sp == NULL) {
-        free(sc->nv_state, M_NVIDIA);
+        kfree(sc->nv_state, M_NVIDIA);
         return ENOMEM;
     }
 
@@ -348,8 +348,8 @@
         goto fail;
     }
 
-    callout_init(&sc->timer, CALLOUT_MPSAFE);
-    sx_init(&sc->api_sx, "dev.api_sx");
+    callout_init_mp(&sc->timer);
+    lockinit(&sc->api_sx, "dev.api_sx", 0, LK_CANRECURSE);
 
     return 0;
 
@@ -359,7 +359,7 @@
     sc->attach_sp = NULL;
     NV_UMA_ZONE_FREE_STACK(sp);
 
-    free(sc->nv_state, M_NVIDIA);
+    kfree(sc->nv_state, M_NVIDIA);
 
     return status;
 }
@@ -387,7 +387,7 @@
     }
 
     nv_unlock_api(nv);
-    sx_destroy(&sc->api_sx);
+    lockuninit(&sc->api_sx);
 
     status = nvidia_pci_teardown_intr(dev);
     if (status)
@@ -407,7 +407,7 @@
     sc->attach_sp = NULL;
     NV_UMA_ZONE_FREE_STACK(sp);
 
-    free(sc->nv_state, M_NVIDIA);
+    kfree(sc->nv_state, M_NVIDIA);
 
 fail:
     /* XXX Fix me? (state) */
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_subr.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_subr.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_subr.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_subr.c	2015-12-06 15:16:08.356946000 +0100
@@ -17,7 +17,7 @@
 #include <machine/vm86.h>
 #endif
 
-uma_zone_t nvidia_stack_t_zone;
+MALLOC_DEFINE(M_NVSTACK, "nvstack", "NVIDIA stack allocations");
 static nvidia_stack_t *__nvidia_init_sp = NULL;
 
 devclass_t nvidia_devclass;
@@ -422,12 +422,12 @@
         if (size > NV_ABSOLUTE_MAX_IOCTL_SIZE)
             return EINVAL;
 
-        args = malloc(size, M_NVIDIA, M_WAITOK);
+        args = kmalloc(size, M_NVIDIA, M_WAITOK);
         if (args == NULL)
             return ENOMEM;
 
         if (copyin(NvP64_VALUE(xfer->ptr), args, size) != 0) {
-            free(args, M_NVIDIA);
+            kfree(args, M_NVIDIA);
             return EFAULT;
         }
 
@@ -455,7 +455,7 @@
     if (args != (void *)data) {
         if (copyout(args, NvP64_VALUE(xfer->ptr), size) != 0)
             status = EFAULT;
-        free(args, M_NVIDIA);
+        kfree(args, M_NVIDIA);
     }
 
     return status;
@@ -638,30 +638,23 @@
              */
             sc = &nvidia_ctl_sc;
 
-            nvidia_stack_t_zone = uma_zcreate("nvidia_stack_t", sizeof(nvidia_stack_t),
-                    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
-            if (nvidia_stack_t_zone == NULL)
-                return ENOMEM;
-
             NV_UMA_ZONE_ALLOC_STACK(sp);
             if (sp == NULL) {
-                uma_zdestroy(nvidia_stack_t_zone);
                 return ENOMEM;
             }
 
             bzero(sc, sizeof(nvidia_softc_t));
 
             if (!rm_init_rm(sp)) {
-                printf("NVRM: rm_init_rm() failed!\n");
+                kprintf("NVRM: rm_init_rm() failed!\n");
                 NV_UMA_ZONE_FREE_STACK(sp);
-                uma_zdestroy(nvidia_stack_t_zone);
                 return EIO;
             }
 
             __nvidia_init_sp = sp;
 
-            callout_init(&sc->timer, CALLOUT_MPSAFE);
-            sx_init(&sc->api_sx, "ctl.api_sx");
+            callout_init_mp(&sc->timer);
+            lockinit(&sc->api_sx, "ctl.api_sx", 0, LK_CANRECURSE);
 
             nvidia_ctl_state.os_state = sc;
             sc->nv_state = (void *)&nvidia_ctl_state;
@@ -688,7 +681,7 @@
             }
 
             nv_unlock_api(nv);
-            sx_destroy(&sc->api_sx);
+            lockuninit(&sc->api_sx);
 
             sp = __nvidia_init_sp;
             rm_shutdown_rm(sp);
@@ -698,8 +691,6 @@
             nvidia_sysctl_exit();
             nvidia_linux_exit();
 
-            uma_zdestroy(nvidia_stack_t_zone);
-
             break;
 
         default:
@@ -717,13 +708,13 @@
 void nv_lock_api(nv_state_t *nv)
 {
     struct nvidia_softc *sc = nv->os_state;
-    sx_xlock(&sc->api_sx);
+    lockmgr(&sc->api_sx, LK_EXCLUSIVE);
 }
 
 void nv_unlock_api(nv_state_t *nv)
 {
     struct nvidia_softc *sc = nv->os_state;
-    sx_xunlock(&sc->api_sx);
+    lockmgr(&sc->api_sx, LK_RELEASE);
 }
 
 void NV_API_CALL nv_post_event(
@@ -737,12 +728,12 @@
     struct nvidia_filep *filep = event->file;
     struct nvidia_event *et;
 
-    mtx_lock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_EXCLUSIVE);
 
     if (data_valid) {
-        et = malloc(sizeof(nvidia_event_t), M_NVIDIA, M_NOWAIT);
+        et = kmalloc(sizeof(nvidia_event_t), M_NVIDIA, M_NOWAIT);
         if (et == NULL) {
-            mtx_unlock(&filep->event_mtx);
+	    lockmgr(&filep->event_mtx, LK_RELEASE);
             return;
         }
 
@@ -754,9 +745,9 @@
     }
 
     filep->event_pending = TRUE;
-    mtx_unlock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_RELEASE);
 
-    selwakeup(&filep->event_rsel);
+    KNOTE(&filep->event_kq.ki_note, 0);
 }
 
 NvS32 NV_API_CALL nv_get_event(
@@ -769,11 +760,11 @@
     struct nvidia_filep *filep = file;
     struct nvidia_event *et;
 
-    mtx_lock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_EXCLUSIVE);
 
     et = STAILQ_FIRST(&filep->event_queue);
     if (et == NULL) {
-        mtx_unlock(&filep->event_mtx);
+	lockmgr(&filep->event_mtx, LK_RELEASE);
         return NV_ERR_GENERIC;
     }
 
@@ -783,9 +774,9 @@
 
     *pending = !STAILQ_EMPTY(&filep->event_queue);
 
-    mtx_unlock(&filep->event_mtx);
+    lockmgr(&filep->event_mtx, LK_RELEASE);
 
-    free(et, M_NVIDIA);
+    kfree(et, M_NVIDIA);
 
     return NV_OK;
 }
@@ -812,9 +803,9 @@
     size = (size + PAGE_MASK) & ~PAGE_MASK;
 
     vm_object_reference(at->object);
-    virtual_address = vm_map_min(kernel_map);
+    virtual_address = vm_map_min(&kernel_map);
 
-    status = vm_map_find(kernel_map, at->object, (pageIndex * PAGE_SIZE),
+    status = vm_map_find(&kernel_map, at->object, (pageIndex * PAGE_SIZE),
             &virtual_address, size, 0, VMFS_ANY_SPACE,
             (VM_PROT_READ | VM_PROT_WRITE),
             (VM_PROT_READ | VM_PROT_WRITE), 0);
@@ -823,11 +814,11 @@
         return NULL;
     }
 
-    status = vm_map_wire(kernel_map, virtual_address,
+    status = vm_map_wire(&kernel_map, virtual_address,
             (virtual_address + size),
             (VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES));
     if (status != KERN_SUCCESS) {
-        vm_map_remove(kernel_map, virtual_address,
+        vm_map_remove(&kernel_map, virtual_address,
             (virtual_address + size));
         return NULL;
     }
@@ -850,7 +841,7 @@
     if (pPrivate != NULL) {
         virtual_address = (vm_offset_t)address & ~PAGE_MASK;
         size = (NvUPtr)pPrivate;
-        vm_map_remove(kernel_map, virtual_address,
+        vm_map_remove(&kernel_map, virtual_address,
             (virtual_address + size));
     }
 
@@ -913,7 +904,7 @@
     vm_memattr_t attr;
     vm_offset_t address;
     NvU32 size = (count * PAGE_SIZE);
-    int flags = (zero ? M_ZERO : 0);
+//    int flags = (zero ? M_ZERO : 0);
     int status;
 
     switch (cache_type) {
@@ -936,7 +927,7 @@
             return EINVAL;
     }
 
-    at = malloc(sizeof(nvidia_alloc_t), M_NVIDIA, (M_WAITOK | M_ZERO));
+    at = kmalloc(sizeof(nvidia_alloc_t), M_NVIDIA, (M_WAITOK | M_ZERO));
     if (!at)
         return ENOMEM;
 
@@ -944,15 +935,14 @@
     at->alloc_type_contiguous = 1;
     at->attr = attr;
 
-    at->pte_array = malloc(sizeof(nvidia_pte_t), M_NVIDIA,
+    at->pte_array = kmalloc(sizeof(nvidia_pte_t), M_NVIDIA,
             (M_WAITOK | M_ZERO));
     if (!at->pte_array) {
-        free(at, M_NVIDIA);
+        kfree(at, M_NVIDIA);
         return ENOMEM;
     }
 
-    address = kmem_alloc_contig(kmem_arena, size, flags, 0,
-            sc->dma_mask, PAGE_SIZE, 0, attr);
+    address = kmem_alloc_contig(size, 0, sc->dma_mask, PAGE_SIZE);
     if (!address) {
         status = ENOMEM;
         goto failed;
@@ -1000,12 +990,12 @@
         os_flush_cpu_cache();
 
     if (at->pte_array[0].virtual_address != NULL) {
-        kmem_free(kmem_arena, at->pte_array[0].virtual_address, at->size);
+        kmem_free(&kernel_map, at->pte_array[0].virtual_address, at->size);
         malloc_type_freed(M_NVIDIA, at->size);
     }
 
-    free(at->pte_array, M_NVIDIA);
-    free(at, M_NVIDIA);
+    kfree(at->pte_array, M_NVIDIA);
+    kfree(at, M_NVIDIA);
 
     return status;
 }
@@ -1026,11 +1016,11 @@
     if (at->attr != VM_MEMATTR_WRITE_BACK)
         os_flush_cpu_cache();
 
-    kmem_free(kmem_arena, at->pte_array[0].virtual_address, at->size);
+    kmem_free(&kernel_map, at->pte_array[0].virtual_address, at->size);
     malloc_type_freed(M_NVIDIA, at->size);
 
-    free(at->pte_array, M_NVIDIA);
-    free(at, M_NVIDIA);
+    kfree(at->pte_array, M_NVIDIA);
+    kfree(at, M_NVIDIA);
 
     return 0;
 }
@@ -1050,7 +1040,7 @@
     uint32_t i;
     vm_memattr_t attr;
     uint32_t size = (count * PAGE_SIZE);
-    int flags = (zero ? M_ZERO : 0);
+//    int flags = (zero ? M_ZERO : 0);
     int status;
 
     switch (cache_type) {
@@ -1073,7 +1063,7 @@
             return EINVAL;
     }
 
-    at = malloc(sizeof(nvidia_alloc_t), M_NVIDIA, (M_WAITOK | M_ZERO));
+    at = kmalloc(sizeof(nvidia_alloc_t), M_NVIDIA, (M_WAITOK | M_ZERO));
     if (!at)
         return ENOMEM;
 
@@ -1081,16 +1071,15 @@
     at->alloc_type_contiguous = 0;
     at->attr = attr;
 
-    at->pte_array = malloc((sizeof(nvidia_pte_t) * count),
+    at->pte_array = kmalloc((sizeof(nvidia_pte_t) * count),
             M_NVIDIA, (M_WAITOK | M_ZERO));
     if (!at->pte_array) {
-        free(at, M_NVIDIA);
+        kfree(at, M_NVIDIA);
         return ENOMEM;
     }
 
     for (i = 0; i < count; i++) {
-        address = kmem_alloc_contig(kmem_arena, PAGE_SIZE, flags, 0,
-                sc->dma_mask, PAGE_SIZE, 0, attr);
+        address = kmem_alloc_contig(PAGE_SIZE, 0, sc->dma_mask, PAGE_SIZE);
         if (!address) {
             status = ENOMEM;
             goto failed;
@@ -1143,12 +1132,12 @@
     for (i = 0; i < count; i++) {
         if (at->pte_array[i].virtual_address == 0)
             break;
-        kmem_free(kmem_arena, at->pte_array[i].virtual_address, PAGE_SIZE);
+        kmem_free(&kernel_map, at->pte_array[i].virtual_address, PAGE_SIZE);
         malloc_type_freed(M_NVIDIA, PAGE_SIZE);
     }
 
-    free(at->pte_array, M_NVIDIA);
-    free(at, M_NVIDIA);
+    kfree(at->pte_array, M_NVIDIA);
+    kfree(at, M_NVIDIA);
 
     return status;
 }
@@ -1172,12 +1161,12 @@
         os_flush_cpu_cache();
 
     for (i = 0; i < count; i++) {
-        kmem_free(kmem_arena, at->pte_array[i].virtual_address, PAGE_SIZE);
+        kmem_free(&kernel_map, at->pte_array[i].virtual_address, PAGE_SIZE);
         malloc_type_freed(M_NVIDIA, PAGE_SIZE);
     }
 
-    free(at->pte_array, M_NVIDIA);
-    free(at, M_NVIDIA);
+    kfree(at->pte_array, M_NVIDIA);
+    kfree(at, M_NVIDIA);
 
     return 0;
 }
diff -ur NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_sysctl.c NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_sysctl.c
--- NVIDIA-FreeBSD-x86_64-352.63/src/nvidia_sysctl.c	2015-11-08 05:03:53.000000000 +0100
+++ NVIDIA-FreeBSD-x86_64-352.63_df/src/nvidia_sysctl.c	2015-12-05 12:21:31.530584000 +0100
@@ -65,7 +65,7 @@
         entry++;
     } while(entry->name != NULL);
 
-    option_string = malloc(1, M_NVIDIA, (M_WAITOK | M_ZERO));
+    option_string = kmalloc(1, M_NVIDIA, (M_WAITOK | M_ZERO));
 
     SYSCTL_ADD_PROC(&sysctl_ctx,
             SYSCTL_CHILDREN(oid_registry),
@@ -80,7 +80,7 @@
 {
     sysctl_ctx_free(&sysctl_ctx);
     if (option_string != NULL)
-        free((void *)option_string, M_NVIDIA);
+        kfree((void *)option_string, M_NVIDIA);
 }
 
 
@@ -150,9 +150,9 @@
          * The VBIOS version is only accessible after the device has been
          * initialized with rm_init_adapter.
          */
-        sprintf(vbios_version, "??.??.??.??.??");
+        ksprintf(vbios_version, "??.??.??.??.??");
     } else {
-        sprintf(vbios_version, "%02x.%02x.%02x.%02x.%02x", vbios[0],
+        ksprintf(vbios_version, "%02x.%02x.%02x.%02x.%02x", vbios[0],
                 vbios[1], vbios[2], vbios[3], vbios[4]);
     }
 
@@ -202,7 +202,7 @@
 
     len = (req->newlen - req->newidx);
 
-    new_option_string = malloc((len + 1), M_NVIDIA, M_WAITOK);
+    new_option_string = kmalloc((len + 1), M_NVIDIA, M_WAITOK);
     if (!new_option_string)
         return ENOMEM;
 
@@ -210,7 +210,7 @@
     if (error)
         return error;
 
-    free(option_string, M_NVIDIA);
+    kfree(option_string, M_NVIDIA);
 
     option_string = new_option_string;
     option_string[len] = '\0';
@@ -226,7 +226,7 @@
     struct nvidia_softc *sc = nv->os_state;
 
     char name[4];
-    sprintf(name, "%d", device_get_unit(sc->dev));
+    ksprintf(name, "%d", device_get_unit(sc->dev));
 
     sysctl_ctx_init(&sc->sysctl_ctx);
 
