Merge tag 'amd-drm-next-6.7-2023-10-13' of https://gitlab.freedesktop.org/agd5f/linux...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / amd / amdkfd / kfd_topology.c
index ff98fded953499017a90b57c066570c09721e7e0..4e530791507e1f16df50bd7d2b0907beb19fd7e7 100644 (file)
@@ -450,8 +450,7 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
        sysfs_show_32bit_prop(buffer, offs, "cpu_cores_count",
                              dev->node_props.cpu_cores_count);
        sysfs_show_32bit_prop(buffer, offs, "simd_count",
-                             dev->gpu ? (dev->node_props.simd_count *
-                                         NUM_XCC(dev->gpu->xcc_mask)) : 0);
+                             dev->gpu ? dev->node_props.simd_count : 0);
        sysfs_show_32bit_prop(buffer, offs, "mem_banks_count",
                              dev->node_props.mem_banks_count);
        sysfs_show_32bit_prop(buffer, offs, "caches_count",
@@ -1534,7 +1533,6 @@ out:
 /* Helper function. See kfd_fill_gpu_cache_info for parameter description */
 static int fill_in_l1_pcache(struct kfd_cache_properties **props_ext,
                                struct kfd_gpu_cache_info *pcache_info,
-                               struct kfd_cu_info *cu_info,
                                int cu_bitmask,
                                int cache_type, unsigned int cu_processor_id,
                                int cu_block)
@@ -1596,15 +1594,19 @@ static int fill_in_l1_pcache(struct kfd_cache_properties **props_ext,
 /* Helper function. See kfd_fill_gpu_cache_info for parameter description */
 static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
                                struct kfd_gpu_cache_info *pcache_info,
-                               struct kfd_cu_info *cu_info,
-                               int cache_type, unsigned int cu_processor_id)
+                               struct amdgpu_cu_info *cu_info,
+                               struct amdgpu_gfx_config *gfx_info,
+                               int cache_type, unsigned int cu_processor_id,
+                               struct kfd_node *knode)
 {
        unsigned int cu_sibling_map_mask;
        int first_active_cu;
-       int i, j, k;
+       int i, j, k, xcc, start, end;
        struct kfd_cache_properties *pcache = NULL;
 
-       cu_sibling_map_mask = cu_info->cu_bitmap[0][0];
+       start = ffs(knode->xcc_mask) - 1;
+       end = start + NUM_XCC(knode->xcc_mask);
+       cu_sibling_map_mask = cu_info->bitmap[start][0][0];
        cu_sibling_map_mask &=
                ((1 << pcache_info[cache_type].num_cu_shared) - 1);
        first_active_cu = ffs(cu_sibling_map_mask);
@@ -1639,16 +1641,18 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
                cu_sibling_map_mask = cu_sibling_map_mask >> (first_active_cu - 1);
                k = 0;
 
-               for (i = 0; i < cu_info->num_shader_engines; i++) {
-                       for (j = 0; j < cu_info->num_shader_arrays_per_engine; j++) {
-                               pcache->sibling_map[k] = (uint8_t)(cu_sibling_map_mask & 0xFF);
-                               pcache->sibling_map[k+1] = (uint8_t)((cu_sibling_map_mask >> 8) & 0xFF);
-                               pcache->sibling_map[k+2] = (uint8_t)((cu_sibling_map_mask >> 16) & 0xFF);
-                               pcache->sibling_map[k+3] = (uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);
-                               k += 4;
-
-                               cu_sibling_map_mask = cu_info->cu_bitmap[i % 4][j + i / 4];
-                               cu_sibling_map_mask &= ((1 << pcache_info[cache_type].num_cu_shared) - 1);
+               for (xcc = start; xcc < end; xcc++) {
+                       for (i = 0; i < gfx_info->max_shader_engines; i++) {
+                               for (j = 0; j < gfx_info->max_sh_per_se; j++) {
+                                       pcache->sibling_map[k] = (uint8_t)(cu_sibling_map_mask & 0xFF);
+                                       pcache->sibling_map[k+1] = (uint8_t)((cu_sibling_map_mask >> 8) & 0xFF);
+                                       pcache->sibling_map[k+2] = (uint8_t)((cu_sibling_map_mask >> 16) & 0xFF);
+                                       pcache->sibling_map[k+3] = (uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);
+                                       k += 4;
+
+                                       cu_sibling_map_mask = cu_info->bitmap[xcc][i % 4][j + i / 4];
+                                       cu_sibling_map_mask &= ((1 << pcache_info[cache_type].num_cu_shared) - 1);
+                               }
                        }
                }
                pcache->sibling_map_size = k;
@@ -1666,21 +1670,19 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
 static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct kfd_node *kdev)
 {
        struct kfd_gpu_cache_info *pcache_info = NULL;
-       int i, j, k;
+       int i, j, k, xcc, start, end;
        int ct = 0;
        unsigned int cu_processor_id;
        int ret;
        unsigned int num_cu_shared;
-       struct kfd_cu_info cu_info;
-       struct kfd_cu_info *pcu_info;
+       struct amdgpu_cu_info *cu_info = &kdev->adev->gfx.cu_info;
+       struct amdgpu_gfx_config *gfx_info = &kdev->adev->gfx.config;
        int gpu_processor_id;
        struct kfd_cache_properties *props_ext;
        int num_of_entries = 0;
        int num_of_cache_types = 0;
        struct kfd_gpu_cache_info cache_info[KFD_MAX_CACHE_TYPES];
 
-       amdgpu_amdkfd_get_cu_info(kdev->adev, &cu_info);
-       pcu_info = &cu_info;
 
        gpu_processor_id = dev->node_props.simd_id_base;
 
@@ -1700,37 +1702,42 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
         *                      then it will consider only one CU from
         *                      the shared unit
         */
+       start = ffs(kdev->xcc_mask) - 1;
+       end = start + NUM_XCC(kdev->xcc_mask);
+
        for (ct = 0; ct < num_of_cache_types; ct++) {
                cu_processor_id = gpu_processor_id;
                if (pcache_info[ct].cache_level == 1) {
-                       for (i = 0; i < pcu_info->num_shader_engines; i++) {
-                               for (j = 0; j < pcu_info->num_shader_arrays_per_engine; j++) {
-                                       for (k = 0; k < pcu_info->num_cu_per_sh; k += pcache_info[ct].num_cu_shared) {
+                       for (xcc = start; xcc < end; xcc++) {
+                               for (i = 0; i < gfx_info->max_shader_engines; i++) {
+                                       for (j = 0; j < gfx_info->max_sh_per_se; j++) {
+                                               for (k = 0; k < gfx_info->max_cu_per_sh; k += pcache_info[ct].num_cu_shared) {
 
-                                               ret = fill_in_l1_pcache(&props_ext, pcache_info, pcu_info,
-                                                                               pcu_info->cu_bitmap[i % 4][j + i / 4], ct,
+                                                       ret = fill_in_l1_pcache(&props_ext, pcache_info,
+                                                                               cu_info->bitmap[xcc][i % 4][j + i / 4], ct,
                                                                                cu_processor_id, k);
 
-                                               if (ret < 0)
-                                                       break;
+                                                       if (ret < 0)
+                                                               break;
 
-                                               if (!ret) {
-                                                       num_of_entries++;
-                                                       list_add_tail(&props_ext->list, &dev->cache_props);
-                                               }
+                                                       if (!ret) {
+                                                               num_of_entries++;
+                                                               list_add_tail(&props_ext->list, &dev->cache_props);
+                                                       }
 
-                                               /* Move to next CU block */
-                                               num_cu_shared = ((k + pcache_info[ct].num_cu_shared) <=
-                                                       pcu_info->num_cu_per_sh) ?
-                                                       pcache_info[ct].num_cu_shared :
-                                                       (pcu_info->num_cu_per_sh - k);
-                                               cu_processor_id += num_cu_shared;
+                                                       /* Move to next CU block */
+                                                       num_cu_shared = ((k + pcache_info[ct].num_cu_shared) <=
+                                                               gfx_info->max_cu_per_sh) ?
+                                                               pcache_info[ct].num_cu_shared :
+                                                               (gfx_info->max_cu_per_sh - k);
+                                                       cu_processor_id += num_cu_shared;
+                                               }
                                        }
                                }
                        }
                } else {
                        ret = fill_in_l2_l3_pcache(&props_ext, pcache_info,
-                                                               pcu_info, ct, cu_processor_id);
+                                                  cu_info, gfx_info, ct, cu_processor_id, kdev);
 
                        if (ret < 0)
                                break;
@@ -1909,10 +1916,11 @@ int kfd_topology_add_device(struct kfd_node *gpu)
 {
        uint32_t gpu_id;
        struct kfd_topology_device *dev;
-       struct kfd_cu_info cu_info;
        int res = 0;
        int i;
        const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
+       struct amdgpu_gfx_config *gfx_info = &gpu->adev->gfx.config;
+       struct amdgpu_cu_info *cu_info = &gpu->adev->gfx.cu_info;
 
        gpu_id = kfd_generate_gpu_id(gpu);
        if (gpu->xcp && !gpu->xcp->ddev) {
@@ -1950,9 +1958,6 @@ int kfd_topology_add_device(struct kfd_node *gpu)
        /* Fill-in additional information that is not available in CRAT but
         * needed for the topology
         */
-
-       amdgpu_amdkfd_get_cu_info(dev->gpu->adev, &cu_info);
-
        for (i = 0; i < KFD_TOPOLOGY_PUBLIC_NAME_SIZE-1; i++) {
                dev->node_props.name[i] = __tolower(asic_name[i]);
                if (asic_name[i] == '\0')
@@ -1961,7 +1966,7 @@ int kfd_topology_add_device(struct kfd_node *gpu)
        dev->node_props.name[i] = '\0';
 
        dev->node_props.simd_arrays_per_engine =
-               cu_info.num_shader_arrays_per_engine;
+               gfx_info->max_sh_per_se;
 
        dev->node_props.gfx_target_version =
                                gpu->kfd->device_info.gfx_target_version;
@@ -2042,7 +2047,7 @@ int kfd_topology_add_device(struct kfd_node *gpu)
         */
        if (dev->gpu->adev->asic_type == CHIP_CARRIZO) {
                dev->node_props.simd_count =
-                       cu_info.simd_per_cu * cu_info.cu_active_number;
+                       cu_info->simd_per_cu * cu_info->number;
                dev->node_props.max_waves_per_simd = 10;
        }