From patchwork Wed Jun 27 11:19:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10491151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1515760375 for ; Wed, 27 Jun 2018 11:19:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03E2D28BBB for ; Wed, 27 Jun 2018 11:19:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC66928BCC; Wed, 27 Jun 2018 11:19:25 +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 9947C28BBB for ; Wed, 27 Jun 2018 11:19:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E0106E892; Wed, 27 Jun 2018 11:19:24 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 50D406E892 for ; Wed, 27 Jun 2018 11:19:23 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 12174086-1500050 for multiple; Wed, 27 Jun 2018 12:19:17 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Wed, 27 Jun 2018 12:19:15 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 27 Jun 2018 12:19:15 +0100 Message-Id: <20180627111915.14221-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.18.0 In-Reply-To: <3e030e1a78ddcd11068c660bd969c8353af929d3> References: <3e030e1a78ddcd11068c660bd969c8353af929d3> X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH] horror X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP --- drivers/gpu/drm/i915/i915_drv.c | 8 ++++++++ drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++++ drivers/gpu/drm/i915/i915_request.c | 7 +++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 5ba785387c2b..3c2625b50448 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1479,6 +1479,14 @@ static void i915_driver_release(struct drm_device *dev) kfree(dev_priv); } +void i915_release(struct kref *kref) +{ + struct drm_i915_private *i915 = + container_of(kref, struct drm_i915_private, drm.ref); + + i915_driver_release(&i915->drm); +} + static int i915_driver_open(struct drm_device *dev, struct drm_file *file) { struct drm_i915_private *i915 = to_i915(dev); diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 397e587a8688..052e4952e370 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -3552,4 +3552,16 @@ static inline int intel_hws_csb_write_index(struct drm_i915_private *i915) return I915_HWS_CSB_WRITE_INDEX; } +static inline struct drm_i915_private *i915_get(struct drm_i915_private *i915) +{ + kref_get(&i915->drm.ref); + return i915; +} + +void i915_release(struct kref *kref); +static inline void i915_put(struct drm_i915_private *i915) +{ + kref_put(&i915->drm.ref, i915_release); +} + #endif diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c index e808087928f7..6753fe8e6400 100644 --- a/drivers/gpu/drm/i915/i915_request.c +++ b/drivers/gpu/drm/i915/i915_request.c @@ -74,6 +74,7 @@ static signed long i915_fence_wait(struct dma_fence *fence, static void i915_fence_release(struct dma_fence *fence) { struct i915_request *rq = to_request(fence); + struct drm_i915_private *i915 = rq->i915; /* * The request is put onto a RCU freelist (i.e. the address @@ -84,7 +85,8 @@ static void i915_fence_release(struct dma_fence *fence) */ i915_sw_fence_fini(&rq->submit); - kmem_cache_free(rq->i915->requests, rq); + kmem_cache_free(i915->requests, rq); + i915_put(i915); } const struct dma_fence_ops i915_fence_ops = { @@ -717,7 +719,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx) } INIT_LIST_HEAD(&rq->active_list); - rq->i915 = i915; + rq->i915 = i915_get(i915); rq->engine = engine; rq->gem_context = ctx; rq->hw_context = ce; @@ -795,6 +797,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx) GEM_BUG_ON(!list_empty(&rq->sched.waiters_list)); kmem_cache_free(i915->requests, rq); + i915_put(i915); err_unreserve: unreserve_gt(i915); err_unpin: