[PATCH 3/5] xfree86/os: add xf86DMI stubs

Daniel Martin consume.noise at gmail.com
Sat Dec 7 07:48:48 PST 2013


Add stubs for DMI identifier initialization, cleanup, add and matching.

Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
 hw/xfree86/common/xf86Init.c              |   2 +
 hw/xfree86/os-support/bsd/Makefile.am     |   2 +
 hw/xfree86/os-support/hurd/Makefile.am    |   4 +-
 hw/xfree86/os-support/linux/Makefile.am   |   2 +
 hw/xfree86/os-support/shared/dmi.c        | 121 ++++++++++++++++++++++++++++++
 hw/xfree86/os-support/solaris/Makefile.am |   2 +
 hw/xfree86/os-support/stub/Makefile.am    |   1 +
 hw/xfree86/os-support/stub/stub_dmi.c     |  13 ++++
 hw/xfree86/os-support/xf86_OSproc.h       |   8 ++
 9 files changed, 154 insertions(+), 1 deletion(-)

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 91ec4c8..863450e 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -954,6 +954,7 @@ InitInput(int argc, char **argv)
     DeviceIntPtr dev;
 
     xf86Info.vtRequestsPending = FALSE;
+    xf86DMIInit();
 
     mieqInit();
 
@@ -976,6 +977,7 @@ CloseInput(void)
 {
     config_fini();
     mieqFini();
+    xf86DMICleanup();
 }
 
 /*
diff --git a/hw/xfree86/os-support/bsd/Makefile.am b/hw/xfree86/os-support/bsd/Makefile.am
index 7133c0f..04d8fa9 100644
--- a/hw/xfree86/os-support/bsd/Makefile.am
+++ b/hw/xfree86/os-support/bsd/Makefile.am
@@ -57,9 +57,11 @@ AM_CFLAGS = -DUSESTDRES $(XORG_CFLAGS) $(DIX_CFLAGS)
 AM_CPPFLAGS = $(XORG_INCS)
 
 libbsd_la_SOURCES = \
+	$(srcdir)/../shared/dmi.c \
 	$(srcdir)/../shared/posix_tty.c \
 	$(srcdir)/../shared/sigio.c \
 	$(srcdir)/../shared/vidmem.c \
+	$(srcdir)/../stub/stub_dmi.c \
 	bsd_VTsw.c \
 	bsd_init.c \
 	bsd_bell.c \
diff --git a/hw/xfree86/os-support/hurd/Makefile.am b/hw/xfree86/os-support/hurd/Makefile.am
index f228c1c..9b6d8ec 100644
--- a/hw/xfree86/os-support/hurd/Makefile.am
+++ b/hw/xfree86/os-support/hurd/Makefile.am
@@ -8,7 +8,9 @@ libhurd_la_SOURCES = hurd_bell.c hurd_init.c hurd_mmap.c \
 		$(srcdir)/../shared/sigiostubs.c \
 		$(srcdir)/../shared/pm_noop.c \
 		$(srcdir)/../shared/kmod_noop.c \
-		$(srcdir)/../shared/agp_noop.c
+		$(srcdir)/../shared/agp_noop.c \
+		$(srcdir)/../shared/dmi.c \
+		$(srcdir)/../stub/stub_dmi.c
 
 AM_CFLAGS = -DUSESTDRES -DHAVE_SYSV_IPC $(XORG_CFLAGS) $(DIX_CFLAGS)
 
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index e7be8c9..2918c38 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -24,9 +24,11 @@ endif
 liblinux_la_SOURCES = \
 	$(srcdir)/../shared/VTsw_usl.c \
 	$(srcdir)/../shared/bios_mmap.c \
+	$(srcdir)/../shared/dmi.c \
 	$(srcdir)/../shared/posix_tty.c \
 	$(srcdir)/../shared/sigio.c \
 	$(srcdir)/../shared/vidmem.c \
+	$(srcdir)/../stub/stub_dmi.c \
 	$(ACPI_SRCS) \
 	$(APM_SRCS) \
 	$(PLATFORM_PCI_SUPPORT) \
diff --git a/hw/xfree86/os-support/shared/dmi.c b/hw/xfree86/os-support/shared/dmi.c
new file mode 100644
index 0000000..8cf9f63
--- /dev/null
+++ b/hw/xfree86/os-support/shared/dmi.c
@@ -0,0 +1,121 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdlib.h>
+
+#include "xf86.h"
+#include "xf86_OSlib.h"
+#include "parser/xf86Parser.h"
+
+
+struct dmi_kv {
+    const char *const key;
+    char *value;
+}
+/* The key value mapping list. */
+static dmi_kv_map[] = {
+    {"BiosDate", NULL},
+    {"BiosVendor", NULL},
+    {"BiosVersion", NULL},
+    {"BoardName", NULL},
+    {"BoardVendor", NULL},
+    {"BoardVersion", NULL},
+    {"ChassisType", NULL},
+    {"ChassisVendor", NULL},
+    {"ChassisVersion", NULL},
+    {"ProductName", NULL},
+    {"ProductVersion", NULL},
+    {"SystemVendor", NULL},
+    {NULL, NULL}
+};
+
+/*
+ * Clear the key value mapping list.
+ */
+void
+xf86DMICleanup(void)
+{
+    struct dmi_kv *cur;
+
+    for (cur = &dmi_kv_map[0]; cur->key; cur++) {
+        free(cur->value);
+        cur->value = NULL;
+    }
+}
+
+/*
+ * Add a DMI id value for specific key to the key value mapping.
+ */
+void
+xf86DMIAdd(const char *const key, char *value)
+{
+    struct dmi_kv *dst, *tmp;
+
+    for (dst = NULL, tmp = &dmi_kv_map[0]; tmp->key; tmp++)
+        if (strcmp(tmp->key, key) == 0) {
+            dst = tmp;
+            break;
+        }
+
+    assert(dst);
+    dst->value = value;
+}
+
+/*
+ * Match DMI id values against a key value pair pattern. If a key value pair
+ * matches a key and value in dmi_kv_map, return TRUE.
+ */
+Bool
+xf86DMIMatchToken(struct xorg_list *patterns,
+                  int (*compare) (const char *attr, const char *pattern))
+{
+    Bool match;
+    const xf86MatchGroup *group;
+
+    match = FALSE;
+
+    /* If there are no patterns, accept the match */
+    if (xorg_list_is_empty(patterns))
+        return TRUE;
+
+    xorg_list_for_each_entry(group, patterns, entry) {
+        struct dmi_kv *cur;
+        const char *key;
+        const char *value;
+
+        /* group->values needs to have 2 values, the key and value. That's
+         * the result of a MatchDMI "key|value". */
+        key = group->values ? group->values[0] : NULL;
+        value = group->values && key ? group->values[1] : NULL;
+        if (!key || !value)
+            continue;
+
+        for (cur = &dmi_kv_map[0]; cur->key; cur++) {
+            if (compare(cur->key, key) != 0)
+                continue;
+
+            if (compare(cur->value, value) != 0)
+                return FALSE;
+
+            match = TRUE;
+        }
+    }
+
+    return match;
+}
+
+/*
+ * Is the passed string a valid key? (Used within the parser.)
+ */
+Bool
+xf86DMIValidKey(const char *const key)
+{
+    struct dmi_kv *cur;
+
+    for (cur = &dmi_kv_map[0]; cur->key; cur++)
+        if (strcmp(cur->key, key) == 0)
+            return TRUE;
+
+    return FALSE;
+}
diff --git a/hw/xfree86/os-support/solaris/Makefile.am b/hw/xfree86/os-support/solaris/Makefile.am
index 6cda4b3..08f85a5 100644
--- a/hw/xfree86/os-support/solaris/Makefile.am
+++ b/hw/xfree86/os-support/solaris/Makefile.am
@@ -19,10 +19,12 @@ solaris- at SOLARIS_INOUT_ARCH@.il: solaris- at SOLARIS_INOUT_ARCH@.S
 noinst_LTLIBRARIES = libsolaris.la
 libsolaris_la_SOURCES = sun_init.c \
 	sun_vid.c sun_bell.c $(AGP_SRC) sun_apm.c \
+	$(srcdir)/../shared/dmi.c \
 	$(srcdir)/../shared/kmod_noop.c \
 	$(srcdir)/../shared/posix_tty.c \
 	$(srcdir)/../shared/sigio.c \
 	$(srcdir)/../shared/vidmem.c \
+	$(srcdir)/../stub/stub_dmi.c \
 	$(VTSW_SRC)
 nodist_libsolaris_la_SOURCES = $(SOLARIS_INOUT_SRC)
 
diff --git a/hw/xfree86/os-support/stub/Makefile.am b/hw/xfree86/os-support/stub/Makefile.am
index a39e17d..133cd8c 100644
--- a/hw/xfree86/os-support/stub/Makefile.am
+++ b/hw/xfree86/os-support/stub/Makefile.am
@@ -15,5 +15,6 @@ libstub_la_SOURCES = \
 	$(srcdir)/../shared/sigio.c \
 	stub_bell.c \
 	stub_bios.c \
+	stub_dmi.c \
 	stub_init.c \
 	stub_video.c
diff --git a/hw/xfree86/os-support/stub/stub_dmi.c b/hw/xfree86/os-support/stub/stub_dmi.c
new file mode 100644
index 0000000..30efadf
--- /dev/null
+++ b/hw/xfree86/os-support/stub/stub_dmi.c
@@ -0,0 +1,13 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86_OSlib.h"
+
+
+void
+xf86DMIInit(void)
+{
+    xf86Msg(X_WARNING, "MatchDMI not supported on this platform.\n");
+}
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 106168a..a622a53 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -217,6 +217,14 @@ extern _X_EXPORT void xf86InitVidMem(void);
 
 #endif                          /* XF86_OS_PRIVS */
 
+extern _X_HIDDEN void xf86DMIInit(void);
+extern _X_HIDDEN void xf86DMICleanup(void);
+extern _X_HIDDEN void xf86DMIAdd(const char *const key, char *value);
+extern _X_HIDDEN Bool xf86DMIMatchToken(struct xorg_list *patterns,
+                                        int (*compare) (const char *attr,
+                                                        const char *pattern));
+extern _X_HIDDEN Bool xf86DMIValidKey(const char *const key);
+
 #ifdef XSERVER_PLATFORM_BUS
 #include "hotplug.h"
 void
-- 
1.8.4.2



More information about the xorg-devel mailing list