2017-02-03 00:25:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2016 Broadcom
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "clif_dump.h"
|
2018-01-09 23:13:27 +00:00
|
|
|
#include "clif_private.h"
|
2017-02-03 00:25:12 +00:00
|
|
|
#include "util/list.h"
|
|
|
|
#include "util/ralloc.h"
|
|
|
|
|
|
|
|
#include "broadcom/cle/v3d_decoder.h"
|
|
|
|
|
2018-01-09 23:13:27 +00:00
|
|
|
struct reloc_worklist_entry *
|
2017-02-03 00:25:12 +00:00
|
|
|
clif_dump_add_address_to_worklist(struct clif_dump *clif,
|
|
|
|
enum reloc_worklist_type type,
|
|
|
|
uint32_t addr)
|
|
|
|
{
|
|
|
|
struct reloc_worklist_entry *entry =
|
|
|
|
rzalloc(clif, struct reloc_worklist_entry);
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
entry->type = type;
|
|
|
|
entry->addr = addr;
|
|
|
|
|
|
|
|
list_addtail(&entry->link, &clif->worklist);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct clif_dump *
|
|
|
|
clif_dump_init(const struct v3d_device_info *devinfo,
|
2018-07-30 19:29:26 +01:00
|
|
|
FILE *out, bool pretty)
|
2017-02-03 00:25:12 +00:00
|
|
|
{
|
|
|
|
struct clif_dump *clif = rzalloc(NULL, struct clif_dump);
|
|
|
|
|
|
|
|
clif->devinfo = devinfo;
|
|
|
|
clif->out = out;
|
|
|
|
clif->spec = v3d_spec_load(devinfo);
|
2018-07-30 19:29:26 +01:00
|
|
|
clif->pretty = pretty;
|
2017-02-03 00:25:12 +00:00
|
|
|
|
|
|
|
list_inithead(&clif->worklist);
|
|
|
|
|
|
|
|
return clif;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clif_dump_destroy(struct clif_dump *clif)
|
|
|
|
{
|
|
|
|
ralloc_free(clif);
|
|
|
|
}
|
|
|
|
|
2018-06-25 23:37:51 +01:00
|
|
|
struct clif_bo *
|
|
|
|
clif_lookup_bo(struct clif_dump *clif, uint32_t addr)
|
2018-06-25 22:58:15 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < clif->bo_count; i++) {
|
|
|
|
struct clif_bo *bo = &clif->bo[i];
|
|
|
|
|
|
|
|
if (addr >= bo->offset &&
|
|
|
|
addr < bo->offset + bo->size) {
|
2018-06-25 23:37:51 +01:00
|
|
|
return bo;
|
2018-06-25 22:58:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 23:37:51 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
clif_lookup_vaddr(struct clif_dump *clif, uint32_t addr, void **vaddr)
|
|
|
|
{
|
|
|
|
struct clif_bo *bo = clif_lookup_bo(clif, addr);
|
|
|
|
if (!bo)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*vaddr = bo->vaddr + addr - bo->offset;
|
|
|
|
return true;
|
2018-06-25 22:58:15 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:25:12 +00:00
|
|
|
#define out_uint(_clif, field) out(_clif, " /* %s = */ %u\n", \
|
|
|
|
#field, values-> field);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
clif_dump_packet(struct clif_dump *clif, uint32_t offset, const uint8_t *cl,
|
|
|
|
uint32_t *size)
|
|
|
|
{
|
2018-01-09 23:23:21 +00:00
|
|
|
if (clif->devinfo->ver >= 41)
|
|
|
|
return v3d41_clif_dump_packet(clif, offset, cl, size);
|
|
|
|
else
|
|
|
|
return v3d33_clif_dump_packet(clif, offset, cl, size);
|
2017-02-03 00:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-25 01:52:31 +01:00
|
|
|
clif_dump_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
|
2017-02-03 00:25:12 +00:00
|
|
|
{
|
2017-09-28 21:36:54 +01:00
|
|
|
void *start_vaddr;
|
2018-06-25 22:58:15 +01:00
|
|
|
if (!clif_lookup_vaddr(clif, start, &start_vaddr)) {
|
2017-02-03 00:25:12 +00:00
|
|
|
out(clif, "Failed to look up address 0x%08x\n",
|
2017-09-28 21:36:54 +01:00
|
|
|
start);
|
2017-02-03 00:25:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-28 21:36:54 +01:00
|
|
|
/* The end address is optional (for example, a BRANCH instruction
|
|
|
|
* won't set an end), but is used for BCL/RCL termination.
|
|
|
|
*/
|
|
|
|
void *end_vaddr = NULL;
|
2018-06-25 22:58:15 +01:00
|
|
|
if (end && !clif_lookup_vaddr(clif, end, &end_vaddr)) {
|
2017-09-28 21:36:54 +01:00
|
|
|
out(clif, "Failed to look up address 0x%08x\n",
|
|
|
|
end);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-26 21:04:09 +01:00
|
|
|
out(clif, "@format ctrllist\n");
|
|
|
|
|
2017-10-25 01:52:31 +01:00
|
|
|
uint32_t size;
|
2017-09-28 21:36:54 +01:00
|
|
|
uint8_t *cl = start_vaddr;
|
|
|
|
while (clif_dump_packet(clif, start, cl, &size)) {
|
2017-02-03 00:25:12 +00:00
|
|
|
cl += size;
|
2017-09-28 21:36:54 +01:00
|
|
|
start += size;
|
|
|
|
|
|
|
|
if (cl == end_vaddr)
|
|
|
|
break;
|
2017-02-03 00:25:12 +00:00
|
|
|
}
|
2017-10-25 01:52:31 +01:00
|
|
|
}
|
2017-02-03 00:25:12 +00:00
|
|
|
|
2018-06-28 20:33:43 +01:00
|
|
|
static void
|
|
|
|
clif_dump_gl_shader_state_record(struct clif_dump *clif,
|
|
|
|
struct reloc_worklist_entry *reloc,
|
|
|
|
void *vaddr)
|
|
|
|
{
|
|
|
|
struct v3d_group *state = v3d_spec_find_struct(clif->spec,
|
|
|
|
"GL Shader State Record");
|
|
|
|
struct v3d_group *attr = v3d_spec_find_struct(clif->spec,
|
|
|
|
"GL Shader State Attribute Record");
|
|
|
|
assert(state);
|
|
|
|
assert(attr);
|
|
|
|
|
2018-06-26 21:04:09 +01:00
|
|
|
out(clif, "@format shadrec_gl_main\n");
|
2018-06-25 23:18:51 +01:00
|
|
|
v3d_print_group(clif, state, 0, vaddr);
|
2018-06-28 20:33:43 +01:00
|
|
|
vaddr += v3d_group_get_length(state);
|
|
|
|
|
|
|
|
for (int i = 0; i < reloc->shader_state.num_attrs; i++) {
|
2018-06-26 21:04:09 +01:00
|
|
|
out(clif, "@format shadrec_gl_attr /* %d */\n", i);
|
2018-06-25 23:18:51 +01:00
|
|
|
v3d_print_group(clif, attr, 0, vaddr);
|
2018-06-28 20:33:43 +01:00
|
|
|
vaddr += v3d_group_get_length(attr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-25 01:52:31 +01:00
|
|
|
static void
|
|
|
|
clif_process_worklist(struct clif_dump *clif)
|
|
|
|
{
|
|
|
|
while (!list_empty(&clif->worklist)) {
|
|
|
|
struct reloc_worklist_entry *reloc =
|
|
|
|
list_first_entry(&clif->worklist,
|
|
|
|
struct reloc_worklist_entry, link);
|
|
|
|
list_del(&reloc->link);
|
|
|
|
|
|
|
|
void *vaddr;
|
2018-06-25 22:58:15 +01:00
|
|
|
if (!clif_lookup_vaddr(clif, reloc->addr, &vaddr)) {
|
2017-10-25 01:52:31 +01:00
|
|
|
out(clif, "Failed to look up address 0x%08x\n",
|
|
|
|
reloc->addr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (reloc->type) {
|
2018-06-25 23:02:26 +01:00
|
|
|
case reloc_cl:
|
|
|
|
clif_dump_cl(clif, reloc->addr, reloc->cl.end);
|
|
|
|
out(clif, "\n");
|
|
|
|
break;
|
|
|
|
|
2017-10-25 01:52:31 +01:00
|
|
|
case reloc_gl_shader_state:
|
2018-06-28 20:33:43 +01:00
|
|
|
clif_dump_gl_shader_state_record(clif,
|
|
|
|
reloc,
|
|
|
|
vaddr);
|
2017-10-25 01:52:31 +01:00
|
|
|
break;
|
2017-10-25 01:55:03 +01:00
|
|
|
case reloc_generic_tile_list:
|
|
|
|
clif_dump_cl(clif, reloc->addr,
|
|
|
|
reloc->generic_tile_list.end);
|
|
|
|
break;
|
2017-10-25 01:52:31 +01:00
|
|
|
}
|
|
|
|
out(clif, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 23:02:26 +01:00
|
|
|
void clif_dump(struct clif_dump *clif)
|
|
|
|
{
|
|
|
|
clif_process_worklist(clif);
|
|
|
|
}
|
|
|
|
|
2017-10-25 01:52:31 +01:00
|
|
|
void
|
|
|
|
clif_dump_add_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
|
|
|
|
{
|
2018-06-25 23:02:26 +01:00
|
|
|
struct reloc_worklist_entry *entry =
|
|
|
|
clif_dump_add_address_to_worklist(clif, reloc_cl, start);
|
2017-02-03 00:25:12 +00:00
|
|
|
|
2018-06-25 23:02:26 +01:00
|
|
|
entry->cl.end = end;
|
2017-02-03 00:25:12 +00:00
|
|
|
}
|
2018-06-25 22:58:15 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
clif_dump_add_bo(struct clif_dump *clif, const char *name,
|
|
|
|
uint32_t offset, uint32_t size, void *vaddr)
|
|
|
|
{
|
|
|
|
if (clif->bo_count >= clif->bo_array_size) {
|
|
|
|
clif->bo_array_size = MAX2(4, clif->bo_array_size * 2);
|
|
|
|
clif->bo = reralloc(clif, clif->bo, struct clif_bo,
|
|
|
|
clif->bo_array_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
clif->bo[clif->bo_count].name = ralloc_strdup(clif, name);
|
|
|
|
clif->bo[clif->bo_count].offset = offset;
|
|
|
|
clif->bo[clif->bo_count].size = size;
|
|
|
|
clif->bo[clif->bo_count].vaddr = vaddr;
|
|
|
|
clif->bo_count++;
|
|
|
|
}
|