From 33b9445a68913ebbd02f12c132fd251b8a86d2c9 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 21 May 2021 13:58:13 -0700 Subject: [PATCH] freedreno: Move pkt parsing helpers to common I'll be needing these in afuc as well. Signed-off-by: Rob Clark Part-of: --- src/freedreno/afuc/disasm.c | 17 ++---------- src/freedreno/afuc/meson.build | 6 +++- src/freedreno/common/freedreno_pm4.h | 43 ++++++++++++++++++++++++++++ src/freedreno/decode/cffdec.c | 2 ++ src/freedreno/decode/cffdec.h | 54 ------------------------------------ src/freedreno/decode/crashdec.c | 2 ++ 6 files changed, 55 insertions(+), 69 deletions(-) diff --git a/src/freedreno/afuc/disasm.c b/src/freedreno/afuc/disasm.c index b761cac..14e9d2f 100644 --- a/src/freedreno/afuc/disasm.c +++ b/src/freedreno/afuc/disasm.c @@ -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 diff --git a/src/freedreno/afuc/meson.build b/src/freedreno/afuc/meson.build index 516b243..54c19b3 100644 --- a/src/freedreno/afuc/meson.build +++ b/src/freedreno/afuc/meson.build @@ -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, diff --git a/src/freedreno/common/freedreno_pm4.h b/src/freedreno/common/freedreno_pm4.h index 78b4e0f..4320a5c 100644 --- a/src/freedreno/common/freedreno_pm4.h +++ b/src/freedreno/common/freedreno_pm4.h @@ -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 diff --git a/src/freedreno/decode/cffdec.c b/src/freedreno/decode/cffdec.c index 8cae4a0..ef7d436 100644 --- a/src/freedreno/decode/cffdec.c +++ b/src/freedreno/decode/cffdec.c @@ -39,6 +39,8 @@ #include #include +#include "freedreno_pm4.h" + #include "buffers.h" #include "cffdec.h" #include "disasm.h" diff --git a/src/freedreno/decode/cffdec.h b/src/freedreno/decode/cffdec.h index 49b952f..1d0a05d 100644 --- a/src/freedreno/decode/cffdec.h +++ b/src/freedreno/decode/cffdec.h @@ -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__ */ diff --git a/src/freedreno/decode/crashdec.c b/src/freedreno/decode/crashdec.c index cb6ff79..14313ca 100644 --- a/src/freedreno/decode/crashdec.c +++ b/src/freedreno/decode/crashdec.c @@ -47,6 +47,8 @@ #include #include +#include "freedreno_pm4.h" + #include "ir3/instr-a3xx.h" #include "buffers.h" #include "cffdec.h" -- 2.7.4