From 712acd2027fd91726efa55fe5e291efba59a4704 Mon Sep 17 00:00:00 2001 From: Alex Deucher Date: Wed, 11 Jul 2018 13:56:44 -0500 Subject: [PATCH 3/4] drm/amd/pp/smu7: split memory allocation/free from init/fini Split the buffer alloc/free from the init/fini functions so we can restructure this later. No intended functional change. Signed-off-by: Alex Deucher --- drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c | 102 ++++++++++++--------- drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h | 2 + 2 files changed, 62 insertions(+), 42 deletions(-) diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c index ee6281759672..e192c90eaa57 100644 --- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c +++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c @@ -567,66 +567,84 @@ int smu7_setup_pwr_virus(struct pp_hwmgr *hwmgr) return 0; } +int smu7_alloc_buffers(struct pp_hwmgr *hwmgr) +{ + struct smu7_smumgr *smu_data = (struct smu7_smumgr *)(hwmgr->smu_backend); + int r; + + /* Allocate FW image data structure and header buffer and + * send the header buffer address to SMU + */ + r = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev, + smu_data->header_buffer.data_size, + PAGE_SIZE, + AMDGPU_GEM_DOMAIN_VRAM, + &smu_data->header_buffer.handle, + &smu_data->header_buffer.mc_addr, + &smu_data->header_buffer.kaddr); + + if (r) + return r; + + if (hwmgr->not_vf) { + r = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev, + smu_data->smu_buffer.data_size, + PAGE_SIZE, + AMDGPU_GEM_DOMAIN_VRAM, + &smu_data->smu_buffer.handle, + &smu_data->smu_buffer.mc_addr, + &smu_data->smu_buffer.kaddr); + + if (r) { + amdgpu_bo_free_kernel(&smu_data->header_buffer.handle, + &smu_data->header_buffer.mc_addr, + &smu_data->header_buffer.kaddr); + return r; + } + } + return r; +} + +void smu7_free_buffers(struct pp_hwmgr *hwmgr) +{ + struct smu7_smumgr *smu_data = (struct smu7_smumgr *)(hwmgr->smu_backend); + + amdgpu_bo_free_kernel(&smu_data->header_buffer.handle, + &smu_data->header_buffer.mc_addr, + &smu_data->header_buffer.kaddr); + + if (hwmgr->not_vf) + amdgpu_bo_free_kernel(&smu_data->smu_buffer.handle, + &smu_data->smu_buffer.mc_addr, + &smu_data->smu_buffer.kaddr); +} + int smu7_init(struct pp_hwmgr *hwmgr) { struct smu7_smumgr *smu_data; int r; + /* Allocate memory for backend private data */ smu_data = (struct smu7_smumgr *)(hwmgr->smu_backend); smu_data->header_buffer.data_size = ((sizeof(struct SMU_DRAMData_TOC) / 4096) + 1) * 4096; -/* Allocate FW image data structure and header buffer and - * send the header buffer address to SMU */ - r = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev, - smu_data->header_buffer.data_size, - PAGE_SIZE, - AMDGPU_GEM_DOMAIN_VRAM, - &smu_data->header_buffer.handle, - &smu_data->header_buffer.mc_addr, - &smu_data->header_buffer.kaddr); - - if (r) - return -EINVAL; - - if (!hwmgr->not_vf) - return 0; + if (hwmgr->not_vf) { + smu_data->smu_buffer.data_size = 200 * 4096; - smu_data->smu_buffer.data_size = 200*4096; - r = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev, - smu_data->smu_buffer.data_size, - PAGE_SIZE, - AMDGPU_GEM_DOMAIN_VRAM, - &smu_data->smu_buffer.handle, - &smu_data->smu_buffer.mc_addr, - &smu_data->smu_buffer.kaddr); - - if (r) { - amdgpu_bo_free_kernel(&smu_data->header_buffer.handle, - &smu_data->header_buffer.mc_addr, - &smu_data->header_buffer.kaddr); - return -EINVAL; + if (smum_is_hw_avfs_present(hwmgr)) + hwmgr->avfs_supported = true; } - if (smum_is_hw_avfs_present(hwmgr)) - hwmgr->avfs_supported = true; + r = smu7_alloc_buffers(hwmgr); - return 0; + return r; } int smu7_smu_fini(struct pp_hwmgr *hwmgr) { - struct smu7_smumgr *smu_data = (struct smu7_smumgr *)(hwmgr->smu_backend); - - amdgpu_bo_free_kernel(&smu_data->header_buffer.handle, - &smu_data->header_buffer.mc_addr, - &smu_data->header_buffer.kaddr); - - if (hwmgr->not_vf) - amdgpu_bo_free_kernel(&smu_data->smu_buffer.handle, - &smu_data->smu_buffer.mc_addr, - &smu_data->smu_buffer.kaddr); + smu7_free_buffers(hwmgr); kfree(hwmgr->smu_backend); hwmgr->smu_backend = NULL; diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h index e6def283b731..7ed19822d701 100644 --- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h +++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h @@ -76,6 +76,8 @@ int smu7_request_smu_load_fw(struct pp_hwmgr *hwmgr); int smu7_check_fw_load_finish(struct pp_hwmgr *hwmgr, uint32_t fw_type); int smu7_reload_firmware(struct pp_hwmgr *hwmgr); int smu7_upload_smu_firmware_image(struct pp_hwmgr *hwmgr); +int smu7_alloc_buffers(struct pp_hwmgr *hwmgr); +void smu7_free_buffers(struct pp_hwmgr *hwmgr); int smu7_init(struct pp_hwmgr *hwmgr); int smu7_smu_fini(struct pp_hwmgr *hwmgr); -- 2.13.6