v3d: Move clif dump BO lookup into the clif dumper.
authorEric Anholt <eric@anholt.net>
Mon, 25 Jun 2018 21:58:15 +0000 (14:58 -0700)
committerEric Anholt <eric@anholt.net>
Sat, 28 Jul 2018 00:08:35 +0000 (17:08 -0700)
The clif dumper is going to need information about all of our BOs if we're
going to dump them for replay purposes.

src/broadcom/clif/clif_dump.c
src/broadcom/clif/clif_dump.h
src/broadcom/clif/clif_private.h
src/gallium/drivers/v3d/v3d_job.c
src/gallium/drivers/vc4/vc4_cl_dump.c

index ca8d6d3e6fddc333fad6763352ec5f9a37363b1b..fe68b5102ebfbeab6e15d6cace38883a0a1d1f2d 100644 (file)
@@ -51,16 +51,12 @@ clif_dump_add_address_to_worklist(struct clif_dump *clif,
 
 struct clif_dump *
 clif_dump_init(const struct v3d_device_info *devinfo,
-               FILE *out,
-               bool (*lookup_vaddr)(void *data, uint32_t addr, void **vaddr),
-               void *data)
+               FILE *out)
 {
         struct clif_dump *clif = rzalloc(NULL, struct clif_dump);
 
         clif->devinfo = devinfo;
-        clif->lookup_vaddr = lookup_vaddr;
         clif->out = out;
-        clif->data = data;
         clif->spec = v3d_spec_load(devinfo);
 
         list_inithead(&clif->worklist);
@@ -74,6 +70,22 @@ clif_dump_destroy(struct clif_dump *clif)
         ralloc_free(clif);
 }
 
+static bool
+clif_lookup_vaddr(struct clif_dump *clif, uint32_t addr, void **vaddr)
+{
+        for (int i = 0; i < clif->bo_count; i++) {
+                struct clif_bo *bo = &clif->bo[i];
+
+                if (addr >= bo->offset &&
+                    addr < bo->offset + bo->size) {
+                        *vaddr = bo->vaddr + addr - bo->offset;
+                        return true;
+                }
+        }
+
+        return false;
+}
+
 #define out_uint(_clif, field) out(_clif, "    /* %s = */ %u\n",        \
                             #field,  values-> field);
 
@@ -91,7 +103,7 @@ static void
 clif_dump_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
 {
         void *start_vaddr;
-        if (!clif->lookup_vaddr(clif->data, start, &start_vaddr)) {
+        if (!clif_lookup_vaddr(clif, start, &start_vaddr)) {
                 out(clif, "Failed to look up address 0x%08x\n",
                     start);
                 return;
@@ -101,7 +113,7 @@ clif_dump_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
          * won't set an end), but is used for BCL/RCL termination.
          */
         void *end_vaddr = NULL;
-        if (end && !clif->lookup_vaddr(clif->data, end, &end_vaddr)) {
+        if (end && !clif_lookup_vaddr(clif, end, &end_vaddr)) {
                 out(clif, "Failed to look up address 0x%08x\n",
                     end);
                 return;
@@ -151,7 +163,7 @@ clif_process_worklist(struct clif_dump *clif)
                 list_del(&reloc->link);
 
                 void *vaddr;
-                if (!clif->lookup_vaddr(clif->data, reloc->addr, &vaddr)) {
+                if (!clif_lookup_vaddr(clif, reloc->addr, &vaddr)) {
                         out(clif, "Failed to look up address 0x%08x\n",
                             reloc->addr);
                         continue;
@@ -180,3 +192,20 @@ clif_dump_add_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
 
         clif_process_worklist(clif);
 }
+
+void
+clif_dump_add_bo(struct clif_dump *clif, const char *name,
+                 uint32_t offset, uint32_t size, void *vaddr)
+{
+        if (clif->bo_count >= clif->bo_array_size) {
+                clif->bo_array_size = MAX2(4, clif->bo_array_size * 2);
+                clif->bo = reralloc(clif, clif->bo, struct clif_bo,
+                                    clif->bo_array_size);
+        }
+
+        clif->bo[clif->bo_count].name = ralloc_strdup(clif, name);
+        clif->bo[clif->bo_count].offset = offset;
+        clif->bo[clif->bo_count].size = size;
+        clif->bo[clif->bo_count].vaddr = vaddr;
+        clif->bo_count++;
+}
index d46cc84710e4df2e2fc4a6aacbabd8545eea1445..f89447b9bd9765bcd4265b990e6fdcda97e2a487 100644 (file)
@@ -31,12 +31,12 @@ struct v3d_device_info;
 struct clif_dump;
 
 struct clif_dump *clif_dump_init(const struct v3d_device_info *devinfo,
-                                 FILE *output,
-                                 bool (*lookup_vaddr)(void *data, uint32_t addr,
-                                                      void **vaddr),
-                                 void *data);
+                                 FILE *output);
+void clif_dump(struct clif_dump *clif);
 void clif_dump_destroy(struct clif_dump *clif);
 
+void clif_dump_add_bo(struct clif_dump *clif, const char *name,
+                      uint32_t offset, uint32_t size, void *vaddr);
 void clif_dump_add_cl(struct clif_dump *clif, uint32_t start, uint32_t end);
 
 #endif
index 376daef80d949efb8cc823da0dd08fc6f23fa2bb..0d762c4b74702118078afa1f06a2e50ce5cf1646 100644 (file)
 #include <stdarg.h>
 #include "util/list.h"
 
+struct clif_bo {
+        const char *name;
+        uint32_t offset;
+        uint32_t size;
+        void *vaddr;
+};
+
 struct clif_dump {
         const struct v3d_device_info *devinfo;
-        bool (*lookup_vaddr)(void *data, uint32_t addr, void **vaddr);
         FILE *out;
-        /* Opaque data from the caller that is passed to the callbacks. */
-        void *data;
 
         struct v3d_spec *spec;
 
         /* List of struct reloc_worklist_entry */
         struct list_head worklist;
+
+        struct clif_bo *bo;
+        int bo_count;
+        int bo_array_size;
 };
 
 enum reloc_worklist_type {
index 9ab8e5107a72f1d5498e006f49f7835e3455bb60..20f8bcc3f322510c6cf71ffd05c577b9480e6ed8 100644 (file)
@@ -341,26 +341,6 @@ v3d_get_job_for_fbo(struct v3d_context *v3d)
         return job;
 }
 
-static bool
-v3d_clif_dump_lookup(void *data, uint32_t addr, void **vaddr)
-{
-        struct v3d_job *job = data;
-        struct set_entry *entry;
-
-        set_foreach(job->bos, entry) {
-                struct v3d_bo *bo = (void *)entry->key;
-
-                if (addr >= bo->offset &&
-                    addr < bo->offset + bo->size) {
-                        v3d_bo_map(bo);
-                        *vaddr = bo->map + addr - bo->offset;
-                        return true;
-                }
-        }
-
-        return false;
-}
-
 static void
 v3d_clif_dump(struct v3d_context *v3d, struct v3d_job *job)
 {
@@ -368,8 +348,19 @@ v3d_clif_dump(struct v3d_context *v3d, struct v3d_job *job)
                 return;
 
         struct clif_dump *clif = clif_dump_init(&v3d->screen->devinfo,
-                                                stderr, v3d_clif_dump_lookup,
-                                                job);
+                                                stderr);
+
+        struct set_entry *entry;
+        set_foreach(job->bos, entry) {
+                struct v3d_bo *bo = (void *)entry->key;
+                char *name = ralloc_asprintf(NULL, "%s_0x%x",
+                                             bo->name, bo->offset);
+
+                v3d_bo_map(bo);
+                clif_dump_add_bo(clif, name, bo->offset, bo->size, bo->map);
+
+                ralloc_free(name);
+        }
 
         fprintf(stderr, "BCL: 0x%08x..0x%08x\n",
                 job->submit.bcl_start, job->submit.bcl_end);
@@ -379,6 +370,8 @@ v3d_clif_dump(struct v3d_context *v3d, struct v3d_job *job)
         fprintf(stderr, "RCL: 0x%08x..0x%08x\n",
                 job->submit.rcl_start, job->submit.rcl_end);
         clif_dump_add_cl(clif, job->submit.rcl_start, job->submit.rcl_end);
+
+        clif_dump_destroy(clif);
 }
 
 /**
index c5be426d132a667a2fce226f64d2deef8e85bbe0..bd2d7137c582da1551d4637b990cd9882f08ae76 100644 (file)
@@ -42,7 +42,7 @@ vc4_dump_cl(void *cl, uint32_t size, bool is_render)
         };
         struct v3d_spec *spec = v3d_spec_load(&devinfo);
 
-        struct clif_dump *clif = clif_dump_init(&devinfo, stderr, NULL, NULL);
+        struct clif_dump *clif = clif_dump_init(&devinfo, stderr);
 
         uint32_t offset = 0, hw_offset = 0;
         uint8_t *p = cl;