xref: /dflybsd-src/sys/dev/drm/ttm/ttm_module.c (revision 932d855e0922ed9e1decd9e1557d1ad3c065b76b)
13a2096e8SFrançois Tigeot /**************************************************************************
23a2096e8SFrançois Tigeot  *
33a2096e8SFrançois Tigeot  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
43a2096e8SFrançois Tigeot  * All Rights Reserved.
53a2096e8SFrançois Tigeot  *
63a2096e8SFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
73a2096e8SFrançois Tigeot  * copy of this software and associated documentation files (the
83a2096e8SFrançois Tigeot  * "Software"), to deal in the Software without restriction, including
93a2096e8SFrançois Tigeot  * without limitation the rights to use, copy, modify, merge, publish,
103a2096e8SFrançois Tigeot  * distribute, sub license, and/or sell copies of the Software, and to
113a2096e8SFrançois Tigeot  * permit persons to whom the Software is furnished to do so, subject to
123a2096e8SFrançois Tigeot  * the following conditions:
133a2096e8SFrançois Tigeot  *
143a2096e8SFrançois Tigeot  * The above copyright notice and this permission notice (including the
153a2096e8SFrançois Tigeot  * next paragraph) shall be included in all copies or substantial portions
163a2096e8SFrançois Tigeot  * of the Software.
173a2096e8SFrançois Tigeot  *
183a2096e8SFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
193a2096e8SFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
203a2096e8SFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
213a2096e8SFrançois Tigeot  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
223a2096e8SFrançois Tigeot  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
233a2096e8SFrançois Tigeot  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
243a2096e8SFrançois Tigeot  * USE OR OTHER DEALINGS IN THE SOFTWARE.
253a2096e8SFrançois Tigeot  *
263a2096e8SFrançois Tigeot  **************************************************************************/
273a2096e8SFrançois Tigeot /*
283a2096e8SFrançois Tigeot  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
293a2096e8SFrançois Tigeot  * 	    Jerome Glisse
303a2096e8SFrançois Tigeot  */
313a2096e8SFrançois Tigeot #include <linux/module.h>
323a2096e8SFrançois Tigeot #include <linux/device.h>
333a2096e8SFrançois Tigeot #include <linux/sched.h>
343a2096e8SFrançois Tigeot #include <drm/ttm/ttm_module.h>
353a2096e8SFrançois Tigeot #include <drm/drm_sysfs.h>
363a2096e8SFrançois Tigeot 
373a2096e8SFrançois Tigeot static DECLARE_WAIT_QUEUE_HEAD(exit_q);
381cfef1a5SFrançois Tigeot static atomic_t device_released;
393a2096e8SFrançois Tigeot 
403a2096e8SFrançois Tigeot #if 0
413a2096e8SFrançois Tigeot static struct device_type ttm_drm_class_type = {
423a2096e8SFrançois Tigeot 	.name = "ttm",
433a2096e8SFrançois Tigeot 	/**
443a2096e8SFrançois Tigeot 	 * Add pm ops here.
453a2096e8SFrançois Tigeot 	 */
463a2096e8SFrançois Tigeot };
473a2096e8SFrançois Tigeot 
483a2096e8SFrançois Tigeot static void ttm_drm_class_device_release(struct device *dev)
493a2096e8SFrançois Tigeot {
503a2096e8SFrançois Tigeot 	atomic_set(&device_released, 1);
513a2096e8SFrançois Tigeot 	wake_up_all(&exit_q);
523a2096e8SFrançois Tigeot }
533a2096e8SFrançois Tigeot #endif
543a2096e8SFrançois Tigeot 
553a2096e8SFrançois Tigeot static struct device ttm_drm_class_device = {
563a2096e8SFrançois Tigeot #if 0
573a2096e8SFrançois Tigeot 	.type = &ttm_drm_class_type,
583a2096e8SFrançois Tigeot 	.release = &ttm_drm_class_device_release
593a2096e8SFrançois Tigeot #endif
603a2096e8SFrançois Tigeot };
613a2096e8SFrançois Tigeot 
ttm_get_kobj(void)623a2096e8SFrançois Tigeot struct kobject *ttm_get_kobj(void)
633a2096e8SFrançois Tigeot {
643a2096e8SFrançois Tigeot 	struct kobject *kobj = &ttm_drm_class_device.kobj;
653a2096e8SFrançois Tigeot 	BUG_ON(kobj == NULL);
663a2096e8SFrançois Tigeot 	return kobj;
673a2096e8SFrançois Tigeot }
683a2096e8SFrançois Tigeot 
ttm_init(void)693a2096e8SFrançois Tigeot static int __init ttm_init(void)
703a2096e8SFrançois Tigeot {
713a2096e8SFrançois Tigeot 	int ret;
723a2096e8SFrançois Tigeot 
733a2096e8SFrançois Tigeot 	ret = dev_set_name(&ttm_drm_class_device, "ttm");
743a2096e8SFrançois Tigeot 	if (unlikely(ret != 0))
753a2096e8SFrançois Tigeot 		return ret;
763a2096e8SFrançois Tigeot 
773a2096e8SFrançois Tigeot 	atomic_set(&device_released, 0);
783a2096e8SFrançois Tigeot 	ret = drm_class_device_register(&ttm_drm_class_device);
793a2096e8SFrançois Tigeot 	if (unlikely(ret != 0))
803a2096e8SFrançois Tigeot 		goto out_no_dev_reg;
813a2096e8SFrançois Tigeot 
823a2096e8SFrançois Tigeot 	return 0;
833a2096e8SFrançois Tigeot out_no_dev_reg:
843a2096e8SFrançois Tigeot 	atomic_set(&device_released, 1);
853a2096e8SFrançois Tigeot 	wake_up_all(&exit_q);
863a2096e8SFrançois Tigeot 	return ret;
873a2096e8SFrançois Tigeot }
883a2096e8SFrançois Tigeot 
ttm_exit(void)893a2096e8SFrançois Tigeot static void __exit ttm_exit(void)
903a2096e8SFrançois Tigeot {
913a2096e8SFrançois Tigeot 	drm_class_device_unregister(&ttm_drm_class_device);
923a2096e8SFrançois Tigeot 
933a2096e8SFrançois Tigeot 	/**
943a2096e8SFrançois Tigeot 	 * Refuse to unload until the TTM device is released.
953a2096e8SFrançois Tigeot 	 * Not sure this is 100% needed.
963a2096e8SFrançois Tigeot 	 */
97*932d855eSSergey Zigachev 	kprintf("#10#begin#: ttm_exit.wait_event\n");
983a2096e8SFrançois Tigeot 	wait_event(exit_q, atomic_read(&device_released) == 1);
99*932d855eSSergey Zigachev 	kprintf("#10#end#: ttm_exit.wait_event\n");
1003a2096e8SFrançois Tigeot }
1013a2096e8SFrançois Tigeot 
1023a2096e8SFrançois Tigeot module_init(ttm_init);
1033a2096e8SFrançois Tigeot module_exit(ttm_exit);
1043a2096e8SFrançois Tigeot 
1053a2096e8SFrançois Tigeot MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
1063a2096e8SFrançois Tigeot MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
107