Subject: linux-next: manual merge of the drm-misc tree with Linus' tree

From: Stephen Rothwell <[email-masked]>
Date: Mon, 16 Dec 2019 11:46:12 +1100

Hi all,

Today's linux-next merge of the drm-misc tree got a conflict in:

  drivers/gpu/drm/drm_dp_mst_topology.c

between commit:

  14692a3637d4 ("drm/dp_mst: Add probe_lock")
  3f9b3f02dda5 ("drm/dp_mst: Protect drm_dp_mst_port members with locking")
  6f85f73821f6 ("drm/dp_mst: Add basic topology reprobing when resuming")

from Linus' tree and commits:

  f79489074c59 ("drm/dp_mst: Clear all payload id tables downstream when initializing")

from the drm-misc tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/drm_dp_mst_topology.c
index 273dd80fabf3,1770754bcd4a..000000000000
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@@ -74,8 -61,13 +74,13 @@@ static int drm_dp_send_dpcd_write(struc
  				  struct drm_dp_mst_port *port,
  				  int offset, int size, u8 *bytes);
  
 -static void drm_dp_send_link_address(struct drm_dp_mst_topology_mgr *mgr,
 -				     struct drm_dp_mst_branch *mstb);
 +static int drm_dp_send_link_address(struct drm_dp_mst_topology_mgr *mgr,
 +				    struct drm_dp_mst_branch *mstb);
+ 
+ static void
+ drm_dp_send_clear_payload_id_table(struct drm_dp_mst_topology_mgr *mgr,
+ 				   struct drm_dp_mst_branch *mstb);
+ 
  static int drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr,
  					   struct drm_dp_mst_branch *mstb,
  					   struct drm_dp_mst_port *port);
@@@ -2515,15 -2179,15 +2533,19 @@@ static int drm_dp_check_and_send_link_a
  
  static void drm_dp_mst_link_probe_work(struct work_struct *work)
  {
 -	struct drm_dp_mst_topology_mgr *mgr = container_of(work, struct drm_dp_mst_topology_mgr, work);
 +	struct drm_dp_mst_topology_mgr *mgr =
 +		container_of(work, struct drm_dp_mst_topology_mgr, work);
 +	struct drm_device *dev = mgr->dev;
  	struct drm_dp_mst_branch *mstb;
  	int ret;
+ 	bool clear_payload_id_table;
  
 +	mutex_lock(&mgr->probe_lock);
 +
  	mutex_lock(&mgr->lock);
+ 	clear_payload_id_table = !mgr->payload_id_table_cleared;
+ 	mgr->payload_id_table_cleared = true;
+ 
  	mstb = mgr->mst_primary;
  	if (mstb) {
  		ret = drm_dp_mst_topology_try_get_mstb(mstb);
@@@ -2531,17 -2195,24 +2553,30 @@@
  			mstb = NULL;
  	}
  	mutex_unlock(&mgr->lock);
 -	if (!mstb)
 +	if (!mstb) {
 +		mutex_unlock(&mgr->probe_lock);
  		return;
 +	}
  
+ 	/*
+ 	 * Certain branch devices seem to incorrectly report an available_pbn
+ 	 * of 0 on downstream sinks, even after clearing the
+ 	 * DP_PAYLOAD_ALLOCATE_* registers in
+ 	 * drm_dp_mst_topology_mgr_set_mst(). Namely, the CableMatters USB-C
+ 	 * 2x DP hub. Sending a CLEAR_PAYLOAD_ID_TABLE message seems to make
+ 	 * things work again.
+ 	 */
+ 	if (clear_payload_id_table) {
+ 		DRM_DEBUG_KMS("Clearing payload ID table\n");
+ 		drm_dp_send_clear_payload_id_table(mgr, mstb);
+ 	}
+ 
 -	drm_dp_check_and_send_link_address(mgr, mstb);
 +	ret = drm_dp_check_and_send_link_address(mgr, mstb);
  	drm_dp_mst_topology_put_mstb(mstb);
 +
 +	mutex_unlock(&mgr->probe_lock);
 +	if (ret)
 +		drm_kms_helper_hotplug_event(dev);
  }
  
  static bool drm_dp_validate_guid(struct drm_dp_mst_topology_mgr *mgr,
@@@ -2856,9 -2503,30 +2891,31 @@@ out
  	if (ret <= 0)
  		mstb->link_address_sent = false;
  	kfree(txmsg);
 +	return ret < 0 ? ret : changed;
  }
  
+ void drm_dp_send_clear_payload_id_table(struct drm_dp_mst_topology_mgr *mgr,
+ 					struct drm_dp_mst_branch *mstb)
+ {
+ 	struct drm_dp_sideband_msg_tx *txmsg;
+ 	int len, ret;
+ 
+ 	txmsg = kzalloc(sizeof(*txmsg), GFP_KERNEL);
+ 	if (!txmsg)
+ 		return;
+ 
+ 	txmsg->dst = mstb;
+ 	len = build_clear_payload_id_table(txmsg);
+ 
+ 	drm_dp_queue_down_tx(mgr, txmsg);
+ 
+ 	ret = drm_dp_mst_wait_tx_reply(mstb, txmsg);
+ 	if (ret > 0 && txmsg->reply.reply_type == DP_SIDEBAND_REPLY_NAK)
+ 		DRM_DEBUG_KMS("clear payload table id nak received\n");
+ 
+ 	kfree(txmsg);
+ }
+ 
  static int
  drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr,
  				struct drm_dp_mst_branch *mstb,