CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2014-01-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 15 13:53:20 UTC 2014

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Implement drm_pci_set_busid and drm_pci_set_unique.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.10 -r1.1.2.11 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.10 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.11
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.10	Sun Sep  8 16:15:17 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Wed Jan 15 13:53:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.10 2013/09/08 16:15:17 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.11 2014/01/15 13:53:20 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.10 2013/09/08 16:15:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.11 2014/01/15 13:53:20 riastradh Exp $");
 
 #include 
 #include 
@@ -232,16 +232,76 @@ drm_pci_get_name(struct drm_device *dev)
 }
 
 static int
+drm_pci_format_unique(struct drm_device *dev, char *buf, size_t size)
+{
+	const unsigned int domain = 0; /* XXX PCI domains? */
+	const unsigned int bus = dev->pdev->pd_pa.pa_bus;
+	const unsigned int device = dev->pdev->pd_pa.pa_device;
+	const unsigned int function = dev->pdev->pd_pa.pa_function;
+
+	return snprintf(buf, size, "pci:%04x:%02x:%02x.%d",
+	domain, bus, device, function);
+}
+
+static int
+drm_pci_format_devname(struct drm_device *dev, const char *unique,
+char *buf, size_t size)
+{
+
+	return snprintf(buf, size, "%s@%s",
+	device_xname(device_parent(dev->dev)),
+	unique);
+}
+
+static int
 drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
 {
-	return -ENOSYS;		/* XXX PCI bus ids?  */
+	int n;
+	char *buf;
+
+	n = drm_pci_format_unique(dev, NULL, 0);
+	if (n < 0)
+		return -ENOSPC;	/* XXX */
+	if (0xff < n)
+		n = 0xff;
+
+	buf = kzalloc(n + 1, GFP_KERNEL);
+	(void)drm_pci_format_unique(dev, buf, n + 1);
+
+	if (master->unique)
+		kfree(master->unique);
+	master->unique = buf;
+	master->unique_len = n;
+	master->unique_size = n + 1;
+
+	n = drm_pci_format_devname(dev, master->unique, NULL, 0);
+	if (n < 0)
+		return -ENOSPC;	/* XXX back out? */
+	if (0xff < n)
+		n = 0xff;
+
+	buf = kzalloc(n + 1, GFP_KERNEL);
+	(void)drm_pci_format_devname(dev, master->unique, buf, n + 1);
+
+	if (dev->devname)
+		kfree(dev->devname);
+	dev->devname = buf;
+
+	return 0;
 }
 
 static int
 drm_pci_set_unique(struct drm_device *dev, struct drm_master *master,
-struct drm_unique *unique)
+struct drm_unique *unique __unused)
 {
-	return -ENOSYS;		/* XXX */
+
+	/*
+	 * XXX This is silly.  We're supposed to reject unique names
+	 * that don't match the ones we would generate anyway.  For
+	 * expedience, we'll just generate the one we would and ignore
+	 * whatever userland threw at us...
+	 */
+	return drm_pci_set_busid(dev, master);
 }
 
 static int



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-09-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Sep  8 16:15:17 UTC 2013

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Use the 64-bit PCI DMA tag if available.

Otherwise, it can't handle >32-bit physical addresses, which
uvm_obj_wirepages seems to have a tendency to return.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.9 -r1.1.2.10 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.9 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.10
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.9	Sun Sep  8 15:46:22 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Sun Sep  8 16:15:17 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.9 2013/09/08 15:46:22 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.10 2013/09/08 16:15:17 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.9 2013/09/08 15:46:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.10 2013/09/08 16:15:17 riastradh Exp $");
 
 #include 
 #include 
@@ -105,7 +105,8 @@ drm_pci_attach(device_t self, const stru
 	/* XXX Set the power state to D0?  */
 
 	dev->bst = pa->pa_memt;
-	dev->bus_dmat = pa->pa_dmat; /* XXX dmat64?  */
+	/* XXX Let the driver say something about 32-bit vs 64-bit DMA?  */
+	dev->bus_dmat = (pci_dma64_available(pa)? pa->pa_dmat64 : pa->pa_dmat);
 	dev->dmat = dev->bus_dmat;
 	dev->dmat_subregion_p = false;
 



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-09-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Sep  8 15:46:22 UTC 2013

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Add missing initialization of dev->dmat in drm_pci_attach.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.8 -r1.1.2.9 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.8 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.9
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.8	Wed Jul 24 04:05:34 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Sun Sep  8 15:46:22 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.8 2013/07/24 04:05:34 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.9 2013/09/08 15:46:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.8 2013/07/24 04:05:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.9 2013/09/08 15:46:22 riastradh Exp $");
 
 #include 
 #include 
@@ -106,6 +106,7 @@ drm_pci_attach(device_t self, const stru
 
 	dev->bst = pa->pa_memt;
 	dev->bus_dmat = pa->pa_dmat; /* XXX dmat64?  */
+	dev->dmat = dev->bus_dmat;
 	dev->dmat_subregion_p = false;
 
 	CTASSERT(PCI_NMAPREGS < (SIZE_MAX / sizeof(dev->bus_maps[0])));



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 24 03:58:51 UTC 2013

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Initialize PCI memory maps and bus space/dma tags in drm_pci_attach.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.6 -r1.1.2.7 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.6 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.7
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.6	Wed Jul 24 03:57:03 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Wed Jul 24 03:58:51 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.6 2013/07/24 03:57:03 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.7 2013/07/24 03:58:51 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.6 2013/07/24 03:57:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.7 2013/07/24 03:58:51 riastradh Exp $");
 
 #include 
 #include 
@@ -87,10 +87,14 @@ drm_pci_exit(struct drm_driver *driver _
 {
 }
 
+/* XXX Should go elsewhere.  */
+#define	PCI_NMAPREGS	((PCI_MAPREG_END - PCI_MAPREG_START) / 4)
+
 void
 drm_pci_attach(device_t self, const struct pci_attach_args *pa,
 struct pci_dev *pdev, struct drm_device *dev)
 {
+	unsigned int unit;
 
 	linux_pci_dev_init(pdev, self, pa, 0);
 
@@ -99,12 +103,65 @@ drm_pci_attach(device_t self, const stru
 	dev->pci_device = pdev->device;
 
 	/* XXX Set the power state to D0?  */
+
+	dev->bst = pa->pa_memt;
+	dev->bus_dmat = pa->pa_dmat; /* XXX dmat64?  */
+	dev->dmat_subregion_p = false;
+
+	CTASSERT(PCI_NMAPREGS < (SIZE_MAX / sizeof(dev->bus_maps[0])));
+	dev->bus_nmaps = PCI_NMAPREGS;
+	dev->bus_maps = kmem_zalloc((PCI_NMAPREGS * sizeof(dev->bus_maps[0])),
+	KM_SLEEP);
+	for (unit = 0; unit < dev->bus_nmaps; unit++) {
+		struct drm_bus_map *const bm = &dev->bus_maps[unit];
+		const int reg = (PCI_MAPREG_START + (unit*4));
+		const pcireg_t type =
+		pci_mapreg_type(pa->pa_pc, pa->pa_tag, reg);
+
+		/* Reject non-memory mappings.  */
+		if ((type & PCI_MAPREG_TYPE_MEM) != PCI_MAPREG_TYPE_MEM) {
+			aprint_debug_dev(self, "map %u has non-memory type:"
+			" 0x%"PRIxMAX"\n", unit, (uintmax_t)type);
+			continue;
+		}
+
+		/* Inquire about it.  We'll map it in drm_ioremap.  */
+		if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, reg, type,
+			&bm->bm_base, &bm->bm_size, &bm->bm_flags) != 0) {
+			aprint_debug_dev(self, "map %u failed\n", unit);
+			continue;
+		}
+
+		aprint_debug_dev(self, "map %u at %"PRIxMAX" size %"PRIxMAX
+		" flags 0x%"PRIxMAX"\n",
+		unit, (uintmax_t)bm->bm_base, (uintmax_t)bm->bm_size,
+		(uintmax_t)bm->bm_flags);
+
+		/* Assume since it is a memory mapping it can be linear.  */
+		bm->bm_flags |= BUS_SPACE_MAP_LINEAR;
+	}
+
+	/* All `agp' maps are just initialized to zero.  */
+	CTASSERT(PCI_NMAPREGS < (SIZE_MAX / sizeof(dev->agp_maps[0])));
+	dev->agp_nmaps = PCI_NMAPREGS;
+	dev->agp_maps = kmem_zalloc((PCI_NMAPREGS * sizeof(dev->agp_maps[0])),
+	KM_SLEEP);
 }
 
 int
 drm_pci_detach(struct drm_device *dev __unused, int flags __unused)
 {
 
+	kmem_free(dev->bus_maps, (PCI_NMAPREGS * sizeof(dev->bus_maps[0])));
+	kmem_free(dev->agp_maps, (PCI_NMAPREGS * sizeof(dev->agp_maps[0])));
+
+	/*
+	 * XXX This is the wrong place!  Should be a routine in
+	 * drm_memory.c.
+	 */
+	if (dev->dmat_subregion_p)
+		bus_dmatag_destroy(dev->dmat);
+
 	/* XXX Disestablish irqs or anything?  */
 	return 0;
 }



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 24 03:57:04 UTC 2013

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Move driver->bus setting to drm_pci_init.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.5 -r1.1.2.6 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.5 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.6
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.5	Wed Jul 24 03:54:14 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Wed Jul 24 03:57:03 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.5 2013/07/24 03:54:14 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.6 2013/07/24 03:57:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.5 2013/07/24 03:54:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.6 2013/07/24 03:57:03 riastradh Exp $");
 
 #include 
 #include 
@@ -73,13 +73,25 @@ drm_pci_attach_args(struct drm_device *d
 	return &dev->pdev->pd_pa;
 }
 
+int
+drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver __unused)
+{
+
+	driver->bus = &drm_pci_bus;
+	return 0;
+}
+
+void
+drm_pci_exit(struct drm_driver *driver __unused,
+struct pci_driver *pdriver __unused)
+{
+}
+
 void
 drm_pci_attach(device_t self, const struct pci_attach_args *pa,
 struct pci_dev *pdev, struct drm_device *dev)
 {
 
-	dev->driver->bus = &drm_pci_bus;
-
 	linux_pci_dev_init(pdev, self, pa, 0);
 
 	dev->pdev = pdev;



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 24 03:54:14 UTC 2013

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Make drm_pci_agp_init succeed for now.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.4 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.5
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.4	Wed Jul 24 03:53:30 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Wed Jul 24 03:54:14 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.4 2013/07/24 03:53:30 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.5 2013/07/24 03:54:14 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.4 2013/07/24 03:53:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.5 2013/07/24 03:54:14 riastradh Exp $");
 
 #include 
 #include 
@@ -182,5 +182,5 @@ drm_pci_irq_by_busid(struct drm_device *
 static int
 drm_pci_agp_init(struct drm_device *dev)
 {
-	return -ENOSYS;		/* XXX */
+	return 0;		/* XXX */
 }



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 24 03:53:31 UTC 2013

Modified Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
Initialize dev->driver->bus in drm_pci_attach.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Modified files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.3 src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.4
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.3	Wed Jul 24 03:32:19 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Wed Jul 24 03:53:30 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.1.2.3 2013/07/24 03:32:19 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.1.2.4 2013/07/24 03:53:30 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.3 2013/07/24 03:32:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.4 2013/07/24 03:53:30 riastradh Exp $");
 
 #include 
 #include 
@@ -78,6 +78,8 @@ drm_pci_attach(device_t self, const stru
 struct pci_dev *pdev, struct drm_device *dev)
 {
 
+	dev->driver->bus = &drm_pci_bus;
+
 	linux_pci_dev_init(pdev, self, pa, 0);
 
 	dev->pdev = pdev;



CVS commit: [riastradh-drm2] src/sys/external/bsd/drm2/pci

2013-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 24 02:35:07 UTC 2013

Added Files:
src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c

Log Message:
First draft of a local drm_pci.c.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1.2.1 src/sys/external/bsd/drm2/pci/drm_pci.c

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

Added files:

Index: src/sys/external/bsd/drm2/pci/drm_pci.c
diff -u /dev/null src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.1
--- /dev/null	Wed Jul 24 02:35:07 2013
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Wed Jul 24 02:35:07 2013
@@ -0,0 +1,162 @@
+/*	$NetBSD: drm_pci.c,v 1.1.2.1 2013/07/24 02:35:07 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.1 2013/07/24 02:35:07 riastradh Exp $");
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+static int	drm_pci_get_irq(struct drm_device *);
+static int	drm_pci_irq_install(struct drm_device *,
+		irqreturn_t (*)(void *), int, const char *, void *,
+		struct drm_bus_irq_cookie **);
+static void	drm_pci_irq_uninstall(struct drm_device *,
+		struct drm_bus_irq_cookie *);
+static const char *
+		drm_pci_get_name(struct drm_device *);
+static int	drm_pci_set_busid(struct drm_device *, struct drm_master *);
+static int	drm_pci_set_unique(struct drm_device *, struct drm_master *,
+		struct drm_unique *);
+static int	drm_pci_irq_by_busid(struct drm_device *,
+		struct drm_irq_busid *);
+static int	drm_pci_agp_init(struct drm_device *);
+
+const struct drm_bus drm_pci_bus = {
+	.bus_type = DRIVER_BUS_PCI,
+	.get_irq = drm_pci_get_irq,
+	.irq_install = drm_pci_irq_install,
+	.irq_uninstall = drm_pci_irq_uninstall,
+	.get_name = drm_pci_get_name,
+	.set_busid = drm_pci_set_busid,
+	.set_unique = drm_pci_set_unique,
+	.irq_by_busid = drm_pci_irq_by_busid,
+	.agp_init = drm_pci_agp_init,
+};
+
+static const struct pci_attach_args *
+drm_pci_attach_args(struct drm_device *dev)
+{
+	return &dev->pdev->pd_pa;
+}
+
+static int
+drm_pci_get_irq(struct drm_device *dev)
+{
+	pci_intr_handle_t ih_pih;
+	int ih_int;
+
+	/*
+	 * This is a compile-time assertion that the types match.  If
+	 * this fails, we have to change a bunch of drm code that uses
+	 * int for intr handles.
+	 */
+	KASSERT(&ih_pih != &ih_int);
+
+	if (pci_intr_map(drm_pci_attach_args(dev), &ih_pih))
+		return -1;	/* XXX Hope -1 is an invalid intr handle.  */
+
+	ih_int = ih_pih;
+	return ih_int;
+}
+
+static int
+drm_pci_irq_install(struct drm_device *dev, irqreturn_t (*handler)(void *),
+int flags, const char *name, void *arg,
+struct drm_bus_irq_cookie **cookiep)
+{
+	const struct pci_attach_args *const pa = drm_pci_attach_args(dev);
+	pci_intr_handle_t ih;
+	const char *intrstr;
+	void *ih_cookie;
+
+	if (pci_intr_map(pa, &ih))
+		return -ENOENT;
+
+	intrstr = pci_intr_string(pa->pa_pc, ih);
+	ih_cookie = pci_intr_establish(pa->pa_pc, ih, IPL_DRM, handler, arg);
+	if (ih_cookie == NULL) {
+		aprint_error_dev(dev->dev,
+		"couldn't establish interrupt at %s (%s)\n",
+		intrstr, name);
+		return -ENOENT;
+	}
+
+	aprint_normal_dev(dev->dev, "interrupting at %s (%s)\n",
+	intrstr, name);
+	*cookiep = (struct drm_bus_irq_cookie *)ih_cookie;
+	return 0;
+}
+
+static void
+drm_pci_irq_uninstall(struct drm_device *dev,
+struct drm_bus_irq_cookie *cookie)
+{
+	const struct pci_attach_args *pa = drm_pci_attach