Module Name:    src
Committed By:   riastradh
Date:           Tue Aug 28 03:41:40 UTC 2018

Modified Files:
        src/sys/external/bsd/drm2/dist/drm: drm_agpsupport.c drm_internal.h
            drm_ioctl.c
        src/sys/external/bsd/drm2/dist/drm/ast: ast_drv.c
        src/sys/external/bsd/drm2/dist/drm/i810: i810_drv.c
        src/sys/external/bsd/drm2/dist/drm/i915: i915_dma.c
        src/sys/external/bsd/drm2/dist/drm/mga: mga_drv.c
        src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci: agp.h
        src/sys/external/bsd/drm2/dist/drm/qxl: qxl_drv.c
        src/sys/external/bsd/drm2/dist/drm/r128: r128_drv.c
        src/sys/external/bsd/drm2/dist/drm/radeon: radeon_drv.c
        src/sys/external/bsd/drm2/dist/drm/savage: savage_drv.c
        src/sys/external/bsd/drm2/dist/drm/sis: sis_drv.c
        src/sys/external/bsd/drm2/dist/drm/tdfx: tdfx_drv.c
        src/sys/external/bsd/drm2/dist/drm/via: via_drv.c
        src/sys/external/bsd/drm2/dist/include/drm: drmP.h drm_agpsupport.h
        src/sys/external/bsd/drm2/drm: drm_cdevsw.c drm_module.c files.drmkms
        src/sys/external/bsd/drm2/include/drm: drm_agp_netbsd.h drm_os_netbsd.h
        src/sys/external/bsd/drm2/linux: linux_pci.c
        src/sys/external/bsd/drm2/pci: drm_pci.c drm_pci_module.c
            files.drmkms_pci
        src/sys/external/bsd/drm2/ttm: ttm_agp_backend.c
        src/sys/modules: Makefile
        src/sys/modules/drmkms: Makefile
        src/sys/modules/drmkms_linux: Makefile
        src/sys/modules/drmkms_pci: Makefile
        src/sys/modules/i915drmkms: Makefile
Added Files:
        src/sys/external/bsd/drm2/drm: drm_agp_hook.c
        src/sys/modules/drmkms: agp.h
        src/sys/modules/drmkms_agp: Makefile

Log Message:
Rework PCI and AGP conditionalization.

- Push drm_pci_set_unique into driver callback.
- Eliminate drm_pci_set_unique_hook.
- Gather all drm_agp_* functions into struct drm_agp_hooks.
- Replace the nonsensical old atomic garbage by serious locking.
- Make drm_agpsupport.c its own module.
- Eliminate NDRMKMS_PCI.
- Use NAGP from "agp.h" only in drm_module.c for horrible hack.
  => See comment in file for rationale.
- Always define CONFIG_PCI=1 and CONFIG_AGP=1.
- Always go through the drm_agp_* function hooks.
- Ifdef out nouveau agp stuff that doesn't go through drm_agp_*
  for reasons that I'm too frustrated to figure out tonight.
- pci_iomap no longer automagically does agp_i810_borrow.
  => Use drm_agp_borrow instead.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c \
    src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/dist/drm/drm_internal.h
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/dist/drm/ast/ast_drv.c
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/dist/drm/i810/i810_drv.c
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c
cvs rdiff -u -r1.2 -r1.3 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/agp.h
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/dist/drm/qxl/qxl_drv.c
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/dist/drm/r128/r128_drv.c
cvs rdiff -u -r1.8 -r1.9 \
    src/sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c
cvs rdiff -u -r1.2 -r1.3 \
    src/sys/external/bsd/drm2/dist/drm/savage/savage_drv.c
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/dist/drm/sis/sis_drv.c
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/dist/drm/tdfx/tdfx_drv.c
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/dist/drm/via/via_drv.c
cvs rdiff -u -r1.33 -r1.34 src/sys/external/bsd/drm2/dist/include/drm/drmP.h
cvs rdiff -u -r1.7 -r1.8 \
    src/sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h
cvs rdiff -u -r0 -r1.1 src/sys/external/bsd/drm2/drm/drm_agp_hook.c
cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/drm2/drm/drm_cdevsw.c
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/drm/drm_module.c
cvs rdiff -u -r1.29 -r1.30 src/sys/external/bsd/drm2/drm/files.drmkms
cvs rdiff -u -r1.7 -r1.8 \
    src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h
cvs rdiff -u -r1.12 -r1.13 \
    src/sys/external/bsd/drm2/include/drm/drm_os_netbsd.h
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_pci.c
cvs rdiff -u -r1.30 -r1.31 src/sys/external/bsd/drm2/pci/drm_pci.c
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/pci/drm_pci_module.c
cvs rdiff -u -r1.12 -r1.13 src/sys/external/bsd/drm2/pci/files.drmkms_pci
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c
cvs rdiff -u -r1.208 -r1.209 src/sys/modules/Makefile
cvs rdiff -u -r1.10 -r1.11 src/sys/modules/drmkms/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/modules/drmkms/agp.h
cvs rdiff -u -r0 -r1.1 src/sys/modules/drmkms_agp/Makefile
cvs rdiff -u -r1.10 -r1.11 src/sys/modules/drmkms_linux/Makefile
cvs rdiff -u -r1.6 -r1.7 src/sys/modules/drmkms_pci/Makefile
cvs rdiff -u -r1.9 -r1.10 src/sys/modules/i915drmkms/Makefile

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

Modified files:

Index: src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c
diff -u src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c:1.9 src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c:1.10
--- src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c:1.9	Tue Aug 28 03:33:54 2018
+++ src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_agpsupport.c,v 1.9 2018/08/28 03:33:54 riastradh Exp $	*/
+/*	$NetBSD: drm_agpsupport.c,v 1.10 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /**
  * \file drm_agpsupport.c
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_agpsupport.c,v 1.9 2018/08/28 03:33:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_agpsupport.c,v 1.10 2018/08/28 03:41:38 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <linux/errno.h>
@@ -57,7 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: drm_agpsuppo
  * Verifies the AGP device has been initialized and acquired and fills in the
  * drm_agp_info structure with the information in drm_agp_head::agp_info.
  */
-int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info)
+static int drm_agp_info_hook(struct drm_device *dev, struct drm_agp_info *info)
 {
 	struct agp_kern_info *kern;
 
@@ -92,7 +92,7 @@ int drm_agp_info(struct drm_device *dev,
 
 EXPORT_SYMBOL(drm_agp_info);
 
-int drm_agp_info_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_info_ioctl_hook(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv)
 {
 	struct drm_agp_info *info = data;
@@ -114,7 +114,7 @@ int drm_agp_info_ioctl(struct drm_device
  * Verifies the AGP device hasn't been acquired before and calls
  * \c agp_backend_acquire.
  */
-int drm_agp_acquire(struct drm_device * dev)
+static int drm_agp_acquire_hook(struct drm_device * dev)
 {
 	if (!dev->agp)
 		return -ENODEV;
@@ -140,7 +140,7 @@ EXPORT_SYMBOL(drm_agp_acquire);
  * Verifies the AGP device hasn't been acquired before and calls
  * \c agp_backend_acquire.
  */
-int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_acquire_ioctl_hook(struct drm_device *dev, void *data,
 			  struct drm_file *file_priv)
 {
 	return drm_agp_acquire((struct drm_device *) file_priv->minor->dev);
@@ -154,7 +154,7 @@ int drm_agp_acquire_ioctl(struct drm_dev
  *
  * Verifies the AGP device has been acquired and calls \c agp_backend_release.
  */
-int drm_agp_release(struct drm_device * dev)
+static int drm_agp_release_hook(struct drm_device * dev)
 {
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
@@ -164,7 +164,7 @@ int drm_agp_release(struct drm_device * 
 }
 EXPORT_SYMBOL(drm_agp_release);
 
-int drm_agp_release_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_release_ioctl_hook(struct drm_device *dev, void *data,
 			  struct drm_file *file_priv)
 {
 	return drm_agp_release(dev);
@@ -180,7 +180,7 @@ int drm_agp_release_ioctl(struct drm_dev
  * Verifies the AGP device has been acquired but not enabled, and calls
  * \c agp_enable.
  */
-int drm_agp_enable(struct drm_device * dev, struct drm_agp_mode mode)
+static int drm_agp_enable_hook(struct drm_device * dev, struct drm_agp_mode mode)
 {
 	if (!dev->agp || !dev->agp->acquired)
 		return -EINVAL;
@@ -193,7 +193,7 @@ int drm_agp_enable(struct drm_device * d
 
 EXPORT_SYMBOL(drm_agp_enable);
 
-int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_enable_ioctl_hook(struct drm_device *dev, void *data,
 			 struct drm_file *file_priv)
 {
 	struct drm_agp_mode *mode = data;
@@ -213,7 +213,7 @@ int drm_agp_enable_ioctl(struct drm_devi
  * Verifies the AGP device is present and has been acquired, allocates the
  * memory via agp_allocate_memory() and creates a drm_agp_mem entry for it.
  */
-int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
+static int drm_agp_alloc_hook(struct drm_device *dev, struct drm_agp_buffer *request)
 {
 	struct drm_agp_mem *entry;
 	struct agp_memory *memory;
@@ -259,7 +259,7 @@ int drm_agp_alloc(struct drm_device *dev
 EXPORT_SYMBOL(drm_agp_alloc);
 
 
-int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_alloc_ioctl_hook(struct drm_device *dev, void *data,
 			struct drm_file *file_priv)
 {
 	struct drm_agp_buffer *request = data;
@@ -300,7 +300,7 @@ static struct drm_agp_mem *drm_agp_looku
  * Verifies the AGP device is present and acquired, looks-up the AGP memory
  * entry and passes it to the unbind_agp() function.
  */
-int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
+static int drm_agp_unbind_hook(struct drm_device *dev, struct drm_agp_binding *request)
 {
 	struct drm_agp_mem *entry;
 	int ret;
@@ -323,7 +323,7 @@ int drm_agp_unbind(struct drm_device *de
 EXPORT_SYMBOL(drm_agp_unbind);
 
 
-int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_unbind_ioctl_hook(struct drm_device *dev, void *data,
 			 struct drm_file *file_priv)
 {
 	struct drm_agp_binding *request = data;
@@ -344,7 +344,7 @@ int drm_agp_unbind_ioctl(struct drm_devi
  * is currently bound into the GATT. Looks-up the AGP memory entry and passes
  * it to bind_agp() function.
  */
-int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
+static int drm_agp_bind_hook(struct drm_device *dev, struct drm_agp_binding *request)
 {
 	struct drm_agp_mem *entry;
 	int retcode;
@@ -372,7 +372,7 @@ int drm_agp_bind(struct drm_device *dev,
 EXPORT_SYMBOL(drm_agp_bind);
 
 
-int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_bind_ioctl_hook(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv)
 {
 	struct drm_agp_binding *request = data;
@@ -394,7 +394,7 @@ int drm_agp_bind_ioctl(struct drm_device
  * unbind_agp(). Frees it via free_agp() as well as the entry itself
  * and unlinks from the doubly linked list it's inserted in.
  */
-int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
+static int drm_agp_free_hook(struct drm_device *dev, struct drm_agp_buffer *request)
 {
 	struct drm_agp_mem *entry;
 
@@ -423,7 +423,7 @@ EXPORT_SYMBOL(drm_agp_free);
 
 
 
-int drm_agp_free_ioctl(struct drm_device *dev, void *data,
+static int drm_agp_free_ioctl_hook(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv)
 {
 	struct drm_agp_buffer *request = data;
@@ -443,7 +443,7 @@ int drm_agp_free_ioctl(struct drm_device
  * Note that final cleanup of the kmalloced structure is directly done in
  * drm_pci_agp_destroy.
  */
-struct drm_agp_head *drm_agp_init(struct drm_device *dev)
+static struct drm_agp_head *drm_agp_init_hook(struct drm_device *dev)
 {
 	struct drm_agp_head *head = NULL;
 
@@ -492,7 +492,7 @@ struct drm_agp_head *drm_agp_init(struct
  * resources from getting destroyed. Drivers are responsible of cleaning them up
  * during device shutdown.
  */
-void drm_agp_clear(struct drm_device *dev)
+static void drm_agp_clear_hook(struct drm_device *dev)
 {
 	struct drm_agp_mem *entry, *tempe;
 
@@ -502,13 +502,13 @@ void drm_agp_clear(struct drm_device *de
 		return;
 
 	list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) {
-		if (entry->bound)
 #ifdef __NetBSD__
+		if (entry->bound)
 			drm_unbind_agp(dev->agp->bridge, entry->memory);
-#endif
-#ifdef __NetBSD__
 		drm_free_agp(dev->agp->bridge, entry->memory, entry->pages);
 #else
+		if (entry->bound)
+			drm_unbind_agp(entry->memory);
 		drm_free_agp(entry->memory, entry->pages);
 #endif
 		kfree(entry);
@@ -566,3 +566,110 @@ drm_agp_bind_pages(struct drm_device *de
 }
 EXPORT_SYMBOL(drm_agp_bind_pages);
 #endif
+
+#ifdef __NetBSD__
+
+static void __pci_iomem *
+drm_agp_borrow_hook(struct drm_device *dev, unsigned i, bus_size_t size)
+{
+	struct pci_dev *pdev = dev->pdev;
+
+	if (!agp_i810_borrow(pdev->pd_resources[i].addr, size,
+		&pdev->pd_resources[i].bsh))
+		return NULL;
+	/* XXX Synchronize with pci_iomap in linux_pci.c.  */
+	pdev->pd_resources[i].bst = pdev->pd_pa.pa_memt;
+	pdev->pd_resources[i].kva = bus_space_vaddr(pdev->pd_resources[i].bst,
+	    pdev->pd_resources[i].bsh);
+	pdev->pd_resources[i].mapped = true;
+
+	return pdev->pd_resources[i].kva;
+}
+
+static void
+drm_agp_flush_hook(void)
+{
+
+	agp_flush_cache();
+}
+
+static const struct drm_agp_hooks agp_hooks = {
+	.agph_info = drm_agp_info_hook,
+	.agph_info_ioctl = drm_agp_info_ioctl_hook,
+	.agph_acquire = drm_agp_acquire_hook,
+	.agph_acquire_ioctl = drm_agp_acquire_ioctl_hook,
+	.agph_release = drm_agp_release_hook,
+	.agph_release_ioctl = drm_agp_release_ioctl_hook,
+	.agph_enable = drm_agp_enable_hook,
+	.agph_enable_ioctl = drm_agp_enable_ioctl_hook,
+	.agph_alloc = drm_agp_alloc_hook,
+	.agph_alloc_ioctl = drm_agp_alloc_ioctl_hook,
+	.agph_unbind = drm_agp_unbind_hook,
+	.agph_unbind_ioctl = drm_agp_unbind_ioctl_hook,
+	.agph_bind = drm_agp_bind_hook,
+	.agph_bind_ioctl = drm_agp_bind_ioctl_hook,
+	.agph_free = drm_agp_free_hook,
+	.agph_free_ioctl = drm_agp_free_ioctl_hook,
+	.agph_init = drm_agp_init_hook,
+	.agph_clear = drm_agp_clear_hook,
+	.agph_borrow = drm_agp_borrow_hook,
+	.agph_flush = drm_agp_flush_hook,
+};
+
+#include <sys/module.h>
+#include <sys/once.h>
+
+MODULE(MODULE_CLASS_MISC, drmkms_agp, "drmkms"); /* XXX agp */
+
+static int
+drmkms_agp_init(void)
+{
+
+	return drm_agp_register(&agp_hooks);
+}
+
+int
+drmkms_agp_guarantee_initialized(void)
+{
+#ifdef _MODULE
+	return 0;
+#else
+	static ONCE_DECL(drmkms_agp_init_once);
+
+	return RUN_ONCE(&drmkms_agp_init_once, &drmkms_agp_init);
+#endif
+}
+
+static int
+drmkms_agp_fini(void)
+{
+
+	return drm_agp_deregister(&agp_hooks);
+}
+
+static int
+drmkms_agp_modcmd(modcmd_t cmd, void *arg __unused)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+#ifdef _MODULE
+		error = drmkms_agp_init();
+#else
+		error = drmkms_agp_guarantee_initialized();
+#endif
+		if (error)
+			return error;
+		return 0;
+	case MODULE_CMD_FINI:
+		error = drmkms_agp_fini();
+		if (error)
+			return error;
+		return 0;
+	default:
+		return ENOTTY;
+	}
+}
+
+#endif	/* __NetBSD__ */
Index: src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c
diff -u src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c:1.9 src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c:1.10
--- src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c:1.9	Mon Aug 27 15:22:53 2018
+++ src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_ioctl.c,v 1.9 2018/08/27 15:22:53 riastradh Exp $	*/
+/*	$NetBSD: drm_ioctl.c,v 1.10 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /*
  * Created: Fri Jan  8 09:01:26 1999 by [email protected]
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,v 1.9 2018/08/27 15:22:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,v 1.10 2018/08/28 03:41:38 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <drm/drm_core.h>
@@ -45,27 +45,6 @@ __KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,
 static int drm_version(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv);
 
-#if IS_ENABLED(CONFIG_AGP)
-/* XXX Kludge for AGP.  */
-static drm_ioctl_t	drm_agp_acquire_hook_ioctl;
-static drm_ioctl_t	drm_agp_release_hook_ioctl;
-static drm_ioctl_t	drm_agp_enable_hook_ioctl;
-static drm_ioctl_t	drm_agp_info_hook_ioctl;
-static drm_ioctl_t	drm_agp_alloc_hook_ioctl;
-static drm_ioctl_t	drm_agp_free_hook_ioctl;
-static drm_ioctl_t	drm_agp_bind_hook_ioctl;
-static drm_ioctl_t	drm_agp_unbind_hook_ioctl;
-
-#define	drm_agp_acquire_ioctl	drm_agp_acquire_hook_ioctl
-#define	drm_agp_release_ioctl	drm_agp_release_hook_ioctl
-#define	drm_agp_enable_ioctl	drm_agp_enable_hook_ioctl
-#define	drm_agp_info_ioctl	drm_agp_info_hook_ioctl
-#define	drm_agp_alloc_ioctl	drm_agp_alloc_hook_ioctl
-#define	drm_agp_free_ioctl	drm_agp_free_hook_ioctl
-#define	drm_agp_bind_ioctl	drm_agp_bind_hook_ioctl
-#define	drm_agp_unbind_ioctl	drm_agp_unbind_hook_ioctl
-#endif
-
 /*
  * Get the bus id.
  *
@@ -135,7 +114,10 @@ static int drm_setunique(struct drm_devi
 	if (WARN_ON(!dev->pdev))
 		return -EINVAL;
 
-	ret = drm_pci_set_unique(dev, master, u);
+	if (!dev->driver->set_unique)
+		return -ENODEV;
+
+	ret = dev->driver->set_unique(dev, master, u);
 	if (ret)
 		goto err;
 
@@ -937,92 +919,3 @@ bool drm_ioctl_flags(unsigned int nr, un
 	return true;
 }
 EXPORT_SYMBOL(drm_ioctl_flags);
-
-/* XXX Kludge to allow agp to be implemented in another kernel module.  */
-#ifdef __NetBSD__
-
-#include <sys/atomic.h>
-
-static const struct drm_agp_hooks *volatile drm_current_agp_hooks;
-
-int
-drm_agp_register(const struct drm_agp_hooks *hooks)
-{
-
-	membar_producer();
-	if (atomic_cas_ptr(&drm_current_agp_hooks, NULL, __UNCONST(hooks))
-	    != NULL)
-		return EBUSY;
-
-	return 0;
-}
-
-void
-drm_agp_deregister(const struct drm_agp_hooks *hooks)
-{
-
-	if (atomic_cas_ptr(&drm_current_agp_hooks, __UNCONST(hooks), NULL)
-	    != hooks)
-		panic("%s: wrong hooks: %p != %p", __func__,
-		    hooks, drm_current_agp_hooks);
-}
-
-static void __dead
-drm_noagp_panic(struct drm_device *dev)
-{
-	if ((dev != NULL) &&
-	    (dev->control != NULL) &&
-	    (dev->control->kdev != NULL))
-		panic("%s: no agp loaded", device_xname(dev->control->kdev));
-	else
-		panic("drm_device %p: no agp loaded", dev);
-}
-
-int
-drm_agp_release_hook(struct drm_device *dev)
-{
-	const struct drm_agp_hooks *const hooks = drm_current_agp_hooks;
-
-	if (hooks == NULL)
-		drm_noagp_panic(dev);
-	membar_consumer();
-	return (*hooks->agph_release)(dev);
-}
-
-void
-drm_agp_clear_hook(struct drm_device *dev)
-{
-	const struct drm_agp_hooks *const hooks = drm_current_agp_hooks;
-
-	if (hooks == NULL)
-		drm_noagp_panic(dev);
-	membar_consumer();
-	(*hooks->agph_clear)(dev);
-}
-
-#if IS_ENABLED(CONFIG_AGP)
-
-#define	DEFINE_AGP_HOOK_IOCTL(NAME, HOOK)				      \
-static int								      \
-NAME(struct drm_device *dev, void *data, struct drm_file *file)		      \
-{									      \
-	const struct drm_agp_hooks *const hooks = drm_current_agp_hooks;      \
-									      \
-	if (hooks == NULL)						      \
-		return -ENODEV;						      \
-	membar_consumer();						      \
-	return (*hooks->HOOK)(dev, data, file);				      \
-}
-
-DEFINE_AGP_HOOK_IOCTL(drm_agp_acquire_hook_ioctl, agph_acquire_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_release_hook_ioctl, agph_release_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_enable_hook_ioctl, agph_enable_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_info_hook_ioctl, agph_info_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_alloc_hook_ioctl, agph_alloc_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_free_hook_ioctl, agph_free_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_bind_hook_ioctl, agph_bind_ioctl)
-DEFINE_AGP_HOOK_IOCTL(drm_agp_unbind_hook_ioctl, agph_unbind_ioctl)
-
-#endif
-
-#endif

Index: src/sys/external/bsd/drm2/dist/drm/drm_internal.h
diff -u src/sys/external/bsd/drm2/dist/drm/drm_internal.h:1.4 src/sys/external/bsd/drm2/dist/drm/drm_internal.h:1.5
--- src/sys/external/bsd/drm2/dist/drm/drm_internal.h:1.4	Mon Aug 27 15:31:27 2018
+++ src/sys/external/bsd/drm2/dist/drm/drm_internal.h	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_internal.h,v 1.4 2018/08/27 15:31:27 riastradh Exp $	*/
+/*	$NetBSD: drm_internal.h,v 1.5 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /*
  * Copyright © 2014 Intel Corporation
@@ -37,13 +37,6 @@ int drm_pci_set_unique(struct drm_device
 int drm_irq_by_busid(struct drm_device *dev, void *data,
 		     struct drm_file *file_priv);
 
-#ifdef __NetBSD__
-int drm_pci_set_unique_impl(struct drm_device *, struct drm_master *,
-    struct drm_unique *);
-void drm_pci_set_unique_hook(int (**)(struct drm_device *, struct drm_master *,
-	struct drm_unique *));
-#endif
-
 /* drm_vm.c */
 #ifndef __NetBSD__
 int drm_vma_info(struct seq_file *m, void *data);

Index: src/sys/external/bsd/drm2/dist/drm/ast/ast_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/ast/ast_drv.c:1.2 src/sys/external/bsd/drm2/dist/drm/ast/ast_drv.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/ast/ast_drv.c:1.2	Mon Aug 27 04:58:23 2018
+++ src/sys/external/bsd/drm2/dist/drm/ast/ast_drv.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ast_drv.c,v 1.2 2018/08/27 04:58:23 riastradh Exp $	*/
+/*	$NetBSD: ast_drv.c,v 1.3 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -28,7 +28,7 @@
  * Authors: Dave Airlie <[email protected]>
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ast_drv.c,v 1.2 2018/08/27 04:58:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ast_drv.c,v 1.3 2018/08/28 03:41:38 riastradh Exp $");
 
 #include <linux/module.h>
 #include <linux/console.h>
@@ -205,6 +205,7 @@ static struct drm_driver driver = {
 	.load = ast_driver_load,
 	.unload = ast_driver_unload,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 
 	.fops = &ast_fops,
 	.name = DRIVER_NAME,

Index: src/sys/external/bsd/drm2/dist/drm/i810/i810_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/i810/i810_drv.c:1.2 src/sys/external/bsd/drm2/dist/drm/i810/i810_drv.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/i810/i810_drv.c:1.2	Mon Aug 27 04:58:23 2018
+++ src/sys/external/bsd/drm2/dist/drm/i810/i810_drv.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i810_drv.c,v 1.2 2018/08/27 04:58:23 riastradh Exp $	*/
+/*	$NetBSD: i810_drv.c,v 1.3 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /* i810_drv.c -- I810 driver -*- linux-c -*-
  * Created: Mon Dec 13 01:56:22 1999 by [email protected]
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i810_drv.c,v 1.2 2018/08/27 04:58:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i810_drv.c,v 1.3 2018/08/28 03:41:38 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -69,6 +69,7 @@ static struct drm_driver driver = {
 	.lastclose = i810_driver_lastclose,
 	.preclose = i810_driver_preclose,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.device_is_agp = i810_driver_device_is_agp,
 	.dma_quiescent = i810_driver_dma_quiescent,
 	.ioctls = i810_ioctls,

Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c:1.24 src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c:1.25
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c:1.24	Mon Aug 27 14:47:02 2018
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_dma.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_dma.c,v 1.24 2018/08/27 14:47:02 riastradh Exp $	*/
+/*	$NetBSD: i915_dma.c,v 1.25 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
  */
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_dma.c,v 1.24 2018/08/27 14:47:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_dma.c,v 1.25 2018/08/28 03:41:38 riastradh Exp $");
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
@@ -967,6 +967,10 @@ int i915_driver_load(struct drm_device *
 		mmio_size = 2*1024*1024;
 
 	dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, mmio_size);
+#ifdef __NetBSD__
+	if (!dev_priv->regs)
+		dev_priv->regs = drm_agp_borrow(dev, mmio_bar, mmio_size);
+#endif
 	if (!dev_priv->regs) {
 		DRM_ERROR("failed to map registers\n");
 		ret = -EIO;

Index: src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c:1.3 src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c:1.3	Mon Aug 27 07:03:25 2018
+++ src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mga_drv.c,v 1.3 2018/08/27 07:03:25 riastradh Exp $	*/
+/*	$NetBSD: mga_drv.c,v 1.4 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
  * Created: Mon Dec 13 01:56:22 1999 by [email protected]
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mga_drv.c,v 1.3 2018/08/27 07:03:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mga_drv.c,v 1.4 2018/08/28 03:41:38 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -70,6 +70,7 @@ static struct drm_driver driver = {
 	.unload = mga_driver_unload,
 	.lastclose = mga_driver_lastclose,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.dma_quiescent = mga_driver_dma_quiescent,
 	.device_is_agp = mga_driver_device_is_agp,
 	.get_vblank_counter = mga_get_vblank_counter,

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/agp.h
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/agp.h:1.2 src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/agp.h:1.3
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/agp.h:1.2	Mon Aug 27 04:58:34 2018
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/agp.h	Tue Aug 28 03:41:38 2018
@@ -1,7 +1,7 @@
-/*	$NetBSD: agp.h,v 1.2 2018/08/27 04:58:34 riastradh Exp $	*/
+/*	$NetBSD: agp.h,v 1.3 2018/08/28 03:41:38 riastradh Exp $	*/
 
 #include "priv.h"
-#if defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE))
+#if 0 && (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE))) /* XXX nouveau agp */
 #ifndef __NVKM_PCI_AGP_H__
 #define __NVKM_PCI_AGP_H__
 

Index: src/sys/external/bsd/drm2/dist/drm/qxl/qxl_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/qxl/qxl_drv.c:1.3 src/sys/external/bsd/drm2/dist/drm/qxl/qxl_drv.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/qxl/qxl_drv.c:1.3	Mon Aug 27 07:03:26 2018
+++ src/sys/external/bsd/drm2/dist/drm/qxl/qxl_drv.c	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: qxl_drv.c,v 1.3 2018/08/27 07:03:26 riastradh Exp $	*/
+/*	$NetBSD: qxl_drv.c,v 1.4 2018/08/28 03:41:38 riastradh Exp $	*/
 
 /* vim: set ts=8 sw=8 tw=78 ai noexpandtab */
 /* qxl_drv.c -- QXL driver -*- linux-c -*-
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: qxl_drv.c,v 1.3 2018/08/27 07:03:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: qxl_drv.c,v 1.4 2018/08/28 03:41:38 riastradh Exp $");
 
 #include <linux/module.h>
 #include <linux/console.h>
@@ -242,6 +242,7 @@ static struct drm_driver qxl_driver = {
 	.disable_vblank = qxl_noop_disable_vblank,
 
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 
 	.dumb_create = qxl_mode_dumb_create,
 	.dumb_map_offset = qxl_mode_dumb_mmap,

Index: src/sys/external/bsd/drm2/dist/drm/r128/r128_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/r128/r128_drv.c:1.3 src/sys/external/bsd/drm2/dist/drm/r128/r128_drv.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/r128/r128_drv.c:1.3	Mon Aug 27 07:03:26 2018
+++ src/sys/external/bsd/drm2/dist/drm/r128/r128_drv.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: r128_drv.c,v 1.3 2018/08/27 07:03:26 riastradh Exp $	*/
+/*	$NetBSD: r128_drv.c,v 1.4 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
  * Created: Mon Dec 13 09:47:27 1999 by [email protected]
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: r128_drv.c,v 1.3 2018/08/27 07:03:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: r128_drv.c,v 1.4 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -68,6 +68,7 @@ static struct drm_driver driver = {
 	.preclose = r128_driver_preclose,
 	.lastclose = r128_driver_lastclose,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.get_vblank_counter = r128_get_vblank_counter,
 	.enable_vblank = r128_enable_vblank,
 	.disable_vblank = r128_disable_vblank,

Index: src/sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c:1.8 src/sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c:1.9
--- src/sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c:1.8	Mon Aug 27 15:22:54 2018
+++ src/sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeon_drv.c,v 1.8 2018/08/27 15:22:54 riastradh Exp $	*/
+/*	$NetBSD: radeon_drv.c,v 1.9 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /**
  * \file radeon_drv.c
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: radeon_drv.c,v 1.8 2018/08/27 15:22:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeon_drv.c,v 1.9 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <drm/drmP.h>
 #include <drm/radeon_drm.h>
@@ -361,6 +361,7 @@ static struct drm_driver driver_old = {
 	.postclose = radeon_driver_postclose,
 	.lastclose = radeon_driver_lastclose,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.unload = radeon_driver_unload,
 	.suspend = radeon_suspend,
 	.resume = radeon_resume,

Index: src/sys/external/bsd/drm2/dist/drm/savage/savage_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/savage/savage_drv.c:1.2 src/sys/external/bsd/drm2/dist/drm/savage/savage_drv.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/savage/savage_drv.c:1.2	Mon Aug 27 04:58:36 2018
+++ src/sys/external/bsd/drm2/dist/drm/savage/savage_drv.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: savage_drv.c,v 1.2 2018/08/27 04:58:36 riastradh Exp $	*/
+/*	$NetBSD: savage_drv.c,v 1.3 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /* savage_drv.c -- Savage driver for Linux
  *
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: savage_drv.c,v 1.2 2018/08/27 04:58:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: savage_drv.c,v 1.3 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -63,6 +63,7 @@ static struct drm_driver driver = {
 	.lastclose = savage_driver_lastclose,
 	.unload = savage_driver_unload,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.ioctls = savage_ioctls,
 	.dma_ioctl = savage_bci_buffers,
 	.fops = &savage_driver_fops,

Index: src/sys/external/bsd/drm2/dist/drm/sis/sis_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/sis/sis_drv.c:1.2 src/sys/external/bsd/drm2/dist/drm/sis/sis_drv.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/sis/sis_drv.c:1.2	Mon Aug 27 04:58:36 2018
+++ src/sys/external/bsd/drm2/dist/drm/sis/sis_drv.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sis_drv.c,v 1.2 2018/08/27 04:58:36 riastradh Exp $	*/
+/*	$NetBSD: sis_drv.c,v 1.3 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /* sis.c -- sis driver -*- linux-c -*-
  *
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sis_drv.c,v 1.2 2018/08/27 04:58:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sis_drv.c,v 1.3 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -114,6 +114,7 @@ static struct drm_driver driver = {
 	.preclose = sis_reclaim_buffers_locked,
 	.postclose = sis_driver_postclose,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.dma_quiescent = sis_idle,
 	.lastclose = sis_lastclose,
 	.ioctls = sis_ioctls,

Index: src/sys/external/bsd/drm2/dist/drm/tdfx/tdfx_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/tdfx/tdfx_drv.c:1.2 src/sys/external/bsd/drm2/dist/drm/tdfx/tdfx_drv.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/tdfx/tdfx_drv.c:1.2	Mon Aug 27 04:58:37 2018
+++ src/sys/external/bsd/drm2/dist/drm/tdfx/tdfx_drv.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tdfx_drv.c,v 1.2 2018/08/27 04:58:37 riastradh Exp $	*/
+/*	$NetBSD: tdfx_drv.c,v 1.3 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /* tdfx_drv.c -- tdfx driver -*- linux-c -*-
  * Created: Thu Oct  7 10:38:32 1999 by [email protected]
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tdfx_drv.c,v 1.2 2018/08/27 04:58:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tdfx_drv.c,v 1.3 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -62,6 +62,7 @@ static const struct file_operations tdfx
 
 static struct drm_driver driver = {
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.fops = &tdfx_driver_fops,
 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,

Index: src/sys/external/bsd/drm2/dist/drm/via/via_drv.c
diff -u src/sys/external/bsd/drm2/dist/drm/via/via_drv.c:1.6 src/sys/external/bsd/drm2/dist/drm/via/via_drv.c:1.7
--- src/sys/external/bsd/drm2/dist/drm/via/via_drv.c:1.6	Mon Aug 27 07:51:06 2018
+++ src/sys/external/bsd/drm2/dist/drm/via/via_drv.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: via_drv.c,v 1.6 2018/08/27 07:51:06 riastradh Exp $	*/
+/*	$NetBSD: via_drv.c,v 1.7 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*
  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: via_drv.c,v 1.6 2018/08/27 07:51:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: via_drv.c,v 1.7 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <linux/module.h>
 
@@ -87,6 +87,7 @@ static struct drm_driver driver = {
 	.preclose = via_reclaim_buffers_locked,
 	.postclose = via_driver_postclose,
 	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
 	.context_dtor = via_final_context,
 	.get_vblank_counter = via_get_vblank_counter,
 	.enable_vblank = via_enable_vblank,

Index: src/sys/external/bsd/drm2/dist/include/drm/drmP.h
diff -u src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.33 src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.34
--- src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.33	Tue Aug 28 03:35:08 2018
+++ src/sys/external/bsd/drm2/dist/include/drm/drmP.h	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drmP.h,v 1.33 2018/08/28 03:35:08 riastradh Exp $	*/
+/*	$NetBSD: drmP.h,v 1.34 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*
  * Internal Header for the Direct Rendering Manager
@@ -470,6 +470,8 @@ struct drm_driver {
 	int (*dma_quiescent) (struct drm_device *);
 	int (*context_dtor) (struct drm_device *dev, int context);
 	int (*set_busid)(struct drm_device *dev, struct drm_master *master);
+	int (*set_unique)(struct drm_device *dev, struct drm_master *master,
+	    struct drm_unique *);
 
 	/**
 	 * get_vblank_counter - get raw hardware vblank counter
@@ -1118,27 +1120,6 @@ static inline wait_queue_head_t *drm_crt
 extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
 extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
 
-#ifdef __NetBSD__
-struct drm_agp_hooks {
-	drm_ioctl_t	*agph_acquire_ioctl;
-	drm_ioctl_t	*agph_release_ioctl;
-	drm_ioctl_t	*agph_enable_ioctl;
-	drm_ioctl_t	*agph_info_ioctl;
-	drm_ioctl_t	*agph_alloc_ioctl;
-	drm_ioctl_t	*agph_free_ioctl;
-	drm_ioctl_t	*agph_bind_ioctl;
-	drm_ioctl_t	*agph_unbind_ioctl;
-	int		(*agph_release)(struct drm_device *);
-	void		(*agph_clear)(struct drm_device *);
-};
-
-extern int drm_agp_release_hook(struct drm_device *);
-extern void drm_agp_clear_hook(struct drm_device *);
-
-extern int drm_agp_register(const struct drm_agp_hooks *);
-extern void drm_agp_deregister(const struct drm_agp_hooks *);
-#endif
-
 				/* Stub support (drm_stub.h) */
 extern struct drm_master *drm_master_get(struct drm_master *master);
 extern void drm_master_put(struct drm_master **master);
@@ -1198,16 +1179,12 @@ extern struct sg_table *drm_prime_pages_
 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
 
 
+int drm_pci_set_unique(struct drm_device *dev,
+		       struct drm_master *master,
+		       struct drm_unique *u);
 extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
 					    size_t align);
 extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
-#ifdef __NetBSD__
-extern int drmkms_pci_agp_guarantee_initialized(void);
-extern int drm_pci_attach(device_t, const struct pci_attach_args *,
-    struct pci_dev *, struct drm_driver *, unsigned long,
-    struct drm_device **);
-extern int drm_pci_detach(struct drm_device *, int);
-#endif
 
 			       /* sysfs support (drm_sysfs.c) */
 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
@@ -1251,6 +1228,10 @@ extern void drm_pci_exit(struct drm_driv
 #ifdef __NetBSD__
 int drm_pci_request_irq(struct drm_device *, int);
 void drm_pci_free_irq(struct drm_device *);
+extern int drm_pci_attach(device_t, const struct pci_attach_args *,
+    struct pci_dev *, struct drm_driver *, unsigned long,
+    struct drm_device **);
+extern int drm_pci_detach(struct drm_device *, int);
 #endif
 #ifdef CONFIG_PCI
 extern int drm_get_pci_dev(struct pci_dev *pdev,

Index: src/sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h
diff -u src/sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h:1.7 src/sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h:1.8
--- src/sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h:1.7	Mon Aug 27 07:44:52 2018
+++ src/sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_agpsupport.h,v 1.7 2018/08/27 07:44:52 riastradh Exp $	*/
+/*	$NetBSD: drm_agpsupport.h,v 1.8 2018/08/28 03:41:39 riastradh Exp $	*/
 
 #ifndef _DRM_AGPSUPPORT_H_
 #define _DRM_AGPSUPPORT_H_
@@ -18,7 +18,43 @@
 struct drm_device;
 struct drm_file;
 
+struct drm_agp_hooks {
+	void __pci_iomem *
+		(*agph_borrow)(struct drm_device *, unsigned, bus_size_t);
+	void	(*agph_flush)(void);
+
+	struct drm_agp_head *
+		(*agph_init)(struct drm_device *);
+	void	(*agph_clear)(struct drm_device *);
+	int	(*agph_acquire)(struct drm_device *);
+	int	(*agph_release)(struct drm_device *);
+	int	(*agph_enable)(struct drm_device *, struct drm_agp_mode);
+	int	(*agph_info)(struct drm_device *, struct drm_agp_info *);
+	int	(*agph_alloc)(struct drm_device *, struct drm_agp_buffer *);
+	int	(*agph_free)(struct drm_device *, struct drm_agp_buffer *);
+	int	(*agph_bind)(struct drm_device *, struct drm_agp_binding *);
+	int	(*agph_unbind)(struct drm_device *, struct drm_agp_binding *);
+
+	int	(*agph_acquire_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_release_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_enable_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_info_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_alloc_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_free_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_bind_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+	int	(*agph_unbind_ioctl)(struct drm_device *, void *,
+		    struct drm_file *);
+};
+
 struct drm_agp_head {
+	const struct drm_agp_hooks *hooks;
 	struct agp_kern_info agp_info;
 	struct list_head memory;
 	unsigned long mode;
@@ -75,6 +111,17 @@ int drm_agp_bind(struct drm_device *dev,
 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
 		       struct drm_file *file_priv);
 
+#ifdef __NetBSD__
+void __pci_iomem *drm_agp_borrow(struct drm_device *, unsigned, bus_size_t);
+void drm_agp_flush(void);
+void drm_agp_fini(struct drm_device *);
+int drm_agp_register(const struct drm_agp_hooks *);
+int drm_agp_deregister(const struct drm_agp_hooks *);
+void drm_agp_hooks_init(void);
+void drm_agp_hooks_fini(void);
+int drmkms_agp_guarantee_initialized(void);
+#endif
+
 #else /* CONFIG_AGP */
 
 #if !defined(__NetBSD__)

Index: src/sys/external/bsd/drm2/drm/drm_cdevsw.c
diff -u src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.11 src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.12
--- src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.11	Tue Aug 28 03:35:08 2018
+++ src/sys/external/bsd/drm2/drm/drm_cdevsw.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_cdevsw.c,v 1.11 2018/08/28 03:35:08 riastradh Exp $	*/
+/*	$NetBSD: drm_cdevsw.c,v 1.12 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.11 2018/08/28 03:35:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.12 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -251,7 +251,7 @@ drm_lastclose(struct drm_device *dev)
 
 	mutex_lock(&dev->struct_mutex);
 	if (dev->agp)
-		drm_agp_clear_hook(dev);
+		drm_agp_clear(dev);
 	drm_legacy_sg_cleanup(dev);
 	drm_legacy_dma_takedown(dev);
 	mutex_unlock(&dev->struct_mutex);

Index: src/sys/external/bsd/drm2/drm/drm_module.c
diff -u src/sys/external/bsd/drm2/drm/drm_module.c:1.14 src/sys/external/bsd/drm2/drm/drm_module.c:1.15
--- src/sys/external/bsd/drm2/drm/drm_module.c:1.14	Tue Aug 28 03:35:08 2018
+++ src/sys/external/bsd/drm2/drm/drm_module.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_module.c,v 1.14 2018/08/28 03:35:08 riastradh Exp $	*/
+/*	$NetBSD: drm_module.c,v 1.15 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.14 2018/08/28 03:35:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.15 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/condvar.h>
@@ -38,9 +38,7 @@ __KERNEL_RCSID(0, "$NetBSD: drm_module.c
 #include <sys/device.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
-#ifndef _MODULE
 #include <sys/once.h>
-#endif
 #include <sys/reboot.h>
 #include <sys/systm.h>
 
@@ -52,6 +50,42 @@ __KERNEL_RCSID(0, "$NetBSD: drm_module.c
 #include <drm/drm_sysctl.h>
 
 /*
+ * XXX This is stupid.
+ *
+ * 1. Builtin modules are broken: they don't get initialized before
+ *    autoconf matches devices, but we need the initialization to be
+ *    run in order to match and attach drmkms drivers.
+ *
+ * 2. The following dependencies are _not_ correct:
+ *    - drmkms can't depend on agp because not all drmkms drivers run
+ *      on platforms guaranteed to have pci, let alone agp
+ *    - drmkms_pci can't depend on agp because not all _pci_ has agp
+ *      (e.g., tegra)
+ *    - radeon (e.g.) can't depend on agp because not all radeon
+ *      devices are on platforms guaranteed to have agp
+ *
+ * 3. We need to register the agp hooks before we try to attach a
+ *    device.
+ *
+ * 4. The only mechanism we have to force this is the
+ *    mumblefrotz_guarantee_initialized kludge.
+ *
+ * 5. We don't know if we even _can_ call
+ *    drmkms_agp_guarantee_initialized unless we know NAGP.
+ *
+ * 6. We don't know NAGP unless we include "agp.h".
+ *
+ * 7. We can't include "agp.h" if the platform has agp.
+ *
+ * 8. The way we determine whether we have agp is NAGP.
+ *
+ * 9. @!*#&^@&*@!&^#@
+ */
+#if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
+#include "agp.h"
+#endif
+
+/*
  * XXX I2C stuff should be moved to a separate drmkms_i2c module.
  */
 MODULE(MODULE_CLASS_DRIVER, drmkms, "drmkms_linux");
@@ -60,14 +94,6 @@ struct mutex	drm_global_mutex;
 
 struct drm_sysctl_def drm_def = DRM_SYSCTL_INIT();
 
-static struct {
-	kmutex_t		lock;
-	kcondvar_t		cv;
-	unsigned		refcnt;
-	int			(*hook)(struct drm_device *,
-				    struct drm_master *, struct drm_unique *);
-} set_unique_hook __cacheline_aligned;
-
 static int
 drm_init(void)
 {
@@ -78,13 +104,22 @@ drm_init(void)
 	if (error)
 		return error;
 
+	drm_agp_hooks_init();
+#if NAGP > 0
+	extern int drmkms_agp_guarantee_initialized(void);
+	error = drmkms_agp_guarantee_initialized();
+	if (error) {
+		drm_agp_hooks_fini();
+		return error;
+	}
+#endif
+
 	if (ISSET(boothowto, AB_DEBUG))
 		drm_debug = ~(unsigned int)0;
 
 	spin_lock_init(&drm_minor_lock);
 	idr_init(&drm_minors_idr);
 	linux_mutex_init(&drm_global_mutex);
-	mutex_init(&set_unique_hook.lock, MUTEX_DEFAULT, IPL_NONE);
 	drm_connector_ida_init();
 	drm_global_init();
 	drm_sysctl_init(&drm_def);
@@ -113,10 +148,10 @@ drm_fini(void)
 	drm_sysctl_fini(&drm_def);
 	drm_global_release();
 	drm_connector_ida_destroy();
-	mutex_destroy(&set_unique_hook.lock);
 	linux_mutex_destroy(&drm_global_mutex);
 	idr_destroy(&drm_minors_idr);
 	spin_lock_destroy(&drm_minor_lock);
+	drm_agp_hooks_fini();
 }
 
 int
@@ -126,50 +161,6 @@ drm_irq_by_busid(struct drm_device *dev,
 	return -ENODEV;
 }
 
-/* XXX Stupid kludge...  */
-
-void
-drm_pci_set_unique_hook(int (**hook)(struct drm_device *, struct drm_master *,
-	struct drm_unique *))
-{
-	int (*old)(struct drm_device *, struct drm_master *,
-	    struct drm_unique *);
-
-	mutex_enter(&set_unique_hook.lock);
-	while (set_unique_hook.refcnt)
-		cv_wait(&set_unique_hook.cv, &set_unique_hook.lock);
-	old = set_unique_hook.hook;
-	set_unique_hook.hook = *hook;
-	*hook = old;
-	mutex_exit(&set_unique_hook.lock);
-}
-
-int
-drm_pci_set_unique(struct drm_device *dev, struct drm_master *master,
-    struct drm_unique *unique)
-{
-	int ret;
-
-	mutex_enter(&set_unique_hook.lock);
-	while (set_unique_hook.refcnt == UINT_MAX)
-		cv_wait(&set_unique_hook.cv, &set_unique_hook.lock);
-	set_unique_hook.refcnt++;
-	mutex_exit(&set_unique_hook.lock);
-
-	if (set_unique_hook.hook)
-		ret = set_unique_hook.hook(dev, master, unique);
-	else
-		ret = -ENODEV;
-
-	mutex_enter(&set_unique_hook.lock);
-	if (set_unique_hook.refcnt-- == UINT_MAX ||
-	    set_unique_hook.refcnt == 0)
-		cv_broadcast(&set_unique_hook.cv);
-	mutex_exit(&set_unique_hook.lock);
-
-	return ret;
-}
-
 static int
 drmkms_modcmd(modcmd_t cmd, void *arg __unused)
 {

Index: src/sys/external/bsd/drm2/drm/files.drmkms
diff -u src/sys/external/bsd/drm2/drm/files.drmkms:1.29 src/sys/external/bsd/drm2/drm/files.drmkms:1.30
--- src/sys/external/bsd/drm2/drm/files.drmkms:1.29	Mon Aug 27 15:29:42 2018
+++ src/sys/external/bsd/drm2/drm/files.drmkms	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.drmkms,v 1.29 2018/08/27 15:29:42 riastradh Exp $
+#	$NetBSD: files.drmkms,v 1.30 2018/08/28 03:41:39 riastradh Exp $
 
 include "external/bsd/drm2/linux/files.drmkms_linux"
 
@@ -38,6 +38,7 @@ makeoptions	drmkms	CPPFLAGS+="-DCONFIG_D
 makeoptions	drmkms	CPPFLAGS+="-DCONFIG_FB=0"
 
 # NetBSD additions.
+file	external/bsd/drm2/drm/drm_agp_hook.c		drmkms
 file	external/bsd/drm2/drm/drm_cdevsw.c		drmkms
 file	external/bsd/drm2/drm/drm_gem_cma_helper.c	drmkms
 file	external/bsd/drm2/drm/drm_gem_vm.c		drmkms

Index: src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h
diff -u src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h:1.7 src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h:1.8
--- src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h:1.7	Mon Aug 27 13:55:24 2018
+++ src/sys/external/bsd/drm2/include/drm/drm_agp_netbsd.h	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_agp_netbsd.h,v 1.7 2018/08/27 13:55:24 riastradh Exp $	*/
+/*	$NetBSD: drm_agp_netbsd.h,v 1.8 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -49,18 +49,7 @@
 
 #define	PCI_AGP_COMMAND_FW	AGPCMD_FWEN
 
-#if defined(__i386__) || defined(__x86_64__)
-#if defined(_KERNEL_OPT)
-#include "agp.h"
-#else
-#define NAGP 1
-#endif
-#if NAGP > 0
 #define	CONFIG_AGP	1
-#endif
-__CTASSERT(PAGE_SIZE == AGP_PAGE_SIZE);
-__CTASSERT(PAGE_SHIFT == AGP_PAGE_SHIFT);
-#endif
 
 struct agp_kern_info {
 	struct agp_info aki_info;

Index: src/sys/external/bsd/drm2/include/drm/drm_os_netbsd.h
diff -u src/sys/external/bsd/drm2/include/drm/drm_os_netbsd.h:1.12 src/sys/external/bsd/drm2/include/drm/drm_os_netbsd.h:1.13
--- src/sys/external/bsd/drm2/include/drm/drm_os_netbsd.h:1.12	Mon Aug 27 16:20:35 2018
+++ src/sys/external/bsd/drm2/include/drm/drm_os_netbsd.h	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_os_netbsd.h,v 1.12 2018/08/27 16:20:35 riastradh Exp $	*/
+/*	$NetBSD: drm_os_netbsd.h,v 1.13 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -41,13 +41,11 @@
 #define	CONFIG_X86_PAT	1
 #endif
 
-#if defined(_KERNEL_OPT)
-#include "pci.h"
-#endif
-
-#if NPCI > 0
+/*
+ * Nothing meaningfully depends on this; defining this avoids patching
+ * away some conditionalization in drmP.h.
+ */
 #define	CONFIG_PCI	1
-#endif
 
 #ifdef notyet
 #if defined(__i386__)

Index: src/sys/external/bsd/drm2/linux/linux_pci.c
diff -u src/sys/external/bsd/drm2/linux/linux_pci.c:1.5 src/sys/external/bsd/drm2/linux/linux_pci.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.5	Mon Aug 27 15:12:21 2018
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.5 2018/08/27 15:12:21 riastradh Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.6 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.5 2018/08/27 15:12:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.6 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <linux/pci.h>
 
@@ -607,16 +607,9 @@ pci_iomap(struct pci_dev *pdev, unsigned
 	error = bus_space_map(pdev->pd_pa.pa_memt, pdev->pd_resources[i].addr,
 	    size, BUS_SPACE_MAP_LINEAR | pdev->pd_resources[i].flags,
 	    &pdev->pd_resources[i].bsh);
-	if (error) {
-#ifdef CONFIG_AGP
-		/* Horrible hack: try asking the fake AGP device.  */
-		if (!agp_i810_borrow(pdev->pd_resources[i].addr, size,
-			&pdev->pd_resources[i].bsh))
-			return NULL;
-#else
+	if (error)
 		return NULL;
-#endif
-	}
+	/* XXX Synchronize with drm_agp_borrow_hook in drm_agpsupport.c.  */
 	pdev->pd_resources[i].bst = pdev->pd_pa.pa_memt;
 	pdev->pd_resources[i].kva = bus_space_vaddr(pdev->pd_resources[i].bst,
 	    pdev->pd_resources[i].bsh);

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.30 src/sys/external/bsd/drm2/pci/drm_pci.c:1.31
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.30	Tue Aug 28 03:34:39 2018
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.30 2018/08/28 03:34:39 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.31 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.30 2018/08/28 03:34:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.31 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/errno.h>
@@ -39,7 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 
 #include <dev/pci/pcivar.h>
 
 #include <drm/drmP.h>
-#include <drm/drm_internal.h>
 #include <drm/drm_legacy.h>
 
 struct drm_bus_irq_cookie {
@@ -62,9 +61,9 @@ drm_pci_attach(device_t self, const stru
 	unsigned int unit;
 	int ret;
 
-	/* Ensure the drm agp hooks are installed.  */
+	/* Ensure the drm agp hooks are initialized.  */
 	/* XXX errno NetBSD->Linux */
-	ret = -drmkms_pci_agp_guarantee_initialized();
+	ret = -drm_guarantee_initialized();
 	if (ret)
 		goto fail0;
 
@@ -178,9 +177,8 @@ drm_pci_agp_destroy(struct drm_device *d
 
 	if (dev->agp) {
 		arch_phys_wc_del(dev->agp->agp_mtrr);
-		drm_agp_clear(dev);
-		kfree(dev->agp); /* XXX Should go in drm_agp_clear...  */
-		dev->agp = NULL;
+		drm_agp_fini(dev);
+		KASSERT(dev->agp == NULL);
 	}
 }
 
@@ -264,7 +262,7 @@ drm_pci_set_busid(struct drm_device *dev
 }
 
 int
-drm_pci_set_unique_impl(struct drm_device *dev, struct drm_master *master,
+drm_pci_set_unique(struct drm_device *dev, struct drm_master *master,
     struct drm_unique *unique)
 {
 	char kbuf[64], ubuf[64];

Index: src/sys/external/bsd/drm2/pci/drm_pci_module.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci_module.c:1.6 src/sys/external/bsd/drm2/pci/drm_pci_module.c:1.7
--- src/sys/external/bsd/drm2/pci/drm_pci_module.c:1.6	Mon Aug 27 15:31:27 2018
+++ src/sys/external/bsd/drm2/pci/drm_pci_module.c	Tue Aug 28 03:41:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci_module.c,v 1.6 2018/08/27 15:31:27 riastradh Exp $	*/
+/*	$NetBSD: drm_pci_module.c,v 1.7 2018/08/28 03:41:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,95 +30,21 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_pci_module.c,v 1.6 2018/08/27 15:31:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci_module.c,v 1.7 2018/08/28 03:41:39 riastradh Exp $");
 
 #include <sys/module.h>
-#include <sys/once.h>
-
-#include <drm/drmP.h>
-#include <drm/drm_internal.h>
 
 MODULE(MODULE_CLASS_MISC, drmkms_pci, "drmkms,pci");
 
-#ifdef CONFIG_AGP
-const struct drm_agp_hooks drmkms_pci_agp_hooks = {
-	.agph_acquire_ioctl = &drm_agp_acquire_ioctl,
-	.agph_release_ioctl = &drm_agp_release_ioctl,
-	.agph_enable_ioctl = &drm_agp_enable_ioctl,
-	.agph_info_ioctl = &drm_agp_info_ioctl,
-	.agph_alloc_ioctl = &drm_agp_alloc_ioctl,
-	.agph_free_ioctl = &drm_agp_free_ioctl,
-	.agph_bind_ioctl = &drm_agp_bind_ioctl,
-	.agph_unbind_ioctl = &drm_agp_unbind_ioctl,
-	.agph_release = &drm_agp_release,
-	.agph_clear = &drm_agp_clear,
-};
-#endif
-
-static int (*drm_pci_set_unique_save)(struct drm_device *, struct drm_master *,
-    struct drm_unique *);
-
-static int
-drmkms_pci_agp_init(void)
-{
-#ifdef CONFIG_AGP
-	int error;
-
-	error = drm_agp_register(&drmkms_pci_agp_hooks);
-	if (error)
-		return error;
-#endif
-
-	drm_pci_set_unique_save = drm_pci_set_unique_impl;
-	drm_pci_set_unique_hook(&drm_pci_set_unique_save);
-
-	return 0;
-}
-
-int
-drmkms_pci_agp_guarantee_initialized(void)
-{
-#ifdef _MODULE
-	return 0;
-#else
-	static ONCE_DECL(drmkms_pci_agp_init_once);
-
-	return RUN_ONCE(&drmkms_pci_agp_init_once, &drmkms_pci_agp_init);
-#endif
-}
-
-static void
-drmkms_pci_agp_fini(void)
-{
-
-	drm_pci_set_unique_hook(&drm_pci_set_unique_save);
-	KASSERT(drm_pci_set_unique_save == drm_pci_set_unique_impl);
-
-#ifdef CONFIG_AGP
-	drm_agp_deregister(&drmkms_pci_agp_hooks);
-#endif
-}
-
 static int
 drmkms_pci_modcmd(modcmd_t cmd, void *arg __unused)
 {
-	int error;
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
-#ifdef _MODULE
-		error = drmkms_pci_agp_init();
-#else
-		error = drmkms_pci_agp_guarantee_initialized();
-#endif
-		if (error)
-			return error;
 		return 0;
-
 	case MODULE_CMD_FINI:
-		drmkms_pci_agp_fini();
 		return 0;
-
 	default:
 		return ENOTTY;
 	}

Index: src/sys/external/bsd/drm2/pci/files.drmkms_pci
diff -u src/sys/external/bsd/drm2/pci/files.drmkms_pci:1.12 src/sys/external/bsd/drm2/pci/files.drmkms_pci:1.13
--- src/sys/external/bsd/drm2/pci/files.drmkms_pci:1.12	Mon Aug 27 15:31:27 2018
+++ src/sys/external/bsd/drm2/pci/files.drmkms_pci	Tue Aug 28 03:41:39 2018
@@ -1,11 +1,6 @@
-#	$NetBSD: files.drmkms_pci,v 1.12 2018/08/27 15:31:27 riastradh Exp $
+#	$NetBSD: files.drmkms_pci,v 1.13 2018/08/28 03:41:39 riastradh Exp $
 
-# Attribute for kernel components supporting PCI-based real graphics
-# drivers, a.k.a. `KMS' (kernel mode-setting), as opposed to the legacy
-# `drm' interface attribute, which is where PCI-based fake graphics
-# drivers, a.k.a. `UMS' (user mode-setting), attach.
 define	drmkms_pci: drmkms
-defflag	opt_drmkms_pci.h	DRMKMS_PCI
 
 #file	external/bsd/drm2/dist/drm/ati_pcigart.c	drmkms_pci
 file	external/bsd/drm2/dist/drm/drm_agpsupport.c	drmkms_pci & agp

Index: src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c
diff -u src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c:1.7 src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c:1.8
--- src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c:1.7	Mon Aug 27 13:55:24 2018
+++ src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c	Tue Aug 28 03:41:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ttm_agp_backend.c,v 1.7 2018/08/27 13:55:24 riastradh Exp $	*/
+/*	$NetBSD: ttm_agp_backend.c,v 1.8 2018/08/28 03:41:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ttm_agp_backend.c,v 1.7 2018/08/27 13:55:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ttm_agp_backend.c,v 1.8 2018/08/28 03:41:40 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/kmem.h>
@@ -116,7 +116,7 @@ ttm_agp_bind(struct ttm_tt *ttm, struct 
 		if (ret)
 			goto fail;
 	}
-	agp_flush_cache();
+	drm_agp_flush();
 	AGP_FLUSH_TLB(sc);
 
 	/* Success!  */

Index: src/sys/modules/Makefile
diff -u src/sys/modules/Makefile:1.208 src/sys/modules/Makefile:1.209
--- src/sys/modules/Makefile:1.208	Sat Aug 25 20:12:22 2018
+++ src/sys/modules/Makefile	Tue Aug 28 03:41:38 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.208 2018/08/25 20:12:22 rin Exp $
+#	$NetBSD: Makefile,v 1.209 2018/08/28 03:41:38 riastradh Exp $
 
 .include <bsd.own.mk>
 
@@ -293,6 +293,7 @@ SUBDIR+=	azalia
 SUBDIR+=	compat_linux
 SUBDIR+=	drm
 SUBDIR+=	drmkms
+SUBDIR+=	drmkms_agp
 SUBDIR+=	drmkms_linux
 SUBDIR+=	drmkms_pci
 SUBDIR+=	i915drm

Index: src/sys/modules/drmkms/Makefile
diff -u src/sys/modules/drmkms/Makefile:1.10 src/sys/modules/drmkms/Makefile:1.11
--- src/sys/modules/drmkms/Makefile:1.10	Mon Aug 27 13:53:42 2018
+++ src/sys/modules/drmkms/Makefile	Tue Aug 28 03:41:40 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2018/08/27 13:53:42 riastradh Exp $
+# $NetBSD: Makefile,v 1.11 2018/08/28 03:41:40 riastradh Exp $
 
 .include "../Makefile.inc"
 .include "Makefile.inc"
@@ -13,6 +13,7 @@ MKLDSCRIPT=yes
 .PATH:	${S}/external/bsd/drm2/dist/drm
 
 # NetBSD additions.
+SRCS+=	drm_agp_hook.c
 SRCS+=	drm_cdevsw.c
 SRCS+=	drm_gem_cma_helper.c
 SRCS+=	drm_gem_vm.c
@@ -24,6 +25,8 @@ SRCS+=	drmfb.c
 
 # XXX ttm
 
+CPPFLAGS+=	-I.
+
 # XXX CWARNFLAGS.foo.c doesn't work.
 COPTS.drm_atomic_helper.c+=	-Wno-shadow
 COPTS.drm_crtc.c+=		-Wno-missing-field-initializers

Index: src/sys/modules/drmkms_linux/Makefile
diff -u src/sys/modules/drmkms_linux/Makefile:1.10 src/sys/modules/drmkms_linux/Makefile:1.11
--- src/sys/modules/drmkms_linux/Makefile:1.10	Mon Aug 27 14:16:38 2018
+++ src/sys/modules/drmkms_linux/Makefile	Tue Aug 28 03:41:40 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2018/08/27 14:16:38 riastradh Exp $
+# $NetBSD: Makefile,v 1.11 2018/08/28 03:41:40 riastradh Exp $
 
 #
 # At some point this needs to turn into linux.kmod and a proper home for it
@@ -19,6 +19,8 @@ CPPFLAGS+=	-DDIAGNOSTIC
 
 KMOD=	drmkms_linux
 
+SRCS+=	linux_atomic64.c
+SRCS+=	linux_dma_buf.c
 SRCS+=	linux_dmi.c
 SRCS+=	linux_fence.c
 SRCS+=	linux_i2c.c
@@ -26,7 +28,6 @@ SRCS+=	linux_idr.c
 SRCS+=	linux_kmap.c
 SRCS+=	linux_list_sort.c
 SRCS+=	linux_module.c
-SRCS+=	linux_pci.c
 SRCS+=	linux_rcu.c
 SRCS+=	linux_reservation.c
 SRCS+=	linux_work.c		# XXX Move me to linux.kmod.

Index: src/sys/modules/drmkms_pci/Makefile
diff -u src/sys/modules/drmkms_pci/Makefile:1.6 src/sys/modules/drmkms_pci/Makefile:1.7
--- src/sys/modules/drmkms_pci/Makefile:1.6	Mon Aug 27 13:55:35 2018
+++ src/sys/modules/drmkms_pci/Makefile	Tue Aug 28 03:41:40 2018
@@ -1,21 +1,23 @@
-# $NetBSD: Makefile,v 1.6 2018/08/27 13:55:35 riastradh Exp $
+# $NetBSD: Makefile,v 1.7 2018/08/28 03:41:40 riastradh Exp $
 
 .include "../Makefile.inc"
 .include "../drmkms/Makefile.inc"
 
+.PATH:	${S}/external/bsd/drm2/linux
 .PATH:	${S}/external/bsd/drm2/pci
+
 .PATH:	${S}/external/bsd/drm2/dist/drm
 
 KMOD=	drmkms_pci
 
-CPPFLAGS+=	-DCONFIG_AGP
-CPPFLAGS+=	-DCONFIG_PCI
+CPPFLAGS+=	-I.
+
+SRCS+=	drmfb_pci.c
+SRCS+=	linux_pci.c
 
 #SRCS+=	ati_pcigart.c		# XXX Restore for ATI support.
 SRCS+=	drm_agpsupport.c
 SRCS+=	drm_pci.c
 SRCS+=	drm_pci_module.c
 
-SRCS+=	drmfb_pci.c
-
 .include <bsd.kmodule.mk>

Index: src/sys/modules/i915drmkms/Makefile
diff -u src/sys/modules/i915drmkms/Makefile:1.9 src/sys/modules/i915drmkms/Makefile:1.10
--- src/sys/modules/i915drmkms/Makefile:1.9	Mon Aug 27 13:54:25 2018
+++ src/sys/modules/i915drmkms/Makefile	Tue Aug 28 03:41:40 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2018/08/27 13:54:25 riastradh Exp $
+# $NetBSD: Makefile,v 1.10 2018/08/28 03:41:40 riastradh Exp $
 
 .include "../Makefile.inc"
 .include "../drmkms/Makefile.inc"
@@ -11,6 +11,9 @@ MKLDSCRIPT=yes
 
 .PATH:	${S}/external/bsd/drm2/dist/drm/i915
 
+CPPFLAGS+=	-I.
+CPPFLAGS+=	-I${S}/sys/modules/drmkms
+
 CPPFLAGS+=	-I${S}/external/bsd/drm2/i915drm
 
 CPPFLAGS+=	-I${S}/external/bsd/drm2/dist/drm/i915

Added files:

Index: src/sys/external/bsd/drm2/drm/drm_agp_hook.c
diff -u /dev/null src/sys/external/bsd/drm2/drm/drm_agp_hook.c:1.1
--- /dev/null	Tue Aug 28 03:41:40 2018
+++ src/sys/external/bsd/drm2/drm/drm_agp_hook.c	Tue Aug 28 03:41:39 2018
@@ -0,0 +1,287 @@
+/*	$NetBSD: drm_agp_hook.c,v 1.1 2018/08/28 03:41:39 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2018 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: drm_agp_hook.c,v 1.1 2018/08/28 03:41:39 riastradh Exp $");
+
+#include <sys/types.h>
+#include <sys/condvar.h>
+#include <sys/errno.h>
+#include <sys/mutex.h>
+#include <sys/once.h>
+
+#include <drm/drmP.h>
+#include <drm/drm_internal.h>
+
+static struct {
+	kmutex_t			lock;
+	kcondvar_t			cv;
+	unsigned			refcnt; /* at most one per device */
+	const struct drm_agp_hooks	*hooks;
+} agp_hooks __cacheline_aligned;
+
+void
+drm_agp_hooks_init(void)
+{
+
+	mutex_init(&agp_hooks.lock, MUTEX_DEFAULT, IPL_NONE);
+	cv_init(&agp_hooks.cv, "agphooks");
+	agp_hooks.refcnt = 0;
+	agp_hooks.hooks = NULL;
+}
+
+void
+drm_agp_hooks_fini(void)
+{
+
+	KASSERT(agp_hooks.hooks == NULL);
+	KASSERT(agp_hooks.refcnt == 0);
+	cv_destroy(&agp_hooks.cv);
+	mutex_destroy(&agp_hooks.lock);
+}
+
+int
+drm_agp_register(const struct drm_agp_hooks *hooks)
+{
+	int error = 0;
+
+	mutex_enter(&agp_hooks.lock);
+	if (agp_hooks.refcnt) {
+		KASSERT(agp_hooks.hooks);
+		error = EBUSY;
+	} else {
+		agp_hooks.refcnt++;
+		agp_hooks.hooks = hooks;
+	}
+	mutex_exit(&agp_hooks.lock);
+
+	return error;
+}
+
+int
+drm_agp_deregister(const struct drm_agp_hooks *hooks)
+{
+	int error;
+
+	mutex_enter(&agp_hooks.lock);
+	KASSERT(agp_hooks.hooks == hooks);
+	if (agp_hooks.refcnt > 1) {
+		error = EBUSY;
+	} else {
+		agp_hooks.refcnt = 0;
+		agp_hooks.hooks = NULL;
+	}
+	mutex_exit(&agp_hooks.lock);
+
+	return error;
+}
+
+static const struct drm_agp_hooks *
+drm_agp_hooks_acquire(void)
+{
+	const struct drm_agp_hooks *hooks;
+
+	mutex_enter(&agp_hooks.lock);
+	if (agp_hooks.refcnt == 0) {
+		hooks = NULL;
+	} else {
+		KASSERT(agp_hooks.refcnt < UINT_MAX);
+		agp_hooks.refcnt++;
+		hooks = agp_hooks.hooks;
+	}
+	mutex_exit(&agp_hooks.lock);
+
+	return hooks;
+}
+
+static void
+drm_agp_hooks_release(const struct drm_agp_hooks *hooks)
+{
+
+	mutex_enter(&agp_hooks.lock);
+	KASSERT(agp_hooks.hooks == hooks);
+	KASSERT(agp_hooks.refcnt);
+	if (--agp_hooks.refcnt == 0)
+		cv_broadcast(&agp_hooks.cv);
+	mutex_exit(&agp_hooks.lock);
+}
+
+struct drm_agp_head *
+drm_agp_init(struct drm_device *dev)
+{
+	const struct drm_agp_hooks *hooks;
+	struct drm_agp_head *agp;
+
+	if ((hooks = drm_agp_hooks_acquire()) == NULL)
+		return NULL;
+	agp = hooks->agph_init(dev);
+	if (agp == NULL)
+		drm_agp_hooks_release(hooks);
+
+	return agp;
+}
+
+void
+drm_agp_fini(struct drm_device *dev)
+{
+
+	if (dev->agp == NULL)
+		return;
+	dev->agp->hooks->agph_clear(dev);
+	drm_agp_hooks_release(dev->agp->hooks);
+	kfree(dev->agp);
+	dev->agp = NULL;
+}
+
+void
+drm_agp_clear(struct drm_device *dev)
+{
+
+	if (dev->agp == NULL)
+		return;
+	dev->agp->hooks->agph_clear(dev);
+}
+
+int
+drm_agp_acquire(struct drm_device *dev)
+{
+
+	if (dev->agp == NULL)
+		return -ENODEV;
+	return dev->agp->hooks->agph_acquire(dev);
+}
+
+int
+drm_agp_release(struct drm_device *dev)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_release(dev);
+}
+
+int
+drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_enable(dev, mode);
+}
+
+int
+drm_agp_info(struct drm_device *dev, struct drm_agp_info *info)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_info(dev, info);
+}
+
+int
+drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_alloc(dev, request);
+}
+
+int
+drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_free(dev, request);
+}
+
+int
+drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_bind(dev, request);
+}
+
+int
+drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
+{
+
+	if (dev->agp == NULL)
+		return -EINVAL;
+	return dev->agp->hooks->agph_unbind(dev, request);
+}
+
+#define	DEFINE_AGP_HOOK_IOCTL(NAME, FIELD)				      \
+int									      \
+NAME(struct drm_device *dev, void *data, struct drm_file *file)		      \
+{									      \
+									      \
+	if (dev->agp == NULL)						      \
+		return -ENODEV;						      \
+	return dev->agp->hooks->FIELD(dev, data, file);			      \
+}
+
+DEFINE_AGP_HOOK_IOCTL(drm_agp_acquire_ioctl, agph_acquire_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_release_ioctl, agph_release_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_enable_ioctl, agph_enable_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_info_ioctl, agph_info_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_alloc_ioctl, agph_alloc_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_free_ioctl, agph_free_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_bind_ioctl, agph_bind_ioctl)
+DEFINE_AGP_HOOK_IOCTL(drm_agp_unbind_ioctl, agph_unbind_ioctl)
+
+void __pci_iomem *
+drm_agp_borrow(struct drm_device *dev, unsigned bar, bus_size_t size)
+{
+	const struct drm_agp_hooks *hooks;
+	void __pci_iomem *iomem;
+
+	if ((hooks = drm_agp_hooks_acquire()) == NULL)
+		return NULL;
+	iomem = hooks->agph_borrow(dev, bar, size);
+	drm_agp_hooks_release(hooks);
+
+	return iomem;
+}
+
+void
+drm_agp_flush(void)
+{
+	const struct drm_agp_hooks *hooks;
+
+	if ((hooks = drm_agp_hooks_acquire()) == NULL)
+		return;
+	hooks->agph_flush();
+	drm_agp_hooks_release(hooks);
+}

Index: src/sys/modules/drmkms/agp.h
diff -u /dev/null src/sys/modules/drmkms/agp.h:1.1
--- /dev/null	Tue Aug 28 03:41:40 2018
+++ src/sys/modules/drmkms/agp.h	Tue Aug 28 03:41:40 2018
@@ -0,0 +1 @@
+/* no AGP in generic drmkms module */

Index: src/sys/modules/drmkms_agp/Makefile
diff -u /dev/null src/sys/modules/drmkms_agp/Makefile:1.1
--- /dev/null	Tue Aug 28 03:41:40 2018
+++ src/sys/modules/drmkms_agp/Makefile	Tue Aug 28 03:41:40 2018
@@ -0,0 +1,12 @@
+#	$NetBSD: Makefile,v 1.1 2018/08/28 03:41:40 riastradh Exp $
+
+.include "../Makefile.inc"
+.include "../drmkms/Makefile.inc"
+
+.PATH:	${S}/external/bsd/drm2/dist/drm
+
+KMOD=	drmkms_agp
+
+SRCS+=	drm_agpsupport.c
+
+.include <bsd.kmodule.mk>

Reply via email to