Received: by 10.223.185.116 with SMTP id b49csp188830wrg; Thu, 8 Mar 2018 15:26:08 -0800 (PST) X-Google-Smtp-Source: AG47ELt4KgIY1jQpC0VCJ6ChJeKiJkxNDBoYdmvmYqW2SqiadmEsCVpIJuBowa3gmzn13Iqc3JIc X-Received: by 2002:a17:902:42e:: with SMTP id 43-v6mr26158314ple.186.1520551568596; Thu, 08 Mar 2018 15:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520551568; cv=none; d=google.com; s=arc-20160816; b=kRrOxtAsBtqmUfwhqP/Jyl90quUVfN106kVq4w/CINWg2anmFEIXmwni4mWJW5fKGv 70PgMInX+cY5HKmWRdHxcxjqpMeJXwB37a0YZfPfWbERjxSK3AeXF9WpsijJDksfy8T2 VqyvUhOGYBFTpdJNnS5l5JPbarGoosuUH9qj9KaG7yRJ7as1pcGWr7hmvuLZLKeS77dI Z43qzTQ8jHFcZBE5nsFJQFDvoTgPw6b9By8F9IMWH3t16Mm/PRPBTevQaiO5590MnasI xquyWxLRXv0gMBBp5ZpWYrpMoBPNnuebKESgaMUZA/ATfRpXEd07RqymvfFOKLXF5iJ0 26zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=390p5GMABiIjmIC4eR+1HVrbkjRdipM3IPfeDFkoMVU=; b=tRCzt6cmMDRrT5Zqp+DP0xaUvPo4W9jaBnsTDSALBMMjBwFgsYCUuPzPeUKO+a2vH6 oV6sCKaCIHemU0Y7QFq6VqDjPFC6WBL0zUZs13Q2BTjLWpfDwdMbWPlPfxrr+8nAIMmi c//Lk579C8Zej1r2UyLnOQBT7NKLoAcTbTLcWckmpprn5zk02sJIrEblMXFdsdin95zR j7CrGdhoq/Y8YJUAj2Xj+Qsqqn1cVAKOdWPdoyiO76xw4mO0/oLuWza4QNpSt0wEiy+Q QuUPFmZrIaDSQZS8CIYpymTJVfnxA3ldcZdDPLzTtOtrui0o+In/UeaU8XkOvWMvE18J S6XA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l4-v6si15880153plk.510.2018.03.08.15.25.53; Thu, 08 Mar 2018 15:26:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751297AbeCHXYd (ORCPT + 99 others); Thu, 8 Mar 2018 18:24:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36026 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751182AbeCHXYb (ORCPT ); Thu, 8 Mar 2018 18:24:31 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6790A5AB2E; Thu, 8 Mar 2018 23:24:31 +0000 (UTC) Received: from malachite.bss.redhat.com (dhcp-10-20-1-75.bss.redhat.com [10.20.1.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEBAC202322A; Thu, 8 Mar 2018 23:24:30 +0000 (UTC) From: Lyude Paul To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Manasi Navare , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Gustavo Padovan , Maarten Lankhorst , Sean Paul , David Airlie , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] drm/dp_mst: Add drm_atomic_dp_mst_retrain_topology() Date: Thu, 8 Mar 2018 18:24:19 -0500 Message-Id: <20180308232421.14049-6-lyude@redhat.com> In-Reply-To: <20180308232421.14049-1-lyude@redhat.com> References: <20180308232421.14049-1-lyude@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 08 Mar 2018 23:24:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 08 Mar 2018 23:24:31 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lyude@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Retraining MST is rather difficult. In order to do it properly while guaranteeing that we'll never run into a spot where we commit a physically impossible configuration, we have to do a lot of checks on atomic commits which affect MST topologies. All of this work is going to need to be repeated for every driver at some point, so let's save ourselves some trouble and just implement these atomic checks as a single helper. Signed-off-by: Lyude Paul Cc: Manasi Navare Cc: Ville Syrjälä --- drivers/gpu/drm/drm_dp_mst_topology.c | 223 ++++++++++++++++++++++++++++++++++ include/drm/drm_dp_mst_helper.h | 2 + 2 files changed, 225 insertions(+) diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c index 0d6604500b29..c4a91b1ba61b 100644 --- a/drivers/gpu/drm/drm_dp_mst_topology.c +++ b/drivers/gpu/drm/drm_dp_mst_topology.c @@ -2167,6 +2167,229 @@ int drm_dp_mst_topology_mgr_lower_link_rate(struct drm_dp_mst_topology_mgr *mgr, } EXPORT_SYMBOL(drm_dp_mst_topology_mgr_lower_link_rate); +static bool drm_atomic_dp_mst_state_only_disables_mstbs(struct drm_atomic_state *state, + struct drm_dp_mst_topology_mgr *mgr, + struct drm_dp_mst_branch *mstb) +{ + struct drm_dp_mst_branch *rmstb; + struct drm_dp_mst_port *port; + struct drm_connector *connector; + struct drm_connector_state *conn_state; + struct drm_crtc *crtc; + struct drm_crtc_state *crtc_state; + int ret; + + list_for_each_entry(port, &mstb->ports, next) { + rmstb = drm_dp_get_validated_mstb_ref(mstb->mgr, port->mstb); + if (rmstb) { + ret = drm_atomic_dp_mst_state_only_disables_mstbs( + state, mgr, rmstb); + drm_dp_put_mst_branch_device(rmstb); + if (!ret) + return false; + } + + connector = port->connector; + if (!connector) + continue; + + conn_state = drm_atomic_get_new_connector_state( + state, connector); + if (!conn_state) + continue; + + crtc = conn_state->crtc; + if (!crtc) + continue; + + crtc_state = drm_atomic_get_new_crtc_state(state, crtc); + if (!crtc_state) + continue; + + if (drm_atomic_crtc_needs_modeset(crtc_state)) + return false; + } + + return true; +} + +static int drm_atomic_dp_mst_all_mstbs_disabled(struct drm_atomic_state *state, + struct drm_dp_mst_topology_mgr *mgr, + struct drm_dp_mst_branch *mstb) +{ + struct drm_dp_mst_branch *rmstb; + struct drm_dp_mst_port *port; + struct drm_connector *connector; + struct drm_connector_state *conn_state; + int ret; + + list_for_each_entry(port, &mstb->ports, next) { + rmstb = drm_dp_get_validated_mstb_ref(mstb->mgr, port->mstb); + if (rmstb) { + ret = drm_atomic_dp_mst_all_mstbs_disabled( + state, mgr, rmstb); + drm_dp_put_mst_branch_device(rmstb); + if (ret <= 0) + return ret; + } + + connector = port->connector; + if (!connector) + continue; + + conn_state = drm_atomic_get_connector_state( + state, connector); + if (IS_ERR(conn_state)) + return PTR_ERR(conn_state); + + if (conn_state->crtc) + return false; + } + + /* No enabled CRTCs found */ + return true; +} + +static int drm_atomic_dp_mst_retrain_mstb(struct drm_atomic_state *state, + struct drm_dp_mst_topology_mgr *mgr, + struct drm_dp_mst_branch *mstb, + bool full_modeset) +{ + struct drm_dp_mst_branch *rmstb; + struct drm_dp_mst_port *port; + struct drm_connector *connector; + struct drm_connector_state *conn_state; + struct drm_crtc *crtc; + struct drm_crtc_state *crtc_state; + int ret; + + list_for_each_entry(port, &mstb->ports, next) { + rmstb = drm_dp_get_validated_mstb_ref(mstb->mgr, port->mstb); + if (rmstb) { + ret = drm_atomic_dp_mst_retrain_mstb( + state, mgr, rmstb, full_modeset); + drm_dp_put_mst_branch_device(rmstb); + if (ret) + return ret; + } + + connector = port->connector; + if (!connector) + continue; + + conn_state = drm_atomic_get_connector_state(state, connector); + if (IS_ERR(conn_state)) + return PTR_ERR(conn_state); + + if (conn_state->link_status != DRM_MODE_LINK_STATUS_GOOD) { + DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] link status bad -> good\n", + connector->base.id, connector->name); + conn_state->link_status = DRM_MODE_LINK_STATUS_GOOD; + } + + if (!full_modeset) + continue; + + crtc = conn_state->crtc; + if (!crtc) + continue; + + crtc_state = drm_atomic_get_crtc_state(state, crtc); + if (IS_ERR(crtc_state)) + return PTR_ERR(crtc_state); + + if (!crtc_state->mode_changed) { + DRM_DEBUG_ATOMIC("[CRTC:%d:%s] needs full modeset\n", + crtc->base.id, crtc->name); + crtc_state->mode_changed = true; + } + } + + return 0; +} + +/** + * drm_atomic_dp_mst_retrain_topology() - prepare a modeset that will retrain + * an MST topology + * @state: The new state that would retrain the topology link + * @mgr: The topology manager to use + * + * After userspace has been signaled that connectors are in need of + * retraining, it's expected that a modeset will be performed for any CRTCs on + * said connectors. Since all of the branch devices in an MST topology share a + * single link, they also share the same link status, lane count, and link + * rate. + * + * Since all of these characteristics are shared, there's only two valid + * solutions when fallback link training parameters need to be applied. The + * first is simply unassigning each mstb connector's CRTC. Since this action + * can only free slots on the VCPI table and not allocate them, this can be + * done without pulling in additional CRTCs on the MST topology. Additionally + * if this action would result in there no longer being any CRTCs assigned to + * mstb connectors, this would be enough to bring the topology back into a + * trained state since there would be nothing left requiring VCPI + * reallocations. + * + * The second solution is to commit new modes to all of the connectors on the + * topology. Since this action would result in VCPI reallocations with a new + * link rate and lane count, a modeset must also be performed on every other + * CRTC driving a branch device on the given topology at the same time. This + * is to ensure that all VCPI allocations are properly recalculated in + * response to the new link rate and lane count, that the new modes will fit + * into the recalculated VCPI table, and that the new atomic state could never + * result in an otherwise physically impossible configuration (e.g. different + * mstbs with CRTCs trained to different link rates/lane counts). + * + * Finally, any atomic commit which would result in going from an + * unrecoverable link state to a properly trained link state must also take + * care of appropriately updating the link status properties of all connectors + * on the topology from bad to good. This function takes care of all of these + * checks in @state for the topology manager @mgr including possibly pulling + * in additional CRTCs into the modeset, and possibly updating the link status + * of each mstb's DRM connector. + * + * This function should be called within the driver's atomic check callbacks + * whenever a modeset happens on an MST connector with it's link status set to + * DRM_MODE_LINK_STATUS_BAD. + * + * RETURNS: + * + * Returns 0 for success, or negative error code for failure. + */ +int drm_atomic_dp_mst_retrain_topology(struct drm_atomic_state *state, + struct drm_dp_mst_topology_mgr *mgr) +{ + struct drm_dp_mst_branch *mstb = + drm_dp_get_validated_mstb_ref(mgr, mgr->mst_primary); + int ret = 0; + bool need_modeset = false; + + if (!mstb) + return 0; + + if (drm_atomic_dp_mst_state_only_disables_mstbs(state, mgr, mstb)) { + ret = drm_atomic_dp_mst_all_mstbs_disabled(state, mgr, mstb); + if (ret < 0) + goto out; + + if (ret) + DRM_DEBUG_ATOMIC("state %p disables all CRTCs on mst mgr %p\n", + state, mgr); + else + goto out; /* valid, but doesn't retrain link */ + } else { + DRM_DEBUG_ATOMIC("state %p requires full modeset for CRTCs on mst mgr %p\n", + state, mgr); + need_modeset = true; + } + + ret = drm_atomic_dp_mst_retrain_mstb(state, mgr, mstb, need_modeset); +out: + drm_dp_put_mst_branch_device(mgr->mst_primary); + return ret; +} +EXPORT_SYMBOL(drm_atomic_dp_mst_retrain_topology); + /** * drm_dp_mst_topology_mgr_set_mst() - Set the MST state for a topology manager * @mgr: manager to set state for diff --git a/include/drm/drm_dp_mst_helper.h b/include/drm/drm_dp_mst_helper.h index 6261ec43a2c0..24075eb2dd1b 100644 --- a/include/drm/drm_dp_mst_helper.h +++ b/include/drm/drm_dp_mst_helper.h @@ -636,5 +636,7 @@ int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr, int drm_dp_mst_topology_mgr_lower_link_rate(struct drm_dp_mst_topology_mgr *mgr, int dp_link_bw, int dp_link_count); +int drm_atomic_dp_mst_retrain_topology(struct drm_atomic_state *state, + struct drm_dp_mst_topology_mgr *mgr); #endif -- 2.14.3