1 /*
2 * Copyright (c) 2012 Rob Clark <robdclark@gmail.com>
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24 #ifndef __CFFDEC_H__
25 #define __CFFDEC_H__
26
27 #include <stdbool.h>
28
29 enum query_mode {
30 /* default mode, dump all queried regs on each draw: */
31 QUERY_ALL = 0,
32
33 /* only dump if any of the queried regs were written
34 * since last draw:
35 */
36 QUERY_WRITTEN,
37
38 /* only dump if any of the queried regs changed since
39 * last draw:
40 */
41 QUERY_DELTA,
42 };
43
44 struct cffdec_options {
45 unsigned gpu_id;
46 int draw_filter;
47 int color;
48 int dump_shaders;
49 int summary;
50 int allregs;
51 int dump_textures;
52 int decode_markers;
53 char *script;
54
55 int query_compare; /* binning vs SYSMEM/GMEM compare mode */
56 int query_mode; /* enum query_mode */
57 char **querystrs;
58 int nquery;
59
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)
64 */
65 int once;
66
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.
70 */
71 struct {
72 uint64_t base;
73 uint32_t rem;
74 } ibs[4];
75 };
76
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);
89
90 /*
91 * Helpers for packet parsing:
92 */
93
94
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
100
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)
104
105 #define pkt_is_type2(pkt) ((pkt) == CP_TYPE2_PKT)
106
107 /*
108 * Check both for the type3 opcode and make sure that the reserved bits [1:7]
109 * and 15 are 0
110 */
111
pm4_calc_odd_parity_bit(uint val)112 static inline uint pm4_calc_odd_parity_bit(uint val)
113 {
114 return (0x9669 >> (0xf & ((val) ^
115 ((val) >> 4) ^ ((val) >> 8) ^ ((val) >> 12) ^
116 ((val) >> 16) ^ ((val) >> 20) ^ ((val) >> 24) ^
117 ((val) >> 28)))) & 1;
118 }
119
120 #define pkt_is_type3(pkt) \
121 ((((pkt) & 0xC0000000) == CP_TYPE3_PKT) && \
122 (((pkt) & 0x80FE) == 0))
123
124 #define cp_type3_opcode(pkt) (((pkt) >> 8) & 0xFF)
125 #define type3_pkt_size(pkt) ((((pkt) >> 16) & 0x3FFF) + 1)
126
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))))
133
134 #define type4_pkt_offset(pkt) (((pkt) >> 8) & 0x7FFFF)
135 #define type4_pkt_size(pkt) ((pkt) & 0x7F)
136
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))))
144
145 #define cp_type7_opcode(pkt) (((pkt) >> 16) & 0x7F)
146 #define type7_pkt_size(pkt) ((pkt) & 0x3FFF)
147
148 #endif /* __CFFDEC_H__ */
149