1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2016 Intel Corporation
3bf215546Sopenharmony_ci * Copyright © 2017 Broadcom
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22bf215546Sopenharmony_ci * IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#ifndef V3D_DECODER_H
26bf215546Sopenharmony_ci#define V3D_DECODER_H
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include <stdint.h>
29bf215546Sopenharmony_ci#include <stdio.h>
30bf215546Sopenharmony_ci#include <stdbool.h>
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "broadcom/common/v3d_device_info.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_cistruct v3d_spec;
35bf215546Sopenharmony_cistruct v3d_group;
36bf215546Sopenharmony_cistruct v3d_field;
37bf215546Sopenharmony_cistruct clif_dump;
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistruct v3d_group *v3d_spec_find_struct(struct v3d_spec *spec, const char *name);
40bf215546Sopenharmony_cistruct v3d_spec *v3d_spec_load(const struct v3d_device_info *devinfo);
41bf215546Sopenharmony_cistruct v3d_group *v3d_spec_find_instruction(struct v3d_spec *spec, const uint8_t *p);
42bf215546Sopenharmony_cistruct v3d_group *v3d_spec_find_register(struct v3d_spec *spec, uint32_t offset);
43bf215546Sopenharmony_cistruct v3d_group *v3d_spec_find_register_by_name(struct v3d_spec *spec, const char *name);
44bf215546Sopenharmony_ciint v3d_group_get_length(struct v3d_group *group);
45bf215546Sopenharmony_ciconst char *v3d_group_get_name(struct v3d_group *group);
46bf215546Sopenharmony_ciuint8_t v3d_group_get_opcode(struct v3d_group *group);
47bf215546Sopenharmony_cistruct v3d_enum *v3d_spec_find_enum(struct v3d_spec *spec, const char *name);
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_cistruct v3d_field_iterator {
50bf215546Sopenharmony_ci        struct v3d_group *group;
51bf215546Sopenharmony_ci        char name[128];
52bf215546Sopenharmony_ci        char value[128];
53bf215546Sopenharmony_ci        struct v3d_group *struct_desc;
54bf215546Sopenharmony_ci        const uint8_t *p;
55bf215546Sopenharmony_ci        int offset; /**< current field starts at &p[offset] */
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci        int field_iter;
58bf215546Sopenharmony_ci        int group_iter;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci        struct v3d_field *field;
61bf215546Sopenharmony_ci};
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_cistruct v3d_group {
64bf215546Sopenharmony_ci        struct v3d_spec *spec;
65bf215546Sopenharmony_ci        char *name;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci        struct v3d_field **fields;
68bf215546Sopenharmony_ci        uint32_t nfields;
69bf215546Sopenharmony_ci        uint32_t fields_size;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci        uint32_t group_offset, group_count;
72bf215546Sopenharmony_ci        uint32_t group_size;
73bf215546Sopenharmony_ci        bool variable;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci        struct v3d_group *parent;
76bf215546Sopenharmony_ci        struct v3d_group *next;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci        uint8_t opcode;
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci        /* Register specific */
81bf215546Sopenharmony_ci        uint32_t register_offset;
82bf215546Sopenharmony_ci};
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistruct v3d_value {
85bf215546Sopenharmony_ci        char *name;
86bf215546Sopenharmony_ci        uint64_t value;
87bf215546Sopenharmony_ci};
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_cistruct v3d_enum {
90bf215546Sopenharmony_ci        char *name;
91bf215546Sopenharmony_ci        int nvalues;
92bf215546Sopenharmony_ci        struct v3d_value **values;
93bf215546Sopenharmony_ci};
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_cistruct v3d_type {
96bf215546Sopenharmony_ci        enum {
97bf215546Sopenharmony_ci                V3D_TYPE_UNKNOWN,
98bf215546Sopenharmony_ci                V3D_TYPE_INT,
99bf215546Sopenharmony_ci                V3D_TYPE_UINT,
100bf215546Sopenharmony_ci                V3D_TYPE_BOOL,
101bf215546Sopenharmony_ci                V3D_TYPE_FLOAT,
102bf215546Sopenharmony_ci                V3D_TYPE_F187,
103bf215546Sopenharmony_ci                V3D_TYPE_ADDRESS,
104bf215546Sopenharmony_ci                V3D_TYPE_OFFSET,
105bf215546Sopenharmony_ci                V3D_TYPE_STRUCT,
106bf215546Sopenharmony_ci                V3D_TYPE_UFIXED,
107bf215546Sopenharmony_ci                V3D_TYPE_SFIXED,
108bf215546Sopenharmony_ci                V3D_TYPE_MBO,
109bf215546Sopenharmony_ci                V3D_TYPE_ENUM
110bf215546Sopenharmony_ci        } kind;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci        /* Struct definition for V3D_TYPE_STRUCT */
113bf215546Sopenharmony_ci        union {
114bf215546Sopenharmony_ci                struct v3d_group *v3d_struct;
115bf215546Sopenharmony_ci                struct v3d_enum *v3d_enum;
116bf215546Sopenharmony_ci                struct {
117bf215546Sopenharmony_ci                        /* Integer and fractional sizes for V3D_TYPE_UFIXED and
118bf215546Sopenharmony_ci                         * V3D_TYPE_SFIXED
119bf215546Sopenharmony_ci                         */
120bf215546Sopenharmony_ci                        int i, f;
121bf215546Sopenharmony_ci                };
122bf215546Sopenharmony_ci        };
123bf215546Sopenharmony_ci};
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_cistruct v3d_field {
126bf215546Sopenharmony_ci        char *name;
127bf215546Sopenharmony_ci        int start, end;
128bf215546Sopenharmony_ci        struct v3d_type type;
129bf215546Sopenharmony_ci        bool minus_one;
130bf215546Sopenharmony_ci        bool has_default;
131bf215546Sopenharmony_ci        uint32_t default_value;
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci        struct v3d_enum inline_enum;
134bf215546Sopenharmony_ci};
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_civoid v3d_field_iterator_init(struct v3d_field_iterator *iter,
137bf215546Sopenharmony_ci                             struct v3d_group *group,
138bf215546Sopenharmony_ci                             const uint8_t *p);
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_cibool v3d_field_iterator_next(struct clif_dump *clif,
141bf215546Sopenharmony_ci                             struct v3d_field_iterator *iter);
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_civoid v3d_print_group(struct clif_dump *clif,
144bf215546Sopenharmony_ci                     struct v3d_group *group,
145bf215546Sopenharmony_ci                     uint64_t offset, const uint8_t *p);
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci#endif /* V3D_DECODER_H */
148