ttm_module.c 3.0 KB

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