aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/drm_drv.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2008-04-21 02:47:32 -0400
committerDave Airlie <airlied@linux.ie>2008-04-26 03:55:07 -0400
commit2c14f28be2a3f2a2e9861b156d64fbe2bc7000c3 (patch)
treedbf55c07d1b245a45330e0d879833df29954fe12 /drivers/char/drm/drm_drv.c
parent7b832b56bd971348329c3f4c753ca0abfdf3a3d1 (diff)
drm: reorganise minor number handling using backported modesetting code.
rips out the head crap and replaces it with an idr and drm_minor structure Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/char/drm/drm_drv.c')
-rw-r--r--drivers/char/drm/drm_drv.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index 0e7af53c87de..fc54140551a7 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -313,35 +313,36 @@ static void drm_cleanup(struct drm_device * dev)
313 drm_ht_remove(&dev->map_hash); 313 drm_ht_remove(&dev->map_hash);
314 drm_ctxbitmap_cleanup(dev); 314 drm_ctxbitmap_cleanup(dev);
315 315
316 drm_put_head(&dev->primary); 316 drm_put_minor(&dev->primary);
317 if (drm_put_dev(dev)) 317 if (drm_put_dev(dev))
318 DRM_ERROR("Cannot unload module\n"); 318 DRM_ERROR("Cannot unload module\n");
319} 319}
320 320
321void drm_exit(struct drm_driver *driver) 321int drm_minors_cleanup(int id, void *ptr, void *data)
322{ 322{
323 int i; 323 struct drm_minor *minor = ptr;
324 struct drm_device *dev = NULL; 324 struct drm_device *dev;
325 struct drm_head *head; 325 struct drm_driver *driver = data;
326
327 dev = minor->dev;
328 if (minor->dev->driver != driver)
329 return 0;
330
331 if (minor->type != DRM_MINOR_LEGACY)
332 return 0;
326 333
334 if (dev)
335 pci_dev_put(dev->pdev);
336 drm_cleanup(dev);
337 return 1;
338}
339
340void drm_exit(struct drm_driver *driver)
341{
327 DRM_DEBUG("\n"); 342 DRM_DEBUG("\n");
328 343
329 for (i = 0; i < drm_cards_limit; i++) { 344 idr_for_each(&drm_minors_idr, &drm_minors_cleanup, driver);
330 head = drm_heads[i]; 345
331 if (!head)
332 continue;
333 if (!head->dev)
334 continue;
335 if (head->dev->driver != driver)
336 continue;
337 dev = head->dev;
338 if (dev) {
339 /* release the pci driver */
340 if (dev->pdev)
341 pci_dev_put(dev->pdev);
342 drm_cleanup(dev);
343 }
344 }
345 DRM_INFO("Module unloaded\n"); 346 DRM_INFO("Module unloaded\n");
346} 347}
347 348
@@ -357,13 +358,7 @@ static int __init drm_core_init(void)
357{ 358{
358 int ret = -ENOMEM; 359 int ret = -ENOMEM;
359 360
360 drm_cards_limit = 361 idr_init(&drm_minors_idr);
361 (drm_cards_limit <
362 DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
363 drm_heads =
364 drm_calloc(drm_cards_limit, sizeof(*drm_heads), DRM_MEM_STUB);
365 if (!drm_heads)
366 goto err_p1;
367 362
368 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) 363 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
369 goto err_p1; 364 goto err_p1;
@@ -391,7 +386,8 @@ err_p3:
391 drm_sysfs_destroy(); 386 drm_sysfs_destroy();
392err_p2: 387err_p2:
393 unregister_chrdev(DRM_MAJOR, "drm"); 388 unregister_chrdev(DRM_MAJOR, "drm");
394 drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB); 389
390 idr_destroy(&drm_minors_idr);
395err_p1: 391err_p1:
396 return ret; 392 return ret;
397} 393}
@@ -403,7 +399,7 @@ static void __exit drm_core_exit(void)
403 399
404 unregister_chrdev(DRM_MAJOR, "drm"); 400 unregister_chrdev(DRM_MAJOR, "drm");
405 401
406 drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB); 402 idr_destroy(&drm_minors_idr);
407} 403}
408 404
409module_init(drm_core_init); 405module_init(drm_core_init);
@@ -452,7 +448,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
452 unsigned int cmd, unsigned long arg) 448 unsigned int cmd, unsigned long arg)
453{ 449{
454 struct drm_file *file_priv = filp->private_data; 450 struct drm_file *file_priv = filp->private_data;
455 struct drm_device *dev = file_priv->head->dev; 451 struct drm_device *dev = file_priv->minor->dev;
456 struct drm_ioctl_desc *ioctl; 452 struct drm_ioctl_desc *ioctl;
457 drm_ioctl_t *func; 453 drm_ioctl_t *func;
458 unsigned int nr = DRM_IOCTL_NR(cmd); 454 unsigned int nr = DRM_IOCTL_NR(cmd);
@@ -465,7 +461,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
465 461
466 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n", 462 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
467 task_pid_nr(current), cmd, nr, 463 task_pid_nr(current), cmd, nr,
468 (long)old_encode_dev(file_priv->head->device), 464 (long)old_encode_dev(file_priv->minor->device),
469 file_priv->authenticated); 465 file_priv->authenticated);
470 466
471 if ((nr >= DRM_CORE_IOCTL_COUNT) && 467 if ((nr >= DRM_CORE_IOCTL_COUNT) &&