From patchwork Thu Jun 6 21:52:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Ceraolo Spurio X-Patchwork-Id: 10980509 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 DD32414C0 for ; Thu, 6 Jun 2019 21:52:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB5C428AD7 for ; Thu, 6 Jun 2019 21:52:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFC6B28ADA; Thu, 6 Jun 2019 21:52:51 +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 38E4F28AD7 for ; Thu, 6 Jun 2019 21:52:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 93289899D4; Thu, 6 Jun 2019 21:52:50 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 809CE899D4 for ; Thu, 6 Jun 2019 21:52:47 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2019 14:52:47 -0700 X-ExtLoop1: 1 Received: from dceraolo-linux.fm.intel.com ([10.1.27.145]) by orsmga002.jf.intel.com with ESMTP; 06 Jun 2019 14:52:47 -0700 From: Daniele Ceraolo Spurio To: intel-gfx@lists.freedesktop.org Date: Thu, 6 Jun 2019 14:52:15 -0700 Message-Id: <20190606215218.34486-7-daniele.ceraolospurio@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606215218.34486-1-daniele.ceraolospurio@intel.com> References: <20190606215218.34486-1-daniele.ceraolospurio@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 6/8] drm/i915: drop forcewake_user_get/put 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: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Now that we've split out the mmio_debug, we can manipulate that independently from the debugfs and just call the normal forcewake get/put functions. Signed-off-by: Daniele Ceraolo Spurio --- drivers/gpu/drm/i915/i915_debugfs.c | 19 +++++-- drivers/gpu/drm/i915/i915_drv.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/intel_uncore.c | 80 +++++++++-------------------- drivers/gpu/drm/i915/intel_uncore.h | 14 ++--- 5 files changed, 45 insertions(+), 71 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index f212241a2758..7e69829008e6 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -1391,7 +1391,7 @@ static int i915_forcewake_domains(struct seq_file *m, void *data) unsigned int tmp; seq_printf(m, "user.bypass_count = %u\n", - uncore->user_forcewake.count); + atomic_read(&i915->user_forcewake_count)); for_each_fw_domain(fw_domain, uncore, tmp) seq_printf(m, "%s.wake_count = %u\n", @@ -4219,7 +4219,11 @@ static int i915_forcewake_open(struct inode *inode, struct file *file) return 0; file->private_data = (void *)(uintptr_t)intel_runtime_pm_get(i915); - intel_uncore_forcewake_user_get(&i915->uncore); + + if (atomic_inc_return(&i915->user_forcewake_count) == 1) { + intel_uncore_forcewake_get(&i915->uncore, FORCEWAKE_ALL); + intel_uncore_mmio_debug_suspend(&i915->mmio_debug); + } return 0; } @@ -4231,9 +4235,14 @@ static int i915_forcewake_release(struct inode *inode, struct file *file) if (INTEL_GEN(i915) < 6) return 0; - intel_uncore_forcewake_user_put(&i915->uncore); - intel_runtime_pm_put(i915, - (intel_wakeref_t)(uintptr_t)file->private_data); + if (atomic_dec_and_test(&i915->user_forcewake_count)) { + if (intel_uncore_unclaimed_mmio(&i915->uncore)) + dev_info(i915->drm.dev, + "Invalid mmio detected during user access\n"); + + intel_uncore_mmio_debug_resume(&i915->mmio_debug); + intel_uncore_forcewake_put(&i915->uncore, FORCEWAKE_ALL); + } return 0; } diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 8fdd668eb7c7..024f270f6f00 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -2187,7 +2187,7 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) out: enable_rpm_wakeref_asserts(dev_priv); - if (!dev_priv->uncore.user_forcewake.count) + if (!atomic_read(&dev_priv->user_forcewake_count)) intel_runtime_pm_cleanup(dev_priv); return ret; diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 5522132a2ad2..dc6b3e4af575 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1399,6 +1399,7 @@ struct drm_i915_private { struct intel_uncore uncore; struct intel_uncore_mmio_debug mmio_debug; + atomic_t user_forcewake_count; struct i915_virtual_gpu vgpu; diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 8e42476ea4a7..c460426b0562 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -41,6 +41,28 @@ intel_uncore_mmio_debug_init_early(struct intel_uncore_mmio_debug *mmio_debug) mmio_debug->unclaimed_mmio_check = 1; } +/* Save and disable mmio debugging for the user bypass */ +void intel_uncore_mmio_debug_suspend(struct intel_uncore_mmio_debug *mmio_debug) +{ + spin_lock_irq(&mmio_debug->lock); + if (!mmio_debug->suspended) { + mmio_debug->saved_mmio_check = mmio_debug->unclaimed_mmio_check; + mmio_debug->unclaimed_mmio_check = 0; + mmio_debug->suspended = true; + } + spin_unlock_irq(&mmio_debug->lock); +} + +void intel_uncore_mmio_debug_resume(struct intel_uncore_mmio_debug *mmio_debug) +{ + spin_lock_irq(&mmio_debug->lock); + if (mmio_debug->suspended) { + mmio_debug->unclaimed_mmio_check = mmio_debug->saved_mmio_check; + mmio_debug->suspended = false; + } + spin_unlock_irq(&mmio_debug->lock); +} + static const char * const forcewake_domain_names[] = { "render", "blitter", @@ -482,6 +504,9 @@ check_for_unclaimed_mmio(struct intel_uncore *uncore) lockdep_assert_held(&uncore->debug->lock); + if (uncore->debug->suspended) + return false; + if (intel_uncore_has_fpga_dbg_unclaimed(uncore)) ret |= fpga_check_for_unclaimed_mmio(uncore); @@ -593,61 +618,6 @@ void intel_uncore_forcewake_get(struct intel_uncore *uncore, spin_unlock_irqrestore(&uncore->lock, irqflags); } -/** - * intel_uncore_forcewake_user_get - claim forcewake on behalf of userspace - * @uncore: the intel_uncore structure - * - * This function is a wrapper around intel_uncore_forcewake_get() to acquire - * the GT powerwell and in the process disable our debugging for the - * duration of userspace's bypass. - */ -void intel_uncore_forcewake_user_get(struct intel_uncore *uncore) -{ - spin_lock_irq(&uncore->lock); - spin_lock_irq(&uncore->debug->lock); - if (!uncore->user_forcewake.count++) { - intel_uncore_forcewake_get__locked(uncore, FORCEWAKE_ALL); - - /* Save and disable mmio debugging for the user bypass */ - uncore->user_forcewake.saved_mmio_check = - uncore->debug->unclaimed_mmio_check; - uncore->user_forcewake.saved_mmio_debug = - i915_modparams.mmio_debug; - - uncore->debug->unclaimed_mmio_check = 0; - i915_modparams.mmio_debug = 0; - } - spin_unlock_irq(&uncore->debug->lock); - spin_unlock_irq(&uncore->lock); -} - -/** - * intel_uncore_forcewake_user_put - release forcewake on behalf of userspace - * @uncore: the intel_uncore structure - * - * This function complements intel_uncore_forcewake_user_get() and releases - * the GT powerwell taken on behalf of the userspace bypass. - */ -void intel_uncore_forcewake_user_put(struct intel_uncore *uncore) -{ - spin_lock_irq(&uncore->lock); - spin_lock_irq(&uncore->debug->lock); - if (!--uncore->user_forcewake.count) { - if (check_for_unclaimed_mmio(uncore)) - dev_info(uncore_to_i915(uncore)->drm.dev, - "Invalid mmio detected during user access\n"); - - uncore->debug->unclaimed_mmio_check = - uncore->user_forcewake.saved_mmio_check; - i915_modparams.mmio_debug = - uncore->user_forcewake.saved_mmio_debug; - - intel_uncore_forcewake_put__locked(uncore, FORCEWAKE_ALL); - } - spin_unlock_irq(&uncore->debug->lock); - spin_unlock_irq(&uncore->lock); -} - /** * intel_uncore_forcewake_get__locked - grab forcewake domain references * @uncore: the intel_uncore structure diff --git a/drivers/gpu/drm/i915/intel_uncore.h b/drivers/gpu/drm/i915/intel_uncore.h index 53c1a334e2ae..1de1e8505124 100644 --- a/drivers/gpu/drm/i915/intel_uncore.h +++ b/drivers/gpu/drm/i915/intel_uncore.h @@ -39,6 +39,8 @@ struct intel_uncore; struct intel_uncore_mmio_debug { spinlock_t lock; /** lock is also taken in irq contexts. */ int unclaimed_mmio_check; + int saved_mmio_check; + bool suspended; }; enum forcewake_domain_id { @@ -140,13 +142,6 @@ struct intel_uncore { u32 __iomem *reg_ack; } *fw_domain[FW_DOMAIN_ID_COUNT]; - struct { - unsigned int count; - - int saved_mmio_check; - int saved_mmio_debug; - } user_forcewake; - struct intel_uncore_mmio_debug *debug; }; @@ -184,6 +179,8 @@ intel_uncore_has_fifo(const struct intel_uncore *uncore) void intel_uncore_mmio_debug_init_early(struct intel_uncore_mmio_debug *mmio_debug); +void intel_uncore_mmio_debug_suspend(struct intel_uncore_mmio_debug *mmio_debug); +void intel_uncore_mmio_debug_resume(struct intel_uncore_mmio_debug *mmio_debug); void intel_uncore_init_early(struct intel_uncore *uncore); int intel_uncore_init_mmio(struct intel_uncore *uncore); @@ -219,9 +216,6 @@ void intel_uncore_forcewake_get__locked(struct intel_uncore *uncore, void intel_uncore_forcewake_put__locked(struct intel_uncore *uncore, enum forcewake_domains domains); -void intel_uncore_forcewake_user_get(struct intel_uncore *uncore); -void intel_uncore_forcewake_user_put(struct intel_uncore *uncore); - int __intel_wait_for_register(struct intel_uncore *uncore, i915_reg_t reg, u32 mask,