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