@@ -1,6 +1,6 @@
/*
* Copyright 2010 Matt Turner.
- * Copyright 2012 Red Hat
+ * Copyright 2012 Red Hat
*
* This file is subject to the terms and conditions of the GNU General
* Public License version 2. See the file COPYING in the main
@@ -22,6 +22,7 @@
#include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_memory.h>
#include <drm/ttm/ttm_module.h>
+#include <drm/ttm/ttm_global.h>
#include <drm/drm_gem.h>
@@ -212,9 +213,9 @@ struct mga_device {
int fb_mtrr;
struct {
- struct drm_global_reference mem_global_ref;
- struct ttm_bo_global_ref bo_global_ref;
+ struct ttm_global glob;
struct ttm_bo_device bdev;
+ bool glob_initialized;
} ttm;
/* SE model number stored in reg 0x1e24 */
@@ -36,60 +36,27 @@ 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);
+ int r = ttm_global_init(&ast->ttm.glob);
if (r != 0) {
- DRM_ERROR("Failed setting up TTM memory accounting "
- "subsystem.\n");
+ DRM_ERROR("Failed setting up TTM 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);
- global_ref->init = &ttm_bo_global_ref_init;
- global_ref->release = &ttm_bo_global_ref_release;
- 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;
- }
+ ast->ttm.glob_initialized = true;
+
return 0;
}
static void
mgag200_ttm_global_release(struct mga_device *ast)
{
- if (ast->ttm.mem_global_ref.release == NULL)
+ if (!ast->ttm.glob_initialized)
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;
+ ttm_global_release(&ast->ttm.glob);
+ ast->ttm.glob_initialized = false;
}
@@ -237,7 +204,7 @@ int mgag200_mm_init(struct mga_device *mdev)
return ret;
ret = ttm_bo_device_init(&mdev->ttm.bdev,
- mdev->ttm.bo_global_ref.ref.object,
+ mdev->ttm.glob.bo_ref.object,
&mgag200_bo_driver,
dev->anon_inode->i_mapping,
DRM_FILE_PAGE_OFFSET,
Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> --- drivers/gpu/drm/mgag200/mgag200_drv.h | 7 ++-- drivers/gpu/drm/mgag200/mgag200_ttm.c | 49 +++++---------------------- 2 files changed, 12 insertions(+), 44 deletions(-)