aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/ttm
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2010-03-08 19:56:52 -0500
committerDave Airlie <airlied@redhat.com>2010-08-03 19:46:06 -0400
commitba4420c224c2808f2661cf8428f43ceef7a73a4a (patch)
tree67b32498483c797c76e8f504a83746bdef35db7d /drivers/gpu/drm/ttm
parent2581afccadd347bf97c3a5620ba72c99aca8c355 (diff)
drm: move ttm global code to core drm
I wrote this for the prime sharing work, but I also noticed other external non-upstream drivers from a large company carrying a similiar patch, so I may as well ship it in master. Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/ttm')
-rw-r--r--drivers/gpu/drm/ttm/Makefile2
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c4
-rw-r--r--drivers/gpu/drm/ttm/ttm_global.c112
-rw-r--r--drivers/gpu/drm/ttm/ttm_module.c4
4 files changed, 3 insertions, 119 deletions
diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
index 4256e200647..b256d4adfaf 100644
--- a/drivers/gpu/drm/ttm/Makefile
+++ b/drivers/gpu/drm/ttm/Makefile
@@ -3,7 +3,7 @@
3 3
4ccflags-y := -Iinclude/drm 4ccflags-y := -Iinclude/drm
5ttm-y := ttm_agp_backend.o ttm_memory.o ttm_tt.o ttm_bo.o \ 5ttm-y := ttm_agp_backend.o ttm_memory.o ttm_tt.o ttm_bo.o \
6 ttm_bo_util.o ttm_bo_vm.o ttm_module.o ttm_global.o \ 6 ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
7 ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o 7 ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o
8 8
9obj-$(CONFIG_DRM_TTM) += ttm.o 9obj-$(CONFIG_DRM_TTM) += ttm.o
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 9763288c6b2..cb4cf7ef4d1 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1395,7 +1395,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)
1395 kfree(glob); 1395 kfree(glob);
1396} 1396}
1397 1397
1398void ttm_bo_global_release(struct ttm_global_reference *ref) 1398void ttm_bo_global_release(struct drm_global_reference *ref)
1399{ 1399{
1400 struct ttm_bo_global *glob = ref->object; 1400 struct ttm_bo_global *glob = ref->object;
1401 1401
@@ -1404,7 +1404,7 @@ void ttm_bo_global_release(struct ttm_global_reference *ref)
1404} 1404}
1405EXPORT_SYMBOL(ttm_bo_global_release); 1405EXPORT_SYMBOL(ttm_bo_global_release);
1406 1406
1407int ttm_bo_global_init(struct ttm_global_reference *ref) 1407int ttm_bo_global_init(struct drm_global_reference *ref)
1408{ 1408{
1409 struct ttm_bo_global_ref *bo_ref = 1409 struct ttm_bo_global_ref *bo_ref =
1410 container_of(ref, struct ttm_bo_global_ref, ref); 1410 container_of(ref, struct ttm_bo_global_ref, ref);
diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
deleted file mode 100644
index b17007178a3..00000000000
--- a/drivers/gpu/drm/ttm/ttm_global.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/**************************************************************************
2 *
3 * Copyright 2008-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 */
30
31#include "ttm/ttm_module.h"
32#include <linux/mutex.h>
33#include <linux/slab.h>
34#include <linux/module.h>
35
36struct ttm_global_item {
37 struct mutex mutex;
38 void *object;
39 int refcount;
40};
41
42static struct ttm_global_item glob[TTM_GLOBAL_NUM];
43
44void ttm_global_init(void)
45{
46 int i;
47
48 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
49 struct ttm_global_item *item = &glob[i];
50 mutex_init(&item->mutex);
51 item->object = NULL;
52 item->refcount = 0;
53 }
54}
55
56void ttm_global_release(void)
57{
58 int i;
59 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
60 struct ttm_global_item *item = &glob[i];
61 BUG_ON(item->object != NULL);
62 BUG_ON(item->refcount != 0);
63 }
64}
65
66int ttm_global_item_ref(struct ttm_global_reference *ref)
67{
68 int ret;
69 struct ttm_global_item *item = &glob[ref->global_type];
70 void *object;
71
72 mutex_lock(&item->mutex);
73 if (item->refcount == 0) {
74 item->object = kzalloc(ref->size, GFP_KERNEL);
75 if (unlikely(item->object == NULL)) {
76 ret = -ENOMEM;
77 goto out_err;
78 }
79
80 ref->object = item->object;
81 ret = ref->init(ref);
82 if (unlikely(ret != 0))
83 goto out_err;
84
85 }
86 ++item->refcount;
87 ref->object = item->object;
88 object = item->object;
89 mutex_unlock(&item->mutex);
90 return 0;
91out_err:
92 mutex_unlock(&item->mutex);
93 item->object = NULL;
94 return ret;
95}
96EXPORT_SYMBOL(ttm_global_item_ref);
97
98void ttm_global_item_unref(struct ttm_global_reference *ref)
99{
100 struct ttm_global_item *item = &glob[ref->global_type];
101
102 mutex_lock(&item->mutex);
103 BUG_ON(item->refcount == 0);
104 BUG_ON(ref->object != item->object);
105 if (--item->refcount == 0) {
106 ref->release(ref);
107 item->object = NULL;
108 }
109 mutex_unlock(&item->mutex);
110}
111EXPORT_SYMBOL(ttm_global_item_unref);
112
diff --git a/drivers/gpu/drm/ttm/ttm_module.c b/drivers/gpu/drm/ttm/ttm_module.c
index 9a6edbfeaa9..902d7cf9fb4 100644
--- a/drivers/gpu/drm/ttm/ttm_module.c
+++ b/drivers/gpu/drm/ttm/ttm_module.c
@@ -70,8 +70,6 @@ static int __init ttm_init(void)
70 if (unlikely(ret != 0)) 70 if (unlikely(ret != 0))
71 return ret; 71 return ret;
72 72
73 ttm_global_init();
74
75 atomic_set(&device_released, 0); 73 atomic_set(&device_released, 0);
76 ret = drm_class_device_register(&ttm_drm_class_device); 74 ret = drm_class_device_register(&ttm_drm_class_device);
77 if (unlikely(ret != 0)) 75 if (unlikely(ret != 0))
@@ -81,7 +79,6 @@ static int __init ttm_init(void)
81out_no_dev_reg: 79out_no_dev_reg:
82 atomic_set(&device_released, 1); 80 atomic_set(&device_released, 1);
83 wake_up_all(&exit_q); 81 wake_up_all(&exit_q);
84 ttm_global_release();
85 return ret; 82 return ret;
86} 83}
87 84
@@ -95,7 +92,6 @@ static void __exit ttm_exit(void)
95 */ 92 */
96 93
97 wait_event(exit_q, atomic_read(&device_released) == 1); 94 wait_event(exit_q, atomic_read(&device_released) == 1);
98 ttm_global_release();
99} 95}
100 96
101module_init(ttm_init); 97module_init(ttm_init);