gfx_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. Suggested-by: Alex Deucher <[email protected]> Signed-off-by: Jesse Zhang <[email protected]> --- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 75 +++++++++++--------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c index 315dfd806d56..cdf543f1cd9a 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c @@ -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); } -- 2.50.1
