freedreno: Move pkt parsing helpers to common
authorRob Clark <robdclark@chromium.org>
Fri, 21 May 2021 20:58:13 +0000 (13:58 -0700)
committerMarge Bot <eric+marge@anholt.net>
Mon, 31 May 2021 23:34:43 +0000 (23:34 +0000)
I'll be needing these in afuc as well.

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

src/freedreno/afuc/disasm.c
src/freedreno/afuc/meson.build
src/freedreno/common/freedreno_pm4.h
src/freedreno/decode/cffdec.c
src/freedreno/decode/cffdec.h
src/freedreno/decode/crashdec.c

index b761cac..14e9d2f 100644 (file)
@@ -35,6 +35,8 @@
 
 #include "util/os_file.h"
 
+#include "freedreno_pm4.h"
+
 #include "afuc.h"
 #include "rnn.h"
 #include "rnndec.h"
@@ -171,19 +173,6 @@ getpm4(uint32_t id)
    return rnndec_decode_enum(ctx, "adreno_pm4_type3_packets", id);
 }
 
-static inline unsigned
-_odd_parity_bit(unsigned val)
-{
-   /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel
-    * note that we want odd parity so 0x6996 is inverted.
-    */
-   val ^= val >> 16;
-   val ^= val >> 8;
-   val ^= val >> 4;
-   val &= 0xf;
-   return (~0x6996 >> val) & 1;
-}
-
 static struct {
    uint32_t offset;
    uint32_t num_jump_labels;
@@ -483,7 +472,7 @@ disasm(uint32_t *buf, int sizedwords)
             unsigned opc, p;
 
             opc = instr->movi.uimm & 0x7f;
-            p = _odd_parity_bit(opc);
+            p = pm4_odd_parity_bit(opc);
 
             /* So, you'd think that checking the parity bit would be
              * a good way to rule out false positives, but seems like
index 516b243..54c19b3 100644 (file)
@@ -58,7 +58,11 @@ disasm = executable(
   'afuc-disasm',
   'disasm.c',
   include_directories: [
-    inc_freedreno_rnn, inc_include, inc_src, inc_util,
+    inc_freedreno,
+    inc_freedreno_rnn,
+    inc_include,
+    inc_src,
+    inc_util,
   ],
   link_with: [
     libfreedreno_rnn,
index 78b4e0f..4320a5c 100644 (file)
@@ -84,6 +84,49 @@ pm4_pkt7_hdr(uint8_t opcode, uint16_t cnt)
          ((pm4_odd_parity_bit(opcode) << 23));
 }
 
+/*
+ * Helpers for packet parsing:
+ */
+
+#define pkt_is_type0(pkt)     (((pkt)&0XC0000000) == CP_TYPE0_PKT)
+#define type0_pkt_size(pkt)   ((((pkt) >> 16) & 0x3FFF) + 1)
+#define type0_pkt_offset(pkt) ((pkt)&0x7FFF)
+
+#define pkt_is_type2(pkt) ((pkt) == CP_TYPE2_PKT)
+
+#define pkt_is_type3(pkt)                                                      \
+   ((((pkt)&0xC0000000) == CP_TYPE3_PKT) && (((pkt)&0x80FE) == 0))
+
+#define cp_type3_opcode(pkt) (((pkt) >> 8) & 0xFF)
+#define type3_pkt_size(pkt)  ((((pkt) >> 16) & 0x3FFF) + 1)
+
+static inline uint
+pm4_calc_odd_parity_bit(uint val)
+{
+   return (0x9669 >> (0xf & ((val) ^ ((val) >> 4) ^ ((val) >> 8) ^
+                             ((val) >> 12) ^ ((val) >> 16) ^ ((val) >> 20) ^
+                             ((val) >> 24) ^ ((val) >> 28)))) &
+          1;
+}
+
+#define pkt_is_type4(pkt)                                                      \
+   ((((pkt)&0xF0000000) == CP_TYPE4_PKT) &&                                    \
+    ((((pkt) >> 27) & 0x1) ==                                                  \
+     pm4_calc_odd_parity_bit(type4_pkt_offset(pkt))) &&                        \
+    ((((pkt) >> 7) & 0x1) == pm4_calc_odd_parity_bit(type4_pkt_size(pkt))))
+
+#define type4_pkt_offset(pkt) (((pkt) >> 8) & 0x7FFFF)
+#define type4_pkt_size(pkt)   ((pkt)&0x7F)
+
+#define pkt_is_type7(pkt)                                                      \
+   ((((pkt)&0xF0000000) == CP_TYPE7_PKT) && (((pkt)&0x0F000000) == 0) &&       \
+    ((((pkt) >> 23) & 0x1) ==                                                  \
+     pm4_calc_odd_parity_bit(cp_type7_opcode(pkt))) &&                         \
+    ((((pkt) >> 15) & 0x1) == pm4_calc_odd_parity_bit(type7_pkt_size(pkt))))
+
+#define cp_type7_opcode(pkt) (((pkt) >> 16) & 0x7F)
+#define type7_pkt_size(pkt)  ((pkt)&0x3FFF)
+
 #ifdef __cplusplus
 } /* end of extern "C" */
 #endif
index 8cae4a0..ef7d436 100644 (file)
@@ -39,6 +39,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "freedreno_pm4.h"
+
 #include "buffers.h"
 #include "cffdec.h"
 #include "disasm.h"
index 49b952f..1d0a05d 100644 (file)
@@ -87,58 +87,4 @@ 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);
 
-/*
- * Helpers for packet parsing:
- */
-
-#define CP_TYPE0_PKT 0x00000000
-#define CP_TYPE2_PKT 0x80000000
-#define CP_TYPE3_PKT 0xc0000000
-#define CP_TYPE4_PKT 0x40000000
-#define CP_TYPE7_PKT 0x70000000
-
-#define pkt_is_type0(pkt)     (((pkt)&0XC0000000) == CP_TYPE0_PKT)
-#define type0_pkt_size(pkt)   ((((pkt) >> 16) & 0x3FFF) + 1)
-#define type0_pkt_offset(pkt) ((pkt)&0x7FFF)
-
-#define pkt_is_type2(pkt) ((pkt) == CP_TYPE2_PKT)
-
-/*
- * Check both for the type3 opcode and make sure that the reserved bits [1:7]
- * and 15 are 0
- */
-
-static inline uint
-pm4_calc_odd_parity_bit(uint val)
-{
-   return (0x9669 >> (0xf & ((val) ^ ((val) >> 4) ^ ((val) >> 8) ^
-                             ((val) >> 12) ^ ((val) >> 16) ^ ((val) >> 20) ^
-                             ((val) >> 24) ^ ((val) >> 28)))) &
-          1;
-}
-
-#define pkt_is_type3(pkt)                                                      \
-   ((((pkt)&0xC0000000) == CP_TYPE3_PKT) && (((pkt)&0x80FE) == 0))
-
-#define cp_type3_opcode(pkt) (((pkt) >> 8) & 0xFF)
-#define type3_pkt_size(pkt)  ((((pkt) >> 16) & 0x3FFF) + 1)
-
-#define pkt_is_type4(pkt)                                                      \
-   ((((pkt)&0xF0000000) == CP_TYPE4_PKT) &&                                    \
-    ((((pkt) >> 27) & 0x1) ==                                                  \
-     pm4_calc_odd_parity_bit(type4_pkt_offset(pkt))) &&                        \
-    ((((pkt) >> 7) & 0x1) == pm4_calc_odd_parity_bit(type4_pkt_size(pkt))))
-
-#define type4_pkt_offset(pkt) (((pkt) >> 8) & 0x7FFFF)
-#define type4_pkt_size(pkt)   ((pkt)&0x7F)
-
-#define pkt_is_type7(pkt)                                                      \
-   ((((pkt)&0xF0000000) == CP_TYPE7_PKT) && (((pkt)&0x0F000000) == 0) &&       \
-    ((((pkt) >> 23) & 0x1) ==                                                  \
-     pm4_calc_odd_parity_bit(cp_type7_opcode(pkt))) &&                         \
-    ((((pkt) >> 15) & 0x1) == pm4_calc_odd_parity_bit(type7_pkt_size(pkt))))
-
-#define cp_type7_opcode(pkt) (((pkt) >> 16) & 0x7F)
-#define type7_pkt_size(pkt)  ((pkt)&0x3FFF)
-
 #endif /* __CFFDEC_H__ */
index cb6ff79..14313ca 100644 (file)
@@ -47,6 +47,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "freedreno_pm4.h"
+
 #include "ir3/instr-a3xx.h"
 #include "buffers.h"
 #include "cffdec.h"