aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_drv.c1
-rw-r--r--drivers/gpu/drm/drm_global.c (renamed from drivers/gpu/drm/ttm/ttm_global.c)30
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_ttm.c20
-rw-r--r--drivers/gpu/drm/radeon/radeon.h2
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c20
-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_module.c4
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c20
-rw-r--r--include/drm/drm.h2
-rw-r--r--include/drm/drmP.h2
-rw-r--r--include/drm/drm_global.h53
-rw-r--r--include/drm/ttm/ttm_bo_driver.h7
-rw-r--r--include/drm/ttm/ttm_module.h20
17 files changed, 114 insertions, 79 deletions
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index df8f92322865..f3a23a329f4e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -12,7 +12,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
12 drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \ 12 drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
13 drm_crtc.o drm_modes.o drm_edid.o \ 13 drm_crtc.o drm_modes.o drm_edid.o \
14 drm_info.o drm_debugfs.o drm_encoder_slave.o \ 14 drm_info.o drm_debugfs.o drm_encoder_slave.o \
15 drm_trace_points.o 15 drm_trace_points.o drm_global.o
16 16
17drm-$(CONFIG_COMPAT) += drm_ioc32.o 17drm-$(CONFIG_COMPAT) += drm_ioc32.o
18 18
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index b5a51686f492..d5b349d279f5 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -288,6 +288,7 @@ static int __init drm_core_init(void)
288{ 288{
289 int ret = -ENOMEM; 289 int ret = -ENOMEM;
290 290
291 drm_global_init();
291 idr_init(&drm_minors_idr); 292 idr_init(&drm_minors_idr);
292 293
293 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) 294 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/drm_global.c
index b17007178a36..c87dc96444de 100644
--- a/drivers/gpu/drm/ttm/ttm_global.c
+++ b/drivers/gpu/drm/drm_global.c
@@ -28,45 +28,45 @@
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */ 29 */
30 30
31#include "ttm/ttm_module.h"
32#include <linux/mutex.h> 31#include <linux/mutex.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/module.h> 33#include <linux/module.h>
34#include "drm_global.h"
35 35
36struct ttm_global_item { 36struct drm_global_item {
37 struct mutex mutex; 37 struct mutex mutex;
38 void *object; 38 void *object;
39 int refcount; 39 int refcount;
40}; 40};
41 41
42static struct ttm_global_item glob[TTM_GLOBAL_NUM]; 42static struct drm_global_item glob[DRM_GLOBAL_NUM];
43 43
44void ttm_global_init(void) 44void drm_global_init(void)
45{ 45{
46 int i; 46 int i;
47 47
48 for (i = 0; i < TTM_GLOBAL_NUM; ++i) { 48 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
49 struct ttm_global_item *item = &glob[i]; 49 struct drm_global_item *item = &glob[i];
50 mutex_init(&item->mutex); 50 mutex_init(&item->mutex);
51 item->object = NULL; 51 item->object = NULL;
52 item->refcount = 0; 52 item->refcount = 0;
53 } 53 }
54} 54}
55 55
56void ttm_global_release(void) 56void drm_global_release(void)
57{ 57{
58 int i; 58 int i;
59 for (i = 0; i < TTM_GLOBAL_NUM; ++i) { 59 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
60 struct ttm_global_item *item = &glob[i]; 60 struct drm_global_item *item = &glob[i];
61 BUG_ON(item->object != NULL); 61 BUG_ON(item->object != NULL);
62 BUG_ON(item->refcount != 0); 62 BUG_ON(item->refcount != 0);
63 } 63 }
64} 64}
65 65
66int ttm_global_item_ref(struct ttm_global_reference *ref) 66int drm_global_item_ref(struct drm_global_reference *ref)
67{ 67{
68 int ret; 68 int ret;
69 struct ttm_global_item *item = &glob[ref->global_type]; 69 struct drm_global_item *item = &glob[ref->global_type];
70 void *object; 70 void *object;
71 71
72 mutex_lock(&item->mutex); 72 mutex_lock(&item->mutex);
@@ -93,11 +93,11 @@ out_err:
93 item->object = NULL; 93 item->object = NULL;
94 return ret; 94 return ret;
95} 95}
96EXPORT_SYMBOL(ttm_global_item_ref); 96EXPORT_SYMBOL(drm_global_item_ref);
97 97
98void ttm_global_item_unref(struct ttm_global_reference *ref) 98void drm_global_item_unref(struct drm_global_reference *ref)
99{ 99{
100 struct ttm_global_item *item = &glob[ref->global_type]; 100 struct drm_global_item *item = &glob[ref->global_type];
101 101
102 mutex_lock(&item->mutex); 102 mutex_lock(&item->mutex);
103 BUG_ON(item->refcount == 0); 103 BUG_ON(item->refcount == 0);
@@ -108,5 +108,5 @@ void ttm_global_item_unref(struct ttm_global_reference *ref)
108 } 108 }
109 mutex_unlock(&item->mutex); 109 mutex_unlock(&item->mutex);
110} 110}
111EXPORT_SYMBOL(ttm_global_item_unref); 111EXPORT_SYMBOL(drm_global_item_unref);
112 112
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index d0a35d9ba522..e15db15dca77 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -533,7 +533,7 @@ struct drm_nouveau_private {
533 struct list_head vbl_waiting; 533 struct list_head vbl_waiting;
534 534
535 struct { 535 struct {
536 struct ttm_global_reference mem_global_ref; 536 struct drm_global_reference mem_global_ref;
537 struct ttm_bo_global_ref bo_global_ref; 537 struct ttm_bo_global_ref bo_global_ref;
538 struct ttm_bo_device bdev; 538 struct ttm_bo_device bdev;
539 spinlock_t bo_list_lock; 539 spinlock_t bo_list_lock;
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index c385d50f041b..bd35f930568c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -42,13 +42,13 @@ nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)
42} 42}
43 43
44static int 44static int
45nouveau_ttm_mem_global_init(struct ttm_global_reference *ref) 45nouveau_ttm_mem_global_init(struct drm_global_reference *ref)
46{ 46{
47 return ttm_mem_global_init(ref->object); 47 return ttm_mem_global_init(ref->object);
48} 48}
49 49
50static void 50static void
51nouveau_ttm_mem_global_release(struct ttm_global_reference *ref) 51nouveau_ttm_mem_global_release(struct drm_global_reference *ref)
52{ 52{
53 ttm_mem_global_release(ref->object); 53 ttm_mem_global_release(ref->object);
54} 54}
@@ -56,16 +56,16 @@ nouveau_ttm_mem_global_release(struct ttm_global_reference *ref)
56int 56int
57nouveau_ttm_global_init(struct drm_nouveau_private *dev_priv) 57nouveau_ttm_global_init(struct drm_nouveau_private *dev_priv)
58{ 58{
59 struct ttm_global_reference *global_ref; 59 struct drm_global_reference *global_ref;
60 int ret; 60 int ret;
61 61
62 global_ref = &dev_priv->ttm.mem_global_ref; 62 global_ref = &dev_priv->ttm.mem_global_ref;
63 global_ref->global_type = TTM_GLOBAL_TTM_MEM; 63 global_ref->global_type = DRM_GLOBAL_TTM_MEM;
64 global_ref->size = sizeof(struct ttm_mem_global); 64 global_ref->size = sizeof(struct ttm_mem_global);
65 global_ref->init = &nouveau_ttm_mem_global_init; 65 global_ref->init = &nouveau_ttm_mem_global_init;
66 global_ref->release = &nouveau_ttm_mem_global_release; 66 global_ref->release = &nouveau_ttm_mem_global_release;
67 67
68 ret = ttm_global_item_ref(global_ref); 68 ret = drm_global_item_ref(global_ref);
69 if (unlikely(ret != 0)) { 69 if (unlikely(ret != 0)) {
70 DRM_ERROR("Failed setting up TTM memory accounting\n"); 70 DRM_ERROR("Failed setting up TTM memory accounting\n");
71 dev_priv->ttm.mem_global_ref.release = NULL; 71 dev_priv->ttm.mem_global_ref.release = NULL;
@@ -74,15 +74,15 @@ nouveau_ttm_global_init(struct drm_nouveau_private *dev_priv)
74 74
75 dev_priv->ttm.bo_global_ref.mem_glob = global_ref->object; 75 dev_priv->ttm.bo_global_ref.mem_glob = global_ref->object;
76 global_ref = &dev_priv->ttm.bo_global_ref.ref; 76 global_ref = &dev_priv->ttm.bo_global_ref.ref;
77 global_ref->global_type = TTM_GLOBAL_TTM_BO; 77 global_ref->global_type = DRM_GLOBAL_TTM_BO;
78 global_ref->size = sizeof(struct ttm_bo_global); 78 global_ref->size = sizeof(struct ttm_bo_global);
79 global_ref->init = &ttm_bo_global_init; 79 global_ref->init = &ttm_bo_global_init;
80 global_ref->release = &ttm_bo_global_release; 80 global_ref->release = &ttm_bo_global_release;
81 81
82 ret = ttm_global_item_ref(global_ref); 82 ret = drm_global_item_ref(global_ref);
83 if (unlikely(ret != 0)) { 83 if (unlikely(ret != 0)) {
84 DRM_ERROR("Failed setting up TTM BO subsystem\n"); 84 DRM_ERROR("Failed setting up TTM BO subsystem\n");
85 ttm_global_item_unref(&dev_priv->ttm.mem_global_ref); 85 drm_global_item_unref(&dev_priv->ttm.mem_global_ref);
86 dev_priv->ttm.mem_global_ref.release = NULL; 86 dev_priv->ttm.mem_global_ref.release = NULL;
87 return ret; 87 return ret;
88 } 88 }
@@ -96,8 +96,8 @@ nouveau_ttm_global_release(struct drm_nouveau_private *dev_priv)
96 if (dev_priv->ttm.mem_global_ref.release == NULL) 96 if (dev_priv->ttm.mem_global_ref.release == NULL)
97 return; 97 return;
98 98
99 ttm_global_item_unref(&dev_priv->ttm.bo_global_ref.ref); 99 drm_global_item_unref(&dev_priv->ttm.bo_global_ref.ref);
100 ttm_global_item_unref(&dev_priv->ttm.mem_global_ref); 100 drm_global_item_unref(&dev_priv->ttm.mem_global_ref);
101 dev_priv->ttm.mem_global_ref.release = NULL; 101 dev_priv->ttm.mem_global_ref.release = NULL;
102} 102}
103 103
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 368fecf0c2b7..3cd1c470b777 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -235,7 +235,7 @@ struct radeon_surface_reg {
235 */ 235 */
236struct radeon_mman { 236struct radeon_mman {
237 struct ttm_bo_global_ref bo_global_ref; 237 struct ttm_bo_global_ref bo_global_ref;
238 struct ttm_global_reference mem_global_ref; 238 struct drm_global_reference mem_global_ref;
239 struct ttm_bo_device bdev; 239 struct ttm_bo_device bdev;
240 bool mem_global_referenced; 240 bool mem_global_referenced;
241 bool initialized; 241 bool initialized;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index e9918d88f5b0..84c53e41a88f 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -59,28 +59,28 @@ static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
59/* 59/*
60 * Global memory. 60 * Global memory.
61 */ 61 */
62static int radeon_ttm_mem_global_init(struct ttm_global_reference *ref) 62static int radeon_ttm_mem_global_init(struct drm_global_reference *ref)
63{ 63{
64 return ttm_mem_global_init(ref->object); 64 return ttm_mem_global_init(ref->object);
65} 65}
66 66
67static void radeon_ttm_mem_global_release(struct ttm_global_reference *ref) 67static void radeon_ttm_mem_global_release(struct drm_global_reference *ref)
68{ 68{
69 ttm_mem_global_release(ref->object); 69 ttm_mem_global_release(ref->object);
70} 70}
71 71
72static int radeon_ttm_global_init(struct radeon_device *rdev) 72static int radeon_ttm_global_init(struct radeon_device *rdev)
73{ 73{
74 struct ttm_global_reference *global_ref; 74 struct drm_global_reference *global_ref;
75 int r; 75 int r;
76 76
77 rdev->mman.mem_global_referenced = false; 77 rdev->mman.mem_global_referenced = false;
78 global_ref = &rdev->mman.mem_global_ref; 78 global_ref = &rdev->mman.mem_global_ref;
79 global_ref->global_type = TTM_GLOBAL_TTM_MEM; 79 global_ref->global_type = DRM_GLOBAL_TTM_MEM;
80 global_ref->size = sizeof(struct ttm_mem_global); 80 global_ref->size = sizeof(struct ttm_mem_global);
81 global_ref->init = &radeon_ttm_mem_global_init; 81 global_ref->init = &radeon_ttm_mem_global_init;
82 global_ref->release = &radeon_ttm_mem_global_release; 82 global_ref->release = &radeon_ttm_mem_global_release;
83 r = ttm_global_item_ref(global_ref); 83 r = drm_global_item_ref(global_ref);
84 if (r != 0) { 84 if (r != 0) {
85 DRM_ERROR("Failed setting up TTM memory accounting " 85 DRM_ERROR("Failed setting up TTM memory accounting "
86 "subsystem.\n"); 86 "subsystem.\n");
@@ -90,14 +90,14 @@ static int radeon_ttm_global_init(struct radeon_device *rdev)
90 rdev->mman.bo_global_ref.mem_glob = 90 rdev->mman.bo_global_ref.mem_glob =
91 rdev->mman.mem_global_ref.object; 91 rdev->mman.mem_global_ref.object;
92 global_ref = &rdev->mman.bo_global_ref.ref; 92 global_ref = &rdev->mman.bo_global_ref.ref;
93 global_ref->global_type = TTM_GLOBAL_TTM_BO; 93 global_ref->global_type = DRM_GLOBAL_TTM_BO;
94 global_ref->size = sizeof(struct ttm_bo_global); 94 global_ref->size = sizeof(struct ttm_bo_global);
95 global_ref->init = &ttm_bo_global_init; 95 global_ref->init = &ttm_bo_global_init;
96 global_ref->release = &ttm_bo_global_release; 96 global_ref->release = &ttm_bo_global_release;
97 r = ttm_global_item_ref(global_ref); 97 r = drm_global_item_ref(global_ref);
98 if (r != 0) { 98 if (r != 0) {
99 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 99 DRM_ERROR("Failed setting up TTM BO subsystem.\n");
100 ttm_global_item_unref(&rdev->mman.mem_global_ref); 100 drm_global_item_unref(&rdev->mman.mem_global_ref);
101 return r; 101 return r;
102 } 102 }
103 103
@@ -108,8 +108,8 @@ static int radeon_ttm_global_init(struct radeon_device *rdev)
108static void radeon_ttm_global_fini(struct radeon_device *rdev) 108static void radeon_ttm_global_fini(struct radeon_device *rdev)
109{ 109{
110 if (rdev->mman.mem_global_referenced) { 110 if (rdev->mman.mem_global_referenced) {
111 ttm_global_item_unref(&rdev->mman.bo_global_ref.ref); 111 drm_global_item_unref(&rdev->mman.bo_global_ref.ref);
112 ttm_global_item_unref(&rdev->mman.mem_global_ref); 112 drm_global_item_unref(&rdev->mman.mem_global_ref);
113 rdev->mman.mem_global_referenced = false; 113 rdev->mman.mem_global_referenced = false;
114 } 114 }
115} 115}
diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
index 4256e2006476..b256d4adfafe 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 9763288c6b2d..cb4cf7ef4d1e 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_module.c b/drivers/gpu/drm/ttm/ttm_module.c
index 9a6edbfeaa9e..902d7cf9fb4e 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);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index eaad52095339..429f917b60bf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -164,7 +164,7 @@ struct vmw_vga_topology_state {
164struct vmw_private { 164struct vmw_private {
165 struct ttm_bo_device bdev; 165 struct ttm_bo_device bdev;
166 struct ttm_bo_global_ref bo_global_ref; 166 struct ttm_bo_global_ref bo_global_ref;
167 struct ttm_global_reference mem_global_ref; 167 struct drm_global_reference mem_global_ref;
168 168
169 struct vmw_fifo_state fifo; 169 struct vmw_fifo_state fifo;
170 170
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
index e3df4adfb4d8..83123287c60c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
@@ -44,29 +44,29 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
44 return ttm_bo_mmap(filp, vma, &dev_priv->bdev); 44 return ttm_bo_mmap(filp, vma, &dev_priv->bdev);
45} 45}
46 46
47static int vmw_ttm_mem_global_init(struct ttm_global_reference *ref) 47static int vmw_ttm_mem_global_init(struct drm_global_reference *ref)
48{ 48{
49 DRM_INFO("global init.\n"); 49 DRM_INFO("global init.\n");
50 return ttm_mem_global_init(ref->object); 50 return ttm_mem_global_init(ref->object);
51} 51}
52 52
53static void vmw_ttm_mem_global_release(struct ttm_global_reference *ref) 53static void vmw_ttm_mem_global_release(struct drm_global_reference *ref)
54{ 54{
55 ttm_mem_global_release(ref->object); 55 ttm_mem_global_release(ref->object);
56} 56}
57 57
58int vmw_ttm_global_init(struct vmw_private *dev_priv) 58int vmw_ttm_global_init(struct vmw_private *dev_priv)
59{ 59{
60 struct ttm_global_reference *global_ref; 60 struct drm_global_reference *global_ref;
61 int ret; 61 int ret;
62 62
63 global_ref = &dev_priv->mem_global_ref; 63 global_ref = &dev_priv->mem_global_ref;
64 global_ref->global_type = TTM_GLOBAL_TTM_MEM; 64 global_ref->global_type = DRM_GLOBAL_TTM_MEM;
65 global_ref->size = sizeof(struct ttm_mem_global); 65 global_ref->size = sizeof(struct ttm_mem_global);
66 global_ref->init = &vmw_ttm_mem_global_init; 66 global_ref->init = &vmw_ttm_mem_global_init;
67 global_ref->release = &vmw_ttm_mem_global_release; 67 global_ref->release = &vmw_ttm_mem_global_release;
68 68
69 ret = ttm_global_item_ref(global_ref); 69 ret = drm_global_item_ref(global_ref);
70 if (unlikely(ret != 0)) { 70 if (unlikely(ret != 0)) {
71 DRM_ERROR("Failed setting up TTM memory accounting.\n"); 71 DRM_ERROR("Failed setting up TTM memory accounting.\n");
72 return ret; 72 return ret;
@@ -75,11 +75,11 @@ int vmw_ttm_global_init(struct vmw_private *dev_priv)
75 dev_priv->bo_global_ref.mem_glob = 75 dev_priv->bo_global_ref.mem_glob =
76 dev_priv->mem_global_ref.object; 76 dev_priv->mem_global_ref.object;
77 global_ref = &dev_priv->bo_global_ref.ref; 77 global_ref = &dev_priv->bo_global_ref.ref;
78 global_ref->global_type = TTM_GLOBAL_TTM_BO; 78 global_ref->global_type = DRM_GLOBAL_TTM_BO;
79 global_ref->size = sizeof(struct ttm_bo_global); 79 global_ref->size = sizeof(struct ttm_bo_global);
80 global_ref->init = &ttm_bo_global_init; 80 global_ref->init = &ttm_bo_global_init;
81 global_ref->release = &ttm_bo_global_release; 81 global_ref->release = &ttm_bo_global_release;
82 ret = ttm_global_item_ref(global_ref); 82 ret = drm_global_item_ref(global_ref);
83 83
84 if (unlikely(ret != 0)) { 84 if (unlikely(ret != 0)) {
85 DRM_ERROR("Failed setting up TTM buffer objects.\n"); 85 DRM_ERROR("Failed setting up TTM buffer objects.\n");
@@ -88,12 +88,12 @@ int vmw_ttm_global_init(struct vmw_private *dev_priv)
88 88
89 return 0; 89 return 0;
90out_no_bo: 90out_no_bo:
91 ttm_global_item_unref(&dev_priv->mem_global_ref); 91 drm_global_item_unref(&dev_priv->mem_global_ref);
92 return ret; 92 return ret;
93} 93}
94 94
95void vmw_ttm_global_release(struct vmw_private *dev_priv) 95void vmw_ttm_global_release(struct vmw_private *dev_priv)
96{ 96{
97 ttm_global_item_unref(&dev_priv->bo_global_ref.ref); 97 drm_global_item_unref(&dev_priv->bo_global_ref.ref);
98 ttm_global_item_unref(&dev_priv->mem_global_ref); 98 drm_global_item_unref(&dev_priv->mem_global_ref);
99} 99}
diff --git a/include/drm/drm.h b/include/drm/drm.h
index e3f46e0cb7dc..e5f70617dec5 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -663,6 +663,8 @@ struct drm_gem_open {
663#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock) 663#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock)
664#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock) 664#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock)
665 665
666#define DRM_IOCTL_GEM_PRIME_OPEN DRM_IOWR(0x2e, struct drm_gem_open)
667
666#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30) 668#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30)
667#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31) 669#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31)
668#define DRM_IOCTL_AGP_ENABLE DRM_IOW( 0x32, struct drm_agp_mode) 670#define DRM_IOCTL_AGP_ENABLE DRM_IOW( 0x32, struct drm_agp_mode)
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 04b564bfc4a1..53017ba0ab7b 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1453,6 +1453,8 @@ void drm_gem_vm_open(struct vm_area_struct *vma);
1453void drm_gem_vm_close(struct vm_area_struct *vma); 1453void drm_gem_vm_close(struct vm_area_struct *vma);
1454int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); 1454int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1455 1455
1456#include "drm_global.h"
1457
1456static inline void 1458static inline void
1457drm_gem_object_reference(struct drm_gem_object *obj) 1459drm_gem_object_reference(struct drm_gem_object *obj)
1458{ 1460{
diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
new file mode 100644
index 000000000000..a06805eaf649
--- /dev/null
+++ b/include/drm/drm_global.h
@@ -0,0 +1,53 @@
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#ifndef _DRM_GLOBAL_H_
32#define _DRM_GLOBAL_H_
33enum drm_global_types {
34 DRM_GLOBAL_TTM_MEM = 0,
35 DRM_GLOBAL_TTM_BO,
36 DRM_GLOBAL_TTM_OBJECT,
37 DRM_GLOBAL_NUM
38};
39
40struct drm_global_reference {
41 enum drm_global_types global_type;
42 size_t size;
43 void *object;
44 int (*init) (struct drm_global_reference *);
45 void (*release) (struct drm_global_reference *);
46};
47
48extern void drm_global_init(void);
49extern void drm_global_release(void);
50extern int drm_global_item_ref(struct drm_global_reference *ref);
51extern void drm_global_item_unref(struct drm_global_reference *ref);
52
53#endif
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 0ea602da43e7..b87504235f18 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -34,6 +34,7 @@
34#include "ttm/ttm_memory.h" 34#include "ttm/ttm_memory.h"
35#include "ttm/ttm_module.h" 35#include "ttm/ttm_module.h"
36#include "drm_mm.h" 36#include "drm_mm.h"
37#include "drm_global.h"
37#include "linux/workqueue.h" 38#include "linux/workqueue.h"
38#include "linux/fs.h" 39#include "linux/fs.h"
39#include "linux/spinlock.h" 40#include "linux/spinlock.h"
@@ -362,7 +363,7 @@ struct ttm_bo_driver {
362 */ 363 */
363 364
364struct ttm_bo_global_ref { 365struct ttm_bo_global_ref {
365 struct ttm_global_reference ref; 366 struct drm_global_reference ref;
366 struct ttm_mem_global *mem_glob; 367 struct ttm_mem_global *mem_glob;
367}; 368};
368 369
@@ -687,8 +688,8 @@ extern int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
687extern void ttm_mem_io_free(struct ttm_bo_device *bdev, 688extern void ttm_mem_io_free(struct ttm_bo_device *bdev,
688 struct ttm_mem_reg *mem); 689 struct ttm_mem_reg *mem);
689 690
690extern void ttm_bo_global_release(struct ttm_global_reference *ref); 691extern void ttm_bo_global_release(struct drm_global_reference *ref);
691extern int ttm_bo_global_init(struct ttm_global_reference *ref); 692extern int ttm_bo_global_init(struct drm_global_reference *ref);
692 693
693extern int ttm_bo_device_release(struct ttm_bo_device *bdev); 694extern int ttm_bo_device_release(struct ttm_bo_device *bdev);
694 695
diff --git a/include/drm/ttm/ttm_module.h b/include/drm/ttm/ttm_module.h
index cf416aee19af..45fa318c1585 100644
--- a/include/drm/ttm/ttm_module.h
+++ b/include/drm/ttm/ttm_module.h
@@ -35,26 +35,6 @@
35struct kobject; 35struct kobject;
36 36
37#define TTM_PFX "[TTM] " 37#define TTM_PFX "[TTM] "
38
39enum ttm_global_types {
40 TTM_GLOBAL_TTM_MEM = 0,
41 TTM_GLOBAL_TTM_BO,
42 TTM_GLOBAL_TTM_OBJECT,
43 TTM_GLOBAL_NUM
44};
45
46struct ttm_global_reference {
47 enum ttm_global_types global_type;
48 size_t size;
49 void *object;
50 int (*init) (struct ttm_global_reference *);
51 void (*release) (struct ttm_global_reference *);
52};
53
54extern void ttm_global_init(void);
55extern void ttm_global_release(void);
56extern int ttm_global_item_ref(struct ttm_global_reference *ref);
57extern void ttm_global_item_unref(struct ttm_global_reference *ref);
58extern struct kobject *ttm_get_kobj(void); 38extern struct kobject *ttm_get_kobj(void);
59 39
60#endif /* _TTM_MODULE_H_ */ 40#endif /* _TTM_MODULE_H_ */