enable switching to new gpu index for hibernate on SRIOV.
Subsystems (3)
v2 cover enable switching to new gpu index for hibernate on SRIOV.
On SRIOV and VM environment, customer may need to switch to new vGPU indexes after hibernate and then resume the VM. For GPUs with XGMI, vram_start will change in this case, the FB aperture gpu address of VRAM BOs will also change. These gpu addresses need to be updated when resume. But these addresses are all over the KMD codebase, updating each of them is error-prone and not acceptable.
The solution is to use pdb0 page table to cover both vram and gart memory and use GART aperture gpu address instead. When gpu indexes change, the GART gpu address won't change.
For psp and smu, pdb0's gpu address does not work, so the original FB aperture gpu address is used instead. They need to be updated when resume with changed vGPUs.
Samuel Zhang (3):
drm/amdgpu: update XGMI physical node id and GMC configs on resume drm/amdgpu: update GPU addresses for SMU and PSP drm/amdgpu: enable pdb0 for hibernation on SRIOV
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 25 ++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 46 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 22 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 21 ++++++++-- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 ++++++++ 10 files changed, 140 insertions(+), 17 deletions(-)
Signature · 1 line
2.43.5
PATCH v2 1/3 drm/amdgpu: update XGMI physical node id and GMC configs on resume
For virtual machine with vGPUs in SRIOV single device mode and XGMI is enabled, XGMI physical node ids may change when waking up from hiberation with different vGPU devices. So update XGMI physical node ids on resume.
Update GPU memory controller configuration on resume if XGMI physical node ids are changed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 25 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 +-- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 5 +++++ 3 files changed, 31 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +25 -0
@@ -5040,6 +5040,28 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return 0 ; } +static int amdgpu_device_update_xgmi_nodes (struct amdgpu_device *adev) +{ +int r; +unsigned int prev_physical_node_id; + +/* Get xgmi info again for sriov to detect device changes */ +if (amdgpu_sriov_vf (adev) && + !(adev->flags &AMD_IS_APU ) && + adev->gmc.xgmi.supported && + !adev->gmc.xgmi.connected_to_cpu) { + prev_physical_node_id = adev->gmc.xgmi.physical_node_id; + r = adev->gfxhub.funcs->get_xgmi_info (adev); +if (r) +return r; + +dev_info (adev->dev,"xgmi node, old id %d, new id %d\n" , + prev_physical_node_id, adev->gmc.xgmi.physical_node_id); + } +return 0 ; +} + +/** * amdgpu_device_resume - initiate device resume *
@@ -5059,6 +5081,9 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) r =amdgpu_virt_request_full_gpu (adev, true);if (r)return r; + r =amdgpu_device_update_xgmi_nodes (adev); +if (r) +return r; }if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -2
@@ -1298,8 +1298,7 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,if (!mem_ranges || !exp_ranges)return -EINVAL ; - refresh = (adev->init_lvl->level !=AMDGPU_INIT_LEVEL_MINIMAL_XGMI ) && - (adev->gmc.reset_flags &AMDGPU_GMC_INIT_RESET_NPS ); + refresh = true; ret =amdgpu_discovery_get_nps_info (adev, &nps_type, &ranges, &range_cnt, refresh);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5 -0
@@ -2533,6 +2533,11 @@ static int gmc_v9_0_resume(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int r; + r =gmc_v9_0_mc_init (adev); +if (r) +return r; +gmc_v9_0_init_sw_mem_ranges (adev, adev->gmc.mem_partitions); +/* If a reset is done for NPS mode switch, read the memory range * information again. */
Signature · 1 line
2.43.5
Christian König
maintainerRe: [PATCH v2 1/3] drm/amdgpu: update XGMI physical node id and GMC configs on resume
Quoted 78 lines · Samuel Zhang
For virtual machine with vGPUs in SRIOV single device mode and XGMI is enabled, XGMI physical node ids may change when waking up from hiberation with different vGPU devices. So update XGMI physical node ids on resume.
Update GPU memory controller configuration on resume if XGMI physical node ids are changed.
Signed-off-by Jiang Liu <[email protected]>Signed-off-by Samuel Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 25 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 +-- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 5 +++++ 3 files changed, 31 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +25
-0@@ -5040,6 +5040,28 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return 0 ; } +static int amdgpu_device_update_xgmi_nodes (struct amdgpu_device *adev) +{ +int r; +unsigned int prev_physical_node_id; + +/* Get xgmi info again for sriov to detect device changes */ +if (amdgpu_sriov_vf (adev) && + !(adev->flags &AMD_IS_APU ) && + adev->gmc.xgmi.supported && + !adev->gmc.xgmi.connected_to_cpu) { + prev_physical_node_id = adev->gmc.xgmi.physical_node_id; + r = adev->gfxhub.funcs->get_xgmi_info (adev); +if (r) +return r; + +dev_info (adev->dev,"xgmi node, old id %d, new id %d\n" , + prev_physical_node_id, adev->gmc.xgmi.physical_node_id); + } +return 0 ; +} + +/** * amdgpu_device_resume - initiate device resume * @@ -5059,6 +5081,9 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) r =amdgpu_virt_request_full_gpu (adev, true);if (r)return r; + r =amdgpu_device_update_xgmi_nodes (adev); +if (r) +return r; }if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-2@@ -1298,8 +1298,7 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,if (!mem_ranges || !exp_ranges)return -EINVAL ; - refresh = (adev->init_lvl->level !=AMDGPU_INIT_LEVEL_MINIMAL_XGMI ) && - (adev->gmc.reset_flags &AMDGPU_GMC_INIT_RESET_NPS ); + refresh = true; ret =amdgpu_discovery_get_nps_info (adev, &nps_type, &ranges, &range_cnt, refresh);drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_resume(struct amdgpu_ip_block *ip_block) · line 2540
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5
-0@@ -2533,6 +2533,11 @@ static int gmc_v9_0_resume(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int r; + r =gmc_v9_0_mc_init (adev); +if (r) +return r; +gmc_v9_0_init_sw_mem_ranges (adev, adev->gmc.mem_partitions); +
That is most likely a no-go. We should only adjust the base of the memory partitions and not re-initialize the number of partitions.
Regards,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0/* If a reset is done for NPS mode switch, read the memory range * information again. */
PATCH v2 2/3 drm/amdgpu: update GPU addresses for SMU and PSP
In reply to Samuel Zhangadd amdgpu_bo_fb_aper_addr() and update the cached GPU addresses to use the FB aperture address for SMU and PSP.
2 reasons for this change:
1. when pdb0 is enabled, gpu addr from amdgpu_bo_create_kernel() is GART aperture address, it is not compatible with SMU and PSP, it need to updated to use FB aperture address.
2. Since FB aperture address will change after switching to new GPU index after hibernation, it need to be updated after resume.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 3 +++ drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 +++++++++++++++++ 7 files changed, 63 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
@@ -209,6 +209,7 @@ void amdgpu_gmc_vram_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc,uint64_t vis_limit = (uint64_t )amdgpu_vis_vram_limit <<20 ;uint64_t limit = (uint64_t )amdgpu_vram_limit <<20 ; + mc->vram_offset = base; mc->vram_start = base; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ;if (limit < mc->real_vram_size)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1 -0
@@ -251,6 +251,7 @@ struct amdgpu_gmc {*/ u64 vram_start;u64 vram_end; +u64 vram_offset;/* FB region , it's same as local vram region in single GPU, in XGMI * configuration, this region covers all GPUs in the same hive , * each GPU in the hive has the same view of this FB region .
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +18 -0
@@ -1513,6 +1513,24 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)return amdgpu_bo_gpu_offset_no_check (bo); } +/** +* amdgpu_bo_fb_aper_addr - return FB aperture GPU offset of the VRAM bo +* @bo: amdgpu VRAM buffer object for which we query the offset +* +* Returns: +* current FB aperture GPU offset of the object. +*/ +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +uint64_t offset; + +WARN_ON_ONCE (bo->tbo.resource->mem_type !=TTM_PL_VRAM ); + + offset = (bo->tbo.resource->start <<PAGE_SHIFT ) + adev->gmc.vram_offset; +return amdgpu_gmc_sign_extend (offset); +} +/** * amdgpu_bo_gpu_offset_no_check - return GPU offset of bo * @bo: amdgpu object for which we query the offset
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -320,6 +320,7 @@ int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv, bool intr);int amdgpu_bo_sync_wait (struct amdgpu_bo *bo,void *owner,bool intr);u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo); +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo);u64 amdgpu_bo_gpu_offset_no_check (struct amdgpu_bo *bo);uint32_t amdgpu_bo_mem_stats_placement (struct amdgpu_bo *bo); uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +22 -0
@@ -871,6 +871,8 @@ static int psp_tmr_init(struct psp_context *psp) &psp->tmr_bo, &psp->tmr_mc_addr, pptr); } +if (psp->tmr_bo) + psp->tmr_mc_addr =amdgpu_bo_fb_aper_addr (psp->tmr_bo);return ret; }
@@ -1210,6 +1212,9 @@ static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, cmd->cmd.cmd_load_ta.app_phy_addr_hi =upper_32_bits (ta_bin_mc); cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes; +if (context->mem_context.shared_bo) + context->mem_context.shared_mc_addr =amdgpu_bo_fb_aper_addr (context->mem_context.shared_bo); + cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo =lower_32_bits (context->mem_context.shared_mc_addr); cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi =
@@ -2336,11 +2341,26 @@ bool amdgpu_psp_tos_reload_needed(struct amdgpu_device *adev)return false; } +static void psp_update_gpu_addresses (struct amdgpu_device *adev) +{ +struct psp_context *psp = &adev->psp; + +if (psp->cmd_buf_bo && psp->cmd_buf_mem) { + psp->fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (psp->fw_pri_bo); + psp->fence_buf_mc_addr =amdgpu_bo_fb_aper_addr (psp->fence_buf_bo); + psp->cmd_buf_mc_addr =amdgpu_bo_fb_aper_addr (psp->cmd_buf_bo); + } +if (adev->firmware.rbuf && psp->km_ring.ring_mem) + psp->km_ring.ring_mem_mc_addr =amdgpu_bo_fb_aper_addr (adev->firmware.rbuf); +} +static int psp_hw_start (struct psp_context *psp) {struct amdgpu_device *adev = psp->adev;int ret; +psp_update_gpu_addresses (adev); +if (!amdgpu_sriov_vf (adev)) {if ((is_psp_fw_valid (psp->kdb)) && (psp->funcs->bootloader_load_kdb !=NULL )) {
@@ -3976,6 +3996,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,memcpy_toio (fw_pri_cpu_addr, usbc_pd_fw->data, usbc_pd_fw->size);mutex_lock (&adev->psp.mutex); + fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (fw_buf_bo); ret =psp_load_usbc_pd_fw (&adev->psp, fw_pri_mc_addr);mutex_unlock (&adev->psp.mutex);
@@ -4085,6 +4106,7 @@ static ssize_t amdgpu_psp_vbflash_read(struct file *filp, struct kobject *kobj,memcpy_toio (fw_pri_cpu_addr, adev->psp.vbflash_tmp_buf, adev->psp.vbflash_image_size);mutex_lock (&adev->psp.mutex); + fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (fw_buf_bo); ret =psp_update_spirom (&adev->psp, fw_pri_mc_addr);mutex_unlock (&adev->psp.mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +3 -0
@@ -1152,6 +1152,9 @@ int amdgpu_ucode_init_bo(struct amdgpu_device *adev) adev->firmware.max_ucodes =AMDGPU_UCODE_ID_MAXIMUM ; } +if (adev->firmware.fw_buf) + adev->firmware.fw_buf_mc =amdgpu_bo_fb_aper_addr (adev->firmware.fw_buf); +for (i =0 ; i < adev->firmware.max_ucodes; i++) { ucode = &adev->firmware.ucode[i];if (ucode->fw) {
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +17 -0
@@ -1000,6 +1000,21 @@ static int smu_fini_fb_allocations(struct smu_context *smu)return 0 ; } +static void smu_update_gpu_addresses (struct smu_context *smu) +{ +struct smu_table_context *smu_table = &smu->smu_table; +struct smu_table *pm_status_table = smu_table->tables +SMU_TABLE_PMSTATUSLOG ; +struct smu_table *driver_table = &(smu_table->driver_table); +struct smu_table *dummy_read_1_table = &smu_table->dummy_read_1_table; + +if (pm_status_table->bo) + pm_status_table->mc_address =amdgpu_bo_fb_aper_addr (pm_status_table->bo); +if (driver_table->bo) + driver_table->mc_address =amdgpu_bo_fb_aper_addr (driver_table->bo); +if (dummy_read_1_table->bo) + dummy_read_1_table->mc_address =amdgpu_bo_fb_aper_addr (dummy_read_1_table->bo); +} +/** * smu_alloc_memory_pool - allocate memory pool in the system memory *
@@ -1789,6 +1804,8 @@ static int smu_start_smc_engine(struct smu_context *smu)struct amdgpu_device *adev = smu->adev;int ret =0 ; +smu_update_gpu_addresses (smu); + smu->smc_fw_state =SMU_FW_INIT ;if (adev->firmware.load_type !=AMDGPU_FW_LOAD_PSP ) {
Signature · 1 line
2.43.5
Christian König
maintainerRe: [PATCH v2 2/3] drm/amdgpu: update GPU addresses for SMU and PSP
Quoted 39 lines · Samuel Zhang
add
amdgpu_bo_fb_aper_addr()and update the cached GPU addresses to use the FB aperture address for SMU and PSP.2 reasons for this change:
1. when pdb0 is enabled, gpu addr fromamdgpu_bo_create_kernel()is GART aperture address, it is not compatible with SMU and PSP, it need to updated to use FB aperture address.
2. Since FB aperture address will change after switching to new GPU index after hibernation, it need to be updated after resume.Signed-off-by Jiang Liu <[email protected]>Signed-off-by Samuel Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 3 +++ drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 +++++++++++++++++ 7 files changed, 63 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-0@@ -209,6 +209,7 @@ void amdgpu_gmc_vram_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc,uint64_t vis_limit = (uint64_t )amdgpu_vis_vram_limit <<20 ;uint64_t limit = (uint64_t )amdgpu_vram_limit <<20 ; + mc->vram_offset = base; mc->vram_start = base; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ;if (limit < mc->real_vram_size)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h struct amdgpu_gmc { · line 254
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1
-0@@ -251,6 +251,7 @@ struct amdgpu_gmc {*/ u64 vram_start;u64 vram_end; +u64 vram_offset;
Please don't add any new fields here. We should already have all the necessary information in that structure.
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0
-0/* FB region , it's same as local vram region in single GPU, in XGMI * configuration, this region covers all GPUs in the same hive , * each GPU in the hive has the same view of this FB region . drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-0@@ -1513,6 +1513,24 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)return amdgpu_bo_gpu_offset_no_check (bo); } +/** +* amdgpu_bo_fb_aper_addr - return FB aperture GPU offset of the VRAM bo +* @bo: amdgpu VRAM buffer object for which we query the offset +* +* Returns:
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1530
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +10
-0+* current FB aperture GPU offset of the object. +*/ +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +uint64_t offset; + +WARN_ON_ONCE (bo->tbo.resource->mem_type !=TTM_PL_VRAM ); + + offset = (bo->tbo.resource->start <<PAGE_SHIFT ) + adev->gmc.vram_offset;
Rather use fb_base + XGMI hive index here.
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0+return amdgpu_gmc_sign_extend (offset); +} +/** * amdgpu_bo_gpu_offset_no_check - return GPU offset of bo * @bo: amdgpu object for which we query the offset drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1
-0@@ -320,6 +320,7 @@ int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv, bool intr);int amdgpu_bo_sync_wait (struct amdgpu_bo *bo,void *owner,bool intr);u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo); +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo);u64 amdgpu_bo_gpu_offset_no_check (struct amdgpu_bo *bo);uint32_t amdgpu_bo_mem_stats_placement (struct amdgpu_bo *bo); uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2
-0@@ -871,6 +871,8 @@ static int psp_tmr_init(struct psp_context *psp) &psp->tmr_bo, &psp->tmr_mc_addr, pptr); } +if (psp->tmr_bo) + psp->tmr_mc_addr =amdgpu_bo_fb_aper_addr (psp->tmr_bo);return ret; }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, · line 1217
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3
-0@@ -1210,6 +1212,9 @@ static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, cmd->cmd.cmd_load_ta.app_phy_addr_hi =upper_32_bits (ta_bin_mc); cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes; +if (context->mem_context.shared_bo) + context->mem_context.shared_mc_addr =amdgpu_bo_fb_aper_addr (context->mem_context.shared_bo); +
Rather put this into the psp_prep_ta_load_cmd_buf() function and remove the shared_mc_addr member.
Please double check other similar cases as well.
Apart from that this looks rather good to me,
Christian.
Quoted 95 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +17
-0cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo =lower_32_bits (context->mem_context.shared_mc_addr); cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi =@@ -2336,11 +2341,26 @@ bool amdgpu_psp_tos_reload_needed(struct amdgpu_device *adev)return false; } +static void psp_update_gpu_addresses (struct amdgpu_device *adev) +{ +struct psp_context *psp = &adev->psp; + +if (psp->cmd_buf_bo && psp->cmd_buf_mem) { + psp->fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (psp->fw_pri_bo); + psp->fence_buf_mc_addr =amdgpu_bo_fb_aper_addr (psp->fence_buf_bo); + psp->cmd_buf_mc_addr =amdgpu_bo_fb_aper_addr (psp->cmd_buf_bo); + } +if (adev->firmware.rbuf && psp->km_ring.ring_mem) + psp->km_ring.ring_mem_mc_addr =amdgpu_bo_fb_aper_addr (adev->firmware.rbuf); +} +static int psp_hw_start (struct psp_context *psp) {struct amdgpu_device *adev = psp->adev;int ret; +psp_update_gpu_addresses (adev); +if (!amdgpu_sriov_vf (adev)) {if ((is_psp_fw_valid (psp->kdb)) && (psp->funcs->bootloader_load_kdb !=NULL )) {@@ -3976,6 +3996,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,memcpy_toio (fw_pri_cpu_addr, usbc_pd_fw->data, usbc_pd_fw->size);mutex_lock (&adev->psp.mutex); + fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (fw_buf_bo); ret =psp_load_usbc_pd_fw (&adev->psp, fw_pri_mc_addr);mutex_unlock (&adev->psp.mutex);@@ -4085,6 +4106,7 @@ static ssize_t amdgpu_psp_vbflash_read(struct file *filp, struct kobject *kobj,memcpy_toio (fw_pri_cpu_addr, adev->psp.vbflash_tmp_buf, adev->psp.vbflash_image_size);mutex_lock (&adev->psp.mutex); + fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (fw_buf_bo); ret =psp_update_spirom (&adev->psp, fw_pri_mc_addr);mutex_unlock (&adev->psp.mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +3
-0@@ -1152,6 +1152,9 @@ int amdgpu_ucode_init_bo(struct amdgpu_device *adev) adev->firmware.max_ucodes =AMDGPU_UCODE_ID_MAXIMUM ; } +if (adev->firmware.fw_buf) + adev->firmware.fw_buf_mc =amdgpu_bo_fb_aper_addr (adev->firmware.fw_buf); +for (i =0 ; i < adev->firmware.max_ucodes; i++) { ucode = &adev->firmware.ucode[i];if (ucode->fw) {drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +17
-0@@ -1000,6 +1000,21 @@ static int smu_fini_fb_allocations(struct smu_context *smu)return 0 ; } +static void smu_update_gpu_addresses (struct smu_context *smu) +{ +struct smu_table_context *smu_table = &smu->smu_table; +struct smu_table *pm_status_table = smu_table->tables +SMU_TABLE_PMSTATUSLOG ; +struct smu_table *driver_table = &(smu_table->driver_table); +struct smu_table *dummy_read_1_table = &smu_table->dummy_read_1_table; + +if (pm_status_table->bo) + pm_status_table->mc_address =amdgpu_bo_fb_aper_addr (pm_status_table->bo); +if (driver_table->bo) + driver_table->mc_address =amdgpu_bo_fb_aper_addr (driver_table->bo); +if (dummy_read_1_table->bo) + dummy_read_1_table->mc_address =amdgpu_bo_fb_aper_addr (dummy_read_1_table->bo); +} +/** * smu_alloc_memory_pool - allocate memory pool in the system memory * @@ -1789,6 +1804,8 @@ static int smu_start_smc_engine(struct smu_context *smu)struct amdgpu_device *adev = smu->adev;int ret =0 ; +smu_update_gpu_addresses (smu); + smu->smc_fw_state =SMU_FW_INIT ;if (adev->firmware.load_type !=AMDGPU_FW_LOAD_PSP ) {
Re: [PATCH v2 2/3] drm/amdgpu: update GPU addresses for SMU and PSP
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, · line 1217
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3
-0@@ -1210,6 +1212,9 @@ static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, cmd->cmd.cmd_load_ta.app_phy_addr_hi =upper_32_bits (ta_bin_mc); cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes; +if (context->mem_context.shared_bo) + context->mem_context.shared_mc_addr =amdgpu_bo_fb_aper_addr (context->mem_context.shared_bo); +Rather put this into the
psp_prep_ta_load_cmd_buf()function and remove theshared_mc_addrmember.Please double check other similar cases as well.
Removing of these members are easy to change and test, since they are used in one c file. I can make one refactoring patch for each removal.
- ta_mem_context.shared_mc_addr
- amdgpu_firmware.fw_buf_mc
- psp_context.tmr_mc_addr
- psp_context.cmd_buf_mc_addr
- dummy_read_1_table->mc_address
Removing of these members will involve changes in multiple PSP and SMU version files. For versions that MI308 don't use, I don't have the environment to test the changes. Should I remove them as well? @Koenig, Christian<mailto:[email protected]>
- psp->fw_pri_mc_addr
- psp->fence_buf_mc_addr
- psp->km_ring.ring_mem_mc_addr
- driver_table->mc_address
- pm_status_table->mc_address
Thanks
Sam
From: Koenig, Christian <[email protected]>
Date: Wednesday, April 30, 2025 at 20:51
To: Zhang, GuoQing (Sam) <[email protected]>, [email protected] <[email protected]>
Cc: Zhao, Victor <[email protected]>, Chang, HaiJun <[email protected]>, Deucher, Alexander <[email protected]>, Jiang Liu <[email protected]>
Subject: Re: [PATCH v2 2/3] drm/amdgpu: update GPU addresses for SMU and PSP
Quoted 39 lines · Samuel Zhang
add
amdgpu_bo_fb_aper_addr()and update the cached GPU addresses to use the FB aperture address for SMU and PSP.2 reasons for this change:
1. when pdb0 is enabled, gpu addr fromamdgpu_bo_create_kernel()is GART aperture address, it is not compatible with SMU and PSP, it need to updated to use FB aperture address.
2. Since FB aperture address will change after switching to new GPU index after hibernation, it need to be updated after resume.Signed-off-by Jiang Liu <[email protected]>Signed-off-by Samuel Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 3 +++ drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 +++++++++++++++++ 7 files changed, 63 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-0@@ -209,6 +209,7 @@ void amdgpu_gmc_vram_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc,uint64_t vis_limit = (uint64_t )amdgpu_vis_vram_limit <<20 ;uint64_t limit = (uint64_t )amdgpu_vram_limit <<20 ; + mc->vram_offset = base; mc->vram_start = base; mc->vram_end = mc->vram_start + mc->mc_vram_size -1 ;if (limit < mc->real_vram_size)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h struct amdgpu_gmc { · line 254
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1
-0@@ -251,6 +251,7 @@ struct amdgpu_gmc {*/ u64 vram_start;u64 vram_end; +u64 vram_offset;
Please don't add any new fields here. We should already have all the necessary information in that structure.
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0
-0/* FB region , it's same as local vram region in single GPU, in XGMI * configuration, this region covers all GPUs in the same hive , * each GPU in the hive has the same view of this FB region . drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-0@@ -1513,6 +1513,24 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)return amdgpu_bo_gpu_offset_no_check (bo); } +/** +* amdgpu_bo_fb_aper_addr - return FB aperture GPU offset of the VRAM bo +* @bo: amdgpu VRAM buffer object for which we query the offset +* +* Returns:
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1530
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +10
-0+* current FB aperture GPU offset of the object. +*/ +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +uint64_t offset; + +WARN_ON_ONCE (bo->tbo.resource->mem_type !=TTM_PL_VRAM ); + + offset = (bo->tbo.resource->start <<PAGE_SHIFT ) + adev->gmc.vram_offset;
Rather use fb_base + XGMI hive index here.
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0+return amdgpu_gmc_sign_extend (offset); +} +/** * amdgpu_bo_gpu_offset_no_check - return GPU offset of bo * @bo: amdgpu object for which we query the offset drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1
-0@@ -320,6 +320,7 @@ int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv, bool intr);int amdgpu_bo_sync_wait (struct amdgpu_bo *bo,void *owner,bool intr);u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo); +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo);u64 amdgpu_bo_gpu_offset_no_check (struct amdgpu_bo *bo);uint32_t amdgpu_bo_mem_stats_placement (struct amdgpu_bo *bo); uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2
-0@@ -871,6 +871,8 @@ static int psp_tmr_init(struct psp_context *psp) &psp->tmr_bo, &psp->tmr_mc_addr, pptr); } +if (psp->tmr_bo) + psp->tmr_mc_addr =amdgpu_bo_fb_aper_addr (psp->tmr_bo);return ret; }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, · line 1217
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3
-0@@ -1210,6 +1212,9 @@ static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, cmd->cmd.cmd_load_ta.app_phy_addr_hi =upper_32_bits (ta_bin_mc); cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes; +if (context->mem_context.shared_bo) + context->mem_context.shared_mc_addr =amdgpu_bo_fb_aper_addr (context->mem_context.shared_bo); +
Rather put this into the psp_prep_ta_load_cmd_buf() function and remove the shared_mc_addr member.
Please double check other similar cases as well.
Apart from that this looks rather good to me,
Christian.
Quoted 95 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +17
-0cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo =lower_32_bits (context->mem_context.shared_mc_addr); cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi =@@ -2336,11 +2341,26 @@ bool amdgpu_psp_tos_reload_needed(struct amdgpu_device *adev)return false; } +static void psp_update_gpu_addresses (struct amdgpu_device *adev) +{ +struct psp_context *psp = &adev->psp; + +if (psp->cmd_buf_bo && psp->cmd_buf_mem) { + psp->fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (psp->fw_pri_bo); + psp->fence_buf_mc_addr =amdgpu_bo_fb_aper_addr (psp->fence_buf_bo); + psp->cmd_buf_mc_addr =amdgpu_bo_fb_aper_addr (psp->cmd_buf_bo); + } +if (adev->firmware.rbuf && psp->km_ring.ring_mem) + psp->km_ring.ring_mem_mc_addr =amdgpu_bo_fb_aper_addr (adev->firmware.rbuf); +} +static int psp_hw_start (struct psp_context *psp) {struct amdgpu_device *adev = psp->adev;int ret; +psp_update_gpu_addresses (adev); +if (!amdgpu_sriov_vf (adev)) {if ((is_psp_fw_valid (psp->kdb)) && (psp->funcs->bootloader_load_kdb !=NULL )) {@@ -3976,6 +3996,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,memcpy_toio (fw_pri_cpu_addr, usbc_pd_fw->data, usbc_pd_fw->size);mutex_lock (&adev->psp.mutex); + fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (fw_buf_bo); ret =psp_load_usbc_pd_fw (&adev->psp, fw_pri_mc_addr);mutex_unlock (&adev->psp.mutex);@@ -4085,6 +4106,7 @@ static ssize_t amdgpu_psp_vbflash_read(struct file *filp, struct kobject *kobj,memcpy_toio (fw_pri_cpu_addr, adev->psp.vbflash_tmp_buf, adev->psp.vbflash_image_size);mutex_lock (&adev->psp.mutex); + fw_pri_mc_addr =amdgpu_bo_fb_aper_addr (fw_buf_bo); ret =psp_update_spirom (&adev->psp, fw_pri_mc_addr);mutex_unlock (&adev->psp.mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +3
-0@@ -1152,6 +1152,9 @@ int amdgpu_ucode_init_bo(struct amdgpu_device *adev) adev->firmware.max_ucodes =AMDGPU_UCODE_ID_MAXIMUM ; } +if (adev->firmware.fw_buf) + adev->firmware.fw_buf_mc =amdgpu_bo_fb_aper_addr (adev->firmware.fw_buf); +for (i =0 ; i < adev->firmware.max_ucodes; i++) { ucode = &adev->firmware.ucode[i];if (ucode->fw) {drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +17
-0@@ -1000,6 +1000,21 @@ static int smu_fini_fb_allocations(struct smu_context *smu)return 0 ; } +static void smu_update_gpu_addresses (struct smu_context *smu) +{ +struct smu_table_context *smu_table = &smu->smu_table; +struct smu_table *pm_status_table = smu_table->tables +SMU_TABLE_PMSTATUSLOG ; +struct smu_table *driver_table = &(smu_table->driver_table); +struct smu_table *dummy_read_1_table = &smu_table->dummy_read_1_table; + +if (pm_status_table->bo) + pm_status_table->mc_address =amdgpu_bo_fb_aper_addr (pm_status_table->bo); +if (driver_table->bo) + driver_table->mc_address =amdgpu_bo_fb_aper_addr (driver_table->bo); +if (dummy_read_1_table->bo) + dummy_read_1_table->mc_address =amdgpu_bo_fb_aper_addr (dummy_read_1_table->bo); +} +/** * smu_alloc_memory_pool - allocate memory pool in the system memory * @@ -1789,6 +1804,8 @@ static int smu_start_smc_engine(struct smu_context *smu)struct amdgpu_device *adev = smu->adev;int ret =0 ; +smu_update_gpu_addresses (smu); + smu->smc_fw_state =SMU_FW_INIT ;if (adev->firmware.load_type !=AMDGPU_FW_LOAD_PSP ) {
Christian König
maintainerRe: [PATCH v2 2/3] drm/amdgpu: update GPU addresses for SMU and PSP
Quoted 35 lines · GuoQing (Sam)
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 16 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -1210,6 +1212,9 @@ static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(ta_bin_mc); cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes;Quoted 5 lines
+ if (
context->mem_context.shared_bo)+
context->mem_context.shared_mc_addr=amdgpu_bo_fb_aper_addr(context->mem_context.shared_bo);+
Quoted 5 lines
Rather put this into the
psp_prep_ta_load_cmd_buf()function and remove theshared_mc_addrmember.Please double check other similar cases as well.
Removing of these members are easy to change and test, since they are used in one c file. I can make one refactoring patch for each removal.
- ta_mem_context.shared_mc_addr
- amdgpu_firmware.fw_buf_mc
- psp_context.tmr_mc_addr
Quoted 7 lines
- psp_context.cmd_buf_mc_addr
-
dummy_read_1_table->mc_addressRemoving of these members will involve changes in multiple PSP and SMU version files. For versions that MI308 don't use, I don't have the environment to test the changes. Should I remove them as well? @Koenig, Christian <mailto:[email protected]>
Keep them as they are for now. Such cleanups can come later.
Regards,
Christian.
Quoted 246 lines
-
psp->fw_pri_mc_addr-
psp->fence_buf_mc_addr-
psp->km_ring.ring_mem_mc_addr-
driver_table->mc_address-
pm_status_table->mc_addressThanks
Sam
*From: *Koenig, Christian <[email protected]>
*Date: *Wednesday, April 30, 2025 at 20:51
*To: *Zhang, GuoQing (Sam) <[email protected]>, [email protected] <[email protected]>
*Cc: *Zhao, Victor <[email protected]>, Chang, HaiJun <[email protected]>, Deucher, Alexander <[email protected]>, Jiang Liu <[email protected]> *Subject: *Re: [PATCH v2 2/3] drm/amdgpu: update GPU addresses for SMU and PSPQuoted 39 lines · Samuel Zhang
add
amdgpu_bo_fb_aper_addr()and update the cached GPU addresses to use the FB aperture address for SMU and PSP.2 reasons for this change:
1. when pdb0 is enabled, gpu addr fromamdgpu_bo_create_kernel()is GART aperture address, it is not compatible with SMU and PSP, it need to updated to use FB aperture address.
2. Since FB aperture address will change after switching to new GPU index after hibernation, it need to be updated after resume.Signed-off-by Jiang Liu <[email protected]>Signed-off-by Samuel Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 +drivers/gpu/drm/amd/amdgpu/amdgpu_object.c| 18 ++++++++++++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_object.h| 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 3 +++ drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 +++++++++++++++++7 files changed, 63 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0@@ -209,6 +209,7 @@ void amdgpu_gmc_vram_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc, uint64_t vis_limit = (uint64_t)amdgpu_vis_vram_limit << 20; uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
+mc->vram_offset= base;
mc->vram_start= base;
mc->vram_end=mc->vram_start+mc->mc_vram_size- 1; if (limit <mc->real_vram_size)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h struct amdgpu_gmc { · line 254
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1
-0@@ -251,6 +251,7 @@ struct amdgpu_gmc {*/ u64 vram_start; u64 vram_end; + u64 vram_offset;Please don't add any new fields here. We should already have all the necessary information in that structure.
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0
-0/* FB region , it's same as local vram region in single GPU, in XGMI* configuration, this region covers all GPUs in the same hive , * each GPU in the hive has the same view of this FB region . drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -1513,6 +1513,24 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) return amdgpu_bo_gpu_offset_no_check(bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-0+/** +* amdgpu_bo_fb_aper_addr - return FB aperture GPU offset of the VRAM bo +* @bo: amdgpu VRAM buffer object for which we query the offset +* +* Returns: drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1530
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +10
-0+* current FB aperture GPU offset of the object. +*/ +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo) +{ + struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); + uint64_t offset; + + WARN_ON_ONCE(bo->tbo.resource->mem_type != TTM_PL_VRAM); + + offset = (bo->tbo.resource->start << PAGE_SHIFT) + adev->gmc.vram_offset;Rather use
fb_base+ XGMI hive index here.Quoted 34 lines
+ return
amdgpu_gmc_sign_extend(offset);drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-0+} +/**
*amdgpu_bo_gpu_offset_no_check- return GPU offset of bo
* @bo: amdgpu object for which we query the offsetdrivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1
-0@@ -320,6 +320,7 @@ int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv, bool intr); int amdgpu_bo_sync_wait(struct amdgpu_bo *bo, void *owner, bool intr); u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo); +u64 amdgpu_bo_fb_aper_addr (struct amdgpu_bo *bo); u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo); uint32_t amdgpu_bo_mem_stats_placement(struct amdgpu_bo *bo); uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2
-0@@ -871,6 +871,8 @@ static int psp_tmr_init(struct psp_context *psp) &psp->tmr_bo, &psp->tmr_mc_addr, pptr); } + if (psp->tmr_bo) + psp->tmr_mc_addr = amdgpu_bo_fb_aper_addr(psp->tmr_bo);
return ret;
}drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -1210,6 +1212,9 @@ static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd, cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(ta_bin_mc); cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes;Quoted 4 lines
+ if (context->mem_context.shared_bo)
+context->mem_context.shared_mc_addr=amdgpu_bo_fb_aper_addr(context->mem_context.shared_bo); +Rather put this into the
psp_prep_ta_load_cmd_buf()function and remove theshared_mc_addrmember.Please double check other similar cases as well.
Apart from that this looks rather good to me,
Christian.Quoted 95 lines
cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo=lower_32_bits(context->mem_context.shared_mc_addr);cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi=drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -2336,11 +2341,26 @@ bool amdgpu_psp_tos_reload_needed(struct amdgpu_device *adev) return false; }drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +13
-0+static void psp_update_gpu_addresses (struct amdgpu_device *adev) +{ + struct psp_context *psp = &adev->psp; + + if (psp->cmd_buf_bo && psp->cmd_buf_mem) { + psp->fw_pri_mc_addr = amdgpu_bo_fb_aper_addr(psp->fw_pri_bo); + psp->fence_buf_mc_addr = amdgpu_bo_fb_aper_addr(psp->fence_buf_bo); + psp->cmd_buf_mc_addr = amdgpu_bo_fb_aper_addr(psp->cmd_buf_bo); + } + if (adev->firmware.rbuf && psp->km_ring.ring_mem) + psp->km_ring.ring_mem_mc_addr = amdgpu_bo_fb_aper_addr(adev->firmware.rbuf); +} +static int
psp_hw_start(struct psp_context *psp)
{
structamdgpu_device*adev =psp->adev;
int ret;
+psp_update_gpu_addresses(adev);
+
if (!amdgpu_sriov_vf(adev)) {
if ((is_psp_fw_valid(psp->kdb)) && (psp->funcs->bootloader_load_kdb!= NULL)) {drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -3976,6 +3996,7 @@ static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev, memcpy_toio(fw_pri_cpu_addr, usbc_pd_fw->data, usbc_pd_fw->size);
mutex_lock(&adev->psp.mutex);
+fw_pri_mc_addr=amdgpu_bo_fb_aper_addr(fw_buf_bo); ret =psp_load_usbc_pd_fw(&adev->psp, fw_pri_mc_addr);mutex_unlock(&adev->psp.mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -4085,6 +4106,7 @@ static ssize_t amdgpu_psp_vbflash_read(struct file *filp, struct kobject *kobj, memcpy_toio(fw_pri_cpu_addr, adev->psp.vbflash_tmp_buf, adev->psp.vbflash_image_size);
mutex_lock(&adev->psp.mutex);
+fw_pri_mc_addr=amdgpu_bo_fb_aper_addr(fw_buf_bo); ret =psp_update_spirom(&adev->psp, fw_pri_mc_addr);mutex_unlock(&adev->psp.mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +0
-0@@ -1152,6 +1152,9 @@ int amdgpu_ucode_init_bo(struct amdgpu_device *adev) adev->firmware.max_ucodes = AMDGPU_UCODE_ID_MAXIMUM; }
+ if (adev->firmware.fw_buf)
+adev->firmware.fw_buf_mc=amdgpu_bo_fb_aper_addr(adev->firmware.fw_buf); +
for (i = 0; i <adev->firmware.max_ucodes; i++) {
ucode = &adev->firmware.ucode[i];
if (ucode->fw) {drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0@@ -1000,6 +1000,21 @@ static int smu_fini_fb_allocations(struct smu_context *smu) return 0; }drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +15
-0+static void smu_update_gpu_addresses (struct smu_context *smu) +{ + struct smu_table_context *smu_table = &smu->smu_table; + struct smu_table *pm_status_table = smu_table->tables + SMU_TABLE_PMSTATUSLOG; + struct smu_table *driver_table = &(smu_table->driver_table); + struct smu_table *dummy_read_1_table = &smu_table->dummy_read_1_table; + + if (pm_status_table->bo) + pm_status_table->mc_address = amdgpu_bo_fb_aper_addr(pm_status_table->bo); + if (driver_table->bo) + driver_table->mc_address = amdgpu_bo_fb_aper_addr(driver_table->bo); + if (dummy_read_1_table->bo) + dummy_read_1_table->mc_address = amdgpu_bo_fb_aper_addr(dummy_read_1_table->bo); +} +/**
*smu_alloc_memory_pool- allocate memory pool in the system memory *drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0
-0@@ -1789,6 +1804,8 @@ static int smu_start_smc_engine(struct smu_context *smu) struct amdgpu_device *adev = smu->adev; int ret = 0;
+smu_update_gpu_addresses(smu);
+
smu->smc_fw_state=SMU_FW_INIT;
if (adev->firmware.load_type!=AMDGPU_FW_LOAD_PSP) {
PATCH v2 3/3 drm/amdgpu: enable pdb0 for hibernation on SRIOV
In reply to Samuel ZhangWhen switching to new GPU index after hibernation and then resume, VRAM offset of each VRAM BO will be changed, and the cached gpu addresses needed to updated.
This is to enable pdb0 and switch to use pdb0-based virtual gpu address by default in amdgpu_bo_create_reserved(). since the virtual addresses do not change, this can avoid the need to update all cached gpu addresses all over the codebase.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 42 ++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 16 ++++++--- 4 files changed, 46 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +32 -10
@@ -38,6 +38,8 @@#include <drm/drm_drv.h> #include <drm/ttm/ttm_tt.h> +static const u64 four_gb =0x100000000ULL ; +/** * amdgpu_gmc_pdb0_alloc - allocate vram for pdb0 *
@@ -250,15 +252,26 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc {u64 hive_vram_start =0 ;u64 hive_vram_end = mc->xgmi.node_segment_size * mc->xgmi.num_physical_nodes -1 ; - mc->vram_start = mc->xgmi.node_segment_size * mc->xgmi.physical_node_id; - mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size -1 ; + +if (adev->gmc.xgmi.connected_to_cpu) { + mc->vram_start = mc->xgmi.node_segment_size * mc->xgmi.physical_node_id; + mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size -1 ; +dev_info (adev->dev,"VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n" , + mc->mc_vram_size >>20 , mc->vram_start, + mc->vram_end, mc->real_vram_size >>20 ); + }else { +/* reset vram_start to 0 to switch the returned GPU address of +* amdgpu_bo_create_reserved() from FB aperture to GART aperture. +*/ + mc->vram_start =0 ; + hive_vram_end =ALIGN (hive_vram_end +1 , four_gb) -1 ; + } + mc->gart_start = hive_vram_end +1 ; mc->gart_end = mc->gart_start + mc->gart_size -1 ; mc->fb_start = hive_vram_start; mc->fb_end = hive_vram_end; -dev_info (adev->dev,"VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n" , - mc->mc_vram_size >>20 , mc->vram_start, - mc->vram_end, mc->real_vram_size >>20 ); +dev_info (adev->dev,"GART: %lluM 0x%016llX - 0x%016llX\n" , mc->gart_size >>20 , mc->gart_start, mc->gart_end); }
@@ -277,7 +290,6 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mcvoid amdgpu_gmc_gart_location (struct amdgpu_device *adev,struct amdgpu_gmc *mc,enum amdgpu_gart_placement gart_placement) { -const uint64_t four_gb =0x100000000ULL ;u64 size_af, size_bf;/*To avoid the hole, limit the max mc address to AMDGPU_GMC_HOLE_START*/ u64 max_mc_address =min (adev->gmc.mc_mask,AMDGPU_GMC_HOLE_START -1 );
@@ -678,8 +690,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid, &job);if (r) goto error_alloc; - - job->vm_pd_addr =amdgpu_gmc_pd_addr (adev->gart.bo); + job->vm_pd_addr =amdgpu_gmc_pd_addr (adev->gmc.pdb0_bo ?: adev->gart.bo); job->vm_needs_flush = true; job->ibs->ptr[job->ibs->length_dw++] = ring->funcs->nop;amdgpu_ring_pad_ib (ring, &job->ibs[0 ]);
@@ -1057,6 +1068,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)u64 vram_addr = adev->vm_manager.vram_base_offset - adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;u64 vram_end = vram_addr + vram_size; +u64 vram_last = vram_end, vram_pa;u64 gart_ptb_gpu_pa =amdgpu_gmc_vram_pa (adev, adev->gart.bo);int idx;
@@ -1069,11 +1081,21 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) flags |=AMDGPU_PTE_FRAG ((adev->gmc.vmid0_page_table_block_size +9 *1 )); flags |=AMDGPU_PDE_PTE_FLAG (adev); +if (!adev->gmc.xgmi.connected_to_cpu) { +/* always start from current device so that the GART address can keep +* consistent when hibernate-resume with different GPUs. +*/ + vram_addr = adev->vm_manager.vram_base_offset; + vram_end = vram_addr + vram_size; + } +/* The first n PDE0 entries are used as PTE, * pointing to vram */ -for (i =0 ; vram_addr < vram_end; i++, vram_addr += pde0_page_size) -amdgpu_gmc_set_pte_pde (adev, adev->gmc.ptr_pdb0, i, vram_addr, flags); +for (i =0 ; vram_addr < vram_end; i++, vram_addr += pde0_page_size) { + vram_pa = (vram_addr >= vram_last) ? (vram_addr - vram_size) : vram_addr; +amdgpu_gmc_set_pte_pde (adev, adev->gmc.ptr_pdb0, i, vram_pa, flags); + }/* The n+1'th PDE0 entry points to a huge * PTB who has more than 512 entries each
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1 -0
@@ -308,6 +308,7 @@ struct amdgpu_gmc {struct amdgpu_bo *pdb0_bo;/* CPU kmapped address of pdb0*/ void *ptr_pdb0; +bool enable_pdb0;/* MALL size */ u64 mall_size;
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1 -1
@@ -180,7 +180,7 @@ gfxhub_v1_2_xcc_init_system_aperture_regs(struct amdgpu_device *adev,/* In the case squeezing vram into GART aperture, we don't use * FB aperture and AGP aperture. Disable them. */ -if (adev->gmc.pdb0_bo) { +if (adev->gmc.pdb0_bo && !amdgpu_sriov_vf (adev)) {WREG32_SOC15 (GC ,GET_INST (GC , i), regMC_VM_FB_LOCATION_TOP,0 );WREG32_SOC15 (GC ,GET_INST (GC , i), regMC_VM_FB_LOCATION_BASE,0x00FFFFFF );WREG32_SOC15 (GC ,GET_INST (GC , i), regMC_VM_AGP_TOP,0 );
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +12 -4
@@ -1682,6 +1682,11 @@ static int gmc_v9_0_early_init(struct amdgpu_ip_block *ip_block) adev->gmc.private_aperture_start + (4ULL <<30 ) -1 ; adev->gmc.noretry_flags =AMDGPU_VM_NORETRY_FLAGS_TF ; + adev->gmc.enable_pdb0 = adev->gmc.xgmi.connected_to_cpu; +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,3 ) || +amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,4 ) || +amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,5 ,0 )) + adev->gmc.enable_pdb0 =amdgpu_sriov_vf (adev);return 0 ; }
@@ -1730,7 +1735,10 @@ static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev,amdgpu_gmc_sysvm_location (adev, mc); }else {amdgpu_gmc_vram_location (adev, mc, base); -amdgpu_gmc_gart_location (adev, mc,AMDGPU_GART_PLACEMENT_BEST_FIT ); +if (adev->gmc.enable_pdb0) +amdgpu_gmc_sysvm_location (adev, mc); +else +amdgpu_gmc_gart_location (adev, mc,AMDGPU_GART_PLACEMENT_BEST_FIT );if (!amdgpu_sriov_vf (adev) && (amdgpu_agp ==1 ))amdgpu_gmc_agp_location (adev, mc); }
@@ -1841,7 +1849,7 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)return 0 ; } -if (adev->gmc.xgmi.connected_to_cpu) { +if (adev->gmc.enable_pdb0) { adev->gmc.vmid0_page_table_depth =1 ; adev->gmc.vmid0_page_table_block_size =12 ; }else {
@@ -1867,7 +1875,7 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)if (r)return r; -if (adev->gmc.xgmi.connected_to_cpu) +if (adev->gmc.enable_pdb0) r =amdgpu_gmc_pdb0_alloc (adev); }
@@ -2372,7 +2380,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev) {int r; -if (adev->gmc.xgmi.connected_to_cpu) +if (adev->gmc.enable_pdb0)amdgpu_gmc_init_pdb0 (adev);if (adev->gart.bo ==NULL ) {
Signature · 1 line
2.43.5
Christian König
maintainerRe: [PATCH v2 3/3] drm/amdgpu: enable pdb0 for hibernation on SRIOV
Quoted 39 lines · Samuel Zhang
When switching to new GPU index after hibernation and then resume, VRAM offset of each VRAM BO will be changed, and the cached gpu addresses needed to updated.
This is to enable pdb0 and switch to use pdb0-based virtual gpu address by default in
amdgpu_bo_create_reserved(). since the virtual addresses do not change, this can avoid the need to update all cached gpu addresses all over the codebase.Signed-off-by Emily Deng <[email protected]>Signed-off-by Samuel Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 42 ++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 16 ++++++--- 4 files changed, 46 insertions(+), 15 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4
-2@@ -38,6 +38,8 @@#include <drm/drm_drv.h> #include <drm/ttm/ttm_tt.h> +static const u64 four_gb =0x100000000ULL ; +/** * amdgpu_gmc_pdb0_alloc - allocate vram for pdb0 * @@ -250,15 +252,26 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc {u64 hive_vram_start =0 ;u64 hive_vram_end = mc->xgmi.node_segment_size * mc->xgmi.num_physical_nodes -1 ; - mc->vram_start = mc->xgmi.node_segment_size * mc->xgmi.physical_node_id; - mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size -1 ; + +if (adev->gmc.xgmi.connected_to_cpu) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc · line 266
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +10
-0+ mc->vram_start = mc->xgmi.node_segment_size * mc->xgmi.physical_node_id; + mc->vram_end = mc->vram_start + mc->xgmi.node_segment_size -1 ; +dev_info (adev->dev,"VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n" , + mc->mc_vram_size >>20 , mc->vram_start, + mc->vram_end, mc->real_vram_size >>20 ); + }else { +/* reset vram_start to 0 to switch the returned GPU address of +* amdgpu_bo_create_reserved() from FB aperture to GART aperture. +*/ + mc->vram_start =0 ;
You need to setup mc->vram_end here as well.
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc · line 267
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-0+ hive_vram_end =ALIGN (hive_vram_end +1 , four_gb) -1 ;
Don't touch hive_vram_end here. When this isn't 4GiB aligned we have a problem with node_segment_size.
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc · line 261
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2
-3+ } + mc->gart_start = hive_vram_end +1 ; mc->gart_end = mc->gart_start + mc->gart_size -1 ; mc->fb_start = hive_vram_start; mc->fb_end = hive_vram_end; -dev_info (adev->dev,"VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n" , - mc->mc_vram_size >>20 , mc->vram_start, - mc->vram_end, mc->real_vram_size >>20 );
Please keep that print here
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-1+dev_info (adev->dev,"GART: %lluM 0x%016llX - 0x%016llX\n" , mc->gart_size >>20 , mc->gart_start, mc->gart_end); }@@ -277,7 +290,6 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mcvoid amdgpu_gmc_gart_location (struct amdgpu_device *adev,struct amdgpu_gmc *mc,enum amdgpu_gart_placement gart_placement) { -const uint64_t four_gb =0x100000000ULL ;u64 size_af, size_bf;/*To avoid the hole, limit the max mc address to AMDGPU_GMC_HOLE_START*/ u64 max_mc_address =min (adev->gmc.mc_mask,AMDGPU_GMC_HOLE_START -1 );
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid, · line 693
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-2@@ -678,8 +690,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid, &job);if (r) goto error_alloc; - - job->vm_pd_addr =amdgpu_gmc_pd_addr (adev->gart.bo); + job->vm_pd_addr =amdgpu_gmc_pd_addr (adev->gmc.pdb0_bo ?: adev->gart.bo);
Move that change into a separate patch.
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +8
-0job->vm_needs_flush = true; job->ibs->ptr[job->ibs->length_dw++] = ring->funcs->nop;amdgpu_ring_pad_ib (ring, &job->ibs[0 ]);@@ -1057,6 +1068,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)u64 vram_addr = adev->vm_manager.vram_base_offset - adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;u64 vram_end = vram_addr + vram_size; +u64 vram_last = vram_end, vram_pa;u64 gart_ptb_gpu_pa =amdgpu_gmc_vram_pa (adev, adev->gart.bo);int idx;@@ -1069,11 +1081,21 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) flags |=AMDGPU_PTE_FRAG ((adev->gmc.vmid0_page_table_block_size +9 *1 )); flags |=AMDGPU_PDE_PTE_FLAG (adev); +if (!adev->gmc.xgmi.connected_to_cpu) { +/* always start from current device so that the GART address can keep +* consistent when hibernate-resume with different GPUs. +*/ + vram_addr = adev->vm_manager.vram_base_offset; + vram_end = vram_addr + vram_size; + }
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev) · line 1098
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +5
-2+/* The first n PDE0 entries are used as PTE, * pointing to vram */ -for (i =0 ; vram_addr < vram_end; i++, vram_addr += pde0_page_size) -amdgpu_gmc_set_pte_pde (adev, adev->gmc.ptr_pdb0, i, vram_addr, flags); +for (i =0 ; vram_addr < vram_end; i++, vram_addr += pde0_page_size) { + vram_pa = (vram_addr >= vram_last) ? (vram_addr - vram_size) : vram_addr; +amdgpu_gmc_set_pte_pde (adev, adev->gmc.ptr_pdb0, i, vram_pa, flags); + }
Hui? That doesn't seem to make any sense.
Quoted 45 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0/* The n+1'th PDE0 entry points to a huge * PTB who has more than 512 entries each drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1
-0@@ -308,6 +308,7 @@ struct amdgpu_gmc {struct amdgpu_bo *pdb0_bo;/* CPU kmapped address of pdb0*/ void *ptr_pdb0; +bool enable_pdb0;/* MALL size */ u64 mall_size;drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1
-1@@ -180,7 +180,7 @@ gfxhub_v1_2_xcc_init_system_aperture_regs(struct amdgpu_device *adev,/* In the case squeezing vram into GART aperture, we don't use * FB aperture and AGP aperture. Disable them. */ -if (adev->gmc.pdb0_bo) { +if (adev->gmc.pdb0_bo && !amdgpu_sriov_vf (adev)) {WREG32_SOC15 (GC ,GET_INST (GC , i), regMC_VM_FB_LOCATION_TOP,0 );WREG32_SOC15 (GC ,GET_INST (GC , i), regMC_VM_FB_LOCATION_BASE,0x00FFFFFF );WREG32_SOC15 (GC ,GET_INST (GC , i), regMC_VM_AGP_TOP,0 );drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5
-0@@ -1682,6 +1682,11 @@ static int gmc_v9_0_early_init(struct amdgpu_ip_block *ip_block) adev->gmc.private_aperture_start + (4ULL <<30 ) -1 ; adev->gmc.noretry_flags =AMDGPU_VM_NORETRY_FLAGS_TF ; + adev->gmc.enable_pdb0 = adev->gmc.xgmi.connected_to_cpu; +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,3 ) || +amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,4 ) || +amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,5 ,0 )) + adev->gmc.enable_pdb0 =amdgpu_sriov_vf (adev);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev, · line 1741
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4
-1@@ -1730,7 +1735,10 @@ static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev,amdgpu_gmc_sysvm_location (adev, mc); }else {amdgpu_gmc_vram_location (adev, mc, base); -amdgpu_gmc_gart_location (adev, mc,AMDGPU_GART_PLACEMENT_BEST_FIT ); +if (adev->gmc.enable_pdb0) +amdgpu_gmc_sysvm_location (adev, mc); +else +amdgpu_gmc_gart_location (adev, mc,AMDGPU_GART_PLACEMENT_BEST_FIT );
That is nonsense. You need to adjust the if above and not here.
The amdgpu_gmc_vram_location() function should never be called when PDB0 is in use.
Regards,
Christian.
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +3
-3if (!amdgpu_sriov_vf (adev) && (amdgpu_agp ==1 ))amdgpu_gmc_agp_location (adev, mc); }@@ -1841,7 +1849,7 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)return 0 ; } -if (adev->gmc.xgmi.connected_to_cpu) { +if (adev->gmc.enable_pdb0) { adev->gmc.vmid0_page_table_depth =1 ; adev->gmc.vmid0_page_table_block_size =12 ; }else {@@ -1867,7 +1875,7 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)if (r)return r; -if (adev->gmc.xgmi.connected_to_cpu) +if (adev->gmc.enable_pdb0) r =amdgpu_gmc_pdb0_alloc (adev); }@@ -2372,7 +2380,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev) {int r; -if (adev->gmc.xgmi.connected_to_cpu) +if (adev->gmc.enable_pdb0)amdgpu_gmc_init_pdb0 (adev);if (adev->gart.bo ==NULL ) {