1b8e80941Smrg/*
2b8e80941Smrg * Copyright © 2016-2018 Broadcom
3b8e80941Smrg *
4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
6b8e80941Smrg * to deal in the Software without restriction, including without limitation
7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
9b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
10b8e80941Smrg *
11b8e80941Smrg * The above copyright notice and this permission notice (including the next
12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
13b8e80941Smrg * Software.
14b8e80941Smrg *
15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21b8e80941Smrg * IN THE SOFTWARE.
22b8e80941Smrg */
23b8e80941Smrg
24b8e80941Smrg#ifndef CLIF_PRIVATE_H
25b8e80941Smrg#define CLIF_PRIVATE_H
26b8e80941Smrg
27b8e80941Smrg#include <stdint.h>
28b8e80941Smrg#include <stdarg.h>
29b8e80941Smrg#include "util/list.h"
30b8e80941Smrg
31b8e80941Smrgstruct clif_bo {
32b8e80941Smrg        const char *name;
33b8e80941Smrg        uint32_t offset;
34b8e80941Smrg        uint32_t size;
35b8e80941Smrg        void *vaddr;
36b8e80941Smrg        bool dumped;
37b8e80941Smrg};
38b8e80941Smrg
39b8e80941Smrgstruct clif_dump {
40b8e80941Smrg        const struct v3d_device_info *devinfo;
41b8e80941Smrg        FILE *out;
42b8e80941Smrg
43b8e80941Smrg        struct v3d_spec *spec;
44b8e80941Smrg
45b8e80941Smrg        /* List of struct reloc_worklist_entry */
46b8e80941Smrg        struct list_head worklist;
47b8e80941Smrg
48b8e80941Smrg        struct clif_bo *bo;
49b8e80941Smrg        int bo_count;
50b8e80941Smrg        int bo_array_size;
51b8e80941Smrg
52b8e80941Smrg        /**
53b8e80941Smrg         * Flag to switch from CLIF ABI to slightly more human-readable
54b8e80941Smrg         * output.
55b8e80941Smrg         */
56b8e80941Smrg        bool pretty;
57b8e80941Smrg};
58b8e80941Smrg
59b8e80941Smrgenum reloc_worklist_type {
60b8e80941Smrg        reloc_cl,
61b8e80941Smrg        reloc_gl_shader_state,
62b8e80941Smrg        reloc_generic_tile_list,
63b8e80941Smrg};
64b8e80941Smrg
65b8e80941Smrgstruct reloc_worklist_entry {
66b8e80941Smrg        struct list_head link;
67b8e80941Smrg
68b8e80941Smrg        enum reloc_worklist_type type;
69b8e80941Smrg        uint32_t addr;
70b8e80941Smrg
71b8e80941Smrg        union {
72b8e80941Smrg                struct {
73b8e80941Smrg                        uint32_t end;
74b8e80941Smrg                } cl;
75b8e80941Smrg                struct {
76b8e80941Smrg                        uint32_t num_attrs;
77b8e80941Smrg                } shader_state;
78b8e80941Smrg                struct {
79b8e80941Smrg                        uint32_t end;
80b8e80941Smrg                } generic_tile_list;
81b8e80941Smrg        };
82b8e80941Smrg};
83b8e80941Smrg
84b8e80941Smrgstruct clif_bo *
85b8e80941Smrgclif_lookup_bo(struct clif_dump *clif, uint32_t addr);
86b8e80941Smrg
87b8e80941Smrgstruct reloc_worklist_entry *
88b8e80941Smrgclif_dump_add_address_to_worklist(struct clif_dump *clif,
89b8e80941Smrg                                  enum reloc_worklist_type type,
90b8e80941Smrg                                  uint32_t addr);
91b8e80941Smrg
92b8e80941Smrgbool v3d33_clif_dump_packet(struct clif_dump *clif, uint32_t offset,
93b8e80941Smrg                            const uint8_t *cl, uint32_t *size, bool reloc_mode);
94b8e80941Smrgbool v3d41_clif_dump_packet(struct clif_dump *clif, uint32_t offset,
95b8e80941Smrg                            const uint8_t *cl, uint32_t *size, bool reloc_mode);
96b8e80941Smrgbool v3d42_clif_dump_packet(struct clif_dump *clif, uint32_t offset,
97b8e80941Smrg                            const uint8_t *cl, uint32_t *size, bool reloc_mode);
98b8e80941Smrg
99b8e80941Smrgstatic inline void
100b8e80941Smrgout(struct clif_dump *clif, const char *fmt, ...)
101b8e80941Smrg{
102b8e80941Smrg        va_list args;
103b8e80941Smrg
104b8e80941Smrg        va_start(args, fmt);
105b8e80941Smrg        vfprintf(clif->out, fmt, args);
106b8e80941Smrg        va_end(args);
107b8e80941Smrg}
108b8e80941Smrg
109b8e80941Smrgstatic inline void
110b8e80941Smrgout_address(struct clif_dump *clif, uint32_t addr)
111b8e80941Smrg{
112b8e80941Smrg        struct clif_bo *bo = clif_lookup_bo(clif, addr);
113b8e80941Smrg        if (bo) {
114b8e80941Smrg                out(clif, "[%s+0x%08x] /* 0x%08x */",
115b8e80941Smrg                    bo->name, addr - bo->offset, addr);
116b8e80941Smrg        } else if (addr) {
117b8e80941Smrg                out(clif, "/* XXX: BO unknown */ 0x%08x", addr);
118b8e80941Smrg        } else {
119b8e80941Smrg                out(clif, "[null]");
120b8e80941Smrg        }
121b8e80941Smrg}
122b8e80941Smrg
123b8e80941Smrg#endif /* CLIF_PRIVATE_H */
124