xref: /aosp_15_r20/external/mesa3d/src/nouveau/headers/nv_push.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 #include "nv_push.h"
2 
3 #include "nv_device_info.h"
4 
5 #include <inttypes.h>
6 
7 #include "nv_push_cl902d.h"
8 #include "nv_push_cl9039.h"
9 #include "nv_push_cl906f.h"
10 #include "nv_push_cl9097.h"
11 #include "nv_push_cl90b5.h"
12 #include "nv_push_cla097.h"
13 #include "nv_push_cla0b5.h"
14 #include "nv_push_cla040.h"
15 #include "nv_push_cla0c0.h"
16 #include "nv_push_cla140.h"
17 #include "nv_push_clb197.h"
18 #include "nv_push_clc0c0.h"
19 #include "nv_push_clc1b5.h"
20 #include "nv_push_clc397.h"
21 #include "nv_push_clc3c0.h"
22 #include "nv_push_clc597.h"
23 #include "nv_push_clc5c0.h"
24 #include "nv_push_clc697.h"
25 #include "nv_push_clc6c0.h"
26 #include "nv_push_clc797.h"
27 #include "nv_push_clc7c0.h"
28 
29 #ifndef NDEBUG
30 void
nv_push_validate(struct nv_push * push)31 nv_push_validate(struct nv_push *push)
32 {
33    uint32_t *cur = push->start;
34 
35    /* submitting empty push buffers is probably a bug */
36    assert(push->end != push->start);
37 
38    /* make sure we don't overrun the bo */
39    assert(push->end <= push->limit);
40 
41    /* parse all the headers to see if we get to buf->map */
42    while (cur < push->end) {
43       uint32_t hdr = *cur;
44       uint32_t mthd = hdr >> 29;
45 
46       switch (mthd) {
47       /* immd */
48       case 4:
49          break;
50       case 1:
51       case 3:
52       case 5: {
53          uint32_t count = (hdr >> 16) & 0x1fff;
54          assert(count);
55          cur += count;
56          break;
57       }
58       default:
59          assert(!"unknown method found");
60       }
61 
62       cur++;
63       assert(cur <= push->end);
64    }
65 }
66 #endif
67 
68 void
vk_push_print(FILE * fp,const struct nv_push * push,const struct nv_device_info * devinfo)69 vk_push_print(FILE *fp, const struct nv_push *push,
70               const struct nv_device_info *devinfo)
71 {
72    uint32_t *cur = push->start;
73 
74    const bool print_offsets = true;
75 
76    while (cur < push->end) {
77       uint32_t hdr = *cur;
78       uint32_t type = hdr >> 29;
79       bool is_tert = type == 0 || type == 2;
80       uint32_t inc = 0;
81       uint32_t count = is_tert ? (hdr >> 18) & 0x3ff : (hdr >> 16) & 0x1fff;
82       uint32_t tert_op = (hdr >> 16) & 0x3;
83       uint32_t subchan = (hdr >> 13) & 0x7;
84       uint32_t mthd = (hdr & 0xfff) << 2;
85       uint32_t value = 0;
86       bool is_immd = false;
87 
88       if (print_offsets)
89          fprintf(fp, "[0x%08" PRIxPTR "] ", cur - push->start);
90 
91       if (is_tert && tert_op != 0) {
92          fprintf(fp, "HDR %x subch N/A", hdr);
93       } else {
94          fprintf(fp, "HDR %x subch %i", hdr, subchan);
95       }
96 
97       cur++;
98 
99       const char *mthd_name = "";
100 
101       switch (type) {
102       case 4:
103          fprintf(fp, " IMMD\n");
104          inc = 0;
105          is_immd = true;
106          value = count;
107          count = 1;
108          break;
109       case 1:
110          fprintf(fp, " NINC\n");
111          inc = count;
112          break;
113       case 2:
114       case 3:
115          fprintf(fp, " 0INC\n");
116          inc = 0;
117          break;
118       case 5:
119          fprintf(fp, " 1INC\n");
120          inc = 1;
121          break;
122       case 0:
123          switch (tert_op) {
124          case 0:
125             fprintf(fp, " NINC\n");
126             inc = count;
127             break;
128          case 1:
129             fprintf(fp, " SUB_DEVICE_OP\n");
130             mthd_name = "SET_SUBDEVICE_MASK";
131             mthd = tert_op;
132             value = (hdr >> 4) & 0xfff;
133             count = 1;
134             is_immd = true;
135             break;
136          case 2:
137             fprintf(fp, " SUB_DEVICE_OP\n");
138             mthd_name = "STORE_SUBDEVICE_MASK";
139             mthd = tert_op;
140             value = (hdr >> 4) & 0xfff;
141             count = 1;
142             is_immd = true;
143             break;
144          case 3:
145             fprintf(fp, " SUB_DEVICE_OP\n");
146             mthd_name = "USE_SUBDEVICE_MASK";
147             mthd = tert_op;
148             count = 1;
149             break;
150          }
151          break;
152       }
153 
154       while (count--) {
155          if (!is_tert) {
156             if (mthd < 0x100) {
157                mthd_name = P_PARSE_NV906F_MTHD(mthd);
158             } else {
159                switch (subchan) {
160                case 0:
161                   if (devinfo->cls_eng3d >= 0xc797)
162                      mthd_name = P_PARSE_NVC797_MTHD(mthd);
163                   else if (devinfo->cls_eng3d >= 0xc697)
164                      mthd_name = P_PARSE_NVC697_MTHD(mthd);
165                   else if (devinfo->cls_eng3d >= 0xc597)
166                      mthd_name = P_PARSE_NVC597_MTHD(mthd);
167                   else if (devinfo->cls_eng3d >= 0xc397)
168                      mthd_name = P_PARSE_NVC397_MTHD(mthd);
169                   else if (devinfo->cls_eng3d >= 0xb197)
170                      mthd_name = P_PARSE_NVB197_MTHD(mthd);
171                   else if (devinfo->cls_eng3d >= 0xa097)
172                      mthd_name = P_PARSE_NVA097_MTHD(mthd);
173                   else
174                      mthd_name = P_PARSE_NV9097_MTHD(mthd);
175                   break;
176                case 1:
177                   if (devinfo->cls_compute >= 0xc7c0)
178                      mthd_name = P_PARSE_NVC7C0_MTHD(mthd);
179                   else if (devinfo->cls_compute >= 0xc6c0)
180                      mthd_name = P_PARSE_NVC6C0_MTHD(mthd);
181                   else if (devinfo->cls_compute >= 0xc5c0)
182                      mthd_name = P_PARSE_NVC5C0_MTHD(mthd);
183                   else if (devinfo->cls_compute >= 0xc3c0)
184                      mthd_name = P_PARSE_NVC3C0_MTHD(mthd);
185                   else if (devinfo->cls_compute >= 0xc0c0)
186                      mthd_name = P_PARSE_NVC0C0_MTHD(mthd);
187                   else
188                      mthd_name = P_PARSE_NVA0C0_MTHD(mthd);
189                   break;
190                case 2:
191                   if (devinfo->cls_m2mf >= 0xa140)
192                      mthd_name = P_PARSE_NVA140_MTHD(mthd);
193                   else if (devinfo->cls_m2mf >= 0xa040)
194                      mthd_name = P_PARSE_NVA040_MTHD(mthd);
195                   else if (devinfo->cls_m2mf >= 0x9039)
196                      mthd_name = P_PARSE_NV9039_MTHD(mthd);
197                   break;
198                case 3:
199                   mthd_name = P_PARSE_NV902D_MTHD(mthd);
200                   break;
201                case 4:
202                   if (devinfo->cls_copy >= 0xc1b5)
203                      mthd_name = P_PARSE_NVC1B5_MTHD(mthd);
204                   else if (devinfo->cls_copy >= 0xa0b5)
205                      mthd_name = P_PARSE_NVA0B5_MTHD(mthd);
206                   else
207                      mthd_name = P_PARSE_NV90B5_MTHD(mthd);
208                   break;
209                default:
210                   mthd_name = "unknown method";
211                   break;
212                }
213             }
214          }
215 
216          if (!is_immd)
217             value = *cur;
218 
219          fprintf(fp, "\tmthd %04x %s\n", mthd, mthd_name);
220          if (mthd < 0x100) {
221             P_DUMP_NV906F_MTHD_DATA(fp, mthd, value, "\t\t");
222          } else {
223             switch (subchan) {
224             case 0:
225                if (devinfo->cls_eng3d >= 0xc597)
226                   P_DUMP_NVC597_MTHD_DATA(fp, mthd, value, "\t\t");
227                else if (devinfo->cls_eng3d >= 0xc397)
228                   P_DUMP_NVC397_MTHD_DATA(fp, mthd, value, "\t\t");
229                else if (devinfo->cls_eng3d >= 0xb197)
230                   P_DUMP_NVB197_MTHD_DATA(fp, mthd, value, "\t\t");
231                else if (devinfo->cls_eng3d >= 0xa097)
232                   P_DUMP_NVA097_MTHD_DATA(fp, mthd, value, "\t\t");
233                else
234                   P_DUMP_NV9097_MTHD_DATA(fp, mthd, value, "\t\t");
235                break;
236             case 1:
237                if (devinfo->cls_compute >= 0xc3c0)
238                   P_DUMP_NVC3C0_MTHD_DATA(fp, mthd, value, "\t\t");
239                else if (devinfo->cls_compute >= 0xc0c0)
240                   P_DUMP_NVC0C0_MTHD_DATA(fp, mthd, value, "\t\t");
241                else
242                   P_DUMP_NVA0C0_MTHD_DATA(fp, mthd, value, "\t\t");
243                break;
244             case 3:
245                P_DUMP_NV902D_MTHD_DATA(fp, mthd, value, "\t\t");
246                break;
247             case 4:
248                if (devinfo->cls_copy >= 0xc1b5)
249                   P_DUMP_NVC1B5_MTHD_DATA(fp, mthd, value, "\t\t");
250                else if (devinfo->cls_copy >= 0xa0b5)
251                   P_DUMP_NVA0B5_MTHD_DATA(fp, mthd, value, "\t\t");
252                else
253                   P_DUMP_NV90B5_MTHD_DATA(fp, mthd, value, "\t\t");
254                break;
255             default:
256                fprintf(fp, "%s.VALUE = 0x%x\n", "\t\t", value);
257                break;
258             }
259          }
260 
261          if (!is_immd)
262             cur++;
263 
264          if (inc) {
265             inc--;
266             mthd += 4;
267          }
268       }
269 
270       fprintf(fp, "\n");
271    }
272 }
273