gmc_v12_1_get_vm_pde() converts a VRAM MC address to a physical address and skips that conversion when AMDGPU_PTE_SYSTEM is already set. Set the bit after the translation so the address stays physical.
gmc_v12_1_get_vm_pte() sets the bit for a VRAM buffer object. SVM calls it with a NULL buffer object, and svm_range_get_pte_flags() sets the bit only for system memory, so the NULL case sets it for SPM VRAM. NPA mappings are left unchanged. v2: - Set the bit for a VRAM BO inside if (bo), and for the SVM NULL BO in the else. v3: - Set S only when AMDGPU_PTE_VALID is already set, so PRT, clears, and NPA stay unchanged. Signed-off-by: Zhigang Luo <[email protected]> --- drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c index 76391fca6c62..507a9c52ccd1 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c @@ -586,6 +586,13 @@ static void gmc_v12_1_get_vm_pde(struct amdgpu_device *adev, int level, *addr = adev->vm_manager.vram_base_offset + *addr - adev->gmc.vram_start; + /* SPM VRAM is reached at a system physical address. Set S after the + * translation above so that translation is not skipped. A cleared + * PDE or an NPA leaf has VALID clear and keeps S clear. + */ + if (amdgpu_virt_vram_is_spm(adev) && (*flags & AMDGPU_PTE_VALID)) + *flags |= AMDGPU_PTE_SYSTEM; + if (*addr & ~adev->gmc.pte_addr_mask) { dev_err(adev->dev, "Invalid PDE address: %llx\n", *addr); *addr = 0; @@ -758,6 +765,11 @@ static void gmc_v12_1_get_vm_pte(struct amdgpu_device *adev, if (bo) { mem = bo->tbo.resource; + if (amdgpu_virt_vram_is_spm(adev) && + (*flags & AMDGPU_PTE_VALID) && + mem && mem->mem_type == TTM_PL_VRAM) + *flags |= AMDGPU_PTE_SYSTEM; + if (mem && mem->mem_type == AMDGPU_PL_NPA) { dev_dbg(adev->dev, "Setting PTE for NPA BO, mem->type: %d, mem->start: %lx, mem->size: %u, cur_flags: %llx\n", @@ -766,6 +778,12 @@ static void gmc_v12_1_get_vm_pte(struct amdgpu_device *adev, } else if (*flags & AMDGPU_PTE_VALID) { gmc_v12_1_get_coherence_flags(adev, bo, flags); } + } else if (amdgpu_virt_vram_is_spm(adev) && + (*flags & AMDGPU_PTE_VALID)) { + /* SVM has no BO and sets VALID first. System memory already + * has S. PRT and a clear have VALID clear and stay unchanged. + */ + *flags |= AMDGPU_PTE_SYSTEM; } } -- 2.43.0
