From 7eeb781c8bbc2ba84bc3a040d20e054cb3c2bfb4 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Thu, 28 Mar 2024 18:01:20 +0100 Subject: [PATCH] ir3-disasm: add options to specify GPU by chip ID or name Signed-off-by: Job Noorman Part-of: --- src/freedreno/common/freedreno_dev_info.c | 12 +++++ src/freedreno/common/freedreno_dev_info.h | 2 + src/freedreno/common/meson.build | 1 + src/freedreno/isa/ir3-disasm.c | 61 ++++++++++++++++++++++- src/freedreno/isa/meson.build | 2 +- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/freedreno/common/freedreno_dev_info.c b/src/freedreno/common/freedreno_dev_info.c index cb30c962f53..79d1a8b9b0a 100644 --- a/src/freedreno/common/freedreno_dev_info.c +++ b/src/freedreno/common/freedreno_dev_info.c @@ -106,6 +106,18 @@ fd_dev_info(const struct fd_dev_id *id) return modified; } +const struct fd_dev_info * +fd_dev_info_raw_by_name(const char *name) +{ + for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) { + if (!strcmp(fd_dev_recs[i].name, name)) { + return fd_dev_recs[i].info; + } + } + + return NULL; +} + const char * fd_dev_name(const struct fd_dev_id *id) { diff --git a/src/freedreno/common/freedreno_dev_info.h b/src/freedreno/common/freedreno_dev_info.h index 6697867959c..d5e5cbb694b 100644 --- a/src/freedreno/common/freedreno_dev_info.h +++ b/src/freedreno/common/freedreno_dev_info.h @@ -269,6 +269,8 @@ const struct fd_dev_info *fd_dev_info_raw(const struct fd_dev_id *id); /* Final dev info with dbg options and everything else applied. */ const struct fd_dev_info fd_dev_info(const struct fd_dev_id *id); +const struct fd_dev_info *fd_dev_info_raw_by_name(const char *name); + static uint8_t fd_dev_gen(const struct fd_dev_id *id) { diff --git a/src/freedreno/common/meson.build b/src/freedreno/common/meson.build index 20a54e0adf9..183e1b5d13c 100644 --- a/src/freedreno/common/meson.build +++ b/src/freedreno/common/meson.build @@ -56,4 +56,5 @@ libfreedreno_common = static_library( idep_libfreedreno_common = declare_dependency( link_with: [libfreedreno_common], + include_directories : [inc_freedreno, inc_include, inc_src], ) diff --git a/src/freedreno/isa/ir3-disasm.c b/src/freedreno/isa/ir3-disasm.c index f95e768aec9..ed78580f0b6 100644 --- a/src/freedreno/isa/ir3-disasm.c +++ b/src/freedreno/isa/ir3-disasm.c @@ -21,11 +21,15 @@ * SOFTWARE. */ +#include #include #include +#include +#include #include "util/os_file.h" +#include "freedreno_dev_info.h" #include "ir3-isa.h" static void @@ -35,17 +39,72 @@ disasm_instr_cb(void *d, unsigned n, void *instr) printf("%3d[%08x_%08x] ", n, dwords[1], dwords[0]); } +static void +usage(const char *prog) +{ + fprintf(stderr, + "Usage: %s [-g GPU_ID | -c CHIP_ID] FILE\n" + " -g GPU_ID: specify GPU ID\n" + " -c CHIP_ID: specify GPU chip ID in hex\n", + prog); +} + int main(int argc, char **argv) { size_t sz; - void *raw = os_read_file(argv[1], &sz); + void *raw = NULL; + const struct fd_dev_info *info = NULL; + int opt; + + while ((opt = getopt(argc, argv, "g:c:")) != -1) { + switch (opt) { + case 'g': + info = fd_dev_info_raw_by_name(optarg); + if (!info) { + fprintf(stderr, "Unknown GPU name: %s\n", optarg); + usage(argv[0]); + return EXIT_FAILURE; + } + break; + case 'c': { + uint64_t chip_id; + if (sscanf(optarg, "%" PRIx64, &chip_id) != 1) { + fprintf(stderr, "Invalid chip ID: %s\n", optarg); + usage(argv[0]); + return EXIT_FAILURE; + } + + struct fd_dev_id id = {.chip_id = chip_id}; + info = fd_dev_info_raw(&id); + if (!info) { + fprintf(stderr, "Unknown chip ID: %s\n", optarg); + usage(argv[0]); + return EXIT_FAILURE; + } + break; + } + default: + usage(argv[0]); + return EXIT_FAILURE; + } + } + + if (optind >= argc) { + fprintf(stderr, "No file specified\n"); + usage(argv[0]); + return EXIT_FAILURE; + } + + raw = os_read_file(argv[optind], &sz); + unsigned chip = info ? info->chip : 7; ir3_isa_disasm(raw, sz, stdout, &(struct isa_decode_options){ .show_errors = true, .branch_labels = true, .pre_instr_cb = disasm_instr_cb, + .gpu_id = chip * 100, }); return 0; diff --git a/src/freedreno/isa/meson.build b/src/freedreno/isa/meson.build index 9f49d948337..c363dc47094 100644 --- a/src/freedreno/isa/meson.build +++ b/src/freedreno/isa/meson.build @@ -73,7 +73,7 @@ idep_libir3decode = declare_dependency( ir3disasm = executable( 'ir3-disasm', ['ir3-disasm.c'], - dependencies: [idep_libir3decode], + dependencies: [idep_libir3decode, idep_libfreedreno_common], build_by_default: with_tools.contains('freedreno'), include_directories: [ inc_src,