From b3128c17d74233a4de449464559f26094be41d5e Mon Sep 17 00:00:00 2001
From: YunYi Yang <yangyunyi2@huawei.com>
Date: Sat, 29 Mar 2025 15:31:39 +0800
Subject: [PATCH] Add new cpu model name of arm Kunpeng

Add the display of the CPU model name when the CPU part id is 0xd02/0xd03 
for Kunpeng. The ID may correspond to multiple cpu model names. Therefore,
refer to the bios model name.

https://gitee.com/src-openeuler/util-linux/issues/IBBNGQ
---
 sys-utils/lscpu-arm.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
index 79b8e3a..4c60973 100644
--- a/sys-utils/lscpu-arm.c
+++ b/sys-utils/lscpu-arm.c
@@ -29,6 +29,7 @@
 struct id_part {
     const int id;
     const char* name;
+    char* (*inner)(const int, const char*, struct lscpu_cputype *ct);
 };
 
 static const struct id_part arm_part[] = {
@@ -183,9 +184,13 @@ static const struct id_part fujitsu_part[] = {
     { -1, "unknown" },
 };
 
+
+char* hisi_get_inner_name_compatible(const int id, const char* name, struct lscpu_cputype *ct);
+
 static const struct id_part hisi_part[] = {
-    { 0xd01, "Kunpeng-920" },	/* aka tsv110 */
-    { -1, "unknown" },
+    { 0xd01, "Kunpeng-920", NULL },
+    { 0xd02, "unknown", hisi_get_inner_name_compatible},
+    { -1, "unknown", NULL },
 };
 
 static const struct id_part ft_part[] = {
@@ -252,6 +2597,19 @@ static inline int parse_implementer_id(struct lscpu_cputype *ct)
 	return ct->vendor_id;
 }
 
+char* hisi_get_inner_name_compatible(const int id __attribute__((unused)), const char* name, struct lscpu_cputype *ct)
+{
+    char* bios_modelname = ct->bios_modelname;
+    if (bios_modelname == NULL) {
+        return (char*)name;
+    }
+    // Compatible with HUAWEI Kunpeng 920 7282C models
+    if (strstr(bios_modelname, "7282C") != NULL) {
+        return "Kunpeng 920 7282C";
+    }
+    return bios_modelname;
+}
+
 /*
  * Use model and vendor IDs to decode to human readable names.
  */
@@ -285,7 +303,13 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
 	for (j = 0; parts[j].id != -1; j++) {
 		if (parts[j].id == part) {
 			free(ct->modelname);
-			ct->modelname = xstrdup(parts[j].name);
+            char* real_name = NULL;
+            if (parts[j].inner != NULL) {
+                real_name = parts[j].inner(parts[j].id, parts[j].name, ct);
+            } else {
+                real_name = (char*)parts[j].name;
+            }
+			ct->modelname = xstrdup(real_name);
 			break;
 		}
 	}
-- 
2.33.0

