1 /* 2 * Copyright 2016 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/module.h> 25 26 #ifdef CONFIG_X86 27 #include <asm/hypervisor.h> 28 #endif 29 30 #include <drm/drm_drv.h> 31 #include <xen/xen.h> 32 33 #include "amdgpu.h" 34 #include "amdgpu_ras.h" 35 #include "amdgpu_reset.h" 36 #include "amdgpu_dpm.h" 37 #include "vi.h" 38 #include "soc15.h" 39 #include "nv.h" 40 41 #define POPULATE_UCODE_INFO(vf2pf_info, ucode, ver) \ 42 do { \ 43 vf2pf_info->ucode_info[ucode].id = ucode; \ 44 vf2pf_info->ucode_info[ucode].version = ver; \ 45 } while (0) 46 47 bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev) 48 { 49 /* By now all MMIO pages except mailbox are blocked */ 50 /* if blocking is enabled in hypervisor. Choose the */ 51 /* SCRATCH_REG0 to test. */ 52 return RREG32_NO_KIQ(0xc040) == 0xffffffff; 53 } 54 55 void amdgpu_virt_init_setting(struct amdgpu_device *adev) 56 { 57 struct drm_device *ddev = adev_to_drm(adev); 58 59 /* enable virtual display */ 60 if (adev->asic_type != CHIP_ALDEBARAN && 61 adev->asic_type != CHIP_ARCTURUS && 62 ((adev->pdev->class >> 8) != PCI_CLASS_ACCELERATOR_PROCESSING)) { 63 if (adev->mode_info.num_crtc == 0) 64 adev->mode_info.num_crtc = 1; 65 adev->enable_virtual_display = true; 66 } 67 ddev->driver_features &= ~DRIVER_ATOMIC; 68 adev->cg_flags = 0; 69 adev->pg_flags = 0; 70 71 /* Reduce kcq number to 2 to reduce latency */ 72 if (amdgpu_num_kcq == -1) 73 amdgpu_num_kcq = 2; 74 } 75 76 /** 77 * amdgpu_virt_request_full_gpu() - request full gpu access 78 * @adev: amdgpu device. 79 * @init: is driver init time. 80 * When start to init/fini driver, first need to request full gpu access. 81 * Return: Zero if request success, otherwise will return error. 82 */ 83 int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init) 84 { 85 struct amdgpu_virt *virt = &adev->virt; 86 int r; 87 88 if (virt->ops && virt->ops->req_full_gpu) { 89 r = virt->ops->req_full_gpu(adev, init); 90 if (r) { 91 adev->no_hw_access = true; 92 return r; 93 } 94 95 adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME; 96 } 97 98 return 0; 99 } 100 101 /** 102 * amdgpu_virt_release_full_gpu() - release full gpu access 103 * @adev: amdgpu device. 104 * @init: is driver init time. 105 * When finishing driver init/fini, need to release full gpu access. 106 * Return: Zero if release success, otherwise will returen error. 107 */ 108 int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init) 109 { 110 struct amdgpu_virt *virt = &adev->virt; 111 int r; 112 113 if (virt->ops && virt->ops->rel_full_gpu) { 114 r = virt->ops->rel_full_gpu(adev, init); 115 if (r) 116 return r; 117 118 adev->virt.caps |= AMDGPU_SRIOV_CAPS_RUNTIME; 119 } 120 return 0; 121 } 122 123 /** 124 * amdgpu_virt_reset_gpu() - reset gpu 125 * @adev: amdgpu device. 126 * Send reset command to GPU hypervisor to reset GPU that VM is using 127 * Return: Zero if reset success, otherwise will return error. 128 */ 129 int amdgpu_virt_reset_gpu(struct amdgpu_device *adev) 130 { 131 struct amdgpu_virt *virt = &adev->virt; 132 int r; 133 134 if (virt->ops && virt->ops->reset_gpu) { 135 r = virt->ops->reset_gpu(adev); 136 if (r) 137 return r; 138 139 adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME; 140 } 141 142 return 0; 143 } 144 145 void amdgpu_virt_request_init_data(struct amdgpu_device *adev) 146 { 147 struct amdgpu_virt *virt = &adev->virt; 148 149 if (virt->ops && virt->ops->req_init_data) 150 virt->ops->req_init_data(adev); 151 152 if (adev->virt.req_init_data_ver > 0) 153 DRM_INFO("host supports REQ_INIT_DATA handshake\n"); 154 else 155 DRM_WARN("host doesn't support REQ_INIT_DATA handshake\n"); 156 } 157 158 /** 159 * amdgpu_virt_ready_to_reset() - send ready to reset to host 160 * @adev: amdgpu device. 161 * Send ready to reset message to GPU hypervisor to signal we have stopped GPU 162 * activity and is ready for host FLR 163 */ 164 void amdgpu_virt_ready_to_reset(struct amdgpu_device *adev) 165 { 166 struct amdgpu_virt *virt = &adev->virt; 167 168 if (virt->ops && virt->ops->reset_gpu) 169 virt->ops->ready_to_reset(adev); 170 } 171 172 /** 173 * amdgpu_virt_wait_reset() - wait for reset gpu completed 174 * @adev: amdgpu device. 175 * Wait for GPU reset completed. 176 * Return: Zero if reset success, otherwise will return error. 177 */ 178 int amdgpu_virt_wait_reset(struct amdgpu_device *adev) 179 { 180 struct amdgpu_virt *virt = &adev->virt; 181 182 if (!virt->ops || !virt->ops->wait_reset) 183 return -EINVAL; 184 185 return virt->ops->wait_reset(adev); 186 } 187 188 /** 189 * amdgpu_virt_alloc_mm_table() - alloc memory for mm table 190 * @adev: amdgpu device. 191 * MM table is used by UVD and VCE for its initialization 192 * Return: Zero if allocate success. 193 */ 194 int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev) 195 { 196 int r; 197 198 if (!amdgpu_sriov_vf(adev) || adev->virt.mm_table.gpu_addr) 199 return 0; 200 201 r = amdgpu_bo_create_kernel(adev, PAGE_SIZE, PAGE_SIZE, 202 AMDGPU_GEM_DOMAIN_VRAM | 203 AMDGPU_GEM_DOMAIN_GTT, 204 &adev->virt.mm_table.bo, 205 &adev->virt.mm_table.gpu_addr, 206 (void *)&adev->virt.mm_table.cpu_addr); 207 if (r) { 208 DRM_ERROR("failed to alloc mm table and error = %d.\n", r); 209 return r; 210 } 211 212 memset((void *)adev->virt.mm_table.cpu_addr, 0, PAGE_SIZE); 213 DRM_INFO("MM table gpu addr = 0x%llx, cpu addr = %p.\n", 214 adev->virt.mm_table.gpu_addr, 215 adev->virt.mm_table.cpu_addr); 216 return 0; 217 } 218 219 /** 220 * amdgpu_virt_free_mm_table() - free mm table memory 221 * @adev: amdgpu device. 222 * Free MM table memory 223 */ 224 void amdgpu_virt_free_mm_table(struct amdgpu_device *adev) 225 { 226 if (!amdgpu_sriov_vf(adev) || !adev->virt.mm_table.gpu_addr) 227 return; 228 229 amdgpu_bo_free_kernel(&adev->virt.mm_table.bo, 230 &adev->virt.mm_table.gpu_addr, 231 (void *)&adev->virt.mm_table.cpu_addr); 232 adev->virt.mm_table.gpu_addr = 0; 233 } 234 235 /** 236 * amdgpu_virt_rcvd_ras_interrupt() - receive ras interrupt 237 * @adev: amdgpu device. 238 * Check whether host sent RAS error message 239 * Return: true if found, otherwise false 240 */ 241 bool amdgpu_virt_rcvd_ras_interrupt(struct amdgpu_device *adev) 242 { 243 struct amdgpu_virt *virt = &adev->virt; 244 245 if (!virt->ops || !virt->ops->rcvd_ras_intr) 246 return false; 247 248 return virt->ops->rcvd_ras_intr(adev); 249 } 250 251 252 unsigned int amd_sriov_msg_checksum(void *obj, 253 unsigned long obj_size, 254 unsigned int key, 255 unsigned int checksum) 256 { 257 unsigned int ret = key; 258 unsigned long i = 0; 259 unsigned char *pos; 260 261 pos = (char *)obj; 262 /* calculate checksum */ 263 for (i = 0; i < obj_size; ++i) 264 ret += *(pos + i); 265 /* minus the checksum itself */ 266 pos = (char *)&checksum; 267 for (i = 0; i < sizeof(checksum); ++i) 268 ret -= *(pos + i); 269 return ret; 270 } 271 272 static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev) 273 { 274 struct amdgpu_virt *virt = &adev->virt; 275 struct amdgpu_virt_ras_err_handler_data **data = &virt->virt_eh_data; 276 /* GPU will be marked bad on host if bp count more then 10, 277 * so alloc 512 is enough. 278 */ 279 unsigned int align_space = 512; 280 void *bps = NULL; 281 struct amdgpu_bo **bps_bo = NULL; 282 283 *data = kmalloc(sizeof(struct amdgpu_virt_ras_err_handler_data), GFP_KERNEL); 284 if (!*data) 285 goto data_failure; 286 287 bps = kmalloc_array(align_space, sizeof(*(*data)->bps), GFP_KERNEL); 288 if (!bps) 289 goto bps_failure; 290 291 bps_bo = kmalloc_array(align_space, sizeof(*(*data)->bps_bo), GFP_KERNEL); 292 if (!bps_bo) 293 goto bps_bo_failure; 294 295 (*data)->bps = bps; 296 (*data)->bps_bo = bps_bo; 297 (*data)->count = 0; 298 (*data)->last_reserved = 0; 299 300 virt->ras_init_done = true; 301 302 return 0; 303 304 bps_bo_failure: 305 kfree(bps); 306 bps_failure: 307 kfree(*data); 308 data_failure: 309 return -ENOMEM; 310 } 311 312 static void amdgpu_virt_ras_release_bp(struct amdgpu_device *adev) 313 { 314 struct amdgpu_virt *virt = &adev->virt; 315 struct amdgpu_virt_ras_err_handler_data *data = virt->virt_eh_data; 316 struct amdgpu_bo *bo; 317 int i; 318 319 if (!data) 320 return; 321 322 for (i = data->last_reserved - 1; i >= 0; i--) { 323 bo = data->bps_bo[i]; 324 if (bo) { 325 amdgpu_bo_free_kernel(&bo, NULL, NULL); 326 data->bps_bo[i] = bo; 327 } 328 data->last_reserved = i; 329 } 330 } 331 332 void amdgpu_virt_release_ras_err_handler_data(struct amdgpu_device *adev) 333 { 334 struct amdgpu_virt *virt = &adev->virt; 335 struct amdgpu_virt_ras_err_handler_data *data = virt->virt_eh_data; 336 337 virt->ras_init_done = false; 338 339 if (!data) 340 return; 341 342 amdgpu_virt_ras_release_bp(adev); 343 344 kfree(data->bps); 345 kfree(data->bps_bo); 346 kfree(data); 347 virt->virt_eh_data = NULL; 348 } 349 350 static void amdgpu_virt_ras_add_bps(struct amdgpu_device *adev, 351 struct eeprom_table_record *bps, int pages) 352 { 353 struct amdgpu_virt *virt = &adev->virt; 354 struct amdgpu_virt_ras_err_handler_data *data = virt->virt_eh_data; 355 356 if (!data) 357 return; 358 359 memcpy(&data->bps[data->count], bps, pages * sizeof(*data->bps)); 360 data->count += pages; 361 } 362 363 static void amdgpu_virt_ras_reserve_bps(struct amdgpu_device *adev) 364 { 365 struct amdgpu_virt *virt = &adev->virt; 366 struct amdgpu_virt_ras_err_handler_data *data = virt->virt_eh_data; 367 struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr; 368 struct ttm_resource_manager *man = &mgr->manager; 369 struct amdgpu_bo *bo = NULL; 370 uint64_t bp; 371 int i; 372 373 if (!data) 374 return; 375 376 for (i = data->last_reserved; i < data->count; i++) { 377 bp = data->bps[i].retired_page; 378 379 /* There are two cases of reserve error should be ignored: 380 * 1) a ras bad page has been allocated (used by someone); 381 * 2) a ras bad page has been reserved (duplicate error injection 382 * for one page); 383 */ 384 if (ttm_resource_manager_used(man)) { 385 amdgpu_vram_mgr_reserve_range(&adev->mman.vram_mgr, 386 bp << AMDGPU_GPU_PAGE_SHIFT, 387 AMDGPU_GPU_PAGE_SIZE); 388 data->bps_bo[i] = NULL; 389 } else { 390 if (amdgpu_bo_create_kernel_at(adev, bp << AMDGPU_GPU_PAGE_SHIFT, 391 AMDGPU_GPU_PAGE_SIZE, 392 &bo, NULL)) 393 DRM_DEBUG("RAS WARN: reserve vram for retired page %llx fail\n", bp); 394 data->bps_bo[i] = bo; 395 } 396 data->last_reserved = i + 1; 397 bo = NULL; 398 } 399 } 400 401 static bool amdgpu_virt_ras_check_bad_page(struct amdgpu_device *adev, 402 uint64_t retired_page) 403 { 404 struct amdgpu_virt *virt = &adev->virt; 405 struct amdgpu_virt_ras_err_handler_data *data = virt->virt_eh_data; 406 int i; 407 408 if (!data) 409 return true; 410 411 for (i = 0; i < data->count; i++) 412 if (retired_page == data->bps[i].retired_page) 413 return true; 414 415 return false; 416 } 417 418 static void amdgpu_virt_add_bad_page(struct amdgpu_device *adev, 419 uint64_t bp_block_offset, uint32_t bp_block_size) 420 { 421 struct eeprom_table_record bp; 422 uint64_t retired_page; 423 uint32_t bp_idx, bp_cnt; 424 void *vram_usage_va = NULL; 425 426 if (adev->mman.fw_vram_usage_va) 427 vram_usage_va = adev->mman.fw_vram_usage_va; 428 else 429 vram_usage_va = adev->mman.drv_vram_usage_va; 430 431 memset(&bp, 0, sizeof(bp)); 432 433 if (bp_block_size) { 434 bp_cnt = bp_block_size / sizeof(uint64_t); 435 for (bp_idx = 0; bp_idx < bp_cnt; bp_idx++) { 436 retired_page = *(uint64_t *)(vram_usage_va + 437 bp_block_offset + bp_idx * sizeof(uint64_t)); 438 bp.retired_page = retired_page; 439 440 if (amdgpu_virt_ras_check_bad_page(adev, retired_page)) 441 continue; 442 443 amdgpu_virt_ras_add_bps(adev, &bp, 1); 444 445 amdgpu_virt_ras_reserve_bps(adev); 446 } 447 } 448 } 449 450 static int amdgpu_virt_read_pf2vf_data(struct amdgpu_device *adev) 451 { 452 struct amd_sriov_msg_pf2vf_info_header *pf2vf_info = adev->virt.fw_reserve.p_pf2vf; 453 uint32_t checksum; 454 uint32_t checkval; 455 456 uint32_t i; 457 uint32_t tmp; 458 459 if (adev->virt.fw_reserve.p_pf2vf == NULL) 460 return -EINVAL; 461 462 if (pf2vf_info->size > 1024) { 463 dev_err(adev->dev, "invalid pf2vf message size: 0x%x\n", pf2vf_info->size); 464 return -EINVAL; 465 } 466 467 switch (pf2vf_info->version) { 468 case 1: 469 checksum = ((struct amdgim_pf2vf_info_v1 *)pf2vf_info)->checksum; 470 checkval = amd_sriov_msg_checksum( 471 adev->virt.fw_reserve.p_pf2vf, pf2vf_info->size, 472 adev->virt.fw_reserve.checksum_key, checksum); 473 if (checksum != checkval) { 474 dev_err(adev->dev, 475 "invalid pf2vf message: header checksum=0x%x calculated checksum=0x%x\n", 476 checksum, checkval); 477 return -EINVAL; 478 } 479 480 adev->virt.gim_feature = 481 ((struct amdgim_pf2vf_info_v1 *)pf2vf_info)->feature_flags; 482 break; 483 case 2: 484 /* TODO: missing key, need to add it later */ 485 checksum = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->checksum; 486 checkval = amd_sriov_msg_checksum( 487 adev->virt.fw_reserve.p_pf2vf, pf2vf_info->size, 488 0, checksum); 489 if (checksum != checkval) { 490 dev_err(adev->dev, 491 "invalid pf2vf message: header checksum=0x%x calculated checksum=0x%x\n", 492 checksum, checkval); 493 return -EINVAL; 494 } 495 496 adev->virt.vf2pf_update_interval_ms = 497 ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->vf2pf_update_interval_ms; 498 adev->virt.gim_feature = 499 ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->feature_flags.all; 500 adev->virt.reg_access = 501 ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->reg_access_flags.all; 502 503 adev->virt.decode_max_dimension_pixels = 0; 504 adev->virt.decode_max_frame_pixels = 0; 505 adev->virt.encode_max_dimension_pixels = 0; 506 adev->virt.encode_max_frame_pixels = 0; 507 adev->virt.is_mm_bw_enabled = false; 508 for (i = 0; i < AMD_SRIOV_MSG_RESERVE_VCN_INST; i++) { 509 tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].decode_max_dimension_pixels; 510 adev->virt.decode_max_dimension_pixels = max(tmp, adev->virt.decode_max_dimension_pixels); 511 512 tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].decode_max_frame_pixels; 513 adev->virt.decode_max_frame_pixels = max(tmp, adev->virt.decode_max_frame_pixels); 514 515 tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].encode_max_dimension_pixels; 516 adev->virt.encode_max_dimension_pixels = max(tmp, adev->virt.encode_max_dimension_pixels); 517 518 tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].encode_max_frame_pixels; 519 adev->virt.encode_max_frame_pixels = max(tmp, adev->virt.encode_max_frame_pixels); 520 } 521 if ((adev->virt.decode_max_dimension_pixels > 0) || (adev->virt.encode_max_dimension_pixels > 0)) 522 adev->virt.is_mm_bw_enabled = true; 523 524 adev->unique_id = 525 ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->uuid; 526 adev->virt.ras_en_caps.all = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->ras_en_caps.all; 527 break; 528 default: 529 dev_err(adev->dev, "invalid pf2vf version: 0x%x\n", pf2vf_info->version); 530 return -EINVAL; 531 } 532 533 /* correct too large or too little interval value */ 534 if (adev->virt.vf2pf_update_interval_ms < 200 || adev->virt.vf2pf_update_interval_ms > 10000) 535 adev->virt.vf2pf_update_interval_ms = 2000; 536 537 return 0; 538 } 539 540 static void amdgpu_virt_populate_vf2pf_ucode_info(struct amdgpu_device *adev) 541 { 542 struct amd_sriov_msg_vf2pf_info *vf2pf_info; 543 vf2pf_info = (struct amd_sriov_msg_vf2pf_info *) adev->virt.fw_reserve.p_vf2pf; 544 545 if (adev->virt.fw_reserve.p_vf2pf == NULL) 546 return; 547 548 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_VCE, adev->vce.fw_version); 549 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_UVD, adev->uvd.fw_version); 550 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_MC, adev->gmc.fw_version); 551 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_ME, adev->gfx.me_fw_version); 552 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_PFP, adev->gfx.pfp_fw_version); 553 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_CE, adev->gfx.ce_fw_version); 554 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_RLC, adev->gfx.rlc_fw_version); 555 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_RLC_SRLC, adev->gfx.rlc_srlc_fw_version); 556 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_RLC_SRLG, adev->gfx.rlc_srlg_fw_version); 557 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_RLC_SRLS, adev->gfx.rlc_srls_fw_version); 558 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_MEC, adev->gfx.mec_fw_version); 559 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_MEC2, adev->gfx.mec2_fw_version); 560 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_SOS, adev->psp.sos.fw_version); 561 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_ASD, 562 adev->psp.asd_context.bin_desc.fw_version); 563 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_TA_RAS, 564 adev->psp.ras_context.context.bin_desc.fw_version); 565 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_TA_XGMI, 566 adev->psp.xgmi_context.context.bin_desc.fw_version); 567 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_SMC, adev->pm.fw_version); 568 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_SDMA, adev->sdma.instance[0].fw_version); 569 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_SDMA2, adev->sdma.instance[1].fw_version); 570 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_VCN, adev->vcn.fw_version); 571 POPULATE_UCODE_INFO(vf2pf_info, AMD_SRIOV_UCODE_ID_DMCU, adev->dm.dmcu_fw_version); 572 } 573 574 static int amdgpu_virt_write_vf2pf_data(struct amdgpu_device *adev) 575 { 576 struct amd_sriov_msg_vf2pf_info *vf2pf_info; 577 578 vf2pf_info = (struct amd_sriov_msg_vf2pf_info *) adev->virt.fw_reserve.p_vf2pf; 579 580 if (adev->virt.fw_reserve.p_vf2pf == NULL) 581 return -EINVAL; 582 583 memset(vf2pf_info, 0, sizeof(struct amd_sriov_msg_vf2pf_info)); 584 585 vf2pf_info->header.size = sizeof(struct amd_sriov_msg_vf2pf_info); 586 vf2pf_info->header.version = AMD_SRIOV_MSG_FW_VRAM_VF2PF_VER; 587 588 #ifdef MODULE 589 if (THIS_MODULE->version != NULL) 590 strcpy(vf2pf_info->driver_version, THIS_MODULE->version); 591 else 592 #endif 593 strcpy(vf2pf_info->driver_version, "N/A"); 594 595 vf2pf_info->pf2vf_version_required = 0; // no requirement, guest understands all 596 vf2pf_info->driver_cert = 0; 597 vf2pf_info->os_info.all = 0; 598 599 vf2pf_info->fb_usage = 600 ttm_resource_manager_usage(&adev->mman.vram_mgr.manager) >> 20; 601 vf2pf_info->fb_vis_usage = 602 amdgpu_vram_mgr_vis_usage(&adev->mman.vram_mgr) >> 20; 603 vf2pf_info->fb_size = adev->gmc.real_vram_size >> 20; 604 vf2pf_info->fb_vis_size = adev->gmc.visible_vram_size >> 20; 605 606 amdgpu_virt_populate_vf2pf_ucode_info(adev); 607 608 /* TODO: read dynamic info */ 609 vf2pf_info->gfx_usage = 0; 610 vf2pf_info->compute_usage = 0; 611 vf2pf_info->encode_usage = 0; 612 vf2pf_info->decode_usage = 0; 613 614 vf2pf_info->dummy_page_addr = (uint64_t)adev->dummy_page_addr; 615 vf2pf_info->mes_info_addr = (uint64_t)adev->mes.resource_1_gpu_addr; 616 617 if (adev->mes.resource_1) { 618 vf2pf_info->mes_info_size = adev->mes.resource_1->tbo.base.size; 619 } 620 vf2pf_info->checksum = 621 amd_sriov_msg_checksum( 622 vf2pf_info, sizeof(*vf2pf_info), 0, 0); 623 624 return 0; 625 } 626 627 static void amdgpu_virt_update_vf2pf_work_item(struct work_struct *work) 628 { 629 struct amdgpu_device *adev = container_of(work, struct amdgpu_device, virt.vf2pf_work.work); 630 int ret; 631 632 ret = amdgpu_virt_read_pf2vf_data(adev); 633 if (ret) { 634 adev->virt.vf2pf_update_retry_cnt++; 635 636 if ((amdgpu_virt_rcvd_ras_interrupt(adev) || 637 adev->virt.vf2pf_update_retry_cnt >= AMDGPU_VF2PF_UPDATE_MAX_RETRY_LIMIT) && 638 amdgpu_sriov_runtime(adev)) { 639 640 amdgpu_ras_set_fed(adev, true); 641 if (amdgpu_reset_domain_schedule(adev->reset_domain, 642 &adev->kfd.reset_work)) 643 return; 644 else 645 dev_err(adev->dev, "Failed to queue work! at %s", __func__); 646 } 647 648 goto out; 649 } 650 651 adev->virt.vf2pf_update_retry_cnt = 0; 652 amdgpu_virt_write_vf2pf_data(adev); 653 654 out: 655 schedule_delayed_work(&(adev->virt.vf2pf_work), adev->virt.vf2pf_update_interval_ms); 656 } 657 658 void amdgpu_virt_fini_data_exchange(struct amdgpu_device *adev) 659 { 660 if (adev->virt.vf2pf_update_interval_ms != 0) { 661 DRM_INFO("clean up the vf2pf work item\n"); 662 cancel_delayed_work_sync(&adev->virt.vf2pf_work); 663 adev->virt.vf2pf_update_interval_ms = 0; 664 } 665 } 666 667 void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev) 668 { 669 adev->virt.fw_reserve.p_pf2vf = NULL; 670 adev->virt.fw_reserve.p_vf2pf = NULL; 671 adev->virt.vf2pf_update_interval_ms = 0; 672 adev->virt.vf2pf_update_retry_cnt = 0; 673 674 if (adev->mman.fw_vram_usage_va && adev->mman.drv_vram_usage_va) { 675 DRM_WARN("Currently fw_vram and drv_vram should not have values at the same time!"); 676 } else if (adev->mman.fw_vram_usage_va || adev->mman.drv_vram_usage_va) { 677 /* go through this logic in ip_init and reset to init workqueue*/ 678 amdgpu_virt_exchange_data(adev); 679 680 INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_item); 681 schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms)); 682 } else if (adev->bios != NULL) { 683 /* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/ 684 adev->virt.fw_reserve.p_pf2vf = 685 (struct amd_sriov_msg_pf2vf_info_header *) 686 (adev->bios + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10)); 687 688 amdgpu_virt_read_pf2vf_data(adev); 689 } 690 } 691 692 693 void amdgpu_virt_exchange_data(struct amdgpu_device *adev) 694 { 695 uint64_t bp_block_offset = 0; 696 uint32_t bp_block_size = 0; 697 struct amd_sriov_msg_pf2vf_info *pf2vf_v2 = NULL; 698 699 if (adev->mman.fw_vram_usage_va || adev->mman.drv_vram_usage_va) { 700 if (adev->mman.fw_vram_usage_va) { 701 adev->virt.fw_reserve.p_pf2vf = 702 (struct amd_sriov_msg_pf2vf_info_header *) 703 (adev->mman.fw_vram_usage_va + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10)); 704 adev->virt.fw_reserve.p_vf2pf = 705 (struct amd_sriov_msg_vf2pf_info_header *) 706 (adev->mman.fw_vram_usage_va + (AMD_SRIOV_MSG_VF2PF_OFFSET_KB << 10)); 707 } else if (adev->mman.drv_vram_usage_va) { 708 adev->virt.fw_reserve.p_pf2vf = 709 (struct amd_sriov_msg_pf2vf_info_header *) 710 (adev->mman.drv_vram_usage_va + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10)); 711 adev->virt.fw_reserve.p_vf2pf = 712 (struct amd_sriov_msg_vf2pf_info_header *) 713 (adev->mman.drv_vram_usage_va + (AMD_SRIOV_MSG_VF2PF_OFFSET_KB << 10)); 714 } 715 716 amdgpu_virt_read_pf2vf_data(adev); 717 amdgpu_virt_write_vf2pf_data(adev); 718 719 /* bad page handling for version 2 */ 720 if (adev->virt.fw_reserve.p_pf2vf->version == 2) { 721 pf2vf_v2 = (struct amd_sriov_msg_pf2vf_info *)adev->virt.fw_reserve.p_pf2vf; 722 723 bp_block_offset = ((uint64_t)pf2vf_v2->bp_block_offset_low & 0xFFFFFFFF) | 724 ((((uint64_t)pf2vf_v2->bp_block_offset_high) << 32) & 0xFFFFFFFF00000000); 725 bp_block_size = pf2vf_v2->bp_block_size; 726 727 if (bp_block_size && !adev->virt.ras_init_done) 728 amdgpu_virt_init_ras_err_handler_data(adev); 729 730 if (adev->virt.ras_init_done) 731 amdgpu_virt_add_bad_page(adev, bp_block_offset, bp_block_size); 732 } 733 } 734 } 735 736 void amdgpu_detect_virtualization(struct amdgpu_device *adev) 737 { 738 uint32_t reg; 739 740 switch (adev->asic_type) { 741 case CHIP_TONGA: 742 case CHIP_FIJI: 743 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER); 744 break; 745 case CHIP_VEGA10: 746 case CHIP_VEGA20: 747 case CHIP_NAVI10: 748 case CHIP_NAVI12: 749 case CHIP_SIENNA_CICHLID: 750 case CHIP_ARCTURUS: 751 case CHIP_ALDEBARAN: 752 case CHIP_IP_DISCOVERY: 753 reg = RREG32(mmRCC_IOV_FUNC_IDENTIFIER); 754 break; 755 default: /* other chip doesn't support SRIOV */ 756 reg = 0; 757 break; 758 } 759 760 if (reg & 1) 761 adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF; 762 763 if (reg & 0x80000000) 764 adev->virt.caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV; 765 766 if (!reg) { 767 /* passthrough mode exclus sriov mod */ 768 if (is_virtual_machine() && !xen_initial_domain()) 769 adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE; 770 } 771 772 /* we have the ability to check now */ 773 if (amdgpu_sriov_vf(adev)) { 774 switch (adev->asic_type) { 775 case CHIP_TONGA: 776 case CHIP_FIJI: 777 vi_set_virt_ops(adev); 778 break; 779 case CHIP_VEGA10: 780 soc15_set_virt_ops(adev); 781 #ifdef CONFIG_X86 782 /* not send GPU_INIT_DATA with MS_HYPERV*/ 783 if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) 784 #endif 785 /* send a dummy GPU_INIT_DATA request to host on vega10 */ 786 amdgpu_virt_request_init_data(adev); 787 break; 788 case CHIP_VEGA20: 789 case CHIP_ARCTURUS: 790 case CHIP_ALDEBARAN: 791 soc15_set_virt_ops(adev); 792 break; 793 case CHIP_NAVI10: 794 case CHIP_NAVI12: 795 case CHIP_SIENNA_CICHLID: 796 case CHIP_IP_DISCOVERY: 797 nv_set_virt_ops(adev); 798 /* try send GPU_INIT_DATA request to host */ 799 amdgpu_virt_request_init_data(adev); 800 break; 801 default: /* other chip doesn't support SRIOV */ 802 DRM_ERROR("Unknown asic type: %d!\n", adev->asic_type); 803 break; 804 } 805 } 806 } 807 808 static bool amdgpu_virt_access_debugfs_is_mmio(struct amdgpu_device *adev) 809 { 810 return amdgpu_sriov_is_debug(adev) ? true : false; 811 } 812 813 static bool amdgpu_virt_access_debugfs_is_kiq(struct amdgpu_device *adev) 814 { 815 return amdgpu_sriov_is_normal(adev) ? true : false; 816 } 817 818 int amdgpu_virt_enable_access_debugfs(struct amdgpu_device *adev) 819 { 820 if (!amdgpu_sriov_vf(adev) || 821 amdgpu_virt_access_debugfs_is_kiq(adev)) 822 return 0; 823 824 if (amdgpu_virt_access_debugfs_is_mmio(adev)) 825 adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME; 826 else 827 return -EPERM; 828 829 return 0; 830 } 831 832 void amdgpu_virt_disable_access_debugfs(struct amdgpu_device *adev) 833 { 834 if (amdgpu_sriov_vf(adev)) 835 adev->virt.caps |= AMDGPU_SRIOV_CAPS_RUNTIME; 836 } 837 838 enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *adev) 839 { 840 enum amdgpu_sriov_vf_mode mode; 841 842 if (amdgpu_sriov_vf(adev)) { 843 if (amdgpu_sriov_is_pp_one_vf(adev)) 844 mode = SRIOV_VF_MODE_ONE_VF; 845 else 846 mode = SRIOV_VF_MODE_MULTI_VF; 847 } else { 848 mode = SRIOV_VF_MODE_BARE_METAL; 849 } 850 851 return mode; 852 } 853 854 void amdgpu_virt_pre_reset(struct amdgpu_device *adev) 855 { 856 /* stop the data exchange thread */ 857 amdgpu_virt_fini_data_exchange(adev); 858 amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR); 859 } 860 861 void amdgpu_virt_post_reset(struct amdgpu_device *adev) 862 { 863 if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 0, 3)) { 864 /* force set to GFXOFF state after reset, 865 * to avoid some invalid operation before GC enable 866 */ 867 adev->gfx.is_poweron = false; 868 } 869 870 adev->mes.ring[0].sched.ready = false; 871 } 872 873 bool amdgpu_virt_fw_load_skip_check(struct amdgpu_device *adev, uint32_t ucode_id) 874 { 875 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) { 876 case IP_VERSION(13, 0, 0): 877 /* no vf autoload, white list */ 878 if (ucode_id == AMDGPU_UCODE_ID_VCN1 || 879 ucode_id == AMDGPU_UCODE_ID_VCN) 880 return false; 881 else 882 return true; 883 case IP_VERSION(11, 0, 9): 884 case IP_VERSION(11, 0, 7): 885 /* black list for CHIP_NAVI12 and CHIP_SIENNA_CICHLID */ 886 if (ucode_id == AMDGPU_UCODE_ID_RLC_G 887 || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL 888 || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM 889 || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM 890 || ucode_id == AMDGPU_UCODE_ID_SMC) 891 return true; 892 else 893 return false; 894 case IP_VERSION(13, 0, 10): 895 /* white list */ 896 if (ucode_id == AMDGPU_UCODE_ID_CAP 897 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_PFP 898 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_ME 899 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_MEC 900 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_PFP_P0_STACK 901 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_PFP_P1_STACK 902 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_ME_P0_STACK 903 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_ME_P1_STACK 904 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_MEC_P0_STACK 905 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_MEC_P1_STACK 906 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_MEC_P2_STACK 907 || ucode_id == AMDGPU_UCODE_ID_CP_RS64_MEC_P3_STACK 908 || ucode_id == AMDGPU_UCODE_ID_CP_MES 909 || ucode_id == AMDGPU_UCODE_ID_CP_MES_DATA 910 || ucode_id == AMDGPU_UCODE_ID_CP_MES1 911 || ucode_id == AMDGPU_UCODE_ID_CP_MES1_DATA 912 || ucode_id == AMDGPU_UCODE_ID_VCN1 913 || ucode_id == AMDGPU_UCODE_ID_VCN) 914 return false; 915 else 916 return true; 917 default: 918 /* lagacy black list */ 919 if (ucode_id == AMDGPU_UCODE_ID_SDMA0 920 || ucode_id == AMDGPU_UCODE_ID_SDMA1 921 || ucode_id == AMDGPU_UCODE_ID_SDMA2 922 || ucode_id == AMDGPU_UCODE_ID_SDMA3 923 || ucode_id == AMDGPU_UCODE_ID_SDMA4 924 || ucode_id == AMDGPU_UCODE_ID_SDMA5 925 || ucode_id == AMDGPU_UCODE_ID_SDMA6 926 || ucode_id == AMDGPU_UCODE_ID_SDMA7 927 || ucode_id == AMDGPU_UCODE_ID_RLC_G 928 || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL 929 || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM 930 || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM 931 || ucode_id == AMDGPU_UCODE_ID_SMC) 932 return true; 933 else 934 return false; 935 } 936 } 937 938 void amdgpu_virt_update_sriov_video_codec(struct amdgpu_device *adev, 939 struct amdgpu_video_codec_info *encode, uint32_t encode_array_size, 940 struct amdgpu_video_codec_info *decode, uint32_t decode_array_size) 941 { 942 uint32_t i; 943 944 if (!adev->virt.is_mm_bw_enabled) 945 return; 946 947 if (encode) { 948 for (i = 0; i < encode_array_size; i++) { 949 encode[i].max_width = adev->virt.encode_max_dimension_pixels; 950 encode[i].max_pixels_per_frame = adev->virt.encode_max_frame_pixels; 951 if (encode[i].max_width > 0) 952 encode[i].max_height = encode[i].max_pixels_per_frame / encode[i].max_width; 953 else 954 encode[i].max_height = 0; 955 } 956 } 957 958 if (decode) { 959 for (i = 0; i < decode_array_size; i++) { 960 decode[i].max_width = adev->virt.decode_max_dimension_pixels; 961 decode[i].max_pixels_per_frame = adev->virt.decode_max_frame_pixels; 962 if (decode[i].max_width > 0) 963 decode[i].max_height = decode[i].max_pixels_per_frame / decode[i].max_width; 964 else 965 decode[i].max_height = 0; 966 } 967 } 968 } 969 970 bool amdgpu_virt_get_rlcg_reg_access_flag(struct amdgpu_device *adev, 971 u32 acc_flags, u32 hwip, 972 bool write, u32 *rlcg_flag) 973 { 974 bool ret = false; 975 976 switch (hwip) { 977 case GC_HWIP: 978 if (amdgpu_sriov_reg_indirect_gc(adev)) { 979 *rlcg_flag = 980 write ? AMDGPU_RLCG_GC_WRITE : AMDGPU_RLCG_GC_READ; 981 ret = true; 982 /* only in new version, AMDGPU_REGS_NO_KIQ and 983 * AMDGPU_REGS_RLC are enabled simultaneously */ 984 } else if ((acc_flags & AMDGPU_REGS_RLC) && 985 !(acc_flags & AMDGPU_REGS_NO_KIQ) && write) { 986 *rlcg_flag = AMDGPU_RLCG_GC_WRITE_LEGACY; 987 ret = true; 988 } 989 break; 990 case MMHUB_HWIP: 991 if (amdgpu_sriov_reg_indirect_mmhub(adev) && 992 (acc_flags & AMDGPU_REGS_RLC) && write) { 993 *rlcg_flag = AMDGPU_RLCG_MMHUB_WRITE; 994 ret = true; 995 } 996 break; 997 default: 998 break; 999 } 1000 return ret; 1001 } 1002 1003 u32 amdgpu_virt_rlcg_reg_rw(struct amdgpu_device *adev, u32 offset, u32 v, u32 flag, u32 xcc_id) 1004 { 1005 struct amdgpu_rlcg_reg_access_ctrl *reg_access_ctrl; 1006 uint32_t timeout = 50000; 1007 uint32_t i, tmp; 1008 uint32_t ret = 0; 1009 void *scratch_reg0; 1010 void *scratch_reg1; 1011 void *scratch_reg2; 1012 void *scratch_reg3; 1013 void *spare_int; 1014 1015 if (!adev->gfx.rlc.rlcg_reg_access_supported) { 1016 dev_err(adev->dev, 1017 "indirect registers access through rlcg is not available\n"); 1018 return 0; 1019 } 1020 1021 if (adev->gfx.xcc_mask && (((1 << xcc_id) & adev->gfx.xcc_mask) == 0)) { 1022 dev_err(adev->dev, "invalid xcc\n"); 1023 return 0; 1024 } 1025 1026 if (amdgpu_device_skip_hw_access(adev)) 1027 return 0; 1028 1029 reg_access_ctrl = &adev->gfx.rlc.reg_access_ctrl[xcc_id]; 1030 scratch_reg0 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg0; 1031 scratch_reg1 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg1; 1032 scratch_reg2 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg2; 1033 scratch_reg3 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg3; 1034 1035 mutex_lock(&adev->virt.rlcg_reg_lock); 1036 1037 if (reg_access_ctrl->spare_int) 1038 spare_int = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->spare_int; 1039 1040 if (offset == reg_access_ctrl->grbm_cntl) { 1041 /* if the target reg offset is grbm_cntl, write to scratch_reg2 */ 1042 writel(v, scratch_reg2); 1043 if (flag == AMDGPU_RLCG_GC_WRITE_LEGACY) 1044 writel(v, ((void __iomem *)adev->rmmio) + (offset * 4)); 1045 } else if (offset == reg_access_ctrl->grbm_idx) { 1046 /* if the target reg offset is grbm_idx, write to scratch_reg3 */ 1047 writel(v, scratch_reg3); 1048 if (flag == AMDGPU_RLCG_GC_WRITE_LEGACY) 1049 writel(v, ((void __iomem *)adev->rmmio) + (offset * 4)); 1050 } else { 1051 /* 1052 * SCRATCH_REG0 = read/write value 1053 * SCRATCH_REG1[30:28] = command 1054 * SCRATCH_REG1[19:0] = address in dword 1055 * SCRATCH_REG1[27:24] = Error reporting 1056 */ 1057 writel(v, scratch_reg0); 1058 writel((offset | flag), scratch_reg1); 1059 if (reg_access_ctrl->spare_int) 1060 writel(1, spare_int); 1061 1062 for (i = 0; i < timeout; i++) { 1063 tmp = readl(scratch_reg1); 1064 if (!(tmp & AMDGPU_RLCG_SCRATCH1_ADDRESS_MASK)) 1065 break; 1066 udelay(10); 1067 } 1068 1069 tmp = readl(scratch_reg1); 1070 if (i >= timeout || (tmp & AMDGPU_RLCG_SCRATCH1_ERROR_MASK) != 0) { 1071 if (amdgpu_sriov_rlcg_error_report_enabled(adev)) { 1072 if (tmp & AMDGPU_RLCG_VFGATE_DISABLED) { 1073 dev_err(adev->dev, 1074 "vfgate is disabled, rlcg failed to program reg: 0x%05x\n", offset); 1075 } else if (tmp & AMDGPU_RLCG_WRONG_OPERATION_TYPE) { 1076 dev_err(adev->dev, 1077 "wrong operation type, rlcg failed to program reg: 0x%05x\n", offset); 1078 } else if (tmp & AMDGPU_RLCG_REG_NOT_IN_RANGE) { 1079 dev_err(adev->dev, 1080 "register is not in range, rlcg failed to program reg: 0x%05x\n", offset); 1081 } else { 1082 dev_err(adev->dev, 1083 "unknown error type, rlcg failed to program reg: 0x%05x\n", offset); 1084 } 1085 } else { 1086 dev_err(adev->dev, 1087 "timeout: rlcg faled to program reg: 0x%05x\n", offset); 1088 } 1089 } 1090 } 1091 1092 ret = readl(scratch_reg0); 1093 1094 mutex_unlock(&adev->virt.rlcg_reg_lock); 1095 1096 return ret; 1097 } 1098 1099 void amdgpu_sriov_wreg(struct amdgpu_device *adev, 1100 u32 offset, u32 value, 1101 u32 acc_flags, u32 hwip, u32 xcc_id) 1102 { 1103 u32 rlcg_flag; 1104 1105 if (amdgpu_device_skip_hw_access(adev)) 1106 return; 1107 1108 if (!amdgpu_sriov_runtime(adev) && 1109 amdgpu_virt_get_rlcg_reg_access_flag(adev, acc_flags, hwip, true, &rlcg_flag)) { 1110 amdgpu_virt_rlcg_reg_rw(adev, offset, value, rlcg_flag, xcc_id); 1111 return; 1112 } 1113 1114 if (acc_flags & AMDGPU_REGS_NO_KIQ) 1115 WREG32_NO_KIQ(offset, value); 1116 else 1117 WREG32(offset, value); 1118 } 1119 1120 u32 amdgpu_sriov_rreg(struct amdgpu_device *adev, 1121 u32 offset, u32 acc_flags, u32 hwip, u32 xcc_id) 1122 { 1123 u32 rlcg_flag; 1124 1125 if (amdgpu_device_skip_hw_access(adev)) 1126 return 0; 1127 1128 if (!amdgpu_sriov_runtime(adev) && 1129 amdgpu_virt_get_rlcg_reg_access_flag(adev, acc_flags, hwip, false, &rlcg_flag)) 1130 return amdgpu_virt_rlcg_reg_rw(adev, offset, 0, rlcg_flag, xcc_id); 1131 1132 if (acc_flags & AMDGPU_REGS_NO_KIQ) 1133 return RREG32_NO_KIQ(offset); 1134 else 1135 return RREG32(offset); 1136 } 1137 1138 bool amdgpu_sriov_xnack_support(struct amdgpu_device *adev) 1139 { 1140 bool xnack_mode = true; 1141 1142 if (amdgpu_sriov_vf(adev) && 1143 amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 2)) 1144 xnack_mode = false; 1145 1146 return xnack_mode; 1147 } 1148 1149 bool amdgpu_virt_get_ras_capability(struct amdgpu_device *adev) 1150 { 1151 struct amdgpu_ras *con = amdgpu_ras_get_context(adev); 1152 1153 if (!amdgpu_sriov_ras_caps_en(adev)) 1154 return false; 1155 1156 if (adev->virt.ras_en_caps.bits.block_umc) 1157 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__UMC); 1158 if (adev->virt.ras_en_caps.bits.block_sdma) 1159 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__SDMA); 1160 if (adev->virt.ras_en_caps.bits.block_gfx) 1161 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__GFX); 1162 if (adev->virt.ras_en_caps.bits.block_mmhub) 1163 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__MMHUB); 1164 if (adev->virt.ras_en_caps.bits.block_athub) 1165 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__ATHUB); 1166 if (adev->virt.ras_en_caps.bits.block_pcie_bif) 1167 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__PCIE_BIF); 1168 if (adev->virt.ras_en_caps.bits.block_hdp) 1169 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__HDP); 1170 if (adev->virt.ras_en_caps.bits.block_xgmi_wafl) 1171 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__XGMI_WAFL); 1172 if (adev->virt.ras_en_caps.bits.block_df) 1173 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__DF); 1174 if (adev->virt.ras_en_caps.bits.block_smn) 1175 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__SMN); 1176 if (adev->virt.ras_en_caps.bits.block_sem) 1177 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__SEM); 1178 if (adev->virt.ras_en_caps.bits.block_mp0) 1179 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__MP0); 1180 if (adev->virt.ras_en_caps.bits.block_mp1) 1181 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__MP1); 1182 if (adev->virt.ras_en_caps.bits.block_fuse) 1183 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__FUSE); 1184 if (adev->virt.ras_en_caps.bits.block_mca) 1185 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__MCA); 1186 if (adev->virt.ras_en_caps.bits.block_vcn) 1187 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__VCN); 1188 if (adev->virt.ras_en_caps.bits.block_jpeg) 1189 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__JPEG); 1190 if (adev->virt.ras_en_caps.bits.block_ih) 1191 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__IH); 1192 if (adev->virt.ras_en_caps.bits.block_mpio) 1193 adev->ras_hw_enabled |= BIT(AMDGPU_RAS_BLOCK__MPIO); 1194 1195 if (adev->virt.ras_en_caps.bits.poison_propogation_mode) 1196 con->poison_supported = true; /* Poison is handled by host */ 1197 1198 return true; 1199 } 1200