Skip to content

Commit

Permalink
demmt: add basic nouveau ioctl parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mslusarz committed Jul 13, 2014
1 parent 4f96b5f commit 805e695
Show file tree
Hide file tree
Showing 5 changed files with 452 additions and 9 deletions.
11 changes: 10 additions & 1 deletion rnn/CMakeLists.txt
Expand Up @@ -21,7 +21,16 @@ add_executable(dedma dedma.c dedma_cache.c dedma_back.c)
add_executable(lookup lookup.c) add_executable(lookup lookup.c)
add_executable(rnncheck rnncheck.c) add_executable(rnncheck rnncheck.c)
add_executable(mmt_bin2dedma mmt_bin2dedma.c mmt_bin2dedma_nvidia.c mmt_bin_decode.c mmt_bin_decode_nvidia.c) add_executable(mmt_bin2dedma mmt_bin2dedma.c mmt_bin2dedma_nvidia.c mmt_bin_decode.c mmt_bin_decode_nvidia.c)
add_executable(demmt demmt.c mmt_bin_decode.c mmt_bin_decode_nvidia.c demmt_pushbuf.c demmt_objects.c) add_executable(demmt demmt.c mmt_bin_decode.c mmt_bin_decode_nvidia.c demmt_pushbuf.c demmt_objects.c demmt_drm.c)

find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_LIBDRM_NV libdrm_nouveau)
if (PC_LIBDRM_NV_FOUND)
include_directories(${PC_LIBDRM_NV_INCLUDE_DIRS})
add_definitions(-DLIBDRM_AVAILABLE)
else (PC_LIBDRM_NV_FOUND)
message("Warning: demmt won't parse nouveau ioctls because libdrm_nouveau was not found")
endif (PC_LIBDRM_NV_FOUND)


target_link_libraries(rnn ${LIBXML2_LIBRARIES} envyutil) target_link_libraries(rnn ${LIBXML2_LIBRARIES} envyutil)
target_link_libraries(demmio envy nvhw rnn seq) target_link_libraries(demmio envy nvhw rnn seq)
Expand Down
61 changes: 53 additions & 8 deletions rnn/demmt.c
Expand Up @@ -31,8 +31,9 @@
#include "mmt_bin_decode.h" #include "mmt_bin_decode.h"
#include "mmt_bin_decode_nvidia.h" #include "mmt_bin_decode_nvidia.h"
#include "demmt.h" #include "demmt.h"
#include "demmt_pushbuf.h" #include "demmt_drm.h"
#include "demmt_objects.h" #include "demmt_objects.h"
#include "demmt_pushbuf.h"
#include "rnndec.h" #include "rnndec.h"
#include "util.h" #include "util.h"


Expand Down Expand Up @@ -828,31 +829,75 @@ static void ioctl_data_print(struct mmt_buf *data)
mmt_log_cont(" 0x%08x", ((uint32_t *)data->data)[i]); mmt_log_cont(" 0x%08x", ((uint32_t *)data->data)[i]);
} }


static void decode_ioctl_id(uint32_t id, uint8_t *dir, uint8_t *type, uint8_t *nr, uint16_t *size)
{
*nr = id & 0x000000ff;
*type = (id & 0x0000ff00) >> 8;
*size = (id & 0x3fff0000) >> 16;
*dir = (id & 0xc0000000) >> 30;
}

static char *dir_desc[] = { "?", "w", "r", "rw" };

static void demmt_nv_ioctl_pre(struct mmt_nvidia_ioctl_pre *ctl, void *state) static void demmt_nv_ioctl_pre(struct mmt_nvidia_ioctl_pre *ctl, void *state)
{ {
mmt_log("ioctl pre 0x%02x (0x%08x)", ctl->id & 0xff, ctl->id); uint8_t dir, type, nr;
ioctl_data_print(&ctl->data); uint16_t size;
decode_ioctl_id(ctl->id, &dir, &type, &nr, &size);
int print_raw = 1;

if (type == 0x64) // DRM
print_raw = demmt_drm_ioctl_pre(dir, nr, size, &ctl->data, state);
else if (type == 0x46) // nvidia
{ }
print_raw = print_raw || dump_ioctls;

if (print_raw)
{
mmt_log("ioctl pre 0x%02x (0x%08x), dir: %2s, size: %4d", nr, ctl->id, dir_desc[dir], size);
if (size != ctl->data.len)
mmt_log_cont(", data.len: %d", ctl->data.len);

ioctl_data_print(&ctl->data);
}

if (1) if (1)
{ {
if (wreg_count) if (wreg_count)
{ {
mmt_log_cont(", flushing buffered writes%s\n", ""); if (print_raw)
mmt_log_cont(", flushing buffered writes%s\n", "");
else
mmt_log("flushing buffered writes%s\n", "");
dump_buffered_writes(1); dump_buffered_writes(1);
clear_buffered_writes(); clear_buffered_writes();
mmt_log("%s\n", ""); mmt_log("%s\n", "");
} }
else else if (print_raw)
mmt_log_cont(", no dirty buffers%s\n", ""); mmt_log_cont(", no dirty buffers%s\n", "");
} }
else else if (print_raw)
mmt_log_cont("%s\n", ""); mmt_log_cont("%s\n", "");
} }


static void demmt_nv_ioctl_post(struct mmt_nvidia_ioctl_post *ctl, void *state) static void demmt_nv_ioctl_post(struct mmt_nvidia_ioctl_post *ctl, void *state)
{ {
if (dump_ioctls) uint8_t dir, type, nr;
uint16_t size;
decode_ioctl_id(ctl->id, &dir, &type, &nr, &size);
int print_raw = 0;

if (type == 0x64) // DRM
print_raw = demmt_drm_ioctl_post(dir, nr, size, &ctl->data, state);
else if (type == 0x46) // nvidia
{ }
print_raw = print_raw || dump_ioctls;

if (print_raw)
{ {
mmt_log("ioctl post 0x%02x (0x%08x)", ctl->id & 0xff, ctl->id); mmt_log("ioctl post 0x%02x (0x%08x), dir: %2s, size: %4d", nr, ctl->id, dir_desc[dir], size);
if (size != ctl->data.len)
mmt_log_cont(", data.len: %d", ctl->data.len);
ioctl_data_print(&ctl->data); ioctl_data_print(&ctl->data);
mmt_log_cont("%s\n", ""); mmt_log_cont("%s\n", "");
} }
Expand Down
1 change: 1 addition & 0 deletions rnn/demmt.h
Expand Up @@ -9,6 +9,7 @@ extern int quiet;
extern int disassemble_shaders; extern int disassemble_shaders;
extern const struct envy_colors *colors; extern const struct envy_colors *colors;


#include <stdio.h>
#define mmt_debug(fmt, ...) do { if (MMT_DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0) #define mmt_debug(fmt, ...) do { if (MMT_DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
#define mmt_log(fmt, ...) do { if (!find_pb_pointer && !quiet) fprintf(stdout, "%64s" fmt, " ", __VA_ARGS__); } while (0) #define mmt_log(fmt, ...) do { if (!find_pb_pointer && !quiet) fprintf(stdout, "%64s" fmt, " ", __VA_ARGS__); } while (0)
#define mmt_log_cont(fmt, ...) do { if (!find_pb_pointer && !quiet) fprintf(stdout, fmt, __VA_ARGS__); } while (0) #define mmt_log_cont(fmt, ...) do { if (!find_pb_pointer && !quiet) fprintf(stdout, fmt, __VA_ARGS__); } while (0)
Expand Down

0 comments on commit 805e695

Please sign in to comment.