From patchwork Fri Apr 15 05:10:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Airlie X-Patchwork-Id: 8844921 Return-Path: X-Original-To: patchwork-dri-devel@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 BE1FDC0554 for ; Fri, 15 Apr 2016 05:11:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C10E120381 for ; Fri, 15 Apr 2016 05:11:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6038C2037C for ; Fri, 15 Apr 2016 05:11:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 210F16EB7A; Fri, 15 Apr 2016 05:11:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id A809C6E114 for ; Fri, 15 Apr 2016 05:11:01 +0000 (UTC) Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E7D36316D for ; Fri, 15 Apr 2016 05:11:01 +0000 (UTC) Received: from dreadlord-bne-redhat-com.bne.redhat.com (dhcp-40-179.bne.redhat.com [10.64.40.179]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3F5AlYq005176 for ; Fri, 15 Apr 2016 01:11:00 -0400 From: Dave Airlie To: dri-devel@lists.freedesktop.org Subject: [PATCH 13/15] drm: take references to connectors used in a modeset. Date: Fri, 15 Apr 2016 15:10:44 +1000 Message-Id: <1460697046-23781-14-git-send-email-airlied@gmail.com> In-Reply-To: <1460697046-23781-1-git-send-email-airlied@gmail.com> References: <1460697046-23781-1-git-send-email-airlied@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Apr 2016 05:11:01 +0000 (UTC) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,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 From: Dave Airlie As suggested by Daniel, if we are actively using the connector in a modeset we don't want it to disappear from underneath us. This takes a reference to the connector in the atomic paths when we are setting the state up, and in the non-atomic paths when binding the encoder. Signed-off-by: Dave Airlie --- drivers/gpu/drm/drm_atomic.c | 11 ++++++++++- drivers/gpu/drm/drm_crtc_helper.c | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 9d5e3c8..d899dac 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1159,7 +1159,7 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state, struct drm_crtc *crtc) { struct drm_crtc_state *crtc_state; - + bool had_crtc = conn_state->crtc ? true : false; if (conn_state->crtc && conn_state->crtc != crtc) { crtc_state = drm_atomic_get_existing_crtc_state(conn_state->state, conn_state->crtc); @@ -1179,6 +1179,15 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state, conn_state->crtc = crtc; + /* If we had no crtc then got one, add a reference, + * if we had a crtc and are going to none, drop a reference, + * otherwise just keep the reference we have. + */ + if (!had_crtc && crtc) + drm_connector_reference(conn_state->connector); + else if (!crtc && had_crtc) + drm_connector_unreference(conn_state->connector); + if (crtc) DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n", conn_state, crtc->base.id, crtc->name); diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c index 79555d2..71b6c72 100644 --- a/drivers/gpu/drm/drm_crtc_helper.c +++ b/drivers/gpu/drm/drm_crtc_helper.c @@ -456,6 +456,9 @@ drm_crtc_helper_disable(struct drm_crtc *crtc) * between them is henceforth no longer available. */ connector->dpms = DRM_MODE_DPMS_OFF; + + /* we keep a reference while the encoder is bound */ + drm_connector_unreference(connector); } } @@ -635,9 +638,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) mode_changed = true; /* If the encoder is reused for another connector, then * the appropriate crtc will be set later. + * take a reference only if we haven't had an encoder before. */ if (connector->encoder) connector->encoder->crtc = NULL; + else + drm_connector_reference(connector); connector->encoder = new_encoder; } }