@@ -4890,3 +4890,106 @@ const struct link_resource *dc_link_get_cur_link_res(const struct dc_link *link)
48904890
48914891 return link_res ;
48924892}
4893+
4894+ /**
4895+ * dc_get_cur_link_res_map() - take a snapshot of current link resource allocation state
4896+ * @dc: pointer to dc of the dm calling this
4897+ * @map: a dc link resource snapshot defined internally to dc.
4898+ *
4899+ * DM needs to capture a snapshot of current link resource allocation mapping
4900+ * and store it in its persistent storage.
4901+ *
4902+ * Some of the link resource is using first come first serve policy.
4903+ * The allocation mapping depends on original hotplug order. This information
4904+ * is lost after driver is loaded next time. The snapshot is used in order to
4905+ * restore link resource to its previous state so user will get consistent
4906+ * link capability allocation across reboot.
4907+ *
4908+ * Return: none (void function)
4909+ *
4910+ */
4911+ void dc_get_cur_link_res_map (const struct dc * dc , uint32_t * map )
4912+ {
4913+ #if defined(CONFIG_DRM_AMD_DC_DCN )
4914+ struct dc_link * link ;
4915+ uint8_t i ;
4916+ uint32_t hpo_dp_recycle_map = 0 ;
4917+
4918+ * map = 0 ;
4919+
4920+ if (dc -> caps .dp_hpo ) {
4921+ for (i = 0 ; i < dc -> caps .max_links ; i ++ ) {
4922+ link = dc -> links [i ];
4923+ if (link -> link_status .link_active &&
4924+ dp_get_link_encoding_format (& link -> reported_link_cap ) == DP_128b_132b_ENCODING &&
4925+ dp_get_link_encoding_format (& link -> cur_link_settings ) != DP_128b_132b_ENCODING )
4926+ /* hpo dp link encoder is considered as recycled, when RX reports 128b/132b encoding capability
4927+ * but current link doesn't use it.
4928+ */
4929+ hpo_dp_recycle_map |= (1 << i );
4930+ }
4931+ * map |= (hpo_dp_recycle_map << LINK_RES_HPO_DP_REC_MAP__SHIFT );
4932+ }
4933+ #endif
4934+ }
4935+
4936+ /**
4937+ * dc_restore_link_res_map() - restore link resource allocation state from a snapshot
4938+ * @dc: pointer to dc of the dm calling this
4939+ * @map: a dc link resource snapshot defined internally to dc.
4940+ *
4941+ * DM needs to call this function after initial link detection on boot and
4942+ * before first commit streams to restore link resource allocation state
4943+ * from previous boot session.
4944+ *
4945+ * Some of the link resource is using first come first serve policy.
4946+ * The allocation mapping depends on original hotplug order. This information
4947+ * is lost after driver is loaded next time. The snapshot is used in order to
4948+ * restore link resource to its previous state so user will get consistent
4949+ * link capability allocation across reboot.
4950+ *
4951+ * Return: none (void function)
4952+ *
4953+ */
4954+ void dc_restore_link_res_map (const struct dc * dc , uint32_t * map )
4955+ {
4956+ #if defined(CONFIG_DRM_AMD_DC_DCN )
4957+ struct dc_link * link ;
4958+ uint8_t i ;
4959+ unsigned int available_hpo_dp_count ;
4960+ uint32_t hpo_dp_recycle_map = (* map & LINK_RES_HPO_DP_REC_MAP__MASK )
4961+ >> LINK_RES_HPO_DP_REC_MAP__SHIFT ;
4962+
4963+ if (dc -> caps .dp_hpo ) {
4964+ available_hpo_dp_count = dc -> res_pool -> hpo_dp_link_enc_count ;
4965+ /* remove excess 128b/132b encoding support for not recycled links */
4966+ for (i = 0 ; i < dc -> caps .max_links ; i ++ ) {
4967+ if ((hpo_dp_recycle_map & (1 << i )) == 0 ) {
4968+ link = dc -> links [i ];
4969+ if (link -> type != dc_connection_none &&
4970+ dp_get_link_encoding_format (& link -> verified_link_cap ) == DP_128b_132b_ENCODING ) {
4971+ if (available_hpo_dp_count > 0 )
4972+ available_hpo_dp_count -- ;
4973+ else
4974+ /* remove 128b/132b encoding capability by limiting verified link rate to HBR3 */
4975+ link -> verified_link_cap .link_rate = LINK_RATE_HIGH3 ;
4976+ }
4977+ }
4978+ }
4979+ /* remove excess 128b/132b encoding support for recycled links */
4980+ for (i = 0 ; i < dc -> caps .max_links ; i ++ ) {
4981+ if ((hpo_dp_recycle_map & (1 << i )) != 0 ) {
4982+ link = dc -> links [i ];
4983+ if (link -> type != dc_connection_none &&
4984+ dp_get_link_encoding_format (& link -> verified_link_cap ) == DP_128b_132b_ENCODING ) {
4985+ if (available_hpo_dp_count > 0 )
4986+ available_hpo_dp_count -- ;
4987+ else
4988+ /* remove 128b/132b encoding capability by limiting verified link rate to HBR3 */
4989+ link -> verified_link_cap .link_rate = LINK_RATE_HIGH3 ;
4990+ }
4991+ }
4992+ }
4993+ }
4994+ #endif
4995+ }
0 commit comments