1 /* 2 * Copyright 2020 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 27 #include "dm_services.h" 28 #include "dc.h" 29 30 #include "dcn301_init.h" 31 32 #include "resource.h" 33 #include "include/irq_service_interface.h" 34 #include "dcn30/dcn30_resource.h" 35 #include "dcn301_resource.h" 36 37 #include "dcn20/dcn20_resource.h" 38 39 #include "dcn10/dcn10_ipp.h" 40 #include "dcn301/dcn301_hubbub.h" 41 #include "dcn30/dcn30_mpc.h" 42 #include "dcn30/dcn30_hubp.h" 43 #include "irq/dcn30/irq_service_dcn30.h" 44 #include "dcn30/dcn30_dpp.h" 45 #include "dcn30/dcn30_optc.h" 46 #include "dcn20/dcn20_hwseq.h" 47 #include "dcn30/dcn30_hwseq.h" 48 #include "dce110/dce110_hw_sequencer.h" 49 #include "dcn30/dcn30_opp.h" 50 #include "dcn20/dcn20_dsc.h" 51 #include "dcn30/dcn30_vpg.h" 52 #include "dcn30/dcn30_afmt.h" 53 #include "dce/dce_clock_source.h" 54 #include "dce/dce_audio.h" 55 #include "dce/dce_hwseq.h" 56 #include "clk_mgr.h" 57 #include "virtual/virtual_stream_encoder.h" 58 #include "dce110/dce110_resource.h" 59 #include "dml/display_mode_vba.h" 60 #include "dcn301/dcn301_dccg.h" 61 #include "dcn10/dcn10_resource.h" 62 #include "dcn30/dcn30_dio_stream_encoder.h" 63 #include "dcn301/dcn301_dio_link_encoder.h" 64 #include "dcn301_panel_cntl.h" 65 66 #include "vangogh_ip_offset.h" 67 68 #include "dcn30/dcn30_dwb.h" 69 #include "dcn30/dcn30_mmhubbub.h" 70 71 #include "dcn/dcn_3_0_1_offset.h" 72 #include "dcn/dcn_3_0_1_sh_mask.h" 73 74 #include "nbio/nbio_7_2_0_offset.h" 75 76 #include "reg_helper.h" 77 #include "dce/dmub_abm.h" 78 #include "dce/dce_aux.h" 79 #include "dce/dce_i2c.h" 80 81 #include "dml/dcn30/display_mode_vba_30.h" 82 #include "vm_helper.h" 83 #include "dcn20/dcn20_vmid.h" 84 #include "amdgpu_socbb.h" 85 86 #define TO_DCN301_RES_POOL(pool)\ 87 container_of(pool, struct dcn301_resource_pool, base) 88 89 #define DC_LOGGER_INIT(logger) 90 91 struct _vcs_dpi_ip_params_st dcn3_01_ip = { 92 .odm_capable = 1, 93 .gpuvm_enable = 1, 94 .hostvm_enable = 1, 95 .gpuvm_max_page_table_levels = 1, 96 .hostvm_max_page_table_levels = 2, 97 .hostvm_cached_page_table_levels = 0, 98 .pte_group_size_bytes = 2048, 99 .num_dsc = 3, 100 .rob_buffer_size_kbytes = 184, 101 .det_buffer_size_kbytes = 184, 102 .dpte_buffer_size_in_pte_reqs_luma = 64, 103 .dpte_buffer_size_in_pte_reqs_chroma = 32, 104 .pde_proc_buffer_size_64k_reqs = 48, 105 .dpp_output_buffer_pixels = 2560, 106 .opp_output_buffer_lines = 1, 107 .pixel_chunk_size_kbytes = 8, 108 .meta_chunk_size_kbytes = 2, 109 .writeback_chunk_size_kbytes = 8, 110 .line_buffer_size_bits = 789504, 111 .is_line_buffer_bpp_fixed = 0, // ? 112 .line_buffer_fixed_bpp = 48, // ? 113 .dcc_supported = true, 114 .writeback_interface_buffer_size_kbytes = 90, 115 .writeback_line_buffer_buffer_size = 656640, 116 .max_line_buffer_lines = 12, 117 .writeback_luma_buffer_size_kbytes = 12, // writeback_line_buffer_buffer_size = 656640 118 .writeback_chroma_buffer_size_kbytes = 8, 119 .writeback_chroma_line_buffer_width_pixels = 4, 120 .writeback_max_hscl_ratio = 1, 121 .writeback_max_vscl_ratio = 1, 122 .writeback_min_hscl_ratio = 1, 123 .writeback_min_vscl_ratio = 1, 124 .writeback_max_hscl_taps = 1, 125 .writeback_max_vscl_taps = 1, 126 .writeback_line_buffer_luma_buffer_size = 0, 127 .writeback_line_buffer_chroma_buffer_size = 14643, 128 .cursor_buffer_size = 8, 129 .cursor_chunk_size = 2, 130 .max_num_otg = 4, 131 .max_num_dpp = 4, 132 .max_num_wb = 1, 133 .max_dchub_pscl_bw_pix_per_clk = 4, 134 .max_pscl_lb_bw_pix_per_clk = 2, 135 .max_lb_vscl_bw_pix_per_clk = 4, 136 .max_vscl_hscl_bw_pix_per_clk = 4, 137 .max_hscl_ratio = 6, 138 .max_vscl_ratio = 6, 139 .hscl_mults = 4, 140 .vscl_mults = 4, 141 .max_hscl_taps = 8, 142 .max_vscl_taps = 8, 143 .dispclk_ramp_margin_percent = 1, 144 .underscan_factor = 1.11, 145 .min_vblank_lines = 32, 146 .dppclk_delay_subtotal = 46, 147 .dynamic_metadata_vm_enabled = true, 148 .dppclk_delay_scl_lb_only = 16, 149 .dppclk_delay_scl = 50, 150 .dppclk_delay_cnvc_formatter = 27, 151 .dppclk_delay_cnvc_cursor = 6, 152 .dispclk_delay_subtotal = 119, 153 .dcfclk_cstate_latency = 5.2, // SRExitTime 154 .max_inter_dcn_tile_repeaters = 8, 155 .max_num_hdmi_frl_outputs = 0, 156 .odm_combine_4to1_supported = true, 157 158 .xfc_supported = false, 159 .xfc_fill_bw_overhead_percent = 10.0, 160 .xfc_fill_constant_bytes = 0, 161 .gfx7_compat_tiling_supported = 0, 162 .number_of_cursors = 1, 163 }; 164 165 struct _vcs_dpi_soc_bounding_box_st dcn3_01_soc = { 166 .clock_limits = { 167 { 168 .state = 0, 169 .dram_speed_mts = 2400.0, 170 .fabricclk_mhz = 600, 171 .socclk_mhz = 278.0, 172 .dcfclk_mhz = 400.0, 173 .dscclk_mhz = 206.0, 174 .dppclk_mhz = 1015.0, 175 .dispclk_mhz = 1015.0, 176 .phyclk_mhz = 600.0, 177 }, 178 { 179 .state = 1, 180 .dram_speed_mts = 2400.0, 181 .fabricclk_mhz = 688, 182 .socclk_mhz = 278.0, 183 .dcfclk_mhz = 400.0, 184 .dscclk_mhz = 206.0, 185 .dppclk_mhz = 1015.0, 186 .dispclk_mhz = 1015.0, 187 .phyclk_mhz = 600.0, 188 }, 189 { 190 .state = 2, 191 .dram_speed_mts = 4267.0, 192 .fabricclk_mhz = 1067, 193 .socclk_mhz = 278.0, 194 .dcfclk_mhz = 608.0, 195 .dscclk_mhz = 296.0, 196 .dppclk_mhz = 1015.0, 197 .dispclk_mhz = 1015.0, 198 .phyclk_mhz = 810.0, 199 }, 200 201 { 202 .state = 3, 203 .dram_speed_mts = 4267.0, 204 .fabricclk_mhz = 1067, 205 .socclk_mhz = 715.0, 206 .dcfclk_mhz = 676.0, 207 .dscclk_mhz = 338.0, 208 .dppclk_mhz = 1015.0, 209 .dispclk_mhz = 1015.0, 210 .phyclk_mhz = 810.0, 211 }, 212 213 { 214 .state = 4, 215 .dram_speed_mts = 4267.0, 216 .fabricclk_mhz = 1067, 217 .socclk_mhz = 953.0, 218 .dcfclk_mhz = 810.0, 219 .dscclk_mhz = 338.0, 220 .dppclk_mhz = 1015.0, 221 .dispclk_mhz = 1015.0, 222 .phyclk_mhz = 810.0, 223 }, 224 }, 225 226 .sr_exit_time_us = 9.0, 227 .sr_enter_plus_exit_time_us = 11.0, 228 .urgent_latency_us = 4.0, 229 .urgent_latency_pixel_data_only_us = 4.0, 230 .urgent_latency_pixel_mixed_with_vm_data_us = 4.0, 231 .urgent_latency_vm_data_only_us = 4.0, 232 .urgent_out_of_order_return_per_channel_pixel_only_bytes = 4096, 233 .urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 4096, 234 .urgent_out_of_order_return_per_channel_vm_only_bytes = 4096, 235 .pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 80.0, 236 .pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 75.0, 237 .pct_ideal_dram_sdp_bw_after_urgent_vm_only = 40.0, 238 .max_avg_sdp_bw_use_normal_percent = 60.0, 239 .max_avg_dram_bw_use_normal_percent = 60.0, 240 .writeback_latency_us = 12.0, 241 .max_request_size_bytes = 256, 242 .dram_channel_width_bytes = 4, 243 .fabric_datapath_to_dcn_data_return_bytes = 32, 244 .dcn_downspread_percent = 0.5, 245 .downspread_percent = 0.38, 246 .dram_page_open_time_ns = 50.0, 247 .dram_rw_turnaround_time_ns = 17.5, 248 .dram_return_buffer_per_channel_bytes = 8192, 249 .round_trip_ping_latency_dcfclk_cycles = 191, 250 .urgent_out_of_order_return_per_channel_bytes = 4096, 251 .channel_interleave_bytes = 256, 252 .num_banks = 8, 253 .num_chans = 4, 254 .gpuvm_min_page_size_bytes = 4096, 255 .hostvm_min_page_size_bytes = 4096, 256 .dram_clock_change_latency_us = 23.84, 257 .writeback_dram_clock_change_latency_us = 23.0, 258 .return_bus_width_bytes = 64, 259 .dispclk_dppclk_vco_speed_mhz = 3550, 260 .xfc_bus_transport_time_us = 20, // ? 261 .xfc_xbuf_latency_tolerance_us = 4, // ? 262 .use_urgent_burst_bw = 1, // ? 263 .num_states = 5, 264 .do_urgent_latency_adjustment = false, 265 .urgent_latency_adjustment_fabric_clock_component_us = 0, 266 .urgent_latency_adjustment_fabric_clock_reference_mhz = 0, 267 }; 268 269 enum dcn301_clk_src_array_id { 270 DCN301_CLK_SRC_PLL0, 271 DCN301_CLK_SRC_PLL1, 272 DCN301_CLK_SRC_PLL2, 273 DCN301_CLK_SRC_PLL3, 274 DCN301_CLK_SRC_TOTAL 275 }; 276 277 /* begin ********************* 278 * macros to expend register list macro defined in HW object header file 279 */ 280 281 /* DCN */ 282 /* TODO awful hack. fixup dcn20_dwb.h */ 283 #undef BASE_INNER 284 #define BASE_INNER(seg) DCN_BASE__INST0_SEG ## seg 285 286 #define BASE(seg) BASE_INNER(seg) 287 288 #define SR(reg_name)\ 289 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 290 mm ## reg_name 291 292 #define SRI(reg_name, block, id)\ 293 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 294 mm ## block ## id ## _ ## reg_name 295 296 #define SRI2(reg_name, block, id)\ 297 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \ 298 mm ## reg_name 299 300 #define SRIR(var_name, reg_name, block, id)\ 301 .var_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 302 mm ## block ## id ## _ ## reg_name 303 304 #define SRII(reg_name, block, id)\ 305 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 306 mm ## block ## id ## _ ## reg_name 307 308 #define SRII2(reg_name_pre, reg_name_post, id)\ 309 .reg_name_pre ## _ ## reg_name_post[id] = BASE(mm ## reg_name_pre \ 310 ## id ## _ ## reg_name_post ## _BASE_IDX) + \ 311 mm ## reg_name_pre ## id ## _ ## reg_name_post 312 313 #define SRII_MPC_RMU(reg_name, block, id)\ 314 .RMU##_##reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 315 mm ## block ## id ## _ ## reg_name 316 317 #define SRII_DWB(reg_name, temp_name, block, id)\ 318 .reg_name[id] = BASE(mm ## block ## id ## _ ## temp_name ## _BASE_IDX) + \ 319 mm ## block ## id ## _ ## temp_name 320 321 #define DCCG_SRII(reg_name, block, id)\ 322 .block ## _ ## reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \ 323 mm ## block ## id ## _ ## reg_name 324 325 #define VUPDATE_SRII(reg_name, block, id)\ 326 .reg_name[id] = BASE(mm ## reg_name ## _ ## block ## id ## _BASE_IDX) + \ 327 mm ## reg_name ## _ ## block ## id 328 329 /* NBIO */ 330 #define NBIO_BASE_INNER(seg) \ 331 NBIO_BASE__INST0_SEG ## seg 332 333 #define NBIO_BASE(seg) \ 334 NBIO_BASE_INNER(seg) 335 336 #define NBIO_SR(reg_name)\ 337 .reg_name = NBIO_BASE(regBIF_BX0_ ## reg_name ## _BASE_IDX) + \ 338 regBIF_BX0_ ## reg_name 339 340 /* MMHUB */ 341 #define MMHUB_BASE_INNER(seg) \ 342 MMHUB_BASE__INST0_SEG ## seg 343 344 #define MMHUB_BASE(seg) \ 345 MMHUB_BASE_INNER(seg) 346 347 #define MMHUB_SR(reg_name)\ 348 .reg_name = MMHUB_BASE(regMM ## reg_name ## _BASE_IDX) + \ 349 regMM ## reg_name 350 351 /* CLOCK */ 352 #define CLK_BASE_INNER(seg) \ 353 CLK_BASE__INST0_SEG ## seg 354 355 #define CLK_BASE(seg) \ 356 CLK_BASE_INNER(seg) 357 358 #define CLK_SRI(reg_name, block, inst)\ 359 .reg_name = CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \ 360 mm ## block ## _ ## inst ## _ ## reg_name 361 362 static const struct bios_registers bios_regs = { 363 NBIO_SR(BIOS_SCRATCH_3), 364 NBIO_SR(BIOS_SCRATCH_6) 365 }; 366 367 #define clk_src_regs(index, pllid)\ 368 [index] = {\ 369 CS_COMMON_REG_LIST_DCN3_01(index, pllid),\ 370 } 371 372 static const struct dce110_clk_src_regs clk_src_regs[] = { 373 clk_src_regs(0, A), 374 clk_src_regs(1, B), 375 clk_src_regs(2, C), 376 clk_src_regs(3, D) 377 }; 378 379 static const struct dce110_clk_src_shift cs_shift = { 380 CS_COMMON_MASK_SH_LIST_DCN2_0(__SHIFT) 381 }; 382 383 static const struct dce110_clk_src_mask cs_mask = { 384 CS_COMMON_MASK_SH_LIST_DCN2_0(_MASK) 385 }; 386 387 #define abm_regs(id)\ 388 [id] = {\ 389 ABM_DCN301_REG_LIST(id)\ 390 } 391 392 static const struct dce_abm_registers abm_regs[] = { 393 abm_regs(0), 394 abm_regs(1), 395 abm_regs(2), 396 abm_regs(3), 397 }; 398 399 static const struct dce_abm_shift abm_shift = { 400 ABM_MASK_SH_LIST_DCN30(__SHIFT) 401 }; 402 403 static const struct dce_abm_mask abm_mask = { 404 ABM_MASK_SH_LIST_DCN30(_MASK) 405 }; 406 407 #define audio_regs(id)\ 408 [id] = {\ 409 AUD_COMMON_REG_LIST(id)\ 410 } 411 412 static const struct dce_audio_registers audio_regs[] = { 413 audio_regs(0), 414 audio_regs(1), 415 audio_regs(2), 416 audio_regs(3), 417 audio_regs(4), 418 audio_regs(5), 419 audio_regs(6) 420 }; 421 422 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\ 423 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\ 424 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\ 425 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh) 426 427 static const struct dce_audio_shift audio_shift = { 428 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT) 429 }; 430 431 static const struct dce_audio_mask audio_mask = { 432 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK) 433 }; 434 435 #define vpg_regs(id)\ 436 [id] = {\ 437 VPG_DCN3_REG_LIST(id)\ 438 } 439 440 static const struct dcn30_vpg_registers vpg_regs[] = { 441 vpg_regs(0), 442 vpg_regs(1), 443 vpg_regs(2), 444 vpg_regs(3), 445 }; 446 447 static const struct dcn30_vpg_shift vpg_shift = { 448 DCN3_VPG_MASK_SH_LIST(__SHIFT) 449 }; 450 451 static const struct dcn30_vpg_mask vpg_mask = { 452 DCN3_VPG_MASK_SH_LIST(_MASK) 453 }; 454 455 #define afmt_regs(id)\ 456 [id] = {\ 457 AFMT_DCN3_REG_LIST(id)\ 458 } 459 460 static const struct dcn30_afmt_registers afmt_regs[] = { 461 afmt_regs(0), 462 afmt_regs(1), 463 afmt_regs(2), 464 afmt_regs(3), 465 }; 466 467 static const struct dcn30_afmt_shift afmt_shift = { 468 DCN3_AFMT_MASK_SH_LIST(__SHIFT) 469 }; 470 471 static const struct dcn30_afmt_mask afmt_mask = { 472 DCN3_AFMT_MASK_SH_LIST(_MASK) 473 }; 474 475 #define stream_enc_regs(id)\ 476 [id] = {\ 477 SE_DCN3_REG_LIST(id)\ 478 } 479 480 static const struct dcn10_stream_enc_registers stream_enc_regs[] = { 481 stream_enc_regs(0), 482 stream_enc_regs(1), 483 stream_enc_regs(2), 484 stream_enc_regs(3), 485 }; 486 487 static const struct dcn10_stream_encoder_shift se_shift = { 488 SE_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 489 }; 490 491 static const struct dcn10_stream_encoder_mask se_mask = { 492 SE_COMMON_MASK_SH_LIST_DCN30(_MASK) 493 }; 494 495 496 #define aux_regs(id)\ 497 [id] = {\ 498 DCN2_AUX_REG_LIST(id)\ 499 } 500 501 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = { 502 aux_regs(0), 503 aux_regs(1), 504 aux_regs(2), 505 aux_regs(3), 506 }; 507 508 #define hpd_regs(id)\ 509 [id] = {\ 510 HPD_REG_LIST(id)\ 511 } 512 513 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = { 514 hpd_regs(0), 515 hpd_regs(1), 516 hpd_regs(2), 517 hpd_regs(3), 518 }; 519 520 #define link_regs(id, phyid)\ 521 [id] = {\ 522 LE_DCN301_REG_LIST(id), \ 523 UNIPHY_DCN2_REG_LIST(phyid), \ 524 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \ 525 } 526 527 static const struct dce110_aux_registers_shift aux_shift = { 528 DCN_AUX_MASK_SH_LIST(__SHIFT) 529 }; 530 531 static const struct dce110_aux_registers_mask aux_mask = { 532 DCN_AUX_MASK_SH_LIST(_MASK) 533 }; 534 535 static const struct dcn10_link_enc_registers link_enc_regs[] = { 536 link_regs(0, A), 537 link_regs(1, B), 538 link_regs(2, C), 539 link_regs(3, D), 540 }; 541 542 static const struct dcn10_link_enc_shift le_shift = { 543 LINK_ENCODER_MASK_SH_LIST_DCN301(__SHIFT) 544 }; 545 546 static const struct dcn10_link_enc_mask le_mask = { 547 LINK_ENCODER_MASK_SH_LIST_DCN301(_MASK) 548 }; 549 550 #define panel_cntl_regs(id)\ 551 [id] = {\ 552 DCN301_PANEL_CNTL_REG_LIST(id),\ 553 } 554 555 static const struct dce_panel_cntl_registers panel_cntl_regs[] = { 556 panel_cntl_regs(0), 557 panel_cntl_regs(1), 558 }; 559 560 static const struct dcn301_panel_cntl_shift panel_cntl_shift = { 561 DCN301_PANEL_CNTL_MASK_SH_LIST(__SHIFT) 562 }; 563 564 static const struct dcn301_panel_cntl_mask panel_cntl_mask = { 565 DCN301_PANEL_CNTL_MASK_SH_LIST(_MASK) 566 }; 567 568 #define dpp_regs(id)\ 569 [id] = {\ 570 DPP_REG_LIST_DCN30(id),\ 571 } 572 573 static const struct dcn3_dpp_registers dpp_regs[] = { 574 dpp_regs(0), 575 dpp_regs(1), 576 dpp_regs(2), 577 dpp_regs(3), 578 }; 579 580 static const struct dcn3_dpp_shift tf_shift = { 581 DPP_REG_LIST_SH_MASK_DCN30(__SHIFT) 582 }; 583 584 static const struct dcn3_dpp_mask tf_mask = { 585 DPP_REG_LIST_SH_MASK_DCN30(_MASK) 586 }; 587 588 #define opp_regs(id)\ 589 [id] = {\ 590 OPP_REG_LIST_DCN30(id),\ 591 } 592 593 static const struct dcn20_opp_registers opp_regs[] = { 594 opp_regs(0), 595 opp_regs(1), 596 opp_regs(2), 597 opp_regs(3), 598 }; 599 600 static const struct dcn20_opp_shift opp_shift = { 601 OPP_MASK_SH_LIST_DCN20(__SHIFT) 602 }; 603 604 static const struct dcn20_opp_mask opp_mask = { 605 OPP_MASK_SH_LIST_DCN20(_MASK) 606 }; 607 608 #define aux_engine_regs(id)\ 609 [id] = {\ 610 AUX_COMMON_REG_LIST0(id), \ 611 .AUXN_IMPCAL = 0, \ 612 .AUXP_IMPCAL = 0, \ 613 .AUX_RESET_MASK = DP_AUX0_AUX_CONTROL__AUX_RESET_MASK, \ 614 } 615 616 static const struct dce110_aux_registers aux_engine_regs[] = { 617 aux_engine_regs(0), 618 aux_engine_regs(1), 619 aux_engine_regs(2), 620 aux_engine_regs(3), 621 }; 622 623 #define dwbc_regs_dcn3(id)\ 624 [id] = {\ 625 DWBC_COMMON_REG_LIST_DCN30(id),\ 626 } 627 628 static const struct dcn30_dwbc_registers dwbc30_regs[] = { 629 dwbc_regs_dcn3(0), 630 }; 631 632 static const struct dcn30_dwbc_shift dwbc30_shift = { 633 DWBC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 634 }; 635 636 static const struct dcn30_dwbc_mask dwbc30_mask = { 637 DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK) 638 }; 639 640 #define mcif_wb_regs_dcn3(id)\ 641 [id] = {\ 642 MCIF_WB_COMMON_REG_LIST_DCN30(id),\ 643 } 644 645 static const struct dcn30_mmhubbub_registers mcif_wb30_regs[] = { 646 mcif_wb_regs_dcn3(0) 647 }; 648 649 static const struct dcn30_mmhubbub_shift mcif_wb30_shift = { 650 MCIF_WB_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 651 }; 652 653 static const struct dcn30_mmhubbub_mask mcif_wb30_mask = { 654 MCIF_WB_COMMON_MASK_SH_LIST_DCN30(_MASK) 655 }; 656 657 #define dsc_regsDCN20(id)\ 658 [id] = {\ 659 DSC_REG_LIST_DCN20(id)\ 660 } 661 662 static const struct dcn20_dsc_registers dsc_regs[] = { 663 dsc_regsDCN20(0), 664 dsc_regsDCN20(1), 665 dsc_regsDCN20(2), 666 }; 667 668 static const struct dcn20_dsc_shift dsc_shift = { 669 DSC_REG_LIST_SH_MASK_DCN20(__SHIFT) 670 }; 671 672 static const struct dcn20_dsc_mask dsc_mask = { 673 DSC_REG_LIST_SH_MASK_DCN20(_MASK) 674 }; 675 676 static const struct dcn30_mpc_registers mpc_regs = { 677 MPC_REG_LIST_DCN3_0(0), 678 MPC_REG_LIST_DCN3_0(1), 679 MPC_REG_LIST_DCN3_0(2), 680 MPC_REG_LIST_DCN3_0(3), 681 MPC_OUT_MUX_REG_LIST_DCN3_0(0), 682 MPC_OUT_MUX_REG_LIST_DCN3_0(1), 683 MPC_OUT_MUX_REG_LIST_DCN3_0(2), 684 MPC_OUT_MUX_REG_LIST_DCN3_0(3), 685 MPC_RMU_GLOBAL_REG_LIST_DCN3AG, 686 MPC_RMU_REG_LIST_DCN3AG(0), 687 MPC_RMU_REG_LIST_DCN3AG(1), 688 MPC_DWB_MUX_REG_LIST_DCN3_0(0), 689 }; 690 691 static const struct dcn30_mpc_shift mpc_shift = { 692 MPC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 693 }; 694 695 static const struct dcn30_mpc_mask mpc_mask = { 696 MPC_COMMON_MASK_SH_LIST_DCN30(_MASK) 697 }; 698 699 #define optc_regs(id)\ 700 [id] = {OPTC_COMMON_REG_LIST_DCN3_0(id)} 701 702 703 static const struct dcn_optc_registers optc_regs[] = { 704 optc_regs(0), 705 optc_regs(1), 706 optc_regs(2), 707 optc_regs(3), 708 }; 709 710 static const struct dcn_optc_shift optc_shift = { 711 OPTC_COMMON_MASK_SH_LIST_DCN30(__SHIFT) 712 }; 713 714 static const struct dcn_optc_mask optc_mask = { 715 OPTC_COMMON_MASK_SH_LIST_DCN30(_MASK) 716 }; 717 718 #define hubp_regs(id)\ 719 [id] = {\ 720 HUBP_REG_LIST_DCN30(id)\ 721 } 722 723 static const struct dcn_hubp2_registers hubp_regs[] = { 724 hubp_regs(0), 725 hubp_regs(1), 726 hubp_regs(2), 727 hubp_regs(3), 728 }; 729 730 static const struct dcn_hubp2_shift hubp_shift = { 731 HUBP_MASK_SH_LIST_DCN30(__SHIFT) 732 }; 733 734 static const struct dcn_hubp2_mask hubp_mask = { 735 HUBP_MASK_SH_LIST_DCN30(_MASK) 736 }; 737 738 static const struct dcn_hubbub_registers hubbub_reg = { 739 HUBBUB_REG_LIST_DCN301(0) 740 }; 741 742 static const struct dcn_hubbub_shift hubbub_shift = { 743 HUBBUB_MASK_SH_LIST_DCN301(__SHIFT) 744 }; 745 746 static const struct dcn_hubbub_mask hubbub_mask = { 747 HUBBUB_MASK_SH_LIST_DCN301(_MASK) 748 }; 749 750 static const struct dccg_registers dccg_regs = { 751 DCCG_REG_LIST_DCN301() 752 }; 753 754 static const struct dccg_shift dccg_shift = { 755 DCCG_MASK_SH_LIST_DCN301(__SHIFT) 756 }; 757 758 static const struct dccg_mask dccg_mask = { 759 DCCG_MASK_SH_LIST_DCN301(_MASK) 760 }; 761 762 static const struct dce_hwseq_registers hwseq_reg = { 763 HWSEQ_DCN301_REG_LIST() 764 }; 765 766 static const struct dce_hwseq_shift hwseq_shift = { 767 HWSEQ_DCN301_MASK_SH_LIST(__SHIFT) 768 }; 769 770 static const struct dce_hwseq_mask hwseq_mask = { 771 HWSEQ_DCN301_MASK_SH_LIST(_MASK) 772 }; 773 #define vmid_regs(id)\ 774 [id] = {\ 775 DCN20_VMID_REG_LIST(id)\ 776 } 777 778 static const struct dcn_vmid_registers vmid_regs[] = { 779 vmid_regs(0), 780 vmid_regs(1), 781 vmid_regs(2), 782 vmid_regs(3), 783 vmid_regs(4), 784 vmid_regs(5), 785 vmid_regs(6), 786 vmid_regs(7), 787 vmid_regs(8), 788 vmid_regs(9), 789 vmid_regs(10), 790 vmid_regs(11), 791 vmid_regs(12), 792 vmid_regs(13), 793 vmid_regs(14), 794 vmid_regs(15) 795 }; 796 797 static const struct dcn20_vmid_shift vmid_shifts = { 798 DCN20_VMID_MASK_SH_LIST(__SHIFT) 799 }; 800 801 static const struct dcn20_vmid_mask vmid_masks = { 802 DCN20_VMID_MASK_SH_LIST(_MASK) 803 }; 804 805 static const struct resource_caps res_cap_dcn301 = { 806 .num_timing_generator = 4, 807 .num_opp = 4, 808 .num_video_plane = 4, 809 .num_audio = 4, 810 .num_stream_encoder = 4, 811 .num_pll = 4, 812 .num_dwb = 1, 813 .num_ddc = 4, 814 .num_vmid = 16, 815 .num_mpc_3dlut = 2, 816 .num_dsc = 3, 817 }; 818 819 static const struct dc_plane_cap plane_cap = { 820 .type = DC_PLANE_TYPE_DCN_UNIVERSAL, 821 .blends_with_above = true, 822 .blends_with_below = true, 823 .per_pixel_alpha = true, 824 825 .pixel_format_support = { 826 .argb8888 = true, 827 .nv12 = true, 828 .fp16 = true, 829 .p010 = false, 830 .ayuv = false, 831 }, 832 833 .max_upscale_factor = { 834 .argb8888 = 16000, 835 .nv12 = 16000, 836 .fp16 = 16000 837 }, 838 839 .max_downscale_factor = { 840 .argb8888 = 600, 841 .nv12 = 600, 842 .fp16 = 600 843 }, 844 64, 845 64 846 }; 847 848 static const struct dc_debug_options debug_defaults_drv = { 849 .disable_dmcu = true, 850 .force_abm_enable = false, 851 .timing_trace = false, 852 .clock_trace = true, 853 .disable_dpp_power_gate = true, 854 .disable_hubp_power_gate = true, 855 .disable_clock_gate = true, 856 .disable_pplib_clock_request = true, 857 .disable_pplib_wm_range = true, 858 .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP, 859 .force_single_disp_pipe_split = false, 860 .disable_dcc = DCC_ENABLE, 861 .vsr_support = true, 862 .performance_trace = false, 863 .max_downscale_src_width = 7680,/*upto 8K*/ 864 .scl_reset_length10 = true, 865 .sanity_checks = false, 866 .underflow_assert_delay_us = 0xFFFFFFFF, 867 .dwb_fi_phase = -1, // -1 = disable 868 .dmub_command_table = true, 869 }; 870 871 static const struct dc_debug_options debug_defaults_diags = { 872 .disable_dmcu = true, 873 .force_abm_enable = false, 874 .timing_trace = true, 875 .clock_trace = true, 876 .disable_dpp_power_gate = true, 877 .disable_hubp_power_gate = true, 878 .disable_clock_gate = true, 879 .disable_pplib_clock_request = true, 880 .disable_pplib_wm_range = true, 881 .disable_stutter = true, 882 .scl_reset_length10 = true, 883 .dwb_fi_phase = -1, // -1 = disable 884 .dmub_command_table = true, 885 }; 886 887 void dcn301_dpp_destroy(struct dpp **dpp) 888 { 889 kfree(TO_DCN20_DPP(*dpp)); 890 *dpp = NULL; 891 } 892 893 struct dpp *dcn301_dpp_create( 894 struct dc_context *ctx, 895 uint32_t inst) 896 { 897 struct dcn3_dpp *dpp = 898 kzalloc(sizeof(struct dcn3_dpp), GFP_KERNEL); 899 900 if (!dpp) 901 return NULL; 902 903 if (dpp3_construct(dpp, ctx, inst, 904 &dpp_regs[inst], &tf_shift, &tf_mask)) 905 return &dpp->base; 906 907 BREAK_TO_DEBUGGER(); 908 kfree(dpp); 909 return NULL; 910 } 911 struct output_pixel_processor *dcn301_opp_create( 912 struct dc_context *ctx, uint32_t inst) 913 { 914 struct dcn20_opp *opp = 915 kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL); 916 917 if (!opp) { 918 BREAK_TO_DEBUGGER(); 919 return NULL; 920 } 921 922 dcn20_opp_construct(opp, ctx, inst, 923 &opp_regs[inst], &opp_shift, &opp_mask); 924 return &opp->base; 925 } 926 927 struct dce_aux *dcn301_aux_engine_create( 928 struct dc_context *ctx, 929 uint32_t inst) 930 { 931 struct aux_engine_dce110 *aux_engine = 932 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL); 933 934 if (!aux_engine) 935 return NULL; 936 937 dce110_aux_engine_construct(aux_engine, ctx, inst, 938 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD, 939 &aux_engine_regs[inst], 940 &aux_mask, 941 &aux_shift, 942 ctx->dc->caps.extended_aux_timeout_support); 943 944 return &aux_engine->base; 945 } 946 #define i2c_inst_regs(id) { I2C_HW_ENGINE_COMMON_REG_LIST(id) } 947 948 static const struct dce_i2c_registers i2c_hw_regs[] = { 949 i2c_inst_regs(1), 950 i2c_inst_regs(2), 951 i2c_inst_regs(3), 952 i2c_inst_regs(4), 953 }; 954 955 static const struct dce_i2c_shift i2c_shifts = { 956 I2C_COMMON_MASK_SH_LIST_DCN2(__SHIFT) 957 }; 958 959 static const struct dce_i2c_mask i2c_masks = { 960 I2C_COMMON_MASK_SH_LIST_DCN2(_MASK) 961 }; 962 963 struct dce_i2c_hw *dcn301_i2c_hw_create( 964 struct dc_context *ctx, 965 uint32_t inst) 966 { 967 struct dce_i2c_hw *dce_i2c_hw = 968 kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL); 969 970 if (!dce_i2c_hw) 971 return NULL; 972 973 dcn2_i2c_hw_construct(dce_i2c_hw, ctx, inst, 974 &i2c_hw_regs[inst], &i2c_shifts, &i2c_masks); 975 976 return dce_i2c_hw; 977 } 978 static struct mpc *dcn301_mpc_create( 979 struct dc_context *ctx, 980 int num_mpcc, 981 int num_rmu) 982 { 983 struct dcn30_mpc *mpc30 = kzalloc(sizeof(struct dcn30_mpc), 984 GFP_KERNEL); 985 986 if (!mpc30) 987 return NULL; 988 989 dcn30_mpc_construct(mpc30, ctx, 990 &mpc_regs, 991 &mpc_shift, 992 &mpc_mask, 993 num_mpcc, 994 num_rmu); 995 996 return &mpc30->base; 997 } 998 999 struct hubbub *dcn301_hubbub_create(struct dc_context *ctx) 1000 { 1001 int i; 1002 1003 struct dcn20_hubbub *hubbub3 = kzalloc(sizeof(struct dcn20_hubbub), 1004 GFP_KERNEL); 1005 1006 if (!hubbub3) 1007 return NULL; 1008 1009 hubbub301_construct(hubbub3, ctx, 1010 &hubbub_reg, 1011 &hubbub_shift, 1012 &hubbub_mask); 1013 1014 1015 for (i = 0; i < res_cap_dcn301.num_vmid; i++) { 1016 struct dcn20_vmid *vmid = &hubbub3->vmid[i]; 1017 1018 vmid->ctx = ctx; 1019 1020 vmid->regs = &vmid_regs[i]; 1021 vmid->shifts = &vmid_shifts; 1022 vmid->masks = &vmid_masks; 1023 } 1024 1025 hubbub3->num_vmid = res_cap_dcn301.num_vmid; 1026 1027 return &hubbub3->base; 1028 } 1029 1030 struct timing_generator *dcn301_timing_generator_create( 1031 struct dc_context *ctx, 1032 uint32_t instance) 1033 { 1034 struct optc *tgn10 = 1035 kzalloc(sizeof(struct optc), GFP_KERNEL); 1036 1037 if (!tgn10) 1038 return NULL; 1039 1040 tgn10->base.inst = instance; 1041 tgn10->base.ctx = ctx; 1042 1043 tgn10->tg_regs = &optc_regs[instance]; 1044 tgn10->tg_shift = &optc_shift; 1045 tgn10->tg_mask = &optc_mask; 1046 1047 dcn30_timing_generator_init(tgn10); 1048 1049 return &tgn10->base; 1050 } 1051 1052 static const struct encoder_feature_support link_enc_feature = { 1053 .max_hdmi_deep_color = COLOR_DEPTH_121212, 1054 .max_hdmi_pixel_clock = 600000, 1055 .hdmi_ycbcr420_supported = true, 1056 .dp_ycbcr420_supported = true, 1057 .fec_supported = true, 1058 .flags.bits.IS_HBR2_CAPABLE = true, 1059 .flags.bits.IS_HBR3_CAPABLE = true, 1060 .flags.bits.IS_TPS3_CAPABLE = true, 1061 .flags.bits.IS_TPS4_CAPABLE = true 1062 }; 1063 1064 struct link_encoder *dcn301_link_encoder_create( 1065 const struct encoder_init_data *enc_init_data) 1066 { 1067 struct dcn20_link_encoder *enc20 = 1068 kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL); 1069 1070 if (!enc20) 1071 return NULL; 1072 1073 dcn301_link_encoder_construct(enc20, 1074 enc_init_data, 1075 &link_enc_feature, 1076 &link_enc_regs[enc_init_data->transmitter], 1077 &link_enc_aux_regs[enc_init_data->channel - 1], 1078 &link_enc_hpd_regs[enc_init_data->hpd_source], 1079 &le_shift, 1080 &le_mask); 1081 1082 return &enc20->enc10.base; 1083 } 1084 1085 struct panel_cntl *dcn301_panel_cntl_create(const struct panel_cntl_init_data *init_data) 1086 { 1087 struct dcn301_panel_cntl *panel_cntl = 1088 kzalloc(sizeof(struct dcn301_panel_cntl), GFP_KERNEL); 1089 1090 if (!panel_cntl) 1091 return NULL; 1092 1093 dcn301_panel_cntl_construct(panel_cntl, 1094 init_data, 1095 &panel_cntl_regs[init_data->inst], 1096 &panel_cntl_shift, 1097 &panel_cntl_mask); 1098 1099 return &panel_cntl->base; 1100 } 1101 1102 1103 #define CTX ctx 1104 1105 #define REG(reg_name) \ 1106 (DCN_BASE.instance[0].segment[mm ## reg_name ## _BASE_IDX] + mm ## reg_name) 1107 1108 static uint32_t read_pipe_fuses(struct dc_context *ctx) 1109 { 1110 uint32_t value = REG_READ(CC_DC_PIPE_DIS); 1111 /* RV1 support max 4 pipes */ 1112 value = value & 0xf; 1113 return value; 1114 } 1115 1116 1117 static void read_dce_straps( 1118 struct dc_context *ctx, 1119 struct resource_straps *straps) 1120 { 1121 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX), 1122 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio); 1123 1124 } 1125 1126 static struct audio *dcn301_create_audio( 1127 struct dc_context *ctx, unsigned int inst) 1128 { 1129 return dce_audio_create(ctx, inst, 1130 &audio_regs[inst], &audio_shift, &audio_mask); 1131 } 1132 1133 static struct vpg *dcn301_vpg_create( 1134 struct dc_context *ctx, 1135 uint32_t inst) 1136 { 1137 struct dcn30_vpg *vpg3 = kzalloc(sizeof(struct dcn30_vpg), GFP_KERNEL); 1138 1139 if (!vpg3) 1140 return NULL; 1141 1142 vpg3_construct(vpg3, ctx, inst, 1143 &vpg_regs[inst], 1144 &vpg_shift, 1145 &vpg_mask); 1146 1147 return &vpg3->base; 1148 } 1149 1150 static struct afmt *dcn301_afmt_create( 1151 struct dc_context *ctx, 1152 uint32_t inst) 1153 { 1154 struct dcn30_afmt *afmt3 = kzalloc(sizeof(struct dcn30_afmt), GFP_KERNEL); 1155 1156 if (!afmt3) 1157 return NULL; 1158 1159 afmt3_construct(afmt3, ctx, inst, 1160 &afmt_regs[inst], 1161 &afmt_shift, 1162 &afmt_mask); 1163 1164 return &afmt3->base; 1165 } 1166 1167 struct stream_encoder *dcn301_stream_encoder_create( 1168 enum engine_id eng_id, 1169 struct dc_context *ctx) 1170 { 1171 struct dcn10_stream_encoder *enc1; 1172 struct vpg *vpg; 1173 struct afmt *afmt; 1174 int vpg_inst; 1175 int afmt_inst; 1176 1177 /* Mapping of VPG, AFMT, DME register blocks to DIO block instance */ 1178 if (eng_id <= ENGINE_ID_DIGF) { 1179 vpg_inst = eng_id; 1180 afmt_inst = eng_id; 1181 } else 1182 return NULL; 1183 1184 enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL); 1185 vpg = dcn301_vpg_create(ctx, vpg_inst); 1186 afmt = dcn301_afmt_create(ctx, afmt_inst); 1187 1188 if (!enc1 || !vpg || !afmt) 1189 return NULL; 1190 1191 dcn30_dio_stream_encoder_construct(enc1, ctx, ctx->dc_bios, 1192 eng_id, vpg, afmt, 1193 &stream_enc_regs[eng_id], 1194 &se_shift, &se_mask); 1195 1196 return &enc1->base; 1197 } 1198 1199 struct dce_hwseq *dcn301_hwseq_create( 1200 struct dc_context *ctx) 1201 { 1202 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL); 1203 1204 if (hws) { 1205 hws->ctx = ctx; 1206 hws->regs = &hwseq_reg; 1207 hws->shifts = &hwseq_shift; 1208 hws->masks = &hwseq_mask; 1209 } 1210 return hws; 1211 } 1212 static const struct resource_create_funcs res_create_funcs = { 1213 .read_dce_straps = read_dce_straps, 1214 .create_audio = dcn301_create_audio, 1215 .create_stream_encoder = dcn301_stream_encoder_create, 1216 .create_hwseq = dcn301_hwseq_create, 1217 }; 1218 1219 static const struct resource_create_funcs res_create_maximus_funcs = { 1220 .read_dce_straps = NULL, 1221 .create_audio = NULL, 1222 .create_stream_encoder = NULL, 1223 .create_hwseq = dcn301_hwseq_create, 1224 }; 1225 1226 static void dcn301_pp_smu_destroy(struct pp_smu_funcs **pp_smu); 1227 1228 static void dcn301_destruct(struct dcn301_resource_pool *pool) 1229 { 1230 unsigned int i; 1231 1232 for (i = 0; i < pool->base.stream_enc_count; i++) { 1233 if (pool->base.stream_enc[i] != NULL) { 1234 if (pool->base.stream_enc[i]->vpg != NULL) { 1235 kfree(DCN30_VPG_FROM_VPG(pool->base.stream_enc[i]->vpg)); 1236 pool->base.stream_enc[i]->vpg = NULL; 1237 } 1238 if (pool->base.stream_enc[i]->afmt != NULL) { 1239 kfree(DCN30_AFMT_FROM_AFMT(pool->base.stream_enc[i]->afmt)); 1240 pool->base.stream_enc[i]->afmt = NULL; 1241 } 1242 kfree(DCN10STRENC_FROM_STRENC(pool->base.stream_enc[i])); 1243 pool->base.stream_enc[i] = NULL; 1244 } 1245 } 1246 1247 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 1248 if (pool->base.dscs[i] != NULL) 1249 dcn20_dsc_destroy(&pool->base.dscs[i]); 1250 } 1251 1252 if (pool->base.mpc != NULL) { 1253 kfree(TO_DCN20_MPC(pool->base.mpc)); 1254 pool->base.mpc = NULL; 1255 } 1256 if (pool->base.hubbub != NULL) { 1257 kfree(pool->base.hubbub); 1258 pool->base.hubbub = NULL; 1259 } 1260 for (i = 0; i < pool->base.pipe_count; i++) { 1261 if (pool->base.dpps[i] != NULL) 1262 dcn301_dpp_destroy(&pool->base.dpps[i]); 1263 1264 if (pool->base.ipps[i] != NULL) 1265 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]); 1266 1267 if (pool->base.hubps[i] != NULL) { 1268 kfree(TO_DCN20_HUBP(pool->base.hubps[i])); 1269 pool->base.hubps[i] = NULL; 1270 } 1271 1272 if (pool->base.irqs != NULL) { 1273 dal_irq_service_destroy(&pool->base.irqs); 1274 } 1275 } 1276 1277 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 1278 if (pool->base.engines[i] != NULL) 1279 dce110_engine_destroy(&pool->base.engines[i]); 1280 if (pool->base.hw_i2cs[i] != NULL) { 1281 kfree(pool->base.hw_i2cs[i]); 1282 pool->base.hw_i2cs[i] = NULL; 1283 } 1284 if (pool->base.sw_i2cs[i] != NULL) { 1285 kfree(pool->base.sw_i2cs[i]); 1286 pool->base.sw_i2cs[i] = NULL; 1287 } 1288 } 1289 1290 for (i = 0; i < pool->base.res_cap->num_opp; i++) { 1291 if (pool->base.opps[i] != NULL) 1292 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]); 1293 } 1294 1295 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1296 if (pool->base.timing_generators[i] != NULL) { 1297 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i])); 1298 pool->base.timing_generators[i] = NULL; 1299 } 1300 } 1301 1302 for (i = 0; i < pool->base.res_cap->num_dwb; i++) { 1303 if (pool->base.dwbc[i] != NULL) { 1304 kfree(TO_DCN30_DWBC(pool->base.dwbc[i])); 1305 pool->base.dwbc[i] = NULL; 1306 } 1307 if (pool->base.mcif_wb[i] != NULL) { 1308 kfree(TO_DCN30_MMHUBBUB(pool->base.mcif_wb[i])); 1309 pool->base.mcif_wb[i] = NULL; 1310 } 1311 } 1312 1313 for (i = 0; i < pool->base.audio_count; i++) { 1314 if (pool->base.audios[i]) 1315 dce_aud_destroy(&pool->base.audios[i]); 1316 } 1317 1318 for (i = 0; i < pool->base.clk_src_count; i++) { 1319 if (pool->base.clock_sources[i] != NULL) { 1320 dcn20_clock_source_destroy(&pool->base.clock_sources[i]); 1321 pool->base.clock_sources[i] = NULL; 1322 } 1323 } 1324 1325 for (i = 0; i < pool->base.res_cap->num_mpc_3dlut; i++) { 1326 if (pool->base.mpc_lut[i] != NULL) { 1327 dc_3dlut_func_release(pool->base.mpc_lut[i]); 1328 pool->base.mpc_lut[i] = NULL; 1329 } 1330 if (pool->base.mpc_shaper[i] != NULL) { 1331 dc_transfer_func_release(pool->base.mpc_shaper[i]); 1332 pool->base.mpc_shaper[i] = NULL; 1333 } 1334 } 1335 1336 if (pool->base.dp_clock_source != NULL) { 1337 dcn20_clock_source_destroy(&pool->base.dp_clock_source); 1338 pool->base.dp_clock_source = NULL; 1339 } 1340 1341 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1342 if (pool->base.multiple_abms[i] != NULL) 1343 dce_abm_destroy(&pool->base.multiple_abms[i]); 1344 } 1345 1346 if (pool->base.dccg != NULL) 1347 dcn_dccg_destroy(&pool->base.dccg); 1348 1349 if (pool->base.pp_smu != NULL) 1350 dcn301_pp_smu_destroy(&pool->base.pp_smu); 1351 } 1352 1353 struct hubp *dcn301_hubp_create( 1354 struct dc_context *ctx, 1355 uint32_t inst) 1356 { 1357 struct dcn20_hubp *hubp2 = 1358 kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL); 1359 1360 if (!hubp2) 1361 return NULL; 1362 1363 if (hubp3_construct(hubp2, ctx, inst, 1364 &hubp_regs[inst], &hubp_shift, &hubp_mask)) 1365 return &hubp2->base; 1366 1367 BREAK_TO_DEBUGGER(); 1368 kfree(hubp2); 1369 return NULL; 1370 } 1371 1372 bool dcn301_dwbc_create(struct dc_context *ctx, struct resource_pool *pool) 1373 { 1374 int i; 1375 uint32_t pipe_count = pool->res_cap->num_dwb; 1376 1377 for (i = 0; i < pipe_count; i++) { 1378 struct dcn30_dwbc *dwbc30 = kzalloc(sizeof(struct dcn30_dwbc), 1379 GFP_KERNEL); 1380 1381 if (!dwbc30) { 1382 dm_error("DC: failed to create dwbc30!\n"); 1383 return false; 1384 } 1385 1386 dcn30_dwbc_construct(dwbc30, ctx, 1387 &dwbc30_regs[i], 1388 &dwbc30_shift, 1389 &dwbc30_mask, 1390 i); 1391 1392 pool->dwbc[i] = &dwbc30->base; 1393 } 1394 return true; 1395 } 1396 1397 bool dcn301_mmhubbub_create(struct dc_context *ctx, struct resource_pool *pool) 1398 { 1399 int i; 1400 uint32_t pipe_count = pool->res_cap->num_dwb; 1401 1402 for (i = 0; i < pipe_count; i++) { 1403 struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub), 1404 GFP_KERNEL); 1405 1406 if (!mcif_wb30) { 1407 dm_error("DC: failed to create mcif_wb30!\n"); 1408 return false; 1409 } 1410 1411 dcn30_mmhubbub_construct(mcif_wb30, ctx, 1412 &mcif_wb30_regs[i], 1413 &mcif_wb30_shift, 1414 &mcif_wb30_mask, 1415 i); 1416 1417 pool->mcif_wb[i] = &mcif_wb30->base; 1418 } 1419 return true; 1420 } 1421 1422 static struct display_stream_compressor *dcn301_dsc_create( 1423 struct dc_context *ctx, uint32_t inst) 1424 { 1425 struct dcn20_dsc *dsc = 1426 kzalloc(sizeof(struct dcn20_dsc), GFP_KERNEL); 1427 1428 if (!dsc) { 1429 BREAK_TO_DEBUGGER(); 1430 return NULL; 1431 } 1432 1433 dsc2_construct(dsc, ctx, inst, &dsc_regs[inst], &dsc_shift, &dsc_mask); 1434 return &dsc->base; 1435 } 1436 1437 1438 static void dcn301_destroy_resource_pool(struct resource_pool **pool) 1439 { 1440 struct dcn301_resource_pool *dcn301_pool = TO_DCN301_RES_POOL(*pool); 1441 1442 dcn301_destruct(dcn301_pool); 1443 kfree(dcn301_pool); 1444 *pool = NULL; 1445 } 1446 1447 static struct clock_source *dcn301_clock_source_create( 1448 struct dc_context *ctx, 1449 struct dc_bios *bios, 1450 enum clock_source_id id, 1451 const struct dce110_clk_src_regs *regs, 1452 bool dp_clk_src) 1453 { 1454 struct dce110_clk_src *clk_src = 1455 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL); 1456 1457 if (!clk_src) 1458 return NULL; 1459 1460 if (dcn301_clk_src_construct(clk_src, ctx, bios, id, 1461 regs, &cs_shift, &cs_mask)) { 1462 clk_src->base.dp_clk_src = dp_clk_src; 1463 return &clk_src->base; 1464 } 1465 1466 BREAK_TO_DEBUGGER(); 1467 return NULL; 1468 } 1469 1470 static struct dc_cap_funcs cap_funcs = { 1471 .get_dcc_compression_cap = dcn20_get_dcc_compression_cap 1472 }; 1473 1474 #define fixed16_to_double(x) (((double) x) / ((double) (1 << 16))) 1475 #define fixed16_to_double_to_cpu(x) fixed16_to_double(le32_to_cpu(x)) 1476 1477 static bool is_soc_bounding_box_valid(struct dc *dc) 1478 { 1479 uint32_t hw_internal_rev = dc->ctx->asic_id.hw_internal_rev; 1480 1481 if (ASICREV_IS_VANGOGH(hw_internal_rev)) 1482 return true; 1483 1484 return false; 1485 } 1486 1487 static bool init_soc_bounding_box(struct dc *dc, 1488 struct dcn301_resource_pool *pool) 1489 { 1490 const struct gpu_info_soc_bounding_box_v1_0 *bb = dc->soc_bounding_box; 1491 struct _vcs_dpi_soc_bounding_box_st *loaded_bb = &dcn3_01_soc; 1492 struct _vcs_dpi_ip_params_st *loaded_ip = &dcn3_01_ip; 1493 1494 DC_LOGGER_INIT(dc->ctx->logger); 1495 1496 if (!bb && !is_soc_bounding_box_valid(dc)) { 1497 DC_LOG_ERROR("%s: not valid soc bounding box/n", __func__); 1498 return false; 1499 } 1500 1501 if (bb && !is_soc_bounding_box_valid(dc)) { 1502 int i; 1503 1504 dcn3_01_soc.sr_exit_time_us = 1505 fixed16_to_double_to_cpu(bb->sr_exit_time_us); 1506 dcn3_01_soc.sr_enter_plus_exit_time_us = 1507 fixed16_to_double_to_cpu(bb->sr_enter_plus_exit_time_us); 1508 dcn3_01_soc.urgent_latency_us = 1509 fixed16_to_double_to_cpu(bb->urgent_latency_us); 1510 dcn3_01_soc.urgent_latency_pixel_data_only_us = 1511 fixed16_to_double_to_cpu(bb->urgent_latency_pixel_data_only_us); 1512 dcn3_01_soc.urgent_latency_pixel_mixed_with_vm_data_us = 1513 fixed16_to_double_to_cpu(bb->urgent_latency_pixel_mixed_with_vm_data_us); 1514 dcn3_01_soc.urgent_latency_vm_data_only_us = 1515 fixed16_to_double_to_cpu(bb->urgent_latency_vm_data_only_us); 1516 dcn3_01_soc.urgent_out_of_order_return_per_channel_pixel_only_bytes = 1517 le32_to_cpu(bb->urgent_out_of_order_return_per_channel_pixel_only_bytes); 1518 dcn3_01_soc.urgent_out_of_order_return_per_channel_pixel_and_vm_bytes = 1519 le32_to_cpu(bb->urgent_out_of_order_return_per_channel_pixel_and_vm_bytes); 1520 dcn3_01_soc.urgent_out_of_order_return_per_channel_vm_only_bytes = 1521 le32_to_cpu(bb->urgent_out_of_order_return_per_channel_vm_only_bytes); 1522 dcn3_01_soc.pct_ideal_dram_sdp_bw_after_urgent_pixel_only = 1523 fixed16_to_double_to_cpu(bb->pct_ideal_dram_sdp_bw_after_urgent_pixel_only); 1524 dcn3_01_soc.pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm = 1525 fixed16_to_double_to_cpu(bb->pct_ideal_dram_sdp_bw_after_urgent_pixel_and_vm); 1526 dcn3_01_soc.pct_ideal_dram_sdp_bw_after_urgent_vm_only = 1527 fixed16_to_double_to_cpu(bb->pct_ideal_dram_sdp_bw_after_urgent_vm_only); 1528 dcn3_01_soc.max_avg_sdp_bw_use_normal_percent = 1529 fixed16_to_double_to_cpu(bb->max_avg_sdp_bw_use_normal_percent); 1530 dcn3_01_soc.max_avg_dram_bw_use_normal_percent = 1531 fixed16_to_double_to_cpu(bb->max_avg_dram_bw_use_normal_percent); 1532 dcn3_01_soc.writeback_latency_us = 1533 fixed16_to_double_to_cpu(bb->writeback_latency_us); 1534 dcn3_01_soc.ideal_dram_bw_after_urgent_percent = 1535 fixed16_to_double_to_cpu(bb->ideal_dram_bw_after_urgent_percent); 1536 dcn3_01_soc.max_request_size_bytes = 1537 le32_to_cpu(bb->max_request_size_bytes); 1538 dcn3_01_soc.dram_channel_width_bytes = 1539 le32_to_cpu(bb->dram_channel_width_bytes); 1540 dcn3_01_soc.fabric_datapath_to_dcn_data_return_bytes = 1541 le32_to_cpu(bb->fabric_datapath_to_dcn_data_return_bytes); 1542 dcn3_01_soc.dcn_downspread_percent = 1543 fixed16_to_double_to_cpu(bb->dcn_downspread_percent); 1544 dcn3_01_soc.downspread_percent = 1545 fixed16_to_double_to_cpu(bb->downspread_percent); 1546 dcn3_01_soc.dram_page_open_time_ns = 1547 fixed16_to_double_to_cpu(bb->dram_page_open_time_ns); 1548 dcn3_01_soc.dram_rw_turnaround_time_ns = 1549 fixed16_to_double_to_cpu(bb->dram_rw_turnaround_time_ns); 1550 dcn3_01_soc.dram_return_buffer_per_channel_bytes = 1551 le32_to_cpu(bb->dram_return_buffer_per_channel_bytes); 1552 dcn3_01_soc.round_trip_ping_latency_dcfclk_cycles = 1553 le32_to_cpu(bb->round_trip_ping_latency_dcfclk_cycles); 1554 dcn3_01_soc.urgent_out_of_order_return_per_channel_bytes = 1555 le32_to_cpu(bb->urgent_out_of_order_return_per_channel_bytes); 1556 dcn3_01_soc.channel_interleave_bytes = 1557 le32_to_cpu(bb->channel_interleave_bytes); 1558 dcn3_01_soc.num_banks = 1559 le32_to_cpu(bb->num_banks); 1560 dcn3_01_soc.num_chans = 1561 le32_to_cpu(bb->num_chans); 1562 dcn3_01_soc.gpuvm_min_page_size_bytes = 1563 le32_to_cpu(bb->vmm_page_size_bytes); 1564 dcn3_01_soc.dram_clock_change_latency_us = 1565 fixed16_to_double_to_cpu(bb->dram_clock_change_latency_us); 1566 dcn3_01_soc.writeback_dram_clock_change_latency_us = 1567 fixed16_to_double_to_cpu(bb->writeback_dram_clock_change_latency_us); 1568 dcn3_01_soc.return_bus_width_bytes = 1569 le32_to_cpu(bb->return_bus_width_bytes); 1570 dcn3_01_soc.dispclk_dppclk_vco_speed_mhz = 1571 le32_to_cpu(bb->dispclk_dppclk_vco_speed_mhz); 1572 dcn3_01_soc.xfc_bus_transport_time_us = 1573 le32_to_cpu(bb->xfc_bus_transport_time_us); 1574 dcn3_01_soc.xfc_xbuf_latency_tolerance_us = 1575 le32_to_cpu(bb->xfc_xbuf_latency_tolerance_us); 1576 dcn3_01_soc.use_urgent_burst_bw = 1577 le32_to_cpu(bb->use_urgent_burst_bw); 1578 dcn3_01_soc.num_states = 1579 le32_to_cpu(bb->num_states); 1580 1581 for (i = 0; i < dcn3_01_soc.num_states; i++) { 1582 dcn3_01_soc.clock_limits[i].state = 1583 le32_to_cpu(bb->clock_limits[i].state); 1584 dcn3_01_soc.clock_limits[i].dcfclk_mhz = 1585 fixed16_to_double_to_cpu(bb->clock_limits[i].dcfclk_mhz); 1586 dcn3_01_soc.clock_limits[i].fabricclk_mhz = 1587 fixed16_to_double_to_cpu(bb->clock_limits[i].fabricclk_mhz); 1588 dcn3_01_soc.clock_limits[i].dispclk_mhz = 1589 fixed16_to_double_to_cpu(bb->clock_limits[i].dispclk_mhz); 1590 dcn3_01_soc.clock_limits[i].dppclk_mhz = 1591 fixed16_to_double_to_cpu(bb->clock_limits[i].dppclk_mhz); 1592 dcn3_01_soc.clock_limits[i].phyclk_mhz = 1593 fixed16_to_double_to_cpu(bb->clock_limits[i].phyclk_mhz); 1594 dcn3_01_soc.clock_limits[i].socclk_mhz = 1595 fixed16_to_double_to_cpu(bb->clock_limits[i].socclk_mhz); 1596 dcn3_01_soc.clock_limits[i].dscclk_mhz = 1597 fixed16_to_double_to_cpu(bb->clock_limits[i].dscclk_mhz); 1598 dcn3_01_soc.clock_limits[i].dram_speed_mts = 1599 fixed16_to_double_to_cpu(bb->clock_limits[i].dram_speed_mts); 1600 } 1601 } 1602 1603 if (pool->base.pp_smu) { 1604 struct pp_smu_nv_clock_table max_clocks = {0}; 1605 unsigned int uclk_states[8] = {0}; 1606 unsigned int num_states = 0; 1607 enum pp_smu_status status; 1608 bool clock_limits_available = false; 1609 bool uclk_states_available = false; 1610 1611 if (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) { 1612 status = (pool->base.pp_smu->nv_funcs.get_uclk_dpm_states) 1613 (&pool->base.pp_smu->nv_funcs.pp_smu, uclk_states, &num_states); 1614 1615 uclk_states_available = (status == PP_SMU_RESULT_OK); 1616 } 1617 1618 if (pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) { 1619 status = (*pool->base.pp_smu->nv_funcs.get_maximum_sustainable_clocks) 1620 (&pool->base.pp_smu->nv_funcs.pp_smu, &max_clocks); 1621 /* SMU cannot set DCF clock to anything equal to or higher than SOC clock 1622 */ 1623 if (max_clocks.dcfClockInKhz >= max_clocks.socClockInKhz) 1624 max_clocks.dcfClockInKhz = max_clocks.socClockInKhz - 1000; 1625 clock_limits_available = (status == PP_SMU_RESULT_OK); 1626 } 1627 1628 if (clock_limits_available && uclk_states_available && num_states) 1629 dcn20_update_bounding_box(dc, loaded_bb, &max_clocks, uclk_states, num_states); 1630 else if (clock_limits_available) 1631 dcn20_cap_soc_clocks(loaded_bb, max_clocks); 1632 } 1633 1634 loaded_ip->max_num_otg = pool->base.res_cap->num_timing_generator; 1635 loaded_ip->max_num_dpp = pool->base.pipe_count; 1636 dcn20_patch_bounding_box(dc, loaded_bb); 1637 1638 return true; 1639 } 1640 1641 static void set_wm_ranges( 1642 struct pp_smu_funcs *pp_smu, 1643 struct _vcs_dpi_soc_bounding_box_st *loaded_bb) 1644 { 1645 struct pp_smu_wm_range_sets ranges = {0}; 1646 int i; 1647 1648 ranges.num_reader_wm_sets = 0; 1649 1650 if (loaded_bb->num_states == 1) { 1651 ranges.reader_wm_sets[0].wm_inst = 0; 1652 ranges.reader_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 1653 ranges.reader_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 1654 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 1655 ranges.reader_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 1656 1657 ranges.num_reader_wm_sets = 1; 1658 } else if (loaded_bb->num_states > 1) { 1659 for (i = 0; i < 4 && i < loaded_bb->num_states; i++) { 1660 ranges.reader_wm_sets[i].wm_inst = i; 1661 ranges.reader_wm_sets[i].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 1662 ranges.reader_wm_sets[i].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 1663 ranges.reader_wm_sets[i].min_fill_clk_mhz = (i > 0) ? (loaded_bb->clock_limits[i - 1].dram_speed_mts / 16) + 1 : 0; 1664 ranges.reader_wm_sets[i].max_fill_clk_mhz = loaded_bb->clock_limits[i].dram_speed_mts / 16; 1665 1666 ranges.num_reader_wm_sets = i + 1; 1667 } 1668 1669 ranges.reader_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 1670 ranges.reader_wm_sets[ranges.num_reader_wm_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 1671 } 1672 1673 ranges.num_writer_wm_sets = 1; 1674 1675 ranges.writer_wm_sets[0].wm_inst = 0; 1676 ranges.writer_wm_sets[0].min_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 1677 ranges.writer_wm_sets[0].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 1678 ranges.writer_wm_sets[0].min_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MIN; 1679 ranges.writer_wm_sets[0].max_drain_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX; 1680 1681 /* Notify PP Lib/SMU which Watermarks to use for which clock ranges */ 1682 pp_smu->nv_funcs.set_wm_ranges(&pp_smu->nv_funcs.pp_smu, &ranges); 1683 } 1684 1685 static struct pp_smu_funcs *dcn301_pp_smu_create(struct dc_context *ctx) 1686 { 1687 struct pp_smu_funcs *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL); 1688 1689 if (!pp_smu) 1690 return pp_smu; 1691 1692 if (!IS_FPGA_MAXIMUS_DC(ctx->dce_environment) && !IS_DIAG_DC(ctx->dce_environment)) { 1693 dm_pp_get_funcs(ctx, pp_smu); 1694 1695 /* TODO: update once we have n21 smu*/ 1696 if (pp_smu->ctx.ver != PP_SMU_VER_NV) 1697 pp_smu = memset(pp_smu, 0, sizeof(struct pp_smu_funcs)); 1698 } 1699 1700 return pp_smu; 1701 } 1702 1703 static void dcn301_pp_smu_destroy(struct pp_smu_funcs **pp_smu) 1704 { 1705 if (pp_smu && *pp_smu) { 1706 kfree(*pp_smu); 1707 *pp_smu = NULL; 1708 } 1709 } 1710 1711 static void dcn301_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw_params) 1712 { 1713 dcn3_01_soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0; 1714 dc->dml.soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0; 1715 } 1716 1717 static struct resource_funcs dcn301_res_pool_funcs = { 1718 .destroy = dcn301_destroy_resource_pool, 1719 .link_enc_create = dcn301_link_encoder_create, 1720 .panel_cntl_create = dcn301_panel_cntl_create, 1721 .validate_bandwidth = dcn30_validate_bandwidth, 1722 .calculate_wm_and_dlg = dcn30_calculate_wm_and_dlg, 1723 .populate_dml_pipes = dcn30_populate_dml_pipes_from_context, 1724 .acquire_idle_pipe_for_layer = dcn20_acquire_idle_pipe_for_layer, 1725 .add_stream_to_ctx = dcn30_add_stream_to_ctx, 1726 .remove_stream_from_ctx = dcn20_remove_stream_from_ctx, 1727 .populate_dml_writeback_from_context = dcn30_populate_dml_writeback_from_context, 1728 .set_mcif_arb_params = dcn30_set_mcif_arb_params, 1729 .find_first_free_match_stream_enc_for_link = dcn10_find_first_free_match_stream_enc_for_link, 1730 .acquire_post_bldn_3dlut = dcn30_acquire_post_bldn_3dlut, 1731 .release_post_bldn_3dlut = dcn30_release_post_bldn_3dlut, 1732 .update_bw_bounding_box = dcn301_update_bw_bounding_box 1733 }; 1734 1735 static bool dcn301_resource_construct( 1736 uint8_t num_virtual_links, 1737 struct dc *dc, 1738 struct dcn301_resource_pool *pool) 1739 { 1740 int i, j; 1741 struct dc_context *ctx = dc->ctx; 1742 struct irq_service_init_data init_data; 1743 uint32_t pipe_fuses = read_pipe_fuses(ctx); 1744 uint32_t num_pipes = 0; 1745 1746 DC_LOGGER_INIT(dc->ctx->logger); 1747 1748 ctx->dc_bios->regs = &bios_regs; 1749 1750 pool->base.res_cap = &res_cap_dcn301; 1751 1752 pool->base.funcs = &dcn301_res_pool_funcs; 1753 1754 /************************************************* 1755 * Resource + asic cap harcoding * 1756 *************************************************/ 1757 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE; 1758 pool->base.pipe_count = pool->base.res_cap->num_timing_generator; 1759 pool->base.mpcc_count = pool->base.res_cap->num_timing_generator; 1760 dc->caps.max_downscale_ratio = 600; 1761 dc->caps.i2c_speed_in_khz = 100; 1762 dc->caps.i2c_speed_in_khz_hdcp = 5; /*1.4 w/a enabled by default*/ 1763 dc->caps.max_cursor_size = 256; 1764 dc->caps.min_horizontal_blanking_period = 80; 1765 dc->caps.dmdata_alloc_size = 2048; 1766 dc->caps.max_slave_planes = 1; 1767 dc->caps.is_apu = true; 1768 dc->caps.post_blend_color_processing = true; 1769 dc->caps.force_dp_tps4_for_cp2520 = true; 1770 dc->caps.extended_aux_timeout_support = true; 1771 #ifdef CONFIG_DRM_AMD_DC_DMUB 1772 dc->caps.dmcub_support = true; 1773 #endif 1774 1775 /* Color pipeline capabilities */ 1776 dc->caps.color.dpp.dcn_arch = 1; 1777 dc->caps.color.dpp.input_lut_shared = 0; 1778 dc->caps.color.dpp.icsc = 1; 1779 dc->caps.color.dpp.dgam_ram = 0; // must use gamma_corr 1780 dc->caps.color.dpp.dgam_rom_caps.srgb = 1; 1781 dc->caps.color.dpp.dgam_rom_caps.bt2020 = 1; 1782 dc->caps.color.dpp.dgam_rom_caps.gamma2_2 = 1; 1783 dc->caps.color.dpp.dgam_rom_caps.pq = 1; 1784 dc->caps.color.dpp.dgam_rom_caps.hlg = 1; 1785 dc->caps.color.dpp.post_csc = 1; 1786 dc->caps.color.dpp.gamma_corr = 1; 1787 dc->caps.color.dpp.dgam_rom_for_yuv = 0; 1788 1789 dc->caps.color.dpp.hw_3d_lut = 1; 1790 dc->caps.color.dpp.ogam_ram = 1; 1791 // no OGAM ROM on DCN301 1792 dc->caps.color.dpp.ogam_rom_caps.srgb = 0; 1793 dc->caps.color.dpp.ogam_rom_caps.bt2020 = 0; 1794 dc->caps.color.dpp.ogam_rom_caps.gamma2_2 = 0; 1795 dc->caps.color.dpp.ogam_rom_caps.pq = 0; 1796 dc->caps.color.dpp.ogam_rom_caps.hlg = 0; 1797 dc->caps.color.dpp.ocsc = 0; 1798 1799 dc->caps.color.mpc.gamut_remap = 1; 1800 dc->caps.color.mpc.num_3dluts = pool->base.res_cap->num_mpc_3dlut; //2 1801 dc->caps.color.mpc.ogam_ram = 1; 1802 dc->caps.color.mpc.ogam_rom_caps.srgb = 0; 1803 dc->caps.color.mpc.ogam_rom_caps.bt2020 = 0; 1804 dc->caps.color.mpc.ogam_rom_caps.gamma2_2 = 0; 1805 dc->caps.color.mpc.ogam_rom_caps.pq = 0; 1806 dc->caps.color.mpc.ogam_rom_caps.hlg = 0; 1807 dc->caps.color.mpc.ocsc = 1; 1808 1809 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV) 1810 dc->debug = debug_defaults_drv; 1811 else if (dc->ctx->dce_environment == DCE_ENV_FPGA_MAXIMUS) { 1812 dc->debug = debug_defaults_diags; 1813 } else 1814 dc->debug = debug_defaults_diags; 1815 // Init the vm_helper 1816 if (dc->vm_helper) 1817 vm_helper_init(dc->vm_helper, 16); 1818 1819 /************************************************* 1820 * Create resources * 1821 *************************************************/ 1822 1823 /* Clock Sources for Pixel Clock*/ 1824 pool->base.clock_sources[DCN301_CLK_SRC_PLL0] = 1825 dcn301_clock_source_create(ctx, ctx->dc_bios, 1826 CLOCK_SOURCE_COMBO_PHY_PLL0, 1827 &clk_src_regs[0], false); 1828 pool->base.clock_sources[DCN301_CLK_SRC_PLL1] = 1829 dcn301_clock_source_create(ctx, ctx->dc_bios, 1830 CLOCK_SOURCE_COMBO_PHY_PLL1, 1831 &clk_src_regs[1], false); 1832 pool->base.clock_sources[DCN301_CLK_SRC_PLL2] = 1833 dcn301_clock_source_create(ctx, ctx->dc_bios, 1834 CLOCK_SOURCE_COMBO_PHY_PLL2, 1835 &clk_src_regs[2], false); 1836 pool->base.clock_sources[DCN301_CLK_SRC_PLL3] = 1837 dcn301_clock_source_create(ctx, ctx->dc_bios, 1838 CLOCK_SOURCE_COMBO_PHY_PLL3, 1839 &clk_src_regs[3], false); 1840 1841 pool->base.clk_src_count = DCN301_CLK_SRC_TOTAL; 1842 1843 /* todo: not reuse phy_pll registers */ 1844 pool->base.dp_clock_source = 1845 dcn301_clock_source_create(ctx, ctx->dc_bios, 1846 CLOCK_SOURCE_ID_DP_DTO, 1847 &clk_src_regs[0], true); 1848 1849 for (i = 0; i < pool->base.clk_src_count; i++) { 1850 if (pool->base.clock_sources[i] == NULL) { 1851 dm_error("DC: failed to create clock sources!\n"); 1852 BREAK_TO_DEBUGGER(); 1853 goto create_fail; 1854 } 1855 } 1856 1857 /* DCCG */ 1858 pool->base.dccg = dccg301_create(ctx, &dccg_regs, &dccg_shift, &dccg_mask); 1859 if (pool->base.dccg == NULL) { 1860 dm_error("DC: failed to create dccg!\n"); 1861 BREAK_TO_DEBUGGER(); 1862 goto create_fail; 1863 } 1864 1865 /* PP Lib and SMU interfaces */ 1866 pool->base.pp_smu = dcn301_pp_smu_create(ctx); 1867 init_soc_bounding_box(dc, pool); 1868 if (!dc->debug.disable_pplib_wm_range && pool->base.pp_smu->nv_funcs.set_wm_ranges) 1869 set_wm_ranges(pool->base.pp_smu, &dcn3_01_soc); 1870 1871 num_pipes = dcn3_01_ip.max_num_dpp; 1872 1873 for (i = 0; i < dcn3_01_ip.max_num_dpp; i++) 1874 if (pipe_fuses & 1 << i) 1875 num_pipes--; 1876 dcn3_01_ip.max_num_dpp = num_pipes; 1877 dcn3_01_ip.max_num_otg = num_pipes; 1878 1879 1880 dml_init_instance(&dc->dml, &dcn3_01_soc, &dcn3_01_ip, DML_PROJECT_DCN30); 1881 1882 /* IRQ */ 1883 init_data.ctx = dc->ctx; 1884 pool->base.irqs = dal_irq_service_dcn30_create(&init_data); 1885 if (!pool->base.irqs) 1886 goto create_fail; 1887 1888 /* HUBBUB */ 1889 pool->base.hubbub = dcn301_hubbub_create(ctx); 1890 if (pool->base.hubbub == NULL) { 1891 BREAK_TO_DEBUGGER(); 1892 dm_error("DC: failed to create hubbub!\n"); 1893 goto create_fail; 1894 } 1895 1896 j = 0; 1897 /* HUBPs, DPPs, OPPs and TGs */ 1898 for (i = 0; i < pool->base.pipe_count; i++) { 1899 1900 /* if pipe is disabled, skip instance of HW pipe, 1901 * i.e, skip ASIC register instance 1902 */ 1903 if ((pipe_fuses & (1 << i)) != 0) { 1904 DC_LOG_DEBUG("%s: fusing pipe %d\n", __func__, i); 1905 continue; 1906 } 1907 1908 pool->base.hubps[j] = dcn301_hubp_create(ctx, i); 1909 if (pool->base.hubps[j] == NULL) { 1910 BREAK_TO_DEBUGGER(); 1911 dm_error( 1912 "DC: failed to create hubps!\n"); 1913 goto create_fail; 1914 } 1915 1916 pool->base.dpps[j] = dcn301_dpp_create(ctx, i); 1917 if (pool->base.dpps[j] == NULL) { 1918 BREAK_TO_DEBUGGER(); 1919 dm_error( 1920 "DC: failed to create dpps!\n"); 1921 goto create_fail; 1922 } 1923 1924 pool->base.opps[j] = dcn301_opp_create(ctx, i); 1925 if (pool->base.opps[j] == NULL) { 1926 BREAK_TO_DEBUGGER(); 1927 dm_error( 1928 "DC: failed to create output pixel processor!\n"); 1929 goto create_fail; 1930 } 1931 1932 pool->base.timing_generators[j] = dcn301_timing_generator_create(ctx, i); 1933 if (pool->base.timing_generators[j] == NULL) { 1934 BREAK_TO_DEBUGGER(); 1935 dm_error("DC: failed to create tg!\n"); 1936 goto create_fail; 1937 } 1938 j++; 1939 } 1940 pool->base.timing_generator_count = j; 1941 pool->base.pipe_count = j; 1942 pool->base.mpcc_count = j; 1943 1944 /* ABM (or ABMs for NV2x) */ 1945 /* TODO: */ 1946 for (i = 0; i < pool->base.res_cap->num_timing_generator; i++) { 1947 pool->base.multiple_abms[i] = dmub_abm_create(ctx, 1948 &abm_regs[i], 1949 &abm_shift, 1950 &abm_mask); 1951 if (pool->base.multiple_abms[i] == NULL) { 1952 dm_error("DC: failed to create abm for pipe %d!\n", i); 1953 BREAK_TO_DEBUGGER(); 1954 goto create_fail; 1955 } 1956 } 1957 1958 /* MPC and DSC */ 1959 pool->base.mpc = dcn301_mpc_create(ctx, pool->base.mpcc_count, pool->base.res_cap->num_mpc_3dlut); 1960 if (pool->base.mpc == NULL) { 1961 BREAK_TO_DEBUGGER(); 1962 dm_error("DC: failed to create mpc!\n"); 1963 goto create_fail; 1964 } 1965 1966 for (i = 0; i < pool->base.res_cap->num_dsc; i++) { 1967 pool->base.dscs[i] = dcn301_dsc_create(ctx, i); 1968 if (pool->base.dscs[i] == NULL) { 1969 BREAK_TO_DEBUGGER(); 1970 dm_error("DC: failed to create display stream compressor %d!\n", i); 1971 goto create_fail; 1972 } 1973 } 1974 1975 /* DWB and MMHUBBUB */ 1976 if (!dcn301_dwbc_create(ctx, &pool->base)) { 1977 BREAK_TO_DEBUGGER(); 1978 dm_error("DC: failed to create dwbc!\n"); 1979 goto create_fail; 1980 } 1981 1982 if (!dcn301_mmhubbub_create(ctx, &pool->base)) { 1983 BREAK_TO_DEBUGGER(); 1984 dm_error("DC: failed to create mcif_wb!\n"); 1985 goto create_fail; 1986 } 1987 1988 /* AUX and I2C */ 1989 for (i = 0; i < pool->base.res_cap->num_ddc; i++) { 1990 pool->base.engines[i] = dcn301_aux_engine_create(ctx, i); 1991 if (pool->base.engines[i] == NULL) { 1992 BREAK_TO_DEBUGGER(); 1993 dm_error( 1994 "DC:failed to create aux engine!!\n"); 1995 goto create_fail; 1996 } 1997 pool->base.hw_i2cs[i] = dcn301_i2c_hw_create(ctx, i); 1998 if (pool->base.hw_i2cs[i] == NULL) { 1999 BREAK_TO_DEBUGGER(); 2000 dm_error( 2001 "DC:failed to create hw i2c!!\n"); 2002 goto create_fail; 2003 } 2004 pool->base.sw_i2cs[i] = NULL; 2005 } 2006 2007 /* Audio, Stream Encoders including HPO and virtual, MPC 3D LUTs */ 2008 if (!resource_construct(num_virtual_links, dc, &pool->base, 2009 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ? 2010 &res_create_funcs : &res_create_maximus_funcs))) 2011 goto create_fail; 2012 2013 /* HW Sequencer and Plane caps */ 2014 dcn301_hw_sequencer_construct(dc); 2015 2016 dc->caps.max_planes = pool->base.pipe_count; 2017 2018 for (i = 0; i < dc->caps.max_planes; ++i) 2019 dc->caps.planes[i] = plane_cap; 2020 2021 dc->cap_funcs = cap_funcs; 2022 2023 return true; 2024 2025 create_fail: 2026 2027 dcn301_destruct(pool); 2028 2029 return false; 2030 } 2031 2032 struct resource_pool *dcn301_create_resource_pool( 2033 const struct dc_init_data *init_data, 2034 struct dc *dc) 2035 { 2036 struct dcn301_resource_pool *pool = 2037 kzalloc(sizeof(struct dcn301_resource_pool), GFP_KERNEL); 2038 2039 if (!pool) 2040 return NULL; 2041 2042 if (dcn301_resource_construct(init_data->num_virtual_links, dc, pool)) 2043 return &pool->base; 2044 2045 BREAK_TO_DEBUGGER(); 2046 kfree(pool); 2047 return NULL; 2048 } 2049