2 * Copyright 2015 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.
25 #include "dm_services.h"
29 #include "core_status.h"
30 #include "core_types.h"
31 #include "hw_sequencer.h"
35 #include "clock_source.h"
36 #include "dc_bios_types.h"
38 #include "dce_calcs.h"
39 #include "bios_parser_interface.h"
40 #include "include/irq_service_interface.h"
41 #include "transform.h"
42 #include "timing_generator.h"
43 #include "virtual/virtual_link_encoder.h"
45 #include "link_hwss.h"
46 #include "link_encoder.h"
48 #include "dc_link_ddc.h"
49 #include "dm_helpers.h"
50 #include "mem_input.h"
52 /*******************************************************************************
54 ******************************************************************************/
55 static void destroy_links(struct core_dc *dc)
59 for (i = 0; i < dc->link_count; i++) {
60 if (NULL != dc->links[i])
61 link_destroy(&dc->links[i]);
65 static bool create_links(
67 uint32_t num_virtual_links)
71 struct dc_bios *bios = dc->ctx->dc_bios;
75 connectors_num = bios->funcs->get_connectors_number(bios);
77 if (connectors_num > ENUM_ID_COUNT) {
79 "DC: Number of connectors %d exceeds maximum of %d!\n",
85 if (connectors_num == 0 && num_virtual_links == 0) {
86 dm_error("DC: Number of connectors is zero!\n");
90 "DC: %s: connectors_num: physical:%d, virtual:%d\n",
95 for (i = 0; i < connectors_num; i++) {
96 struct link_init_data link_init_params = {0};
99 link_init_params.ctx = dc->ctx;
100 /* next BIOS object table connector */
101 link_init_params.connector_index = i;
102 link_init_params.link_index = dc->link_count;
103 link_init_params.dc = dc;
104 link = link_create(&link_init_params);
107 dc->links[dc->link_count] = link;
113 for (i = 0; i < num_virtual_links; i++) {
114 struct dc_link *link = dm_alloc(sizeof(*link));
115 struct encoder_init_data enc_init = {0};
124 link->connector_signal = SIGNAL_TYPE_VIRTUAL;
125 link->link_id.type = OBJECT_TYPE_CONNECTOR;
126 link->link_id.id = CONNECTOR_ID_VIRTUAL;
127 link->link_id.enum_id = ENUM_ID_1;
128 link->link_enc = dm_alloc(sizeof(*link->link_enc));
130 enc_init.ctx = dc->ctx;
131 enc_init.channel = CHANNEL_ID_UNKNOWN;
132 enc_init.hpd_source = HPD_SOURCEID_UNKNOWN;
133 enc_init.transmitter = TRANSMITTER_UNKNOWN;
134 enc_init.connector = link->link_id;
135 enc_init.encoder.type = OBJECT_TYPE_ENCODER;
136 enc_init.encoder.id = ENCODER_ID_INTERNAL_VIRTUAL;
137 enc_init.encoder.enum_id = ENUM_ID_1;
138 virtual_link_encoder_construct(link->link_enc, &enc_init);
140 link->link_index = dc->link_count;
141 dc->links[dc->link_count] = link;
151 static bool stream_adjust_vmin_vmax(struct dc *dc,
152 const struct dc_stream **stream, int num_streams,
155 /* TODO: Support multiple streams */
156 struct core_dc *core_dc = DC_TO_CORE(dc);
157 struct core_stream *core_stream = DC_STREAM_TO_CORE(stream[0]);
161 for (i = 0; i < MAX_PIPES; i++) {
162 struct pipe_ctx *pipe = &core_dc->current_context->res_ctx.pipe_ctx[i];
164 if (pipe->stream == core_stream && pipe->stream_enc) {
165 core_dc->hwss.set_drr(&pipe, 1, vmin, vmax);
167 /* build and update the info frame */
168 resource_build_info_frame(pipe);
169 core_dc->hwss.update_info_frame(pipe);
177 static bool stream_get_crtc_position(struct dc *dc,
178 const struct dc_stream **stream, int num_streams,
179 unsigned int *v_pos, unsigned int *nom_v_pos)
181 /* TODO: Support multiple streams */
182 struct core_dc *core_dc = DC_TO_CORE(dc);
183 struct core_stream *core_stream = DC_STREAM_TO_CORE(stream[0]);
186 struct crtc_position position;
188 for (i = 0; i < MAX_PIPES; i++) {
189 struct pipe_ctx *pipe =
190 &core_dc->current_context->res_ctx.pipe_ctx[i];
192 if (pipe->stream == core_stream && pipe->stream_enc) {
193 core_dc->hwss.get_position(&pipe, 1, &position);
195 *v_pos = position.vertical_count;
196 *nom_v_pos = position.nominal_vcount;
203 static bool set_gamut_remap(struct dc *dc, const struct dc_stream *stream)
205 struct core_dc *core_dc = DC_TO_CORE(dc);
206 struct core_stream *core_stream = DC_STREAM_TO_CORE(stream);
209 struct pipe_ctx *pipes;
211 for (i = 0; i < MAX_PIPES; i++) {
212 if (core_dc->current_context->res_ctx.pipe_ctx[i].stream
215 pipes = &core_dc->current_context->res_ctx.pipe_ctx[i];
216 core_dc->hwss.program_gamut_remap(pipes);
224 static bool program_csc_matrix(struct dc *dc, const struct dc_stream *stream)
226 struct core_dc *core_dc = DC_TO_CORE(dc);
227 struct core_stream *core_stream = DC_STREAM_TO_CORE(stream);
230 struct pipe_ctx *pipes;
232 for (i = 0; i < MAX_PIPES; i++) {
233 if (core_dc->current_context->res_ctx.pipe_ctx[i].stream
236 pipes = &core_dc->current_context->res_ctx.pipe_ctx[i];
237 core_dc->hwss.program_csc_matrix(pipes,
238 core_stream->public.output_color_space,
239 core_stream->public.csc_color_matrix.matrix);
247 static void set_static_screen_events(struct dc *dc,
248 const struct dc_stream **stream,
250 const struct dc_static_screen_events *events)
252 struct core_dc *core_dc = DC_TO_CORE(dc);
255 struct pipe_ctx *pipes_affected[MAX_PIPES];
256 int num_pipes_affected = 0;
258 for (i = 0; i < num_streams; i++) {
259 struct core_stream *core_stream = DC_STREAM_TO_CORE(stream[i]);
261 for (j = 0; j < MAX_PIPES; j++) {
262 if (core_dc->current_context->res_ctx.pipe_ctx[j].stream
264 pipes_affected[num_pipes_affected++] =
265 &core_dc->current_context->res_ctx.pipe_ctx[j];
270 core_dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, events);
273 static void set_drive_settings(struct dc *dc,
274 struct link_training_settings *lt_settings,
275 const struct dc_link *link)
277 struct core_dc *core_dc = DC_TO_CORE(dc);
280 for (i = 0; i < core_dc->link_count; i++) {
281 if (core_dc->links[i] == link)
285 if (i >= core_dc->link_count)
286 ASSERT_CRITICAL(false);
288 dc_link_dp_set_drive_settings(core_dc->links[i], lt_settings);
291 static void perform_link_training(struct dc *dc,
292 struct dc_link_settings *link_setting,
293 bool skip_video_pattern)
295 struct core_dc *core_dc = DC_TO_CORE(dc);
298 for (i = 0; i < core_dc->link_count; i++)
299 dc_link_dp_perform_link_training(
305 static void set_preferred_link_settings(struct dc *dc,
306 struct dc_link_settings *link_setting,
307 struct dc_link *link)
309 link->preferred_link_setting = *link_setting;
310 dp_retrain_link_dp_test(link, link_setting, false);
313 static void enable_hpd(const struct dc_link *link)
315 dc_link_dp_enable_hpd(link);
318 static void disable_hpd(const struct dc_link *link)
320 dc_link_dp_disable_hpd(link);
324 static void set_test_pattern(
325 struct dc_link *link,
326 enum dp_test_pattern test_pattern,
327 const struct link_training_settings *p_link_settings,
328 const unsigned char *p_custom_pattern,
329 unsigned int cust_pattern_size)
332 dc_link_dp_set_test_pattern(
340 void set_dither_option(const struct dc_stream *dc_stream,
341 enum dc_dither_option option)
343 struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
344 struct bit_depth_reduction_params params;
345 struct dc_link *link = stream->status.link;
346 struct pipe_ctx *pipes = link->dc->current_context->res_ctx.pipe_ctx;
348 memset(¶ms, 0, sizeof(params));
351 if (option > DITHER_OPTION_MAX)
353 if (option == DITHER_OPTION_DEFAULT) {
354 switch (stream->public.timing.display_color_depth) {
355 case COLOR_DEPTH_666:
356 stream->public.dither_option = DITHER_OPTION_SPATIAL6;
358 case COLOR_DEPTH_888:
359 stream->public.dither_option = DITHER_OPTION_SPATIAL8;
361 case COLOR_DEPTH_101010:
362 stream->public.dither_option = DITHER_OPTION_SPATIAL10;
365 option = DITHER_OPTION_DISABLE;
368 stream->public.dither_option = option;
370 resource_build_bit_depth_reduction_params(stream,
372 stream->bit_depth_params = params;
374 opp_program_bit_depth_reduction(pipes->opp, ¶ms);
377 static void allocate_dc_stream_funcs(struct core_dc *core_dc)
379 if (core_dc->hwss.set_drr != NULL) {
380 core_dc->public.stream_funcs.adjust_vmin_vmax =
381 stream_adjust_vmin_vmax;
384 core_dc->public.stream_funcs.set_static_screen_events =
385 set_static_screen_events;
387 core_dc->public.stream_funcs.get_crtc_position =
388 stream_get_crtc_position;
390 core_dc->public.stream_funcs.set_gamut_remap =
393 core_dc->public.stream_funcs.program_csc_matrix =
396 core_dc->public.stream_funcs.set_dither_option =
399 core_dc->public.link_funcs.set_drive_settings =
402 core_dc->public.link_funcs.perform_link_training =
403 perform_link_training;
405 core_dc->public.link_funcs.set_preferred_link_settings =
406 set_preferred_link_settings;
408 core_dc->public.link_funcs.enable_hpd =
411 core_dc->public.link_funcs.disable_hpd =
414 core_dc->public.link_funcs.set_test_pattern =
418 static void destruct(struct core_dc *dc)
420 dc_release_validate_context(dc->current_context);
421 dc->current_context = NULL;
425 dc_destroy_resource_pool(dc);
427 if (dc->ctx->gpio_service)
428 dal_gpio_service_destroy(&dc->ctx->gpio_service);
431 dal_i2caux_destroy(&dc->ctx->i2caux);
433 if (dc->ctx->created_bios)
434 dal_bios_parser_destroy(&dc->ctx->dc_bios);
437 dal_logger_destroy(&dc->ctx->logger);
443 static bool construct(struct core_dc *dc,
444 const struct dc_init_data *init_params)
446 struct dal_logger *logger;
447 struct dc_context *dc_ctx = dm_alloc(sizeof(*dc_ctx));
448 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
451 dm_error("%s: failed to create ctx\n", __func__);
455 dc->current_context = dm_alloc(sizeof(*dc->current_context));
457 if (!dc->current_context) {
458 dm_error("%s: failed to create validate ctx\n", __func__);
462 dc->current_context->ref_count++;
464 dc_ctx->cgs_device = init_params->cgs_device;
465 dc_ctx->driver_context = init_params->driver;
466 dc_ctx->dc = &dc->public;
467 dc_ctx->asic_id = init_params->asic_id;
470 logger = dal_logger_create(dc_ctx);
473 /* can *not* call logger. call base driver 'print error' */
474 dm_error("%s: failed to create Logger!\n", __func__);
477 dc_ctx->logger = logger;
479 dc->ctx->dce_environment = init_params->dce_environment;
481 dc_version = resource_parse_asic_id(init_params->asic_id);
482 dc->ctx->dce_version = dc_version;
484 /* Resource should construct all asic specific resources.
485 * This should be the only place where we need to parse the asic id
487 if (init_params->vbios_override)
488 dc_ctx->dc_bios = init_params->vbios_override;
490 /* Create BIOS parser */
491 struct bp_init_data bp_init_data;
493 bp_init_data.ctx = dc_ctx;
494 bp_init_data.bios = init_params->asic_id.atombios_base_address;
496 dc_ctx->dc_bios = dal_bios_parser_create(
497 &bp_init_data, dc_version);
499 if (!dc_ctx->dc_bios) {
500 ASSERT_CRITICAL(false);
504 dc_ctx->created_bios = true;
508 dc_ctx->i2caux = dal_i2caux_create(dc_ctx);
510 if (!dc_ctx->i2caux) {
511 ASSERT_CRITICAL(false);
512 goto failed_to_create_i2caux;
515 /* Create GPIO service */
516 dc_ctx->gpio_service = dal_gpio_service_create(
518 dc_ctx->dce_environment,
521 if (!dc_ctx->gpio_service) {
522 ASSERT_CRITICAL(false);
526 dc->res_pool = dc_create_resource_pool(
528 init_params->num_virtual_links,
530 init_params->asic_id);
532 goto create_resource_fail;
534 if (!create_links(dc, init_params->num_virtual_links))
535 goto create_links_fail;
537 allocate_dc_stream_funcs(dc);
541 /**** error handling here ****/
543 create_resource_fail:
545 failed_to_create_i2caux:
555 void ProgramPixelDurationV(unsigned int pixelClockInKHz )
557 fixed31_32 pixel_duration = Fixed31_32(100000000, pixelClockInKHz) * 10;
558 unsigned int pixDurationInPico = round(pixel_duration);
560 DPG_PIPE_ARBITRATION_CONTROL1 arb_control;
562 arb_control.u32All = ReadReg (mmDPGV0_PIPE_ARBITRATION_CONTROL1);
563 arb_control.bits.PIXEL_DURATION = pixDurationInPico;
564 WriteReg (mmDPGV0_PIPE_ARBITRATION_CONTROL1, arb_control.u32All);
566 arb_control.u32All = ReadReg (mmDPGV1_PIPE_ARBITRATION_CONTROL1);
567 arb_control.bits.PIXEL_DURATION = pixDurationInPico;
568 WriteReg (mmDPGV1_PIPE_ARBITRATION_CONTROL1, arb_control.u32All);
570 WriteReg (mmDPGV0_PIPE_ARBITRATION_CONTROL2, 0x4000800);
571 WriteReg (mmDPGV0_REPEATER_PROGRAM, 0x11);
573 WriteReg (mmDPGV1_PIPE_ARBITRATION_CONTROL2, 0x4000800);
574 WriteReg (mmDPGV1_REPEATER_PROGRAM, 0x11);
578 /*******************************************************************************
580 ******************************************************************************/
582 struct dc *dc_create(const struct dc_init_data *init_params)
584 struct core_dc *core_dc = dm_alloc(sizeof(*core_dc));
585 unsigned int full_pipe_count;
590 if (false == construct(core_dc, init_params))
593 /*TODO: separate HW and SW initialization*/
594 core_dc->hwss.init_hw(core_dc);
596 full_pipe_count = core_dc->res_pool->pipe_count;
597 if (core_dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
599 core_dc->public.caps.max_streams = min(
601 core_dc->res_pool->stream_enc_count);
603 core_dc->public.caps.max_links = core_dc->link_count;
604 core_dc->public.caps.max_audios = core_dc->res_pool->audio_count;
606 core_dc->public.config = init_params->flags;
608 dm_logger_write(core_dc->ctx->logger, LOG_DC,
609 "Display Core initialized\n");
612 /* TODO: missing feature to be enabled */
613 core_dc->public.debug.disable_dfs_bypass = true;
615 return &core_dc->public;
624 void dc_destroy(struct dc **dc)
626 struct core_dc *core_dc = DC_TO_CORE(*dc);
632 static bool is_validation_required(
633 const struct core_dc *dc,
634 const struct dc_validation_set set[],
637 const struct validate_context *context = dc->current_context;
640 if (context->stream_count != set_count)
643 for (i = 0; i < set_count; i++) {
645 if (set[i].surface_count != context->stream_status[i].surface_count)
647 if (!is_stream_unchanged(DC_STREAM_TO_CORE(set[i].stream), context->streams[i]))
650 for (j = 0; j < set[i].surface_count; j++) {
651 struct dc_surface temp_surf;
652 memset(&temp_surf, 0, sizeof(temp_surf));
654 temp_surf = *context->stream_status[i].surfaces[j];
655 temp_surf.clip_rect = set[i].surfaces[j]->clip_rect;
656 temp_surf.dst_rect.x = set[i].surfaces[j]->dst_rect.x;
657 temp_surf.dst_rect.y = set[i].surfaces[j]->dst_rect.y;
659 if (memcmp(&temp_surf, set[i].surfaces[j], sizeof(temp_surf)) != 0)
667 struct validate_context *dc_get_validate_context(
669 const struct dc_validation_set set[],
672 struct core_dc *core_dc = DC_TO_CORE(dc);
673 enum dc_status result = DC_ERROR_UNEXPECTED;
674 struct validate_context *context;
676 context = dm_alloc(sizeof(struct validate_context));
678 goto context_alloc_fail;
680 ++context->ref_count;
682 if (!is_validation_required(core_dc, set, set_count)) {
683 dc_resource_validate_ctx_copy_construct(core_dc->current_context, context);
687 result = core_dc->res_pool->funcs->validate_with_context(
688 core_dc, set, set_count, context, core_dc->current_context);
691 if (result != DC_OK) {
692 dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
693 "%s:resource validation failed, dc_status:%d\n",
697 dc_release_validate_context(context);
705 bool dc_validate_resources(
707 const struct dc_validation_set set[],
710 struct core_dc *core_dc = DC_TO_CORE(dc);
711 enum dc_status result = DC_ERROR_UNEXPECTED;
712 struct validate_context *context;
714 context = dm_alloc(sizeof(struct validate_context));
716 goto context_alloc_fail;
718 ++context->ref_count;
720 result = core_dc->res_pool->funcs->validate_with_context(
721 core_dc, set, set_count, context, NULL);
724 if (result != DC_OK) {
725 dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
726 "%s:resource validation failed, dc_status:%d\n",
731 dc_release_validate_context(context);
734 return result == DC_OK;
737 bool dc_validate_guaranteed(
739 const struct dc_stream *stream)
741 struct core_dc *core_dc = DC_TO_CORE(dc);
742 enum dc_status result = DC_ERROR_UNEXPECTED;
743 struct validate_context *context;
745 context = dm_alloc(sizeof(struct validate_context));
747 goto context_alloc_fail;
749 ++context->ref_count;
751 result = core_dc->res_pool->funcs->validate_guaranteed(
752 core_dc, stream, context);
754 dc_release_validate_context(context);
757 if (result != DC_OK) {
758 dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
759 "%s:guaranteed validation failed, dc_status:%d\n",
764 return (result == DC_OK);
767 static void program_timing_sync(
768 struct core_dc *core_dc,
769 struct validate_context *ctx)
773 int pipe_count = core_dc->res_pool->pipe_count;
774 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
776 for (i = 0; i < pipe_count; i++) {
777 if (!ctx->res_ctx.pipe_ctx[i].stream || ctx->res_ctx.pipe_ctx[i].top_pipe)
780 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
783 for (i = 0; i < pipe_count; i++) {
785 struct pipe_ctx *pipe_set[MAX_PIPES];
787 if (!unsynced_pipes[i])
790 pipe_set[0] = unsynced_pipes[i];
791 unsynced_pipes[i] = NULL;
793 /* Add tg to the set, search rest of the tg's for ones with
794 * same timing, add all tgs with same timing to the group
796 for (j = i + 1; j < pipe_count; j++) {
797 if (!unsynced_pipes[j])
800 if (resource_are_streams_timing_synchronizable(
801 unsynced_pipes[j]->stream,
802 pipe_set[0]->stream)) {
803 pipe_set[group_size] = unsynced_pipes[j];
804 unsynced_pipes[j] = NULL;
809 /* set first unblanked pipe as master */
810 for (j = 0; j < group_size; j++) {
811 struct pipe_ctx *temp;
813 if (!pipe_set[j]->tg->funcs->is_blanked(pipe_set[j]->tg)) {
818 pipe_set[0] = pipe_set[j];
824 /* remove any other unblanked pipes as they have already been synced */
825 for (j = j + 1; j < group_size; j++) {
826 if (!pipe_set[j]->tg->funcs->is_blanked(pipe_set[j]->tg)) {
828 pipe_set[j] = pipe_set[group_size];
833 if (group_size > 1) {
834 core_dc->hwss.enable_timing_synchronization(
835 core_dc, group_index, group_size, pipe_set);
841 static bool context_changed(
843 struct validate_context *context)
847 if (context->stream_count != dc->current_context->stream_count)
850 for (i = 0; i < dc->current_context->stream_count; i++) {
851 if (&dc->current_context->streams[i]->public != &context->streams[i]->public)
858 static bool streams_changed(
860 const struct dc_stream *streams[],
861 uint8_t stream_count)
865 if (stream_count != dc->current_context->stream_count)
868 for (i = 0; i < dc->current_context->stream_count; i++) {
869 if (&dc->current_context->streams[i]->public != streams[i])
876 bool dc_enable_stereo(
878 struct validate_context *context,
879 const struct dc_stream *streams[],
880 uint8_t stream_count)
884 struct pipe_ctx *pipe;
885 struct core_dc *core_dc = DC_TO_CORE(dc);
888 struct compressor *fbc_compressor = core_dc->fbc_compressor;
891 for (i = 0; i < MAX_PIPES; i++) {
893 pipe = &context->res_ctx.pipe_ctx[i];
895 pipe = &core_dc->current_context->res_ctx.pipe_ctx[i];
896 for (j = 0 ; pipe && j < stream_count; j++) {
897 if (streams[j] && streams[j] == &pipe->stream->public &&
898 core_dc->hwss.setup_stereo)
899 core_dc->hwss.setup_stereo(pipe, core_dc);
904 if (fbc_compressor != NULL &&
905 fbc_compressor->funcs->is_fbc_enabled_in_hw(core_dc->fbc_compressor,
907 fbc_compressor->funcs->disable_fbc(fbc_compressor);
915 * Applies given context to HW and copy it into current context.
916 * It's up to the user to release the src context afterwards.
918 static bool dc_commit_context_no_check(struct dc *dc, struct validate_context *context)
920 struct core_dc *core_dc = DC_TO_CORE(dc);
921 struct dc_bios *dcb = core_dc->ctx->dc_bios;
922 enum dc_status result = DC_ERROR_UNEXPECTED;
923 struct pipe_ctx *pipe;
925 const struct dc_stream *dc_streams[MAX_STREAMS] = {0};
927 for (i = 0; i < context->stream_count; i++)
928 dc_streams[i] = &context->streams[i]->public;
930 if (!dcb->funcs->is_accelerated_mode(dcb))
931 core_dc->hwss.enable_accelerated_mode(core_dc);
933 for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
934 pipe = &context->res_ctx.pipe_ctx[i];
935 core_dc->hwss.wait_for_mpcc_disconnect(core_dc, core_dc->res_pool, pipe);
937 result = core_dc->hwss.apply_ctx_to_hw(core_dc, context);
939 program_timing_sync(core_dc, context);
941 for (i = 0; i < context->stream_count; i++) {
942 const struct dc_sink *sink = context->streams[i]->sink;
944 for (j = 0; j < context->stream_status[i].surface_count; j++) {
945 const struct dc_surface *surface =
946 context->stream_status[i].surfaces[j];
948 core_dc->hwss.apply_ctx_for_surface(core_dc, surface, context);
952 * TODO rework dc_enable_stereo call to work with validation sets?
954 for (k = 0; k < MAX_PIPES; k++) {
955 pipe = &context->res_ctx.pipe_ctx[k];
957 for (l = 0 ; pipe && l < context->stream_count; l++) {
958 if (context->streams[l] &&
959 context->streams[l] == pipe->stream &&
960 core_dc->hwss.setup_stereo)
961 core_dc->hwss.setup_stereo(pipe, core_dc);
966 CONN_MSG_MODE(sink->link, "{%dx%d, %dx%d@%dKhz}",
967 context->streams[i]->public.timing.h_addressable,
968 context->streams[i]->public.timing.v_addressable,
969 context->streams[i]->public.timing.h_total,
970 context->streams[i]->public.timing.v_total,
971 context->streams[i]->public.timing.pix_clk_khz);
974 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
976 dc_release_validate_context(core_dc->current_context);
978 core_dc->current_context = context;
980 dc_retain_validate_context(core_dc->current_context);
982 return (result == DC_OK);
985 bool dc_commit_context(struct dc *dc, struct validate_context *context)
987 enum dc_status result = DC_ERROR_UNEXPECTED;
988 struct core_dc *core_dc = DC_TO_CORE(dc);
991 if (false == context_changed(core_dc, context))
994 dm_logger_write(core_dc->ctx->logger, LOG_DC, "%s: %d streams\n",
995 __func__, context->stream_count);
997 for (i = 0; i < context->stream_count; i++) {
998 const struct dc_stream *stream = &context->streams[i]->public;
1000 dc_stream_log(stream,
1001 core_dc->ctx->logger,
1005 result = dc_commit_context_no_check(dc, context);
1007 return (result == DC_OK);
1011 bool dc_commit_streams(
1013 const struct dc_stream *streams[],
1014 uint8_t stream_count)
1016 struct core_dc *core_dc = DC_TO_CORE(dc);
1017 enum dc_status result = DC_ERROR_UNEXPECTED;
1018 struct validate_context *context;
1019 struct dc_validation_set set[MAX_STREAMS] = { {0, {0} } };
1022 if (false == streams_changed(core_dc, streams, stream_count))
1025 dm_logger_write(core_dc->ctx->logger, LOG_DC, "%s: %d streams\n",
1026 __func__, stream_count);
1028 for (i = 0; i < stream_count; i++) {
1029 const struct dc_stream *stream = streams[i];
1030 const struct dc_stream_status *status = dc_stream_get_status(stream);
1033 dc_stream_log(stream,
1034 core_dc->ctx->logger,
1037 set[i].stream = stream;
1040 set[i].surface_count = status->surface_count;
1041 for (j = 0; j < status->surface_count; j++)
1042 set[i].surfaces[j] = status->surfaces[j];
1047 context = dm_alloc(sizeof(struct validate_context));
1048 if (context == NULL)
1049 goto context_alloc_fail;
1051 ++context->ref_count;
1053 result = core_dc->res_pool->funcs->validate_with_context(
1054 core_dc, set, stream_count, context, core_dc->current_context);
1055 if (result != DC_OK){
1056 dm_logger_write(core_dc->ctx->logger, LOG_ERROR,
1057 "%s: Context validation failed! dc_status:%d\n",
1060 BREAK_TO_DEBUGGER();
1064 result = dc_commit_context_no_check(dc, context);
1067 dc_release_validate_context(context);
1070 return (result == DC_OK);
1073 bool dc_post_update_surfaces_to_stream(struct dc *dc)
1076 struct core_dc *core_dc = DC_TO_CORE(dc);
1077 struct validate_context *context = core_dc->current_context;
1079 post_surface_trace(dc);
1081 for (i = 0; i < core_dc->res_pool->pipe_count; i++)
1082 if (context->res_ctx.pipe_ctx[i].stream == NULL
1083 || context->res_ctx.pipe_ctx[i].surface == NULL)
1084 core_dc->hwss.power_down_front_end(core_dc, i);
1086 /* 3rd param should be true, temp w/a for RV*/
1087 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1088 core_dc->hwss.set_bandwidth(core_dc, context, core_dc->ctx->dce_version != DCN_VERSION_1_0);
1090 core_dc->hwss.set_bandwidth(core_dc, context, true);
1095 bool dc_commit_surfaces_to_stream(
1097 struct dc_surface **new_surfaces,
1098 uint8_t new_surface_count,
1099 const struct dc_stream *dc_stream)
1101 struct dc_surface_update updates[MAX_SURFACES];
1102 struct dc_flip_addrs flip_addr[MAX_SURFACES];
1103 struct dc_plane_info plane_info[MAX_SURFACES];
1104 struct dc_scaling_info scaling_info[MAX_SURFACES];
1106 struct dc_stream_update *stream_update =
1107 dm_alloc(sizeof(struct dc_stream_update));
1109 if (!stream_update) {
1110 BREAK_TO_DEBUGGER();
1114 memset(updates, 0, sizeof(updates));
1115 memset(flip_addr, 0, sizeof(flip_addr));
1116 memset(plane_info, 0, sizeof(plane_info));
1117 memset(scaling_info, 0, sizeof(scaling_info));
1119 stream_update->src = dc_stream->src;
1120 stream_update->dst = dc_stream->dst;
1121 stream_update->out_transfer_func = dc_stream->out_transfer_func;
1123 for (i = 0; i < new_surface_count; i++) {
1124 updates[i].surface = new_surfaces[i];
1126 (struct dc_gamma *)new_surfaces[i]->gamma_correction;
1127 updates[i].in_transfer_func = new_surfaces[i]->in_transfer_func;
1128 flip_addr[i].address = new_surfaces[i]->address;
1129 flip_addr[i].flip_immediate = new_surfaces[i]->flip_immediate;
1130 plane_info[i].color_space = new_surfaces[i]->color_space;
1131 plane_info[i].format = new_surfaces[i]->format;
1132 plane_info[i].plane_size = new_surfaces[i]->plane_size;
1133 plane_info[i].rotation = new_surfaces[i]->rotation;
1134 plane_info[i].horizontal_mirror = new_surfaces[i]->horizontal_mirror;
1135 plane_info[i].stereo_format = new_surfaces[i]->stereo_format;
1136 plane_info[i].tiling_info = new_surfaces[i]->tiling_info;
1137 plane_info[i].visible = new_surfaces[i]->visible;
1138 plane_info[i].per_pixel_alpha = new_surfaces[i]->per_pixel_alpha;
1139 plane_info[i].dcc = new_surfaces[i]->dcc;
1140 scaling_info[i].scaling_quality = new_surfaces[i]->scaling_quality;
1141 scaling_info[i].src_rect = new_surfaces[i]->src_rect;
1142 scaling_info[i].dst_rect = new_surfaces[i]->dst_rect;
1143 scaling_info[i].clip_rect = new_surfaces[i]->clip_rect;
1145 updates[i].flip_addr = &flip_addr[i];
1146 updates[i].plane_info = &plane_info[i];
1147 updates[i].scaling_info = &scaling_info[i];
1150 dc_update_surfaces_and_stream(
1154 dc_stream, stream_update);
1156 dc_post_update_surfaces_to_stream(dc);
1158 dm_free(stream_update);
1162 void dc_retain_validate_context(struct validate_context *context)
1164 ASSERT(context->ref_count > 0);
1165 ++context->ref_count;
1168 void dc_release_validate_context(struct validate_context *context)
1170 ASSERT(context->ref_count > 0);
1171 --context->ref_count;
1173 if (context->ref_count == 0) {
1174 dc_resource_validate_ctx_destruct(context);
1179 static bool is_surface_in_context(
1180 const struct validate_context *context,
1181 const struct dc_surface *surface)
1185 for (j = 0; j < MAX_PIPES; j++) {
1186 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1188 if (surface == pipe_ctx->surface) {
1196 static unsigned int pixel_format_to_bpp(enum surface_pixel_format format)
1199 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
1200 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
1202 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
1203 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
1204 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
1205 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
1207 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
1208 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
1209 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
1210 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
1212 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
1213 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
1214 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
1217 ASSERT_CRITICAL(false);
1222 static enum surface_update_type get_plane_info_update_type(
1223 const struct dc_surface_update *u,
1226 struct dc_plane_info temp_plane_info;
1227 memset(&temp_plane_info, 0, sizeof(temp_plane_info));
1230 return UPDATE_TYPE_FAST;
1232 temp_plane_info = *u->plane_info;
1234 /* Copy all parameters that will cause a full update
1235 * from current surface, the rest of the parameters
1236 * from provided plane configuration.
1237 * Perform memory compare and special validation
1238 * for those that can cause fast/medium updates
1241 /* Full update parameters */
1242 temp_plane_info.color_space = u->surface->color_space;
1243 temp_plane_info.dcc = u->surface->dcc;
1244 temp_plane_info.horizontal_mirror = u->surface->horizontal_mirror;
1245 temp_plane_info.plane_size = u->surface->plane_size;
1246 temp_plane_info.rotation = u->surface->rotation;
1247 temp_plane_info.stereo_format = u->surface->stereo_format;
1248 temp_plane_info.tiling_info = u->surface->tiling_info;
1250 if (surface_index == 0)
1251 temp_plane_info.visible = u->plane_info->visible;
1253 temp_plane_info.visible = u->surface->visible;
1255 if (memcmp(u->plane_info, &temp_plane_info,
1256 sizeof(struct dc_plane_info)) != 0)
1257 return UPDATE_TYPE_FULL;
1259 if (pixel_format_to_bpp(u->plane_info->format) !=
1260 pixel_format_to_bpp(u->surface->format)) {
1261 return UPDATE_TYPE_FULL;
1263 return UPDATE_TYPE_MED;
1267 static enum surface_update_type get_scaling_info_update_type(
1268 const struct dc_surface_update *u)
1270 if (!u->scaling_info)
1271 return UPDATE_TYPE_FAST;
1273 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
1274 || u->scaling_info->src_rect.height != u->surface->src_rect.height
1275 || u->scaling_info->clip_rect.width != u->surface->clip_rect.width
1276 || u->scaling_info->clip_rect.height != u->surface->clip_rect.height
1277 || u->scaling_info->dst_rect.width != u->surface->dst_rect.width
1278 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height)
1279 return UPDATE_TYPE_FULL;
1281 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
1282 || u->scaling_info->src_rect.y != u->surface->src_rect.y
1283 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
1284 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
1285 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
1286 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
1287 return UPDATE_TYPE_MED;
1289 return UPDATE_TYPE_FAST;
1292 static enum surface_update_type det_surface_update(
1293 const struct core_dc *dc,
1294 const struct dc_surface_update *u,
1297 const struct validate_context *context = dc->current_context;
1298 enum surface_update_type type = UPDATE_TYPE_FAST;
1299 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1301 if (!is_surface_in_context(context, u->surface))
1302 return UPDATE_TYPE_FULL;
1304 type = get_plane_info_update_type(u, surface_index);
1305 if (overall_type < type)
1306 overall_type = type;
1308 type = get_scaling_info_update_type(u);
1309 if (overall_type < type)
1310 overall_type = type;
1312 if (u->in_transfer_func ||
1313 u->hdr_static_metadata) {
1314 if (overall_type < UPDATE_TYPE_MED)
1315 overall_type = UPDATE_TYPE_MED;
1318 return overall_type;
1321 enum surface_update_type dc_check_update_surfaces_for_stream(
1323 struct dc_surface_update *updates,
1325 struct dc_stream_update *stream_update,
1326 const struct dc_stream_status *stream_status)
1328 struct core_dc *core_dc = DC_TO_CORE(dc);
1330 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1332 if (stream_status == NULL || stream_status->surface_count != surface_count)
1333 return UPDATE_TYPE_FULL;
1336 return UPDATE_TYPE_FULL;
1338 for (i = 0 ; i < surface_count; i++) {
1339 enum surface_update_type type =
1340 det_surface_update(core_dc, &updates[i], i);
1342 if (type == UPDATE_TYPE_FULL)
1345 if (overall_type < type)
1346 overall_type = type;
1349 return overall_type;
1352 enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
1354 void dc_update_surfaces_and_stream(struct dc *dc,
1355 struct dc_surface_update *srf_updates, int surface_count,
1356 const struct dc_stream *dc_stream,
1357 struct dc_stream_update *stream_update)
1359 struct core_dc *core_dc = DC_TO_CORE(dc);
1360 struct validate_context *context;
1362 enum surface_update_type update_type;
1363 const struct dc_stream_status *stream_status;
1364 struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
1365 struct dc_context *dc_ctx = core_dc->ctx;
1367 /* Currently this function do not result in any HW programming
1368 * when called with 0 surface. But proceeding will cause
1369 * SW state to be updated in validate_context. So we might as
1370 * well make it not do anything at all until the hw programming
1371 * is implemented properly to handle 0 surface case.
1372 * TODO: fix hw programming then remove this early return
1374 if (surface_count == 0)
1377 stream_status = dc_stream_get_status(dc_stream);
1378 ASSERT(stream_status);
1380 return; /* Cannot commit surface to stream that is not committed */
1383 if (srf_updates->flip_addr) {
1384 if (srf_updates->flip_addr->address.grph.addr.low_part == 0)
1388 context = core_dc->current_context;
1390 /* update current stream with the new updates */
1391 if (stream_update) {
1392 if ((stream_update->src.height != 0) &&
1393 (stream_update->src.width != 0))
1394 stream->public.src = stream_update->src;
1396 if ((stream_update->dst.height != 0) &&
1397 (stream_update->dst.width != 0))
1398 stream->public.dst = stream_update->dst;
1400 if (stream_update->out_transfer_func &&
1401 stream_update->out_transfer_func !=
1402 dc_stream->out_transfer_func) {
1403 if (dc_stream->out_transfer_func != NULL)
1404 dc_transfer_func_release(dc_stream->out_transfer_func);
1405 dc_transfer_func_retain(stream_update->out_transfer_func);
1406 stream->public.out_transfer_func =
1407 stream_update->out_transfer_func;
1411 /* do not perform surface update if surface has invalid dimensions
1412 * (all zero) and no scaling_info is provided
1414 if (surface_count > 0 &&
1415 srf_updates->surface->src_rect.width == 0 &&
1416 srf_updates->surface->src_rect.height == 0 &&
1417 srf_updates->surface->dst_rect.width == 0 &&
1418 srf_updates->surface->dst_rect.height == 0 &&
1419 !srf_updates->scaling_info) {
1424 update_type = dc_check_update_surfaces_for_stream(
1425 dc, srf_updates, surface_count, stream_update, stream_status);
1427 if (update_type >= update_surface_trace_level)
1428 update_surface_trace(dc, srf_updates, surface_count);
1430 if (update_type >= UPDATE_TYPE_FULL) {
1431 struct dc_surface *new_surfaces[MAX_SURFACES] = {0};
1433 for (i = 0; i < surface_count; i++)
1434 new_surfaces[i] = srf_updates[i].surface;
1436 /* initialize scratch memory for building context */
1437 context = dm_alloc(sizeof(*context));
1438 if (context == NULL)
1439 goto context_alloc_fail;
1441 ++context->ref_count;
1443 dc_resource_validate_ctx_copy_construct(
1444 core_dc->current_context, context);
1446 /* add surface to context */
1447 if (!resource_attach_surfaces_to_context(
1448 new_surfaces, surface_count, dc_stream,
1449 context, core_dc->res_pool)) {
1450 BREAK_TO_DEBUGGER();
1455 /* save update parameters into surface */
1456 for (i = 0; i < surface_count; i++) {
1457 struct dc_surface *surface = srf_updates[i].surface;
1459 if (srf_updates[i].flip_addr) {
1460 surface->address = srf_updates[i].flip_addr->address;
1461 surface->flip_immediate =
1462 srf_updates[i].flip_addr->flip_immediate;
1465 if (srf_updates[i].scaling_info) {
1466 surface->scaling_quality =
1467 srf_updates[i].scaling_info->scaling_quality;
1469 srf_updates[i].scaling_info->dst_rect;
1471 srf_updates[i].scaling_info->src_rect;
1472 surface->clip_rect =
1473 srf_updates[i].scaling_info->clip_rect;
1476 if (srf_updates[i].plane_info) {
1477 surface->color_space =
1478 srf_updates[i].plane_info->color_space;
1480 srf_updates[i].plane_info->format;
1481 surface->plane_size =
1482 srf_updates[i].plane_info->plane_size;
1484 srf_updates[i].plane_info->rotation;
1485 surface->horizontal_mirror =
1486 srf_updates[i].plane_info->horizontal_mirror;
1487 surface->stereo_format =
1488 srf_updates[i].plane_info->stereo_format;
1489 surface->tiling_info =
1490 srf_updates[i].plane_info->tiling_info;
1492 srf_updates[i].plane_info->visible;
1493 surface->per_pixel_alpha =
1494 srf_updates[i].plane_info->per_pixel_alpha;
1496 srf_updates[i].plane_info->dcc;
1499 if (update_type >= UPDATE_TYPE_MED) {
1500 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1501 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1503 if (pipe_ctx->surface != surface)
1506 resource_build_scaling_params(pipe_ctx);
1510 if (srf_updates[i].gamma &&
1511 srf_updates[i].gamma != surface->gamma_correction) {
1512 if (surface->gamma_correction != NULL)
1513 dc_gamma_release(&surface->gamma_correction);
1515 dc_gamma_retain(srf_updates[i].gamma);
1516 surface->gamma_correction = srf_updates[i].gamma;
1519 if (srf_updates[i].in_transfer_func &&
1520 srf_updates[i].in_transfer_func != surface->in_transfer_func) {
1521 if (surface->in_transfer_func != NULL)
1522 dc_transfer_func_release(
1526 dc_transfer_func_retain(
1527 srf_updates[i].in_transfer_func);
1528 surface->in_transfer_func =
1529 srf_updates[i].in_transfer_func;
1532 if (srf_updates[i].hdr_static_metadata)
1533 surface->hdr_static_ctx =
1534 *(srf_updates[i].hdr_static_metadata);
1537 if (update_type == UPDATE_TYPE_FULL) {
1538 if (!core_dc->res_pool->funcs->validate_bandwidth(core_dc, context)) {
1539 BREAK_TO_DEBUGGER();
1542 core_dc->hwss.set_bandwidth(core_dc, context, false);
1543 context_clock_trace(dc, context);
1547 if (update_type > UPDATE_TYPE_FAST) {
1548 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1549 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1551 core_dc->hwss.wait_for_mpcc_disconnect(core_dc, core_dc->res_pool, pipe_ctx);
1555 if (surface_count == 0)
1556 core_dc->hwss.apply_ctx_for_surface(core_dc, NULL, context);
1558 /* Lock pipes for provided surfaces, or all active if full update*/
1559 for (i = 0; i < surface_count; i++) {
1560 struct dc_surface *surface = srf_updates[i].surface;
1562 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1563 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1565 if (update_type != UPDATE_TYPE_FULL && pipe_ctx->surface != surface)
1567 if (!pipe_ctx->surface || pipe_ctx->top_pipe)
1570 if (!pipe_ctx->tg->funcs->is_blanked(pipe_ctx->tg)) {
1571 core_dc->hwss.pipe_control_lock(
1577 if (update_type == UPDATE_TYPE_FULL)
1582 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1583 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1584 struct pipe_ctx *cur_pipe_ctx = &core_dc->current_context->res_ctx.pipe_ctx[j];
1585 bool is_new_pipe_surface = cur_pipe_ctx->surface != pipe_ctx->surface;
1586 struct dc_cursor_position position = { 0 };
1588 if (update_type != UPDATE_TYPE_FULL || !pipe_ctx->surface)
1591 if (!pipe_ctx->top_pipe)
1592 core_dc->hwss.apply_ctx_for_surface(
1593 core_dc, pipe_ctx->surface, context);
1595 /* TODO: this is a hack w/a for switching from mpo to pipe split */
1596 dc_stream_set_cursor_position(&pipe_ctx->stream->public, &position);
1598 if (is_new_pipe_surface) {
1599 core_dc->hwss.update_plane_addr(core_dc, pipe_ctx);
1600 core_dc->hwss.set_input_transfer_func(
1601 pipe_ctx, pipe_ctx->surface);
1602 core_dc->hwss.set_output_transfer_func(
1603 pipe_ctx, pipe_ctx->stream);
1607 if (update_type > UPDATE_TYPE_FAST)
1608 context_timing_trace(dc, &context->res_ctx);
1610 /* Perform requested Updates */
1611 for (i = 0; i < surface_count; i++) {
1612 struct dc_surface *surface = srf_updates[i].surface;
1614 if (update_type == UPDATE_TYPE_MED)
1615 core_dc->hwss.apply_ctx_for_surface(
1616 core_dc, surface, context);
1618 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1619 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1621 if (pipe_ctx->surface != surface)
1624 if (srf_updates[i].flip_addr)
1625 core_dc->hwss.update_plane_addr(core_dc, pipe_ctx);
1627 if (update_type == UPDATE_TYPE_FAST)
1630 if (srf_updates[i].in_transfer_func)
1631 core_dc->hwss.set_input_transfer_func(
1632 pipe_ctx, pipe_ctx->surface);
1634 if (stream_update != NULL &&
1635 stream_update->out_transfer_func != NULL) {
1636 core_dc->hwss.set_output_transfer_func(
1637 pipe_ctx, pipe_ctx->stream);
1640 if (srf_updates[i].hdr_static_metadata) {
1641 resource_build_info_frame(pipe_ctx);
1642 core_dc->hwss.update_info_frame(pipe_ctx);
1648 for (i = core_dc->res_pool->pipe_count - 1; i >= 0; i--) {
1649 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1651 for (j = 0; j < surface_count; j++) {
1652 if (update_type != UPDATE_TYPE_FULL &&
1653 srf_updates[j].surface != pipe_ctx->surface)
1655 if (!pipe_ctx->surface || pipe_ctx->top_pipe)
1658 if (!pipe_ctx->tg->funcs->is_blanked(pipe_ctx->tg)) {
1659 core_dc->hwss.pipe_control_lock(
1668 if (core_dc->current_context != context) {
1669 dc_release_validate_context(core_dc->current_context);
1670 core_dc->current_context = context;
1675 dc_release_validate_context(context);
1678 DC_ERROR("Failed to allocate new validate context!\n");
1681 uint8_t dc_get_current_stream_count(const struct dc *dc)
1683 struct core_dc *core_dc = DC_TO_CORE(dc);
1684 return core_dc->current_context->stream_count;
1687 struct dc_stream *dc_get_stream_at_index(const struct dc *dc, uint8_t i)
1689 struct core_dc *core_dc = DC_TO_CORE(dc);
1690 if (i < core_dc->current_context->stream_count)
1691 return &(core_dc->current_context->streams[i]->public);
1695 struct dc_link *dc_get_link_at_index(const struct dc *dc, uint32_t link_index)
1697 struct core_dc *core_dc = DC_TO_CORE(dc);
1698 return core_dc->links[link_index];
1701 const struct graphics_object_id dc_get_link_id_at_index(
1702 struct dc *dc, uint32_t link_index)
1704 struct core_dc *core_dc = DC_TO_CORE(dc);
1705 return core_dc->links[link_index]->link_id;
1708 enum dc_irq_source dc_get_hpd_irq_source_at_index(
1709 struct dc *dc, uint32_t link_index)
1711 struct core_dc *core_dc = DC_TO_CORE(dc);
1712 return core_dc->links[link_index]->irq_source_hpd;
1715 const struct audio **dc_get_audios(struct dc *dc)
1717 struct core_dc *core_dc = DC_TO_CORE(dc);
1718 return (const struct audio **)core_dc->res_pool->audios;
1721 enum dc_irq_source dc_interrupt_to_irq_source(
1726 struct core_dc *core_dc = DC_TO_CORE(dc);
1727 return dal_irq_service_to_irq_source(core_dc->res_pool->irqs, src_id, ext_id);
1730 void dc_interrupt_set(const struct dc *dc, enum dc_irq_source src, bool enable)
1732 struct core_dc *core_dc;
1736 core_dc = DC_TO_CORE(dc);
1738 dal_irq_service_set(core_dc->res_pool->irqs, src, enable);
1741 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
1743 struct core_dc *core_dc = DC_TO_CORE(dc);
1744 dal_irq_service_ack(core_dc->res_pool->irqs, src);
1747 void dc_set_power_state(
1749 enum dc_acpi_cm_power_state power_state)
1751 struct core_dc *core_dc = DC_TO_CORE(dc);
1754 switch (power_state) {
1755 case DC_ACPI_CM_POWER_STATE_D0:
1756 core_dc->hwss.init_hw(core_dc);
1760 core_dc->hwss.power_down(core_dc);
1762 /* Zero out the current context so that on resume we start with
1763 * clean state, and dc hw programming optimizations will not
1764 * cause any trouble.
1767 /* Preserve refcount */
1768 ref_count = core_dc->current_context->ref_count;
1769 dc_resource_validate_ctx_destruct(core_dc->current_context);
1770 memset(core_dc->current_context, 0,
1771 sizeof(*core_dc->current_context));
1772 core_dc->current_context->ref_count = ref_count;
1779 void dc_resume(const struct dc *dc)
1781 struct core_dc *core_dc = DC_TO_CORE(dc);
1785 for (i = 0; i < core_dc->link_count; i++)
1786 core_link_resume(core_dc->links[i]);
1789 bool dc_read_aux_dpcd(
1791 uint32_t link_index,
1796 struct core_dc *core_dc = DC_TO_CORE(dc);
1798 struct dc_link *link = core_dc->links[link_index];
1799 enum ddc_result r = dal_ddc_service_read_dpcd_data(
1806 return r == DDC_RESULT_SUCESSFULL;
1809 bool dc_write_aux_dpcd(
1811 uint32_t link_index,
1813 const uint8_t *data,
1816 struct core_dc *core_dc = DC_TO_CORE(dc);
1817 struct dc_link *link = core_dc->links[link_index];
1819 enum ddc_result r = dal_ddc_service_write_dpcd_data(
1826 return r == DDC_RESULT_SUCESSFULL;
1829 bool dc_read_aux_i2c(
1831 uint32_t link_index,
1832 enum i2c_mot_mode mot,
1837 struct core_dc *core_dc = DC_TO_CORE(dc);
1839 struct dc_link *link = core_dc->links[link_index];
1840 enum ddc_result r = dal_ddc_service_read_dpcd_data(
1847 return r == DDC_RESULT_SUCESSFULL;
1850 bool dc_write_aux_i2c(
1852 uint32_t link_index,
1853 enum i2c_mot_mode mot,
1855 const uint8_t *data,
1858 struct core_dc *core_dc = DC_TO_CORE(dc);
1859 struct dc_link *link = core_dc->links[link_index];
1861 enum ddc_result r = dal_ddc_service_write_dpcd_data(
1868 return r == DDC_RESULT_SUCESSFULL;
1871 bool dc_query_ddc_data(
1873 uint32_t link_index,
1876 uint32_t write_size,
1878 uint32_t read_size) {
1880 struct core_dc *core_dc = DC_TO_CORE(dc);
1882 struct dc_link *link = core_dc->links[link_index];
1884 bool result = dal_ddc_service_query_ddc_data(
1897 uint32_t link_index,
1898 struct i2c_command *cmd)
1900 struct core_dc *core_dc = DC_TO_CORE(dc);
1902 struct dc_link *link = core_dc->links[link_index];
1903 struct ddc_service *ddc = link->ddc;
1905 return dal_i2caux_submit_i2c_command(
1911 static bool link_add_remote_sink_helper(struct dc_link *dc_link, struct dc_sink *sink)
1913 if (dc_link->sink_count >= MAX_SINKS_PER_LINK) {
1914 BREAK_TO_DEBUGGER();
1918 dc_sink_retain(sink);
1920 dc_link->remote_sinks[dc_link->sink_count] = sink;
1921 dc_link->sink_count++;
1926 struct dc_sink *dc_link_add_remote_sink(
1927 struct dc_link *link,
1928 const uint8_t *edid,
1930 struct dc_sink_init_data *init_data)
1932 struct dc_sink *dc_sink;
1933 enum dc_edid_status edid_status;
1935 if (len > MAX_EDID_BUFFER_SIZE) {
1936 dm_error("Max EDID buffer size breached!\n");
1941 BREAK_TO_DEBUGGER();
1945 if (!init_data->link) {
1946 BREAK_TO_DEBUGGER();
1950 dc_sink = dc_sink_create(init_data);
1955 memmove(dc_sink->dc_edid.raw_edid, edid, len);
1956 dc_sink->dc_edid.length = len;
1958 if (!link_add_remote_sink_helper(
1963 edid_status = dm_helpers_parse_edid_caps(
1966 &dc_sink->edid_caps);
1968 if (edid_status != EDID_OK)
1973 dc_link_remove_remote_sink(link, dc_sink);
1975 dc_sink_release(dc_sink);
1979 void dc_link_set_sink(struct dc_link *link, struct dc_sink *sink)
1981 link->local_sink = sink;
1984 link->type = dc_connection_none;
1986 link->type = dc_connection_single;
1990 void dc_link_remove_remote_sink(struct dc_link *link, struct dc_sink *sink)
1994 if (!link->sink_count) {
1995 BREAK_TO_DEBUGGER();
1999 for (i = 0; i < link->sink_count; i++) {
2000 if (link->remote_sinks[i] == sink) {
2001 dc_sink_release(sink);
2002 link->remote_sinks[i] = NULL;
2004 /* shrink array to remove empty place */
2005 while (i < link->sink_count - 1) {
2006 link->remote_sinks[i] = link->remote_sinks[i+1];
2009 link->remote_sinks[i] = NULL;
2016 bool dc_init_dchub(struct dc *dc, struct dchub_init_data *dh_data)
2019 struct core_dc *core_dc = DC_TO_CORE(dc);
2020 struct mem_input *mi = NULL;
2022 for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
2023 if (core_dc->res_pool->mis[i] != NULL) {
2024 mi = core_dc->res_pool->mis[i];
2029 dm_error("no mem_input!\n");
2033 if (core_dc->hwss.update_dchub)
2034 core_dc->hwss.update_dchub(core_dc->hwseq, dh_data);
2036 ASSERT(core_dc->hwss.update_dchub);
2043 void dc_log_hw_state(struct dc *dc)
2045 struct core_dc *core_dc = DC_TO_CORE(dc);
2047 if (core_dc->hwss.log_hw_state)
2048 core_dc->hwss.log_hw_state(core_dc);