From patchwork Thu Oct 18 16:27:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 10647607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4EBD14E2 for ; Thu, 18 Oct 2018 16:28:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4C6C28E42 for ; Thu, 18 Oct 2018 16:28:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A640128E53; Thu, 18 Oct 2018 16:28:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 100C928E42 for ; Thu, 18 Oct 2018 16:28:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE1956E03C; Thu, 18 Oct 2018 16:28:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7FF9E6E02F; Thu, 18 Oct 2018 16:28:03 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 22343AF54; Thu, 18 Oct 2018 16:28:02 +0000 (UTC) From: Thomas Zimmermann To: christian.koenig@amd.com, ray.huang@amd.com, Jerry.Zhang@amd.com, alexander.deucher@amd.com, David1.Zhou@amd.com, airlied@linux.ie Subject: [PATCH 1/3] drm/ttm: Provide struct ttm_global for referencing TTM global state Date: Thu, 18 Oct 2018 18:27:50 +0200 Message-Id: <20181018162752.2241-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018162752.2241-1-tzimmermann@suse.de> References: <20181018162752.2241-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 +#include +#include +#include + +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 */ +/* + * The interfaces in this file are deprecated. Please use ttm_global + * from instead. + */ + #ifndef _DRM_GLOBAL_H_ #define _DRM_GLOBAL_H_ + +#include + 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 + +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_ */ From patchwork Thu Oct 18 16:27:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 10647611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB9DE14E2 for ; Thu, 18 Oct 2018 16:28:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD4F428BFB for ; Thu, 18 Oct 2018 16:28:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0C6128E53; Thu, 18 Oct 2018 16:28:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5816428BFB for ; Thu, 18 Oct 2018 16:28:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 99C166E059; Thu, 18 Oct 2018 16:28:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id EAB816E03C; Thu, 18 Oct 2018 16:28:04 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 869BCB051; Thu, 18 Oct 2018 16:28:03 +0000 (UTC) From: Thomas Zimmermann To: christian.koenig@amd.com, ray.huang@amd.com, Jerry.Zhang@amd.com, alexander.deucher@amd.com, David1.Zhou@amd.com, airlied@linux.ie Subject: [PATCH 2/3] drm/amdgpu: Replace TTM initialization/release with ttm_global Date: Thu, 18 Oct 2018 18:27:51 +0200 Message-Id: <20181018162752.2241-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018162752.2241-1-tzimmermann@suse.de> References: <20181018162752.2241-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Unified initialization and relesae of the global TTM state is provided by struct ttm_global and its interfaces. Signed-off-by: Thomas Zimmermann Reviewed-by: Huang Rui --- 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 +#include #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; From patchwork Thu Oct 18 16:27:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 10647613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 061BF1057 for ; Thu, 18 Oct 2018 16:28:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED18128E23 for ; Thu, 18 Oct 2018 16:28:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E115C28E53; Thu, 18 Oct 2018 16:28:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8AC8728E23 for ; Thu, 18 Oct 2018 16:28:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 885536E05E; Thu, 18 Oct 2018 16:28:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id D01F26E046; Thu, 18 Oct 2018 16:28:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5F28EB052; Thu, 18 Oct 2018 16:28:04 +0000 (UTC) From: Thomas Zimmermann To: christian.koenig@amd.com, ray.huang@amd.com, Jerry.Zhang@amd.com, alexander.deucher@amd.com, David1.Zhou@amd.com, airlied@linux.ie Subject: [PATCH 3/3] drm/radeon: Replace TTM initialization/release with ttm_global Date: Thu, 18 Oct 2018 18:27:52 +0200 Message-Id: <20181018162752.2241-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018162752.2241-1-tzimmermann@suse.de> References: <20181018162752.2241-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Unified initialization and release of the global TTM state is provided by struct ttm_global and its interfaces. Signed-off-by: Thomas Zimmermann Reviewed-by: Huang Rui --- 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 #include #include +#include #include @@ -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,