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. Suggested-by: Alex Deucher <[email protected]> Signed-off-by: Jesse Zhang <[email protected]> --- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 64 ++++++++++++-------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c index d334fb805020..336eee54d63a 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c @@ -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, -- 2.50.1
