Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 24 03:54:43 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/drm [riastradh-drm2]: drm_drv.c
        src/sys/external/bsd/drm2/i915drm [riastradh-drm2]: i915_pci.c

Log Message:
Fix up drm attachment code.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.12 -r1.1.2.13 src/sys/external/bsd/drm2/drm/drm_drv.c
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/external/bsd/drm2/i915drm/i915_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/drm/drm_drv.c
diff -u src/sys/external/bsd/drm2/drm/drm_drv.c:1.1.2.12 src/sys/external/bsd/drm2/drm/drm_drv.c:1.1.2.13
--- src/sys/external/bsd/drm2/drm/drm_drv.c:1.1.2.12	Wed Jul 24 03:46:37 2013
+++ src/sys/external/bsd/drm2/drm/drm_drv.c	Wed Jul 24 03:54:43 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_drv.c,v 1.1.2.12 2013/07/24 03:46:37 riastradh Exp $	*/
+/*	$NetBSD: drm_drv.c,v 1.1.2.13 2013/07/24 03:54:43 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.1.2.12 2013/07/24 03:46:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.1.2.13 2013/07/24 03:54:43 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -62,9 +62,7 @@ struct drm_softc {
 
 static int	drm_match(device_t, cfdata_t, void *);
 static void	drm_attach(device_t, device_t, void *);
-#if 0				/* XXX drm detach */
 static int	drm_detach(device_t, int);
-#endif
 
 static struct drm_softc *drm_dev_softc(dev_t);
 static struct drm_minor *drm_dev_minor(dev_t);
@@ -234,8 +232,8 @@ static const struct fileops drm_fileops 
 	.fo_restart = fnullop_restart,
 };
 
-CFATTACH_DECL_NEW(drm, sizeof(struct drm_minor),
-    drm_match, drm_attach, NULL /* XXX drm_detach */, NULL);
+CFATTACH_DECL_NEW(drm, sizeof(struct drm_softc),
+    drm_match, drm_attach, drm_detach, NULL);
 
 static int
 drm_match(device_t parent __unused, cfdata_t match __unused,
@@ -251,12 +249,15 @@ drm_attach(device_t parent, device_t sel
 	struct drm_softc *sc = device_private(self);
 	struct drm_device *dev = aux;
 	unsigned int i;
+	int error;
 
 	KASSERT(sc != NULL);
 	KASSERT(dev != NULL);
 	KASSERT(dev->driver != NULL);
 	KASSERT(device_unit(self) >= 0);
 
+	aprint_normal("\n");
+
 	if (device_unit(self) >= 64) { /* XXX Need to do something here!  */
 		aprint_error_dev(self, "can't handle >=64 drm devices!");
 		return;
@@ -276,31 +277,61 @@ drm_attach(device_t parent, device_t sel
 		    sizeof(sc->sc_minor[i].mode_group));
 	}
 
+	/*
+	 * XXX drm_fill_in_dev reinitializes dev->driver as an artefact
+	 * of Linux's driver attachment goop.  Harmless.
+	 */
+	error = drm_fill_in_dev(dev, NULL, dev->driver);
+	if (error) {
+		aprint_error_dev(parent, "unable to initialize drm: %d\n",
+		    error);
+		return;
+	}
+
 #if 0				/* XXX drm wsdisplay */
 	attach wsdisplay;
 #endif
 }
 
-#if 0				/* XXX drm detach */
 static int
 drm_detach(device_t self, int flags)
 {
 	struct drm_softc *const sc = device_private(self);
 	KASSERT(sc != NULL);
-	struct drm_device *const dev = sc->sc_minor.dev;
+	struct drm_device *const dev = sc->sc_drm_dev;
 	KASSERT(dev != NULL);
+	const struct drm_driver *const driver = dev->driver;
+	KASSERT(driver != NULL);
+
+	/*
+	 * XXX Synchronize with drm_fill_in_dev, perhaps with reference
+	 * to drm_put_dev.
+	 */
+
+	if (ISSET(driver->driver_features, DRIVER_GEM))
+		drm_gem_destroy(dev);
 
-	drm_sysctl_cleanup(dev);
 	drm_ctxbitmap_cleanup(dev);
-	clean up mtrr crap;
-	do the last close;
-	unload it all;
-	vblank clenaup;
-	kill hash tables;
-	and more;
-	in a different order;
+
+	/* XXX Move to dev->driver->bus->agp_destroy.  */
+	if (drm_core_has_MTRR(dev) &&
+	    drm_core_has_AGP(dev) &&
+	    (dev->agp != NULL) &&
+	    (dev->agp->agp_mtrr >= 0)) {
+		int error __unused;
+		error = mtrr_del(dev->agp->agp_mtrr,
+		    dev->agp->agp_info.ai_aperture_base,
+		    dev->agp->agp_info.ai_aperture_size);
+		DRM_DEBUG("mtrr_del=%d\n", error);
+	}
+
+	linux_mutex_destroy(&dev->ctxlist_mutex);
+	linux_mutex_destroy(&dev->struct_mutex);
+	spin_lock_destroy(&dev->event_lock);
+	spin_lock_destroy(&dev->count_lock);
+
+	return 0;
 }
-#endif
 
 static struct drm_softc *
 drm_dev_softc(dev_t d)
@@ -593,15 +624,8 @@ void
 drm_config_found(device_t parent, struct drm_driver *driver,
     unsigned long flags, struct drm_device *dev)
 {
-	int error;
-
-	error = drm_fill_in_dev(dev, NULL, driver);
-	if (error) {
-		aprint_error_dev(parent, "unable to initialize drm: %d\n",
-		    error);
-		return;
-	}
 
+	dev->driver = driver;
 	if (config_found_ia(parent, "drmbus", dev, NULL) == NULL) {
 		aprint_error_dev(parent, "unable to attach drm\n");
 		return;

Index: src/sys/external/bsd/drm2/i915drm/i915_pci.c
diff -u src/sys/external/bsd/drm2/i915drm/i915_pci.c:1.1.2.2 src/sys/external/bsd/drm2/i915drm/i915_pci.c:1.1.2.3
--- src/sys/external/bsd/drm2/i915drm/i915_pci.c:1.1.2.2	Wed Jul 24 03:54:01 2013
+++ src/sys/external/bsd/drm2/i915drm/i915_pci.c	Wed Jul 24 03:54:43 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_pci.c,v 1.1.2.2 2013/07/24 03:54:01 riastradh Exp $	*/
+/*	$NetBSD: i915_pci.c,v 1.1.2.3 2013/07/24 03:54:43 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_pci.c,v 1.1.2.2 2013/07/24 03:54:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_pci.c,v 1.1.2.3 2013/07/24 03:54:43 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -115,6 +115,11 @@ i915drm_attach(device_t parent, device_t
 
 	KASSERT(info != NULL);
 
+	/* XXX Show more information...  */
+	aprint_naive("\n");
+	aprint_normal(": vendor 0x%04x, device 0x%04x, gen %u\n",
+	    PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id), info->gen);
+
 	/* XXX Whattakludge!  */
 	if (info->gen != 3) {
 		i915_drm_driver->driver_features &=~ DRIVER_REQUIRE_AGP;

Reply via email to