drm/ttm: use a static ttm_mem_global instance
authorChristian König <christian.koenig@amd.com>
Fri, 19 Oct 2018 11:49:05 +0000 (13:49 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 5 Nov 2018 19:21:18 +0000 (14:21 -0500)
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>
29 files changed:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
drivers/gpu/drm/ast/ast_drv.h
drivers/gpu/drm/ast/ast_ttm.c
drivers/gpu/drm/bochs/bochs.h
drivers/gpu/drm/bochs/bochs_mm.c
drivers/gpu/drm/cirrus/cirrus_drv.h
drivers/gpu/drm/cirrus/cirrus_ttm.c
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
drivers/gpu/drm/mgag200/mgag200_drv.h
drivers/gpu/drm/mgag200/mgag200_ttm.c
drivers/gpu/drm/nouveau/nouveau_drv.h
drivers/gpu/drm/nouveau/nouveau_ttm.c
drivers/gpu/drm/qxl/qxl_drv.h
drivers/gpu/drm/qxl/qxl_ttm.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_ttm.c
drivers/gpu/drm/ttm/ttm_bo.c
drivers/gpu/drm/ttm/ttm_memory.c
drivers/gpu/drm/virtio/virtgpu_drv.h
drivers/gpu/drm/virtio/virtgpu_ttm.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
drivers/staging/vboxvideo/vbox_drv.h
drivers/staging/vboxvideo/vbox_ttm.c
include/drm/ttm/ttm_bo_driver.h
include/drm/ttm/ttm_memory.h

index 3a680284669819b5d067b246cfa3815116f5031e..fda252022b1508ff7b26b50f94841b3af6a3937b 100644 (file)
@@ -65,33 +65,6 @@ static void amdgpu_ttm_debugfs_fini(struct amdgpu_device *adev);
  * Global memory.
  */
 
-/**
- * amdgpu_ttm_mem_global_init - Initialize and acquire reference to
- * memory object
- *
- * @ref: Object for initialization.
- *
- * This is called by drm_global_item_ref() when an object is being
- * initialized.
- */
-static int amdgpu_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-/**
- * amdgpu_ttm_mem_global_release - Drop reference to a memory object
- *
- * @ref: Object being removed
- *
- * This is called by drm_global_item_unref() when an object is being
- * released.
- */
-static void amdgpu_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 /**
  * amdgpu_ttm_global_init - Initialize global TTM memory reference structures.
  *
@@ -108,20 +81,6 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
        /* ensure reference is false in case init fails */
        adev->mman.mem_global_referenced = false;
 
-       global_ref = &adev->mman.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &amdgpu_ttm_mem_global_init;
-       global_ref->release = &amdgpu_ttm_mem_global_release;
-       r = drm_global_item_ref(global_ref);
-       if (r) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               goto error_mem;
-       }
-
-       adev->mman.bo_global_ref.mem_glob =
-               adev->mman.mem_global_ref.object;
        global_ref = &adev->mman.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -140,8 +99,6 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
        return 0;
 
 error_bo:
-       drm_global_item_unref(&adev->mman.mem_global_ref);
-error_mem:
        return r;
 }
 
@@ -150,7 +107,6 @@ static void amdgpu_ttm_global_fini(struct amdgpu_device *adev)
        if (adev->mman.mem_global_referenced) {
                mutex_destroy(&adev->mman.gtt_window_lock);
                drm_global_item_unref(&adev->mman.bo_global_ref.ref);
-               drm_global_item_unref(&adev->mman.mem_global_ref);
                adev->mman.mem_global_referenced = false;
        }
 }
index fe8f276e9811c02e1bdee63c136e7bcf81afc876..e114f209b701b24357367f9b2efd134379080260 100644 (file)
@@ -40,7 +40,6 @@
 
 struct amdgpu_mman {
        struct ttm_bo_global_ref        bo_global_ref;
-       struct drm_global_reference     mem_global_ref;
        struct ttm_bo_device            bdev;
        bool                            mem_global_referenced;
        bool                            initialized;
index e6c4cd3dc50ec7540d65efd61fea71ddb249ecdd..6ae11a4776431b36cb206ea0e8a976278cfe0f72 100644 (file)
@@ -104,7 +104,6 @@ struct ast_private {
        int fb_mtrr;
 
        struct {
-               struct drm_global_reference mem_global_ref;
                struct ttm_bo_global_ref bo_global_ref;
                struct ttm_bo_device bdev;
        } ttm;
index d21fbd26785a11f700a5896271d1d513c4dba9fc..8a59d6fc11608db95407bad6a43b041eb17bbb45 100644 (file)
@@ -36,37 +36,11 @@ ast_bdev(struct ttm_bo_device *bd)
        return container_of(bd, struct ast_private, ttm.bdev);
 }
 
-static int
-ast_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void
-ast_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int ast_ttm_global_init(struct ast_private *ast)
 {
        struct drm_global_reference *global_ref;
        int r;
 
-       global_ref = &ast->ttm.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &ast_ttm_mem_global_init;
-       global_ref->release = &ast_ttm_mem_global_release;
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       ast->ttm.bo_global_ref.mem_glob =
-               ast->ttm.mem_global_ref.object;
        global_ref = &ast->ttm.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -75,7 +49,6 @@ static int ast_ttm_global_init(struct ast_private *ast)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&ast->ttm.mem_global_ref);
                return r;
        }
        return 0;
@@ -84,12 +57,11 @@ static int ast_ttm_global_init(struct ast_private *ast)
 static void
 ast_ttm_global_release(struct ast_private *ast)
 {
-       if (ast->ttm.mem_global_ref.release == NULL)
+       if (ast->ttm.bo_global_ref.ref.release == NULL)
                return;
 
        drm_global_item_unref(&ast->ttm.bo_global_ref.ref);
-       drm_global_item_unref(&ast->ttm.mem_global_ref);
-       ast->ttm.mem_global_ref.release = NULL;
+       ast->ttm.bo_global_ref.ref.release = NULL;
 }
 
 
index e7a69077e45adfa15431fdb8bb89d6d00c420541..a035257d1b56c429acb420960d6531e37c1e06f6 100644 (file)
@@ -76,7 +76,6 @@ struct bochs_device {
 
        /* ttm */
        struct {
-               struct drm_global_reference mem_global_ref;
                struct ttm_bo_global_ref bo_global_ref;
                struct ttm_bo_device bdev;
                bool initialized;
index 2d36179c0e836e47a34a41e4f110a539ed091a4e..c697d456656fd0fc2486e56dae6542f1d5f4dda3 100644 (file)
@@ -16,35 +16,11 @@ static inline struct bochs_device *bochs_bdev(struct ttm_bo_device *bd)
        return container_of(bd, struct bochs_device, ttm.bdev);
 }
 
-static int bochs_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void bochs_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int bochs_ttm_global_init(struct bochs_device *bochs)
 {
        struct drm_global_reference *global_ref;
        int r;
 
-       global_ref = &bochs->ttm.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &bochs_ttm_mem_global_init;
-       global_ref->release = &bochs_ttm_mem_global_release;
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       bochs->ttm.bo_global_ref.mem_glob =
-               bochs->ttm.mem_global_ref.object;
        global_ref = &bochs->ttm.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -53,7 +29,6 @@ static int bochs_ttm_global_init(struct bochs_device *bochs)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&bochs->ttm.mem_global_ref);
                return r;
        }
 
@@ -62,12 +37,11 @@ static int bochs_ttm_global_init(struct bochs_device *bochs)
 
 static void bochs_ttm_global_release(struct bochs_device *bochs)
 {
-       if (bochs->ttm.mem_global_ref.release == NULL)
+       if (bochs->ttm.bo_global_ref.ref.release == NULL)
                return;
 
        drm_global_item_unref(&bochs->ttm.bo_global_ref.ref);
-       drm_global_item_unref(&bochs->ttm.mem_global_ref);
-       bochs->ttm.mem_global_ref.release = NULL;
+       bochs->ttm.bo_global_ref.ref.release = NULL;
 }
 
 
index a29f87e98d9d2a224cfb699528e38f4cbdb44c7b..01852fbda9daec266fe3e80da1db2111944ffada 100644 (file)
@@ -136,7 +136,6 @@ struct cirrus_device {
        int fb_mtrr;
 
        struct {
-               struct drm_global_reference mem_global_ref;
                struct ttm_bo_global_ref bo_global_ref;
                struct ttm_bo_device bdev;
        } ttm;
index 2e2141f26c5b2767b78440e341eb0f369687ffb7..7801c56c3c9b47f97c315cdef2e448e4999ad10d 100644 (file)
@@ -36,37 +36,11 @@ cirrus_bdev(struct ttm_bo_device *bd)
        return container_of(bd, struct cirrus_device, ttm.bdev);
 }
 
-static int
-cirrus_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void
-cirrus_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int cirrus_ttm_global_init(struct cirrus_device *cirrus)
 {
        struct drm_global_reference *global_ref;
        int r;
 
-       global_ref = &cirrus->ttm.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &cirrus_ttm_mem_global_init;
-       global_ref->release = &cirrus_ttm_mem_global_release;
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       cirrus->ttm.bo_global_ref.mem_glob =
-               cirrus->ttm.mem_global_ref.object;
        global_ref = &cirrus->ttm.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -75,7 +49,6 @@ static int cirrus_ttm_global_init(struct cirrus_device *cirrus)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&cirrus->ttm.mem_global_ref);
                return r;
        }
        return 0;
@@ -84,12 +57,11 @@ static int cirrus_ttm_global_init(struct cirrus_device *cirrus)
 static void
 cirrus_ttm_global_release(struct cirrus_device *cirrus)
 {
-       if (cirrus->ttm.mem_global_ref.release == NULL)
+       if (cirrus->ttm.bo_global_ref.ref.release == NULL)
                return;
 
        drm_global_item_unref(&cirrus->ttm.bo_global_ref.ref);
-       drm_global_item_unref(&cirrus->ttm.mem_global_ref);
-       cirrus->ttm.mem_global_ref.release = NULL;
+       cirrus->ttm.bo_global_ref.ref.release = NULL;
 }
 
 
index 45c25a488f429f58b126de5ce1a5c2ef6c4aa8d5..60479502e277c3ac0ebc57edc152119a71aa483d 100644 (file)
@@ -49,7 +49,6 @@ struct hibmc_drm_private {
        bool mode_config_initialized;
 
        /* ttm */
-       struct drm_global_reference mem_global_ref;
        struct ttm_bo_global_ref bo_global_ref;
        struct ttm_bo_device bdev;
        bool initialized;
index 0454aa43ffc69248733dad49762ddd88a3720c93..14071c849121650104408d40f50a3f5260ed15ac 100644 (file)
@@ -29,34 +29,10 @@ hibmc_bdev(struct ttm_bo_device *bd)
        return container_of(bd, struct hibmc_drm_private, bdev);
 }
 
-static int
-hibmc_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void
-hibmc_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc)
 {
        int ret;
 
-       hibmc->mem_global_ref.global_type = DRM_GLOBAL_TTM_MEM;
-       hibmc->mem_global_ref.size = sizeof(struct ttm_mem_global);
-       hibmc->mem_global_ref.init = &hibmc_ttm_mem_global_init;
-       hibmc->mem_global_ref.release = &hibmc_ttm_mem_global_release;
-       ret = drm_global_item_ref(&hibmc->mem_global_ref);
-       if (ret) {
-               DRM_ERROR("could not get ref on ttm global: %d\n", ret);
-               return ret;
-       }
-
-       hibmc->bo_global_ref.mem_glob =
-               hibmc->mem_global_ref.object;
        hibmc->bo_global_ref.ref.global_type = DRM_GLOBAL_TTM_BO;
        hibmc->bo_global_ref.ref.size = sizeof(struct ttm_bo_global);
        hibmc->bo_global_ref.ref.init = &ttm_bo_global_ref_init;
@@ -64,7 +40,6 @@ static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc)
        ret = drm_global_item_ref(&hibmc->bo_global_ref.ref);
        if (ret) {
                DRM_ERROR("failed setting up TTM BO subsystem: %d\n", ret);
-               drm_global_item_unref(&hibmc->mem_global_ref);
                return ret;
        }
        return 0;
@@ -73,9 +48,11 @@ static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc)
 static void
 hibmc_ttm_global_release(struct hibmc_drm_private *hibmc)
 {
+       if (hibmc->bo_global_ref.ref.release == NULL)
+               return;
+
        drm_global_item_unref(&hibmc->bo_global_ref.ref);
-       drm_global_item_unref(&hibmc->mem_global_ref);
-       hibmc->mem_global_ref.release = NULL;
+       hibmc->bo_global_ref.ref.release = NULL;
 }
 
 static void hibmc_bo_ttm_destroy(struct ttm_buffer_object *tbo)
index 04f1dfba12e5993ead71b7ef1639ac208c0be938..e5348955a3cc441e2dbd23e91c5c27b6d89d857b 100644 (file)
@@ -212,7 +212,6 @@ struct mga_device {
        int fb_mtrr;
 
        struct {
-               struct drm_global_reference mem_global_ref;
                struct ttm_bo_global_ref bo_global_ref;
                struct ttm_bo_device bdev;
        } ttm;
index 3444b539e7f46ddc31b63b9003a961887474f21e..11bdc8121a7d7ecf5db3240f3e04972117591959 100644 (file)
@@ -36,37 +36,11 @@ mgag200_bdev(struct ttm_bo_device *bd)
        return container_of(bd, struct mga_device, ttm.bdev);
 }
 
-static int
-mgag200_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void
-mgag200_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int mgag200_ttm_global_init(struct mga_device *ast)
 {
        struct drm_global_reference *global_ref;
        int r;
 
-       global_ref = &ast->ttm.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &mgag200_ttm_mem_global_init;
-       global_ref->release = &mgag200_ttm_mem_global_release;
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       ast->ttm.bo_global_ref.mem_glob =
-               ast->ttm.mem_global_ref.object;
        global_ref = &ast->ttm.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -75,7 +49,6 @@ static int mgag200_ttm_global_init(struct mga_device *ast)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&ast->ttm.mem_global_ref);
                return r;
        }
        return 0;
@@ -84,12 +57,11 @@ static int mgag200_ttm_global_init(struct mga_device *ast)
 static void
 mgag200_ttm_global_release(struct mga_device *ast)
 {
-       if (ast->ttm.mem_global_ref.release == NULL)
+       if (ast->ttm.bo_global_ref.ref.release == NULL)
                return;
 
        drm_global_item_unref(&ast->ttm.bo_global_ref.ref);
-       drm_global_item_unref(&ast->ttm.mem_global_ref);
-       ast->ttm.mem_global_ref.release = NULL;
+       ast->ttm.bo_global_ref.ref.release = NULL;
 }
 
 
index 0b2191fa96f7bc288e28e2cb6df141422882ef1a..0f3bb1a11fc926c2aa983409a12012f448c3f24a 100644 (file)
@@ -146,7 +146,6 @@ struct nouveau_drm {
 
        /* TTM interface support */
        struct {
-               struct drm_global_reference mem_global_ref;
                struct ttm_bo_global_ref bo_global_ref;
                struct ttm_bo_device bdev;
                atomic_t validate_sequence;
index a293383c8654191a5eaad5b04b911353e7a8ccae..69448b02649e5472c5886c54f20e140fecdd1388 100644 (file)
@@ -174,38 +174,12 @@ nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)
        return ttm_bo_mmap(filp, vma, &drm->ttm.bdev);
 }
 
-static int
-nouveau_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void
-nouveau_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 int
 nouveau_ttm_global_init(struct nouveau_drm *drm)
 {
        struct drm_global_reference *global_ref;
        int ret;
 
-       global_ref = &drm->ttm.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &nouveau_ttm_mem_global_init;
-       global_ref->release = &nouveau_ttm_mem_global_release;
-
-       ret = drm_global_item_ref(global_ref);
-       if (unlikely(ret != 0)) {
-               DRM_ERROR("Failed setting up TTM memory accounting\n");
-               drm->ttm.mem_global_ref.release = NULL;
-               return ret;
-       }
-
-       drm->ttm.bo_global_ref.mem_glob = global_ref->object;
        global_ref = &drm->ttm.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -215,8 +189,7 @@ nouveau_ttm_global_init(struct nouveau_drm *drm)
        ret = drm_global_item_ref(global_ref);
        if (unlikely(ret != 0)) {
                DRM_ERROR("Failed setting up TTM BO subsystem\n");
-               drm_global_item_unref(&drm->ttm.mem_global_ref);
-               drm->ttm.mem_global_ref.release = NULL;
+               drm->ttm.bo_global_ref.ref.release = NULL;
                return ret;
        }
 
@@ -226,12 +199,11 @@ nouveau_ttm_global_init(struct nouveau_drm *drm)
 void
 nouveau_ttm_global_release(struct nouveau_drm *drm)
 {
-       if (drm->ttm.mem_global_ref.release == NULL)
+       if (drm->ttm.bo_global_ref.ref.release == NULL)
                return;
 
        drm_global_item_unref(&drm->ttm.bo_global_ref.ref);
-       drm_global_item_unref(&drm->ttm.mem_global_ref);
-       drm->ttm.mem_global_ref.release = NULL;
+       drm->ttm.bo_global_ref.ref.release = NULL;
 }
 
 static int
index 8ff70a7281a73580f2d8e475d6d8d5489392a82c..52912e54e990acd2e7999d77aa862f7ad17a5dc1 100644 (file)
@@ -128,7 +128,6 @@ struct qxl_output {
 
 struct qxl_mman {
        struct ttm_bo_global_ref        bo_global_ref;
-       struct drm_global_reference     mem_global_ref;
        bool                            mem_global_referenced;
        struct ttm_bo_device            bdev;
 };
index db2a0036e9c45617b4e26ee08c4957853c0d949f..bb8cc9b16780137cdda530a60dbf14c9b7c773c0 100644 (file)
@@ -46,37 +46,11 @@ static struct qxl_device *qxl_get_qdev(struct ttm_bo_device *bdev)
        return qdev;
 }
 
-static int qxl_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void qxl_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int qxl_ttm_global_init(struct qxl_device *qdev)
 {
        struct drm_global_reference *global_ref;
        int r;
 
-       qdev->mman.mem_global_referenced = false;
-       global_ref = &qdev->mman.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &qxl_ttm_mem_global_init;
-       global_ref->release = &qxl_ttm_mem_global_release;
-
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       qdev->mman.bo_global_ref.mem_glob =
-               qdev->mman.mem_global_ref.object;
        global_ref = &qdev->mman.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -85,7 +59,6 @@ static int qxl_ttm_global_init(struct qxl_device *qdev)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&qdev->mman.mem_global_ref);
                return r;
        }
 
@@ -97,7 +70,6 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
 {
        if (qdev->mman.mem_global_referenced) {
                drm_global_item_unref(&qdev->mman.bo_global_ref.ref);
-               drm_global_item_unref(&qdev->mman.mem_global_ref);
                qdev->mman.mem_global_referenced = false;
        }
 }
index 1a6f6edb3515188ea55e3ce8e2b9d2e951d0c8c7..06fb952b6290d870a9ce3c63be3ea97718ff1dd6 100644 (file)
@@ -449,7 +449,6 @@ struct radeon_surface_reg {
  */
 struct radeon_mman {
        struct ttm_bo_global_ref        bo_global_ref;
-       struct drm_global_reference     mem_global_ref;
        struct ttm_bo_device            bdev;
        bool                            mem_global_referenced;
        bool                            initialized;
index dac4ec5a120bbf78f53a480930114a11ef3d930e..2104429ddbac321e64e0b1b86a2107822a169904 100644 (file)
@@ -64,36 +64,12 @@ static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
 /*
  * Global memory.
  */
-static int radeon_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void radeon_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int radeon_ttm_global_init(struct radeon_device *rdev)
 {
        struct drm_global_reference *global_ref;
        int r;
 
        rdev->mman.mem_global_referenced = false;
-       global_ref = &rdev->mman.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &radeon_ttm_mem_global_init;
-       global_ref->release = &radeon_ttm_mem_global_release;
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       rdev->mman.bo_global_ref.mem_glob =
-               rdev->mman.mem_global_ref.object;
        global_ref = &rdev->mman.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -102,7 +78,6 @@ static int radeon_ttm_global_init(struct radeon_device *rdev)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&rdev->mman.mem_global_ref);
                return r;
        }
 
@@ -114,7 +89,6 @@ static void radeon_ttm_global_fini(struct radeon_device *rdev)
 {
        if (rdev->mman.mem_global_referenced) {
                drm_global_item_unref(&rdev->mman.bo_global_ref.ref);
-               drm_global_item_unref(&rdev->mman.mem_global_ref);
                rdev->mman.mem_global_referenced = false;
        }
 }
index 9edece6510d3995caa57dcab521b9b47af6d0d80..3006050b1720aa488e0688a7ff7d0c13a779c405 100644 (file)
@@ -1526,18 +1526,22 @@ void ttm_bo_global_release(struct ttm_bo_global *glob)
 {
        kobject_del(&glob->kobj);
        kobject_put(&glob->kobj);
+       ttm_mem_global_release(&ttm_mem_glob);
 }
 EXPORT_SYMBOL(ttm_bo_global_release);
 
-int ttm_bo_global_init(struct ttm_bo_global *glob,
-                      struct ttm_mem_global *mem_glob)
+int ttm_bo_global_init(struct ttm_bo_global *glob)
 {
        int ret;
        unsigned i;
 
+       ret = ttm_mem_global_init(&ttm_mem_glob);
+       if (ret)
+               return ret;
+
        mutex_init(&glob->device_list_mutex);
        spin_lock_init(&glob->lru_lock);
-       glob->mem_glob = mem_glob;
+       glob->mem_glob = &ttm_mem_glob;
        glob->mem_glob->bo_glob = glob;
        glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
 
index 450387c92b63510df8b9e8ff340b511472b69462..7704e17c402fa842c5e8c3b7df6fc9fd21f8df8f 100644 (file)
@@ -41,6 +41,9 @@
 
 #define TTM_MEMORY_ALLOC_RETRIES 4
 
+struct ttm_mem_global ttm_mem_glob;
+EXPORT_SYMBOL(ttm_mem_glob);
+
 struct ttm_mem_zone {
        struct kobject kobj;
        struct ttm_mem_global *glob;
@@ -464,7 +467,6 @@ out_no_zone:
        ttm_mem_global_release(glob);
        return ret;
 }
-EXPORT_SYMBOL(ttm_mem_global_init);
 
 void ttm_mem_global_release(struct ttm_mem_global *glob)
 {
@@ -486,7 +488,6 @@ void ttm_mem_global_release(struct ttm_mem_global *glob)
        kobject_del(&glob->kobj);
        kobject_put(&glob->kobj);
 }
-EXPORT_SYMBOL(ttm_mem_global_release);
 
 static void ttm_check_swapping(struct ttm_mem_global *glob)
 {
index d29f0c7c768c199b7e959883becf6f893d54ee9a..d9756b59e329528fe651b7527799ef986fd02eba 100644 (file)
@@ -143,7 +143,6 @@ struct virtio_gpu_fbdev {
 
 struct virtio_gpu_mman {
        struct ttm_bo_global_ref        bo_global_ref;
-       struct drm_global_reference     mem_global_ref;
        bool                            mem_global_referenced;
        struct ttm_bo_device            bdev;
 };
index 526a5e48dc3b12a70efcb9ba681be319b6a266c6..8510109e09da6d636ec3f32fa9a88643b6cb80fc 100644 (file)
@@ -50,37 +50,12 @@ virtio_gpu_device *virtio_gpu_get_vgdev(struct ttm_bo_device *bdev)
        return vgdev;
 }
 
-static int virtio_gpu_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void virtio_gpu_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 static int virtio_gpu_ttm_global_init(struct virtio_gpu_device *vgdev)
 {
        struct drm_global_reference *global_ref;
        int r;
 
        vgdev->mman.mem_global_referenced = false;
-       global_ref = &vgdev->mman.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &virtio_gpu_ttm_mem_global_init;
-       global_ref->release = &virtio_gpu_ttm_mem_global_release;
-
-       r = drm_global_item_ref(global_ref);
-       if (r != 0) {
-               DRM_ERROR("Failed setting up TTM memory accounting "
-                         "subsystem.\n");
-               return r;
-       }
-
-       vgdev->mman.bo_global_ref.mem_glob =
-               vgdev->mman.mem_global_ref.object;
        global_ref = &vgdev->mman.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -89,7 +64,6 @@ static int virtio_gpu_ttm_global_init(struct virtio_gpu_device *vgdev)
        r = drm_global_item_ref(global_ref);
        if (r != 0) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&vgdev->mman.mem_global_ref);
                return r;
        }
 
@@ -101,7 +75,6 @@ static void virtio_gpu_ttm_global_fini(struct virtio_gpu_device *vgdev)
 {
        if (vgdev->mman.mem_global_referenced) {
                drm_global_item_unref(&vgdev->mman.bo_global_ref.ref);
-               drm_global_item_unref(&vgdev->mman.mem_global_ref);
                vgdev->mman.mem_global_referenced = false;
        }
 }
index 61a84b958d671671cb56c37b6e44a589989d026b..67494148accd6f4ee119936e9427301f23eb4d54 100644 (file)
@@ -828,8 +828,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
                goto out_err4;
        }
 
-       dev_priv->tdev = ttm_object_device_init
-               (dev_priv->mem_global_ref.object, 12, &vmw_prime_dmabuf_ops);
+       dev_priv->tdev = ttm_object_device_init(&ttm_mem_glob, 12,
+                                               &vmw_prime_dmabuf_ops);
 
        if (unlikely(dev_priv->tdev == NULL)) {
                DRM_ERROR("Unable to initialize TTM object management.\n");
index 59f614225bcd72b8a84a5de42813359e9a2760d0..252f202ae8972e22fcd6d9a1ed75a2b9102f85e9 100644 (file)
@@ -418,7 +418,6 @@ enum {
 struct vmw_private {
        struct ttm_bo_device bdev;
        struct ttm_bo_global_ref bo_global_ref;
-       struct drm_global_reference mem_global_ref;
 
        struct vmw_fifo_state fifo;
 
@@ -1363,7 +1362,7 @@ vmw_bo_reference(struct vmw_buffer_object *buf)
 
 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
 {
-       return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
+       return &ttm_mem_glob;
 }
 
 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
index f3ce43c41978243e346f0399520b01cad28882e2..0ac473cd5136a3201531c02cbc999bffd03ac700 100644 (file)
@@ -43,36 +43,11 @@ int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
        return ttm_bo_mmap(filp, vma, &dev_priv->bdev);
 }
 
-static int vmw_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       DRM_INFO("global init.\n");
-       return ttm_mem_global_init(ref->object);
-}
-
-static void vmw_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 int vmw_ttm_global_init(struct vmw_private *dev_priv)
 {
        struct drm_global_reference *global_ref;
        int ret;
 
-       global_ref = &dev_priv->mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &vmw_ttm_mem_global_init;
-       global_ref->release = &vmw_ttm_mem_global_release;
-
-       ret = drm_global_item_ref(global_ref);
-       if (unlikely(ret != 0)) {
-               DRM_ERROR("Failed setting up TTM memory accounting.\n");
-               return ret;
-       }
-
-       dev_priv->bo_global_ref.mem_glob =
-               dev_priv->mem_global_ref.object;
        global_ref = &dev_priv->bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -87,12 +62,10 @@ int vmw_ttm_global_init(struct vmw_private *dev_priv)
 
        return 0;
 out_no_bo:
-       drm_global_item_unref(&dev_priv->mem_global_ref);
        return ret;
 }
 
 void vmw_ttm_global_release(struct vmw_private *dev_priv)
 {
        drm_global_item_unref(&dev_priv->bo_global_ref.ref);
-       drm_global_item_unref(&dev_priv->mem_global_ref);
 }
index 73395a7536c5aecd8c62bc04634cb0afb4b418b6..dc257a892ecbf79ad0dccae4d579e66e0d51d624 100644 (file)
@@ -99,7 +99,6 @@ struct vbox_private {
        int fb_mtrr;
 
        struct {
-               struct drm_global_reference mem_global_ref;
                struct ttm_bo_global_ref bo_global_ref;
                struct ttm_bo_device bdev;
        } ttm;
index 344975579ea5d9c65ba4fb5ab21c9407abdb981c..73b8953280597383a4fcdf47f6b7c93a34a4d22c 100644 (file)
@@ -35,16 +35,6 @@ static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd)
        return container_of(bd, struct vbox_private, ttm.bdev);
 }
 
-static int vbox_ttm_mem_global_init(struct drm_global_reference *ref)
-{
-       return ttm_mem_global_init(ref->object);
-}
-
-static void vbox_ttm_mem_global_release(struct drm_global_reference *ref)
-{
-       ttm_mem_global_release(ref->object);
-}
-
 /**
  * Adds the vbox memory manager object/structures to the global memory manager.
  */
@@ -53,18 +43,6 @@ static int vbox_ttm_global_init(struct vbox_private *vbox)
        struct drm_global_reference *global_ref;
        int ret;
 
-       global_ref = &vbox->ttm.mem_global_ref;
-       global_ref->global_type = DRM_GLOBAL_TTM_MEM;
-       global_ref->size = sizeof(struct ttm_mem_global);
-       global_ref->init = &vbox_ttm_mem_global_init;
-       global_ref->release = &vbox_ttm_mem_global_release;
-       ret = drm_global_item_ref(global_ref);
-       if (ret) {
-               DRM_ERROR("Failed setting up TTM memory subsystem.\n");
-               return ret;
-       }
-
-       vbox->ttm.bo_global_ref.mem_glob = vbox->ttm.mem_global_ref.object;
        global_ref = &vbox->ttm.bo_global_ref.ref;
        global_ref->global_type = DRM_GLOBAL_TTM_BO;
        global_ref->size = sizeof(struct ttm_bo_global);
@@ -74,7 +52,6 @@ static int vbox_ttm_global_init(struct vbox_private *vbox)
        ret = drm_global_item_ref(global_ref);
        if (ret) {
                DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-               drm_global_item_unref(&vbox->ttm.mem_global_ref);
                return ret;
        }
 
@@ -87,7 +64,6 @@ static int vbox_ttm_global_init(struct vbox_private *vbox)
 static void vbox_ttm_global_release(struct vbox_private *vbox)
 {
        drm_global_item_unref(&vbox->ttm.bo_global_ref.ref);
-       drm_global_item_unref(&vbox->ttm.mem_global_ref);
 }
 
 static void vbox_bo_ttm_destroy(struct ttm_buffer_object *tbo)
index c6ee07d102817b5d6e9803f70177bbf2195b18b1..4ae6fc33f76140275a56aed44849c43257243de5 100644 (file)
@@ -570,8 +570,7 @@ void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo,
                           struct ttm_mem_reg *mem);
 
 void ttm_bo_global_release(struct ttm_bo_global *glob);
-int ttm_bo_global_init(struct ttm_bo_global *glob,
-                      struct ttm_mem_global *mem_glob);
+int ttm_bo_global_init(struct ttm_bo_global *glob);
 
 int ttm_bo_device_release(struct ttm_bo_device *bdev);
 
@@ -895,7 +894,6 @@ extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
 struct ttm_bo_global_ref {
        struct drm_global_reference ref;
-       struct ttm_mem_global *mem_glob;
 };
 
 /**
@@ -909,9 +907,7 @@ struct ttm_bo_global_ref {
  */
 static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref)
 {
-       struct ttm_bo_global_ref *bo_ref =
-               container_of(ref, struct ttm_bo_global_ref, ref);
-       return ttm_bo_global_init(ref->object, bo_ref->mem_glob);
+       return ttm_bo_global_init(ref->object);
 }
 
 /**
index 737b5fed80031bac39aa1a59b65a3f2a6da42d11..3ff48a0a2d7b7728469034430434a311e4bbcb40 100644 (file)
@@ -63,7 +63,7 @@
 
 #define TTM_MEM_MAX_ZONES 2
 struct ttm_mem_zone;
-struct ttm_mem_global {
+extern struct ttm_mem_global {
        struct kobject kobj;
        struct ttm_bo_global *bo_glob;
        struct workqueue_struct *swap_queue;
@@ -78,7 +78,7 @@ struct ttm_mem_global {
 #else
        struct ttm_mem_zone *zone_dma32;
 #endif
-};
+} ttm_mem_glob;
 
 extern int ttm_mem_global_init(struct ttm_mem_global *glob);
 extern void ttm_mem_global_release(struct ttm_mem_global *glob);