<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Calibri" size="2"><span style="font-size:10pt;">
<div style="padding-right:5pt;padding-left:5pt;"><font color="blue">[AMD Official Use Only - AMD Internal Distribution Only]<br>
</font></div>
<div style="margin-top:5pt;"><font face="Times New Roman" size="3"><span style="font-size:12pt;"><br>
</span></font></div>
<div><font face="Calibri" size="2"><span style="font-size:11pt;">Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com></span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Calibri" size="2"><span style="font-size:11pt;">Regards,<br>
Hawking</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">-----Original Message-----<br>
From: Kamal, Asad <Asad.Kamal@amd.com> <br>
Sent: Tuesday, November 5, 2024 20:34<br>
To: amd-gfx@lists.freedesktop.org; Lazar, Lijo <Lijo.Lazar@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
Cc: Ma, Le <Le.Ma@amd.com>; Zhang, Morris <Shiwu.Zhang@amd.com>; Kamal, Asad <Asad.Kamal@amd.com>; Poag, Charis <Charis.Poag@amd.com>; Cheung, Donald <donald.cheung@amd.com>; Khatir, Sepehr <sepehr.khatir@amd.com>; Oliveira, Daniel <Daniel.Oliveira@amd.com><br>
Subject: [PATCH v3] drm/amdgpu: Add supported NPS modes node</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">Add sysfs node to show supported NPS mode for the partition configuration selected using xcp_config</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">v2: Hide node if dynamic nps switch not supported</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">v3: Fix removal of files in case of error</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">Signed-off-by: Asad Kamal <<a href="mailto:asad.kamal@amd.com">asad.kamal@amd.com</a>></span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">Reviewed-by: Lijo Lazar <<a href="mailto:lijo.lazar@amd.com">lijo.lazar@amd.com</a>></span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">---</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 48 ++++++++++++++++++++++++-</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> 1 file changed, 47 insertions(+), 1 deletion(-)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">index 83a16918ea76..e209b5e101df 100644</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">@@ -471,6 +471,16 @@ static const char *xcp_desc[] = {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> [AMDGPU_CPX_PARTITION_MODE] = "CPX",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> };</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+static const char *nps_desc[] = {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [UNKNOWN_MEMORY_PARTITION_MODE] = "UNKNOWN",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [AMDGPU_NPS1_PARTITION_MODE] = "NPS1",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [AMDGPU_NPS2_PARTITION_MODE] = "NPS2",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [AMDGPU_NPS3_PARTITION_MODE] = "NPS3",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [AMDGPU_NPS4_PARTITION_MODE] = "NPS4",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [AMDGPU_NPS6_PARTITION_MODE] = "NPS6",</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ [AMDGPU_NPS8_PARTITION_MODE] = "NPS8", };</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> ATTRIBUTE_GROUPS(xcp_cfg_res_sysfs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> #define to_xcp_attr(x) \</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">@@ -540,6 +550,26 @@ static ssize_t supported_xcp_configs_show(struct kobject *kobj,</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> return size;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+static ssize_t supported_nps_configs_show(struct kobject *kobj,</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ struct kobj_attribute *attr, char *buf) {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ struct amdgpu_xcp_cfg *xcp_cfg = to_xcp_cfg(kobj);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ int size = 0, mode;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ char *sep = "";</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ if (!xcp_cfg || !xcp_cfg->compatible_nps_modes)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ return sysfs_emit(buf, "Not supported\n");</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ for_each_inst(mode, xcp_cfg->compatible_nps_modes) {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ size += sysfs_emit_at(buf, size, "%s%s", sep, nps_desc[mode]);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ sep = ", ";</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ size += sysfs_emit_at(buf, size, "\n");</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ return size;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+}</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> static ssize_t xcp_config_show(struct kobject *kobj,</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> struct kobj_attribute *attr, char *buf) { @@ -596,6 +626,9 @@ static const struct kobj_type xcp_cfg_sysfs_ktype = { static struct kobj_attribute supp_part_sysfs_mode
=</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> __ATTR_RO(supported_xcp_configs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+static struct kobj_attribute supp_nps_sysfs_mode =</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ __ATTR_RO(supported_nps_configs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> static const struct attribute *xcp_attrs[] = {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> &supp_part_sysfs_mode.attr,</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> &xcp_cfg_sysfs_mode.attr,</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">@@ -625,13 +658,24 @@ void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> if (r)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> goto err1;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ if (adev->gmc.supported_nps_modes != 0) {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ r = sysfs_create_file(&xcp_cfg->kobj, &supp_nps_sysfs_mode.attr);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ if (r) {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ sysfs_remove_files(&xcp_cfg->kobj, xcp_attrs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ goto err1;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> mode = (xcp_cfg->xcp_mgr->mode ==</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE) ?</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> AMDGPU_SPX_PARTITION_MODE :</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> xcp_cfg->xcp_mgr->mode;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> r = amdgpu_xcp_get_res_info(xcp_cfg->xcp_mgr, mode, xcp_cfg);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">- if (r)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ if (r) {</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ sysfs_remove_file(&xcp_cfg->kobj, &supp_nps_sysfs_mode.attr);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ sysfs_remove_files(&xcp_cfg->kobj, xcp_attrs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> goto err1;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> xcp_cfg->mode = mode;</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> for (i = 0; i < xcp_cfg->num_res; i++) { @@ -653,6 +697,7 @@ void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> kobject_put(&xcp_res->kobj);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ sysfs_remove_file(&xcp_cfg->kobj, &supp_nps_sysfs_mode.attr);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> sysfs_remove_files(&xcp_cfg->kobj, xcp_attrs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> err1:</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> kobject_put(&xcp_cfg->kobj);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">@@ -673,6 +718,7 @@ void amdgpu_xcp_cfg_sysfs_fini(struct amdgpu_device *adev)</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> kobject_put(&xcp_res->kobj);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">+ sysfs_remove_file(&xcp_cfg->kobj, &supp_nps_sysfs_mode.attr);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> sysfs_remove_files(&xcp_cfg->kobj, xcp_attrs);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> kobject_put(&xcp_cfg->kobj);</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> }</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">--</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;">2.46.0</span></font></div>
<div><font face="Arial" size="2"><span style="font-size:11pt;"> </span></font></div>
</span></font>
</body>
</html>