v3d: Print addresses in CLIFs as references to buffers.
authorEric Anholt <eric@anholt.net>
Mon, 25 Jun 2018 22:37:51 +0000 (15:37 -0700)
committerEric Anholt <eric@anholt.net>
Sat, 28 Jul 2018 00:56:36 +0000 (17:56 -0700)
With CLIFs, the parser will choose an address for the buffer being
created, so we need to use effectively relocations to buffers instead of
the addresses that the driver uses.  This is also a whole lot more
intelligible for console output than raw addresses!

src/broadcom/cle/v3d_decoder.c
src/broadcom/cle/v3d_decoder.h
src/broadcom/clif/clif_dump.c
src/broadcom/clif/clif_private.h

index f97aa6604cb1a5218b8d93959e273332f7707e6e..725561cef858510b3ae946391923c4f4f378e613 100644 (file)
@@ -827,7 +827,7 @@ iter_advance_field(struct v3d_field_iterator *iter)
 }
 
 bool
-v3d_field_iterator_next(struct v3d_field_iterator *iter)
+v3d_field_iterator_next(struct clif_dump *clif, struct v3d_field_iterator *iter)
 {
         if (!iter_advance_field(iter))
                 return false;
@@ -872,7 +872,26 @@ v3d_field_iterator_next(struct v3d_field_iterator *iter)
                 snprintf(iter->value, sizeof(iter->value), "%f",
                          __gen_unpack_float(iter->p, s, e));
                 break;
-        case V3D_TYPE_ADDRESS:
+
+        case V3D_TYPE_ADDRESS: {
+                uint32_t addr =
+                        __gen_unpack_uint(iter->p, s, e) << (31 - (e - s));
+                struct clif_bo *bo = clif_lookup_bo(clif, addr);
+                if (bo) {
+                        snprintf(iter->value, sizeof(iter->value),
+                                 "[%s+0x%08x] /* 0x%08x */",
+                                 bo->name, addr - bo->offset, addr);
+                } else if (addr) {
+                        snprintf(iter->value, sizeof(iter->value),
+                                 "/* XXX: BO unknown */ 0x%08x", addr);
+                } else {
+                        snprintf(iter->value, sizeof(iter->value),
+                                 "[null]");
+                }
+
+                break;
+        }
+
         case V3D_TYPE_OFFSET:
                 snprintf(iter->value, sizeof(iter->value), "0x%08"PRIx64,
                          __gen_unpack_uint(iter->p, s, e) << (31 - (e - s)));
@@ -926,7 +945,7 @@ v3d_print_group(struct clif_dump *clif, struct v3d_group *group,
         struct v3d_field_iterator iter;
 
         v3d_field_iterator_init(&iter, group, p);
-        while (v3d_field_iterator_next(&iter)) {
+        while (v3d_field_iterator_next(clif, &iter)) {
                 fprintf(clif->out, "    %s: %s\n", iter.name, iter.value);
                 if (iter.struct_desc) {
                         uint64_t struct_offset = offset + iter.offset;
index e147b1ea703f827adccafaf2b20cdb96d7f046a5..10a7e50b87f9cbee0a2eec59b60c79822862f72b 100644 (file)
@@ -136,7 +136,8 @@ void v3d_field_iterator_init(struct v3d_field_iterator *iter,
                              struct v3d_group *group,
                              const uint8_t *p);
 
-bool v3d_field_iterator_next(struct v3d_field_iterator *iter);
+bool v3d_field_iterator_next(struct clif_dump *clif,
+                             struct v3d_field_iterator *iter);
 
 void v3d_print_group(struct clif_dump *clif,
                      struct v3d_group *group,
index f297c774b5a68980dedba096626aa920fb849212..3b693284e494f450438f0e85e1e6ef059dac34c6 100644 (file)
@@ -70,20 +70,30 @@ clif_dump_destroy(struct clif_dump *clif)
         ralloc_free(clif);
 }
 
-static bool
-clif_lookup_vaddr(struct clif_dump *clif, uint32_t addr, void **vaddr)
+struct clif_bo *
+clif_lookup_bo(struct clif_dump *clif, uint32_t addr)
 {
         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 bo;
                 }
         }
 
-        return false;
+        return NULL;
+}
+
+static bool
+clif_lookup_vaddr(struct clif_dump *clif, uint32_t addr, void **vaddr)
+{
+        struct clif_bo *bo = clif_lookup_bo(clif, addr);
+        if (!bo)
+                return false;
+
+        *vaddr = bo->vaddr + addr - bo->offset;
+        return true;
 }
 
 #define out_uint(_clif, field) out(_clif, "    /* %s = */ %u\n",        \
index da5f2a3cc29f289f8ef87e109d490c078317a77b..ea96784289a8ae4fea0906577894045693f17e65 100644 (file)
@@ -74,6 +74,9 @@ struct reloc_worklist_entry {
         };
 };
 
+struct clif_bo *
+clif_lookup_bo(struct clif_dump *clif, uint32_t addr);
+
 struct reloc_worklist_entry *
 clif_dump_add_address_to_worklist(struct clif_dump *clif,
                                   enum reloc_worklist_type type,