Skip to contentSkip to conversation

drm/amdgpu: fix sysfs ip base addr for 64bit in standalone mode

PATCH In review Mukul Joshi 3 participants 3 messages Aug 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix sysfs ip base addr for 64bit in standalone mode

In standalone mode the ip_discovery sysfs tree is built from a verbatim copy of the discovery binary taken before reg_base_init() collapses the 64bit base addresses in place. Decoding as 32bit there yields interleaved zeros. Decode base_address_64[] in that case; keep reading the already collapsed adev->discovery.bin as-is otherwise.

Fixes 3ee1065e9830 ("drm/amdgpu: Export ip_discovery sysfs on probe failure")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +13 -2
index b5bc0d71653d..8745b0a66f1d 100644
@@ -1308,8 +1308,19 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
 					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++)
-				ip_hw_instance->base_addr[kk] = ip->base_address[kk];
+			for (kk = 0; kk < ip_hw_instance->num_base_addresses; kk++) {
+				/*
+				 * Standalone mode uses a raw copy of the discovery
+				 * binary; decode 64-bit addresses here. The shared
+				 * bin is already collapsed to 32-bit in place.
+				 */
+				if (reg_base_64 && ip_top->standalone_mode)
+					ip_hw_instance->base_addr[kk] =
+						lower_32_bits(le64_to_cpu(ip->base_address_64[kk])) & 0x3FFFFFFF;
+				else
+					ip_hw_instance->base_addr[kk] =
+						le32_to_cpu(ip->base_address[kk]);
+			}
 
 			kobject_init(&ip_hw_instance->kobj, &ip_hw_instance_ktype);
 			ip_hw_instance->kobj.kset = &ip_hw_id->hw_id_kset;
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Mukul Joshi

In standalone mode the ip_discovery sysfs tree is built from a verbatim copy of the discovery binary taken before reg_base_init() collapses the 64bit base addresses in place. Decoding as 32bit there yields interleaved zeros. Decode base_address_64[] in that case; keep reading the already collapsed adev->discovery.bin as-is otherwise.

Fixes 3ee1065e9830 ("drm/amdgpu: Export ip_discovery sysfs on probe failure")
Quoted 33 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +13 -3
index b5bc0d71653d..8745b0a66f1d 100644
@@ -1308,8 +1308,19 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
                                        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++)
-                               ip_hw_instance->base_addr[kk] = ip->base_address[kk];
+                       for (kk = 0; kk < ip_hw_instance->num_base_addresses; kk++) {
+                               /*
+                                * Standalone mode uses a raw copy of the discovery
+                                * binary; decode 64-bit addresses here. The shared
+                                * bin is already collapsed to 32-bit in place.
+                                */
+                               if (reg_base_64 && ip_top->standalone_mode)
+                                       ip_hw_instance->base_addr[kk] =
+                                               lower_32_bits(le64_to_cpu(ip->base_address_64[kk])) & 0x3FFFFFFF;
+                               else
+                                       ip_hw_instance->base_addr[kk] =
+                                               le32_to_cpu(ip->base_address[kk]);
+                       }
 
                        kobject_init(&ip_hw_instance->kobj, &ip_hw_instance_ktype);
                        ip_hw_instance->kobj.kset = &ip_hw_id->hw_id_kset;
--

2.54.0

Reviewed-by
#2 lore raw
Quoted 8 lines · Alex Deucher
Quoted 7 lines · Mukul Joshi

In standalone mode the ip_discovery sysfs tree is built from a verbatim copy of the discovery binary taken before reg_base_init() collapses the 64bit base addresses in place. Decoding as 32bit there yields interleaved zeros. Decode base_address_64[] in that case; keep reading the already collapsed adev->discovery.bin as-is otherwise.

Quoted 4 lines
Quoted 2 lines
Fixes 3ee1065e9830 ("drm/amdgpu: Export ip_discovery sysfs on probe failure")
Quoted 34 lines
Quoted 34 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +13 -3
index b5bc0d71653d..8745b0a66f1d 100644
@@ -1308,8 +1308,19 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
                                         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++)
-                               ip_hw_instance->base_addr[kk] = ip->base_address[kk];
+                       for (kk = 0; kk < ip_hw_instance->num_base_addresses; kk++) {
+                               /*
+                                * Standalone mode uses a raw copy of the discovery
+                                * binary; decode 64-bit addresses here. The shared
+                                * bin is already collapsed to 32-bit in place.
+                                */
+                               if (reg_base_64 && ip_top->standalone_mode)
+                                       ip_hw_instance->base_addr[kk] =
+                                               lower_32_bits(le64_to_cpu(ip->base_address_64[kk])) & 0x3FFFFFFF;
+                               else
+                                       ip_hw_instance->base_addr[kk] =
+                                               le32_to_cpu(ip->base_address[kk]);
+                       }
 
                         kobject_init(&ip_hw_instance->kobj, &ip_hw_instance_ktype);
                         ip_hw_instance->kobj.kset = &ip_hw_id->hw_id_kset;
--

2.54.0