[Mesa-dev] [PATCH 1/5] intel: aubinator: pack supported generations into an array

Lionel Landwerlin llandwerlin at gmail.com
Tue Oct 4 15:59:01 UTC 2016


Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Cc: Sirisha Gandikota <Sirisha.Gandikota at intel.com>
---
 src/intel/tools/aubinator.c | 79 +++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 49 deletions(-)

diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
index 9b32e5b..4e2cafa 100644
--- a/src/intel/tools/aubinator.c
+++ b/src/intel/tools/aubinator.c
@@ -36,6 +36,8 @@
 #include <sys/wait.h>
 #include <sys/mman.h>
 
+#include "util/macros.h"
+
 #include "decoder.h"
 #include "intel_aub.h"
 #include "gen_disasm.h"
@@ -1060,11 +1062,25 @@ int main(int argc, char *argv[])
 {
    struct gen_spec *spec;
    struct aub_file *file;
-   int i, pci_id = 0;
+   int i;
    bool found_arg_gen = false, pager = true;
-   int gen_major, gen_minor;
    const char *value;
    char gen_file[256], gen_val[24];
+   const struct {
+      const char *name;
+      int pci_id;
+      int major;
+      int minor;
+   } gens[] = {
+      { "ivb", 0x0166, 7, 0 }, /* Intel(R) Ivybridge Mobile GT2 */
+      { "hsw", 0x0416, 7, 5 }, /* Intel(R) Haswell Mobile GT2 */
+      { "byt", 0x0155, 7, 5 }, /* Intel(R) Bay Trail */
+      { "bdw", 0x1616, 8, 0 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
+      { "chv", 0x22B3, 8, 0 }, /* Intel(R) HD Graphics (Cherryview) */
+      { "skl", 0x1912, 9, 0 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */
+      { "kbl", 0x591D, 9, 0 }, /* Intel(R) Kabylake GT2 */
+      { "bxt", 0x0A84, 9, 0 }  /* Intel(R) HD Graphics (Broxton) */
+   }, *gen = NULL;
 
    if (argc == 1) {
       print_help(argv[0], stderr);
@@ -1082,8 +1098,6 @@ int main(int argc, char *argv[])
             exit(EXIT_FAILURE);
          }
          found_arg_gen = true;
-         gen_major = 0;
-         gen_minor = 0;
          snprintf(gen_val, sizeof(gen_val), "%s", value);
       } else if (strcmp(argv[i], "--headers") == 0) {
          option_full_decode = false;
@@ -1115,47 +1129,14 @@ int main(int argc, char *argv[])
       exit(EXIT_FAILURE);
    }
 
-   if (strstr(gen_val, "ivb") != NULL) {
-      /* Intel(R) Ivybridge Mobile GT2 */
-      pci_id = 0x0166;
-      gen_major = 7;
-      gen_minor = 0;
-   } else if (strstr(gen_val, "hsw") != NULL) {
-      /* Intel(R) Haswell Mobile GT2 */
-      pci_id = 0x0416;
-      gen_major = 7;
-      gen_minor = 5;
-   } else if (strstr(gen_val, "byt") != NULL) {
-      /* Intel(R) Bay Trail */
-      pci_id = 0x0155;
-      gen_major = 7;
-      gen_minor = 5;
-   } else if (strstr(gen_val, "bdw") != NULL) {
-      /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
-      pci_id = 0x1616;
-      gen_major = 8;
-      gen_minor = 0;
-   }  else if (strstr(gen_val, "chv") != NULL) {
-      /* Intel(R) HD Graphics (Cherryview) */
-      pci_id = 0x22B3;
-      gen_major = 8;
-      gen_minor = 0;
-   } else if (strstr(gen_val, "skl") != NULL) {
-      /* Intel(R) HD Graphics 530 (Skylake GT2) */
-      pci_id = 0x1912;
-      gen_major = 9;
-      gen_minor = 0;
-   } else if (strstr(gen_val, "kbl") != NULL) {
-      /* Intel(R) Kabylake GT2 */
-      pci_id = 0x591D;
-      gen_major = 9;
-      gen_minor = 0;
-   } else if (strstr(gen_val, "bxt") != NULL) {
-      /* Intel(R) HD Graphics (Broxton) */
-      pci_id = 0x0A84;
-      gen_major = 9;
-      gen_minor = 0;
-   } else {
+   for (i = 0; i < ARRAY_SIZE(gens); i++) {
+      if (!strcmp(gen_val, gens[i].name)) {
+         gen = &gens[i];
+         break;
+      }
+   }
+
+   if (gen == NULL) {
       fprintf(stderr, "can't parse gen: %s, expected ivb, byt, hsw, "
                              "bdw, chv, skl, kbl or bxt\n", gen_val);
       exit(EXIT_FAILURE);
@@ -1168,15 +1149,15 @@ int main(int argc, char *argv[])
    if (isatty(1) && pager)
       setup_pager();
 
-   if (gen_minor > 0) {
+   if (gen->minor > 0) {
       snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d%d.xml",
-               gen_major, gen_minor);
+               gen->major, gen->minor);
    } else {
-      snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d.xml", gen_major);
+      snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d.xml", gen->major);
    }
 
    spec = gen_spec_load(gen_file);
-   disasm = gen_disasm_create(pci_id);
+   disasm = gen_disasm_create(gen->pci_id);
 
    if (argv[i] == NULL) {
        print_help(argv[0], stderr);
-- 
2.9.3



More information about the mesa-dev mailing list