intel/dump_gpu: only map in GTT buffers not previously mapped
[mesa.git] / src / intel / tools / error2aub.c
index e2dded29c2c8b5fa9c6d955193c8210ba5c13ab1..48cd8a0666f638667451041a6041c628461a18b8 100644 (file)
@@ -208,18 +208,27 @@ engine_from_name(const char *engine_name,
    const struct {
       const char *match;
       enum drm_i915_gem_engine_class engine_class;
+      bool parse_instance;
    } rings[] = {
-      { "rcs", I915_ENGINE_CLASS_RENDER },
-      { "vcs", I915_ENGINE_CLASS_VIDEO },
-      { "vecs", I915_ENGINE_CLASS_VIDEO_ENHANCE },
-      { "bcs", I915_ENGINE_CLASS_COPY },
+      { "rcs", I915_ENGINE_CLASS_RENDER, true },
+      { "vcs", I915_ENGINE_CLASS_VIDEO, true },
+      { "vecs", I915_ENGINE_CLASS_VIDEO_ENHANCE, true },
+      { "bcs", I915_ENGINE_CLASS_COPY, true },
+      { "global", I915_ENGINE_CLASS_INVALID, false },
+      { "render command stream", I915_ENGINE_CLASS_RENDER, false },
+      { "blt command stream", I915_ENGINE_CLASS_COPY, false },
+      { "bsd command stream", I915_ENGINE_CLASS_VIDEO, false },
+      { "vebox command stream", I915_ENGINE_CLASS_VIDEO_ENHANCE, false },
       { NULL, I915_ENGINE_CLASS_INVALID },
    }, *r;
 
    for (r = rings; r->match; r++) {
       if (strncasecmp(engine_name, r->match, strlen(r->match)) == 0) {
          *engine_class = r->engine_class;
-         *engine_instance = strtol(engine_name + strlen(r->match), NULL, 10);
+         if (r->parse_instance)
+            *engine_instance = strtol(engine_name + strlen(r->match), NULL, 10);
+         else
+            *engine_instance = 0;
          return;
       }
    }
@@ -231,16 +240,17 @@ int
 main(int argc, char *argv[])
 {
    int i, c;
-   bool help = false;
+   bool help = false, verbose;
    char *out_filename = NULL, *in_filename = NULL;
    const struct option aubinator_opts[] = {
       { "help",       no_argument,       NULL,     'h' },
       { "output",     required_argument, NULL,     'o' },
+      { "verbose",    no_argument,       NULL,     'v' },
       { NULL,         0,                 NULL,     0 }
    };
 
    i = 0;
-   while ((c = getopt_long(argc, argv, "ho:", aubinator_opts, &i)) != -1) {
+   while ((c = getopt_long(argc, argv, "ho:v", aubinator_opts, &i)) != -1) {
       switch (c) {
       case 'h':
          help = true;
@@ -248,6 +258,9 @@ main(int argc, char *argv[])
       case 'o':
          out_filename = strdup(optarg);
          break;
+      case 'v':
+         verbose = true;
+         break;
       default:
          break;
       }
@@ -279,6 +292,7 @@ main(int argc, char *argv[])
    int active_engine_instance = -1;
 
    enum address_space active_gtt = PPGTT;
+   enum address_space default_gtt = PPGTT;
 
    struct {
       struct {
@@ -306,8 +320,9 @@ main(int argc, char *argv[])
 
          aub_file_init(&aub, aub_file,
                        NULL, pci_id, "error_state");
-         fail_if(!aub_use_execlists(&aub),
-                 "%s currently only works on gen8+\n", argv[0]);
+         if (verbose)
+            aub.verbose_log_file = stdout;
+         default_gtt = active_gtt = aub_use_execlists(&aub) ? PPGTT : GGTT;
          continue;
       }
 
@@ -335,7 +350,7 @@ main(int argc, char *argv[])
          char *ring = line + strlen(active_start);
 
          engine_from_name(ring, &active_engine_class, &active_engine_instance);
-         active_gtt = PPGTT;
+         active_gtt = default_gtt;
 
          char *count = strchr(ring, '[');
          fail_if(!count || sscanf(count, "[%d]:", &num_ring_bos) < 1,
@@ -354,7 +369,6 @@ main(int argc, char *argv[])
       if (num_ring_bos > 0) {
          unsigned hi, lo, size;
          if (sscanf(line, " %x_%x %d", &hi, &lo, &size) == 3) {
-            assert(aub_use_execlists(&aub));
             struct bo *bo_entry = find_or_create(&bo_list, ((uint64_t)hi) << 32 | lo,
                                                  active_gtt,
                                                  active_engine_class,
@@ -393,8 +407,8 @@ main(int argc, char *argv[])
             enum bo_type type;
             enum address_space gtt;
          } bo_types[] = {
-            { "gtt_offset", BO_TYPE_BATCH,      PPGTT },
-            { "user",       BO_TYPE_USER,       PPGTT },
+            { "gtt_offset", BO_TYPE_BATCH,      default_gtt },
+            { "user",       BO_TYPE_USER,       default_gtt },
             { "HW context", BO_TYPE_CONTEXT,    GGTT },
             { "ringbuffer", BO_TYPE_RINGBUFFER, GGTT },
             { "HW Status",  BO_TYPE_STATUS,     GGTT },
@@ -423,6 +437,14 @@ main(int argc, char *argv[])
       }
    }
 
+   if (verbose) {
+      fprintf(stdout, "BOs found:\n");
+      list_for_each_entry(struct bo, bo_entry, &bo_list, link) {
+         fprintf(stdout, "\t type=%i addr=0x%016" PRIx64 " size=%" PRIu64 "\n",
+                 bo_entry->type, bo_entry->addr, bo_entry->size);
+      }
+   }
+
    /* Find the batch that trigger the hang */
    struct bo *batch_bo = NULL;
    list_for_each_entry(struct bo, bo_entry, &bo_list, link) {
@@ -438,18 +460,25 @@ main(int argc, char *argv[])
    list_for_each_entry(struct bo, bo_entry, &bo_list, link) {
       switch (bo_entry->type) {
       case BO_TYPE_BATCH:
-         aub_map_ppgtt(&aub, bo_entry->addr, bo_entry->size);
-         aub_write_trace_block(&aub, AUB_TRACE_TYPE_BATCH,
-                               bo_entry->data, bo_entry->size, bo_entry->addr);
+         if (bo_entry->gtt == PPGTT) {
+            aub_map_ppgtt(&aub, bo_entry->addr, bo_entry->size);
+            aub_write_trace_block(&aub, AUB_TRACE_TYPE_BATCH,
+                                  bo_entry->data, bo_entry->size, bo_entry->addr);
+         } else
+            aub_write_ggtt(&aub, bo_entry->addr, bo_entry->size, bo_entry->data);
          break;
       case BO_TYPE_USER:
-         aub_map_ppgtt(&aub, bo_entry->addr, bo_entry->size);
-         aub_write_trace_block(&aub, AUB_TRACE_TYPE_NOTYPE,
-                               bo_entry->data, bo_entry->size, bo_entry->addr);
+         if (bo_entry->gtt == PPGTT) {
+            aub_map_ppgtt(&aub, bo_entry->addr, bo_entry->size);
+            aub_write_trace_block(&aub, AUB_TRACE_TYPE_NOTYPE,
+                                  bo_entry->data, bo_entry->size, bo_entry->addr);
+         } else
+            aub_write_ggtt(&aub, bo_entry->addr, bo_entry->size, bo_entry->data);
          break;
       case BO_TYPE_CONTEXT:
          if (bo_entry->engine_class == batch_bo->engine_class &&
-             bo_entry->engine_instance == batch_bo->engine_instance) {
+             bo_entry->engine_instance == batch_bo->engine_instance &&
+             aub_use_execlists(&aub)) {
             hwsp_bo = bo_entry;
 
             uint32_t *context = (uint32_t *) (bo_entry->data + 4096 /* GuC */ + 4096 /* HWSP */);
@@ -475,7 +504,7 @@ main(int argc, char *argv[])
             fprintf(stdout, "context dump:\n");
             for (int i = 0; i < 60; i++) {
                if (i % 4 == 0)
-                  fprintf(stdout, "\n 0x%08lx: ", bo_entry->addr + 8192 + i * 4);
+                  fprintf(stdout, "\n 0x%08" PRIx64 ": ", bo_entry->addr + 8192 + i * 4);
                fprintf(stdout, "0x%08x ", context[i]);
             }
             fprintf(stdout, "\n");
@@ -508,8 +537,15 @@ main(int argc, char *argv[])
       }
    }
 
-   fail_if(!hwsp_bo, "Failed to find Context buffer.\n");
-   aub_write_context_execlists(&aub, hwsp_bo->addr + 4096 /* skip GuC page */, hwsp_bo->engine_class);
+   if (aub_use_execlists(&aub)) {
+      fail_if(!hwsp_bo, "Failed to find Context buffer.\n");
+      aub_write_context_execlists(&aub, hwsp_bo->addr + 4096 /* skip GuC page */, hwsp_bo->engine_class);
+   } else {
+      /* Use context id 0 -- if we are not using execlists it doesn't matter
+       * anyway
+       */
+      aub_write_exec(&aub, 0, batch_bo->addr, 0, I915_ENGINE_CLASS_RENDER);
+   }
 
    /* Cleanup */
    list_for_each_entry_safe(struct bo, bo_entry, &bo_list, link) {