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_ */