--- xorg_current/mesa/drm/bsd-core/drm_drv.c 2007-07-21 23:13:43.000000000 -0700 +++ drm-mine/bsd-core/drm_drv.c 2007-07-26 20:36:28.000000000 -0700 @@ -1,4 +1,4 @@ -/* drm_drv.h -- Generic driver template -*- linux-c -*- +/* drm_drv.c -- Generic driver template -*- linux-c -*- * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com */ /*- @@ -532,6 +532,7 @@ if (dev->driver.load != NULL) { DRM_LOCK(); + /* shared code returns -errno */ retcode = -dev->driver.load(dev, dev->id_entry->driver_private); DRM_UNLOCK(); @@ -714,6 +715,15 @@ return EINVAL; } + atomic_inc( &dev->counts[_DRM_STAT_CLOSES] ); +#ifdef __FreeBSD__ + device_unbusy(dev->device); +#endif + if (--dev->open_count != 0) { + DRM_UNLOCK(); + return 0; + } + if (dev->driver.preclose != NULL) dev->driver.preclose(dev, file_priv); @@ -800,13 +810,7 @@ * End inline drm_release */ - atomic_inc( &dev->counts[_DRM_STAT_CLOSES] ); -#ifdef __FreeBSD__ - device_unbusy(dev->device); -#endif - if (--dev->open_count == 0) { - retcode = drm_lastclose(dev); - } + retcode = drm_lastclose(dev); DRM_UNLOCK(); @@ -818,14 +822,7 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p) { -#ifdef __FreeBSD__ - drm_device_t *dev = kdev->si_drv1; -#elif defined(__NetBSD__) - drm_device_t *dev = device_lookup(&drm_cd, minor(kdev)); -#else - drm_device_t *dev = device_lookup(&drm_cd, - minor(kdev)))->dv_cfdata->cf_driver->cd_devs[minor(kdev)]; -#endif + drm_device_t *dev = drm_get_device_from_kdev(kdev); int retcode = 0; drm_ioctl_desc_t *ioctl; int (*func)(drm_device_t *dev, void *data, struct drm_file *file_priv); @@ -912,15 +909,13 @@ ((ioctl->flags & DRM_MASTER) && !file_priv->master)) return EACCES; - if (is_driver_ioctl) - DRM_LOCK(); - retcode = func(dev, data, file_priv); if (is_driver_ioctl) { + DRM_LOCK(); + /* shared code returns -errno */ + retcode = -func(dev, data, file_priv); DRM_UNLOCK(); - /* Driver ioctls in shared code follow the linux convention of - * returning -errno instead of errno. - */ - retcode = -retcode; + } else { + retcode = func(dev, data, file_priv); } if (retcode != 0)