1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2014 Broadcom
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include "util/u_math.h"
25bf215546Sopenharmony_ci#include "util/u_prim.h"
26bf215546Sopenharmony_ci#include "util/macros.h"
27bf215546Sopenharmony_ci#include "vc4_cl_dump.h"
28bf215546Sopenharmony_ci#include "kernel/vc4_packet.h"
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "broadcom/cle/v3d_decoder.h"
31bf215546Sopenharmony_ci#include "broadcom/clif/clif_dump.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_civoid
34bf215546Sopenharmony_civc4_dump_cl(void *cl, uint32_t size, bool is_render)
35bf215546Sopenharmony_ci{
36bf215546Sopenharmony_ci        struct v3d_device_info devinfo = {
37bf215546Sopenharmony_ci                /* While the driver supports V3D 2.1 and 2.6, we haven't split
38bf215546Sopenharmony_ci                 * off a 2.6 XML yet (there are a couple of fields different
39bf215546Sopenharmony_ci                 * in render target formatting)
40bf215546Sopenharmony_ci                 */
41bf215546Sopenharmony_ci                .ver = 21,
42bf215546Sopenharmony_ci        };
43bf215546Sopenharmony_ci        struct v3d_spec *spec = v3d_spec_load(&devinfo);
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci        struct clif_dump *clif = clif_dump_init(&devinfo, stderr, true, false);
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci        uint32_t offset = 0, hw_offset = 0;
48bf215546Sopenharmony_ci        uint8_t *p = cl;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci        while (offset < size) {
51bf215546Sopenharmony_ci                struct v3d_group *inst = v3d_spec_find_instruction(spec, p);
52bf215546Sopenharmony_ci                uint8_t header = *p;
53bf215546Sopenharmony_ci                uint32_t length;
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci                if (inst == NULL) {
56bf215546Sopenharmony_ci                        fprintf(stderr, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
57bf215546Sopenharmony_ci                                offset, hw_offset, header, header);
58bf215546Sopenharmony_ci                        return;
59bf215546Sopenharmony_ci                }
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci                length = v3d_group_get_length(inst);
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci                fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
64bf215546Sopenharmony_ci                        offset, hw_offset, header, v3d_group_get_name(inst));
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci                v3d_print_group(clif, inst, offset, p);
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci                switch (header) {
69bf215546Sopenharmony_ci                case VC4_PACKET_HALT:
70bf215546Sopenharmony_ci                case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF:
71bf215546Sopenharmony_ci                        return;
72bf215546Sopenharmony_ci                default:
73bf215546Sopenharmony_ci                        break;
74bf215546Sopenharmony_ci                }
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci                offset += length;
77bf215546Sopenharmony_ci                if (header != VC4_PACKET_GEM_HANDLES)
78bf215546Sopenharmony_ci                        hw_offset += length;
79bf215546Sopenharmony_ci                p += length;
80bf215546Sopenharmony_ci        }
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci        clif_dump_destroy(clif);
83bf215546Sopenharmony_ci}
84bf215546Sopenharmony_ci
85