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"
45 #if defined(CONFIG_DRM_AMD_DC_SI)
46 #include "dce60/dce60_resource.h"
48 #include "dce80/dce80_resource.h"
49 #include "dce100/dce100_resource.h"
50 #include "dce110/dce110_resource.h"
51 #include "dce112/dce112_resource.h"
52 #include "dce120/dce120_resource.h"
53 #if defined(CONFIG_DRM_AMD_DC_DCN)
54 #include "dcn10/dcn10_resource.h"
55 #include "dcn20/dcn20_resource.h"
56 #include "dcn21/dcn21_resource.h"
58 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
59 #include "../dcn30/dcn30_resource.h"
61 #if defined(CONFIG_DRM_AMD_DC_DCN3_01)
62 #include "../dcn301/dcn301_resource.h"
64 #if defined(CONFIG_DRM_AMD_DC_DCN3_02)
65 #include "../dcn302/dcn302_resource.h"
68 #define DC_LOGGER_INIT(logger)
70 enum dce_version resource_parse_asic_id(struct hw_asic_id asic_id)
72 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
73 switch (asic_id.chip_family) {
75 #if defined(CONFIG_DRM_AMD_DC_SI)
77 if (ASIC_REV_IS_TAHITI_P(asic_id.hw_internal_rev) ||
78 ASIC_REV_IS_PITCAIRN_PM(asic_id.hw_internal_rev) ||
79 ASIC_REV_IS_CAPEVERDE_M(asic_id.hw_internal_rev))
80 dc_version = DCE_VERSION_6_0;
81 else if (ASIC_REV_IS_OLAND_M(asic_id.hw_internal_rev))
82 dc_version = DCE_VERSION_6_4;
84 dc_version = DCE_VERSION_6_1;
88 dc_version = DCE_VERSION_8_0;
91 if (ASIC_REV_IS_KALINDI(asic_id.hw_internal_rev) ||
92 ASIC_REV_IS_BHAVANI(asic_id.hw_internal_rev) ||
93 ASIC_REV_IS_GODAVARI(asic_id.hw_internal_rev))
94 dc_version = DCE_VERSION_8_3;
96 dc_version = DCE_VERSION_8_1;
99 dc_version = DCE_VERSION_11_0;
103 if (ASIC_REV_IS_TONGA_P(asic_id.hw_internal_rev) ||
104 ASIC_REV_IS_FIJI_P(asic_id.hw_internal_rev)) {
105 dc_version = DCE_VERSION_10_0;
108 if (ASIC_REV_IS_POLARIS10_P(asic_id.hw_internal_rev) ||
109 ASIC_REV_IS_POLARIS11_M(asic_id.hw_internal_rev) ||
110 ASIC_REV_IS_POLARIS12_V(asic_id.hw_internal_rev)) {
111 dc_version = DCE_VERSION_11_2;
113 if (ASIC_REV_IS_VEGAM(asic_id.hw_internal_rev))
114 dc_version = DCE_VERSION_11_22;
117 if (ASICREV_IS_VEGA20_P(asic_id.hw_internal_rev))
118 dc_version = DCE_VERSION_12_1;
120 dc_version = DCE_VERSION_12_0;
122 #if defined(CONFIG_DRM_AMD_DC_DCN)
124 dc_version = DCN_VERSION_1_0;
125 if (ASICREV_IS_RAVEN2(asic_id.hw_internal_rev))
126 dc_version = DCN_VERSION_1_01;
127 if (ASICREV_IS_RENOIR(asic_id.hw_internal_rev))
128 dc_version = DCN_VERSION_2_1;
129 #if defined(CONFIG_DRM_AMD_DC_GREEN_SARDINE)
130 if (ASICREV_IS_GREEN_SARDINE(asic_id.hw_internal_rev))
131 dc_version = DCN_VERSION_2_1;
137 dc_version = DCN_VERSION_2_0;
138 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
139 if (ASICREV_IS_SIENNA_CICHLID_P(asic_id.hw_internal_rev))
140 dc_version = DCN_VERSION_3_0;
142 #if defined(CONFIG_DRM_AMD_DC_DCN3_02)
143 if (ASICREV_IS_DIMGREY_CAVEFISH_P(asic_id.hw_internal_rev))
144 dc_version = DCN_VERSION_3_02;
148 #if defined(CONFIG_DRM_AMD_DC_DCN3_01)
150 dc_version = DCN_VERSION_3_01;
154 dc_version = DCE_VERSION_UNKNOWN;
160 struct resource_pool *dc_create_resource_pool(struct dc *dc,
161 const struct dc_init_data *init_data,
162 enum dce_version dc_version)
164 struct resource_pool *res_pool = NULL;
166 switch (dc_version) {
167 #if defined(CONFIG_DRM_AMD_DC_SI)
168 case DCE_VERSION_6_0:
169 res_pool = dce60_create_resource_pool(
170 init_data->num_virtual_links, dc);
172 case DCE_VERSION_6_1:
173 res_pool = dce61_create_resource_pool(
174 init_data->num_virtual_links, dc);
176 case DCE_VERSION_6_4:
177 res_pool = dce64_create_resource_pool(
178 init_data->num_virtual_links, dc);
181 case DCE_VERSION_8_0:
182 res_pool = dce80_create_resource_pool(
183 init_data->num_virtual_links, dc);
185 case DCE_VERSION_8_1:
186 res_pool = dce81_create_resource_pool(
187 init_data->num_virtual_links, dc);
189 case DCE_VERSION_8_3:
190 res_pool = dce83_create_resource_pool(
191 init_data->num_virtual_links, dc);
193 case DCE_VERSION_10_0:
194 res_pool = dce100_create_resource_pool(
195 init_data->num_virtual_links, dc);
197 case DCE_VERSION_11_0:
198 res_pool = dce110_create_resource_pool(
199 init_data->num_virtual_links, dc,
202 case DCE_VERSION_11_2:
203 case DCE_VERSION_11_22:
204 res_pool = dce112_create_resource_pool(
205 init_data->num_virtual_links, dc);
207 case DCE_VERSION_12_0:
208 case DCE_VERSION_12_1:
209 res_pool = dce120_create_resource_pool(
210 init_data->num_virtual_links, dc);
213 #if defined(CONFIG_DRM_AMD_DC_DCN)
214 case DCN_VERSION_1_0:
215 case DCN_VERSION_1_01:
216 res_pool = dcn10_create_resource_pool(init_data, dc);
220 case DCN_VERSION_2_0:
221 res_pool = dcn20_create_resource_pool(init_data, dc);
223 case DCN_VERSION_2_1:
224 res_pool = dcn21_create_resource_pool(init_data, dc);
227 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
228 case DCN_VERSION_3_0:
229 res_pool = dcn30_create_resource_pool(init_data, dc);
233 #if defined(CONFIG_DRM_AMD_DC_DCN3_01)
234 case DCN_VERSION_3_01:
235 res_pool = dcn301_create_resource_pool(init_data, dc);
238 #if defined(CONFIG_DRM_AMD_DC_DCN3_02)
239 case DCN_VERSION_3_02:
240 res_pool = dcn302_create_resource_pool(init_data, dc);
248 if (res_pool != NULL) {
249 if (dc->ctx->dc_bios->fw_info_valid) {
250 res_pool->ref_clocks.xtalin_clock_inKhz =
251 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency;
252 /* initialize with firmware data first, no all
253 * ASIC have DCCG SW component. FPGA or
254 * simulation need initialization of
255 * dccg_ref_clock_inKhz, dchub_ref_clock_inKhz
256 * with xtalin_clock_inKhz
258 res_pool->ref_clocks.dccg_ref_clock_inKhz =
259 res_pool->ref_clocks.xtalin_clock_inKhz;
260 res_pool->ref_clocks.dchub_ref_clock_inKhz =
261 res_pool->ref_clocks.xtalin_clock_inKhz;
263 ASSERT_CRITICAL(false);
269 void dc_destroy_resource_pool(struct dc *dc)
273 dc->res_pool->funcs->destroy(&dc->res_pool);
279 static void update_num_audio(
280 const struct resource_straps *straps,
281 unsigned int *num_audio,
282 struct audio_support *aud_support)
284 aud_support->dp_audio = true;
285 aud_support->hdmi_audio_native = false;
286 aud_support->hdmi_audio_on_dongle = false;
288 if (straps->hdmi_disable == 0) {
289 if (straps->dc_pinstraps_audio & 0x2) {
290 aud_support->hdmi_audio_on_dongle = true;
291 aud_support->hdmi_audio_native = true;
295 switch (straps->audio_stream_number) {
296 case 0: /* multi streams supported */
298 case 1: /* multi streams not supported */
302 DC_ERR("DC: unexpected audio fuse!\n");
306 bool resource_construct(
307 unsigned int num_virtual_links,
309 struct resource_pool *pool,
310 const struct resource_create_funcs *create_funcs)
312 struct dc_context *ctx = dc->ctx;
313 const struct resource_caps *caps = pool->res_cap;
315 unsigned int num_audio = caps->num_audio;
316 struct resource_straps straps = {0};
318 if (create_funcs->read_dce_straps)
319 create_funcs->read_dce_straps(dc->ctx, &straps);
321 pool->audio_count = 0;
322 if (create_funcs->create_audio) {
323 /* find the total number of streams available via the
324 * AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT
325 * registers (one for each pin) starting from pin 1
326 * up to the max number of audio pins.
327 * We stop on the first pin where
328 * PORT_CONNECTIVITY == 1 (as instructed by HW team).
330 update_num_audio(&straps, &num_audio, &pool->audio_support);
331 for (i = 0; i < caps->num_audio; i++) {
332 struct audio *aud = create_funcs->create_audio(ctx, i);
335 DC_ERR("DC: failed to create audio!\n");
338 if (!aud->funcs->endpoint_valid(aud)) {
339 aud->funcs->destroy(&aud);
342 pool->audios[i] = aud;
347 pool->stream_enc_count = 0;
348 if (create_funcs->create_stream_encoder) {
349 for (i = 0; i < caps->num_stream_encoder; i++) {
350 pool->stream_enc[i] = create_funcs->create_stream_encoder(i, ctx);
351 if (pool->stream_enc[i] == NULL)
352 DC_ERR("DC: failed to create stream_encoder!\n");
353 pool->stream_enc_count++;
357 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
358 for (i = 0; i < caps->num_mpc_3dlut; i++) {
359 pool->mpc_lut[i] = dc_create_3dlut_func();
360 if (pool->mpc_lut[i] == NULL)
361 DC_ERR("DC: failed to create MPC 3dlut!\n");
362 pool->mpc_shaper[i] = dc_create_transfer_func();
363 if (pool->mpc_shaper[i] == NULL)
364 DC_ERR("DC: failed to create MPC shaper!\n");
367 dc->caps.dynamic_audio = false;
368 if (pool->audio_count < pool->stream_enc_count) {
369 dc->caps.dynamic_audio = true;
371 for (i = 0; i < num_virtual_links; i++) {
372 pool->stream_enc[pool->stream_enc_count] =
373 virtual_stream_encoder_create(
375 if (pool->stream_enc[pool->stream_enc_count] == NULL) {
376 DC_ERR("DC: failed to create stream_encoder!\n");
379 pool->stream_enc_count++;
382 dc->hwseq = create_funcs->create_hwseq(ctx);
386 static int find_matching_clock_source(
387 const struct resource_pool *pool,
388 struct clock_source *clock_source)
393 for (i = 0; i < pool->clk_src_count; i++) {
394 if (pool->clock_sources[i] == clock_source)
400 void resource_unreference_clock_source(
401 struct resource_context *res_ctx,
402 const struct resource_pool *pool,
403 struct clock_source *clock_source)
405 int i = find_matching_clock_source(pool, clock_source);
408 res_ctx->clock_source_ref_count[i]--;
410 if (pool->dp_clock_source == clock_source)
411 res_ctx->dp_clock_source_ref_count--;
414 void resource_reference_clock_source(
415 struct resource_context *res_ctx,
416 const struct resource_pool *pool,
417 struct clock_source *clock_source)
419 int i = find_matching_clock_source(pool, clock_source);
422 res_ctx->clock_source_ref_count[i]++;
424 if (pool->dp_clock_source == clock_source)
425 res_ctx->dp_clock_source_ref_count++;
428 int resource_get_clock_source_reference(
429 struct resource_context *res_ctx,
430 const struct resource_pool *pool,
431 struct clock_source *clock_source)
433 int i = find_matching_clock_source(pool, clock_source);
436 return res_ctx->clock_source_ref_count[i];
438 if (pool->dp_clock_source == clock_source)
439 return res_ctx->dp_clock_source_ref_count;
444 bool resource_are_streams_timing_synchronizable(
445 struct dc_stream_state *stream1,
446 struct dc_stream_state *stream2)
448 if (stream1->timing.h_total != stream2->timing.h_total)
451 if (stream1->timing.v_total != stream2->timing.v_total)
454 if (stream1->timing.h_addressable
455 != stream2->timing.h_addressable)
458 if (stream1->timing.v_addressable
459 != stream2->timing.v_addressable)
462 if (stream1->timing.v_front_porch
463 != stream2->timing.v_front_porch)
466 if (stream1->timing.pix_clk_100hz
467 != stream2->timing.pix_clk_100hz)
470 if (stream1->clamping.c_depth != stream2->clamping.c_depth)
473 if (stream1->phy_pix_clk != stream2->phy_pix_clk
474 && (!dc_is_dp_signal(stream1->signal)
475 || !dc_is_dp_signal(stream2->signal)))
478 if (stream1->view_format != stream2->view_format)
481 if (stream1->ignore_msa_timing_param || stream2->ignore_msa_timing_param)
486 static bool is_dp_and_hdmi_sharable(
487 struct dc_stream_state *stream1,
488 struct dc_stream_state *stream2)
490 if (stream1->ctx->dc->caps.disable_dp_clk_share)
493 if (stream1->clamping.c_depth != COLOR_DEPTH_888 ||
494 stream2->clamping.c_depth != COLOR_DEPTH_888)
501 static bool is_sharable_clk_src(
502 const struct pipe_ctx *pipe_with_clk_src,
503 const struct pipe_ctx *pipe)
505 if (pipe_with_clk_src->clock_source == NULL)
508 if (pipe_with_clk_src->stream->signal == SIGNAL_TYPE_VIRTUAL)
511 if (dc_is_dp_signal(pipe_with_clk_src->stream->signal) ||
512 (dc_is_dp_signal(pipe->stream->signal) &&
513 !is_dp_and_hdmi_sharable(pipe_with_clk_src->stream,
517 if (dc_is_hdmi_signal(pipe_with_clk_src->stream->signal)
518 && dc_is_dual_link_signal(pipe->stream->signal))
521 if (dc_is_hdmi_signal(pipe->stream->signal)
522 && dc_is_dual_link_signal(pipe_with_clk_src->stream->signal))
525 if (!resource_are_streams_timing_synchronizable(
526 pipe_with_clk_src->stream, pipe->stream))
532 struct clock_source *resource_find_used_clk_src_for_sharing(
533 struct resource_context *res_ctx,
534 struct pipe_ctx *pipe_ctx)
538 for (i = 0; i < MAX_PIPES; i++) {
539 if (is_sharable_clk_src(&res_ctx->pipe_ctx[i], pipe_ctx))
540 return res_ctx->pipe_ctx[i].clock_source;
546 static enum pixel_format convert_pixel_format_to_dalsurface(
547 enum surface_pixel_format surface_pixel_format)
549 enum pixel_format dal_pixel_format = PIXEL_FORMAT_UNKNOWN;
551 switch (surface_pixel_format) {
552 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
553 dal_pixel_format = PIXEL_FORMAT_INDEX8;
555 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
556 dal_pixel_format = PIXEL_FORMAT_RGB565;
558 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
559 dal_pixel_format = PIXEL_FORMAT_RGB565;
561 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
562 dal_pixel_format = PIXEL_FORMAT_ARGB8888;
564 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
565 dal_pixel_format = PIXEL_FORMAT_ARGB8888;
567 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
568 dal_pixel_format = PIXEL_FORMAT_ARGB2101010;
570 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
571 dal_pixel_format = PIXEL_FORMAT_ARGB2101010;
573 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
574 dal_pixel_format = PIXEL_FORMAT_ARGB2101010_XRBIAS;
576 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
577 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
578 dal_pixel_format = PIXEL_FORMAT_FP16;
580 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
581 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
582 dal_pixel_format = PIXEL_FORMAT_420BPP8;
584 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
585 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
586 dal_pixel_format = PIXEL_FORMAT_420BPP10;
588 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
590 dal_pixel_format = PIXEL_FORMAT_UNKNOWN;
593 return dal_pixel_format;
596 static inline void get_vp_scan_direction(
597 enum dc_rotation_angle rotation,
598 bool horizontal_mirror,
599 bool *orthogonal_rotation,
600 bool *flip_vert_scan_dir,
601 bool *flip_horz_scan_dir)
603 *orthogonal_rotation = false;
604 *flip_vert_scan_dir = false;
605 *flip_horz_scan_dir = false;
606 if (rotation == ROTATION_ANGLE_180) {
607 *flip_vert_scan_dir = true;
608 *flip_horz_scan_dir = true;
609 } else if (rotation == ROTATION_ANGLE_90) {
610 *orthogonal_rotation = true;
611 *flip_horz_scan_dir = true;
612 } else if (rotation == ROTATION_ANGLE_270) {
613 *orthogonal_rotation = true;
614 *flip_vert_scan_dir = true;
617 if (horizontal_mirror)
618 *flip_horz_scan_dir = !*flip_horz_scan_dir;
621 int get_num_mpc_splits(struct pipe_ctx *pipe)
623 int mpc_split_count = 0;
624 struct pipe_ctx *other_pipe = pipe->bottom_pipe;
626 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
628 other_pipe = other_pipe->bottom_pipe;
630 other_pipe = pipe->top_pipe;
631 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
633 other_pipe = other_pipe->top_pipe;
636 return mpc_split_count;
639 int get_num_odm_splits(struct pipe_ctx *pipe)
641 int odm_split_count = 0;
642 struct pipe_ctx *next_pipe = pipe->next_odm_pipe;
645 next_pipe = next_pipe->next_odm_pipe;
647 pipe = pipe->prev_odm_pipe;
650 pipe = pipe->prev_odm_pipe;
652 return odm_split_count;
655 static void calculate_split_count_and_index(struct pipe_ctx *pipe_ctx, int *split_count, int *split_idx)
657 *split_count = get_num_odm_splits(pipe_ctx);
659 if (*split_count == 0) {
660 /*Check for mpc split*/
661 struct pipe_ctx *split_pipe = pipe_ctx->top_pipe;
663 *split_count = get_num_mpc_splits(pipe_ctx);
664 while (split_pipe && split_pipe->plane_state == pipe_ctx->plane_state) {
666 split_pipe = split_pipe->top_pipe;
669 /*Get odm split index*/
670 struct pipe_ctx *split_pipe = pipe_ctx->prev_odm_pipe;
674 split_pipe = split_pipe->prev_odm_pipe;
679 static void calculate_viewport(struct pipe_ctx *pipe_ctx)
681 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
682 const struct dc_stream_state *stream = pipe_ctx->stream;
683 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
684 struct rect surf_src = plane_state->src_rect;
685 struct rect clip, dest;
686 int vpc_div = (data->format == PIXEL_FORMAT_420BPP8
687 || data->format == PIXEL_FORMAT_420BPP10) ? 2 : 1;
690 bool orthogonal_rotation, flip_y_start, flip_x_start;
692 calculate_split_count_and_index(pipe_ctx, &split_count, &split_idx);
694 if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE ||
695 stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM) {
700 /* The actual clip is an intersection between stream
701 * source and surface clip
703 dest = plane_state->dst_rect;
704 clip.x = stream->src.x > plane_state->clip_rect.x ?
705 stream->src.x : plane_state->clip_rect.x;
707 clip.width = stream->src.x + stream->src.width <
708 plane_state->clip_rect.x + plane_state->clip_rect.width ?
709 stream->src.x + stream->src.width - clip.x :
710 plane_state->clip_rect.x + plane_state->clip_rect.width - clip.x ;
712 clip.y = stream->src.y > plane_state->clip_rect.y ?
713 stream->src.y : plane_state->clip_rect.y;
715 clip.height = stream->src.y + stream->src.height <
716 plane_state->clip_rect.y + plane_state->clip_rect.height ?
717 stream->src.y + stream->src.height - clip.y :
718 plane_state->clip_rect.y + plane_state->clip_rect.height - clip.y ;
721 * Need to calculate how scan origin is shifted in vp space
722 * to correctly rotate clip and dst
724 get_vp_scan_direction(
725 plane_state->rotation,
726 plane_state->horizontal_mirror,
727 &orthogonal_rotation,
731 if (orthogonal_rotation) {
732 swap(clip.x, clip.y);
733 swap(clip.width, clip.height);
734 swap(dest.x, dest.y);
735 swap(dest.width, dest.height);
738 clip.x = dest.x + dest.width - clip.x - clip.width;
742 clip.y = dest.y + dest.height - clip.y - clip.height;
746 /* offset = surf_src.ofs + (clip.ofs - surface->dst_rect.ofs) * scl_ratio
747 * num_pixels = clip.num_pix * scl_ratio
749 data->viewport.x = surf_src.x + (clip.x - dest.x) * surf_src.width / dest.width;
750 data->viewport.width = clip.width * surf_src.width / dest.width;
752 data->viewport.y = surf_src.y + (clip.y - dest.y) * surf_src.height / dest.height;
753 data->viewport.height = clip.height * surf_src.height / dest.height;
757 /* extra pixels in the division remainder need to go to pipes after
758 * the extra pixel index minus one(epimo) defined here as:
762 if (orthogonal_rotation) {
764 split_idx = split_count - split_idx;
766 epimo = split_count - data->viewport.height % (split_count + 1);
768 data->viewport.y += (data->viewport.height / (split_count + 1)) * split_idx;
769 if (split_idx > epimo)
770 data->viewport.y += split_idx - epimo - 1;
771 data->viewport.height = data->viewport.height / (split_count + 1) + (split_idx > epimo ? 1 : 0);
774 split_idx = split_count - split_idx;
776 epimo = split_count - data->viewport.width % (split_count + 1);
778 data->viewport.x += (data->viewport.width / (split_count + 1)) * split_idx;
779 if (split_idx > epimo)
780 data->viewport.x += split_idx - epimo - 1;
781 data->viewport.width = data->viewport.width / (split_count + 1) + (split_idx > epimo ? 1 : 0);
785 /* Round down, compensate in init */
786 data->viewport_c.x = data->viewport.x / vpc_div;
787 data->viewport_c.y = data->viewport.y / vpc_div;
788 data->inits.h_c = (data->viewport.x % vpc_div) != 0 ? dc_fixpt_half : dc_fixpt_zero;
789 data->inits.v_c = (data->viewport.y % vpc_div) != 0 ? dc_fixpt_half : dc_fixpt_zero;
791 /* Round up, assume original video size always even dimensions */
792 data->viewport_c.width = (data->viewport.width + vpc_div - 1) / vpc_div;
793 data->viewport_c.height = (data->viewport.height + vpc_div - 1) / vpc_div;
795 data->viewport_unadjusted = data->viewport;
796 data->viewport_c_unadjusted = data->viewport_c;
799 static void calculate_recout(struct pipe_ctx *pipe_ctx)
801 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
802 const struct dc_stream_state *stream = pipe_ctx->stream;
803 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
804 struct rect surf_clip = plane_state->clip_rect;
805 bool pri_split_tb = pipe_ctx->bottom_pipe &&
806 pipe_ctx->bottom_pipe->plane_state == pipe_ctx->plane_state &&
807 stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM;
808 bool sec_split_tb = pipe_ctx->top_pipe &&
809 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state &&
810 stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM;
814 calculate_split_count_and_index(pipe_ctx, &split_count, &split_idx);
817 * Only the leftmost ODM pipe should be offset by a nonzero distance
819 if (!pipe_ctx->prev_odm_pipe) {
820 data->recout.x = stream->dst.x;
821 if (stream->src.x < surf_clip.x)
822 data->recout.x += (surf_clip.x - stream->src.x) * stream->dst.width
828 data->recout.width = surf_clip.width * stream->dst.width / stream->src.width;
829 if (data->recout.width + data->recout.x > stream->dst.x + stream->dst.width)
830 data->recout.width = stream->dst.x + stream->dst.width - data->recout.x;
832 data->recout.y = stream->dst.y;
833 if (stream->src.y < surf_clip.y)
834 data->recout.y += (surf_clip.y - stream->src.y) * stream->dst.height
835 / stream->src.height;
837 data->recout.height = surf_clip.height * stream->dst.height / stream->src.height;
838 if (data->recout.height + data->recout.y > stream->dst.y + stream->dst.height)
839 data->recout.height = stream->dst.y + stream->dst.height - data->recout.y;
841 /* Handle h & v split, handle rotation using viewport */
843 data->recout.y += data->recout.height / 2;
844 /* Floor primary pipe, ceil 2ndary pipe */
845 data->recout.height = (data->recout.height + 1) / 2;
846 } else if (pri_split_tb)
847 data->recout.height /= 2;
848 else if (split_count) {
849 /* extra pixels in the division remainder need to go to pipes after
850 * the extra pixel index minus one(epimo) defined here as:
852 int epimo = split_count - data->recout.width % (split_count + 1);
854 /*no recout offset due to odm */
855 if (!pipe_ctx->next_odm_pipe && !pipe_ctx->prev_odm_pipe) {
856 data->recout.x += (data->recout.width / (split_count + 1)) * split_idx;
857 if (split_idx > epimo)
858 data->recout.x += split_idx - epimo - 1;
860 data->recout.width = data->recout.width / (split_count + 1) + (split_idx > epimo ? 1 : 0);
864 static void calculate_scaling_ratios(struct pipe_ctx *pipe_ctx)
866 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
867 const struct dc_stream_state *stream = pipe_ctx->stream;
868 struct rect surf_src = plane_state->src_rect;
869 const int in_w = stream->src.width;
870 const int in_h = stream->src.height;
871 const int out_w = stream->dst.width;
872 const int out_h = stream->dst.height;
874 /*Swap surf_src height and width since scaling ratios are in recout rotation*/
875 if (pipe_ctx->plane_state->rotation == ROTATION_ANGLE_90 ||
876 pipe_ctx->plane_state->rotation == ROTATION_ANGLE_270)
877 swap(surf_src.height, surf_src.width);
879 pipe_ctx->plane_res.scl_data.ratios.horz = dc_fixpt_from_fraction(
881 plane_state->dst_rect.width);
882 pipe_ctx->plane_res.scl_data.ratios.vert = dc_fixpt_from_fraction(
884 plane_state->dst_rect.height);
886 if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE)
887 pipe_ctx->plane_res.scl_data.ratios.horz.value *= 2;
888 else if (stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM)
889 pipe_ctx->plane_res.scl_data.ratios.vert.value *= 2;
891 pipe_ctx->plane_res.scl_data.ratios.vert.value = div64_s64(
892 pipe_ctx->plane_res.scl_data.ratios.vert.value * in_h, out_h);
893 pipe_ctx->plane_res.scl_data.ratios.horz.value = div64_s64(
894 pipe_ctx->plane_res.scl_data.ratios.horz.value * in_w, out_w);
896 pipe_ctx->plane_res.scl_data.ratios.horz_c = pipe_ctx->plane_res.scl_data.ratios.horz;
897 pipe_ctx->plane_res.scl_data.ratios.vert_c = pipe_ctx->plane_res.scl_data.ratios.vert;
899 if (pipe_ctx->plane_res.scl_data.format == PIXEL_FORMAT_420BPP8
900 || pipe_ctx->plane_res.scl_data.format == PIXEL_FORMAT_420BPP10) {
901 pipe_ctx->plane_res.scl_data.ratios.horz_c.value /= 2;
902 pipe_ctx->plane_res.scl_data.ratios.vert_c.value /= 2;
904 pipe_ctx->plane_res.scl_data.ratios.horz = dc_fixpt_truncate(
905 pipe_ctx->plane_res.scl_data.ratios.horz, 19);
906 pipe_ctx->plane_res.scl_data.ratios.vert = dc_fixpt_truncate(
907 pipe_ctx->plane_res.scl_data.ratios.vert, 19);
908 pipe_ctx->plane_res.scl_data.ratios.horz_c = dc_fixpt_truncate(
909 pipe_ctx->plane_res.scl_data.ratios.horz_c, 19);
910 pipe_ctx->plane_res.scl_data.ratios.vert_c = dc_fixpt_truncate(
911 pipe_ctx->plane_res.scl_data.ratios.vert_c, 19);
914 static inline void adjust_vp_and_init_for_seamless_clip(
919 struct fixed31_32 ratio,
920 struct fixed31_32 *init,
924 if (!flip_scan_dir) {
925 /* Adjust for viewport end clip-off */
926 if ((*vp_offset + *vp_size) < src_size) {
927 int vp_clip = src_size - *vp_size - *vp_offset;
928 int int_part = dc_fixpt_floor(dc_fixpt_sub(*init, ratio));
930 int_part = int_part > 0 ? int_part : 0;
931 *vp_size += int_part < vp_clip ? int_part : vp_clip;
934 /* Adjust for non-0 viewport offset */
938 *init = dc_fixpt_add(*init, dc_fixpt_mul_int(ratio, recout_skip));
939 int_part = dc_fixpt_floor(*init) - *vp_offset;
940 if (int_part < taps) {
941 int int_adj = *vp_offset >= (taps - int_part) ?
942 (taps - int_part) : *vp_offset;
943 *vp_offset -= int_adj;
946 } else if (int_part > taps) {
947 *vp_offset += int_part - taps;
948 *vp_size -= int_part - taps;
951 init->value &= 0xffffffff;
952 *init = dc_fixpt_add_int(*init, int_part);
955 /* Adjust for non-0 viewport offset */
957 int int_part = dc_fixpt_floor(dc_fixpt_sub(*init, ratio));
959 int_part = int_part > 0 ? int_part : 0;
960 *vp_size += int_part < *vp_offset ? int_part : *vp_offset;
961 *vp_offset -= int_part < *vp_offset ? int_part : *vp_offset;
964 /* Adjust for viewport end clip-off */
965 if ((*vp_offset + *vp_size) < src_size) {
967 int end_offset = src_size - *vp_offset - *vp_size;
970 * this is init if vp had no offset, keep in mind this is from the
971 * right side of vp due to scan direction
973 *init = dc_fixpt_add(*init, dc_fixpt_mul_int(ratio, recout_skip));
975 * this is the difference between first pixel of viewport available to read
976 * and init position, takning into account scan direction
978 int_part = dc_fixpt_floor(*init) - end_offset;
979 if (int_part < taps) {
980 int int_adj = end_offset >= (taps - int_part) ?
981 (taps - int_part) : end_offset;
984 } else if (int_part > taps) {
985 *vp_size += int_part - taps;
988 init->value &= 0xffffffff;
989 *init = dc_fixpt_add_int(*init, int_part);
994 static void calculate_inits_and_adj_vp(struct pipe_ctx *pipe_ctx)
996 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
997 const struct dc_stream_state *stream = pipe_ctx->stream;
998 struct pipe_ctx *odm_pipe = pipe_ctx;
999 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
1000 struct rect src = pipe_ctx->plane_state->src_rect;
1001 int recout_skip_h, recout_skip_v, surf_size_h, surf_size_v;
1002 int vpc_div = (data->format == PIXEL_FORMAT_420BPP8
1003 || data->format == PIXEL_FORMAT_420BPP10) ? 2 : 1;
1004 bool orthogonal_rotation, flip_vert_scan_dir, flip_horz_scan_dir;
1008 * Need to calculate the scan direction for viewport to make adjustments
1010 get_vp_scan_direction(
1011 plane_state->rotation,
1012 plane_state->horizontal_mirror,
1013 &orthogonal_rotation,
1014 &flip_vert_scan_dir,
1015 &flip_horz_scan_dir);
1017 /* Calculate src rect rotation adjusted to recout space */
1018 surf_size_h = src.x + src.width;
1019 surf_size_v = src.y + src.height;
1020 if (flip_horz_scan_dir)
1022 if (flip_vert_scan_dir)
1024 if (orthogonal_rotation) {
1026 swap(src.width, src.height);
1029 /*modified recout_skip_h calculation due to odm having no recout offset*/
1030 while (odm_pipe->prev_odm_pipe) {
1032 odm_pipe = odm_pipe->prev_odm_pipe;
1034 /*odm_pipe is the leftmost pipe in the ODM group*/
1035 recout_skip_h = odm_idx * data->recout.width;
1037 /* Recout matching initial vp offset = recout_offset - (stream dst offset +
1038 * ((surf dst offset - stream src offset) * 1/ stream scaling ratio)
1039 * - (surf surf_src offset * 1/ full scl ratio))
1041 recout_skip_h += odm_pipe->plane_res.scl_data.recout.x
1042 - (stream->dst.x + (plane_state->dst_rect.x - stream->src.x)
1043 * stream->dst.width / stream->src.width -
1044 src.x * plane_state->dst_rect.width / src.width
1045 * stream->dst.width / stream->src.width);
1048 recout_skip_v = data->recout.y - (stream->dst.y + (plane_state->dst_rect.y - stream->src.y)
1049 * stream->dst.height / stream->src.height -
1050 src.y * plane_state->dst_rect.height / src.height
1051 * stream->dst.height / stream->src.height);
1052 if (orthogonal_rotation)
1053 swap(recout_skip_h, recout_skip_v);
1055 * Init calculated according to formula:
1056 * init = (scaling_ratio + number_of_taps + 1) / 2
1057 * init_bot = init + scaling_ratio
1058 * init_c = init + truncated_vp_c_offset(from calculate viewport)
1060 data->inits.h = dc_fixpt_truncate(dc_fixpt_div_int(
1061 dc_fixpt_add_int(data->ratios.horz, data->taps.h_taps + 1), 2), 19);
1063 data->inits.h_c = dc_fixpt_truncate(dc_fixpt_add(data->inits.h_c, dc_fixpt_div_int(
1064 dc_fixpt_add_int(data->ratios.horz_c, data->taps.h_taps_c + 1), 2)), 19);
1066 data->inits.v = dc_fixpt_truncate(dc_fixpt_div_int(
1067 dc_fixpt_add_int(data->ratios.vert, data->taps.v_taps + 1), 2), 19);
1069 data->inits.v_c = dc_fixpt_truncate(dc_fixpt_add(data->inits.v_c, dc_fixpt_div_int(
1070 dc_fixpt_add_int(data->ratios.vert_c, data->taps.v_taps_c + 1), 2)), 19);
1073 * Taps, inits and scaling ratios are in recout space need to rotate
1074 * to viewport rotation before adjustment
1076 adjust_vp_and_init_for_seamless_clip(
1080 orthogonal_rotation ? data->taps.v_taps : data->taps.h_taps,
1081 orthogonal_rotation ? data->ratios.vert : data->ratios.horz,
1082 orthogonal_rotation ? &data->inits.v : &data->inits.h,
1084 &data->viewport.width);
1085 adjust_vp_and_init_for_seamless_clip(
1088 surf_size_h / vpc_div,
1089 orthogonal_rotation ? data->taps.v_taps_c : data->taps.h_taps_c,
1090 orthogonal_rotation ? data->ratios.vert_c : data->ratios.horz_c,
1091 orthogonal_rotation ? &data->inits.v_c : &data->inits.h_c,
1092 &data->viewport_c.x,
1093 &data->viewport_c.width);
1094 adjust_vp_and_init_for_seamless_clip(
1098 orthogonal_rotation ? data->taps.h_taps : data->taps.v_taps,
1099 orthogonal_rotation ? data->ratios.horz : data->ratios.vert,
1100 orthogonal_rotation ? &data->inits.h : &data->inits.v,
1102 &data->viewport.height);
1103 adjust_vp_and_init_for_seamless_clip(
1106 surf_size_v / vpc_div,
1107 orthogonal_rotation ? data->taps.h_taps_c : data->taps.v_taps_c,
1108 orthogonal_rotation ? data->ratios.horz_c : data->ratios.vert_c,
1109 orthogonal_rotation ? &data->inits.h_c : &data->inits.v_c,
1110 &data->viewport_c.y,
1111 &data->viewport_c.height);
1113 /* Interlaced inits based on final vert inits */
1114 data->inits.v_bot = dc_fixpt_add(data->inits.v, data->ratios.vert);
1115 data->inits.v_c_bot = dc_fixpt_add(data->inits.v_c, data->ratios.vert_c);
1120 * When handling 270 rotation in mixed SLS mode, we have
1121 * stream->timing.h_border_left that is non zero. If we are doing
1122 * pipe-splitting, this h_border_left value gets added to recout.x and when it
1123 * calls calculate_inits_and_adj_vp() and
1124 * adjust_vp_and_init_for_seamless_clip(), it can cause viewport.height for a
1125 * pipe to be incorrect.
1127 * To fix this, instead of using stream->timing.h_border_left, we can use
1128 * stream->dst.x to represent the border instead. So we will set h_border_left
1129 * to 0 and shift the appropriate amount in stream->dst.x. We will then
1130 * perform all calculations in resource_build_scaling_params() based on this
1131 * and then restore the h_border_left and stream->dst.x to their original
1134 * shift_border_left_to_dst() will shift the amount of h_border_left to
1135 * stream->dst.x and set h_border_left to 0. restore_border_left_from_dst()
1136 * will restore h_border_left and stream->dst.x back to their original values
1137 * We also need to make sure pipe_ctx->plane_res.scl_data.h_active uses the
1138 * original h_border_left value in its calculation.
1140 int shift_border_left_to_dst(struct pipe_ctx *pipe_ctx)
1142 int store_h_border_left = pipe_ctx->stream->timing.h_border_left;
1144 if (store_h_border_left) {
1145 pipe_ctx->stream->timing.h_border_left = 0;
1146 pipe_ctx->stream->dst.x += store_h_border_left;
1148 return store_h_border_left;
1151 void restore_border_left_from_dst(struct pipe_ctx *pipe_ctx,
1152 int store_h_border_left)
1154 pipe_ctx->stream->dst.x -= store_h_border_left;
1155 pipe_ctx->stream->timing.h_border_left = store_h_border_left;
1158 bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx)
1160 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1161 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
1163 int store_h_border_left = shift_border_left_to_dst(pipe_ctx);
1164 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1165 /* Important: scaling ratio calculation requires pixel format,
1166 * lb depth calculation requires recout and taps require scaling ratios.
1167 * Inits require viewport, taps, ratios and recout of split pipe
1169 pipe_ctx->plane_res.scl_data.format = convert_pixel_format_to_dalsurface(
1170 pipe_ctx->plane_state->format);
1172 calculate_scaling_ratios(pipe_ctx);
1174 calculate_viewport(pipe_ctx);
1176 if (pipe_ctx->plane_res.scl_data.viewport.height < 12 ||
1177 pipe_ctx->plane_res.scl_data.viewport.width < 12) {
1178 if (store_h_border_left) {
1179 restore_border_left_from_dst(pipe_ctx,
1180 store_h_border_left);
1185 calculate_recout(pipe_ctx);
1188 * Setting line buffer pixel depth to 24bpp yields banding
1189 * on certain displays, such as the Sharp 4k
1191 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1192 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = plane_state->per_pixel_alpha;
1194 pipe_ctx->plane_res.scl_data.recout.x += timing->h_border_left;
1195 pipe_ctx->plane_res.scl_data.recout.y += timing->v_border_top;
1197 pipe_ctx->plane_res.scl_data.h_active = timing->h_addressable +
1198 store_h_border_left + timing->h_border_right;
1199 pipe_ctx->plane_res.scl_data.v_active = timing->v_addressable +
1200 timing->v_border_top + timing->v_border_bottom;
1201 if (pipe_ctx->next_odm_pipe || pipe_ctx->prev_odm_pipe)
1202 pipe_ctx->plane_res.scl_data.h_active /= get_num_odm_splits(pipe_ctx) + 1;
1204 /* Taps calculations */
1205 if (pipe_ctx->plane_res.xfm != NULL)
1206 res = pipe_ctx->plane_res.xfm->funcs->transform_get_optimal_number_of_taps(
1207 pipe_ctx->plane_res.xfm, &pipe_ctx->plane_res.scl_data, &plane_state->scaling_quality);
1209 if (pipe_ctx->plane_res.dpp != NULL)
1210 res = pipe_ctx->plane_res.dpp->funcs->dpp_get_optimal_number_of_taps(
1211 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data, &plane_state->scaling_quality);
1215 /* Try 24 bpp linebuffer */
1216 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_24BPP;
1218 if (pipe_ctx->plane_res.xfm != NULL)
1219 res = pipe_ctx->plane_res.xfm->funcs->transform_get_optimal_number_of_taps(
1220 pipe_ctx->plane_res.xfm,
1221 &pipe_ctx->plane_res.scl_data,
1222 &plane_state->scaling_quality);
1224 if (pipe_ctx->plane_res.dpp != NULL)
1225 res = pipe_ctx->plane_res.dpp->funcs->dpp_get_optimal_number_of_taps(
1226 pipe_ctx->plane_res.dpp,
1227 &pipe_ctx->plane_res.scl_data,
1228 &plane_state->scaling_quality);
1232 /* May need to re-check lb size after this in some obscure scenario */
1233 calculate_inits_and_adj_vp(pipe_ctx);
1235 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"
1236 "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",
1239 pipe_ctx->plane_res.scl_data.viewport.height,
1240 pipe_ctx->plane_res.scl_data.viewport.width,
1241 pipe_ctx->plane_res.scl_data.viewport.x,
1242 pipe_ctx->plane_res.scl_data.viewport.y,
1243 pipe_ctx->plane_res.scl_data.recout.height,
1244 pipe_ctx->plane_res.scl_data.recout.width,
1245 pipe_ctx->plane_res.scl_data.recout.x,
1246 pipe_ctx->plane_res.scl_data.recout.y,
1247 pipe_ctx->plane_res.scl_data.h_active,
1248 pipe_ctx->plane_res.scl_data.v_active,
1249 plane_state->src_rect.height,
1250 plane_state->src_rect.width,
1251 plane_state->src_rect.x,
1252 plane_state->src_rect.y,
1253 plane_state->dst_rect.height,
1254 plane_state->dst_rect.width,
1255 plane_state->dst_rect.x,
1256 plane_state->dst_rect.y,
1257 plane_state->clip_rect.height,
1258 plane_state->clip_rect.width,
1259 plane_state->clip_rect.x,
1260 plane_state->clip_rect.y);
1262 if (store_h_border_left)
1263 restore_border_left_from_dst(pipe_ctx, store_h_border_left);
1269 enum dc_status resource_build_scaling_params_for_context(
1270 const struct dc *dc,
1271 struct dc_state *context)
1275 for (i = 0; i < MAX_PIPES; i++) {
1276 if (context->res_ctx.pipe_ctx[i].plane_state != NULL &&
1277 context->res_ctx.pipe_ctx[i].stream != NULL)
1278 if (!resource_build_scaling_params(&context->res_ctx.pipe_ctx[i]))
1279 return DC_FAIL_SCALING;
1285 struct pipe_ctx *find_idle_secondary_pipe(
1286 struct resource_context *res_ctx,
1287 const struct resource_pool *pool,
1288 const struct pipe_ctx *primary_pipe)
1291 struct pipe_ctx *secondary_pipe = NULL;
1294 * We add a preferred pipe mapping to avoid the chance that
1295 * MPCCs already in use will need to be reassigned to other trees.
1296 * For example, if we went with the strict, assign backwards logic:
1299 * Display A on, no surface, top pipe = 0
1300 * Display B on, no surface, top pipe = 1
1303 * Display A on, no surface, top pipe = 0
1304 * Display B on, surface enable, top pipe = 1, bottom pipe = 5
1307 * Display A on, surface enable, top pipe = 0, bottom pipe = 5
1308 * Display B on, surface enable, top pipe = 1, bottom pipe = 4
1310 * The state 2->3 transition requires remapping MPCC 5 from display B
1313 * However, with the preferred pipe logic, state 2 would look like:
1316 * Display A on, no surface, top pipe = 0
1317 * Display B on, surface enable, top pipe = 1, bottom pipe = 4
1319 * This would then cause 2->3 to not require remapping any MPCCs.
1322 int preferred_pipe_idx = (pool->pipe_count - 1) - primary_pipe->pipe_idx;
1323 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1324 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1325 secondary_pipe->pipe_idx = preferred_pipe_idx;
1330 * search backwards for the second pipe to keep pipe
1331 * assignment more consistent
1333 if (!secondary_pipe)
1334 for (i = pool->pipe_count - 1; i >= 0; i--) {
1335 if (res_ctx->pipe_ctx[i].stream == NULL) {
1336 secondary_pipe = &res_ctx->pipe_ctx[i];
1337 secondary_pipe->pipe_idx = i;
1342 return secondary_pipe;
1345 struct pipe_ctx *resource_get_head_pipe_for_stream(
1346 struct resource_context *res_ctx,
1347 struct dc_stream_state *stream)
1351 for (i = 0; i < MAX_PIPES; i++) {
1352 if (res_ctx->pipe_ctx[i].stream == stream
1353 && !res_ctx->pipe_ctx[i].top_pipe
1354 && !res_ctx->pipe_ctx[i].prev_odm_pipe)
1355 return &res_ctx->pipe_ctx[i];
1360 static struct pipe_ctx *resource_get_tail_pipe(
1361 struct resource_context *res_ctx,
1362 struct pipe_ctx *head_pipe)
1364 struct pipe_ctx *tail_pipe;
1366 tail_pipe = head_pipe->bottom_pipe;
1369 head_pipe = tail_pipe;
1370 tail_pipe = tail_pipe->bottom_pipe;
1377 * A free_pipe for a stream is defined here as a pipe
1378 * that has no surface attached yet
1380 static struct pipe_ctx *acquire_free_pipe_for_head(
1381 struct dc_state *context,
1382 const struct resource_pool *pool,
1383 struct pipe_ctx *head_pipe)
1386 struct resource_context *res_ctx = &context->res_ctx;
1388 if (!head_pipe->plane_state)
1391 /* Re-use pipe already acquired for this stream if available*/
1392 for (i = pool->pipe_count - 1; i >= 0; i--) {
1393 if (res_ctx->pipe_ctx[i].stream == head_pipe->stream &&
1394 !res_ctx->pipe_ctx[i].plane_state) {
1395 return &res_ctx->pipe_ctx[i];
1400 * At this point we have no re-useable pipe for this stream and we need
1401 * to acquire an idle one to satisfy the request
1404 if (!pool->funcs->acquire_idle_pipe_for_layer)
1407 return pool->funcs->acquire_idle_pipe_for_layer(context, pool, head_pipe->stream);
1410 #if defined(CONFIG_DRM_AMD_DC_DCN)
1411 static int acquire_first_split_pipe(
1412 struct resource_context *res_ctx,
1413 const struct resource_pool *pool,
1414 struct dc_stream_state *stream)
1418 for (i = 0; i < pool->pipe_count; i++) {
1419 struct pipe_ctx *split_pipe = &res_ctx->pipe_ctx[i];
1421 if (split_pipe->top_pipe &&
1422 split_pipe->top_pipe->plane_state == split_pipe->plane_state) {
1423 split_pipe->top_pipe->bottom_pipe = split_pipe->bottom_pipe;
1424 if (split_pipe->bottom_pipe)
1425 split_pipe->bottom_pipe->top_pipe = split_pipe->top_pipe;
1427 if (split_pipe->top_pipe->plane_state)
1428 resource_build_scaling_params(split_pipe->top_pipe);
1430 memset(split_pipe, 0, sizeof(*split_pipe));
1431 split_pipe->stream_res.tg = pool->timing_generators[i];
1432 split_pipe->plane_res.hubp = pool->hubps[i];
1433 split_pipe->plane_res.ipp = pool->ipps[i];
1434 split_pipe->plane_res.dpp = pool->dpps[i];
1435 split_pipe->stream_res.opp = pool->opps[i];
1436 split_pipe->plane_res.mpcc_inst = pool->dpps[i]->inst;
1437 split_pipe->pipe_idx = i;
1439 split_pipe->stream = stream;
1447 bool dc_add_plane_to_context(
1448 const struct dc *dc,
1449 struct dc_stream_state *stream,
1450 struct dc_plane_state *plane_state,
1451 struct dc_state *context)
1454 struct resource_pool *pool = dc->res_pool;
1455 struct pipe_ctx *head_pipe, *tail_pipe, *free_pipe;
1456 struct dc_stream_status *stream_status = NULL;
1458 for (i = 0; i < context->stream_count; i++)
1459 if (context->streams[i] == stream) {
1460 stream_status = &context->stream_status[i];
1463 if (stream_status == NULL) {
1464 dm_error("Existing stream not found; failed to attach surface!\n");
1469 if (stream_status->plane_count == MAX_SURFACE_NUM) {
1470 dm_error("Surface: can not attach plane_state %p! Maximum is: %d\n",
1471 plane_state, MAX_SURFACE_NUM);
1475 head_pipe = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
1478 dm_error("Head pipe not found for stream_state %p !\n", stream);
1482 /* retain new surface, but only once per stream */
1483 dc_plane_state_retain(plane_state);
1486 free_pipe = acquire_free_pipe_for_head(context, pool, head_pipe);
1488 #if defined(CONFIG_DRM_AMD_DC_DCN)
1490 int pipe_idx = acquire_first_split_pipe(&context->res_ctx, pool, stream);
1492 free_pipe = &context->res_ctx.pipe_ctx[pipe_idx];
1496 dc_plane_state_release(plane_state);
1500 free_pipe->plane_state = plane_state;
1502 if (head_pipe != free_pipe) {
1503 tail_pipe = resource_get_tail_pipe(&context->res_ctx, head_pipe);
1505 free_pipe->stream_res.tg = tail_pipe->stream_res.tg;
1506 free_pipe->stream_res.abm = tail_pipe->stream_res.abm;
1507 free_pipe->stream_res.opp = tail_pipe->stream_res.opp;
1508 free_pipe->stream_res.stream_enc = tail_pipe->stream_res.stream_enc;
1509 free_pipe->stream_res.audio = tail_pipe->stream_res.audio;
1510 free_pipe->clock_source = tail_pipe->clock_source;
1511 free_pipe->top_pipe = tail_pipe;
1512 tail_pipe->bottom_pipe = free_pipe;
1513 if (!free_pipe->next_odm_pipe && tail_pipe->next_odm_pipe && tail_pipe->next_odm_pipe->bottom_pipe) {
1514 free_pipe->next_odm_pipe = tail_pipe->next_odm_pipe->bottom_pipe;
1515 tail_pipe->next_odm_pipe->bottom_pipe->prev_odm_pipe = free_pipe;
1517 if (!free_pipe->prev_odm_pipe && tail_pipe->prev_odm_pipe && tail_pipe->prev_odm_pipe->bottom_pipe) {
1518 free_pipe->prev_odm_pipe = tail_pipe->prev_odm_pipe->bottom_pipe;
1519 tail_pipe->prev_odm_pipe->bottom_pipe->next_odm_pipe = free_pipe;
1522 head_pipe = head_pipe->next_odm_pipe;
1524 /* assign new surfaces*/
1525 stream_status->plane_states[stream_status->plane_count] = plane_state;
1527 stream_status->plane_count++;
1532 bool dc_remove_plane_from_context(
1533 const struct dc *dc,
1534 struct dc_stream_state *stream,
1535 struct dc_plane_state *plane_state,
1536 struct dc_state *context)
1539 struct dc_stream_status *stream_status = NULL;
1540 struct resource_pool *pool = dc->res_pool;
1542 for (i = 0; i < context->stream_count; i++)
1543 if (context->streams[i] == stream) {
1544 stream_status = &context->stream_status[i];
1548 if (stream_status == NULL) {
1549 dm_error("Existing stream not found; failed to remove plane.\n");
1553 /* release pipe for plane*/
1554 for (i = pool->pipe_count - 1; i >= 0; i--) {
1555 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1557 if (pipe_ctx->plane_state == plane_state) {
1558 if (pipe_ctx->top_pipe)
1559 pipe_ctx->top_pipe->bottom_pipe = pipe_ctx->bottom_pipe;
1561 /* Second condition is to avoid setting NULL to top pipe
1562 * of tail pipe making it look like head pipe in subsequent
1565 if (pipe_ctx->bottom_pipe && pipe_ctx->top_pipe)
1566 pipe_ctx->bottom_pipe->top_pipe = pipe_ctx->top_pipe;
1569 * For head pipe detach surfaces from pipe for tail
1570 * pipe just zero it out
1572 if (!pipe_ctx->top_pipe)
1573 pipe_ctx->plane_state = NULL;
1575 memset(pipe_ctx, 0, sizeof(*pipe_ctx));
1580 for (i = 0; i < stream_status->plane_count; i++) {
1581 if (stream_status->plane_states[i] == plane_state) {
1583 dc_plane_state_release(stream_status->plane_states[i]);
1588 if (i == stream_status->plane_count) {
1589 dm_error("Existing plane_state not found; failed to detach it!\n");
1593 stream_status->plane_count--;
1595 /* Start at the plane we've just released, and move all the planes one index forward to "trim" the array */
1596 for (; i < stream_status->plane_count; i++)
1597 stream_status->plane_states[i] = stream_status->plane_states[i + 1];
1599 stream_status->plane_states[stream_status->plane_count] = NULL;
1604 bool dc_rem_all_planes_for_stream(
1605 const struct dc *dc,
1606 struct dc_stream_state *stream,
1607 struct dc_state *context)
1609 int i, old_plane_count;
1610 struct dc_stream_status *stream_status = NULL;
1611 struct dc_plane_state *del_planes[MAX_SURFACE_NUM] = { 0 };
1613 for (i = 0; i < context->stream_count; i++)
1614 if (context->streams[i] == stream) {
1615 stream_status = &context->stream_status[i];
1619 if (stream_status == NULL) {
1620 dm_error("Existing stream %p not found!\n", stream);
1624 old_plane_count = stream_status->plane_count;
1626 for (i = 0; i < old_plane_count; i++)
1627 del_planes[i] = stream_status->plane_states[i];
1629 for (i = 0; i < old_plane_count; i++)
1630 if (!dc_remove_plane_from_context(dc, stream, del_planes[i], context))
1636 static bool add_all_planes_for_stream(
1637 const struct dc *dc,
1638 struct dc_stream_state *stream,
1639 const struct dc_validation_set set[],
1641 struct dc_state *context)
1645 for (i = 0; i < set_count; i++)
1646 if (set[i].stream == stream)
1649 if (i == set_count) {
1650 dm_error("Stream %p not found in set!\n", stream);
1654 for (j = 0; j < set[i].plane_count; j++)
1655 if (!dc_add_plane_to_context(dc, stream, set[i].plane_states[j], context))
1661 bool dc_add_all_planes_for_stream(
1662 const struct dc *dc,
1663 struct dc_stream_state *stream,
1664 struct dc_plane_state * const *plane_states,
1666 struct dc_state *context)
1668 struct dc_validation_set set;
1671 set.stream = stream;
1672 set.plane_count = plane_count;
1674 for (i = 0; i < plane_count; i++)
1675 set.plane_states[i] = plane_states[i];
1677 return add_all_planes_for_stream(dc, stream, &set, 1, context);
1680 static bool is_timing_changed(struct dc_stream_state *cur_stream,
1681 struct dc_stream_state *new_stream)
1683 if (cur_stream == NULL)
1686 /* If sink pointer changed, it means this is a hotplug, we should do
1689 if (cur_stream->sink != new_stream->sink)
1692 /* If output color space is changed, need to reprogram info frames */
1693 if (cur_stream->output_color_space != new_stream->output_color_space)
1697 &cur_stream->timing,
1698 &new_stream->timing,
1699 sizeof(struct dc_crtc_timing)) != 0;
1702 static bool are_stream_backends_same(
1703 struct dc_stream_state *stream_a, struct dc_stream_state *stream_b)
1705 if (stream_a == stream_b)
1708 if (stream_a == NULL || stream_b == NULL)
1711 if (is_timing_changed(stream_a, stream_b))
1714 if (stream_a->dpms_off != stream_b->dpms_off)
1721 * dc_is_stream_unchanged() - Compare two stream states for equivalence.
1723 * Checks if there a difference between the two states
1724 * that would require a mode change.
1726 * Does not compare cursor position or attributes.
1728 bool dc_is_stream_unchanged(
1729 struct dc_stream_state *old_stream, struct dc_stream_state *stream)
1732 if (!are_stream_backends_same(old_stream, stream))
1735 if (old_stream->ignore_msa_timing_param != stream->ignore_msa_timing_param)
1742 * dc_is_stream_scaling_unchanged() - Compare scaling rectangles of two streams.
1744 bool dc_is_stream_scaling_unchanged(
1745 struct dc_stream_state *old_stream, struct dc_stream_state *stream)
1747 if (old_stream == stream)
1750 if (old_stream == NULL || stream == NULL)
1753 if (memcmp(&old_stream->src,
1755 sizeof(struct rect)) != 0)
1758 if (memcmp(&old_stream->dst,
1760 sizeof(struct rect)) != 0)
1766 static void update_stream_engine_usage(
1767 struct resource_context *res_ctx,
1768 const struct resource_pool *pool,
1769 struct stream_encoder *stream_enc,
1774 for (i = 0; i < pool->stream_enc_count; i++) {
1775 if (pool->stream_enc[i] == stream_enc)
1776 res_ctx->is_stream_enc_acquired[i] = acquired;
1780 /* TODO: release audio object */
1781 void update_audio_usage(
1782 struct resource_context *res_ctx,
1783 const struct resource_pool *pool,
1784 struct audio *audio,
1788 for (i = 0; i < pool->audio_count; i++) {
1789 if (pool->audios[i] == audio)
1790 res_ctx->is_audio_acquired[i] = acquired;
1794 static int acquire_first_free_pipe(
1795 struct resource_context *res_ctx,
1796 const struct resource_pool *pool,
1797 struct dc_stream_state *stream)
1801 for (i = 0; i < pool->pipe_count; i++) {
1802 if (!res_ctx->pipe_ctx[i].stream) {
1803 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
1805 pipe_ctx->stream_res.tg = pool->timing_generators[i];
1806 pipe_ctx->plane_res.mi = pool->mis[i];
1807 pipe_ctx->plane_res.hubp = pool->hubps[i];
1808 pipe_ctx->plane_res.ipp = pool->ipps[i];
1809 pipe_ctx->plane_res.xfm = pool->transforms[i];
1810 pipe_ctx->plane_res.dpp = pool->dpps[i];
1811 pipe_ctx->stream_res.opp = pool->opps[i];
1813 pipe_ctx->plane_res.mpcc_inst = pool->dpps[i]->inst;
1814 pipe_ctx->pipe_idx = i;
1817 pipe_ctx->stream = stream;
1824 static struct audio *find_first_free_audio(
1825 struct resource_context *res_ctx,
1826 const struct resource_pool *pool,
1828 enum dce_version dc_version)
1830 int i, available_audio_count;
1832 available_audio_count = pool->audio_count;
1834 for (i = 0; i < available_audio_count; i++) {
1835 if ((res_ctx->is_audio_acquired[i] == false) && (res_ctx->is_stream_enc_acquired[i] == true)) {
1836 /*we have enough audio endpoint, find the matching inst*/
1839 return pool->audios[i];
1843 /* use engine id to find free audio */
1844 if ((id < available_audio_count) && (res_ctx->is_audio_acquired[id] == false)) {
1845 return pool->audios[id];
1847 /*not found the matching one, first come first serve*/
1848 for (i = 0; i < available_audio_count; i++) {
1849 if (res_ctx->is_audio_acquired[i] == false) {
1850 return pool->audios[i];
1857 * dc_add_stream_to_ctx() - Add a new dc_stream_state to a dc_state.
1859 enum dc_status dc_add_stream_to_ctx(
1861 struct dc_state *new_ctx,
1862 struct dc_stream_state *stream)
1865 DC_LOGGER_INIT(dc->ctx->logger);
1867 if (new_ctx->stream_count >= dc->res_pool->timing_generator_count) {
1868 DC_LOG_WARNING("Max streams reached, can't add stream %p !\n", stream);
1869 return DC_ERROR_UNEXPECTED;
1872 new_ctx->streams[new_ctx->stream_count] = stream;
1873 dc_stream_retain(stream);
1874 new_ctx->stream_count++;
1876 res = dc->res_pool->funcs->add_stream_to_ctx(dc, new_ctx, stream);
1878 DC_LOG_WARNING("Adding stream %p to context failed with err %d!\n", stream, res);
1884 * dc_remove_stream_from_ctx() - Remove a stream from a dc_state.
1886 enum dc_status dc_remove_stream_from_ctx(
1888 struct dc_state *new_ctx,
1889 struct dc_stream_state *stream)
1892 struct dc_context *dc_ctx = dc->ctx;
1893 struct pipe_ctx *del_pipe = resource_get_head_pipe_for_stream(&new_ctx->res_ctx, stream);
1894 struct pipe_ctx *odm_pipe;
1897 DC_ERROR("Pipe not found for stream %p !\n", stream);
1898 return DC_ERROR_UNEXPECTED;
1901 odm_pipe = del_pipe->next_odm_pipe;
1903 /* Release primary pipe */
1904 ASSERT(del_pipe->stream_res.stream_enc);
1905 update_stream_engine_usage(
1908 del_pipe->stream_res.stream_enc,
1911 if (del_pipe->stream_res.audio)
1915 del_pipe->stream_res.audio,
1918 resource_unreference_clock_source(&new_ctx->res_ctx,
1920 del_pipe->clock_source);
1922 if (dc->res_pool->funcs->remove_stream_from_ctx)
1923 dc->res_pool->funcs->remove_stream_from_ctx(dc, new_ctx, stream);
1926 struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe;
1928 memset(odm_pipe, 0, sizeof(*odm_pipe));
1929 odm_pipe = next_odm_pipe;
1931 memset(del_pipe, 0, sizeof(*del_pipe));
1933 for (i = 0; i < new_ctx->stream_count; i++)
1934 if (new_ctx->streams[i] == stream)
1937 if (new_ctx->streams[i] != stream) {
1938 DC_ERROR("Context doesn't have stream %p !\n", stream);
1939 return DC_ERROR_UNEXPECTED;
1942 dc_stream_release(new_ctx->streams[i]);
1943 new_ctx->stream_count--;
1945 /* Trim back arrays */
1946 for (; i < new_ctx->stream_count; i++) {
1947 new_ctx->streams[i] = new_ctx->streams[i + 1];
1948 new_ctx->stream_status[i] = new_ctx->stream_status[i + 1];
1951 new_ctx->streams[new_ctx->stream_count] = NULL;
1953 &new_ctx->stream_status[new_ctx->stream_count],
1955 sizeof(new_ctx->stream_status[0]));
1960 static struct dc_stream_state *find_pll_sharable_stream(
1961 struct dc_stream_state *stream_needs_pll,
1962 struct dc_state *context)
1966 for (i = 0; i < context->stream_count; i++) {
1967 struct dc_stream_state *stream_has_pll = context->streams[i];
1969 /* We are looking for non dp, non virtual stream */
1970 if (resource_are_streams_timing_synchronizable(
1971 stream_needs_pll, stream_has_pll)
1972 && !dc_is_dp_signal(stream_has_pll->signal)
1973 && stream_has_pll->link->connector_signal
1974 != SIGNAL_TYPE_VIRTUAL)
1975 return stream_has_pll;
1982 static int get_norm_pix_clk(const struct dc_crtc_timing *timing)
1984 uint32_t pix_clk = timing->pix_clk_100hz;
1985 uint32_t normalized_pix_clk = pix_clk;
1987 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
1989 if (timing->pixel_encoding != PIXEL_ENCODING_YCBCR422) {
1990 switch (timing->display_color_depth) {
1991 case COLOR_DEPTH_666:
1992 case COLOR_DEPTH_888:
1993 normalized_pix_clk = pix_clk;
1995 case COLOR_DEPTH_101010:
1996 normalized_pix_clk = (pix_clk * 30) / 24;
1998 case COLOR_DEPTH_121212:
1999 normalized_pix_clk = (pix_clk * 36) / 24;
2001 case COLOR_DEPTH_161616:
2002 normalized_pix_clk = (pix_clk * 48) / 24;
2009 return normalized_pix_clk;
2012 static void calculate_phy_pix_clks(struct dc_stream_state *stream)
2014 /* update actual pixel clock on all streams */
2015 if (dc_is_hdmi_signal(stream->signal))
2016 stream->phy_pix_clk = get_norm_pix_clk(
2017 &stream->timing) / 10;
2019 stream->phy_pix_clk =
2020 stream->timing.pix_clk_100hz / 10;
2022 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
2023 stream->phy_pix_clk *= 2;
2026 static int acquire_resource_from_hw_enabled_state(
2027 struct resource_context *res_ctx,
2028 const struct resource_pool *pool,
2029 struct dc_stream_state *stream)
2031 struct dc_link *link = stream->link;
2032 unsigned int i, inst, tg_inst = 0;
2034 /* Check for enabled DIG to identify enabled display */
2035 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
2038 inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
2040 if (inst == ENGINE_ID_UNKNOWN)
2043 for (i = 0; i < pool->stream_enc_count; i++) {
2044 if (pool->stream_enc[i]->id == inst) {
2045 tg_inst = pool->stream_enc[i]->funcs->dig_source_otg(
2046 pool->stream_enc[i]);
2051 // tg_inst not found
2052 if (i == pool->stream_enc_count)
2055 if (tg_inst >= pool->timing_generator_count)
2058 if (!res_ctx->pipe_ctx[tg_inst].stream) {
2059 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[tg_inst];
2061 pipe_ctx->stream_res.tg = pool->timing_generators[tg_inst];
2062 pipe_ctx->plane_res.mi = pool->mis[tg_inst];
2063 pipe_ctx->plane_res.hubp = pool->hubps[tg_inst];
2064 pipe_ctx->plane_res.ipp = pool->ipps[tg_inst];
2065 pipe_ctx->plane_res.xfm = pool->transforms[tg_inst];
2066 pipe_ctx->plane_res.dpp = pool->dpps[tg_inst];
2067 pipe_ctx->stream_res.opp = pool->opps[tg_inst];
2069 if (pool->dpps[tg_inst]) {
2070 pipe_ctx->plane_res.mpcc_inst = pool->dpps[tg_inst]->inst;
2072 // Read DPP->MPCC->OPP Pipe from HW State
2073 if (pool->mpc->funcs->read_mpcc_state) {
2074 struct mpcc_state s = {0};
2076 pool->mpc->funcs->read_mpcc_state(pool->mpc, pipe_ctx->plane_res.mpcc_inst, &s);
2078 if (s.dpp_id < MAX_MPCC)
2079 pool->mpc->mpcc_array[pipe_ctx->plane_res.mpcc_inst].dpp_id = s.dpp_id;
2081 if (s.bot_mpcc_id < MAX_MPCC)
2082 pool->mpc->mpcc_array[pipe_ctx->plane_res.mpcc_inst].mpcc_bot =
2083 &pool->mpc->mpcc_array[s.bot_mpcc_id];
2085 if (s.opp_id < MAX_OPP)
2086 pipe_ctx->stream_res.opp->mpc_tree_params.opp_id = s.opp_id;
2089 pipe_ctx->pipe_idx = tg_inst;
2091 pipe_ctx->stream = stream;
2098 enum dc_status resource_map_pool_resources(
2099 const struct dc *dc,
2100 struct dc_state *context,
2101 struct dc_stream_state *stream)
2103 const struct resource_pool *pool = dc->res_pool;
2105 struct dc_context *dc_ctx = dc->ctx;
2106 struct pipe_ctx *pipe_ctx = NULL;
2108 struct dc_bios *dcb = dc->ctx->dc_bios;
2110 calculate_phy_pix_clks(stream);
2112 /* TODO: Check Linux */
2113 if (dc->config.allow_seamless_boot_optimization &&
2114 !dcb->funcs->is_accelerated_mode(dcb)) {
2115 if (dc_validate_seamless_boot_timing(dc, stream->sink, &stream->timing))
2116 stream->apply_seamless_boot_optimization = true;
2119 if (stream->apply_seamless_boot_optimization)
2120 pipe_idx = acquire_resource_from_hw_enabled_state(
2126 /* acquire new resources */
2127 pipe_idx = acquire_first_free_pipe(&context->res_ctx, pool, stream);
2129 #ifdef CONFIG_DRM_AMD_DC_DCN
2131 pipe_idx = acquire_first_split_pipe(&context->res_ctx, pool, stream);
2134 if (pipe_idx < 0 || context->res_ctx.pipe_ctx[pipe_idx].stream_res.tg == NULL)
2135 return DC_NO_CONTROLLER_RESOURCE;
2137 pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2139 pipe_ctx->stream_res.stream_enc =
2140 dc->res_pool->funcs->find_first_free_match_stream_enc_for_link(
2141 &context->res_ctx, pool, stream);
2143 if (!pipe_ctx->stream_res.stream_enc)
2144 return DC_NO_STREAM_ENC_RESOURCE;
2146 update_stream_engine_usage(
2147 &context->res_ctx, pool,
2148 pipe_ctx->stream_res.stream_enc,
2151 /* TODO: Add check if ASIC support and EDID audio */
2152 if (!stream->converter_disable_audio &&
2153 dc_is_audio_capable_signal(pipe_ctx->stream->signal) &&
2154 stream->audio_info.mode_count && stream->audio_info.flags.all) {
2155 pipe_ctx->stream_res.audio = find_first_free_audio(
2156 &context->res_ctx, pool, pipe_ctx->stream_res.stream_enc->id, dc_ctx->dce_version);
2159 * Audio assigned in order first come first get.
2160 * There are asics which has number of audio
2161 * resources less then number of pipes
2163 if (pipe_ctx->stream_res.audio)
2164 update_audio_usage(&context->res_ctx, pool,
2165 pipe_ctx->stream_res.audio, true);
2168 /* Add ABM to the resource if on EDP */
2169 if (pipe_ctx->stream && dc_is_embedded_signal(pipe_ctx->stream->signal)) {
2170 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2172 pipe_ctx->stream_res.abm = pool->abm;
2174 pipe_ctx->stream_res.abm = pool->multiple_abms[pipe_ctx->stream_res.tg->inst];
2176 pipe_ctx->stream_res.abm = pool->abm;
2180 for (i = 0; i < context->stream_count; i++)
2181 if (context->streams[i] == stream) {
2182 context->stream_status[i].primary_otg_inst = pipe_ctx->stream_res.tg->inst;
2183 context->stream_status[i].stream_enc_inst = pipe_ctx->stream_res.stream_enc->stream_enc_inst;
2184 context->stream_status[i].audio_inst =
2185 pipe_ctx->stream_res.audio ? pipe_ctx->stream_res.audio->inst : -1;
2190 DC_ERROR("Stream %p not found in new ctx!\n", stream);
2191 return DC_ERROR_UNEXPECTED;
2195 * dc_resource_state_copy_construct_current() - Creates a new dc_state from existing state
2196 * Is a shallow copy. Increments refcounts on existing streams and planes.
2197 * @dc: copy out of dc->current_state
2198 * @dst_ctx: copy into this
2200 void dc_resource_state_copy_construct_current(
2201 const struct dc *dc,
2202 struct dc_state *dst_ctx)
2204 dc_resource_state_copy_construct(dc->current_state, dst_ctx);
2208 void dc_resource_state_construct(
2209 const struct dc *dc,
2210 struct dc_state *dst_ctx)
2212 dst_ctx->clk_mgr = dc->clk_mgr;
2216 bool dc_resource_is_dsc_encoding_supported(const struct dc *dc)
2218 return dc->res_pool->res_cap->num_dsc > 0;
2223 * dc_validate_global_state() - Determine if HW can support a given state
2224 * Checks HW resource availability and bandwidth requirement.
2225 * @dc: dc struct for this driver
2226 * @new_ctx: state to be validated
2227 * @fast_validate: set to true if only yes/no to support matters
2229 * Return: DC_OK if the result can be programmed. Otherwise, an error code.
2231 enum dc_status dc_validate_global_state(
2233 struct dc_state *new_ctx,
2236 enum dc_status result = DC_ERROR_UNEXPECTED;
2240 return DC_ERROR_UNEXPECTED;
2242 if (dc->res_pool->funcs->validate_global) {
2243 result = dc->res_pool->funcs->validate_global(dc, new_ctx);
2244 if (result != DC_OK)
2248 for (i = 0; i < new_ctx->stream_count; i++) {
2249 struct dc_stream_state *stream = new_ctx->streams[i];
2251 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2252 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[j];
2254 if (pipe_ctx->stream != stream)
2257 if (dc->res_pool->funcs->patch_unknown_plane_state &&
2258 pipe_ctx->plane_state &&
2259 pipe_ctx->plane_state->tiling_info.gfx9.swizzle == DC_SW_UNKNOWN) {
2260 result = dc->res_pool->funcs->patch_unknown_plane_state(pipe_ctx->plane_state);
2261 if (result != DC_OK)
2265 /* Switch to dp clock source only if there is
2266 * no non dp stream that shares the same timing
2267 * with the dp stream.
2269 if (dc_is_dp_signal(pipe_ctx->stream->signal) &&
2270 !find_pll_sharable_stream(stream, new_ctx)) {
2272 resource_unreference_clock_source(
2275 pipe_ctx->clock_source);
2277 pipe_ctx->clock_source = dc->res_pool->dp_clock_source;
2278 resource_reference_clock_source(
2281 pipe_ctx->clock_source);
2286 result = resource_build_scaling_params_for_context(dc, new_ctx);
2288 if (result == DC_OK)
2289 if (!dc->res_pool->funcs->validate_bandwidth(dc, new_ctx, fast_validate))
2290 result = DC_FAIL_BANDWIDTH_VALIDATE;
2295 static void patch_gamut_packet_checksum(
2296 struct dc_info_packet *gamut_packet)
2298 /* For gamut we recalc checksum */
2299 if (gamut_packet->valid) {
2300 uint8_t chk_sum = 0;
2304 /*start of the Gamut data. */
2305 ptr = &gamut_packet->sb[3];
2307 for (i = 0; i <= gamut_packet->sb[1]; i++)
2310 gamut_packet->sb[2] = (uint8_t) (0x100 - chk_sum);
2314 static void set_avi_info_frame(
2315 struct dc_info_packet *info_packet,
2316 struct pipe_ctx *pipe_ctx)
2318 struct dc_stream_state *stream = pipe_ctx->stream;
2319 enum dc_color_space color_space = COLOR_SPACE_UNKNOWN;
2320 uint32_t pixel_encoding = 0;
2321 enum scanning_type scan_type = SCANNING_TYPE_NODATA;
2322 enum dc_aspect_ratio aspect = ASPECT_RATIO_NO_DATA;
2324 uint8_t itc_value = 0;
2325 uint8_t cn0_cn1 = 0;
2326 unsigned int cn0_cn1_value = 0;
2327 uint8_t *check_sum = NULL;
2328 uint8_t byte_index = 0;
2329 union hdmi_info_packet hdmi_info;
2330 union display_content_support support = {0};
2331 unsigned int vic = pipe_ctx->stream->timing.vic;
2332 enum dc_timing_3d_format format;
2334 memset(&hdmi_info, 0, sizeof(union hdmi_info_packet));
2336 color_space = pipe_ctx->stream->output_color_space;
2337 if (color_space == COLOR_SPACE_UNKNOWN)
2338 color_space = (stream->timing.pixel_encoding == PIXEL_ENCODING_RGB) ?
2339 COLOR_SPACE_SRGB:COLOR_SPACE_YCBCR709;
2341 /* Initialize header */
2342 hdmi_info.bits.header.info_frame_type = HDMI_INFOFRAME_TYPE_AVI;
2343 /* InfoFrameVersion_3 is defined by CEA861F (Section 6.4), but shall
2344 * not be used in HDMI 2.0 (Section 10.1) */
2345 hdmi_info.bits.header.version = 2;
2346 hdmi_info.bits.header.length = HDMI_AVI_INFOFRAME_SIZE;
2349 * IDO-defined (Y2,Y1,Y0 = 1,1,1) shall not be used by devices built
2350 * according to HDMI 2.0 spec (Section 10.1)
2353 switch (stream->timing.pixel_encoding) {
2354 case PIXEL_ENCODING_YCBCR422:
2358 case PIXEL_ENCODING_YCBCR444:
2361 case PIXEL_ENCODING_YCBCR420:
2365 case PIXEL_ENCODING_RGB:
2370 /* Y0_Y1_Y2 : The pixel encoding */
2371 /* H14b AVI InfoFrame has extension on Y-field from 2 bits to 3 bits */
2372 hdmi_info.bits.Y0_Y1_Y2 = pixel_encoding;
2374 /* A0 = 1 Active Format Information valid */
2375 hdmi_info.bits.A0 = ACTIVE_FORMAT_VALID;
2377 /* B0, B1 = 3; Bar info data is valid */
2378 hdmi_info.bits.B0_B1 = BAR_INFO_BOTH_VALID;
2380 hdmi_info.bits.SC0_SC1 = PICTURE_SCALING_UNIFORM;
2382 /* S0, S1 : Underscan / Overscan */
2383 /* TODO: un-hardcode scan type */
2384 scan_type = SCANNING_TYPE_UNDERSCAN;
2385 hdmi_info.bits.S0_S1 = scan_type;
2387 /* C0, C1 : Colorimetry */
2388 if (color_space == COLOR_SPACE_YCBCR709 ||
2389 color_space == COLOR_SPACE_YCBCR709_LIMITED)
2390 hdmi_info.bits.C0_C1 = COLORIMETRY_ITU709;
2391 else if (color_space == COLOR_SPACE_YCBCR601 ||
2392 color_space == COLOR_SPACE_YCBCR601_LIMITED)
2393 hdmi_info.bits.C0_C1 = COLORIMETRY_ITU601;
2395 hdmi_info.bits.C0_C1 = COLORIMETRY_NO_DATA;
2397 if (color_space == COLOR_SPACE_2020_RGB_FULLRANGE ||
2398 color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE ||
2399 color_space == COLOR_SPACE_2020_YCBCR) {
2400 hdmi_info.bits.EC0_EC2 = COLORIMETRYEX_BT2020RGBYCBCR;
2401 hdmi_info.bits.C0_C1 = COLORIMETRY_EXTENDED;
2402 } else if (color_space == COLOR_SPACE_ADOBERGB) {
2403 hdmi_info.bits.EC0_EC2 = COLORIMETRYEX_ADOBERGB;
2404 hdmi_info.bits.C0_C1 = COLORIMETRY_EXTENDED;
2407 /* TODO: un-hardcode aspect ratio */
2408 aspect = stream->timing.aspect_ratio;
2411 case ASPECT_RATIO_4_3:
2412 case ASPECT_RATIO_16_9:
2413 hdmi_info.bits.M0_M1 = aspect;
2416 case ASPECT_RATIO_NO_DATA:
2417 case ASPECT_RATIO_64_27:
2418 case ASPECT_RATIO_256_135:
2420 hdmi_info.bits.M0_M1 = 0;
2423 /* Active Format Aspect ratio - same as Picture Aspect Ratio. */
2424 hdmi_info.bits.R0_R3 = ACTIVE_FORMAT_ASPECT_RATIO_SAME_AS_PICTURE;
2426 /* TODO: un-hardcode cn0_cn1 and itc */
2434 support = stream->content_support;
2437 if (!support.bits.valid_content_type) {
2440 if (cn0_cn1 == DISPLAY_CONTENT_TYPE_GRAPHICS) {
2441 if (support.bits.graphics_content == 1) {
2444 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_PHOTO) {
2445 if (support.bits.photo_content == 1) {
2451 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_CINEMA) {
2452 if (support.bits.cinema_content == 1) {
2458 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_GAME) {
2459 if (support.bits.game_content == 1) {
2467 hdmi_info.bits.CN0_CN1 = cn0_cn1_value;
2468 hdmi_info.bits.ITC = itc_value;
2471 /* TODO : We should handle YCC quantization */
2472 /* but we do not have matrix calculation */
2473 if (stream->qs_bit == 1 &&
2474 stream->qy_bit == 1) {
2475 if (color_space == COLOR_SPACE_SRGB ||
2476 color_space == COLOR_SPACE_2020_RGB_FULLRANGE) {
2477 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_FULL_RANGE;
2478 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2479 } else if (color_space == COLOR_SPACE_SRGB_LIMITED ||
2480 color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE) {
2481 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_LIMITED_RANGE;
2482 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2484 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_DEFAULT_RANGE;
2485 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2488 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_DEFAULT_RANGE;
2489 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2493 format = stream->timing.timing_3d_format;
2494 /*todo, add 3DStereo support*/
2495 if (format != TIMING_3D_FORMAT_NONE) {
2496 // Based on HDMI specs hdmi vic needs to be converted to cea vic when 3D is enabled
2497 switch (pipe_ctx->stream->timing.hdmi_vic) {
2514 /* If VIC >= 128, the Source shall use AVI InfoFrame Version 3*/
2515 hdmi_info.bits.VIC0_VIC7 = vic;
2517 hdmi_info.bits.header.version = 3;
2518 /* If (C1, C0)=(1, 1) and (EC2, EC1, EC0)=(1, 1, 1),
2519 * the Source shall use 20 AVI InfoFrame Version 4
2521 if (hdmi_info.bits.C0_C1 == COLORIMETRY_EXTENDED &&
2522 hdmi_info.bits.EC0_EC2 == COLORIMETRYEX_RESERVED) {
2523 hdmi_info.bits.header.version = 4;
2524 hdmi_info.bits.header.length = 14;
2528 * PR0 - PR3 start from 0 whereas pHwPathMode->mode.timing.flags.pixel
2529 * repetition start from 1 */
2530 hdmi_info.bits.PR0_PR3 = 0;
2533 * barTop: Line Number of End of Top Bar.
2534 * barBottom: Line Number of Start of Bottom Bar.
2535 * barLeft: Pixel Number of End of Left Bar.
2536 * barRight: Pixel Number of Start of Right Bar. */
2537 hdmi_info.bits.bar_top = stream->timing.v_border_top;
2538 hdmi_info.bits.bar_bottom = (stream->timing.v_total
2539 - stream->timing.v_border_bottom + 1);
2540 hdmi_info.bits.bar_left = stream->timing.h_border_left;
2541 hdmi_info.bits.bar_right = (stream->timing.h_total
2542 - stream->timing.h_border_right + 1);
2544 /* Additional Colorimetry Extension
2545 * Used in conduction with C0-C1 and EC0-EC2
2546 * 0 = DCI-P3 RGB (D65)
2547 * 1 = DCI-P3 RGB (theater)
2549 hdmi_info.bits.ACE0_ACE3 = 0;
2551 /* check_sum - Calculate AFMT_AVI_INFO0 ~ AFMT_AVI_INFO3 */
2552 check_sum = &hdmi_info.packet_raw_data.sb[0];
2554 *check_sum = HDMI_INFOFRAME_TYPE_AVI + hdmi_info.bits.header.length + hdmi_info.bits.header.version;
2556 for (byte_index = 1; byte_index <= hdmi_info.bits.header.length; byte_index++)
2557 *check_sum += hdmi_info.packet_raw_data.sb[byte_index];
2559 /* one byte complement */
2560 *check_sum = (uint8_t) (0x100 - *check_sum);
2562 /* Store in hw_path_mode */
2563 info_packet->hb0 = hdmi_info.packet_raw_data.hb0;
2564 info_packet->hb1 = hdmi_info.packet_raw_data.hb1;
2565 info_packet->hb2 = hdmi_info.packet_raw_data.hb2;
2567 for (byte_index = 0; byte_index < sizeof(hdmi_info.packet_raw_data.sb); byte_index++)
2568 info_packet->sb[byte_index] = hdmi_info.packet_raw_data.sb[byte_index];
2570 info_packet->valid = true;
2573 static void set_vendor_info_packet(
2574 struct dc_info_packet *info_packet,
2575 struct dc_stream_state *stream)
2577 /* SPD info packet for FreeSync */
2579 /* Check if Freesync is supported. Return if false. If true,
2580 * set the corresponding bit in the info packet
2582 if (!stream->vsp_infopacket.valid)
2585 *info_packet = stream->vsp_infopacket;
2588 static void set_spd_info_packet(
2589 struct dc_info_packet *info_packet,
2590 struct dc_stream_state *stream)
2592 /* SPD info packet for FreeSync */
2594 /* Check if Freesync is supported. Return if false. If true,
2595 * set the corresponding bit in the info packet
2597 if (!stream->vrr_infopacket.valid)
2600 *info_packet = stream->vrr_infopacket;
2603 static void set_hdr_static_info_packet(
2604 struct dc_info_packet *info_packet,
2605 struct dc_stream_state *stream)
2607 /* HDR Static Metadata info packet for HDR10 */
2609 if (!stream->hdr_static_metadata.valid ||
2610 stream->use_dynamic_meta)
2613 *info_packet = stream->hdr_static_metadata;
2616 static void set_vsc_info_packet(
2617 struct dc_info_packet *info_packet,
2618 struct dc_stream_state *stream)
2620 if (!stream->vsc_infopacket.valid)
2623 *info_packet = stream->vsc_infopacket;
2626 void dc_resource_state_destruct(struct dc_state *context)
2630 for (i = 0; i < context->stream_count; i++) {
2631 for (j = 0; j < context->stream_status[i].plane_count; j++)
2632 dc_plane_state_release(
2633 context->stream_status[i].plane_states[j]);
2635 context->stream_status[i].plane_count = 0;
2636 dc_stream_release(context->streams[i]);
2637 context->streams[i] = NULL;
2641 void dc_resource_state_copy_construct(
2642 const struct dc_state *src_ctx,
2643 struct dc_state *dst_ctx)
2646 struct kref refcount = dst_ctx->refcount;
2648 *dst_ctx = *src_ctx;
2650 for (i = 0; i < MAX_PIPES; i++) {
2651 struct pipe_ctx *cur_pipe = &dst_ctx->res_ctx.pipe_ctx[i];
2653 if (cur_pipe->top_pipe)
2654 cur_pipe->top_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
2656 if (cur_pipe->bottom_pipe)
2657 cur_pipe->bottom_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
2659 if (cur_pipe->next_odm_pipe)
2660 cur_pipe->next_odm_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
2662 if (cur_pipe->prev_odm_pipe)
2663 cur_pipe->prev_odm_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
2666 for (i = 0; i < dst_ctx->stream_count; i++) {
2667 dc_stream_retain(dst_ctx->streams[i]);
2668 for (j = 0; j < dst_ctx->stream_status[i].plane_count; j++)
2669 dc_plane_state_retain(
2670 dst_ctx->stream_status[i].plane_states[j]);
2673 /* context refcount should not be overridden */
2674 dst_ctx->refcount = refcount;
2678 struct clock_source *dc_resource_find_first_free_pll(
2679 struct resource_context *res_ctx,
2680 const struct resource_pool *pool)
2684 for (i = 0; i < pool->clk_src_count; ++i) {
2685 if (res_ctx->clock_source_ref_count[i] == 0)
2686 return pool->clock_sources[i];
2692 void resource_build_info_frame(struct pipe_ctx *pipe_ctx)
2694 enum signal_type signal = SIGNAL_TYPE_NONE;
2695 struct encoder_info_frame *info = &pipe_ctx->stream_res.encoder_info_frame;
2697 /* default all packets to invalid */
2698 info->avi.valid = false;
2699 info->gamut.valid = false;
2700 info->vendor.valid = false;
2701 info->spd.valid = false;
2702 info->hdrsmd.valid = false;
2703 info->vsc.valid = false;
2705 signal = pipe_ctx->stream->signal;
2707 /* HDMi and DP have different info packets*/
2708 if (dc_is_hdmi_signal(signal)) {
2709 set_avi_info_frame(&info->avi, pipe_ctx);
2711 set_vendor_info_packet(&info->vendor, pipe_ctx->stream);
2713 set_spd_info_packet(&info->spd, pipe_ctx->stream);
2715 set_hdr_static_info_packet(&info->hdrsmd, pipe_ctx->stream);
2717 } else if (dc_is_dp_signal(signal)) {
2718 set_vsc_info_packet(&info->vsc, pipe_ctx->stream);
2720 set_spd_info_packet(&info->spd, pipe_ctx->stream);
2722 set_hdr_static_info_packet(&info->hdrsmd, pipe_ctx->stream);
2725 patch_gamut_packet_checksum(&info->gamut);
2728 enum dc_status resource_map_clock_resources(
2729 const struct dc *dc,
2730 struct dc_state *context,
2731 struct dc_stream_state *stream)
2733 /* acquire new resources */
2734 const struct resource_pool *pool = dc->res_pool;
2735 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(
2736 &context->res_ctx, stream);
2739 return DC_ERROR_UNEXPECTED;
2741 if (dc_is_dp_signal(pipe_ctx->stream->signal)
2742 || pipe_ctx->stream->signal == SIGNAL_TYPE_VIRTUAL)
2743 pipe_ctx->clock_source = pool->dp_clock_source;
2745 pipe_ctx->clock_source = NULL;
2747 if (!dc->config.disable_disp_pll_sharing)
2748 pipe_ctx->clock_source = resource_find_used_clk_src_for_sharing(
2752 if (pipe_ctx->clock_source == NULL)
2753 pipe_ctx->clock_source =
2754 dc_resource_find_first_free_pll(
2759 if (pipe_ctx->clock_source == NULL)
2760 return DC_NO_CLOCK_SOURCE_RESOURCE;
2762 resource_reference_clock_source(
2763 &context->res_ctx, pool,
2764 pipe_ctx->clock_source);
2770 * Note: We need to disable output if clock sources change,
2771 * since bios does optimization and doesn't apply if changing
2772 * PHY when not already disabled.
2774 bool pipe_need_reprogram(
2775 struct pipe_ctx *pipe_ctx_old,
2776 struct pipe_ctx *pipe_ctx)
2778 if (!pipe_ctx_old->stream)
2781 if (pipe_ctx_old->stream->sink != pipe_ctx->stream->sink)
2784 if (pipe_ctx_old->stream->signal != pipe_ctx->stream->signal)
2787 if (pipe_ctx_old->stream_res.audio != pipe_ctx->stream_res.audio)
2790 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source
2791 && pipe_ctx_old->stream != pipe_ctx->stream)
2794 if (pipe_ctx_old->stream_res.stream_enc != pipe_ctx->stream_res.stream_enc)
2797 if (is_timing_changed(pipe_ctx_old->stream, pipe_ctx->stream))
2800 if (pipe_ctx_old->stream->dpms_off != pipe_ctx->stream->dpms_off)
2803 if (false == pipe_ctx_old->stream->link->link_state_valid &&
2804 false == pipe_ctx_old->stream->dpms_off)
2807 if (pipe_ctx_old->stream_res.dsc != pipe_ctx->stream_res.dsc)
2813 void resource_build_bit_depth_reduction_params(struct dc_stream_state *stream,
2814 struct bit_depth_reduction_params *fmt_bit_depth)
2816 enum dc_dither_option option = stream->dither_option;
2817 enum dc_pixel_encoding pixel_encoding =
2818 stream->timing.pixel_encoding;
2820 memset(fmt_bit_depth, 0, sizeof(*fmt_bit_depth));
2822 if (option == DITHER_OPTION_DEFAULT) {
2823 switch (stream->timing.display_color_depth) {
2824 case COLOR_DEPTH_666:
2825 option = DITHER_OPTION_SPATIAL6;
2827 case COLOR_DEPTH_888:
2828 option = DITHER_OPTION_SPATIAL8;
2830 case COLOR_DEPTH_101010:
2831 option = DITHER_OPTION_SPATIAL10;
2834 option = DITHER_OPTION_DISABLE;
2838 if (option == DITHER_OPTION_DISABLE)
2841 if (option == DITHER_OPTION_TRUN6) {
2842 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2843 fmt_bit_depth->flags.TRUNCATE_DEPTH = 0;
2844 } else if (option == DITHER_OPTION_TRUN8 ||
2845 option == DITHER_OPTION_TRUN8_SPATIAL6 ||
2846 option == DITHER_OPTION_TRUN8_FM6) {
2847 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2848 fmt_bit_depth->flags.TRUNCATE_DEPTH = 1;
2849 } else if (option == DITHER_OPTION_TRUN10 ||
2850 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
2851 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
2852 option == DITHER_OPTION_TRUN10_FM8 ||
2853 option == DITHER_OPTION_TRUN10_FM6 ||
2854 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
2855 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2856 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
2859 /* special case - Formatter can only reduce by 4 bits at most.
2860 * When reducing from 12 to 6 bits,
2861 * HW recommends we use trunc with round mode
2862 * (if we did nothing, trunc to 10 bits would be used)
2863 * note that any 12->10 bit reduction is ignored prior to DCE8,
2864 * as the input was 10 bits.
2866 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
2867 option == DITHER_OPTION_SPATIAL6 ||
2868 option == DITHER_OPTION_FM6) {
2869 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2870 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
2871 fmt_bit_depth->flags.TRUNCATE_MODE = 1;
2875 * note that spatial modes 1-3 are never used
2877 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
2878 option == DITHER_OPTION_SPATIAL6 ||
2879 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
2880 option == DITHER_OPTION_TRUN8_SPATIAL6) {
2881 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
2882 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 0;
2883 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
2884 fmt_bit_depth->flags.RGB_RANDOM =
2885 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
2886 } else if (option == DITHER_OPTION_SPATIAL8_FRAME_RANDOM ||
2887 option == DITHER_OPTION_SPATIAL8 ||
2888 option == DITHER_OPTION_SPATIAL8_FM6 ||
2889 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
2890 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
2891 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
2892 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 1;
2893 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
2894 fmt_bit_depth->flags.RGB_RANDOM =
2895 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
2896 } else if (option == DITHER_OPTION_SPATIAL10_FRAME_RANDOM ||
2897 option == DITHER_OPTION_SPATIAL10 ||
2898 option == DITHER_OPTION_SPATIAL10_FM8 ||
2899 option == DITHER_OPTION_SPATIAL10_FM6) {
2900 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
2901 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 2;
2902 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
2903 fmt_bit_depth->flags.RGB_RANDOM =
2904 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
2907 if (option == DITHER_OPTION_SPATIAL6 ||
2908 option == DITHER_OPTION_SPATIAL8 ||
2909 option == DITHER_OPTION_SPATIAL10) {
2910 fmt_bit_depth->flags.FRAME_RANDOM = 0;
2912 fmt_bit_depth->flags.FRAME_RANDOM = 1;
2915 //////////////////////
2916 //// temporal dither
2917 //////////////////////
2918 if (option == DITHER_OPTION_FM6 ||
2919 option == DITHER_OPTION_SPATIAL8_FM6 ||
2920 option == DITHER_OPTION_SPATIAL10_FM6 ||
2921 option == DITHER_OPTION_TRUN10_FM6 ||
2922 option == DITHER_OPTION_TRUN8_FM6 ||
2923 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
2924 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
2925 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 0;
2926 } else if (option == DITHER_OPTION_FM8 ||
2927 option == DITHER_OPTION_SPATIAL10_FM8 ||
2928 option == DITHER_OPTION_TRUN10_FM8) {
2929 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
2930 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 1;
2931 } else if (option == DITHER_OPTION_FM10) {
2932 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
2933 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 2;
2936 fmt_bit_depth->pixel_encoding = pixel_encoding;
2939 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream)
2941 struct dc_link *link = stream->link;
2942 struct timing_generator *tg = dc->res_pool->timing_generators[0];
2943 enum dc_status res = DC_OK;
2945 calculate_phy_pix_clks(stream);
2947 if (!tg->funcs->validate_timing(tg, &stream->timing))
2948 res = DC_FAIL_CONTROLLER_VALIDATE;
2951 if (!link->link_enc->funcs->validate_output_with_stream(
2952 link->link_enc, stream))
2953 res = DC_FAIL_ENC_VALIDATE;
2956 /* TODO: validate audio ASIC caps, encoder */
2959 res = dc_link_validate_mode_timing(stream,
2966 enum dc_status dc_validate_plane(struct dc *dc, const struct dc_plane_state *plane_state)
2968 enum dc_status res = DC_OK;
2970 /* TODO For now validates pixel format only */
2971 if (dc->res_pool->funcs->validate_plane)
2972 return dc->res_pool->funcs->validate_plane(plane_state, &dc->caps);
2977 unsigned int resource_pixel_format_to_bpp(enum surface_pixel_format format)
2980 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
2982 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
2983 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
2985 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
2986 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
2987 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
2988 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
2990 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
2991 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
2992 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
2993 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
2994 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
2995 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2996 case SURFACE_PIXEL_FORMAT_GRPH_RGBE:
2997 case SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA:
3000 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
3001 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
3002 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
3005 ASSERT_CRITICAL(false);
3009 static unsigned int get_max_audio_sample_rate(struct audio_mode *modes)
3012 if (modes->sample_rates.rate.RATE_192)
3014 if (modes->sample_rates.rate.RATE_176_4)
3016 if (modes->sample_rates.rate.RATE_96)
3018 if (modes->sample_rates.rate.RATE_88_2)
3020 if (modes->sample_rates.rate.RATE_48)
3022 if (modes->sample_rates.rate.RATE_44_1)
3024 if (modes->sample_rates.rate.RATE_32)
3027 /*original logic when no audio info*/
3031 void get_audio_check(struct audio_info *aud_modes,
3032 struct audio_check *audio_chk)
3035 unsigned int max_sample_rate = 0;
3038 audio_chk->audio_packet_type = 0x2;/*audio sample packet AP = .25 for layout0, 1 for layout1*/
3040 audio_chk->max_audiosample_rate = 0;
3041 for (i = 0; i < aud_modes->mode_count; i++) {
3042 max_sample_rate = get_max_audio_sample_rate(&aud_modes->modes[i]);
3043 if (audio_chk->max_audiosample_rate < max_sample_rate)
3044 audio_chk->max_audiosample_rate = max_sample_rate;
3045 /*dts takes the same as type 2: AP = 0.25*/
3047 /*check which one take more bandwidth*/
3048 if (audio_chk->max_audiosample_rate > 192000)
3049 audio_chk->audio_packet_type = 0x9;/*AP =1*/
3050 audio_chk->acat = 0;/*not support*/