Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+114 -79
+1 -1
drivers/gpu/drm/Makefile
··· 12 12 drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \ 13 13 drm_crtc.o drm_modes.o drm_edid.o \ 14 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 17 17 drm-$(CONFIG_COMPAT) += drm_ioc32.o 18 18
+1
drivers/gpu/drm/drm_drv.c
··· 288 288 { 289 289 int ret = -ENOMEM; 290 290 291 + drm_global_init(); 291 292 idr_init(&drm_minors_idr); 292 293 293 294 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
+1 -1
drivers/gpu/drm/nouveau/nouveau_drv.h
··· 533 533 struct list_head vbl_waiting; 534 534 535 535 struct { 536 - struct ttm_global_reference mem_global_ref; 536 + struct drm_global_reference mem_global_ref; 537 537 struct ttm_bo_global_ref bo_global_ref; 538 538 struct ttm_bo_device bdev; 539 539 spinlock_t bo_list_lock;
+10 -10
drivers/gpu/drm/nouveau/nouveau_ttm.c
··· 42 42 } 43 43 44 44 static int 45 - nouveau_ttm_mem_global_init(struct ttm_global_reference *ref) 45 + nouveau_ttm_mem_global_init(struct drm_global_reference *ref) 46 46 { 47 47 return ttm_mem_global_init(ref->object); 48 48 } 49 49 50 50 static void 51 - nouveau_ttm_mem_global_release(struct ttm_global_reference *ref) 51 + nouveau_ttm_mem_global_release(struct drm_global_reference *ref) 52 52 { 53 53 ttm_mem_global_release(ref->object); 54 54 } ··· 56 56 int 57 57 nouveau_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 60 int ret; 61 61 62 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 64 global_ref->size = sizeof(struct ttm_mem_global); 65 65 global_ref->init = &nouveau_ttm_mem_global_init; 66 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 69 if (unlikely(ret != 0)) { 70 70 DRM_ERROR("Failed setting up TTM memory accounting\n"); 71 71 dev_priv->ttm.mem_global_ref.release = NULL; ··· 74 74 75 75 dev_priv->ttm.bo_global_ref.mem_glob = global_ref->object; 76 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 78 global_ref->size = sizeof(struct ttm_bo_global); 79 79 global_ref->init = &ttm_bo_global_init; 80 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 83 if (unlikely(ret != 0)) { 84 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 86 dev_priv->ttm.mem_global_ref.release = NULL; 87 87 return ret; 88 88 } ··· 96 96 if (dev_priv->ttm.mem_global_ref.release == NULL) 97 97 return; 98 98 99 - ttm_global_item_unref(&dev_priv->ttm.bo_global_ref.ref); 100 - ttm_global_item_unref(&dev_priv->ttm.mem_global_ref); 99 + drm_global_item_unref(&dev_priv->ttm.bo_global_ref.ref); 100 + drm_global_item_unref(&dev_priv->ttm.mem_global_ref); 101 101 dev_priv->ttm.mem_global_ref.release = NULL; 102 102 } 103 103
+1 -1
drivers/gpu/drm/radeon/radeon.h
··· 235 235 */ 236 236 struct radeon_mman { 237 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 239 struct ttm_bo_device bdev; 240 240 bool mem_global_referenced; 241 241 bool initialized;
+10 -10
drivers/gpu/drm/radeon/radeon_ttm.c
··· 59 59 /* 60 60 * Global memory. 61 61 */ 62 - static int radeon_ttm_mem_global_init(struct ttm_global_reference *ref) 62 + static int radeon_ttm_mem_global_init(struct drm_global_reference *ref) 63 63 { 64 64 return ttm_mem_global_init(ref->object); 65 65 } 66 66 67 - static void radeon_ttm_mem_global_release(struct ttm_global_reference *ref) 67 + static void radeon_ttm_mem_global_release(struct drm_global_reference *ref) 68 68 { 69 69 ttm_mem_global_release(ref->object); 70 70 } 71 71 72 72 static 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 75 int r; 76 76 77 77 rdev->mman.mem_global_referenced = false; 78 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 80 global_ref->size = sizeof(struct ttm_mem_global); 81 81 global_ref->init = &radeon_ttm_mem_global_init; 82 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 84 if (r != 0) { 85 85 DRM_ERROR("Failed setting up TTM memory accounting " 86 86 "subsystem.\n"); ··· 90 90 rdev->mman.bo_global_ref.mem_glob = 91 91 rdev->mman.mem_global_ref.object; 92 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 94 global_ref->size = sizeof(struct ttm_bo_global); 95 95 global_ref->init = &ttm_bo_global_init; 96 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 98 if (r != 0) { 99 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 101 return r; 102 102 } 103 103 ··· 108 108 static void radeon_ttm_global_fini(struct radeon_device *rdev) 109 109 { 110 110 if (rdev->mman.mem_global_referenced) { 111 - ttm_global_item_unref(&rdev->mman.bo_global_ref.ref); 112 - ttm_global_item_unref(&rdev->mman.mem_global_ref); 111 + drm_global_item_unref(&rdev->mman.bo_global_ref.ref); 112 + drm_global_item_unref(&rdev->mman.mem_global_ref); 113 113 rdev->mman.mem_global_referenced = false; 114 114 } 115 115 }
+1 -1
drivers/gpu/drm/ttm/Makefile
··· 3 3 4 4 ccflags-y := -Iinclude/drm 5 5 ttm-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 7 ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o 8 8 9 9 obj-$(CONFIG_DRM_TTM) += ttm.o
+2 -2
drivers/gpu/drm/ttm/ttm_bo.c
··· 1395 1395 kfree(glob); 1396 1396 } 1397 1397 1398 - void ttm_bo_global_release(struct ttm_global_reference *ref) 1398 + void ttm_bo_global_release(struct drm_global_reference *ref) 1399 1399 { 1400 1400 struct ttm_bo_global *glob = ref->object; 1401 1401 ··· 1404 1404 } 1405 1405 EXPORT_SYMBOL(ttm_bo_global_release); 1406 1406 1407 - int ttm_bo_global_init(struct ttm_global_reference *ref) 1407 + int ttm_bo_global_init(struct drm_global_reference *ref) 1408 1408 { 1409 1409 struct ttm_bo_global_ref *bo_ref = 1410 1410 container_of(ref, struct ttm_bo_global_ref, ref);
+15 -15
drivers/gpu/drm/ttm/ttm_global.c drivers/gpu/drm/drm_global.c
··· 28 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 29 29 */ 30 30 31 - #include "ttm/ttm_module.h" 32 31 #include <linux/mutex.h> 33 32 #include <linux/slab.h> 34 33 #include <linux/module.h> 34 + #include "drm_global.h" 35 35 36 - struct ttm_global_item { 36 + struct drm_global_item { 37 37 struct mutex mutex; 38 38 void *object; 39 39 int refcount; 40 40 }; 41 41 42 - static struct ttm_global_item glob[TTM_GLOBAL_NUM]; 42 + static struct drm_global_item glob[DRM_GLOBAL_NUM]; 43 43 44 - void ttm_global_init(void) 44 + void drm_global_init(void) 45 45 { 46 46 int i; 47 47 48 - for (i = 0; i < TTM_GLOBAL_NUM; ++i) { 49 - struct ttm_global_item *item = &glob[i]; 48 + for (i = 0; i < DRM_GLOBAL_NUM; ++i) { 49 + struct drm_global_item *item = &glob[i]; 50 50 mutex_init(&item->mutex); 51 51 item->object = NULL; 52 52 item->refcount = 0; 53 53 } 54 54 } 55 55 56 - void ttm_global_release(void) 56 + void drm_global_release(void) 57 57 { 58 58 int i; 59 - for (i = 0; i < TTM_GLOBAL_NUM; ++i) { 60 - struct ttm_global_item *item = &glob[i]; 59 + for (i = 0; i < DRM_GLOBAL_NUM; ++i) { 60 + struct drm_global_item *item = &glob[i]; 61 61 BUG_ON(item->object != NULL); 62 62 BUG_ON(item->refcount != 0); 63 63 } 64 64 } 65 65 66 - int ttm_global_item_ref(struct ttm_global_reference *ref) 66 + int drm_global_item_ref(struct drm_global_reference *ref) 67 67 { 68 68 int ret; 69 - struct ttm_global_item *item = &glob[ref->global_type]; 69 + struct drm_global_item *item = &glob[ref->global_type]; 70 70 void *object; 71 71 72 72 mutex_lock(&item->mutex); ··· 93 93 item->object = NULL; 94 94 return ret; 95 95 } 96 - EXPORT_SYMBOL(ttm_global_item_ref); 96 + EXPORT_SYMBOL(drm_global_item_ref); 97 97 98 - void ttm_global_item_unref(struct ttm_global_reference *ref) 98 + void 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 102 mutex_lock(&item->mutex); 103 103 BUG_ON(item->refcount == 0); ··· 108 108 } 109 109 mutex_unlock(&item->mutex); 110 110 } 111 - EXPORT_SYMBOL(ttm_global_item_unref); 111 + EXPORT_SYMBOL(drm_global_item_unref); 112 112
-4
drivers/gpu/drm/ttm/ttm_module.c
··· 70 70 if (unlikely(ret != 0)) 71 71 return ret; 72 72 73 - ttm_global_init(); 74 - 75 73 atomic_set(&device_released, 0); 76 74 ret = drm_class_device_register(&ttm_drm_class_device); 77 75 if (unlikely(ret != 0)) ··· 79 81 out_no_dev_reg: 80 82 atomic_set(&device_released, 1); 81 83 wake_up_all(&exit_q); 82 - ttm_global_release(); 83 84 return ret; 84 85 } 85 86 ··· 92 95 */ 93 96 94 97 wait_event(exit_q, atomic_read(&device_released) == 1); 95 - ttm_global_release(); 96 98 } 97 99 98 100 module_init(ttm_init);
+1 -1
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
··· 164 164 struct vmw_private { 165 165 struct ttm_bo_device bdev; 166 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 169 struct vmw_fifo_state fifo; 170 170
+10 -10
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
··· 44 44 return ttm_bo_mmap(filp, vma, &dev_priv->bdev); 45 45 } 46 46 47 - static int vmw_ttm_mem_global_init(struct ttm_global_reference *ref) 47 + static int vmw_ttm_mem_global_init(struct drm_global_reference *ref) 48 48 { 49 49 DRM_INFO("global init.\n"); 50 50 return ttm_mem_global_init(ref->object); 51 51 } 52 52 53 - static void vmw_ttm_mem_global_release(struct ttm_global_reference *ref) 53 + static void vmw_ttm_mem_global_release(struct drm_global_reference *ref) 54 54 { 55 55 ttm_mem_global_release(ref->object); 56 56 } 57 57 58 58 int 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 61 int ret; 62 62 63 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 65 global_ref->size = sizeof(struct ttm_mem_global); 66 66 global_ref->init = &vmw_ttm_mem_global_init; 67 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 70 if (unlikely(ret != 0)) { 71 71 DRM_ERROR("Failed setting up TTM memory accounting.\n"); 72 72 return ret; ··· 75 75 dev_priv->bo_global_ref.mem_glob = 76 76 dev_priv->mem_global_ref.object; 77 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 79 global_ref->size = sizeof(struct ttm_bo_global); 80 80 global_ref->init = &ttm_bo_global_init; 81 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 84 if (unlikely(ret != 0)) { 85 85 DRM_ERROR("Failed setting up TTM buffer objects.\n"); ··· 88 88 89 89 return 0; 90 90 out_no_bo: 91 - ttm_global_item_unref(&dev_priv->mem_global_ref); 91 + drm_global_item_unref(&dev_priv->mem_global_ref); 92 92 return ret; 93 93 } 94 94 95 95 void vmw_ttm_global_release(struct vmw_private *dev_priv) 96 96 { 97 - ttm_global_item_unref(&dev_priv->bo_global_ref.ref); 98 - ttm_global_item_unref(&dev_priv->mem_global_ref); 97 + drm_global_item_unref(&dev_priv->bo_global_ref.ref); 98 + drm_global_item_unref(&dev_priv->mem_global_ref); 99 99 }
+2
include/drm/drm.h
··· 663 663 #define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock) 664 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 668 #define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30) 667 669 #define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31) 668 670 #define DRM_IOCTL_AGP_ENABLE DRM_IOW( 0x32, struct drm_agp_mode)
+2
include/drm/drmP.h
··· 1453 1453 void drm_gem_vm_close(struct vm_area_struct *vma); 1454 1454 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); 1455 1455 1456 + #include "drm_global.h" 1457 + 1456 1458 static inline void 1457 1459 drm_gem_object_reference(struct drm_gem_object *obj) 1458 1460 {
+53
include/drm/drm_global.h
··· 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_ 33 + enum 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 + 40 + struct 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 + 48 + extern void drm_global_init(void); 49 + extern void drm_global_release(void); 50 + extern int drm_global_item_ref(struct drm_global_reference *ref); 51 + extern void drm_global_item_unref(struct drm_global_reference *ref); 52 + 53 + #endif
+4 -3
include/drm/ttm/ttm_bo_driver.h
··· 34 34 #include "ttm/ttm_memory.h" 35 35 #include "ttm/ttm_module.h" 36 36 #include "drm_mm.h" 37 + #include "drm_global.h" 37 38 #include "linux/workqueue.h" 38 39 #include "linux/fs.h" 39 40 #include "linux/spinlock.h" ··· 363 362 */ 364 363 365 364 struct ttm_bo_global_ref { 366 - struct ttm_global_reference ref; 365 + struct drm_global_reference ref; 367 366 struct ttm_mem_global *mem_glob; 368 367 }; 369 368 ··· 688 687 extern void ttm_mem_io_free(struct ttm_bo_device *bdev, 689 688 struct ttm_mem_reg *mem); 690 689 691 - extern void ttm_bo_global_release(struct ttm_global_reference *ref); 692 - extern int ttm_bo_global_init(struct ttm_global_reference *ref); 690 + extern void ttm_bo_global_release(struct drm_global_reference *ref); 691 + extern int ttm_bo_global_init(struct drm_global_reference *ref); 693 692 694 693 extern int ttm_bo_device_release(struct ttm_bo_device *bdev); 695 694
-20
include/drm/ttm/ttm_module.h
··· 35 35 struct kobject; 36 36 37 37 #define TTM_PFX "[TTM] " 38 - 39 - enum 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 - 46 - struct 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 - 54 - extern void ttm_global_init(void); 55 - extern void ttm_global_release(void); 56 - extern int ttm_global_item_ref(struct ttm_global_reference *ref); 57 - extern void ttm_global_item_unref(struct ttm_global_reference *ref); 58 38 extern struct kobject *ttm_get_kobj(void); 59 39 60 40 #endif /* _TTM_MODULE_H_ */