]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu-dmi: Move some functions related to DMI to lscpu-dmi
authorMasayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Fri, 20 Nov 2020 05:06:07 +0000 (00:06 -0500)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Nov 2020 08:17:12 +0000 (09:17 +0100)
Move some functions related to DMI to lscpu-dmi.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
sys-utils/Makemodule.am
sys-utils/lscpu-dmi.c [new file with mode: 0644]
sys-utils/lscpu-virt.c
sys-utils/lscpu.h

index 5459a3a2eb13617d0bcfbb9c785b5d15ba4e1b98..df8fd403a7ac4dba6230de33fdc6e4c450dcf33c 100644 (file)
@@ -396,6 +396,7 @@ lscpu_SOURCES = sys-utils/lscpu.c \
                sys-utils/lscpu-topology.c \
                sys-utils/lscpu-virt.c \
                sys-utils/lscpu-arm.c \
+               sys-utils/lscpu-dmi.c \
                sys-utils/lscpu.h
 lscpu_LDADD = $(LDADD) libcommon.la libsmartcols.la $(RTAS_LIBS)
 lscpu_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
new file mode 100644 (file)
index 0000000..00d4439
--- /dev/null
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 FUJITSU LIMITED.  All rights reserved.
+ */
+
+#include "lscpu.h"
+
+void to_dmi_header(struct lscpu_dmi_header *h, uint8_t *data)
+{
+       h->type = data[0];
+       h->length = data[1];
+       memcpy(&h->handle, data + 2, sizeof(h->handle));
+       h->data = data;
+}
+
+char *dmi_string(const struct lscpu_dmi_header *dm, uint8_t s)
+{
+       char *bp = (char *)dm->data;
+
+       if (!s || !bp)
+               return NULL;
+
+       bp += dm->length;
+       while (s > 1 && *bp) {
+               bp += strlen(bp);
+               bp++;
+               s--;
+       }
+
+       return !*bp ? NULL : bp;
+}
+
+int parse_dmi_table(uint16_t len, uint16_t num,
+                               uint8_t *data,
+                               struct dmi_info *di)
+{
+       uint8_t *buf = data;
+       int rc = -1;
+       int i = 0;
+
+        /* 4 is the length of an SMBIOS structure header */
+       while (i < num && data + 4 <= buf + len) {
+               uint8_t *next;
+               struct lscpu_dmi_header h;
+
+               to_dmi_header(&h, data);
+
+               /*
+                * If a short entry is found (less than 4 bytes), not only it
+                * is invalid, but we cannot reliably locate the next entry.
+                * Better stop at this point.
+                */
+               if (h.length < 4)
+                       goto done;
+
+               /* look for the next handle */
+               next = data + h.length;
+               while (next - buf + 1 < len && (next[0] != 0 || next[1] != 0))
+                       next++;
+               next += 2;
+               switch (h.type) {
+               case 0:
+                       di->vendor = dmi_string(&h, data[0x04]);
+                       break;
+               case 1:
+                       di->manufacturer = dmi_string(&h, data[0x04]);
+                       di->product = dmi_string(&h, data[0x05]);
+                       break;
+               default:
+                       break;
+               }
+
+               data = next;
+               i++;
+       }
+       rc = 0;
+done:
+       return rc;
+}
index c86dae8c993ace97ba09c49905de669e6d11ce07..9b61eb6f84e3234c335cf0cc9664e005314fb0f7 100644 (file)
@@ -52,7 +52,7 @@ static const int hv_graphics_pci[] = {
 #define WORD(x) (uint16_t)(*(const uint16_t *)(x))
 #define DWORD(x) (uint32_t)(*(const uint32_t *)(x))
 
-static void *get_mem_chunk(size_t base, size_t len, const char *devmem)
+void *get_mem_chunk(size_t base, size_t len, const char *devmem)
 {
        void *p = NULL;
        int fd;
@@ -76,54 +76,6 @@ nothing:
        return NULL;
 }
 
-static int parse_dmi_table(uint16_t len, uint16_t num,
-                               uint8_t *data,
-                               struct dmi_info *di)
-{
-       uint8_t *buf = data;
-       int rc = -1;
-       int i = 0;
-
-        /* 4 is the length of an SMBIOS structure header */
-       while (i < num && data + 4 <= buf + len) {
-               uint8_t *next;
-               struct lscpu_dmi_header h;
-
-               to_dmi_header(&h, data);
-
-               /*
-                * If a short entry is found (less than 4 bytes), not only it
-                * is invalid, but we cannot reliably locate the next entry.
-                * Better stop at this point.
-                */
-               if (h.length < 4)
-                       goto done;
-
-               /* look for the next handle */
-               next = data + h.length;
-               while (next - buf + 1 < len && (next[0] != 0 || next[1] != 0))
-                       next++;
-               next += 2;
-               switch (h.type) {
-                       case 0:
-                               di->vendor = dmi_string(&h, data[0x04]);
-                               break;
-                       case 1:
-                               di->manufacturer = dmi_string(&h, data[0x04]);
-                               di->product = dmi_string(&h, data[0x05]);
-                               break;
-                       default:
-                               break;
-               }
-
-               data = next;
-               i++;
-       }
-       rc = 0;
-done:
-       return rc;
-}
-
 static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
                                uint16_t num, const char *devmem)
 {
index 11b27fb142ae3edec4da4d3fb3d57c9a55d1c37f..9ec3fca17c8c237905b233b71ce34b47a1ee2c21 100644 (file)
@@ -297,6 +297,8 @@ void lscpu_decode_arm(struct lscpu_cxt *cxt);
 
 int lookup(char *line, char *pattern, char **value);
 
+void *get_mem_chunk(size_t base, size_t len, const char *devmem);
+
 struct lscpu_dmi_header
 {
        uint8_t type;
@@ -311,28 +313,8 @@ struct dmi_info {
        char *manufacturer;
 };
 
-static inline void to_dmi_header(struct lscpu_dmi_header *h, uint8_t *data)
-{
-       h->type = data[0];
-       h->length = data[1];
-       memcpy(&h->handle, data + 2, sizeof(h->handle));
-       h->data = data;
-}
-
-static inline char *dmi_string(const struct lscpu_dmi_header *dm, uint8_t s)
-{
-       char *bp = (char *)dm->data;
-
-       if (!s || !bp)
-               return NULL;
-
-       bp += dm->length;
-       while (s > 1 && *bp) {
-               bp += strlen(bp);
-               bp++;
-               s--;
-       }
 
-       return !*bp ? NULL : bp;
-}
+void to_dmi_header(struct lscpu_dmi_header *h, uint8_t *data);
+char *dmi_string(const struct lscpu_dmi_header *dm, uint8_t s);
+int parse_dmi_table(uint16_t len, uint16_t num, uint8_t *data, struct dmi_info *di);
 #endif /* LSCPU_H */