]>
Commit | Line | Data |
---|---|---|
f42ef862 JK |
1 | /* |
2 | * Copyright 2021 Advanced Micro Devices, Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
20 | * OTHER DEALINGS IN THE SOFTWARE. | |
21 | * | |
22 | * Authors: AMD | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "link_enc_cfg.h" | |
27 | #include "resource.h" | |
28 | #include "dc_link_dp.h" | |
29 | ||
30 | /* Check whether stream is supported by DIG link encoders. */ | |
31 | static bool is_dig_link_enc_stream(struct dc_stream_state *stream) | |
32 | { | |
33 | bool is_dig_stream = false; | |
34 | struct link_encoder *link_enc = NULL; | |
35 | int i; | |
36 | ||
37 | /* Loop over created link encoder objects. */ | |
ec7077b5 JK |
38 | if (stream) { |
39 | for (i = 0; i < stream->ctx->dc->res_pool->res_cap->num_dig_link_enc; i++) { | |
40 | link_enc = stream->ctx->dc->res_pool->link_encoders[i]; | |
41 | ||
42 | /* Need to check link signal type rather than stream signal type which may not | |
43 | * yet match. | |
44 | */ | |
45 | if (link_enc && ((uint32_t)stream->link->connector_signal & link_enc->output_signals)) { | |
46 | if (dc_is_dp_signal(stream->signal)) { | |
47 | /* DIGs do not support DP2.0 streams with 128b/132b encoding. */ | |
48 | struct dc_link_settings link_settings = {0}; | |
49 | ||
50 | decide_link_settings(stream, &link_settings); | |
51 | if ((link_settings.link_rate >= LINK_RATE_LOW) && | |
52 | link_settings.link_rate <= LINK_RATE_HIGH3) { | |
53 | is_dig_stream = true; | |
54 | break; | |
55 | } | |
56 | } else { | |
f42ef862 JK |
57 | is_dig_stream = true; |
58 | break; | |
59 | } | |
f42ef862 JK |
60 | } |
61 | } | |
62 | } | |
f42ef862 JK |
63 | return is_dig_stream; |
64 | } | |
65 | ||
6f941d4e JK |
66 | static struct link_enc_assignment get_assignment(struct dc *dc, int i) |
67 | { | |
68 | struct link_enc_assignment assignment; | |
69 | ||
70 | if (dc->current_state->res_ctx.link_enc_cfg_ctx.mode == LINK_ENC_CFG_TRANSIENT) | |
71 | assignment = dc->current_state->res_ctx.link_enc_cfg_ctx.transient_assignments[i]; | |
72 | else /* LINK_ENC_CFG_STEADY */ | |
73 | assignment = dc->current_state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; | |
74 | ||
75 | return assignment; | |
76 | } | |
77 | ||
ec7077b5 JK |
78 | /* Return stream using DIG link encoder resource. NULL if unused. */ |
79 | static struct dc_stream_state *get_stream_using_link_enc( | |
80 | struct dc_state *state, | |
81 | enum engine_id eng_id) | |
82 | { | |
83 | struct dc_stream_state *stream = NULL; | |
84 | int i; | |
85 | ||
86 | for (i = 0; i < state->stream_count; i++) { | |
6f941d4e | 87 | struct link_enc_assignment assignment = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
ec7077b5 JK |
88 | |
89 | if ((assignment.valid == true) && (assignment.eng_id == eng_id)) { | |
90 | stream = state->streams[i]; | |
91 | break; | |
92 | } | |
93 | } | |
94 | ||
95 | return stream; | |
96 | } | |
97 | ||
98 | static void remove_link_enc_assignment( | |
f42ef862 JK |
99 | struct dc_state *state, |
100 | struct dc_stream_state *stream, | |
ec7077b5 | 101 | enum engine_id eng_id) |
f42ef862 JK |
102 | { |
103 | int eng_idx; | |
f42ef862 JK |
104 | int i; |
105 | ||
106 | if (eng_id != ENGINE_ID_UNKNOWN) { | |
107 | eng_idx = eng_id - ENGINE_ID_DIGA; | |
f42ef862 | 108 | |
ec7077b5 | 109 | /* stream ptr of stream in dc_state used to update correct entry in |
f42ef862 JK |
110 | * link_enc_assignments table. |
111 | */ | |
ec7077b5 | 112 | for (i = 0; i < MAX_PIPES; i++) { |
6f941d4e | 113 | struct link_enc_assignment assignment = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
ec7077b5 JK |
114 | |
115 | if (assignment.valid && assignment.stream == stream) { | |
6f941d4e | 116 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].valid = false; |
ec7077b5 JK |
117 | /* Only add link encoder back to availability pool if not being |
118 | * used by any other stream (i.e. removing SST stream or last MST stream). | |
119 | */ | |
120 | if (get_stream_using_link_enc(state, eng_id) == NULL) | |
6f941d4e | 121 | state->res_ctx.link_enc_cfg_ctx.link_enc_avail[eng_idx] = eng_id; |
77f37faa | 122 | |
ec7077b5 | 123 | stream->link_enc = NULL; |
77f37faa RC |
124 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].eng_id = ENGINE_ID_UNKNOWN; |
125 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].stream = NULL; | |
f42ef862 JK |
126 | break; |
127 | } | |
128 | } | |
ec7077b5 JK |
129 | } |
130 | } | |
131 | ||
132 | static void add_link_enc_assignment( | |
133 | struct dc_state *state, | |
134 | struct dc_stream_state *stream, | |
135 | enum engine_id eng_id) | |
136 | { | |
137 | int eng_idx; | |
138 | int i; | |
139 | ||
140 | if (eng_id != ENGINE_ID_UNKNOWN) { | |
141 | eng_idx = eng_id - ENGINE_ID_DIGA; | |
f42ef862 | 142 | |
ec7077b5 JK |
143 | /* stream ptr of stream in dc_state used to update correct entry in |
144 | * link_enc_assignments table. | |
f42ef862 | 145 | */ |
ec7077b5 JK |
146 | for (i = 0; i < state->stream_count; i++) { |
147 | if (stream == state->streams[i]) { | |
6f941d4e | 148 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i] = (struct link_enc_assignment){ |
f42ef862 JK |
149 | .valid = true, |
150 | .ep_id = (struct display_endpoint_id) { | |
151 | .link_id = stream->link->link_id, | |
152 | .ep_type = stream->link->ep_type}, | |
ec7077b5 JK |
153 | .eng_id = eng_id, |
154 | .stream = stream}; | |
6f941d4e | 155 | state->res_ctx.link_enc_cfg_ctx.link_enc_avail[eng_idx] = ENGINE_ID_UNKNOWN; |
f42ef862 | 156 | stream->link_enc = stream->ctx->dc->res_pool->link_encoders[eng_idx]; |
ec7077b5 | 157 | break; |
f42ef862 | 158 | } |
f42ef862 | 159 | } |
ec7077b5 JK |
160 | |
161 | /* Attempted to add an encoder assignment for a stream not in dc_state. */ | |
162 | ASSERT(i != state->stream_count); | |
f42ef862 JK |
163 | } |
164 | } | |
165 | ||
166 | /* Return first available DIG link encoder. */ | |
167 | static enum engine_id find_first_avail_link_enc( | |
ede4f6da JK |
168 | const struct dc_context *ctx, |
169 | const struct dc_state *state) | |
f42ef862 JK |
170 | { |
171 | enum engine_id eng_id = ENGINE_ID_UNKNOWN; | |
172 | int i; | |
173 | ||
174 | for (i = 0; i < ctx->dc->res_pool->res_cap->num_dig_link_enc; i++) { | |
6f941d4e | 175 | eng_id = state->res_ctx.link_enc_cfg_ctx.link_enc_avail[i]; |
f42ef862 JK |
176 | if (eng_id != ENGINE_ID_UNKNOWN) |
177 | break; | |
178 | } | |
179 | ||
180 | return eng_id; | |
181 | } | |
182 | ||
ec7077b5 | 183 | static bool is_avail_link_enc(struct dc_state *state, enum engine_id eng_id) |
79ed7354 | 184 | { |
ec7077b5 JK |
185 | bool is_avail = false; |
186 | int eng_idx = eng_id - ENGINE_ID_DIGA; | |
79ed7354 | 187 | |
6f941d4e | 188 | if (eng_id != ENGINE_ID_UNKNOWN && state->res_ctx.link_enc_cfg_ctx.link_enc_avail[eng_idx] != ENGINE_ID_UNKNOWN) |
ec7077b5 | 189 | is_avail = true; |
79ed7354 | 190 | |
ec7077b5 JK |
191 | return is_avail; |
192 | } | |
79ed7354 | 193 | |
ec7077b5 JK |
194 | /* Test for display_endpoint_id equality. */ |
195 | static bool are_ep_ids_equal(struct display_endpoint_id *lhs, struct display_endpoint_id *rhs) | |
196 | { | |
197 | bool are_equal = false; | |
79ed7354 | 198 | |
ec7077b5 JK |
199 | if (lhs->link_id.id == rhs->link_id.id && |
200 | lhs->link_id.enum_id == rhs->link_id.enum_id && | |
201 | lhs->link_id.type == rhs->link_id.type && | |
202 | lhs->ep_type == rhs->ep_type) | |
203 | are_equal = true; | |
204 | ||
205 | return are_equal; | |
79ed7354 JK |
206 | } |
207 | ||
6f941d4e JK |
208 | static struct link_encoder *get_link_enc_used_by_link( |
209 | struct dc_state *state, | |
210 | const struct dc_link *link) | |
211 | { | |
212 | struct link_encoder *link_enc = NULL; | |
213 | struct display_endpoint_id ep_id; | |
214 | int i; | |
215 | ||
216 | ep_id = (struct display_endpoint_id) { | |
217 | .link_id = link->link_id, | |
218 | .ep_type = link->ep_type}; | |
219 | ||
797c598d | 220 | for (i = 0; i < MAX_PIPES; i++) { |
6f941d4e JK |
221 | struct link_enc_assignment assignment = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
222 | ||
223 | if (assignment.valid == true && are_ep_ids_equal(&assignment.ep_id, &ep_id)) | |
224 | link_enc = link->dc->res_pool->link_encoders[assignment.eng_id - ENGINE_ID_DIGA]; | |
225 | } | |
226 | ||
227 | return link_enc; | |
228 | } | |
55917340 | 229 | /* Clear all link encoder assignments. */ |
6faacf90 | 230 | static void clear_enc_assignments(const struct dc *dc, struct dc_state *state) |
55917340 JK |
231 | { |
232 | int i; | |
55917340 JK |
233 | |
234 | for (i = 0; i < MAX_PIPES; i++) { | |
235 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].valid = false; | |
77f37faa RC |
236 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].eng_id = ENGINE_ID_UNKNOWN; |
237 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].stream = NULL; | |
55917340 | 238 | } |
f42ef862 JK |
239 | |
240 | for (i = 0; i < dc->res_pool->res_cap->num_dig_link_enc; i++) { | |
241 | if (dc->res_pool->link_encoders[i]) | |
6f941d4e | 242 | state->res_ctx.link_enc_cfg_ctx.link_enc_avail[i] = (enum engine_id) i; |
f42ef862 | 243 | else |
6f941d4e | 244 | state->res_ctx.link_enc_cfg_ctx.link_enc_avail[i] = ENGINE_ID_UNKNOWN; |
f42ef862 | 245 | } |
77f37faa | 246 | } |
6f941d4e | 247 | |
77f37faa | 248 | void link_enc_cfg_init( |
6faacf90 | 249 | const struct dc *dc, |
77f37faa RC |
250 | struct dc_state *state) |
251 | { | |
252 | clear_enc_assignments(dc, state); | |
55917340 | 253 | |
6f941d4e | 254 | state->res_ctx.link_enc_cfg_ctx.mode = LINK_ENC_CFG_STEADY; |
f42ef862 JK |
255 | } |
256 | ||
257 | void link_enc_cfg_link_encs_assign( | |
258 | struct dc *dc, | |
259 | struct dc_state *state, | |
260 | struct dc_stream_state *streams[], | |
261 | uint8_t stream_count) | |
262 | { | |
263 | enum engine_id eng_id = ENGINE_ID_UNKNOWN; | |
264 | int i; | |
ec7077b5 JK |
265 | int j; |
266 | ||
267 | ASSERT(state->stream_count == stream_count); | |
f42ef862 JK |
268 | |
269 | /* Release DIG link encoder resources before running assignment algorithm. */ | |
77f37faa RC |
270 | for (i = 0; i < dc->current_state->stream_count; i++) |
271 | dc->res_pool->funcs->link_enc_unassign(state, dc->current_state->streams[i]); | |
f42ef862 | 272 | |
ec7077b5 | 273 | for (i = 0; i < MAX_PIPES; i++) |
6f941d4e | 274 | ASSERT(state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].valid == false); |
ec7077b5 | 275 | |
f42ef862 JK |
276 | /* (a) Assign DIG link encoders to physical (unmappable) endpoints first. */ |
277 | for (i = 0; i < stream_count; i++) { | |
278 | struct dc_stream_state *stream = streams[i]; | |
279 | ||
280 | /* Skip stream if not supported by DIG link encoder. */ | |
281 | if (!is_dig_link_enc_stream(stream)) | |
282 | continue; | |
283 | ||
284 | /* Physical endpoints have a fixed mapping to DIG link encoders. */ | |
285 | if (!stream->link->is_dig_mapping_flexible) { | |
286 | eng_id = stream->link->eng_id; | |
ec7077b5 JK |
287 | add_link_enc_assignment(state, stream, eng_id); |
288 | } | |
289 | } | |
290 | ||
291 | /* (b) Retain previous assignments for mappable endpoints if encoders still available. */ | |
292 | eng_id = ENGINE_ID_UNKNOWN; | |
293 | ||
294 | if (state != dc->current_state) { | |
295 | struct dc_state *prev_state = dc->current_state; | |
296 | ||
297 | for (i = 0; i < stream_count; i++) { | |
298 | struct dc_stream_state *stream = state->streams[i]; | |
299 | ||
300 | /* Skip stream if not supported by DIG link encoder. */ | |
301 | if (!is_dig_link_enc_stream(stream)) | |
302 | continue; | |
303 | ||
304 | if (!stream->link->is_dig_mapping_flexible) | |
305 | continue; | |
306 | ||
307 | for (j = 0; j < prev_state->stream_count; j++) { | |
308 | struct dc_stream_state *prev_stream = prev_state->streams[j]; | |
309 | ||
310 | if (stream == prev_stream && stream->link == prev_stream->link && | |
6f941d4e JK |
311 | prev_state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[j].valid) { |
312 | eng_id = prev_state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[j].eng_id; | |
ec7077b5 JK |
313 | if (is_avail_link_enc(state, eng_id)) |
314 | add_link_enc_assignment(state, stream, eng_id); | |
315 | } | |
316 | } | |
f42ef862 JK |
317 | } |
318 | } | |
319 | ||
ec7077b5 | 320 | /* (c) Then assign encoders to remaining mappable endpoints. */ |
f42ef862 JK |
321 | eng_id = ENGINE_ID_UNKNOWN; |
322 | ||
323 | for (i = 0; i < stream_count; i++) { | |
324 | struct dc_stream_state *stream = streams[i]; | |
325 | ||
326 | /* Skip stream if not supported by DIG link encoder. */ | |
ec7077b5 JK |
327 | if (!is_dig_link_enc_stream(stream)) { |
328 | ASSERT(stream->link->is_dig_mapping_flexible != true); | |
f42ef862 | 329 | continue; |
ec7077b5 | 330 | } |
f42ef862 JK |
331 | |
332 | /* Mappable endpoints have a flexible mapping to DIG link encoders. */ | |
333 | if (stream->link->is_dig_mapping_flexible) { | |
ec7077b5 JK |
334 | struct link_encoder *link_enc = NULL; |
335 | ||
336 | /* Skip if encoder assignment retained in step (b) above. */ | |
337 | if (stream->link_enc) | |
338 | continue; | |
339 | ||
340 | /* For MST, multiple streams will share the same link / display | |
341 | * endpoint. These streams should use the same link encoder | |
342 | * assigned to that endpoint. | |
343 | */ | |
6f941d4e | 344 | link_enc = get_link_enc_used_by_link(state, stream->link); |
ec7077b5 JK |
345 | if (link_enc == NULL) |
346 | eng_id = find_first_avail_link_enc(stream->ctx, state); | |
347 | else | |
348 | eng_id = link_enc->preferred_engine; | |
349 | add_link_enc_assignment(state, stream, eng_id); | |
f42ef862 JK |
350 | } |
351 | } | |
ec7077b5 JK |
352 | |
353 | link_enc_cfg_validate(dc, state); | |
6f941d4e JK |
354 | |
355 | /* Update transient assignments. */ | |
356 | for (i = 0; i < MAX_PIPES; i++) { | |
357 | dc->current_state->res_ctx.link_enc_cfg_ctx.transient_assignments[i] = | |
358 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; | |
359 | } | |
360 | ||
361 | /* Current state mode will be set to steady once this state committed. */ | |
362 | state->res_ctx.link_enc_cfg_ctx.mode = LINK_ENC_CFG_STEADY; | |
f42ef862 JK |
363 | } |
364 | ||
365 | void link_enc_cfg_link_enc_unassign( | |
366 | struct dc_state *state, | |
367 | struct dc_stream_state *stream) | |
368 | { | |
369 | enum engine_id eng_id = ENGINE_ID_UNKNOWN; | |
370 | ||
371 | /* Only DIG link encoders. */ | |
372 | if (!is_dig_link_enc_stream(stream)) | |
373 | return; | |
374 | ||
375 | if (stream->link_enc) | |
376 | eng_id = stream->link_enc->preferred_engine; | |
377 | ||
ec7077b5 | 378 | remove_link_enc_assignment(state, stream, eng_id); |
f42ef862 | 379 | } |
79ed7354 JK |
380 | |
381 | bool link_enc_cfg_is_transmitter_mappable( | |
6f941d4e | 382 | struct dc *dc, |
79ed7354 JK |
383 | struct link_encoder *link_enc) |
384 | { | |
385 | bool is_mappable = false; | |
386 | enum engine_id eng_id = link_enc->preferred_engine; | |
6f941d4e | 387 | struct dc_stream_state *stream = link_enc_cfg_get_stream_using_link_enc(dc, eng_id); |
79ed7354 JK |
388 | |
389 | if (stream) | |
390 | is_mappable = stream->link->is_dig_mapping_flexible; | |
391 | ||
392 | return is_mappable; | |
393 | } | |
394 | ||
6f941d4e JK |
395 | struct dc_stream_state *link_enc_cfg_get_stream_using_link_enc( |
396 | struct dc *dc, | |
79ed7354 JK |
397 | enum engine_id eng_id) |
398 | { | |
6f941d4e | 399 | struct dc_stream_state *stream = NULL; |
79ed7354 JK |
400 | int i; |
401 | ||
6f941d4e JK |
402 | for (i = 0; i < MAX_PIPES; i++) { |
403 | struct link_enc_assignment assignment = get_assignment(dc, i); | |
79ed7354 | 404 | |
940e084d | 405 | if ((assignment.valid == true) && (assignment.eng_id == eng_id)) { |
6f941d4e | 406 | stream = assignment.stream; |
79ed7354 JK |
407 | break; |
408 | } | |
409 | } | |
410 | ||
6f941d4e JK |
411 | return stream; |
412 | } | |
79ed7354 | 413 | |
6f941d4e JK |
414 | struct dc_link *link_enc_cfg_get_link_using_link_enc( |
415 | struct dc *dc, | |
416 | enum engine_id eng_id) | |
417 | { | |
418 | struct dc_link *link = NULL; | |
419 | struct dc_stream_state *stream = NULL; | |
420 | ||
421 | stream = link_enc_cfg_get_stream_using_link_enc(dc, eng_id); | |
422 | ||
423 | if (stream) | |
424 | link = stream->link; | |
425 | ||
426 | // dm_output_to_console("%s: No link using DIG(%d).\n", __func__, eng_id); | |
79ed7354 JK |
427 | return link; |
428 | } | |
429 | ||
430 | struct link_encoder *link_enc_cfg_get_link_enc_used_by_link( | |
6f941d4e | 431 | struct dc *dc, |
ede4f6da | 432 | const struct dc_link *link) |
79ed7354 JK |
433 | { |
434 | struct link_encoder *link_enc = NULL; | |
435 | struct display_endpoint_id ep_id; | |
79ed7354 JK |
436 | int i; |
437 | ||
438 | ep_id = (struct display_endpoint_id) { | |
439 | .link_id = link->link_id, | |
440 | .ep_type = link->ep_type}; | |
441 | ||
6f941d4e JK |
442 | for (i = 0; i < MAX_PIPES; i++) { |
443 | struct link_enc_assignment assignment = get_assignment(dc, i); | |
ec7077b5 | 444 | |
6f941d4e | 445 | if (assignment.valid == true && are_ep_ids_equal(&assignment.ep_id, &ep_id)) { |
940e084d | 446 | link_enc = link->dc->res_pool->link_encoders[assignment.eng_id - ENGINE_ID_DIGA]; |
6f941d4e JK |
447 | break; |
448 | } | |
79ed7354 JK |
449 | } |
450 | ||
ede4f6da JK |
451 | return link_enc; |
452 | } | |
453 | ||
6f941d4e | 454 | struct link_encoder *link_enc_cfg_get_next_avail_link_enc(struct dc *dc) |
ede4f6da JK |
455 | { |
456 | struct link_encoder *link_enc = NULL; | |
6f941d4e JK |
457 | enum engine_id encs_assigned[MAX_DIG_LINK_ENCODERS]; |
458 | int i; | |
459 | ||
460 | for (i = 0; i < MAX_DIG_LINK_ENCODERS; i++) | |
461 | encs_assigned[i] = ENGINE_ID_UNKNOWN; | |
ede4f6da | 462 | |
6f941d4e JK |
463 | /* Add assigned encoders to list. */ |
464 | for (i = 0; i < MAX_PIPES; i++) { | |
465 | struct link_enc_assignment assignment = get_assignment(dc, i); | |
466 | ||
467 | if (assignment.valid) | |
468 | encs_assigned[assignment.eng_id - ENGINE_ID_DIGA] = assignment.eng_id; | |
469 | } | |
470 | ||
471 | for (i = 0; i < dc->res_pool->res_cap->num_dig_link_enc; i++) { | |
472 | if (encs_assigned[i] == ENGINE_ID_UNKNOWN) { | |
473 | link_enc = dc->res_pool->link_encoders[i]; | |
474 | break; | |
475 | } | |
476 | } | |
79ed7354 JK |
477 | |
478 | return link_enc; | |
479 | } | |
940e084d JK |
480 | |
481 | struct link_encoder *link_enc_cfg_get_link_enc_used_by_stream( | |
6f941d4e | 482 | struct dc *dc, |
940e084d JK |
483 | const struct dc_stream_state *stream) |
484 | { | |
485 | struct link_encoder *link_enc; | |
486 | ||
6f941d4e | 487 | link_enc = link_enc_cfg_get_link_enc_used_by_link(dc, stream->link); |
940e084d JK |
488 | |
489 | return link_enc; | |
490 | } | |
ec7077b5 | 491 | |
6f941d4e JK |
492 | bool link_enc_cfg_is_link_enc_avail(struct dc *dc, enum engine_id eng_id) |
493 | { | |
494 | bool is_avail = true; | |
495 | int i; | |
496 | ||
497 | /* Add assigned encoders to list. */ | |
498 | for (i = 0; i < MAX_PIPES; i++) { | |
499 | struct link_enc_assignment assignment = get_assignment(dc, i); | |
500 | ||
501 | if (assignment.valid && assignment.eng_id == eng_id) { | |
502 | is_avail = false; | |
503 | break; | |
504 | } | |
505 | } | |
506 | ||
507 | return is_avail; | |
508 | } | |
509 | ||
ec7077b5 JK |
510 | bool link_enc_cfg_validate(struct dc *dc, struct dc_state *state) |
511 | { | |
512 | bool is_valid = false; | |
513 | bool valid_entries = true; | |
514 | bool valid_stream_ptrs = true; | |
515 | bool valid_uniqueness = true; | |
516 | bool valid_avail = true; | |
517 | bool valid_streams = true; | |
518 | int i, j; | |
519 | uint8_t valid_count = 0; | |
520 | uint8_t dig_stream_count = 0; | |
521 | int matching_stream_ptrs = 0; | |
522 | int eng_ids_per_ep_id[MAX_PIPES] = {0}; | |
797c598d | 523 | int valid_bitmap = 0; |
ec7077b5 JK |
524 | |
525 | /* (1) No. valid entries same as stream count. */ | |
526 | for (i = 0; i < MAX_PIPES; i++) { | |
6f941d4e | 527 | struct link_enc_assignment assignment = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
ec7077b5 JK |
528 | |
529 | if (assignment.valid) | |
530 | valid_count++; | |
531 | ||
532 | if (is_dig_link_enc_stream(state->streams[i])) | |
533 | dig_stream_count++; | |
534 | } | |
535 | if (valid_count != dig_stream_count) | |
536 | valid_entries = false; | |
537 | ||
538 | /* (2) Matching stream ptrs. */ | |
539 | for (i = 0; i < MAX_PIPES; i++) { | |
6f941d4e | 540 | struct link_enc_assignment assignment = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
ec7077b5 JK |
541 | |
542 | if (assignment.valid) { | |
543 | if (assignment.stream == state->streams[i]) | |
544 | matching_stream_ptrs++; | |
545 | else | |
546 | valid_stream_ptrs = false; | |
547 | } | |
548 | } | |
549 | ||
550 | /* (3) Each endpoint assigned unique encoder. */ | |
551 | for (i = 0; i < MAX_PIPES; i++) { | |
6f941d4e | 552 | struct link_enc_assignment assignment_i = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
ec7077b5 JK |
553 | |
554 | if (assignment_i.valid) { | |
555 | struct display_endpoint_id ep_id_i = assignment_i.ep_id; | |
556 | ||
557 | eng_ids_per_ep_id[i]++; | |
558 | for (j = 0; j < MAX_PIPES; j++) { | |
6f941d4e JK |
559 | struct link_enc_assignment assignment_j = |
560 | state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[j]; | |
ec7077b5 JK |
561 | |
562 | if (j == i) | |
563 | continue; | |
564 | ||
565 | if (assignment_j.valid) { | |
566 | struct display_endpoint_id ep_id_j = assignment_j.ep_id; | |
567 | ||
568 | if (are_ep_ids_equal(&ep_id_i, &ep_id_j) && | |
569 | assignment_i.eng_id != assignment_j.eng_id) { | |
570 | valid_uniqueness = false; | |
571 | eng_ids_per_ep_id[i]++; | |
572 | } | |
573 | } | |
574 | } | |
575 | } | |
576 | } | |
577 | ||
578 | /* (4) Assigned encoders not in available pool. */ | |
579 | for (i = 0; i < MAX_PIPES; i++) { | |
6f941d4e | 580 | struct link_enc_assignment assignment = state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i]; |
ec7077b5 JK |
581 | |
582 | if (assignment.valid) { | |
583 | for (j = 0; j < dc->res_pool->res_cap->num_dig_link_enc; j++) { | |
6f941d4e | 584 | if (state->res_ctx.link_enc_cfg_ctx.link_enc_avail[j] == assignment.eng_id) { |
ec7077b5 JK |
585 | valid_avail = false; |
586 | break; | |
587 | } | |
588 | } | |
589 | } | |
590 | } | |
591 | ||
592 | /* (5) All streams have valid link encoders. */ | |
593 | for (i = 0; i < state->stream_count; i++) { | |
594 | struct dc_stream_state *stream = state->streams[i]; | |
595 | ||
596 | if (is_dig_link_enc_stream(stream) && stream->link_enc == NULL) { | |
597 | valid_streams = false; | |
598 | break; | |
599 | } | |
600 | } | |
601 | ||
602 | is_valid = valid_entries && valid_stream_ptrs && valid_uniqueness && valid_avail && valid_streams; | |
603 | ASSERT(is_valid); | |
604 | ||
797c598d JK |
605 | if (is_valid == false) { |
606 | valid_bitmap = | |
607 | (valid_entries & 0x1) | | |
608 | ((valid_stream_ptrs & 0x1) << 1) | | |
609 | ((valid_uniqueness & 0x1) << 2) | | |
610 | ((valid_avail & 0x1) << 3) | | |
611 | ((valid_streams & 0x1) << 4); | |
612 | dm_error("Invalid link encoder assignments: 0x%x\n", valid_bitmap); | |
613 | } | |
614 | ||
ec7077b5 JK |
615 | return is_valid; |
616 | } |