drm/amdgpu: set the A+A VF SYSTEM bit in the GFX 12.1 helpers
Subsystems (2)
PATCH 4/7 drm/amdgpu: set the A+A VF SYSTEM bit in the GFX 12.1 helpers
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.
--- drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +18 -0
@@ -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 ; } }
Signature · 1 line
2.43.0
PATCH 7/7 drm/amdgpu: keep the A+A VF VRAM base at the SRAT address
On the A+A VF the hypervisor reports each VF's VRAM address and length in the ACPI SRAT table. The XGMI LFB region and segment registers describe the physical GPU, not the VF, so the node id and segment read from those registers are not a valid VRAM starting address.
Read the SRAT length in mmhub_v4_2_0_get_xgmi_info() and report the VF as one physical node at id 0 whose segment is that length. get_mc_fb_offset() reads the SRAT address on each call. mc_init copies that address, plus the node product, into aper_base and sets aper_size from the segment. Node id 0 makes the product zero, so the PTE base stays at the SRAT address.
v2:
- Explain that the SRAT address is already the VF VRAM base and must not be adjusted by the XGMI node segment.
v3:
- Report the VF as XGMI node 0 of 1 instead of special-casing the node offset and the PDB0 size.
v4:
- Read SRAT in get_xgmi_info() and derive aper_base and aper_size from the FB offset and the segment size.
- Move the 8GB GART alignment into its own patch.
v5:
- Revert the SRAT aperture commit with the other two reverts. Leave mc_init on the restored connected_to_cpu path.
v6:
- Read the SRAT address in both get_mc_fb_offset() helpers on each call instead of caching it. Keep the SRAT length as the segment size.
- PDB0 is already enabled because the VF is CPU-connected. Leave amdgpu_gmc_is_pdb0_enabled() unchanged.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 8 +++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 16 ++++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 38 +++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +5 -3
@@ -79,11 +79,13 @@ struct amdgpu_xgmi {/* from psp */ u64 node_id;u64 hive_id; -/* fixed per family */ +/* Segment size. Fixed per family on a hive. On an SPM VF this is +* the SRAT length of that one VF. +*/ u64 node_segment_size; -/* physical node (0-3) */ +/* Physical node, 0-3. An SPM VF is node 0. */ unsigned physical_node_id; -/* number of nodes (0-4) */ +/* Number of nodes, 0-4. An SPM VF reports one node. */ unsigned num_physical_nodes;/* gpu list in the same hive */ struct list_head head;
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +16 -0
@@ -53,6 +53,22 @@ static u64 gfxhub_v12_1_get_fb_location(struct amdgpu_device *adev)static u64 gfxhub_v12_1_get_mc_fb_offset (struct amdgpu_device *adev) { +/* SPM VRAM starts at the SRAT address. */ +if (amdgpu_virt_vram_is_spm (adev)) { +u64 fb_offset, seg_size; +int r; + + r =amdgpu_acpi_find_gpu_memory_in_srat (adev, &fb_offset, + &seg_size); +if (r) { +dev_err (adev->dev, +"Failed to find SPM VRAM in SRAT: %d\n" , r); +return 0 ; + } + +return fb_offset; + } +return (u64)(RREG32_SOC15 (GC ,GET_INST (GC ,0 ), regGCMC_VM_FB_OFFSET) <<24 ); }
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -1
@@ -707,7 +707,7 @@ static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,amdgpu_gmc_agp_location (adev, mc); }/* base offset of vram pages */ -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) && !amdgpu_virt_vram_is_spm (adev)) adev->vm_manager.vram_base_offset =0 ;else adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset (adev);
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +38 -0
@@ -132,6 +132,26 @@ static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)if (!adev->gmc.xgmi.connected_to_cpu)return 0 ; +/* The SRAT entry is the VF's whole VRAM. PF_LFB_REGION describes +* the physical GPU, not the VF, so report a single node. The +* length is the segment size. get_mc_fb_offset() reads the +* address later. +*/ +if (amdgpu_virt_vram_is_spm (adev)) { +u64 fb_offset; +int r; + + r =amdgpu_acpi_find_gpu_memory_in_srat (adev, &fb_offset, + &seg_size); +if (r) +return r; + + adev->gmc.xgmi.num_physical_nodes =1 ; + adev->gmc.xgmi.physical_node_id =0 ; + adev->gmc.xgmi.node_segment_size = seg_size; +return 0 ; + } + xgmi_lfb_cntl =RREG32_SOC15 (MMHUB ,GET_INST (MMHUB ,0 ), regMMMC_VM_XGMI_LFB_CNTL); seg_size = REG_GET_FIELD(
@@ -177,6 +197,24 @@ static u64 mmhub_v4_2_0_get_fb_location(struct amdgpu_device *adev)static u64 mmhub_v4_2_0_get_mc_fb_offset (struct amdgpu_device *adev) { +/* SPM VRAM starts at the SRAT address. mc_init copies it into +* aper_base. +*/ +if (amdgpu_virt_vram_is_spm (adev)) { +u64 fb_offset, seg_size; +int r; + + r =amdgpu_acpi_find_gpu_memory_in_srat (adev, &fb_offset, + &seg_size); +if (r) { +dev_err (adev->dev, +"Failed to find SPM VRAM in SRAT: %d\n" , r); +return 0 ; + } + +return fb_offset; + } +return (u64 )RREG32_SOC15 (MMHUB ,GET_INST (MMHUB ,0 ), regMMMC_VM_FB_OFFSET) <<24 ; }
Signature · 1 line
2.43.0
Re: [PATCH 7/7] drm/amdgpu: keep the A+A VF VRAM base at the SRAT address
Quoted 29 lines · Zhigang Luo
On the A+A VF the hypervisor reports each VF's VRAM address and length in the ACPI SRAT table. The XGMI LFB region and segment registers describe the physical GPU, not the VF, so the node id and segment read from those registers are not a valid VRAM starting address.
Read the SRAT length in
mmhub_v4_2_0_get_xgmi_info()and report the VF as one physical node at id 0 whose segment is that length.get_mc_fb_offset()reads the SRAT address on each call.mc_initcopies that address, plus the node product, intoaper_baseand setsaper_sizefrom the segment. Node id 0 makes the product zero, so the PTE base stays at the SRAT address.v2:
- Explain that the SRAT address is already the VF VRAM base and must not be adjusted by the XGMI node segment.v3:
- Report the VF as XGMI node 0 of 1 instead of special-casing the node offset and the PDB0 size.v4:
- Read SRAT inget_xgmi_info()and deriveaper_baseandaper_sizefrom the FB offset and the segment size.
- Move the 8GB GART alignment into its own patch.v5:
- Revert the SRAT aperture commit with the other two reverts. Leavemc_initon the restoredconnected_to_cpupath.
Quoted 8 lines
v6:
- Read the SRAT address in bothget_mc_fb_offset()helpers on each call instead of caching it. Keep the SRAT length as the segment size.
- PDB0 is already enabled because the VF is CPU-connected. Leaveamdgpu_gmc_is_pdb0_enabled()unchanged.Signed-off-by Zhigang Luo <[email protected]>
The handling in gmc_v12_0_vram_gtt_location() needs some more cleanup, but that wasn't messed up by this patch in the first place.
Sorry for the delay,
Christian.
Quoted 124 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 8 +++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 16 ++++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 38 +++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +5
-3@@ -79,11 +79,13 @@ struct amdgpu_xgmi {/* from psp */ u64 node_id;u64 hive_id; -/* fixed per family */ +/* Segment size. Fixed per family on a hive. On an SPM VF this is +* the SRAT length of that one VF. +*/ u64 node_segment_size; -/* physical node (0-3) */ +/* Physical node, 0-3. An SPM VF is node 0. */ unsigned physical_node_id; -/* number of nodes (0-4) */ +/* Number of nodes, 0-4. An SPM VF reports one node. */ unsigned num_physical_nodes;/* gpu list in the same hive */ struct list_head head;drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +16
-0@@ -53,6 +53,22 @@ static u64 gfxhub_v12_1_get_fb_location(struct amdgpu_device *adev)static u64 gfxhub_v12_1_get_mc_fb_offset (struct amdgpu_device *adev) { +/* SPM VRAM starts at the SRAT address. */ +if (amdgpu_virt_vram_is_spm (adev)) { +u64 fb_offset, seg_size; +int r; + + r =amdgpu_acpi_find_gpu_memory_in_srat (adev, &fb_offset, + &seg_size); +if (r) { +dev_err (adev->dev, +"Failed to find SPM VRAM in SRAT: %d\n" , r); +return 0 ; + } + +return fb_offset; + } +return (u64)(RREG32_SOC15 (GC ,GET_INST (GC ,0 ), regGCMC_VM_FB_OFFSET) <<24 ); }drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1
-1@@ -707,7 +707,7 @@ static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,amdgpu_gmc_agp_location (adev, mc); }/* base offset of vram pages */ -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) && !amdgpu_virt_vram_is_spm (adev)) adev->vm_manager.vram_base_offset =0 ;else adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset (adev);drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +38
-0@@ -132,6 +132,26 @@ static int mmhub_v4_2_0_get_xgmi_info(struct amdgpu_device *adev)if (!adev->gmc.xgmi.connected_to_cpu)return 0 ; +/* The SRAT entry is the VF's whole VRAM. PF_LFB_REGION describes +* the physical GPU, not the VF, so report a single node. The +* length is the segment size. get_mc_fb_offset() reads the +* address later. +*/ +if (amdgpu_virt_vram_is_spm (adev)) { +u64 fb_offset; +int r; + + r =amdgpu_acpi_find_gpu_memory_in_srat (adev, &fb_offset, + &seg_size); +if (r) +return r; + + adev->gmc.xgmi.num_physical_nodes =1 ; + adev->gmc.xgmi.physical_node_id =0 ; + adev->gmc.xgmi.node_segment_size = seg_size; +return 0 ; + } + xgmi_lfb_cntl =RREG32_SOC15 (MMHUB ,GET_INST (MMHUB ,0 ), regMMMC_VM_XGMI_LFB_CNTL); seg_size = REG_GET_FIELD(@@ -177,6 +197,24 @@ static u64 mmhub_v4_2_0_get_fb_location(struct amdgpu_device *adev)static u64 mmhub_v4_2_0_get_mc_fb_offset (struct amdgpu_device *adev) { +/* SPM VRAM starts at the SRAT address. mc_init copies it into +* aper_base. +*/ +if (amdgpu_virt_vram_is_spm (adev)) { +u64 fb_offset, seg_size; +int r; + + r =amdgpu_acpi_find_gpu_memory_in_srat (adev, &fb_offset, + &seg_size); +if (r) { +dev_err (adev->dev, +"Failed to find SPM VRAM in SRAT: %d\n" , r); +return 0 ; + } + +return fb_offset; + } +return (u64 )RREG32_SOC15 (MMHUB ,GET_INST (MMHUB ,0 ), regMMMC_VM_FB_OFFSET) <<24 ; }
Quoted 13 lines · Zhigang Luo
gmc_v12_1_get_vm_pde()converts a VRAM MC address to a physical address and skips that conversion whenAMDGPU_PTE_SYSTEMis 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, andsvm_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.
Quoted 5 lines
v3:
- Set S only whenAMDGPU_PTE_VALIDis already set, so PRT, clears, and NPA stay unchanged.Signed-off-by Zhigang Luo <[email protected]>
Quoted 47 lines
--- drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +18
-0@@ -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 ; } }