aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
diff options
context:
space:
mode:
authorRex Zhu <Rex.Zhu@amd.com>2018-10-09 01:55:49 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-10-10 15:48:52 -0400
commitc8963ea4ce1783034e1f9cf0d702fa490eb77836 (patch)
tree09cafe09785721ceba14450917a6461daeb5e5bf /drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
parenta2d31dc3cfab29f79c1cda2876d32b909ae26e25 (diff)
drm/amdgpu: Split amdgpu_ucode_init/fini_bo into two functions
1. one is for create/free bo when init/fini 2. one is for fill the bo before fw loading the ucode bo only need to be created when load driver and free when driver unload. when resume/reset, driver only need to re-fill the bo if the bo is allocated in vram. Suggested by Christian. v2: Return error when bo create failed. Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Rex Zhu <Rex.Zhu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
index adfeb93c612e..57ed38422089 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
@@ -422,32 +422,42 @@ static int amdgpu_ucode_patch_jt(struct amdgpu_firmware_info *ucode,
422 return 0; 422 return 0;
423} 423}
424 424
425int amdgpu_ucode_create_bo(struct amdgpu_device *adev)
426{
427 if (adev->firmware.load_type != AMDGPU_FW_LOAD_DIRECT) {
428 amdgpu_bo_create_kernel(adev, adev->firmware.fw_size, PAGE_SIZE,
429 amdgpu_sriov_vf(adev) ? AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
430 &adev->firmware.fw_buf,
431 &adev->firmware.fw_buf_mc,
432 &adev->firmware.fw_buf_ptr);
433 if (!adev->firmware.fw_buf) {
434 dev_err(adev->dev, "failed to create kernel buffer for firmware.fw_buf\n");
435 return -ENOMEM;
436 } else if (amdgpu_sriov_vf(adev)) {
437 memset(adev->firmware.fw_buf_ptr, 0, adev->firmware.fw_size);
438 }
439 }
440 return 0;
441}
442
443void amdgpu_ucode_free_bo(struct amdgpu_device *adev)
444{
445 if (adev->firmware.load_type != AMDGPU_FW_LOAD_DIRECT)
446 amdgpu_bo_free_kernel(&adev->firmware.fw_buf,
447 &adev->firmware.fw_buf_mc,
448 &adev->firmware.fw_buf_ptr);
449}
450
425int amdgpu_ucode_init_bo(struct amdgpu_device *adev) 451int amdgpu_ucode_init_bo(struct amdgpu_device *adev)
426{ 452{
427 uint64_t fw_offset = 0; 453 uint64_t fw_offset = 0;
428 int i, err; 454 int i;
429 struct amdgpu_firmware_info *ucode = NULL; 455 struct amdgpu_firmware_info *ucode = NULL;
430 const struct common_firmware_header *header = NULL; 456 const struct common_firmware_header *header = NULL;
431 457
432 if (!adev->firmware.fw_size) { 458 /* for baremetal, the ucode is allocated in gtt, so don't need to fill the bo when reset/suspend */
433 dev_warn(adev->dev, "No ip firmware need to load\n"); 459 if (!amdgpu_sriov_vf(adev) && (adev->in_gpu_reset || adev->in_suspend))
434 return 0; 460 return 0;
435 }
436
437 if (!adev->in_gpu_reset && !adev->in_suspend) {
438 err = amdgpu_bo_create_kernel(adev, adev->firmware.fw_size, PAGE_SIZE,
439 amdgpu_sriov_vf(adev) ? AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
440 &adev->firmware.fw_buf,
441 &adev->firmware.fw_buf_mc,
442 &adev->firmware.fw_buf_ptr);
443 if (err) {
444 dev_err(adev->dev, "failed to create kernel buffer for firmware.fw_buf\n");
445 goto failed;
446 }
447 }
448
449 memset(adev->firmware.fw_buf_ptr, 0, adev->firmware.fw_size);
450
451 /* 461 /*
452 * if SMU loaded firmware, it needn't add SMC, UVD, and VCE 462 * if SMU loaded firmware, it needn't add SMC, UVD, and VCE
453 * ucode info here 463 * ucode info here
@@ -479,12 +489,6 @@ int amdgpu_ucode_init_bo(struct amdgpu_device *adev)
479 } 489 }
480 } 490 }
481 return 0; 491 return 0;
482
483failed:
484 if (err)
485 adev->firmware.load_type = AMDGPU_FW_LOAD_DIRECT;
486
487 return err;
488} 492}
489 493
490int amdgpu_ucode_fini_bo(struct amdgpu_device *adev) 494int amdgpu_ucode_fini_bo(struct amdgpu_device *adev)
@@ -503,9 +507,5 @@ int amdgpu_ucode_fini_bo(struct amdgpu_device *adev)
503 } 507 }
504 } 508 }
505 509
506 amdgpu_bo_free_kernel(&adev->firmware.fw_buf,
507 &adev->firmware.fw_buf_mc,
508 &adev->firmware.fw_buf_ptr);
509
510 return 0; 510 return 0;
511} 511}