PDB0 is written directly and does not go through get_vm_pte(). Route
both entries through amdgpu_gmc_get_vm_pde() so they take the same
SYSTEM-bit path as every other GFX 12.1 mapping.

The VRAM entries are PDE_PTEs and already hold a physical address, so
the translation is skipped and S is set for SPM. The GART PDE is given
the GART BO's MC address and translated once.

Signed-off-by: Zhigang Luo <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index 659e89e5e78f..04cf02dd22ac 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -1272,7 +1272,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
        u64 vram_size = adev->gmc.xgmi.node_segment_size * 
adev->gmc.xgmi.num_physical_nodes;
        u64 pde0_page_size = (1ULL<<adev->gmc.vmid0_page_table_block_size)<<21;
        u64 vram_addr, vram_end;
-       u64 gart_ptb_gpu_pa = amdgpu_gmc_vram_pa(adev, adev->gart.bo);
+       u64 pde_addr, pde_flags;
        int idx;
 
        if (!drm_dev_enter(adev_to_drm(adev), &idx))
@@ -1290,10 +1290,16 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
        vram_end = vram_addr + vram_size;
 
        /* The first n PDE0 entries are used as PTE,
-        * pointing to vram
+        * pointing to vram. PDE_PTE already holds a physical address, so
+        * get_vm_pde() skips translation and sets S for SPM.
         */
-       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) {
+               pde_addr = vram_addr;
+               pde_flags = flags;
+               amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr, 
&pde_flags);
+               amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr,
+                                      pde_flags);
+       }
 
        /* The n+1'th PDE0 entry points to a huge
         * PTB who has more than 512 entries each
@@ -1301,8 +1307,12 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
         */
        flags = AMDGPU_PTE_VALID;
        flags |= AMDGPU_PTE_SNOOPED | AMDGPU_PDE_BFS_FLAG(adev, 0);
-       /* Requires gart_ptb_gpu_pa to be 4K aligned */
-       amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, gart_ptb_gpu_pa, 
flags);
+       /* MC address. get_vm_pde() translates it once and sets S for SPM.
+        * Requires the GART PT to be 4K aligned.
+        */
+       pde_addr = amdgpu_bo_gpu_offset(adev->gart.bo);
+       amdgpu_gmc_get_vm_pde(adev, AMDGPU_VM_PDB0, &pde_addr, &flags);
+       amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, pde_addr, flags);
        drm_dev_exit(idx);
 }
 
-- 
2.43.0

Reply via email to