1 /* 2 * Copyright 2019 Advanced Micro Devices, Inc. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 #include "dc.h" 27 #include "dc_dmub_srv.h" 28 #include "../dmub/dmub_srv.h" 29 #include "dm_helpers.h" 30 #include "dc_hw_types.h" 31 #include "core_types.h" 32 #include "../basics/conversion.h" 33 #include "cursor_reg_cache.h" 34 35 #define CTX dc_dmub_srv->ctx 36 #define DC_LOGGER CTX->logger 37 38 static void dc_dmub_srv_construct(struct dc_dmub_srv *dc_srv, struct dc *dc, 39 struct dmub_srv *dmub) 40 { 41 dc_srv->dmub = dmub; 42 dc_srv->ctx = dc->ctx; 43 } 44 45 struct dc_dmub_srv *dc_dmub_srv_create(struct dc *dc, struct dmub_srv *dmub) 46 { 47 struct dc_dmub_srv *dc_srv = 48 kzalloc(sizeof(struct dc_dmub_srv), GFP_KERNEL); 49 50 if (dc_srv == NULL) { 51 BREAK_TO_DEBUGGER(); 52 return NULL; 53 } 54 55 dc_dmub_srv_construct(dc_srv, dc, dmub); 56 57 return dc_srv; 58 } 59 60 void dc_dmub_srv_destroy(struct dc_dmub_srv **dmub_srv) 61 { 62 if (*dmub_srv) { 63 kfree(*dmub_srv); 64 *dmub_srv = NULL; 65 } 66 } 67 68 void dc_dmub_srv_wait_idle(struct dc_dmub_srv *dc_dmub_srv) 69 { 70 struct dmub_srv *dmub = dc_dmub_srv->dmub; 71 struct dc_context *dc_ctx = dc_dmub_srv->ctx; 72 enum dmub_status status; 73 74 status = dmub_srv_wait_for_idle(dmub, 100000); 75 if (status != DMUB_STATUS_OK) { 76 DC_ERROR("Error waiting for DMUB idle: status=%d\n", status); 77 dc_dmub_srv_log_diagnostic_data(dc_dmub_srv); 78 } 79 } 80 81 void dc_dmub_srv_clear_inbox0_ack(struct dc_dmub_srv *dmub_srv) 82 { 83 struct dmub_srv *dmub = dmub_srv->dmub; 84 struct dc_context *dc_ctx = dmub_srv->ctx; 85 enum dmub_status status = DMUB_STATUS_OK; 86 87 status = dmub_srv_clear_inbox0_ack(dmub); 88 if (status != DMUB_STATUS_OK) { 89 DC_ERROR("Error clearing INBOX0 ack: status=%d\n", status); 90 dc_dmub_srv_log_diagnostic_data(dmub_srv); 91 } 92 } 93 94 void dc_dmub_srv_wait_for_inbox0_ack(struct dc_dmub_srv *dmub_srv) 95 { 96 struct dmub_srv *dmub = dmub_srv->dmub; 97 struct dc_context *dc_ctx = dmub_srv->ctx; 98 enum dmub_status status = DMUB_STATUS_OK; 99 100 status = dmub_srv_wait_for_inbox0_ack(dmub, 100000); 101 if (status != DMUB_STATUS_OK) { 102 DC_ERROR("Error waiting for INBOX0 HW Lock Ack\n"); 103 dc_dmub_srv_log_diagnostic_data(dmub_srv); 104 } 105 } 106 107 void dc_dmub_srv_send_inbox0_cmd(struct dc_dmub_srv *dmub_srv, 108 union dmub_inbox0_data_register data) 109 { 110 struct dmub_srv *dmub = dmub_srv->dmub; 111 struct dc_context *dc_ctx = dmub_srv->ctx; 112 enum dmub_status status = DMUB_STATUS_OK; 113 114 status = dmub_srv_send_inbox0_cmd(dmub, data); 115 if (status != DMUB_STATUS_OK) { 116 DC_ERROR("Error sending INBOX0 cmd\n"); 117 dc_dmub_srv_log_diagnostic_data(dmub_srv); 118 } 119 } 120 121 bool dc_dmub_srv_cmd_run(struct dc_dmub_srv *dc_dmub_srv, union dmub_rb_cmd *cmd, enum dm_dmub_wait_type wait_type) 122 { 123 return dc_dmub_srv_cmd_run_list(dc_dmub_srv, 1, cmd, wait_type); 124 } 125 126 bool dc_dmub_srv_cmd_run_list(struct dc_dmub_srv *dc_dmub_srv, unsigned int count, union dmub_rb_cmd *cmd_list, enum dm_dmub_wait_type wait_type) 127 { 128 struct dc_context *dc_ctx = dc_dmub_srv->ctx; 129 struct dmub_srv *dmub; 130 enum dmub_status status; 131 int i; 132 133 if (!dc_dmub_srv || !dc_dmub_srv->dmub) 134 return false; 135 136 dmub = dc_dmub_srv->dmub; 137 138 for (i = 0 ; i < count; i++) { 139 // Queue command 140 status = dmub_srv_cmd_queue(dmub, &cmd_list[i]); 141 142 if (status == DMUB_STATUS_QUEUE_FULL) { 143 /* Execute and wait for queue to become empty again. */ 144 dmub_srv_cmd_execute(dmub); 145 dmub_srv_wait_for_idle(dmub, 100000); 146 147 /* Requeue the command. */ 148 status = dmub_srv_cmd_queue(dmub, &cmd_list[i]); 149 } 150 151 if (status != DMUB_STATUS_OK) { 152 DC_ERROR("Error queueing DMUB command: status=%d\n", status); 153 dc_dmub_srv_log_diagnostic_data(dc_dmub_srv); 154 return false; 155 } 156 } 157 158 status = dmub_srv_cmd_execute(dmub); 159 if (status != DMUB_STATUS_OK) { 160 DC_ERROR("Error starting DMUB execution: status=%d\n", status); 161 dc_dmub_srv_log_diagnostic_data(dc_dmub_srv); 162 return false; 163 } 164 165 // Wait for DMUB to process command 166 if (wait_type != DM_DMUB_WAIT_TYPE_NO_WAIT) { 167 status = dmub_srv_wait_for_idle(dmub, 100000); 168 169 if (status != DMUB_STATUS_OK) { 170 DC_LOG_DEBUG("No reply for DMUB command: status=%d\n", status); 171 return false; 172 } 173 174 // Copy data back from ring buffer into command 175 if (wait_type == DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY) 176 dmub_rb_get_return_data(&dmub->inbox1_rb, cmd_list); 177 } 178 179 return true; 180 } 181 182 bool dc_dmub_srv_optimized_init_done(struct dc_dmub_srv *dc_dmub_srv) 183 { 184 struct dmub_srv *dmub; 185 union dmub_fw_boot_status status; 186 187 if (!dc_dmub_srv || !dc_dmub_srv->dmub) 188 return false; 189 190 dmub = dc_dmub_srv->dmub; 191 192 return status.bits.optimized_init_done; 193 } 194 195 bool dc_dmub_srv_notify_stream_mask(struct dc_dmub_srv *dc_dmub_srv, 196 unsigned int stream_mask) 197 { 198 struct dmub_srv *dmub; 199 const uint32_t timeout = 30; 200 201 if (!dc_dmub_srv || !dc_dmub_srv->dmub) 202 return false; 203 204 dmub = dc_dmub_srv->dmub; 205 206 return dmub_srv_send_gpint_command( 207 dmub, DMUB_GPINT__IDLE_OPT_NOTIFY_STREAM_MASK, 208 stream_mask, timeout) == DMUB_STATUS_OK; 209 } 210 211 bool dc_dmub_srv_is_restore_required(struct dc_dmub_srv *dc_dmub_srv) 212 { 213 struct dmub_srv *dmub; 214 struct dc_context *dc_ctx; 215 union dmub_fw_boot_status boot_status; 216 enum dmub_status status; 217 218 if (!dc_dmub_srv || !dc_dmub_srv->dmub) 219 return false; 220 221 dmub = dc_dmub_srv->dmub; 222 dc_ctx = dc_dmub_srv->ctx; 223 224 status = dmub_srv_get_fw_boot_status(dmub, &boot_status); 225 if (status != DMUB_STATUS_OK) { 226 DC_ERROR("Error querying DMUB boot status: error=%d\n", status); 227 return false; 228 } 229 230 return boot_status.bits.restore_required; 231 } 232 233 bool dc_dmub_srv_get_dmub_outbox0_msg(const struct dc *dc, struct dmcub_trace_buf_entry *entry) 234 { 235 struct dmub_srv *dmub = dc->ctx->dmub_srv->dmub; 236 return dmub_srv_get_outbox0_msg(dmub, entry); 237 } 238 239 void dc_dmub_trace_event_control(struct dc *dc, bool enable) 240 { 241 dm_helpers_dmub_outbox_interrupt_control(dc->ctx, enable); 242 } 243 244 void dc_dmub_srv_drr_update_cmd(struct dc *dc, uint32_t tg_inst, uint32_t vtotal_min, uint32_t vtotal_max) 245 { 246 union dmub_rb_cmd cmd = { 0 }; 247 248 cmd.drr_update.header.type = DMUB_CMD__FW_ASSISTED_MCLK_SWITCH; 249 cmd.drr_update.header.sub_type = DMUB_CMD__FAMS_DRR_UPDATE; 250 cmd.drr_update.dmub_optc_state_req.v_total_max = vtotal_max; 251 cmd.drr_update.dmub_optc_state_req.v_total_min = vtotal_min; 252 cmd.drr_update.dmub_optc_state_req.tg_inst = tg_inst; 253 254 cmd.drr_update.header.payload_bytes = sizeof(cmd.drr_update) - sizeof(cmd.drr_update.header); 255 256 // Send the command to the DMCUB. 257 dm_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT); 258 } 259 260 void dc_dmub_srv_set_drr_manual_trigger_cmd(struct dc *dc, uint32_t tg_inst) 261 { 262 union dmub_rb_cmd cmd = { 0 }; 263 264 cmd.drr_update.header.type = DMUB_CMD__FW_ASSISTED_MCLK_SWITCH; 265 cmd.drr_update.header.sub_type = DMUB_CMD__FAMS_SET_MANUAL_TRIGGER; 266 cmd.drr_update.dmub_optc_state_req.tg_inst = tg_inst; 267 268 cmd.drr_update.header.payload_bytes = sizeof(cmd.drr_update) - sizeof(cmd.drr_update.header); 269 270 // Send the command to the DMCUB. 271 dm_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT); 272 } 273 274 static uint8_t dc_dmub_srv_get_pipes_for_stream(struct dc *dc, struct dc_stream_state *stream) 275 { 276 uint8_t pipes = 0; 277 int i = 0; 278 279 for (i = 0; i < MAX_PIPES; i++) { 280 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i]; 281 282 if (pipe->stream == stream && pipe->stream_res.tg) 283 pipes = i; 284 } 285 return pipes; 286 } 287 288 static void dc_dmub_srv_populate_fams_pipe_info(struct dc *dc, struct dc_state *context, 289 struct pipe_ctx *head_pipe, 290 struct dmub_cmd_fw_assisted_mclk_switch_pipe_data *fams_pipe_data) 291 { 292 int j; 293 int pipe_idx = 0; 294 295 fams_pipe_data->pipe_index[pipe_idx++] = head_pipe->plane_res.hubp->inst; 296 for (j = 0; j < dc->res_pool->pipe_count; j++) { 297 struct pipe_ctx *split_pipe = &context->res_ctx.pipe_ctx[j]; 298 299 if (split_pipe->stream == head_pipe->stream && (split_pipe->top_pipe || split_pipe->prev_odm_pipe)) { 300 fams_pipe_data->pipe_index[pipe_idx++] = split_pipe->plane_res.hubp->inst; 301 } 302 } 303 fams_pipe_data->pipe_count = pipe_idx; 304 } 305 306 bool dc_dmub_srv_p_state_delegate(struct dc *dc, bool should_manage_pstate, struct dc_state *context) 307 { 308 union dmub_rb_cmd cmd = { 0 }; 309 struct dmub_cmd_fw_assisted_mclk_switch_config *config_data = &cmd.fw_assisted_mclk_switch.config_data; 310 int i = 0, k = 0; 311 int ramp_up_num_steps = 1; // TODO: Ramp is currently disabled. Reenable it. 312 uint8_t visual_confirm_enabled; 313 int pipe_idx = 0; 314 315 if (dc == NULL) 316 return false; 317 318 visual_confirm_enabled = dc->debug.visual_confirm == VISUAL_CONFIRM_FAMS; 319 320 // Format command. 321 cmd.fw_assisted_mclk_switch.header.type = DMUB_CMD__FW_ASSISTED_MCLK_SWITCH; 322 cmd.fw_assisted_mclk_switch.header.sub_type = DMUB_CMD__FAMS_SETUP_FW_CTRL; 323 cmd.fw_assisted_mclk_switch.config_data.fams_enabled = should_manage_pstate; 324 cmd.fw_assisted_mclk_switch.config_data.visual_confirm_enabled = visual_confirm_enabled; 325 326 if (should_manage_pstate) { 327 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 328 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 329 330 if (!pipe->stream) 331 continue; 332 333 /* If FAMS is being used to support P-State and there is a stream 334 * that does not use FAMS, we are in an FPO + VActive scenario. 335 * Assign vactive stretch margin in this case. 336 */ 337 if (!pipe->stream->fpo_in_use) { 338 cmd.fw_assisted_mclk_switch.config_data.vactive_stretch_margin_us = dc->debug.fpo_vactive_margin_us; 339 break; 340 } 341 pipe_idx++; 342 } 343 } 344 345 for (i = 0, k = 0; context && i < dc->res_pool->pipe_count; i++) { 346 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 347 348 if (!pipe->top_pipe && !pipe->prev_odm_pipe && pipe->stream && pipe->stream->fpo_in_use) { 349 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 350 uint8_t min_refresh_in_hz = (pipe->stream->timing.min_refresh_in_uhz + 999999) / 1000000; 351 352 config_data->pipe_data[k].pix_clk_100hz = pipe->stream->timing.pix_clk_100hz; 353 config_data->pipe_data[k].min_refresh_in_hz = min_refresh_in_hz; 354 config_data->pipe_data[k].max_ramp_step = ramp_up_num_steps; 355 config_data->pipe_data[k].pipes = dc_dmub_srv_get_pipes_for_stream(dc, pipe->stream); 356 dc_dmub_srv_populate_fams_pipe_info(dc, context, pipe, &config_data->pipe_data[k]); 357 k++; 358 } 359 } 360 cmd.fw_assisted_mclk_switch.header.payload_bytes = 361 sizeof(cmd.fw_assisted_mclk_switch) - sizeof(cmd.fw_assisted_mclk_switch.header); 362 363 // Send the command to the DMCUB. 364 dm_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT); 365 366 return true; 367 } 368 369 void dc_dmub_srv_query_caps_cmd(struct dc_dmub_srv *dc_dmub_srv) 370 { 371 union dmub_rb_cmd cmd = { 0 }; 372 373 memset(&cmd, 0, sizeof(cmd)); 374 375 /* Prepare fw command */ 376 cmd.query_feature_caps.header.type = DMUB_CMD__QUERY_FEATURE_CAPS; 377 cmd.query_feature_caps.header.sub_type = 0; 378 cmd.query_feature_caps.header.ret_status = 1; 379 cmd.query_feature_caps.header.payload_bytes = sizeof(struct dmub_cmd_query_feature_caps_data); 380 381 /* If command was processed, copy feature caps to dmub srv */ 382 if (dm_execute_dmub_cmd(dc_dmub_srv->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY) && 383 cmd.query_feature_caps.header.ret_status == 0) { 384 memcpy(&dc_dmub_srv->dmub->feature_caps, 385 &cmd.query_feature_caps.query_feature_caps_data, 386 sizeof(struct dmub_feature_caps)); 387 } 388 } 389 390 void dc_dmub_srv_get_visual_confirm_color_cmd(struct dc *dc, struct pipe_ctx *pipe_ctx) 391 { 392 union dmub_rb_cmd cmd = { 0 }; 393 unsigned int panel_inst = 0; 394 395 dc_get_edp_link_panel_inst(dc, pipe_ctx->stream->link, &panel_inst); 396 397 memset(&cmd, 0, sizeof(cmd)); 398 399 // Prepare fw command 400 cmd.visual_confirm_color.header.type = DMUB_CMD__GET_VISUAL_CONFIRM_COLOR; 401 cmd.visual_confirm_color.header.sub_type = 0; 402 cmd.visual_confirm_color.header.ret_status = 1; 403 cmd.visual_confirm_color.header.payload_bytes = sizeof(struct dmub_cmd_visual_confirm_color_data); 404 cmd.visual_confirm_color.visual_confirm_color_data.visual_confirm_color.panel_inst = panel_inst; 405 406 // If command was processed, copy feature caps to dmub srv 407 if (dm_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY) && 408 cmd.visual_confirm_color.header.ret_status == 0) { 409 memcpy(&dc->ctx->dmub_srv->dmub->visual_confirm_color, 410 &cmd.visual_confirm_color.visual_confirm_color_data, 411 sizeof(struct dmub_visual_confirm_color)); 412 } 413 } 414 415 /** 416 * populate_subvp_cmd_drr_info - Helper to populate DRR pipe info for the DMCUB subvp command 417 * 418 * @dc: [in] current dc state 419 * @subvp_pipe: [in] pipe_ctx for the SubVP pipe 420 * @vblank_pipe: [in] pipe_ctx for the DRR pipe 421 * @pipe_data: [in] Pipe data which stores the VBLANK/DRR info 422 * 423 * Populate the DMCUB SubVP command with DRR pipe info. All the information 424 * required for calculating the SubVP + DRR microschedule is populated here. 425 * 426 * High level algorithm: 427 * 1. Get timing for SubVP pipe, phantom pipe, and DRR pipe 428 * 2. Calculate the min and max vtotal which supports SubVP + DRR microschedule 429 * 3. Populate the drr_info with the min and max supported vtotal values 430 */ 431 static void populate_subvp_cmd_drr_info(struct dc *dc, 432 struct pipe_ctx *subvp_pipe, 433 struct pipe_ctx *vblank_pipe, 434 struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data) 435 { 436 struct dc_crtc_timing *main_timing = &subvp_pipe->stream->timing; 437 struct dc_crtc_timing *phantom_timing = &subvp_pipe->stream->mall_stream_config.paired_stream->timing; 438 struct dc_crtc_timing *drr_timing = &vblank_pipe->stream->timing; 439 uint16_t drr_frame_us = 0; 440 uint16_t min_drr_supported_us = 0; 441 uint16_t max_drr_supported_us = 0; 442 uint16_t max_drr_vblank_us = 0; 443 uint16_t max_drr_mallregion_us = 0; 444 uint16_t mall_region_us = 0; 445 uint16_t prefetch_us = 0; 446 uint16_t subvp_active_us = 0; 447 uint16_t drr_active_us = 0; 448 uint16_t min_vtotal_supported = 0; 449 uint16_t max_vtotal_supported = 0; 450 451 pipe_data->pipe_config.vblank_data.drr_info.drr_in_use = true; 452 pipe_data->pipe_config.vblank_data.drr_info.use_ramping = false; // for now don't use ramping 453 pipe_data->pipe_config.vblank_data.drr_info.drr_window_size_ms = 4; // hardcode 4ms DRR window for now 454 455 drr_frame_us = div64_u64(((uint64_t)drr_timing->v_total * drr_timing->h_total * 1000000), 456 (((uint64_t)drr_timing->pix_clk_100hz * 100))); 457 // P-State allow width and FW delays already included phantom_timing->v_addressable 458 mall_region_us = div64_u64(((uint64_t)phantom_timing->v_addressable * phantom_timing->h_total * 1000000), 459 (((uint64_t)phantom_timing->pix_clk_100hz * 100))); 460 min_drr_supported_us = drr_frame_us + mall_region_us + SUBVP_DRR_MARGIN_US; 461 min_vtotal_supported = div64_u64(((uint64_t)drr_timing->pix_clk_100hz * 100 * min_drr_supported_us), 462 (((uint64_t)drr_timing->h_total * 1000000))); 463 464 prefetch_us = div64_u64(((uint64_t)(phantom_timing->v_total - phantom_timing->v_front_porch) * phantom_timing->h_total * 1000000), 465 (((uint64_t)phantom_timing->pix_clk_100hz * 100) + dc->caps.subvp_prefetch_end_to_mall_start_us)); 466 subvp_active_us = div64_u64(((uint64_t)main_timing->v_addressable * main_timing->h_total * 1000000), 467 (((uint64_t)main_timing->pix_clk_100hz * 100))); 468 drr_active_us = div64_u64(((uint64_t)drr_timing->v_addressable * drr_timing->h_total * 1000000), 469 (((uint64_t)drr_timing->pix_clk_100hz * 100))); 470 max_drr_vblank_us = div64_u64((subvp_active_us - prefetch_us - 471 dc->caps.subvp_fw_processing_delay_us - drr_active_us), 2) + drr_active_us; 472 max_drr_mallregion_us = subvp_active_us - prefetch_us - mall_region_us - dc->caps.subvp_fw_processing_delay_us; 473 max_drr_supported_us = max_drr_vblank_us > max_drr_mallregion_us ? max_drr_vblank_us : max_drr_mallregion_us; 474 max_vtotal_supported = div64_u64(((uint64_t)drr_timing->pix_clk_100hz * 100 * max_drr_supported_us), 475 (((uint64_t)drr_timing->h_total * 1000000))); 476 477 /* When calculating the max vtotal supported for SubVP + DRR cases, add 478 * margin due to possible rounding errors (being off by 1 line in the 479 * FW calculation can incorrectly push the P-State switch to wait 1 frame 480 * longer). 481 */ 482 max_vtotal_supported = max_vtotal_supported - dc->caps.subvp_drr_max_vblank_margin_us; 483 484 pipe_data->pipe_config.vblank_data.drr_info.min_vtotal_supported = min_vtotal_supported; 485 pipe_data->pipe_config.vblank_data.drr_info.max_vtotal_supported = max_vtotal_supported; 486 pipe_data->pipe_config.vblank_data.drr_info.drr_vblank_start_margin = dc->caps.subvp_drr_vblank_start_margin_us; 487 } 488 489 /** 490 * populate_subvp_cmd_vblank_pipe_info - Helper to populate VBLANK pipe info for the DMUB subvp command 491 * 492 * @dc: [in] current dc state 493 * @context: [in] new dc state 494 * @cmd: [in] DMUB cmd to be populated with SubVP info 495 * @vblank_pipe: [in] pipe_ctx for the VBLANK pipe 496 * @cmd_pipe_index: [in] index for the pipe array in DMCUB SubVP cmd 497 * 498 * Populate the DMCUB SubVP command with VBLANK pipe info. All the information 499 * required to calculate the microschedule for SubVP + VBLANK case is stored in 500 * the pipe_data (subvp_data and vblank_data). Also check if the VBLANK pipe 501 * is a DRR display -- if it is make a call to populate drr_info. 502 */ 503 static void populate_subvp_cmd_vblank_pipe_info(struct dc *dc, 504 struct dc_state *context, 505 union dmub_rb_cmd *cmd, 506 struct pipe_ctx *vblank_pipe, 507 uint8_t cmd_pipe_index) 508 { 509 uint32_t i; 510 struct pipe_ctx *pipe = NULL; 511 struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data = 512 &cmd->fw_assisted_mclk_switch_v2.config_data.pipe_data[cmd_pipe_index]; 513 514 // Find the SubVP pipe 515 for (i = 0; i < dc->res_pool->pipe_count; i++) { 516 pipe = &context->res_ctx.pipe_ctx[i]; 517 518 // We check for master pipe, but it shouldn't matter since we only need 519 // the pipe for timing info (stream should be same for any pipe splits) 520 if (!pipe->stream || !pipe->plane_state || pipe->top_pipe || pipe->prev_odm_pipe) 521 continue; 522 523 // Find the SubVP pipe 524 if (pipe->stream->mall_stream_config.type == SUBVP_MAIN) 525 break; 526 } 527 528 pipe_data->mode = VBLANK; 529 pipe_data->pipe_config.vblank_data.pix_clk_100hz = vblank_pipe->stream->timing.pix_clk_100hz; 530 pipe_data->pipe_config.vblank_data.vblank_start = vblank_pipe->stream->timing.v_total - 531 vblank_pipe->stream->timing.v_front_porch; 532 pipe_data->pipe_config.vblank_data.vtotal = vblank_pipe->stream->timing.v_total; 533 pipe_data->pipe_config.vblank_data.htotal = vblank_pipe->stream->timing.h_total; 534 pipe_data->pipe_config.vblank_data.vblank_pipe_index = vblank_pipe->pipe_idx; 535 pipe_data->pipe_config.vblank_data.vstartup_start = vblank_pipe->pipe_dlg_param.vstartup_start; 536 pipe_data->pipe_config.vblank_data.vblank_end = 537 vblank_pipe->stream->timing.v_total - vblank_pipe->stream->timing.v_front_porch - vblank_pipe->stream->timing.v_addressable; 538 539 if (vblank_pipe->stream->ignore_msa_timing_param) 540 populate_subvp_cmd_drr_info(dc, pipe, vblank_pipe, pipe_data); 541 } 542 543 /** 544 * update_subvp_prefetch_end_to_mall_start - Helper for SubVP + SubVP case 545 * 546 * @dc: [in] current dc state 547 * @context: [in] new dc state 548 * @cmd: [in] DMUB cmd to be populated with SubVP info 549 * @subvp_pipes: [in] Array of SubVP pipes (should always be length 2) 550 * 551 * For SubVP + SubVP, we use a single vertical interrupt to start the 552 * microschedule for both SubVP pipes. In order for this to work correctly, the 553 * MALL REGION of both SubVP pipes must start at the same time. This function 554 * lengthens the prefetch end to mall start delay of the SubVP pipe that has 555 * the shorter prefetch so that both MALL REGION's will start at the same time. 556 */ 557 static void update_subvp_prefetch_end_to_mall_start(struct dc *dc, 558 struct dc_state *context, 559 union dmub_rb_cmd *cmd, 560 struct pipe_ctx *subvp_pipes[]) 561 { 562 uint32_t subvp0_prefetch_us = 0; 563 uint32_t subvp1_prefetch_us = 0; 564 uint32_t prefetch_delta_us = 0; 565 struct dc_crtc_timing *phantom_timing0 = &subvp_pipes[0]->stream->mall_stream_config.paired_stream->timing; 566 struct dc_crtc_timing *phantom_timing1 = &subvp_pipes[1]->stream->mall_stream_config.paired_stream->timing; 567 struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data = NULL; 568 569 subvp0_prefetch_us = div64_u64(((uint64_t)(phantom_timing0->v_total - phantom_timing0->v_front_porch) * 570 (uint64_t)phantom_timing0->h_total * 1000000), 571 (((uint64_t)phantom_timing0->pix_clk_100hz * 100) + dc->caps.subvp_prefetch_end_to_mall_start_us)); 572 subvp1_prefetch_us = div64_u64(((uint64_t)(phantom_timing1->v_total - phantom_timing1->v_front_porch) * 573 (uint64_t)phantom_timing1->h_total * 1000000), 574 (((uint64_t)phantom_timing1->pix_clk_100hz * 100) + dc->caps.subvp_prefetch_end_to_mall_start_us)); 575 576 // Whichever SubVP PIPE has the smaller prefetch (including the prefetch end to mall start time) 577 // should increase it's prefetch time to match the other 578 if (subvp0_prefetch_us > subvp1_prefetch_us) { 579 pipe_data = &cmd->fw_assisted_mclk_switch_v2.config_data.pipe_data[1]; 580 prefetch_delta_us = subvp0_prefetch_us - subvp1_prefetch_us; 581 pipe_data->pipe_config.subvp_data.prefetch_to_mall_start_lines = 582 div64_u64(((uint64_t)(dc->caps.subvp_prefetch_end_to_mall_start_us + prefetch_delta_us) * 583 ((uint64_t)phantom_timing1->pix_clk_100hz * 100) + ((uint64_t)phantom_timing1->h_total * 1000000 - 1)), 584 ((uint64_t)phantom_timing1->h_total * 1000000)); 585 586 } else if (subvp1_prefetch_us > subvp0_prefetch_us) { 587 pipe_data = &cmd->fw_assisted_mclk_switch_v2.config_data.pipe_data[0]; 588 prefetch_delta_us = subvp1_prefetch_us - subvp0_prefetch_us; 589 pipe_data->pipe_config.subvp_data.prefetch_to_mall_start_lines = 590 div64_u64(((uint64_t)(dc->caps.subvp_prefetch_end_to_mall_start_us + prefetch_delta_us) * 591 ((uint64_t)phantom_timing0->pix_clk_100hz * 100) + ((uint64_t)phantom_timing0->h_total * 1000000 - 1)), 592 ((uint64_t)phantom_timing0->h_total * 1000000)); 593 } 594 } 595 596 /** 597 * populate_subvp_cmd_pipe_info - Helper to populate the SubVP pipe info for the DMUB subvp command 598 * 599 * @dc: [in] current dc state 600 * @context: [in] new dc state 601 * @cmd: [in] DMUB cmd to be populated with SubVP info 602 * @subvp_pipe: [in] pipe_ctx for the SubVP pipe 603 * @cmd_pipe_index: [in] index for the pipe array in DMCUB SubVP cmd 604 * 605 * Populate the DMCUB SubVP command with SubVP pipe info. All the information 606 * required to calculate the microschedule for the SubVP pipe is stored in the 607 * pipe_data of the DMCUB SubVP command. 608 */ 609 static void populate_subvp_cmd_pipe_info(struct dc *dc, 610 struct dc_state *context, 611 union dmub_rb_cmd *cmd, 612 struct pipe_ctx *subvp_pipe, 613 uint8_t cmd_pipe_index) 614 { 615 uint32_t j; 616 struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data = 617 &cmd->fw_assisted_mclk_switch_v2.config_data.pipe_data[cmd_pipe_index]; 618 struct dc_crtc_timing *main_timing = &subvp_pipe->stream->timing; 619 struct dc_crtc_timing *phantom_timing = &subvp_pipe->stream->mall_stream_config.paired_stream->timing; 620 uint32_t out_num_stream, out_den_stream, out_num_plane, out_den_plane, out_num, out_den; 621 622 pipe_data->mode = SUBVP; 623 pipe_data->pipe_config.subvp_data.pix_clk_100hz = subvp_pipe->stream->timing.pix_clk_100hz; 624 pipe_data->pipe_config.subvp_data.htotal = subvp_pipe->stream->timing.h_total; 625 pipe_data->pipe_config.subvp_data.vtotal = subvp_pipe->stream->timing.v_total; 626 pipe_data->pipe_config.subvp_data.main_vblank_start = 627 main_timing->v_total - main_timing->v_front_porch; 628 pipe_data->pipe_config.subvp_data.main_vblank_end = 629 main_timing->v_total - main_timing->v_front_porch - main_timing->v_addressable; 630 pipe_data->pipe_config.subvp_data.mall_region_lines = phantom_timing->v_addressable; 631 pipe_data->pipe_config.subvp_data.main_pipe_index = subvp_pipe->stream_res.tg->inst; 632 pipe_data->pipe_config.subvp_data.is_drr = subvp_pipe->stream->ignore_msa_timing_param; 633 634 /* Calculate the scaling factor from the src and dst height. 635 * e.g. If 3840x2160 being downscaled to 1920x1080, the scaling factor is 1/2. 636 * Reduce the fraction 1080/2160 = 1/2 for the "scaling factor" 637 * 638 * Make sure to combine stream and plane scaling together. 639 */ 640 reduce_fraction(subvp_pipe->stream->src.height, subvp_pipe->stream->dst.height, 641 &out_num_stream, &out_den_stream); 642 reduce_fraction(subvp_pipe->plane_state->src_rect.height, subvp_pipe->plane_state->dst_rect.height, 643 &out_num_plane, &out_den_plane); 644 reduce_fraction(out_num_stream * out_num_plane, out_den_stream * out_den_plane, &out_num, &out_den); 645 pipe_data->pipe_config.subvp_data.scale_factor_numerator = out_num; 646 pipe_data->pipe_config.subvp_data.scale_factor_denominator = out_den; 647 648 // Prefetch lines is equal to VACTIVE + BP + VSYNC 649 pipe_data->pipe_config.subvp_data.prefetch_lines = 650 phantom_timing->v_total - phantom_timing->v_front_porch; 651 652 // Round up 653 pipe_data->pipe_config.subvp_data.prefetch_to_mall_start_lines = 654 div64_u64(((uint64_t)dc->caps.subvp_prefetch_end_to_mall_start_us * ((uint64_t)phantom_timing->pix_clk_100hz * 100) + 655 ((uint64_t)phantom_timing->h_total * 1000000 - 1)), ((uint64_t)phantom_timing->h_total * 1000000)); 656 pipe_data->pipe_config.subvp_data.processing_delay_lines = 657 div64_u64(((uint64_t)(dc->caps.subvp_fw_processing_delay_us) * ((uint64_t)phantom_timing->pix_clk_100hz * 100) + 658 ((uint64_t)phantom_timing->h_total * 1000000 - 1)), ((uint64_t)phantom_timing->h_total * 1000000)); 659 660 if (subvp_pipe->bottom_pipe) { 661 pipe_data->pipe_config.subvp_data.main_split_pipe_index = subvp_pipe->bottom_pipe->pipe_idx; 662 } else if (subvp_pipe->next_odm_pipe) { 663 pipe_data->pipe_config.subvp_data.main_split_pipe_index = subvp_pipe->next_odm_pipe->pipe_idx; 664 } else { 665 pipe_data->pipe_config.subvp_data.main_split_pipe_index = 0; 666 } 667 668 // Find phantom pipe index based on phantom stream 669 for (j = 0; j < dc->res_pool->pipe_count; j++) { 670 struct pipe_ctx *phantom_pipe = &context->res_ctx.pipe_ctx[j]; 671 672 if (phantom_pipe->stream == subvp_pipe->stream->mall_stream_config.paired_stream) { 673 pipe_data->pipe_config.subvp_data.phantom_pipe_index = phantom_pipe->stream_res.tg->inst; 674 if (phantom_pipe->bottom_pipe) { 675 pipe_data->pipe_config.subvp_data.phantom_split_pipe_index = phantom_pipe->bottom_pipe->plane_res.hubp->inst; 676 } else if (phantom_pipe->next_odm_pipe) { 677 pipe_data->pipe_config.subvp_data.phantom_split_pipe_index = phantom_pipe->next_odm_pipe->plane_res.hubp->inst; 678 } else { 679 pipe_data->pipe_config.subvp_data.phantom_split_pipe_index = 0; 680 } 681 break; 682 } 683 } 684 } 685 686 /** 687 * dc_dmub_setup_subvp_dmub_command - Populate the DMCUB SubVP command 688 * 689 * @dc: [in] current dc state 690 * @context: [in] new dc state 691 * @enable: [in] if true enables the pipes population 692 * 693 * This function loops through each pipe and populates the DMUB SubVP CMD info 694 * based on the pipe (e.g. SubVP, VBLANK). 695 */ 696 void dc_dmub_setup_subvp_dmub_command(struct dc *dc, 697 struct dc_state *context, 698 bool enable) 699 { 700 uint8_t cmd_pipe_index = 0; 701 uint32_t i, pipe_idx; 702 uint8_t subvp_count = 0; 703 union dmub_rb_cmd cmd; 704 struct pipe_ctx *subvp_pipes[2]; 705 uint32_t wm_val_refclk = 0; 706 707 memset(&cmd, 0, sizeof(cmd)); 708 // FW command for SUBVP 709 cmd.fw_assisted_mclk_switch_v2.header.type = DMUB_CMD__FW_ASSISTED_MCLK_SWITCH; 710 cmd.fw_assisted_mclk_switch_v2.header.sub_type = DMUB_CMD__HANDLE_SUBVP_CMD; 711 cmd.fw_assisted_mclk_switch_v2.header.payload_bytes = 712 sizeof(cmd.fw_assisted_mclk_switch_v2) - sizeof(cmd.fw_assisted_mclk_switch_v2.header); 713 714 for (i = 0; i < dc->res_pool->pipe_count; i++) { 715 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 716 717 if (!pipe->stream) 718 continue; 719 720 /* For SubVP pipe count, only count the top most (ODM / MPC) pipe 721 */ 722 if (pipe->plane_state && !pipe->top_pipe && !pipe->prev_odm_pipe && 723 pipe->stream->mall_stream_config.type == SUBVP_MAIN) 724 subvp_pipes[subvp_count++] = pipe; 725 } 726 727 if (enable) { 728 // For each pipe that is a "main" SUBVP pipe, fill in pipe data for DMUB SUBVP cmd 729 for (i = 0, pipe_idx = 0; i < dc->res_pool->pipe_count; i++) { 730 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i]; 731 732 if (!pipe->stream) 733 continue; 734 735 /* When populating subvp cmd info, only pass in the top most (ODM / MPC) pipe. 736 * Any ODM or MPC splits being used in SubVP will be handled internally in 737 * populate_subvp_cmd_pipe_info 738 */ 739 if (pipe->plane_state && pipe->stream->mall_stream_config.paired_stream && 740 !pipe->top_pipe && !pipe->prev_odm_pipe && 741 pipe->stream->mall_stream_config.type == SUBVP_MAIN) { 742 populate_subvp_cmd_pipe_info(dc, context, &cmd, pipe, cmd_pipe_index++); 743 } else if (pipe->plane_state && pipe->stream->mall_stream_config.type == SUBVP_NONE && 744 !pipe->top_pipe && !pipe->prev_odm_pipe) { 745 // Don't need to check for ActiveDRAMClockChangeMargin < 0, not valid in cases where 746 // we run through DML without calculating "natural" P-state support 747 populate_subvp_cmd_vblank_pipe_info(dc, context, &cmd, pipe, cmd_pipe_index++); 748 749 } 750 pipe_idx++; 751 } 752 if (subvp_count == 2) { 753 update_subvp_prefetch_end_to_mall_start(dc, context, &cmd, subvp_pipes); 754 } 755 cmd.fw_assisted_mclk_switch_v2.config_data.pstate_allow_width_us = dc->caps.subvp_pstate_allow_width_us; 756 cmd.fw_assisted_mclk_switch_v2.config_data.vertical_int_margin_us = dc->caps.subvp_vertical_int_margin_us; 757 758 // Store the original watermark value for this SubVP config so we can lower it when the 759 // MCLK switch starts 760 wm_val_refclk = context->bw_ctx.bw.dcn.watermarks.a.cstate_pstate.pstate_change_ns * 761 (dc->res_pool->ref_clocks.dchub_ref_clock_inKhz / 1000) / 1000; 762 763 cmd.fw_assisted_mclk_switch_v2.config_data.watermark_a_cache = wm_val_refclk < 0xFFFF ? wm_val_refclk : 0xFFFF; 764 } 765 766 dm_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT); 767 } 768 769 bool dc_dmub_srv_get_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv, struct dmub_diagnostic_data *diag_data) 770 { 771 if (!dc_dmub_srv || !dc_dmub_srv->dmub || !diag_data) 772 return false; 773 return dmub_srv_get_diagnostic_data(dc_dmub_srv->dmub, diag_data); 774 } 775 776 void dc_dmub_srv_log_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv) 777 { 778 struct dmub_diagnostic_data diag_data = {0}; 779 780 if (!dc_dmub_srv || !dc_dmub_srv->dmub) { 781 DC_LOG_ERROR("%s: invalid parameters.", __func__); 782 return; 783 } 784 785 if (!dc_dmub_srv_get_diagnostic_data(dc_dmub_srv, &diag_data)) { 786 DC_LOG_ERROR("%s: dc_dmub_srv_get_diagnostic_data failed.", __func__); 787 return; 788 } 789 790 DC_LOG_DEBUG( 791 "DMCUB STATE\n" 792 " dmcub_version : %08x\n" 793 " scratch [0] : %08x\n" 794 " scratch [1] : %08x\n" 795 " scratch [2] : %08x\n" 796 " scratch [3] : %08x\n" 797 " scratch [4] : %08x\n" 798 " scratch [5] : %08x\n" 799 " scratch [6] : %08x\n" 800 " scratch [7] : %08x\n" 801 " scratch [8] : %08x\n" 802 " scratch [9] : %08x\n" 803 " scratch [10] : %08x\n" 804 " scratch [11] : %08x\n" 805 " scratch [12] : %08x\n" 806 " scratch [13] : %08x\n" 807 " scratch [14] : %08x\n" 808 " scratch [15] : %08x\n" 809 " pc : %08x\n" 810 " unk_fault_addr : %08x\n" 811 " inst_fault_addr : %08x\n" 812 " data_fault_addr : %08x\n" 813 " inbox1_rptr : %08x\n" 814 " inbox1_wptr : %08x\n" 815 " inbox1_size : %08x\n" 816 " inbox0_rptr : %08x\n" 817 " inbox0_wptr : %08x\n" 818 " inbox0_size : %08x\n" 819 " is_enabled : %d\n" 820 " is_soft_reset : %d\n" 821 " is_secure_reset : %d\n" 822 " is_traceport_en : %d\n" 823 " is_cw0_en : %d\n" 824 " is_cw6_en : %d\n", 825 diag_data.dmcub_version, 826 diag_data.scratch[0], 827 diag_data.scratch[1], 828 diag_data.scratch[2], 829 diag_data.scratch[3], 830 diag_data.scratch[4], 831 diag_data.scratch[5], 832 diag_data.scratch[6], 833 diag_data.scratch[7], 834 diag_data.scratch[8], 835 diag_data.scratch[9], 836 diag_data.scratch[10], 837 diag_data.scratch[11], 838 diag_data.scratch[12], 839 diag_data.scratch[13], 840 diag_data.scratch[14], 841 diag_data.scratch[15], 842 diag_data.pc, 843 diag_data.undefined_address_fault_addr, 844 diag_data.inst_fetch_fault_addr, 845 diag_data.data_write_fault_addr, 846 diag_data.inbox1_rptr, 847 diag_data.inbox1_wptr, 848 diag_data.inbox1_size, 849 diag_data.inbox0_rptr, 850 diag_data.inbox0_wptr, 851 diag_data.inbox0_size, 852 diag_data.is_dmcub_enabled, 853 diag_data.is_dmcub_soft_reset, 854 diag_data.is_dmcub_secure_reset, 855 diag_data.is_traceport_en, 856 diag_data.is_cw0_enabled, 857 diag_data.is_cw6_enabled); 858 } 859 860 static bool dc_can_pipe_disable_cursor(struct pipe_ctx *pipe_ctx) 861 { 862 struct pipe_ctx *test_pipe, *split_pipe; 863 const struct scaler_data *scl_data = &pipe_ctx->plane_res.scl_data; 864 struct rect r1 = scl_data->recout, r2, r2_half; 865 int r1_r = r1.x + r1.width, r1_b = r1.y + r1.height, r2_r, r2_b; 866 int cur_layer = pipe_ctx->plane_state->layer_index; 867 868 /** 869 * Disable the cursor if there's another pipe above this with a 870 * plane that contains this pipe's viewport to prevent double cursor 871 * and incorrect scaling artifacts. 872 */ 873 for (test_pipe = pipe_ctx->top_pipe; test_pipe; 874 test_pipe = test_pipe->top_pipe) { 875 // Skip invisible layer and pipe-split plane on same layer 876 if (!test_pipe->plane_state->visible || test_pipe->plane_state->layer_index == cur_layer) 877 continue; 878 879 r2 = test_pipe->plane_res.scl_data.recout; 880 r2_r = r2.x + r2.width; 881 r2_b = r2.y + r2.height; 882 split_pipe = test_pipe; 883 884 /** 885 * There is another half plane on same layer because of 886 * pipe-split, merge together per same height. 887 */ 888 for (split_pipe = pipe_ctx->top_pipe; split_pipe; 889 split_pipe = split_pipe->top_pipe) 890 if (split_pipe->plane_state->layer_index == test_pipe->plane_state->layer_index) { 891 r2_half = split_pipe->plane_res.scl_data.recout; 892 r2.x = (r2_half.x < r2.x) ? r2_half.x : r2.x; 893 r2.width = r2.width + r2_half.width; 894 r2_r = r2.x + r2.width; 895 break; 896 } 897 898 if (r1.x >= r2.x && r1.y >= r2.y && r1_r <= r2_r && r1_b <= r2_b) 899 return true; 900 } 901 902 return false; 903 } 904 905 static bool dc_dmub_should_update_cursor_data(struct pipe_ctx *pipe_ctx) 906 { 907 if (pipe_ctx->plane_state != NULL) { 908 if (pipe_ctx->plane_state->address.type == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE) 909 return false; 910 911 if (dc_can_pipe_disable_cursor(pipe_ctx)) 912 return false; 913 } 914 915 if ((pipe_ctx->stream->link->psr_settings.psr_version == DC_PSR_VERSION_SU_1 || 916 pipe_ctx->stream->link->psr_settings.psr_version == DC_PSR_VERSION_1) && 917 pipe_ctx->stream->ctx->dce_version >= DCN_VERSION_3_1) 918 return true; 919 920 return false; 921 } 922 923 static void dc_build_cursor_update_payload0( 924 struct pipe_ctx *pipe_ctx, uint8_t p_idx, 925 struct dmub_cmd_update_cursor_payload0 *payload) 926 { 927 struct hubp *hubp = pipe_ctx->plane_res.hubp; 928 unsigned int panel_inst = 0; 929 930 if (!dc_get_edp_link_panel_inst(hubp->ctx->dc, 931 pipe_ctx->stream->link, &panel_inst)) 932 return; 933 934 /* Payload: Cursor Rect is built from position & attribute 935 * x & y are obtained from postion 936 */ 937 payload->cursor_rect.x = hubp->cur_rect.x; 938 payload->cursor_rect.y = hubp->cur_rect.y; 939 /* w & h are obtained from attribute */ 940 payload->cursor_rect.width = hubp->cur_rect.w; 941 payload->cursor_rect.height = hubp->cur_rect.h; 942 943 payload->enable = hubp->pos.cur_ctl.bits.cur_enable; 944 payload->pipe_idx = p_idx; 945 payload->cmd_version = DMUB_CMD_PSR_CONTROL_VERSION_1; 946 payload->panel_inst = panel_inst; 947 } 948 949 static void dc_build_cursor_position_update_payload0( 950 struct dmub_cmd_update_cursor_payload0 *pl, const uint8_t p_idx, 951 const struct hubp *hubp, const struct dpp *dpp) 952 { 953 /* Hubp */ 954 pl->position_cfg.pHubp.cur_ctl.raw = hubp->pos.cur_ctl.raw; 955 pl->position_cfg.pHubp.position.raw = hubp->pos.position.raw; 956 pl->position_cfg.pHubp.hot_spot.raw = hubp->pos.hot_spot.raw; 957 pl->position_cfg.pHubp.dst_offset.raw = hubp->pos.dst_offset.raw; 958 959 /* dpp */ 960 pl->position_cfg.pDpp.cur0_ctl.raw = dpp->pos.cur0_ctl.raw; 961 pl->position_cfg.pipe_idx = p_idx; 962 } 963 964 static void dc_build_cursor_attribute_update_payload1( 965 struct dmub_cursor_attributes_cfg *pl_A, const uint8_t p_idx, 966 const struct hubp *hubp, const struct dpp *dpp) 967 { 968 /* Hubp */ 969 pl_A->aHubp.SURFACE_ADDR_HIGH = hubp->att.SURFACE_ADDR_HIGH; 970 pl_A->aHubp.SURFACE_ADDR = hubp->att.SURFACE_ADDR; 971 pl_A->aHubp.cur_ctl.raw = hubp->att.cur_ctl.raw; 972 pl_A->aHubp.size.raw = hubp->att.size.raw; 973 pl_A->aHubp.settings.raw = hubp->att.settings.raw; 974 975 /* dpp */ 976 pl_A->aDpp.cur0_ctl.raw = dpp->att.cur0_ctl.raw; 977 } 978 979 /** 980 * dc_send_update_cursor_info_to_dmu - Populate the DMCUB Cursor update info command 981 * 982 * @pCtx: [in] pipe context 983 * @pipe_idx: [in] pipe index 984 * 985 * This function would store the cursor related information and pass it into 986 * dmub 987 */ 988 void dc_send_update_cursor_info_to_dmu( 989 struct pipe_ctx *pCtx, uint8_t pipe_idx) 990 { 991 union dmub_rb_cmd cmd[2]; 992 union dmub_cmd_update_cursor_info_data *update_cursor_info_0 = 993 &cmd[0].update_cursor_info.update_cursor_info_data; 994 995 memset(cmd, 0, sizeof(cmd)); 996 997 if (!dc_dmub_should_update_cursor_data(pCtx)) 998 return; 999 /* 1000 * Since we use multi_cmd_pending for dmub command, the 2nd command is 1001 * only assigned to store cursor attributes info. 1002 * 1st command can view as 2 parts, 1st is for PSR/Replay data, the other 1003 * is to store cursor position info. 1004 * 1005 * Command heaer type must be the same type if using multi_cmd_pending. 1006 * Besides, while process 2nd command in DMU, the sub type is useless. 1007 * So it's meanless to pass the sub type header with different type. 1008 */ 1009 1010 { 1011 /* Build Payload#0 Header */ 1012 cmd[0].update_cursor_info.header.type = DMUB_CMD__UPDATE_CURSOR_INFO; 1013 cmd[0].update_cursor_info.header.payload_bytes = 1014 sizeof(cmd[0].update_cursor_info.update_cursor_info_data); 1015 cmd[0].update_cursor_info.header.multi_cmd_pending = 1; //To combine multi dmu cmd, 1st cmd 1016 1017 /* Prepare Payload */ 1018 dc_build_cursor_update_payload0(pCtx, pipe_idx, &update_cursor_info_0->payload0); 1019 1020 dc_build_cursor_position_update_payload0(&update_cursor_info_0->payload0, pipe_idx, 1021 pCtx->plane_res.hubp, pCtx->plane_res.dpp); 1022 } 1023 { 1024 /* Build Payload#1 Header */ 1025 cmd[1].update_cursor_info.header.type = DMUB_CMD__UPDATE_CURSOR_INFO; 1026 cmd[1].update_cursor_info.header.payload_bytes = sizeof(struct cursor_attributes_cfg); 1027 cmd[1].update_cursor_info.header.multi_cmd_pending = 0; //Indicate it's the last command. 1028 1029 dc_build_cursor_attribute_update_payload1( 1030 &cmd[1].update_cursor_info.update_cursor_info_data.payload1.attribute_cfg, 1031 pipe_idx, pCtx->plane_res.hubp, pCtx->plane_res.dpp); 1032 1033 /* Combine 2nd cmds update_curosr_info to DMU */ 1034 dm_execute_dmub_cmd_list(pCtx->stream->ctx, 2, cmd, DM_DMUB_WAIT_TYPE_WAIT); 1035 } 1036 } 1037