From patchwork Mon Apr 18 13:31:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: durgadoss.r@intel.com X-Patchwork-Id: 8872091 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 90277BF29F for ; Mon, 18 Apr 2016 12:51:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E712200F3 for ; Mon, 18 Apr 2016 12:51:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5203520251 for ; Mon, 18 Apr 2016 12:51:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1924B6E3CB; Mon, 18 Apr 2016 12:51:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B8306E277 for ; Mon, 18 Apr 2016 12:51:53 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 18 Apr 2016 05:51:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,502,1455004800"; d="scan'208";a="947564530" Received: from dr3-desktop.iind.intel.com ([10.223.26.125]) by fmsmga001.fm.intel.com with ESMTP; 18 Apr 2016 05:51:51 -0700 From: Durgadoss R To: intel-gfx@lists.freedesktop.org Date: Mon, 18 Apr 2016 19:01:43 +0530 Message-Id: <1460986305-7116-2-git-send-email-durgadoss.r@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460986305-7116-1-git-send-email-durgadoss.r@intel.com> References: <1460986305-7116-1-git-send-email-durgadoss.r@intel.com> Cc: ander.conselvan.de.oliveira@intel.com Subject: [Intel-gfx] [PATCHv4 1/3] drm/i915: Make finding unused crtc as a generic function 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=-5.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 Looping over the crtc list and finding an unused crtc has other users like upfront link training. Hence move it to a common function to re-use the logic. v4: * Added ERR_PTR as a return value in kernel Doc comment (Ander) v3: * Added kernel Doc and removed an invalid comment (Ander) * Rebased on top of latest code which includes locking for state->enable usage. v2: * Made this as a separate function instead of having it inside upfront link train code. Signed-off-by: Durgadoss R --- drivers/gpu/drm/i915/intel_display.c | 74 +++++++++++++++++++++--------------- drivers/gpu/drm/i915/intel_drv.h | 2 + 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 4cca155..a6df48b 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -10404,6 +10404,43 @@ static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, return 0; } +/** + * intel_get_unused_crtc - Find an unused crtc for the given encoder + * @encoder: drm_encoder structure + * @ctx: ctx pointer to use with locking + * + * This function tries to find an unused crtc that can drive + * the given encoder. Returns NULL or ERR_PTR on failure. + */ +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_crtc *possible_crtc; + struct drm_crtc *crtc = NULL; + struct drm_device *dev = encoder->dev; + int ret, i = -1; + + for_each_crtc(dev, possible_crtc) { + i++; + if (!(encoder->possible_crtcs & (1 << i))) + continue; + + ret = drm_modeset_lock(&possible_crtc->mutex, ctx); + if (ret) + return ERR_PTR(ret); + + if (possible_crtc->state->enable) { + drm_modeset_unlock(&possible_crtc->mutex); + continue; + } + + crtc = possible_crtc; + break; + } + + return crtc; +} + bool intel_get_load_detect_pipe(struct drm_connector *connector, struct drm_display_mode *mode, struct intel_load_detect_pipe *old, @@ -10412,7 +10449,6 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, struct intel_crtc *intel_crtc; struct intel_encoder *intel_encoder = intel_attached_encoder(connector); - struct drm_crtc *possible_crtc; struct drm_encoder *encoder = &intel_encoder->base; struct drm_crtc *crtc = NULL; struct drm_device *dev = encoder->dev; @@ -10421,7 +10457,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, struct drm_atomic_state *state = NULL, *restore_state = NULL; struct drm_connector_state *connector_state; struct intel_crtc_state *crtc_state; - int ret, i = -1; + int ret; DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", connector->base.id, connector->name, @@ -10451,39 +10487,15 @@ retry: ret = drm_modeset_lock(&crtc->mutex, ctx); if (ret) goto fail; - - /* Make sure the crtc and connector are running */ - goto found; - } - - /* Find an unused one (if possible) */ - for_each_crtc(dev, possible_crtc) { - i++; - if (!(encoder->possible_crtcs & (1 << i))) - continue; - - ret = drm_modeset_lock(&possible_crtc->mutex, ctx); - if (ret) + } else { + crtc = intel_get_unused_crtc(encoder, ctx); + if (IS_ERR_OR_NULL(crtc)) { + ret = PTR_ERR_OR_ZERO(crtc); + DRM_DEBUG_KMS("no pipe available for load-detect\n"); goto fail; - - if (possible_crtc->state->enable) { - drm_modeset_unlock(&possible_crtc->mutex); - continue; } - - crtc = possible_crtc; - break; - } - - /* - * If we didn't find an unused CRTC, don't use any. - */ - if (!crtc) { - DRM_DEBUG_KMS("no pipe available for load-detect\n"); - goto fail; } -found: intel_crtc = to_intel_crtc(crtc); ret = drm_modeset_lock(&crtc->primary->mutex, ctx); diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index e13ce22..27b5dcd 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -1159,6 +1159,8 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, void intel_release_load_detect_pipe(struct drm_connector *connector, struct intel_load_detect_pipe *old, struct drm_modeset_acquire_ctx *ctx); +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, + struct drm_modeset_acquire_ctx *ctx); int intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation); struct drm_framebuffer *