From patchwork Tue Dec 29 18:59:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Gordon X-Patchwork-Id: 7930441 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C3227BEEE5 for ; Tue, 29 Dec 2015 19:00:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE9472015A for ; Tue, 29 Dec 2015 19:00:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 89BCD20114 for ; Tue, 29 Dec 2015 19:00:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00E896E03B; Tue, 29 Dec 2015 11:00:10 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 70AB56E03B for ; Tue, 29 Dec 2015 11:00:08 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 29 Dec 2015 11:00:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,496,1444719600"; d="scan'208";a="883014085" Received: from dsgordon-linux2.isw.intel.com ([10.102.226.88]) by fmsmga002.fm.intel.com with ESMTP; 29 Dec 2015 11:00:07 -0800 From: Dave Gordon To: intel-gfx@lists.freedesktop.org Date: Tue, 29 Dec 2015 18:59:57 +0000 Message-Id: <1451415598-24056-1-git-send-email-david.s.gordon@intel.com> X-Mailer: git-send-email 1.9.1 Organization: Intel Corporation (UK) Ltd. - Co. Reg. #1134945 - Pipers Way, Swindon SN3 1RJ Cc: Jani Nikula Subject: [Intel-gfx] [PATCH 1/2] drm/i915: introduce for_each_engine(), rework for_each_ring() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the discussions around commit 373701b1 (Jani Nikula) drm: fix potential dangling else problems in for_each_ macros Daniel Vetter mooted the idea of a for_each_engine(ring, dev_priv) macro that didn't use or rely on having an integer index variable. So here it is; and, for backwards compatibility, an updated version of for_each_ring() implemented using the same internals. As an example of the use of this new macro, the functions in intel_uncore.c have been converted to use it in preference to for_each_ring() wherever possible. A subsequent patch will convert many of the uses in other source files. Cc: Daniel Vetter Cc: Jani Nikula Cc: Chris Wilson Signed-off-by: Dave Gordon --- drivers/gpu/drm/i915/i915_drv.h | 32 ++++++++++++++++++++++++++++---- drivers/gpu/drm/i915/intel_uncore.c | 5 ++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index cf7e0fc..a6457ee 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1968,10 +1968,34 @@ static inline struct drm_i915_private *guc_to_i915(struct intel_guc *guc) return container_of(guc, struct drm_i915_private, guc); } -/* Iterate over initialised rings */ -#define for_each_ring(ring__, dev_priv__, i__) \ - for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \ - for_each_if ((((ring__) = &(dev_priv__)->ring[(i__)]), intel_ring_initialized((ring__)))) +/* Helpers for the for_each_* macros below */ +#define __INIT_ENGINE_PTR(engine, dev_priv) \ + ({ \ + struct intel_engine_cs *ep = (dev_priv)->ring; \ + (engine) = --ep; \ + }) +#define __NEXT_ACTIVE_ENGINE(engine, dev_priv, nr) \ + ({ \ + struct intel_engine_cs *end = &(dev_priv)->ring[nr]; \ + struct intel_engine_cs *ep = (engine); \ + bool in_range; \ + do { \ + in_range = ++(ep) < end; \ + } while (in_range && !intel_ring_initialized(ep)); \ + (engine) = ep; \ + in_range; \ + }) + +/* Iterate over initialised engines */ +#define for_each_engine(engine, dev_priv) \ + for (__INIT_ENGINE_PTR(engine, dev_priv); \ + __NEXT_ACTIVE_ENGINE(engine, dev_priv, I915_NUM_RINGS); ) + +/* Backwards compatibility: iterate over initialised "rings" */ +#define for_each_ring(engine, dev_priv, ring_id) \ + for (__INIT_ENGINE_PTR(engine, dev_priv); \ + __NEXT_ACTIVE_ENGINE(engine, dev_priv, I915_NUM_RINGS) && \ + ((ring_id) = (engine)->id, true); ) enum hdmi_force_audio { HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */ diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 277e60a..240c244 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -1508,9 +1508,8 @@ static int gen8_do_reset(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; struct intel_engine_cs *engine; - int i; - for_each_ring(engine, dev_priv, i) { + for_each_engine(engine, dev_priv) { I915_WRITE(RING_RESET_CTL(engine->mmio_base), _MASKED_BIT_ENABLE(RESET_CTL_REQUEST_RESET)); @@ -1527,7 +1526,7 @@ static int gen8_do_reset(struct drm_device *dev) return gen6_do_reset(dev); not_ready: - for_each_ring(engine, dev_priv, i) + for_each_engine(engine, dev_priv) I915_WRITE(RING_RESET_CTL(engine->mmio_base), _MASKED_BIT_DISABLE(RESET_CTL_REQUEST_RESET));