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

drm/ttm: use a static ttm_mem_global instance

As the name says we only need one global instance of ttm_mem_global.

Drop all the driver initialization and just use a single exported
instance which is initialized during BO global initialization.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Christian König and committed by
Alex Deucher
27eb1fa9 7e07834c

+32 -380
-44
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 66 66 */ 67 67 68 68 /** 69 - * amdgpu_ttm_mem_global_init - Initialize and acquire reference to 70 - * memory object 71 - * 72 - * @ref: Object for initialization. 73 - * 74 - * This is called by drm_global_item_ref() when an object is being 75 - * initialized. 76 - */ 77 - static int amdgpu_ttm_mem_global_init(struct drm_global_reference *ref) 78 - { 79 - return ttm_mem_global_init(ref->object); 80 - } 81 - 82 - /** 83 - * amdgpu_ttm_mem_global_release - Drop reference to a memory object 84 - * 85 - * @ref: Object being removed 86 - * 87 - * This is called by drm_global_item_unref() when an object is being 88 - * released. 89 - */ 90 - static void amdgpu_ttm_mem_global_release(struct drm_global_reference *ref) 91 - { 92 - ttm_mem_global_release(ref->object); 93 - } 94 - 95 - /** 96 69 * amdgpu_ttm_global_init - Initialize global TTM memory reference structures. 97 70 * 98 71 * @adev: AMDGPU device for which the global structures need to be registered. ··· 81 108 /* ensure reference is false in case init fails */ 82 109 adev->mman.mem_global_referenced = false; 83 110 84 - global_ref = &adev->mman.mem_global_ref; 85 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 86 - global_ref->size = sizeof(struct ttm_mem_global); 87 - global_ref->init = &amdgpu_ttm_mem_global_init; 88 - global_ref->release = &amdgpu_ttm_mem_global_release; 89 - r = drm_global_item_ref(global_ref); 90 - if (r) { 91 - DRM_ERROR("Failed setting up TTM memory accounting " 92 - "subsystem.\n"); 93 - goto error_mem; 94 - } 95 - 96 - adev->mman.bo_global_ref.mem_glob = 97 - adev->mman.mem_global_ref.object; 98 111 global_ref = &adev->mman.bo_global_ref.ref; 99 112 global_ref->global_type = DRM_GLOBAL_TTM_BO; 100 113 global_ref->size = sizeof(struct ttm_bo_global); ··· 99 140 return 0; 100 141 101 142 error_bo: 102 - drm_global_item_unref(&adev->mman.mem_global_ref); 103 - error_mem: 104 143 return r; 105 144 } 106 145 ··· 107 150 if (adev->mman.mem_global_referenced) { 108 151 mutex_destroy(&adev->mman.gtt_window_lock); 109 152 drm_global_item_unref(&adev->mman.bo_global_ref.ref); 110 - drm_global_item_unref(&adev->mman.mem_global_ref); 111 153 adev->mman.mem_global_referenced = false; 112 154 } 113 155 }
-1
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
··· 40 40 41 41 struct amdgpu_mman { 42 42 struct ttm_bo_global_ref bo_global_ref; 43 - struct drm_global_reference mem_global_ref; 44 43 struct ttm_bo_device bdev; 45 44 bool mem_global_referenced; 46 45 bool initialized;
-1
drivers/gpu/drm/ast/ast_drv.h
··· 104 104 int fb_mtrr; 105 105 106 106 struct { 107 - struct drm_global_reference mem_global_ref; 108 107 struct ttm_bo_global_ref bo_global_ref; 109 108 struct ttm_bo_device bdev; 110 109 } ttm;
+2 -30
drivers/gpu/drm/ast/ast_ttm.c
··· 36 36 return container_of(bd, struct ast_private, ttm.bdev); 37 37 } 38 38 39 - static int 40 - ast_ttm_mem_global_init(struct drm_global_reference *ref) 41 - { 42 - return ttm_mem_global_init(ref->object); 43 - } 44 - 45 - static void 46 - ast_ttm_mem_global_release(struct drm_global_reference *ref) 47 - { 48 - ttm_mem_global_release(ref->object); 49 - } 50 - 51 39 static int ast_ttm_global_init(struct ast_private *ast) 52 40 { 53 41 struct drm_global_reference *global_ref; 54 42 int r; 55 43 56 - global_ref = &ast->ttm.mem_global_ref; 57 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 58 - global_ref->size = sizeof(struct ttm_mem_global); 59 - global_ref->init = &ast_ttm_mem_global_init; 60 - global_ref->release = &ast_ttm_mem_global_release; 61 - r = drm_global_item_ref(global_ref); 62 - if (r != 0) { 63 - DRM_ERROR("Failed setting up TTM memory accounting " 64 - "subsystem.\n"); 65 - return r; 66 - } 67 - 68 - ast->ttm.bo_global_ref.mem_glob = 69 - ast->ttm.mem_global_ref.object; 70 44 global_ref = &ast->ttm.bo_global_ref.ref; 71 45 global_ref->global_type = DRM_GLOBAL_TTM_BO; 72 46 global_ref->size = sizeof(struct ttm_bo_global); ··· 49 75 r = drm_global_item_ref(global_ref); 50 76 if (r != 0) { 51 77 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 52 - drm_global_item_unref(&ast->ttm.mem_global_ref); 53 78 return r; 54 79 } 55 80 return 0; ··· 57 84 static void 58 85 ast_ttm_global_release(struct ast_private *ast) 59 86 { 60 - if (ast->ttm.mem_global_ref.release == NULL) 87 + if (ast->ttm.bo_global_ref.ref.release == NULL) 61 88 return; 62 89 63 90 drm_global_item_unref(&ast->ttm.bo_global_ref.ref); 64 - drm_global_item_unref(&ast->ttm.mem_global_ref); 65 - ast->ttm.mem_global_ref.release = NULL; 91 + ast->ttm.bo_global_ref.ref.release = NULL; 66 92 } 67 93 68 94
-1
drivers/gpu/drm/bochs/bochs.h
··· 76 76 77 77 /* ttm */ 78 78 struct { 79 - struct drm_global_reference mem_global_ref; 80 79 struct ttm_bo_global_ref bo_global_ref; 81 80 struct ttm_bo_device bdev; 82 81 bool initialized;
+2 -28
drivers/gpu/drm/bochs/bochs_mm.c
··· 16 16 return container_of(bd, struct bochs_device, ttm.bdev); 17 17 } 18 18 19 - static int bochs_ttm_mem_global_init(struct drm_global_reference *ref) 20 - { 21 - return ttm_mem_global_init(ref->object); 22 - } 23 - 24 - static void bochs_ttm_mem_global_release(struct drm_global_reference *ref) 25 - { 26 - ttm_mem_global_release(ref->object); 27 - } 28 - 29 19 static int bochs_ttm_global_init(struct bochs_device *bochs) 30 20 { 31 21 struct drm_global_reference *global_ref; 32 22 int r; 33 23 34 - global_ref = &bochs->ttm.mem_global_ref; 35 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 36 - global_ref->size = sizeof(struct ttm_mem_global); 37 - global_ref->init = &bochs_ttm_mem_global_init; 38 - global_ref->release = &bochs_ttm_mem_global_release; 39 - r = drm_global_item_ref(global_ref); 40 - if (r != 0) { 41 - DRM_ERROR("Failed setting up TTM memory accounting " 42 - "subsystem.\n"); 43 - return r; 44 - } 45 - 46 - bochs->ttm.bo_global_ref.mem_glob = 47 - bochs->ttm.mem_global_ref.object; 48 24 global_ref = &bochs->ttm.bo_global_ref.ref; 49 25 global_ref->global_type = DRM_GLOBAL_TTM_BO; 50 26 global_ref->size = sizeof(struct ttm_bo_global); ··· 29 53 r = drm_global_item_ref(global_ref); 30 54 if (r != 0) { 31 55 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 32 - drm_global_item_unref(&bochs->ttm.mem_global_ref); 33 56 return r; 34 57 } 35 58 ··· 37 62 38 63 static void bochs_ttm_global_release(struct bochs_device *bochs) 39 64 { 40 - if (bochs->ttm.mem_global_ref.release == NULL) 65 + if (bochs->ttm.bo_global_ref.ref.release == NULL) 41 66 return; 42 67 43 68 drm_global_item_unref(&bochs->ttm.bo_global_ref.ref); 44 - drm_global_item_unref(&bochs->ttm.mem_global_ref); 45 - bochs->ttm.mem_global_ref.release = NULL; 69 + bochs->ttm.bo_global_ref.ref.release = NULL; 46 70 } 47 71 48 72
-1
drivers/gpu/drm/cirrus/cirrus_drv.h
··· 136 136 int fb_mtrr; 137 137 138 138 struct { 139 - struct drm_global_reference mem_global_ref; 140 139 struct ttm_bo_global_ref bo_global_ref; 141 140 struct ttm_bo_device bdev; 142 141 } ttm;
+2 -30
drivers/gpu/drm/cirrus/cirrus_ttm.c
··· 36 36 return container_of(bd, struct cirrus_device, ttm.bdev); 37 37 } 38 38 39 - static int 40 - cirrus_ttm_mem_global_init(struct drm_global_reference *ref) 41 - { 42 - return ttm_mem_global_init(ref->object); 43 - } 44 - 45 - static void 46 - cirrus_ttm_mem_global_release(struct drm_global_reference *ref) 47 - { 48 - ttm_mem_global_release(ref->object); 49 - } 50 - 51 39 static int cirrus_ttm_global_init(struct cirrus_device *cirrus) 52 40 { 53 41 struct drm_global_reference *global_ref; 54 42 int r; 55 43 56 - global_ref = &cirrus->ttm.mem_global_ref; 57 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 58 - global_ref->size = sizeof(struct ttm_mem_global); 59 - global_ref->init = &cirrus_ttm_mem_global_init; 60 - global_ref->release = &cirrus_ttm_mem_global_release; 61 - r = drm_global_item_ref(global_ref); 62 - if (r != 0) { 63 - DRM_ERROR("Failed setting up TTM memory accounting " 64 - "subsystem.\n"); 65 - return r; 66 - } 67 - 68 - cirrus->ttm.bo_global_ref.mem_glob = 69 - cirrus->ttm.mem_global_ref.object; 70 44 global_ref = &cirrus->ttm.bo_global_ref.ref; 71 45 global_ref->global_type = DRM_GLOBAL_TTM_BO; 72 46 global_ref->size = sizeof(struct ttm_bo_global); ··· 49 75 r = drm_global_item_ref(global_ref); 50 76 if (r != 0) { 51 77 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 52 - drm_global_item_unref(&cirrus->ttm.mem_global_ref); 53 78 return r; 54 79 } 55 80 return 0; ··· 57 84 static void 58 85 cirrus_ttm_global_release(struct cirrus_device *cirrus) 59 86 { 60 - if (cirrus->ttm.mem_global_ref.release == NULL) 87 + if (cirrus->ttm.bo_global_ref.ref.release == NULL) 61 88 return; 62 89 63 90 drm_global_item_unref(&cirrus->ttm.bo_global_ref.ref); 64 - drm_global_item_unref(&cirrus->ttm.mem_global_ref); 65 - cirrus->ttm.mem_global_ref.release = NULL; 91 + cirrus->ttm.bo_global_ref.ref.release = NULL; 66 92 } 67 93 68 94
-1
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
··· 49 49 bool mode_config_initialized; 50 50 51 51 /* ttm */ 52 - struct drm_global_reference mem_global_ref; 53 52 struct ttm_bo_global_ref bo_global_ref; 54 53 struct ttm_bo_device bdev; 55 54 bool initialized;
+4 -27
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
··· 29 29 return container_of(bd, struct hibmc_drm_private, bdev); 30 30 } 31 31 32 - static int 33 - hibmc_ttm_mem_global_init(struct drm_global_reference *ref) 34 - { 35 - return ttm_mem_global_init(ref->object); 36 - } 37 - 38 - static void 39 - hibmc_ttm_mem_global_release(struct drm_global_reference *ref) 40 - { 41 - ttm_mem_global_release(ref->object); 42 - } 43 - 44 32 static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc) 45 33 { 46 34 int ret; 47 35 48 - hibmc->mem_global_ref.global_type = DRM_GLOBAL_TTM_MEM; 49 - hibmc->mem_global_ref.size = sizeof(struct ttm_mem_global); 50 - hibmc->mem_global_ref.init = &hibmc_ttm_mem_global_init; 51 - hibmc->mem_global_ref.release = &hibmc_ttm_mem_global_release; 52 - ret = drm_global_item_ref(&hibmc->mem_global_ref); 53 - if (ret) { 54 - DRM_ERROR("could not get ref on ttm global: %d\n", ret); 55 - return ret; 56 - } 57 - 58 - hibmc->bo_global_ref.mem_glob = 59 - hibmc->mem_global_ref.object; 60 36 hibmc->bo_global_ref.ref.global_type = DRM_GLOBAL_TTM_BO; 61 37 hibmc->bo_global_ref.ref.size = sizeof(struct ttm_bo_global); 62 38 hibmc->bo_global_ref.ref.init = &ttm_bo_global_ref_init; ··· 40 64 ret = drm_global_item_ref(&hibmc->bo_global_ref.ref); 41 65 if (ret) { 42 66 DRM_ERROR("failed setting up TTM BO subsystem: %d\n", ret); 43 - drm_global_item_unref(&hibmc->mem_global_ref); 44 67 return ret; 45 68 } 46 69 return 0; ··· 48 73 static void 49 74 hibmc_ttm_global_release(struct hibmc_drm_private *hibmc) 50 75 { 76 + if (hibmc->bo_global_ref.ref.release == NULL) 77 + return; 78 + 51 79 drm_global_item_unref(&hibmc->bo_global_ref.ref); 52 - drm_global_item_unref(&hibmc->mem_global_ref); 53 - hibmc->mem_global_ref.release = NULL; 80 + hibmc->bo_global_ref.ref.release = NULL; 54 81 } 55 82 56 83 static void hibmc_bo_ttm_destroy(struct ttm_buffer_object *tbo)
-1
drivers/gpu/drm/mgag200/mgag200_drv.h
··· 212 212 int fb_mtrr; 213 213 214 214 struct { 215 - struct drm_global_reference mem_global_ref; 216 215 struct ttm_bo_global_ref bo_global_ref; 217 216 struct ttm_bo_device bdev; 218 217 } ttm;
+2 -30
drivers/gpu/drm/mgag200/mgag200_ttm.c
··· 36 36 return container_of(bd, struct mga_device, ttm.bdev); 37 37 } 38 38 39 - static int 40 - mgag200_ttm_mem_global_init(struct drm_global_reference *ref) 41 - { 42 - return ttm_mem_global_init(ref->object); 43 - } 44 - 45 - static void 46 - mgag200_ttm_mem_global_release(struct drm_global_reference *ref) 47 - { 48 - ttm_mem_global_release(ref->object); 49 - } 50 - 51 39 static int mgag200_ttm_global_init(struct mga_device *ast) 52 40 { 53 41 struct drm_global_reference *global_ref; 54 42 int r; 55 43 56 - global_ref = &ast->ttm.mem_global_ref; 57 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 58 - global_ref->size = sizeof(struct ttm_mem_global); 59 - global_ref->init = &mgag200_ttm_mem_global_init; 60 - global_ref->release = &mgag200_ttm_mem_global_release; 61 - r = drm_global_item_ref(global_ref); 62 - if (r != 0) { 63 - DRM_ERROR("Failed setting up TTM memory accounting " 64 - "subsystem.\n"); 65 - return r; 66 - } 67 - 68 - ast->ttm.bo_global_ref.mem_glob = 69 - ast->ttm.mem_global_ref.object; 70 44 global_ref = &ast->ttm.bo_global_ref.ref; 71 45 global_ref->global_type = DRM_GLOBAL_TTM_BO; 72 46 global_ref->size = sizeof(struct ttm_bo_global); ··· 49 75 r = drm_global_item_ref(global_ref); 50 76 if (r != 0) { 51 77 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 52 - drm_global_item_unref(&ast->ttm.mem_global_ref); 53 78 return r; 54 79 } 55 80 return 0; ··· 57 84 static void 58 85 mgag200_ttm_global_release(struct mga_device *ast) 59 86 { 60 - if (ast->ttm.mem_global_ref.release == NULL) 87 + if (ast->ttm.bo_global_ref.ref.release == NULL) 61 88 return; 62 89 63 90 drm_global_item_unref(&ast->ttm.bo_global_ref.ref); 64 - drm_global_item_unref(&ast->ttm.mem_global_ref); 65 - ast->ttm.mem_global_ref.release = NULL; 91 + ast->ttm.bo_global_ref.ref.release = NULL; 66 92 } 67 93 68 94
-1
drivers/gpu/drm/nouveau/nouveau_drv.h
··· 146 146 147 147 /* TTM interface support */ 148 148 struct { 149 - struct drm_global_reference mem_global_ref; 150 149 struct ttm_bo_global_ref bo_global_ref; 151 150 struct ttm_bo_device bdev; 152 151 atomic_t validate_sequence;
+3 -31
drivers/gpu/drm/nouveau/nouveau_ttm.c
··· 174 174 return ttm_bo_mmap(filp, vma, &drm->ttm.bdev); 175 175 } 176 176 177 - static int 178 - nouveau_ttm_mem_global_init(struct drm_global_reference *ref) 179 - { 180 - return ttm_mem_global_init(ref->object); 181 - } 182 - 183 - static void 184 - nouveau_ttm_mem_global_release(struct drm_global_reference *ref) 185 - { 186 - ttm_mem_global_release(ref->object); 187 - } 188 - 189 177 int 190 178 nouveau_ttm_global_init(struct nouveau_drm *drm) 191 179 { 192 180 struct drm_global_reference *global_ref; 193 181 int ret; 194 182 195 - global_ref = &drm->ttm.mem_global_ref; 196 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 197 - global_ref->size = sizeof(struct ttm_mem_global); 198 - global_ref->init = &nouveau_ttm_mem_global_init; 199 - global_ref->release = &nouveau_ttm_mem_global_release; 200 - 201 - ret = drm_global_item_ref(global_ref); 202 - if (unlikely(ret != 0)) { 203 - DRM_ERROR("Failed setting up TTM memory accounting\n"); 204 - drm->ttm.mem_global_ref.release = NULL; 205 - return ret; 206 - } 207 - 208 - drm->ttm.bo_global_ref.mem_glob = global_ref->object; 209 183 global_ref = &drm->ttm.bo_global_ref.ref; 210 184 global_ref->global_type = DRM_GLOBAL_TTM_BO; 211 185 global_ref->size = sizeof(struct ttm_bo_global); ··· 189 215 ret = drm_global_item_ref(global_ref); 190 216 if (unlikely(ret != 0)) { 191 217 DRM_ERROR("Failed setting up TTM BO subsystem\n"); 192 - drm_global_item_unref(&drm->ttm.mem_global_ref); 193 - drm->ttm.mem_global_ref.release = NULL; 218 + drm->ttm.bo_global_ref.ref.release = NULL; 194 219 return ret; 195 220 } 196 221 ··· 199 226 void 200 227 nouveau_ttm_global_release(struct nouveau_drm *drm) 201 228 { 202 - if (drm->ttm.mem_global_ref.release == NULL) 229 + if (drm->ttm.bo_global_ref.ref.release == NULL) 203 230 return; 204 231 205 232 drm_global_item_unref(&drm->ttm.bo_global_ref.ref); 206 - drm_global_item_unref(&drm->ttm.mem_global_ref); 207 - drm->ttm.mem_global_ref.release = NULL; 233 + drm->ttm.bo_global_ref.ref.release = NULL; 208 234 } 209 235 210 236 static int
-1
drivers/gpu/drm/qxl/qxl_drv.h
··· 128 128 129 129 struct qxl_mman { 130 130 struct ttm_bo_global_ref bo_global_ref; 131 - struct drm_global_reference mem_global_ref; 132 131 bool mem_global_referenced; 133 132 struct ttm_bo_device bdev; 134 133 };
-28
drivers/gpu/drm/qxl/qxl_ttm.c
··· 46 46 return qdev; 47 47 } 48 48 49 - static int qxl_ttm_mem_global_init(struct drm_global_reference *ref) 50 - { 51 - return ttm_mem_global_init(ref->object); 52 - } 53 - 54 - static void qxl_ttm_mem_global_release(struct drm_global_reference *ref) 55 - { 56 - ttm_mem_global_release(ref->object); 57 - } 58 - 59 49 static int qxl_ttm_global_init(struct qxl_device *qdev) 60 50 { 61 51 struct drm_global_reference *global_ref; 62 52 int r; 63 53 64 - qdev->mman.mem_global_referenced = false; 65 - global_ref = &qdev->mman.mem_global_ref; 66 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 67 - global_ref->size = sizeof(struct ttm_mem_global); 68 - global_ref->init = &qxl_ttm_mem_global_init; 69 - global_ref->release = &qxl_ttm_mem_global_release; 70 - 71 - r = drm_global_item_ref(global_ref); 72 - if (r != 0) { 73 - DRM_ERROR("Failed setting up TTM memory accounting " 74 - "subsystem.\n"); 75 - return r; 76 - } 77 - 78 - qdev->mman.bo_global_ref.mem_glob = 79 - qdev->mman.mem_global_ref.object; 80 54 global_ref = &qdev->mman.bo_global_ref.ref; 81 55 global_ref->global_type = DRM_GLOBAL_TTM_BO; 82 56 global_ref->size = sizeof(struct ttm_bo_global); ··· 59 85 r = drm_global_item_ref(global_ref); 60 86 if (r != 0) { 61 87 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 62 - drm_global_item_unref(&qdev->mman.mem_global_ref); 63 88 return r; 64 89 } 65 90 ··· 70 97 { 71 98 if (qdev->mman.mem_global_referenced) { 72 99 drm_global_item_unref(&qdev->mman.bo_global_ref.ref); 73 - drm_global_item_unref(&qdev->mman.mem_global_ref); 74 100 qdev->mman.mem_global_referenced = false; 75 101 } 76 102 }
-1
drivers/gpu/drm/radeon/radeon.h
··· 449 449 */ 450 450 struct radeon_mman { 451 451 struct ttm_bo_global_ref bo_global_ref; 452 - struct drm_global_reference mem_global_ref; 453 452 struct ttm_bo_device bdev; 454 453 bool mem_global_referenced; 455 454 bool initialized;
-26
drivers/gpu/drm/radeon/radeon_ttm.c
··· 64 64 /* 65 65 * Global memory. 66 66 */ 67 - static int radeon_ttm_mem_global_init(struct drm_global_reference *ref) 68 - { 69 - return ttm_mem_global_init(ref->object); 70 - } 71 - 72 - static void radeon_ttm_mem_global_release(struct drm_global_reference *ref) 73 - { 74 - ttm_mem_global_release(ref->object); 75 - } 76 - 77 67 static int radeon_ttm_global_init(struct radeon_device *rdev) 78 68 { 79 69 struct drm_global_reference *global_ref; 80 70 int r; 81 71 82 72 rdev->mman.mem_global_referenced = false; 83 - global_ref = &rdev->mman.mem_global_ref; 84 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 85 - global_ref->size = sizeof(struct ttm_mem_global); 86 - global_ref->init = &radeon_ttm_mem_global_init; 87 - global_ref->release = &radeon_ttm_mem_global_release; 88 - r = drm_global_item_ref(global_ref); 89 - if (r != 0) { 90 - DRM_ERROR("Failed setting up TTM memory accounting " 91 - "subsystem.\n"); 92 - return r; 93 - } 94 - 95 - rdev->mman.bo_global_ref.mem_glob = 96 - rdev->mman.mem_global_ref.object; 97 73 global_ref = &rdev->mman.bo_global_ref.ref; 98 74 global_ref->global_type = DRM_GLOBAL_TTM_BO; 99 75 global_ref->size = sizeof(struct ttm_bo_global); ··· 78 102 r = drm_global_item_ref(global_ref); 79 103 if (r != 0) { 80 104 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 81 - drm_global_item_unref(&rdev->mman.mem_global_ref); 82 105 return r; 83 106 } 84 107 ··· 89 114 { 90 115 if (rdev->mman.mem_global_referenced) { 91 116 drm_global_item_unref(&rdev->mman.bo_global_ref.ref); 92 - drm_global_item_unref(&rdev->mman.mem_global_ref); 93 117 rdev->mman.mem_global_referenced = false; 94 118 } 95 119 }
+7 -3
drivers/gpu/drm/ttm/ttm_bo.c
··· 1526 1526 { 1527 1527 kobject_del(&glob->kobj); 1528 1528 kobject_put(&glob->kobj); 1529 + ttm_mem_global_release(&ttm_mem_glob); 1529 1530 } 1530 1531 EXPORT_SYMBOL(ttm_bo_global_release); 1531 1532 1532 - int ttm_bo_global_init(struct ttm_bo_global *glob, 1533 - struct ttm_mem_global *mem_glob) 1533 + int ttm_bo_global_init(struct ttm_bo_global *glob) 1534 1534 { 1535 1535 int ret; 1536 1536 unsigned i; 1537 1537 1538 + ret = ttm_mem_global_init(&ttm_mem_glob); 1539 + if (ret) 1540 + return ret; 1541 + 1538 1542 mutex_init(&glob->device_list_mutex); 1539 1543 spin_lock_init(&glob->lru_lock); 1540 - glob->mem_glob = mem_glob; 1544 + glob->mem_glob = &ttm_mem_glob; 1541 1545 glob->mem_glob->bo_glob = glob; 1542 1546 glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32); 1543 1547
+3 -2
drivers/gpu/drm/ttm/ttm_memory.c
··· 41 41 42 42 #define TTM_MEMORY_ALLOC_RETRIES 4 43 43 44 + struct ttm_mem_global ttm_mem_glob; 45 + EXPORT_SYMBOL(ttm_mem_glob); 46 + 44 47 struct ttm_mem_zone { 45 48 struct kobject kobj; 46 49 struct ttm_mem_global *glob; ··· 467 464 ttm_mem_global_release(glob); 468 465 return ret; 469 466 } 470 - EXPORT_SYMBOL(ttm_mem_global_init); 471 467 472 468 void ttm_mem_global_release(struct ttm_mem_global *glob) 473 469 { ··· 488 486 kobject_del(&glob->kobj); 489 487 kobject_put(&glob->kobj); 490 488 } 491 - EXPORT_SYMBOL(ttm_mem_global_release); 492 489 493 490 static void ttm_check_swapping(struct ttm_mem_global *glob) 494 491 {
-1
drivers/gpu/drm/virtio/virtgpu_drv.h
··· 143 143 144 144 struct virtio_gpu_mman { 145 145 struct ttm_bo_global_ref bo_global_ref; 146 - struct drm_global_reference mem_global_ref; 147 146 bool mem_global_referenced; 148 147 struct ttm_bo_device bdev; 149 148 };
-27
drivers/gpu/drm/virtio/virtgpu_ttm.c
··· 50 50 return vgdev; 51 51 } 52 52 53 - static int virtio_gpu_ttm_mem_global_init(struct drm_global_reference *ref) 54 - { 55 - return ttm_mem_global_init(ref->object); 56 - } 57 - 58 - static void virtio_gpu_ttm_mem_global_release(struct drm_global_reference *ref) 59 - { 60 - ttm_mem_global_release(ref->object); 61 - } 62 - 63 53 static int virtio_gpu_ttm_global_init(struct virtio_gpu_device *vgdev) 64 54 { 65 55 struct drm_global_reference *global_ref; 66 56 int r; 67 57 68 58 vgdev->mman.mem_global_referenced = false; 69 - global_ref = &vgdev->mman.mem_global_ref; 70 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 71 - global_ref->size = sizeof(struct ttm_mem_global); 72 - global_ref->init = &virtio_gpu_ttm_mem_global_init; 73 - global_ref->release = &virtio_gpu_ttm_mem_global_release; 74 - 75 - r = drm_global_item_ref(global_ref); 76 - if (r != 0) { 77 - DRM_ERROR("Failed setting up TTM memory accounting " 78 - "subsystem.\n"); 79 - return r; 80 - } 81 - 82 - vgdev->mman.bo_global_ref.mem_glob = 83 - vgdev->mman.mem_global_ref.object; 84 59 global_ref = &vgdev->mman.bo_global_ref.ref; 85 60 global_ref->global_type = DRM_GLOBAL_TTM_BO; 86 61 global_ref->size = sizeof(struct ttm_bo_global); ··· 64 89 r = drm_global_item_ref(global_ref); 65 90 if (r != 0) { 66 91 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 67 - drm_global_item_unref(&vgdev->mman.mem_global_ref); 68 92 return r; 69 93 } 70 94 ··· 75 101 { 76 102 if (vgdev->mman.mem_global_referenced) { 77 103 drm_global_item_unref(&vgdev->mman.bo_global_ref.ref); 78 - drm_global_item_unref(&vgdev->mman.mem_global_ref); 79 104 vgdev->mman.mem_global_referenced = false; 80 105 } 81 106 }
+2 -2
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 828 828 goto out_err4; 829 829 } 830 830 831 - dev_priv->tdev = ttm_object_device_init 832 - (dev_priv->mem_global_ref.object, 12, &vmw_prime_dmabuf_ops); 831 + dev_priv->tdev = ttm_object_device_init(&ttm_mem_glob, 12, 832 + &vmw_prime_dmabuf_ops); 833 833 834 834 if (unlikely(dev_priv->tdev == NULL)) { 835 835 DRM_ERROR("Unable to initialize TTM object management.\n");
+1 -2
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
··· 418 418 struct vmw_private { 419 419 struct ttm_bo_device bdev; 420 420 struct ttm_bo_global_ref bo_global_ref; 421 - struct drm_global_reference mem_global_ref; 422 421 423 422 struct vmw_fifo_state fifo; 424 423 ··· 1362 1363 1363 1364 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv) 1364 1365 { 1365 - return (struct ttm_mem_global *) dev_priv->mem_global_ref.object; 1366 + return &ttm_mem_glob; 1366 1367 } 1367 1368 1368 1369 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
-27
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
··· 43 43 return ttm_bo_mmap(filp, vma, &dev_priv->bdev); 44 44 } 45 45 46 - static int vmw_ttm_mem_global_init(struct drm_global_reference *ref) 47 - { 48 - DRM_INFO("global init.\n"); 49 - return ttm_mem_global_init(ref->object); 50 - } 51 - 52 - static void vmw_ttm_mem_global_release(struct drm_global_reference *ref) 53 - { 54 - ttm_mem_global_release(ref->object); 55 - } 56 - 57 46 int vmw_ttm_global_init(struct vmw_private *dev_priv) 58 47 { 59 48 struct drm_global_reference *global_ref; 60 49 int ret; 61 50 62 - global_ref = &dev_priv->mem_global_ref; 63 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 64 - global_ref->size = sizeof(struct ttm_mem_global); 65 - global_ref->init = &vmw_ttm_mem_global_init; 66 - global_ref->release = &vmw_ttm_mem_global_release; 67 - 68 - ret = drm_global_item_ref(global_ref); 69 - if (unlikely(ret != 0)) { 70 - DRM_ERROR("Failed setting up TTM memory accounting.\n"); 71 - return ret; 72 - } 73 - 74 - dev_priv->bo_global_ref.mem_glob = 75 - dev_priv->mem_global_ref.object; 76 51 global_ref = &dev_priv->bo_global_ref.ref; 77 52 global_ref->global_type = DRM_GLOBAL_TTM_BO; 78 53 global_ref->size = sizeof(struct ttm_bo_global); ··· 62 87 63 88 return 0; 64 89 out_no_bo: 65 - drm_global_item_unref(&dev_priv->mem_global_ref); 66 90 return ret; 67 91 } 68 92 69 93 void vmw_ttm_global_release(struct vmw_private *dev_priv) 70 94 { 71 95 drm_global_item_unref(&dev_priv->bo_global_ref.ref); 72 - drm_global_item_unref(&dev_priv->mem_global_ref); 73 96 }
-1
drivers/staging/vboxvideo/vbox_drv.h
··· 99 99 int fb_mtrr; 100 100 101 101 struct { 102 - struct drm_global_reference mem_global_ref; 103 102 struct ttm_bo_global_ref bo_global_ref; 104 103 struct ttm_bo_device bdev; 105 104 } ttm;
-24
drivers/staging/vboxvideo/vbox_ttm.c
··· 35 35 return container_of(bd, struct vbox_private, ttm.bdev); 36 36 } 37 37 38 - static int vbox_ttm_mem_global_init(struct drm_global_reference *ref) 39 - { 40 - return ttm_mem_global_init(ref->object); 41 - } 42 - 43 - static void vbox_ttm_mem_global_release(struct drm_global_reference *ref) 44 - { 45 - ttm_mem_global_release(ref->object); 46 - } 47 - 48 38 /** 49 39 * Adds the vbox memory manager object/structures to the global memory manager. 50 40 */ ··· 43 53 struct drm_global_reference *global_ref; 44 54 int ret; 45 55 46 - global_ref = &vbox->ttm.mem_global_ref; 47 - global_ref->global_type = DRM_GLOBAL_TTM_MEM; 48 - global_ref->size = sizeof(struct ttm_mem_global); 49 - global_ref->init = &vbox_ttm_mem_global_init; 50 - global_ref->release = &vbox_ttm_mem_global_release; 51 - ret = drm_global_item_ref(global_ref); 52 - if (ret) { 53 - DRM_ERROR("Failed setting up TTM memory subsystem.\n"); 54 - return ret; 55 - } 56 - 57 - vbox->ttm.bo_global_ref.mem_glob = vbox->ttm.mem_global_ref.object; 58 56 global_ref = &vbox->ttm.bo_global_ref.ref; 59 57 global_ref->global_type = DRM_GLOBAL_TTM_BO; 60 58 global_ref->size = sizeof(struct ttm_bo_global); ··· 52 74 ret = drm_global_item_ref(global_ref); 53 75 if (ret) { 54 76 DRM_ERROR("Failed setting up TTM BO subsystem.\n"); 55 - drm_global_item_unref(&vbox->ttm.mem_global_ref); 56 77 return ret; 57 78 } 58 79 ··· 64 87 static void vbox_ttm_global_release(struct vbox_private *vbox) 65 88 { 66 89 drm_global_item_unref(&vbox->ttm.bo_global_ref.ref); 67 - drm_global_item_unref(&vbox->ttm.mem_global_ref); 68 90 } 69 91 70 92 static void vbox_bo_ttm_destroy(struct ttm_buffer_object *tbo)
+2 -6
include/drm/ttm/ttm_bo_driver.h
··· 570 570 struct ttm_mem_reg *mem); 571 571 572 572 void ttm_bo_global_release(struct ttm_bo_global *glob); 573 - int ttm_bo_global_init(struct ttm_bo_global *glob, 574 - struct ttm_mem_global *mem_glob); 573 + int ttm_bo_global_init(struct ttm_bo_global *glob); 575 574 576 575 int ttm_bo_device_release(struct ttm_bo_device *bdev); 577 576 ··· 894 895 895 896 struct ttm_bo_global_ref { 896 897 struct drm_global_reference ref; 897 - struct ttm_mem_global *mem_glob; 898 898 }; 899 899 900 900 /** ··· 907 909 */ 908 910 static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) 909 911 { 910 - struct ttm_bo_global_ref *bo_ref = 911 - container_of(ref, struct ttm_bo_global_ref, ref); 912 - return ttm_bo_global_init(ref->object, bo_ref->mem_glob); 912 + return ttm_bo_global_init(ref->object); 913 913 } 914 914 915 915 /**
+2 -2
include/drm/ttm/ttm_memory.h
··· 63 63 64 64 #define TTM_MEM_MAX_ZONES 2 65 65 struct ttm_mem_zone; 66 - struct ttm_mem_global { 66 + extern struct ttm_mem_global { 67 67 struct kobject kobj; 68 68 struct ttm_bo_global *bo_glob; 69 69 struct workqueue_struct *swap_queue; ··· 78 78 #else 79 79 struct ttm_mem_zone *zone_dma32; 80 80 #endif 81 - }; 81 + } ttm_mem_glob; 82 82 83 83 extern int ttm_mem_global_init(struct ttm_mem_global *glob); 84 84 extern void ttm_mem_global_release(struct ttm_mem_global *glob);