From patchwork Tue Apr 16 00:35:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Herbst X-Patchwork-Id: 10901759 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 AEC8A922 for ; Tue, 16 Apr 2019 00:35:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97E0628958 for ; Tue, 16 Apr 2019 00:35:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AB5B28961; Tue, 16 Apr 2019 00:35:37 +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 DEF5D28958 for ; Tue, 16 Apr 2019 00:35:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 472FF89316; Tue, 16 Apr 2019 00:35:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8595B8930B for ; Tue, 16 Apr 2019 00:35:30 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id q1so24376067wrp.0 for ; Mon, 15 Apr 2019 17:35:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lRCoUAZ7PZ4cL93H001fY1+e6eLtakuGqXo+rHnw5Rg=; b=Ax5+6BaCMJs8Gsr3tU7HNkt46q7PHi2/hiCDIMRSZ2B1N06czYJ5ltgnmNBKnamiOd EXqcr716gTE9NF9GziyU6ziTt73DBtmhunKYhJkoYYe+Gl6tM8tSh9/sU8RCuH50umdg B7NFsrL2ok5cyvdfD7gMSm8iw7wJXzWwEolgzCnUA88G9+i6Ux8VWAt+KYboeIuDXGbt 00M5k4EYCKlLebUC7FP153r8fmWlxS+FLmfVuLez6X7LhjBuRC+wLs3G9tI73wRMTQ9o YaFoUZeckG4UulyHNMLsyJidMr39QxQGSomeKPg5v8wb8dlwiNYGxs+DmXkukD3UYpIx o0xg== X-Gm-Message-State: APjAAAXo6iEFO4D5ctPgwnOMLHCNZ1FWpZf4ahdH/g4a7SB1W1ct/5O/ UTqaJQNSho3qH4PxikTLIlX4XKe6R8Q= X-Google-Smtp-Source: APXvYqzRQ1GwWZjntCI8Y6ggMqRHIuBEJ1AJ5lezUeuUX7lbVdHZ6ib/Bet4cXMkN4WDXodZmIZlbw== X-Received: by 2002:a5d:6181:: with SMTP id j1mr28606807wru.11.1555374928880; Mon, 15 Apr 2019 17:35:28 -0700 (PDT) Received: from kherbst.pingu.com ([2a02:8308:b0be:6900:a1ae:358d:6041:7470]) by smtp.gmail.com with ESMTPSA id w2sm38801268wrm.74.2019.04.15.17.35.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 17:35:27 -0700 (PDT) From: Karol Herbst To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/6] Revert "drm: Remove drm_global.{c,h} v2" Date: Tue, 16 Apr 2019 02:35:18 +0200 Message-Id: <20190416003523.5069-2-kherbst@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com> References: <20190416003523.5069-1-kherbst@redhat.com> 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: Alex Deucher , Karol Herbst Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 2bb42410b1bd324912389c6ac748df1c1befd69f. Signed-off-by: Karol Herbst --- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++++++++++++++++ include/drm/drmP.h | 1 + include/drm/drm_global.h | 53 ++++++++++++ include/drm/ttm/ttm_bo_driver.h | 1 + 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_global.c create mode 100644 include/drm/drm_global.h diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index ce8d1d384319..a3a19e9020e3 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -11,7 +11,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_sysfs.o drm_hashtab.o drm_mm.o \ drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \ drm_encoder_slave.o \ - drm_trace_points.o drm_prime.o \ + drm_trace_points.o drm_global.o drm_prime.o \ drm_rect.o drm_vma_manager.o drm_flip_work.o \ drm_modeset_lock.o drm_atomic.o drm_bridge.o \ drm_framebuffer.o drm_connector.o drm_blend.o \ diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 12e5e2be7890..5f7e99bf4fa4 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -960,12 +960,14 @@ static void drm_core_exit(void) drm_sysfs_destroy(); idr_destroy(&drm_minors_idr); drm_connector_ida_destroy(); + drm_global_release(); } static int __init drm_core_init(void) { int ret; + drm_global_init(); drm_connector_ida_init(); idr_init(&drm_minors_idr); diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c new file mode 100644 index 000000000000..5799e2782dd1 --- /dev/null +++ b/drivers/gpu/drm/drm_global.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/************************************************************************** + * + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ + +#include +#include +#include +#include + +struct drm_global_item { + struct mutex mutex; + void *object; + int refcount; +}; + +static struct drm_global_item glob[DRM_GLOBAL_NUM]; + +void drm_global_init(void) +{ + int i; + + for (i = 0; i < DRM_GLOBAL_NUM; ++i) { + struct drm_global_item *item = &glob[i]; + mutex_init(&item->mutex); + item->object = NULL; + item->refcount = 0; + } +} + +void drm_global_release(void) +{ + int i; + for (i = 0; i < DRM_GLOBAL_NUM; ++i) { + struct drm_global_item *item = &glob[i]; + BUG_ON(item->object != NULL); + BUG_ON(item->refcount != 0); + } +} + +/** + * drm_global_item_ref - Initialize and acquire reference to memory + * object + * @ref: Object for initialization + * + * This initializes a memory object, allocating memory and calling the + * .init() hook. Further calls will increase the reference count for + * that item. + * + * Returns: + * Zero on success, non-zero otherwise. + */ +int drm_global_item_ref(struct drm_global_reference *ref) +{ + int ret = 0; + struct drm_global_item *item = &glob[ref->global_type]; + + mutex_lock(&item->mutex); + if (item->refcount == 0) { + ref->object = kzalloc(ref->size, GFP_KERNEL); + if (unlikely(ref->object == NULL)) { + ret = -ENOMEM; + goto error_unlock; + } + ret = ref->init(ref); + if (unlikely(ret != 0)) + goto error_free; + + item->object = ref->object; + } else { + ref->object = item->object; + } + + ++item->refcount; + mutex_unlock(&item->mutex); + return 0; + +error_free: + kfree(ref->object); + ref->object = NULL; +error_unlock: + mutex_unlock(&item->mutex); + return ret; +} +EXPORT_SYMBOL(drm_global_item_ref); + +/** + * drm_global_item_unref - Drop reference to memory + * object + * @ref: Object being removed + * + * Drop a reference to the memory object and eventually call the + * release() hook. The allocated object should be dropped in the + * release() hook or before calling this function + * + */ + +void drm_global_item_unref(struct drm_global_reference *ref) +{ + struct drm_global_item *item = &glob[ref->global_type]; + + mutex_lock(&item->mutex); + BUG_ON(item->refcount == 0); + BUG_ON(ref->object != item->object); + if (--item->refcount == 0) { + ref->release(ref); + item->object = NULL; + } + mutex_unlock(&item->mutex); +} +EXPORT_SYMBOL(drm_global_item_unref); + diff --git a/include/drm/drmP.h b/include/drm/drmP.h index bdb0d5548f39..514beb2d483a 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -68,6 +68,7 @@ #include #include #include +#include #include #include #include diff --git a/include/drm/drm_global.h b/include/drm/drm_global.h new file mode 100644 index 000000000000..3a830602a2e4 --- /dev/null +++ b/include/drm/drm_global.h @@ -0,0 +1,53 @@ +/************************************************************************** + * + * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ + +#ifndef _DRM_GLOBAL_H_ +#define _DRM_GLOBAL_H_ +enum drm_global_types { + DRM_GLOBAL_TTM_MEM = 0, + DRM_GLOBAL_TTM_BO, + DRM_GLOBAL_TTM_OBJECT, + DRM_GLOBAL_NUM +}; + +struct drm_global_reference { + enum drm_global_types global_type; + size_t size; + void *object; + int (*init) (struct drm_global_reference *); + void (*release) (struct drm_global_reference *); +}; + +void drm_global_init(void); +void drm_global_release(void); +int drm_global_item_ref(struct drm_global_reference *ref); +void drm_global_item_unref(struct drm_global_reference *ref); + +#endif diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 1021106438b2..6fb589f64633 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -31,6 +31,7 @@ #define _TTM_BO_DRIVER_H_ #include +#include #include #include #include From patchwork Tue Apr 16 00:35:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Herbst X-Patchwork-Id: 10901761 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 195B91515 for ; Tue, 16 Apr 2019 00:35:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F371328958 for ; Tue, 16 Apr 2019 00:35:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7B9828961; Tue, 16 Apr 2019 00:35:40 +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 2982C28958 for ; Tue, 16 Apr 2019 00:35:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 13C768968D; Tue, 16 Apr 2019 00:35:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6D36889316 for ; Tue, 16 Apr 2019 00:35:32 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id c1so22882806wml.4 for ; Mon, 15 Apr 2019 17:35:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ie8iaHKsXaZd9j7c1ReCJ/Ir7PJqm2kUoh0Z2uIQTW0=; b=LXJvW2g1Yw4xmHymxjVM9e0Srk8/mIW01eUxPgEzcVq3mqhhddt+/ylUPThTiu040D y7OurAU81ifeWZtrfQVjM9B1ceBoX30+58Qlz285qzLQB0LamOjP8/sO7YIn0iSVay0A bk4C2WAp+JaENY3obUiIPMTeF7uhkmWkMfRUsAg5PkdEo0BclH41bjh5rFtjtZ21Hm2m HC2m0LnjweQx3D5hDdZp8wJWEABC5ZnDbFf3/n8YbuSuYw+hcTNsVFXkMewBuEL6gOme C9fzJWFJ1blSY8SLBuCO2dQ3l6iKDe1BiQyDSxrwBDC1S3xhUqAzVpB6FBrZxQgxbQLp 0a4w== X-Gm-Message-State: APjAAAWRxDj++gXkxBz2FM84C2Ov/31zY4WOrAfviy73b9wajZ6NNUga cnC8hN2y9GruWme5SA2pUoLWuiZa+lU= X-Google-Smtp-Source: APXvYqwGjq6eAjrWPLvTqc8dwU8Y80Ipi51Z86F4KEbGNyybrERY8WSi34BSvA4rdQCJGvbY2VNH9Q== X-Received: by 2002:a05:600c:ca:: with SMTP id u10mr24751636wmm.122.1555374930354; Mon, 15 Apr 2019 17:35:30 -0700 (PDT) Received: from kherbst.pingu.com ([2a02:8308:b0be:6900:a1ae:358d:6041:7470]) by smtp.gmail.com with ESMTPSA id w2sm38801268wrm.74.2019.04.15.17.35.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 17:35:29 -0700 (PDT) From: Karol Herbst To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/6] Revert "drm/ttm: initialize globals during device init (v2)" Date: Tue, 16 Apr 2019 02:35:19 +0200 Message-Id: <20190416003523.5069-3-kherbst@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com> References: <20190416003523.5069-1-kherbst@redhat.com> 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: Alex Deucher , Karol Herbst Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit a64f784bb14a56bfdfad2dc397dd67e4564e3a29. Signed-off-by: Karol Herbst --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 59 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_ttm.c | 36 +++++++++++ drivers/gpu/drm/bochs/bochs.h | 1 + drivers/gpu/drm/bochs/bochs_mm.c | 35 +++++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 1 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 36 +++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 1 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 34 +++++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 36 +++++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 39 ++++++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 2 + drivers/gpu/drm/qxl/qxl_ttm.c | 33 +++++++++++ drivers/gpu/drm/radeon/radeon.h | 2 + drivers/gpu/drm/radeon/radeon_ttm.c | 39 ++++++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 19 +++--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 35 +++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 11 +++- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 + drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 27 +++++++++ drivers/staging/vboxvideo/vbox_drv.h | 1 + drivers/staging/vboxvideo/vbox_ttm.c | 41 ++++++++++++- include/drm/ttm/ttm_bo_driver.h | 41 ++++++++++++- 27 files changed, 521 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index c91ec3101d00..213d29d0ad80 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -61,6 +61,56 @@ static int amdgpu_map_buffer(struct ttm_buffer_object *bo, static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev); static void amdgpu_ttm_debugfs_fini(struct amdgpu_device *adev); +/* + * Global memory. + */ + +/** + * amdgpu_ttm_global_init - Initialize global TTM memory reference structures. + * + * @adev: AMDGPU device for which the global structures need to be registered. + * + * This is called as part of the AMDGPU ttm init from amdgpu_ttm_init() + * during bring up. + */ +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.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; + } + + mutex_init(&adev->mman.gtt_window_lock); + + adev->mman.mem_global_referenced = true; + + return 0; + +error_bo: + 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); + adev->mman.mem_global_referenced = false; + } +} + static int amdgpu_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) { return 0; @@ -1664,10 +1714,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) int r; u64 vis_vram_limit; - mutex_init(&adev->mman.gtt_window_lock); - + /* initialize global references for vram/gtt */ + r = amdgpu_ttm_global_init(adev); + if (r) { + return r; + } /* 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, &amdgpu_bo_driver, adev->ddev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -1824,6 +1878,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev) ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GWS); ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_OA); ttm_bo_device_release(&adev->mman.bdev); + amdgpu_ttm_global_fini(adev); adev->mman.initialized = false; DRM_INFO("amdgpu: ttm finalized\n"); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h index b5b2d101f7db..e114f209b701 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h @@ -39,6 +39,7 @@ #define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2 struct amdgpu_mman { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; bool mem_global_referenced; bool initialized; diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h index bfc65040dfcb..6ae11a477643 100644 --- a/drivers/gpu/drm/ast/ast_drv.h +++ b/drivers/gpu/drm/ast/ast_drv.h @@ -104,6 +104,7 @@ struct ast_private { int fb_mtrr; struct { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c index c168d62fe8f9..8a59d6fc1160 100644 --- a/drivers/gpu/drm/ast/ast_ttm.c +++ b/drivers/gpu/drm/ast/ast_ttm.c @@ -36,6 +36,35 @@ ast_bdev(struct ttm_bo_device *bd) return container_of(bd, struct ast_private, ttm.bdev); } +static int ast_ttm_global_init(struct ast_private *ast) +{ + struct drm_global_reference *global_ref; + int r; + + global_ref = &ast->ttm.bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + return r; + } + return 0; +} + +static void +ast_ttm_global_release(struct ast_private *ast) +{ + if (ast->ttm.bo_global_ref.ref.release == NULL) + return; + + drm_global_item_unref(&ast->ttm.bo_global_ref.ref); + ast->ttm.bo_global_ref.ref.release = NULL; +} + + static void ast_bo_ttm_destroy(struct ttm_buffer_object *tbo) { struct ast_bo *bo; @@ -175,7 +204,12 @@ int ast_mm_init(struct ast_private *ast) struct drm_device *dev = ast->dev; struct ttm_bo_device *bdev = &ast->ttm.bdev; + ret = ast_ttm_global_init(ast); + if (ret) + return ret; + ret = ttm_bo_device_init(&ast->ttm.bdev, + ast->ttm.bo_global_ref.ref.object, &ast_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -206,6 +240,8 @@ void ast_mm_fini(struct ast_private *ast) ttm_bo_device_release(&ast->ttm.bdev); + ast_ttm_global_release(ast); + arch_phys_wc_del(ast->fb_mtrr); arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0), pci_resource_len(dev->pdev, 0)); diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h index fb38c8b857b5..c1d88ea6b419 100644 --- a/drivers/gpu/drm/bochs/bochs.h +++ b/drivers/gpu/drm/bochs/bochs.h @@ -77,6 +77,7 @@ struct bochs_device { /* ttm */ struct { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; bool initialized; } ttm; diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c index 0980411e41bf..cad65774a973 100644 --- a/drivers/gpu/drm/bochs/bochs_mm.c +++ b/drivers/gpu/drm/bochs/bochs_mm.c @@ -16,6 +16,35 @@ static inline struct bochs_device *bochs_bdev(struct ttm_bo_device *bd) return container_of(bd, struct bochs_device, ttm.bdev); } +static int bochs_ttm_global_init(struct bochs_device *bochs) +{ + struct drm_global_reference *global_ref; + int r; + + global_ref = &bochs->ttm.bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + return r; + } + + return 0; +} + +static void bochs_ttm_global_release(struct bochs_device *bochs) +{ + if (bochs->ttm.bo_global_ref.ref.release == NULL) + return; + + drm_global_item_unref(&bochs->ttm.bo_global_ref.ref); + bochs->ttm.bo_global_ref.ref.release = NULL; +} + + static void bochs_bo_ttm_destroy(struct ttm_buffer_object *tbo) { struct bochs_bo *bo; @@ -153,7 +182,12 @@ int bochs_mm_init(struct bochs_device *bochs) struct ttm_bo_device *bdev = &bochs->ttm.bdev; int ret; + ret = bochs_ttm_global_init(bochs); + if (ret) + return ret; + ret = ttm_bo_device_init(&bochs->ttm.bdev, + bochs->ttm.bo_global_ref.ref.object, &bochs_bo_driver, bochs->dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -180,6 +214,7 @@ void bochs_mm_fini(struct bochs_device *bochs) return; ttm_bo_device_release(&bochs->ttm.bdev); + bochs_ttm_global_release(bochs); bochs->ttm.initialized = false; } diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h index f2b2e0d169fa..01852fbda9da 100644 --- a/drivers/gpu/drm/cirrus/cirrus_drv.h +++ b/drivers/gpu/drm/cirrus/cirrus_drv.h @@ -136,6 +136,7 @@ struct cirrus_device { int fb_mtrr; struct { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; bool mm_inited; diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c index e075810b4bd4..7801c56c3c9b 100644 --- a/drivers/gpu/drm/cirrus/cirrus_ttm.c +++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c @@ -36,6 +36,35 @@ cirrus_bdev(struct ttm_bo_device *bd) return container_of(bd, struct cirrus_device, ttm.bdev); } +static int cirrus_ttm_global_init(struct cirrus_device *cirrus) +{ + struct drm_global_reference *global_ref; + int r; + + global_ref = &cirrus->ttm.bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + return r; + } + return 0; +} + +static void +cirrus_ttm_global_release(struct cirrus_device *cirrus) +{ + if (cirrus->ttm.bo_global_ref.ref.release == NULL) + return; + + drm_global_item_unref(&cirrus->ttm.bo_global_ref.ref); + cirrus->ttm.bo_global_ref.ref.release = NULL; +} + + static void cirrus_bo_ttm_destroy(struct ttm_buffer_object *tbo) { struct cirrus_bo *bo; @@ -175,7 +204,12 @@ int cirrus_mm_init(struct cirrus_device *cirrus) struct drm_device *dev = cirrus->dev; struct ttm_bo_device *bdev = &cirrus->ttm.bdev; + ret = cirrus_ttm_global_init(cirrus); + if (ret) + return ret; + ret = ttm_bo_device_init(&cirrus->ttm.bdev, + cirrus->ttm.bo_global_ref.ref.object, &cirrus_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -211,6 +245,8 @@ void cirrus_mm_fini(struct cirrus_device *cirrus) ttm_bo_device_release(&cirrus->ttm.bdev); + cirrus_ttm_global_release(cirrus); + arch_phys_wc_del(cirrus->fb_mtrr); cirrus->fb_mtrr = 0; arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0), diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h index 3c168ae77b0c..60479502e277 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h @@ -49,6 +49,7 @@ struct hibmc_drm_private { bool mode_config_initialized; /* ttm */ + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; bool initialized; diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c index dd383267884c..14071c849121 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c @@ -29,6 +29,32 @@ hibmc_bdev(struct ttm_bo_device *bd) return container_of(bd, struct hibmc_drm_private, bdev); } +static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc) +{ + int ret; + + 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); + return ret; + } + return 0; +} + +static void +hibmc_ttm_global_release(struct hibmc_drm_private *hibmc) +{ + if (hibmc->bo_global_ref.ref.release == NULL) + return; + + drm_global_item_unref(&hibmc->bo_global_ref.ref); + hibmc->bo_global_ref.ref.release = NULL; +} + static void hibmc_bo_ttm_destroy(struct ttm_buffer_object *tbo) { struct hibmc_bo *bo = container_of(tbo, struct hibmc_bo, bo); @@ -188,12 +214,18 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc) struct drm_device *dev = hibmc->dev; struct ttm_bo_device *bdev = &hibmc->bdev; + ret = hibmc_ttm_global_init(hibmc); + if (ret) + return ret; + ret = ttm_bo_device_init(&hibmc->bdev, + hibmc->bo_global_ref.ref.object, &hibmc_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, true); if (ret) { + hibmc_ttm_global_release(hibmc); DRM_ERROR("error initializing bo driver: %d\n", ret); return ret; } @@ -201,6 +233,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc) ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, hibmc->fb_size >> PAGE_SHIFT); if (ret) { + hibmc_ttm_global_release(hibmc); DRM_ERROR("failed ttm VRAM init: %d\n", ret); return ret; } @@ -215,6 +248,7 @@ void hibmc_mm_fini(struct hibmc_drm_private *hibmc) return; ttm_bo_device_release(&hibmc->bdev); + hibmc_ttm_global_release(hibmc); hibmc->mm_inited = false; } diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index 0aaedc554879..e5348955a3cc 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -212,6 +212,7 @@ struct mga_device { int fb_mtrr; struct { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; diff --git a/drivers/gpu/drm/mgag200/mgag200_ttm.c b/drivers/gpu/drm/mgag200/mgag200_ttm.c index d96a9b32455e..11bdc8121a7d 100644 --- a/drivers/gpu/drm/mgag200/mgag200_ttm.c +++ b/drivers/gpu/drm/mgag200/mgag200_ttm.c @@ -36,6 +36,35 @@ mgag200_bdev(struct ttm_bo_device *bd) return container_of(bd, struct mga_device, ttm.bdev); } +static int mgag200_ttm_global_init(struct mga_device *ast) +{ + struct drm_global_reference *global_ref; + int r; + + global_ref = &ast->ttm.bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + return r; + } + return 0; +} + +static void +mgag200_ttm_global_release(struct mga_device *ast) +{ + if (ast->ttm.bo_global_ref.ref.release == NULL) + return; + + drm_global_item_unref(&ast->ttm.bo_global_ref.ref); + ast->ttm.bo_global_ref.ref.release = NULL; +} + + static void mgag200_bo_ttm_destroy(struct ttm_buffer_object *tbo) { struct mgag200_bo *bo; @@ -175,7 +204,12 @@ int mgag200_mm_init(struct mga_device *mdev) struct drm_device *dev = mdev->dev; struct ttm_bo_device *bdev = &mdev->ttm.bdev; + ret = mgag200_ttm_global_init(mdev); + if (ret) + return ret; + ret = ttm_bo_device_init(&mdev->ttm.bdev, + mdev->ttm.bo_global_ref.ref.object, &mgag200_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -206,6 +240,8 @@ void mgag200_mm_fini(struct mga_device *mdev) ttm_bo_device_release(&mdev->ttm.bdev); + mgag200_ttm_global_release(mdev); + arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0), pci_resource_len(dev->pdev, 0)); arch_phys_wc_del(mdev->fb_mtrr); diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index d20b9ba4b1c1..0f3bb1a11fc9 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -146,6 +146,7 @@ struct nouveau_drm { /* TTM interface support */ struct { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; atomic_t validate_sequence; int (*move)(struct nouveau_channel *, diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c index 1543c2f8d3d3..69448b02649e 100644 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c @@ -174,6 +174,38 @@ nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma) return ttm_bo_mmap(filp, vma, &drm->ttm.bdev); } +int +nouveau_ttm_global_init(struct nouveau_drm *drm) +{ + struct drm_global_reference *global_ref; + int ret; + + global_ref = &drm->ttm.bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + + ret = drm_global_item_ref(global_ref); + if (unlikely(ret != 0)) { + DRM_ERROR("Failed setting up TTM BO subsystem\n"); + drm->ttm.bo_global_ref.ref.release = NULL; + return ret; + } + + return 0; +} + +void +nouveau_ttm_global_release(struct nouveau_drm *drm) +{ + if (drm->ttm.bo_global_ref.ref.release == NULL) + return; + + drm_global_item_unref(&drm->ttm.bo_global_ref.ref); + drm->ttm.bo_global_ref.ref.release = NULL; +} + static int nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind) { @@ -236,7 +268,12 @@ nouveau_ttm_init(struct nouveau_drm *drm) drm->agp.cma = pci->agp.cma; } + ret = nouveau_ttm_global_init(drm); + if (ret) + return ret; + ret = ttm_bo_device_init(&drm->ttm.bdev, + drm->ttm.bo_global_ref.ref.object, &nouveau_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -291,6 +328,8 @@ nouveau_ttm_fini(struct nouveau_drm *drm) ttm_bo_device_release(&drm->ttm.bdev); + nouveau_ttm_global_release(drm); + arch_phys_wc_del(drm->ttm.mtrr); drm->ttm.mtrr = 0; arch_io_free_memtype_wc(device->func->resource_addr(device, 1), diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h index 13a0254b59a1..ac9374028b7d 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.h +++ b/drivers/gpu/drm/qxl/qxl_drv.h @@ -126,6 +126,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; + bool mem_global_referenced; struct ttm_bo_device bdev; }; diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c index 886f61e94f24..b7c4eb3bd179 100644 --- a/drivers/gpu/drm/qxl/qxl_ttm.c +++ b/drivers/gpu/drm/qxl/qxl_ttm.c @@ -46,6 +46,34 @@ static struct qxl_device *qxl_get_qdev(struct ttm_bo_device *bdev) return qdev; } +static int qxl_ttm_global_init(struct qxl_device *qdev) +{ + struct drm_global_reference *global_ref; + int r; + + 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); + if (r != 0) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + return r; + } + + qdev->mman.mem_global_referenced = true; + return 0; +} + +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); + qdev->mman.mem_global_referenced = false; + } +} + static struct vm_operations_struct qxl_ttm_vm_ops; static const struct vm_operations_struct *ttm_vm_ops; @@ -316,8 +344,12 @@ int qxl_ttm_init(struct qxl_device *qdev) int r; int num_io_pages; /* != rom->num_io_pages, we include surface0 */ + r = qxl_ttm_global_init(qdev); + if (r) + 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, &qxl_bo_driver, qdev->ddev.anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, 0); @@ -353,6 +385,7 @@ void qxl_ttm_fini(struct qxl_device *qdev) ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_VRAM); ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_PRIV); ttm_bo_device_release(&qdev->mman.bdev); + qxl_ttm_global_fini(qdev); DRM_INFO("qxl: ttm finalized\n"); } diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 32808e50be12..06fb952b6290 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -448,7 +448,9 @@ struct radeon_surface_reg { * TTM. */ struct radeon_mman { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; + bool mem_global_referenced; bool initialized; #if defined(CONFIG_DEBUG_FS) diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 9920a6fc11bf..2104429ddbac 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -60,6 +60,39 @@ static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev) return rdev; } + +/* + * Global memory. + */ +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.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"); + return r; + } + + rdev->mman.mem_global_referenced = true; + return 0; +} + +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); + rdev->mman.mem_global_referenced = false; + } +} + static int radeon_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) { return 0; @@ -788,8 +821,13 @@ int radeon_ttm_init(struct radeon_device *rdev) { int r; + r = radeon_ttm_global_init(rdev); + if (r) { + return r; + } /* 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, &radeon_bo_driver, rdev->ddev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, @@ -861,6 +899,7 @@ void radeon_ttm_fini(struct radeon_device *rdev) ttm_bo_clean_mm(&rdev->mman.bdev, TTM_PL_TT); ttm_bo_device_release(&rdev->mman.bdev); radeon_gart_fini(rdev); + radeon_ttm_global_fini(rdev); rdev->mman.initialized = false; DRM_INFO("radeon: ttm finalized\n"); } diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 0ec08394e17a..57c89161b5c6 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1530,7 +1530,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj) __free_page(glob->dummy_read_page); } -static void ttm_bo_global_release(void) +void ttm_bo_global_release(void) { struct ttm_bo_global *glob = &ttm_bo_glob; @@ -1544,8 +1544,9 @@ static void ttm_bo_global_release(void) out: mutex_unlock(&ttm_global_mutex); } +EXPORT_SYMBOL(ttm_bo_global_release); -static int ttm_bo_global_init(void) +int ttm_bo_global_init(void) { struct ttm_bo_global *glob = &ttm_bo_glob; int ret = 0; @@ -1582,6 +1583,8 @@ static int ttm_bo_global_init(void) mutex_unlock(&ttm_global_mutex); return ret; } +EXPORT_SYMBOL(ttm_bo_global_init); + int ttm_bo_device_release(struct ttm_bo_device *bdev) { @@ -1620,25 +1623,18 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev) drm_vma_offset_manager_destroy(&bdev->vma_manager); - if (!ret) - ttm_bo_global_release(); - return ret; } EXPORT_SYMBOL(ttm_bo_device_release); int ttm_bo_device_init(struct ttm_bo_device *bdev, + struct ttm_bo_global *glob, struct ttm_bo_driver *driver, struct address_space *mapping, uint64_t file_page_offset, bool need_dma32) { - struct ttm_bo_global *glob = &ttm_bo_glob; - int ret; - - ret = ttm_bo_global_init(); - if (ret) - return ret; + int ret = -EINVAL; bdev->driver = driver; @@ -1665,7 +1661,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, return 0; out_no_sys: - ttm_bo_global_release(); return ret; } EXPORT_SYMBOL(ttm_bo_device_init); diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 0c15000f926e..74628b5cf4e2 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -145,6 +145,8 @@ struct virtio_gpu_fbdev { }; struct virtio_gpu_mman { + struct ttm_bo_global_ref bo_global_ref; + bool mem_global_referenced; struct ttm_bo_device bdev; }; diff --git a/drivers/gpu/drm/virtio/virtgpu_ttm.c b/drivers/gpu/drm/virtio/virtgpu_ttm.c index 4bfbf25fabff..5fecf55ff1ce 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ttm.c +++ b/drivers/gpu/drm/virtio/virtgpu_ttm.c @@ -50,6 +50,35 @@ virtio_gpu_device *virtio_gpu_get_vgdev(struct ttm_bo_device *bdev) return vgdev; } +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.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"); + return r; + } + + vgdev->mman.mem_global_referenced = true; + return 0; +} + +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); + vgdev->mman.mem_global_referenced = false; + } +} + int virtio_gpu_mmap(struct file *filp, struct vm_area_struct *vma) { struct drm_file *file_priv; @@ -326,8 +355,12 @@ int virtio_gpu_ttm_init(struct virtio_gpu_device *vgdev) { int r; + r = virtio_gpu_ttm_global_init(vgdev); + if (r) + 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, &virtio_gpu_bo_driver, vgdev->ddev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, 0); @@ -346,11 +379,13 @@ int virtio_gpu_ttm_init(struct virtio_gpu_device *vgdev) err_mm_init: ttm_bo_device_release(&vgdev->mman.bdev); err_dev_init: + virtio_gpu_ttm_global_fini(vgdev); return r; } void virtio_gpu_ttm_fini(struct virtio_gpu_device *vgdev) { ttm_bo_device_release(&vgdev->mman.bdev); + virtio_gpu_ttm_global_fini(vgdev); DRM_INFO("virtio_gpu: ttm finalized\n"); } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index 7ef5dcb06104..e24d9771e056 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -785,6 +785,11 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) DRM_INFO("MMIO at 0x%08x size is %u kiB\n", dev_priv->mmio_start, dev_priv->mmio_size / 1024); + ret = vmw_ttm_global_init(dev_priv); + if (unlikely(ret != 0)) + goto out_err0; + + vmw_master_init(&dev_priv->fbdev_master); ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM); dev_priv->active_master = &dev_priv->fbdev_master; @@ -795,7 +800,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) if (unlikely(dev_priv->mmio_virt == NULL)) { ret = -ENOMEM; DRM_ERROR("Failed mapping MMIO.\n"); - goto out_err0; + goto out_err3; } /* Need mmio memory to check for fifo pitchlock cap. */ @@ -849,6 +854,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, &vmw_bo_driver, dev->anon_inode->i_mapping, VMWGFX_FILE_PAGE_OFFSET, @@ -970,6 +976,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) ttm_object_device_release(&dev_priv->tdev); out_err4: memunmap(dev_priv->mmio_virt); +out_err3: + vmw_ttm_global_release(dev_priv); out_err0: for (i = vmw_res_context; i < vmw_res_max; ++i) idr_destroy(&dev_priv->res_idr[i]); @@ -1021,6 +1029,7 @@ static void vmw_driver_unload(struct drm_device *dev) memunmap(dev_priv->mmio_virt); if (dev_priv->ctx.staged_bindings) vmw_binding_state_free(dev_priv->ctx.staged_bindings); + vmw_ttm_global_release(dev_priv); for (i = vmw_res_context; i < vmw_res_max; ++i) idr_destroy(&dev_priv->res_idr[i]); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index cd607ba9c2fe..7a3c64bd82b3 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -417,6 +417,7 @@ enum { struct vmw_private { struct ttm_bo_device bdev; + struct ttm_bo_global_ref bo_global_ref; struct vmw_fifo_state fifo; @@ -832,6 +833,8 @@ extern int vmw_fifo_flush(struct vmw_private *dev_priv, * TTM glue - vmwgfx_ttm_glue.c */ +extern int vmw_ttm_global_init(struct vmw_private *dev_priv); +extern void vmw_ttm_global_release(struct vmw_private *dev_priv); extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma); extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv, diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c index e6d75e377dd8..8e3203766882 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c @@ -78,3 +78,30 @@ void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv, size_t gran) vvm->unreserve_mem = vmw_vmt_unreserve; vvm->gran = gran; } + +int vmw_ttm_global_init(struct vmw_private *dev_priv) +{ + struct drm_global_reference *global_ref; + int ret; + + global_ref = &dev_priv->bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + ret = drm_global_item_ref(global_ref); + + if (unlikely(ret != 0)) { + DRM_ERROR("Failed setting up TTM buffer objects.\n"); + goto out_no_bo; + } + + return 0; +out_no_bo: + return ret; +} + +void vmw_ttm_global_release(struct vmw_private *dev_priv) +{ + drm_global_item_unref(&dev_priv->bo_global_ref.ref); +} diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h index aa40e5cc2861..24e54d5dda6b 100644 --- a/drivers/staging/vboxvideo/vbox_drv.h +++ b/drivers/staging/vboxvideo/vbox_drv.h @@ -79,6 +79,7 @@ struct vbox_private { int fb_mtrr; struct { + struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; diff --git a/drivers/staging/vboxvideo/vbox_ttm.c b/drivers/staging/vboxvideo/vbox_ttm.c index 30f270027acf..ceacbc1d3ff7 100644 --- a/drivers/staging/vboxvideo/vbox_ttm.c +++ b/drivers/staging/vboxvideo/vbox_ttm.c @@ -16,6 +16,37 @@ static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) return container_of(bd, struct vbox_private, ttm.bdev); } +/** + * Adds the vbox memory manager object/structures to the global memory manager. + */ +static int vbox_ttm_global_init(struct vbox_private *vbox) +{ + struct drm_global_reference *global_ref; + int ret; + + global_ref = &vbox->ttm.bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + + ret = drm_global_item_ref(global_ref); + if (ret) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + return ret; + } + + return 0; +} + +/** + * Removes the vbox memory manager object from the global memory manager. + */ +static void vbox_ttm_global_release(struct vbox_private *vbox) +{ + drm_global_item_unref(&vbox->ttm.bo_global_ref.ref); +} + static void vbox_bo_ttm_destroy(struct ttm_buffer_object *tbo) { struct vbox_bo *bo; @@ -153,13 +184,18 @@ int vbox_mm_init(struct vbox_private *vbox) struct drm_device *dev = &vbox->ddev; struct ttm_bo_device *bdev = &vbox->ttm.bdev; + ret = vbox_ttm_global_init(vbox); + if (ret) + return ret; + ret = ttm_bo_device_init(&vbox->ttm.bdev, + vbox->ttm.bo_global_ref.ref.object, &vbox_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET, true); if (ret) { DRM_ERROR("Error initialising bo driver; %d\n", ret); - return ret; + goto err_ttm_global_release; } ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, @@ -181,6 +217,8 @@ int vbox_mm_init(struct vbox_private *vbox) err_device_release: ttm_bo_device_release(&vbox->ttm.bdev); +err_ttm_global_release: + vbox_ttm_global_release(vbox); return ret; } @@ -194,6 +232,7 @@ void vbox_mm_fini(struct vbox_private *vbox) arch_phys_wc_del(vbox->fb_mtrr); #endif ttm_bo_device_release(&vbox->ttm.bdev); + vbox_ttm_global_release(vbox); } void vbox_ttm_placement(struct vbox_bo *bo, int domain) diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 6fb589f64633..26be74939f10 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -569,6 +569,9 @@ void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); +void ttm_bo_global_release(void); +int ttm_bo_global_init(void); + int ttm_bo_device_release(struct ttm_bo_device *bdev); /** @@ -586,7 +589,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev); * Returns: * !0: Failure. */ -int ttm_bo_device_init(struct ttm_bo_device *bdev, +int ttm_bo_device_init(struct ttm_bo_device *bdev, struct ttm_bo_global *glob, struct ttm_bo_driver *driver, struct address_space *mapping, uint64_t file_page_offset, bool need_dma32); @@ -885,4 +888,40 @@ 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; +}; + +/** + * 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) +{ + return ttm_bo_global_init(); +} + +/** + * 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(); +} + #endif From patchwork Tue Apr 16 00:35:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Herbst X-Patchwork-Id: 10901769 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 A37051515 for ; Tue, 16 Apr 2019 00:35:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CE6328958 for ; Tue, 16 Apr 2019 00:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8112628961; Tue, 16 Apr 2019 00:35:57 +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 3DEFD28958 for ; Tue, 16 Apr 2019 00:35:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2754789791; Tue, 16 Apr 2019 00:35:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7F4FA89650 for ; Tue, 16 Apr 2019 00:35:33 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id r4so24305739wrq.8 for ; Mon, 15 Apr 2019 17:35:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wJn0UhB3bPLMSz89xNiL5AQvj47M7O2b3KzzdMx/idM=; b=eenL0dGDBup6aZ68DS3iHymmxJ/5Qi6VaQJKIytHmOV7OH/pKuIusMAVXKrZay/n1A TprTIbtTdRNPDvoXTlxjwARpQpgY5q3A9vfBfFwnUZuc0KvqjoRMvjnArxif0WkTzzUH ZJsvuLLuyrQXyyrhsXYOugFztasqfFlkFjuhyePf5BUmB7/Cuh+/hGytIK2ii65TvmPf lpbUjbXmAd1L5mjpwxkDkTJHloyjcfINz92HKbou5tAy17bIzrb6HHVZ9MUR6Jhv/8bW LmpEoCSi/A6UNc4n66EMP4Sf77tz1Mv0dC/yRORHOcVVQVkAj/q25sXCSLq6tzGHmK0P hF3A== X-Gm-Message-State: APjAAAXTZvij2DLMcXKROKL3OLC2OeuExfbeSIgwWgwJf1jCzEB7v58C iQx2uFSx6cc6qybhASwHYF6xJwAQev4= X-Google-Smtp-Source: APXvYqwZk3Qkz+6mGp/p2Tuc8KaWF4gX0Z2oHMzjxlPc1S/gEdG4IeTGYwvj9ocWKVcI3xxQTDcShg== X-Received: by 2002:a5d:458f:: with SMTP id p15mr48796094wrq.188.1555374931783; Mon, 15 Apr 2019 17:35:31 -0700 (PDT) Received: from kherbst.pingu.com ([2a02:8308:b0be:6900:a1ae:358d:6041:7470]) by smtp.gmail.com with ESMTPSA id w2sm38801268wrm.74.2019.04.15.17.35.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 17:35:30 -0700 (PDT) From: Karol Herbst To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/6] Revert "drm/ttm: Fix bo_global and mem_global kfree error" Date: Tue, 16 Apr 2019 02:35:20 +0200 Message-Id: <20190416003523.5069-4-kherbst@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com> References: <20190416003523.5069-1-kherbst@redhat.com> 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: Alex Deucher , Karol Herbst Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 30f33126feca0fe16df9e9302ffc28a953e2eb37. Signed-off-by: Karol Herbst --- drivers/gpu/drm/ttm/ttm_bo.c | 1 + drivers/gpu/drm/ttm/ttm_memory.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 57c89161b5c6..6941562ef2fa 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1528,6 +1528,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj) container_of(kobj, struct ttm_bo_global, kobj); __free_page(glob->dummy_read_page); + kfree(glob); } void ttm_bo_global_release(void) diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index f1567c353b54..7704e17c402f 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -219,6 +219,14 @@ static ssize_t ttm_mem_global_store(struct kobject *kobj, return size; } +static void ttm_mem_global_kobj_release(struct kobject *kobj) +{ + struct ttm_mem_global *glob = + container_of(kobj, struct ttm_mem_global, kobj); + + kfree(glob); +} + static struct attribute *ttm_mem_global_attrs[] = { &ttm_mem_global_lower_mem_limit, NULL @@ -230,6 +238,7 @@ static const struct sysfs_ops ttm_mem_global_ops = { }; static struct kobj_type ttm_mem_glob_kobj_type = { + .release = &ttm_mem_global_kobj_release, .sysfs_ops = &ttm_mem_global_ops, .default_attrs = ttm_mem_global_attrs, }; From patchwork Tue Apr 16 00:35:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Herbst X-Patchwork-Id: 10901763 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 ADD431800 for ; Tue, 16 Apr 2019 00:35:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9670628958 for ; Tue, 16 Apr 2019 00:35:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AE5128961; Tue, 16 Apr 2019 00:35:41 +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 322C628958 for ; Tue, 16 Apr 2019 00:35:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BB7B1896A3; Tue, 16 Apr 2019 00:35:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C65E89688 for ; Tue, 16 Apr 2019 00:35:34 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id q1so24376228wrp.0 for ; Mon, 15 Apr 2019 17:35:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wGObAQcYJ+O0NlolEVMOWXW81hMWX6w2HalvCHEr3o8=; b=Lda6ANNtwLY+VgzfTVZA9DM5CRoQCTxQGu/0ZRT7JVOl+I/lFJ4wrS8lXIREdbf7/F Q52Lf09XIHtiWQTfBgCrporlB5TIlhTWgEL0lbhZaerVCp45dTsz72E7b62leQ2MqGSj gaNwP0wqtOVZ/Ell6f8XLtXE6F3tnjI1xwp1Dx2UU9Ftmqqcdkl14ZHgJm2VymmRWFwb eai4IhLVLHXQJcvfFp+LbZ2ZCRzS1JdsfcLViGnGqMRKnwFSdh2GH+9spW2VpBNqlFiv Bq6dc4fHalykEeXtdw3GlOkIjKd8U7FHo1UOwt+zMjYM6CIZ6sQmv9msnq2lyu7gyzXj fGkg== X-Gm-Message-State: APjAAAXICaXEvOG/GmDYTNFy06l3WhFhC3otXDhfHnmsbQOaNLNAkR1c suhH6pJDFIglpeKxJbCkw5l9toqcEGs= X-Google-Smtp-Source: APXvYqzDhSd9cE0j1ziXbuYV8mP1ky1Kdfn+eSCz+tVbdKGdOvmbruvEFjAP3Nd9Lj9HsUvuDSiwyw== X-Received: by 2002:a5d:4750:: with SMTP id o16mr45696602wrs.206.1555374933132; Mon, 15 Apr 2019 17:35:33 -0700 (PDT) Received: from kherbst.pingu.com ([2a02:8308:b0be:6900:a1ae:358d:6041:7470]) by smtp.gmail.com with ESMTPSA id w2sm38801268wrm.74.2019.04.15.17.35.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 17:35:32 -0700 (PDT) From: Karol Herbst To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/6] Revert "drm/ttm: use a static ttm_bo_global instance" Date: Tue, 16 Apr 2019 02:35:21 +0200 Message-Id: <20190416003523.5069-5-kherbst@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com> References: <20190416003523.5069-1-kherbst@redhat.com> 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: Alex Deucher , Karol Herbst Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 62b53b37e4b1500d4eb4624a44ad861cf8d3cd18. Signed-off-by: Karol Herbst --- drivers/gpu/drm/ttm/ttm_bo.c | 31 ++++++++----------------------- include/drm/ttm/ttm_bo_driver.h | 15 +++++++-------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 6941562ef2fa..c0efe4c89baf 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -49,9 +49,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj); * ttm_global_mutex - protecting the global BO state */ DEFINE_MUTEX(ttm_global_mutex); -struct ttm_bo_global ttm_bo_glob = { - .use_count = 0 -}; static struct attribute ttm_bo_count = { .name = "bo_count", @@ -1531,35 +1528,22 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj) kfree(glob); } -void ttm_bo_global_release(void) +void ttm_bo_global_release(struct ttm_bo_global *glob) { - struct ttm_bo_global *glob = &ttm_bo_glob; - - mutex_lock(&ttm_global_mutex); - if (--glob->use_count > 0) - goto out; - kobject_del(&glob->kobj); kobject_put(&glob->kobj); ttm_mem_global_release(&ttm_mem_glob); -out: - mutex_unlock(&ttm_global_mutex); } EXPORT_SYMBOL(ttm_bo_global_release); -int ttm_bo_global_init(void) +int ttm_bo_global_init(struct ttm_bo_global *glob) { - struct ttm_bo_global *glob = &ttm_bo_glob; - int ret = 0; + int ret; unsigned i; - mutex_lock(&ttm_global_mutex); - if (++glob->use_count > 1) - goto out; - ret = ttm_mem_global_init(&ttm_mem_glob); if (ret) - goto out; + return ret; spin_lock_init(&glob->lru_lock); glob->mem_glob = &ttm_mem_glob; @@ -1568,7 +1552,7 @@ int ttm_bo_global_init(void) if (unlikely(glob->dummy_read_page == NULL)) { ret = -ENOMEM; - goto out; + goto out_no_drp; } for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) @@ -1580,8 +1564,9 @@ int ttm_bo_global_init(void) &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); if (unlikely(ret != 0)) kobject_put(&glob->kobj); -out: - mutex_unlock(&ttm_global_mutex); + return ret; +out_no_drp: + kfree(glob); return ret; } EXPORT_SYMBOL(ttm_bo_global_init); diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 26be74939f10..9cec8835b88f 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -398,7 +398,7 @@ struct ttm_bo_driver { * @swap_lru: Lru list of buffer objects used for swapping. */ -extern struct ttm_bo_global { +struct ttm_bo_global { /** * Constant after init. @@ -410,9 +410,8 @@ extern struct ttm_bo_global { spinlock_t lru_lock; /** - * Protected by ttm_global_mutex. + * Protected by device_list_mutex. */ - unsigned int use_count; struct list_head device_list; /** @@ -424,7 +423,7 @@ extern struct ttm_bo_global { * Internal protection. */ atomic_t bo_count; -} ttm_bo_glob; +}; #define TTM_NUM_MEM_TYPES 8 @@ -569,8 +568,8 @@ void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); -void ttm_bo_global_release(void); -int ttm_bo_global_init(void); +void ttm_bo_global_release(struct ttm_bo_global *glob); +int ttm_bo_global_init(struct ttm_bo_global *glob); int ttm_bo_device_release(struct ttm_bo_device *bdev); @@ -907,7 +906,7 @@ struct ttm_bo_global_ref { */ static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) { - return ttm_bo_global_init(); + return ttm_bo_global_init(ref->object); } /** @@ -921,7 +920,7 @@ static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) */ static inline void ttm_bo_global_ref_release(struct drm_global_reference *ref) { - ttm_bo_global_release(); + ttm_bo_global_release(ref->object); } #endif From patchwork Tue Apr 16 00:35:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Herbst X-Patchwork-Id: 10901765 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 4F947922 for ; Tue, 16 Apr 2019 00:35:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39CAA28958 for ; Tue, 16 Apr 2019 00:35:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E99B28961; Tue, 16 Apr 2019 00:35:43 +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 DEE5928958 for ; Tue, 16 Apr 2019 00:35:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E75C8970E; Tue, 16 Apr 2019 00:35:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 886B589690 for ; Tue, 16 Apr 2019 00:35:36 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id q16so22896678wmj.3 for ; Mon, 15 Apr 2019 17:35:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7oKMEwgvFIAA8GcaSq9cBzivjNSmOSwXh+MwWZJ0IxA=; b=TuvPWWvJSlLj2GWp6ZVCBzdf4HbPCRaPt+eJB6UbUQoznPpb8Ji711mzKdpwRpMGN2 AOXknGz54KLFgAvBU41cMmvz2cujhqtSWHV5BnQtVgjfHHi8wtK9KvLPSteWbTM6+1Mq CC0etLkGAm4wZsnl4Ha0J9FTKNvfwLoelHoBzUggbQNcgg0vjfNXny85UR4ur81zqgOm K7Gmm1MeI4/KJczEnRYmXcIWgOpvuNXAMF1aScoHj7zZomYpQTGJ5TruxxeFRoImTlGu xgYlYnynmAVVC291ICrWMMESh4GxDyWhSQe5LmV15U/A+drHy5+Yl6bTWxjMlh0GrQa1 7PKg== X-Gm-Message-State: APjAAAUIk8dOHR4Byl8BPJs/fmayZtEV1jGTKEg8kjccla1oba6DL+WL msGkuPiUZ3ymyXQrN54bORypsvLolXM= X-Google-Smtp-Source: APXvYqyi4AZ3Eb6gDe7XsHLJwrh4ZT5yYHj3bCorTFDiCFpq9WJAvXBECMm+i9cw9M1LOt7Lzj8S1g== X-Received: by 2002:a7b:c923:: with SMTP id h3mr539338wml.34.1555374934828; Mon, 15 Apr 2019 17:35:34 -0700 (PDT) Received: from kherbst.pingu.com ([2a02:8308:b0be:6900:a1ae:358d:6041:7470]) by smtp.gmail.com with ESMTPSA id w2sm38801268wrm.74.2019.04.15.17.35.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 17:35:33 -0700 (PDT) From: Karol Herbst To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/6] Revert "drm/ttm: make the device list mutex static" Date: Tue, 16 Apr 2019 02:35:22 +0200 Message-Id: <20190416003523.5069-6-kherbst@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com> References: <20190416003523.5069-1-kherbst@redhat.com> 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: Alex Deucher , Karol Herbst Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 56b3d20413587fab6a790cfc8bc075ca94bc8ed9. Signed-off-by: Karol Herbst --- drivers/gpu/drm/ttm/ttm_bo.c | 14 +++++--------- include/drm/ttm/ttm_bo_driver.h | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index c0efe4c89baf..99322c3d6573 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -45,11 +45,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj); -/** - * ttm_global_mutex - protecting the global BO state - */ -DEFINE_MUTEX(ttm_global_mutex); - static struct attribute ttm_bo_count = { .name = "bo_count", .mode = S_IRUGO @@ -1545,6 +1540,7 @@ int ttm_bo_global_init(struct ttm_bo_global *glob) if (ret) return ret; + mutex_init(&glob->device_list_mutex); spin_lock_init(&glob->lru_lock); glob->mem_glob = &ttm_mem_glob; glob->mem_glob->bo_glob = glob; @@ -1592,9 +1588,9 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev) } } - mutex_lock(&ttm_global_mutex); + mutex_lock(&glob->device_list_mutex); list_del(&bdev->device_list); - mutex_unlock(&ttm_global_mutex); + mutex_unlock(&glob->device_list_mutex); cancel_delayed_work_sync(&bdev->wq); @@ -1641,9 +1637,9 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, bdev->dev_mapping = mapping; bdev->glob = glob; bdev->need_dma32 = need_dma32; - mutex_lock(&ttm_global_mutex); + mutex_lock(&glob->device_list_mutex); list_add_tail(&bdev->device_list, &glob->device_list); - mutex_unlock(&ttm_global_mutex); + mutex_unlock(&glob->device_list_mutex); return 0; out_no_sys: diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 9cec8835b88f..4ae6fc33f761 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -407,6 +407,7 @@ struct ttm_bo_global { struct kobject kobj; struct ttm_mem_global *mem_glob; struct page *dummy_read_page; + struct mutex device_list_mutex; spinlock_t lru_lock; /** From patchwork Tue Apr 16 00:35:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Herbst X-Patchwork-Id: 10901767 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 1C097922 for ; Tue, 16 Apr 2019 00:35:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2F5528958 for ; Tue, 16 Apr 2019 00:35:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E730428961; Tue, 16 Apr 2019 00:35:46 +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 3159D28958 for ; Tue, 16 Apr 2019 00:35:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AFE288972D; Tue, 16 Apr 2019 00:35:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id B15A089690 for ; Tue, 16 Apr 2019 00:35:38 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id z24so22870489wmi.5 for ; Mon, 15 Apr 2019 17:35:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pBKcbZV7+8rNWGlffQndfUF0mA3rsjt41NuQUQ8a/e8=; b=tK+Dw6FP0NvcsR5tUcFDlNip9Wgt8edVz3E/34vRIvYOCYN1+rx5AQMnyKEJrzbC2i AKAcaYYRoR78MIJe3Ywx3Ekb1RLDII9fwLLUhLdhorEAB+Iih2O9qLEcL0UKkY7DUI2q LBBaVI9z0i6QzCZK0lwlKkxmfetvJX+L26f2JHm6iwYbzUFlR/addx/G3te647aKpQiE r4sWEZYf2gmY873XWNcOJgm1Y400UAxD4ltG4GGaEsjIJH29wuobDxhkPxquq7ToLU95 +8JwFevmUptiUK1m7QAGmYvf2U4kS1+tkQNcCKGSKkhqbot4fIgeuh6ZAyTjcKeYuMSe Dkbg== X-Gm-Message-State: APjAAAXGe9/JTx2PSTFYDgQFjBk1iV/axLDhlqAePdOKouZtjswHgueb 9Ed41b0xGPnAj9nG9w+Xq5XbkZnSFY8= X-Google-Smtp-Source: APXvYqxCwTxim+kft8vY0cL5zPNJvv7pjzwWRnKvfcqz1/f3qmHAGwf8BhcWa0Q+L19JEkr7YBu/1g== X-Received: by 2002:a1c:a711:: with SMTP id q17mr24859907wme.111.1555374936582; Mon, 15 Apr 2019 17:35:36 -0700 (PDT) Received: from kherbst.pingu.com ([2a02:8308:b0be:6900:a1ae:358d:6041:7470]) by smtp.gmail.com with ESMTPSA id w2sm38801268wrm.74.2019.04.15.17.35.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 17:35:35 -0700 (PDT) From: Karol Herbst To: dri-devel@lists.freedesktop.org Subject: [PATCH 6/6] Revert "drm/ttm: use a static ttm_mem_global instance" Date: Tue, 16 Apr 2019 02:35:23 +0200 Message-Id: <20190416003523.5069-7-kherbst@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416003523.5069-1-kherbst@redhat.com> References: <20190416003523.5069-1-kherbst@redhat.com> 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: Alex Deucher , Karol Herbst Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 27eb1fa9130a98edd2b321d4dbce5c8b244ee7af. Signed-off-by: Karol Herbst --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 44 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_ttm.c | 32 +++++++++++++- drivers/gpu/drm/bochs/bochs.h | 1 + drivers/gpu/drm/bochs/bochs_mm.c | 30 ++++++++++++- drivers/gpu/drm/cirrus/cirrus_drv.h | 1 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 32 +++++++++++++- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 1 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 31 +++++++++++-- drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 32 +++++++++++++- drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 34 ++++++++++++-- drivers/gpu/drm/qxl/qxl_drv.h | 1 + drivers/gpu/drm/qxl/qxl_ttm.c | 28 ++++++++++++ drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_ttm.c | 26 +++++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 10 ++--- drivers/gpu/drm/ttm/ttm_memory.c | 5 +-- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 27 ++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 27 ++++++++++++ drivers/staging/vboxvideo/vbox_drv.h | 1 + drivers/staging/vboxvideo/vbox_ttm.c | 24 ++++++++++ include/drm/ttm/ttm_bo_driver.h | 8 +++- include/drm/ttm/ttm_memory.h | 4 +- 29 files changed, 380 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 213d29d0ad80..d76895c7b0ef 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -65,6 +65,33 @@ 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. * @@ -81,6 +108,20 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev) /* 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); + 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); @@ -99,6 +140,8 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev) return 0; error_bo: + drm_global_item_unref(&adev->mman.mem_global_ref); +error_mem: return r; } @@ -107,6 +150,7 @@ 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); adev->mman.mem_global_referenced = false; } } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h index e114f209b701..fe8f276e9811 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h @@ -40,6 +40,7 @@ struct amdgpu_mman { struct ttm_bo_global_ref bo_global_ref; + struct drm_global_reference mem_global_ref; struct ttm_bo_device bdev; bool mem_global_referenced; bool initialized; diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h index 6ae11a477643..e6c4cd3dc50e 100644 --- a/drivers/gpu/drm/ast/ast_drv.h +++ b/drivers/gpu/drm/ast/ast_drv.h @@ -104,6 +104,7 @@ struct ast_private { int fb_mtrr; struct { + struct drm_global_reference mem_global_ref; struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c index 8a59d6fc1160..d21fbd26785a 100644 --- a/drivers/gpu/drm/ast/ast_ttm.c +++ b/drivers/gpu/drm/ast/ast_ttm.c @@ -36,11 +36,37 @@ ast_bdev(struct ttm_bo_device *bd) return container_of(bd, struct ast_private, ttm.bdev); } +static int +ast_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void +ast_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + static int ast_ttm_global_init(struct ast_private *ast) { struct drm_global_reference *global_ref; int r; + global_ref = &ast->ttm.mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &ast_ttm_mem_global_init; + global_ref->release = &ast_ttm_mem_global_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM memory accounting " + "subsystem.\n"); + return r; + } + + ast->ttm.bo_global_ref.mem_glob = + ast->ttm.mem_global_ref.object; global_ref = &ast->ttm.bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -49,6 +75,7 @@ static int ast_ttm_global_init(struct ast_private *ast) r = drm_global_item_ref(global_ref); if (r != 0) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&ast->ttm.mem_global_ref); return r; } return 0; @@ -57,11 +84,12 @@ static int ast_ttm_global_init(struct ast_private *ast) static void ast_ttm_global_release(struct ast_private *ast) { - if (ast->ttm.bo_global_ref.ref.release == NULL) + if (ast->ttm.mem_global_ref.release == NULL) return; drm_global_item_unref(&ast->ttm.bo_global_ref.ref); - ast->ttm.bo_global_ref.ref.release = NULL; + drm_global_item_unref(&ast->ttm.mem_global_ref); + ast->ttm.mem_global_ref.release = NULL; } diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h index c1d88ea6b419..577a8b917cb9 100644 --- a/drivers/gpu/drm/bochs/bochs.h +++ b/drivers/gpu/drm/bochs/bochs.h @@ -77,6 +77,7 @@ struct bochs_device { /* ttm */ struct { + struct drm_global_reference mem_global_ref; struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; bool initialized; diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c index cad65774a973..ff4f41dec228 100644 --- a/drivers/gpu/drm/bochs/bochs_mm.c +++ b/drivers/gpu/drm/bochs/bochs_mm.c @@ -16,11 +16,35 @@ static inline struct bochs_device *bochs_bdev(struct ttm_bo_device *bd) return container_of(bd, struct bochs_device, ttm.bdev); } +static int bochs_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void bochs_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + static int bochs_ttm_global_init(struct bochs_device *bochs) { struct drm_global_reference *global_ref; int r; + global_ref = &bochs->ttm.mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &bochs_ttm_mem_global_init; + global_ref->release = &bochs_ttm_mem_global_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM memory accounting " + "subsystem.\n"); + return r; + } + + bochs->ttm.bo_global_ref.mem_glob = + bochs->ttm.mem_global_ref.object; global_ref = &bochs->ttm.bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -29,6 +53,7 @@ static int bochs_ttm_global_init(struct bochs_device *bochs) r = drm_global_item_ref(global_ref); if (r != 0) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&bochs->ttm.mem_global_ref); return r; } @@ -37,11 +62,12 @@ static int bochs_ttm_global_init(struct bochs_device *bochs) static void bochs_ttm_global_release(struct bochs_device *bochs) { - if (bochs->ttm.bo_global_ref.ref.release == NULL) + if (bochs->ttm.mem_global_ref.release == NULL) return; drm_global_item_unref(&bochs->ttm.bo_global_ref.ref); - bochs->ttm.bo_global_ref.ref.release = NULL; + drm_global_item_unref(&bochs->ttm.mem_global_ref); + bochs->ttm.mem_global_ref.release = NULL; } diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h index 01852fbda9da..a29f87e98d9d 100644 --- a/drivers/gpu/drm/cirrus/cirrus_drv.h +++ b/drivers/gpu/drm/cirrus/cirrus_drv.h @@ -136,6 +136,7 @@ struct cirrus_device { int fb_mtrr; struct { + struct drm_global_reference mem_global_ref; struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c index 7801c56c3c9b..2e2141f26c5b 100644 --- a/drivers/gpu/drm/cirrus/cirrus_ttm.c +++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c @@ -36,11 +36,37 @@ cirrus_bdev(struct ttm_bo_device *bd) return container_of(bd, struct cirrus_device, ttm.bdev); } +static int +cirrus_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void +cirrus_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + static int cirrus_ttm_global_init(struct cirrus_device *cirrus) { struct drm_global_reference *global_ref; int r; + global_ref = &cirrus->ttm.mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &cirrus_ttm_mem_global_init; + global_ref->release = &cirrus_ttm_mem_global_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM memory accounting " + "subsystem.\n"); + return r; + } + + cirrus->ttm.bo_global_ref.mem_glob = + cirrus->ttm.mem_global_ref.object; global_ref = &cirrus->ttm.bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -49,6 +75,7 @@ static int cirrus_ttm_global_init(struct cirrus_device *cirrus) r = drm_global_item_ref(global_ref); if (r != 0) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&cirrus->ttm.mem_global_ref); return r; } return 0; @@ -57,11 +84,12 @@ static int cirrus_ttm_global_init(struct cirrus_device *cirrus) static void cirrus_ttm_global_release(struct cirrus_device *cirrus) { - if (cirrus->ttm.bo_global_ref.ref.release == NULL) + if (cirrus->ttm.mem_global_ref.release == NULL) return; drm_global_item_unref(&cirrus->ttm.bo_global_ref.ref); - cirrus->ttm.bo_global_ref.ref.release = NULL; + drm_global_item_unref(&cirrus->ttm.mem_global_ref); + cirrus->ttm.mem_global_ref.release = NULL; } diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h index 60479502e277..45c25a488f42 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h @@ -49,6 +49,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_bo_device bdev; bool initialized; diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c index 14071c849121..0454aa43ffc6 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c @@ -29,10 +29,34 @@ 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); + 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; @@ -40,6 +64,7 @@ static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc) 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; @@ -48,11 +73,9 @@ static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc) static void hibmc_ttm_global_release(struct hibmc_drm_private *hibmc) { - if (hibmc->bo_global_ref.ref.release == NULL) - return; - drm_global_item_unref(&hibmc->bo_global_ref.ref); - hibmc->bo_global_ref.ref.release = NULL; + drm_global_item_unref(&hibmc->mem_global_ref); + hibmc->mem_global_ref.release = NULL; } static void hibmc_bo_ttm_destroy(struct ttm_buffer_object *tbo) diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index e5348955a3cc..04f1dfba12e5 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -212,6 +212,7 @@ struct mga_device { int fb_mtrr; struct { + struct drm_global_reference mem_global_ref; struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; } ttm; diff --git a/drivers/gpu/drm/mgag200/mgag200_ttm.c b/drivers/gpu/drm/mgag200/mgag200_ttm.c index 11bdc8121a7d..3444b539e7f4 100644 --- a/drivers/gpu/drm/mgag200/mgag200_ttm.c +++ b/drivers/gpu/drm/mgag200/mgag200_ttm.c @@ -36,11 +36,37 @@ mgag200_bdev(struct ttm_bo_device *bd) return container_of(bd, struct mga_device, ttm.bdev); } +static int +mgag200_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void +mgag200_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + static int mgag200_ttm_global_init(struct mga_device *ast) { struct drm_global_reference *global_ref; int r; + global_ref = &ast->ttm.mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &mgag200_ttm_mem_global_init; + global_ref->release = &mgag200_ttm_mem_global_release; + r = drm_global_item_ref(global_ref); + if (r != 0) { + DRM_ERROR("Failed setting up TTM memory accounting " + "subsystem.\n"); + return r; + } + + ast->ttm.bo_global_ref.mem_glob = + ast->ttm.mem_global_ref.object; global_ref = &ast->ttm.bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -49,6 +75,7 @@ static int mgag200_ttm_global_init(struct mga_device *ast) r = drm_global_item_ref(global_ref); if (r != 0) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&ast->ttm.mem_global_ref); return r; } return 0; @@ -57,11 +84,12 @@ static int mgag200_ttm_global_init(struct mga_device *ast) static void mgag200_ttm_global_release(struct mga_device *ast) { - if (ast->ttm.bo_global_ref.ref.release == NULL) + if (ast->ttm.mem_global_ref.release == NULL) return; drm_global_item_unref(&ast->ttm.bo_global_ref.ref); - ast->ttm.bo_global_ref.ref.release = NULL; + drm_global_item_unref(&ast->ttm.mem_global_ref); + ast->ttm.mem_global_ref.release = NULL; } diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index 0f3bb1a11fc9..0b2191fa96f7 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -146,6 +146,7 @@ struct nouveau_drm { /* TTM interface support */ struct { + struct drm_global_reference mem_global_ref; struct ttm_bo_global_ref bo_global_ref; struct ttm_bo_device bdev; atomic_t validate_sequence; diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c index 69448b02649e..a293383c8654 100644 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c @@ -174,12 +174,38 @@ nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma) return ttm_bo_mmap(filp, vma, &drm->ttm.bdev); } +static int +nouveau_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void +nouveau_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + int nouveau_ttm_global_init(struct nouveau_drm *drm) { struct drm_global_reference *global_ref; int ret; + global_ref = &drm->ttm.mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &nouveau_ttm_mem_global_init; + global_ref->release = &nouveau_ttm_mem_global_release; + + ret = drm_global_item_ref(global_ref); + if (unlikely(ret != 0)) { + DRM_ERROR("Failed setting up TTM memory accounting\n"); + drm->ttm.mem_global_ref.release = NULL; + return ret; + } + + drm->ttm.bo_global_ref.mem_glob = global_ref->object; global_ref = &drm->ttm.bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -189,7 +215,8 @@ nouveau_ttm_global_init(struct nouveau_drm *drm) ret = drm_global_item_ref(global_ref); if (unlikely(ret != 0)) { DRM_ERROR("Failed setting up TTM BO subsystem\n"); - drm->ttm.bo_global_ref.ref.release = NULL; + drm_global_item_unref(&drm->ttm.mem_global_ref); + drm->ttm.mem_global_ref.release = NULL; return ret; } @@ -199,11 +226,12 @@ nouveau_ttm_global_init(struct nouveau_drm *drm) void nouveau_ttm_global_release(struct nouveau_drm *drm) { - if (drm->ttm.bo_global_ref.ref.release == NULL) + if (drm->ttm.mem_global_ref.release == NULL) return; drm_global_item_unref(&drm->ttm.bo_global_ref.ref); - drm->ttm.bo_global_ref.ref.release = NULL; + drm_global_item_unref(&drm->ttm.mem_global_ref); + drm->ttm.mem_global_ref.release = NULL; } static int diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h index ac9374028b7d..65be4e94a998 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.h +++ b/drivers/gpu/drm/qxl/qxl_drv.h @@ -127,6 +127,7 @@ struct qxl_output { struct qxl_mman { struct ttm_bo_global_ref bo_global_ref; + struct drm_global_reference mem_global_ref; bool mem_global_referenced; struct ttm_bo_device bdev; }; diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c index b7c4eb3bd179..a86c7461cfa2 100644 --- a/drivers/gpu/drm/qxl/qxl_ttm.c +++ b/drivers/gpu/drm/qxl/qxl_ttm.c @@ -46,11 +46,37 @@ 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); @@ -59,6 +85,7 @@ static int qxl_ttm_global_init(struct qxl_device *qdev) r = drm_global_item_ref(global_ref); if (r != 0) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&qdev->mman.mem_global_ref); return r; } @@ -70,6 +97,7 @@ 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); qdev->mman.mem_global_referenced = false; } } diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 06fb952b6290..1a6f6edb3515 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -449,6 +449,7 @@ struct radeon_surface_reg { */ struct radeon_mman { struct ttm_bo_global_ref bo_global_ref; + struct drm_global_reference mem_global_ref; 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 2104429ddbac..dac4ec5a120b 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -64,12 +64,36 @@ 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); @@ -78,6 +102,7 @@ static int radeon_ttm_global_init(struct radeon_device *rdev) 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); return r; } @@ -89,6 +114,7 @@ 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); rdev->mman.mem_global_referenced = false; } } diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 99322c3d6573..48bd611027b6 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1527,22 +1527,18 @@ void ttm_bo_global_release(struct ttm_bo_global *glob) { kobject_del(&glob->kobj); kobject_put(&glob->kobj); - ttm_mem_global_release(&ttm_mem_glob); } EXPORT_SYMBOL(ttm_bo_global_release); -int ttm_bo_global_init(struct ttm_bo_global *glob) +int ttm_bo_global_init(struct ttm_bo_global *glob, + struct ttm_mem_global *mem_glob) { int ret; unsigned i; - ret = ttm_mem_global_init(&ttm_mem_glob); - if (ret) - return ret; - mutex_init(&glob->device_list_mutex); spin_lock_init(&glob->lru_lock); - glob->mem_glob = &ttm_mem_glob; + glob->mem_glob = mem_glob; glob->mem_glob->bo_glob = glob; glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32); diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index 7704e17c402f..450387c92b63 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -41,9 +41,6 @@ #define TTM_MEMORY_ALLOC_RETRIES 4 -struct ttm_mem_global ttm_mem_glob; -EXPORT_SYMBOL(ttm_mem_glob); - struct ttm_mem_zone { struct kobject kobj; struct ttm_mem_global *glob; @@ -467,6 +464,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) ttm_mem_global_release(glob); return ret; } +EXPORT_SYMBOL(ttm_mem_global_init); void ttm_mem_global_release(struct ttm_mem_global *glob) { @@ -488,6 +486,7 @@ void ttm_mem_global_release(struct ttm_mem_global *glob) kobject_del(&glob->kobj); kobject_put(&glob->kobj); } +EXPORT_SYMBOL(ttm_mem_global_release); static void ttm_check_swapping(struct ttm_mem_global *glob) { diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 74628b5cf4e2..5465d87f6629 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -146,6 +146,7 @@ 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_bo_device bdev; }; diff --git a/drivers/gpu/drm/virtio/virtgpu_ttm.c b/drivers/gpu/drm/virtio/virtgpu_ttm.c index 5fecf55ff1ce..a3e02335da18 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ttm.c +++ b/drivers/gpu/drm/virtio/virtgpu_ttm.c @@ -50,12 +50,37 @@ 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); @@ -64,6 +89,7 @@ static int virtio_gpu_ttm_global_init(struct virtio_gpu_device *vgdev) r = drm_global_item_ref(global_ref); if (r != 0) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&vgdev->mman.mem_global_ref); return r; } @@ -75,6 +101,7 @@ 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); vgdev->mman.mem_global_referenced = false; } } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index e24d9771e056..e2d33761c99f 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -812,8 +812,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) goto out_err4; } - dev_priv->tdev = ttm_object_device_init(&ttm_mem_glob, 12, - &vmw_prime_dmabuf_ops); + dev_priv->tdev = ttm_object_device_init + (dev_priv->mem_global_ref.object, 12, &vmw_prime_dmabuf_ops); if (unlikely(dev_priv->tdev == NULL)) { DRM_ERROR("Unable to initialize TTM object management.\n"); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index 7a3c64bd82b3..8d9cd8ff8deb 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -418,6 +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 vmw_fifo_state fifo; @@ -1356,7 +1357,7 @@ vmw_bo_reference(struct vmw_buffer_object *buf) static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv) { - return &ttm_mem_glob; + return (struct ttm_mem_global *) dev_priv->mem_global_ref.object; } static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c index 8e3203766882..cb0a12cc4090 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c @@ -79,11 +79,36 @@ void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv, size_t gran) vvm->gran = gran; } +static int vmw_ttm_mem_global_init(struct drm_global_reference *ref) +{ + DRM_INFO("global init.\n"); + return ttm_mem_global_init(ref->object); +} + +static void vmw_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + int vmw_ttm_global_init(struct vmw_private *dev_priv) { struct drm_global_reference *global_ref; int ret; + global_ref = &dev_priv->mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &vmw_ttm_mem_global_init; + global_ref->release = &vmw_ttm_mem_global_release; + + ret = drm_global_item_ref(global_ref); + if (unlikely(ret != 0)) { + DRM_ERROR("Failed setting up TTM memory accounting.\n"); + return ret; + } + + dev_priv->bo_global_ref.mem_glob = + dev_priv->mem_global_ref.object; global_ref = &dev_priv->bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -98,10 +123,12 @@ int vmw_ttm_global_init(struct vmw_private *dev_priv) return 0; out_no_bo: + drm_global_item_unref(&dev_priv->mem_global_ref); return ret; } void vmw_ttm_global_release(struct vmw_private *dev_priv) { drm_global_item_unref(&dev_priv->bo_global_ref.ref); + drm_global_item_unref(&dev_priv->mem_global_ref); } diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h index 24e54d5dda6b..e2a6b2b5bfc3 100644 --- a/drivers/staging/vboxvideo/vbox_drv.h +++ b/drivers/staging/vboxvideo/vbox_drv.h @@ -79,6 +79,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_bo_device bdev; } ttm; diff --git a/drivers/staging/vboxvideo/vbox_ttm.c b/drivers/staging/vboxvideo/vbox_ttm.c index ceacbc1d3ff7..958c928c0d4b 100644 --- a/drivers/staging/vboxvideo/vbox_ttm.c +++ b/drivers/staging/vboxvideo/vbox_ttm.c @@ -16,6 +16,16 @@ static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) return container_of(bd, struct vbox_private, ttm.bdev); } +static int vbox_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void vbox_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + /** * Adds the vbox memory manager object/structures to the global memory manager. */ @@ -24,6 +34,18 @@ static int vbox_ttm_global_init(struct vbox_private *vbox) struct drm_global_reference *global_ref; int ret; + global_ref = &vbox->ttm.mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &vbox_ttm_mem_global_init; + global_ref->release = &vbox_ttm_mem_global_release; + ret = drm_global_item_ref(global_ref); + if (ret) { + DRM_ERROR("Failed setting up TTM memory subsystem.\n"); + return ret; + } + + vbox->ttm.bo_global_ref.mem_glob = vbox->ttm.mem_global_ref.object; global_ref = &vbox->ttm.bo_global_ref.ref; global_ref->global_type = DRM_GLOBAL_TTM_BO; global_ref->size = sizeof(struct ttm_bo_global); @@ -33,6 +55,7 @@ static int vbox_ttm_global_init(struct vbox_private *vbox) ret = drm_global_item_ref(global_ref); if (ret) { DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(&vbox->ttm.mem_global_ref); return ret; } @@ -45,6 +68,7 @@ static int vbox_ttm_global_init(struct vbox_private *vbox) static void vbox_ttm_global_release(struct vbox_private *vbox) { drm_global_item_unref(&vbox->ttm.bo_global_ref.ref); + drm_global_item_unref(&vbox->ttm.mem_global_ref); } static void vbox_bo_ttm_destroy(struct ttm_buffer_object *tbo) diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 4ae6fc33f761..c6ee07d10281 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -570,7 +570,8 @@ void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); void ttm_bo_global_release(struct ttm_bo_global *glob); -int ttm_bo_global_init(struct ttm_bo_global *glob); +int ttm_bo_global_init(struct ttm_bo_global *glob, + struct ttm_mem_global *mem_glob); int ttm_bo_device_release(struct ttm_bo_device *bdev); @@ -894,6 +895,7 @@ extern const struct ttm_mem_type_manager_func ttm_bo_manager_func; struct ttm_bo_global_ref { struct drm_global_reference ref; + struct ttm_mem_global *mem_glob; }; /** @@ -907,7 +909,9 @@ struct ttm_bo_global_ref { */ static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) { - return ttm_bo_global_init(ref->object); + 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); } /** diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h index 3ff48a0a2d7b..737b5fed8003 100644 --- a/include/drm/ttm/ttm_memory.h +++ b/include/drm/ttm/ttm_memory.h @@ -63,7 +63,7 @@ #define TTM_MEM_MAX_ZONES 2 struct ttm_mem_zone; -extern struct ttm_mem_global { +struct ttm_mem_global { struct kobject kobj; struct ttm_bo_global *bo_glob; struct workqueue_struct *swap_queue; @@ -78,7 +78,7 @@ extern struct ttm_mem_global { #else struct ttm_mem_zone *zone_dma32; #endif -} ttm_mem_glob; +}; extern int ttm_mem_global_init(struct ttm_mem_global *glob); extern void ttm_mem_global_release(struct ttm_mem_global *glob);