intel/common: Add gen_device_name_to_pci_device_id
authorJordan Justen <jordan.l.justen@intel.com>
Sat, 10 Feb 2018 03:06:12 +0000 (19:06 -0800)
committerJordan Justen <jordan.l.justen@intel.com>
Tue, 27 Feb 2018 19:15:10 +0000 (11:15 -0800)
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Scott D Phillips <scott.d.phillips@intel.com>
src/intel/common/gen_device_info.c
src/intel/common/gen_device_info.h

index 113a9dca1ff9faeac19089af5d4cdc77e7d598d7..ef0ae4ce8c332d1ef60547b3db6d175d38246955 100644 (file)
 #include "compiler/shader_enums.h"
 #include "util/macros.h"
 
-static int
-parse_devid_override(const char *devid_override)
+/**
+ * Get the PCI ID for the device name.
+ *
+ * Returns -1 if the device is not known.
+ */
+int
+gen_device_name_to_pci_device_id(const char *name)
 {
    static const struct {
       const char *name;
@@ -54,11 +59,11 @@ parse_devid_override(const char *devid_override)
    };
 
    for (unsigned i = 0; i < ARRAY_SIZE(name_map); i++) {
-      if (!strcmp(name_map[i].name, devid_override))
+      if (!strcmp(name_map[i].name, name))
          return name_map[i].pci_id;
    }
 
-   return strtol(devid_override, NULL, 0);
+   return -1;
 }
 
 /**
@@ -72,8 +77,10 @@ gen_get_pci_device_id_override(void)
 {
    if (geteuid() == getuid()) {
       const char *devid_override = getenv("INTEL_DEVID_OVERRIDE");
-      if (devid_override)
-         return parse_devid_override(devid_override);
+      if (devid_override) {
+         const int id = gen_device_name_to_pci_device_id(devid_override);
+         return id >= 0 ? id : strtol(devid_override, NULL, 0);
+      }
    }
 
    return -1;
index 6a96143cebb605fb64c32f7601f0c866844ef321..3e9c087f58c08d0b9fd64d20115256f021ccdf11 100644 (file)
@@ -200,6 +200,7 @@ struct gen_device_info
    ((devinfo)->is_broxton || (devinfo)->is_geminilake)
 
 int gen_get_pci_device_id_override(void);
+int gen_device_name_to_pci_device_id(const char *name);
 bool gen_get_device_info(int devid, struct gen_device_info *devinfo);
 const char *gen_get_device_name(int devid);