diff options
Diffstat (limited to 'drm-dp-mst-fixes.patch')
-rw-r--r-- | drm-dp-mst-fixes.patch | 578 |
1 files changed, 578 insertions, 0 deletions
diff --git a/drm-dp-mst-fixes.patch b/drm-dp-mst-fixes.patch new file mode 100644 index 000000000..d1e61f17d --- /dev/null +++ b/drm-dp-mst-fixes.patch @@ -0,0 +1,578 @@ +From 5118c9aeafecbfa5c2a49d757c882c6033828e7e Mon Sep 17 00:00:00 2001 +From: Lyude Paul <lyude@redhat.com> +Date: Fri, 6 Mar 2020 18:46:19 -0500 +Subject: [PATCH 1/4] drm/dp_mst: Rename drm_dp_mst_is_dp_mst_end_device() to + be less redundant + +It's already prefixed by dp_mst, so we don't really need to repeat +ourselves here. One of the changes I should have picked up originally +when reviewing MST DSC support. + +There should be no functional changes here + +Cc: Mikita Lipski <mikita.lipski@amd.com> +Cc: Sean Paul <seanpaul@google.com> +Cc: Hans de Goede <hdegoede@redhat.com> +Signed-off-by: Lyude Paul <lyude@redhat.com> +--- + drivers/gpu/drm/drm_dp_mst_topology.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c +index cce0b1bba591..9188c53f5c96 100644 +--- a/drivers/gpu/drm/drm_dp_mst_topology.c ++++ b/drivers/gpu/drm/drm_dp_mst_topology.c +@@ -1935,7 +1935,7 @@ static u8 drm_dp_calculate_rad(struct drm_dp_mst_port *port, + 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) { + 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, + + /* Teardown the old pdt, if there is one */ + 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, + * don't bother with reregistering it + */ + 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->mcs = new_mcs; + return 0; +@@ -1991,7 +1991,7 @@ drm_dp_port_set_pdt(struct drm_dp_mst_port *port, u8 new_pdt, + port->mcs = new_mcs; + + 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 */ + ret = drm_dp_mst_register_i2c_bus(&port->aux); + } else { +@@ -2172,7 +2172,7 @@ drm_dp_mst_port_add_connector(struct drm_dp_mst_branch *mstb, + } + + 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->aux.ddc); + drm_connector_set_tile_property(port->connector); +-- +2.25.1 + +From 270862e1b736dc0e7c56a48fbb61b5ec76236982 Mon Sep 17 00:00:00 2001 +From: Lyude Paul <lyude@redhat.com> +Date: Fri, 6 Mar 2020 18:46:20 -0500 +Subject: [PATCH 2/4] drm/dp_mst: Use full_pbn instead of available_pbn for + bandwidth checks + +DisplayPort specifications are fun. For a while, it's been really +unclear to us what available_pbn actually does. There's a somewhat vague +explanation in the DisplayPort spec (starting from 1.2) that partially +explains it: + + The minimum payload bandwidth number supported by the path. Each node + updates this number with its available payload bandwidth number if its + payload bandwidth number is less than that in the Message Transaction + reply. + +So, it sounds like available_pbn represents the smallest link rate in +use between the source and the branch device. Cool, so full_pbn is just +the highest possible PBN that the branch device supports right? + +Well, we assumed that for quite a while until Sean Paul noticed that on +some MST hubs, available_pbn will actually get set to 0 whenever there's +any active payloads on the respective branch device. This caused quite a +bit of confusion since clearing the payload ID table would end up fixing +the available_pbn value. + +So, we just went with that until commit cd82d82cbc04 ("drm/dp_mst: Add +branch bandwidth validation to MST atomic check") started breaking +people's setups due to us getting erroneous available_pbn values. So, we +did some more digging and got confused until we finally looked at the +definition for full_pbn: + + The bandwidth of the link at the trained link rate and lane count + between the DP Source device and the DP Sink device with no time slots + allocated to VC Payloads, represented as a Payload Bandwidth Number. As + with the Available_Payload_Bandwidth_Number, this number is determined + by the link with the lowest lane count and link rate. + +That's what we get for not reading specs closely enough, hehe. So, since +full_pbn is definitely what we want for doing bandwidth restriction +checks - let's start using that instead and ignore available_pbn +entirely. + +Signed-off-by: Lyude Paul <lyude@redhat.com> +Fixes: cd82d82cbc04 ("drm/dp_mst: Add branch bandwidth validation to MST atomic check") +Cc: Mikita Lipski <mikita.lipski@amd.com> +Cc: Hans de Goede <hdegoede@redhat.com> +Cc: Sean Paul <sean@poorly.run> +--- + drivers/gpu/drm/drm_dp_mst_topology.c | 15 +++++++-------- + include/drm/drm_dp_mst_helper.h | 4 ++-- + 2 files changed, 9 insertions(+), 10 deletions(-) + +diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c +index 9188c53f5c96..7df7676b45c4 100644 +--- a/drivers/gpu/drm/drm_dp_mst_topology.c ++++ b/drivers/gpu/drm/drm_dp_mst_topology.c +@@ -2309,7 +2309,7 @@ drm_dp_mst_handle_link_address_port(struct drm_dp_mst_branch *mstb, + port); + } + } else { +- port->available_pbn = 0; ++ port->full_pbn = 0; + } + } + +@@ -2404,7 +2404,7 @@ drm_dp_mst_handle_conn_stat(struct drm_dp_mst_branch *mstb, + if (port->ddps) { + dowork = true; + } else { +- port->available_pbn = 0; ++ port->full_pbn = 0; + } + } + +@@ -2556,7 +2556,7 @@ static int drm_dp_check_and_send_link_address(struct drm_dp_mst_topology_mgr *mg + if (port->input || !port->ddps) + continue; + +- if (!port->available_pbn) { ++ if (!port->full_pbn) { + drm_modeset_lock(&mgr->base.lock, NULL); + drm_dp_send_enum_path_resources(mgr, mstb, port); + drm_modeset_unlock(&mgr->base.lock); +@@ -3002,8 +3002,7 @@ drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, + path_res->port_number, + path_res->full_payload_bw_number, + path_res->avail_payload_bw_number); +- port->available_pbn = +- path_res->avail_payload_bw_number; ++ port->full_pbn = path_res->full_payload_bw_number; + port->fec_capable = path_res->fec_capable; + } + } +@@ -3598,7 +3597,7 @@ drm_dp_mst_topology_mgr_invalidate_mstb(struct drm_dp_mst_branch *mstb) + + list_for_each_entry(port, &mstb->ports, next) { + /* The PBN for each port will also need to be re-probed */ +- port->available_pbn = 0; ++ port->full_pbn = 0; + + if (port->mstb) + drm_dp_mst_topology_mgr_invalidate_mstb(port->mstb); +@@ -4842,8 +4841,8 @@ int drm_dp_mst_atomic_check_bw_limit(struct drm_dp_mst_branch *branch, + if (drm_dp_mst_atomic_check_bw_limit(port->mstb, mst_state)) + return -ENOSPC; + +- if (port->available_pbn > 0) +- pbn_limit = port->available_pbn; ++ if (port->full_pbn > 0) ++ pbn_limit = port->full_pbn; + } + DRM_DEBUG_ATOMIC("[MST BRANCH:%p] branch has %d PBN available\n", + branch, pbn_limit); +diff --git a/include/drm/drm_dp_mst_helper.h b/include/drm/drm_dp_mst_helper.h +index bcb39da9adb4..41725d88d27e 100644 +--- a/include/drm/drm_dp_mst_helper.h ++++ b/include/drm/drm_dp_mst_helper.h +@@ -81,7 +81,7 @@ struct drm_dp_vcpi { + * &drm_dp_mst_topology_mgr.base.lock. + * @num_sdp_stream_sinks: Number of stream sinks. Protected by + * &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. + * @next: link to next port on this branch device + * @aux: i2c aux transport to talk to device connected to this port, protected +@@ -126,7 +126,7 @@ struct drm_dp_mst_port { + u8 dpcd_rev; + u8 num_sdp_streams; + u8 num_sdp_stream_sinks; +- uint16_t available_pbn; ++ uint16_t full_pbn; + struct list_head next; + /** + * @mstb: the branch device connected to this port, if there is one. +-- +2.25.1 + +From 6fceb6d9d9cdef2e26558f6b75700cc0f07a812c Mon Sep 17 00:00:00 2001 +From: Lyude Paul <lyude@redhat.com> +Date: Fri, 6 Mar 2020 18:46:21 -0500 +Subject: [PATCH 3/4] drm/dp_mst: Reprobe path resources in CSN handler + +We used to punt off reprobing path resources to the link address probe +work, but now that we handle CSNs asynchronously from the driver's HPD +handling we can do whatever the heck we want from the CSN! + +So, reprobe the path resources from drm_dp_mst_handle_conn_stat(). Also, +get rid of the path resource reprobing code in +drm_dp_check_and_send_link_address() since it's needlessly complicated +when we already reprobe path resources from +drm_dp_handle_link_address_port(). And finally, teach +drm_dp_send_enum_path_resources() to return 1 on PBN changes so we know +if we need to send another hotplug or not. + +This fixes issues where we've indicated to userspace that a port has +just been connected, before we actually probed it's available PBN - +something that results in unexpected atomic check failures. + +Signed-off-by: Lyude Paul <lyude@redhat.com> +Fixes: cd82d82cbc04 ("drm/dp_mst: Add branch bandwidth validation to MST atomic check") +Cc: Mikita Lipski <mikita.lipski@amd.com> +Cc: Hans de Goede <hdegoede@redhat.com> +Cc: Sean Paul <sean@poorly.run> +--- + drivers/gpu/drm/drm_dp_mst_topology.c | 48 ++++++++++++++------------- + 1 file changed, 25 insertions(+), 23 deletions(-) + +diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c +index 7df7676b45c4..112972031a84 100644 +--- a/drivers/gpu/drm/drm_dp_mst_topology.c ++++ b/drivers/gpu/drm/drm_dp_mst_topology.c +@@ -2302,12 +2302,16 @@ drm_dp_mst_handle_link_address_port(struct drm_dp_mst_branch *mstb, + mutex_unlock(&mgr->lock); + } + +- if (old_ddps != port->ddps) { +- if (port->ddps) { +- if (!port->input) { +- drm_dp_send_enum_path_resources(mgr, mstb, +- port); +- } ++ /* ++ * Reprobe PBN caps on both hotplug, and when re-probing the link ++ * for our parent mstb ++ */ ++ if (old_ddps != port->ddps || !created) { ++ if (port->ddps && !port->input) { ++ ret = drm_dp_send_enum_path_resources(mgr, mstb, ++ port); ++ if (ret == 1) ++ changed = true; + } else { + port->full_pbn = 0; + } +@@ -2401,11 +2405,10 @@ drm_dp_mst_handle_conn_stat(struct drm_dp_mst_branch *mstb, + port->ddps = conn_stat->displayport_device_plug_status; + + if (old_ddps != port->ddps) { +- if (port->ddps) { +- dowork = true; +- } else { ++ if (port->ddps && !port->input) ++ drm_dp_send_enum_path_resources(mgr, mstb, port); ++ else + port->full_pbn = 0; +- } + } + + 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 + if (port->input || !port->ddps) + continue; + +- if (!port->full_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) + mstb_child = drm_dp_mst_topology_get_mstb_validated( + mgr, port->mstb); +@@ -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); + if (ret > 0) { ++ ret = 0; + path_res = &txmsg->reply.u.path_resources; + + if (txmsg->reply.reply_type == DP_SIDEBAND_REPLY_NAK) { +@@ -3002,13 +2999,22 @@ drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, + path_res->port_number, + path_res->full_payload_bw_number, + 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; + } + } + + 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) +@@ -3595,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 */ + mstb->link_address_sent = false; + +- list_for_each_entry(port, &mstb->ports, next) { +- /* The PBN for each port will also need to be re-probed */ +- port->full_pbn = 0; +- ++ list_for_each_entry(port, &mstb->ports, next) + if (port->mstb) + drm_dp_mst_topology_mgr_invalidate_mstb(port->mstb); +- } + } + + /** +-- +2.25.1 + +From 20c8afc6f3f18187517411323a125dfff3c014e7 Mon Sep 17 00:00:00 2001 +From: Lyude Paul <lyude@redhat.com> +Date: Fri, 6 Mar 2020 18:46:22 -0500 +Subject: [PATCH 4/4] drm/dp_mst: Rewrite and fix bandwidth limit checks +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Sigh, this is mostly my fault for not giving commit cd82d82cbc04 +("drm/dp_mst: Add branch bandwidth validation to MST atomic check") +enough scrutiny during review. The way we're checking bandwidth +limitations here is mostly wrong: + +For starters, drm_dp_mst_atomic_check_bw_limit() determines the +pbn_limit of a branch by simply scanning each port on the current branch +device, then uses the last non-zero full_pbn value that it finds. It +then counts the sum of the PBN used on each branch device for that +level, and compares against the full_pbn value it found before. + +This is wrong because ports can and will have different PBN limitations +on many hubs, especially since a number of DisplayPort hubs out there +will be clever and only use the smallest link rate required for each +downstream sink - potentially giving every port a different full_pbn +value depending on what link rate it's trained at. This means with our +current code, which max PBN value we end up with is not well defined. + +Additionally, we also need to remember when checking bandwidth +limitations that the top-most device in any MST topology is a branch +device, not a port. This means that the first level of a topology +doesn't technically have a full_pbn value that needs to be checked. +Instead, we should assume that so long as our VCPI allocations fit we're +within the bandwidth limitations of the primary MSTB. + +We do however, want to check full_pbn on every port including those of +the primary MSTB. However, it's important to keep in mind that this +value represents the minimum link rate /between a port's sink or mstb, +and the mstb itself/. A quick diagram to explain: + + MSTB #1 + / \ + / \ + Port #1 Port #2 + full_pbn for Port #1 → | | ← full_pbn for Port #2 + Sink #1 MSTB #2 + | + etc... + +Note that in the above diagram, the combined PBN from all VCPI +allocations on said hub should not exceed the full_pbn value of port #2, +and the display configuration on sink #1 should not exceed the full_pbn +value of port #1. However, port #1 and port #2 can otherwise consume as +much bandwidth as they want so long as their VCPI allocations still fit. + +And finally - our current bandwidth checking code also makes the mistake +of not checking whether something is an end device or not before trying +to traverse down it. + +So, let's fix it by rewriting our bandwidth checking helpers. We split +the function into one part for handling branches which simply adds up +the total PBN on each branch and returns it, and one for checking each +port to ensure we're not going over its PBN limit. Phew. + +This should fix regressions seen, where we erroneously reject display +configurations due to thinking they're going over our bandwidth limits +when they're not. + +Changes since v1: +* Took an even closer look at how PBN limitations are supposed to be + handled, and did some experimenting with Sean Paul. Ended up rewriting + these helpers again, but this time they should actually be correct! + +Signed-off-by: Lyude Paul <lyude@redhat.com> +Fixes: cd82d82cbc04 ("drm/dp_mst: Add branch bandwidth validation to MST atomic check") +Cc: Mikita Lipski <mikita.lipski@amd.com> +Cc: Sean Paul <seanpaul@google.com> +Cc: Hans de Goede <hdegoede@redhat.com> +--- + drivers/gpu/drm/drm_dp_mst_topology.c | 120 ++++++++++++++++++++------ + 1 file changed, 94 insertions(+), 26 deletions(-) + +diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c +index 112972031a84..415bd0770eab 100644 +--- a/drivers/gpu/drm/drm_dp_mst_topology.c ++++ b/drivers/gpu/drm/drm_dp_mst_topology.c +@@ -4830,41 +4830,103 @@ static bool drm_dp_mst_port_downstream_of_branch(struct drm_dp_mst_port *port, + return false; + } + +-static inline +-int drm_dp_mst_atomic_check_bw_limit(struct drm_dp_mst_branch *branch, +- struct drm_dp_mst_topology_state *mst_state) ++static int ++drm_dp_mst_atomic_check_port_bw_limit(struct drm_dp_mst_port *port, ++ 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; +- 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) { +- if (port->mstb) +- if (drm_dp_mst_atomic_check_bw_limit(port->mstb, mst_state)) +- return -ENOSPC; ++ /* Check that we have at least one port in our state that's downstream ++ * of this branch, otherwise we can skip this branch ++ */ ++ list_for_each_entry(vcpi, &state->vcpis, next) { ++ if (!vcpi->pbn || ++ !drm_dp_mst_port_downstream_of_branch(vcpi->port, ++ mstb)) ++ continue; + +- if (port->full_pbn > 0) +- pbn_limit = port->full_pbn; ++ found = true; ++ break; + } +- DRM_DEBUG_ATOMIC("[MST BRANCH:%p] branch has %d PBN available\n", +- branch, pbn_limit); ++ if (!found) ++ return 0; + +- list_for_each_entry(vcpi, &mst_state->vcpis, next) { +- if (!vcpi->pbn) +- continue; ++ 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); ++ ++ list_for_each_entry(port, &mstb->ports, next) { ++ ret = drm_dp_mst_atomic_check_port_bw_limit(port, state); ++ if (ret < 0) ++ return ret; + +- if (drm_dp_mst_port_downstream_of_branch(vcpi->port, branch)) +- pbn_used += vcpi->pbn; ++ pbn_used += ret; + } +- DRM_DEBUG_ATOMIC("[MST BRANCH:%p] branch used %d PBN\n", +- branch, pbn_used); + +- if (pbn_used > pbn_limit) { +- DRM_DEBUG_ATOMIC("[MST BRANCH:%p] No available bandwidth\n", +- branch); ++ return pbn_used; ++} ++ ++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; ++ if (!vcpi->pbn) ++ return 0; ++ ++ found = true; ++ 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 0; ++ } ++ ++ if (pbn_used > port->full_pbn) { ++ DRM_DEBUG_ATOMIC("[MSTB:%p] [MST PORT:%p] required PBN of %d exceeds port limit of %d\n", ++ port->parent, port, pbn_used, ++ port->full_pbn); + 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 +@@ -5062,9 +5124,15 @@ int drm_dp_mst_atomic_check(struct drm_atomic_state *state) + ret = drm_dp_mst_atomic_check_vcpi_alloc_limit(mgr, mst_state); + if (ret) + 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; ++ else ++ ret = 0; + } + + return ret; +-- +2.25.1 + |