freedreno/cffdec: Add type0/type4 vs type3/type7 pkt helpers
authorRob Clark <robdclark@chromium.org>
Tue, 25 Oct 2022 16:53:41 +0000 (09:53 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 23 Nov 2022 20:12:08 +0000 (20:12 +0000)
The handling is the same, just the format differes for pre-a5xx vs later
gens, so split out some helpers to simplify this.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19444>

src/freedreno/decode/cffdec.c
src/freedreno/decode/cffdec.h

index e15ece7..05eebf0 100644 (file)
@@ -2775,19 +2775,7 @@ dump_commands(uint32_t *dwords, uint32_t sizedwords, int level)
       //               if ((dwords[0] >> 16) == 0xffff)
       //                       goto skip;
 
-      if (pkt_is_type0(dwords[0])) {
-         count = type0_pkt_size(dwords[0]) + 1;
-         val = type0_pkt_offset(dwords[0]);
-         assert(val < regcnt());
-         printl(3, "%swrite %s%s (%04x)\n", levels[level + 1], regname(val, 1),
-                (dwords[0] & 0x8000) ? " (same register)" : "", val);
-         dump_registers(val, dwords + 1, count - 1, level + 2);
-         if (!quiet(3))
-            dump_hex(dwords, count, level + 1);
-      } else if (pkt_is_type4(dwords[0])) {
-         /* basically the same(ish) as type0 prior to a5xx */
-         count = type4_pkt_size(dwords[0]) + 1;
-         val = type4_pkt_offset(dwords[0]);
+      if (pkt_is_regwrite(dwords[0], &val, &count)) {
          assert(val < regcnt());
          printl(3, "%swrite %s (%04x)\n", levels[level + 1], regname(val, 1),
                 val);
@@ -2806,26 +2794,7 @@ dump_commands(uint32_t *dwords, uint32_t sizedwords, int level)
          if (!quiet(3))
             dump_hex(dwords, count, level+1);
 #endif
-      } else if (pkt_is_type3(dwords[0])) {
-         count = type3_pkt_size(dwords[0]) + 1;
-         val = cp_type3_opcode(dwords[0]);
-         const struct type3_op *op = get_type3_op(val);
-         if (op->options.load_all_groups)
-            load_all_groups(level + 1);
-         const char *name = pktname(val);
-         if (!quiet(2)) {
-            printf("\t%sopcode: %s%s%s (%02x) (%d dwords)%s\n", levels[level],
-                   rnn->vc->colors->bctarg, name, rnn->vc->colors->reset, val,
-                   count, (dwords[0] & 0x1) ? " (predicated)" : "");
-         }
-         if (name)
-            dump_domain(dwords + 1, count - 1, level + 2, name);
-         op->fxn(dwords + 1, count - 1, level + 1);
-         if (!quiet(2))
-            dump_hex(dwords, count, level + 1);
-      } else if (pkt_is_type7(dwords[0])) {
-         count = type7_pkt_size(dwords[0]) + 1;
-         val = cp_type7_opcode(dwords[0]);
+      } else if (pkt_is_opcode(dwords[0], &val, &count)) {
          const struct type3_op *op = get_type3_op(val);
          if (op->options.load_all_groups)
             load_all_groups(level + 1);
index a21cf9f..377a677 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <stdbool.h>
 
+#include "freedreno_pm4.h"
+
 enum query_mode {
    /* default mode, dump all queried regs on each draw: */
    QUERY_ALL = 0,
@@ -92,4 +94,41 @@ void cffdec_init(const struct cffdec_options *options);
 void dump_register_val(uint32_t regbase, uint32_t dword, int level);
 void dump_commands(uint32_t *dwords, uint32_t sizedwords, int level);
 
+/*
+ * Packets (mostly) fall into two categories, "write one or more registers"
+ * (type0 or type4 depending on generation) or "packet with opcode and
+ * opcode specific payload" (type3 or type7).  These helpers deal with
+ * the type0+type3 vs type4+type7 differences (a2xx-a4xx vs a5xx+).
+ */
+
+static inline bool
+pkt_is_regwrite(uint32_t dword, uint32_t *offset, uint32_t *size)
+{
+   if (pkt_is_type0(dword)) {
+      *size = type0_pkt_size(dword) + 1;
+      *offset = type0_pkt_offset(dword);
+      return true;
+   } if (pkt_is_type4(dword)) {
+      *size = type4_pkt_size(dword) + 1;
+      *offset = type4_pkt_offset(dword);
+      return true;
+   }
+   return false;
+}
+
+static inline bool
+pkt_is_opcode(uint32_t dword, uint32_t *opcode, uint32_t *size)
+{
+   if (pkt_is_type3(dword)) {
+      *size = type3_pkt_size(dword) + 1;
+      *opcode = cp_type3_opcode(dword);
+      return true;
+   } else if (pkt_is_type7(dword)) {
+      *size = type7_pkt_size(dword) + 1;
+      *opcode = cp_type7_opcode(dword);
+     return true;
+   }
+   return false;
+}
+
 #endif /* __CFFDEC_H__ */