101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2016 Intel Corporation
301e04c3fSmrg * Copyright © 2017 Broadcom
401e04c3fSmrg *
501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
601e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
701e04c3fSmrg * to deal in the Software without restriction, including without limitation
801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1101e04c3fSmrg *
1201e04c3fSmrg * The above copyright notice and this permission notice (including the next
1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1401e04c3fSmrg * Software.
1501e04c3fSmrg *
1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2201e04c3fSmrg * IN THE SOFTWARE.
2301e04c3fSmrg */
2401e04c3fSmrg
2501e04c3fSmrg#ifndef V3D_DECODER_H
2601e04c3fSmrg#define V3D_DECODER_H
2701e04c3fSmrg
2801e04c3fSmrg#include <stdint.h>
2901e04c3fSmrg#include <stdio.h>
3001e04c3fSmrg#include <stdbool.h>
3101e04c3fSmrg
3201e04c3fSmrg#include "broadcom/common/v3d_device_info.h"
3301e04c3fSmrg
3401e04c3fSmrgstruct v3d_spec;
3501e04c3fSmrgstruct v3d_group;
3601e04c3fSmrgstruct v3d_field;
3701e04c3fSmrgstruct clif_dump;
3801e04c3fSmrg
3901e04c3fSmrgstruct v3d_group *v3d_spec_find_struct(struct v3d_spec *spec, const char *name);
4001e04c3fSmrgstruct v3d_spec *v3d_spec_load(const struct v3d_device_info *devinfo);
4101e04c3fSmrgstruct v3d_group *v3d_spec_find_instruction(struct v3d_spec *spec, const uint8_t *p);
4201e04c3fSmrgstruct v3d_group *v3d_spec_find_register(struct v3d_spec *spec, uint32_t offset);
4301e04c3fSmrgstruct v3d_group *v3d_spec_find_register_by_name(struct v3d_spec *spec, const char *name);
4401e04c3fSmrgint v3d_group_get_length(struct v3d_group *group);
4501e04c3fSmrgconst char *v3d_group_get_name(struct v3d_group *group);
4601e04c3fSmrguint8_t v3d_group_get_opcode(struct v3d_group *group);
4701e04c3fSmrgstruct v3d_enum *v3d_spec_find_enum(struct v3d_spec *spec, const char *name);
4801e04c3fSmrg
4901e04c3fSmrgstruct v3d_field_iterator {
5001e04c3fSmrg        struct v3d_group *group;
5101e04c3fSmrg        char name[128];
5201e04c3fSmrg        char value[128];
5301e04c3fSmrg        struct v3d_group *struct_desc;
5401e04c3fSmrg        const uint8_t *p;
5501e04c3fSmrg        int offset; /**< current field starts at &p[offset] */
5601e04c3fSmrg
5701e04c3fSmrg        int field_iter;
5801e04c3fSmrg        int group_iter;
5901e04c3fSmrg
6001e04c3fSmrg        struct v3d_field *field;
6101e04c3fSmrg};
6201e04c3fSmrg
6301e04c3fSmrgstruct v3d_group {
6401e04c3fSmrg        struct v3d_spec *spec;
6501e04c3fSmrg        char *name;
6601e04c3fSmrg
6701e04c3fSmrg        struct v3d_field **fields;
6801e04c3fSmrg        uint32_t nfields;
6901e04c3fSmrg        uint32_t fields_size;
7001e04c3fSmrg
7101e04c3fSmrg        uint32_t group_offset, group_count;
7201e04c3fSmrg        uint32_t group_size;
7301e04c3fSmrg        bool variable;
7401e04c3fSmrg
7501e04c3fSmrg        struct v3d_group *parent;
7601e04c3fSmrg        struct v3d_group *next;
7701e04c3fSmrg
7801e04c3fSmrg        uint8_t opcode;
7901e04c3fSmrg
8001e04c3fSmrg        /* Register specific */
8101e04c3fSmrg        uint32_t register_offset;
8201e04c3fSmrg};
8301e04c3fSmrg
8401e04c3fSmrgstruct v3d_value {
8501e04c3fSmrg        char *name;
8601e04c3fSmrg        uint64_t value;
8701e04c3fSmrg};
8801e04c3fSmrg
8901e04c3fSmrgstruct v3d_enum {
9001e04c3fSmrg        char *name;
9101e04c3fSmrg        int nvalues;
9201e04c3fSmrg        struct v3d_value **values;
9301e04c3fSmrg};
9401e04c3fSmrg
9501e04c3fSmrgstruct v3d_type {
9601e04c3fSmrg        enum {
9701e04c3fSmrg                V3D_TYPE_UNKNOWN,
9801e04c3fSmrg                V3D_TYPE_INT,
9901e04c3fSmrg                V3D_TYPE_UINT,
10001e04c3fSmrg                V3D_TYPE_BOOL,
10101e04c3fSmrg                V3D_TYPE_FLOAT,
10201e04c3fSmrg                V3D_TYPE_F187,
10301e04c3fSmrg                V3D_TYPE_ADDRESS,
10401e04c3fSmrg                V3D_TYPE_OFFSET,
10501e04c3fSmrg                V3D_TYPE_STRUCT,
10601e04c3fSmrg                V3D_TYPE_UFIXED,
10701e04c3fSmrg                V3D_TYPE_SFIXED,
10801e04c3fSmrg                V3D_TYPE_MBO,
10901e04c3fSmrg                V3D_TYPE_ENUM
11001e04c3fSmrg        } kind;
11101e04c3fSmrg
11201e04c3fSmrg        /* Struct definition for V3D_TYPE_STRUCT */
11301e04c3fSmrg        union {
11401e04c3fSmrg                struct v3d_group *v3d_struct;
11501e04c3fSmrg                struct v3d_enum *v3d_enum;
11601e04c3fSmrg                struct {
11701e04c3fSmrg                        /* Integer and fractional sizes for V3D_TYPE_UFIXED and
11801e04c3fSmrg                         * V3D_TYPE_SFIXED
11901e04c3fSmrg                         */
12001e04c3fSmrg                        int i, f;
12101e04c3fSmrg                };
12201e04c3fSmrg        };
12301e04c3fSmrg};
12401e04c3fSmrg
12501e04c3fSmrgstruct v3d_field {
12601e04c3fSmrg        char *name;
12701e04c3fSmrg        int start, end;
12801e04c3fSmrg        struct v3d_type type;
12901e04c3fSmrg        bool minus_one;
13001e04c3fSmrg        bool has_default;
13101e04c3fSmrg        uint32_t default_value;
13201e04c3fSmrg
13301e04c3fSmrg        struct v3d_enum inline_enum;
13401e04c3fSmrg};
13501e04c3fSmrg
13601e04c3fSmrgvoid v3d_field_iterator_init(struct v3d_field_iterator *iter,
13701e04c3fSmrg                             struct v3d_group *group,
13801e04c3fSmrg                             const uint8_t *p);
13901e04c3fSmrg
14001e04c3fSmrgbool v3d_field_iterator_next(struct clif_dump *clif,
14101e04c3fSmrg                             struct v3d_field_iterator *iter);
14201e04c3fSmrg
14301e04c3fSmrgvoid v3d_print_group(struct clif_dump *clif,
14401e04c3fSmrg                     struct v3d_group *group,
14501e04c3fSmrg                     uint64_t offset, const uint8_t *p);
14601e04c3fSmrg
14701e04c3fSmrg#endif /* V3D_DECODER_H */
148