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#include <ctype.h> 25b8e80941Smrg#include <stdlib.h> 26b8e80941Smrg#include <string.h> 27b8e80941Smrg#include "util/macros.h" 28b8e80941Smrg#include "broadcom/cle/v3d_decoder.h" 29b8e80941Smrg#include "clif_dump.h" 30b8e80941Smrg#include "clif_private.h" 31b8e80941Smrg 32b8e80941Smrg#define __gen_user_data void 33b8e80941Smrg#define __gen_address_type uint32_t 34b8e80941Smrg#define __gen_address_offset(reloc) (*reloc) 35b8e80941Smrg#define __gen_emit_reloc(cl, reloc) 36b8e80941Smrg#define __gen_unpack_address(cl, s, e) (__gen_unpack_uint(cl, s, e) << (31 - (e - s))) 37b8e80941Smrg#include "broadcom/cle/v3dx_pack.h" 38b8e80941Smrg#include "broadcom/common/v3d_macros.h" 39b8e80941Smrg 40b8e80941Smrgstatic char * 41b8e80941Smrgclif_name(const char *xml_name) 42b8e80941Smrg{ 43b8e80941Smrg char *name = malloc(strlen(xml_name) + 1); 44b8e80941Smrg 45b8e80941Smrg int j = 0; 46b8e80941Smrg for (int i = 0; i < strlen(xml_name); i++) { 47b8e80941Smrg if (xml_name[i] == ' ') { 48b8e80941Smrg name[j++] = '_'; 49b8e80941Smrg } else if (xml_name[i] == '(' || xml_name[i] == ')') { 50b8e80941Smrg /* skip */ 51b8e80941Smrg } else { 52b8e80941Smrg name[j++] = toupper(xml_name[i]); 53b8e80941Smrg } 54b8e80941Smrg } 55b8e80941Smrg name[j++] = 0; 56b8e80941Smrg 57b8e80941Smrg return name; 58b8e80941Smrg} 59b8e80941Smrg 60b8e80941Smrgbool 61b8e80941Smrgv3dX(clif_dump_packet)(struct clif_dump *clif, uint32_t offset, 62b8e80941Smrg const uint8_t *cl, uint32_t *size, bool reloc_mode) 63b8e80941Smrg{ 64b8e80941Smrg struct v3d_group *inst = v3d_spec_find_instruction(clif->spec, cl); 65b8e80941Smrg if (!inst) { 66b8e80941Smrg out(clif, "0x%08x: Unknown packet %d!\n", offset, *cl); 67b8e80941Smrg return false; 68b8e80941Smrg } 69b8e80941Smrg 70b8e80941Smrg *size = v3d_group_get_length(inst); 71b8e80941Smrg 72b8e80941Smrg if (!reloc_mode) { 73b8e80941Smrg char *name = clif_name(v3d_group_get_name(inst)); 74b8e80941Smrg out(clif, "%s\n", name); 75b8e80941Smrg free(name); 76b8e80941Smrg v3d_print_group(clif, inst, 0, cl); 77b8e80941Smrg } 78b8e80941Smrg 79b8e80941Smrg switch (*cl) { 80b8e80941Smrg case V3DX(GL_SHADER_STATE_opcode): { 81b8e80941Smrg struct V3DX(GL_SHADER_STATE) values; 82b8e80941Smrg V3DX(GL_SHADER_STATE_unpack)(cl, &values); 83b8e80941Smrg 84b8e80941Smrg if (reloc_mode) { 85b8e80941Smrg struct reloc_worklist_entry *reloc = 86b8e80941Smrg clif_dump_add_address_to_worklist(clif, 87b8e80941Smrg reloc_gl_shader_state, 88b8e80941Smrg values.address); 89b8e80941Smrg if (reloc) { 90b8e80941Smrg reloc->shader_state.num_attrs = 91b8e80941Smrg values.number_of_attribute_arrays; 92b8e80941Smrg } 93b8e80941Smrg } 94b8e80941Smrg return true; 95b8e80941Smrg } 96b8e80941Smrg 97b8e80941Smrg#if V3D_VERSION < 40 98b8e80941Smrg case V3DX(STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED_opcode): { 99b8e80941Smrg struct V3DX(STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED) values; 100b8e80941Smrg V3DX(STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED_unpack)(cl, &values); 101b8e80941Smrg 102b8e80941Smrg if (values.last_tile_of_frame) 103b8e80941Smrg return false; 104b8e80941Smrg break; 105b8e80941Smrg } 106b8e80941Smrg#endif /* V3D_VERSION < 40 */ 107b8e80941Smrg 108b8e80941Smrg#if V3D_VERSION > 40 109b8e80941Smrg case V3DX(TRANSFORM_FEEDBACK_SPECS_opcode): { 110b8e80941Smrg struct V3DX(TRANSFORM_FEEDBACK_SPECS) values; 111b8e80941Smrg V3DX(TRANSFORM_FEEDBACK_SPECS_unpack)(cl, &values); 112b8e80941Smrg struct v3d_group *spec = v3d_spec_find_struct(clif->spec, 113b8e80941Smrg "Transform Feedback Output Data Spec"); 114b8e80941Smrg assert(spec); 115b8e80941Smrg 116b8e80941Smrg cl += *size; 117b8e80941Smrg 118b8e80941Smrg for (int i = 0; i < values.number_of_16_bit_output_data_specs_following; i++) { 119b8e80941Smrg if (!reloc_mode) 120b8e80941Smrg v3d_print_group(clif, spec, 0, cl); 121b8e80941Smrg cl += v3d_group_get_length(spec); 122b8e80941Smrg *size += v3d_group_get_length(spec); 123b8e80941Smrg } 124b8e80941Smrg if (!reloc_mode) 125b8e80941Smrg out(clif, "@format ctrllist\n"); 126b8e80941Smrg break; 127b8e80941Smrg } 128b8e80941Smrg#else /* V3D_VERSION < 40 */ 129b8e80941Smrg case V3DX(TRANSFORM_FEEDBACK_ENABLE_opcode): { 130b8e80941Smrg struct V3DX(TRANSFORM_FEEDBACK_ENABLE) values; 131b8e80941Smrg V3DX(TRANSFORM_FEEDBACK_ENABLE_unpack)(cl, &values); 132b8e80941Smrg struct v3d_group *spec = v3d_spec_find_struct(clif->spec, 133b8e80941Smrg "Transform Feedback Output Data Spec"); 134b8e80941Smrg struct v3d_group *addr = v3d_spec_find_struct(clif->spec, 135b8e80941Smrg "Transform Feedback Output Address"); 136b8e80941Smrg assert(spec); 137b8e80941Smrg assert(addr); 138b8e80941Smrg 139b8e80941Smrg cl += *size; 140b8e80941Smrg 141b8e80941Smrg for (int i = 0; i < values.number_of_16_bit_output_data_specs_following; i++) { 142b8e80941Smrg if (!reloc_mode) 143b8e80941Smrg v3d_print_group(clif, spec, 0, cl); 144b8e80941Smrg cl += v3d_group_get_length(spec); 145b8e80941Smrg *size += v3d_group_get_length(spec); 146b8e80941Smrg } 147b8e80941Smrg 148b8e80941Smrg for (int i = 0; i < values.number_of_32_bit_output_buffer_address_following; i++) { 149b8e80941Smrg if (!reloc_mode) 150b8e80941Smrg v3d_print_group(clif, addr, 0, cl); 151b8e80941Smrg cl += v3d_group_get_length(addr); 152b8e80941Smrg *size += v3d_group_get_length(addr); 153b8e80941Smrg } 154b8e80941Smrg break; 155b8e80941Smrg } 156b8e80941Smrg#endif /* V3D_VERSION < 40 */ 157b8e80941Smrg 158b8e80941Smrg case V3DX(START_ADDRESS_OF_GENERIC_TILE_LIST_opcode): { 159b8e80941Smrg struct V3DX(START_ADDRESS_OF_GENERIC_TILE_LIST) values; 160b8e80941Smrg V3DX(START_ADDRESS_OF_GENERIC_TILE_LIST_unpack)(cl, &values); 161b8e80941Smrg struct reloc_worklist_entry *reloc = 162b8e80941Smrg clif_dump_add_address_to_worklist(clif, 163b8e80941Smrg reloc_generic_tile_list, 164b8e80941Smrg values.start); 165b8e80941Smrg reloc->generic_tile_list.end = values.end; 166b8e80941Smrg break; 167b8e80941Smrg } 168b8e80941Smrg 169b8e80941Smrg case V3DX(HALT_opcode): 170b8e80941Smrg return false; 171b8e80941Smrg } 172b8e80941Smrg 173b8e80941Smrg return true; 174b8e80941Smrg} 175