asahi: Use common hexdump utility

We just moved it into common.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23088>
This commit is contained in:
Alyssa Rosenzweig 2023-05-17 17:29:59 -04:00 committed by Marge Bot
parent 016a04fcba
commit e5867b0dca
3 changed files with 16 additions and 70 deletions

View file

@ -14,8 +14,8 @@
#include <sys/mman.h>
#include <agx_pack.h>
#include "util/u_hexdump.h"
#include "decode.h"
#include "hexdump.h"
#ifdef __APPLE__
#include "agx_iokit.h"
#endif
@ -282,7 +282,7 @@ agxdecode_stateful(uint64_t va, const char *label, decode_cmd decoder,
/* If we fail to decode, default to a hexdump (don't hang) */
if (count == 0) {
hexdump(agxdecode_dump_stream, map, 8, false);
u_hexdump(agxdecode_dump_stream, map, 8, false);
count = 8;
}
@ -389,7 +389,7 @@ agxdecode_usc(const uint8_t *map, UNUSED uint64_t *link, UNUSED bool verbose,
DUMP_UNPACKED(USC_UNIFORM, temp, "Uniform\n");
uint8_t *raw = agxdecode_fetch_gpu_mem(temp.buffer, 2 * temp.size_halfs);
hexdump(agxdecode_dump_stream, raw, 2 * temp.size_halfs, false);
u_hexdump(agxdecode_dump_stream, raw, 2 * temp.size_halfs, false);
return AGX_USC_UNIFORM_LENGTH;
}
@ -401,7 +401,7 @@ agxdecode_usc(const uint8_t *map, UNUSED uint64_t *link, UNUSED bool verbose,
default:
fprintf(agxdecode_dump_stream, "Unknown USC control type: %u\n", type);
hexdump(agxdecode_dump_stream, map, 8, false);
u_hexdump(agxdecode_dump_stream, map, 8, false);
return 8;
}
@ -450,7 +450,7 @@ agxdecode_record(uint64_t va, size_t size, bool verbose)
if (frag.cf_bindings) {
uint8_t *cf = agxdecode_fetch_gpu_mem(frag.cf_bindings, 128);
hexdump(agxdecode_dump_stream, cf, 128, false);
u_hexdump(agxdecode_dump_stream, cf, 128, false);
DUMP_CL(CF_BINDING_HEADER, cf, "Coefficient binding header:");
cf += AGX_CF_BINDING_HEADER_LENGTH;
@ -538,7 +538,7 @@ agxdecode_cdm(const uint8_t *map, uint64_t *link, bool verbose,
default:
fprintf(agxdecode_dump_stream, "Unknown CDM block type: %u\n",
block_type);
hexdump(agxdecode_dump_stream, map, 8, false);
u_hexdump(agxdecode_dump_stream, map, 8, false);
return 8;
}
}
@ -653,7 +653,7 @@ agxdecode_vdm(const uint8_t *map, uint64_t *link, bool verbose,
default:
fprintf(agxdecode_dump_stream, "Unknown VDM block type: %u\n",
block_type);
hexdump(agxdecode_dump_stream, map, 8, false);
u_hexdump(agxdecode_dump_stream, map, 8, false);
return 8;
}
}
@ -764,8 +764,8 @@ agxdecode_dump_mappings(unsigned map_handle)
agx_alloc_types[mmap_array[i].type], mmap_array[i].ptr.gpu,
mmap_array[i].handle);
hexdump(agxdecode_dump_stream, mmap_array[i].ptr.cpu, mmap_array[i].size,
false);
u_hexdump(agxdecode_dump_stream, mmap_array[i].ptr.cpu,
mmap_array[i].size, false);
fprintf(agxdecode_dump_stream, "\n");
}
}

View file

@ -1,54 +0,0 @@
/*
* Copyright 2021 Alyssa Rosenzweig
* SPDX-License-Identifier: MIT
*/
#ifndef __HEXDUMP_H
#define __HEXDUMP_H
#include <stdbool.h>
static void
hexdump(FILE *fp, const uint8_t *hex, size_t cnt, bool with_strings)
{
for (unsigned i = 0; i < cnt; ++i) {
if ((i & 0xF) == 0)
fprintf(fp, "%06X ", i);
uint8_t v = hex[i];
if (v == 0 && (i & 0xF) == 0) {
/* Check if we're starting an aligned run of zeroes */
unsigned zero_count = 0;
for (unsigned j = i; j < cnt; ++j) {
if (hex[j] == 0)
zero_count++;
else
break;
}
if (zero_count >= 32) {
fprintf(fp, "*\n");
i += (zero_count & ~0xF) - 1;
continue;
}
}
fprintf(fp, "%02X ", hex[i]);
if ((i & 0xF) == 0xF && with_strings) {
fprintf(fp, " | ");
for (unsigned j = i & ~0xF; j <= i; ++j) {
uint8_t c = hex[j];
fputc((c < 32 || c > 128) ? '.' : c, fp);
}
}
if ((i & 0xF) == 0xF)
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
#endif

View file

@ -13,10 +13,10 @@
#include <mach/mach.h>
#include "util/compiler.h"
#include "util/u_hexdump.h"
#include "agx_iokit.h"
#include "decode.h"
#include "dyld_interpose.h"
#include "hexdump.h"
#include "util.h"
/*
@ -137,7 +137,7 @@ wrap_Method(mach_port_t connection, uint32_t selector, const uint64_t *input,
if (inputStructCnt) {
printf(", struct:\n");
hexdump(stdout, inputStruct, inputStructCnt, true);
u_hexdump(stdout, inputStruct, inputStructCnt, true);
} else {
printf("\n");
}
@ -241,12 +241,12 @@ wrap_Method(mach_port_t connection, uint32_t selector, const uint64_t *input,
if (outputStructCntP) {
printf(" struct\n");
hexdump(stdout, outputStruct, *outputStructCntP, true);
u_hexdump(stdout, outputStruct, *outputStructCntP, true);
if (selector == 2) {
/* Dump linked buffer as well */
void **o = outputStruct;
hexdump(stdout, *o, 64, true);
u_hexdump(stdout, *o, 64, true);
}
}
@ -279,7 +279,7 @@ wrap_AsyncMethod(mach_port_t connection, uint32_t selector,
if (inputStructCnt) {
printf(", struct:\n");
hexdump(stdout, inputStruct, inputStructCnt, true);
u_hexdump(stdout, inputStruct, inputStructCnt, true);
} else {
printf("\n");
}
@ -307,12 +307,12 @@ wrap_AsyncMethod(mach_port_t connection, uint32_t selector,
if (outputStructCntP) {
printf(" struct\n");
hexdump(stdout, outputStruct, *outputStructCntP, true);
u_hexdump(stdout, outputStruct, *outputStructCntP, true);
if (selector == 2) {
/* Dump linked buffer as well */
void **o = outputStruct;
hexdump(stdout, *o, 64, true);
u_hexdump(stdout, *o, 64, true);
}
}