dmidecode-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dmidecode] [PATCH 5/6] dmidecode: Make dmi_print_cpuid more flexible


From: Jean Delvare
Subject: [dmidecode] [PATCH 5/6] dmidecode: Make dmi_print_cpuid more flexible
Date: Thu, 4 Mar 2021 17:48:36 +0100

Let the caller choose which printing helper function will be used.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
 dmidecode.c |   49 +++++++++++++++++++++++++------------------------
 dmidecode.h |    3 ++-
 2 files changed, 27 insertions(+), 25 deletions(-)

--- dmidecode.orig/dmidecode.c  2021-03-04 14:00:51.684765808 +0100
+++ dmidecode/dmidecode.c       2021-03-04 14:03:09.574370312 +0100
@@ -1113,7 +1113,8 @@ static enum cpuid_type dmi_set_cpuid_typ
        return cpuid_none;
 }
 
-void dmi_print_cpuid(const char *label, enum cpuid_type sig, const u8 *p)
+void dmi_print_cpuid(void (*print_cb)(const char *name, const char *format, 
...),
+                    const char *label, enum cpuid_type sig, const u8 *p)
 {
        u32 eax, midr;
        u16 dx;
@@ -1125,18 +1126,18 @@ void dmi_print_cpuid(const char *label,
                        /*
                         * 80386 have a different signature.
                         */
-                       pr_attr(label,
-                               "Type %u, Family %u, Major Stepping %u, Minor 
Stepping %u",
-                               dx >> 12, (dx >> 8) & 0xF,
-                               (dx >> 4) & 0xF, dx & 0xF);
+                       print_cb(label,
+                                "Type %u, Family %u, Major Stepping %u, Minor 
Stepping %u",
+                                dx >> 12, (dx >> 8) & 0xF,
+                                (dx >> 4) & 0xF, dx & 0xF);
                        return;
 
                case cpuid_80486:
                        dx = WORD(p);
-                       pr_attr(label,
-                               "Type %u, Family %u, Model %u, Stepping %u",
-                               (dx >> 12) & 0x3, (dx >> 8) & 0xF,
-                               (dx >> 4) & 0xF, dx & 0xF);
+                       print_cb(label,
+                                "Type %u, Family %u, Model %u, Stepping %u",
+                                (dx >> 12) & 0x3, (dx >> 8) & 0xF,
+                                (dx >> 4) & 0xF, dx & 0xF);
                        return;
 
                case cpuid_arm: /* ARM */
@@ -1148,10 +1149,10 @@ void dmi_print_cpuid(const char *label,
                         */
                        if (midr == 0)
                                return;
-                       pr_attr(label,
-                               "Implementor 0x%02x, Variant 0x%x, Architecture 
%u, Part 0x%03x, Revision %u",
-                               midr >> 24, (midr >> 20) & 0xF,
-                               (midr >> 16) & 0xF, (midr >> 4) & 0xFFF, midr & 
0xF);
+                       print_cb(label,
+                                "Implementor 0x%02x, Variant 0x%x, 
Architecture %u, Part 0x%03x, Revision %u",
+                                midr >> 24, (midr >> 20) & 0xF,
+                                (midr >> 16) & 0xF, (midr >> 4) & 0xFFF, midr 
& 0xF);
                        return;
 
                case cpuid_x86_intel: /* Intel */
@@ -1162,20 +1163,20 @@ void dmi_print_cpuid(const char *label,
                         * explained in table 3-5, but DMI doesn't support this
                         * yet.
                         */
-                       pr_attr(label,
-                               "Type %u, Family %u, Model %u, Stepping %u",
-                               (eax >> 12) & 0x3,
-                               ((eax >> 20) & 0xFF) + ((eax >> 8) & 0x0F),
-                               ((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F),
-                               eax & 0xF);
+                       print_cb(label,
+                                "Type %u, Family %u, Model %u, Stepping %u",
+                                (eax >> 12) & 0x3,
+                                ((eax >> 20) & 0xFF) + ((eax >> 8) & 0x0F),
+                                ((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F),
+                                eax & 0xF);
                        break;
 
                case cpuid_x86_amd: /* AMD, publication #25481 revision 2.28 */
                        eax = DWORD(p);
-                       pr_attr(label, "Family %u, Model %u, Stepping %u",
-                               ((eax >> 8) & 0xF) + (((eax >> 8) & 0xF) == 0xF 
? (eax >> 20) & 0xFF : 0),
-                               ((eax >> 4) & 0xF) | (((eax >> 8) & 0xF) == 0xF 
? (eax >> 12) & 0xF0 : 0),
-                               eax & 0xF);
+                       print_cb(label, "Family %u, Model %u, Stepping %u",
+                                ((eax >> 8) & 0xF) + (((eax >> 8) & 0xF) == 
0xF ? (eax >> 20) & 0xFF : 0),
+                                ((eax >> 4) & 0xF) | (((eax >> 8) & 0xF) == 
0xF ? (eax >> 12) & 0xF0 : 0),
+                                eax & 0xF);
                        break;
                default:
                        return;
@@ -1232,7 +1233,7 @@ static void dmi_processor_id(const struc
                pr_attr("ID", "%02X %02X %02X %02X %02X %02X %02X %02X",
                        p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
 
-       dmi_print_cpuid("Signature", sig, p);
+       dmi_print_cpuid(pr_attr, "Signature", sig, p);
 
        if (sig != cpuid_x86_intel && sig != cpuid_x86_amd)
                return;
--- dmidecode.orig/dmidecode.h  2021-03-04 13:52:42.636061331 +0100
+++ dmidecode/dmidecode.h       2021-03-04 14:02:14.326727441 +0100
@@ -46,6 +46,7 @@ enum cpuid_type cpuid_type;
 int is_printable(const u8 *data, int len);
 const char *dmi_string(const struct dmi_header *dm, u8 s);
 void dmi_print_memory_size(const char *addr, u64 code, int shift);
-void dmi_print_cpuid(const char *label, enum cpuid_type sig, const u8 *p);
+void dmi_print_cpuid(void (*print_cb)(const char *name, const char *format, 
...),
+                    const char *label, enum cpuid_type sig, const u8 *p);
 
 #endif

-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]