1 /* 2 * Copyright 2022 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 */ 23 24 #include <linux/firmware.h> 25 #include <drm/drm_drv.h> 26 27 #include "amdgpu.h" 28 #include "amdgpu_vcn.h" 29 #include "amdgpu_pm.h" 30 #include "soc15.h" 31 #include "soc15d.h" 32 #include "soc15_hw_ip.h" 33 #include "vcn_v2_0.h" 34 35 #include "vcn/vcn_4_0_3_offset.h" 36 #include "vcn/vcn_4_0_3_sh_mask.h" 37 #include "ivsrcid/vcn/irqsrcs_vcn_4_0.h" 38 39 #define mmUVD_DPG_LMA_CTL regUVD_DPG_LMA_CTL 40 #define mmUVD_DPG_LMA_CTL_BASE_IDX regUVD_DPG_LMA_CTL_BASE_IDX 41 #define mmUVD_DPG_LMA_DATA regUVD_DPG_LMA_DATA 42 #define mmUVD_DPG_LMA_DATA_BASE_IDX regUVD_DPG_LMA_DATA_BASE_IDX 43 44 #define VCN_VID_SOC_ADDRESS_2_0 0x1fb00 45 #define VCN1_VID_SOC_ADDRESS_3_0 0x48300 46 47 static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device *adev); 48 static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device *adev); 49 static int vcn_v4_0_3_set_powergating_state(void *handle, 50 enum amd_powergating_state state); 51 static int vcn_v4_0_3_pause_dpg_mode(struct amdgpu_device *adev, 52 int inst_idx, struct dpg_pause_state *new_state); 53 static void vcn_v4_0_3_unified_ring_set_wptr(struct amdgpu_ring *ring); 54 static void vcn_v4_0_3_set_ras_funcs(struct amdgpu_device *adev); 55 static void vcn_v4_0_3_enable_ras(struct amdgpu_device *adev, 56 int inst_idx, bool indirect); 57 /** 58 * vcn_v4_0_3_early_init - set function pointers 59 * 60 * @handle: amdgpu_device pointer 61 * 62 * Set ring and irq function pointers 63 */ 64 static int vcn_v4_0_3_early_init(void *handle) 65 { 66 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 67 68 /* re-use enc ring as unified ring */ 69 adev->vcn.num_enc_rings = 1; 70 71 vcn_v4_0_3_set_unified_ring_funcs(adev); 72 vcn_v4_0_3_set_irq_funcs(adev); 73 vcn_v4_0_3_set_ras_funcs(adev); 74 75 return amdgpu_vcn_early_init(adev); 76 } 77 78 /** 79 * vcn_v4_0_3_sw_init - sw init for VCN block 80 * 81 * @handle: amdgpu_device pointer 82 * 83 * Load firmware and sw initialization 84 */ 85 static int vcn_v4_0_3_sw_init(void *handle) 86 { 87 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 88 struct amdgpu_ring *ring; 89 int i, r, vcn_inst; 90 91 r = amdgpu_vcn_sw_init(adev); 92 if (r) 93 return r; 94 95 amdgpu_vcn_setup_ucode(adev); 96 97 r = amdgpu_vcn_resume(adev); 98 if (r) 99 return r; 100 101 /* VCN DEC TRAP */ 102 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VCN, 103 VCN_4_0__SRCID__UVD_ENC_GENERAL_PURPOSE, &adev->vcn.inst->irq); 104 if (r) 105 return r; 106 107 for (i = 0; i < adev->vcn.num_vcn_inst; i++) { 108 volatile struct amdgpu_vcn4_fw_shared *fw_shared; 109 110 vcn_inst = GET_INST(VCN, i); 111 112 ring = &adev->vcn.inst[i].ring_enc[0]; 113 ring->use_doorbell = true; 114 ring->doorbell_index = 115 (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + 116 9 * vcn_inst; 117 ring->vm_hub = AMDGPU_MMHUB0(adev->vcn.inst[i].aid_id); 118 sprintf(ring->name, "vcn_unified_%d", adev->vcn.inst[i].aid_id); 119 r = amdgpu_ring_init(adev, ring, 512, &adev->vcn.inst->irq, 0, 120 AMDGPU_RING_PRIO_DEFAULT, 121 &adev->vcn.inst[i].sched_score); 122 if (r) 123 return r; 124 125 fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr; 126 fw_shared->present_flag_0 = cpu_to_le32(AMDGPU_FW_SHARED_FLAG_0_UNIFIED_QUEUE); 127 fw_shared->sq.is_enabled = true; 128 129 if (amdgpu_vcnfw_log) 130 amdgpu_vcn_fwlog_init(&adev->vcn.inst[i]); 131 } 132 133 if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) 134 adev->vcn.pause_dpg_mode = vcn_v4_0_3_pause_dpg_mode; 135 136 if (amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__VCN)) { 137 r = amdgpu_vcn_ras_sw_init(adev); 138 if (r) { 139 dev_err(adev->dev, "Failed to initialize vcn ras block!\n"); 140 return r; 141 } 142 } 143 144 return 0; 145 } 146 147 /** 148 * vcn_v4_0_3_sw_fini - sw fini for VCN block 149 * 150 * @handle: amdgpu_device pointer 151 * 152 * VCN suspend and free up sw allocation 153 */ 154 static int vcn_v4_0_3_sw_fini(void *handle) 155 { 156 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 157 int i, r, idx; 158 159 if (drm_dev_enter(&adev->ddev, &idx)) { 160 for (i = 0; i < adev->vcn.num_vcn_inst; i++) { 161 volatile struct amdgpu_vcn4_fw_shared *fw_shared; 162 163 fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr; 164 fw_shared->present_flag_0 = 0; 165 fw_shared->sq.is_enabled = cpu_to_le32(false); 166 } 167 drm_dev_exit(idx); 168 } 169 170 r = amdgpu_vcn_suspend(adev); 171 if (r) 172 return r; 173 174 r = amdgpu_vcn_sw_fini(adev); 175 176 return r; 177 } 178 179 /** 180 * vcn_v4_0_3_hw_init - start and test VCN block 181 * 182 * @handle: amdgpu_device pointer 183 * 184 * Initialize the hardware, boot up the VCPU and do some testing 185 */ 186 static int vcn_v4_0_3_hw_init(void *handle) 187 { 188 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 189 struct amdgpu_ring *ring; 190 int i, r, vcn_inst; 191 192 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 193 vcn_inst = GET_INST(VCN, i); 194 ring = &adev->vcn.inst[i].ring_enc[0]; 195 196 if (ring->use_doorbell) { 197 adev->nbio.funcs->vcn_doorbell_range( 198 adev, ring->use_doorbell, 199 (adev->doorbell_index.vcn.vcn_ring0_1 << 1) + 200 9 * vcn_inst, 201 adev->vcn.inst[i].aid_id); 202 203 WREG32_SOC15( 204 VCN, GET_INST(VCN, ring->me), 205 regVCN_RB1_DB_CTRL, 206 ring->doorbell_index 207 << VCN_RB1_DB_CTRL__OFFSET__SHIFT | 208 VCN_RB1_DB_CTRL__EN_MASK); 209 210 /* Read DB_CTRL to flush the write DB_CTRL command. */ 211 RREG32_SOC15( 212 VCN, GET_INST(VCN, ring->me), 213 regVCN_RB1_DB_CTRL); 214 } 215 216 r = amdgpu_ring_test_helper(ring); 217 if (r) 218 goto done; 219 } 220 221 done: 222 if (!r) 223 DRM_DEV_INFO(adev->dev, "VCN decode initialized successfully(under %s).\n", 224 (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)?"DPG Mode":"SPG Mode"); 225 226 return r; 227 } 228 229 /** 230 * vcn_v4_0_3_hw_fini - stop the hardware block 231 * 232 * @handle: amdgpu_device pointer 233 * 234 * Stop the VCN block, mark ring as not ready any more 235 */ 236 static int vcn_v4_0_3_hw_fini(void *handle) 237 { 238 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 239 240 cancel_delayed_work_sync(&adev->vcn.idle_work); 241 242 if (adev->vcn.cur_state != AMD_PG_STATE_GATE) 243 vcn_v4_0_3_set_powergating_state(adev, AMD_PG_STATE_GATE); 244 245 return 0; 246 } 247 248 /** 249 * vcn_v4_0_3_suspend - suspend VCN block 250 * 251 * @handle: amdgpu_device pointer 252 * 253 * HW fini and suspend VCN block 254 */ 255 static int vcn_v4_0_3_suspend(void *handle) 256 { 257 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 258 int r; 259 260 r = vcn_v4_0_3_hw_fini(adev); 261 if (r) 262 return r; 263 264 r = amdgpu_vcn_suspend(adev); 265 266 return r; 267 } 268 269 /** 270 * vcn_v4_0_3_resume - resume VCN block 271 * 272 * @handle: amdgpu_device pointer 273 * 274 * Resume firmware and hw init VCN block 275 */ 276 static int vcn_v4_0_3_resume(void *handle) 277 { 278 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 279 int r; 280 281 r = amdgpu_vcn_resume(adev); 282 if (r) 283 return r; 284 285 r = vcn_v4_0_3_hw_init(adev); 286 287 return r; 288 } 289 290 /** 291 * vcn_v4_0_3_mc_resume - memory controller programming 292 * 293 * @adev: amdgpu_device pointer 294 * @inst_idx: instance number 295 * 296 * Let the VCN memory controller know it's offsets 297 */ 298 static void vcn_v4_0_3_mc_resume(struct amdgpu_device *adev, int inst_idx) 299 { 300 uint32_t offset, size, vcn_inst; 301 const struct common_firmware_header *hdr; 302 303 hdr = (const struct common_firmware_header *)adev->vcn.fw->data; 304 size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8); 305 306 vcn_inst = GET_INST(VCN, inst_idx); 307 /* cache window 0: fw */ 308 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) { 309 WREG32_SOC15( 310 VCN, vcn_inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW, 311 (adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + inst_idx] 312 .tmr_mc_addr_lo)); 313 WREG32_SOC15( 314 VCN, vcn_inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH, 315 (adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + inst_idx] 316 .tmr_mc_addr_hi)); 317 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_OFFSET0, 0); 318 offset = 0; 319 } else { 320 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW, 321 lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr)); 322 WREG32_SOC15(VCN, vcn_inst, 323 regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH, 324 upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr)); 325 offset = size; 326 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_OFFSET0, 327 AMDGPU_UVD_FIRMWARE_OFFSET >> 3); 328 } 329 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_SIZE0, size); 330 331 /* cache window 1: stack */ 332 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW, 333 lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset)); 334 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH, 335 upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset)); 336 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_OFFSET1, 0); 337 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_SIZE1, 338 AMDGPU_VCN_STACK_SIZE); 339 340 /* cache window 2: context */ 341 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW, 342 lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset + 343 AMDGPU_VCN_STACK_SIZE)); 344 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH, 345 upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset + 346 AMDGPU_VCN_STACK_SIZE)); 347 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_OFFSET2, 0); 348 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_CACHE_SIZE2, 349 AMDGPU_VCN_CONTEXT_SIZE); 350 351 /* non-cache window */ 352 WREG32_SOC15( 353 VCN, vcn_inst, regUVD_LMI_VCPU_NC0_64BIT_BAR_LOW, 354 lower_32_bits(adev->vcn.inst[inst_idx].fw_shared.gpu_addr)); 355 WREG32_SOC15( 356 VCN, vcn_inst, regUVD_LMI_VCPU_NC0_64BIT_BAR_HIGH, 357 upper_32_bits(adev->vcn.inst[inst_idx].fw_shared.gpu_addr)); 358 WREG32_SOC15(VCN, vcn_inst, regUVD_VCPU_NONCACHE_OFFSET0, 0); 359 WREG32_SOC15( 360 VCN, vcn_inst, regUVD_VCPU_NONCACHE_SIZE0, 361 AMDGPU_GPU_PAGE_ALIGN(sizeof(struct amdgpu_vcn4_fw_shared))); 362 } 363 364 /** 365 * vcn_v4_0_3_mc_resume_dpg_mode - memory controller programming for dpg mode 366 * 367 * @adev: amdgpu_device pointer 368 * @inst_idx: instance number index 369 * @indirect: indirectly write sram 370 * 371 * Let the VCN memory controller know it's offsets with dpg mode 372 */ 373 static void vcn_v4_0_3_mc_resume_dpg_mode(struct amdgpu_device *adev, int inst_idx, bool indirect) 374 { 375 uint32_t offset, size; 376 const struct common_firmware_header *hdr; 377 378 hdr = (const struct common_firmware_header *)adev->vcn.fw->data; 379 size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8); 380 381 /* cache window 0: fw */ 382 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) { 383 if (!indirect) { 384 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 385 VCN, 0, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW), 386 (adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + 387 inst_idx].tmr_mc_addr_lo), 0, indirect); 388 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 389 VCN, 0, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH), 390 (adev->firmware.ucode[AMDGPU_UCODE_ID_VCN + 391 inst_idx].tmr_mc_addr_hi), 0, indirect); 392 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 393 VCN, 0, regUVD_VCPU_CACHE_OFFSET0), 0, 0, indirect); 394 } else { 395 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 396 VCN, 0, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW), 0, 0, indirect); 397 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 398 VCN, 0, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH), 0, 0, indirect); 399 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 400 VCN, 0, regUVD_VCPU_CACHE_OFFSET0), 0, 0, indirect); 401 } 402 offset = 0; 403 } else { 404 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 405 VCN, 0, regUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW), 406 lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr), 0, indirect); 407 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 408 VCN, 0, regUVD_LMI_VCPU_CACHE_64BIT_BAR_HIGH), 409 upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr), 0, indirect); 410 offset = size; 411 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 412 VCN, 0, regUVD_VCPU_CACHE_OFFSET0), 413 AMDGPU_UVD_FIRMWARE_OFFSET >> 3, 0, indirect); 414 } 415 416 if (!indirect) 417 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 418 VCN, 0, regUVD_VCPU_CACHE_SIZE0), size, 0, indirect); 419 else 420 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 421 VCN, 0, regUVD_VCPU_CACHE_SIZE0), 0, 0, indirect); 422 423 /* cache window 1: stack */ 424 if (!indirect) { 425 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 426 VCN, 0, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW), 427 lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset), 0, indirect); 428 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 429 VCN, 0, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH), 430 upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset), 0, indirect); 431 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 432 VCN, 0, regUVD_VCPU_CACHE_OFFSET1), 0, 0, indirect); 433 } else { 434 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 435 VCN, 0, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_LOW), 0, 0, indirect); 436 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 437 VCN, 0, regUVD_LMI_VCPU_CACHE1_64BIT_BAR_HIGH), 0, 0, indirect); 438 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 439 VCN, 0, regUVD_VCPU_CACHE_OFFSET1), 0, 0, indirect); 440 } 441 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 442 VCN, 0, regUVD_VCPU_CACHE_SIZE1), AMDGPU_VCN_STACK_SIZE, 0, indirect); 443 444 /* cache window 2: context */ 445 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 446 VCN, 0, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_LOW), 447 lower_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset + 448 AMDGPU_VCN_STACK_SIZE), 0, indirect); 449 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 450 VCN, 0, regUVD_LMI_VCPU_CACHE2_64BIT_BAR_HIGH), 451 upper_32_bits(adev->vcn.inst[inst_idx].gpu_addr + offset + 452 AMDGPU_VCN_STACK_SIZE), 0, indirect); 453 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 454 VCN, 0, regUVD_VCPU_CACHE_OFFSET2), 0, 0, indirect); 455 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 456 VCN, 0, regUVD_VCPU_CACHE_SIZE2), AMDGPU_VCN_CONTEXT_SIZE, 0, indirect); 457 458 /* non-cache window */ 459 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 460 VCN, 0, regUVD_LMI_VCPU_NC0_64BIT_BAR_LOW), 461 lower_32_bits(adev->vcn.inst[inst_idx].fw_shared.gpu_addr), 0, indirect); 462 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 463 VCN, 0, regUVD_LMI_VCPU_NC0_64BIT_BAR_HIGH), 464 upper_32_bits(adev->vcn.inst[inst_idx].fw_shared.gpu_addr), 0, indirect); 465 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 466 VCN, 0, regUVD_VCPU_NONCACHE_OFFSET0), 0, 0, indirect); 467 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 468 VCN, 0, regUVD_VCPU_NONCACHE_SIZE0), 469 AMDGPU_GPU_PAGE_ALIGN(sizeof(struct amdgpu_vcn4_fw_shared)), 0, indirect); 470 471 /* VCN global tiling registers */ 472 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 473 VCN, 0, regUVD_GFX8_ADDR_CONFIG), adev->gfx.config.gb_addr_config, 0, indirect); 474 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 475 VCN, 0, regUVD_GFX10_ADDR_CONFIG), adev->gfx.config.gb_addr_config, 0, indirect); 476 } 477 478 /** 479 * vcn_v4_0_3_disable_clock_gating - disable VCN clock gating 480 * 481 * @adev: amdgpu_device pointer 482 * @inst_idx: instance number 483 * 484 * Disable clock gating for VCN block 485 */ 486 static void vcn_v4_0_3_disable_clock_gating(struct amdgpu_device *adev, int inst_idx) 487 { 488 uint32_t data; 489 int vcn_inst; 490 491 if (adev->cg_flags & AMD_CG_SUPPORT_VCN_MGCG) 492 return; 493 494 vcn_inst = GET_INST(VCN, inst_idx); 495 496 /* VCN disable CGC */ 497 data = RREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL); 498 data &= ~UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK; 499 data |= 1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT; 500 data |= 4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT; 501 WREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL, data); 502 503 data = RREG32_SOC15(VCN, vcn_inst, regUVD_CGC_GATE); 504 data &= ~(UVD_CGC_GATE__SYS_MASK 505 | UVD_CGC_GATE__MPEG2_MASK 506 | UVD_CGC_GATE__REGS_MASK 507 | UVD_CGC_GATE__RBC_MASK 508 | UVD_CGC_GATE__LMI_MC_MASK 509 | UVD_CGC_GATE__LMI_UMC_MASK 510 | UVD_CGC_GATE__MPC_MASK 511 | UVD_CGC_GATE__LBSI_MASK 512 | UVD_CGC_GATE__LRBBM_MASK 513 | UVD_CGC_GATE__WCB_MASK 514 | UVD_CGC_GATE__VCPU_MASK 515 | UVD_CGC_GATE__MMSCH_MASK); 516 517 WREG32_SOC15(VCN, vcn_inst, regUVD_CGC_GATE, data); 518 SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_CGC_GATE, 0, 0xFFFFFFFF); 519 520 data = RREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL); 521 data &= ~(UVD_CGC_CTRL__SYS_MODE_MASK 522 | UVD_CGC_CTRL__MPEG2_MODE_MASK 523 | UVD_CGC_CTRL__REGS_MODE_MASK 524 | UVD_CGC_CTRL__RBC_MODE_MASK 525 | UVD_CGC_CTRL__LMI_MC_MODE_MASK 526 | UVD_CGC_CTRL__LMI_UMC_MODE_MASK 527 | UVD_CGC_CTRL__MPC_MODE_MASK 528 | UVD_CGC_CTRL__LBSI_MODE_MASK 529 | UVD_CGC_CTRL__LRBBM_MODE_MASK 530 | UVD_CGC_CTRL__WCB_MODE_MASK 531 | UVD_CGC_CTRL__VCPU_MODE_MASK 532 | UVD_CGC_CTRL__MMSCH_MODE_MASK); 533 WREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL, data); 534 535 data = RREG32_SOC15(VCN, vcn_inst, regUVD_SUVD_CGC_GATE); 536 data |= (UVD_SUVD_CGC_GATE__SRE_MASK 537 | UVD_SUVD_CGC_GATE__SIT_MASK 538 | UVD_SUVD_CGC_GATE__SMP_MASK 539 | UVD_SUVD_CGC_GATE__SCM_MASK 540 | UVD_SUVD_CGC_GATE__SDB_MASK 541 | UVD_SUVD_CGC_GATE__SRE_H264_MASK 542 | UVD_SUVD_CGC_GATE__SRE_HEVC_MASK 543 | UVD_SUVD_CGC_GATE__SIT_H264_MASK 544 | UVD_SUVD_CGC_GATE__SIT_HEVC_MASK 545 | UVD_SUVD_CGC_GATE__SCM_H264_MASK 546 | UVD_SUVD_CGC_GATE__SCM_HEVC_MASK 547 | UVD_SUVD_CGC_GATE__SDB_H264_MASK 548 | UVD_SUVD_CGC_GATE__SDB_HEVC_MASK 549 | UVD_SUVD_CGC_GATE__ENT_MASK 550 | UVD_SUVD_CGC_GATE__SIT_HEVC_DEC_MASK 551 | UVD_SUVD_CGC_GATE__SITE_MASK 552 | UVD_SUVD_CGC_GATE__SRE_VP9_MASK 553 | UVD_SUVD_CGC_GATE__SCM_VP9_MASK 554 | UVD_SUVD_CGC_GATE__SIT_VP9_DEC_MASK 555 | UVD_SUVD_CGC_GATE__SDB_VP9_MASK 556 | UVD_SUVD_CGC_GATE__IME_HEVC_MASK); 557 WREG32_SOC15(VCN, vcn_inst, regUVD_SUVD_CGC_GATE, data); 558 559 data = RREG32_SOC15(VCN, vcn_inst, regUVD_SUVD_CGC_CTRL); 560 data &= ~(UVD_SUVD_CGC_CTRL__SRE_MODE_MASK 561 | UVD_SUVD_CGC_CTRL__SIT_MODE_MASK 562 | UVD_SUVD_CGC_CTRL__SMP_MODE_MASK 563 | UVD_SUVD_CGC_CTRL__SCM_MODE_MASK 564 | UVD_SUVD_CGC_CTRL__SDB_MODE_MASK 565 | UVD_SUVD_CGC_CTRL__ENT_MODE_MASK 566 | UVD_SUVD_CGC_CTRL__IME_MODE_MASK 567 | UVD_SUVD_CGC_CTRL__SITE_MODE_MASK); 568 WREG32_SOC15(VCN, vcn_inst, regUVD_SUVD_CGC_CTRL, data); 569 } 570 571 /** 572 * vcn_v4_0_3_disable_clock_gating_dpg_mode - disable VCN clock gating dpg mode 573 * 574 * @adev: amdgpu_device pointer 575 * @sram_sel: sram select 576 * @inst_idx: instance number index 577 * @indirect: indirectly write sram 578 * 579 * Disable clock gating for VCN block with dpg mode 580 */ 581 static void vcn_v4_0_3_disable_clock_gating_dpg_mode(struct amdgpu_device *adev, uint8_t sram_sel, 582 int inst_idx, uint8_t indirect) 583 { 584 uint32_t reg_data = 0; 585 586 if (adev->cg_flags & AMD_CG_SUPPORT_VCN_MGCG) 587 return; 588 589 /* enable sw clock gating control */ 590 reg_data = 0 << UVD_CGC_CTRL__DYN_CLOCK_MODE__SHIFT; 591 reg_data |= 1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT; 592 reg_data |= 4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT; 593 reg_data &= ~(UVD_CGC_CTRL__SYS_MODE_MASK | 594 UVD_CGC_CTRL__MPEG2_MODE_MASK | 595 UVD_CGC_CTRL__REGS_MODE_MASK | 596 UVD_CGC_CTRL__RBC_MODE_MASK | 597 UVD_CGC_CTRL__LMI_MC_MODE_MASK | 598 UVD_CGC_CTRL__LMI_UMC_MODE_MASK | 599 UVD_CGC_CTRL__IDCT_MODE_MASK | 600 UVD_CGC_CTRL__MPRD_MODE_MASK | 601 UVD_CGC_CTRL__MPC_MODE_MASK | 602 UVD_CGC_CTRL__LBSI_MODE_MASK | 603 UVD_CGC_CTRL__LRBBM_MODE_MASK | 604 UVD_CGC_CTRL__WCB_MODE_MASK | 605 UVD_CGC_CTRL__VCPU_MODE_MASK); 606 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 607 VCN, 0, regUVD_CGC_CTRL), reg_data, sram_sel, indirect); 608 609 /* turn off clock gating */ 610 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 611 VCN, 0, regUVD_CGC_GATE), 0, sram_sel, indirect); 612 613 /* turn on SUVD clock gating */ 614 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 615 VCN, 0, regUVD_SUVD_CGC_GATE), 1, sram_sel, indirect); 616 617 /* turn on sw mode in UVD_SUVD_CGC_CTRL */ 618 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 619 VCN, 0, regUVD_SUVD_CGC_CTRL), 0, sram_sel, indirect); 620 } 621 622 /** 623 * vcn_v4_0_3_enable_clock_gating - enable VCN clock gating 624 * 625 * @adev: amdgpu_device pointer 626 * @inst_idx: instance number 627 * 628 * Enable clock gating for VCN block 629 */ 630 static void vcn_v4_0_3_enable_clock_gating(struct amdgpu_device *adev, int inst_idx) 631 { 632 uint32_t data; 633 int vcn_inst; 634 635 if (adev->cg_flags & AMD_CG_SUPPORT_VCN_MGCG) 636 return; 637 638 vcn_inst = GET_INST(VCN, inst_idx); 639 640 /* enable VCN CGC */ 641 data = RREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL); 642 data |= 0 << UVD_CGC_CTRL__DYN_CLOCK_MODE__SHIFT; 643 data |= 1 << UVD_CGC_CTRL__CLK_GATE_DLY_TIMER__SHIFT; 644 data |= 4 << UVD_CGC_CTRL__CLK_OFF_DELAY__SHIFT; 645 WREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL, data); 646 647 data = RREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL); 648 data |= (UVD_CGC_CTRL__SYS_MODE_MASK 649 | UVD_CGC_CTRL__MPEG2_MODE_MASK 650 | UVD_CGC_CTRL__REGS_MODE_MASK 651 | UVD_CGC_CTRL__RBC_MODE_MASK 652 | UVD_CGC_CTRL__LMI_MC_MODE_MASK 653 | UVD_CGC_CTRL__LMI_UMC_MODE_MASK 654 | UVD_CGC_CTRL__MPC_MODE_MASK 655 | UVD_CGC_CTRL__LBSI_MODE_MASK 656 | UVD_CGC_CTRL__LRBBM_MODE_MASK 657 | UVD_CGC_CTRL__WCB_MODE_MASK 658 | UVD_CGC_CTRL__VCPU_MODE_MASK); 659 WREG32_SOC15(VCN, vcn_inst, regUVD_CGC_CTRL, data); 660 661 data = RREG32_SOC15(VCN, vcn_inst, regUVD_SUVD_CGC_CTRL); 662 data |= (UVD_SUVD_CGC_CTRL__SRE_MODE_MASK 663 | UVD_SUVD_CGC_CTRL__SIT_MODE_MASK 664 | UVD_SUVD_CGC_CTRL__SMP_MODE_MASK 665 | UVD_SUVD_CGC_CTRL__SCM_MODE_MASK 666 | UVD_SUVD_CGC_CTRL__SDB_MODE_MASK 667 | UVD_SUVD_CGC_CTRL__ENT_MODE_MASK 668 | UVD_SUVD_CGC_CTRL__IME_MODE_MASK 669 | UVD_SUVD_CGC_CTRL__SITE_MODE_MASK); 670 WREG32_SOC15(VCN, vcn_inst, regUVD_SUVD_CGC_CTRL, data); 671 } 672 673 /** 674 * vcn_v4_0_3_start_dpg_mode - VCN start with dpg mode 675 * 676 * @adev: amdgpu_device pointer 677 * @inst_idx: instance number index 678 * @indirect: indirectly write sram 679 * 680 * Start VCN block with dpg mode 681 */ 682 static int vcn_v4_0_3_start_dpg_mode(struct amdgpu_device *adev, int inst_idx, bool indirect) 683 { 684 volatile struct amdgpu_vcn4_fw_shared *fw_shared = 685 adev->vcn.inst[inst_idx].fw_shared.cpu_addr; 686 struct amdgpu_ring *ring; 687 int vcn_inst; 688 uint32_t tmp; 689 690 vcn_inst = GET_INST(VCN, inst_idx); 691 /* disable register anti-hang mechanism */ 692 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_POWER_STATUS), 1, 693 ~UVD_POWER_STATUS__UVD_POWER_STATUS_MASK); 694 /* enable dynamic power gating mode */ 695 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_POWER_STATUS); 696 tmp |= UVD_POWER_STATUS__UVD_PG_MODE_MASK; 697 tmp |= UVD_POWER_STATUS__UVD_PG_EN_MASK; 698 WREG32_SOC15(VCN, vcn_inst, regUVD_POWER_STATUS, tmp); 699 700 if (indirect) { 701 DRM_DEV_DEBUG(adev->dev, "VCN %d start: on AID %d", 702 inst_idx, adev->vcn.inst[inst_idx].aid_id); 703 adev->vcn.inst[inst_idx].dpg_sram_curr_addr = 704 (uint32_t *)adev->vcn.inst[inst_idx].dpg_sram_cpu_addr; 705 /* Use dummy register 0xDEADBEEF passing AID selection to PSP FW */ 706 WREG32_SOC15_DPG_MODE(inst_idx, 0xDEADBEEF, 707 adev->vcn.inst[inst_idx].aid_id, 0, true); 708 } 709 710 /* enable clock gating */ 711 vcn_v4_0_3_disable_clock_gating_dpg_mode(adev, 0, inst_idx, indirect); 712 713 /* enable VCPU clock */ 714 tmp = (0xFF << UVD_VCPU_CNTL__PRB_TIMEOUT_VAL__SHIFT); 715 tmp |= UVD_VCPU_CNTL__CLK_EN_MASK; 716 tmp |= UVD_VCPU_CNTL__BLK_RST_MASK; 717 718 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 719 VCN, 0, regUVD_VCPU_CNTL), tmp, 0, indirect); 720 721 /* disable master interrupt */ 722 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 723 VCN, 0, regUVD_MASTINT_EN), 0, 0, indirect); 724 725 /* setup regUVD_LMI_CTRL */ 726 tmp = (UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK | 727 UVD_LMI_CTRL__REQ_MODE_MASK | 728 UVD_LMI_CTRL__CRC_RESET_MASK | 729 UVD_LMI_CTRL__MASK_MC_URGENT_MASK | 730 UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK | 731 UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK | 732 (8 << UVD_LMI_CTRL__WRITE_CLEAN_TIMER__SHIFT) | 733 0x00100000L); 734 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 735 VCN, 0, regUVD_LMI_CTRL), tmp, 0, indirect); 736 737 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 738 VCN, 0, regUVD_MPC_CNTL), 739 0x2 << UVD_MPC_CNTL__REPLACEMENT_MODE__SHIFT, 0, indirect); 740 741 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 742 VCN, 0, regUVD_MPC_SET_MUXA0), 743 ((0x1 << UVD_MPC_SET_MUXA0__VARA_1__SHIFT) | 744 (0x2 << UVD_MPC_SET_MUXA0__VARA_2__SHIFT) | 745 (0x3 << UVD_MPC_SET_MUXA0__VARA_3__SHIFT) | 746 (0x4 << UVD_MPC_SET_MUXA0__VARA_4__SHIFT)), 0, indirect); 747 748 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 749 VCN, 0, regUVD_MPC_SET_MUXB0), 750 ((0x1 << UVD_MPC_SET_MUXB0__VARB_1__SHIFT) | 751 (0x2 << UVD_MPC_SET_MUXB0__VARB_2__SHIFT) | 752 (0x3 << UVD_MPC_SET_MUXB0__VARB_3__SHIFT) | 753 (0x4 << UVD_MPC_SET_MUXB0__VARB_4__SHIFT)), 0, indirect); 754 755 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 756 VCN, 0, regUVD_MPC_SET_MUX), 757 ((0x0 << UVD_MPC_SET_MUX__SET_0__SHIFT) | 758 (0x1 << UVD_MPC_SET_MUX__SET_1__SHIFT) | 759 (0x2 << UVD_MPC_SET_MUX__SET_2__SHIFT)), 0, indirect); 760 761 vcn_v4_0_3_mc_resume_dpg_mode(adev, inst_idx, indirect); 762 763 tmp = (0xFF << UVD_VCPU_CNTL__PRB_TIMEOUT_VAL__SHIFT); 764 tmp |= UVD_VCPU_CNTL__CLK_EN_MASK; 765 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 766 VCN, 0, regUVD_VCPU_CNTL), tmp, 0, indirect); 767 768 /* enable LMI MC and UMC channels */ 769 tmp = 0x1f << UVD_LMI_CTRL2__RE_OFLD_MIF_WR_REQ_NUM__SHIFT; 770 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 771 VCN, 0, regUVD_LMI_CTRL2), tmp, 0, indirect); 772 773 vcn_v4_0_3_enable_ras(adev, inst_idx, indirect); 774 775 /* enable master interrupt */ 776 WREG32_SOC15_DPG_MODE(inst_idx, SOC15_DPG_MODE_OFFSET( 777 VCN, 0, regUVD_MASTINT_EN), 778 UVD_MASTINT_EN__VCPU_EN_MASK, 0, indirect); 779 780 if (indirect) 781 amdgpu_vcn_psp_update_sram(adev, inst_idx, AMDGPU_UCODE_ID_VCN0_RAM); 782 783 ring = &adev->vcn.inst[inst_idx].ring_enc[0]; 784 785 /* program the RB_BASE for ring buffer */ 786 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_BASE_LO, 787 lower_32_bits(ring->gpu_addr)); 788 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_BASE_HI, 789 upper_32_bits(ring->gpu_addr)); 790 791 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_SIZE, 792 ring->ring_size / sizeof(uint32_t)); 793 794 /* resetting ring, fw should not check RB ring */ 795 tmp = RREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE); 796 tmp &= ~(VCN_RB_ENABLE__RB_EN_MASK); 797 WREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE, tmp); 798 fw_shared->sq.queue_mode |= FW_QUEUE_RING_RESET; 799 800 /* Initialize the ring buffer's read and write pointers */ 801 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_RPTR, 0); 802 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_WPTR, 0); 803 ring->wptr = RREG32_SOC15(VCN, vcn_inst, regUVD_RB_WPTR); 804 805 tmp = RREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE); 806 tmp |= VCN_RB_ENABLE__RB_EN_MASK; 807 WREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE, tmp); 808 fw_shared->sq.queue_mode &= ~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF); 809 810 /*resetting done, fw can check RB ring */ 811 fw_shared->sq.queue_mode &= cpu_to_le32(~FW_QUEUE_RING_RESET); 812 813 return 0; 814 } 815 816 /** 817 * vcn_v4_0_3_start - VCN start 818 * 819 * @adev: amdgpu_device pointer 820 * 821 * Start VCN block 822 */ 823 static int vcn_v4_0_3_start(struct amdgpu_device *adev) 824 { 825 volatile struct amdgpu_vcn4_fw_shared *fw_shared; 826 struct amdgpu_ring *ring; 827 int i, j, k, r, vcn_inst; 828 uint32_t tmp; 829 830 if (adev->pm.dpm_enabled) 831 amdgpu_dpm_enable_uvd(adev, true); 832 833 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 834 if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) { 835 r = vcn_v4_0_3_start_dpg_mode(adev, i, adev->vcn.indirect_sram); 836 continue; 837 } 838 839 vcn_inst = GET_INST(VCN, i); 840 /* set VCN status busy */ 841 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_STATUS) | 842 UVD_STATUS__UVD_BUSY; 843 WREG32_SOC15(VCN, vcn_inst, regUVD_STATUS, tmp); 844 845 /*SW clock gating */ 846 vcn_v4_0_3_disable_clock_gating(adev, i); 847 848 /* enable VCPU clock */ 849 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_VCPU_CNTL), 850 UVD_VCPU_CNTL__CLK_EN_MASK, 851 ~UVD_VCPU_CNTL__CLK_EN_MASK); 852 853 /* disable master interrupt */ 854 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_MASTINT_EN), 0, 855 ~UVD_MASTINT_EN__VCPU_EN_MASK); 856 857 /* enable LMI MC and UMC channels */ 858 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_LMI_CTRL2), 0, 859 ~UVD_LMI_CTRL2__STALL_ARB_UMC_MASK); 860 861 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_SOFT_RESET); 862 tmp &= ~UVD_SOFT_RESET__LMI_SOFT_RESET_MASK; 863 tmp &= ~UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK; 864 WREG32_SOC15(VCN, vcn_inst, regUVD_SOFT_RESET, tmp); 865 866 /* setup regUVD_LMI_CTRL */ 867 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_LMI_CTRL); 868 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_CTRL, 869 tmp | UVD_LMI_CTRL__WRITE_CLEAN_TIMER_EN_MASK | 870 UVD_LMI_CTRL__MASK_MC_URGENT_MASK | 871 UVD_LMI_CTRL__DATA_COHERENCY_EN_MASK | 872 UVD_LMI_CTRL__VCPU_DATA_COHERENCY_EN_MASK); 873 874 /* setup regUVD_MPC_CNTL */ 875 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_MPC_CNTL); 876 tmp &= ~UVD_MPC_CNTL__REPLACEMENT_MODE_MASK; 877 tmp |= 0x2 << UVD_MPC_CNTL__REPLACEMENT_MODE__SHIFT; 878 WREG32_SOC15(VCN, vcn_inst, regUVD_MPC_CNTL, tmp); 879 880 /* setup UVD_MPC_SET_MUXA0 */ 881 WREG32_SOC15(VCN, vcn_inst, regUVD_MPC_SET_MUXA0, 882 ((0x1 << UVD_MPC_SET_MUXA0__VARA_1__SHIFT) | 883 (0x2 << UVD_MPC_SET_MUXA0__VARA_2__SHIFT) | 884 (0x3 << UVD_MPC_SET_MUXA0__VARA_3__SHIFT) | 885 (0x4 << UVD_MPC_SET_MUXA0__VARA_4__SHIFT))); 886 887 /* setup UVD_MPC_SET_MUXB0 */ 888 WREG32_SOC15(VCN, vcn_inst, regUVD_MPC_SET_MUXB0, 889 ((0x1 << UVD_MPC_SET_MUXB0__VARB_1__SHIFT) | 890 (0x2 << UVD_MPC_SET_MUXB0__VARB_2__SHIFT) | 891 (0x3 << UVD_MPC_SET_MUXB0__VARB_3__SHIFT) | 892 (0x4 << UVD_MPC_SET_MUXB0__VARB_4__SHIFT))); 893 894 /* setup UVD_MPC_SET_MUX */ 895 WREG32_SOC15(VCN, vcn_inst, regUVD_MPC_SET_MUX, 896 ((0x0 << UVD_MPC_SET_MUX__SET_0__SHIFT) | 897 (0x1 << UVD_MPC_SET_MUX__SET_1__SHIFT) | 898 (0x2 << UVD_MPC_SET_MUX__SET_2__SHIFT))); 899 900 vcn_v4_0_3_mc_resume(adev, i); 901 902 /* VCN global tiling registers */ 903 WREG32_SOC15(VCN, vcn_inst, regUVD_GFX8_ADDR_CONFIG, 904 adev->gfx.config.gb_addr_config); 905 WREG32_SOC15(VCN, vcn_inst, regUVD_GFX10_ADDR_CONFIG, 906 adev->gfx.config.gb_addr_config); 907 908 /* unblock VCPU register access */ 909 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_RB_ARB_CTRL), 0, 910 ~UVD_RB_ARB_CTRL__VCPU_DIS_MASK); 911 912 /* release VCPU reset to boot */ 913 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_VCPU_CNTL), 0, 914 ~UVD_VCPU_CNTL__BLK_RST_MASK); 915 916 for (j = 0; j < 10; ++j) { 917 uint32_t status; 918 919 for (k = 0; k < 100; ++k) { 920 status = RREG32_SOC15(VCN, vcn_inst, 921 regUVD_STATUS); 922 if (status & 2) 923 break; 924 mdelay(10); 925 } 926 r = 0; 927 if (status & 2) 928 break; 929 930 DRM_DEV_ERROR(adev->dev, 931 "VCN decode not responding, trying to reset the VCPU!!!\n"); 932 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, 933 regUVD_VCPU_CNTL), 934 UVD_VCPU_CNTL__BLK_RST_MASK, 935 ~UVD_VCPU_CNTL__BLK_RST_MASK); 936 mdelay(10); 937 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, 938 regUVD_VCPU_CNTL), 939 0, ~UVD_VCPU_CNTL__BLK_RST_MASK); 940 941 mdelay(10); 942 r = -1; 943 } 944 945 if (r) { 946 DRM_DEV_ERROR(adev->dev, "VCN decode not responding, giving up!!!\n"); 947 return r; 948 } 949 950 /* enable master interrupt */ 951 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_MASTINT_EN), 952 UVD_MASTINT_EN__VCPU_EN_MASK, 953 ~UVD_MASTINT_EN__VCPU_EN_MASK); 954 955 /* clear the busy bit of VCN_STATUS */ 956 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_STATUS), 0, 957 ~(2 << UVD_STATUS__VCPU_REPORT__SHIFT)); 958 959 ring = &adev->vcn.inst[i].ring_enc[0]; 960 fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr; 961 962 /* program the RB_BASE for ring buffer */ 963 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_BASE_LO, 964 lower_32_bits(ring->gpu_addr)); 965 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_BASE_HI, 966 upper_32_bits(ring->gpu_addr)); 967 968 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_SIZE, 969 ring->ring_size / sizeof(uint32_t)); 970 971 /* resetting ring, fw should not check RB ring */ 972 tmp = RREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE); 973 tmp &= ~(VCN_RB_ENABLE__RB_EN_MASK); 974 WREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE, tmp); 975 976 /* Initialize the ring buffer's read and write pointers */ 977 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_RPTR, 0); 978 WREG32_SOC15(VCN, vcn_inst, regUVD_RB_WPTR, 0); 979 980 tmp = RREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE); 981 tmp |= VCN_RB_ENABLE__RB_EN_MASK; 982 WREG32_SOC15(VCN, vcn_inst, regVCN_RB_ENABLE, tmp); 983 984 ring->wptr = RREG32_SOC15(VCN, vcn_inst, regUVD_RB_WPTR); 985 fw_shared->sq.queue_mode &= 986 cpu_to_le32(~(FW_QUEUE_RING_RESET | FW_QUEUE_DPG_HOLD_OFF)); 987 988 } 989 return 0; 990 } 991 992 /** 993 * vcn_v4_0_3_stop_dpg_mode - VCN stop with dpg mode 994 * 995 * @adev: amdgpu_device pointer 996 * @inst_idx: instance number index 997 * 998 * Stop VCN block with dpg mode 999 */ 1000 static int vcn_v4_0_3_stop_dpg_mode(struct amdgpu_device *adev, int inst_idx) 1001 { 1002 uint32_t tmp; 1003 int vcn_inst; 1004 1005 vcn_inst = GET_INST(VCN, inst_idx); 1006 1007 /* Wait for power status to be 1 */ 1008 SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_POWER_STATUS, 1, 1009 UVD_POWER_STATUS__UVD_POWER_STATUS_MASK); 1010 1011 /* wait for read ptr to be equal to write ptr */ 1012 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_RB_WPTR); 1013 SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_RB_RPTR, tmp, 0xFFFFFFFF); 1014 1015 SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_POWER_STATUS, 1, 1016 UVD_POWER_STATUS__UVD_POWER_STATUS_MASK); 1017 1018 /* disable dynamic power gating mode */ 1019 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_POWER_STATUS), 0, 1020 ~UVD_POWER_STATUS__UVD_PG_MODE_MASK); 1021 return 0; 1022 } 1023 1024 /** 1025 * vcn_v4_0_3_stop - VCN stop 1026 * 1027 * @adev: amdgpu_device pointer 1028 * 1029 * Stop VCN block 1030 */ 1031 static int vcn_v4_0_3_stop(struct amdgpu_device *adev) 1032 { 1033 volatile struct amdgpu_vcn4_fw_shared *fw_shared; 1034 int i, r = 0, vcn_inst; 1035 uint32_t tmp; 1036 1037 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 1038 vcn_inst = GET_INST(VCN, i); 1039 1040 fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr; 1041 fw_shared->sq.queue_mode |= FW_QUEUE_DPG_HOLD_OFF; 1042 1043 if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) { 1044 vcn_v4_0_3_stop_dpg_mode(adev, i); 1045 continue; 1046 } 1047 1048 /* wait for vcn idle */ 1049 r = SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_STATUS, 1050 UVD_STATUS__IDLE, 0x7); 1051 if (r) 1052 goto Done; 1053 1054 tmp = UVD_LMI_STATUS__VCPU_LMI_WRITE_CLEAN_MASK | 1055 UVD_LMI_STATUS__READ_CLEAN_MASK | 1056 UVD_LMI_STATUS__WRITE_CLEAN_MASK | 1057 UVD_LMI_STATUS__WRITE_CLEAN_RAW_MASK; 1058 r = SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_LMI_STATUS, tmp, 1059 tmp); 1060 if (r) 1061 goto Done; 1062 1063 /* stall UMC channel */ 1064 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_LMI_CTRL2); 1065 tmp |= UVD_LMI_CTRL2__STALL_ARB_UMC_MASK; 1066 WREG32_SOC15(VCN, vcn_inst, regUVD_LMI_CTRL2, tmp); 1067 tmp = UVD_LMI_STATUS__UMC_READ_CLEAN_RAW_MASK | 1068 UVD_LMI_STATUS__UMC_WRITE_CLEAN_RAW_MASK; 1069 r = SOC15_WAIT_ON_RREG(VCN, vcn_inst, regUVD_LMI_STATUS, tmp, 1070 tmp); 1071 if (r) 1072 goto Done; 1073 1074 /* Unblock VCPU Register access */ 1075 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_RB_ARB_CTRL), 1076 UVD_RB_ARB_CTRL__VCPU_DIS_MASK, 1077 ~UVD_RB_ARB_CTRL__VCPU_DIS_MASK); 1078 1079 /* release VCPU reset to boot */ 1080 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_VCPU_CNTL), 1081 UVD_VCPU_CNTL__BLK_RST_MASK, 1082 ~UVD_VCPU_CNTL__BLK_RST_MASK); 1083 1084 /* disable VCPU clock */ 1085 WREG32_P(SOC15_REG_OFFSET(VCN, vcn_inst, regUVD_VCPU_CNTL), 0, 1086 ~(UVD_VCPU_CNTL__CLK_EN_MASK)); 1087 1088 /* reset LMI UMC/LMI/VCPU */ 1089 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_SOFT_RESET); 1090 tmp |= UVD_SOFT_RESET__LMI_UMC_SOFT_RESET_MASK; 1091 WREG32_SOC15(VCN, vcn_inst, regUVD_SOFT_RESET, tmp); 1092 1093 tmp = RREG32_SOC15(VCN, vcn_inst, regUVD_SOFT_RESET); 1094 tmp |= UVD_SOFT_RESET__LMI_SOFT_RESET_MASK; 1095 WREG32_SOC15(VCN, vcn_inst, regUVD_SOFT_RESET, tmp); 1096 1097 /* clear VCN status */ 1098 WREG32_SOC15(VCN, vcn_inst, regUVD_STATUS, 0); 1099 1100 /* apply HW clock gating */ 1101 vcn_v4_0_3_enable_clock_gating(adev, i); 1102 } 1103 Done: 1104 if (adev->pm.dpm_enabled) 1105 amdgpu_dpm_enable_uvd(adev, false); 1106 1107 return 0; 1108 } 1109 1110 /** 1111 * vcn_v4_0_3_pause_dpg_mode - VCN pause with dpg mode 1112 * 1113 * @adev: amdgpu_device pointer 1114 * @inst_idx: instance number index 1115 * @new_state: pause state 1116 * 1117 * Pause dpg mode for VCN block 1118 */ 1119 static int vcn_v4_0_3_pause_dpg_mode(struct amdgpu_device *adev, int inst_idx, 1120 struct dpg_pause_state *new_state) 1121 { 1122 1123 return 0; 1124 } 1125 1126 /** 1127 * vcn_v4_0_3_unified_ring_get_rptr - get unified read pointer 1128 * 1129 * @ring: amdgpu_ring pointer 1130 * 1131 * Returns the current hardware unified read pointer 1132 */ 1133 static uint64_t vcn_v4_0_3_unified_ring_get_rptr(struct amdgpu_ring *ring) 1134 { 1135 struct amdgpu_device *adev = ring->adev; 1136 1137 if (ring != &adev->vcn.inst[ring->me].ring_enc[0]) 1138 DRM_ERROR("wrong ring id is identified in %s", __func__); 1139 1140 return RREG32_SOC15(VCN, GET_INST(VCN, ring->me), regUVD_RB_RPTR); 1141 } 1142 1143 /** 1144 * vcn_v4_0_3_unified_ring_get_wptr - get unified write pointer 1145 * 1146 * @ring: amdgpu_ring pointer 1147 * 1148 * Returns the current hardware unified write pointer 1149 */ 1150 static uint64_t vcn_v4_0_3_unified_ring_get_wptr(struct amdgpu_ring *ring) 1151 { 1152 struct amdgpu_device *adev = ring->adev; 1153 1154 if (ring != &adev->vcn.inst[ring->me].ring_enc[0]) 1155 DRM_ERROR("wrong ring id is identified in %s", __func__); 1156 1157 if (ring->use_doorbell) 1158 return *ring->wptr_cpu_addr; 1159 else 1160 return RREG32_SOC15(VCN, GET_INST(VCN, ring->me), 1161 regUVD_RB_WPTR); 1162 } 1163 1164 /** 1165 * vcn_v4_0_3_unified_ring_set_wptr - set enc write pointer 1166 * 1167 * @ring: amdgpu_ring pointer 1168 * 1169 * Commits the enc write pointer to the hardware 1170 */ 1171 static void vcn_v4_0_3_unified_ring_set_wptr(struct amdgpu_ring *ring) 1172 { 1173 struct amdgpu_device *adev = ring->adev; 1174 1175 if (ring != &adev->vcn.inst[ring->me].ring_enc[0]) 1176 DRM_ERROR("wrong ring id is identified in %s", __func__); 1177 1178 if (ring->use_doorbell) { 1179 *ring->wptr_cpu_addr = lower_32_bits(ring->wptr); 1180 WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr)); 1181 } else { 1182 WREG32_SOC15(VCN, GET_INST(VCN, ring->me), regUVD_RB_WPTR, 1183 lower_32_bits(ring->wptr)); 1184 } 1185 } 1186 1187 static const struct amdgpu_ring_funcs vcn_v4_0_3_unified_ring_vm_funcs = { 1188 .type = AMDGPU_RING_TYPE_VCN_ENC, 1189 .align_mask = 0x3f, 1190 .nop = VCN_ENC_CMD_NO_OP, 1191 .get_rptr = vcn_v4_0_3_unified_ring_get_rptr, 1192 .get_wptr = vcn_v4_0_3_unified_ring_get_wptr, 1193 .set_wptr = vcn_v4_0_3_unified_ring_set_wptr, 1194 .emit_frame_size = 1195 SOC15_FLUSH_GPU_TLB_NUM_WREG * 3 + 1196 SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 4 + 1197 4 + /* vcn_v2_0_enc_ring_emit_vm_flush */ 1198 5 + 5 + /* vcn_v2_0_enc_ring_emit_fence x2 vm fence */ 1199 1, /* vcn_v2_0_enc_ring_insert_end */ 1200 .emit_ib_size = 5, /* vcn_v2_0_enc_ring_emit_ib */ 1201 .emit_ib = vcn_v2_0_enc_ring_emit_ib, 1202 .emit_fence = vcn_v2_0_enc_ring_emit_fence, 1203 .emit_vm_flush = vcn_v2_0_enc_ring_emit_vm_flush, 1204 .test_ring = amdgpu_vcn_enc_ring_test_ring, 1205 .test_ib = amdgpu_vcn_unified_ring_test_ib, 1206 .insert_nop = amdgpu_ring_insert_nop, 1207 .insert_end = vcn_v2_0_enc_ring_insert_end, 1208 .pad_ib = amdgpu_ring_generic_pad_ib, 1209 .begin_use = amdgpu_vcn_ring_begin_use, 1210 .end_use = amdgpu_vcn_ring_end_use, 1211 .emit_wreg = vcn_v2_0_enc_ring_emit_wreg, 1212 .emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait, 1213 .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, 1214 }; 1215 1216 /** 1217 * vcn_v4_0_3_set_unified_ring_funcs - set unified ring functions 1218 * 1219 * @adev: amdgpu_device pointer 1220 * 1221 * Set unified ring functions 1222 */ 1223 static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device *adev) 1224 { 1225 int i, vcn_inst; 1226 1227 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 1228 adev->vcn.inst[i].ring_enc[0].funcs = &vcn_v4_0_3_unified_ring_vm_funcs; 1229 adev->vcn.inst[i].ring_enc[0].me = i; 1230 vcn_inst = GET_INST(VCN, i); 1231 adev->vcn.inst[i].aid_id = 1232 vcn_inst / adev->vcn.num_inst_per_aid; 1233 } 1234 DRM_DEV_INFO(adev->dev, "VCN decode is enabled in VM mode\n"); 1235 } 1236 1237 /** 1238 * vcn_v4_0_3_is_idle - check VCN block is idle 1239 * 1240 * @handle: amdgpu_device pointer 1241 * 1242 * Check whether VCN block is idle 1243 */ 1244 static bool vcn_v4_0_3_is_idle(void *handle) 1245 { 1246 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1247 int i, ret = 1; 1248 1249 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 1250 ret &= (RREG32_SOC15(VCN, GET_INST(VCN, i), regUVD_STATUS) == 1251 UVD_STATUS__IDLE); 1252 } 1253 1254 return ret; 1255 } 1256 1257 /** 1258 * vcn_v4_0_3_wait_for_idle - wait for VCN block idle 1259 * 1260 * @handle: amdgpu_device pointer 1261 * 1262 * Wait for VCN block idle 1263 */ 1264 static int vcn_v4_0_3_wait_for_idle(void *handle) 1265 { 1266 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1267 int i, ret = 0; 1268 1269 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 1270 ret = SOC15_WAIT_ON_RREG(VCN, GET_INST(VCN, i), regUVD_STATUS, 1271 UVD_STATUS__IDLE, UVD_STATUS__IDLE); 1272 if (ret) 1273 return ret; 1274 } 1275 1276 return ret; 1277 } 1278 1279 /* vcn_v4_0_3_set_clockgating_state - set VCN block clockgating state 1280 * 1281 * @handle: amdgpu_device pointer 1282 * @state: clock gating state 1283 * 1284 * Set VCN block clockgating state 1285 */ 1286 static int vcn_v4_0_3_set_clockgating_state(void *handle, 1287 enum amd_clockgating_state state) 1288 { 1289 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1290 bool enable = (state == AMD_CG_STATE_GATE) ? true : false; 1291 int i; 1292 1293 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 1294 if (enable) { 1295 if (RREG32_SOC15(VCN, GET_INST(VCN, i), 1296 regUVD_STATUS) != UVD_STATUS__IDLE) 1297 return -EBUSY; 1298 vcn_v4_0_3_enable_clock_gating(adev, i); 1299 } else { 1300 vcn_v4_0_3_disable_clock_gating(adev, i); 1301 } 1302 } 1303 return 0; 1304 } 1305 1306 /** 1307 * vcn_v4_0_3_set_powergating_state - set VCN block powergating state 1308 * 1309 * @handle: amdgpu_device pointer 1310 * @state: power gating state 1311 * 1312 * Set VCN block powergating state 1313 */ 1314 static int vcn_v4_0_3_set_powergating_state(void *handle, 1315 enum amd_powergating_state state) 1316 { 1317 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1318 int ret; 1319 1320 if (state == adev->vcn.cur_state) 1321 return 0; 1322 1323 if (state == AMD_PG_STATE_GATE) 1324 ret = vcn_v4_0_3_stop(adev); 1325 else 1326 ret = vcn_v4_0_3_start(adev); 1327 1328 if (!ret) 1329 adev->vcn.cur_state = state; 1330 1331 return ret; 1332 } 1333 1334 /** 1335 * vcn_v4_0_3_set_interrupt_state - set VCN block interrupt state 1336 * 1337 * @adev: amdgpu_device pointer 1338 * @source: interrupt sources 1339 * @type: interrupt types 1340 * @state: interrupt states 1341 * 1342 * Set VCN block interrupt state 1343 */ 1344 static int vcn_v4_0_3_set_interrupt_state(struct amdgpu_device *adev, 1345 struct amdgpu_irq_src *source, 1346 unsigned int type, 1347 enum amdgpu_interrupt_state state) 1348 { 1349 return 0; 1350 } 1351 1352 /** 1353 * vcn_v4_0_3_process_interrupt - process VCN block interrupt 1354 * 1355 * @adev: amdgpu_device pointer 1356 * @source: interrupt sources 1357 * @entry: interrupt entry from clients and sources 1358 * 1359 * Process VCN block interrupt 1360 */ 1361 static int vcn_v4_0_3_process_interrupt(struct amdgpu_device *adev, 1362 struct amdgpu_irq_src *source, 1363 struct amdgpu_iv_entry *entry) 1364 { 1365 uint32_t i, inst; 1366 1367 i = node_id_to_phys_map[entry->node_id]; 1368 1369 DRM_DEV_DEBUG(adev->dev, "IH: VCN TRAP\n"); 1370 1371 for (inst = 0; inst < adev->vcn.num_vcn_inst; ++inst) 1372 if (adev->vcn.inst[inst].aid_id == i) 1373 break; 1374 1375 if (inst >= adev->vcn.num_vcn_inst) { 1376 dev_WARN_ONCE(adev->dev, 1, 1377 "Interrupt received for unknown VCN instance %d", 1378 entry->node_id); 1379 return 0; 1380 } 1381 1382 switch (entry->src_id) { 1383 case VCN_4_0__SRCID__UVD_ENC_GENERAL_PURPOSE: 1384 amdgpu_fence_process(&adev->vcn.inst[inst].ring_enc[0]); 1385 break; 1386 default: 1387 DRM_DEV_ERROR(adev->dev, "Unhandled interrupt: %d %d\n", 1388 entry->src_id, entry->src_data[0]); 1389 break; 1390 } 1391 1392 return 0; 1393 } 1394 1395 static const struct amdgpu_irq_src_funcs vcn_v4_0_3_irq_funcs = { 1396 .set = vcn_v4_0_3_set_interrupt_state, 1397 .process = vcn_v4_0_3_process_interrupt, 1398 }; 1399 1400 /** 1401 * vcn_v4_0_3_set_irq_funcs - set VCN block interrupt irq functions 1402 * 1403 * @adev: amdgpu_device pointer 1404 * 1405 * Set VCN block interrupt irq functions 1406 */ 1407 static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device *adev) 1408 { 1409 int i; 1410 1411 for (i = 0; i < adev->vcn.num_vcn_inst; ++i) { 1412 adev->vcn.inst->irq.num_types++; 1413 } 1414 adev->vcn.inst->irq.funcs = &vcn_v4_0_3_irq_funcs; 1415 } 1416 1417 static const struct amd_ip_funcs vcn_v4_0_3_ip_funcs = { 1418 .name = "vcn_v4_0_3", 1419 .early_init = vcn_v4_0_3_early_init, 1420 .late_init = NULL, 1421 .sw_init = vcn_v4_0_3_sw_init, 1422 .sw_fini = vcn_v4_0_3_sw_fini, 1423 .hw_init = vcn_v4_0_3_hw_init, 1424 .hw_fini = vcn_v4_0_3_hw_fini, 1425 .suspend = vcn_v4_0_3_suspend, 1426 .resume = vcn_v4_0_3_resume, 1427 .is_idle = vcn_v4_0_3_is_idle, 1428 .wait_for_idle = vcn_v4_0_3_wait_for_idle, 1429 .check_soft_reset = NULL, 1430 .pre_soft_reset = NULL, 1431 .soft_reset = NULL, 1432 .post_soft_reset = NULL, 1433 .set_clockgating_state = vcn_v4_0_3_set_clockgating_state, 1434 .set_powergating_state = vcn_v4_0_3_set_powergating_state, 1435 }; 1436 1437 const struct amdgpu_ip_block_version vcn_v4_0_3_ip_block = { 1438 .type = AMD_IP_BLOCK_TYPE_VCN, 1439 .major = 4, 1440 .minor = 0, 1441 .rev = 3, 1442 .funcs = &vcn_v4_0_3_ip_funcs, 1443 }; 1444 1445 static const struct amdgpu_ras_err_status_reg_entry vcn_v4_0_3_ue_reg_list[] = { 1446 {AMDGPU_RAS_REG_ENTRY(VCN, 0, regVCN_UE_ERR_STATUS_LO_VIDD, regVCN_UE_ERR_STATUS_HI_VIDD), 1447 1, (AMDGPU_RAS_ERR_INFO_VALID | AMDGPU_RAS_ERR_STATUS_VALID), "VIDD"}, 1448 {AMDGPU_RAS_REG_ENTRY(VCN, 0, regVCN_UE_ERR_STATUS_LO_VIDV, regVCN_UE_ERR_STATUS_HI_VIDV), 1449 1, (AMDGPU_RAS_ERR_INFO_VALID | AMDGPU_RAS_ERR_STATUS_VALID), "VIDV"}, 1450 }; 1451 1452 static void vcn_v4_0_3_inst_query_ras_error_count(struct amdgpu_device *adev, 1453 uint32_t vcn_inst, 1454 void *ras_err_status) 1455 { 1456 struct ras_err_data *err_data = (struct ras_err_data *)ras_err_status; 1457 1458 /* vcn v4_0_3 only support query uncorrectable errors */ 1459 amdgpu_ras_inst_query_ras_error_count(adev, 1460 vcn_v4_0_3_ue_reg_list, 1461 ARRAY_SIZE(vcn_v4_0_3_ue_reg_list), 1462 NULL, 0, GET_INST(VCN, vcn_inst), 1463 AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE, 1464 &err_data->ue_count); 1465 } 1466 1467 static void vcn_v4_0_3_query_ras_error_count(struct amdgpu_device *adev, 1468 void *ras_err_status) 1469 { 1470 uint32_t i; 1471 1472 if (!amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__VCN)) { 1473 dev_warn(adev->dev, "VCN RAS is not supported\n"); 1474 return; 1475 } 1476 1477 for (i = 0; i < adev->vcn.num_vcn_inst; i++) 1478 vcn_v4_0_3_inst_query_ras_error_count(adev, i, ras_err_status); 1479 } 1480 1481 static void vcn_v4_0_3_inst_reset_ras_error_count(struct amdgpu_device *adev, 1482 uint32_t vcn_inst) 1483 { 1484 amdgpu_ras_inst_reset_ras_error_count(adev, 1485 vcn_v4_0_3_ue_reg_list, 1486 ARRAY_SIZE(vcn_v4_0_3_ue_reg_list), 1487 GET_INST(VCN, vcn_inst)); 1488 } 1489 1490 static void vcn_v4_0_3_reset_ras_error_count(struct amdgpu_device *adev) 1491 { 1492 uint32_t i; 1493 1494 if (!amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__VCN)) { 1495 dev_warn(adev->dev, "VCN RAS is not supported\n"); 1496 return; 1497 } 1498 1499 for (i = 0; i < adev->vcn.num_vcn_inst; i++) 1500 vcn_v4_0_3_inst_reset_ras_error_count(adev, i); 1501 } 1502 1503 static const struct amdgpu_ras_block_hw_ops vcn_v4_0_3_ras_hw_ops = { 1504 .query_ras_error_count = vcn_v4_0_3_query_ras_error_count, 1505 .reset_ras_error_count = vcn_v4_0_3_reset_ras_error_count, 1506 }; 1507 1508 static struct amdgpu_vcn_ras vcn_v4_0_3_ras = { 1509 .ras_block = { 1510 .hw_ops = &vcn_v4_0_3_ras_hw_ops, 1511 }, 1512 }; 1513 1514 static void vcn_v4_0_3_set_ras_funcs(struct amdgpu_device *adev) 1515 { 1516 adev->vcn.ras = &vcn_v4_0_3_ras; 1517 } 1518 1519 static void vcn_v4_0_3_enable_ras(struct amdgpu_device *adev, 1520 int inst_idx, bool indirect) 1521 { 1522 uint32_t tmp; 1523 1524 if (!amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__VCN)) 1525 return; 1526 1527 tmp = VCN_RAS_CNTL__VCPU_VCODEC_REARM_MASK | 1528 VCN_RAS_CNTL__VCPU_VCODEC_IH_EN_MASK | 1529 VCN_RAS_CNTL__VCPU_VCODEC_PMI_EN_MASK | 1530 VCN_RAS_CNTL__VCPU_VCODEC_STALL_EN_MASK; 1531 WREG32_SOC15_DPG_MODE(inst_idx, 1532 SOC15_DPG_MODE_OFFSET(VCN, 0, regVCN_RAS_CNTL), 1533 tmp, 0, indirect); 1534 1535 tmp = UVD_SYS_INT_EN__RASCNTL_VCPU_VCODEC_EN_MASK; 1536 WREG32_SOC15_DPG_MODE(inst_idx, 1537 SOC15_DPG_MODE_OFFSET(VCN, 0, regUVD_SYS_INT_EN), 1538 tmp, 0, indirect); 1539 } 1540