v3d: Print CLIF fixed-point values as just their decimal value.
[mesa.git] / src / broadcom / cle / v3d_decoder.c
index de57e5f5acbed0a8b9005d4632fb895b4d50c0b9..c1e9e50a247a4de382eeee24c26893c6354a3bfa 100644 (file)
@@ -316,6 +316,8 @@ string_to_type(struct parser_context *ctx, const char *s)
                 return (struct v3d_type) { .kind = V3D_TYPE_BOOL };
         else if (strcmp(s, "float") == 0)
                 return (struct v3d_type) { .kind = V3D_TYPE_FLOAT };
+        else if (strcmp(s, "f187") == 0)
+                return (struct v3d_type) { .kind = V3D_TYPE_F187 };
         else if (strcmp(s, "address") == 0)
                 return (struct v3d_type) { .kind = V3D_TYPE_ADDRESS };
         else if (strcmp(s, "offset") == 0)
@@ -511,6 +513,13 @@ skip:
         ctx->parse_depth++;
 }
 
+static int
+field_offset_compare(const void *a, const void *b)
+{
+        return ((*(const struct v3d_field **)a)->start -
+                (*(const struct v3d_field **)b)->start);
+}
+
 static void
 end_element(void *data, const char *name)
 {
@@ -549,6 +558,13 @@ end_element(void *data, const char *name)
                 else if (strcmp(name, "register") == 0)
                         spec->registers[spec->nregisters++] = group;
 
+                /* Sort the fields in increasing offset order.  The XML might
+                 * be specified in any order, but we'll want to iterate from
+                 * the bottom.
+                 */
+                qsort(group->fields, group->nfields, sizeof(*group->fields),
+                      field_offset_compare);
+
                 assert(spec->ncommands < ARRAY_SIZE(spec->commands));
                 assert(spec->nstructs < ARRAY_SIZE(spec->structs));
                 assert(spec->nregisters < ARRAY_SIZE(spec->registers));
@@ -742,14 +758,12 @@ v3d_group_get_length(struct v3d_group *group)
 void
 v3d_field_iterator_init(struct v3d_field_iterator *iter,
                         struct v3d_group *group,
-                        const uint8_t *p,
-                        bool print_colors)
+                        const uint8_t *p)
 {
         memset(iter, 0, sizeof(*iter));
 
         iter->group = group;
         iter->p = p;
-        iter->print_colors = print_colors;
 }
 
 static const char *
@@ -829,7 +843,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;
@@ -865,19 +879,40 @@ v3d_field_iterator_next(struct v3d_field_iterator *iter)
                 enum_name = v3d_get_enum_name(&iter->field->inline_enum, value);
                 break;
         }
-        case V3D_TYPE_BOOL: {
-                const char *true_string =
-                        iter->print_colors ? "\e[0;35mtrue\e[0m" : "true";
+        case V3D_TYPE_BOOL:
                 snprintf(iter->value, sizeof(iter->value), "%s",
                          __gen_unpack_uint(iter->p, s, e) ?
-                         true_string : "false");
+                         "1 /* true */" : "0 /* false */");
                 break;
-        }
         case V3D_TYPE_FLOAT:
                 snprintf(iter->value, sizeof(iter->value), "%f",
                          __gen_unpack_float(iter->p, s, e));
                 break;
-        case V3D_TYPE_ADDRESS:
+
+        case V3D_TYPE_F187:
+                snprintf(iter->value, sizeof(iter->value), "%f",
+                         __gen_unpack_f187(iter->p, s, e));
+                break;
+
+        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)));
@@ -890,14 +925,24 @@ v3d_field_iterator_next(struct v3d_field_iterator *iter)
                                              iter->field->type.v3d_struct->name);
                 break;
         case V3D_TYPE_SFIXED:
-                snprintf(iter->value, sizeof(iter->value), "%f",
-                         __gen_unpack_sfixed(iter->p, s, e,
-                                             iter->field->type.f));
+                if (clif->pretty) {
+                        snprintf(iter->value, sizeof(iter->value), "%f",
+                                 __gen_unpack_sfixed(iter->p, s, e,
+                                                     iter->field->type.f));
+                } else {
+                        snprintf(iter->value, sizeof(iter->value), "%u",
+                                 (unsigned)__gen_unpack_uint(iter->p, s, e));
+                }
                 break;
         case V3D_TYPE_UFIXED:
-                snprintf(iter->value, sizeof(iter->value), "%f",
-                         __gen_unpack_ufixed(iter->p, s, e,
-                                             iter->field->type.f));
+                if (clif->pretty) {
+                        snprintf(iter->value, sizeof(iter->value), "%f",
+                                 __gen_unpack_ufixed(iter->p, s, e,
+                                                     iter->field->type.f));
+                } else {
+                        snprintf(iter->value, sizeof(iter->value), "%u",
+                                 (unsigned)__gen_unpack_uint(iter->p, s, e));
+                }
                 break;
         case V3D_TYPE_MBO:
                 break;
@@ -926,18 +971,32 @@ v3d_field_iterator_next(struct v3d_field_iterator *iter)
 
 void
 v3d_print_group(struct clif_dump *clif, struct v3d_group *group,
-                uint64_t offset, const uint8_t *p, bool color)
+                uint64_t offset, const uint8_t *p)
 {
         struct v3d_field_iterator iter;
 
-        v3d_field_iterator_init(&iter, group, p, color);
-        while (v3d_field_iterator_next(&iter)) {
-                fprintf(clif->out, "    %s: %s\n", iter.name, iter.value);
+        v3d_field_iterator_init(&iter, group, p);
+        while (v3d_field_iterator_next(clif, &iter)) {
+                /* Clif parsing uses the packet name, and expects no
+                 * sub-id.
+                 */
+                if (strcmp(iter.field->name, "sub-id") == 0 ||
+                    strcmp(iter.field->name, "unused") == 0 ||
+                    strcmp(iter.field->name, "Pad") == 0)
+                        continue;
+
+                if (clif->pretty) {
+                        fprintf(clif->out, "    %s: %s\n",
+                                iter.name, iter.value);
+                } else {
+                        fprintf(clif->out, "  /* %30s: */ %s\n",
+                                iter.name, iter.value);
+                }
                 if (iter.struct_desc) {
                         uint64_t struct_offset = offset + iter.offset;
                         v3d_print_group(clif, iter.struct_desc,
                                         struct_offset,
-                                        &p[iter.offset], color);
+                                        &p[iter.offset]);
                 }
         }
 }