From d28a4dfebd56ca69c402c5649f5f39bf91982e8d Mon Sep 17 00:00:00 2001 From: mrg Date: Mon, 30 Mar 2009 01:47:36 +0000 Subject: [PATCH] - set dev->device to the device_t - fix a DEBUG message - apply from sys/dev: revision 1.20 date: 2009/01/18 10:04:35; author: mrg; state: Exp; lines: +6 -2 Don't attempt to unload a DRM device that's in use. (Note: Unloading doesn't work right in any case -- it doesn't clean up the sysctl tree, among other things. This code needs Work, but at least this prevents it crashing randomly due to autounload while X is running.) Also, fix the dependency list for radeondrm. contributed anonymously. --- sys/external/bsd/drm/dist/bsd-core/drm_drv.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/external/bsd/drm/dist/bsd-core/drm_drv.c b/sys/external/bsd/drm/dist/bsd-core/drm_drv.c index dcf4cd7d9406..b108375f974b 100644 --- a/sys/external/bsd/drm/dist/bsd-core/drm_drv.c +++ b/sys/external/bsd/drm/dist/bsd-core/drm_drv.c @@ -395,6 +395,7 @@ void drm_attach(struct device *kdev, struct pci_attach_args *pa, return; dev = drm_units[unit] = device_private(kdev); + dev->device = kdev; dev->unit = unit; for (unit = 0; unit < DRM_MAX_PCI_RESOURCE; unit++) { @@ -434,9 +435,13 @@ void drm_attach(struct device *kdev, struct pci_attach_args *pa, int drm_detach(struct device *self, int flags) { - drm_device_t *dev = (drm_device_t*)self; + drm_device_t *dev = device_private(self); - drm_unload((struct drm_device *)self); + /* XXX locking */ + if (dev->open_count) + return EBUSY; + + drm_unload(dev); drm_units[dev->unit] = NULL; return 0; } @@ -903,7 +908,10 @@ int drm_close(DRM_CDEV kdev, int flags, int fmt, DRM_STRUCTCDEVPROC *p) #ifdef __FreeBSD__ DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n", DRM_CURRENTPID, (long)dev->device, dev->open_count ); -#elif defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) + DRM_DEBUG( "pid = %d, device = 0x%p, open_count = %d\n", + DRM_CURRENTPID, dev->device, dev->open_count); +#elif defined(__OpenBSD__) DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n", DRM_CURRENTPID, (long)&dev->device, dev->open_count); #endif