From: Masayoshi Mizuma <msys.mizuma@gmail.com>
To: util-linux@vger.kernel.org
Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>,
Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Subject: [PATCH v2 3/5] lscpu-dmi: Move some functions related to DMI to lscpu-dmi
Date: Fri, 13 Nov 2020 23:12:27 -0500 [thread overview]
Message-ID: <20201114041229.26417-4-msys.mizuma@gmail.com> (raw)
In-Reply-To: <20201114041229.26417-1-msys.mizuma@gmail.com>
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Move some functions related to DMI to lscpu-dmi.
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
---
sys-utils/Makemodule.am | 1 +
sys-utils/lscpu-dmi.c | 79 +++++++++++++++++++++++++++++++++++++++++
sys-utils/lscpu-virt.c | 50 +-------------------------
sys-utils/lscpu.h | 28 +++------------
4 files changed, 86 insertions(+), 72 deletions(-)
create mode 100644 sys-utils/lscpu-dmi.c
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index 5459a3a2e..df8fd403a 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -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
index 000000000..00d4439f8
--- /dev/null
+++ b/sys-utils/lscpu-dmi.c
@@ -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;
+}
diff --git a/sys-utils/lscpu-virt.c b/sys-utils/lscpu-virt.c
index 32558fd9f..3b9d090a2 100644
--- a/sys-utils/lscpu-virt.c
+++ b/sys-utils/lscpu-virt.c
@@ -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)
{
diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
index b199de3dd..565f6aee5 100644
--- a/sys-utils/lscpu.h
+++ b/sys-utils/lscpu.h
@@ -298,6 +298,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;
@@ -312,28 +314,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 */
--
2.27.0
next prev parent reply other threads:[~2020-11-14 4:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-14 4:12 [PATCH v2 0/5] lscpu: Fix socket information on aarch64 machine Masayoshi Mizuma
2020-11-14 4:12 ` [PATCH v2 1/5] lscpu: use cluster on aarch64 machine which doesn't have ACPI PPTT Masayoshi Mizuma
2020-11-19 8:38 ` Karel Zak
2020-11-20 3:25 ` Masayoshi Mizuma
2020-11-14 4:12 ` [PATCH v2 2/5] lscpu-virt: split hypervisor_from_dmi_table() Masayoshi Mizuma
2020-11-14 4:12 ` Masayoshi Mizuma [this message]
2020-11-14 4:12 ` [PATCH v2 4/5] lscpu: add helper to get physical sockets Masayoshi Mizuma
2020-11-14 4:12 ` [PATCH v2 5/5] lscpu: show the number of physical socket on aarch64 machine without ACPI PPTT Masayoshi Mizuma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201114041229.26417-4-msys.mizuma@gmail.com \
--to=msys.mizuma@gmail.com \
--cc=m.mizuma@jp.fujitsu.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).