ttm_module.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. /*
  28. * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  29. * Jerome Glisse
  30. */
  31. #include <linux/module.h>
  32. #include <linux/device.h>
  33. #include <linux/sched.h>
  34. #include <drm/ttm/ttm_module.h>
  35. #include <drm/drm_sysfs.h>
  36. static DECLARE_WAIT_QUEUE_HEAD(exit_q);
  37. static atomic_t device_released;
  38. static struct device_type ttm_drm_class_type = {
  39. .name = "ttm",
  40. /**
  41. * Add pm ops here.
  42. */
  43. };
  44. static void ttm_drm_class_device_release(struct device *dev)
  45. {
  46. atomic_set(&device_released, 1);
  47. wake_up_all(&exit_q);
  48. }
  49. static struct device ttm_drm_class_device = {
  50. .type = &ttm_drm_class_type,
  51. .release = &ttm_drm_class_device_release
  52. };
  53. struct kobject *ttm_get_kobj(void)
  54. {
  55. struct kobject *kobj = &ttm_drm_class_device.kobj;
  56. BUG_ON(kobj == NULL);
  57. return kobj;
  58. }
  59. static int __init ttm_init(void)
  60. {
  61. int ret;
  62. ret = dev_set_name(&ttm_drm_class_device, "ttm");
  63. if (unlikely(ret != 0))
  64. return ret;
  65. atomic_set(&device_released, 0);
  66. ret = drm_class_device_register(&ttm_drm_class_device);
  67. if (unlikely(ret != 0))
  68. goto out_no_dev_reg;
  69. return 0;
  70. out_no_dev_reg:
  71. atomic_set(&device_released, 1);
  72. wake_up_all(&exit_q);
  73. return ret;
  74. }
  75. static void __exit ttm_exit(void)
  76. {
  77. drm_class_device_unregister(&ttm_drm_class_device);
  78. /**
  79. * Refuse to unload until the TTM device is released.
  80. * Not sure this is 100% needed.
  81. */
  82. wait_event(exit_q, atomic_read(&device_released) == 1);
  83. }
  84. module_init(ttm_init);
  85. module_exit(ttm_exit);
  86. MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
  87. MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
  88. MODULE_LICENSE("GPL and additional rights");