drm/amd/display: Allocation at stream Enable
authorMustapha Ghaddar <mghaddar@amd.com>
Fri, 3 Feb 2023 18:41:13 +0000 (13:41 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 28 Feb 2023 19:29:35 +0000 (14:29 -0500)
[WHY & HOW]
After we allocate BW at plug, we will de-alloc
and allocate only what stream needs at
stream_enable()

[HOW]
Introduce bw allocation check at link_enable()
for DPIA links

Reviewed-by: Wenjing Liu <Wenjing.Liu@amd.com>
Acked-by: Qingqing Zhuo <qingqing.zhuo@amd.com>
Signed-off-by: Mustapha Ghaddar <mghaddar@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/dc_link.h
drivers/gpu/drm/amd/display/dc/link/link_dpms.c
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.h

index cecd807f5ed832990eea130b11368ca96f59412a..bfe0f6877d9e24c744e69ff4e01e7f92a80b144c 100644 (file)
@@ -293,6 +293,8 @@ struct dc_link {
 
        struct dc_panel_config panel_config;
        struct phy_state phy_state;
+       // BW ALLOCATON USB4 ONLY
+       struct dc_dpia_bw_alloc dpia_bw_alloc_config;
 };
 
 
index 180c92a9f1176bf6f2852bd5c4a3ef59500aed59..a1214e5606dd4162eb7f1efa0daac352fb4f7438 100644 (file)
@@ -46,6 +46,7 @@
 #include "protocols/link_dp_capability.h"
 #include "protocols/link_dp_training.h"
 #include "protocols/link_edp_panel_control.h"
+#include "protocols/link_dp_dpia_bw.h"
 
 #include "dm_helpers.h"
 #include "link_enc_cfg.h"
@@ -2044,11 +2045,17 @@ static enum dc_status enable_link_dp(struct dc_state *state,
                }
        }
 
-       /* Train with fallback when enabling DPIA link. Conventional links are
+       /*
+        * If the link is DP-over-USB4 do the following:
+        * - Train with fallback when enabling DPIA link. Conventional links are
         * trained with fallback during sink detection.
+        * - Allocate only what the stream needs for bw in Gbps. Inform the CM
+        * in case stream needs more or less bw from what has been allocated
+        * earlier at plug time.
         */
-       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
+       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
                do_fallback = true;
+       }
 
        /*
         * Temporary w/a to get DP2.0 link rates to work with SST.
index fcb82bb855ed9b692602b749ba18a1eb1464a027..9d3df69fc3408ad09e8a8aec206280242dab8fc4 100644 (file)
@@ -246,7 +246,7 @@ static bool get_cm_response_ready_flag(struct dc_link *link)
 // ------------------------------------------------------------------
 //                                     PUBLIC FUNCTIONS
 // ------------------------------------------------------------------
-bool set_dptx_usb4_bw_alloc_support(struct dc_link *link)
+bool link_dp_dpia_set_dptx_usb4_bw_alloc_support(struct dc_link *link)
 {
        bool ret = false;
        uint8_t response = 0,
@@ -439,3 +439,34 @@ int dc_link_dp_dpia_handle_usb4_bandwidth_allocation_for_link(struct dc_link *li
 out:
        return ret;
 }
+int link_dp_dpia_allocate_usb4_bandwidth_for_stream(struct dc_link *link, int req_bw)
+{
+       int ret = 0;
+       uint8_t timeout = 10;
+
+       if (!get_bw_alloc_proceed_flag(link))
+               goto out;
+
+       /*
+        * Sometimes stream uses same timing parameters as the already
+        * allocated max sink bw so no need to re-alloc
+        */
+       if (req_bw != link->dpia_bw_alloc_config.sink_allocated_bw) {
+               dc_link_set_usb4_req_bw_req(link, req_bw);
+               do {
+                       if (!timeout > 0)
+                               timeout--;
+                       else
+                               break;
+                       udelay(10 * 1000);
+               } while (!get_cm_response_ready_flag(link));
+
+               if (!timeout)
+                       ret = 0;// ERROR TIMEOUT waiting for response for allocating bw
+               else if (link->dpia_bw_alloc_config.sink_allocated_bw > 0)
+                       ret = get_host_router_total_bw(link, HOST_ROUTER_BW_ALLOCATED);
+       }
+
+out:
+       return ret;
+}
index c2c3049adcd143bb4495661c8bfbf0acc4a79209..46d141a1366f471951a4eb4f6ec1defdcbfae022 100644 (file)
@@ -42,6 +42,18 @@ enum bw_type {
  *
  * return: SUCCESS or FAILURE
  */
-bool set_dptx_usb4_bw_alloc_support(struct dc_link *link);
+bool link_dp_dpia_set_dptx_usb4_bw_alloc_support(struct dc_link *link);
+
+/*
+ * Allocates only what the stream needs for bw, so if:
+ * If (stream_req_bw < or > already_allocated_bw_at_HPD)
+ * => Deallocate Max Bw & then allocate only what the stream needs
+ *
+ * @link: pointer to the dc_link struct instance
+ * @req_bw: Bw requested by the stream
+ *
+ * return: allocated bw else return 0
+ */
+int link_dp_dpia_allocate_usb4_bandwidth_for_stream(struct dc_link *link, int req_bw);
 
 #endif /* DC_INC_LINK_DP_DPIA_BW_H_ */