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