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