2 * Copyright 2012-15 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <linux/slab.h>
28 #include "dm_services.h"
31 #include "include/irq_service_interface.h"
32 #include "link_encoder.h"
33 #include "stream_encoder.h"
35 #include "timing_generator.h"
36 #include "transform.h"
40 #include "core_types.h"
41 #include "set_mode_types.h"
42 #include "virtual/virtual_stream_encoder.h"
43 #include "dpcd_defs.h"
44 #include "link_enc_cfg.h"
45 #include "dc_link_dp.h"
46 #include "virtual/virtual_link_hwss.h"
47 #include "link/link_hwss_dio.h"
48 #include "link/link_hwss_dpia.h"
49 #include "link/link_hwss_hpo_dp.h"
51 #if defined(CONFIG_DRM_AMD_DC_SI)
52 #include "dce60/dce60_resource.h"
54 #include "dce80/dce80_resource.h"
55 #include "dce100/dce100_resource.h"
56 #include "dce110/dce110_resource.h"
57 #include "dce112/dce112_resource.h"
58 #include "dce120/dce120_resource.h"
59 #if defined(CONFIG_DRM_AMD_DC_DCN)
60 #include "dcn10/dcn10_resource.h"
61 #include "dcn20/dcn20_resource.h"
62 #include "dcn21/dcn21_resource.h"
63 #include "dcn201/dcn201_resource.h"
64 #include "dcn30/dcn30_resource.h"
65 #include "dcn301/dcn301_resource.h"
66 #include "dcn302/dcn302_resource.h"
67 #include "dcn303/dcn303_resource.h"
68 #include "dcn31/dcn31_resource.h"
69 #include "dcn315/dcn315_resource.h"
70 #include "dcn316/dcn316_resource.h"
73 #define DC_LOGGER_INIT(logger)
75 enum dce_version resource_parse_asic_id(struct hw_asic_id asic_id)
77 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
78 switch (asic_id.chip_family) {
80 #if defined(CONFIG_DRM_AMD_DC_SI)
82 if (ASIC_REV_IS_TAHITI_P(asic_id.hw_internal_rev) ||
83 ASIC_REV_IS_PITCAIRN_PM(asic_id.hw_internal_rev) ||
84 ASIC_REV_IS_CAPEVERDE_M(asic_id.hw_internal_rev))
85 dc_version = DCE_VERSION_6_0;
86 else if (ASIC_REV_IS_OLAND_M(asic_id.hw_internal_rev))
87 dc_version = DCE_VERSION_6_4;
89 dc_version = DCE_VERSION_6_1;
93 dc_version = DCE_VERSION_8_0;
96 if (ASIC_REV_IS_KALINDI(asic_id.hw_internal_rev) ||
97 ASIC_REV_IS_BHAVANI(asic_id.hw_internal_rev) ||
98 ASIC_REV_IS_GODAVARI(asic_id.hw_internal_rev))
99 dc_version = DCE_VERSION_8_3;
101 dc_version = DCE_VERSION_8_1;
104 dc_version = DCE_VERSION_11_0;
108 if (ASIC_REV_IS_TONGA_P(asic_id.hw_internal_rev) ||
109 ASIC_REV_IS_FIJI_P(asic_id.hw_internal_rev)) {
110 dc_version = DCE_VERSION_10_0;
113 if (ASIC_REV_IS_POLARIS10_P(asic_id.hw_internal_rev) ||
114 ASIC_REV_IS_POLARIS11_M(asic_id.hw_internal_rev) ||
115 ASIC_REV_IS_POLARIS12_V(asic_id.hw_internal_rev)) {
116 dc_version = DCE_VERSION_11_2;
118 if (ASIC_REV_IS_VEGAM(asic_id.hw_internal_rev))
119 dc_version = DCE_VERSION_11_22;
122 if (ASICREV_IS_VEGA20_P(asic_id.hw_internal_rev))
123 dc_version = DCE_VERSION_12_1;
125 dc_version = DCE_VERSION_12_0;
127 #if defined(CONFIG_DRM_AMD_DC_DCN)
129 dc_version = DCN_VERSION_1_0;
130 if (ASICREV_IS_RAVEN2(asic_id.hw_internal_rev))
131 dc_version = DCN_VERSION_1_01;
132 if (ASICREV_IS_RENOIR(asic_id.hw_internal_rev))
133 dc_version = DCN_VERSION_2_1;
134 if (ASICREV_IS_GREEN_SARDINE(asic_id.hw_internal_rev))
135 dc_version = DCN_VERSION_2_1;
139 dc_version = DCN_VERSION_2_0;
140 if (asic_id.chip_id == DEVICE_ID_NV_13FE || asic_id.chip_id == DEVICE_ID_NV_143F) {
141 dc_version = DCN_VERSION_2_01;
144 if (ASICREV_IS_SIENNA_CICHLID_P(asic_id.hw_internal_rev))
145 dc_version = DCN_VERSION_3_0;
146 if (ASICREV_IS_DIMGREY_CAVEFISH_P(asic_id.hw_internal_rev))
147 dc_version = DCN_VERSION_3_02;
148 if (ASICREV_IS_BEIGE_GOBY_P(asic_id.hw_internal_rev))
149 dc_version = DCN_VERSION_3_03;
153 dc_version = DCN_VERSION_3_01;
156 case FAMILY_YELLOW_CARP:
157 if (ASICREV_IS_YELLOW_CARP(asic_id.hw_internal_rev))
158 dc_version = DCN_VERSION_3_1;
160 case AMDGPU_FAMILY_GC_10_3_6:
161 if (ASICREV_IS_GC_10_3_6(asic_id.hw_internal_rev))
162 dc_version = DCN_VERSION_3_15;
164 case AMDGPU_FAMILY_GC_10_3_7:
165 if (ASICREV_IS_GC_10_3_7(asic_id.hw_internal_rev))
166 dc_version = DCN_VERSION_3_16;
171 dc_version = DCE_VERSION_UNKNOWN;
177 struct resource_pool *dc_create_resource_pool(struct dc *dc,
178 const struct dc_init_data *init_data,
179 enum dce_version dc_version)
181 struct resource_pool *res_pool = NULL;
183 switch (dc_version) {
184 #if defined(CONFIG_DRM_AMD_DC_SI)
185 case DCE_VERSION_6_0:
186 res_pool = dce60_create_resource_pool(
187 init_data->num_virtual_links, dc);
189 case DCE_VERSION_6_1:
190 res_pool = dce61_create_resource_pool(
191 init_data->num_virtual_links, dc);
193 case DCE_VERSION_6_4:
194 res_pool = dce64_create_resource_pool(
195 init_data->num_virtual_links, dc);
198 case DCE_VERSION_8_0:
199 res_pool = dce80_create_resource_pool(
200 init_data->num_virtual_links, dc);
202 case DCE_VERSION_8_1:
203 res_pool = dce81_create_resource_pool(
204 init_data->num_virtual_links, dc);
206 case DCE_VERSION_8_3:
207 res_pool = dce83_create_resource_pool(
208 init_data->num_virtual_links, dc);
210 case DCE_VERSION_10_0:
211 res_pool = dce100_create_resource_pool(
212 init_data->num_virtual_links, dc);
214 case DCE_VERSION_11_0:
215 res_pool = dce110_create_resource_pool(
216 init_data->num_virtual_links, dc,
219 case DCE_VERSION_11_2:
220 case DCE_VERSION_11_22:
221 res_pool = dce112_create_resource_pool(
222 init_data->num_virtual_links, dc);
224 case DCE_VERSION_12_0:
225 case DCE_VERSION_12_1:
226 res_pool = dce120_create_resource_pool(
227 init_data->num_virtual_links, dc);
230 #if defined(CONFIG_DRM_AMD_DC_DCN)
231 case DCN_VERSION_1_0:
232 case DCN_VERSION_1_01:
233 res_pool = dcn10_create_resource_pool(init_data, dc);
235 case DCN_VERSION_2_0:
236 res_pool = dcn20_create_resource_pool(init_data, dc);
238 case DCN_VERSION_2_1:
239 res_pool = dcn21_create_resource_pool(init_data, dc);
241 case DCN_VERSION_2_01:
242 res_pool = dcn201_create_resource_pool(init_data, dc);
244 case DCN_VERSION_3_0:
245 res_pool = dcn30_create_resource_pool(init_data, dc);
247 case DCN_VERSION_3_01:
248 res_pool = dcn301_create_resource_pool(init_data, dc);
250 case DCN_VERSION_3_02:
251 res_pool = dcn302_create_resource_pool(init_data, dc);
253 case DCN_VERSION_3_03:
254 res_pool = dcn303_create_resource_pool(init_data, dc);
256 case DCN_VERSION_3_1:
257 res_pool = dcn31_create_resource_pool(init_data, dc);
259 case DCN_VERSION_3_15:
260 res_pool = dcn315_create_resource_pool(init_data, dc);
262 case DCN_VERSION_3_16:
263 res_pool = dcn316_create_resource_pool(init_data, dc);
270 if (res_pool != NULL) {
271 if (dc->ctx->dc_bios->fw_info_valid) {
272 res_pool->ref_clocks.xtalin_clock_inKhz =
273 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency;
274 /* initialize with firmware data first, no all
275 * ASIC have DCCG SW component. FPGA or
276 * simulation need initialization of
277 * dccg_ref_clock_inKhz, dchub_ref_clock_inKhz
278 * with xtalin_clock_inKhz
280 res_pool->ref_clocks.dccg_ref_clock_inKhz =
281 res_pool->ref_clocks.xtalin_clock_inKhz;
282 res_pool->ref_clocks.dchub_ref_clock_inKhz =
283 res_pool->ref_clocks.xtalin_clock_inKhz;
285 ASSERT_CRITICAL(false);
291 void dc_destroy_resource_pool(struct dc *dc)
295 dc->res_pool->funcs->destroy(&dc->res_pool);
301 static void update_num_audio(
302 const struct resource_straps *straps,
303 unsigned int *num_audio,
304 struct audio_support *aud_support)
306 aud_support->dp_audio = true;
307 aud_support->hdmi_audio_native = false;
308 aud_support->hdmi_audio_on_dongle = false;
310 if (straps->hdmi_disable == 0) {
311 if (straps->dc_pinstraps_audio & 0x2) {
312 aud_support->hdmi_audio_on_dongle = true;
313 aud_support->hdmi_audio_native = true;
317 switch (straps->audio_stream_number) {
318 case 0: /* multi streams supported */
320 case 1: /* multi streams not supported */
324 DC_ERR("DC: unexpected audio fuse!\n");
328 bool resource_construct(
329 unsigned int num_virtual_links,
331 struct resource_pool *pool,
332 const struct resource_create_funcs *create_funcs)
334 struct dc_context *ctx = dc->ctx;
335 const struct resource_caps *caps = pool->res_cap;
337 unsigned int num_audio = caps->num_audio;
338 struct resource_straps straps = {0};
340 if (create_funcs->read_dce_straps)
341 create_funcs->read_dce_straps(dc->ctx, &straps);
343 pool->audio_count = 0;
344 if (create_funcs->create_audio) {
345 /* find the total number of streams available via the
346 * AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT
347 * registers (one for each pin) starting from pin 1
348 * up to the max number of audio pins.
349 * We stop on the first pin where
350 * PORT_CONNECTIVITY == 1 (as instructed by HW team).
352 update_num_audio(&straps, &num_audio, &pool->audio_support);
353 for (i = 0; i < caps->num_audio; i++) {
354 struct audio *aud = create_funcs->create_audio(ctx, i);
357 DC_ERR("DC: failed to create audio!\n");
360 if (!aud->funcs->endpoint_valid(aud)) {
361 aud->funcs->destroy(&aud);
364 pool->audios[i] = aud;
369 pool->stream_enc_count = 0;
370 if (create_funcs->create_stream_encoder) {
371 for (i = 0; i < caps->num_stream_encoder; i++) {
372 pool->stream_enc[i] = create_funcs->create_stream_encoder(i, ctx);
373 if (pool->stream_enc[i] == NULL)
374 DC_ERR("DC: failed to create stream_encoder!\n");
375 pool->stream_enc_count++;
379 pool->hpo_dp_stream_enc_count = 0;
380 if (create_funcs->create_hpo_dp_stream_encoder) {
381 for (i = 0; i < caps->num_hpo_dp_stream_encoder; i++) {
382 pool->hpo_dp_stream_enc[i] = create_funcs->create_hpo_dp_stream_encoder(i+ENGINE_ID_HPO_DP_0, ctx);
383 if (pool->hpo_dp_stream_enc[i] == NULL)
384 DC_ERR("DC: failed to create HPO DP stream encoder!\n");
385 pool->hpo_dp_stream_enc_count++;
390 pool->hpo_dp_link_enc_count = 0;
391 if (create_funcs->create_hpo_dp_link_encoder) {
392 for (i = 0; i < caps->num_hpo_dp_link_encoder; i++) {
393 pool->hpo_dp_link_enc[i] = create_funcs->create_hpo_dp_link_encoder(i, ctx);
394 if (pool->hpo_dp_link_enc[i] == NULL)
395 DC_ERR("DC: failed to create HPO DP link encoder!\n");
396 pool->hpo_dp_link_enc_count++;
400 #if defined(CONFIG_DRM_AMD_DC_DCN)
401 for (i = 0; i < caps->num_mpc_3dlut; i++) {
402 pool->mpc_lut[i] = dc_create_3dlut_func();
403 if (pool->mpc_lut[i] == NULL)
404 DC_ERR("DC: failed to create MPC 3dlut!\n");
405 pool->mpc_shaper[i] = dc_create_transfer_func();
406 if (pool->mpc_shaper[i] == NULL)
407 DC_ERR("DC: failed to create MPC shaper!\n");
410 dc->caps.dynamic_audio = false;
411 if (pool->audio_count < pool->stream_enc_count) {
412 dc->caps.dynamic_audio = true;
414 for (i = 0; i < num_virtual_links; i++) {
415 pool->stream_enc[pool->stream_enc_count] =
416 virtual_stream_encoder_create(
418 if (pool->stream_enc[pool->stream_enc_count] == NULL) {
419 DC_ERR("DC: failed to create stream_encoder!\n");
422 pool->stream_enc_count++;
425 dc->hwseq = create_funcs->create_hwseq(ctx);
429 static int find_matching_clock_source(
430 const struct resource_pool *pool,
431 struct clock_source *clock_source)
436 for (i = 0; i < pool->clk_src_count; i++) {
437 if (pool->clock_sources[i] == clock_source)
443 void resource_unreference_clock_source(
444 struct resource_context *res_ctx,
445 const struct resource_pool *pool,
446 struct clock_source *clock_source)
448 int i = find_matching_clock_source(pool, clock_source);
451 res_ctx->clock_source_ref_count[i]--;
453 if (pool->dp_clock_source == clock_source)
454 res_ctx->dp_clock_source_ref_count--;
457 void resource_reference_clock_source(
458 struct resource_context *res_ctx,
459 const struct resource_pool *pool,
460 struct clock_source *clock_source)
462 int i = find_matching_clock_source(pool, clock_source);
465 res_ctx->clock_source_ref_count[i]++;
467 if (pool->dp_clock_source == clock_source)
468 res_ctx->dp_clock_source_ref_count++;
471 int resource_get_clock_source_reference(
472 struct resource_context *res_ctx,
473 const struct resource_pool *pool,
474 struct clock_source *clock_source)
476 int i = find_matching_clock_source(pool, clock_source);
479 return res_ctx->clock_source_ref_count[i];
481 if (pool->dp_clock_source == clock_source)
482 return res_ctx->dp_clock_source_ref_count;
487 bool resource_are_vblanks_synchronizable(
488 struct dc_stream_state *stream1,
489 struct dc_stream_state *stream2)
491 uint32_t base60_refresh_rates[] = {10, 20, 5};
493 uint8_t rr_count = ARRAY_SIZE(base60_refresh_rates);
494 uint64_t frame_time_diff;
496 if (stream1->ctx->dc->config.vblank_alignment_dto_params &&
497 stream1->ctx->dc->config.vblank_alignment_max_frame_time_diff > 0 &&
498 dc_is_dp_signal(stream1->signal) &&
499 dc_is_dp_signal(stream2->signal) &&
500 false == stream1->has_non_synchronizable_pclk &&
501 false == stream2->has_non_synchronizable_pclk &&
502 stream1->timing.flags.VBLANK_SYNCHRONIZABLE &&
503 stream2->timing.flags.VBLANK_SYNCHRONIZABLE) {
504 /* disable refresh rates higher than 60Hz for now */
505 if (stream1->timing.pix_clk_100hz*100/stream1->timing.h_total/
506 stream1->timing.v_total > 60)
508 if (stream2->timing.pix_clk_100hz*100/stream2->timing.h_total/
509 stream2->timing.v_total > 60)
511 frame_time_diff = (uint64_t)10000 *
512 stream1->timing.h_total *
513 stream1->timing.v_total *
514 stream2->timing.pix_clk_100hz;
515 frame_time_diff = div_u64(frame_time_diff, stream1->timing.pix_clk_100hz);
516 frame_time_diff = div_u64(frame_time_diff, stream2->timing.h_total);
517 frame_time_diff = div_u64(frame_time_diff, stream2->timing.v_total);
518 for (i = 0; i < rr_count; i++) {
519 int64_t diff = (int64_t)div_u64(frame_time_diff * base60_refresh_rates[i], 10) - 10000;
523 if (diff < stream1->ctx->dc->config.vblank_alignment_max_frame_time_diff)
530 bool resource_are_streams_timing_synchronizable(
531 struct dc_stream_state *stream1,
532 struct dc_stream_state *stream2)
534 if (stream1->timing.h_total != stream2->timing.h_total)
537 if (stream1->timing.v_total != stream2->timing.v_total)
540 if (stream1->timing.h_addressable
541 != stream2->timing.h_addressable)
544 if (stream1->timing.v_addressable
545 != stream2->timing.v_addressable)
548 if (stream1->timing.v_front_porch
549 != stream2->timing.v_front_porch)
552 if (stream1->timing.pix_clk_100hz
553 != stream2->timing.pix_clk_100hz)
556 if (stream1->clamping.c_depth != stream2->clamping.c_depth)
559 if (stream1->phy_pix_clk != stream2->phy_pix_clk
560 && (!dc_is_dp_signal(stream1->signal)
561 || !dc_is_dp_signal(stream2->signal)))
564 if (stream1->view_format != stream2->view_format)
567 if (stream1->ignore_msa_timing_param || stream2->ignore_msa_timing_param)
572 static bool is_dp_and_hdmi_sharable(
573 struct dc_stream_state *stream1,
574 struct dc_stream_state *stream2)
576 if (stream1->ctx->dc->caps.disable_dp_clk_share)
579 if (stream1->clamping.c_depth != COLOR_DEPTH_888 ||
580 stream2->clamping.c_depth != COLOR_DEPTH_888)
587 static bool is_sharable_clk_src(
588 const struct pipe_ctx *pipe_with_clk_src,
589 const struct pipe_ctx *pipe)
591 if (pipe_with_clk_src->clock_source == NULL)
594 if (pipe_with_clk_src->stream->signal == SIGNAL_TYPE_VIRTUAL)
597 if (dc_is_dp_signal(pipe_with_clk_src->stream->signal) ||
598 (dc_is_dp_signal(pipe->stream->signal) &&
599 !is_dp_and_hdmi_sharable(pipe_with_clk_src->stream,
603 if (dc_is_hdmi_signal(pipe_with_clk_src->stream->signal)
604 && dc_is_dual_link_signal(pipe->stream->signal))
607 if (dc_is_hdmi_signal(pipe->stream->signal)
608 && dc_is_dual_link_signal(pipe_with_clk_src->stream->signal))
611 if (!resource_are_streams_timing_synchronizable(
612 pipe_with_clk_src->stream, pipe->stream))
618 struct clock_source *resource_find_used_clk_src_for_sharing(
619 struct resource_context *res_ctx,
620 struct pipe_ctx *pipe_ctx)
624 for (i = 0; i < MAX_PIPES; i++) {
625 if (is_sharable_clk_src(&res_ctx->pipe_ctx[i], pipe_ctx))
626 return res_ctx->pipe_ctx[i].clock_source;
632 static enum pixel_format convert_pixel_format_to_dalsurface(
633 enum surface_pixel_format surface_pixel_format)
635 enum pixel_format dal_pixel_format = PIXEL_FORMAT_UNKNOWN;
637 switch (surface_pixel_format) {
638 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
639 dal_pixel_format = PIXEL_FORMAT_INDEX8;
641 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
642 dal_pixel_format = PIXEL_FORMAT_RGB565;
644 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
645 dal_pixel_format = PIXEL_FORMAT_RGB565;
647 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
648 dal_pixel_format = PIXEL_FORMAT_ARGB8888;
650 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
651 dal_pixel_format = PIXEL_FORMAT_ARGB8888;
653 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
654 dal_pixel_format = PIXEL_FORMAT_ARGB2101010;
656 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
657 dal_pixel_format = PIXEL_FORMAT_ARGB2101010;
659 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
660 dal_pixel_format = PIXEL_FORMAT_ARGB2101010_XRBIAS;
662 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
663 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
664 dal_pixel_format = PIXEL_FORMAT_FP16;
666 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
667 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
668 dal_pixel_format = PIXEL_FORMAT_420BPP8;
670 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
671 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
672 dal_pixel_format = PIXEL_FORMAT_420BPP10;
674 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
675 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
677 dal_pixel_format = PIXEL_FORMAT_UNKNOWN;
680 return dal_pixel_format;
683 static inline void get_vp_scan_direction(
684 enum dc_rotation_angle rotation,
685 bool horizontal_mirror,
686 bool *orthogonal_rotation,
687 bool *flip_vert_scan_dir,
688 bool *flip_horz_scan_dir)
690 *orthogonal_rotation = false;
691 *flip_vert_scan_dir = false;
692 *flip_horz_scan_dir = false;
693 if (rotation == ROTATION_ANGLE_180) {
694 *flip_vert_scan_dir = true;
695 *flip_horz_scan_dir = true;
696 } else if (rotation == ROTATION_ANGLE_90) {
697 *orthogonal_rotation = true;
698 *flip_horz_scan_dir = true;
699 } else if (rotation == ROTATION_ANGLE_270) {
700 *orthogonal_rotation = true;
701 *flip_vert_scan_dir = true;
704 if (horizontal_mirror)
705 *flip_horz_scan_dir = !*flip_horz_scan_dir;
708 int get_num_mpc_splits(struct pipe_ctx *pipe)
710 int mpc_split_count = 0;
711 struct pipe_ctx *other_pipe = pipe->bottom_pipe;
713 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
715 other_pipe = other_pipe->bottom_pipe;
717 other_pipe = pipe->top_pipe;
718 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
720 other_pipe = other_pipe->top_pipe;
723 return mpc_split_count;
726 int get_num_odm_splits(struct pipe_ctx *pipe)
728 int odm_split_count = 0;
729 struct pipe_ctx *next_pipe = pipe->next_odm_pipe;
732 next_pipe = next_pipe->next_odm_pipe;
734 pipe = pipe->prev_odm_pipe;
737 pipe = pipe->prev_odm_pipe;
739 return odm_split_count;
742 static void calculate_split_count_and_index(struct pipe_ctx *pipe_ctx, int *split_count, int *split_idx)
744 *split_count = get_num_odm_splits(pipe_ctx);
746 if (*split_count == 0) {
747 /*Check for mpc split*/
748 struct pipe_ctx *split_pipe = pipe_ctx->top_pipe;
750 *split_count = get_num_mpc_splits(pipe_ctx);
751 while (split_pipe && split_pipe->plane_state == pipe_ctx->plane_state) {
753 split_pipe = split_pipe->top_pipe;
756 /*Get odm split index*/
757 struct pipe_ctx *split_pipe = pipe_ctx->prev_odm_pipe;
761 split_pipe = split_pipe->prev_odm_pipe;
767 * This is a preliminary vp size calculation to allow us to check taps support.
768 * The result is completely overridden afterwards.
770 static void calculate_viewport_size(struct pipe_ctx *pipe_ctx)
772 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
774 data->viewport.width = dc_fixpt_ceil(dc_fixpt_mul_int(data->ratios.horz, data->recout.width));
775 data->viewport.height = dc_fixpt_ceil(dc_fixpt_mul_int(data->ratios.vert, data->recout.height));
776 data->viewport_c.width = dc_fixpt_ceil(dc_fixpt_mul_int(data->ratios.horz_c, data->recout.width));
777 data->viewport_c.height = dc_fixpt_ceil(dc_fixpt_mul_int(data->ratios.vert_c, data->recout.height));
778 if (pipe_ctx->plane_state->rotation == ROTATION_ANGLE_90 ||
779 pipe_ctx->plane_state->rotation == ROTATION_ANGLE_270) {
780 swap(data->viewport.width, data->viewport.height);
781 swap(data->viewport_c.width, data->viewport_c.height);
785 static void calculate_recout(struct pipe_ctx *pipe_ctx)
787 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
788 const struct dc_stream_state *stream = pipe_ctx->stream;
789 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
790 struct rect surf_clip = plane_state->clip_rect;
791 bool split_tb = stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM;
792 int split_count, split_idx;
794 calculate_split_count_and_index(pipe_ctx, &split_count, &split_idx);
795 if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE)
799 * Only the leftmost ODM pipe should be offset by a nonzero distance
801 if (!pipe_ctx->prev_odm_pipe || split_idx == split_count) {
802 data->recout.x = stream->dst.x;
803 if (stream->src.x < surf_clip.x)
804 data->recout.x += (surf_clip.x - stream->src.x) * stream->dst.width
809 if (stream->src.x > surf_clip.x)
810 surf_clip.width -= stream->src.x - surf_clip.x;
811 data->recout.width = surf_clip.width * stream->dst.width / stream->src.width;
812 if (data->recout.width + data->recout.x > stream->dst.x + stream->dst.width)
813 data->recout.width = stream->dst.x + stream->dst.width - data->recout.x;
815 data->recout.y = stream->dst.y;
816 if (stream->src.y < surf_clip.y)
817 data->recout.y += (surf_clip.y - stream->src.y) * stream->dst.height
818 / stream->src.height;
819 else if (stream->src.y > surf_clip.y)
820 surf_clip.height -= stream->src.y - surf_clip.y;
822 data->recout.height = surf_clip.height * stream->dst.height / stream->src.height;
823 if (data->recout.height + data->recout.y > stream->dst.y + stream->dst.height)
824 data->recout.height = stream->dst.y + stream->dst.height - data->recout.y;
826 /* Handle h & v split */
828 ASSERT(data->recout.height % 2 == 0);
829 data->recout.height /= 2;
830 } else if (split_count) {
831 if (!pipe_ctx->next_odm_pipe && !pipe_ctx->prev_odm_pipe) {
832 /* extra pixels in the division remainder need to go to pipes after
833 * the extra pixel index minus one(epimo) defined here as:
835 int epimo = split_count - data->recout.width % (split_count + 1);
837 data->recout.x += (data->recout.width / (split_count + 1)) * split_idx;
838 if (split_idx > epimo)
839 data->recout.x += split_idx - epimo - 1;
840 ASSERT(stream->view_format != VIEW_3D_FORMAT_SIDE_BY_SIDE || data->recout.width % 2 == 0);
841 data->recout.width = data->recout.width / (split_count + 1) + (split_idx > epimo ? 1 : 0);
844 if (split_idx == split_count) {
845 /* rightmost pipe is the remainder recout */
846 data->recout.width -= data->h_active * split_count - data->recout.x;
848 /* ODM combine cases with MPO we can get negative widths */
849 if (data->recout.width < 0)
850 data->recout.width = 0;
854 data->recout.width = data->h_active - data->recout.x;
859 static void calculate_scaling_ratios(struct pipe_ctx *pipe_ctx)
861 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
862 const struct dc_stream_state *stream = pipe_ctx->stream;
863 struct rect surf_src = plane_state->src_rect;
864 const int in_w = stream->src.width;
865 const int in_h = stream->src.height;
866 const int out_w = stream->dst.width;
867 const int out_h = stream->dst.height;
869 /*Swap surf_src height and width since scaling ratios are in recout rotation*/
870 if (pipe_ctx->plane_state->rotation == ROTATION_ANGLE_90 ||
871 pipe_ctx->plane_state->rotation == ROTATION_ANGLE_270)
872 swap(surf_src.height, surf_src.width);
874 pipe_ctx->plane_res.scl_data.ratios.horz = dc_fixpt_from_fraction(
876 plane_state->dst_rect.width);
877 pipe_ctx->plane_res.scl_data.ratios.vert = dc_fixpt_from_fraction(
879 plane_state->dst_rect.height);
881 if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE)
882 pipe_ctx->plane_res.scl_data.ratios.horz.value *= 2;
883 else if (stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM)
884 pipe_ctx->plane_res.scl_data.ratios.vert.value *= 2;
886 pipe_ctx->plane_res.scl_data.ratios.vert.value = div64_s64(
887 pipe_ctx->plane_res.scl_data.ratios.vert.value * in_h, out_h);
888 pipe_ctx->plane_res.scl_data.ratios.horz.value = div64_s64(
889 pipe_ctx->plane_res.scl_data.ratios.horz.value * in_w, out_w);
891 pipe_ctx->plane_res.scl_data.ratios.horz_c = pipe_ctx->plane_res.scl_data.ratios.horz;
892 pipe_ctx->plane_res.scl_data.ratios.vert_c = pipe_ctx->plane_res.scl_data.ratios.vert;
894 if (pipe_ctx->plane_res.scl_data.format == PIXEL_FORMAT_420BPP8
895 || pipe_ctx->plane_res.scl_data.format == PIXEL_FORMAT_420BPP10) {
896 pipe_ctx->plane_res.scl_data.ratios.horz_c.value /= 2;
897 pipe_ctx->plane_res.scl_data.ratios.vert_c.value /= 2;
899 pipe_ctx->plane_res.scl_data.ratios.horz = dc_fixpt_truncate(
900 pipe_ctx->plane_res.scl_data.ratios.horz, 19);
901 pipe_ctx->plane_res.scl_data.ratios.vert = dc_fixpt_truncate(
902 pipe_ctx->plane_res.scl_data.ratios.vert, 19);
903 pipe_ctx->plane_res.scl_data.ratios.horz_c = dc_fixpt_truncate(
904 pipe_ctx->plane_res.scl_data.ratios.horz_c, 19);
905 pipe_ctx->plane_res.scl_data.ratios.vert_c = dc_fixpt_truncate(
906 pipe_ctx->plane_res.scl_data.ratios.vert_c, 19);
911 * We completely calculate vp offset, size and inits here based entirely on scaling
912 * ratios and recout for pixel perfect pipe combine.
914 static void calculate_init_and_vp(
916 int recout_offset_within_recout_full,
920 struct fixed31_32 ratio,
921 struct fixed31_32 *init,
925 struct fixed31_32 temp;
929 * First of the taps starts sampling pixel number <init_int_part> corresponding to recout
930 * pixel 1. Next recout pixel samples int part of <init + scaling ratio> and so on.
931 * All following calculations are based on this logic.
933 * Init calculated according to formula:
934 * init = (scaling_ratio + number_of_taps + 1) / 2
935 * init_bot = init + scaling_ratio
936 * to get pixel perfect combine add the fraction from calculating vp offset
938 temp = dc_fixpt_mul_int(ratio, recout_offset_within_recout_full);
939 *vp_offset = dc_fixpt_floor(temp);
940 temp.value &= 0xffffffff;
941 *init = dc_fixpt_truncate(dc_fixpt_add(dc_fixpt_div_int(
942 dc_fixpt_add_int(ratio, taps + 1), 2), temp), 19);
944 * If viewport has non 0 offset and there are more taps than covered by init then
945 * we should decrease the offset and increase init so we are never sampling
946 * outside of viewport.
948 int_part = dc_fixpt_floor(*init);
949 if (int_part < taps) {
950 int_part = taps - int_part;
951 if (int_part > *vp_offset)
952 int_part = *vp_offset;
953 *vp_offset -= int_part;
954 *init = dc_fixpt_add_int(*init, int_part);
957 * If taps are sampling outside of viewport at end of recout and there are more pixels
958 * available in the surface we should increase the viewport size, regardless set vp to
961 temp = dc_fixpt_add(*init, dc_fixpt_mul_int(ratio, recout_size - 1));
962 *vp_size = dc_fixpt_floor(temp);
963 if (*vp_size + *vp_offset > src_size)
964 *vp_size = src_size - *vp_offset;
966 /* We did all the math assuming we are scanning same direction as display does,
967 * however mirror/rotation changes how vp scans vs how it is offset. If scan direction
968 * is flipped we simply need to calculate offset from the other side of plane.
969 * Note that outside of viewport all scaling hardware works in recout space.
972 *vp_offset = src_size - *vp_offset - *vp_size;
975 static void calculate_inits_and_viewports(struct pipe_ctx *pipe_ctx)
977 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
978 const struct dc_stream_state *stream = pipe_ctx->stream;
979 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
980 struct rect src = plane_state->src_rect;
981 int vpc_div = (data->format == PIXEL_FORMAT_420BPP8
982 || data->format == PIXEL_FORMAT_420BPP10) ? 2 : 1;
983 int split_count, split_idx, ro_lb, ro_tb, recout_full_x, recout_full_y;
984 bool orthogonal_rotation, flip_vert_scan_dir, flip_horz_scan_dir;
986 calculate_split_count_and_index(pipe_ctx, &split_count, &split_idx);
988 * recout full is what the recout would have been if we didnt clip
989 * the source plane at all. We only care about left(ro_lb) and top(ro_tb)
990 * offsets of recout within recout full because those are the directions
991 * we scan from and therefore the only ones that affect inits.
993 recout_full_x = stream->dst.x + (plane_state->dst_rect.x - stream->src.x)
994 * stream->dst.width / stream->src.width;
995 recout_full_y = stream->dst.y + (plane_state->dst_rect.y - stream->src.y)
996 * stream->dst.height / stream->src.height;
997 if (pipe_ctx->prev_odm_pipe && split_idx)
998 ro_lb = data->h_active * split_idx - recout_full_x;
1000 ro_lb = data->recout.x - recout_full_x;
1001 ro_tb = data->recout.y - recout_full_y;
1002 ASSERT(ro_lb >= 0 && ro_tb >= 0);
1005 * Work in recout rotation since that requires less transformations
1007 get_vp_scan_direction(
1008 plane_state->rotation,
1009 plane_state->horizontal_mirror,
1010 &orthogonal_rotation,
1011 &flip_vert_scan_dir,
1012 &flip_horz_scan_dir);
1014 if (orthogonal_rotation) {
1015 swap(src.width, src.height);
1016 swap(flip_vert_scan_dir, flip_horz_scan_dir);
1019 calculate_init_and_vp(
1028 &data->viewport.width);
1029 calculate_init_and_vp(
1033 src.width / vpc_div,
1034 data->taps.h_taps_c,
1035 data->ratios.horz_c,
1037 &data->viewport_c.x,
1038 &data->viewport_c.width);
1039 calculate_init_and_vp(
1042 data->recout.height,
1048 &data->viewport.height);
1049 calculate_init_and_vp(
1052 data->recout.height,
1053 src.height / vpc_div,
1054 data->taps.v_taps_c,
1055 data->ratios.vert_c,
1057 &data->viewport_c.y,
1058 &data->viewport_c.height);
1059 if (orthogonal_rotation) {
1060 swap(data->viewport.x, data->viewport.y);
1061 swap(data->viewport.width, data->viewport.height);
1062 swap(data->viewport_c.x, data->viewport_c.y);
1063 swap(data->viewport_c.width, data->viewport_c.height);
1065 data->viewport.x += src.x;
1066 data->viewport.y += src.y;
1067 ASSERT(src.x % vpc_div == 0 && src.y % vpc_div == 0);
1068 data->viewport_c.x += src.x / vpc_div;
1069 data->viewport_c.y += src.y / vpc_div;
1072 bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx)
1074 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1075 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
1077 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1079 pipe_ctx->plane_res.scl_data.format = convert_pixel_format_to_dalsurface(
1080 pipe_ctx->plane_state->format);
1082 /* Timing borders are part of vactive that we are also supposed to skip in addition
1083 * to any stream dst offset. Since dm logic assumes dst is in addressable
1084 * space we need to add the left and top borders to dst offsets temporarily.
1085 * TODO: fix in DM, stream dst is supposed to be in vactive
1087 pipe_ctx->stream->dst.x += timing->h_border_left;
1088 pipe_ctx->stream->dst.y += timing->v_border_top;
1090 /* Calculate H and V active size */
1091 pipe_ctx->plane_res.scl_data.h_active = timing->h_addressable +
1092 timing->h_border_left + timing->h_border_right;
1093 pipe_ctx->plane_res.scl_data.v_active = timing->v_addressable +
1094 timing->v_border_top + timing->v_border_bottom;
1095 if (pipe_ctx->next_odm_pipe || pipe_ctx->prev_odm_pipe)
1096 pipe_ctx->plane_res.scl_data.h_active /= get_num_odm_splits(pipe_ctx) + 1;
1098 /* depends on h_active */
1099 calculate_recout(pipe_ctx);
1100 /* depends on pixel format */
1101 calculate_scaling_ratios(pipe_ctx);
1102 /* depends on scaling ratios and recout, does not calculate offset yet */
1103 calculate_viewport_size(pipe_ctx);
1105 /* Stopgap for validation of ODM + MPO on one side of screen case */
1106 if (pipe_ctx->plane_res.scl_data.viewport.height < 1 ||
1107 pipe_ctx->plane_res.scl_data.viewport.width < 1)
1111 * LB calculations depend on vp size, h/v_active and scaling ratios
1112 * Setting line buffer pixel depth to 24bpp yields banding
1113 * on certain displays, such as the Sharp 4k. 36bpp is needed
1114 * to support SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616 and
1115 * SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616 with actual > 10 bpc
1116 * precision on at least DCN display engines. However, at least
1117 * Carrizo with DCE_VERSION_11_0 does not like 36 bpp lb depth,
1118 * so use only 30 bpp on DCE_VERSION_11_0. Testing with DCE 11.2 and 8.3
1119 * did not show such problems, so this seems to be the exception.
1121 if (plane_state->ctx->dce_version > DCE_VERSION_11_0)
1122 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_36BPP;
1124 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1126 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = plane_state->per_pixel_alpha;
1128 if (pipe_ctx->plane_res.xfm != NULL)
1129 res = pipe_ctx->plane_res.xfm->funcs->transform_get_optimal_number_of_taps(
1130 pipe_ctx->plane_res.xfm, &pipe_ctx->plane_res.scl_data, &plane_state->scaling_quality);
1132 if (pipe_ctx->plane_res.dpp != NULL)
1133 res = pipe_ctx->plane_res.dpp->funcs->dpp_get_optimal_number_of_taps(
1134 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data, &plane_state->scaling_quality);
1138 /* Try 24 bpp linebuffer */
1139 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_24BPP;
1141 if (pipe_ctx->plane_res.xfm != NULL)
1142 res = pipe_ctx->plane_res.xfm->funcs->transform_get_optimal_number_of_taps(
1143 pipe_ctx->plane_res.xfm,
1144 &pipe_ctx->plane_res.scl_data,
1145 &plane_state->scaling_quality);
1147 if (pipe_ctx->plane_res.dpp != NULL)
1148 res = pipe_ctx->plane_res.dpp->funcs->dpp_get_optimal_number_of_taps(
1149 pipe_ctx->plane_res.dpp,
1150 &pipe_ctx->plane_res.scl_data,
1151 &plane_state->scaling_quality);
1155 * Depends on recout, scaling ratios, h_active and taps
1156 * May need to re-check lb size after this in some obscure scenario
1159 calculate_inits_and_viewports(pipe_ctx);
1162 * Handle side by side and top bottom 3d recout offsets after vp calculation
1163 * since 3d is special and needs to calculate vp as if there is no recout offset
1164 * This may break with rotation, good thing we aren't mixing hw rotation and 3d
1166 if (pipe_ctx->top_pipe && pipe_ctx->top_pipe->plane_state == plane_state) {
1167 ASSERT(plane_state->rotation == ROTATION_ANGLE_0 ||
1168 (pipe_ctx->stream->view_format != VIEW_3D_FORMAT_TOP_AND_BOTTOM &&
1169 pipe_ctx->stream->view_format != VIEW_3D_FORMAT_SIDE_BY_SIDE));
1170 if (pipe_ctx->stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM)
1171 pipe_ctx->plane_res.scl_data.recout.y += pipe_ctx->plane_res.scl_data.recout.height;
1172 else if (pipe_ctx->stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE)
1173 pipe_ctx->plane_res.scl_data.recout.x += pipe_ctx->plane_res.scl_data.recout.width;
1176 if (!pipe_ctx->stream->ctx->dc->config.enable_windowed_mpo_odm) {
1177 if (pipe_ctx->plane_res.scl_data.viewport.height < MIN_VIEWPORT_SIZE ||
1178 pipe_ctx->plane_res.scl_data.viewport.width < MIN_VIEWPORT_SIZE)
1181 /* Clamp minimum viewport size */
1182 if (pipe_ctx->plane_res.scl_data.viewport.height < MIN_VIEWPORT_SIZE)
1183 pipe_ctx->plane_res.scl_data.viewport.height = MIN_VIEWPORT_SIZE;
1184 if (pipe_ctx->plane_res.scl_data.viewport.width < MIN_VIEWPORT_SIZE)
1185 pipe_ctx->plane_res.scl_data.viewport.width = MIN_VIEWPORT_SIZE;
1188 DC_LOG_SCALER("%s pipe %d:\nViewport: height:%d width:%d x:%d y:%d Recout: height:%d width:%d x:%d y:%d HACTIVE:%d VACTIVE:%d\n"
1189 "src_rect: height:%d width:%d x:%d y:%d dst_rect: height:%d width:%d x:%d y:%d clip_rect: height:%d width:%d x:%d y:%d\n",
1192 pipe_ctx->plane_res.scl_data.viewport.height,
1193 pipe_ctx->plane_res.scl_data.viewport.width,
1194 pipe_ctx->plane_res.scl_data.viewport.x,
1195 pipe_ctx->plane_res.scl_data.viewport.y,
1196 pipe_ctx->plane_res.scl_data.recout.height,
1197 pipe_ctx->plane_res.scl_data.recout.width,
1198 pipe_ctx->plane_res.scl_data.recout.x,
1199 pipe_ctx->plane_res.scl_data.recout.y,
1200 pipe_ctx->plane_res.scl_data.h_active,
1201 pipe_ctx->plane_res.scl_data.v_active,
1202 plane_state->src_rect.height,
1203 plane_state->src_rect.width,
1204 plane_state->src_rect.x,
1205 plane_state->src_rect.y,
1206 plane_state->dst_rect.height,
1207 plane_state->dst_rect.width,
1208 plane_state->dst_rect.x,
1209 plane_state->dst_rect.y,
1210 plane_state->clip_rect.height,
1211 plane_state->clip_rect.width,
1212 plane_state->clip_rect.x,
1213 plane_state->clip_rect.y);
1215 pipe_ctx->stream->dst.x -= timing->h_border_left;
1216 pipe_ctx->stream->dst.y -= timing->v_border_top;
1222 enum dc_status resource_build_scaling_params_for_context(
1223 const struct dc *dc,
1224 struct dc_state *context)
1228 for (i = 0; i < MAX_PIPES; i++) {
1229 if (context->res_ctx.pipe_ctx[i].plane_state != NULL &&
1230 context->res_ctx.pipe_ctx[i].stream != NULL)
1231 if (!resource_build_scaling_params(&context->res_ctx.pipe_ctx[i]))
1232 return DC_FAIL_SCALING;
1238 struct pipe_ctx *find_idle_secondary_pipe(
1239 struct resource_context *res_ctx,
1240 const struct resource_pool *pool,
1241 const struct pipe_ctx *primary_pipe)
1244 struct pipe_ctx *secondary_pipe = NULL;
1247 * We add a preferred pipe mapping to avoid the chance that
1248 * MPCCs already in use will need to be reassigned to other trees.
1249 * For example, if we went with the strict, assign backwards logic:
1252 * Display A on, no surface, top pipe = 0
1253 * Display B on, no surface, top pipe = 1
1256 * Display A on, no surface, top pipe = 0
1257 * Display B on, surface enable, top pipe = 1, bottom pipe = 5
1260 * Display A on, surface enable, top pipe = 0, bottom pipe = 5
1261 * Display B on, surface enable, top pipe = 1, bottom pipe = 4
1263 * The state 2->3 transition requires remapping MPCC 5 from display B
1266 * However, with the preferred pipe logic, state 2 would look like:
1269 * Display A on, no surface, top pipe = 0
1270 * Display B on, surface enable, top pipe = 1, bottom pipe = 4
1272 * This would then cause 2->3 to not require remapping any MPCCs.
1275 int preferred_pipe_idx = (pool->pipe_count - 1) - primary_pipe->pipe_idx;
1276 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1277 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1278 secondary_pipe->pipe_idx = preferred_pipe_idx;
1283 * search backwards for the second pipe to keep pipe
1284 * assignment more consistent
1286 if (!secondary_pipe)
1287 for (i = pool->pipe_count - 1; i >= 0; i--) {
1288 if (res_ctx->pipe_ctx[i].stream == NULL) {
1289 secondary_pipe = &res_ctx->pipe_ctx[i];
1290 secondary_pipe->pipe_idx = i;
1295 return secondary_pipe;
1298 struct pipe_ctx *resource_get_head_pipe_for_stream(
1299 struct resource_context *res_ctx,
1300 struct dc_stream_state *stream)
1304 for (i = 0; i < MAX_PIPES; i++) {
1305 if (res_ctx->pipe_ctx[i].stream == stream
1306 && !res_ctx->pipe_ctx[i].top_pipe
1307 && !res_ctx->pipe_ctx[i].prev_odm_pipe)
1308 return &res_ctx->pipe_ctx[i];
1313 static struct pipe_ctx *resource_get_tail_pipe(
1314 struct resource_context *res_ctx,
1315 struct pipe_ctx *head_pipe)
1317 struct pipe_ctx *tail_pipe;
1319 tail_pipe = head_pipe->bottom_pipe;
1322 head_pipe = tail_pipe;
1323 tail_pipe = tail_pipe->bottom_pipe;
1330 * A free_pipe for a stream is defined here as a pipe
1331 * that has no surface attached yet
1333 static struct pipe_ctx *acquire_free_pipe_for_head(
1334 struct dc_state *context,
1335 const struct resource_pool *pool,
1336 struct pipe_ctx *head_pipe)
1339 struct resource_context *res_ctx = &context->res_ctx;
1341 if (!head_pipe->plane_state)
1344 /* Re-use pipe already acquired for this stream if available*/
1345 for (i = pool->pipe_count - 1; i >= 0; i--) {
1346 if (res_ctx->pipe_ctx[i].stream == head_pipe->stream &&
1347 !res_ctx->pipe_ctx[i].plane_state) {
1348 return &res_ctx->pipe_ctx[i];
1353 * At this point we have no re-useable pipe for this stream and we need
1354 * to acquire an idle one to satisfy the request
1357 if (!pool->funcs->acquire_idle_pipe_for_layer)
1360 return pool->funcs->acquire_idle_pipe_for_layer(context, pool, head_pipe->stream);
1363 #if defined(CONFIG_DRM_AMD_DC_DCN)
1364 static int acquire_first_split_pipe(
1365 struct resource_context *res_ctx,
1366 const struct resource_pool *pool,
1367 struct dc_stream_state *stream)
1371 for (i = 0; i < pool->pipe_count; i++) {
1372 struct pipe_ctx *split_pipe = &res_ctx->pipe_ctx[i];
1374 if (split_pipe->top_pipe &&
1375 split_pipe->top_pipe->plane_state == split_pipe->plane_state) {
1376 split_pipe->top_pipe->bottom_pipe = split_pipe->bottom_pipe;
1377 if (split_pipe->bottom_pipe)
1378 split_pipe->bottom_pipe->top_pipe = split_pipe->top_pipe;
1380 if (split_pipe->top_pipe->plane_state)
1381 resource_build_scaling_params(split_pipe->top_pipe);
1383 memset(split_pipe, 0, sizeof(*split_pipe));
1384 split_pipe->stream_res.tg = pool->timing_generators[i];
1385 split_pipe->plane_res.hubp = pool->hubps[i];
1386 split_pipe->plane_res.ipp = pool->ipps[i];
1387 split_pipe->plane_res.dpp = pool->dpps[i];
1388 split_pipe->stream_res.opp = pool->opps[i];
1389 split_pipe->plane_res.mpcc_inst = pool->dpps[i]->inst;
1390 split_pipe->pipe_idx = i;
1392 split_pipe->stream = stream;
1400 bool dc_add_plane_to_context(
1401 const struct dc *dc,
1402 struct dc_stream_state *stream,
1403 struct dc_plane_state *plane_state,
1404 struct dc_state *context)
1407 struct resource_pool *pool = dc->res_pool;
1408 struct pipe_ctx *head_pipe, *tail_pipe, *free_pipe;
1409 struct dc_stream_status *stream_status = NULL;
1411 for (i = 0; i < context->stream_count; i++)
1412 if (context->streams[i] == stream) {
1413 stream_status = &context->stream_status[i];
1416 if (stream_status == NULL) {
1417 dm_error("Existing stream not found; failed to attach surface!\n");
1422 if (stream_status->plane_count == MAX_SURFACE_NUM) {
1423 dm_error("Surface: can not attach plane_state %p! Maximum is: %d\n",
1424 plane_state, MAX_SURFACE_NUM);
1428 head_pipe = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
1431 dm_error("Head pipe not found for stream_state %p !\n", stream);
1435 /* retain new surface, but only once per stream */
1436 dc_plane_state_retain(plane_state);
1439 free_pipe = acquire_free_pipe_for_head(context, pool, head_pipe);
1441 #if defined(CONFIG_DRM_AMD_DC_DCN)
1443 int pipe_idx = acquire_first_split_pipe(&context->res_ctx, pool, stream);
1445 free_pipe = &context->res_ctx.pipe_ctx[pipe_idx];
1449 dc_plane_state_release(plane_state);
1453 free_pipe->plane_state = plane_state;
1455 if (head_pipe != free_pipe) {
1456 tail_pipe = resource_get_tail_pipe(&context->res_ctx, head_pipe);
1458 free_pipe->stream_res.tg = tail_pipe->stream_res.tg;
1459 free_pipe->stream_res.abm = tail_pipe->stream_res.abm;
1460 free_pipe->stream_res.opp = tail_pipe->stream_res.opp;
1461 free_pipe->stream_res.stream_enc = tail_pipe->stream_res.stream_enc;
1462 free_pipe->stream_res.audio = tail_pipe->stream_res.audio;
1463 free_pipe->clock_source = tail_pipe->clock_source;
1464 free_pipe->top_pipe = tail_pipe;
1465 tail_pipe->bottom_pipe = free_pipe;
1466 if (!free_pipe->next_odm_pipe && tail_pipe->next_odm_pipe && tail_pipe->next_odm_pipe->bottom_pipe) {
1467 free_pipe->next_odm_pipe = tail_pipe->next_odm_pipe->bottom_pipe;
1468 tail_pipe->next_odm_pipe->bottom_pipe->prev_odm_pipe = free_pipe;
1470 if (!free_pipe->prev_odm_pipe && tail_pipe->prev_odm_pipe && tail_pipe->prev_odm_pipe->bottom_pipe) {
1471 free_pipe->prev_odm_pipe = tail_pipe->prev_odm_pipe->bottom_pipe;
1472 tail_pipe->prev_odm_pipe->bottom_pipe->next_odm_pipe = free_pipe;
1475 head_pipe = head_pipe->next_odm_pipe;
1477 /* assign new surfaces*/
1478 stream_status->plane_states[stream_status->plane_count] = plane_state;
1480 stream_status->plane_count++;
1485 bool dc_remove_plane_from_context(
1486 const struct dc *dc,
1487 struct dc_stream_state *stream,
1488 struct dc_plane_state *plane_state,
1489 struct dc_state *context)
1492 struct dc_stream_status *stream_status = NULL;
1493 struct resource_pool *pool = dc->res_pool;
1495 for (i = 0; i < context->stream_count; i++)
1496 if (context->streams[i] == stream) {
1497 stream_status = &context->stream_status[i];
1501 if (stream_status == NULL) {
1502 dm_error("Existing stream not found; failed to remove plane.\n");
1506 /* release pipe for plane*/
1507 for (i = pool->pipe_count - 1; i >= 0; i--) {
1508 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1510 if (pipe_ctx->plane_state == plane_state) {
1511 if (pipe_ctx->top_pipe)
1512 pipe_ctx->top_pipe->bottom_pipe = pipe_ctx->bottom_pipe;
1514 /* Second condition is to avoid setting NULL to top pipe
1515 * of tail pipe making it look like head pipe in subsequent
1518 if (pipe_ctx->bottom_pipe && pipe_ctx->top_pipe)
1519 pipe_ctx->bottom_pipe->top_pipe = pipe_ctx->top_pipe;
1522 * For head pipe detach surfaces from pipe for tail
1523 * pipe just zero it out
1525 if (!pipe_ctx->top_pipe)
1526 pipe_ctx->plane_state = NULL;
1528 memset(pipe_ctx, 0, sizeof(*pipe_ctx));
1533 for (i = 0; i < stream_status->plane_count; i++) {
1534 if (stream_status->plane_states[i] == plane_state) {
1536 dc_plane_state_release(stream_status->plane_states[i]);
1541 if (i == stream_status->plane_count) {
1542 dm_error("Existing plane_state not found; failed to detach it!\n");
1546 stream_status->plane_count--;
1548 /* Start at the plane we've just released, and move all the planes one index forward to "trim" the array */
1549 for (; i < stream_status->plane_count; i++)
1550 stream_status->plane_states[i] = stream_status->plane_states[i + 1];
1552 stream_status->plane_states[stream_status->plane_count] = NULL;
1557 bool dc_rem_all_planes_for_stream(
1558 const struct dc *dc,
1559 struct dc_stream_state *stream,
1560 struct dc_state *context)
1562 int i, old_plane_count;
1563 struct dc_stream_status *stream_status = NULL;
1564 struct dc_plane_state *del_planes[MAX_SURFACE_NUM] = { 0 };
1566 for (i = 0; i < context->stream_count; i++)
1567 if (context->streams[i] == stream) {
1568 stream_status = &context->stream_status[i];
1572 if (stream_status == NULL) {
1573 dm_error("Existing stream %p not found!\n", stream);
1577 old_plane_count = stream_status->plane_count;
1579 for (i = 0; i < old_plane_count; i++)
1580 del_planes[i] = stream_status->plane_states[i];
1582 for (i = 0; i < old_plane_count; i++)
1583 if (!dc_remove_plane_from_context(dc, stream, del_planes[i], context))
1589 static bool add_all_planes_for_stream(
1590 const struct dc *dc,
1591 struct dc_stream_state *stream,
1592 const struct dc_validation_set set[],
1594 struct dc_state *context)
1598 for (i = 0; i < set_count; i++)
1599 if (set[i].stream == stream)
1602 if (i == set_count) {
1603 dm_error("Stream %p not found in set!\n", stream);
1607 for (j = 0; j < set[i].plane_count; j++)
1608 if (!dc_add_plane_to_context(dc, stream, set[i].plane_states[j], context))
1614 bool dc_add_all_planes_for_stream(
1615 const struct dc *dc,
1616 struct dc_stream_state *stream,
1617 struct dc_plane_state * const *plane_states,
1619 struct dc_state *context)
1621 struct dc_validation_set set;
1624 set.stream = stream;
1625 set.plane_count = plane_count;
1627 for (i = 0; i < plane_count; i++)
1628 set.plane_states[i] = plane_states[i];
1630 return add_all_planes_for_stream(dc, stream, &set, 1, context);
1633 bool is_timing_changed(struct dc_stream_state *cur_stream,
1634 struct dc_stream_state *new_stream)
1636 if (cur_stream == NULL)
1639 /* If output color space is changed, need to reprogram info frames */
1640 if (cur_stream->output_color_space != new_stream->output_color_space)
1644 &cur_stream->timing,
1645 &new_stream->timing,
1646 sizeof(struct dc_crtc_timing)) != 0;
1649 static bool are_stream_backends_same(
1650 struct dc_stream_state *stream_a, struct dc_stream_state *stream_b)
1652 if (stream_a == stream_b)
1655 if (stream_a == NULL || stream_b == NULL)
1658 if (is_timing_changed(stream_a, stream_b))
1661 if (stream_a->signal != stream_b->signal)
1664 if (stream_a->dpms_off != stream_b->dpms_off)
1671 * dc_is_stream_unchanged() - Compare two stream states for equivalence.
1673 * Checks if there a difference between the two states
1674 * that would require a mode change.
1676 * Does not compare cursor position or attributes.
1678 bool dc_is_stream_unchanged(
1679 struct dc_stream_state *old_stream, struct dc_stream_state *stream)
1682 if (!are_stream_backends_same(old_stream, stream))
1685 if (old_stream->ignore_msa_timing_param != stream->ignore_msa_timing_param)
1688 /*compare audio info*/
1689 if (memcmp(&old_stream->audio_info, &stream->audio_info, sizeof(stream->audio_info)) != 0)
1696 * dc_is_stream_scaling_unchanged() - Compare scaling rectangles of two streams.
1698 bool dc_is_stream_scaling_unchanged(struct dc_stream_state *old_stream,
1699 struct dc_stream_state *stream)
1701 if (old_stream == stream)
1704 if (old_stream == NULL || stream == NULL)
1707 if (memcmp(&old_stream->src,
1709 sizeof(struct rect)) != 0)
1712 if (memcmp(&old_stream->dst,
1714 sizeof(struct rect)) != 0)
1720 static void update_stream_engine_usage(
1721 struct resource_context *res_ctx,
1722 const struct resource_pool *pool,
1723 struct stream_encoder *stream_enc,
1728 for (i = 0; i < pool->stream_enc_count; i++) {
1729 if (pool->stream_enc[i] == stream_enc)
1730 res_ctx->is_stream_enc_acquired[i] = acquired;
1734 static void update_hpo_dp_stream_engine_usage(
1735 struct resource_context *res_ctx,
1736 const struct resource_pool *pool,
1737 struct hpo_dp_stream_encoder *hpo_dp_stream_enc,
1742 for (i = 0; i < pool->hpo_dp_stream_enc_count; i++) {
1743 if (pool->hpo_dp_stream_enc[i] == hpo_dp_stream_enc)
1744 res_ctx->is_hpo_dp_stream_enc_acquired[i] = acquired;
1748 static inline int find_acquired_hpo_dp_link_enc_for_link(
1749 const struct resource_context *res_ctx,
1750 const struct dc_link *link)
1754 for (i = 0; i < ARRAY_SIZE(res_ctx->hpo_dp_link_enc_to_link_idx); i++)
1755 if (res_ctx->hpo_dp_link_enc_ref_cnts[i] > 0 &&
1756 res_ctx->hpo_dp_link_enc_to_link_idx[i] == link->link_index)
1762 static inline int find_free_hpo_dp_link_enc(const struct resource_context *res_ctx,
1763 const struct resource_pool *pool)
1767 for (i = 0; i < ARRAY_SIZE(res_ctx->hpo_dp_link_enc_ref_cnts); i++)
1768 if (res_ctx->hpo_dp_link_enc_ref_cnts[i] == 0)
1771 return (i < ARRAY_SIZE(res_ctx->hpo_dp_link_enc_ref_cnts) &&
1772 i < pool->hpo_dp_link_enc_count) ? i : -1;
1775 static inline void acquire_hpo_dp_link_enc(
1776 struct resource_context *res_ctx,
1777 unsigned int link_index,
1780 res_ctx->hpo_dp_link_enc_to_link_idx[enc_index] = link_index;
1781 res_ctx->hpo_dp_link_enc_ref_cnts[enc_index] = 1;
1784 static inline void retain_hpo_dp_link_enc(
1785 struct resource_context *res_ctx,
1788 res_ctx->hpo_dp_link_enc_ref_cnts[enc_index]++;
1791 static inline void release_hpo_dp_link_enc(
1792 struct resource_context *res_ctx,
1795 ASSERT(res_ctx->hpo_dp_link_enc_ref_cnts[enc_index] > 0);
1796 res_ctx->hpo_dp_link_enc_ref_cnts[enc_index]--;
1799 static bool add_hpo_dp_link_enc_to_ctx(struct resource_context *res_ctx,
1800 const struct resource_pool *pool,
1801 struct pipe_ctx *pipe_ctx,
1802 struct dc_stream_state *stream)
1806 enc_index = find_acquired_hpo_dp_link_enc_for_link(res_ctx, stream->link);
1808 if (enc_index >= 0) {
1809 retain_hpo_dp_link_enc(res_ctx, enc_index);
1811 enc_index = find_free_hpo_dp_link_enc(res_ctx, pool);
1813 acquire_hpo_dp_link_enc(res_ctx, stream->link->link_index, enc_index);
1817 pipe_ctx->link_res.hpo_dp_link_enc = pool->hpo_dp_link_enc[enc_index];
1819 return pipe_ctx->link_res.hpo_dp_link_enc != NULL;
1822 static void remove_hpo_dp_link_enc_from_ctx(struct resource_context *res_ctx,
1823 struct pipe_ctx *pipe_ctx,
1824 struct dc_stream_state *stream)
1828 enc_index = find_acquired_hpo_dp_link_enc_for_link(res_ctx, stream->link);
1830 if (enc_index >= 0) {
1831 release_hpo_dp_link_enc(res_ctx, enc_index);
1832 pipe_ctx->link_res.hpo_dp_link_enc = NULL;
1836 /* TODO: release audio object */
1837 void update_audio_usage(
1838 struct resource_context *res_ctx,
1839 const struct resource_pool *pool,
1840 struct audio *audio,
1844 for (i = 0; i < pool->audio_count; i++) {
1845 if (pool->audios[i] == audio)
1846 res_ctx->is_audio_acquired[i] = acquired;
1850 static int acquire_first_free_pipe(
1851 struct resource_context *res_ctx,
1852 const struct resource_pool *pool,
1853 struct dc_stream_state *stream)
1857 for (i = 0; i < pool->pipe_count; i++) {
1858 if (!res_ctx->pipe_ctx[i].stream) {
1859 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
1861 pipe_ctx->stream_res.tg = pool->timing_generators[i];
1862 pipe_ctx->plane_res.mi = pool->mis[i];
1863 pipe_ctx->plane_res.hubp = pool->hubps[i];
1864 pipe_ctx->plane_res.ipp = pool->ipps[i];
1865 pipe_ctx->plane_res.xfm = pool->transforms[i];
1866 pipe_ctx->plane_res.dpp = pool->dpps[i];
1867 pipe_ctx->stream_res.opp = pool->opps[i];
1869 pipe_ctx->plane_res.mpcc_inst = pool->dpps[i]->inst;
1870 pipe_ctx->pipe_idx = i;
1873 pipe_ctx->stream = stream;
1880 static struct hpo_dp_stream_encoder *find_first_free_match_hpo_dp_stream_enc_for_link(
1881 struct resource_context *res_ctx,
1882 const struct resource_pool *pool,
1883 struct dc_stream_state *stream)
1887 for (i = 0; i < pool->hpo_dp_stream_enc_count; i++) {
1888 if (!res_ctx->is_hpo_dp_stream_enc_acquired[i] &&
1889 pool->hpo_dp_stream_enc[i]) {
1891 return pool->hpo_dp_stream_enc[i];
1898 static struct audio *find_first_free_audio(
1899 struct resource_context *res_ctx,
1900 const struct resource_pool *pool,
1902 enum dce_version dc_version)
1904 int i, available_audio_count;
1906 available_audio_count = pool->audio_count;
1908 for (i = 0; i < available_audio_count; i++) {
1909 if ((res_ctx->is_audio_acquired[i] == false) && (res_ctx->is_stream_enc_acquired[i] == true)) {
1910 /*we have enough audio endpoint, find the matching inst*/
1913 return pool->audios[i];
1917 /* use engine id to find free audio */
1918 if ((id < available_audio_count) && (res_ctx->is_audio_acquired[id] == false)) {
1919 return pool->audios[id];
1921 /*not found the matching one, first come first serve*/
1922 for (i = 0; i < available_audio_count; i++) {
1923 if (res_ctx->is_audio_acquired[i] == false) {
1924 return pool->audios[i];
1931 * dc_add_stream_to_ctx() - Add a new dc_stream_state to a dc_state.
1933 enum dc_status dc_add_stream_to_ctx(
1935 struct dc_state *new_ctx,
1936 struct dc_stream_state *stream)
1939 DC_LOGGER_INIT(dc->ctx->logger);
1941 if (new_ctx->stream_count >= dc->res_pool->timing_generator_count) {
1942 DC_LOG_WARNING("Max streams reached, can't add stream %p !\n", stream);
1943 return DC_ERROR_UNEXPECTED;
1946 new_ctx->streams[new_ctx->stream_count] = stream;
1947 dc_stream_retain(stream);
1948 new_ctx->stream_count++;
1950 res = dc->res_pool->funcs->add_stream_to_ctx(dc, new_ctx, stream);
1952 DC_LOG_WARNING("Adding stream %p to context failed with err %d!\n", stream, res);
1958 * dc_remove_stream_from_ctx() - Remove a stream from a dc_state.
1960 enum dc_status dc_remove_stream_from_ctx(
1962 struct dc_state *new_ctx,
1963 struct dc_stream_state *stream)
1966 struct dc_context *dc_ctx = dc->ctx;
1967 struct pipe_ctx *del_pipe = resource_get_head_pipe_for_stream(&new_ctx->res_ctx, stream);
1968 struct pipe_ctx *odm_pipe;
1971 DC_ERROR("Pipe not found for stream %p !\n", stream);
1972 return DC_ERROR_UNEXPECTED;
1975 odm_pipe = del_pipe->next_odm_pipe;
1977 /* Release primary pipe */
1978 ASSERT(del_pipe->stream_res.stream_enc);
1979 update_stream_engine_usage(
1982 del_pipe->stream_res.stream_enc,
1984 if (is_dp_128b_132b_signal(del_pipe)) {
1985 update_hpo_dp_stream_engine_usage(
1986 &new_ctx->res_ctx, dc->res_pool,
1987 del_pipe->stream_res.hpo_dp_stream_enc,
1989 remove_hpo_dp_link_enc_from_ctx(&new_ctx->res_ctx, del_pipe, del_pipe->stream);
1992 if (del_pipe->stream_res.audio)
1996 del_pipe->stream_res.audio,
1999 resource_unreference_clock_source(&new_ctx->res_ctx,
2001 del_pipe->clock_source);
2003 if (dc->res_pool->funcs->remove_stream_from_ctx)
2004 dc->res_pool->funcs->remove_stream_from_ctx(dc, new_ctx, stream);
2007 struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe;
2009 memset(odm_pipe, 0, sizeof(*odm_pipe));
2010 odm_pipe = next_odm_pipe;
2012 memset(del_pipe, 0, sizeof(*del_pipe));
2014 for (i = 0; i < new_ctx->stream_count; i++)
2015 if (new_ctx->streams[i] == stream)
2018 if (new_ctx->streams[i] != stream) {
2019 DC_ERROR("Context doesn't have stream %p !\n", stream);
2020 return DC_ERROR_UNEXPECTED;
2023 dc_stream_release(new_ctx->streams[i]);
2024 new_ctx->stream_count--;
2026 /* Trim back arrays */
2027 for (; i < new_ctx->stream_count; i++) {
2028 new_ctx->streams[i] = new_ctx->streams[i + 1];
2029 new_ctx->stream_status[i] = new_ctx->stream_status[i + 1];
2032 new_ctx->streams[new_ctx->stream_count] = NULL;
2034 &new_ctx->stream_status[new_ctx->stream_count],
2036 sizeof(new_ctx->stream_status[0]));
2041 static struct dc_stream_state *find_pll_sharable_stream(
2042 struct dc_stream_state *stream_needs_pll,
2043 struct dc_state *context)
2047 for (i = 0; i < context->stream_count; i++) {
2048 struct dc_stream_state *stream_has_pll = context->streams[i];
2050 /* We are looking for non dp, non virtual stream */
2051 if (resource_are_streams_timing_synchronizable(
2052 stream_needs_pll, stream_has_pll)
2053 && !dc_is_dp_signal(stream_has_pll->signal)
2054 && stream_has_pll->link->connector_signal
2055 != SIGNAL_TYPE_VIRTUAL)
2056 return stream_has_pll;
2063 static int get_norm_pix_clk(const struct dc_crtc_timing *timing)
2065 uint32_t pix_clk = timing->pix_clk_100hz;
2066 uint32_t normalized_pix_clk = pix_clk;
2068 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2070 if (timing->pixel_encoding != PIXEL_ENCODING_YCBCR422) {
2071 switch (timing->display_color_depth) {
2072 case COLOR_DEPTH_666:
2073 case COLOR_DEPTH_888:
2074 normalized_pix_clk = pix_clk;
2076 case COLOR_DEPTH_101010:
2077 normalized_pix_clk = (pix_clk * 30) / 24;
2079 case COLOR_DEPTH_121212:
2080 normalized_pix_clk = (pix_clk * 36) / 24;
2082 case COLOR_DEPTH_161616:
2083 normalized_pix_clk = (pix_clk * 48) / 24;
2090 return normalized_pix_clk;
2093 static void calculate_phy_pix_clks(struct dc_stream_state *stream)
2095 /* update actual pixel clock on all streams */
2096 if (dc_is_hdmi_signal(stream->signal))
2097 stream->phy_pix_clk = get_norm_pix_clk(
2098 &stream->timing) / 10;
2100 stream->phy_pix_clk =
2101 stream->timing.pix_clk_100hz / 10;
2103 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2104 stream->phy_pix_clk *= 2;
2107 static int acquire_resource_from_hw_enabled_state(
2108 struct resource_context *res_ctx,
2109 const struct resource_pool *pool,
2110 struct dc_stream_state *stream)
2112 struct dc_link *link = stream->link;
2113 unsigned int i, inst, tg_inst = 0;
2115 /* Check for enabled DIG to identify enabled display */
2116 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
2119 inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
2121 if (inst == ENGINE_ID_UNKNOWN)
2124 for (i = 0; i < pool->stream_enc_count; i++) {
2125 if (pool->stream_enc[i]->id == inst) {
2126 tg_inst = pool->stream_enc[i]->funcs->dig_source_otg(
2127 pool->stream_enc[i]);
2132 // tg_inst not found
2133 if (i == pool->stream_enc_count)
2136 if (tg_inst >= pool->timing_generator_count)
2139 if (!res_ctx->pipe_ctx[tg_inst].stream) {
2140 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[tg_inst];
2142 pipe_ctx->stream_res.tg = pool->timing_generators[tg_inst];
2143 pipe_ctx->plane_res.mi = pool->mis[tg_inst];
2144 pipe_ctx->plane_res.hubp = pool->hubps[tg_inst];
2145 pipe_ctx->plane_res.ipp = pool->ipps[tg_inst];
2146 pipe_ctx->plane_res.xfm = pool->transforms[tg_inst];
2147 pipe_ctx->plane_res.dpp = pool->dpps[tg_inst];
2148 pipe_ctx->stream_res.opp = pool->opps[tg_inst];
2150 if (pool->dpps[tg_inst]) {
2151 pipe_ctx->plane_res.mpcc_inst = pool->dpps[tg_inst]->inst;
2153 // Read DPP->MPCC->OPP Pipe from HW State
2154 if (pool->mpc->funcs->read_mpcc_state) {
2155 struct mpcc_state s = {0};
2157 pool->mpc->funcs->read_mpcc_state(pool->mpc, pipe_ctx->plane_res.mpcc_inst, &s);
2159 if (s.dpp_id < MAX_MPCC)
2160 pool->mpc->mpcc_array[pipe_ctx->plane_res.mpcc_inst].dpp_id = s.dpp_id;
2162 if (s.bot_mpcc_id < MAX_MPCC)
2163 pool->mpc->mpcc_array[pipe_ctx->plane_res.mpcc_inst].mpcc_bot =
2164 &pool->mpc->mpcc_array[s.bot_mpcc_id];
2166 if (s.opp_id < MAX_OPP)
2167 pipe_ctx->stream_res.opp->mpc_tree_params.opp_id = s.opp_id;
2170 pipe_ctx->pipe_idx = tg_inst;
2172 pipe_ctx->stream = stream;
2179 static void mark_seamless_boot_stream(
2180 const struct dc *dc,
2181 struct dc_stream_state *stream)
2183 struct dc_bios *dcb = dc->ctx->dc_bios;
2185 if (dc->config.allow_seamless_boot_optimization &&
2186 !dcb->funcs->is_accelerated_mode(dcb)) {
2187 if (dc_validate_boot_timing(dc, stream->sink, &stream->timing))
2188 stream->apply_seamless_boot_optimization = true;
2192 enum dc_status resource_map_pool_resources(
2193 const struct dc *dc,
2194 struct dc_state *context,
2195 struct dc_stream_state *stream)
2197 const struct resource_pool *pool = dc->res_pool;
2199 struct dc_context *dc_ctx = dc->ctx;
2200 struct pipe_ctx *pipe_ctx = NULL;
2203 calculate_phy_pix_clks(stream);
2205 mark_seamless_boot_stream(dc, stream);
2207 if (stream->apply_seamless_boot_optimization) {
2208 pipe_idx = acquire_resource_from_hw_enabled_state(
2213 /* hw resource was assigned to other stream */
2214 stream->apply_seamless_boot_optimization = false;
2218 /* acquire new resources */
2219 pipe_idx = acquire_first_free_pipe(&context->res_ctx, pool, stream);
2221 #ifdef CONFIG_DRM_AMD_DC_DCN
2223 pipe_idx = acquire_first_split_pipe(&context->res_ctx, pool, stream);
2226 if (pipe_idx < 0 || context->res_ctx.pipe_ctx[pipe_idx].stream_res.tg == NULL)
2227 return DC_NO_CONTROLLER_RESOURCE;
2229 pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2231 pipe_ctx->stream_res.stream_enc =
2232 dc->res_pool->funcs->find_first_free_match_stream_enc_for_link(
2233 &context->res_ctx, pool, stream);
2235 if (!pipe_ctx->stream_res.stream_enc)
2236 return DC_NO_STREAM_ENC_RESOURCE;
2238 update_stream_engine_usage(
2239 &context->res_ctx, pool,
2240 pipe_ctx->stream_res.stream_enc,
2243 /* Allocate DP HPO Stream Encoder based on signal, hw capabilities
2246 if (dc_is_dp_signal(stream->signal) &&
2248 struct dc_link_settings link_settings = {0};
2250 decide_link_settings(stream, &link_settings);
2251 if (dp_get_link_encoding_format(&link_settings) == DP_128b_132b_ENCODING) {
2252 pipe_ctx->stream_res.hpo_dp_stream_enc =
2253 find_first_free_match_hpo_dp_stream_enc_for_link(
2254 &context->res_ctx, pool, stream);
2256 if (!pipe_ctx->stream_res.hpo_dp_stream_enc)
2257 return DC_NO_STREAM_ENC_RESOURCE;
2259 update_hpo_dp_stream_engine_usage(
2260 &context->res_ctx, pool,
2261 pipe_ctx->stream_res.hpo_dp_stream_enc,
2263 if (!add_hpo_dp_link_enc_to_ctx(&context->res_ctx, pool, pipe_ctx, stream))
2264 return DC_NO_LINK_ENC_RESOURCE;
2268 /* TODO: Add check if ASIC support and EDID audio */
2269 if (!stream->converter_disable_audio &&
2270 dc_is_audio_capable_signal(pipe_ctx->stream->signal) &&
2271 stream->audio_info.mode_count && stream->audio_info.flags.all) {
2272 pipe_ctx->stream_res.audio = find_first_free_audio(
2273 &context->res_ctx, pool, pipe_ctx->stream_res.stream_enc->id, dc_ctx->dce_version);
2276 * Audio assigned in order first come first get.
2277 * There are asics which has number of audio
2278 * resources less then number of pipes
2280 if (pipe_ctx->stream_res.audio)
2281 update_audio_usage(&context->res_ctx, pool,
2282 pipe_ctx->stream_res.audio, true);
2285 /* Add ABM to the resource if on EDP */
2286 if (pipe_ctx->stream && dc_is_embedded_signal(pipe_ctx->stream->signal)) {
2287 #if defined(CONFIG_DRM_AMD_DC_DCN)
2289 pipe_ctx->stream_res.abm = pool->abm;
2291 pipe_ctx->stream_res.abm = pool->multiple_abms[pipe_ctx->stream_res.tg->inst];
2293 pipe_ctx->stream_res.abm = pool->abm;
2297 for (i = 0; i < context->stream_count; i++)
2298 if (context->streams[i] == stream) {
2299 context->stream_status[i].primary_otg_inst = pipe_ctx->stream_res.tg->inst;
2300 context->stream_status[i].stream_enc_inst = pipe_ctx->stream_res.stream_enc->stream_enc_inst;
2301 context->stream_status[i].audio_inst =
2302 pipe_ctx->stream_res.audio ? pipe_ctx->stream_res.audio->inst : -1;
2307 DC_ERROR("Stream %p not found in new ctx!\n", stream);
2308 return DC_ERROR_UNEXPECTED;
2312 * dc_resource_state_copy_construct_current() - Creates a new dc_state from existing state
2313 * Is a shallow copy. Increments refcounts on existing streams and planes.
2314 * @dc: copy out of dc->current_state
2315 * @dst_ctx: copy into this
2317 void dc_resource_state_copy_construct_current(
2318 const struct dc *dc,
2319 struct dc_state *dst_ctx)
2321 dc_resource_state_copy_construct(dc->current_state, dst_ctx);
2325 void dc_resource_state_construct(
2326 const struct dc *dc,
2327 struct dc_state *dst_ctx)
2329 dst_ctx->clk_mgr = dc->clk_mgr;
2331 /* Initialise DIG link encoder resource tracking variables. */
2332 link_enc_cfg_init(dc, dst_ctx);
2336 bool dc_resource_is_dsc_encoding_supported(const struct dc *dc)
2338 if (dc->res_pool == NULL)
2341 return dc->res_pool->res_cap->num_dsc > 0;
2346 * dc_validate_global_state() - Determine if HW can support a given state
2347 * Checks HW resource availability and bandwidth requirement.
2348 * @dc: dc struct for this driver
2349 * @new_ctx: state to be validated
2350 * @fast_validate: set to true if only yes/no to support matters
2352 * Return: DC_OK if the result can be programmed. Otherwise, an error code.
2354 enum dc_status dc_validate_global_state(
2356 struct dc_state *new_ctx,
2359 enum dc_status result = DC_ERROR_UNEXPECTED;
2363 return DC_ERROR_UNEXPECTED;
2365 if (dc->res_pool->funcs->validate_global) {
2366 result = dc->res_pool->funcs->validate_global(dc, new_ctx);
2367 if (result != DC_OK)
2371 for (i = 0; i < new_ctx->stream_count; i++) {
2372 struct dc_stream_state *stream = new_ctx->streams[i];
2374 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2375 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[j];
2377 if (pipe_ctx->stream != stream)
2380 if (dc->res_pool->funcs->patch_unknown_plane_state &&
2381 pipe_ctx->plane_state &&
2382 pipe_ctx->plane_state->tiling_info.gfx9.swizzle == DC_SW_UNKNOWN) {
2383 result = dc->res_pool->funcs->patch_unknown_plane_state(pipe_ctx->plane_state);
2384 if (result != DC_OK)
2388 /* Switch to dp clock source only if there is
2389 * no non dp stream that shares the same timing
2390 * with the dp stream.
2392 if (dc_is_dp_signal(pipe_ctx->stream->signal) &&
2393 !find_pll_sharable_stream(stream, new_ctx)) {
2395 resource_unreference_clock_source(
2398 pipe_ctx->clock_source);
2400 pipe_ctx->clock_source = dc->res_pool->dp_clock_source;
2401 resource_reference_clock_source(
2404 pipe_ctx->clock_source);
2409 result = resource_build_scaling_params_for_context(dc, new_ctx);
2411 if (result == DC_OK)
2412 if (!dc->res_pool->funcs->validate_bandwidth(dc, new_ctx, fast_validate))
2413 result = DC_FAIL_BANDWIDTH_VALIDATE;
2415 #if defined(CONFIG_DRM_AMD_DC_DCN)
2417 * Only update link encoder to stream assignment after bandwidth validation passed.
2418 * TODO: Split out assignment and validation.
2420 if (result == DC_OK && dc->res_pool->funcs->link_encs_assign && fast_validate == false)
2421 dc->res_pool->funcs->link_encs_assign(
2422 dc, new_ctx, new_ctx->streams, new_ctx->stream_count);
2428 static void patch_gamut_packet_checksum(
2429 struct dc_info_packet *gamut_packet)
2431 /* For gamut we recalc checksum */
2432 if (gamut_packet->valid) {
2433 uint8_t chk_sum = 0;
2437 /*start of the Gamut data. */
2438 ptr = &gamut_packet->sb[3];
2440 for (i = 0; i <= gamut_packet->sb[1]; i++)
2443 gamut_packet->sb[2] = (uint8_t) (0x100 - chk_sum);
2447 static void set_avi_info_frame(
2448 struct dc_info_packet *info_packet,
2449 struct pipe_ctx *pipe_ctx)
2451 struct dc_stream_state *stream = pipe_ctx->stream;
2452 enum dc_color_space color_space = COLOR_SPACE_UNKNOWN;
2453 uint32_t pixel_encoding = 0;
2454 enum scanning_type scan_type = SCANNING_TYPE_NODATA;
2455 enum dc_aspect_ratio aspect = ASPECT_RATIO_NO_DATA;
2457 uint8_t itc_value = 0;
2458 uint8_t cn0_cn1 = 0;
2459 unsigned int cn0_cn1_value = 0;
2460 uint8_t *check_sum = NULL;
2461 uint8_t byte_index = 0;
2462 union hdmi_info_packet hdmi_info;
2463 union display_content_support support = {0};
2464 unsigned int vic = pipe_ctx->stream->timing.vic;
2465 enum dc_timing_3d_format format;
2467 memset(&hdmi_info, 0, sizeof(union hdmi_info_packet));
2469 color_space = pipe_ctx->stream->output_color_space;
2470 if (color_space == COLOR_SPACE_UNKNOWN)
2471 color_space = (stream->timing.pixel_encoding == PIXEL_ENCODING_RGB) ?
2472 COLOR_SPACE_SRGB:COLOR_SPACE_YCBCR709;
2474 /* Initialize header */
2475 hdmi_info.bits.header.info_frame_type = HDMI_INFOFRAME_TYPE_AVI;
2476 /* InfoFrameVersion_3 is defined by CEA861F (Section 6.4), but shall
2477 * not be used in HDMI 2.0 (Section 10.1) */
2478 hdmi_info.bits.header.version = 2;
2479 hdmi_info.bits.header.length = HDMI_AVI_INFOFRAME_SIZE;
2482 * IDO-defined (Y2,Y1,Y0 = 1,1,1) shall not be used by devices built
2483 * according to HDMI 2.0 spec (Section 10.1)
2486 switch (stream->timing.pixel_encoding) {
2487 case PIXEL_ENCODING_YCBCR422:
2491 case PIXEL_ENCODING_YCBCR444:
2494 case PIXEL_ENCODING_YCBCR420:
2498 case PIXEL_ENCODING_RGB:
2503 /* Y0_Y1_Y2 : The pixel encoding */
2504 /* H14b AVI InfoFrame has extension on Y-field from 2 bits to 3 bits */
2505 hdmi_info.bits.Y0_Y1_Y2 = pixel_encoding;
2507 /* A0 = 1 Active Format Information valid */
2508 hdmi_info.bits.A0 = ACTIVE_FORMAT_VALID;
2510 /* B0, B1 = 3; Bar info data is valid */
2511 hdmi_info.bits.B0_B1 = BAR_INFO_BOTH_VALID;
2513 hdmi_info.bits.SC0_SC1 = PICTURE_SCALING_UNIFORM;
2515 /* S0, S1 : Underscan / Overscan */
2516 /* TODO: un-hardcode scan type */
2517 scan_type = SCANNING_TYPE_UNDERSCAN;
2518 hdmi_info.bits.S0_S1 = scan_type;
2520 /* C0, C1 : Colorimetry */
2521 if (color_space == COLOR_SPACE_YCBCR709 ||
2522 color_space == COLOR_SPACE_YCBCR709_LIMITED)
2523 hdmi_info.bits.C0_C1 = COLORIMETRY_ITU709;
2524 else if (color_space == COLOR_SPACE_YCBCR601 ||
2525 color_space == COLOR_SPACE_YCBCR601_LIMITED)
2526 hdmi_info.bits.C0_C1 = COLORIMETRY_ITU601;
2528 hdmi_info.bits.C0_C1 = COLORIMETRY_NO_DATA;
2530 if (color_space == COLOR_SPACE_2020_RGB_FULLRANGE ||
2531 color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE ||
2532 color_space == COLOR_SPACE_2020_YCBCR) {
2533 hdmi_info.bits.EC0_EC2 = COLORIMETRYEX_BT2020RGBYCBCR;
2534 hdmi_info.bits.C0_C1 = COLORIMETRY_EXTENDED;
2535 } else if (color_space == COLOR_SPACE_ADOBERGB) {
2536 hdmi_info.bits.EC0_EC2 = COLORIMETRYEX_ADOBERGB;
2537 hdmi_info.bits.C0_C1 = COLORIMETRY_EXTENDED;
2540 /* TODO: un-hardcode aspect ratio */
2541 aspect = stream->timing.aspect_ratio;
2544 case ASPECT_RATIO_4_3:
2545 case ASPECT_RATIO_16_9:
2546 hdmi_info.bits.M0_M1 = aspect;
2549 case ASPECT_RATIO_NO_DATA:
2550 case ASPECT_RATIO_64_27:
2551 case ASPECT_RATIO_256_135:
2553 hdmi_info.bits.M0_M1 = 0;
2556 /* Active Format Aspect ratio - same as Picture Aspect Ratio. */
2557 hdmi_info.bits.R0_R3 = ACTIVE_FORMAT_ASPECT_RATIO_SAME_AS_PICTURE;
2559 /* TODO: un-hardcode cn0_cn1 and itc */
2567 support = stream->content_support;
2570 if (!support.bits.valid_content_type) {
2573 if (cn0_cn1 == DISPLAY_CONTENT_TYPE_GRAPHICS) {
2574 if (support.bits.graphics_content == 1) {
2577 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_PHOTO) {
2578 if (support.bits.photo_content == 1) {
2584 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_CINEMA) {
2585 if (support.bits.cinema_content == 1) {
2591 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_GAME) {
2592 if (support.bits.game_content == 1) {
2600 hdmi_info.bits.CN0_CN1 = cn0_cn1_value;
2601 hdmi_info.bits.ITC = itc_value;
2604 if (stream->qs_bit == 1) {
2605 if (color_space == COLOR_SPACE_SRGB ||
2606 color_space == COLOR_SPACE_2020_RGB_FULLRANGE)
2607 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_FULL_RANGE;
2608 else if (color_space == COLOR_SPACE_SRGB_LIMITED ||
2609 color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE)
2610 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_LIMITED_RANGE;
2612 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_DEFAULT_RANGE;
2614 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_DEFAULT_RANGE;
2616 /* TODO : We should handle YCC quantization */
2617 /* but we do not have matrix calculation */
2618 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2621 if (pipe_ctx->stream->timing.hdmi_vic != 0)
2623 format = stream->timing.timing_3d_format;
2624 /*todo, add 3DStereo support*/
2625 if (format != TIMING_3D_FORMAT_NONE) {
2626 // Based on HDMI specs hdmi vic needs to be converted to cea vic when 3D is enabled
2627 switch (pipe_ctx->stream->timing.hdmi_vic) {
2644 /* If VIC >= 128, the Source shall use AVI InfoFrame Version 3*/
2645 hdmi_info.bits.VIC0_VIC7 = vic;
2647 hdmi_info.bits.header.version = 3;
2648 /* If (C1, C0)=(1, 1) and (EC2, EC1, EC0)=(1, 1, 1),
2649 * the Source shall use 20 AVI InfoFrame Version 4
2651 if (hdmi_info.bits.C0_C1 == COLORIMETRY_EXTENDED &&
2652 hdmi_info.bits.EC0_EC2 == COLORIMETRYEX_RESERVED) {
2653 hdmi_info.bits.header.version = 4;
2654 hdmi_info.bits.header.length = 14;
2658 * PR0 - PR3 start from 0 whereas pHwPathMode->mode.timing.flags.pixel
2659 * repetition start from 1 */
2660 hdmi_info.bits.PR0_PR3 = 0;
2663 * barTop: Line Number of End of Top Bar.
2664 * barBottom: Line Number of Start of Bottom Bar.
2665 * barLeft: Pixel Number of End of Left Bar.
2666 * barRight: Pixel Number of Start of Right Bar. */
2667 hdmi_info.bits.bar_top = stream->timing.v_border_top;
2668 hdmi_info.bits.bar_bottom = (stream->timing.v_total
2669 - stream->timing.v_border_bottom + 1);
2670 hdmi_info.bits.bar_left = stream->timing.h_border_left;
2671 hdmi_info.bits.bar_right = (stream->timing.h_total
2672 - stream->timing.h_border_right + 1);
2674 /* Additional Colorimetry Extension
2675 * Used in conduction with C0-C1 and EC0-EC2
2676 * 0 = DCI-P3 RGB (D65)
2677 * 1 = DCI-P3 RGB (theater)
2679 hdmi_info.bits.ACE0_ACE3 = 0;
2681 /* check_sum - Calculate AFMT_AVI_INFO0 ~ AFMT_AVI_INFO3 */
2682 check_sum = &hdmi_info.packet_raw_data.sb[0];
2684 *check_sum = HDMI_INFOFRAME_TYPE_AVI + hdmi_info.bits.header.length + hdmi_info.bits.header.version;
2686 for (byte_index = 1; byte_index <= hdmi_info.bits.header.length; byte_index++)
2687 *check_sum += hdmi_info.packet_raw_data.sb[byte_index];
2689 /* one byte complement */
2690 *check_sum = (uint8_t) (0x100 - *check_sum);
2692 /* Store in hw_path_mode */
2693 info_packet->hb0 = hdmi_info.packet_raw_data.hb0;
2694 info_packet->hb1 = hdmi_info.packet_raw_data.hb1;
2695 info_packet->hb2 = hdmi_info.packet_raw_data.hb2;
2697 for (byte_index = 0; byte_index < sizeof(hdmi_info.packet_raw_data.sb); byte_index++)
2698 info_packet->sb[byte_index] = hdmi_info.packet_raw_data.sb[byte_index];
2700 info_packet->valid = true;
2703 static void set_vendor_info_packet(
2704 struct dc_info_packet *info_packet,
2705 struct dc_stream_state *stream)
2707 /* SPD info packet for FreeSync */
2709 /* Check if Freesync is supported. Return if false. If true,
2710 * set the corresponding bit in the info packet
2712 if (!stream->vsp_infopacket.valid)
2715 *info_packet = stream->vsp_infopacket;
2718 static void set_spd_info_packet(
2719 struct dc_info_packet *info_packet,
2720 struct dc_stream_state *stream)
2722 /* SPD info packet for FreeSync */
2724 /* Check if Freesync is supported. Return if false. If true,
2725 * set the corresponding bit in the info packet
2727 if (!stream->vrr_infopacket.valid)
2730 *info_packet = stream->vrr_infopacket;
2733 static void set_hdr_static_info_packet(
2734 struct dc_info_packet *info_packet,
2735 struct dc_stream_state *stream)
2737 /* HDR Static Metadata info packet for HDR10 */
2739 if (!stream->hdr_static_metadata.valid ||
2740 stream->use_dynamic_meta)
2743 *info_packet = stream->hdr_static_metadata;
2746 static void set_vsc_info_packet(
2747 struct dc_info_packet *info_packet,
2748 struct dc_stream_state *stream)
2750 if (!stream->vsc_infopacket.valid)
2753 *info_packet = stream->vsc_infopacket;
2756 void dc_resource_state_destruct(struct dc_state *context)
2760 for (i = 0; i < context->stream_count; i++) {
2761 for (j = 0; j < context->stream_status[i].plane_count; j++)
2762 dc_plane_state_release(
2763 context->stream_status[i].plane_states[j]);
2765 context->stream_status[i].plane_count = 0;
2766 dc_stream_release(context->streams[i]);
2767 context->streams[i] = NULL;
2769 context->stream_count = 0;
2772 void dc_resource_state_copy_construct(
2773 const struct dc_state *src_ctx,
2774 struct dc_state *dst_ctx)
2777 struct kref refcount = dst_ctx->refcount;
2779 *dst_ctx = *src_ctx;
2781 for (i = 0; i < MAX_PIPES; i++) {
2782 struct pipe_ctx *cur_pipe = &dst_ctx->res_ctx.pipe_ctx[i];
2784 if (cur_pipe->top_pipe)
2785 cur_pipe->top_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
2787 if (cur_pipe->bottom_pipe)
2788 cur_pipe->bottom_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
2790 if (cur_pipe->next_odm_pipe)
2791 cur_pipe->next_odm_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
2793 if (cur_pipe->prev_odm_pipe)
2794 cur_pipe->prev_odm_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
2797 for (i = 0; i < dst_ctx->stream_count; i++) {
2798 dc_stream_retain(dst_ctx->streams[i]);
2799 for (j = 0; j < dst_ctx->stream_status[i].plane_count; j++)
2800 dc_plane_state_retain(
2801 dst_ctx->stream_status[i].plane_states[j]);
2804 /* context refcount should not be overridden */
2805 dst_ctx->refcount = refcount;
2809 struct clock_source *dc_resource_find_first_free_pll(
2810 struct resource_context *res_ctx,
2811 const struct resource_pool *pool)
2815 for (i = 0; i < pool->clk_src_count; ++i) {
2816 if (res_ctx->clock_source_ref_count[i] == 0)
2817 return pool->clock_sources[i];
2823 void resource_build_info_frame(struct pipe_ctx *pipe_ctx)
2825 enum signal_type signal = SIGNAL_TYPE_NONE;
2826 struct encoder_info_frame *info = &pipe_ctx->stream_res.encoder_info_frame;
2828 /* default all packets to invalid */
2829 info->avi.valid = false;
2830 info->gamut.valid = false;
2831 info->vendor.valid = false;
2832 info->spd.valid = false;
2833 info->hdrsmd.valid = false;
2834 info->vsc.valid = false;
2836 signal = pipe_ctx->stream->signal;
2838 /* HDMi and DP have different info packets*/
2839 if (dc_is_hdmi_signal(signal)) {
2840 set_avi_info_frame(&info->avi, pipe_ctx);
2842 set_vendor_info_packet(&info->vendor, pipe_ctx->stream);
2844 set_spd_info_packet(&info->spd, pipe_ctx->stream);
2846 set_hdr_static_info_packet(&info->hdrsmd, pipe_ctx->stream);
2848 } else if (dc_is_dp_signal(signal)) {
2849 set_vsc_info_packet(&info->vsc, pipe_ctx->stream);
2851 set_spd_info_packet(&info->spd, pipe_ctx->stream);
2853 set_hdr_static_info_packet(&info->hdrsmd, pipe_ctx->stream);
2856 patch_gamut_packet_checksum(&info->gamut);
2859 enum dc_status resource_map_clock_resources(
2860 const struct dc *dc,
2861 struct dc_state *context,
2862 struct dc_stream_state *stream)
2864 /* acquire new resources */
2865 const struct resource_pool *pool = dc->res_pool;
2866 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(
2867 &context->res_ctx, stream);
2870 return DC_ERROR_UNEXPECTED;
2872 if (dc_is_dp_signal(pipe_ctx->stream->signal)
2873 || pipe_ctx->stream->signal == SIGNAL_TYPE_VIRTUAL)
2874 pipe_ctx->clock_source = pool->dp_clock_source;
2876 pipe_ctx->clock_source = NULL;
2878 if (!dc->config.disable_disp_pll_sharing)
2879 pipe_ctx->clock_source = resource_find_used_clk_src_for_sharing(
2883 if (pipe_ctx->clock_source == NULL)
2884 pipe_ctx->clock_source =
2885 dc_resource_find_first_free_pll(
2890 if (pipe_ctx->clock_source == NULL)
2891 return DC_NO_CLOCK_SOURCE_RESOURCE;
2893 resource_reference_clock_source(
2894 &context->res_ctx, pool,
2895 pipe_ctx->clock_source);
2901 * Note: We need to disable output if clock sources change,
2902 * since bios does optimization and doesn't apply if changing
2903 * PHY when not already disabled.
2905 bool pipe_need_reprogram(
2906 struct pipe_ctx *pipe_ctx_old,
2907 struct pipe_ctx *pipe_ctx)
2909 if (!pipe_ctx_old->stream)
2912 if (pipe_ctx_old->stream->sink != pipe_ctx->stream->sink)
2915 if (pipe_ctx_old->stream->signal != pipe_ctx->stream->signal)
2918 if (pipe_ctx_old->stream_res.audio != pipe_ctx->stream_res.audio)
2921 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source
2922 && pipe_ctx_old->stream != pipe_ctx->stream)
2925 if (pipe_ctx_old->stream_res.stream_enc != pipe_ctx->stream_res.stream_enc)
2928 if (is_timing_changed(pipe_ctx_old->stream, pipe_ctx->stream))
2931 if (pipe_ctx_old->stream->dpms_off != pipe_ctx->stream->dpms_off)
2934 if (false == pipe_ctx_old->stream->link->link_state_valid &&
2935 false == pipe_ctx_old->stream->dpms_off)
2938 if (pipe_ctx_old->stream_res.dsc != pipe_ctx->stream_res.dsc)
2941 if (pipe_ctx_old->stream_res.hpo_dp_stream_enc != pipe_ctx->stream_res.hpo_dp_stream_enc)
2943 if (pipe_ctx_old->link_res.hpo_dp_link_enc != pipe_ctx->link_res.hpo_dp_link_enc)
2946 /* DIG link encoder resource assignment for stream changed. */
2947 if (pipe_ctx_old->stream->ctx->dc->res_pool->funcs->link_encs_assign) {
2948 bool need_reprogram = false;
2949 struct dc *dc = pipe_ctx_old->stream->ctx->dc;
2950 enum link_enc_cfg_mode mode = dc->current_state->res_ctx.link_enc_cfg_ctx.mode;
2952 dc->current_state->res_ctx.link_enc_cfg_ctx.mode = LINK_ENC_CFG_STEADY;
2953 if (link_enc_cfg_get_link_enc_used_by_stream(dc, pipe_ctx_old->stream) != pipe_ctx->stream->link_enc)
2954 need_reprogram = true;
2955 dc->current_state->res_ctx.link_enc_cfg_ctx.mode = mode;
2957 return need_reprogram;
2963 void resource_build_bit_depth_reduction_params(struct dc_stream_state *stream,
2964 struct bit_depth_reduction_params *fmt_bit_depth)
2966 enum dc_dither_option option = stream->dither_option;
2967 enum dc_pixel_encoding pixel_encoding =
2968 stream->timing.pixel_encoding;
2970 memset(fmt_bit_depth, 0, sizeof(*fmt_bit_depth));
2972 if (option == DITHER_OPTION_DEFAULT) {
2973 switch (stream->timing.display_color_depth) {
2974 case COLOR_DEPTH_666:
2975 option = DITHER_OPTION_SPATIAL6;
2977 case COLOR_DEPTH_888:
2978 option = DITHER_OPTION_SPATIAL8;
2980 case COLOR_DEPTH_101010:
2981 option = DITHER_OPTION_SPATIAL10;
2984 option = DITHER_OPTION_DISABLE;
2988 if (option == DITHER_OPTION_DISABLE)
2991 if (option == DITHER_OPTION_TRUN6) {
2992 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2993 fmt_bit_depth->flags.TRUNCATE_DEPTH = 0;
2994 } else if (option == DITHER_OPTION_TRUN8 ||
2995 option == DITHER_OPTION_TRUN8_SPATIAL6 ||
2996 option == DITHER_OPTION_TRUN8_FM6) {
2997 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2998 fmt_bit_depth->flags.TRUNCATE_DEPTH = 1;
2999 } else if (option == DITHER_OPTION_TRUN10 ||
3000 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
3001 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
3002 option == DITHER_OPTION_TRUN10_FM8 ||
3003 option == DITHER_OPTION_TRUN10_FM6 ||
3004 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
3005 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
3006 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
3009 /* special case - Formatter can only reduce by 4 bits at most.
3010 * When reducing from 12 to 6 bits,
3011 * HW recommends we use trunc with round mode
3012 * (if we did nothing, trunc to 10 bits would be used)
3013 * note that any 12->10 bit reduction is ignored prior to DCE8,
3014 * as the input was 10 bits.
3016 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
3017 option == DITHER_OPTION_SPATIAL6 ||
3018 option == DITHER_OPTION_FM6) {
3019 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
3020 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
3021 fmt_bit_depth->flags.TRUNCATE_MODE = 1;
3025 * note that spatial modes 1-3 are never used
3027 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
3028 option == DITHER_OPTION_SPATIAL6 ||
3029 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
3030 option == DITHER_OPTION_TRUN8_SPATIAL6) {
3031 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
3032 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 0;
3033 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
3034 fmt_bit_depth->flags.RGB_RANDOM =
3035 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
3036 } else if (option == DITHER_OPTION_SPATIAL8_FRAME_RANDOM ||
3037 option == DITHER_OPTION_SPATIAL8 ||
3038 option == DITHER_OPTION_SPATIAL8_FM6 ||
3039 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
3040 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
3041 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
3042 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 1;
3043 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
3044 fmt_bit_depth->flags.RGB_RANDOM =
3045 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
3046 } else if (option == DITHER_OPTION_SPATIAL10_FRAME_RANDOM ||
3047 option == DITHER_OPTION_SPATIAL10 ||
3048 option == DITHER_OPTION_SPATIAL10_FM8 ||
3049 option == DITHER_OPTION_SPATIAL10_FM6) {
3050 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
3051 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 2;
3052 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
3053 fmt_bit_depth->flags.RGB_RANDOM =
3054 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
3057 if (option == DITHER_OPTION_SPATIAL6 ||
3058 option == DITHER_OPTION_SPATIAL8 ||
3059 option == DITHER_OPTION_SPATIAL10) {
3060 fmt_bit_depth->flags.FRAME_RANDOM = 0;
3062 fmt_bit_depth->flags.FRAME_RANDOM = 1;
3065 //////////////////////
3066 //// temporal dither
3067 //////////////////////
3068 if (option == DITHER_OPTION_FM6 ||
3069 option == DITHER_OPTION_SPATIAL8_FM6 ||
3070 option == DITHER_OPTION_SPATIAL10_FM6 ||
3071 option == DITHER_OPTION_TRUN10_FM6 ||
3072 option == DITHER_OPTION_TRUN8_FM6 ||
3073 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
3074 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
3075 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 0;
3076 } else if (option == DITHER_OPTION_FM8 ||
3077 option == DITHER_OPTION_SPATIAL10_FM8 ||
3078 option == DITHER_OPTION_TRUN10_FM8) {
3079 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
3080 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 1;
3081 } else if (option == DITHER_OPTION_FM10) {
3082 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
3083 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 2;
3086 fmt_bit_depth->pixel_encoding = pixel_encoding;
3089 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream)
3091 struct dc_link *link = stream->link;
3092 struct timing_generator *tg = dc->res_pool->timing_generators[0];
3093 enum dc_status res = DC_OK;
3095 calculate_phy_pix_clks(stream);
3097 if (!tg->funcs->validate_timing(tg, &stream->timing))
3098 res = DC_FAIL_CONTROLLER_VALIDATE;
3101 if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
3102 !link->link_enc->funcs->validate_output_with_stream(
3103 link->link_enc, stream))
3104 res = DC_FAIL_ENC_VALIDATE;
3107 /* TODO: validate audio ASIC caps, encoder */
3110 res = dc_link_validate_mode_timing(stream,
3117 enum dc_status dc_validate_plane(struct dc *dc, const struct dc_plane_state *plane_state)
3119 enum dc_status res = DC_OK;
3121 /* check if surface has invalid dimensions */
3122 if (plane_state->src_rect.width == 0 || plane_state->src_rect.height == 0 ||
3123 plane_state->dst_rect.width == 0 || plane_state->dst_rect.height == 0)
3124 return DC_FAIL_SURFACE_VALIDATE;
3126 /* TODO For now validates pixel format only */
3127 if (dc->res_pool->funcs->validate_plane)
3128 return dc->res_pool->funcs->validate_plane(plane_state, &dc->caps);
3133 unsigned int resource_pixel_format_to_bpp(enum surface_pixel_format format)
3136 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
3138 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
3139 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
3141 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
3142 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
3143 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
3144 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
3146 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
3147 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
3148 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
3149 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
3150 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
3151 #if defined(CONFIG_DRM_AMD_DC_DCN)
3152 case SURFACE_PIXEL_FORMAT_GRPH_RGBE:
3153 case SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA:
3156 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
3157 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
3158 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
3159 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
3162 ASSERT_CRITICAL(false);
3166 static unsigned int get_max_audio_sample_rate(struct audio_mode *modes)
3169 if (modes->sample_rates.rate.RATE_192)
3171 if (modes->sample_rates.rate.RATE_176_4)
3173 if (modes->sample_rates.rate.RATE_96)
3175 if (modes->sample_rates.rate.RATE_88_2)
3177 if (modes->sample_rates.rate.RATE_48)
3179 if (modes->sample_rates.rate.RATE_44_1)
3181 if (modes->sample_rates.rate.RATE_32)
3184 /*original logic when no audio info*/
3188 void get_audio_check(struct audio_info *aud_modes,
3189 struct audio_check *audio_chk)
3192 unsigned int max_sample_rate = 0;
3195 audio_chk->audio_packet_type = 0x2;/*audio sample packet AP = .25 for layout0, 1 for layout1*/
3197 audio_chk->max_audiosample_rate = 0;
3198 for (i = 0; i < aud_modes->mode_count; i++) {
3199 max_sample_rate = get_max_audio_sample_rate(&aud_modes->modes[i]);
3200 if (audio_chk->max_audiosample_rate < max_sample_rate)
3201 audio_chk->max_audiosample_rate = max_sample_rate;
3202 /*dts takes the same as type 2: AP = 0.25*/
3204 /*check which one take more bandwidth*/
3205 if (audio_chk->max_audiosample_rate > 192000)
3206 audio_chk->audio_packet_type = 0x9;/*AP =1*/
3207 audio_chk->acat = 0;/*not support*/
3211 static struct hpo_dp_link_encoder *get_temp_hpo_dp_link_enc(
3212 const struct resource_context *res_ctx,
3213 const struct resource_pool *const pool,
3214 const struct dc_link *link)
3216 struct hpo_dp_link_encoder *hpo_dp_link_enc = NULL;
3219 enc_index = find_acquired_hpo_dp_link_enc_for_link(res_ctx, link);
3222 enc_index = find_free_hpo_dp_link_enc(res_ctx, pool);
3225 hpo_dp_link_enc = pool->hpo_dp_link_enc[enc_index];
3227 return hpo_dp_link_enc;
3230 bool get_temp_dp_link_res(struct dc_link *link,
3231 struct link_resource *link_res,
3232 struct dc_link_settings *link_settings)
3234 const struct dc *dc = link->dc;
3235 const struct resource_context *res_ctx = &dc->current_state->res_ctx;
3237 memset(link_res, 0, sizeof(*link_res));
3239 if (dp_get_link_encoding_format(link_settings) == DP_128b_132b_ENCODING) {
3240 link_res->hpo_dp_link_enc = get_temp_hpo_dp_link_enc(res_ctx,
3241 dc->res_pool, link);
3242 if (!link_res->hpo_dp_link_enc)
3248 void reset_syncd_pipes_from_disabled_pipes(struct dc *dc,
3249 struct dc_state *context)
3252 struct pipe_ctx *pipe_ctx_old, *pipe_ctx, *pipe_ctx_syncd;
3254 /* If pipe backend is reset, need to reset pipe syncd status */
3255 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3256 pipe_ctx_old = &dc->current_state->res_ctx.pipe_ctx[i];
3257 pipe_ctx = &context->res_ctx.pipe_ctx[i];
3259 if (!pipe_ctx_old->stream)
3262 if (pipe_ctx_old->top_pipe || pipe_ctx_old->prev_odm_pipe)
3265 if (!pipe_ctx->stream ||
3266 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
3268 /* Reset all the syncd pipes from the disabled pipe */
3269 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3270 pipe_ctx_syncd = &context->res_ctx.pipe_ctx[j];
3271 if ((GET_PIPE_SYNCD_FROM_PIPE(pipe_ctx_syncd) == pipe_ctx_old->pipe_idx) ||
3272 !IS_PIPE_SYNCD_VALID(pipe_ctx_syncd))
3273 SET_PIPE_SYNCD_TO_PIPE(pipe_ctx_syncd, j);
3279 void check_syncd_pipes_for_disabled_master_pipe(struct dc *dc,
3280 struct dc_state *context,
3281 uint8_t disabled_master_pipe_idx)
3284 struct pipe_ctx *pipe_ctx, *pipe_ctx_check;
3286 pipe_ctx = &context->res_ctx.pipe_ctx[disabled_master_pipe_idx];
3287 if ((GET_PIPE_SYNCD_FROM_PIPE(pipe_ctx) != disabled_master_pipe_idx) ||
3288 !IS_PIPE_SYNCD_VALID(pipe_ctx))
3289 SET_PIPE_SYNCD_TO_PIPE(pipe_ctx, disabled_master_pipe_idx);
3291 /* for the pipe disabled, check if any slave pipe exists and assert */
3292 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3293 pipe_ctx_check = &context->res_ctx.pipe_ctx[i];
3295 if ((GET_PIPE_SYNCD_FROM_PIPE(pipe_ctx_check) == disabled_master_pipe_idx) &&
3296 IS_PIPE_SYNCD_VALID(pipe_ctx_check) && (i != disabled_master_pipe_idx))
3297 DC_ERR("DC: Failure: pipe_idx[%d] syncd with disabled master pipe_idx[%d]\n",
3298 i, disabled_master_pipe_idx);
3302 uint8_t resource_transmitter_to_phy_idx(const struct dc *dc, enum transmitter transmitter)
3304 /* TODO - get transmitter to phy idx mapping from DMUB */
3305 uint8_t phy_idx = transmitter - TRANSMITTER_UNIPHY_A;
3307 #if defined(CONFIG_DRM_AMD_DC_DCN)
3308 if (dc->ctx->dce_version == DCN_VERSION_3_1 &&
3309 dc->ctx->asic_id.hw_internal_rev == YELLOW_CARP_B0) {
3310 switch (transmitter) {
3311 case TRANSMITTER_UNIPHY_A:
3314 case TRANSMITTER_UNIPHY_B:
3317 case TRANSMITTER_UNIPHY_C:
3320 case TRANSMITTER_UNIPHY_D:
3323 case TRANSMITTER_UNIPHY_E:
3335 const struct link_hwss *get_link_hwss(const struct dc_link *link,
3336 const struct link_resource *link_res)
3338 /* Link_hwss is only accessible by getter function instead of accessing
3339 * by pointers in dc with the intent to protect against breaking polymorphism.
3341 if (can_use_hpo_dp_link_hwss(link, link_res))
3342 /* TODO: some assumes that if decided link settings is 128b/132b
3343 * channel coding format hpo_dp_link_enc should be used.
3344 * Others believe that if hpo_dp_link_enc is available in link
3345 * resource then hpo_dp_link_enc must be used. This bound between
3346 * hpo_dp_link_enc != NULL and decided link settings is loosely coupled
3347 * with a premise that both hpo_dp_link_enc pointer and decided link
3348 * settings are determined based on single policy function like
3349 * "decide_link_settings" from upper layer. This "convention"
3350 * cannot be maintained and enforced at current level.
3351 * Therefore a refactor is due so we can enforce a strong bound
3352 * between those two parameters at this level.
3354 * To put it simple, we want to make enforcement at low level so that
3355 * we will not return link hwss if caller plans to do 8b/10b
3356 * with an hpo encoder. Or we can return a very dummy one that doesn't
3357 * do work for all functions
3359 return get_hpo_dp_link_hwss();
3360 else if (can_use_dpia_link_hwss(link, link_res))
3361 return get_dpia_link_hwss();
3362 else if (can_use_dio_link_hwss(link, link_res))
3363 return get_dio_link_hwss();
3365 return get_virtual_link_hwss();