Commit 16b78f05 authored by Dave Airlie's avatar Dave Airlie

Merge tag 'topic/mst-bw-check-fixes-for-airlied-2020-03-12-2' of...

Merge tag 'topic/mst-bw-check-fixes-for-airlied-2020-03-12-2' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes

UAPI Changes: None

Cross-subsystem Changes: None

Core Changes: Fixed regressions introduced by commit cd82d82c
("drm/dp_mst: Add branch bandwidth validation to MST atomic check"),
which would cause us to:

* Calculate the available bandwidth on an MST topology incorrectly, and
  as a result reject most display configurations that would try to enable
  more then one sink on a topology
* Occasionally expose MST connectors to userspace before finishing
  probing their PBN capabilities, resulting in us rejecting display
  configurations because we assumed briefly that no bandwidth was
  available

Driver Changes: None
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
From: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/bf16ee577567beed91c86b7d9cda3ec2e8c50a71.camel@redhat.com
parents f31d83f0 047d4cd2
...@@ -1935,7 +1935,7 @@ static u8 drm_dp_calculate_rad(struct drm_dp_mst_port *port, ...@@ -1935,7 +1935,7 @@ static u8 drm_dp_calculate_rad(struct drm_dp_mst_port *port,
return parent_lct + 1; return parent_lct + 1;
} }
static bool drm_dp_mst_is_dp_mst_end_device(u8 pdt, bool mcs) static bool drm_dp_mst_is_end_device(u8 pdt, bool mcs)
{ {
switch (pdt) { switch (pdt) {
case DP_PEER_DEVICE_DP_LEGACY_CONV: case DP_PEER_DEVICE_DP_LEGACY_CONV:
...@@ -1965,13 +1965,13 @@ drm_dp_port_set_pdt(struct drm_dp_mst_port *port, u8 new_pdt, ...@@ -1965,13 +1965,13 @@ drm_dp_port_set_pdt(struct drm_dp_mst_port *port, u8 new_pdt,
/* Teardown the old pdt, if there is one */ /* Teardown the old pdt, if there is one */
if (port->pdt != DP_PEER_DEVICE_NONE) { if (port->pdt != DP_PEER_DEVICE_NONE) {
if (drm_dp_mst_is_dp_mst_end_device(port->pdt, port->mcs)) { if (drm_dp_mst_is_end_device(port->pdt, port->mcs)) {
/* /*
* If the new PDT would also have an i2c bus, * If the new PDT would also have an i2c bus,
* don't bother with reregistering it * don't bother with reregistering it
*/ */
if (new_pdt != DP_PEER_DEVICE_NONE && if (new_pdt != DP_PEER_DEVICE_NONE &&
drm_dp_mst_is_dp_mst_end_device(new_pdt, new_mcs)) { drm_dp_mst_is_end_device(new_pdt, new_mcs)) {
port->pdt = new_pdt; port->pdt = new_pdt;
port->mcs = new_mcs; port->mcs = new_mcs;
return 0; return 0;
...@@ -1991,7 +1991,7 @@ drm_dp_port_set_pdt(struct drm_dp_mst_port *port, u8 new_pdt, ...@@ -1991,7 +1991,7 @@ drm_dp_port_set_pdt(struct drm_dp_mst_port *port, u8 new_pdt,
port->mcs = new_mcs; port->mcs = new_mcs;
if (port->pdt != DP_PEER_DEVICE_NONE) { if (port->pdt != DP_PEER_DEVICE_NONE) {
if (drm_dp_mst_is_dp_mst_end_device(port->pdt, port->mcs)) { if (drm_dp_mst_is_end_device(port->pdt, port->mcs)) {
/* add i2c over sideband */ /* add i2c over sideband */
ret = drm_dp_mst_register_i2c_bus(&port->aux); ret = drm_dp_mst_register_i2c_bus(&port->aux);
} else { } else {
...@@ -2172,7 +2172,7 @@ drm_dp_mst_port_add_connector(struct drm_dp_mst_branch *mstb, ...@@ -2172,7 +2172,7 @@ drm_dp_mst_port_add_connector(struct drm_dp_mst_branch *mstb,
} }
if (port->pdt != DP_PEER_DEVICE_NONE && if (port->pdt != DP_PEER_DEVICE_NONE &&
drm_dp_mst_is_dp_mst_end_device(port->pdt, port->mcs)) { drm_dp_mst_is_end_device(port->pdt, port->mcs)) {
port->cached_edid = drm_get_edid(port->connector, port->cached_edid = drm_get_edid(port->connector,
&port->aux.ddc); &port->aux.ddc);
drm_connector_set_tile_property(port->connector); drm_connector_set_tile_property(port->connector);
...@@ -2302,14 +2302,18 @@ drm_dp_mst_handle_link_address_port(struct drm_dp_mst_branch *mstb, ...@@ -2302,14 +2302,18 @@ drm_dp_mst_handle_link_address_port(struct drm_dp_mst_branch *mstb,
mutex_unlock(&mgr->lock); mutex_unlock(&mgr->lock);
} }
if (old_ddps != port->ddps) { /*
if (port->ddps) { * Reprobe PBN caps on both hotplug, and when re-probing the link
if (!port->input) { * for our parent mstb
drm_dp_send_enum_path_resources(mgr, mstb, */
if (old_ddps != port->ddps || !created) {
if (port->ddps && !port->input) {
ret = drm_dp_send_enum_path_resources(mgr, mstb,
port); port);
} if (ret == 1)
changed = true;
} else { } else {
port->available_pbn = 0; port->full_pbn = 0;
} }
} }
...@@ -2401,11 +2405,10 @@ drm_dp_mst_handle_conn_stat(struct drm_dp_mst_branch *mstb, ...@@ -2401,11 +2405,10 @@ drm_dp_mst_handle_conn_stat(struct drm_dp_mst_branch *mstb,
port->ddps = conn_stat->displayport_device_plug_status; port->ddps = conn_stat->displayport_device_plug_status;
if (old_ddps != port->ddps) { if (old_ddps != port->ddps) {
if (port->ddps) { if (port->ddps && !port->input)
dowork = true; drm_dp_send_enum_path_resources(mgr, mstb, port);
} else { else
port->available_pbn = 0; port->full_pbn = 0;
}
} }
new_pdt = port->input ? DP_PEER_DEVICE_NONE : conn_stat->peer_device_type; new_pdt = port->input ? DP_PEER_DEVICE_NONE : conn_stat->peer_device_type;
...@@ -2556,13 +2559,6 @@ static int drm_dp_check_and_send_link_address(struct drm_dp_mst_topology_mgr *mg ...@@ -2556,13 +2559,6 @@ static int drm_dp_check_and_send_link_address(struct drm_dp_mst_topology_mgr *mg
if (port->input || !port->ddps) if (port->input || !port->ddps)
continue; continue;
if (!port->available_pbn) {
drm_modeset_lock(&mgr->base.lock, NULL);
drm_dp_send_enum_path_resources(mgr, mstb, port);
drm_modeset_unlock(&mgr->base.lock);
changed = true;
}
if (port->mstb) if (port->mstb)
mstb_child = drm_dp_mst_topology_get_mstb_validated( mstb_child = drm_dp_mst_topology_get_mstb_validated(
mgr, port->mstb); mgr, port->mstb);
...@@ -2990,6 +2986,7 @@ drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, ...@@ -2990,6 +2986,7 @@ drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr,
ret = drm_dp_mst_wait_tx_reply(mstb, txmsg); ret = drm_dp_mst_wait_tx_reply(mstb, txmsg);
if (ret > 0) { if (ret > 0) {
ret = 0;
path_res = &txmsg->reply.u.path_resources; path_res = &txmsg->reply.u.path_resources;
if (txmsg->reply.reply_type == DP_SIDEBAND_REPLY_NAK) { if (txmsg->reply.reply_type == DP_SIDEBAND_REPLY_NAK) {
...@@ -3002,14 +2999,22 @@ drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, ...@@ -3002,14 +2999,22 @@ drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr,
path_res->port_number, path_res->port_number,
path_res->full_payload_bw_number, path_res->full_payload_bw_number,
path_res->avail_payload_bw_number); path_res->avail_payload_bw_number);
port->available_pbn =
path_res->avail_payload_bw_number; /*
* If something changed, make sure we send a
* hotplug
*/
if (port->full_pbn != path_res->full_payload_bw_number ||
port->fec_capable != path_res->fec_capable)
ret = 1;
port->full_pbn = path_res->full_payload_bw_number;
port->fec_capable = path_res->fec_capable; port->fec_capable = path_res->fec_capable;
} }
} }
kfree(txmsg); kfree(txmsg);
return 0; return ret;
} }
static struct drm_dp_mst_port *drm_dp_get_last_connected_port_to_mstb(struct drm_dp_mst_branch *mstb) static struct drm_dp_mst_port *drm_dp_get_last_connected_port_to_mstb(struct drm_dp_mst_branch *mstb)
...@@ -3596,13 +3601,9 @@ drm_dp_mst_topology_mgr_invalidate_mstb(struct drm_dp_mst_branch *mstb) ...@@ -3596,13 +3601,9 @@ drm_dp_mst_topology_mgr_invalidate_mstb(struct drm_dp_mst_branch *mstb)
/* The link address will need to be re-sent on resume */ /* The link address will need to be re-sent on resume */
mstb->link_address_sent = false; mstb->link_address_sent = false;
list_for_each_entry(port, &mstb->ports, next) { list_for_each_entry(port, &mstb->ports, next)
/* The PBN for each port will also need to be re-probed */
port->available_pbn = 0;
if (port->mstb) if (port->mstb)
drm_dp_mst_topology_mgr_invalidate_mstb(port->mstb); drm_dp_mst_topology_mgr_invalidate_mstb(port->mstb);
}
} }
/** /**
...@@ -4829,41 +4830,102 @@ static bool drm_dp_mst_port_downstream_of_branch(struct drm_dp_mst_port *port, ...@@ -4829,41 +4830,102 @@ static bool drm_dp_mst_port_downstream_of_branch(struct drm_dp_mst_port *port,
return false; return false;
} }
static inline static int
int drm_dp_mst_atomic_check_bw_limit(struct drm_dp_mst_branch *branch, drm_dp_mst_atomic_check_port_bw_limit(struct drm_dp_mst_port *port,
struct drm_dp_mst_topology_state *mst_state) struct drm_dp_mst_topology_state *state);
static int
drm_dp_mst_atomic_check_mstb_bw_limit(struct drm_dp_mst_branch *mstb,
struct drm_dp_mst_topology_state *state)
{ {
struct drm_dp_mst_port *port;
struct drm_dp_vcpi_allocation *vcpi; struct drm_dp_vcpi_allocation *vcpi;
int pbn_limit = 0, pbn_used = 0; struct drm_dp_mst_port *port;
int pbn_used = 0, ret;
bool found = false;
list_for_each_entry(port, &branch->ports, next) { /* Check that we have at least one port in our state that's downstream
if (port->mstb) * of this branch, otherwise we can skip this branch
if (drm_dp_mst_atomic_check_bw_limit(port->mstb, mst_state)) */
return -ENOSPC; list_for_each_entry(vcpi, &state->vcpis, next) {
if (!vcpi->pbn ||
!drm_dp_mst_port_downstream_of_branch(vcpi->port, mstb))
continue;
found = true;
break;
}
if (!found)
return 0;
if (mstb->port_parent)
DRM_DEBUG_ATOMIC("[MSTB:%p] [MST PORT:%p] Checking bandwidth limits on [MSTB:%p]\n",
mstb->port_parent->parent, mstb->port_parent,
mstb);
else
DRM_DEBUG_ATOMIC("[MSTB:%p] Checking bandwidth limits\n",
mstb);
if (port->available_pbn > 0) list_for_each_entry(port, &mstb->ports, next) {
pbn_limit = port->available_pbn; ret = drm_dp_mst_atomic_check_port_bw_limit(port, state);
if (ret < 0)
return ret;
pbn_used += ret;
} }
DRM_DEBUG_ATOMIC("[MST BRANCH:%p] branch has %d PBN available\n",
branch, pbn_limit);
list_for_each_entry(vcpi, &mst_state->vcpis, next) { return pbn_used;
if (!vcpi->pbn) }
static int
drm_dp_mst_atomic_check_port_bw_limit(struct drm_dp_mst_port *port,
struct drm_dp_mst_topology_state *state)
{
struct drm_dp_vcpi_allocation *vcpi;
int pbn_used = 0;
if (port->pdt == DP_PEER_DEVICE_NONE)
return 0;
if (drm_dp_mst_is_end_device(port->pdt, port->mcs)) {
bool found = false;
list_for_each_entry(vcpi, &state->vcpis, next) {
if (vcpi->port != port)
continue; continue;
if (!vcpi->pbn)
return 0;
if (drm_dp_mst_port_downstream_of_branch(vcpi->port, branch)) found = true;
pbn_used += vcpi->pbn; break;
}
if (!found)
return 0;
/* This should never happen, as it means we tried to
* set a mode before querying the full_pbn
*/
if (WARN_ON(!port->full_pbn))
return -EINVAL;
pbn_used = vcpi->pbn;
} else {
pbn_used = drm_dp_mst_atomic_check_mstb_bw_limit(port->mstb,
state);
if (pbn_used <= 0)
return pbn_used;
} }
DRM_DEBUG_ATOMIC("[MST BRANCH:%p] branch used %d PBN\n",
branch, pbn_used);
if (pbn_used > pbn_limit) { if (pbn_used > port->full_pbn) {
DRM_DEBUG_ATOMIC("[MST BRANCH:%p] No available bandwidth\n", DRM_DEBUG_ATOMIC("[MSTB:%p] [MST PORT:%p] required PBN of %d exceeds port limit of %d\n",
branch); port->parent, port, pbn_used,
port->full_pbn);
return -ENOSPC; return -ENOSPC;
} }
return 0;
DRM_DEBUG_ATOMIC("[MSTB:%p] [MST PORT:%p] uses %d out of %d PBN\n",
port->parent, port, pbn_used, port->full_pbn);
return pbn_used;
} }
static inline int static inline int
...@@ -5061,9 +5123,15 @@ int drm_dp_mst_atomic_check(struct drm_atomic_state *state) ...@@ -5061,9 +5123,15 @@ int drm_dp_mst_atomic_check(struct drm_atomic_state *state)
ret = drm_dp_mst_atomic_check_vcpi_alloc_limit(mgr, mst_state); ret = drm_dp_mst_atomic_check_vcpi_alloc_limit(mgr, mst_state);
if (ret) if (ret)
break; break;
ret = drm_dp_mst_atomic_check_bw_limit(mgr->mst_primary, mst_state);
if (ret) mutex_lock(&mgr->lock);
ret = drm_dp_mst_atomic_check_mstb_bw_limit(mgr->mst_primary,
mst_state);
mutex_unlock(&mgr->lock);
if (ret < 0)
break; break;
else
ret = 0;
} }
return ret; return ret;
......
...@@ -81,7 +81,7 @@ struct drm_dp_vcpi { ...@@ -81,7 +81,7 @@ struct drm_dp_vcpi {
* &drm_dp_mst_topology_mgr.base.lock. * &drm_dp_mst_topology_mgr.base.lock.
* @num_sdp_stream_sinks: Number of stream sinks. Protected by * @num_sdp_stream_sinks: Number of stream sinks. Protected by
* &drm_dp_mst_topology_mgr.base.lock. * &drm_dp_mst_topology_mgr.base.lock.
* @available_pbn: Available bandwidth for this port. Protected by * @full_pbn: Max possible bandwidth for this port. Protected by
* &drm_dp_mst_topology_mgr.base.lock. * &drm_dp_mst_topology_mgr.base.lock.
* @next: link to next port on this branch device * @next: link to next port on this branch device
* @aux: i2c aux transport to talk to device connected to this port, protected * @aux: i2c aux transport to talk to device connected to this port, protected
...@@ -126,7 +126,7 @@ struct drm_dp_mst_port { ...@@ -126,7 +126,7 @@ struct drm_dp_mst_port {
u8 dpcd_rev; u8 dpcd_rev;
u8 num_sdp_streams; u8 num_sdp_streams;
u8 num_sdp_stream_sinks; u8 num_sdp_stream_sinks;
uint16_t available_pbn; uint16_t full_pbn;
struct list_head next; struct list_head next;
/** /**
* @mstb: the branch device connected to this port, if there is one. * @mstb: the branch device connected to this port, if there is one.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment