34 #include <linux/module.h>
36 #include <linux/slab.h>
53 MODULE_PARM_DESC(vblankoffdelay,
"Delay until vblank irq auto-disable [msecs]");
54 MODULE_PARM_DESC(timestamp_precision_usec,
"Max. error on timestamps [usecs]");
87 const char *function_name,
96 vprintk(format, args);
108 if (type == DRM_MINOR_CONTROL) {
111 }
else if (type == DRM_MINOR_RENDER) {
118 DRM_ERROR(
"Out of memory expanding drawable idr\n");
130 if (new_id >=
limit) {
139 struct drm_master *master;
141 master = kzalloc(
sizeof(*master),
GFP_KERNEL);
145 kref_init(&master->refcount);
149 INIT_LIST_HEAD(&master->magicfree);
150 master->minor = minor;
159 kref_get(&master->refcount);
164 static void drm_master_destroy(
struct kref *
kref)
167 struct drm_magic_entry *pt, *
next;
169 struct drm_map_list *r_list, *list_temp;
173 if (dev->driver->master_destroy)
174 dev->driver->master_destroy(dev, master);
177 if (r_list->master == master) {
183 if (master->unique) {
184 kfree(master->unique);
185 master->unique =
NULL;
186 master->unique_len = 0;
205 kref_put(&(*master)->refcount, drm_master_destroy);
211 struct drm_file *file_priv)
215 if (file_priv->is_master)
218 if (file_priv->minor->master && file_priv->minor->master != file_priv->master)
221 if (!file_priv->master)
224 if (!file_priv->minor->master &&
225 file_priv->minor->master != file_priv->master) {
228 file_priv->is_master = 1;
229 if (dev->driver->master_set) {
230 ret = dev->driver->master_set(dev, file_priv,
false);
232 file_priv->is_master = 0;
243 struct drm_file *file_priv)
245 if (!file_priv->is_master)
248 if (!file_priv->minor->master)
252 if (dev->driver->master_drop)
253 dev->driver->master_drop(dev, file_priv,
false);
255 file_priv->is_master = 0;
262 struct drm_driver *
driver)
266 INIT_LIST_HEAD(&dev->filelist);
267 INIT_LIST_HEAD(&dev->ctxlist);
268 INIT_LIST_HEAD(&dev->vmalist);
269 INIT_LIST_HEAD(&dev->maplist);
270 INIT_LIST_HEAD(&dev->vblank_event_list);
292 if (dev->driver->bus->agp_init) {
293 retcode = dev->driver->bus->agp_init(dev);
295 goto error_out_unreg;
302 DRM_ERROR(
"Cannot allocate memory for context bitmap.\n");
303 goto error_out_unreg;
306 if (driver->driver_features & DRIVER_GEM) {
309 DRM_ERROR(
"Cannot initialize graphics execution "
311 goto error_out_unreg;
337 struct drm_minor *new_minor;
343 minor_id = drm_minor_get_id(dev, type);
347 new_minor = kzalloc(
sizeof(
struct drm_minor),
GFP_KERNEL);
353 new_minor->type =
type;
354 new_minor->device =
MKDEV(DRM_MAJOR, minor_id);
355 new_minor->dev =
dev;
356 new_minor->index = minor_id;
357 INIT_LIST_HEAD(&new_minor->master_list);
361 if (type == DRM_MINOR_LEGACY) {
364 DRM_ERROR(
"DRM: Failed to initialize /proc/dri.\n");
368 new_minor->proc_root =
NULL;
370 #if defined(CONFIG_DEBUG_FS)
371 ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root);
373 DRM_ERROR(
"DRM: Failed to initialize /sys/kernel/debug/dri.\n");
381 "DRM: Error sysfs_device_add.\n");
386 DRM_DEBUG(
"new minor assigned %d\n", minor_id);
391 if (new_minor->type == DRM_MINOR_LEGACY)
414 struct drm_minor *
minor = *minor_p;
416 DRM_DEBUG(
"release secondary minor %d\n", minor->index);
418 if (minor->type == DRM_MINOR_LEGACY)
420 #if defined(CONFIG_DEBUG_FS)
421 drm_debugfs_cleanup(minor);
434 static void drm_unplug_minor(
struct drm_minor *minor)
448 struct drm_driver *
driver;
449 struct drm_map_list *r_list, *list_temp;
454 DRM_ERROR(
"cleanup called no dev\n");
457 driver = dev->driver;
461 if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) &&
462 dev->agp && dev->agp->agp_mtrr >= 0) {
464 retval =
mtrr_del(dev->agp->agp_mtrr,
465 dev->agp->agp_info.aper_base,
466 dev->agp->agp_info.aper_size * 1024 * 1024);
467 DRM_DEBUG(
"mtrr_del=%d\n", retval);
470 if (dev->driver->unload)
471 dev->driver->unload(dev);
473 if (drm_core_has_AGP(dev) && dev->agp) {
486 if (drm_core_check_feature(dev, DRIVER_MODESET))
489 if (driver->driver_features & DRIVER_GEM)
506 if (drm_core_check_feature(dev, DRIVER_MODESET))
507 drm_unplug_minor(dev->control);
508 drm_unplug_minor(dev->primary);
512 drm_device_set_unplugged(dev);
514 if (dev->open_count == 0) {