2 * Copyright (c) 2012 Rob Clark <robdclark@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 /* default mode, dump all queried regs on each draw: */
33 /* only dump if any of the queried regs were written
38 /* only dump if any of the queried regs changed since
44 struct cffdec_options
{
55 int query_compare
; /* binning vs SYSMEM/GMEM compare mode */
56 int query_mode
; /* enum query_mode */
60 /* In "once" mode, only decode a cmdstream buffer once (per draw
61 * mode, in the case of a6xx+ where a single cmdstream buffer can
62 * be used for both binning and draw pass), rather than each time
63 * encountered (ie. once per tile/bin in GMEM draw passes)
67 /* for crashdec, where we know CP_IBx_REM_SIZE, we can use this
68 * to highlight the cmdstream not parsed yet, to make it easier
69 * to see how far along the CP is.
77 void printl(int lvl
, const char *fmt
, ...);
78 const char * pktname(unsigned opc
);
79 uint32_t regbase(const char *name
);
80 const char * regname(uint32_t regbase
, int color
);
81 bool reg_written(uint32_t regbase
);
82 uint32_t reg_lastval(uint32_t regbase
);
83 uint32_t reg_val(uint32_t regbase
);
84 void reg_set(uint32_t regbase
, uint32_t val
);
85 void reset_regs(void);
86 void cffdec_init(const struct cffdec_options
*options
);
87 void dump_register_val(uint32_t regbase
, uint32_t dword
, int level
);
88 void dump_commands(uint32_t *dwords
, uint32_t sizedwords
, int level
);
91 * Helpers for packet parsing:
95 #define CP_TYPE0_PKT 0x00000000
96 #define CP_TYPE2_PKT 0x80000000
97 #define CP_TYPE3_PKT 0xc0000000
98 #define CP_TYPE4_PKT 0x40000000
99 #define CP_TYPE7_PKT 0x70000000
101 #define pkt_is_type0(pkt) (((pkt) & 0XC0000000) == CP_TYPE0_PKT)
102 #define type0_pkt_size(pkt) ((((pkt) >> 16) & 0x3FFF) + 1)
103 #define type0_pkt_offset(pkt) ((pkt) & 0x7FFF)
105 #define pkt_is_type2(pkt) ((pkt) == CP_TYPE2_PKT)
108 * Check both for the type3 opcode and make sure that the reserved bits [1:7]
112 static inline uint
pm4_calc_odd_parity_bit(uint val
)
114 return (0x9669 >> (0xf & ((val
) ^
115 ((val
) >> 4) ^ ((val
) >> 8) ^ ((val
) >> 12) ^
116 ((val
) >> 16) ^ ((val
) >> 20) ^ ((val
) >> 24) ^
117 ((val
) >> 28)))) & 1;
120 #define pkt_is_type3(pkt) \
121 ((((pkt) & 0xC0000000) == CP_TYPE3_PKT) && \
122 (((pkt) & 0x80FE) == 0))
124 #define cp_type3_opcode(pkt) (((pkt) >> 8) & 0xFF)
125 #define type3_pkt_size(pkt) ((((pkt) >> 16) & 0x3FFF) + 1)
127 #define pkt_is_type4(pkt) \
128 ((((pkt) & 0xF0000000) == CP_TYPE4_PKT) && \
129 ((((pkt) >> 27) & 0x1) == \
130 pm4_calc_odd_parity_bit(type4_pkt_offset(pkt))) \
131 && ((((pkt) >> 7) & 0x1) == \
132 pm4_calc_odd_parity_bit(type4_pkt_size(pkt))))
134 #define type4_pkt_offset(pkt) (((pkt) >> 8) & 0x7FFFF)
135 #define type4_pkt_size(pkt) ((pkt) & 0x7F)
137 #define pkt_is_type7(pkt) \
138 ((((pkt) & 0xF0000000) == CP_TYPE7_PKT) && \
139 (((pkt) & 0x0F000000) == 0) && \
140 ((((pkt) >> 23) & 0x1) == \
141 pm4_calc_odd_parity_bit(cp_type7_opcode(pkt))) \
142 && ((((pkt) >> 15) & 0x1) == \
143 pm4_calc_odd_parity_bit(type7_pkt_size(pkt))))
145 #define cp_type7_opcode(pkt) (((pkt) >> 16) & 0x7F)
146 #define type7_pkt_size(pkt) ((pkt) & 0x3FFF)
148 #endif /* __CFFDEC_H__ */