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};
97 struct core_link *link;
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 core_link *link = dm_alloc(sizeof(*link));
115 struct encoder_init_data enc_init = {0};
124 link->public.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->public.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]->public == link)
285 if (i >= core_dc->link_count)
286 ASSERT_CRITICAL(false);
288 dc_link_dp_set_drive_settings(&core_dc->links[i]->public, 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(
300 &core_dc->links[i]->public,
305 static void set_preferred_link_settings(struct dc *dc,
306 struct dc_link_settings *link_setting,
307 const struct dc_link *link)
309 struct core_link *core_link = DC_LINK_TO_CORE(link);
311 core_link->public.verified_link_cap.lane_count =
312 link_setting->lane_count;
313 core_link->public.verified_link_cap.link_rate =
314 link_setting->link_rate;
315 dp_retrain_link_dp_test(core_link, link_setting, false);
318 static void enable_hpd(const struct dc_link *link)
320 dc_link_dp_enable_hpd(link);
323 static void disable_hpd(const struct dc_link *link)
325 dc_link_dp_disable_hpd(link);
329 static void set_test_pattern(
330 const struct dc_link *link,
331 enum dp_test_pattern test_pattern,
332 const struct link_training_settings *p_link_settings,
333 const unsigned char *p_custom_pattern,
334 unsigned int cust_pattern_size)
337 dc_link_dp_set_test_pattern(
345 void set_dither_option(const struct dc_stream *dc_stream,
346 enum dc_dither_option option)
348 struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
349 struct bit_depth_reduction_params params;
350 struct core_link *core_link = DC_LINK_TO_CORE(stream->status.link);
351 struct pipe_ctx *pipes =
352 core_link->dc->current_context->res_ctx.pipe_ctx;
354 memset(¶ms, 0, sizeof(params));
357 if (option > DITHER_OPTION_MAX)
359 if (option == DITHER_OPTION_DEFAULT) {
360 switch (stream->public.timing.display_color_depth) {
361 case COLOR_DEPTH_666:
362 stream->public.dither_option = DITHER_OPTION_SPATIAL6;
364 case COLOR_DEPTH_888:
365 stream->public.dither_option = DITHER_OPTION_SPATIAL8;
367 case COLOR_DEPTH_101010:
368 stream->public.dither_option = DITHER_OPTION_SPATIAL10;
371 option = DITHER_OPTION_DISABLE;
374 stream->public.dither_option = option;
376 resource_build_bit_depth_reduction_params(stream,
378 stream->bit_depth_params = params;
380 opp_program_bit_depth_reduction(pipes->opp, ¶ms);
383 static void allocate_dc_stream_funcs(struct core_dc *core_dc)
385 if (core_dc->hwss.set_drr != NULL) {
386 core_dc->public.stream_funcs.adjust_vmin_vmax =
387 stream_adjust_vmin_vmax;
390 core_dc->public.stream_funcs.set_static_screen_events =
391 set_static_screen_events;
393 core_dc->public.stream_funcs.get_crtc_position =
394 stream_get_crtc_position;
396 core_dc->public.stream_funcs.set_gamut_remap =
399 core_dc->public.stream_funcs.program_csc_matrix =
402 core_dc->public.stream_funcs.set_dither_option =
405 core_dc->public.link_funcs.set_drive_settings =
408 core_dc->public.link_funcs.perform_link_training =
409 perform_link_training;
411 core_dc->public.link_funcs.set_preferred_link_settings =
412 set_preferred_link_settings;
414 core_dc->public.link_funcs.enable_hpd =
417 core_dc->public.link_funcs.disable_hpd =
420 core_dc->public.link_funcs.set_test_pattern =
424 static void destruct(struct core_dc *dc)
426 dc_resource_validate_ctx_destruct(dc->current_context);
430 dc_destroy_resource_pool(dc);
432 if (dc->ctx->gpio_service)
433 dal_gpio_service_destroy(&dc->ctx->gpio_service);
436 dal_i2caux_destroy(&dc->ctx->i2caux);
438 if (dc->ctx->created_bios)
439 dal_bios_parser_destroy(&dc->ctx->dc_bios);
442 dal_logger_destroy(&dc->ctx->logger);
444 dm_free(dc->current_context);
445 dc->current_context = NULL;
451 static bool construct(struct core_dc *dc,
452 const struct dc_init_data *init_params)
454 struct dal_logger *logger;
455 struct dc_context *dc_ctx = dm_alloc(sizeof(*dc_ctx));
456 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
459 dm_error("%s: failed to create ctx\n", __func__);
463 dc->current_context = dm_alloc(sizeof(*dc->current_context));
465 if (!dc->current_context) {
466 dm_error("%s: failed to create validate ctx\n", __func__);
470 dc_ctx->cgs_device = init_params->cgs_device;
471 dc_ctx->driver_context = init_params->driver;
472 dc_ctx->dc = &dc->public;
473 dc_ctx->asic_id = init_params->asic_id;
476 logger = dal_logger_create(dc_ctx);
479 /* can *not* call logger. call base driver 'print error' */
480 dm_error("%s: failed to create Logger!\n", __func__);
483 dc_ctx->logger = logger;
485 dc->ctx->dce_environment = init_params->dce_environment;
487 dc_version = resource_parse_asic_id(init_params->asic_id);
488 dc->ctx->dce_version = dc_version;
490 /* Resource should construct all asic specific resources.
491 * This should be the only place where we need to parse the asic id
493 if (init_params->vbios_override)
494 dc_ctx->dc_bios = init_params->vbios_override;
496 /* Create BIOS parser */
497 struct bp_init_data bp_init_data;
499 bp_init_data.ctx = dc_ctx;
500 bp_init_data.bios = init_params->asic_id.atombios_base_address;
502 dc_ctx->dc_bios = dal_bios_parser_create(
503 &bp_init_data, dc_version);
505 if (!dc_ctx->dc_bios) {
506 ASSERT_CRITICAL(false);
510 dc_ctx->created_bios = true;
514 dc_ctx->i2caux = dal_i2caux_create(dc_ctx);
516 if (!dc_ctx->i2caux) {
517 ASSERT_CRITICAL(false);
518 goto failed_to_create_i2caux;
521 /* Create GPIO service */
522 dc_ctx->gpio_service = dal_gpio_service_create(
524 dc_ctx->dce_environment,
527 if (!dc_ctx->gpio_service) {
528 ASSERT_CRITICAL(false);
532 dc->res_pool = dc_create_resource_pool(
534 init_params->num_virtual_links,
536 init_params->asic_id);
538 goto create_resource_fail;
540 if (!create_links(dc, init_params->num_virtual_links))
541 goto create_links_fail;
543 allocate_dc_stream_funcs(dc);
547 /**** error handling here ****/
549 create_resource_fail:
551 failed_to_create_i2caux:
561 void ProgramPixelDurationV(unsigned int pixelClockInKHz )
563 fixed31_32 pixel_duration = Fixed31_32(100000000, pixelClockInKHz) * 10;
564 unsigned int pixDurationInPico = round(pixel_duration);
566 DPG_PIPE_ARBITRATION_CONTROL1 arb_control;
568 arb_control.u32All = ReadReg (mmDPGV0_PIPE_ARBITRATION_CONTROL1);
569 arb_control.bits.PIXEL_DURATION = pixDurationInPico;
570 WriteReg (mmDPGV0_PIPE_ARBITRATION_CONTROL1, arb_control.u32All);
572 arb_control.u32All = ReadReg (mmDPGV1_PIPE_ARBITRATION_CONTROL1);
573 arb_control.bits.PIXEL_DURATION = pixDurationInPico;
574 WriteReg (mmDPGV1_PIPE_ARBITRATION_CONTROL1, arb_control.u32All);
576 WriteReg (mmDPGV0_PIPE_ARBITRATION_CONTROL2, 0x4000800);
577 WriteReg (mmDPGV0_REPEATER_PROGRAM, 0x11);
579 WriteReg (mmDPGV1_PIPE_ARBITRATION_CONTROL2, 0x4000800);
580 WriteReg (mmDPGV1_REPEATER_PROGRAM, 0x11);
584 /*******************************************************************************
586 ******************************************************************************/
588 struct dc *dc_create(const struct dc_init_data *init_params)
590 struct core_dc *core_dc = dm_alloc(sizeof(*core_dc));
591 unsigned int full_pipe_count;
596 if (false == construct(core_dc, init_params))
599 /*TODO: separate HW and SW initialization*/
600 core_dc->hwss.init_hw(core_dc);
602 full_pipe_count = core_dc->res_pool->pipe_count;
603 if (core_dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
605 core_dc->public.caps.max_streams = min(
607 core_dc->res_pool->stream_enc_count);
609 core_dc->public.caps.max_links = core_dc->link_count;
610 core_dc->public.caps.max_audios = core_dc->res_pool->audio_count;
612 core_dc->public.config = init_params->flags;
614 dm_logger_write(core_dc->ctx->logger, LOG_DC,
615 "Display Core initialized\n");
618 /* TODO: missing feature to be enabled */
619 core_dc->public.debug.disable_dfs_bypass = true;
621 return &core_dc->public;
630 void dc_destroy(struct dc **dc)
632 struct core_dc *core_dc = DC_TO_CORE(*dc);
638 static bool is_validation_required(
639 const struct core_dc *dc,
640 const struct dc_validation_set set[],
643 const struct validate_context *context = dc->current_context;
646 if (context->stream_count != set_count)
649 for (i = 0; i < set_count; i++) {
651 if (set[i].surface_count != context->stream_status[i].surface_count)
653 if (!is_stream_unchanged(DC_STREAM_TO_CORE(set[i].stream), context->streams[i]))
656 for (j = 0; j < set[i].surface_count; j++) {
657 struct dc_surface temp_surf;
658 memset(&temp_surf, 0, sizeof(temp_surf));
660 temp_surf = *context->stream_status[i].surfaces[j];
661 temp_surf.clip_rect = set[i].surfaces[j]->clip_rect;
662 temp_surf.dst_rect.x = set[i].surfaces[j]->dst_rect.x;
663 temp_surf.dst_rect.y = set[i].surfaces[j]->dst_rect.y;
665 if (memcmp(&temp_surf, set[i].surfaces[j], sizeof(temp_surf)) != 0)
673 struct validate_context *dc_get_validate_context(
675 const struct dc_validation_set set[],
678 struct core_dc *core_dc = DC_TO_CORE(dc);
679 enum dc_status result = DC_ERROR_UNEXPECTED;
680 struct validate_context *context;
682 context = dm_alloc(sizeof(struct validate_context));
684 goto context_alloc_fail;
686 if (!is_validation_required(core_dc, set, set_count)) {
687 dc_resource_validate_ctx_copy_construct(core_dc->current_context, context);
691 result = core_dc->res_pool->funcs->validate_with_context(
692 core_dc, set, set_count, context, core_dc->current_context);
695 if (result != DC_OK) {
696 dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
697 "%s:resource validation failed, dc_status:%d\n",
701 dc_resource_validate_ctx_destruct(context);
710 bool dc_validate_resources(
712 const struct dc_validation_set set[],
715 struct core_dc *core_dc = DC_TO_CORE(dc);
716 enum dc_status result = DC_ERROR_UNEXPECTED;
717 struct validate_context *context;
719 context = dm_alloc(sizeof(struct validate_context));
721 goto context_alloc_fail;
723 result = core_dc->res_pool->funcs->validate_with_context(
724 core_dc, set, set_count, context, NULL);
727 if (result != DC_OK) {
728 dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
729 "%s:resource validation failed, dc_status:%d\n",
734 dc_resource_validate_ctx_destruct(context);
738 return result == DC_OK;
741 bool dc_validate_guaranteed(
743 const struct dc_stream *stream)
745 struct core_dc *core_dc = DC_TO_CORE(dc);
746 enum dc_status result = DC_ERROR_UNEXPECTED;
747 struct validate_context *context;
749 context = dm_alloc(sizeof(struct validate_context));
751 goto context_alloc_fail;
753 result = core_dc->res_pool->funcs->validate_guaranteed(
754 core_dc, stream, context);
756 dc_resource_validate_ctx_destruct(context);
760 if (result != DC_OK) {
761 dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
762 "%s:guaranteed validation failed, dc_status:%d\n",
767 return (result == DC_OK);
770 static void program_timing_sync(
771 struct core_dc *core_dc,
772 struct validate_context *ctx)
776 int pipe_count = core_dc->res_pool->pipe_count;
777 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
779 for (i = 0; i < pipe_count; i++) {
780 if (!ctx->res_ctx.pipe_ctx[i].stream || ctx->res_ctx.pipe_ctx[i].top_pipe)
783 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
786 for (i = 0; i < pipe_count; i++) {
788 struct pipe_ctx *pipe_set[MAX_PIPES];
790 if (!unsynced_pipes[i])
793 pipe_set[0] = unsynced_pipes[i];
794 unsynced_pipes[i] = NULL;
796 /* Add tg to the set, search rest of the tg's for ones with
797 * same timing, add all tgs with same timing to the group
799 for (j = i + 1; j < pipe_count; j++) {
800 if (!unsynced_pipes[j])
803 if (resource_are_streams_timing_synchronizable(
804 unsynced_pipes[j]->stream,
805 pipe_set[0]->stream)) {
806 pipe_set[group_size] = unsynced_pipes[j];
807 unsynced_pipes[j] = NULL;
812 /* set first unblanked pipe as master */
813 for (j = 0; j < group_size; j++) {
814 struct pipe_ctx *temp;
816 if (!pipe_set[j]->tg->funcs->is_blanked(pipe_set[j]->tg)) {
821 pipe_set[0] = pipe_set[j];
827 /* remove any other unblanked pipes as they have already been synced */
828 for (j = j + 1; j < group_size; j++) {
829 if (!pipe_set[j]->tg->funcs->is_blanked(pipe_set[j]->tg)) {
831 pipe_set[j] = pipe_set[group_size];
836 if (group_size > 1) {
837 core_dc->hwss.enable_timing_synchronization(
838 core_dc, group_index, group_size, pipe_set);
844 static bool context_changed(
846 struct validate_context *context)
850 if (context->stream_count != dc->current_context->stream_count)
853 for (i = 0; i < dc->current_context->stream_count; i++) {
854 if (&dc->current_context->streams[i]->public != &context->streams[i]->public)
861 static bool streams_changed(
863 const struct dc_stream *streams[],
864 uint8_t stream_count)
868 if (stream_count != dc->current_context->stream_count)
871 for (i = 0; i < dc->current_context->stream_count; i++) {
872 if (&dc->current_context->streams[i]->public != streams[i])
879 bool dc_enable_stereo(
881 struct validate_context *context,
882 const struct dc_stream *streams[],
883 uint8_t stream_count)
887 struct pipe_ctx *pipe;
888 struct core_dc *core_dc = DC_TO_CORE(dc);
891 struct compressor *fbc_compressor = core_dc->fbc_compressor;
894 for (i = 0; i < MAX_PIPES; i++) {
896 pipe = &context->res_ctx.pipe_ctx[i];
898 pipe = &core_dc->current_context->res_ctx.pipe_ctx[i];
899 for (j = 0 ; pipe && j < stream_count; j++) {
900 if (streams[j] && streams[j] == &pipe->stream->public &&
901 core_dc->hwss.setup_stereo)
902 core_dc->hwss.setup_stereo(pipe, core_dc);
907 if (fbc_compressor != NULL &&
908 fbc_compressor->funcs->is_fbc_enabled_in_hw(core_dc->fbc_compressor,
910 fbc_compressor->funcs->disable_fbc(fbc_compressor);
918 * Applies given context to HW and copy it into current context.
919 * It's up to the user to release the src context afterwards.
921 static bool dc_commit_context_no_check(struct dc *dc, struct validate_context *context)
923 struct core_dc *core_dc = DC_TO_CORE(dc);
924 struct dc_bios *dcb = core_dc->ctx->dc_bios;
925 enum dc_status result = DC_ERROR_UNEXPECTED;
926 struct pipe_ctx *pipe;
928 const struct dc_stream *dc_streams[MAX_STREAMS] = {0};
930 for (i = 0; i < context->stream_count; i++)
931 dc_streams[i] = &context->streams[i]->public;
933 if (!dcb->funcs->is_accelerated_mode(dcb))
934 core_dc->hwss.enable_accelerated_mode(core_dc);
936 result = core_dc->hwss.apply_ctx_to_hw(core_dc, context);
938 program_timing_sync(core_dc, context);
940 for (i = 0; i < context->stream_count; i++) {
941 const struct core_sink *sink = context->streams[i]->sink;
943 for (j = 0; j < context->stream_status[i].surface_count; j++) {
944 struct core_surface *surface =
945 DC_SURFACE_TO_CORE(context->stream_status[i].surfaces[j]);
947 core_dc->hwss.apply_ctx_for_surface(core_dc, surface, context);
951 * TODO rework dc_enable_stereo call to work with validation sets?
953 for (k = 0; k < MAX_PIPES; k++) {
954 pipe = &context->res_ctx.pipe_ctx[k];
956 for (l = 0 ; pipe && l < context->stream_count; l++) {
957 if (context->streams[l] &&
958 context->streams[l] == pipe->stream &&
959 core_dc->hwss.setup_stereo)
960 core_dc->hwss.setup_stereo(pipe, core_dc);
965 CONN_MSG_MODE(sink->link, "{%dx%d, %dx%d@%dKhz}",
966 context->streams[i]->public.timing.h_addressable,
967 context->streams[i]->public.timing.v_addressable,
968 context->streams[i]->public.timing.h_total,
969 context->streams[i]->public.timing.v_total,
970 context->streams[i]->public.timing.pix_clk_khz);
973 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
975 dc_resource_validate_ctx_copy_construct(context, core_dc->current_context);
977 return (result == DC_OK);
980 bool dc_commit_context(struct dc *dc, struct validate_context *context)
982 enum dc_status result = DC_ERROR_UNEXPECTED;
983 struct core_dc *core_dc = DC_TO_CORE(dc);
986 if (false == context_changed(core_dc, context))
989 dm_logger_write(core_dc->ctx->logger, LOG_DC, "%s: %d streams\n",
990 __func__, context->stream_count);
992 for (i = 0; i < context->stream_count; i++) {
993 const struct dc_stream *stream = &context->streams[i]->public;
995 dc_stream_log(stream,
996 core_dc->ctx->logger,
1000 result = dc_commit_context_no_check(dc, context);
1002 return (result == DC_OK);
1006 bool dc_commit_streams(
1008 const struct dc_stream *streams[],
1009 uint8_t stream_count)
1011 struct core_dc *core_dc = DC_TO_CORE(dc);
1012 enum dc_status result = DC_ERROR_UNEXPECTED;
1013 struct validate_context *context;
1014 struct dc_validation_set set[MAX_STREAMS] = { {0, {0} } };
1017 if (false == streams_changed(core_dc, streams, stream_count))
1020 dm_logger_write(core_dc->ctx->logger, LOG_DC, "%s: %d streams\n",
1021 __func__, stream_count);
1023 for (i = 0; i < stream_count; i++) {
1024 const struct dc_stream *stream = streams[i];
1025 const struct dc_stream_status *status = dc_stream_get_status(stream);
1028 dc_stream_log(stream,
1029 core_dc->ctx->logger,
1032 set[i].stream = stream;
1035 set[i].surface_count = status->surface_count;
1036 for (j = 0; j < status->surface_count; j++)
1037 set[i].surfaces[j] = status->surfaces[j];
1042 context = dm_alloc(sizeof(struct validate_context));
1043 if (context == NULL)
1044 goto context_alloc_fail;
1046 result = core_dc->res_pool->funcs->validate_with_context(
1047 core_dc, set, stream_count, context, core_dc->current_context);
1048 if (result != DC_OK){
1049 dm_logger_write(core_dc->ctx->logger, LOG_ERROR,
1050 "%s: Context validation failed! dc_status:%d\n",
1053 BREAK_TO_DEBUGGER();
1054 dc_resource_validate_ctx_destruct(context);
1058 result = dc_commit_context_no_check(dc, context);
1060 dc_resource_validate_ctx_destruct(context);
1063 return (result == DC_OK);
1069 return (result == DC_OK);
1072 bool dc_post_update_surfaces_to_stream(struct dc *dc)
1075 struct core_dc *core_dc = DC_TO_CORE(dc);
1076 struct validate_context *context = core_dc->current_context;
1078 post_surface_trace(dc);
1080 for (i = 0; i < core_dc->res_pool->pipe_count; i++)
1081 if (context->res_ctx.pipe_ctx[i].stream == NULL
1082 || context->res_ctx.pipe_ctx[i].surface == NULL)
1083 core_dc->hwss.power_down_front_end(core_dc, i);
1085 /* 3rd param should be true, temp w/a for RV*/
1086 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1087 core_dc->hwss.set_bandwidth(core_dc, context, core_dc->ctx->dce_version != DCN_VERSION_1_0);
1089 core_dc->hwss.set_bandwidth(core_dc, context, true);
1094 bool dc_commit_surfaces_to_stream(
1096 const struct dc_surface **new_surfaces,
1097 uint8_t new_surface_count,
1098 const struct dc_stream *dc_stream)
1100 struct dc_surface_update updates[MAX_SURFACES];
1101 struct dc_flip_addrs flip_addr[MAX_SURFACES];
1102 struct dc_plane_info plane_info[MAX_SURFACES];
1103 struct dc_scaling_info scaling_info[MAX_SURFACES];
1105 struct dc_stream_update *stream_update =
1106 dm_alloc(sizeof(struct dc_stream_update));
1108 if (!stream_update) {
1109 BREAK_TO_DEBUGGER();
1113 memset(updates, 0, sizeof(updates));
1114 memset(flip_addr, 0, sizeof(flip_addr));
1115 memset(plane_info, 0, sizeof(plane_info));
1116 memset(scaling_info, 0, sizeof(scaling_info));
1118 stream_update->src = dc_stream->src;
1119 stream_update->dst = dc_stream->dst;
1121 for (i = 0; i < new_surface_count; i++) {
1122 updates[i].surface = new_surfaces[i];
1124 (struct dc_gamma *)new_surfaces[i]->gamma_correction;
1125 flip_addr[i].address = new_surfaces[i]->address;
1126 flip_addr[i].flip_immediate = new_surfaces[i]->flip_immediate;
1127 plane_info[i].color_space = new_surfaces[i]->color_space;
1128 plane_info[i].format = new_surfaces[i]->format;
1129 plane_info[i].plane_size = new_surfaces[i]->plane_size;
1130 plane_info[i].rotation = new_surfaces[i]->rotation;
1131 plane_info[i].horizontal_mirror = new_surfaces[i]->horizontal_mirror;
1132 plane_info[i].stereo_format = new_surfaces[i]->stereo_format;
1133 plane_info[i].tiling_info = new_surfaces[i]->tiling_info;
1134 plane_info[i].visible = new_surfaces[i]->visible;
1135 plane_info[i].per_pixel_alpha = new_surfaces[i]->per_pixel_alpha;
1136 plane_info[i].dcc = new_surfaces[i]->dcc;
1137 scaling_info[i].scaling_quality = new_surfaces[i]->scaling_quality;
1138 scaling_info[i].src_rect = new_surfaces[i]->src_rect;
1139 scaling_info[i].dst_rect = new_surfaces[i]->dst_rect;
1140 scaling_info[i].clip_rect = new_surfaces[i]->clip_rect;
1142 updates[i].flip_addr = &flip_addr[i];
1143 updates[i].plane_info = &plane_info[i];
1144 updates[i].scaling_info = &scaling_info[i];
1147 dc_update_surfaces_and_stream(
1151 dc_stream, stream_update);
1153 dc_post_update_surfaces_to_stream(dc);
1155 dm_free(stream_update);
1159 static bool is_surface_in_context(
1160 const struct validate_context *context,
1161 const struct dc_surface *surface)
1165 for (j = 0; j < MAX_PIPES; j++) {
1166 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1168 if (surface == &pipe_ctx->surface->public) {
1176 static unsigned int pixel_format_to_bpp(enum surface_pixel_format format)
1179 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
1180 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
1182 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555:
1183 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
1184 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
1185 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
1187 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
1188 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
1189 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
1190 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
1192 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
1193 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
1194 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
1197 ASSERT_CRITICAL(false);
1202 static enum surface_update_type get_plane_info_update_type(
1203 const struct dc_surface_update *u,
1206 struct dc_plane_info temp_plane_info;
1207 memset(&temp_plane_info, 0, sizeof(temp_plane_info));
1210 return UPDATE_TYPE_FAST;
1212 temp_plane_info = *u->plane_info;
1214 /* Copy all parameters that will cause a full update
1215 * from current surface, the rest of the parameters
1216 * from provided plane configuration.
1217 * Perform memory compare and special validation
1218 * for those that can cause fast/medium updates
1221 /* Full update parameters */
1222 temp_plane_info.color_space = u->surface->color_space;
1223 temp_plane_info.dcc = u->surface->dcc;
1224 temp_plane_info.horizontal_mirror = u->surface->horizontal_mirror;
1225 temp_plane_info.plane_size = u->surface->plane_size;
1226 temp_plane_info.rotation = u->surface->rotation;
1227 temp_plane_info.stereo_format = u->surface->stereo_format;
1228 temp_plane_info.tiling_info = u->surface->tiling_info;
1230 if (surface_index == 0)
1231 temp_plane_info.visible = u->plane_info->visible;
1233 temp_plane_info.visible = u->surface->visible;
1235 if (memcmp(u->plane_info, &temp_plane_info,
1236 sizeof(struct dc_plane_info)) != 0)
1237 return UPDATE_TYPE_FULL;
1239 if (pixel_format_to_bpp(u->plane_info->format) !=
1240 pixel_format_to_bpp(u->surface->format)) {
1241 return UPDATE_TYPE_FULL;
1243 return UPDATE_TYPE_MED;
1247 static enum surface_update_type get_scaling_info_update_type(
1248 const struct dc_surface_update *u)
1250 if (!u->scaling_info)
1251 return UPDATE_TYPE_FAST;
1253 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
1254 || u->scaling_info->src_rect.height != u->surface->src_rect.height
1255 || u->scaling_info->clip_rect.width != u->surface->clip_rect.width
1256 || u->scaling_info->clip_rect.height != u->surface->clip_rect.height
1257 || u->scaling_info->dst_rect.width != u->surface->dst_rect.width
1258 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height)
1259 return UPDATE_TYPE_FULL;
1261 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
1262 || u->scaling_info->src_rect.y != u->surface->src_rect.y
1263 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
1264 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
1265 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
1266 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
1267 return UPDATE_TYPE_MED;
1269 return UPDATE_TYPE_FAST;
1272 static enum surface_update_type det_surface_update(
1273 const struct core_dc *dc,
1274 const struct dc_surface_update *u,
1277 const struct validate_context *context = dc->current_context;
1278 enum surface_update_type type = UPDATE_TYPE_FAST;
1279 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1281 if (!is_surface_in_context(context, u->surface))
1282 return UPDATE_TYPE_FULL;
1284 type = get_plane_info_update_type(u, surface_index);
1285 if (overall_type < type)
1286 overall_type = type;
1288 type = get_scaling_info_update_type(u);
1289 if (overall_type < type)
1290 overall_type = type;
1292 if (u->in_transfer_func ||
1293 u->hdr_static_metadata) {
1294 if (overall_type < UPDATE_TYPE_MED)
1295 overall_type = UPDATE_TYPE_MED;
1298 return overall_type;
1301 enum surface_update_type dc_check_update_surfaces_for_stream(
1303 struct dc_surface_update *updates,
1305 struct dc_stream_update *stream_update,
1306 const struct dc_stream_status *stream_status)
1308 struct core_dc *core_dc = DC_TO_CORE(dc);
1310 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1312 if (stream_status == NULL || stream_status->surface_count != surface_count)
1313 return UPDATE_TYPE_FULL;
1316 return UPDATE_TYPE_FULL;
1318 for (i = 0 ; i < surface_count; i++) {
1319 enum surface_update_type type =
1320 det_surface_update(core_dc, &updates[i], i);
1322 if (type == UPDATE_TYPE_FULL)
1325 if (overall_type < type)
1326 overall_type = type;
1329 return overall_type;
1332 enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
1334 void dc_update_surfaces_and_stream(struct dc *dc,
1335 struct dc_surface_update *srf_updates, int surface_count,
1336 const struct dc_stream *dc_stream,
1337 struct dc_stream_update *stream_update)
1339 struct core_dc *core_dc = DC_TO_CORE(dc);
1340 struct validate_context *context;
1342 enum surface_update_type update_type;
1343 const struct dc_stream_status *stream_status;
1344 struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
1346 stream_status = dc_stream_get_status(dc_stream);
1347 ASSERT(stream_status);
1349 return; /* Cannot commit surface to stream that is not committed */
1352 if (srf_updates->flip_addr) {
1353 if (srf_updates->flip_addr->address.grph.addr.low_part == 0)
1357 context = core_dc->current_context;
1359 /* update current stream with the new updates */
1360 if (stream_update) {
1361 if ((stream_update->src.height != 0) &&
1362 (stream_update->src.width != 0))
1363 stream->public.src = stream_update->src;
1365 if ((stream_update->dst.height != 0) &&
1366 (stream_update->dst.width != 0))
1367 stream->public.dst = stream_update->dst;
1369 if (stream_update->out_transfer_func &&
1370 stream_update->out_transfer_func !=
1371 dc_stream->out_transfer_func) {
1372 if (dc_stream->out_transfer_func != NULL)
1373 dc_transfer_func_release(dc_stream->out_transfer_func);
1374 dc_transfer_func_retain(stream_update->out_transfer_func);
1375 stream->public.out_transfer_func =
1376 stream_update->out_transfer_func;
1380 /* do not perform surface update if surface has invalid dimensions
1381 * (all zero) and no scaling_info is provided
1383 if (surface_count > 0 &&
1384 srf_updates->surface->src_rect.width == 0 &&
1385 srf_updates->surface->src_rect.height == 0 &&
1386 srf_updates->surface->dst_rect.width == 0 &&
1387 srf_updates->surface->dst_rect.height == 0 &&
1388 !srf_updates->scaling_info) {
1393 update_type = dc_check_update_surfaces_for_stream(
1394 dc, srf_updates, surface_count, stream_update, stream_status);
1396 if (update_type >= update_surface_trace_level)
1397 update_surface_trace(dc, srf_updates, surface_count);
1399 if (update_type >= UPDATE_TYPE_FULL) {
1400 const struct dc_surface *new_surfaces[MAX_SURFACES] = {0};
1402 for (i = 0; i < surface_count; i++)
1403 new_surfaces[i] = srf_updates[i].surface;
1405 /* initialize scratch memory for building context */
1406 context = dm_alloc(sizeof(*context));
1407 dc_resource_validate_ctx_copy_construct(
1408 core_dc->current_context, context);
1410 /* add surface to context */
1411 if (!resource_attach_surfaces_to_context(
1412 new_surfaces, surface_count, dc_stream,
1413 context, core_dc->res_pool)) {
1414 BREAK_TO_DEBUGGER();
1419 /* save update parameters into surface */
1420 for (i = 0; i < surface_count; i++) {
1421 struct core_surface *surface =
1422 DC_SURFACE_TO_CORE(srf_updates[i].surface);
1424 if (srf_updates[i].flip_addr) {
1425 surface->public.address = srf_updates[i].flip_addr->address;
1426 surface->public.flip_immediate =
1427 srf_updates[i].flip_addr->flip_immediate;
1430 if (srf_updates[i].scaling_info) {
1431 surface->public.scaling_quality =
1432 srf_updates[i].scaling_info->scaling_quality;
1433 surface->public.dst_rect =
1434 srf_updates[i].scaling_info->dst_rect;
1435 surface->public.src_rect =
1436 srf_updates[i].scaling_info->src_rect;
1437 surface->public.clip_rect =
1438 srf_updates[i].scaling_info->clip_rect;
1441 if (srf_updates[i].plane_info) {
1442 surface->public.color_space =
1443 srf_updates[i].plane_info->color_space;
1444 surface->public.format =
1445 srf_updates[i].plane_info->format;
1446 surface->public.plane_size =
1447 srf_updates[i].plane_info->plane_size;
1448 surface->public.rotation =
1449 srf_updates[i].plane_info->rotation;
1450 surface->public.horizontal_mirror =
1451 srf_updates[i].plane_info->horizontal_mirror;
1452 surface->public.stereo_format =
1453 srf_updates[i].plane_info->stereo_format;
1454 surface->public.tiling_info =
1455 srf_updates[i].plane_info->tiling_info;
1456 surface->public.visible =
1457 srf_updates[i].plane_info->visible;
1458 surface->public.per_pixel_alpha =
1459 srf_updates[i].plane_info->per_pixel_alpha;
1460 surface->public.dcc =
1461 srf_updates[i].plane_info->dcc;
1464 if (update_type >= UPDATE_TYPE_MED) {
1465 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1466 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1468 if (pipe_ctx->surface != surface)
1471 resource_build_scaling_params(pipe_ctx);
1475 if (srf_updates[i].gamma &&
1476 srf_updates[i].gamma != surface->public.gamma_correction) {
1477 if (surface->public.gamma_correction != NULL)
1478 dc_gamma_release(&surface->public.
1481 dc_gamma_retain(srf_updates[i].gamma);
1482 surface->public.gamma_correction =
1483 srf_updates[i].gamma;
1486 if (srf_updates[i].in_transfer_func &&
1487 srf_updates[i].in_transfer_func != surface->public.in_transfer_func) {
1488 if (surface->public.in_transfer_func != NULL)
1489 dc_transfer_func_release(
1493 dc_transfer_func_retain(
1494 srf_updates[i].in_transfer_func);
1495 surface->public.in_transfer_func =
1496 srf_updates[i].in_transfer_func;
1499 if (srf_updates[i].hdr_static_metadata)
1500 surface->public.hdr_static_ctx =
1501 *(srf_updates[i].hdr_static_metadata);
1504 if (update_type == UPDATE_TYPE_FULL) {
1505 if (!core_dc->res_pool->funcs->validate_bandwidth(core_dc, context)) {
1506 BREAK_TO_DEBUGGER();
1509 core_dc->hwss.set_bandwidth(core_dc, context, false);
1510 context_clock_trace(dc, context);
1514 if (surface_count == 0)
1515 core_dc->hwss.apply_ctx_for_surface(core_dc, NULL, context);
1517 /* Lock pipes for provided surfaces, or all active if full update*/
1518 for (i = 0; i < surface_count; i++) {
1519 struct core_surface *surface = DC_SURFACE_TO_CORE(srf_updates[i].surface);
1521 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1522 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1524 if (update_type != UPDATE_TYPE_FULL && pipe_ctx->surface != surface)
1526 if (!pipe_ctx->surface || pipe_ctx->top_pipe)
1529 if (!pipe_ctx->tg->funcs->is_blanked(pipe_ctx->tg)) {
1530 core_dc->hwss.pipe_control_lock(
1536 if (update_type == UPDATE_TYPE_FULL)
1541 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1542 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1543 struct pipe_ctx *cur_pipe_ctx = &core_dc->current_context->res_ctx.pipe_ctx[j];
1544 bool is_new_pipe_surface = cur_pipe_ctx->surface != pipe_ctx->surface;
1545 struct dc_cursor_position position = { 0 };
1547 if (update_type != UPDATE_TYPE_FULL || !pipe_ctx->surface)
1550 if (!pipe_ctx->top_pipe)
1551 core_dc->hwss.apply_ctx_for_surface(
1552 core_dc, pipe_ctx->surface, context);
1554 /* TODO: this is a hack w/a for switching from mpo to pipe split */
1555 dc_stream_set_cursor_position(&pipe_ctx->stream->public, &position);
1557 if (is_new_pipe_surface) {
1558 core_dc->hwss.update_plane_addr(core_dc, pipe_ctx);
1559 core_dc->hwss.set_input_transfer_func(
1560 pipe_ctx, pipe_ctx->surface);
1561 core_dc->hwss.set_output_transfer_func(
1562 pipe_ctx, pipe_ctx->stream);
1566 if (update_type > UPDATE_TYPE_FAST)
1567 context_timing_trace(dc, &context->res_ctx);
1569 /* Perform requested Updates */
1570 for (i = 0; i < surface_count; i++) {
1571 struct core_surface *surface = DC_SURFACE_TO_CORE(srf_updates[i].surface);
1573 if (update_type == UPDATE_TYPE_MED)
1574 core_dc->hwss.apply_ctx_for_surface(
1575 core_dc, surface, context);
1577 for (j = 0; j < core_dc->res_pool->pipe_count; j++) {
1578 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1580 if (pipe_ctx->surface != surface)
1583 if (srf_updates[i].flip_addr)
1584 core_dc->hwss.update_plane_addr(core_dc, pipe_ctx);
1586 if (update_type == UPDATE_TYPE_FAST)
1589 if (srf_updates[i].in_transfer_func)
1590 core_dc->hwss.set_input_transfer_func(
1591 pipe_ctx, pipe_ctx->surface);
1593 if (stream_update != NULL &&
1594 stream_update->out_transfer_func != NULL) {
1595 core_dc->hwss.set_output_transfer_func(
1596 pipe_ctx, pipe_ctx->stream);
1599 if (srf_updates[i].hdr_static_metadata) {
1600 resource_build_info_frame(pipe_ctx);
1601 core_dc->hwss.update_info_frame(pipe_ctx);
1607 for (i = core_dc->res_pool->pipe_count - 1; i >= 0; i--) {
1608 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1610 for (j = 0; j < surface_count; j++) {
1611 if (update_type != UPDATE_TYPE_FULL &&
1612 srf_updates[j].surface != &pipe_ctx->surface->public)
1614 if (!pipe_ctx->surface || pipe_ctx->top_pipe)
1617 if (!pipe_ctx->tg->funcs->is_blanked(pipe_ctx->tg)) {
1618 core_dc->hwss.pipe_control_lock(
1627 if (core_dc->current_context != context) {
1628 dc_resource_validate_ctx_destruct(core_dc->current_context);
1629 dm_free(core_dc->current_context);
1631 core_dc->current_context = context;
1636 dc_resource_validate_ctx_destruct(context);
1640 uint8_t dc_get_current_stream_count(const struct dc *dc)
1642 struct core_dc *core_dc = DC_TO_CORE(dc);
1643 return core_dc->current_context->stream_count;
1646 struct dc_stream *dc_get_stream_at_index(const struct dc *dc, uint8_t i)
1648 struct core_dc *core_dc = DC_TO_CORE(dc);
1649 if (i < core_dc->current_context->stream_count)
1650 return &(core_dc->current_context->streams[i]->public);
1654 const struct dc_link *dc_get_link_at_index(const struct dc *dc, uint32_t link_index)
1656 struct core_dc *core_dc = DC_TO_CORE(dc);
1657 return &core_dc->links[link_index]->public;
1660 const struct graphics_object_id dc_get_link_id_at_index(
1661 struct dc *dc, uint32_t link_index)
1663 struct core_dc *core_dc = DC_TO_CORE(dc);
1664 return core_dc->links[link_index]->link_id;
1667 enum dc_irq_source dc_get_hpd_irq_source_at_index(
1668 struct dc *dc, uint32_t link_index)
1670 struct core_dc *core_dc = DC_TO_CORE(dc);
1671 return core_dc->links[link_index]->public.irq_source_hpd;
1674 const struct audio **dc_get_audios(struct dc *dc)
1676 struct core_dc *core_dc = DC_TO_CORE(dc);
1677 return (const struct audio **)core_dc->res_pool->audios;
1680 enum dc_irq_source dc_interrupt_to_irq_source(
1685 struct core_dc *core_dc = DC_TO_CORE(dc);
1686 return dal_irq_service_to_irq_source(core_dc->res_pool->irqs, src_id, ext_id);
1689 void dc_interrupt_set(const struct dc *dc, enum dc_irq_source src, bool enable)
1691 struct core_dc *core_dc;
1695 core_dc = DC_TO_CORE(dc);
1697 dal_irq_service_set(core_dc->res_pool->irqs, src, enable);
1700 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
1702 struct core_dc *core_dc = DC_TO_CORE(dc);
1703 dal_irq_service_ack(core_dc->res_pool->irqs, src);
1706 void dc_set_power_state(
1708 enum dc_acpi_cm_power_state power_state)
1710 struct core_dc *core_dc = DC_TO_CORE(dc);
1712 switch (power_state) {
1713 case DC_ACPI_CM_POWER_STATE_D0:
1714 core_dc->hwss.init_hw(core_dc);
1718 core_dc->hwss.power_down(core_dc);
1720 /* Zero out the current context so that on resume we start with
1721 * clean state, and dc hw programming optimizations will not
1722 * cause any trouble.
1724 memset(core_dc->current_context, 0,
1725 sizeof(*core_dc->current_context));
1732 void dc_resume(const struct dc *dc)
1734 struct core_dc *core_dc = DC_TO_CORE(dc);
1738 for (i = 0; i < core_dc->link_count; i++)
1739 core_link_resume(core_dc->links[i]);
1742 bool dc_read_aux_dpcd(
1744 uint32_t link_index,
1749 struct core_dc *core_dc = DC_TO_CORE(dc);
1751 struct core_link *link = core_dc->links[link_index];
1752 enum ddc_result r = dal_ddc_service_read_dpcd_data(
1759 return r == DDC_RESULT_SUCESSFULL;
1762 bool dc_write_aux_dpcd(
1764 uint32_t link_index,
1766 const uint8_t *data,
1769 struct core_dc *core_dc = DC_TO_CORE(dc);
1770 struct core_link *link = core_dc->links[link_index];
1772 enum ddc_result r = dal_ddc_service_write_dpcd_data(
1779 return r == DDC_RESULT_SUCESSFULL;
1782 bool dc_read_aux_i2c(
1784 uint32_t link_index,
1785 enum i2c_mot_mode mot,
1790 struct core_dc *core_dc = DC_TO_CORE(dc);
1792 struct core_link *link = core_dc->links[link_index];
1793 enum ddc_result r = dal_ddc_service_read_dpcd_data(
1800 return r == DDC_RESULT_SUCESSFULL;
1803 bool dc_write_aux_i2c(
1805 uint32_t link_index,
1806 enum i2c_mot_mode mot,
1808 const uint8_t *data,
1811 struct core_dc *core_dc = DC_TO_CORE(dc);
1812 struct core_link *link = core_dc->links[link_index];
1814 enum ddc_result r = dal_ddc_service_write_dpcd_data(
1821 return r == DDC_RESULT_SUCESSFULL;
1824 bool dc_query_ddc_data(
1826 uint32_t link_index,
1829 uint32_t write_size,
1831 uint32_t read_size) {
1833 struct core_dc *core_dc = DC_TO_CORE(dc);
1835 struct core_link *link = core_dc->links[link_index];
1837 bool result = dal_ddc_service_query_ddc_data(
1850 uint32_t link_index,
1851 struct i2c_command *cmd)
1853 struct core_dc *core_dc = DC_TO_CORE(dc);
1855 struct core_link *link = core_dc->links[link_index];
1856 struct ddc_service *ddc = link->public.ddc;
1858 return dal_i2caux_submit_i2c_command(
1864 static bool link_add_remote_sink_helper(struct core_link *core_link, struct dc_sink *sink)
1866 struct dc_link *dc_link = &core_link->public;
1868 if (dc_link->sink_count >= MAX_SINKS_PER_LINK) {
1869 BREAK_TO_DEBUGGER();
1873 dc_sink_retain(sink);
1875 dc_link->remote_sinks[dc_link->sink_count] = sink;
1876 dc_link->sink_count++;
1881 struct dc_sink *dc_link_add_remote_sink(
1882 const struct dc_link *link,
1883 const uint8_t *edid,
1885 struct dc_sink_init_data *init_data)
1887 struct dc_sink *dc_sink;
1888 enum dc_edid_status edid_status;
1889 struct core_link *core_link = DC_LINK_TO_LINK(link);
1891 if (len > MAX_EDID_BUFFER_SIZE) {
1892 dm_error("Max EDID buffer size breached!\n");
1897 BREAK_TO_DEBUGGER();
1901 if (!init_data->link) {
1902 BREAK_TO_DEBUGGER();
1906 dc_sink = dc_sink_create(init_data);
1911 memmove(dc_sink->dc_edid.raw_edid, edid, len);
1912 dc_sink->dc_edid.length = len;
1914 if (!link_add_remote_sink_helper(
1919 edid_status = dm_helpers_parse_edid_caps(
1922 &dc_sink->edid_caps);
1924 if (edid_status != EDID_OK)
1929 dc_link_remove_remote_sink(link, dc_sink);
1931 dc_sink_release(dc_sink);
1935 void dc_link_set_sink(const struct dc_link *link, struct dc_sink *sink)
1937 struct core_link *core_link = DC_LINK_TO_LINK(link);
1938 struct dc_link *dc_link = &core_link->public;
1940 dc_link->local_sink = sink;
1943 dc_link->type = dc_connection_none;
1945 dc_link->type = dc_connection_single;
1949 void dc_link_remove_remote_sink(const struct dc_link *link, const struct dc_sink *sink)
1952 struct core_link *core_link = DC_LINK_TO_LINK(link);
1953 struct dc_link *dc_link = &core_link->public;
1955 if (!link->sink_count) {
1956 BREAK_TO_DEBUGGER();
1960 for (i = 0; i < dc_link->sink_count; i++) {
1961 if (dc_link->remote_sinks[i] == sink) {
1962 dc_sink_release(sink);
1963 dc_link->remote_sinks[i] = NULL;
1965 /* shrink array to remove empty place */
1966 while (i < dc_link->sink_count - 1) {
1967 dc_link->remote_sinks[i] = dc_link->remote_sinks[i+1];
1970 dc_link->remote_sinks[i] = NULL;
1971 dc_link->sink_count--;
1977 bool dc_init_dchub(struct dc *dc, struct dchub_init_data *dh_data)
1980 struct core_dc *core_dc = DC_TO_CORE(dc);
1981 struct mem_input *mi = NULL;
1983 for (i = 0; i < core_dc->res_pool->pipe_count; i++) {
1984 if (core_dc->res_pool->mis[i] != NULL) {
1985 mi = core_dc->res_pool->mis[i];
1990 dm_error("no mem_input!\n");
1994 if (mi->funcs->mem_input_update_dchub)
1995 mi->funcs->mem_input_update_dchub(mi, dh_data);
1997 ASSERT(mi->funcs->mem_input_update_dchub);