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