[v2 4/6] xfree86/os: add xf86DMI stubs
Peter Hutterer
peter.hutterer at who-t.net
Tue Dec 17 18:09:52 PST 2013
On Tue, Dec 17, 2013 at 11:35:57PM +0100, Daniel Martin wrote:
> Add stubs for DMI identifier initialization, cleanup, add and matching.
>
> Signed-off-by: Daniel Martin <consume.noise at gmail.com>
> ---
> v2: xf86DMIAdd: don't assert, log values on verbose=10
> xf86DMIMatchToken: comment on "if (xorg_list_is_empty(patterns))"
> xf86DMIValidKey: renamed to xf86DMIIsValidKey
> removed unnecessary tmp variables
Alan, can you work with that for the SMBios on solaris? Matthieu, Mark?
see patch 6/6 for the documentation.
> 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 | 120 ++++++++++++++++++++++++++++++
> 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, 153 insertions(+), 1 deletion(-)
> create mode 100644 hw/xfree86/os-support/shared/dmi.c
> create mode 100644 hw/xfree86/os-support/stub/stub_dmi.c
>
> diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
> index e9d1e7e..bfdd45a 100644
> --- a/hw/xfree86/common/xf86Init.c
> +++ b/hw/xfree86/common/xf86Init.c
> @@ -956,6 +956,7 @@ InitInput(int argc, char **argv)
> DeviceIntPtr dev;
>
> xf86Info.vtRequestsPending = FALSE;
> + xf86DMIInit();
>
> mieqInit();
>
> @@ -978,6 +979,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 746c340..e1f8bd8 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 = \
> ../shared/VTsw_usl.c \
> ../shared/bios_mmap.c \
> + ../shared/dmi.c \
> ../shared/posix_tty.c \
> ../shared/sigio.c \
> ../shared/vidmem.c \
> + ../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..6c02a18
> --- /dev/null
> +++ b/hw/xfree86/os-support/shared/dmi.c
> @@ -0,0 +1,120 @@
> +#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;
> +}
> +/* Supported keys. */
> +static dmi_kv_map[] = {
> + {"bios_date", NULL},
> + {"bios_vendor", NULL},
> + {"bios_version", NULL},
> + {"board_name", NULL},
> + {"board_vendor", NULL},
> + {"board_version", NULL},
> + {"chassis_type", NULL},
> + {"chassis_vendor", NULL},
> + {"chassis_version", NULL},
> + {"product_name", NULL},
> + {"product_version", NULL},
> + {"system_vendor", NULL},
> + {NULL, NULL}
> +};
> +
> +/*
> + * Clear the key value mapping list.
> + */
> +void
> +xf86DMICleanup(void)
> +{
> + struct dmi_kv *cur;
> +
> + for (cur = dmi_kv_map; cur->key; cur++) {
> + free(cur->value);
> + cur->value = NULL;
> + }
> +}
> +
> +/*
> + * Add a DMI id value for specific key to the key value mapping.
> + */
> +Bool
> +xf86DMIAdd(const char *const key, char *value)
> +{
> + struct dmi_kv *dst;
> +
> + for (dst = dmi_kv_map; dst->key; dst++)
> + if (strcmp(dst->key, key) == 0) {
> + xf86MsgVerb(X_PROBED, 10, "DMI: adding (%s:%s)\n", key, value);
> + dst->value = value;
Make this a const char *value and strdup it here. Then the memory is
self-contained within the DMI paths and doesn't need tracing back to where
it's allocated and why it needs to be freed here.
> + return TRUE;
> + }
> +
> + xf86Msg(X_ERROR, "DMI: unsupported key (%s)\n", key);
> + return FALSE;
> +}
> +
> +/*
> + * 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))
> +{
> + const xf86MatchKVGroup *group;
> +
> + /* If there are no patterns, accept the match.
> + * (This happens if no MatchDMI option was configured and therefor
typo, therefore
> + * match_dmi is an empty list.) */
> + if (xorg_list_is_empty(patterns))
> + return TRUE;
> +
> + xorg_list_for_each_entry(group, patterns, entry) {
> + Bool match = FALSE;
> + const struct dmi_kv *cur;
> + const xf86KVPair *pair;
> +
> + for (pair = group->pairs; pair && pair->key && pair->value; pair++)
> + for (cur = dmi_kv_map; cur->key; cur++) {
> + if ((*compare)(cur->key, pair->key) != 0)
> + continue;
> +
> + if (cur->value && (*compare)(cur->value, pair->value) == 0) {
> + match = TRUE;
> + break;
> + }
> + }
> + if (!match)
> + return FALSE;
> + }
> +
> + return TRUE;
> +}
> +
> +/*
> + * Is the passed string a valid key?
> + */
> +Bool
> +xf86DMIIsValidKey(const char *const key)
A const char * key is sufficient here, const key doesn't add anything imo.
goes for the other functions too (and the ones in the next patch).
Cheers,
Peter
> +{
> + const struct dmi_kv *cur;
> +
> + if (!key)
> + return FALSE;
> +
> + for (cur = dmi_kv_map; 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..fe1a874
> --- /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, "DMI: matching 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 8d27e8b..43ce52d 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 Bool 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 xf86DMIIsValidKey(const char *const key);
> +
> #ifdef XSERVER_PLATFORM_BUS
> #include "hotplug.h"
> void
> --
> 1.8.5.1
>
More information about the xorg-devel
mailing list