<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div dir="ltr">
<div></div>
<div>
<div>
<div dir="ltr"><span id="ms-outlook-ios-cursor"></span>Reviewed-by: Yang Wang <kevinyang.wang@amd.com></div>
</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Best Regards,</div>
<div dir="ltr">Kevin</div>
<div id="mail-editor-reference-message-container" class="ms-outlook-mobile-reference-message">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"><b>发件人:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> 代表 Lijo Lazar <lijo.lazar@amd.com><br>
<b>发送时间:</b> 星期五, 八月 25, 2023 17:29<br>
<b>收件人:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>抄送:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>主题:</b> [PATCH] drm/amdgpu: Add only valid firmware version nodes
<div> </div>
</font></div>
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Show only firmware version attributes that have valid version. Hide<br>
others.<br>
<br>
Signed-off-by: Lijo Lazar <lijo.lazar@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 33 ++++++++++++++++++++---<br>
1 file changed, 29 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c<br>
index 8beefc045e14..b0b37c056c36 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c<br>
@@ -669,15 +669,25 @@ const char *amdgpu_ucode_name(enum AMDGPU_UCODE_ID ucode_id)<br>
}<br>
}<br>
<br>
+static inline int amdgpu_ucode_is_valid(uint32_t fw_version)<br>
+{<br>
+ if (!fw_version)<br>
+ return -EINVAL;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
#define FW_VERSION_ATTR(name, mode, field) \<br>
static ssize_t show_##name(struct device *dev, \<br>
- struct device_attribute *attr, \<br>
- char *buf) \<br>
+ struct device_attribute *attr, char *buf) \<br>
{ \<br>
struct drm_device *ddev = dev_get_drvdata(dev); \<br>
struct amdgpu_device *adev = drm_to_adev(ddev); \<br>
\<br>
- return sysfs_emit(buf, "0x%08x\n", adev->field); \<br>
+ if (!buf) \<br>
+ return amdgpu_ucode_is_valid(adev->field); \<br>
+ \<br>
+ return sysfs_emit(buf, "0x%08x\n", adev->field); \<br>
} \<br>
static DEVICE_ATTR(name, mode, show_##name, NULL)<br>
<br>
@@ -722,9 +732,24 @@ static struct attribute *fw_attrs[] = {<br>
NULL<br>
};<br>
<br>
+#define to_dev_attr(x) container_of(x, struct device_attribute, attr)<br>
+<br>
+static umode_t amdgpu_ucode_sys_visible(struct kobject *kobj,<br>
+ struct attribute *attr, int idx)<br>
+{<br>
+ struct device_attribute *dev_attr = to_dev_attr(attr);<br>
+ struct device *dev = kobj_to_dev(kobj);<br>
+<br>
+ if (dev_attr->show(dev, dev_attr, NULL) == -EINVAL)<br>
+ return 0;<br>
+<br>
+ return attr->mode;<br>
+}<br>
+<br>
static const struct attribute_group fw_attr_group = {<br>
.name = "fw_version",<br>
- .attrs = fw_attrs<br>
+ .attrs = fw_attrs,<br>
+ .is_visible = amdgpu_ucode_sys_visible<br>
};<br>
<br>
int amdgpu_ucode_sysfs_init(struct amdgpu_device *adev)<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>