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"
62 #define DC_LOGGER_INIT(logger)
64 enum dce_version resource_parse_asic_id(struct hw_asic_id asic_id)
66 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
67 switch (asic_id.chip_family) {
69 #if defined(CONFIG_DRM_AMD_DC_SI)
71 if (ASIC_REV_IS_TAHITI_P(asic_id.hw_internal_rev) ||
72 ASIC_REV_IS_PITCAIRN_PM(asic_id.hw_internal_rev) ||
73 ASIC_REV_IS_CAPEVERDE_M(asic_id.hw_internal_rev))
74 dc_version = DCE_VERSION_6_0;
75 else if (ASIC_REV_IS_OLAND_M(asic_id.hw_internal_rev))
76 dc_version = DCE_VERSION_6_4;
78 dc_version = DCE_VERSION_6_1;
82 dc_version = DCE_VERSION_8_0;
85 if (ASIC_REV_IS_KALINDI(asic_id.hw_internal_rev) ||
86 ASIC_REV_IS_BHAVANI(asic_id.hw_internal_rev) ||
87 ASIC_REV_IS_GODAVARI(asic_id.hw_internal_rev))
88 dc_version = DCE_VERSION_8_3;
90 dc_version = DCE_VERSION_8_1;
93 dc_version = DCE_VERSION_11_0;
97 if (ASIC_REV_IS_TONGA_P(asic_id.hw_internal_rev) ||
98 ASIC_REV_IS_FIJI_P(asic_id.hw_internal_rev)) {
99 dc_version = DCE_VERSION_10_0;
102 if (ASIC_REV_IS_POLARIS10_P(asic_id.hw_internal_rev) ||
103 ASIC_REV_IS_POLARIS11_M(asic_id.hw_internal_rev) ||
104 ASIC_REV_IS_POLARIS12_V(asic_id.hw_internal_rev)) {
105 dc_version = DCE_VERSION_11_2;
107 if (ASIC_REV_IS_VEGAM(asic_id.hw_internal_rev))
108 dc_version = DCE_VERSION_11_22;
111 if (ASICREV_IS_VEGA20_P(asic_id.hw_internal_rev))
112 dc_version = DCE_VERSION_12_1;
114 dc_version = DCE_VERSION_12_0;
116 #if defined(CONFIG_DRM_AMD_DC_DCN)
118 dc_version = DCN_VERSION_1_0;
119 if (ASICREV_IS_RAVEN2(asic_id.hw_internal_rev))
120 dc_version = DCN_VERSION_1_01;
121 if (ASICREV_IS_RENOIR(asic_id.hw_internal_rev))
122 dc_version = DCN_VERSION_2_1;
123 if (ASICREV_IS_GREEN_SARDINE(asic_id.hw_internal_rev))
124 dc_version = DCN_VERSION_2_1;
129 dc_version = DCN_VERSION_2_0;
130 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
131 if (ASICREV_IS_SIENNA_CICHLID_P(asic_id.hw_internal_rev))
132 dc_version = DCN_VERSION_3_0;
136 dc_version = DCE_VERSION_UNKNOWN;
142 struct resource_pool *dc_create_resource_pool(struct dc *dc,
143 const struct dc_init_data *init_data,
144 enum dce_version dc_version)
146 struct resource_pool *res_pool = NULL;
148 switch (dc_version) {
149 #if defined(CONFIG_DRM_AMD_DC_SI)
150 case DCE_VERSION_6_0:
151 res_pool = dce60_create_resource_pool(
152 init_data->num_virtual_links, dc);
154 case DCE_VERSION_6_1:
155 res_pool = dce61_create_resource_pool(
156 init_data->num_virtual_links, dc);
158 case DCE_VERSION_6_4:
159 res_pool = dce64_create_resource_pool(
160 init_data->num_virtual_links, dc);
163 case DCE_VERSION_8_0:
164 res_pool = dce80_create_resource_pool(
165 init_data->num_virtual_links, dc);
167 case DCE_VERSION_8_1:
168 res_pool = dce81_create_resource_pool(
169 init_data->num_virtual_links, dc);
171 case DCE_VERSION_8_3:
172 res_pool = dce83_create_resource_pool(
173 init_data->num_virtual_links, dc);
175 case DCE_VERSION_10_0:
176 res_pool = dce100_create_resource_pool(
177 init_data->num_virtual_links, dc);
179 case DCE_VERSION_11_0:
180 res_pool = dce110_create_resource_pool(
181 init_data->num_virtual_links, dc,
184 case DCE_VERSION_11_2:
185 case DCE_VERSION_11_22:
186 res_pool = dce112_create_resource_pool(
187 init_data->num_virtual_links, dc);
189 case DCE_VERSION_12_0:
190 case DCE_VERSION_12_1:
191 res_pool = dce120_create_resource_pool(
192 init_data->num_virtual_links, dc);
195 #if defined(CONFIG_DRM_AMD_DC_DCN)
196 case DCN_VERSION_1_0:
197 case DCN_VERSION_1_01:
198 res_pool = dcn10_create_resource_pool(init_data, dc);
202 case DCN_VERSION_2_0:
203 res_pool = dcn20_create_resource_pool(init_data, dc);
205 case DCN_VERSION_2_1:
206 res_pool = dcn21_create_resource_pool(init_data, dc);
209 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
210 case DCN_VERSION_3_0:
211 res_pool = dcn30_create_resource_pool(init_data, dc);
219 if (res_pool != NULL) {
220 if (dc->ctx->dc_bios->fw_info_valid) {
221 res_pool->ref_clocks.xtalin_clock_inKhz =
222 dc->ctx->dc_bios->fw_info.pll_info.crystal_frequency;
223 /* initialize with firmware data first, no all
224 * ASIC have DCCG SW component. FPGA or
225 * simulation need initialization of
226 * dccg_ref_clock_inKhz, dchub_ref_clock_inKhz
227 * with xtalin_clock_inKhz
229 res_pool->ref_clocks.dccg_ref_clock_inKhz =
230 res_pool->ref_clocks.xtalin_clock_inKhz;
231 res_pool->ref_clocks.dchub_ref_clock_inKhz =
232 res_pool->ref_clocks.xtalin_clock_inKhz;
234 ASSERT_CRITICAL(false);
240 void dc_destroy_resource_pool(struct dc *dc)
244 dc->res_pool->funcs->destroy(&dc->res_pool);
250 static void update_num_audio(
251 const struct resource_straps *straps,
252 unsigned int *num_audio,
253 struct audio_support *aud_support)
255 aud_support->dp_audio = true;
256 aud_support->hdmi_audio_native = false;
257 aud_support->hdmi_audio_on_dongle = false;
259 if (straps->hdmi_disable == 0) {
260 if (straps->dc_pinstraps_audio & 0x2) {
261 aud_support->hdmi_audio_on_dongle = true;
262 aud_support->hdmi_audio_native = true;
266 switch (straps->audio_stream_number) {
267 case 0: /* multi streams supported */
269 case 1: /* multi streams not supported */
273 DC_ERR("DC: unexpected audio fuse!\n");
277 bool resource_construct(
278 unsigned int num_virtual_links,
280 struct resource_pool *pool,
281 const struct resource_create_funcs *create_funcs)
283 struct dc_context *ctx = dc->ctx;
284 const struct resource_caps *caps = pool->res_cap;
286 unsigned int num_audio = caps->num_audio;
287 struct resource_straps straps = {0};
289 if (create_funcs->read_dce_straps)
290 create_funcs->read_dce_straps(dc->ctx, &straps);
292 pool->audio_count = 0;
293 if (create_funcs->create_audio) {
294 /* find the total number of streams available via the
295 * AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT
296 * registers (one for each pin) starting from pin 1
297 * up to the max number of audio pins.
298 * We stop on the first pin where
299 * PORT_CONNECTIVITY == 1 (as instructed by HW team).
301 update_num_audio(&straps, &num_audio, &pool->audio_support);
302 for (i = 0; i < caps->num_audio; i++) {
303 struct audio *aud = create_funcs->create_audio(ctx, i);
306 DC_ERR("DC: failed to create audio!\n");
309 if (!aud->funcs->endpoint_valid(aud)) {
310 aud->funcs->destroy(&aud);
313 pool->audios[i] = aud;
318 pool->stream_enc_count = 0;
319 if (create_funcs->create_stream_encoder) {
320 for (i = 0; i < caps->num_stream_encoder; i++) {
321 pool->stream_enc[i] = create_funcs->create_stream_encoder(i, ctx);
322 if (pool->stream_enc[i] == NULL)
323 DC_ERR("DC: failed to create stream_encoder!\n");
324 pool->stream_enc_count++;
328 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
329 for (i = 0; i < caps->num_mpc_3dlut; i++) {
330 pool->mpc_lut[i] = dc_create_3dlut_func();
331 if (pool->mpc_lut[i] == NULL)
332 DC_ERR("DC: failed to create MPC 3dlut!\n");
333 pool->mpc_shaper[i] = dc_create_transfer_func();
334 if (pool->mpc_shaper[i] == NULL)
335 DC_ERR("DC: failed to create MPC shaper!\n");
338 dc->caps.dynamic_audio = false;
339 if (pool->audio_count < pool->stream_enc_count) {
340 dc->caps.dynamic_audio = true;
342 for (i = 0; i < num_virtual_links; i++) {
343 pool->stream_enc[pool->stream_enc_count] =
344 virtual_stream_encoder_create(
346 if (pool->stream_enc[pool->stream_enc_count] == NULL) {
347 DC_ERR("DC: failed to create stream_encoder!\n");
350 pool->stream_enc_count++;
353 dc->hwseq = create_funcs->create_hwseq(ctx);
357 static int find_matching_clock_source(
358 const struct resource_pool *pool,
359 struct clock_source *clock_source)
364 for (i = 0; i < pool->clk_src_count; i++) {
365 if (pool->clock_sources[i] == clock_source)
371 void resource_unreference_clock_source(
372 struct resource_context *res_ctx,
373 const struct resource_pool *pool,
374 struct clock_source *clock_source)
376 int i = find_matching_clock_source(pool, clock_source);
379 res_ctx->clock_source_ref_count[i]--;
381 if (pool->dp_clock_source == clock_source)
382 res_ctx->dp_clock_source_ref_count--;
385 void resource_reference_clock_source(
386 struct resource_context *res_ctx,
387 const struct resource_pool *pool,
388 struct clock_source *clock_source)
390 int i = find_matching_clock_source(pool, clock_source);
393 res_ctx->clock_source_ref_count[i]++;
395 if (pool->dp_clock_source == clock_source)
396 res_ctx->dp_clock_source_ref_count++;
399 int resource_get_clock_source_reference(
400 struct resource_context *res_ctx,
401 const struct resource_pool *pool,
402 struct clock_source *clock_source)
404 int i = find_matching_clock_source(pool, clock_source);
407 return res_ctx->clock_source_ref_count[i];
409 if (pool->dp_clock_source == clock_source)
410 return res_ctx->dp_clock_source_ref_count;
415 bool resource_are_streams_timing_synchronizable(
416 struct dc_stream_state *stream1,
417 struct dc_stream_state *stream2)
419 if (stream1->timing.h_total != stream2->timing.h_total)
422 if (stream1->timing.v_total != stream2->timing.v_total)
425 if (stream1->timing.h_addressable
426 != stream2->timing.h_addressable)
429 if (stream1->timing.v_addressable
430 != stream2->timing.v_addressable)
433 if (stream1->timing.v_front_porch
434 != stream2->timing.v_front_porch)
437 if (stream1->timing.pix_clk_100hz
438 != stream2->timing.pix_clk_100hz)
441 if (stream1->clamping.c_depth != stream2->clamping.c_depth)
444 if (stream1->phy_pix_clk != stream2->phy_pix_clk
445 && (!dc_is_dp_signal(stream1->signal)
446 || !dc_is_dp_signal(stream2->signal)))
449 if (stream1->view_format != stream2->view_format)
452 if (stream1->ignore_msa_timing_param || stream2->ignore_msa_timing_param)
457 static bool is_dp_and_hdmi_sharable(
458 struct dc_stream_state *stream1,
459 struct dc_stream_state *stream2)
461 if (stream1->ctx->dc->caps.disable_dp_clk_share)
464 if (stream1->clamping.c_depth != COLOR_DEPTH_888 ||
465 stream2->clamping.c_depth != COLOR_DEPTH_888)
472 static bool is_sharable_clk_src(
473 const struct pipe_ctx *pipe_with_clk_src,
474 const struct pipe_ctx *pipe)
476 if (pipe_with_clk_src->clock_source == NULL)
479 if (pipe_with_clk_src->stream->signal == SIGNAL_TYPE_VIRTUAL)
482 if (dc_is_dp_signal(pipe_with_clk_src->stream->signal) ||
483 (dc_is_dp_signal(pipe->stream->signal) &&
484 !is_dp_and_hdmi_sharable(pipe_with_clk_src->stream,
488 if (dc_is_hdmi_signal(pipe_with_clk_src->stream->signal)
489 && dc_is_dual_link_signal(pipe->stream->signal))
492 if (dc_is_hdmi_signal(pipe->stream->signal)
493 && dc_is_dual_link_signal(pipe_with_clk_src->stream->signal))
496 if (!resource_are_streams_timing_synchronizable(
497 pipe_with_clk_src->stream, pipe->stream))
503 struct clock_source *resource_find_used_clk_src_for_sharing(
504 struct resource_context *res_ctx,
505 struct pipe_ctx *pipe_ctx)
509 for (i = 0; i < MAX_PIPES; i++) {
510 if (is_sharable_clk_src(&res_ctx->pipe_ctx[i], pipe_ctx))
511 return res_ctx->pipe_ctx[i].clock_source;
517 static enum pixel_format convert_pixel_format_to_dalsurface(
518 enum surface_pixel_format surface_pixel_format)
520 enum pixel_format dal_pixel_format = PIXEL_FORMAT_UNKNOWN;
522 switch (surface_pixel_format) {
523 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
524 dal_pixel_format = PIXEL_FORMAT_INDEX8;
526 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
527 dal_pixel_format = PIXEL_FORMAT_RGB565;
529 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
530 dal_pixel_format = PIXEL_FORMAT_RGB565;
532 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
533 dal_pixel_format = PIXEL_FORMAT_ARGB8888;
535 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
536 dal_pixel_format = PIXEL_FORMAT_ARGB8888;
538 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
539 dal_pixel_format = PIXEL_FORMAT_ARGB2101010;
541 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
542 dal_pixel_format = PIXEL_FORMAT_ARGB2101010;
544 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
545 dal_pixel_format = PIXEL_FORMAT_ARGB2101010_XRBIAS;
547 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
548 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
549 dal_pixel_format = PIXEL_FORMAT_FP16;
551 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
552 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
553 dal_pixel_format = PIXEL_FORMAT_420BPP8;
555 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
556 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
557 dal_pixel_format = PIXEL_FORMAT_420BPP10;
559 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
561 dal_pixel_format = PIXEL_FORMAT_UNKNOWN;
564 return dal_pixel_format;
567 static inline void get_vp_scan_direction(
568 enum dc_rotation_angle rotation,
569 bool horizontal_mirror,
570 bool *orthogonal_rotation,
571 bool *flip_vert_scan_dir,
572 bool *flip_horz_scan_dir)
574 *orthogonal_rotation = false;
575 *flip_vert_scan_dir = false;
576 *flip_horz_scan_dir = false;
577 if (rotation == ROTATION_ANGLE_180) {
578 *flip_vert_scan_dir = true;
579 *flip_horz_scan_dir = true;
580 } else if (rotation == ROTATION_ANGLE_90) {
581 *orthogonal_rotation = true;
582 *flip_horz_scan_dir = true;
583 } else if (rotation == ROTATION_ANGLE_270) {
584 *orthogonal_rotation = true;
585 *flip_vert_scan_dir = true;
588 if (horizontal_mirror)
589 *flip_horz_scan_dir = !*flip_horz_scan_dir;
592 int get_num_mpc_splits(struct pipe_ctx *pipe)
594 int mpc_split_count = 0;
595 struct pipe_ctx *other_pipe = pipe->bottom_pipe;
597 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
599 other_pipe = other_pipe->bottom_pipe;
601 other_pipe = pipe->top_pipe;
602 while (other_pipe && other_pipe->plane_state == pipe->plane_state) {
604 other_pipe = other_pipe->top_pipe;
607 return mpc_split_count;
610 int get_num_odm_splits(struct pipe_ctx *pipe)
612 int odm_split_count = 0;
613 struct pipe_ctx *next_pipe = pipe->next_odm_pipe;
616 next_pipe = next_pipe->next_odm_pipe;
618 pipe = pipe->prev_odm_pipe;
621 pipe = pipe->prev_odm_pipe;
623 return odm_split_count;
626 static void calculate_split_count_and_index(struct pipe_ctx *pipe_ctx, int *split_count, int *split_idx)
628 *split_count = get_num_odm_splits(pipe_ctx);
630 if (*split_count == 0) {
631 /*Check for mpc split*/
632 struct pipe_ctx *split_pipe = pipe_ctx->top_pipe;
634 *split_count = get_num_mpc_splits(pipe_ctx);
635 while (split_pipe && split_pipe->plane_state == pipe_ctx->plane_state) {
637 split_pipe = split_pipe->top_pipe;
640 /*Get odm split index*/
641 struct pipe_ctx *split_pipe = pipe_ctx->prev_odm_pipe;
645 split_pipe = split_pipe->prev_odm_pipe;
650 static void calculate_viewport(struct pipe_ctx *pipe_ctx)
652 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
653 const struct dc_stream_state *stream = pipe_ctx->stream;
654 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
655 struct rect surf_src = plane_state->src_rect;
656 struct rect clip, dest;
657 int vpc_div = (data->format == PIXEL_FORMAT_420BPP8
658 || data->format == PIXEL_FORMAT_420BPP10) ? 2 : 1;
661 bool orthogonal_rotation, flip_y_start, flip_x_start;
663 calculate_split_count_and_index(pipe_ctx, &split_count, &split_idx);
665 if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE ||
666 stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM) {
671 /* The actual clip is an intersection between stream
672 * source and surface clip
674 dest = plane_state->dst_rect;
675 clip.x = stream->src.x > plane_state->clip_rect.x ?
676 stream->src.x : plane_state->clip_rect.x;
678 clip.width = stream->src.x + stream->src.width <
679 plane_state->clip_rect.x + plane_state->clip_rect.width ?
680 stream->src.x + stream->src.width - clip.x :
681 plane_state->clip_rect.x + plane_state->clip_rect.width - clip.x ;
683 clip.y = stream->src.y > plane_state->clip_rect.y ?
684 stream->src.y : plane_state->clip_rect.y;
686 clip.height = stream->src.y + stream->src.height <
687 plane_state->clip_rect.y + plane_state->clip_rect.height ?
688 stream->src.y + stream->src.height - clip.y :
689 plane_state->clip_rect.y + plane_state->clip_rect.height - clip.y ;
692 * Need to calculate how scan origin is shifted in vp space
693 * to correctly rotate clip and dst
695 get_vp_scan_direction(
696 plane_state->rotation,
697 plane_state->horizontal_mirror,
698 &orthogonal_rotation,
702 if (orthogonal_rotation) {
703 swap(clip.x, clip.y);
704 swap(clip.width, clip.height);
705 swap(dest.x, dest.y);
706 swap(dest.width, dest.height);
709 clip.x = dest.x + dest.width - clip.x - clip.width;
713 clip.y = dest.y + dest.height - clip.y - clip.height;
717 /* offset = surf_src.ofs + (clip.ofs - surface->dst_rect.ofs) * scl_ratio
718 * num_pixels = clip.num_pix * scl_ratio
720 data->viewport.x = surf_src.x + (clip.x - dest.x) * surf_src.width / dest.width;
721 data->viewport.width = clip.width * surf_src.width / dest.width;
723 data->viewport.y = surf_src.y + (clip.y - dest.y) * surf_src.height / dest.height;
724 data->viewport.height = clip.height * surf_src.height / dest.height;
728 /* extra pixels in the division remainder need to go to pipes after
729 * the extra pixel index minus one(epimo) defined here as:
733 if (orthogonal_rotation) {
735 split_idx = split_count - split_idx;
737 epimo = split_count - data->viewport.height % (split_count + 1);
739 data->viewport.y += (data->viewport.height / (split_count + 1)) * split_idx;
740 if (split_idx > epimo)
741 data->viewport.y += split_idx - epimo - 1;
742 data->viewport.height = data->viewport.height / (split_count + 1) + (split_idx > epimo ? 1 : 0);
745 split_idx = split_count - split_idx;
747 epimo = split_count - data->viewport.width % (split_count + 1);
749 data->viewport.x += (data->viewport.width / (split_count + 1)) * split_idx;
750 if (split_idx > epimo)
751 data->viewport.x += split_idx - epimo - 1;
752 data->viewport.width = data->viewport.width / (split_count + 1) + (split_idx > epimo ? 1 : 0);
756 /* Round down, compensate in init */
757 data->viewport_c.x = data->viewport.x / vpc_div;
758 data->viewport_c.y = data->viewport.y / vpc_div;
759 data->inits.h_c = (data->viewport.x % vpc_div) != 0 ? dc_fixpt_half : dc_fixpt_zero;
760 data->inits.v_c = (data->viewport.y % vpc_div) != 0 ? dc_fixpt_half : dc_fixpt_zero;
762 /* Round up, assume original video size always even dimensions */
763 data->viewport_c.width = (data->viewport.width + vpc_div - 1) / vpc_div;
764 data->viewport_c.height = (data->viewport.height + vpc_div - 1) / vpc_div;
766 data->viewport_unadjusted = data->viewport;
767 data->viewport_c_unadjusted = data->viewport_c;
770 static void calculate_recout(struct pipe_ctx *pipe_ctx)
772 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
773 const struct dc_stream_state *stream = pipe_ctx->stream;
774 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
775 struct rect surf_clip = plane_state->clip_rect;
776 bool pri_split_tb = pipe_ctx->bottom_pipe &&
777 pipe_ctx->bottom_pipe->plane_state == pipe_ctx->plane_state &&
778 stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM;
779 bool sec_split_tb = pipe_ctx->top_pipe &&
780 pipe_ctx->top_pipe->plane_state == pipe_ctx->plane_state &&
781 stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM;
785 calculate_split_count_and_index(pipe_ctx, &split_count, &split_idx);
788 * Only the leftmost ODM pipe should be offset by a nonzero distance
790 if (!pipe_ctx->prev_odm_pipe) {
791 data->recout.x = stream->dst.x;
792 if (stream->src.x < surf_clip.x)
793 data->recout.x += (surf_clip.x - stream->src.x) * stream->dst.width
799 data->recout.width = surf_clip.width * stream->dst.width / stream->src.width;
800 if (data->recout.width + data->recout.x > stream->dst.x + stream->dst.width)
801 data->recout.width = stream->dst.x + stream->dst.width - data->recout.x;
803 data->recout.y = stream->dst.y;
804 if (stream->src.y < surf_clip.y)
805 data->recout.y += (surf_clip.y - stream->src.y) * stream->dst.height
806 / stream->src.height;
808 data->recout.height = surf_clip.height * stream->dst.height / stream->src.height;
809 if (data->recout.height + data->recout.y > stream->dst.y + stream->dst.height)
810 data->recout.height = stream->dst.y + stream->dst.height - data->recout.y;
812 /* Handle h & v split, handle rotation using viewport */
814 data->recout.y += data->recout.height / 2;
815 /* Floor primary pipe, ceil 2ndary pipe */
816 data->recout.height = (data->recout.height + 1) / 2;
817 } else if (pri_split_tb)
818 data->recout.height /= 2;
819 else if (split_count) {
820 /* extra pixels in the division remainder need to go to pipes after
821 * the extra pixel index minus one(epimo) defined here as:
823 int epimo = split_count - data->recout.width % (split_count + 1);
825 /*no recout offset due to odm */
826 if (!pipe_ctx->next_odm_pipe && !pipe_ctx->prev_odm_pipe) {
827 data->recout.x += (data->recout.width / (split_count + 1)) * split_idx;
828 if (split_idx > epimo)
829 data->recout.x += split_idx - epimo - 1;
831 data->recout.width = data->recout.width / (split_count + 1) + (split_idx > epimo ? 1 : 0);
835 static void calculate_scaling_ratios(struct pipe_ctx *pipe_ctx)
837 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
838 const struct dc_stream_state *stream = pipe_ctx->stream;
839 struct rect surf_src = plane_state->src_rect;
840 const int in_w = stream->src.width;
841 const int in_h = stream->src.height;
842 const int out_w = stream->dst.width;
843 const int out_h = stream->dst.height;
845 /*Swap surf_src height and width since scaling ratios are in recout rotation*/
846 if (pipe_ctx->plane_state->rotation == ROTATION_ANGLE_90 ||
847 pipe_ctx->plane_state->rotation == ROTATION_ANGLE_270)
848 swap(surf_src.height, surf_src.width);
850 pipe_ctx->plane_res.scl_data.ratios.horz = dc_fixpt_from_fraction(
852 plane_state->dst_rect.width);
853 pipe_ctx->plane_res.scl_data.ratios.vert = dc_fixpt_from_fraction(
855 plane_state->dst_rect.height);
857 if (stream->view_format == VIEW_3D_FORMAT_SIDE_BY_SIDE)
858 pipe_ctx->plane_res.scl_data.ratios.horz.value *= 2;
859 else if (stream->view_format == VIEW_3D_FORMAT_TOP_AND_BOTTOM)
860 pipe_ctx->plane_res.scl_data.ratios.vert.value *= 2;
862 pipe_ctx->plane_res.scl_data.ratios.vert.value = div64_s64(
863 pipe_ctx->plane_res.scl_data.ratios.vert.value * in_h, out_h);
864 pipe_ctx->plane_res.scl_data.ratios.horz.value = div64_s64(
865 pipe_ctx->plane_res.scl_data.ratios.horz.value * in_w, out_w);
867 pipe_ctx->plane_res.scl_data.ratios.horz_c = pipe_ctx->plane_res.scl_data.ratios.horz;
868 pipe_ctx->plane_res.scl_data.ratios.vert_c = pipe_ctx->plane_res.scl_data.ratios.vert;
870 if (pipe_ctx->plane_res.scl_data.format == PIXEL_FORMAT_420BPP8
871 || pipe_ctx->plane_res.scl_data.format == PIXEL_FORMAT_420BPP10) {
872 pipe_ctx->plane_res.scl_data.ratios.horz_c.value /= 2;
873 pipe_ctx->plane_res.scl_data.ratios.vert_c.value /= 2;
875 pipe_ctx->plane_res.scl_data.ratios.horz = dc_fixpt_truncate(
876 pipe_ctx->plane_res.scl_data.ratios.horz, 19);
877 pipe_ctx->plane_res.scl_data.ratios.vert = dc_fixpt_truncate(
878 pipe_ctx->plane_res.scl_data.ratios.vert, 19);
879 pipe_ctx->plane_res.scl_data.ratios.horz_c = dc_fixpt_truncate(
880 pipe_ctx->plane_res.scl_data.ratios.horz_c, 19);
881 pipe_ctx->plane_res.scl_data.ratios.vert_c = dc_fixpt_truncate(
882 pipe_ctx->plane_res.scl_data.ratios.vert_c, 19);
885 static inline void adjust_vp_and_init_for_seamless_clip(
890 struct fixed31_32 ratio,
891 struct fixed31_32 *init,
895 if (!flip_scan_dir) {
896 /* Adjust for viewport end clip-off */
897 if ((*vp_offset + *vp_size) < src_size) {
898 int vp_clip = src_size - *vp_size - *vp_offset;
899 int int_part = dc_fixpt_floor(dc_fixpt_sub(*init, ratio));
901 int_part = int_part > 0 ? int_part : 0;
902 *vp_size += int_part < vp_clip ? int_part : vp_clip;
905 /* Adjust for non-0 viewport offset */
909 *init = dc_fixpt_add(*init, dc_fixpt_mul_int(ratio, recout_skip));
910 int_part = dc_fixpt_floor(*init) - *vp_offset;
911 if (int_part < taps) {
912 int int_adj = *vp_offset >= (taps - int_part) ?
913 (taps - int_part) : *vp_offset;
914 *vp_offset -= int_adj;
917 } else if (int_part > taps) {
918 *vp_offset += int_part - taps;
919 *vp_size -= int_part - taps;
922 init->value &= 0xffffffff;
923 *init = dc_fixpt_add_int(*init, int_part);
926 /* Adjust for non-0 viewport 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_offset ? int_part : *vp_offset;
932 *vp_offset -= int_part < *vp_offset ? int_part : *vp_offset;
935 /* Adjust for viewport end clip-off */
936 if ((*vp_offset + *vp_size) < src_size) {
938 int end_offset = src_size - *vp_offset - *vp_size;
941 * this is init if vp had no offset, keep in mind this is from the
942 * right side of vp due to scan direction
944 *init = dc_fixpt_add(*init, dc_fixpt_mul_int(ratio, recout_skip));
946 * this is the difference between first pixel of viewport available to read
947 * and init position, takning into account scan direction
949 int_part = dc_fixpt_floor(*init) - end_offset;
950 if (int_part < taps) {
951 int int_adj = end_offset >= (taps - int_part) ?
952 (taps - int_part) : end_offset;
955 } else if (int_part > taps) {
956 *vp_size += int_part - taps;
959 init->value &= 0xffffffff;
960 *init = dc_fixpt_add_int(*init, int_part);
965 static void calculate_inits_and_adj_vp(struct pipe_ctx *pipe_ctx)
967 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
968 const struct dc_stream_state *stream = pipe_ctx->stream;
969 struct pipe_ctx *odm_pipe = pipe_ctx;
970 struct scaler_data *data = &pipe_ctx->plane_res.scl_data;
971 struct rect src = pipe_ctx->plane_state->src_rect;
972 int recout_skip_h, recout_skip_v, surf_size_h, surf_size_v;
973 int vpc_div = (data->format == PIXEL_FORMAT_420BPP8
974 || data->format == PIXEL_FORMAT_420BPP10) ? 2 : 1;
975 bool orthogonal_rotation, flip_vert_scan_dir, flip_horz_scan_dir;
979 * Need to calculate the scan direction for viewport to make adjustments
981 get_vp_scan_direction(
982 plane_state->rotation,
983 plane_state->horizontal_mirror,
984 &orthogonal_rotation,
986 &flip_horz_scan_dir);
988 /* Calculate src rect rotation adjusted to recout space */
989 surf_size_h = src.x + src.width;
990 surf_size_v = src.y + src.height;
991 if (flip_horz_scan_dir)
993 if (flip_vert_scan_dir)
995 if (orthogonal_rotation) {
997 swap(src.width, src.height);
1000 /*modified recout_skip_h calculation due to odm having no recout offset*/
1001 while (odm_pipe->prev_odm_pipe) {
1003 odm_pipe = odm_pipe->prev_odm_pipe;
1005 /*odm_pipe is the leftmost pipe in the ODM group*/
1006 recout_skip_h = odm_idx * data->recout.width;
1008 /* Recout matching initial vp offset = recout_offset - (stream dst offset +
1009 * ((surf dst offset - stream src offset) * 1/ stream scaling ratio)
1010 * - (surf surf_src offset * 1/ full scl ratio))
1012 recout_skip_h += odm_pipe->plane_res.scl_data.recout.x
1013 - (stream->dst.x + (plane_state->dst_rect.x - stream->src.x)
1014 * stream->dst.width / stream->src.width -
1015 src.x * plane_state->dst_rect.width / src.width
1016 * stream->dst.width / stream->src.width);
1019 recout_skip_v = data->recout.y - (stream->dst.y + (plane_state->dst_rect.y - stream->src.y)
1020 * stream->dst.height / stream->src.height -
1021 src.y * plane_state->dst_rect.height / src.height
1022 * stream->dst.height / stream->src.height);
1023 if (orthogonal_rotation)
1024 swap(recout_skip_h, recout_skip_v);
1026 * Init calculated according to formula:
1027 * init = (scaling_ratio + number_of_taps + 1) / 2
1028 * init_bot = init + scaling_ratio
1029 * init_c = init + truncated_vp_c_offset(from calculate viewport)
1031 data->inits.h = dc_fixpt_truncate(dc_fixpt_div_int(
1032 dc_fixpt_add_int(data->ratios.horz, data->taps.h_taps + 1), 2), 19);
1034 data->inits.h_c = dc_fixpt_truncate(dc_fixpt_add(data->inits.h_c, dc_fixpt_div_int(
1035 dc_fixpt_add_int(data->ratios.horz_c, data->taps.h_taps_c + 1), 2)), 19);
1037 data->inits.v = dc_fixpt_truncate(dc_fixpt_div_int(
1038 dc_fixpt_add_int(data->ratios.vert, data->taps.v_taps + 1), 2), 19);
1040 data->inits.v_c = dc_fixpt_truncate(dc_fixpt_add(data->inits.v_c, dc_fixpt_div_int(
1041 dc_fixpt_add_int(data->ratios.vert_c, data->taps.v_taps_c + 1), 2)), 19);
1044 * Taps, inits and scaling ratios are in recout space need to rotate
1045 * to viewport rotation before adjustment
1047 adjust_vp_and_init_for_seamless_clip(
1051 orthogonal_rotation ? data->taps.v_taps : data->taps.h_taps,
1052 orthogonal_rotation ? data->ratios.vert : data->ratios.horz,
1053 orthogonal_rotation ? &data->inits.v : &data->inits.h,
1055 &data->viewport.width);
1056 adjust_vp_and_init_for_seamless_clip(
1059 surf_size_h / vpc_div,
1060 orthogonal_rotation ? data->taps.v_taps_c : data->taps.h_taps_c,
1061 orthogonal_rotation ? data->ratios.vert_c : data->ratios.horz_c,
1062 orthogonal_rotation ? &data->inits.v_c : &data->inits.h_c,
1063 &data->viewport_c.x,
1064 &data->viewport_c.width);
1065 adjust_vp_and_init_for_seamless_clip(
1069 orthogonal_rotation ? data->taps.h_taps : data->taps.v_taps,
1070 orthogonal_rotation ? data->ratios.horz : data->ratios.vert,
1071 orthogonal_rotation ? &data->inits.h : &data->inits.v,
1073 &data->viewport.height);
1074 adjust_vp_and_init_for_seamless_clip(
1077 surf_size_v / vpc_div,
1078 orthogonal_rotation ? data->taps.h_taps_c : data->taps.v_taps_c,
1079 orthogonal_rotation ? data->ratios.horz_c : data->ratios.vert_c,
1080 orthogonal_rotation ? &data->inits.h_c : &data->inits.v_c,
1081 &data->viewport_c.y,
1082 &data->viewport_c.height);
1084 /* Interlaced inits based on final vert inits */
1085 data->inits.v_bot = dc_fixpt_add(data->inits.v, data->ratios.vert);
1086 data->inits.v_c_bot = dc_fixpt_add(data->inits.v_c, data->ratios.vert_c);
1091 * When handling 270 rotation in mixed SLS mode, we have
1092 * stream->timing.h_border_left that is non zero. If we are doing
1093 * pipe-splitting, this h_border_left value gets added to recout.x and when it
1094 * calls calculate_inits_and_adj_vp() and
1095 * adjust_vp_and_init_for_seamless_clip(), it can cause viewport.height for a
1096 * pipe to be incorrect.
1098 * To fix this, instead of using stream->timing.h_border_left, we can use
1099 * stream->dst.x to represent the border instead. So we will set h_border_left
1100 * to 0 and shift the appropriate amount in stream->dst.x. We will then
1101 * perform all calculations in resource_build_scaling_params() based on this
1102 * and then restore the h_border_left and stream->dst.x to their original
1105 * shift_border_left_to_dst() will shift the amount of h_border_left to
1106 * stream->dst.x and set h_border_left to 0. restore_border_left_from_dst()
1107 * will restore h_border_left and stream->dst.x back to their original values
1108 * We also need to make sure pipe_ctx->plane_res.scl_data.h_active uses the
1109 * original h_border_left value in its calculation.
1111 int shift_border_left_to_dst(struct pipe_ctx *pipe_ctx)
1113 int store_h_border_left = pipe_ctx->stream->timing.h_border_left;
1115 if (store_h_border_left) {
1116 pipe_ctx->stream->timing.h_border_left = 0;
1117 pipe_ctx->stream->dst.x += store_h_border_left;
1119 return store_h_border_left;
1122 void restore_border_left_from_dst(struct pipe_ctx *pipe_ctx,
1123 int store_h_border_left)
1125 pipe_ctx->stream->dst.x -= store_h_border_left;
1126 pipe_ctx->stream->timing.h_border_left = store_h_border_left;
1129 bool resource_build_scaling_params(struct pipe_ctx *pipe_ctx)
1131 const struct dc_plane_state *plane_state = pipe_ctx->plane_state;
1132 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
1134 int store_h_border_left = shift_border_left_to_dst(pipe_ctx);
1135 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1136 /* Important: scaling ratio calculation requires pixel format,
1137 * lb depth calculation requires recout and taps require scaling ratios.
1138 * Inits require viewport, taps, ratios and recout of split pipe
1140 pipe_ctx->plane_res.scl_data.format = convert_pixel_format_to_dalsurface(
1141 pipe_ctx->plane_state->format);
1143 calculate_scaling_ratios(pipe_ctx);
1145 calculate_viewport(pipe_ctx);
1147 if (pipe_ctx->plane_res.scl_data.viewport.height < 12 ||
1148 pipe_ctx->plane_res.scl_data.viewport.width < 12) {
1149 if (store_h_border_left) {
1150 restore_border_left_from_dst(pipe_ctx,
1151 store_h_border_left);
1156 calculate_recout(pipe_ctx);
1159 * Setting line buffer pixel depth to 24bpp yields banding
1160 * on certain displays, such as the Sharp 4k
1162 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_30BPP;
1163 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = plane_state->per_pixel_alpha;
1165 pipe_ctx->plane_res.scl_data.recout.x += timing->h_border_left;
1166 pipe_ctx->plane_res.scl_data.recout.y += timing->v_border_top;
1168 pipe_ctx->plane_res.scl_data.h_active = timing->h_addressable +
1169 store_h_border_left + timing->h_border_right;
1170 pipe_ctx->plane_res.scl_data.v_active = timing->v_addressable +
1171 timing->v_border_top + timing->v_border_bottom;
1172 if (pipe_ctx->next_odm_pipe || pipe_ctx->prev_odm_pipe)
1173 pipe_ctx->plane_res.scl_data.h_active /= get_num_odm_splits(pipe_ctx) + 1;
1175 /* Taps calculations */
1176 if (pipe_ctx->plane_res.xfm != NULL)
1177 res = pipe_ctx->plane_res.xfm->funcs->transform_get_optimal_number_of_taps(
1178 pipe_ctx->plane_res.xfm, &pipe_ctx->plane_res.scl_data, &plane_state->scaling_quality);
1180 if (pipe_ctx->plane_res.dpp != NULL)
1181 res = pipe_ctx->plane_res.dpp->funcs->dpp_get_optimal_number_of_taps(
1182 pipe_ctx->plane_res.dpp, &pipe_ctx->plane_res.scl_data, &plane_state->scaling_quality);
1186 /* Try 24 bpp linebuffer */
1187 pipe_ctx->plane_res.scl_data.lb_params.depth = LB_PIXEL_DEPTH_24BPP;
1189 if (pipe_ctx->plane_res.xfm != NULL)
1190 res = pipe_ctx->plane_res.xfm->funcs->transform_get_optimal_number_of_taps(
1191 pipe_ctx->plane_res.xfm,
1192 &pipe_ctx->plane_res.scl_data,
1193 &plane_state->scaling_quality);
1195 if (pipe_ctx->plane_res.dpp != NULL)
1196 res = pipe_ctx->plane_res.dpp->funcs->dpp_get_optimal_number_of_taps(
1197 pipe_ctx->plane_res.dpp,
1198 &pipe_ctx->plane_res.scl_data,
1199 &plane_state->scaling_quality);
1203 /* May need to re-check lb size after this in some obscure scenario */
1204 calculate_inits_and_adj_vp(pipe_ctx);
1206 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"
1207 "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",
1210 pipe_ctx->plane_res.scl_data.viewport.height,
1211 pipe_ctx->plane_res.scl_data.viewport.width,
1212 pipe_ctx->plane_res.scl_data.viewport.x,
1213 pipe_ctx->plane_res.scl_data.viewport.y,
1214 pipe_ctx->plane_res.scl_data.recout.height,
1215 pipe_ctx->plane_res.scl_data.recout.width,
1216 pipe_ctx->plane_res.scl_data.recout.x,
1217 pipe_ctx->plane_res.scl_data.recout.y,
1218 pipe_ctx->plane_res.scl_data.h_active,
1219 pipe_ctx->plane_res.scl_data.v_active,
1220 plane_state->src_rect.height,
1221 plane_state->src_rect.width,
1222 plane_state->src_rect.x,
1223 plane_state->src_rect.y,
1224 plane_state->dst_rect.height,
1225 plane_state->dst_rect.width,
1226 plane_state->dst_rect.x,
1227 plane_state->dst_rect.y,
1228 plane_state->clip_rect.height,
1229 plane_state->clip_rect.width,
1230 plane_state->clip_rect.x,
1231 plane_state->clip_rect.y);
1233 if (store_h_border_left)
1234 restore_border_left_from_dst(pipe_ctx, store_h_border_left);
1240 enum dc_status resource_build_scaling_params_for_context(
1241 const struct dc *dc,
1242 struct dc_state *context)
1246 for (i = 0; i < MAX_PIPES; i++) {
1247 if (context->res_ctx.pipe_ctx[i].plane_state != NULL &&
1248 context->res_ctx.pipe_ctx[i].stream != NULL)
1249 if (!resource_build_scaling_params(&context->res_ctx.pipe_ctx[i]))
1250 return DC_FAIL_SCALING;
1256 struct pipe_ctx *find_idle_secondary_pipe(
1257 struct resource_context *res_ctx,
1258 const struct resource_pool *pool,
1259 const struct pipe_ctx *primary_pipe)
1262 struct pipe_ctx *secondary_pipe = NULL;
1265 * We add a preferred pipe mapping to avoid the chance that
1266 * MPCCs already in use will need to be reassigned to other trees.
1267 * For example, if we went with the strict, assign backwards logic:
1270 * Display A on, no surface, top pipe = 0
1271 * Display B on, no surface, top pipe = 1
1274 * Display A on, no surface, top pipe = 0
1275 * Display B on, surface enable, top pipe = 1, bottom pipe = 5
1278 * Display A on, surface enable, top pipe = 0, bottom pipe = 5
1279 * Display B on, surface enable, top pipe = 1, bottom pipe = 4
1281 * The state 2->3 transition requires remapping MPCC 5 from display B
1284 * However, with the preferred pipe logic, state 2 would look like:
1287 * Display A on, no surface, top pipe = 0
1288 * Display B on, surface enable, top pipe = 1, bottom pipe = 4
1290 * This would then cause 2->3 to not require remapping any MPCCs.
1293 int preferred_pipe_idx = (pool->pipe_count - 1) - primary_pipe->pipe_idx;
1294 if (res_ctx->pipe_ctx[preferred_pipe_idx].stream == NULL) {
1295 secondary_pipe = &res_ctx->pipe_ctx[preferred_pipe_idx];
1296 secondary_pipe->pipe_idx = preferred_pipe_idx;
1301 * search backwards for the second pipe to keep pipe
1302 * assignment more consistent
1304 if (!secondary_pipe)
1305 for (i = pool->pipe_count - 1; i >= 0; i--) {
1306 if (res_ctx->pipe_ctx[i].stream == NULL) {
1307 secondary_pipe = &res_ctx->pipe_ctx[i];
1308 secondary_pipe->pipe_idx = i;
1313 return secondary_pipe;
1316 struct pipe_ctx *resource_get_head_pipe_for_stream(
1317 struct resource_context *res_ctx,
1318 struct dc_stream_state *stream)
1322 for (i = 0; i < MAX_PIPES; i++) {
1323 if (res_ctx->pipe_ctx[i].stream == stream
1324 && !res_ctx->pipe_ctx[i].top_pipe
1325 && !res_ctx->pipe_ctx[i].prev_odm_pipe)
1326 return &res_ctx->pipe_ctx[i];
1331 static struct pipe_ctx *resource_get_tail_pipe(
1332 struct resource_context *res_ctx,
1333 struct pipe_ctx *head_pipe)
1335 struct pipe_ctx *tail_pipe;
1337 tail_pipe = head_pipe->bottom_pipe;
1340 head_pipe = tail_pipe;
1341 tail_pipe = tail_pipe->bottom_pipe;
1348 * A free_pipe for a stream is defined here as a pipe
1349 * that has no surface attached yet
1351 static struct pipe_ctx *acquire_free_pipe_for_head(
1352 struct dc_state *context,
1353 const struct resource_pool *pool,
1354 struct pipe_ctx *head_pipe)
1357 struct resource_context *res_ctx = &context->res_ctx;
1359 if (!head_pipe->plane_state)
1362 /* Re-use pipe already acquired for this stream if available*/
1363 for (i = pool->pipe_count - 1; i >= 0; i--) {
1364 if (res_ctx->pipe_ctx[i].stream == head_pipe->stream &&
1365 !res_ctx->pipe_ctx[i].plane_state) {
1366 return &res_ctx->pipe_ctx[i];
1371 * At this point we have no re-useable pipe for this stream and we need
1372 * to acquire an idle one to satisfy the request
1375 if (!pool->funcs->acquire_idle_pipe_for_layer)
1378 return pool->funcs->acquire_idle_pipe_for_layer(context, pool, head_pipe->stream);
1381 #if defined(CONFIG_DRM_AMD_DC_DCN)
1382 static int acquire_first_split_pipe(
1383 struct resource_context *res_ctx,
1384 const struct resource_pool *pool,
1385 struct dc_stream_state *stream)
1389 for (i = 0; i < pool->pipe_count; i++) {
1390 struct pipe_ctx *split_pipe = &res_ctx->pipe_ctx[i];
1392 if (split_pipe->top_pipe &&
1393 split_pipe->top_pipe->plane_state == split_pipe->plane_state) {
1394 split_pipe->top_pipe->bottom_pipe = split_pipe->bottom_pipe;
1395 if (split_pipe->bottom_pipe)
1396 split_pipe->bottom_pipe->top_pipe = split_pipe->top_pipe;
1398 if (split_pipe->top_pipe->plane_state)
1399 resource_build_scaling_params(split_pipe->top_pipe);
1401 memset(split_pipe, 0, sizeof(*split_pipe));
1402 split_pipe->stream_res.tg = pool->timing_generators[i];
1403 split_pipe->plane_res.hubp = pool->hubps[i];
1404 split_pipe->plane_res.ipp = pool->ipps[i];
1405 split_pipe->plane_res.dpp = pool->dpps[i];
1406 split_pipe->stream_res.opp = pool->opps[i];
1407 split_pipe->plane_res.mpcc_inst = pool->dpps[i]->inst;
1408 split_pipe->pipe_idx = i;
1410 split_pipe->stream = stream;
1418 bool dc_add_plane_to_context(
1419 const struct dc *dc,
1420 struct dc_stream_state *stream,
1421 struct dc_plane_state *plane_state,
1422 struct dc_state *context)
1425 struct resource_pool *pool = dc->res_pool;
1426 struct pipe_ctx *head_pipe, *tail_pipe, *free_pipe;
1427 struct dc_stream_status *stream_status = NULL;
1429 for (i = 0; i < context->stream_count; i++)
1430 if (context->streams[i] == stream) {
1431 stream_status = &context->stream_status[i];
1434 if (stream_status == NULL) {
1435 dm_error("Existing stream not found; failed to attach surface!\n");
1440 if (stream_status->plane_count == MAX_SURFACE_NUM) {
1441 dm_error("Surface: can not attach plane_state %p! Maximum is: %d\n",
1442 plane_state, MAX_SURFACE_NUM);
1446 head_pipe = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
1449 dm_error("Head pipe not found for stream_state %p !\n", stream);
1453 /* retain new surface, but only once per stream */
1454 dc_plane_state_retain(plane_state);
1457 free_pipe = acquire_free_pipe_for_head(context, pool, head_pipe);
1459 #if defined(CONFIG_DRM_AMD_DC_DCN)
1461 int pipe_idx = acquire_first_split_pipe(&context->res_ctx, pool, stream);
1463 free_pipe = &context->res_ctx.pipe_ctx[pipe_idx];
1467 dc_plane_state_release(plane_state);
1471 free_pipe->plane_state = plane_state;
1473 if (head_pipe != free_pipe) {
1474 tail_pipe = resource_get_tail_pipe(&context->res_ctx, head_pipe);
1476 free_pipe->stream_res.tg = tail_pipe->stream_res.tg;
1477 free_pipe->stream_res.abm = tail_pipe->stream_res.abm;
1478 free_pipe->stream_res.opp = tail_pipe->stream_res.opp;
1479 free_pipe->stream_res.stream_enc = tail_pipe->stream_res.stream_enc;
1480 free_pipe->stream_res.audio = tail_pipe->stream_res.audio;
1481 free_pipe->clock_source = tail_pipe->clock_source;
1482 free_pipe->top_pipe = tail_pipe;
1483 tail_pipe->bottom_pipe = free_pipe;
1485 head_pipe = head_pipe->next_odm_pipe;
1487 /* assign new surfaces*/
1488 stream_status->plane_states[stream_status->plane_count] = plane_state;
1490 stream_status->plane_count++;
1495 bool dc_remove_plane_from_context(
1496 const struct dc *dc,
1497 struct dc_stream_state *stream,
1498 struct dc_plane_state *plane_state,
1499 struct dc_state *context)
1502 struct dc_stream_status *stream_status = NULL;
1503 struct resource_pool *pool = dc->res_pool;
1505 for (i = 0; i < context->stream_count; i++)
1506 if (context->streams[i] == stream) {
1507 stream_status = &context->stream_status[i];
1511 if (stream_status == NULL) {
1512 dm_error("Existing stream not found; failed to remove plane.\n");
1516 /* release pipe for plane*/
1517 for (i = pool->pipe_count - 1; i >= 0; i--) {
1518 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1520 if (pipe_ctx->plane_state == plane_state) {
1521 if (pipe_ctx->top_pipe)
1522 pipe_ctx->top_pipe->bottom_pipe = pipe_ctx->bottom_pipe;
1524 /* Second condition is to avoid setting NULL to top pipe
1525 * of tail pipe making it look like head pipe in subsequent
1528 if (pipe_ctx->bottom_pipe && pipe_ctx->top_pipe)
1529 pipe_ctx->bottom_pipe->top_pipe = pipe_ctx->top_pipe;
1532 * For head pipe detach surfaces from pipe for tail
1533 * pipe just zero it out
1535 if (!pipe_ctx->top_pipe)
1536 pipe_ctx->plane_state = NULL;
1538 memset(pipe_ctx, 0, sizeof(*pipe_ctx));
1543 for (i = 0; i < stream_status->plane_count; i++) {
1544 if (stream_status->plane_states[i] == plane_state) {
1546 dc_plane_state_release(stream_status->plane_states[i]);
1551 if (i == stream_status->plane_count) {
1552 dm_error("Existing plane_state not found; failed to detach it!\n");
1556 stream_status->plane_count--;
1558 /* Start at the plane we've just released, and move all the planes one index forward to "trim" the array */
1559 for (; i < stream_status->plane_count; i++)
1560 stream_status->plane_states[i] = stream_status->plane_states[i + 1];
1562 stream_status->plane_states[stream_status->plane_count] = NULL;
1567 bool dc_rem_all_planes_for_stream(
1568 const struct dc *dc,
1569 struct dc_stream_state *stream,
1570 struct dc_state *context)
1572 int i, old_plane_count;
1573 struct dc_stream_status *stream_status = NULL;
1574 struct dc_plane_state *del_planes[MAX_SURFACE_NUM] = { 0 };
1576 for (i = 0; i < context->stream_count; i++)
1577 if (context->streams[i] == stream) {
1578 stream_status = &context->stream_status[i];
1582 if (stream_status == NULL) {
1583 dm_error("Existing stream %p not found!\n", stream);
1587 old_plane_count = stream_status->plane_count;
1589 for (i = 0; i < old_plane_count; i++)
1590 del_planes[i] = stream_status->plane_states[i];
1592 for (i = 0; i < old_plane_count; i++)
1593 if (!dc_remove_plane_from_context(dc, stream, del_planes[i], context))
1599 static bool add_all_planes_for_stream(
1600 const struct dc *dc,
1601 struct dc_stream_state *stream,
1602 const struct dc_validation_set set[],
1604 struct dc_state *context)
1608 for (i = 0; i < set_count; i++)
1609 if (set[i].stream == stream)
1612 if (i == set_count) {
1613 dm_error("Stream %p not found in set!\n", stream);
1617 for (j = 0; j < set[i].plane_count; j++)
1618 if (!dc_add_plane_to_context(dc, stream, set[i].plane_states[j], context))
1624 bool dc_add_all_planes_for_stream(
1625 const struct dc *dc,
1626 struct dc_stream_state *stream,
1627 struct dc_plane_state * const *plane_states,
1629 struct dc_state *context)
1631 struct dc_validation_set set;
1634 set.stream = stream;
1635 set.plane_count = plane_count;
1637 for (i = 0; i < plane_count; i++)
1638 set.plane_states[i] = plane_states[i];
1640 return add_all_planes_for_stream(dc, stream, &set, 1, context);
1643 static bool is_timing_changed(struct dc_stream_state *cur_stream,
1644 struct dc_stream_state *new_stream)
1646 if (cur_stream == NULL)
1649 /* If sink pointer changed, it means this is a hotplug, we should do
1652 if (cur_stream->sink != new_stream->sink)
1655 /* If output color space is changed, need to reprogram info frames */
1656 if (cur_stream->output_color_space != new_stream->output_color_space)
1660 &cur_stream->timing,
1661 &new_stream->timing,
1662 sizeof(struct dc_crtc_timing)) != 0;
1665 static bool are_stream_backends_same(
1666 struct dc_stream_state *stream_a, struct dc_stream_state *stream_b)
1668 if (stream_a == stream_b)
1671 if (stream_a == NULL || stream_b == NULL)
1674 if (is_timing_changed(stream_a, stream_b))
1677 if (stream_a->dpms_off != stream_b->dpms_off)
1684 * dc_is_stream_unchanged() - Compare two stream states for equivalence.
1686 * Checks if there a difference between the two states
1687 * that would require a mode change.
1689 * Does not compare cursor position or attributes.
1691 bool dc_is_stream_unchanged(
1692 struct dc_stream_state *old_stream, struct dc_stream_state *stream)
1695 if (!are_stream_backends_same(old_stream, stream))
1698 if (old_stream->ignore_msa_timing_param != stream->ignore_msa_timing_param)
1705 * dc_is_stream_scaling_unchanged() - Compare scaling rectangles of two streams.
1707 bool dc_is_stream_scaling_unchanged(
1708 struct dc_stream_state *old_stream, struct dc_stream_state *stream)
1710 if (old_stream == stream)
1713 if (old_stream == NULL || stream == NULL)
1716 if (memcmp(&old_stream->src,
1718 sizeof(struct rect)) != 0)
1721 if (memcmp(&old_stream->dst,
1723 sizeof(struct rect)) != 0)
1729 static void update_stream_engine_usage(
1730 struct resource_context *res_ctx,
1731 const struct resource_pool *pool,
1732 struct stream_encoder *stream_enc,
1737 for (i = 0; i < pool->stream_enc_count; i++) {
1738 if (pool->stream_enc[i] == stream_enc)
1739 res_ctx->is_stream_enc_acquired[i] = acquired;
1743 /* TODO: release audio object */
1744 void update_audio_usage(
1745 struct resource_context *res_ctx,
1746 const struct resource_pool *pool,
1747 struct audio *audio,
1751 for (i = 0; i < pool->audio_count; i++) {
1752 if (pool->audios[i] == audio)
1753 res_ctx->is_audio_acquired[i] = acquired;
1757 static int acquire_first_free_pipe(
1758 struct resource_context *res_ctx,
1759 const struct resource_pool *pool,
1760 struct dc_stream_state *stream)
1764 for (i = 0; i < pool->pipe_count; i++) {
1765 if (!res_ctx->pipe_ctx[i].stream) {
1766 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
1768 pipe_ctx->stream_res.tg = pool->timing_generators[i];
1769 pipe_ctx->plane_res.mi = pool->mis[i];
1770 pipe_ctx->plane_res.hubp = pool->hubps[i];
1771 pipe_ctx->plane_res.ipp = pool->ipps[i];
1772 pipe_ctx->plane_res.xfm = pool->transforms[i];
1773 pipe_ctx->plane_res.dpp = pool->dpps[i];
1774 pipe_ctx->stream_res.opp = pool->opps[i];
1776 pipe_ctx->plane_res.mpcc_inst = pool->dpps[i]->inst;
1777 pipe_ctx->pipe_idx = i;
1780 pipe_ctx->stream = stream;
1787 static struct audio *find_first_free_audio(
1788 struct resource_context *res_ctx,
1789 const struct resource_pool *pool,
1791 enum dce_version dc_version)
1793 int i, available_audio_count;
1795 available_audio_count = pool->audio_count;
1797 for (i = 0; i < available_audio_count; i++) {
1798 if ((res_ctx->is_audio_acquired[i] == false) && (res_ctx->is_stream_enc_acquired[i] == true)) {
1799 /*we have enough audio endpoint, find the matching inst*/
1802 return pool->audios[i];
1806 /* use engine id to find free audio */
1807 if ((id < available_audio_count) && (res_ctx->is_audio_acquired[id] == false)) {
1808 return pool->audios[id];
1810 /*not found the matching one, first come first serve*/
1811 for (i = 0; i < available_audio_count; i++) {
1812 if (res_ctx->is_audio_acquired[i] == false) {
1813 return pool->audios[i];
1820 * dc_add_stream_to_ctx() - Add a new dc_stream_state to a dc_state.
1822 enum dc_status dc_add_stream_to_ctx(
1824 struct dc_state *new_ctx,
1825 struct dc_stream_state *stream)
1828 DC_LOGGER_INIT(dc->ctx->logger);
1830 if (new_ctx->stream_count >= dc->res_pool->timing_generator_count) {
1831 DC_LOG_WARNING("Max streams reached, can't add stream %p !\n", stream);
1832 return DC_ERROR_UNEXPECTED;
1835 new_ctx->streams[new_ctx->stream_count] = stream;
1836 dc_stream_retain(stream);
1837 new_ctx->stream_count++;
1839 res = dc->res_pool->funcs->add_stream_to_ctx(dc, new_ctx, stream);
1841 DC_LOG_WARNING("Adding stream %p to context failed with err %d!\n", stream, res);
1847 * dc_remove_stream_from_ctx() - Remove a stream from a dc_state.
1849 enum dc_status dc_remove_stream_from_ctx(
1851 struct dc_state *new_ctx,
1852 struct dc_stream_state *stream)
1855 struct dc_context *dc_ctx = dc->ctx;
1856 struct pipe_ctx *del_pipe = resource_get_head_pipe_for_stream(&new_ctx->res_ctx, stream);
1857 struct pipe_ctx *odm_pipe;
1860 DC_ERROR("Pipe not found for stream %p !\n", stream);
1861 return DC_ERROR_UNEXPECTED;
1864 odm_pipe = del_pipe->next_odm_pipe;
1866 /* Release primary pipe */
1867 ASSERT(del_pipe->stream_res.stream_enc);
1868 update_stream_engine_usage(
1871 del_pipe->stream_res.stream_enc,
1874 if (del_pipe->stream_res.audio)
1878 del_pipe->stream_res.audio,
1881 resource_unreference_clock_source(&new_ctx->res_ctx,
1883 del_pipe->clock_source);
1885 if (dc->res_pool->funcs->remove_stream_from_ctx)
1886 dc->res_pool->funcs->remove_stream_from_ctx(dc, new_ctx, stream);
1889 struct pipe_ctx *next_odm_pipe = odm_pipe->next_odm_pipe;
1891 memset(odm_pipe, 0, sizeof(*odm_pipe));
1892 odm_pipe = next_odm_pipe;
1894 memset(del_pipe, 0, sizeof(*del_pipe));
1896 for (i = 0; i < new_ctx->stream_count; i++)
1897 if (new_ctx->streams[i] == stream)
1900 if (new_ctx->streams[i] != stream) {
1901 DC_ERROR("Context doesn't have stream %p !\n", stream);
1902 return DC_ERROR_UNEXPECTED;
1905 dc_stream_release(new_ctx->streams[i]);
1906 new_ctx->stream_count--;
1908 /* Trim back arrays */
1909 for (; i < new_ctx->stream_count; i++) {
1910 new_ctx->streams[i] = new_ctx->streams[i + 1];
1911 new_ctx->stream_status[i] = new_ctx->stream_status[i + 1];
1914 new_ctx->streams[new_ctx->stream_count] = NULL;
1916 &new_ctx->stream_status[new_ctx->stream_count],
1918 sizeof(new_ctx->stream_status[0]));
1923 static struct dc_stream_state *find_pll_sharable_stream(
1924 struct dc_stream_state *stream_needs_pll,
1925 struct dc_state *context)
1929 for (i = 0; i < context->stream_count; i++) {
1930 struct dc_stream_state *stream_has_pll = context->streams[i];
1932 /* We are looking for non dp, non virtual stream */
1933 if (resource_are_streams_timing_synchronizable(
1934 stream_needs_pll, stream_has_pll)
1935 && !dc_is_dp_signal(stream_has_pll->signal)
1936 && stream_has_pll->link->connector_signal
1937 != SIGNAL_TYPE_VIRTUAL)
1938 return stream_has_pll;
1945 static int get_norm_pix_clk(const struct dc_crtc_timing *timing)
1947 uint32_t pix_clk = timing->pix_clk_100hz;
1948 uint32_t normalized_pix_clk = pix_clk;
1950 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
1952 if (timing->pixel_encoding != PIXEL_ENCODING_YCBCR422) {
1953 switch (timing->display_color_depth) {
1954 case COLOR_DEPTH_666:
1955 case COLOR_DEPTH_888:
1956 normalized_pix_clk = pix_clk;
1958 case COLOR_DEPTH_101010:
1959 normalized_pix_clk = (pix_clk * 30) / 24;
1961 case COLOR_DEPTH_121212:
1962 normalized_pix_clk = (pix_clk * 36) / 24;
1964 case COLOR_DEPTH_161616:
1965 normalized_pix_clk = (pix_clk * 48) / 24;
1972 return normalized_pix_clk;
1975 static void calculate_phy_pix_clks(struct dc_stream_state *stream)
1977 /* update actual pixel clock on all streams */
1978 if (dc_is_hdmi_signal(stream->signal))
1979 stream->phy_pix_clk = get_norm_pix_clk(
1980 &stream->timing) / 10;
1982 stream->phy_pix_clk =
1983 stream->timing.pix_clk_100hz / 10;
1985 if (stream->timing.timing_3d_format == TIMING_3D_FORMAT_HW_FRAME_PACKING)
1986 stream->phy_pix_clk *= 2;
1989 static int acquire_resource_from_hw_enabled_state(
1990 struct resource_context *res_ctx,
1991 const struct resource_pool *pool,
1992 struct dc_stream_state *stream)
1994 struct dc_link *link = stream->link;
1995 unsigned int i, inst, tg_inst = 0;
1997 /* Check for enabled DIG to identify enabled display */
1998 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
2001 inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
2003 if (inst == ENGINE_ID_UNKNOWN)
2006 for (i = 0; i < pool->stream_enc_count; i++) {
2007 if (pool->stream_enc[i]->id == inst) {
2008 tg_inst = pool->stream_enc[i]->funcs->dig_source_otg(
2009 pool->stream_enc[i]);
2014 // tg_inst not found
2015 if (i == pool->stream_enc_count)
2018 if (tg_inst >= pool->timing_generator_count)
2021 if (!res_ctx->pipe_ctx[tg_inst].stream) {
2022 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[tg_inst];
2024 pipe_ctx->stream_res.tg = pool->timing_generators[tg_inst];
2025 pipe_ctx->plane_res.mi = pool->mis[tg_inst];
2026 pipe_ctx->plane_res.hubp = pool->hubps[tg_inst];
2027 pipe_ctx->plane_res.ipp = pool->ipps[tg_inst];
2028 pipe_ctx->plane_res.xfm = pool->transforms[tg_inst];
2029 pipe_ctx->plane_res.dpp = pool->dpps[tg_inst];
2030 pipe_ctx->stream_res.opp = pool->opps[tg_inst];
2032 if (pool->dpps[tg_inst]) {
2033 pipe_ctx->plane_res.mpcc_inst = pool->dpps[tg_inst]->inst;
2035 // Read DPP->MPCC->OPP Pipe from HW State
2036 if (pool->mpc->funcs->read_mpcc_state) {
2037 struct mpcc_state s = {0};
2039 pool->mpc->funcs->read_mpcc_state(pool->mpc, pipe_ctx->plane_res.mpcc_inst, &s);
2041 if (s.dpp_id < MAX_MPCC)
2042 pool->mpc->mpcc_array[pipe_ctx->plane_res.mpcc_inst].dpp_id = s.dpp_id;
2044 if (s.bot_mpcc_id < MAX_MPCC)
2045 pool->mpc->mpcc_array[pipe_ctx->plane_res.mpcc_inst].mpcc_bot =
2046 &pool->mpc->mpcc_array[s.bot_mpcc_id];
2048 if (s.opp_id < MAX_OPP)
2049 pipe_ctx->stream_res.opp->mpc_tree_params.opp_id = s.opp_id;
2052 pipe_ctx->pipe_idx = tg_inst;
2054 pipe_ctx->stream = stream;
2061 enum dc_status resource_map_pool_resources(
2062 const struct dc *dc,
2063 struct dc_state *context,
2064 struct dc_stream_state *stream)
2066 const struct resource_pool *pool = dc->res_pool;
2068 struct dc_context *dc_ctx = dc->ctx;
2069 struct pipe_ctx *pipe_ctx = NULL;
2071 struct dc_bios *dcb = dc->ctx->dc_bios;
2073 calculate_phy_pix_clks(stream);
2075 /* TODO: Check Linux */
2076 if (dc->config.allow_seamless_boot_optimization &&
2077 !dcb->funcs->is_accelerated_mode(dcb)) {
2078 if (dc_validate_seamless_boot_timing(dc, stream->sink, &stream->timing))
2079 stream->apply_seamless_boot_optimization = true;
2082 if (stream->apply_seamless_boot_optimization)
2083 pipe_idx = acquire_resource_from_hw_enabled_state(
2089 /* acquire new resources */
2090 pipe_idx = acquire_first_free_pipe(&context->res_ctx, pool, stream);
2092 #ifdef CONFIG_DRM_AMD_DC_DCN
2094 pipe_idx = acquire_first_split_pipe(&context->res_ctx, pool, stream);
2097 if (pipe_idx < 0 || context->res_ctx.pipe_ctx[pipe_idx].stream_res.tg == NULL)
2098 return DC_NO_CONTROLLER_RESOURCE;
2100 pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2102 pipe_ctx->stream_res.stream_enc =
2103 dc->res_pool->funcs->find_first_free_match_stream_enc_for_link(
2104 &context->res_ctx, pool, stream);
2106 if (!pipe_ctx->stream_res.stream_enc)
2107 return DC_NO_STREAM_ENC_RESOURCE;
2109 update_stream_engine_usage(
2110 &context->res_ctx, pool,
2111 pipe_ctx->stream_res.stream_enc,
2114 /* TODO: Add check if ASIC support and EDID audio */
2115 if (!stream->converter_disable_audio &&
2116 dc_is_audio_capable_signal(pipe_ctx->stream->signal) &&
2117 stream->audio_info.mode_count && stream->audio_info.flags.all) {
2118 pipe_ctx->stream_res.audio = find_first_free_audio(
2119 &context->res_ctx, pool, pipe_ctx->stream_res.stream_enc->id, dc_ctx->dce_version);
2122 * Audio assigned in order first come first get.
2123 * There are asics which has number of audio
2124 * resources less then number of pipes
2126 if (pipe_ctx->stream_res.audio)
2127 update_audio_usage(&context->res_ctx, pool,
2128 pipe_ctx->stream_res.audio, true);
2131 /* Add ABM to the resource if on EDP */
2132 if (pipe_ctx->stream && dc_is_embedded_signal(pipe_ctx->stream->signal)) {
2133 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2135 pipe_ctx->stream_res.abm = pool->abm;
2137 pipe_ctx->stream_res.abm = pool->multiple_abms[pipe_ctx->stream_res.tg->inst];
2139 pipe_ctx->stream_res.abm = pool->abm;
2143 for (i = 0; i < context->stream_count; i++)
2144 if (context->streams[i] == stream) {
2145 context->stream_status[i].primary_otg_inst = pipe_ctx->stream_res.tg->inst;
2146 context->stream_status[i].stream_enc_inst = pipe_ctx->stream_res.stream_enc->stream_enc_inst;
2147 context->stream_status[i].audio_inst =
2148 pipe_ctx->stream_res.audio ? pipe_ctx->stream_res.audio->inst : -1;
2153 DC_ERROR("Stream %p not found in new ctx!\n", stream);
2154 return DC_ERROR_UNEXPECTED;
2158 * dc_resource_state_copy_construct_current() - Creates a new dc_state from existing state
2159 * Is a shallow copy. Increments refcounts on existing streams and planes.
2160 * @dc: copy out of dc->current_state
2161 * @dst_ctx: copy into this
2163 void dc_resource_state_copy_construct_current(
2164 const struct dc *dc,
2165 struct dc_state *dst_ctx)
2167 dc_resource_state_copy_construct(dc->current_state, dst_ctx);
2171 void dc_resource_state_construct(
2172 const struct dc *dc,
2173 struct dc_state *dst_ctx)
2175 dst_ctx->clk_mgr = dc->clk_mgr;
2179 bool dc_resource_is_dsc_encoding_supported(const struct dc *dc)
2181 return dc->res_pool->res_cap->num_dsc > 0;
2186 * dc_validate_global_state() - Determine if HW can support a given state
2187 * Checks HW resource availability and bandwidth requirement.
2188 * @dc: dc struct for this driver
2189 * @new_ctx: state to be validated
2190 * @fast_validate: set to true if only yes/no to support matters
2192 * Return: DC_OK if the result can be programmed. Otherwise, an error code.
2194 enum dc_status dc_validate_global_state(
2196 struct dc_state *new_ctx,
2199 enum dc_status result = DC_ERROR_UNEXPECTED;
2203 return DC_ERROR_UNEXPECTED;
2205 if (dc->res_pool->funcs->validate_global) {
2206 result = dc->res_pool->funcs->validate_global(dc, new_ctx);
2207 if (result != DC_OK)
2211 for (i = 0; i < new_ctx->stream_count; i++) {
2212 struct dc_stream_state *stream = new_ctx->streams[i];
2214 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2215 struct pipe_ctx *pipe_ctx = &new_ctx->res_ctx.pipe_ctx[j];
2217 if (pipe_ctx->stream != stream)
2220 if (dc->res_pool->funcs->patch_unknown_plane_state &&
2221 pipe_ctx->plane_state &&
2222 pipe_ctx->plane_state->tiling_info.gfx9.swizzle == DC_SW_UNKNOWN) {
2223 result = dc->res_pool->funcs->patch_unknown_plane_state(pipe_ctx->plane_state);
2224 if (result != DC_OK)
2228 /* Switch to dp clock source only if there is
2229 * no non dp stream that shares the same timing
2230 * with the dp stream.
2232 if (dc_is_dp_signal(pipe_ctx->stream->signal) &&
2233 !find_pll_sharable_stream(stream, new_ctx)) {
2235 resource_unreference_clock_source(
2238 pipe_ctx->clock_source);
2240 pipe_ctx->clock_source = dc->res_pool->dp_clock_source;
2241 resource_reference_clock_source(
2244 pipe_ctx->clock_source);
2249 result = resource_build_scaling_params_for_context(dc, new_ctx);
2251 if (result == DC_OK)
2252 if (!dc->res_pool->funcs->validate_bandwidth(dc, new_ctx, fast_validate))
2253 result = DC_FAIL_BANDWIDTH_VALIDATE;
2258 static void patch_gamut_packet_checksum(
2259 struct dc_info_packet *gamut_packet)
2261 /* For gamut we recalc checksum */
2262 if (gamut_packet->valid) {
2263 uint8_t chk_sum = 0;
2267 /*start of the Gamut data. */
2268 ptr = &gamut_packet->sb[3];
2270 for (i = 0; i <= gamut_packet->sb[1]; i++)
2273 gamut_packet->sb[2] = (uint8_t) (0x100 - chk_sum);
2277 static void set_avi_info_frame(
2278 struct dc_info_packet *info_packet,
2279 struct pipe_ctx *pipe_ctx)
2281 struct dc_stream_state *stream = pipe_ctx->stream;
2282 enum dc_color_space color_space = COLOR_SPACE_UNKNOWN;
2283 uint32_t pixel_encoding = 0;
2284 enum scanning_type scan_type = SCANNING_TYPE_NODATA;
2285 enum dc_aspect_ratio aspect = ASPECT_RATIO_NO_DATA;
2287 uint8_t itc_value = 0;
2288 uint8_t cn0_cn1 = 0;
2289 unsigned int cn0_cn1_value = 0;
2290 uint8_t *check_sum = NULL;
2291 uint8_t byte_index = 0;
2292 union hdmi_info_packet hdmi_info;
2293 union display_content_support support = {0};
2294 unsigned int vic = pipe_ctx->stream->timing.vic;
2295 enum dc_timing_3d_format format;
2297 memset(&hdmi_info, 0, sizeof(union hdmi_info_packet));
2299 color_space = pipe_ctx->stream->output_color_space;
2300 if (color_space == COLOR_SPACE_UNKNOWN)
2301 color_space = (stream->timing.pixel_encoding == PIXEL_ENCODING_RGB) ?
2302 COLOR_SPACE_SRGB:COLOR_SPACE_YCBCR709;
2304 /* Initialize header */
2305 hdmi_info.bits.header.info_frame_type = HDMI_INFOFRAME_TYPE_AVI;
2306 /* InfoFrameVersion_3 is defined by CEA861F (Section 6.4), but shall
2307 * not be used in HDMI 2.0 (Section 10.1) */
2308 hdmi_info.bits.header.version = 2;
2309 hdmi_info.bits.header.length = HDMI_AVI_INFOFRAME_SIZE;
2312 * IDO-defined (Y2,Y1,Y0 = 1,1,1) shall not be used by devices built
2313 * according to HDMI 2.0 spec (Section 10.1)
2316 switch (stream->timing.pixel_encoding) {
2317 case PIXEL_ENCODING_YCBCR422:
2321 case PIXEL_ENCODING_YCBCR444:
2324 case PIXEL_ENCODING_YCBCR420:
2328 case PIXEL_ENCODING_RGB:
2333 /* Y0_Y1_Y2 : The pixel encoding */
2334 /* H14b AVI InfoFrame has extension on Y-field from 2 bits to 3 bits */
2335 hdmi_info.bits.Y0_Y1_Y2 = pixel_encoding;
2337 /* A0 = 1 Active Format Information valid */
2338 hdmi_info.bits.A0 = ACTIVE_FORMAT_VALID;
2340 /* B0, B1 = 3; Bar info data is valid */
2341 hdmi_info.bits.B0_B1 = BAR_INFO_BOTH_VALID;
2343 hdmi_info.bits.SC0_SC1 = PICTURE_SCALING_UNIFORM;
2345 /* S0, S1 : Underscan / Overscan */
2346 /* TODO: un-hardcode scan type */
2347 scan_type = SCANNING_TYPE_UNDERSCAN;
2348 hdmi_info.bits.S0_S1 = scan_type;
2350 /* C0, C1 : Colorimetry */
2351 if (color_space == COLOR_SPACE_YCBCR709 ||
2352 color_space == COLOR_SPACE_YCBCR709_LIMITED)
2353 hdmi_info.bits.C0_C1 = COLORIMETRY_ITU709;
2354 else if (color_space == COLOR_SPACE_YCBCR601 ||
2355 color_space == COLOR_SPACE_YCBCR601_LIMITED)
2356 hdmi_info.bits.C0_C1 = COLORIMETRY_ITU601;
2358 hdmi_info.bits.C0_C1 = COLORIMETRY_NO_DATA;
2360 if (color_space == COLOR_SPACE_2020_RGB_FULLRANGE ||
2361 color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE ||
2362 color_space == COLOR_SPACE_2020_YCBCR) {
2363 hdmi_info.bits.EC0_EC2 = COLORIMETRYEX_BT2020RGBYCBCR;
2364 hdmi_info.bits.C0_C1 = COLORIMETRY_EXTENDED;
2365 } else if (color_space == COLOR_SPACE_ADOBERGB) {
2366 hdmi_info.bits.EC0_EC2 = COLORIMETRYEX_ADOBERGB;
2367 hdmi_info.bits.C0_C1 = COLORIMETRY_EXTENDED;
2370 /* TODO: un-hardcode aspect ratio */
2371 aspect = stream->timing.aspect_ratio;
2374 case ASPECT_RATIO_4_3:
2375 case ASPECT_RATIO_16_9:
2376 hdmi_info.bits.M0_M1 = aspect;
2379 case ASPECT_RATIO_NO_DATA:
2380 case ASPECT_RATIO_64_27:
2381 case ASPECT_RATIO_256_135:
2383 hdmi_info.bits.M0_M1 = 0;
2386 /* Active Format Aspect ratio - same as Picture Aspect Ratio. */
2387 hdmi_info.bits.R0_R3 = ACTIVE_FORMAT_ASPECT_RATIO_SAME_AS_PICTURE;
2389 /* TODO: un-hardcode cn0_cn1 and itc */
2397 support = stream->content_support;
2400 if (!support.bits.valid_content_type) {
2403 if (cn0_cn1 == DISPLAY_CONTENT_TYPE_GRAPHICS) {
2404 if (support.bits.graphics_content == 1) {
2407 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_PHOTO) {
2408 if (support.bits.photo_content == 1) {
2414 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_CINEMA) {
2415 if (support.bits.cinema_content == 1) {
2421 } else if (cn0_cn1 == DISPLAY_CONTENT_TYPE_GAME) {
2422 if (support.bits.game_content == 1) {
2430 hdmi_info.bits.CN0_CN1 = cn0_cn1_value;
2431 hdmi_info.bits.ITC = itc_value;
2434 /* TODO : We should handle YCC quantization */
2435 /* but we do not have matrix calculation */
2436 if (stream->qs_bit == 1 &&
2437 stream->qy_bit == 1) {
2438 if (color_space == COLOR_SPACE_SRGB ||
2439 color_space == COLOR_SPACE_2020_RGB_FULLRANGE) {
2440 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_FULL_RANGE;
2441 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2442 } else if (color_space == COLOR_SPACE_SRGB_LIMITED ||
2443 color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE) {
2444 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_LIMITED_RANGE;
2445 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2447 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_DEFAULT_RANGE;
2448 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2451 hdmi_info.bits.Q0_Q1 = RGB_QUANTIZATION_DEFAULT_RANGE;
2452 hdmi_info.bits.YQ0_YQ1 = YYC_QUANTIZATION_LIMITED_RANGE;
2456 format = stream->timing.timing_3d_format;
2457 /*todo, add 3DStereo support*/
2458 if (format != TIMING_3D_FORMAT_NONE) {
2459 // Based on HDMI specs hdmi vic needs to be converted to cea vic when 3D is enabled
2460 switch (pipe_ctx->stream->timing.hdmi_vic) {
2477 /* If VIC >= 128, the Source shall use AVI InfoFrame Version 3*/
2478 hdmi_info.bits.VIC0_VIC7 = vic;
2480 hdmi_info.bits.header.version = 3;
2481 /* If (C1, C0)=(1, 1) and (EC2, EC1, EC0)=(1, 1, 1),
2482 * the Source shall use 20 AVI InfoFrame Version 4
2484 if (hdmi_info.bits.C0_C1 == COLORIMETRY_EXTENDED &&
2485 hdmi_info.bits.EC0_EC2 == COLORIMETRYEX_RESERVED) {
2486 hdmi_info.bits.header.version = 4;
2487 hdmi_info.bits.header.length = 14;
2491 * PR0 - PR3 start from 0 whereas pHwPathMode->mode.timing.flags.pixel
2492 * repetition start from 1 */
2493 hdmi_info.bits.PR0_PR3 = 0;
2496 * barTop: Line Number of End of Top Bar.
2497 * barBottom: Line Number of Start of Bottom Bar.
2498 * barLeft: Pixel Number of End of Left Bar.
2499 * barRight: Pixel Number of Start of Right Bar. */
2500 hdmi_info.bits.bar_top = stream->timing.v_border_top;
2501 hdmi_info.bits.bar_bottom = (stream->timing.v_total
2502 - stream->timing.v_border_bottom + 1);
2503 hdmi_info.bits.bar_left = stream->timing.h_border_left;
2504 hdmi_info.bits.bar_right = (stream->timing.h_total
2505 - stream->timing.h_border_right + 1);
2507 /* Additional Colorimetry Extension
2508 * Used in conduction with C0-C1 and EC0-EC2
2509 * 0 = DCI-P3 RGB (D65)
2510 * 1 = DCI-P3 RGB (theater)
2512 hdmi_info.bits.ACE0_ACE3 = 0;
2514 /* check_sum - Calculate AFMT_AVI_INFO0 ~ AFMT_AVI_INFO3 */
2515 check_sum = &hdmi_info.packet_raw_data.sb[0];
2517 *check_sum = HDMI_INFOFRAME_TYPE_AVI + hdmi_info.bits.header.length + hdmi_info.bits.header.version;
2519 for (byte_index = 1; byte_index <= hdmi_info.bits.header.length; byte_index++)
2520 *check_sum += hdmi_info.packet_raw_data.sb[byte_index];
2522 /* one byte complement */
2523 *check_sum = (uint8_t) (0x100 - *check_sum);
2525 /* Store in hw_path_mode */
2526 info_packet->hb0 = hdmi_info.packet_raw_data.hb0;
2527 info_packet->hb1 = hdmi_info.packet_raw_data.hb1;
2528 info_packet->hb2 = hdmi_info.packet_raw_data.hb2;
2530 for (byte_index = 0; byte_index < sizeof(hdmi_info.packet_raw_data.sb); byte_index++)
2531 info_packet->sb[byte_index] = hdmi_info.packet_raw_data.sb[byte_index];
2533 info_packet->valid = true;
2536 static void set_vendor_info_packet(
2537 struct dc_info_packet *info_packet,
2538 struct dc_stream_state *stream)
2540 /* SPD info packet for FreeSync */
2542 /* Check if Freesync is supported. Return if false. If true,
2543 * set the corresponding bit in the info packet
2545 if (!stream->vsp_infopacket.valid)
2548 *info_packet = stream->vsp_infopacket;
2551 static void set_spd_info_packet(
2552 struct dc_info_packet *info_packet,
2553 struct dc_stream_state *stream)
2555 /* SPD info packet for FreeSync */
2557 /* Check if Freesync is supported. Return if false. If true,
2558 * set the corresponding bit in the info packet
2560 if (!stream->vrr_infopacket.valid)
2563 *info_packet = stream->vrr_infopacket;
2566 static void set_hdr_static_info_packet(
2567 struct dc_info_packet *info_packet,
2568 struct dc_stream_state *stream)
2570 /* HDR Static Metadata info packet for HDR10 */
2572 if (!stream->hdr_static_metadata.valid ||
2573 stream->use_dynamic_meta)
2576 *info_packet = stream->hdr_static_metadata;
2579 static void set_vsc_info_packet(
2580 struct dc_info_packet *info_packet,
2581 struct dc_stream_state *stream)
2583 if (!stream->vsc_infopacket.valid)
2586 *info_packet = stream->vsc_infopacket;
2589 void dc_resource_state_destruct(struct dc_state *context)
2593 for (i = 0; i < context->stream_count; i++) {
2594 for (j = 0; j < context->stream_status[i].plane_count; j++)
2595 dc_plane_state_release(
2596 context->stream_status[i].plane_states[j]);
2598 context->stream_status[i].plane_count = 0;
2599 dc_stream_release(context->streams[i]);
2600 context->streams[i] = NULL;
2604 void dc_resource_state_copy_construct(
2605 const struct dc_state *src_ctx,
2606 struct dc_state *dst_ctx)
2609 struct kref refcount = dst_ctx->refcount;
2611 *dst_ctx = *src_ctx;
2613 for (i = 0; i < MAX_PIPES; i++) {
2614 struct pipe_ctx *cur_pipe = &dst_ctx->res_ctx.pipe_ctx[i];
2616 if (cur_pipe->top_pipe)
2617 cur_pipe->top_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
2619 if (cur_pipe->bottom_pipe)
2620 cur_pipe->bottom_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
2622 if (cur_pipe->next_odm_pipe)
2623 cur_pipe->next_odm_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
2625 if (cur_pipe->prev_odm_pipe)
2626 cur_pipe->prev_odm_pipe = &dst_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
2629 for (i = 0; i < dst_ctx->stream_count; i++) {
2630 dc_stream_retain(dst_ctx->streams[i]);
2631 for (j = 0; j < dst_ctx->stream_status[i].plane_count; j++)
2632 dc_plane_state_retain(
2633 dst_ctx->stream_status[i].plane_states[j]);
2636 /* context refcount should not be overridden */
2637 dst_ctx->refcount = refcount;
2641 struct clock_source *dc_resource_find_first_free_pll(
2642 struct resource_context *res_ctx,
2643 const struct resource_pool *pool)
2647 for (i = 0; i < pool->clk_src_count; ++i) {
2648 if (res_ctx->clock_source_ref_count[i] == 0)
2649 return pool->clock_sources[i];
2655 void resource_build_info_frame(struct pipe_ctx *pipe_ctx)
2657 enum signal_type signal = SIGNAL_TYPE_NONE;
2658 struct encoder_info_frame *info = &pipe_ctx->stream_res.encoder_info_frame;
2660 /* default all packets to invalid */
2661 info->avi.valid = false;
2662 info->gamut.valid = false;
2663 info->vendor.valid = false;
2664 info->spd.valid = false;
2665 info->hdrsmd.valid = false;
2666 info->vsc.valid = false;
2668 signal = pipe_ctx->stream->signal;
2670 /* HDMi and DP have different info packets*/
2671 if (dc_is_hdmi_signal(signal)) {
2672 set_avi_info_frame(&info->avi, pipe_ctx);
2674 set_vendor_info_packet(&info->vendor, pipe_ctx->stream);
2676 set_spd_info_packet(&info->spd, pipe_ctx->stream);
2678 set_hdr_static_info_packet(&info->hdrsmd, pipe_ctx->stream);
2680 } else if (dc_is_dp_signal(signal)) {
2681 set_vsc_info_packet(&info->vsc, pipe_ctx->stream);
2683 set_spd_info_packet(&info->spd, pipe_ctx->stream);
2685 set_hdr_static_info_packet(&info->hdrsmd, pipe_ctx->stream);
2688 patch_gamut_packet_checksum(&info->gamut);
2691 enum dc_status resource_map_clock_resources(
2692 const struct dc *dc,
2693 struct dc_state *context,
2694 struct dc_stream_state *stream)
2696 /* acquire new resources */
2697 const struct resource_pool *pool = dc->res_pool;
2698 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(
2699 &context->res_ctx, stream);
2702 return DC_ERROR_UNEXPECTED;
2704 if (dc_is_dp_signal(pipe_ctx->stream->signal)
2705 || pipe_ctx->stream->signal == SIGNAL_TYPE_VIRTUAL)
2706 pipe_ctx->clock_source = pool->dp_clock_source;
2708 pipe_ctx->clock_source = NULL;
2710 if (!dc->config.disable_disp_pll_sharing)
2711 pipe_ctx->clock_source = resource_find_used_clk_src_for_sharing(
2715 if (pipe_ctx->clock_source == NULL)
2716 pipe_ctx->clock_source =
2717 dc_resource_find_first_free_pll(
2722 if (pipe_ctx->clock_source == NULL)
2723 return DC_NO_CLOCK_SOURCE_RESOURCE;
2725 resource_reference_clock_source(
2726 &context->res_ctx, pool,
2727 pipe_ctx->clock_source);
2733 * Note: We need to disable output if clock sources change,
2734 * since bios does optimization and doesn't apply if changing
2735 * PHY when not already disabled.
2737 bool pipe_need_reprogram(
2738 struct pipe_ctx *pipe_ctx_old,
2739 struct pipe_ctx *pipe_ctx)
2741 if (!pipe_ctx_old->stream)
2744 if (pipe_ctx_old->stream->sink != pipe_ctx->stream->sink)
2747 if (pipe_ctx_old->stream->signal != pipe_ctx->stream->signal)
2750 if (pipe_ctx_old->stream_res.audio != pipe_ctx->stream_res.audio)
2753 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source
2754 && pipe_ctx_old->stream != pipe_ctx->stream)
2757 if (pipe_ctx_old->stream_res.stream_enc != pipe_ctx->stream_res.stream_enc)
2760 if (is_timing_changed(pipe_ctx_old->stream, pipe_ctx->stream))
2763 if (pipe_ctx_old->stream->dpms_off != pipe_ctx->stream->dpms_off)
2766 if (false == pipe_ctx_old->stream->link->link_state_valid &&
2767 false == pipe_ctx_old->stream->dpms_off)
2770 if (pipe_ctx_old->stream_res.dsc != pipe_ctx->stream_res.dsc)
2776 void resource_build_bit_depth_reduction_params(struct dc_stream_state *stream,
2777 struct bit_depth_reduction_params *fmt_bit_depth)
2779 enum dc_dither_option option = stream->dither_option;
2780 enum dc_pixel_encoding pixel_encoding =
2781 stream->timing.pixel_encoding;
2783 memset(fmt_bit_depth, 0, sizeof(*fmt_bit_depth));
2785 if (option == DITHER_OPTION_DEFAULT) {
2786 switch (stream->timing.display_color_depth) {
2787 case COLOR_DEPTH_666:
2788 option = DITHER_OPTION_SPATIAL6;
2790 case COLOR_DEPTH_888:
2791 option = DITHER_OPTION_SPATIAL8;
2793 case COLOR_DEPTH_101010:
2794 option = DITHER_OPTION_SPATIAL10;
2797 option = DITHER_OPTION_DISABLE;
2801 if (option == DITHER_OPTION_DISABLE)
2804 if (option == DITHER_OPTION_TRUN6) {
2805 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2806 fmt_bit_depth->flags.TRUNCATE_DEPTH = 0;
2807 } else if (option == DITHER_OPTION_TRUN8 ||
2808 option == DITHER_OPTION_TRUN8_SPATIAL6 ||
2809 option == DITHER_OPTION_TRUN8_FM6) {
2810 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2811 fmt_bit_depth->flags.TRUNCATE_DEPTH = 1;
2812 } else if (option == DITHER_OPTION_TRUN10 ||
2813 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
2814 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
2815 option == DITHER_OPTION_TRUN10_FM8 ||
2816 option == DITHER_OPTION_TRUN10_FM6 ||
2817 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
2818 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2819 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
2822 /* special case - Formatter can only reduce by 4 bits at most.
2823 * When reducing from 12 to 6 bits,
2824 * HW recommends we use trunc with round mode
2825 * (if we did nothing, trunc to 10 bits would be used)
2826 * note that any 12->10 bit reduction is ignored prior to DCE8,
2827 * as the input was 10 bits.
2829 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
2830 option == DITHER_OPTION_SPATIAL6 ||
2831 option == DITHER_OPTION_FM6) {
2832 fmt_bit_depth->flags.TRUNCATE_ENABLED = 1;
2833 fmt_bit_depth->flags.TRUNCATE_DEPTH = 2;
2834 fmt_bit_depth->flags.TRUNCATE_MODE = 1;
2838 * note that spatial modes 1-3 are never used
2840 if (option == DITHER_OPTION_SPATIAL6_FRAME_RANDOM ||
2841 option == DITHER_OPTION_SPATIAL6 ||
2842 option == DITHER_OPTION_TRUN10_SPATIAL6 ||
2843 option == DITHER_OPTION_TRUN8_SPATIAL6) {
2844 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
2845 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 0;
2846 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
2847 fmt_bit_depth->flags.RGB_RANDOM =
2848 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
2849 } else if (option == DITHER_OPTION_SPATIAL8_FRAME_RANDOM ||
2850 option == DITHER_OPTION_SPATIAL8 ||
2851 option == DITHER_OPTION_SPATIAL8_FM6 ||
2852 option == DITHER_OPTION_TRUN10_SPATIAL8 ||
2853 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
2854 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
2855 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 1;
2856 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
2857 fmt_bit_depth->flags.RGB_RANDOM =
2858 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
2859 } else if (option == DITHER_OPTION_SPATIAL10_FRAME_RANDOM ||
2860 option == DITHER_OPTION_SPATIAL10 ||
2861 option == DITHER_OPTION_SPATIAL10_FM8 ||
2862 option == DITHER_OPTION_SPATIAL10_FM6) {
2863 fmt_bit_depth->flags.SPATIAL_DITHER_ENABLED = 1;
2864 fmt_bit_depth->flags.SPATIAL_DITHER_DEPTH = 2;
2865 fmt_bit_depth->flags.HIGHPASS_RANDOM = 1;
2866 fmt_bit_depth->flags.RGB_RANDOM =
2867 (pixel_encoding == PIXEL_ENCODING_RGB) ? 1 : 0;
2870 if (option == DITHER_OPTION_SPATIAL6 ||
2871 option == DITHER_OPTION_SPATIAL8 ||
2872 option == DITHER_OPTION_SPATIAL10) {
2873 fmt_bit_depth->flags.FRAME_RANDOM = 0;
2875 fmt_bit_depth->flags.FRAME_RANDOM = 1;
2878 //////////////////////
2879 //// temporal dither
2880 //////////////////////
2881 if (option == DITHER_OPTION_FM6 ||
2882 option == DITHER_OPTION_SPATIAL8_FM6 ||
2883 option == DITHER_OPTION_SPATIAL10_FM6 ||
2884 option == DITHER_OPTION_TRUN10_FM6 ||
2885 option == DITHER_OPTION_TRUN8_FM6 ||
2886 option == DITHER_OPTION_TRUN10_SPATIAL8_FM6) {
2887 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
2888 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 0;
2889 } else if (option == DITHER_OPTION_FM8 ||
2890 option == DITHER_OPTION_SPATIAL10_FM8 ||
2891 option == DITHER_OPTION_TRUN10_FM8) {
2892 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
2893 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 1;
2894 } else if (option == DITHER_OPTION_FM10) {
2895 fmt_bit_depth->flags.FRAME_MODULATION_ENABLED = 1;
2896 fmt_bit_depth->flags.FRAME_MODULATION_DEPTH = 2;
2899 fmt_bit_depth->pixel_encoding = pixel_encoding;
2902 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream)
2904 struct dc_link *link = stream->link;
2905 struct timing_generator *tg = dc->res_pool->timing_generators[0];
2906 enum dc_status res = DC_OK;
2908 calculate_phy_pix_clks(stream);
2910 if (!tg->funcs->validate_timing(tg, &stream->timing))
2911 res = DC_FAIL_CONTROLLER_VALIDATE;
2914 if (!link->link_enc->funcs->validate_output_with_stream(
2915 link->link_enc, stream))
2916 res = DC_FAIL_ENC_VALIDATE;
2919 /* TODO: validate audio ASIC caps, encoder */
2922 res = dc_link_validate_mode_timing(stream,
2929 enum dc_status dc_validate_plane(struct dc *dc, const struct dc_plane_state *plane_state)
2931 enum dc_status res = DC_OK;
2933 /* TODO For now validates pixel format only */
2934 if (dc->res_pool->funcs->validate_plane)
2935 return dc->res_pool->funcs->validate_plane(plane_state, &dc->caps);
2940 unsigned int resource_pixel_format_to_bpp(enum surface_pixel_format format)
2943 case SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS:
2945 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
2946 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
2948 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
2949 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
2950 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
2951 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
2953 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
2954 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
2955 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
2956 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
2957 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010_XR_BIAS:
2958 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2959 case SURFACE_PIXEL_FORMAT_GRPH_RGBE:
2960 case SURFACE_PIXEL_FORMAT_GRPH_RGBE_ALPHA:
2963 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
2964 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
2965 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
2968 ASSERT_CRITICAL(false);
2972 static unsigned int get_max_audio_sample_rate(struct audio_mode *modes)
2975 if (modes->sample_rates.rate.RATE_192)
2977 if (modes->sample_rates.rate.RATE_176_4)
2979 if (modes->sample_rates.rate.RATE_96)
2981 if (modes->sample_rates.rate.RATE_88_2)
2983 if (modes->sample_rates.rate.RATE_48)
2985 if (modes->sample_rates.rate.RATE_44_1)
2987 if (modes->sample_rates.rate.RATE_32)
2990 /*original logic when no audio info*/
2994 void get_audio_check(struct audio_info *aud_modes,
2995 struct audio_check *audio_chk)
2998 unsigned int max_sample_rate = 0;
3001 audio_chk->audio_packet_type = 0x2;/*audio sample packet AP = .25 for layout0, 1 for layout1*/
3003 audio_chk->max_audiosample_rate = 0;
3004 for (i = 0; i < aud_modes->mode_count; i++) {
3005 max_sample_rate = get_max_audio_sample_rate(&aud_modes->modes[i]);
3006 if (audio_chk->max_audiosample_rate < max_sample_rate)
3007 audio_chk->max_audiosample_rate = max_sample_rate;
3008 /*dts takes the same as type 2: AP = 0.25*/
3010 /*check which one take more bandwidth*/
3011 if (audio_chk->max_audiosample_rate > 192000)
3012 audio_chk->audio_packet_type = 0x9;/*AP =1*/
3013 audio_chk->acat = 0;/*not support*/