From 52d2d4ae2c59b6ae5abbbb0b9053eb1500b56c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Thu, 11 Apr 2024 12:04:15 -0700 Subject: [PATCH] intel/tools/error2hangdump: Move code that will be shared with Xe parser to error2hangdump_lib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No changes in behavior expected here. Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/tools/error2hangdump.c | 87 +--------------------------- src/intel/tools/error2hangdump_lib.c | 69 ++++++++++++++++++++++ src/intel/tools/error2hangdump_lib.h | 39 +++++++++++++ src/intel/tools/meson.build | 2 + 4 files changed, 111 insertions(+), 86 deletions(-) create mode 100644 src/intel/tools/error2hangdump_lib.c create mode 100644 src/intel/tools/error2hangdump_lib.h diff --git a/src/intel/tools/error2hangdump.c b/src/intel/tools/error2hangdump.c index 5ea0375d1be4b..947d6c4da2eba 100644 --- a/src/intel/tools/error2hangdump.c +++ b/src/intel/tools/error2hangdump.c @@ -34,34 +34,10 @@ #include "util/list.h" -#include "common/intel_hang_dump.h" - #include "error_decode_lib.h" +#include "error2hangdump_lib.h" #include "intel/dev/intel_device_info.h" -static inline void -_fail(const char *prefix, const char *format, ...) -{ - va_list args; - - va_start(args, format); - if (prefix) - fprintf(stderr, "%s: ", prefix); - vfprintf(stderr, format, args); - va_end(args); - - abort(); -} - -#define _fail_if(cond, prefix, ...) do { \ - if (cond) \ - _fail(prefix, __VA_ARGS__); \ -} while (0) - -#define fail_if(cond, ...) _fail_if(cond, NULL, __VA_ARGS__) - -#define fail(...) fail_if(true, __VA_ARGS__) - static int zlib_inflate(uint32_t **ptr, int len) { struct z_stream_s zstream; @@ -234,67 +210,6 @@ engine_from_name(const char *engine_name, fail("Unknown engine %s\n", engine_name); } -static void -write_header(FILE *f) -{ - struct intel_hang_dump_block_header header = { - .base = { - .type = INTEL_HANG_DUMP_BLOCK_TYPE_HEADER, - }, - .magic = INTEL_HANG_DUMP_MAGIC, - .version = INTEL_HANG_DUMP_VERSION, - }; - - fwrite(&header, sizeof(header), 1, f); -} - -static void -write_buffer(FILE *f, - uint64_t offset, - const void *data, - uint64_t size, - const char *name) -{ - struct intel_hang_dump_block_bo header = { - .base = { - .type = INTEL_HANG_DUMP_BLOCK_TYPE_BO, - }, - .offset = offset, - .size = size, - }; - snprintf(header.name, sizeof(header.name), "%s", name); - - fwrite(&header, sizeof(header), 1, f); - fwrite(data, size, 1, f); -} - -static void -write_hw_image_buffer(FILE *f, const void *data, uint64_t size) -{ - struct intel_hang_dump_block_hw_image header = { - .base = { - .type = INTEL_HANG_DUMP_BLOCK_TYPE_HW_IMAGE, - }, - .size = size, - }; - - fwrite(&header, sizeof(header), 1, f); - fwrite(data, size, 1, f); -} - -static void -write_exec(FILE *f, uint64_t offset) -{ - struct intel_hang_dump_block_exec header = { - .base = { - .type = INTEL_HANG_DUMP_BLOCK_TYPE_EXEC, - }, - .offset = offset, - }; - - fwrite(&header, sizeof(header), 1, f); -} - int main(int argc, char *argv[]) { diff --git a/src/intel/tools/error2hangdump_lib.c b/src/intel/tools/error2hangdump_lib.c new file mode 100644 index 0000000000000..055856ba3e154 --- /dev/null +++ b/src/intel/tools/error2hangdump_lib.c @@ -0,0 +1,69 @@ +/* + * Copyright 2024 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "error2hangdump_lib.h" + +#include "common/intel_hang_dump.h" + +void +write_header(FILE *f) +{ + struct intel_hang_dump_block_header header = { + .base = { + .type = INTEL_HANG_DUMP_BLOCK_TYPE_HEADER, + }, + .magic = INTEL_HANG_DUMP_MAGIC, + .version = INTEL_HANG_DUMP_VERSION, + }; + + fwrite(&header, sizeof(header), 1, f); +} + +void +write_buffer(FILE *f, + uint64_t offset, + const void *data, + uint64_t size, + const char *name) +{ + struct intel_hang_dump_block_bo header = { + .base = { + .type = INTEL_HANG_DUMP_BLOCK_TYPE_BO, + }, + .offset = offset, + .size = size, + }; + snprintf(header.name, sizeof(header.name), "%s", name); + + fwrite(&header, sizeof(header), 1, f); + fwrite(data, size, 1, f); +} + +void +write_hw_image_buffer(FILE *f, const void *data, uint64_t size) +{ + struct intel_hang_dump_block_hw_image header = { + .base = { + .type = INTEL_HANG_DUMP_BLOCK_TYPE_HW_IMAGE, + }, + .size = size, + }; + + fwrite(&header, sizeof(header), 1, f); + fwrite(data, size, 1, f); +} + +void +write_exec(FILE *f, uint64_t offset) +{ + struct intel_hang_dump_block_exec header = { + .base = { + .type = INTEL_HANG_DUMP_BLOCK_TYPE_EXEC, + }, + .offset = offset, + }; + + fwrite(&header, sizeof(header), 1, f); +} diff --git a/src/intel/tools/error2hangdump_lib.h b/src/intel/tools/error2hangdump_lib.h new file mode 100644 index 0000000000000..33ead7ae7da31 --- /dev/null +++ b/src/intel/tools/error2hangdump_lib.h @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include +#include + +static inline void +_fail(const char *prefix, const char *format, ...) +{ + va_list args; + + va_start(args, format); + if (prefix) + fprintf(stderr, "%s: ", prefix); + vfprintf(stderr, format, args); + va_end(args); + + abort(); +} + +#define _fail_if(cond, prefix, ...) do { \ + if (cond) \ + _fail(prefix, __VA_ARGS__); \ +} while (0) + +#define fail_if(cond, ...) _fail_if(cond, NULL, __VA_ARGS__) + +#define fail(...) fail_if(true, __VA_ARGS__) + +void write_header(FILE *f); +void write_buffer(FILE *f, uint64_t offset, const void *data, uint64_t size, const char *name); +void write_hw_image_buffer(FILE *f, const void *data, uint64_t size); +void write_exec(FILE *f, uint64_t offset); diff --git a/src/intel/tools/meson.build b/src/intel/tools/meson.build index fd8b9a59fd1e8..5baa131850360 100644 --- a/src/intel/tools/meson.build +++ b/src/intel/tools/meson.build @@ -80,6 +80,8 @@ error2aub = executable( error2hangdump = executable( 'intel_error2hangdump', files('error2hangdump.c', + 'error2hangdump_lib.c', + 'error2hangdump_lib.h', 'error_decode_lib.c', 'error_decode_lib.h'), dependencies : [dep_zlib, dep_dl, dep_thread, dep_m, idep_intel_dev],