add dmi_match() and change dmi_found() to use it
authorjsg <jsg@openbsd.org>
Wed, 31 Jan 2018 03:26:00 +0000 (03:26 +0000)
committerjsg <jsg@openbsd.org>
Wed, 31 Jan 2018 03:26:00 +0000 (03:26 +0000)
sys/dev/pci/drm/drm_linux.c
sys/dev/pci/drm/drm_linux.h

index 5a26c24..918e281 100644 (file)
@@ -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 <jsg@openbsd.org>
  * Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
@@ -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;
index 87b11a0..1c7fd9f 100644 (file)
@@ -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;