drm/amdgpu: program the SH_MEM registers of the SPM VMID
Subsystems (2)
PATCH 1/6 drm/amdgpu: program the SH_MEM registers of the SPM VMID
Commit 02232367be23 ("drm/amdgpu: add spm_vmid and exclude it from the MES, KFD and kq pools") took the SPM VMID out of the kernel queue and the user queue VMID masks, and since commit 8a9263fc8812 ("drm/amdgpu: use dedicated SPM VMID from the reserved path") the kernel queue jobs of a VM with a reserved VMID run on it. The gfx constants_init() only programs SH_MEM_CONFIG and SH_MEM_BASES for VMID 0 and the kernel queue mask though, and init_compute_vmid() for the user queue mask, so the SPM VMID keeps the reset defaults: no unaligned access mode and no apertures.
On navi48 VMID 15 has SH_MEM_CONFIG 0xc000 and SH_MEM_BASES 0 while the other graphics VMIDs have 0xc00c and 0x20001000. A shader storing a dword to an address with a byte offset of 1 writes it there in a normal process, but at the dword aligned address in one which reserved a VMID, e.g. for profiling with SPM:
$ umr -i 0 -sb 0 0 0 15 -r '*.*.regSH_MEM_CONFIG' gfx1201.regSH_MEM_CONFIG => 0x0000c000 $ amd_uapi_regression --run-subtest reserved-vmid-unaligned-store unaligned store: 0x0000000000002a00 normally, 0x000000000000002a with a reserved VMID
Add amdgpu_vmid_kq_mask() for VMID 0 and the kernel queue VMIDs of a hub, including the SPM VMID on the GFXHUB, and walk it in for_each_vmid_and_zero(), so the constants_init() of all gfx generations program the SPM VMID like the other kernel queue VMIDs. The mask is only used for the register initialization, the VMID allocation pool stays unchanged.
v2: split out of the SPM VMID series, the per generation consolidation
of the SH_MEM initialization follows (Alex)
build the walked mask with amdgpu_vmid_kq_mask(), which the consolidation reuses
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +22 -8
@@ -36,23 +36,37 @@#define AMDGPU_NUM_VMID 16/** -* for_each_vmid_and_zero - iterate over VMID 0 plus every VMID set in a hub's -* vmid_mask +* amdgpu_vmid_kq_mask - VMIDs the kernel queues of a hub run on +* @adev: struct amdgpu_device * +* @hub: vmhub index into adev->vm_manager.id_mgr[] +* +* VMID 0, the VMIDs of the hub's kernel queue pool and, on the GFXHUB, the +* dedicated SPM VMID, which is kept out of the pool but runs the kernel queue +* jobs of the VM reserving it. Only builds a mask for the register +* initialization, the VMID allocation pool is not changed. +*/ +#define amdgpu_vmid_kq_mask (adev, hub) \ + ((adev)->vm_manager.id_mgr[(hub)].vmid_mask[0] | BIT(0) | \ + ((hub) == AMDGPU_GFXHUB(0) && (adev)->vm_manager.spm_vmid ? \ + BIT((adev)->vm_manager.spm_vmid) : 0)) + +/** +* for_each_vmid_and_zero - iterate over VMID 0 and the kernel queue VMIDs of +* a hub * @vmid: loop cursor (int / unsigned int) * @adev: struct amdgpu_device * * @hub: vmhub index into adev->vm_manager.id_mgr[] * -* Equivalent to OR-ing BIT(0) into id_mgr[hub].vmid_mask and walking -* the result with for_each_set_bit(). Used by the gfx_v*_constants_init() -* paths which must always touch VMID 0 (system) in addition to the regular -* VMIDs owned by the hub. +* Iterate over VMID 0 and the hub's kernel-queue pool, including the +* dedicated SPM VMID on GFXHUB, see amdgpu_vmid_kq_mask(). Used by the +* gfx_v*_constants_init() paths which must always touch VMID 0 (system) in +* addition to the VMIDs the kernel queues of the hub run on. * * Relies on AMDGPU_NUM_VMID (16) fitting in a single unsigned long, i.e. * vmid_mask[] being a 1-element bitmap. */ #define for_each_vmid_and_zero (vmid, adev, hub) \ - for (unsigned long __vmid_mask = \ - (adev)->vm_manager.id_mgr[(hub)].vmid_mask[0] | BIT(0); \ + for (unsigned long __vmid_mask = amdgpu_vmid_kq_mask(adev, hub); \ __vmid_mask; __vmid_mask = 0) \ for_each_set_bit((vmid), &__vmid_mask, AMDGPU_NUM_VMID)
Signature · 1 line
2.50.1
PATCH 2/6 drm/amdgpu/gfx12: consolidate SH_MEM initialization
gfx_v12_0_constants_init() programs SH_MEM_CONFIG and SH_MEM_BASES of VMID 0 and the kernel queue VMIDs, and gfx_v12_0_init_compute_vmid() those of the user queue VMIDs, each walking its own VMID mask.
Program them in one place, walking the kernel queue and the user queue VMIDs together and giving each the configuration of its users. The kernel queue VMIDs come from amdgpu_vmid_kq_mask(), like those for_each_vmid_and_zero() walks, so the SPM VMID stays with them.
No functional change.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 64 ++++++++++++-------------- 1 file changed, 30 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +30 -34
@@ -1792,32 +1792,48 @@ static void gfx_v12_0_setup_rb(struct amdgpu_device *adev)#define LDS_APP_BASE 0x1#define SCRATCH_APP_BASE 0x2 -static void gfx_v12_0_init_compute_vmid (struct amdgpu_device *adev) +/* +* Program SH_MEM_CONFIG and SH_MEM_BASES of all VMIDs in one place: the user +* queue VMIDs get the application apertures and traps enabled, the kernel +* queue VMIDs, including the SPM VMID, the GPUVM apertures. VMID 0 only gets +* SH_MEM_CONFIG, its SH_MEM_BASES is left alone. +*/ +static void gfx_v12_0_init_sh_mem (struct amdgpu_device *adev) { +unsigned long uq_mask = adev->vm_manager.vmid_uq_mask_gfxhub; +unsigned long mask =amdgpu_vmid_kq_mask (adev,AMDGPU_GFXHUB (0 )) | uq_mask; +u32 kq_bases, uq_bases, data;int i; -uint32_t sh_mem_bases; -uint32_t data; + + kq_bases =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , + adev->gmc.private_aperture_start >>48 ); + kq_bases =REG_SET_FIELD (kq_bases,SH_MEM_BASES ,SHARED_BASE , + adev->gmc.shared_aperture_start >>48 );/* -* Configure apertures: +* Configure apertures of the user queue VMIDs: * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB) * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB) * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB) */ - sh_mem_bases = (LDS_APP_BASE <<SH_MEM_BASES__SHARED_BASE__SHIFT ) | -SCRATCH_APP_BASE ; + uq_bases = (LDS_APP_BASE <<SH_MEM_BASES__SHARED_BASE__SHIFT ) | +SCRATCH_APP_BASE ;mutex_lock (&adev->srbm_mutex); -for_each_uq_gfx_vmid (i, adev) { +for_each_set_bit (i, &mask,AMDGPU_NUM_VMID ) {soc24_grbm_select (adev,0 ,0 ,0 , i);/* CP and shaders */ WREG32_SOC15 (GC ,0 , regSH_MEM_CONFIG,DEFAULT_SH_MEM_CONFIG ); -WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, sh_mem_bases); - -/* Enable trap for each kfd vmid. */ - data =RREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL); - data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN ,1 ); -WREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL, data); +if (uq_mask &BIT (i)) { +WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, uq_bases); + +/* Enable trap for each kfd vmid. */ + data =RREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN ,1 ); +WREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL, data); + }else if (i) { +WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, kq_bases); + } }soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);
@@ -1835,7 +1851,6 @@ static void gfx_v12_0_get_tcc_info(struct amdgpu_device *adev)static void gfx_v12_0_constants_init (struct amdgpu_device *adev) {u32 tmp; -int i;if (!amdgpu_sriov_vf (adev))WREG32_FIELD15_PREREG (GC ,0 ,GRBM_CNTL ,READ_TIMEOUT ,0xff );
@@ -1860,26 +1875,7 @@ static void gfx_v12_0_constants_init(struct amdgpu_device *adev)WREG32_FIELD15_PREREG (GC ,0 ,DB_RING_CONTROL ,COUNTER_CONTROL , (adev->gfx.me.num_pipe_per_me >1 ) ?0 :1 ); -/* XXX SH_MEM regs */ -/* where to put LDS, scratch, GPUVM in FSA64 space */ -mutex_lock (&adev->srbm_mutex); -for_each_vmid_and_zero (i, adev,AMDGPU_GFXHUB (0 )) { -soc24_grbm_select (adev,0 ,0 ,0 , i); -/* CP and shaders */ -WREG32_SOC15 (GC ,0 , regSH_MEM_CONFIG,DEFAULT_SH_MEM_CONFIG ); -if (i !=0 ) { - tmp =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , - (adev->gmc.private_aperture_start >>48 )); - tmp =REG_SET_FIELD (tmp,SH_MEM_BASES ,SHARED_BASE , - (adev->gmc.shared_aperture_start >>48 )); -WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, tmp); - } - } -soc24_grbm_select (adev,0 ,0 ,0 ,0 ); - -mutex_unlock (&adev->srbm_mutex); - -gfx_v12_0_init_compute_vmid (adev); +gfx_v12_0_init_sh_mem (adev); } static u32 gfx_v12_0_get_cpg_int_cntl(struct amdgpu_device *adev,
Signature · 1 line
2.50.1
PATCH 3/6 drm/amdgpu/gfx11: consolidate SH_MEM initialization
In reply to Jesse Zhanggfx_v11_0_constants_init() programs SH_MEM_CONFIG and SH_MEM_BASES of VMID 0 and the kernel queue VMIDs, and gfx_v11_0_init_compute_vmid() those of the user queue VMIDs, each walking its own VMID mask.
Program them in one place, walking the kernel queue and the user queue VMIDs together and giving each the configuration of its users, as on GFX12. The GDS, GWS and OA clearing of the user queue VMIDs in gfx_v11_0_init_compute_vmid() goes away, gfx_v11_0_init_gds_vmid() clears them for all VMIDs but 0 right after.
No functional change.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 75 +++++++++++--------------- 1 file changed, 30 insertions(+), 45 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +30 -45
@@ -2151,46 +2151,51 @@ static void gfx_v11_0_setup_rb(struct amdgpu_device *adev)#define LDS_APP_BASE 0x1#define SCRATCH_APP_BASE 0x2 -static void gfx_v11_0_init_compute_vmid (struct amdgpu_device *adev) +/* +* Program SH_MEM_CONFIG and SH_MEM_BASES of all VMIDs in one place: the user +* queue VMIDs get the application apertures and traps enabled, the kernel +* queue VMIDs, including the SPM VMID, the GPUVM apertures. VMID 0 only gets +* SH_MEM_CONFIG, its SH_MEM_BASES is left alone. +*/ +static void gfx_v11_0_init_sh_mem (struct amdgpu_device *adev) { +unsigned long uq_mask = adev->vm_manager.vmid_uq_mask_gfxhub; +unsigned long mask =amdgpu_vmid_kq_mask (adev,AMDGPU_GFXHUB (0 )) | uq_mask; +u32 kq_bases, uq_bases, data;int i; -uint32_t sh_mem_bases; -uint32_t data; + + kq_bases =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , + adev->gmc.private_aperture_start >>48 ); + kq_bases =REG_SET_FIELD (kq_bases,SH_MEM_BASES ,SHARED_BASE , + adev->gmc.shared_aperture_start >>48 );/* -* Configure apertures: +* Configure apertures of the user queue VMIDs: * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB) * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB) * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB) */ - sh_mem_bases = (LDS_APP_BASE <<SH_MEM_BASES__SHARED_BASE__SHIFT ) | -SCRATCH_APP_BASE ; + uq_bases = (LDS_APP_BASE <<SH_MEM_BASES__SHARED_BASE__SHIFT ) | +SCRATCH_APP_BASE ;mutex_lock (&adev->srbm_mutex); -for_each_uq_gfx_vmid (i, adev) { +for_each_set_bit (i, &mask,AMDGPU_NUM_VMID ) {soc21_grbm_select (adev,0 ,0 ,0 , i);/* CP and shaders */ WREG32_SOC15 (GC ,0 , regSH_MEM_CONFIG,DEFAULT_SH_MEM_CONFIG ); -WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, sh_mem_bases); - -/* Enable trap for each kfd vmid. */ - data =RREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL); - data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN ,1 ); -WREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL, data); +if (uq_mask &BIT (i)) { +WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, uq_bases); + +/* Enable trap for each kfd vmid. */ + data =RREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN ,1 ); +WREG32_SOC15 (GC ,0 , regSPI_GDBG_PER_VMID_CNTL, data); + }else if (i) { +WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, kq_bases); + } }soc21_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); - -/* -* Initialize all compute VMIDs to have no GDS, GWS, or OA -* access. These should be enabled by FW for target VMIDs. -*/ -for_each_uq_gfx_vmid (i, adev) { -WREG32_SOC15_OFFSET (GC ,0 , regGDS_VMID0_BASE,2 * i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , regGDS_VMID0_SIZE,2 * i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , regGDS_GWS_VMID0, i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , regGDS_OA_VMID0, i,0 ); - } }static void gfx_v11_0_init_gds_vmid (struct amdgpu_device *adev)
@@ -2230,7 +2235,6 @@ static void gfx_v11_0_get_tcc_info(struct amdgpu_device *adev)static void gfx_v11_0_constants_init (struct amdgpu_device *adev) {u32 tmp; -int i;if (!amdgpu_sriov_vf (adev))WREG32_FIELD15_PREREG (GC ,0 ,GRBM_CNTL ,READ_TIMEOUT ,0xff );
@@ -2254,26 +2258,7 @@ static void gfx_v11_0_constants_init(struct amdgpu_device *adev)WREG32_FIELD15_PREREG (GC ,0 ,DB_RING_CONTROL ,COUNTER_CONTROL , (adev->gfx.me.num_pipe_per_me >1 ) ?0 :1 ); -/* XXX SH_MEM regs */ -/* where to put LDS, scratch, GPUVM in FSA64 space */ -mutex_lock (&adev->srbm_mutex); -for_each_vmid_and_zero (i, adev,AMDGPU_GFXHUB (0 )) { -soc21_grbm_select (adev,0 ,0 ,0 , i); -/* CP and shaders */ -WREG32_SOC15 (GC ,0 , regSH_MEM_CONFIG,DEFAULT_SH_MEM_CONFIG ); -if (i !=0 ) { - tmp =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , - (adev->gmc.private_aperture_start >>48 )); - tmp =REG_SET_FIELD (tmp,SH_MEM_BASES ,SHARED_BASE , - (adev->gmc.shared_aperture_start >>48 )); -WREG32_SOC15 (GC ,0 , regSH_MEM_BASES, tmp); - } - } -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); - -mutex_unlock (&adev->srbm_mutex); - -gfx_v11_0_init_compute_vmid (adev); +gfx_v11_0_init_sh_mem (adev);gfx_v11_0_init_gds_vmid (adev); }
Signature · 1 line
2.50.1
PATCH 4/6 drm/amdgpu/gfx10: consolidate SH_MEM initialization
In reply to Jesse Zhanggfx_v10_0_constants_init() programs SH_MEM_CONFIG and SH_MEM_BASES of VMID 0 and the kernel queue VMIDs, and gfx_v10_0_init_compute_vmid() those of the user queue VMIDs, each walking its own VMID mask.
Program them in one place, walking the kernel queue and the user queue VMIDs together and giving each the configuration of its users, as on GFX11 and GFX12, and keep enabling the traps of the user queue VMIDs with gfx_v10_0_debug_trap_config_init(). The GDS, GWS and OA clearing of the user queue VMIDs in gfx_v10_0_init_compute_vmid() goes away, gfx_v10_0_init_gds_vmid() clears them for all VMIDs but 0 right after.
No functional change.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 65 ++++++++++---------------- 1 file changed, 24 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +24 -41
@@ -5193,41 +5193,46 @@ static void gfx_v10_0_debug_trap_config_init(struct amdgpu_device *adev,WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA1),0 ); } -static void gfx_v10_0_init_compute_vmid (struct amdgpu_device *adev) +/* +* Program SH_MEM_CONFIG and SH_MEM_BASES of all VMIDs in one place: the user +* queue VMIDs get the application apertures and traps enabled, the kernel +* queue VMIDs, including the SPM VMID, the GPUVM apertures. VMID 0 only gets +* SH_MEM_CONFIG, its SH_MEM_BASES is left alone. +*/ +static void gfx_v10_0_init_sh_mem (struct amdgpu_device *adev) { +unsigned long uq_mask = adev->vm_manager.vmid_uq_mask_gfxhub; +unsigned long mask =amdgpu_vmid_kq_mask (adev,AMDGPU_GFXHUB (0 )) | uq_mask; +u32 kq_bases, uq_bases;int i; -uint32_t sh_mem_bases; + + kq_bases =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , + adev->gmc.private_aperture_start >>48 ); + kq_bases =REG_SET_FIELD (kq_bases,SH_MEM_BASES ,SHARED_BASE , + adev->gmc.shared_aperture_start >>48 );/* -* Configure apertures: +* Configure apertures of the user queue VMIDs: * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB) * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB) * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB) */ - sh_mem_bases =DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES <<16 ); + uq_bases =DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES <<16 );mutex_lock (&adev->srbm_mutex); -for_each_uq_gfx_vmid (i, adev) { +for_each_set_bit (i, &mask,AMDGPU_NUM_VMID ) {nv_grbm_select (adev,0 ,0 ,0 , i);/* CP and shaders */ WREG32_SOC15 (GC ,0 , mmSH_MEM_CONFIG,DEFAULT_SH_MEM_CONFIG ); -WREG32_SOC15 (GC ,0 , mmSH_MEM_BASES, sh_mem_bases); +if (uq_mask &BIT (i)) +WREG32_SOC15 (GC ,0 , mmSH_MEM_BASES, uq_bases); +else if (i) +WREG32_SOC15 (GC ,0 , mmSH_MEM_BASES, kq_bases); }nv_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); -/* -* Initialize all compute VMIDs to have no GDS, GWS, or OA -* access. These should be enabled by FW for target VMIDs. -*/ -for_each_uq_gfx_vmid (i, adev) { -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_VMID0_BASE,2 * i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_VMID0_SIZE,2 * i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_GWS_VMID0, i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_OA_VMID0, i,0 ); - } - -gfx_v10_0_debug_trap_config_init (adev, adev->vm_manager.vmid_uq_mask_gfxhub); +gfx_v10_0_debug_trap_config_init (adev, uq_mask); }static void gfx_v10_0_init_gds_vmid (struct amdgpu_device *adev)
@@ -5336,9 +5341,6 @@ static void gfx_v10_0_get_tcc_info(struct amdgpu_device *adev)static void gfx_v10_0_constants_init (struct amdgpu_device *adev) { -u32 tmp; -int i; -if (!amdgpu_sriov_vf (adev))WREG32_FIELD15 (GC ,0 ,GRBM_CNTL ,READ_TIMEOUT ,0xff );
@@ -5357,26 +5359,7 @@ static void gfx_v10_0_constants_init(struct amdgpu_device *adev)WREG32_FIELD15 (GC ,0 ,DB_RING_CONTROL ,COUNTER_CONTROL , (adev->gfx.me.num_pipe_per_me >1 ) ?0 :1 ); -/* XXX SH_MEM regs */ -/* where to put LDS, scratch, GPUVM in FSA64 space */ -mutex_lock (&adev->srbm_mutex); -for_each_vmid_and_zero (i, adev,AMDGPU_GFXHUB (0 )) { -nv_grbm_select (adev,0 ,0 ,0 , i); -/* CP and shaders */ -WREG32_SOC15 (GC ,0 , mmSH_MEM_CONFIG,DEFAULT_SH_MEM_CONFIG ); -if (i !=0 ) { - tmp =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , - (adev->gmc.private_aperture_start >>48 )); - tmp =REG_SET_FIELD (tmp,SH_MEM_BASES ,SHARED_BASE , - (adev->gmc.shared_aperture_start >>48 )); -WREG32_SOC15 (GC ,0 , mmSH_MEM_BASES, tmp); - } - } -nv_grbm_select (adev,0 ,0 ,0 ,0 ); - -mutex_unlock (&adev->srbm_mutex); - -gfx_v10_0_init_compute_vmid (adev); +gfx_v10_0_init_sh_mem (adev);gfx_v10_0_init_gds_vmid (adev); }
Signature · 1 line
2.50.1
PATCH 5/6 drm/amdgpu/gfx9: consolidate SH_MEM initialization
In reply to Jesse Zhanggfx_v9_0_constants_init() programs SH_MEM_CONFIG and SH_MEM_BASES of VMID 0 and the kernel queue VMIDs, and gfx_v9_0_init_compute_vmid() those of the user queue VMIDs, each walking its own VMID mask.
Program them in one place, walking the kernel queue and the user queue VMIDs together and giving each the configuration of its users: the kernel queue VMIDs keep the retry mode of the GMC and the GPUVM apertures, VMID 0 null bases, and the user queue VMIDs the 64-bit address mode and the application apertures. The GDS, GWS and OA clearing of the user queue VMIDs in gfx_v9_0_init_compute_vmid() goes away, gfx_v9_0_init_gds_vmid() clears them for all VMIDs but 0 right after.
No functional change.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 89 ++++++++++----------------- 1 file changed, 34 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +34 -55
@@ -2584,42 +2584,54 @@ static void gfx_v9_0_debug_trap_config_init(struct amdgpu_device *adev, }#define DEFAULT_SH_MEM_BASES (0x6000) -static void gfx_v9_0_init_compute_vmid (struct amdgpu_device *adev) +/* +* Program SH_MEM_CONFIG and SH_MEM_BASES of all VMIDs in one place: the user +* queue VMIDs get the 64-bit address mode and the application apertures, +* VMID 0 and the kernel queue VMIDs, including the SPM VMID, the retry mode +* of the GMC, the kernel queue VMIDs the GPUVM apertures and VMID 0 null +* bases. +*/ +static void gfx_v9_0_init_sh_mem (struct amdgpu_device *adev) { +unsigned long uq_mask = adev->vm_manager.vmid_uq_mask_gfxhub; +unsigned long mask =amdgpu_vmid_kq_mask (adev,AMDGPU_GFXHUB (0 )) | uq_mask; +u32 kq_config, kq_bases, uq_config, uq_bases;int i; -uint32_t sh_mem_config; -uint32_t sh_mem_bases; + + kq_config =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,ALIGNMENT_MODE , +SH_MEM_ALIGNMENT_MODE_UNALIGNED ); + kq_config =REG_SET_FIELD (kq_config,SH_MEM_CONFIG ,RETRY_DISABLE , + !!adev->gmc.noretry); + kq_bases =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , + adev->gmc.private_aperture_start >>48 ); + kq_bases =REG_SET_FIELD (kq_bases,SH_MEM_BASES ,SHARED_BASE , + adev->gmc.shared_aperture_start >>48 );/* -* Configure apertures: +* Configure apertures of the user queue VMIDs: * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB) * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB) * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB) */ - sh_mem_bases =DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES <<16 ); - - sh_mem_config =SH_MEM_ADDRESS_MODE_64 | -SH_MEM_ALIGNMENT_MODE_UNALIGNED << -SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT ; + uq_bases =DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES <<16 ); + uq_config =SH_MEM_ADDRESS_MODE_64 | +SH_MEM_ALIGNMENT_MODE_UNALIGNED << +SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT ;mutex_lock (&adev->srbm_mutex); -for_each_uq_gfx_vmid (i, adev) { +for_each_set_bit (i, &mask,AMDGPU_NUM_VMID ) {soc15_grbm_select (adev,0 ,0 ,0 , i,0 );/* CP and shaders */ -WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_CONFIG, sh_mem_config); -WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_BASES, sh_mem_bases); +if (uq_mask &BIT (i)) { +WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_CONFIG, uq_config); +WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_BASES, uq_bases); + }else { +WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_CONFIG, kq_config); +WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_BASES, i ? kq_bases :0 ); + } }soc15_grbm_select (adev,0 ,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); - -/* Initialize all compute VMIDs to have no GDS, GWS, or OA -access. These should be enabled by FW for target VMIDs. */ -for_each_uq_gfx_vmid (i, adev) { -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_VMID0_BASE,2 * i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_VMID0_SIZE,2 * i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_GWS_VMID0, i,0 ); -WREG32_SOC15_OFFSET (GC ,0 , mmGDS_OA_VMID0, i,0 ); - } }static void gfx_v9_0_init_gds_vmid (struct amdgpu_device *adev)
@@ -2661,9 +2673,6 @@ static void gfx_v9_0_init_sq_config(struct amdgpu_device *adev)static void gfx_v9_0_constants_init (struct amdgpu_device *adev) { -u32 tmp; -int i; -if (!amdgpu_sriov_vf (adev) ||amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,2 )) {WREG32_FIELD15_RLC (GC ,0 ,GRBM_CNTL ,READ_TIMEOUT ,0xff );
@@ -2676,37 +2685,7 @@ static void gfx_v9_0_constants_init(struct amdgpu_device *adev)gfx_v9_0_get_cu_info (adev, &adev->gfx.cu_info); adev->gfx.config.db_debug2 =RREG32_SOC15 (GC ,0 , mmDB_DEBUG2); -/* XXX SH_MEM regs */ -/* where to put LDS, scratch, GPUVM in FSA64 space */ -mutex_lock (&adev->srbm_mutex); -for_each_vmid_and_zero (i, adev,AMDGPU_GFXHUB (0 )) { -soc15_grbm_select (adev,0 ,0 ,0 , i,0 ); -/* CP and shaders */ -if (i ==0 ) { - tmp =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,ALIGNMENT_MODE , -SH_MEM_ALIGNMENT_MODE_UNALIGNED ); - tmp =REG_SET_FIELD (tmp,SH_MEM_CONFIG ,RETRY_DISABLE , - !!adev->gmc.noretry); -WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_CONFIG, tmp); -WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_BASES,0 ); - }else { - tmp =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,ALIGNMENT_MODE , -SH_MEM_ALIGNMENT_MODE_UNALIGNED ); - tmp =REG_SET_FIELD (tmp,SH_MEM_CONFIG ,RETRY_DISABLE , - !!adev->gmc.noretry); -WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_CONFIG, tmp); - tmp =REG_SET_FIELD (0 ,SH_MEM_BASES ,PRIVATE_BASE , - (adev->gmc.private_aperture_start >>48 )); - tmp =REG_SET_FIELD (tmp,SH_MEM_BASES ,SHARED_BASE , - (adev->gmc.shared_aperture_start >>48 )); -WREG32_SOC15_RLC (GC ,0 , mmSH_MEM_BASES, tmp); - } - } -soc15_grbm_select (adev,0 ,0 ,0 ,0 ,0 ); - -mutex_unlock (&adev->srbm_mutex); - -gfx_v9_0_init_compute_vmid (adev); +gfx_v9_0_init_sh_mem (adev);gfx_v9_0_init_gds_vmid (adev);gfx_v9_0_init_sq_config (adev); }
Signature · 1 line
2.50.1
PATCH 6/6 drm/amdgpu/gfx8: consolidate SH_MEM initialization
In reply to Jesse Zhanggfx_v8_0_constants_init() programs the SH_MEM registers of VMID 0 and the kernel queue VMIDs, and gfx_v8_0_init_compute_vmid() those of the user queue VMIDs, each walking its own VMID mask.
Program them in one place, walking the kernel queue and the user queue VMIDs together and giving each the configuration of its users: VMID 0 uncached with null bases, the kernel queue VMIDs non-coherent with the shared aperture, and the user queue VMIDs the HSA64 address mode, cache coherency, ATC for the private aperture and the application apertures; APE1 stays disabled for all of them. The GDS, GWS and OA clearing of the user queue VMIDs in gfx_v8_0_init_compute_vmid() goes away, gfx_v8_0_init_gds_vmid() clears them for all VMIDs but 0 right after.
No functional change.
--- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 96 ++++++++++++--------------- 1 file changed, 41 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +41 -55
@@ -3644,54 +3644,68 @@ static void gfx_v8_0_setup_rb(struct amdgpu_device *adev)#define DEFAULT_SH_MEM_BASES (0x6000)/** -* gfx_v8_0_init_compute_vmid - gart enable +* gfx_v8_0_init_sh_mem - initialize the sh_mem registers of all VMIDs * * @adev: amdgpu_device pointer * -* Initialize compute vmid sh_mem registers -* +* Program the sh_mem registers of VMID 0, the kernel queue VMIDs, including +* the SPM VMID, and the user queue VMIDs in one place, each with the +* configuration of its users. */ -static void gfx_v8_0_init_compute_vmid (struct amdgpu_device *adev) +static void gfx_v8_0_init_sh_mem (struct amdgpu_device *adev) { +unsigned long uq_mask = adev->vm_manager.vmid_uq_mask_gfxhub; +unsigned long mask =amdgpu_vmid_kq_mask (adev,AMDGPU_GFXHUB (0 )) | uq_mask; +u32 vmid0_config, kq_config, uq_config, uq_bases;int i; -uint32_t sh_mem_config; -uint32_t sh_mem_bases; + + vmid0_config =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,DEFAULT_MTYPE ,MTYPE_UC ); + vmid0_config =REG_SET_FIELD (vmid0_config,SH_MEM_CONFIG ,APE1_MTYPE , +MTYPE_UC ); + vmid0_config =REG_SET_FIELD (vmid0_config,SH_MEM_CONFIG ,ALIGNMENT_MODE , +SH_MEM_ALIGNMENT_MODE_UNALIGNED ); + + kq_config =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,DEFAULT_MTYPE ,MTYPE_NC ); + kq_config =REG_SET_FIELD (kq_config,SH_MEM_CONFIG ,APE1_MTYPE ,MTYPE_UC ); + kq_config =REG_SET_FIELD (kq_config,SH_MEM_CONFIG ,ALIGNMENT_MODE , +SH_MEM_ALIGNMENT_MODE_UNALIGNED );/* -* Configure apertures: +* Configure apertures of the user queue VMIDs: * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB) * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB) * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB) */ - sh_mem_bases =DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES <<16 ); + uq_bases =DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES <<16 ); - sh_mem_config =SH_MEM_ADDRESS_MODE_HSA64 << -SH_MEM_CONFIG__ADDRESS_MODE__SHIFT | -SH_MEM_ALIGNMENT_MODE_UNALIGNED << -SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT | -MTYPE_CC <<SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT | -SH_MEM_CONFIG__PRIVATE_ATC_MASK ; + uq_config =SH_MEM_ADDRESS_MODE_HSA64 << +SH_MEM_CONFIG__ADDRESS_MODE__SHIFT | +SH_MEM_ALIGNMENT_MODE_UNALIGNED << +SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT | +MTYPE_CC <<SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT | +SH_MEM_CONFIG__PRIVATE_ATC_MASK ;mutex_lock (&adev->srbm_mutex); -for_each_uq_gfx_vmid (i, adev) { +for_each_set_bit (i, &mask,AMDGPU_NUM_VMID ) {vi_srbm_select (adev,0 ,0 ,0 , i);/* CP and shaders */ -WREG32 (mmSH_MEM_CONFIG, sh_mem_config); +if (uq_mask &BIT (i)) { +WREG32 (mmSH_MEM_CONFIG, uq_config); +WREG32 (mmSH_MEM_BASES, uq_bases); + }else if (i) { +WREG32 (mmSH_MEM_CONFIG, kq_config); +WREG32 (mmSH_MEM_BASES, + adev->gmc.shared_aperture_start >>48 ); + }else { +WREG32 (mmSH_MEM_CONFIG, vmid0_config); +WREG32 (mmSH_MEM_BASES,0 ); + } +WREG32 (mmSH_MEM_APE1_BASE,1 );WREG32 (mmSH_MEM_APE1_LIMIT,0 ); -WREG32 (mmSH_MEM_BASES, sh_mem_bases); }vi_srbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); - -/* Initialize all compute VMIDs to have no GDS, GWS, or OA -access. These should be enabled by FW for target VMIDs. */ -for_each_uq_gfx_vmid (i, adev) { -WREG32 (amdgpu_gds_reg_offset[i].mem_base,0 ); -WREG32 (amdgpu_gds_reg_offset[i].mem_size,0 ); -WREG32 (amdgpu_gds_reg_offset[i].gws,0 ); -WREG32 (amdgpu_gds_reg_offset[i].oa,0 ); - } }static void gfx_v8_0_init_gds_vmid (struct amdgpu_device *adev)
@@ -3728,7 +3742,6 @@ static void gfx_v8_0_config_init(struct amdgpu_device *adev)static void gfx_v8_0_constants_init (struct amdgpu_device *adev) {u32 tmp, sh_static_mem_cfg; -int i;WREG32_FIELD (GRBM_CNTL ,READ_TIMEOUT ,0xFF );WREG32 (mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
@@ -3750,34 +3763,7 @@ static void gfx_v8_0_constants_init(struct amdgpu_device *adev) INDEX_STRIDE, 3);WREG32 (mmSH_STATIC_MEM_CONFIG, sh_static_mem_cfg); -mutex_lock (&adev->srbm_mutex); -for_each_vmid_and_zero (i, adev,0 ) { -vi_srbm_select (adev,0 ,0 ,0 , i); -/* CP and shaders */ -if (i ==0 ) { - tmp =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,DEFAULT_MTYPE ,MTYPE_UC ); - tmp =REG_SET_FIELD (tmp,SH_MEM_CONFIG ,APE1_MTYPE ,MTYPE_UC ); - tmp =REG_SET_FIELD (tmp,SH_MEM_CONFIG ,ALIGNMENT_MODE , -SH_MEM_ALIGNMENT_MODE_UNALIGNED ); -WREG32 (mmSH_MEM_CONFIG, tmp); -WREG32 (mmSH_MEM_BASES,0 ); - }else { - tmp =REG_SET_FIELD (0 ,SH_MEM_CONFIG ,DEFAULT_MTYPE ,MTYPE_NC ); - tmp =REG_SET_FIELD (tmp,SH_MEM_CONFIG ,APE1_MTYPE ,MTYPE_UC ); - tmp =REG_SET_FIELD (tmp,SH_MEM_CONFIG ,ALIGNMENT_MODE , -SH_MEM_ALIGNMENT_MODE_UNALIGNED ); -WREG32 (mmSH_MEM_CONFIG, tmp); - tmp = adev->gmc.shared_aperture_start >>48 ; -WREG32 (mmSH_MEM_BASES, tmp); - } - -WREG32 (mmSH_MEM_APE1_BASE,1 ); -WREG32 (mmSH_MEM_APE1_LIMIT,0 ); - } -vi_srbm_select (adev,0 ,0 ,0 ,0 ); -mutex_unlock (&adev->srbm_mutex); - -gfx_v8_0_init_compute_vmid (adev); +gfx_v8_0_init_sh_mem (adev);gfx_v8_0_init_gds_vmid (adev);mutex_lock (&adev->grbm_idx_mutex);
Signature · 1 line
2.50.1
AMD General
Ping the series.
Quoted 118 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Friday, October 30, 2026 3:20 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; Khatri, Sunil <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 1/6] drm/amdgpu: program theSH_MEMregisters of the SPM VMIDCommit
02232367be23("drm/amdgpu: addspm_vmidand exclude it from the MES, KFD and kq pools") took the SPM VMID out of the kernel queue and the user queue VMID masks, and since commit8a9263fc8812("drm/amdgpu: use dedicated SPM VMID from the reserved path") the kernel queue jobs of a VM with a reserved VMID run on it. The gfxconstants_init()only programsSH_MEM_CONFIGandSH_MEM_BASESfor VMID 0 and the kernel queue mask though, andinit_compute_vmid()for the user queue mask, so the SPM VMID keeps the reset defaults: no unaligned access mode and no apertures.On navi48 VMID 15 has
SH_MEM_CONFIG0xc000andSH_MEM_BASES0
while the other graphics VMIDs have0xc00cand0x20001000. A shader storing a dword to an address with a byte offset of 1 writes it there in a normal process, but at the dword aligned address in one which reserved a VMID, e.g. for profiling with SPM:$ umr -i 0 -sb 0 0 0 15 -r '*.*.regSH_MEM_CONFIG' gfx1201.regSH_MEM_CONFIG => 0x0000c000 $ amd_uapi_regression --run-subtest reserved-vmid-unaligned-store unaligned store: 0x0000000000002a00 normally, 0x000000000000002a with a reserved VMIDAdd
amdgpu_vmid_kq_mask()for VMID 0 and the kernel queue VMIDs of a hub, including the SPM VMID on the GFXHUB, and walk it infor_each_vmid_and_zero(), so theconstants_init()of all gfx generations program the SPM VMID like the other kernel queue VMIDs. The mask is only used for the register initialization, the VMID allocation pool stays unchanged.v2: split out of the SPM VMID series, the per generation consolidation
of theSH_MEMinitialization follows (Alex)
build the walked mask withamdgpu_vmid_kq_mask(), which the
consolidation reusesFixes 8a9263fc8812 ("drm/amdgpu: use dedicated SPM VMID from thereserved path")
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 30 ++++++++++++++++++-- ----- 1 file changed, 22 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +0
-1@@ -36,23 +36,37 @@#define AMDGPU_NUM_VMID 16/** -* for_each_vmid_and_zero - iterate over VMID 0 plus every VMID set in a hub's
- *vmid_mask
+ *amdgpu_vmid_kq_mask- VMIDs the kernel queues of a hub run on
+ * @adev: structamdgpu_device*
+ * @hub: vmhub index into adev->vm_manager.id_mgr[]
+ *
+ * VMID 0, the VMIDs of the hub's kernel queue pool and, on the GFXHUB,drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +9
-0+the +* dedicated SPM VMID, which is kept out of the pool but runs the +kernel queue +* jobs of the VM reserving it. Only builds a mask for the register +* initialization, the VMID allocation pool is not changed. +*/ +#define amdgpu_vmid_kq_mask (adev, hub) \ + ((adev)->vm_manager.id_mgr[(hub)].vmid_mask[0] | BIT(0) | \ + ((hub) == AMDGPU_GFXHUB(0) && (adev)-Quoted 1 line
vm_manager.spm_vmid ? \
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +4
-0+ BIT((adev)->vm_manager.spm_vmid) : 0)) + +/** +* for_each_vmid_and_zero - iterate over VMID 0 and the kernel queue VMIDs of
+ * a hub* @vmid: loop cursor (int / unsigned int) * @adev: struct amdgpu_device * * @hub: vmhub index into adev->vm_manager.id_mgr[]*
- * Equivalent to OR-ing BIT(0) into id_mgr[hub].vmid_mask and walking
- * the result withfor_each_set_bit(). Used by the gfx_v*_constants_init()
- * paths which must always touch VMID 0 (system) in addition to the regular
- * VMIDs owned by the hub.
+ * Iterate over VMID 0 and the hub's kernel-queue pool, including the
+ * dedicated SPM VMID on GFXHUB, seeamdgpu_vmid_kq_mask(). Used by the
+ * gfx_v*_constants_init() paths which must always touch VMID 0
+ (system) in
+ * addition to the VMIDs the kernel queues of the hub run on.
*
* Relies onAMDGPU_NUM_VMID(16) fitting in a single unsigned long, i.e.
* vmid_mask[] being a 1-element bitmap.
*/#define for_each_vmid_and_zero(vmid, adev, hub) \drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +1
-2- for (unsigned long __vmid_mask = \ - (adev)->vm_manager.id_mgr[(hub)].vmid_mask[0] | BIT(0); \ + for (unsigned long __vmid_mask = amdgpu_vmid_kq_mask(adev,hub); \ __vmid_mask; __vmid_mask = 0) \ for_each_set_bit((vmid), &__vmid_mask,
AMDGPU_NUM_VMID)--
2.50.1