Skip to contentSkip to conversation

drm/amdgpu: Add only valid firmware version nodes

PATCH In review Lijo Lazar 3 participants 3 messages Aug 25, 2023

Subsystems (2)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Add only valid firmware version nodes

Show only firmware version attributes that have valid version. Hide others.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 33 ++++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +29 -4
index 8beefc045e14..b0b37c056c36 100644
@@ -669,15 +669,25 @@ const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)
 	}
 }
 
+static inline int amdgpu_ucode_is_valid(uint32_t fw_version)
+{
+	if (!fw_version)
+		return -EINVAL;
+
+	return 0;
+}
+
 #define FW_VERSION_ATTR(name, mode, field)				\
 static ssize_t show_##name(struct device *dev,				\
-			  struct device_attribute *attr,		\
-			  char *buf)					\
+			   struct device_attribute *attr, char *buf)	\
 {									\
 	struct drm_device *ddev = dev_get_drvdata(dev);			\
 	struct amdgpu_device *adev = drm_to_adev(ddev);			\
 									\
-	return sysfs_emit(buf, "0x%08x\n", adev->field);	\
+	if (!buf)							\
+		return amdgpu_ucode_is_valid(adev->field);		\
+									\
+	return sysfs_emit(buf, "0x%08x\n", adev->field);		\
 }									\
 static DEVICE_ATTR(name, mode, show_##name, NULL)
 
@@ -722,9 +732,24 @@ static struct attribute *fw_attrs[] = {
 	NULL
 };
 
+#define to_dev_attr(x) container_of(x, struct device_attribute, attr)
+
+static umode_t amdgpu_ucode_sys_visible(struct kobject *kobj,
+					struct attribute *attr, int idx)
+{
+	struct device_attribute *dev_attr = to_dev_attr(attr);
+	struct device *dev = kobj_to_dev(kobj);
+
+	if (dev_attr->show(dev, dev_attr, NULL) == -EINVAL)
+		return 0;
+
+	return attr->mode;
+}
+
 static const struct attribute_group fw_attr_group = {
 	.name = "fw_version",
-	.attrs = fw_attrs
+	.attrs = fw_attrs,
+	.is_visible = amdgpu_ucode_sys_visible
 };
 
 int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev)
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - General]

Best Regards,
Kevin
________________________________
发件人: amd-gfx <[email protected]> 代表 Lijo Lazar <[email protected]> 发送时间: 星期五, 八月 25, 2023 17:29
收件人: [email protected] <[email protected]>
抄送: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]> 主题: [PATCH] drm/amdgpu: Add only valid firmware version nodes

Show only firmware version attributes that have valid version. Hide others.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 33 ++++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +29 -4
index 8beefc045e14..b0b37c056c36 100644
@@ -669,15 +669,25 @@ const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)
         }
 }
 
+static inline int amdgpu_ucode_is_valid(uint32_t fw_version)
+{
+       if (!fw_version)
+               return -EINVAL;
+
+       return 0;
+}
+
 #define FW_VERSION_ATTR(name, mode, field)                              \
 static ssize_t show_##name(struct device *dev,                          \
-                         struct device_attribute *attr,         \
-                         char *buf)                                     \
+                          struct device_attribute *attr, char *buf)     \
 {                                                                       \
         struct drm_device *ddev = dev_get_drvdata(dev);                 \
         struct amdgpu_device *adev = drm_to_adev(ddev);                 \
                                                                         \
-       return sysfs_emit(buf, "0x%08x\n", adev->field);        \
+       if (!buf)                                                       \
+               return amdgpu_ucode_is_valid(adev->field);              \
+                                                                       \
+       return sysfs_emit(buf, "0x%08x\n", adev->field);                \
 }                                                                       \
 static DEVICE_ATTR(name, mode, show_##name, NULL)
 
@@ -722,9 +732,24 @@ static struct attribute *fw_attrs[] = {
         NULL
 };
 
+#define to_dev_attr(x) container_of(x, struct device_attribute, attr)
+
+static umode_t amdgpu_ucode_sys_visible(struct kobject *kobj,
+                                       struct attribute *attr, int idx)
+{
+       struct device_attribute *dev_attr = to_dev_attr(attr);
+       struct device *dev = kobj_to_dev(kobj);
+
+       if (dev_attr->show(dev, dev_attr, NULL) == -EINVAL)
+               return 0;
+
+       return attr->mode;
+}
+
 static const struct attribute_group fw_attr_group = {
         .name = "fw_version",
-       .attrs = fw_attrs
+       .attrs = fw_attrs,
+       .is_visible = amdgpu_ucode_sys_visible
 };
 
 int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev)

--
2.25.1

Reviewed-by Asad Kamal [email protected] Reviewed-by Yang Wang
#2 lore raw

[AMD Official Use Only - General]

Thanks & Regards
Asad

From: amd-gfx <[email protected]> On Behalf Of Wang, Yang(Kevin)
Sent: Friday, August 25, 2023 4:46 PM
To: [email protected]; Lazar, Lijo <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Add only valid firmware version nodes

[AMD Official Use Only - General]

[AMD Official Use Only - General]

Best Regards,
Kevin
________________________________
发件人: amd-gfx <[email protected]<mailto:[email protected]>> 代表 Lijo Lazar <[email protected]<mailto:[email protected]>> 发送时间: 星期五, 八月 25, 2023 17:29
收件人: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>> 抄送: Deucher, Alexander <[email protected]<mailto:[email protected]>>; Zhang, Hawking <[email protected]<mailto:[email protected]>> 主题: [PATCH] drm/amdgpu: Add only valid firmware version nodes

Show only firmware version attributes that have valid version. Hide others.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 33 ++++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +29 -4
index 8beefc045e14..b0b37c056c36 100644
@@ -669,15 +669,25 @@ const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)
         }
 }
 
+static inline int amdgpu_ucode_is_valid(uint32_t fw_version)
+{
+       if (!fw_version)
+               return -EINVAL;
+
+       return 0;
+}
+
 #define FW_VERSION_ATTR(name, mode, field)                              \
 static ssize_t show_##name(struct device *dev,                          \
-                         struct device_attribute *attr,         \
-                         char *buf)                                     \
+                          struct device_attribute *attr, char *buf)     \
 {                                                                       \
         struct drm_device *ddev = dev_get_drvdata(dev);                 \
         struct amdgpu_device *adev = drm_to_adev(ddev);                 \
                                                                         \
-       return sysfs_emit(buf, "0x%08x\n", adev->field);        \
+       if (!buf)                                                       \
+               return amdgpu_ucode_is_valid(adev->field);              \
+                                                                       \
+       return sysfs_emit(buf, "0x%08x\n", adev->field);                \
 }                                                                       \
 static DEVICE_ATTR(name, mode, show_##name, NULL)
 
@@ -722,9 +732,24 @@ static struct attribute *fw_attrs[] = {
         NULL
 };
 
+#define to_dev_attr(x) container_of(x, struct device_attribute, attr)
+
+static umode_t amdgpu_ucode_sys_visible(struct kobject *kobj,
+                                       struct attribute *attr, int idx)
+{
+       struct device_attribute *dev_attr = to_dev_attr(attr);
+       struct device *dev = kobj_to_dev(kobj);
+
+       if (dev_attr->show(dev, dev_attr, NULL) == -EINVAL)
+               return 0;
+
+       return attr->mode;
+}
+
 static const struct attribute_group fw_attr_group = {
         .name = "fw_version",
-       .attrs = fw_attrs
+       .attrs = fw_attrs,
+       .is_visible = amdgpu_ucode_sys_visible
 };
 
 int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev)

--
2.25.1