drm/amdgpu: Fix discovery sys node harvest info
authorLijo Lazar <lijo.lazar@amd.com>
Fri, 10 Feb 2023 06:35:59 +0000 (12:05 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 9 Jun 2023 13:55:51 +0000 (09:55 -0400)
Initalize syfs nodes after harvest information is fetched and fetch the
correct harvest info based on each IP instance.

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Le Ma <le.ma@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c

index 01b2198..d81b2e1 100644 (file)
@@ -877,6 +877,36 @@ static void ip_disc_release(struct kobject *kobj)
        kfree(ip_top);
 }
 
+static uint8_t amdgpu_discovery_get_harvest_info(struct amdgpu_device *adev,
+                                                uint16_t hw_id, uint8_t inst)
+{
+       uint8_t harvest = 0;
+
+       /* Until a uniform way is figured, get mask based on hwid */
+       switch (hw_id) {
+       case VCN_HWID:
+               harvest = (1 << inst) & adev->vcn.harvest_config;
+               break;
+       case DMU_HWID:
+               if (adev->harvest_ip_mask & AMD_HARVEST_IP_DMU_MASK)
+                       harvest = 0x1;
+               break;
+       case UMC_HWID:
+               /* TODO: It needs another parsing; for now, ignore.*/
+               break;
+       case GC_HWID:
+               harvest = ((1 << inst) & adev->gfx.xcc_mask) == 0;
+               break;
+       case SDMA0_HWID:
+               harvest = ((1 << inst) & adev->sdma.sdma_mask) == 0;
+               break;
+       default:
+               break;
+       }
+
+       return harvest;
+}
+
 static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
                                      struct ip_die_entry *ip_die_entry,
                                      const size_t _ip_offset, const int num_ips,
@@ -949,7 +979,10 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
                        ip_hw_instance->major = ip->major;
                        ip_hw_instance->minor = ip->minor;
                        ip_hw_instance->revision = ip->revision;
-                       ip_hw_instance->harvest = ip->variant;
+                       ip_hw_instance->harvest =
+                               amdgpu_discovery_get_harvest_info(
+                                       adev, ip_hw_instance->hw_id,
+                                       ip_hw_instance->num_instance);
                        ip_hw_instance->num_base_addresses = ip->num_base_address;
 
                        for (kk = 0; kk < ip_hw_instance->num_base_addresses; kk++) {
@@ -1035,6 +1068,9 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev)
        struct kset *die_kset;
        int res, ii;
 
+       if (!adev->mman.discovery_bin)
+               return -EINVAL;
+
        adev->ip_top = kzalloc(sizeof(*adev->ip_top), GFP_KERNEL);
        if (!adev->ip_top)
                return -ENOMEM;
@@ -1282,8 +1318,6 @@ next_ip:
                }
        }
 
-       amdgpu_discovery_sysfs_init(adev);
-
        return 0;
 }
 
@@ -2224,6 +2258,7 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
        }
 
        amdgpu_discovery_init_soc_config(adev);
+       amdgpu_discovery_sysfs_init(adev);
 
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):