nouveau: mme: Add a dumper

Signed-off-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27126>
This commit is contained in:
Mary Guillemard 2023-10-18 19:11:16 +02:00 committed by Marge Bot
parent cb6d954c67
commit 531505f8c5
2 changed files with 78 additions and 0 deletions

View file

@ -81,3 +81,11 @@ if with_tests and not with_platform_android
install : true,
)
endif
executable(
'nv_mme_dump',
'nv_mme_dump.c',
dependencies : [ idep_mesautil, idep_nouveau_mme ],
build_by_default : with_tools.contains('nouveau'),
install : with_tools.contains('nouveau'),
)

View file

@ -0,0 +1,70 @@
/*
* Copyright © 2023 Collabora Ltd. and Red Hat Inc.
* SPDX-License-Identifier: MIT
*/
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mme_fermi.h"
#include "mme_tu104.h"
int main(int argc, char **argv) {
const char *arch_name;
const char *file_name;
FILE *file;
long file_size;
uint32_t *data;
if (argc != 3) {
fprintf(stderr, "Usage: nv_mme_dump file.bin "
"<FERMI|TURING>\n");
return 1;
}
file_name = argv[1];
arch_name = argv[2];
file = fopen(file_name, "r");
if (file == NULL) {
fprintf(stderr, "couldn't open file \"%s\"\n", file_name);
return 1;
}
fseek(file, 0L, SEEK_END);
file_size = ftell(file);
fseek(file, 0L, SEEK_SET);
if (file_size % 4 != 0) {
fclose(file);
fprintf(stderr, "invalid file, data isn't aligned to 4 bytes\n");
return 1;
}
data = malloc(file_size);
if (data == NULL) {
fclose(file);
fprintf(stderr, "memory allocation failed\n");
return 1;
}
fread(data, file_size, 1, file);
fclose(file);
if (!strcmp(arch_name, "FERMI")) {
mme_fermi_dump(stdout, data, file_size);
} else {
mme_tu104_dump(stdout, data, file_size);
}
free(data);
return 0;
}