Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Clean up KFD VMID assignment

The KFD VMID assignment was hard-coded in a few places. Consolidate that in
a single variable adev->vm_manager.first_kfd_vmid. The value is still
assigned in gmc-ip-version-specific code.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Felix Kuehling and committed by
Alex Deucher
40111ec2 a71a4f50

+22 -43
+5 -7
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
··· 31 31 #include "amdgpu_xgmi.h" 32 32 #include <uapi/linux/kfd_ioctl.h> 33 33 34 - static const unsigned int compute_vmid_bitmap = 0xFF00; 35 - 36 34 /* Total memory size in system memory and all GPU VRAM. Used to 37 35 * estimate worst case amount of memory to reserve for page tables 38 36 */ ··· 111 113 112 114 if (adev->kfd.dev) { 113 115 struct kgd2kfd_shared_resources gpu_resources = { 114 - .compute_vmid_bitmap = compute_vmid_bitmap, 116 + .compute_vmid_bitmap = 117 + ((1 << AMDGPU_NUM_VMID) - 1) - 118 + ((1 << adev->vm_manager.first_kfd_vmid) - 1), 115 119 .num_pipe_per_mec = adev->gfx.mec.num_pipe_per_mec, 116 120 .num_queue_per_pipe = adev->gfx.mec.num_queue_per_pipe, 117 121 .gpuvm_size = min(adev->vm_manager.max_pfn ··· 637 637 638 638 bool amdgpu_amdkfd_is_kfd_vmid(struct amdgpu_device *adev, u32 vmid) 639 639 { 640 - if (adev->kfd.dev) { 641 - if ((1 << vmid) & compute_vmid_bitmap) 642 - return true; 643 - } 640 + if (adev->kfd.dev) 641 + return vmid >= adev->vm_manager.first_kfd_vmid; 644 642 645 643 return false; 646 644 }
+3
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
··· 574 574 INIT_LIST_HEAD(&id_mgr->ids_lru); 575 575 atomic_set(&id_mgr->reserved_vmid_num, 0); 576 576 577 + /* manage only VMIDs not used by KFD */ 578 + id_mgr->num_ids = adev->vm_manager.first_kfd_vmid; 579 + 577 580 /* skip over VMID 0, since it is the system VM */ 578 581 for (j = 1; j < id_mgr->num_ids; ++j) { 579 582 amdgpu_vmid_reset(adev, i, j);
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
··· 324 324 struct amdgpu_vm_manager { 325 325 /* Handling of VMIDs */ 326 326 struct amdgpu_vmid_mgr id_mgr[AMDGPU_MAX_VMHUBS]; 327 + unsigned int first_kfd_vmid; 327 328 328 329 /* Handling of VM fences */ 329 330 u64 fence_context;
-2
drivers/gpu/drm/amd/amdgpu/cikd.h
··· 54 54 #define BONAIRE_GB_ADDR_CONFIG_GOLDEN 0x12010001 55 55 #define HAWAII_GB_ADDR_CONFIG_GOLDEN 0x12011003 56 56 57 - #define AMDGPU_NUM_OF_VMIDS 8 58 - 59 57 #define PIPEID(x) ((x) << 0) 60 58 #define MEID(x) ((x) << 2) 61 59 #define VMID(x) ((x) << 4)
+2 -4
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
··· 4512 4512 } 4513 4513 4514 4514 #define DEFAULT_SH_MEM_BASES (0x6000) 4515 - #define FIRST_COMPUTE_VMID (8) 4516 - #define LAST_COMPUTE_VMID (16) 4517 4515 4518 4516 static void gfx_v10_0_init_compute_vmid(struct amdgpu_device *adev) 4519 4517 { ··· 4527 4529 sh_mem_bases = DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES << 16); 4528 4530 4529 4531 mutex_lock(&adev->srbm_mutex); 4530 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 4532 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 4531 4533 nv_grbm_select(adev, 0, 0, 0, i); 4532 4534 /* CP and shaders */ 4533 4535 WREG32_SOC15(GC, 0, mmSH_MEM_CONFIG, DEFAULT_SH_MEM_CONFIG); ··· 4538 4540 4539 4541 /* Initialize all compute VMIDs to have no GDS, GWS, or OA 4540 4542 acccess. These should be enabled by FW for target VMIDs. */ 4541 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 4543 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 4542 4544 WREG32_SOC15_OFFSET(GC, 0, mmGDS_VMID0_BASE, 2 * i, 0); 4543 4545 WREG32_SOC15_OFFSET(GC, 0, mmGDS_VMID0_SIZE, 2 * i, 0); 4544 4546 WREG32_SOC15_OFFSET(GC, 0, mmGDS_GWS_VMID0, i, 0);
+2 -4
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
··· 1850 1850 * 1851 1851 */ 1852 1852 #define DEFAULT_SH_MEM_BASES (0x6000) 1853 - #define FIRST_COMPUTE_VMID (8) 1854 - #define LAST_COMPUTE_VMID (16) 1855 1853 static void gfx_v7_0_init_compute_vmid(struct amdgpu_device *adev) 1856 1854 { 1857 1855 int i; ··· 1867 1869 SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT; 1868 1870 sh_mem_config |= MTYPE_NONCACHED << SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT; 1869 1871 mutex_lock(&adev->srbm_mutex); 1870 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 1872 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 1871 1873 cik_srbm_select(adev, 0, 0, 0, i); 1872 1874 /* CP and shaders */ 1873 1875 WREG32(mmSH_MEM_CONFIG, sh_mem_config); ··· 1880 1882 1881 1883 /* Initialize all compute VMIDs to have no GDS, GWS, or OA 1882 1884 acccess. These should be enabled by FW for target VMIDs. */ 1883 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 1885 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 1884 1886 WREG32(amdgpu_gds_reg_offset[i].mem_base, 0); 1885 1887 WREG32(amdgpu_gds_reg_offset[i].mem_size, 0); 1886 1888 WREG32(amdgpu_gds_reg_offset[i].gws, 0);
+2 -4
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
··· 3686 3686 * 3687 3687 */ 3688 3688 #define DEFAULT_SH_MEM_BASES (0x6000) 3689 - #define FIRST_COMPUTE_VMID (8) 3690 - #define LAST_COMPUTE_VMID (16) 3691 3689 static void gfx_v8_0_init_compute_vmid(struct amdgpu_device *adev) 3692 3690 { 3693 3691 int i; ··· 3708 3710 SH_MEM_CONFIG__PRIVATE_ATC_MASK; 3709 3711 3710 3712 mutex_lock(&adev->srbm_mutex); 3711 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 3713 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 3712 3714 vi_srbm_select(adev, 0, 0, 0, i); 3713 3715 /* CP and shaders */ 3714 3716 WREG32(mmSH_MEM_CONFIG, sh_mem_config); ··· 3721 3723 3722 3724 /* Initialize all compute VMIDs to have no GDS, GWS, or OA 3723 3725 acccess. These should be enabled by FW for target VMIDs. */ 3724 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 3726 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 3725 3727 WREG32(amdgpu_gds_reg_offset[i].mem_base, 0); 3726 3728 WREG32(amdgpu_gds_reg_offset[i].mem_size, 0); 3727 3729 WREG32(amdgpu_gds_reg_offset[i].gws, 0);
+2 -4
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
··· 2463 2463 } 2464 2464 2465 2465 #define DEFAULT_SH_MEM_BASES (0x6000) 2466 - #define FIRST_COMPUTE_VMID (8) 2467 - #define LAST_COMPUTE_VMID (16) 2468 2466 static void gfx_v9_0_init_compute_vmid(struct amdgpu_device *adev) 2469 2467 { 2470 2468 int i; ··· 2482 2484 SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT; 2483 2485 2484 2486 mutex_lock(&adev->srbm_mutex); 2485 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 2487 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 2486 2488 soc15_grbm_select(adev, 0, 0, 0, i); 2487 2489 /* CP and shaders */ 2488 2490 WREG32_SOC15_RLC(GC, 0, mmSH_MEM_CONFIG, sh_mem_config); ··· 2493 2495 2494 2496 /* Initialize all compute VMIDs to have no GDS, GWS, or OA 2495 2497 acccess. These should be enabled by FW for target VMIDs. */ 2496 - for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) { 2498 + for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) { 2497 2499 WREG32_SOC15_OFFSET(GC, 0, mmGDS_VMID0_BASE, 2 * i, 0); 2498 2500 WREG32_SOC15_OFFSET(GC, 0, mmGDS_VMID0_SIZE, 2 * i, 0); 2499 2501 WREG32_SOC15_OFFSET(GC, 0, mmGDS_GWS_VMID0, i, 0);
+1 -4
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
··· 49 49 #include "mmhub_v2_0.h" 50 50 #include "athub_v2_0.h" 51 51 #include "athub_v2_1.h" 52 - /* XXX Move this macro to navi10 header file, which is like vid.h for VI.*/ 53 - #define AMDGPU_NUM_OF_VMIDS 8 54 52 55 53 #if 0 56 54 static const struct soc15_reg_golden golden_settings_navi10_hdp[] = ··· 903 905 * amdgpu graphics/compute will use VMIDs 1-7 904 906 * amdkfd will use VMIDs 8-15 905 907 */ 906 - adev->vm_manager.id_mgr[AMDGPU_GFXHUB_0].num_ids = AMDGPU_NUM_OF_VMIDS; 907 - adev->vm_manager.id_mgr[AMDGPU_MMHUB_0].num_ids = AMDGPU_NUM_OF_VMIDS; 908 + adev->vm_manager.first_kfd_vmid = 8; 908 909 909 910 amdgpu_vm_manager_init(adev); 910 911
+1 -1
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
··· 878 878 * amdgpu graphics/compute will use VMIDs 1-7 879 879 * amdkfd will use VMIDs 8-15 880 880 */ 881 - adev->vm_manager.id_mgr[0].num_ids = AMDGPU_NUM_OF_VMIDS; 881 + adev->vm_manager.first_kfd_vmid = 8; 882 882 amdgpu_vm_manager_init(adev); 883 883 884 884 /* base offset of vram pages */
+1 -1
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
··· 1052 1052 * amdgpu graphics/compute will use VMIDs 1-7 1053 1053 * amdkfd will use VMIDs 8-15 1054 1054 */ 1055 - adev->vm_manager.id_mgr[0].num_ids = AMDGPU_NUM_OF_VMIDS; 1055 + adev->vm_manager.first_kfd_vmid = 8; 1056 1056 amdgpu_vm_manager_init(adev); 1057 1057 1058 1058 /* base offset of vram pages */
+1 -1
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
··· 1177 1177 * amdgpu graphics/compute will use VMIDs 1-7 1178 1178 * amdkfd will use VMIDs 8-15 1179 1179 */ 1180 - adev->vm_manager.id_mgr[0].num_ids = AMDGPU_NUM_OF_VMIDS; 1180 + adev->vm_manager.first_kfd_vmid = 8; 1181 1181 amdgpu_vm_manager_init(adev); 1182 1182 1183 1183 /* base offset of vram pages */
+1 -6
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
··· 68 68 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK 0x00003FFFL 69 69 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK 0x3FFF0000L 70 70 71 - /* XXX Move this macro to VEGA10 header file, which is like vid.h for VI.*/ 72 - #define AMDGPU_NUM_OF_VMIDS 8 73 - 74 71 static const u32 golden_settings_vega10_hdp[] = 75 72 { 76 73 0xf64, 0x0fffffff, 0x00000000, ··· 1248 1251 * amdgpu graphics/compute will use VMIDs 1-7 1249 1252 * amdkfd will use VMIDs 8-15 1250 1253 */ 1251 - adev->vm_manager.id_mgr[AMDGPU_GFXHUB_0].num_ids = AMDGPU_NUM_OF_VMIDS; 1252 - adev->vm_manager.id_mgr[AMDGPU_MMHUB_0].num_ids = AMDGPU_NUM_OF_VMIDS; 1253 - adev->vm_manager.id_mgr[AMDGPU_MMHUB_1].num_ids = AMDGPU_NUM_OF_VMIDS; 1254 + adev->vm_manager.first_kfd_vmid = 8; 1254 1255 1255 1256 amdgpu_vm_manager_init(adev); 1256 1257
-1
drivers/gpu/drm/amd/amdgpu/si_enums.h
··· 121 121 #define CURSOR_UPDATE_LOCK (1 << 16) 122 122 #define CURSOR_DISABLE_MULTIPLE_UPDATE (1 << 24) 123 123 124 - #define AMDGPU_NUM_OF_VMIDS 8 125 124 #define SI_CRTC0_REGISTER_OFFSET 0 126 125 #define SI_CRTC1_REGISTER_OFFSET 0x300 127 126 #define SI_CRTC2_REGISTER_OFFSET 0x2600
-2
drivers/gpu/drm/amd/amdgpu/sid.h
··· 49 49 #define SI_MAX_TCC_MASK 0xFFFF 50 50 #define SI_MAX_CTLACKS_ASSERTION_WAIT 100 51 51 52 - #define AMDGPU_NUM_OF_VMIDS 8 53 - 54 52 /* SMC IND accessor regs */ 55 53 #define SMC_IND_INDEX_0 0x80 56 54 #define SMC_IND_DATA_0 0x81
-2
drivers/gpu/drm/amd/amdgpu/vid.h
··· 67 67 #define HPD4_REGISTER_OFFSET (0x18b8 - 0x1898) 68 68 #define HPD5_REGISTER_OFFSET (0x18c0 - 0x1898) 69 69 70 - #define AMDGPU_NUM_OF_VMIDS 8 71 - 72 70 #define PIPEID(x) ((x) << 0) 73 71 #define MEID(x) ((x) << 2) 74 72 #define VMID(x) ((x) << 4)