dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH 00/18] Provide a nice interface for TTM global state
@ 2018-10-19  8:54 Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing " Thomas Zimmermann
                   ` (6 more replies)
  0 siblings, 7 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

This is the full patch set for cleaning up the TTM global-state handling
and offering a nice interface for drivers. The first 3 patches have been
discussed on dri-devel already.

Patch [01] adds struct ttm_global, a data structure that gives drivers
a handle ot the global TTM state.

Patches [02] to [13] convert all TTM drivers to struct ttm_global.

Patches [14] and [15] remove unused code.

Patches [16] to [18] merge the functionality of struct drm_global_reference
into the implementation of struct ttm_global and remove the former.

I'd really like to see patches [01] to [15] being merging in one way or the
other. Using struct ttm_global allows for sharing code that touches TTM
internals, and it gets drivers out of the way for the cleanup of the final
3 patches.

One question was if the current infrastructure around drm_global_reference
isn't over-engineered and could be simplified. For now, I took the existing
ref-counting as it is in drm_global.c. This can certainly be simplified if
prefered.

Thomas Zimmermann (18):
  drm/ttm: Provide struct ttm_global for referencing TTM global state
  drm/amdgpu: Replace TTM initialization/release with ttm_global
  drm/radeon: Replace TTM initialization/release with ttm_global
  drm/ast: Replace TTM initialization/release with ttm_global
  drm/bochs: Replace TTM initialization/release with ttm_global
  drm/cirrus: Replace TTM initialization/release with ttm_global
  drm/hisilicon: Replace TTM initialization/release with ttm_global
  drm/mgag200: Replace TTM initialization/release with ttm_global
  drm/nouveau: Replace TTM initialization/release with ttm_global
  drm/qlx: Replace TTM initialization/release with ttm_global
  drm/virtio: Replace TTM initialization/release with ttm_global
  drm/vmwgfx: Replace TTM initialization/release with ttm_global
  staging/vboxvideo: Replace TTM initialization/release with ttm_global
  drm/ttm: Remove struct ttm_bo_global_ref and helpers
  drm: Remove DRM_GLOBAL_TTM_OBJECT
  drm/ttm: Implement struct ttm_global_item and helpers
  drm/ttm: Implement struct ttm_global with struct ttm_global_ref
  drm: Remove drm_global.{c,h}

 drivers/gpu/drm/Makefile                      |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  63 +-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |   4 +-
 drivers/gpu/drm/ast/ast_drv.h                 |   5 +-
 drivers/gpu/drm/ast/ast_ttm.c                 |  49 +----
 drivers/gpu/drm/bochs/bochs.h                 |   5 +-
 drivers/gpu/drm/bochs/bochs_mm.c              |  47 +----
 drivers/gpu/drm/cirrus/cirrus_drv.h           |   5 +-
 drivers/gpu/drm/cirrus/cirrus_ttm.c           |  49 +----
 drivers/gpu/drm/drm_drv.c                     |   2 -
 drivers/gpu/drm/drm_global.c                  | 137 ------------
 drivers/gpu/drm/gma500/psb_drv.h              |   4 +-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |   4 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c   |  36 +---
 drivers/gpu/drm/mgag200/mgag200_drv.h         |   7 +-
 drivers/gpu/drm/mgag200/mgag200_ttm.c         |  49 +----
 drivers/gpu/drm/nouveau/nouveau_drv.h         |   5 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c         |  48 +----
 drivers/gpu/drm/qxl/qxl_drv.h                 |   4 +-
 drivers/gpu/drm/qxl/qxl_ttm.c                 |  40 +---
 drivers/gpu/drm/radeon/radeon.h               |   4 +-
 drivers/gpu/drm/radeon/radeon_ttm.c           |  40 +---
 drivers/gpu/drm/ttm/Makefile                  |   2 +-
 drivers/gpu/drm/ttm/ttm_global.c              | 198 ++++++++++++++++++
 drivers/gpu/drm/virtio/virtgpu_drv.h          |   4 +-
 drivers/gpu/drm/virtio/virtgpu_ttm.c          |  40 +---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           |   6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |   6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c      |  44 +---
 drivers/staging/vboxvideo/vbox_drv.h          |   4 +-
 drivers/staging/vboxvideo/vbox_ttm.c          |  42 +---
 include/drm/drmP.h                            |   1 -
 include/drm/drm_global.h                      |  53 -----
 include/drm/ttm/ttm_bo_driver.h               |  40 ----
 include/drm/ttm/ttm_global.h                  | 100 +++++++++
 35 files changed, 401 insertions(+), 748 deletions(-)
 delete mode 100644 drivers/gpu/drm/drm_global.c
 create mode 100644 drivers/gpu/drm/ttm/ttm_global.c
 delete mode 100644 include/drm/drm_global.h
 create mode 100644 include/drm/ttm/ttm_global.h

--
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state
  2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
@ 2018-10-19  8:54 ` Thomas Zimmermann
       [not found]   ` <20181019085423.28159-2-tzimmermann-l3A5Bk7waGM@public.gmane.org>
  2018-10-19  8:54 ` [PATCH 03/18] drm/radeon: Replace TTM initialization/release with ttm_global Thomas Zimmermann
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

The new struct ttm_global provides drivers with TTM's global memory and
BO in a unified way. Initialization and release is handled internally.

The functionality provided by struct ttm_global is currently re-implemented
by a dozen individual DRM drivers using struct drm_global. The implementation
of struct ttm_global is also built on top of drm_global, so it can co-exists
with the existing drivers. Once all TTM-based drivers have been converted to
struct ttm_global, the implementation of struct drm_global can be made
private to TTM.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/ttm/Makefile     |  2 +-
 drivers/gpu/drm/ttm/ttm_global.c | 98 ++++++++++++++++++++++++++++++++
 include/drm/drm_global.h         |  8 +++
 include/drm/ttm/ttm_global.h     | 79 +++++++++++++++++++++++++
 4 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/ttm/ttm_global.c
 create mode 100644 include/drm/ttm/ttm_global.h

diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
index 01fc670ce7a2..b7272b26e9f3 100644
--- a/drivers/gpu/drm/ttm/Makefile
+++ b/drivers/gpu/drm/ttm/Makefile
@@ -5,7 +5,7 @@
 ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \
 	ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
 	ttm_execbuf_util.o ttm_page_alloc.o ttm_bo_manager.o \
-	ttm_page_alloc_dma.o
+	ttm_page_alloc_dma.o ttm_global.o
 ttm-$(CONFIG_AGP) += ttm_agp_backend.o
 
 obj-$(CONFIG_DRM_TTM) += ttm.o
diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
new file mode 100644
index 000000000000..ca9da0a46147
--- /dev/null
+++ b/drivers/gpu/drm/ttm/ttm_global.c
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+/**************************************************************************
+ *
+ * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include <drm/ttm/ttm_global.h>
+#include <drm/ttm/ttm_bo_driver.h>
+#include <drm/ttm/ttm_memory.h>
+#include <linux/kernel.h>
+
+static int ttm_global_init_mem(struct drm_global_reference *ref)
+{
+	BUG_ON(!ref->object);
+	return ttm_mem_global_init(ref->object);
+}
+
+static void ttm_global_release_mem(struct drm_global_reference *ref)
+{
+	BUG_ON(!ref->object);
+	ttm_mem_global_release(ref->object);
+}
+
+static int ttm_global_init_bo(struct drm_global_reference *ref)
+{
+	struct ttm_global *glob =
+		container_of(ref, struct ttm_global, bo_ref);
+	BUG_ON(!ref->object);
+	BUG_ON(!glob->mem_ref.object);
+	return ttm_bo_global_init(ref->object, glob->mem_ref.object);
+}
+
+static void ttm_global_release_bo(struct drm_global_reference *ref)
+{
+	BUG_ON(!ref->object);
+	ttm_bo_global_release(ref->object);
+}
+
+int ttm_global_init(struct ttm_global *glob)
+{
+	int ret;
+
+	glob->mem_ref.global_type = DRM_GLOBAL_TTM_MEM;
+	glob->mem_ref.size = sizeof(struct ttm_mem_global);
+	glob->bo_ref.object = NULL;
+	glob->mem_ref.init = &ttm_global_init_mem;
+	glob->mem_ref.release = &ttm_global_release_mem;
+	ret = drm_global_item_ref(&glob->mem_ref);
+	if (ret)
+		return ret;
+
+	glob->bo_ref.global_type = DRM_GLOBAL_TTM_BO;
+	glob->bo_ref.size = sizeof(struct ttm_bo_global);
+	glob->bo_ref.object = NULL;
+	glob->bo_ref.init = &ttm_global_init_bo;
+	glob->bo_ref.release = &ttm_global_release_bo;
+	ret = drm_global_item_ref(&glob->bo_ref);
+	if (ret)
+		goto err_drm_global_item_unref_mem;
+
+	return 0;
+
+err_drm_global_item_unref_mem:
+	drm_global_item_unref(&glob->mem_ref);
+	return ret;
+}
+
+EXPORT_SYMBOL(ttm_global_init);
+
+void ttm_global_release(struct ttm_global *glob)
+{
+	drm_global_item_unref(&glob->bo_ref);
+	drm_global_item_unref(&glob->mem_ref);
+}
+
+EXPORT_SYMBOL(ttm_global_release);
diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
index 3a830602a2e4..4482a9bbd6e9 100644
--- a/include/drm/drm_global.h
+++ b/include/drm/drm_global.h
@@ -28,8 +28,16 @@
  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  */
 
+/*
+ *  The interfaces in this file are deprecated. Please use ttm_global
+ *  from <drm/ttm/ttm_global.h> instead.
+ */
+
 #ifndef _DRM_GLOBAL_H_
 #define _DRM_GLOBAL_H_
+
+#include <linux/types.h>
+
 enum drm_global_types {
 	DRM_GLOBAL_TTM_MEM = 0,
 	DRM_GLOBAL_TTM_BO,
diff --git a/include/drm/ttm/ttm_global.h b/include/drm/ttm/ttm_global.h
new file mode 100644
index 000000000000..06e791499f87
--- /dev/null
+++ b/include/drm/ttm/ttm_global.h
@@ -0,0 +1,79 @@
+/**************************************************************************
+ *
+ * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _TTM_GLOBAL_H_
+#define _TTM_GLOBAL_H_
+
+#include <drm/drm_global.h>
+
+struct ttm_bo_global;
+
+/**
+ * struct ttm_global - Stores references to global TTM state
+ */
+struct ttm_global {
+	struct drm_global_reference mem_ref;
+	struct drm_global_reference bo_ref;
+};
+
+/**
+ * ttm_global_init
+ *
+ * @glob: A pointer to a struct ttm_global that is about to be initialized
+ * @return Zero on success, or a negative error code otherwise.
+ *
+ * Initializes an instance of struct ttm_global with TTM's global state
+ */
+int ttm_global_init(struct ttm_global *glob);
+
+/**
+ * ttm_global_release
+ *
+ * @glob: A pointer to an instance of struct ttm_global
+ *
+ * Releases an initialized instance of struct ttm_global. If the instance
+ * constains the final references to the global memory and BO, the global
+ * structures are released as well.
+ */
+void ttm_global_release(struct ttm_global *glob);
+
+/**
+ * ttm_global_get_bo_global
+ *
+ * @glob A pointer to an instance of struct ttm_global
+ * @return A refernce to the global BO.
+ *
+ * Returns the global BO. The BO should be forwarded to the initialization
+ * of a driver's TTM BO device.
+ */
+static inline struct ttm_bo_global*
+ttm_global_get_bo_global(struct ttm_global *glob)
+{
+	return glob->bo_ref.object;
+}
+
+#endif /* _TTM_GLOBAL_H_ */
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 02/18] drm/amdgpu: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 05/18] drm/bochs: " Thomas Zimmermann
                     ` (10 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Unified initialization and relesae 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/amd/amdgpu/amdgpu_ttm.c | 63 ++-----------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h |  4 +-
 2 files changed, 7 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 3a6802846698..70b0e8c77bb4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -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.
  *
@@ -102,35 +75,15 @@ static void amdgpu_ttm_mem_global_release(struct drm_global_reference *ref)
  */
 static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
 {
-	struct drm_global_reference *global_ref;
 	int r;
 
 	/* 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);
+	r = ttm_global_init(&adev->mman.glob);
 	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);
-	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) {
-		DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-		goto error_bo;
+		DRM_ERROR("Failed setting up TTM subsystem.\n");
+		return r;
 	}
 
 	mutex_init(&adev->mman.gtt_window_lock);
@@ -138,19 +91,13 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
 	adev->mman.mem_global_referenced = true;
 
 	return 0;
-
-error_bo:
-	drm_global_item_unref(&adev->mman.mem_global_ref);
-error_mem:
-	return r;
 }
 
 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);
+		ttm_global_release(&adev->mman.glob);
 		adev->mman.mem_global_referenced = false;
 	}
 }
@@ -1765,7 +1712,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	}
 	/* No others user of address space so set it to 0 */
 	r = ttm_bo_device_init(&adev->mman.bdev,
-			       adev->mman.bo_global_ref.ref.object,
+			       ttm_global_get_bo_global(&adev->mman.glob),
 			       &amdgpu_bo_driver,
 			       adev->ddev->anon_inode->i_mapping,
 			       DRM_FILE_PAGE_OFFSET,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index fe8f276e9811..c3a7fe3ead3a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -26,6 +26,7 @@
 
 #include "amdgpu.h"
 #include <drm/gpu_scheduler.h>
+#include <drm/ttm/ttm_global.h>
 
 #define AMDGPU_PL_GDS		(TTM_PL_PRIV + 0)
 #define AMDGPU_PL_GWS		(TTM_PL_PRIV + 1)
@@ -39,8 +40,7 @@
 #define AMDGPU_GTT_NUM_TRANSFER_WINDOWS	2
 
 struct amdgpu_mman {
-	struct ttm_bo_global_ref        bo_global_ref;
-	struct drm_global_reference	mem_global_ref;
+	struct ttm_global		glob;
 	struct ttm_bo_device		bdev;
 	bool				mem_global_referenced;
 	bool				initialized;
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 03/18] drm/radeon: Replace TTM initialization/release with ttm_global
  2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing " Thomas Zimmermann
@ 2018-10-19  8:54 ` Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 04/18] drm/ast: " Thomas Zimmermann
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

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/radeon/radeon.h     |  4 +--
 drivers/gpu/drm/radeon/radeon_ttm.c | 40 ++++-------------------------
 2 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 1a6f6edb3515..554c0421b779 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -73,6 +73,7 @@
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_module.h>
 #include <drm/ttm/ttm_execbuf_util.h>
+#include <drm/ttm/ttm_global.h>
 
 #include <drm/drm_gem.h>
 
@@ -448,8 +449,7 @@ struct radeon_surface_reg {
  * TTM.
  */
 struct radeon_mman {
-	struct ttm_bo_global_ref        bo_global_ref;
-	struct drm_global_reference	mem_global_ref;
+	struct ttm_global		glob;
 	struct ttm_bo_device		bdev;
 	bool				mem_global_referenced;
 	bool				initialized;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index dac4ec5a120b..363860e82892 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -64,45 +64,16 @@ 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);
-	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(&rdev->mman.mem_global_ref);
+	r = ttm_global_init(&rdev->mman.glob);
+	if (r) {
+		DRM_ERROR("Failed setting up TTM subsystem.\n");
 		return r;
 	}
 
@@ -113,8 +84,7 @@ static int radeon_ttm_global_init(struct radeon_device *rdev)
 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);
+		ttm_global_release(&rdev->mman.glob);
 		rdev->mman.mem_global_referenced = false;
 	}
 }
@@ -853,7 +823,7 @@ int radeon_ttm_init(struct radeon_device *rdev)
 	}
 	/* No others user of address space so set it to 0 */
 	r = ttm_bo_device_init(&rdev->mman.bdev,
-			       rdev->mman.bo_global_ref.ref.object,
+			       ttm_global_get_bo_global(&rdev->mman.glob),
 			       &radeon_bo_driver,
 			       rdev->ddev->anon_inode->i_mapping,
 			       DRM_FILE_PAGE_OFFSET,
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 04/18] drm/ast: Replace TTM initialization/release with ttm_global
  2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing " Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 03/18] drm/radeon: Replace TTM initialization/release with ttm_global Thomas Zimmermann
@ 2018-10-19  8:54 ` Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 07/18] drm/hisilicon: " Thomas Zimmermann
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

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/ast/ast_drv.h |  5 ++--
 drivers/gpu/drm/ast/ast_ttm.c | 49 ++++++-----------------------------
 2 files changed, 11 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index e6c4cd3dc50e..e0c9ee2b0e00 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -36,6 +36,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>
 
@@ -104,9 +105,9 @@ struct ast_private {
 	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;
 
 	struct drm_gem_object *cursor_cache;
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index d21fbd26785a..dad24f37a3ea 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -36,60 +36,27 @@ 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);
+	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
 ast_ttm_global_release(struct ast_private *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 ast_mm_init(struct ast_private *ast)
 		return ret;
 
 	ret = ttm_bo_device_init(&ast->ttm.bdev,
-				 ast->ttm.bo_global_ref.ref.object,
+				 ast->ttm.glob.bo_ref.object,
 				 &ast_bo_driver,
 				 dev->anon_inode->i_mapping,
 				 DRM_FILE_PAGE_OFFSET,
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 05/18] drm/bochs: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
  2018-10-19  8:54   ` [PATCH 02/18] drm/amdgpu: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 06/18] drm/cirrus: " Thomas Zimmermann
                     ` (9 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/bochs/bochs.h    |  5 ++--
 drivers/gpu/drm/bochs/bochs_mm.c | 47 +++++---------------------------
 2 files changed, 10 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
index e7a69077e45a..f73911ac1d77 100644
--- a/drivers/gpu/drm/bochs/bochs.h
+++ b/drivers/gpu/drm/bochs/bochs.h
@@ -12,6 +12,7 @@
 
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_page_alloc.h>
+#include <drm/ttm/ttm_global.h>
 
 /* ---------------------------------------------------------------------- */
 
@@ -76,9 +77,9 @@ struct bochs_device {
 
 	/* ttm */
 	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;
 		bool initialized;
 	} ttm;
 
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index ff4f41dec228..bdaab57bcd13 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -16,61 +16,28 @@ 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);
+	int r = ttm_global_init(&bochs->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;
 	}
 
-	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);
-	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(&bochs->ttm.mem_global_ref);
-		return r;
-	}
+	bochs->ttm.glob_initialized = true;
 
 	return 0;
 }
 
 static void bochs_ttm_global_release(struct bochs_device *bochs)
 {
-	if (bochs->ttm.mem_global_ref.release == NULL)
+	if (!bochs->ttm.glob_initialized)
 		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;
+	ttm_global_release(&bochs->ttm.glob);
+	bochs->ttm.glob_initialized = false;
 }
 
-
 static void bochs_bo_ttm_destroy(struct ttm_buffer_object *tbo)
 {
 	struct bochs_bo *bo;
@@ -213,7 +180,7 @@ int bochs_mm_init(struct bochs_device *bochs)
 		return ret;
 
 	ret = ttm_bo_device_init(&bochs->ttm.bdev,
-				 bochs->ttm.bo_global_ref.ref.object,
+				 bochs->ttm.glob.bo_ref.object,
 				 &bochs_bo_driver,
 				 bochs->dev->anon_inode->i_mapping,
 				 DRM_FILE_PAGE_OFFSET,
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 06/18] drm/cirrus: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
  2018-10-19  8:54   ` [PATCH 02/18] drm/amdgpu: " Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 05/18] drm/bochs: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 08/18] drm/mgag200: " Thomas Zimmermann
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/cirrus/cirrus_drv.h |  5 +--
 drivers/gpu/drm/cirrus/cirrus_ttm.c | 49 +++++------------------------
 2 files changed, 11 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h
index a29f87e98d9d..f62774cfb68e 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.h
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.h
@@ -21,6 +21,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>
 
@@ -136,9 +137,9 @@ struct cirrus_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;
 	bool mm_inited;
 };
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index 2e2141f26c5b..f1c5e6b8e80a 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -36,60 +36,27 @@ 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);
+	int r = ttm_global_init(&cirrus->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;
 	}
 
-	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);
-	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(&cirrus->ttm.mem_global_ref);
-		return r;
-	}
+	cirrus->ttm.glob_initialized = true;
+
 	return 0;
 }
 
 static void
 cirrus_ttm_global_release(struct cirrus_device *cirrus)
 {
-	if (cirrus->ttm.mem_global_ref.release == NULL)
+	if (!cirrus->ttm.glob_initialized)
 		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;
+	ttm_global_init(&cirrus->ttm.glob);
+	cirrus->ttm.glob_initialized = false;
 }
 
 
@@ -237,7 +204,7 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
 		return ret;
 
 	ret = ttm_bo_device_init(&cirrus->ttm.bdev,
-				 cirrus->ttm.bo_global_ref.ref.object,
+				 cirrus->ttm.glob.bo_ref.object,
 				 &cirrus_bo_driver,
 				 dev->anon_inode->i_mapping,
 				 DRM_FILE_PAGE_OFFSET,
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 07/18] drm/hisilicon: Replace TTM initialization/release with ttm_global
  2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
                   ` (2 preceding siblings ...)
  2018-10-19  8:54 ` [PATCH 04/18] drm/ast: " Thomas Zimmermann
@ 2018-10-19  8:54 ` Thomas Zimmermann
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

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>
---
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  4 +--
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c   | 36 ++-----------------
 2 files changed, 5 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index 45c25a488f42..1091f3bb81c4 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -24,6 +24,7 @@
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_gem.h>
 #include <drm/ttm/ttm_bo_driver.h>
+#include <drm/ttm/ttm_global.h>
 
 struct hibmc_framebuffer {
 	struct drm_framebuffer fb;
@@ -49,8 +50,7 @@ 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_global glob;
 	struct ttm_bo_device bdev;
 	bool initialized;
 
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
index 0454aa43ffc6..4f51ac5d8340 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
@@ -29,53 +29,23 @@ 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);
+	ret = ttm_global_init(&hibmc->glob);
 	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;
-	hibmc->bo_global_ref.ref.release = &ttm_bo_global_ref_release;
-	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;
 }
 
 static void
 hibmc_ttm_global_release(struct hibmc_drm_private *hibmc)
 {
-	drm_global_item_unref(&hibmc->bo_global_ref.ref);
-	drm_global_item_unref(&hibmc->mem_global_ref);
-	hibmc->mem_global_ref.release = NULL;
+	ttm_global_release(&hibmc->glob);
 }
 
 static void hibmc_bo_ttm_destroy(struct ttm_buffer_object *tbo)
@@ -242,7 +212,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
 		return ret;
 
 	ret = ttm_bo_device_init(&hibmc->bdev,
-				 hibmc->bo_global_ref.ref.object,
+				 hibmc->glob.bo_ref.object,
 				 &hibmc_bo_driver,
 				 dev->anon_inode->i_mapping,
 				 DRM_FILE_PAGE_OFFSET,
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 08/18] drm/mgag200: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (2 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 06/18] drm/cirrus: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 09/18] drm/nouveau: " Thomas Zimmermann
                     ` (7 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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(-)

diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h
index 04f1dfba12e5..f82c1034b2ea 100644
--- a/drivers/gpu/drm/mgag200/mgag200_drv.h
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.h
@@ -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 */
diff --git a/drivers/gpu/drm/mgag200/mgag200_ttm.c b/drivers/gpu/drm/mgag200/mgag200_ttm.c
index 3444b539e7f4..52407000eb50 100644
--- a/drivers/gpu/drm/mgag200/mgag200_ttm.c
+++ b/drivers/gpu/drm/mgag200/mgag200_ttm.c
@@ -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,
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 09/18] drm/nouveau: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (3 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 08/18] drm/mgag200: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 10/18] drm/qlx: " Thomas Zimmermann
                     ` (6 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/nouveau/nouveau_drv.h |  5 +--
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 48 ++++-----------------------
 2 files changed, 9 insertions(+), 44 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index 0b2191fa96f7..0d5a78f4ad75 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -54,6 +54,7 @@
 #include <drm/ttm/ttm_memory.h>
 #include <drm/ttm/ttm_module.h>
 #include <drm/ttm/ttm_page_alloc.h>
+#include <drm/ttm/ttm_global.h>
 
 #include "uapi/drm/nouveau_drm.h"
 
@@ -146,9 +147,9 @@ struct nouveau_drm {
 
 	/* TTM interface support */
 	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;
 		atomic_t validate_sequence;
 		int (*move)(struct nouveau_channel *,
 			    struct ttm_buffer_object *,
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index a293383c8654..f2bd707ad7b1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -174,51 +174,16 @@ 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);
+	int ret = ttm_global_init(&drm->ttm.glob);
 	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);
-	global_ref->init = &ttm_bo_global_ref_init;
-	global_ref->release = &ttm_bo_global_ref_release;
-
-	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;
-		return ret;
-	}
+	drm->ttm.glob_initialized = true;
 
 	return 0;
 }
@@ -226,12 +191,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.glob_initialized)
 		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;
+	ttm_global_release(&drm->ttm.glob);
+	drm->ttm.glob_initialized = false;
 }
 
 static int
@@ -301,7 +265,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
 		return ret;
 
 	ret = ttm_bo_device_init(&drm->ttm.bdev,
-				  drm->ttm.bo_global_ref.ref.object,
+				  drm->ttm.glob.bo_ref.object,
 				  &nouveau_bo_driver,
 				  dev->anon_inode->i_mapping,
 				  DRM_FILE_PAGE_OFFSET,
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 10/18] drm/qlx: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (4 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 09/18] drm/nouveau: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 11/18] drm/virtio: " Thomas Zimmermann
                     ` (5 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/qxl/qxl_drv.h |  4 ++--
 drivers/gpu/drm/qxl/qxl_ttm.c | 40 ++++-------------------------------
 2 files changed, 6 insertions(+), 38 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
index 8ff70a7281a7..64232a2684fd 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.h
+++ b/drivers/gpu/drm/qxl/qxl_drv.h
@@ -47,6 +47,7 @@
 #include <drm/ttm/ttm_execbuf_util.h>
 #include <drm/ttm/ttm_module.h>
 #include <drm/ttm/ttm_placement.h>
+#include <drm/ttm/ttm_global.h>
 #include <drm/qxl_drm.h>
 
 #include "qxl_dev.h"
@@ -127,9 +128,8 @@ struct qxl_output {
 #define drm_encoder_to_qxl_output(x) container_of(x, struct qxl_output, enc)
 
 struct qxl_mman {
-	struct ttm_bo_global_ref        bo_global_ref;
-	struct drm_global_reference	mem_global_ref;
 	bool				mem_global_referenced;
+	struct ttm_global		glob;
 	struct ttm_bo_device		bdev;
 };
 
diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index db2a0036e9c4..2e852fac97d3 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -46,46 +46,15 @@ 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);
-	global_ref->init = &ttm_bo_global_ref_init;
-	global_ref->release = &ttm_bo_global_ref_release;
-	r = drm_global_item_ref(global_ref);
+	r = ttm_global_init(&qdev->mman.glob);
 	if (r != 0) {
-		DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-		drm_global_item_unref(&qdev->mman.mem_global_ref);
+		DRM_ERROR("Failed setting up TTM subsystem.\n");
 		return r;
 	}
 
@@ -96,8 +65,7 @@ static int qxl_ttm_global_init(struct qxl_device *qdev)
 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);
+		ttm_global_release(&qdev->mman.glob);
 		qdev->mman.mem_global_referenced = false;
 	}
 }
@@ -378,7 +346,7 @@ int qxl_ttm_init(struct qxl_device *qdev)
 		return r;
 	/* No others user of address space so set it to 0 */
 	r = ttm_bo_device_init(&qdev->mman.bdev,
-			       qdev->mman.bo_global_ref.ref.object,
+			       qdev->mman.glob.bo_ref.object,
 			       &qxl_bo_driver,
 			       qdev->ddev.anon_inode->i_mapping,
 			       DRM_FILE_PAGE_OFFSET, 0);
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 11/18] drm/virtio: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (5 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 10/18] drm/qlx: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 12/18] drm/vmwgfx: " Thomas Zimmermann
                     ` (4 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/virtio/virtgpu_drv.h |  4 +--
 drivers/gpu/drm/virtio/virtgpu_ttm.c | 40 +++-------------------------
 2 files changed, 6 insertions(+), 38 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
index d29f0c7c768c..502e4d531df7 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -41,6 +41,7 @@
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_module.h>
+#include <drm/ttm/ttm_global.h>
 
 #define DRIVER_NAME "virtio_gpu"
 #define DRIVER_DESC "virtio GPU"
@@ -142,9 +143,8 @@ 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_global		glob;
 	struct ttm_bo_device		bdev;
 };
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_ttm.c b/drivers/gpu/drm/virtio/virtgpu_ttm.c
index 526a5e48dc3b..113491cc6595 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ttm.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ttm.c
@@ -50,46 +50,15 @@ 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);
-	global_ref->init = &ttm_bo_global_ref_init;
-	global_ref->release = &ttm_bo_global_ref_release;
-	r = drm_global_item_ref(global_ref);
+	r = ttm_global_init(&vgdev->mman.glob);
 	if (r != 0) {
-		DRM_ERROR("Failed setting up TTM BO subsystem.\n");
-		drm_global_item_unref(&vgdev->mman.mem_global_ref);
+		DRM_ERROR("Failed setting up TTM subsystem.\n");
 		return r;
 	}
 
@@ -100,8 +69,7 @@ static int virtio_gpu_ttm_global_init(struct virtio_gpu_device *vgdev)
 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);
+		ttm_global_release(&vgdev->mman.glob);
 		vgdev->mman.mem_global_referenced = false;
 	}
 }
@@ -388,7 +356,7 @@ int virtio_gpu_ttm_init(struct virtio_gpu_device *vgdev)
 		return r;
 	/* No others user of address space so set it to 0 */
 	r = ttm_bo_device_init(&vgdev->mman.bdev,
-			       vgdev->mman.bo_global_ref.ref.object,
+			       vgdev->mman.glob.bo_ref.object,
 			       &virtio_gpu_bo_driver,
 			       vgdev->ddev->anon_inode->i_mapping,
 			       DRM_FILE_PAGE_OFFSET, 0);
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 12/18] drm/vmwgfx: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (6 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 11/18] drm/virtio: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 13/18] staging/vboxvideo: " Thomas Zimmermann
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/vmwgfx/vmwgfx_drv.c      |  6 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h      |  6 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 44 ++----------------------
 3 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 61a84b958d67..85b58e0c25fa 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -829,7 +829,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 	}
 
 	dev_priv->tdev = ttm_object_device_init
-		(dev_priv->mem_global_ref.object, 12, &vmw_prime_dmabuf_ops);
+		(dev_priv->glob.mem_ref.object, 12, &vmw_prime_dmabuf_ops);
 
 	if (unlikely(dev_priv->tdev == NULL)) {
 		DRM_ERROR("Unable to initialize TTM object management.\n");
@@ -870,7 +870,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 	}
 
 	ret = ttm_bo_device_init(&dev_priv->bdev,
-				 dev_priv->bo_global_ref.ref.object,
+				 dev_priv->glob.bo_ref.object,
 				 &vmw_bo_driver,
 				 dev->anon_inode->i_mapping,
 				 VMWGFX_FILE_PAGE_OFFSET,
@@ -1530,7 +1530,7 @@ static int vmw_pm_freeze(struct device *kdev)
 
 	vmw_fence_fifo_down(dev_priv->fman);
 	__vmw_svga_disable(dev_priv);
-	
+
 	vmw_release_device_late(dev_priv);
 	return 0;
 }
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 59f614225bcd..ae724c756bf0 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -38,6 +38,7 @@
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_execbuf_util.h>
 #include <drm/ttm/ttm_module.h>
+#include <drm/ttm/ttm_global.h>
 #include "vmwgfx_fence.h"
 #include "ttm_object.h"
 #include "ttm_lock.h"
@@ -417,8 +418,7 @@ 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 ttm_global glob;
 
 	struct vmw_fifo_state fifo;
 
@@ -1363,7 +1363,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 (struct ttm_mem_global *) dev_priv->glob.mem_ref.object;
 }
 
 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
index f3ce43c41978..2125a0e3f431 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c
@@ -43,56 +43,18 @@ 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);
+	int ret = ttm_global_init(&dev_priv->glob);
 	if (unlikely(ret != 0)) {
-		DRM_ERROR("Failed setting up TTM memory accounting.\n");
+		DRM_ERROR("Failed setting up TTM.\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);
-	global_ref->init = &ttm_bo_global_ref_init;
-	global_ref->release = &ttm_bo_global_ref_release;
-	ret = drm_global_item_ref(global_ref);
-
-	if (unlikely(ret != 0)) {
-		DRM_ERROR("Failed setting up TTM buffer objects.\n");
-		goto out_no_bo;
-	}
-
 	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);
+	ttm_global_release(&dev_priv->glob);
 }
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 13/18] staging/vboxvideo: Replace TTM initialization/release with ttm_global
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (7 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 12/18] drm/vmwgfx: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 15/18] drm: Remove DRM_GLOBAL_TTM_OBJECT Thomas Zimmermann
                     ` (2 subsequent siblings)
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

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/staging/vboxvideo/vbox_drv.h |  4 +--
 drivers/staging/vboxvideo/vbox_ttm.c | 42 +++-------------------------
 2 files changed, 6 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h
index 594f84272957..21cca25d00f5 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -45,6 +45,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 "vboxvideo_guest.h"
 #include "vboxvideo_vbe.h"
@@ -95,8 +96,7 @@ struct vbox_private {
 	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;
 	} ttm;
 
diff --git a/drivers/staging/vboxvideo/vbox_ttm.c b/drivers/staging/vboxvideo/vbox_ttm.c
index 2329a55d4636..4c2c75daf94c 100644
--- a/drivers/staging/vboxvideo/vbox_ttm.c
+++ b/drivers/staging/vboxvideo/vbox_ttm.c
@@ -35,49 +35,16 @@ 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.
  */
 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);
+	int ret = ttm_global_init(&vbox->ttm.glob);
 	if (ret) {
-		DRM_ERROR("Failed setting up TTM memory subsystem.\n");
+		DRM_ERROR("Failed setting up TTM 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);
-	global_ref->init = &ttm_bo_global_ref_init;
-	global_ref->release = &ttm_bo_global_ref_release;
-
-	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;
-	}
-
 	return 0;
 }
 
@@ -86,8 +53,7 @@ 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);
+	ttm_global_release(&vbox->ttm.glob);
 }
 
 static void vbox_bo_ttm_destroy(struct ttm_buffer_object *tbo)
@@ -232,7 +198,7 @@ int vbox_mm_init(struct vbox_private *vbox)
 		return ret;
 
 	ret = ttm_bo_device_init(&vbox->ttm.bdev,
-				 vbox->ttm.bo_global_ref.ref.object,
+				 vbox->ttm.glob.bo_ref.object,
 				 &vbox_bo_driver,
 				 dev->anon_inode->i_mapping,
 				 DRM_FILE_PAGE_OFFSET, true);
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 14/18] drm/ttm: Remove struct ttm_bo_global_ref and helpers
  2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
                   ` (4 preceding siblings ...)
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
@ 2018-10-19  8:54 ` Thomas Zimmermann
  2018-10-19  8:54 ` [PATCH 17/18] drm/ttm: Implement struct ttm_global with struct ttm_global_ref Thomas Zimmermann
  6 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

The struct ttm_bo_global_ref data type providede a workaround for passing
an instance of struct ttm_mem_global to ttm_bo_global_init().

This functionality has been replaced by struct ttm_global and all drivers
have been converted. struct ttm_bo_global_ref is obsolete.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 include/drm/ttm/ttm_bo_driver.h | 40 ---------------------------------
 1 file changed, 40 deletions(-)

diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index c6ee07d10281..e51ced5f5e75 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -31,7 +31,6 @@
 #define _TTM_BO_DRIVER_H_
 
 #include <drm/drm_mm.h>
-#include <drm/drm_global.h>
 #include <drm/drm_vma_manager.h>
 #include <linux/workqueue.h>
 #include <linux/fs.h>
@@ -889,43 +888,4 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 
 extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
-/**
- * struct ttm_bo_global_ref - Argument to initialize a struct ttm_bo_global.
- */
-
-struct ttm_bo_global_ref {
-	struct drm_global_reference ref;
-	struct ttm_mem_global *mem_glob;
-};
-
-/**
- * ttm_bo_global_ref_init
- *
- * @ref: DRM global reference
- *
- * Helper function that initializes a struct ttm_bo_global. This function
- * is used as init call-back function for DRM global references of type
- * DRM_GLOBAL_TTM_BO_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);
-}
-
-/**
- * ttm_bo_global_ref_release
- *
- * @ref: DRM global reference
- *
- * Helper function that releases a struct ttm_bo_global. This function
- * is used as release call-back function for DRM global references of type
- * DRM_GLOBAL_TTM_BO_REF.
- */
-static inline void ttm_bo_global_ref_release(struct drm_global_reference *ref)
-{
-	ttm_bo_global_release(ref->object);
-}
-
 #endif
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 15/18] drm: Remove DRM_GLOBAL_TTM_OBJECT
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (8 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 13/18] staging/vboxvideo: " Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 16/18] drm/ttm: Implement struct ttm_global_item and helpers Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 18/18] drm: Remove drm_global.{c,h} Thomas Zimmermann
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

The constant DRM_GLOBAL_TTM_OBJECT is unused and not obviously useful.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 include/drm/drm_global.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
index 4482a9bbd6e9..63ffdcec6690 100644
--- a/include/drm/drm_global.h
+++ b/include/drm/drm_global.h
@@ -41,7 +41,6 @@
 enum drm_global_types {
 	DRM_GLOBAL_TTM_MEM = 0,
 	DRM_GLOBAL_TTM_BO,
-	DRM_GLOBAL_TTM_OBJECT,
 	DRM_GLOBAL_NUM
 };
 
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 16/18] drm/ttm: Implement struct ttm_global_item and helpers
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (9 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 15/18] drm: Remove DRM_GLOBAL_TTM_OBJECT Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  2018-10-19  8:54   ` [PATCH 18/18] drm: Remove drm_global.{c,h} Thomas Zimmermann
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

The data structure struct ttm_global_item is a replacement for struct
drm_global_item. While struct drm_global_item depends on global data
instances, struct ttm_global_item allows drivers to use their own privat
instances.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/ttm/ttm_global.c | 98 ++++++++++++++++++++++++++++++++
 include/drm/ttm/ttm_global.h     | 22 +++++++
 2 files changed, 120 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
index ca9da0a46147..1e5c2f5eeca0 100644
--- a/drivers/gpu/drm/ttm/ttm_global.c
+++ b/drivers/gpu/drm/ttm/ttm_global.c
@@ -31,6 +31,104 @@
 #include <drm/ttm/ttm_memory.h>
 #include <linux/kernel.h>
 
+/*
+ * struct ttm_global_item
+ */
+
+struct ttm_global_item {
+	struct mutex mutex;
+	void *object;
+	int refcount;
+};
+
+#define TTM_GLOBAL_ITEM_INIT(name_) { \
+	.mutex = __MUTEX_INITIALIZER(name_.mutex), \
+	.object = NULL, \
+	.refcount = 0 }
+
+#define DEFINE_TTM_GLOBAL_ITEM_ARRAY(name_) \
+	struct ttm_global_item name_[TTM_NUM_GLOBAL_TYPES] = { \
+		[0] = TTM_GLOBAL_ITEM_INIT(name_[0]), \
+		[1] = TTM_GLOBAL_ITEM_INIT(name_[0]) \
+	}
+
+/**
+ * ttm_global_item_ref - Initialize and acquire reference to a global TTM item
+ *
+ * @items: Array of global TTM items
+ * @ref: Object for initialization
+ * @return Zero on success, or a negative error code otherwise.
+ *
+ * This initializes a TTM item by allocating memory and calling the
+ * .init() hook. Further calls will increase the reference count for
+ * that item.
+ */
+static int ttm_global_item_ref(
+	struct ttm_global_item items[TTM_NUM_GLOBAL_TYPES],
+	struct ttm_global_ref *ref)
+{
+	struct ttm_global_item *item = &items[ref->global_type];
+	int ret = 0;
+
+	mutex_lock(&item->mutex);
+	if (item->refcount == 0) {
+		ref->object = kzalloc(ref->size, GFP_KERNEL);
+		if (unlikely(ref->object == NULL)) {
+			ret = -ENOMEM;
+			goto error_mutex_unlock;
+		}
+		ret = ref->init(ref);
+		if (unlikely(ret != 0))
+			goto error_kfree;
+
+		item->object = ref->object;
+	} else {
+		ref->object = item->object;
+	}
+
+	++item->refcount;
+	mutex_unlock(&item->mutex);
+
+	return 0;
+
+error_kfree:
+	kfree(ref->object);
+	ref->object = NULL;
+error_mutex_unlock:
+	mutex_unlock(&item->mutex);
+	return ret;
+}
+
+/**
+ * ttm_global_item_unref - Drop reference to global TTM item
+ *
+ * @items: Array of global TTM items
+ * @ref: Object being removed
+ *
+ * Drops a reference to the global TTM item and eventually call the
+ * release() hook. The allocated object should be dropped in the
+ * release() hook or before calling this function
+ */
+static void ttm_global_item_unref(
+	struct ttm_global_item items[TTM_NUM_GLOBAL_TYPES],
+	struct ttm_global_ref *ref)
+{
+	struct ttm_global_item *item = &items[ref->global_type];
+
+	mutex_lock(&item->mutex);
+	BUG_ON(item->refcount == 0);
+	BUG_ON(ref->object != item->object);
+	if (--item->refcount == 0) {
+		ref->release(ref);
+		item->object = NULL;
+	}
+	mutex_unlock(&item->mutex);
+}
+
+/*
+ * struct ttm_global
+ */
+
 static int ttm_global_init_mem(struct drm_global_reference *ref)
 {
 	BUG_ON(!ref->object);
diff --git a/include/drm/ttm/ttm_global.h b/include/drm/ttm/ttm_global.h
index 06e791499f87..9aa0ddbbe2ef 100644
--- a/include/drm/ttm/ttm_global.h
+++ b/include/drm/ttm/ttm_global.h
@@ -29,6 +29,28 @@
 #define _TTM_GLOBAL_H_
 
 #include <drm/drm_global.h>
+#include <linux/mutex.h>
+#include <linux/types.h>
+
+/**
+ * enum ttm_global_types - Enumerates types of global TTM state
+ */
+enum ttm_global_types {
+	TTM_GLOBAL_MEM = 0,
+	TTM_GLOBAL_BO,
+	TTM_NUM_GLOBAL_TYPES
+};
+
+/**
+ * struct ttm_global_ref - References global TTM item
+ */
+struct ttm_global_ref {
+	enum ttm_global_types global_type;
+	size_t size;
+	void *object;
+	int (*init) (struct ttm_global_ref *);
+	void (*release) (struct ttm_global_ref *);
+};
 
 struct ttm_bo_global;
 
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 17/18] drm/ttm: Implement struct ttm_global with struct ttm_global_ref
  2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
                   ` (5 preceding siblings ...)
  2018-10-19  8:54 ` [PATCH 14/18] drm/ttm: Remove struct ttm_bo_global_ref and helpers Thomas Zimmermann
@ 2018-10-19  8:54 ` Thomas Zimmermann
  6 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: Thomas Zimmermann, amd-gfx, dri-devel

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/ttm/ttm_global.c | 28 +++++++++++++++-------------
 include/drm/ttm/ttm_global.h     |  5 ++---
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
index 1e5c2f5eeca0..93d268daf97b 100644
--- a/drivers/gpu/drm/ttm/ttm_global.c
+++ b/drivers/gpu/drm/ttm/ttm_global.c
@@ -129,19 +129,21 @@ static void ttm_global_item_unref(
  * struct ttm_global
  */
 
-static int ttm_global_init_mem(struct drm_global_reference *ref)
+static DEFINE_TTM_GLOBAL_ITEM_ARRAY(global_items);
+
+static int ttm_global_init_mem(struct ttm_global_ref *ref)
 {
 	BUG_ON(!ref->object);
 	return ttm_mem_global_init(ref->object);
 }
 
-static void ttm_global_release_mem(struct drm_global_reference *ref)
+static void ttm_global_release_mem(struct ttm_global_ref *ref)
 {
 	BUG_ON(!ref->object);
 	ttm_mem_global_release(ref->object);
 }
 
-static int ttm_global_init_bo(struct drm_global_reference *ref)
+static int ttm_global_init_bo(struct ttm_global_ref *ref)
 {
 	struct ttm_global *glob =
 		container_of(ref, struct ttm_global, bo_ref);
@@ -150,7 +152,7 @@ static int ttm_global_init_bo(struct drm_global_reference *ref)
 	return ttm_bo_global_init(ref->object, glob->mem_ref.object);
 }
 
-static void ttm_global_release_bo(struct drm_global_reference *ref)
+static void ttm_global_release_bo(struct ttm_global_ref *ref)
 {
 	BUG_ON(!ref->object);
 	ttm_bo_global_release(ref->object);
@@ -160,28 +162,28 @@ int ttm_global_init(struct ttm_global *glob)
 {
 	int ret;
 
-	glob->mem_ref.global_type = DRM_GLOBAL_TTM_MEM;
+	glob->mem_ref.global_type = TTM_GLOBAL_MEM;
 	glob->mem_ref.size = sizeof(struct ttm_mem_global);
 	glob->bo_ref.object = NULL;
 	glob->mem_ref.init = &ttm_global_init_mem;
 	glob->mem_ref.release = &ttm_global_release_mem;
-	ret = drm_global_item_ref(&glob->mem_ref);
+	ret = ttm_global_item_ref(global_items, &glob->mem_ref);
 	if (ret)
 		return ret;
 
-	glob->bo_ref.global_type = DRM_GLOBAL_TTM_BO;
+	glob->bo_ref.global_type = TTM_GLOBAL_BO;
 	glob->bo_ref.size = sizeof(struct ttm_bo_global);
 	glob->bo_ref.object = NULL;
 	glob->bo_ref.init = &ttm_global_init_bo;
 	glob->bo_ref.release = &ttm_global_release_bo;
-	ret = drm_global_item_ref(&glob->bo_ref);
+	ret = ttm_global_item_ref(global_items, &glob->bo_ref);
 	if (ret)
-		goto err_drm_global_item_unref_mem;
+		goto err_ttm_global_item_unref;
 
 	return 0;
 
-err_drm_global_item_unref_mem:
-	drm_global_item_unref(&glob->mem_ref);
+err_ttm_global_item_unref:
+	ttm_global_item_unref(global_items, &glob->mem_ref);
 	return ret;
 }
 
@@ -189,8 +191,8 @@ EXPORT_SYMBOL(ttm_global_init);
 
 void ttm_global_release(struct ttm_global *glob)
 {
-	drm_global_item_unref(&glob->bo_ref);
-	drm_global_item_unref(&glob->mem_ref);
+	ttm_global_item_unref(global_items, &glob->bo_ref);
+	ttm_global_item_unref(global_items, &glob->mem_ref);
 }
 
 EXPORT_SYMBOL(ttm_global_release);
diff --git a/include/drm/ttm/ttm_global.h b/include/drm/ttm/ttm_global.h
index 9aa0ddbbe2ef..8dedac053611 100644
--- a/include/drm/ttm/ttm_global.h
+++ b/include/drm/ttm/ttm_global.h
@@ -28,7 +28,6 @@
 #ifndef _TTM_GLOBAL_H_
 #define _TTM_GLOBAL_H_
 
-#include <drm/drm_global.h>
 #include <linux/mutex.h>
 #include <linux/types.h>
 
@@ -58,8 +57,8 @@ struct ttm_bo_global;
  * struct ttm_global - Stores references to global TTM state
  */
 struct ttm_global {
-	struct drm_global_reference mem_ref;
-	struct drm_global_reference bo_ref;
+	struct ttm_global_ref mem_ref;
+	struct ttm_global_ref bo_ref;
 };
 
 /**
-- 
2.19.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 18/18] drm: Remove drm_global.{c,h}
       [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
                     ` (10 preceding siblings ...)
  2018-10-19  8:54   ` [PATCH 16/18] drm/ttm: Implement struct ttm_global_item and helpers Thomas Zimmermann
@ 2018-10-19  8:54   ` Thomas Zimmermann
  11 siblings, 0 replies; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  8:54 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, ray.huang-5C7GfCeVMHo,
	Jerry.Zhang-5C7GfCeVMHo, alexander.deucher-5C7GfCeVMHo,
	David1.Zhou-5C7GfCeVMHo, airlied-cv59FeDIM0c,
	kraxel-H+wXaHxf7aLQT0dZR+AlfA, bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: Thomas Zimmermann, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

The content of drm_global.{c,h} is obsolete. The functionality is provided
in ttm_global.{c,h}.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/Makefile         |   2 +-
 drivers/gpu/drm/drm_drv.c        |   2 -
 drivers/gpu/drm/drm_global.c     | 137 -------------------------------
 drivers/gpu/drm/gma500/psb_drv.h |   4 +-
 include/drm/drmP.h               |   1 -
 include/drm/drm_global.h         |  60 --------------
 6 files changed, 3 insertions(+), 203 deletions(-)
 delete mode 100644 drivers/gpu/drm/drm_global.c
 delete mode 100644 include/drm/drm_global.h

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 576ba985e138..7f3be3506057 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -11,7 +11,7 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
 		drm_sysfs.o drm_hashtab.o drm_mm.o \
 		drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
 		drm_info.o drm_encoder_slave.o \
-		drm_trace_points.o drm_global.o drm_prime.o \
+		drm_trace_points.o drm_prime.o \
 		drm_rect.o drm_vma_manager.o drm_flip_work.o \
 		drm_modeset_lock.o drm_atomic.o drm_bridge.o \
 		drm_framebuffer.o drm_connector.o drm_blend.o \
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 36e8e9cbec52..fc29f46b7c32 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -975,14 +975,12 @@ static void drm_core_exit(void)
 	drm_sysfs_destroy();
 	idr_destroy(&drm_minors_idr);
 	drm_connector_ida_destroy();
-	drm_global_release();
 }
 
 static int __init drm_core_init(void)
 {
 	int ret;
 
-	drm_global_init();
 	drm_connector_ida_init();
 	idr_init(&drm_minors_idr);
 
diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
deleted file mode 100644
index 5799e2782dd1..000000000000
--- a/drivers/gpu/drm/drm_global.c
+++ /dev/null
@@ -1,137 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR MIT
-/**************************************************************************
- *
- * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
- */
-
-#include <linux/mutex.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <drm/drm_global.h>
-
-struct drm_global_item {
-	struct mutex mutex;
-	void *object;
-	int refcount;
-};
-
-static struct drm_global_item glob[DRM_GLOBAL_NUM];
-
-void drm_global_init(void)
-{
-	int i;
-
-	for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
-		struct drm_global_item *item = &glob[i];
-		mutex_init(&item->mutex);
-		item->object = NULL;
-		item->refcount = 0;
-	}
-}
-
-void drm_global_release(void)
-{
-	int i;
-	for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
-		struct drm_global_item *item = &glob[i];
-		BUG_ON(item->object != NULL);
-		BUG_ON(item->refcount != 0);
-	}
-}
-
-/**
- * drm_global_item_ref - Initialize and acquire reference to memory
- * object
- * @ref: Object for initialization
- *
- * This initializes a memory object, allocating memory and calling the
- * .init() hook. Further calls will increase the reference count for
- * that item.
- *
- * Returns:
- * Zero on success, non-zero otherwise.
- */
-int drm_global_item_ref(struct drm_global_reference *ref)
-{
-	int ret = 0;
-	struct drm_global_item *item = &glob[ref->global_type];
-
-	mutex_lock(&item->mutex);
-	if (item->refcount == 0) {
-		ref->object = kzalloc(ref->size, GFP_KERNEL);
-		if (unlikely(ref->object == NULL)) {
-			ret = -ENOMEM;
-			goto error_unlock;
-		}
-		ret = ref->init(ref);
-		if (unlikely(ret != 0))
-			goto error_free;
-
-		item->object = ref->object;
-	} else {
-		ref->object = item->object;
-	}
-
-	++item->refcount;
-	mutex_unlock(&item->mutex);
-	return 0;
-
-error_free:
-	kfree(ref->object);
-	ref->object = NULL;
-error_unlock:
-	mutex_unlock(&item->mutex);
-	return ret;
-}
-EXPORT_SYMBOL(drm_global_item_ref);
-
-/**
- * drm_global_item_unref - Drop reference to memory
- * object
- * @ref: Object being removed
- *
- * Drop a reference to the memory object and eventually call the
- * release() hook.  The allocated object should be dropped in the
- * release() hook or before calling this function
- *
- */
-
-void drm_global_item_unref(struct drm_global_reference *ref)
-{
-	struct drm_global_item *item = &glob[ref->global_type];
-
-	mutex_lock(&item->mutex);
-	BUG_ON(item->refcount == 0);
-	BUG_ON(ref->object != item->object);
-	if (--item->refcount == 0) {
-		ref->release(ref);
-		item->object = NULL;
-	}
-	mutex_unlock(&item->mutex);
-}
-EXPORT_SYMBOL(drm_global_item_unref);
-
diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
index 941b238bdcc9..c4f084fdf630 100644
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -444,7 +444,7 @@ struct drm_psb_private {
 	struct pci_dev *lpc_pdev; /* Currently only used by mrst */
 	const struct psb_ops *ops;
 	const struct psb_offset *regmap;
-	
+
 	struct child_device_config *child_dev;
 	int child_dev_num;
 
@@ -551,7 +551,7 @@ struct drm_psb_private {
 
 	/* Oaktrail HDMI state */
 	struct oaktrail_hdmi_dev *hdmi_priv;
-	
+
 	/* Register state */
 	struct psb_save_area regs;
 
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 05350424a4d3..2557001d1b21 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -68,7 +68,6 @@
 #include <drm/drm_agpsupport.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_fourcc.h>
-#include <drm/drm_global.h>
 #include <drm/drm_hashtab.h>
 #include <drm/drm_mm.h>
 #include <drm/drm_os_linux.h>
diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
deleted file mode 100644
index 63ffdcec6690..000000000000
--- a/include/drm/drm_global.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-/*
- * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
- */
-
-/*
- *  The interfaces in this file are deprecated. Please use ttm_global
- *  from <drm/ttm/ttm_global.h> instead.
- */
-
-#ifndef _DRM_GLOBAL_H_
-#define _DRM_GLOBAL_H_
-
-#include <linux/types.h>
-
-enum drm_global_types {
-	DRM_GLOBAL_TTM_MEM = 0,
-	DRM_GLOBAL_TTM_BO,
-	DRM_GLOBAL_NUM
-};
-
-struct drm_global_reference {
-	enum drm_global_types global_type;
-	size_t size;
-	void *object;
-	int (*init) (struct drm_global_reference *);
-	void (*release) (struct drm_global_reference *);
-};
-
-void drm_global_init(void);
-void drm_global_release(void);
-int drm_global_item_ref(struct drm_global_reference *ref);
-void drm_global_item_unref(struct drm_global_reference *ref);
-
-#endif
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state
       [not found]   ` <20181019085423.28159-2-tzimmermann-l3A5Bk7waGM@public.gmane.org>
@ 2018-10-19  9:30     ` Christian König
  2018-10-19  9:41       ` Thomas Zimmermann
  0 siblings, 1 reply; 22+ messages in thread
From: Christian König @ 2018-10-19  9:30 UTC (permalink / raw)
  To: Thomas Zimmermann, christian.koenig-5C7GfCeVMHo,
	ray.huang-5C7GfCeVMHo, Jerry.Zhang-5C7GfCeVMHo,
	alexander.deucher-5C7GfCeVMHo, David1.Zhou-5C7GfCeVMHo,
	airlied-cv59FeDIM0c, kraxel-H+wXaHxf7aLQT0dZR+AlfA,
	bskeggs-H+wXaHxf7aLQT0dZR+AlfA, syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

In general I'm really graceful that you look into this, but you are just 
moving the complexity around instead of cleaning it up.

This whole global reference stuff is just going into the wrong direction.

Please let me clean that up instead,
Christian.

Am 19.10.18 um 10:54 schrieb Thomas Zimmermann:
> The new struct ttm_global provides drivers with TTM's global memory and
> BO in a unified way. Initialization and release is handled internally.
>
> The functionality provided by struct ttm_global is currently re-implemented
> by a dozen individual DRM drivers using struct drm_global. The implementation
> of struct ttm_global is also built on top of drm_global, so it can co-exists
> with the existing drivers. Once all TTM-based drivers have been converted to
> struct ttm_global, the implementation of struct drm_global can be made
> private to TTM.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>   drivers/gpu/drm/ttm/Makefile     |  2 +-
>   drivers/gpu/drm/ttm/ttm_global.c | 98 ++++++++++++++++++++++++++++++++
>   include/drm/drm_global.h         |  8 +++
>   include/drm/ttm/ttm_global.h     | 79 +++++++++++++++++++++++++
>   4 files changed, 186 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/gpu/drm/ttm/ttm_global.c
>   create mode 100644 include/drm/ttm/ttm_global.h
>
> diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
> index 01fc670ce7a2..b7272b26e9f3 100644
> --- a/drivers/gpu/drm/ttm/Makefile
> +++ b/drivers/gpu/drm/ttm/Makefile
> @@ -5,7 +5,7 @@
>   ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \
>   	ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
>   	ttm_execbuf_util.o ttm_page_alloc.o ttm_bo_manager.o \
> -	ttm_page_alloc_dma.o
> +	ttm_page_alloc_dma.o ttm_global.o
>   ttm-$(CONFIG_AGP) += ttm_agp_backend.o
>   
>   obj-$(CONFIG_DRM_TTM) += ttm.o
> diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
> new file mode 100644
> index 000000000000..ca9da0a46147
> --- /dev/null
> +++ b/drivers/gpu/drm/ttm/ttm_global.c
> @@ -0,0 +1,98 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR MIT */
> +/**************************************************************************
> + *
> + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **************************************************************************/
> +
> +#include <drm/ttm/ttm_global.h>
> +#include <drm/ttm/ttm_bo_driver.h>
> +#include <drm/ttm/ttm_memory.h>
> +#include <linux/kernel.h>
> +
> +static int ttm_global_init_mem(struct drm_global_reference *ref)
> +{
> +	BUG_ON(!ref->object);
> +	return ttm_mem_global_init(ref->object);
> +}
> +
> +static void ttm_global_release_mem(struct drm_global_reference *ref)
> +{
> +	BUG_ON(!ref->object);
> +	ttm_mem_global_release(ref->object);
> +}
> +
> +static int ttm_global_init_bo(struct drm_global_reference *ref)
> +{
> +	struct ttm_global *glob =
> +		container_of(ref, struct ttm_global, bo_ref);
> +	BUG_ON(!ref->object);
> +	BUG_ON(!glob->mem_ref.object);
> +	return ttm_bo_global_init(ref->object, glob->mem_ref.object);
> +}
> +
> +static void ttm_global_release_bo(struct drm_global_reference *ref)
> +{
> +	BUG_ON(!ref->object);
> +	ttm_bo_global_release(ref->object);
> +}
> +
> +int ttm_global_init(struct ttm_global *glob)
> +{
> +	int ret;
> +
> +	glob->mem_ref.global_type = DRM_GLOBAL_TTM_MEM;
> +	glob->mem_ref.size = sizeof(struct ttm_mem_global);
> +	glob->bo_ref.object = NULL;
> +	glob->mem_ref.init = &ttm_global_init_mem;
> +	glob->mem_ref.release = &ttm_global_release_mem;
> +	ret = drm_global_item_ref(&glob->mem_ref);
> +	if (ret)
> +		return ret;
> +
> +	glob->bo_ref.global_type = DRM_GLOBAL_TTM_BO;
> +	glob->bo_ref.size = sizeof(struct ttm_bo_global);
> +	glob->bo_ref.object = NULL;
> +	glob->bo_ref.init = &ttm_global_init_bo;
> +	glob->bo_ref.release = &ttm_global_release_bo;
> +	ret = drm_global_item_ref(&glob->bo_ref);
> +	if (ret)
> +		goto err_drm_global_item_unref_mem;
> +
> +	return 0;
> +
> +err_drm_global_item_unref_mem:
> +	drm_global_item_unref(&glob->mem_ref);
> +	return ret;
> +}
> +
> +EXPORT_SYMBOL(ttm_global_init);
> +
> +void ttm_global_release(struct ttm_global *glob)
> +{
> +	drm_global_item_unref(&glob->bo_ref);
> +	drm_global_item_unref(&glob->mem_ref);
> +}
> +
> +EXPORT_SYMBOL(ttm_global_release);
> diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
> index 3a830602a2e4..4482a9bbd6e9 100644
> --- a/include/drm/drm_global.h
> +++ b/include/drm/drm_global.h
> @@ -28,8 +28,16 @@
>    * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
>    */
>   
> +/*
> + *  The interfaces in this file are deprecated. Please use ttm_global
> + *  from <drm/ttm/ttm_global.h> instead.
> + */
> +
>   #ifndef _DRM_GLOBAL_H_
>   #define _DRM_GLOBAL_H_
> +
> +#include <linux/types.h>
> +
>   enum drm_global_types {
>   	DRM_GLOBAL_TTM_MEM = 0,
>   	DRM_GLOBAL_TTM_BO,
> diff --git a/include/drm/ttm/ttm_global.h b/include/drm/ttm/ttm_global.h
> new file mode 100644
> index 000000000000..06e791499f87
> --- /dev/null
> +++ b/include/drm/ttm/ttm_global.h
> @@ -0,0 +1,79 @@
> +/**************************************************************************
> + *
> + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **************************************************************************/
> +
> +#ifndef _TTM_GLOBAL_H_
> +#define _TTM_GLOBAL_H_
> +
> +#include <drm/drm_global.h>
> +
> +struct ttm_bo_global;
> +
> +/**
> + * struct ttm_global - Stores references to global TTM state
> + */
> +struct ttm_global {
> +	struct drm_global_reference mem_ref;
> +	struct drm_global_reference bo_ref;
> +};
> +
> +/**
> + * ttm_global_init
> + *
> + * @glob: A pointer to a struct ttm_global that is about to be initialized
> + * @return Zero on success, or a negative error code otherwise.
> + *
> + * Initializes an instance of struct ttm_global with TTM's global state
> + */
> +int ttm_global_init(struct ttm_global *glob);
> +
> +/**
> + * ttm_global_release
> + *
> + * @glob: A pointer to an instance of struct ttm_global
> + *
> + * Releases an initialized instance of struct ttm_global. If the instance
> + * constains the final references to the global memory and BO, the global
> + * structures are released as well.
> + */
> +void ttm_global_release(struct ttm_global *glob);
> +
> +/**
> + * ttm_global_get_bo_global
> + *
> + * @glob A pointer to an instance of struct ttm_global
> + * @return A refernce to the global BO.
> + *
> + * Returns the global BO. The BO should be forwarded to the initialization
> + * of a driver's TTM BO device.
> + */
> +static inline struct ttm_bo_global*
> +ttm_global_get_bo_global(struct ttm_global *glob)
> +{
> +	return glob->bo_ref.object;
> +}
> +
> +#endif /* _TTM_GLOBAL_H_ */

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state
  2018-10-19  9:30     ` Christian König
@ 2018-10-19  9:41       ` Thomas Zimmermann
       [not found]         ` <616760d1-6598-9769-f058-54777e55b392-l3A5Bk7waGM@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Thomas Zimmermann @ 2018-10-19  9:41 UTC (permalink / raw)
  To: christian.koenig, ray.huang, Jerry.Zhang, alexander.deucher,
	David1.Zhou, airlied, kraxel, bskeggs, syeh, z.liuxinliang,
	zourongrong, kong.kongxinwei, puck.chen
  Cc: dri-devel, amd-gfx


[-- Attachment #1.1.1: Type: text/plain, Size: 10694 bytes --]

Hi

Am 19.10.18 um 11:30 schrieb Christian König:
> In general I'm really graceful that you look into this, but you are just
> moving the complexity around instead of cleaning it up.
> 
> This whole global reference stuff is just going into the wrong direction.
> 
> Please let me clean that up instead,

Well, Ok.

One thing I noticed is that none of the drivers does anything with the
global TTM state. One thing that could be done is to remove the state
from the drivers and handle it entirely in ttm_bo_device.

Best regards
Thomas

> Christian.
> 
> Am 19.10.18 um 10:54 schrieb Thomas Zimmermann:
>> The new struct ttm_global provides drivers with TTM's global memory and
>> BO in a unified way. Initialization and release is handled internally.
>>
>> The functionality provided by struct ttm_global is currently
>> re-implemented
>> by a dozen individual DRM drivers using struct drm_global. The
>> implementation
>> of struct ttm_global is also built on top of drm_global, so it can
>> co-exists
>> with the existing drivers. Once all TTM-based drivers have been
>> converted to
>> struct ttm_global, the implementation of struct drm_global can be made
>> private to TTM.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> ---
>>   drivers/gpu/drm/ttm/Makefile     |  2 +-
>>   drivers/gpu/drm/ttm/ttm_global.c | 98 ++++++++++++++++++++++++++++++++
>>   include/drm/drm_global.h         |  8 +++
>>   include/drm/ttm/ttm_global.h     | 79 +++++++++++++++++++++++++
>>   4 files changed, 186 insertions(+), 1 deletion(-)
>>   create mode 100644 drivers/gpu/drm/ttm/ttm_global.c
>>   create mode 100644 include/drm/ttm/ttm_global.h
>>
>> diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
>> index 01fc670ce7a2..b7272b26e9f3 100644
>> --- a/drivers/gpu/drm/ttm/Makefile
>> +++ b/drivers/gpu/drm/ttm/Makefile
>> @@ -5,7 +5,7 @@
>>   ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \
>>       ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
>>       ttm_execbuf_util.o ttm_page_alloc.o ttm_bo_manager.o \
>> -    ttm_page_alloc_dma.o
>> +    ttm_page_alloc_dma.o ttm_global.o
>>   ttm-$(CONFIG_AGP) += ttm_agp_backend.o
>>     obj-$(CONFIG_DRM_TTM) += ttm.o
>> diff --git a/drivers/gpu/drm/ttm/ttm_global.c
>> b/drivers/gpu/drm/ttm/ttm_global.c
>> new file mode 100644
>> index 000000000000..ca9da0a46147
>> --- /dev/null
>> +++ b/drivers/gpu/drm/ttm/ttm_global.c
>> @@ -0,0 +1,98 @@
>> +/* SPDX-License-Identifier: GPL-2.0 OR MIT */
>> +/**************************************************************************
>>
>> + *
>> + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
>> + * All Rights Reserved.
>> + *
>> + * Permission is hereby granted, free of charge, to any person
>> obtaining a
>> + * copy of this software and associated documentation files (the
>> + * "Software"), to deal in the Software without restriction, including
>> + * without limitation the rights to use, copy, modify, merge, publish,
>> + * distribute, sub license, and/or sell copies of the Software, and to
>> + * permit persons to whom the Software is furnished to do so, subject to
>> + * the following conditions:
>> + *
>> + * The above copyright notice and this permission notice (including the
>> + * next paragraph) shall be included in all copies or substantial
>> portions
>> + * of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> EXPRESS OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT
>> SHALL
>> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
>> ANY CLAIM,
>> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
>> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
>> OR THE
>> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
>> + *
>> +
>> **************************************************************************/
>>
>> +
>> +#include <drm/ttm/ttm_global.h>
>> +#include <drm/ttm/ttm_bo_driver.h>
>> +#include <drm/ttm/ttm_memory.h>
>> +#include <linux/kernel.h>
>> +
>> +static int ttm_global_init_mem(struct drm_global_reference *ref)
>> +{
>> +    BUG_ON(!ref->object);
>> +    return ttm_mem_global_init(ref->object);
>> +}
>> +
>> +static void ttm_global_release_mem(struct drm_global_reference *ref)
>> +{
>> +    BUG_ON(!ref->object);
>> +    ttm_mem_global_release(ref->object);
>> +}
>> +
>> +static int ttm_global_init_bo(struct drm_global_reference *ref)
>> +{
>> +    struct ttm_global *glob =
>> +        container_of(ref, struct ttm_global, bo_ref);
>> +    BUG_ON(!ref->object);
>> +    BUG_ON(!glob->mem_ref.object);
>> +    return ttm_bo_global_init(ref->object, glob->mem_ref.object);
>> +}
>> +
>> +static void ttm_global_release_bo(struct drm_global_reference *ref)
>> +{
>> +    BUG_ON(!ref->object);
>> +    ttm_bo_global_release(ref->object);
>> +}
>> +
>> +int ttm_global_init(struct ttm_global *glob)
>> +{
>> +    int ret;
>> +
>> +    glob->mem_ref.global_type = DRM_GLOBAL_TTM_MEM;
>> +    glob->mem_ref.size = sizeof(struct ttm_mem_global);
>> +    glob->bo_ref.object = NULL;
>> +    glob->mem_ref.init = &ttm_global_init_mem;
>> +    glob->mem_ref.release = &ttm_global_release_mem;
>> +    ret = drm_global_item_ref(&glob->mem_ref);
>> +    if (ret)
>> +        return ret;
>> +
>> +    glob->bo_ref.global_type = DRM_GLOBAL_TTM_BO;
>> +    glob->bo_ref.size = sizeof(struct ttm_bo_global);
>> +    glob->bo_ref.object = NULL;
>> +    glob->bo_ref.init = &ttm_global_init_bo;
>> +    glob->bo_ref.release = &ttm_global_release_bo;
>> +    ret = drm_global_item_ref(&glob->bo_ref);
>> +    if (ret)
>> +        goto err_drm_global_item_unref_mem;
>> +
>> +    return 0;
>> +
>> +err_drm_global_item_unref_mem:
>> +    drm_global_item_unref(&glob->mem_ref);
>> +    return ret;
>> +}
>> +
>> +EXPORT_SYMBOL(ttm_global_init);
>> +
>> +void ttm_global_release(struct ttm_global *glob)
>> +{
>> +    drm_global_item_unref(&glob->bo_ref);
>> +    drm_global_item_unref(&glob->mem_ref);
>> +}
>> +
>> +EXPORT_SYMBOL(ttm_global_release);
>> diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
>> index 3a830602a2e4..4482a9bbd6e9 100644
>> --- a/include/drm/drm_global.h
>> +++ b/include/drm/drm_global.h
>> @@ -28,8 +28,16 @@
>>    * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
>>    */
>>   +/*
>> + *  The interfaces in this file are deprecated. Please use ttm_global
>> + *  from <drm/ttm/ttm_global.h> instead.
>> + */
>> +
>>   #ifndef _DRM_GLOBAL_H_
>>   #define _DRM_GLOBAL_H_
>> +
>> +#include <linux/types.h>
>> +
>>   enum drm_global_types {
>>       DRM_GLOBAL_TTM_MEM = 0,
>>       DRM_GLOBAL_TTM_BO,
>> diff --git a/include/drm/ttm/ttm_global.h b/include/drm/ttm/ttm_global.h
>> new file mode 100644
>> index 000000000000..06e791499f87
>> --- /dev/null
>> +++ b/include/drm/ttm/ttm_global.h
>> @@ -0,0 +1,79 @@
>> +/**************************************************************************
>>
>> + *
>> + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
>> + * All Rights Reserved.
>> + *
>> + * Permission is hereby granted, free of charge, to any person
>> obtaining a
>> + * copy of this software and associated documentation files (the
>> + * "Software"), to deal in the Software without restriction, including
>> + * without limitation the rights to use, copy, modify, merge, publish,
>> + * distribute, sub license, and/or sell copies of the Software, and to
>> + * permit persons to whom the Software is furnished to do so, subject to
>> + * the following conditions:
>> + *
>> + * The above copyright notice and this permission notice (including the
>> + * next paragraph) shall be included in all copies or substantial
>> portions
>> + * of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> EXPRESS OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT
>> SHALL
>> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
>> ANY CLAIM,
>> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
>> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
>> OR THE
>> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
>> + *
>> +
>> **************************************************************************/
>>
>> +
>> +#ifndef _TTM_GLOBAL_H_
>> +#define _TTM_GLOBAL_H_
>> +
>> +#include <drm/drm_global.h>
>> +
>> +struct ttm_bo_global;
>> +
>> +/**
>> + * struct ttm_global - Stores references to global TTM state
>> + */
>> +struct ttm_global {
>> +    struct drm_global_reference mem_ref;
>> +    struct drm_global_reference bo_ref;
>> +};
>> +
>> +/**
>> + * ttm_global_init
>> + *
>> + * @glob: A pointer to a struct ttm_global that is about to be
>> initialized
>> + * @return Zero on success, or a negative error code otherwise.
>> + *
>> + * Initializes an instance of struct ttm_global with TTM's global state
>> + */
>> +int ttm_global_init(struct ttm_global *glob);
>> +
>> +/**
>> + * ttm_global_release
>> + *
>> + * @glob: A pointer to an instance of struct ttm_global
>> + *
>> + * Releases an initialized instance of struct ttm_global. If the
>> instance
>> + * constains the final references to the global memory and BO, the
>> global
>> + * structures are released as well.
>> + */
>> +void ttm_global_release(struct ttm_global *glob);
>> +
>> +/**
>> + * ttm_global_get_bo_global
>> + *
>> + * @glob A pointer to an instance of struct ttm_global
>> + * @return A refernce to the global BO.
>> + *
>> + * Returns the global BO. The BO should be forwarded to the
>> initialization
>> + * of a driver's TTM BO device.
>> + */
>> +static inline struct ttm_bo_global*
>> +ttm_global_get_bo_global(struct ttm_global *glob)
>> +{
>> +    return glob->bo_ref.object;
>> +}
>> +
>> +#endif /* _TTM_GLOBAL_H_ */
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstr. 5, D-90409 Nürnberg
Tel: +49-911-74053-0; Fax: +49-911-7417755;  https://www.suse.com/
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard,
Graham Norton, HRB 21284 (AG Nürnberg)


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state
       [not found]         ` <616760d1-6598-9769-f058-54777e55b392-l3A5Bk7waGM@public.gmane.org>
@ 2018-10-19  9:45           ` Koenig, Christian
  0 siblings, 0 replies; 22+ messages in thread
From: Koenig, Christian @ 2018-10-19  9:45 UTC (permalink / raw)
  To: Thomas Zimmermann, Huang, Ray, Zhang, Jerry, Deucher, Alexander,
	Zhou, David(ChunMing),
	airlied-cv59FeDIM0c, kraxel-H+wXaHxf7aLQT0dZR+AlfA,
	bskeggs-H+wXaHxf7aLQT0dZR+AlfA, syeh-pghWNbHTmq7QT0dZR+AlfA,
	z.liuxinliang-C8/M+/jPZTeaMJb+Lgu22Q,
	zourongrong-Re5JQEeQqe8AvxtiuMwx3w,
	kong.kongxinwei-C8/M+/jPZTeaMJb+Lgu22Q,
	puck.chen-C8/M+/jPZTeaMJb+Lgu22Q
  Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 19.10.18 um 11:41 schrieb Thomas Zimmermann:
> Hi
>
> Am 19.10.18 um 11:30 schrieb Christian König:
>> In general I'm really graceful that you look into this, but you are just
>> moving the complexity around instead of cleaning it up.
>>
>> This whole global reference stuff is just going into the wrong direction.
>>
>> Please let me clean that up instead,
> Well, Ok.
>
> One thing I noticed is that none of the drivers does anything with the
> global TTM state. One thing that could be done is to remove the state
> from the drivers and handle it entirely in ttm_bo_device.

Yeah, exactly that's the point and you can even go a step further.

All what's in those "global" states are actually static information.

I can't work on much else today because I locked myself out of the AMD 
VPN. So going to give that a try.

Thanks,
Christian.

>
> Best regards
> Thomas
>
>> Christian.
>>
>> Am 19.10.18 um 10:54 schrieb Thomas Zimmermann:
>>> The new struct ttm_global provides drivers with TTM's global memory and
>>> BO in a unified way. Initialization and release is handled internally.
>>>
>>> The functionality provided by struct ttm_global is currently
>>> re-implemented
>>> by a dozen individual DRM drivers using struct drm_global. The
>>> implementation
>>> of struct ttm_global is also built on top of drm_global, so it can
>>> co-exists
>>> with the existing drivers. Once all TTM-based drivers have been
>>> converted to
>>> struct ttm_global, the implementation of struct drm_global can be made
>>> private to TTM.
>>>
>>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>>> ---
>>>    drivers/gpu/drm/ttm/Makefile     |  2 +-
>>>    drivers/gpu/drm/ttm/ttm_global.c | 98 ++++++++++++++++++++++++++++++++
>>>    include/drm/drm_global.h         |  8 +++
>>>    include/drm/ttm/ttm_global.h     | 79 +++++++++++++++++++++++++
>>>    4 files changed, 186 insertions(+), 1 deletion(-)
>>>    create mode 100644 drivers/gpu/drm/ttm/ttm_global.c
>>>    create mode 100644 include/drm/ttm/ttm_global.h
>>>
>>> diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
>>> index 01fc670ce7a2..b7272b26e9f3 100644
>>> --- a/drivers/gpu/drm/ttm/Makefile
>>> +++ b/drivers/gpu/drm/ttm/Makefile
>>> @@ -5,7 +5,7 @@
>>>    ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \
>>>        ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
>>>        ttm_execbuf_util.o ttm_page_alloc.o ttm_bo_manager.o \
>>> -    ttm_page_alloc_dma.o
>>> +    ttm_page_alloc_dma.o ttm_global.o
>>>    ttm-$(CONFIG_AGP) += ttm_agp_backend.o
>>>      obj-$(CONFIG_DRM_TTM) += ttm.o
>>> diff --git a/drivers/gpu/drm/ttm/ttm_global.c
>>> b/drivers/gpu/drm/ttm/ttm_global.c
>>> new file mode 100644
>>> index 000000000000..ca9da0a46147
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/ttm/ttm_global.c
>>> @@ -0,0 +1,98 @@
>>> +/* SPDX-License-Identifier: GPL-2.0 OR MIT */
>>> +/**************************************************************************
>>>
>>> + *
>>> + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
>>> + * All Rights Reserved.
>>> + *
>>> + * Permission is hereby granted, free of charge, to any person
>>> obtaining a
>>> + * copy of this software and associated documentation files (the
>>> + * "Software"), to deal in the Software without restriction, including
>>> + * without limitation the rights to use, copy, modify, merge, publish,
>>> + * distribute, sub license, and/or sell copies of the Software, and to
>>> + * permit persons to whom the Software is furnished to do so, subject to
>>> + * the following conditions:
>>> + *
>>> + * The above copyright notice and this permission notice (including the
>>> + * next paragraph) shall be included in all copies or substantial
>>> portions
>>> + * of the Software.
>>> + *
>>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>>> EXPRESS OR
>>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>>> MERCHANTABILITY,
>>> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT
>>> SHALL
>>> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
>>> ANY CLAIM,
>>> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
>>> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
>>> OR THE
>>> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
>>> + *
>>> +
>>> **************************************************************************/
>>>
>>> +
>>> +#include <drm/ttm/ttm_global.h>
>>> +#include <drm/ttm/ttm_bo_driver.h>
>>> +#include <drm/ttm/ttm_memory.h>
>>> +#include <linux/kernel.h>
>>> +
>>> +static int ttm_global_init_mem(struct drm_global_reference *ref)
>>> +{
>>> +    BUG_ON(!ref->object);
>>> +    return ttm_mem_global_init(ref->object);
>>> +}
>>> +
>>> +static void ttm_global_release_mem(struct drm_global_reference *ref)
>>> +{
>>> +    BUG_ON(!ref->object);
>>> +    ttm_mem_global_release(ref->object);
>>> +}
>>> +
>>> +static int ttm_global_init_bo(struct drm_global_reference *ref)
>>> +{
>>> +    struct ttm_global *glob =
>>> +        container_of(ref, struct ttm_global, bo_ref);
>>> +    BUG_ON(!ref->object);
>>> +    BUG_ON(!glob->mem_ref.object);
>>> +    return ttm_bo_global_init(ref->object, glob->mem_ref.object);
>>> +}
>>> +
>>> +static void ttm_global_release_bo(struct drm_global_reference *ref)
>>> +{
>>> +    BUG_ON(!ref->object);
>>> +    ttm_bo_global_release(ref->object);
>>> +}
>>> +
>>> +int ttm_global_init(struct ttm_global *glob)
>>> +{
>>> +    int ret;
>>> +
>>> +    glob->mem_ref.global_type = DRM_GLOBAL_TTM_MEM;
>>> +    glob->mem_ref.size = sizeof(struct ttm_mem_global);
>>> +    glob->bo_ref.object = NULL;
>>> +    glob->mem_ref.init = &ttm_global_init_mem;
>>> +    glob->mem_ref.release = &ttm_global_release_mem;
>>> +    ret = drm_global_item_ref(&glob->mem_ref);
>>> +    if (ret)
>>> +        return ret;
>>> +
>>> +    glob->bo_ref.global_type = DRM_GLOBAL_TTM_BO;
>>> +    glob->bo_ref.size = sizeof(struct ttm_bo_global);
>>> +    glob->bo_ref.object = NULL;
>>> +    glob->bo_ref.init = &ttm_global_init_bo;
>>> +    glob->bo_ref.release = &ttm_global_release_bo;
>>> +    ret = drm_global_item_ref(&glob->bo_ref);
>>> +    if (ret)
>>> +        goto err_drm_global_item_unref_mem;
>>> +
>>> +    return 0;
>>> +
>>> +err_drm_global_item_unref_mem:
>>> +    drm_global_item_unref(&glob->mem_ref);
>>> +    return ret;
>>> +}
>>> +
>>> +EXPORT_SYMBOL(ttm_global_init);
>>> +
>>> +void ttm_global_release(struct ttm_global *glob)
>>> +{
>>> +    drm_global_item_unref(&glob->bo_ref);
>>> +    drm_global_item_unref(&glob->mem_ref);
>>> +}
>>> +
>>> +EXPORT_SYMBOL(ttm_global_release);
>>> diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h
>>> index 3a830602a2e4..4482a9bbd6e9 100644
>>> --- a/include/drm/drm_global.h
>>> +++ b/include/drm/drm_global.h
>>> @@ -28,8 +28,16 @@
>>>     * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
>>>     */
>>>    +/*
>>> + *  The interfaces in this file are deprecated. Please use ttm_global
>>> + *  from <drm/ttm/ttm_global.h> instead.
>>> + */
>>> +
>>>    #ifndef _DRM_GLOBAL_H_
>>>    #define _DRM_GLOBAL_H_
>>> +
>>> +#include <linux/types.h>
>>> +
>>>    enum drm_global_types {
>>>        DRM_GLOBAL_TTM_MEM = 0,
>>>        DRM_GLOBAL_TTM_BO,
>>> diff --git a/include/drm/ttm/ttm_global.h b/include/drm/ttm/ttm_global.h
>>> new file mode 100644
>>> index 000000000000..06e791499f87
>>> --- /dev/null
>>> +++ b/include/drm/ttm/ttm_global.h
>>> @@ -0,0 +1,79 @@
>>> +/**************************************************************************
>>>
>>> + *
>>> + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
>>> + * All Rights Reserved.
>>> + *
>>> + * Permission is hereby granted, free of charge, to any person
>>> obtaining a
>>> + * copy of this software and associated documentation files (the
>>> + * "Software"), to deal in the Software without restriction, including
>>> + * without limitation the rights to use, copy, modify, merge, publish,
>>> + * distribute, sub license, and/or sell copies of the Software, and to
>>> + * permit persons to whom the Software is furnished to do so, subject to
>>> + * the following conditions:
>>> + *
>>> + * The above copyright notice and this permission notice (including the
>>> + * next paragraph) shall be included in all copies or substantial
>>> portions
>>> + * of the Software.
>>> + *
>>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>>> EXPRESS OR
>>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>>> MERCHANTABILITY,
>>> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT
>>> SHALL
>>> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
>>> ANY CLAIM,
>>> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
>>> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
>>> OR THE
>>> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
>>> + *
>>> +
>>> **************************************************************************/
>>>
>>> +
>>> +#ifndef _TTM_GLOBAL_H_
>>> +#define _TTM_GLOBAL_H_
>>> +
>>> +#include <drm/drm_global.h>
>>> +
>>> +struct ttm_bo_global;
>>> +
>>> +/**
>>> + * struct ttm_global - Stores references to global TTM state
>>> + */
>>> +struct ttm_global {
>>> +    struct drm_global_reference mem_ref;
>>> +    struct drm_global_reference bo_ref;
>>> +};
>>> +
>>> +/**
>>> + * ttm_global_init
>>> + *
>>> + * @glob: A pointer to a struct ttm_global that is about to be
>>> initialized
>>> + * @return Zero on success, or a negative error code otherwise.
>>> + *
>>> + * Initializes an instance of struct ttm_global with TTM's global state
>>> + */
>>> +int ttm_global_init(struct ttm_global *glob);
>>> +
>>> +/**
>>> + * ttm_global_release
>>> + *
>>> + * @glob: A pointer to an instance of struct ttm_global
>>> + *
>>> + * Releases an initialized instance of struct ttm_global. If the
>>> instance
>>> + * constains the final references to the global memory and BO, the
>>> global
>>> + * structures are released as well.
>>> + */
>>> +void ttm_global_release(struct ttm_global *glob);
>>> +
>>> +/**
>>> + * ttm_global_get_bo_global
>>> + *
>>> + * @glob A pointer to an instance of struct ttm_global
>>> + * @return A refernce to the global BO.
>>> + *
>>> + * Returns the global BO. The BO should be forwarded to the
>>> initialization
>>> + * of a driver's TTM BO device.
>>> + */
>>> +static inline struct ttm_bo_global*
>>> +ttm_global_get_bo_global(struct ttm_global *glob)
>>> +{
>>> +    return glob->bo_ref.object;
>>> +}
>>> +
>>> +#endif /* _TTM_GLOBAL_H_ */

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2018-10-19  9:45 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19  8:54 [RFC][PATCH 00/18] Provide a nice interface for TTM global state Thomas Zimmermann
2018-10-19  8:54 ` [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing " Thomas Zimmermann
     [not found]   ` <20181019085423.28159-2-tzimmermann-l3A5Bk7waGM@public.gmane.org>
2018-10-19  9:30     ` Christian König
2018-10-19  9:41       ` Thomas Zimmermann
     [not found]         ` <616760d1-6598-9769-f058-54777e55b392-l3A5Bk7waGM@public.gmane.org>
2018-10-19  9:45           ` Koenig, Christian
2018-10-19  8:54 ` [PATCH 03/18] drm/radeon: Replace TTM initialization/release with ttm_global Thomas Zimmermann
2018-10-19  8:54 ` [PATCH 04/18] drm/ast: " Thomas Zimmermann
2018-10-19  8:54 ` [PATCH 07/18] drm/hisilicon: " Thomas Zimmermann
     [not found] ` <20181019085423.28159-1-tzimmermann-l3A5Bk7waGM@public.gmane.org>
2018-10-19  8:54   ` [PATCH 02/18] drm/amdgpu: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 05/18] drm/bochs: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 06/18] drm/cirrus: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 08/18] drm/mgag200: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 09/18] drm/nouveau: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 10/18] drm/qlx: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 11/18] drm/virtio: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 12/18] drm/vmwgfx: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 13/18] staging/vboxvideo: " Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 15/18] drm: Remove DRM_GLOBAL_TTM_OBJECT Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 16/18] drm/ttm: Implement struct ttm_global_item and helpers Thomas Zimmermann
2018-10-19  8:54   ` [PATCH 18/18] drm: Remove drm_global.{c,h} Thomas Zimmermann
2018-10-19  8:54 ` [PATCH 14/18] drm/ttm: Remove struct ttm_bo_global_ref and helpers Thomas Zimmermann
2018-10-19  8:54 ` [PATCH 17/18] drm/ttm: Implement struct ttm_global with struct ttm_global_ref Thomas Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).