Permalink
Browse files

demmt: wrap object state

  • Loading branch information...
1 parent df13079 commit 3181550ae0f1d9dd74637cfa4013b06edea586ae @mslusarz mslusarz committed Jul 7, 2014
Showing with 33 additions and 26 deletions.
  1. +33 −26 rnn/demmt_objects.c
View
@@ -26,12 +26,6 @@
#include "dis.h"
#include <stdlib.h>
-static uint64_t code_address = 0;
-static struct buffer *code_buffer = NULL;
-static uint64_t m2mf_dest_address = 0;
-static struct buffer *m2mf_buffer = NULL;
-static int m2mf_data_cur_offset;
-
static struct buffer *find_buffer_by_gpu_address(uint64_t addr)
{
struct buffer *buf, *ret = NULL;
@@ -63,29 +57,35 @@ static struct buffer *find_buffer_by_gpu_address(uint64_t addr)
static const struct disisa *isa_nvc0 = NULL;
+static struct
+{
+ uint64_t code_address;
+ struct buffer *code_buffer;
+} nvc1_3d = { 0, NULL };
+
static void decode_nvc1_3d(int mthd, uint32_t data)
{
if (mthd == 0x1608) // CODE_ADDRESS_HIGH
{
mmt_debug("code address high: 0x%08x\n", data);
- code_address = ((uint64_t)data) << 32;
+ nvc1_3d.code_address = ((uint64_t)data) << 32;
}
else if (mthd == 0x160c) // CODE_ADDRESS_LOW
{
mmt_debug("code address low: 0x%08x\n", data);
- code_address |= data;
- code_buffer = find_buffer_by_gpu_address(code_address);
- mmt_debug("code address: 0x%08lx, buffer found: %d\n", code_address, code_buffer ? 1 : 0);
+ nvc1_3d.code_address |= data;
+ nvc1_3d.code_buffer = find_buffer_by_gpu_address(nvc1_3d.code_address);
+ mmt_debug("code address: 0x%08lx, buffer found: %d\n", nvc1_3d.code_address, nvc1_3d.code_buffer ? 1 : 0);
}
- else if (code_buffer && mthd >= 0x2000 && mthd < 0x2000 + 0x40 * 6 && (mthd & 0x4) == 4) // SP
+ else if (nvc1_3d.code_buffer && mthd >= 0x2000 && mthd < 0x2000 + 0x40 * 6 && (mthd & 0x4) == 4) // SP
{
int i;
for (i = 0; i < 6; ++i)
if (mthd == 0x2004 + i * 0x40) // SP[i].START_ID
{
mmt_debug("start id[%d]: 0x%08x\n", i, data);
struct region *reg;
- for (reg = code_buffer->written_regions; reg != NULL; reg = reg->next)
+ for (reg = nvc1_3d.code_buffer->written_regions; reg != NULL; reg = reg->next)
{
if (reg->start == data)
{
@@ -94,15 +94,15 @@ static void decode_nvc1_3d(int mthd, uint32_t data)
uint32_t x;
mmt_debug("CODE: %s\n", "");
for (x = reg->start + 20 * 4; x < reg->end; x += 4)
- mmt_debug("0x%08x ", *(uint32_t *)(code_buffer->data + x));
+ mmt_debug("0x%08x ", *(uint32_t *)(nvc1_3d.code_buffer->data + x));
mmt_debug("%s\n", "");
}
if (!isa_nvc0)
isa_nvc0 = ed_getisa("nvc0");
struct varinfo *var = varinfo_new(isa_nvc0->vardata);
- envydis(isa_nvc0, stdout, code_buffer->data + reg->start + 20 * 4, 0,
+ envydis(isa_nvc0, stdout, nvc1_3d.code_buffer->data + reg->start + 20 * 4, 0,
reg->end - reg->start - 20 * 4, var, 0, NULL, 0, colors);
varinfo_del(var);
break;
@@ -113,41 +113,48 @@ static void decode_nvc1_3d(int mthd, uint32_t data)
}
}
+static struct
+{
+ uint64_t offset_out;
+ struct buffer *offset_out_buffer;
+ int data_offset;
+} nvc0_m2mf = { 0, NULL, 0 };
+
static void decode_nvc0_m2mf(int mthd, uint32_t data)
{
if (mthd == 0x0238) // OFFSET_OUT_HIGH
{
mmt_debug("m2mf offset out high: 0x%08x\n", data);
- m2mf_dest_address = ((uint64_t)data) << 32;
- m2mf_buffer = NULL;
+ nvc0_m2mf.offset_out = ((uint64_t)data) << 32;
+ nvc0_m2mf.offset_out_buffer = NULL;
}
else if (mthd == 0x023c) // OFFSET_OUT_LOW
{
mmt_debug("m2mf offset out low: 0x%08x\n", data);
- m2mf_dest_address |= data;
+ nvc0_m2mf.offset_out |= data;
}
else if (mthd == 0x0300) // EXEC
{
int flags_ok = (data & 0x111) == 0x111 ? 1 : 0;
mmt_debug("m2mf exec: 0x%08x push&linear: %d\n", data, flags_ok);
if (flags_ok)
- m2mf_buffer = find_buffer_by_gpu_address(m2mf_dest_address);
+ nvc0_m2mf.offset_out_buffer = find_buffer_by_gpu_address(nvc0_m2mf.offset_out);
- if (!flags_ok || m2mf_buffer == NULL)
+ if (!flags_ok || nvc0_m2mf.offset_out_buffer == NULL)
{
- m2mf_dest_address = 0;
- m2mf_buffer = NULL;
+ nvc0_m2mf.offset_out = 0;
+ nvc0_m2mf.offset_out_buffer = NULL;
}
- if (m2mf_buffer)
- m2mf_data_cur_offset = m2mf_dest_address - m2mf_buffer->gpu_start;
+ if (nvc0_m2mf.offset_out_buffer)
+ nvc0_m2mf.data_offset = nvc0_m2mf.offset_out - nvc0_m2mf.offset_out_buffer->gpu_start;
}
else if (mthd == 0x0304) // DATA
{
mmt_debug("m2mf data: 0x%08x\n", data);
- if (m2mf_buffer)
+ if (nvc0_m2mf.offset_out_buffer)
{
- buffer_register_write(m2mf_buffer, m2mf_data_cur_offset, 4, &data);
- m2mf_data_cur_offset += 4;
+ buffer_register_write(nvc0_m2mf.offset_out_buffer, nvc0_m2mf.data_offset, 4, &data);
+ nvc0_m2mf.data_offset += 4;
}
}
}

0 comments on commit 3181550

Please sign in to comment.