From 807828a6570f2326452ba5c9aa654413283c9490 Mon Sep 17 00:00:00 2001 From: jsg Date: Wed, 31 Jan 2018 03:26:00 +0000 Subject: [PATCH] add dmi_match() and change dmi_found() to use it --- sys/dev/pci/drm/drm_linux.c | 54 +++++++++++++++++++++++-------------- sys/dev/pci/drm/drm_linux.h | 3 ++- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index 5a26c246833..918e281e4cf 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.19 2018/01/30 08:27:17 jsg Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.20 2018/01/31 03:26:00 jsg Exp $ */ /* * Copyright (c) 2013 Jonathan Gray * Copyright (c) 2015, 2016 Mark Kettenis @@ -143,7 +143,37 @@ timeval_to_us(const struct timeval *tv) return ((int64_t)tv->tv_sec * 1000000) + tv->tv_usec; } -extern char *hw_vendor, *hw_prod; +extern char *hw_vendor, *hw_prod, *hw_ver; + +bool +dmi_match(int slot, const char *str) +{ + switch (slot) { + case DMI_SYS_VENDOR: + case DMI_BOARD_VENDOR: + if (hw_vendor != NULL && + !strcmp(hw_vendor, str)) + return true; + break; + case DMI_PRODUCT_NAME: + case DMI_BOARD_NAME: + if (hw_prod != NULL && + !strcmp(hw_prod, str)) + return true; + break; + case DMI_PRODUCT_VERSION: + case DMI_BOARD_VERSION: + if (hw_ver != NULL && + !strcmp(hw_ver, str)) + return true; + break; + case DMI_NONE: + default: + return false; + } + + return false; +} static bool dmi_found(const struct dmi_system_id *dsi) @@ -152,26 +182,10 @@ dmi_found(const struct dmi_system_id *dsi) for (i = 0; i < nitems(dsi->matches); i++) { slot = dsi->matches[i].slot; - switch (slot) { - case DMI_NONE: + if (slot == DMI_NONE) break; - case DMI_SYS_VENDOR: - case DMI_BOARD_VENDOR: - if (hw_vendor != NULL && - !strcmp(hw_vendor, dsi->matches[i].substr)) - break; - else - return false; - case DMI_PRODUCT_NAME: - case DMI_BOARD_NAME: - if (hw_prod != NULL && - !strcmp(hw_prod, dsi->matches[i].substr)) - break; - else - return false; - default: + if (!dmi_match(slot, dsi->matches[i].substr)) return false; - } } return true; diff --git a/sys/dev/pci/drm/drm_linux.h b/sys/dev/pci/drm/drm_linux.h index 87b11a0abbd..1c7fd9fb16e 100644 --- a/sys/dev/pci/drm/drm_linux.h +++ b/sys/dev/pci/drm/drm_linux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.h,v 1.80 2018/01/30 09:57:58 jsg Exp $ */ +/* $OpenBSD: drm_linux.h,v 1.81 2018/01/31 03:26:00 jsg Exp $ */ /* * Copyright (c) 2013, 2014, 2015 Mark Kettenis * Copyright (c) 2017 Martin Pieuchot @@ -1425,6 +1425,7 @@ struct dmi_system_id { #define DMI_MATCH(a, b) {(a), (b)} #define DMI_EXACT_MATCH(a, b) {(a), (b)} int dmi_check_system(const struct dmi_system_id *); +bool dmi_match(int, const char *); struct resource { u_long start; -- 2.20.1