1*f005ef32Sjsg /*
2*f005ef32Sjsg * Copyright 2023 Advanced Micro Devices, Inc.
3*f005ef32Sjsg *
4*f005ef32Sjsg * Permission is hereby granted, free of charge, to any person obtaining a
5*f005ef32Sjsg * copy of this software and associated documentation files (the "Software"),
6*f005ef32Sjsg * to deal in the Software without restriction, including without limitation
7*f005ef32Sjsg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*f005ef32Sjsg * and/or sell copies of the Software, and to permit persons to whom the
9*f005ef32Sjsg * Software is furnished to do so, subject to the following conditions:
10*f005ef32Sjsg *
11*f005ef32Sjsg * The above copyright notice and this permission notice shall be included in
12*f005ef32Sjsg * all copies or substantial portions of the Software.
13*f005ef32Sjsg *
14*f005ef32Sjsg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*f005ef32Sjsg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*f005ef32Sjsg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*f005ef32Sjsg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*f005ef32Sjsg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*f005ef32Sjsg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*f005ef32Sjsg * OTHER DEALINGS IN THE SOFTWARE.
21*f005ef32Sjsg *
22*f005ef32Sjsg * Authors: AMD
23*f005ef32Sjsg *
24*f005ef32Sjsg */
25*f005ef32Sjsg /* FILE POLICY AND INTENDED USAGE:
26*f005ef32Sjsg * This file implements accessors to link resource.
27*f005ef32Sjsg */
28*f005ef32Sjsg
29*f005ef32Sjsg #include "link_resource.h"
30*f005ef32Sjsg #include "protocols/link_dp_capability.h"
31*f005ef32Sjsg
link_get_cur_link_res(const struct dc_link * link,struct link_resource * link_res)32*f005ef32Sjsg void link_get_cur_link_res(const struct dc_link *link,
33*f005ef32Sjsg struct link_resource *link_res)
34*f005ef32Sjsg {
35*f005ef32Sjsg int i;
36*f005ef32Sjsg struct pipe_ctx *pipe = NULL;
37*f005ef32Sjsg
38*f005ef32Sjsg memset(link_res, 0, sizeof(*link_res));
39*f005ef32Sjsg
40*f005ef32Sjsg for (i = 0; i < MAX_PIPES; i++) {
41*f005ef32Sjsg pipe = &link->dc->current_state->res_ctx.pipe_ctx[i];
42*f005ef32Sjsg if (pipe->stream && pipe->stream->link && pipe->top_pipe == NULL) {
43*f005ef32Sjsg if (pipe->stream->link == link) {
44*f005ef32Sjsg *link_res = pipe->link_res;
45*f005ef32Sjsg break;
46*f005ef32Sjsg }
47*f005ef32Sjsg }
48*f005ef32Sjsg }
49*f005ef32Sjsg
50*f005ef32Sjsg }
51*f005ef32Sjsg
link_get_cur_res_map(const struct dc * dc,uint32_t * map)52*f005ef32Sjsg void link_get_cur_res_map(const struct dc *dc, uint32_t *map)
53*f005ef32Sjsg {
54*f005ef32Sjsg struct dc_link *link;
55*f005ef32Sjsg uint32_t i;
56*f005ef32Sjsg uint32_t hpo_dp_recycle_map = 0;
57*f005ef32Sjsg
58*f005ef32Sjsg *map = 0;
59*f005ef32Sjsg
60*f005ef32Sjsg if (dc->caps.dp_hpo) {
61*f005ef32Sjsg for (i = 0; i < dc->caps.max_links; i++) {
62*f005ef32Sjsg link = dc->links[i];
63*f005ef32Sjsg if (link->link_status.link_active &&
64*f005ef32Sjsg link_dp_get_encoding_format(&link->reported_link_cap) == DP_128b_132b_ENCODING &&
65*f005ef32Sjsg link_dp_get_encoding_format(&link->cur_link_settings) != DP_128b_132b_ENCODING)
66*f005ef32Sjsg /* hpo dp link encoder is considered as recycled, when RX reports 128b/132b encoding capability
67*f005ef32Sjsg * but current link doesn't use it.
68*f005ef32Sjsg */
69*f005ef32Sjsg hpo_dp_recycle_map |= (1 << i);
70*f005ef32Sjsg }
71*f005ef32Sjsg *map |= (hpo_dp_recycle_map << LINK_RES_HPO_DP_REC_MAP__SHIFT);
72*f005ef32Sjsg }
73*f005ef32Sjsg }
74*f005ef32Sjsg
link_restore_res_map(const struct dc * dc,uint32_t * map)75*f005ef32Sjsg void link_restore_res_map(const struct dc *dc, uint32_t *map)
76*f005ef32Sjsg {
77*f005ef32Sjsg struct dc_link *link;
78*f005ef32Sjsg uint32_t i;
79*f005ef32Sjsg unsigned int available_hpo_dp_count;
80*f005ef32Sjsg uint32_t hpo_dp_recycle_map = (*map & LINK_RES_HPO_DP_REC_MAP__MASK)
81*f005ef32Sjsg >> LINK_RES_HPO_DP_REC_MAP__SHIFT;
82*f005ef32Sjsg
83*f005ef32Sjsg if (dc->caps.dp_hpo) {
84*f005ef32Sjsg available_hpo_dp_count = dc->res_pool->hpo_dp_link_enc_count;
85*f005ef32Sjsg /* remove excess 128b/132b encoding support for not recycled links */
86*f005ef32Sjsg for (i = 0; i < dc->caps.max_links; i++) {
87*f005ef32Sjsg if ((hpo_dp_recycle_map & (1 << i)) == 0) {
88*f005ef32Sjsg link = dc->links[i];
89*f005ef32Sjsg if (link->type != dc_connection_none &&
90*f005ef32Sjsg link_dp_get_encoding_format(&link->verified_link_cap) == DP_128b_132b_ENCODING) {
91*f005ef32Sjsg if (available_hpo_dp_count > 0)
92*f005ef32Sjsg available_hpo_dp_count--;
93*f005ef32Sjsg else
94*f005ef32Sjsg /* remove 128b/132b encoding capability by limiting verified link rate to HBR3 */
95*f005ef32Sjsg link->verified_link_cap.link_rate = LINK_RATE_HIGH3;
96*f005ef32Sjsg }
97*f005ef32Sjsg }
98*f005ef32Sjsg }
99*f005ef32Sjsg /* remove excess 128b/132b encoding support for recycled links */
100*f005ef32Sjsg for (i = 0; i < dc->caps.max_links; i++) {
101*f005ef32Sjsg if ((hpo_dp_recycle_map & (1 << i)) != 0) {
102*f005ef32Sjsg link = dc->links[i];
103*f005ef32Sjsg if (link->type != dc_connection_none &&
104*f005ef32Sjsg link_dp_get_encoding_format(&link->verified_link_cap) == DP_128b_132b_ENCODING) {
105*f005ef32Sjsg if (available_hpo_dp_count > 0)
106*f005ef32Sjsg available_hpo_dp_count--;
107*f005ef32Sjsg else
108*f005ef32Sjsg /* remove 128b/132b encoding capability by limiting verified link rate to HBR3 */
109*f005ef32Sjsg link->verified_link_cap.link_rate = LINK_RATE_HIGH3;
110*f005ef32Sjsg }
111*f005ef32Sjsg }
112*f005ef32Sjsg }
113*f005ef32Sjsg }
114*f005ef32Sjsg }
115