intel: Add simple logging façade for Android (v2)
[mesa.git] / src / intel / common / gen_decoder.h
1 /*
2 * Copyright © 2016 Intel Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef GEN_DECODER_H
25 #define GEN_DECODER_H
26
27 #include <stdint.h>
28 #include <stdbool.h>
29
30 #include "common/gen_device_info.h"
31
32 struct gen_spec;
33 struct gen_group;
34 struct gen_field;
35
36 static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)
37 {
38 return (major << 8) | minor;
39 }
40
41 struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);
42 struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
43 struct gen_spec *gen_spec_load_from_path(const struct gen_device_info *devinfo,
44 const char *path);
45 uint32_t gen_spec_get_gen(struct gen_spec *spec);
46 struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p);
47 struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);
48 struct gen_group *gen_spec_find_register_by_name(struct gen_spec *spec, const char *name);
49 int gen_group_get_length(struct gen_group *group, const uint32_t *p);
50 const char *gen_group_get_name(struct gen_group *group);
51 uint32_t gen_group_get_opcode(struct gen_group *group);
52 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
53
54 struct gen_field_iterator {
55 struct gen_group *group;
56 char name[128];
57 char value[128];
58 struct gen_group *struct_desc;
59 const uint32_t *p;
60 int dword; /**< current field starts at &p[dword] */
61
62 int field_iter;
63 int group_iter;
64
65 struct gen_field *field;
66 bool print_colors;
67 };
68
69 struct gen_group {
70 struct gen_spec *spec;
71 char *name;
72
73 struct gen_field **fields;
74 uint32_t nfields;
75 uint32_t fields_size;
76
77 uint32_t group_offset, group_count;
78 uint32_t group_size;
79 bool variable;
80
81 struct gen_group *parent;
82 struct gen_group *next;
83
84 uint32_t opcode_mask;
85 uint32_t opcode;
86
87 /* Register specific */
88 uint32_t register_offset;
89 };
90
91 struct gen_value {
92 char *name;
93 uint64_t value;
94 };
95
96 struct gen_enum {
97 char *name;
98 int nvalues;
99 struct gen_value **values;
100 };
101
102 struct gen_type {
103 enum {
104 GEN_TYPE_UNKNOWN,
105 GEN_TYPE_INT,
106 GEN_TYPE_UINT,
107 GEN_TYPE_BOOL,
108 GEN_TYPE_FLOAT,
109 GEN_TYPE_ADDRESS,
110 GEN_TYPE_OFFSET,
111 GEN_TYPE_STRUCT,
112 GEN_TYPE_UFIXED,
113 GEN_TYPE_SFIXED,
114 GEN_TYPE_MBO,
115 GEN_TYPE_ENUM
116 } kind;
117
118 /* Struct definition for GEN_TYPE_STRUCT */
119 union {
120 struct gen_group *gen_struct;
121 struct gen_enum *gen_enum;
122 struct {
123 /* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
124 int i, f;
125 };
126 };
127 };
128
129 struct gen_field {
130 char *name;
131 int start, end;
132 struct gen_type type;
133 bool has_default;
134 uint32_t default_value;
135
136 struct gen_enum inline_enum;
137 };
138
139 void gen_field_iterator_init(struct gen_field_iterator *iter,
140 struct gen_group *group,
141 const uint32_t *p,
142 bool print_colors);
143
144 bool gen_field_iterator_next(struct gen_field_iterator *iter);
145
146 void gen_print_group(FILE *out,
147 struct gen_group *group,
148 uint64_t offset, const uint32_t *p,
149 bool color);
150
151 #endif /* GEN_DECODER_H */