Skip to contentSkip to conversation

Provide a nice interface for TTM global state

RFC PATCH In review Thomas Zimmermann 4 participants 22 messages Oct 19, 2018 3 messages not in the archive

Subsystems (13)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover Provide a nice interface for TTM global state

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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#1 lore raw

PATCH 1/18 drm/ttm: Provide struct ttm_global for referencing TTM global state

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.

---
 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
drivers/gpu/drm/ttm/Makefile +1 -1
index 01fc670ce7a2..b7272b26e9f3 100644
@@ -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
drivers/gpu/drm/ttm/ttm_global.c new file +98 -0

98 lines not on this page · raw message

include/drm/drm_global.h +8 -0
index 3a830602a2e4..4482a9bbd6e9 100644
@@ -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,
include/drm/ttm/ttm_global.h new file +79 -0

79 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Re: [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state

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:

Quoted 233 lines

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.

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

drivers/gpu/drm/ttm/Makefile +1 -1
index 01fc670ce7a2..b7272b26e9f3 100644
@@ -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
drivers/gpu/drm/ttm/ttm_global.c new file +98 -0
new file mode 100644
index 000000000000..ca9da0a46147
@@ -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);
include/drm/drm_global.h +8 -0
index 3a830602a2e4..4482a9bbd6e9 100644
@@ -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,
include/drm/ttm/ttm_global.h new file +69 -0
new file mode 100644
index 000000000000..06e791499f87
@@ -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.
+ *

include/drm/ttm/ttm_global.h line 79

Quoted 10 lines
include/drm/ttm/ttm_global.h new file +10 -0
+ * 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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author maintainer
#4 lore raw

Re: [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state

Hi

Am 19.10.18 um 11:30 schrieb Christian König:

Quoted 6 lines

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

Quoted 274 lines

Christian.

Am 19.10.18 um 10:54 schrieb Thomas Zimmermann:

Quoted 270 lines

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.

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

drivers/gpu/drm/ttm/Makefile +1 -1
index 01fc670ce7a2..b7272b26e9f3 100644
@@ -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

drivers/gpu/drm/ttm/ttm_global.c new file +7 -0
new file mode 100644
index 000000000000..ca9da0a46147
@@ -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.
+ *
+ **************************************************************************/

drivers/gpu/drm/ttm/ttm_global.c new file +71 -0
+
+#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);
include/drm/drm_global.h +0 -0
index 3a830602a2e4..4482a9bbd6e9 100644
@@ -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/drm/drm_global.h +3 -0
+
+#include <linux/types.h>
+

  enum drm_global_types {
      DRM_GLOBAL_TTM_MEM = 0,
      DRM_GLOBAL_TTM_BO,

include/drm/ttm/ttm_global.h new file +6 -0
new file mode 100644
index 000000000000..06e791499f87
@@ -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.
+ *
+ **************************************************************************/

include/drm/ttm/ttm_global.h new file +20 -0
+
+#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
+ */

include/drm/ttm/ttm_global.h new file +8 -0
+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.
+ */

include/drm/ttm/ttm_global.h new file +9 -0
+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.
+ */

include/drm/ttm/ttm_global.h new file +7 -0
+static inline struct ttm_bo_global*
+ttm_global_get_bo_global(struct ttm_global *glob)
+{
+    return glob->bo_ref.object;
+}
+
+#endif /* _TTM_GLOBAL_H_ */
Signature · 6 lines
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)

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 616760d1-6598-9769-f058-54777e55b392-l3A5Bk7waGM@public.gmane.org

#6 lore raw

Re: [PATCH 01/18] drm/ttm: Provide struct ttm_global for referencing TTM global state

Am 19.10.18 um 11:41 schrieb Thomas Zimmermann:

Quoted 6 lines

Hi

Am 19.10.18 um 11:30 schrieb Christian König:

Quoted 3 lines

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

Quoted 8 lines
Quoted 3 lines

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.

Quoted 269 lines

Best regards
Thomas

Quoted 265 lines

Christian.

Am 19.10.18 um 10:54 schrieb Thomas Zimmermann:

Quoted 262 lines

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.

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

drivers/gpu/drm/ttm/Makefile +1 -1
index 01fc670ce7a2..b7272b26e9f3 100644
@@ -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
drivers/gpu/drm/ttm/ttm_global.c new file +7 -0
new file mode 100644
index 000000000000..ca9da0a46147
@@ -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.
+ *
+ **************************************************************************/

drivers/gpu/drm/ttm/ttm_global.c new file +71 -0
+
+#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);
include/drm/drm_global.h +7 -0
index 3a830602a2e4..4482a9bbd6e9 100644
@@ -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,
include/drm/ttm/ttm_global.h new file +6 -0
new file mode 100644
index 000000000000..06e791499f87
@@ -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.
+ *
+ **************************************************************************/

include/drm/ttm/ttm_global.h new file +20 -0
+
+#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
+ */

include/drm/ttm/ttm_global.h new file +8 -0
+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.
+ */

include/drm/ttm/ttm_global.h new file +9 -0
+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.

Quoted 8 lines
Quoted 8 lines

include/drm/ttm/ttm_global.h line 79

Quoted 8 lines

+ */

include/drm/ttm/ttm_global.h new file +7 -0
+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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

PATCH 2/18 drm/amdgpu: Replace TTM initialization/release with ttm_global

Unified initialization and relesae of the global TTM state is provided by struct ttm_global and its interfaces.

---
 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -58
index 3a6802846698..70b0e8c77bb4 100644
@@ -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,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +2 -2
index fe8f276e9811..c3a7fe3ead3a 100644
@@ -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;
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#9 lore raw

PATCH 5/18 drm/bochs: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/bochs/bochs.h    |  5 ++--
 drivers/gpu/drm/bochs/bochs_mm.c | 47 +++++---------------------------
 2 files changed, 10 insertions(+), 42 deletions(-)
drivers/gpu/drm/bochs/bochs.h +3 -2
index e7a69077e45a..f73911ac1d77 100644
@@ -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;
 
drivers/gpu/drm/bochs/bochs_mm.c +7 -40

75 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#10 lore raw

PATCH 6/18 drm/cirrus: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/cirrus/cirrus_drv.h |  5 +--
 drivers/gpu/drm/cirrus/cirrus_ttm.c | 49 +++++------------------------
 2 files changed, 11 insertions(+), 43 deletions(-)
drivers/gpu/drm/cirrus/cirrus_drv.h +3 -2
index a29f87e98d9d..f62774cfb68e 100644
@@ -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;
 };
drivers/gpu/drm/cirrus/cirrus_ttm.c +8 -41

75 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#11 lore raw

PATCH 8/18 drm/mgag200: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/mgag200/mgag200_drv.h |  7 ++--
 drivers/gpu/drm/mgag200/mgag200_ttm.c | 49 +++++----------------------
 2 files changed, 12 insertions(+), 44 deletions(-)
drivers/gpu/drm/mgag200/mgag200_drv.h +4 -3
index 04f1dfba12e5..f82c1034b2ea 100644
@@ -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 */
drivers/gpu/drm/mgag200/mgag200_ttm.c +8 -41

75 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#12 lore raw

PATCH 9/18 drm/nouveau: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/nouveau/nouveau_drv.h |  5 +--
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 48 ++++-----------------------
 2 files changed, 9 insertions(+), 44 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drv.h +3 -2
index 0b2191fa96f7..0d5a78f4ad75 100644
@@ -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 *,
drivers/gpu/drm/nouveau/nouveau_ttm.c +6 -42

76 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#13 lore raw

PATCH 10/18 drm/qlx: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/qxl/qxl_drv.h |  4 ++--
 drivers/gpu/drm/qxl/qxl_ttm.c | 40 ++++-------------------------------
 2 files changed, 6 insertions(+), 38 deletions(-)
drivers/gpu/drm/qxl/qxl_drv.h +2 -2
index 8ff70a7281a7..64232a2684fd 100644
@@ -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;
 };
 
drivers/gpu/drm/qxl/qxl_ttm.c +4 -36
index db2a0036e9c4..2e852fac97d3 100644
@@ -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);
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#14 lore raw

PATCH 11/18 drm/virtio: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/virtio/virtgpu_drv.h |  4 +--
 drivers/gpu/drm/virtio/virtgpu_ttm.c | 40 +++-------------------------
 2 files changed, 6 insertions(+), 38 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -2
index d29f0c7c768c..502e4d531df7 100644
@@ -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;
 };
 
drivers/gpu/drm/virtio/virtgpu_ttm.c +4 -36
index 526a5e48dc3b..113491cc6595 100644
@@ -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);
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#15 lore raw

PATCH 12/18 drm/vmwgfx: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 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(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -3
index 61a84b958d67..85b58e0c25fa 100644
@@ -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;
 }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +3 -3
index 59f614225bcd..ae724c756bf0 100644
@@ -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)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +3 -41

59 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#16 lore raw

PATCH 13/18 staging/vboxvideo: Replace TTM initialization/release with ttm_global

In reply to a message not in the archive

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/staging/vboxvideo/vbox_drv.h |  4 +--
 drivers/staging/vboxvideo/vbox_ttm.c | 42 +++-------------------------
 2 files changed, 6 insertions(+), 40 deletions(-)
drivers/staging/vboxvideo/vbox_drv.h +2 -2
index 594f84272957..21cca25d00f5 100644
@@ -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;
 
drivers/staging/vboxvideo/vbox_ttm.c +4 -38

68 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#17 lore raw

PATCH 15/18 drm: Remove DRM_GLOBAL_TTM_OBJECT

In reply to a message not in the archive

The constant DRM_GLOBAL_TTM_OBJECT is unused and not obviously useful.

---
 include/drm/drm_global.h | 1 -
 1 file changed, 1 deletion(-)
include/drm/drm_global.h +0 -1
index 4482a9bbd6e9..63ffdcec6690 100644
@@ -41,7 +41,6 @@
 enum drm_global_types {
 	DRM_GLOBAL_TTM_MEM = 0,
 	DRM_GLOBAL_TTM_BO,
-	DRM_GLOBAL_TTM_OBJECT,
 	DRM_GLOBAL_NUM
 };
 
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#18 lore raw

PATCH 16/18 drm/ttm: Implement struct ttm_global_item and helpers

In reply to a message not in the archive

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.

---
 drivers/gpu/drm/ttm/ttm_global.c | 98 ++++++++++++++++++++++++++++++++
 include/drm/ttm/ttm_global.h     | 22 +++++++
 2 files changed, 120 insertions(+)
drivers/gpu/drm/ttm/ttm_global.c +98 -0
index ca9da0a46147..1e5c2f5eeca0 100644
@@ -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);
include/drm/ttm/ttm_global.h +22 -0
index 06e791499f87..9aa0ddbbe2ef 100644
@@ -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;
 
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#19 lore raw

PATCH 18/18 drm: Remove drm_global.{c,h}

In reply to a message not in the archive

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

---
 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
drivers/gpu/drm/Makefile +1 -1
index 576ba985e138..7f3be3506057 100644
@@ -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 \
drivers/gpu/drm/drm_drv.c +0 -2
index 36e8e9cbec52..fc29f46b7c32 100644
@@ -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);
 
drivers/gpu/drm/drm_global.c deleted +0 -137

137 lines not on this page · raw message

drivers/gpu/drm/gma500/psb_drv.h +2 -2
index 941b238bdcc9..c4f084fdf630 100644
@@ -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;
 
include/drm/drmP.h +0 -1
index 05350424a4d3..2557001d1b21 100644
@@ -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>
include/drm/drm_global.h deleted +0 -60

60 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author maintainer
#20 lore raw

PATCH 3/18 drm/radeon: Replace TTM initialization/release with ttm_global

In reply to Thomas Zimmermann

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/radeon/radeon.h     |  4 +--
 drivers/gpu/drm/radeon/radeon_ttm.c | 40 ++++-------------------------
 2 files changed, 7 insertions(+), 37 deletions(-)
drivers/gpu/drm/radeon/radeon.h +2 -2
index 1a6f6edb3515..554c0421b779 100644
@@ -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;
drivers/gpu/drm/radeon/radeon_ttm.c +5 -35
index dac4ec5a120b..363860e82892 100644
@@ -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,
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#21 lore raw

PATCH 4/18 drm/ast: Replace TTM initialization/release with ttm_global

In reply to Thomas Zimmermann

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 drivers/gpu/drm/ast/ast_drv.h |  5 ++--
 drivers/gpu/drm/ast/ast_ttm.c | 49 ++++++-----------------------------
 2 files changed, 11 insertions(+), 43 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +3 -2
index e6c4cd3dc50e..e0c9ee2b0e00 100644
@@ -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;
drivers/gpu/drm/ast/ast_ttm.c +8 -41

75 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#22 lore raw

PATCH 7/18 drm/hisilicon: Replace TTM initialization/release with ttm_global

In reply to Thomas Zimmermann

Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces.

---
 .../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(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +2 -2
index 45c25a488f42..1091f3bb81c4 100644
@@ -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;
 
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +3 -33
index 0454aa43ffc6..4f51ac5d8340 100644
@@ -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,
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#23 lore raw

PATCH 14/18 drm/ttm: Remove struct ttm_bo_global_ref and helpers

In reply to Thomas Zimmermann

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.

---
 include/drm/ttm/ttm_bo_driver.h | 40 ---------------------------------
 1 file changed, 40 deletions(-)
include/drm/ttm/ttm_bo_driver.h +0 -40
index c6ee07d10281..e51ced5f5e75 100644
@@ -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
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#24 lore raw

PATCH 17/18 drm/ttm: Implement struct ttm_global with struct ttm_global_ref

In reply to Thomas Zimmermann
---
 drivers/gpu/drm/ttm/ttm_global.c | 28 +++++++++++++++-------------
 include/drm/ttm/ttm_global.h     |  5 ++---
 2 files changed, 17 insertions(+), 16 deletions(-)
drivers/gpu/drm/ttm/ttm_global.c +15 -13
index 1e5c2f5eeca0..93d268daf97b 100644
@@ -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);
include/drm/ttm/ttm_global.h +2 -3
index 9aa0ddbbe2ef..8dedac053611 100644
@@ -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;
 };
 
 /**
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel