[igt-dev] [PATCH i-g-t] tools/aubdump: dump 48-bit addresses
Scott D Phillips
scott.d.phillips at intel.com
Fri Mar 30 19:56:25 UTC 2018
For gen10+, write out PPGTT tables in aub files so that full
48-bit addresses can be serialized.
Signed-off-by: Scott D Phillips <scott.d.phillips at intel.com>
Cc: Jordan Justen <jordan.l.justen at intel.com>
---
lib/intel_aub.h | 3 +-
tools/aubdump.c | 276 +++++++++++++++++++++++++-------------------------------
2 files changed, 125 insertions(+), 154 deletions(-)
diff --git a/lib/intel_aub.h b/lib/intel_aub.h
index 9ca548ed..28885150 100644
--- a/lib/intel_aub.h
+++ b/lib/intel_aub.h
@@ -117,7 +117,8 @@
/* DW3 */
#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_MASK 0xf0000000
-#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL (1 << 28)
+#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT (0 << 28)
+#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_PHYSICAL (2 << 28)
#define AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT_ENTRY (4 << 28)
/**
diff --git a/tools/aubdump.c b/tools/aubdump.c
index 267061b0..78fda93c 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -56,6 +56,12 @@
_a < _b ? _a : _b; \
})
+#define max(a, b) ({ \
+ typeof(a) _a = (a); \
+ typeof(b) _b = (b); \
+ _a > _b ? _a : _b; \
+})
+
#define HWS_PGA_RCSUNIT 0x02080
#define HWS_PGA_VCSUNIT0 0x12080
#define HWS_PGA_BCSUNIT 0x22080
@@ -107,12 +113,14 @@
#define STATIC_GGTT_MAP_END (VIDEO_CONTEXT_ADDR + PPHWSP_SIZE + GEN8_LR_CONTEXT_OTHER_SIZE)
#define STATIC_GGTT_MAP_SIZE (STATIC_GGTT_MAP_END - STATIC_GGTT_MAP_START)
-#define CONTEXT_FLAGS (0x229) /* Normal Priority | L3-LLC Coherency |
- Legacy Context with no 64 bit VA support | Valid */
+#define PML4_PHYS_ADDR ((uint64_t)(STATIC_GGTT_MAP_END))
+
+#define CONTEXT_FLAGS (0x339) /* Normal Priority | L3-LLC Coherency |
+ PPGTT Enabled | Legacy Context with 64 bit VA support | Valid */
-#define RENDER_CONTEXT_DESCRIPTOR ((uint64_t)1 << 32 | RENDER_CONTEXT_ADDR | CONTEXT_FLAGS)
-#define BLITTER_CONTEXT_DESCRIPTOR ((uint64_t)2 << 32 | BLITTER_CONTEXT_ADDR | CONTEXT_FLAGS)
-#define VIDEO_CONTEXT_DESCRIPTOR ((uint64_t)3 << 32 | VIDEO_CONTEXT_ADDR | CONTEXT_FLAGS)
+#define RENDER_CONTEXT_DESCRIPTOR ((uint64_t)1 << 62 | RENDER_CONTEXT_ADDR | CONTEXT_FLAGS)
+#define BLITTER_CONTEXT_DESCRIPTOR ((uint64_t)2 << 62 | BLITTER_CONTEXT_ADDR | CONTEXT_FLAGS)
+#define VIDEO_CONTEXT_DESCRIPTOR ((uint64_t)3 << 62 | VIDEO_CONTEXT_ADDR | CONTEXT_FLAGS)
static const uint32_t render_context_init[GEN10_LR_CONTEXT_RENDER_SIZE /
sizeof(uint32_t)] = {
@@ -144,8 +152,8 @@ static const uint32_t render_context_init[GEN10_LR_CONTEXT_RENDER_SIZE /
0x2280 /* PDP2_LDW */, 0,
0x227C /* PDP1_UDW */, 0,
0x2278 /* PDP1_LDW */, 0,
- 0x2274 /* PDP0_UDW */, 0,
- 0x2270 /* PDP0_LDW */, 0,
+ 0x2274 /* PDP0_UDW */, PML4_PHYS_ADDR >> 32,
+ 0x2270 /* PDP0_LDW */, PML4_PHYS_ADDR,
/* MI_NOOP */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -182,8 +190,8 @@ static const uint32_t blitter_context_init[GEN8_LR_CONTEXT_OTHER_SIZE /
0x22280 /* PDP2_LDW */, 0,
0x2227C /* PDP1_UDW */, 0,
0x22278 /* PDP1_LDW */, 0,
- 0x22274 /* PDP0_UDW */, 0,
- 0x22270 /* PDP0_LDW */, 0,
+ 0x22274 /* PDP0_UDW */, PML4_PHYS_ADDR >> 32,
+ 0x22270 /* PDP0_LDW */, PML4_PHYS_ADDR,
/* MI_NOOP */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -217,8 +225,8 @@ static const uint32_t video_context_init[GEN8_LR_CONTEXT_OTHER_SIZE /
0x1C280 /* PDP2_LDW */, 0,
0x1C27C /* PDP1_UDW */, 0,
0x1C278 /* PDP1_LDW */, 0,
- 0x1C274 /* PDP0_UDW */, 0,
- 0x1C270 /* PDP0_LDW */, 0,
+ 0x1C274 /* PDP0_UDW */, PML4_PHYS_ADDR >> 32,
+ 0x1C270 /* PDP0_LDW */, PML4_PHYS_ADDR,
/* MI_NOOP */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -316,12 +324,6 @@ align_u32(uint32_t v, uint32_t a)
return (v + a - 1) & ~(a - 1);
}
-static inline uint64_t
-align_u64(uint64_t v, uint64_t a)
-{
- return (v + a - 1) & ~(a - 1);
-}
-
static void
dword_out(uint32_t data)
{
@@ -382,132 +384,101 @@ register_write_out(uint32_t addr, uint32_t value)
dword_out(value);
}
-static void
-gen8_emit_ggtt_pte_for_range(uint64_t start, uint64_t end)
-{
- uint64_t entry_addr;
- uint64_t page_num;
- uint64_t end_aligned = align_u64(end, 4096);
-
- if (start >= end || end > (1ull << 32))
- return;
-
- entry_addr = start & ~(4096 - 1);
- do {
- page_num = entry_addr >> 21;
- uint64_t last_page_entry =
- min((page_num + 1) << 21, end_aligned);
- uint64_t num_entries = (last_page_entry - entry_addr) >> 12;
- mem_trace_memory_write_header_out(
- entry_addr >> 9, num_entries * GEN8_PTE_SIZE,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT_ENTRY);
- while (num_entries-- > 0) {
- dword_out((entry_addr & ~(4096 - 1)) |
- 3 /* read/write | present */);
- dword_out(entry_addr >> 32);
- entry_addr += 4096;
- }
- } while (entry_addr < end);
-}
-
-/**
- * Sets bits `start` through `end` - 1 in the bitmap array.
- */
-static void
-set_bitmap_range(uint32_t *bitmap, uint32_t start, uint32_t end)
-{
- uint32_t pos = start;
- while (pos < end) {
- const uint32_t bit = 1 << (pos & 0x1f);
- if (bit == 1 && (end - pos) > 32) {
- bitmap[pos >> 5] = 0xffffffff;
- pos += 32;
- } else {
- bitmap[pos >> 5] |= bit;
- pos++;
- }
- }
-}
-
-/**
- * Finds the next `set` (or clear) bit in the bitmap array.
- *
- * The search starts at `*start` and only checks until `end` - 1.
- *
- * If found, returns true, and the found bit index in `*start`.
- */
-static bool
-find_bitmap_bit(uint32_t *bitmap, bool set, uint32_t *start, uint32_t end)
-{
- uint32_t pos = *start;
- const uint32_t neg_dw = set ? 0 : -1;
- while (pos < end) {
- const uint32_t dw = bitmap[pos >> 5];
- const uint32_t bit = 1 << (pos & 0x1f);
- if (!!(dw & bit) == set) {
- *start = pos;
- return true;
- } else if (bit == 1 && dw == neg_dw)
- pos += 32;
- else
- pos++;
- }
- return false;
-}
-
-/**
- * Finds a range of clear bits within the bitmap array.
- *
- * The search starts at `*start` and only checks until `*end` - 1.
- *
- * If found, returns true, and `*start` and `*end` are set for the
- * range of clear bits.
- */
-static bool
-find_bitmap_clear_bit_range(uint32_t *bitmap, uint32_t *start, uint32_t *end)
-{
- if (find_bitmap_bit(bitmap, false, start, *end)) {
- uint32_t found_end = *start;
- if (find_bitmap_bit(bitmap, true, &found_end, *end))
- *end = found_end;
- return true;
- }
- return false;
-}
-
-static void
-gen8_map_ggtt_range(uint64_t start, uint64_t end)
-{
- uint32_t pos1, pos2, end_pos;
- static uint32_t *bitmap = NULL;
- if (bitmap == NULL) {
- /* 4GiB (32-bits) of 4KiB pages (12-bits) in dwords (5-bits) */
- bitmap = calloc(1 << (32 - 12 - 5), sizeof(*bitmap));
- if (bitmap == NULL)
- return;
- }
-
- pos1 = start >> 12;
- end_pos = (end + 4096 - 1) >> 12;
- while (pos1 < end_pos) {
- pos2 = end_pos;
- if (!find_bitmap_clear_bit_range(bitmap, &pos1, &pos2))
- break;
-
- if (verbose)
- printf("MAPPING 0x%08lx-0x%08lx\n",
- (uint64_t)pos1 << 12, (uint64_t)pos2 << 12);
- gen8_emit_ggtt_pte_for_range((uint64_t)pos1 << 12,
- (uint64_t)pos2 << 12);
- set_bitmap_range(bitmap, (uint64_t)pos1, (uint64_t)pos2);
- pos1 = pos2;
- }
-}
-
-static void
-gen8_map_base_size(uint64_t base, uint64_t size)
-{
- gen8_map_ggtt_range(base, base + size);
-}
-
+static struct ppgtt_table {
+ uint64_t phys_addr;
+ struct ppgtt_table *subtables[512];
+} pml4 = {PML4_PHYS_ADDR};
+
+static void
+populate_ppgtt_table(struct ppgtt_table *table, int start, int end,
+ int level)
+{
+ static uint64_t phys_addrs_allocator = (PML4_PHYS_ADDR >> 12) + 1;
+ uint64_t entries[512] = {0};
+ int dirty_start = 512, dirty_end = 0;
+
+ for (int i = start; i < end; i++) {
+ if (!table->subtables[i]) {
+ dirty_start = min(dirty_start, i);
+ dirty_end = max(dirty_end, i + 1);
+ if (level == 1) {
+ table->subtables[i] =
+ (void *)(phys_addrs_allocator++ << 12);
+ } else {
+ table->subtables[i] =
+ calloc(1, sizeof(struct ppgtt_table));
+ table->subtables[i]->phys_addr =
+ phys_addrs_allocator++ << 12;
+ }
+ }
+ entries[i] = 3 /* read/write | present */ |
+ (level == 1 ? (uint64_t)table->subtables[i] :
+ table->subtables[i]->phys_addr);
+ }
+
+ if (dirty_start < dirty_end) {
+ uint64_t write_addr = table->phys_addr + dirty_start *
+ sizeof(uint64_t);
+ uint64_t write_size = (dirty_end - dirty_start) *
+ sizeof(uint64_t);
+ mem_trace_memory_write_header_out(write_addr, write_size,
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_PHYSICAL);
+ data_out(entries + dirty_start, write_size);
+ }
+}
+
+static void
+map_ppgtt(uint64_t start, uint64_t size)
+{
+ uint64_t l4_start = start & 0xff8000000000;
+ uint64_t l3_start = start & 0xffffc0000000;
+ uint64_t l2_start = start & 0xffffffe00000;
+ uint64_t l1_start = start & 0xfffffffff000;
+ uint64_t l4_end = (start + size + (1ULL << 39) - 1) & 0xff8000000000;
+ uint64_t l3_end = (start + size + (1ULL << 30) - 1) & 0xffffc0000000;
+ uint64_t l2_end = (start + size + (1ULL << 21) - 1) & 0xffffffe00000;
+ uint64_t l1_end = (start + size + (1ULL << 12) - 1) & 0xfffffffff000;
+
+#define L4_index(addr) (((addr) >> 39) & 0x1ff)
+#define L3_index(addr) (((addr) >> 30) & 0x1ff)
+#define L2_index(addr) (((addr) >> 21) & 0x1ff)
+#define L1_index(addr) (((addr) >> 12) & 0x1ff)
+
+#define L3_table(addr) (pml4.subtables[L4_index(addr)])
+#define L2_table(addr) (L3_table(addr)->subtables[L3_index(addr)])
+#define L1_table(addr) (L2_table(addr)->subtables[L2_index(addr)])
+
+ populate_ppgtt_table(&pml4, L4_index(l4_start), L4_index(l4_end), 4);
+
+ for (uint64_t a = l4_start; a < l4_end; a += (1ULL << 39)) {
+ uint64_t _start = max(a, l3_start);
+ uint64_t _end = min(a + (1ULL << 39), l3_end);
+
+ populate_ppgtt_table(L3_table(a), L3_index(_start),
+ L3_index(_end), 3);
+ }
+
+ for (uint64_t a = l3_start; a < l3_end; a += (1ULL << 30)) {
+ uint64_t _start = max(a, l2_start);
+ uint64_t _end = min(a + (1ULL << 30), l2_end);
+
+ populate_ppgtt_table(L2_table(a), L2_index(_start),
+ L2_index(_end), 2);
+ }
+
+ for (uint64_t a = l2_start; a < l2_end; a += (1ULL << 21)) {
+ uint64_t _start = max(a, l1_start);
+ uint64_t _end = min(a + (1ULL << 21), l1_end);
+
+ populate_ppgtt_table(L1_table(a), L1_index(_start),
+ L1_index(_end), 1);
+ }
+}
+
+static uint64_t
+ppgtt_lookup(uint64_t ppgtt_addr)
+{
+ return (uint64_t)L1_table(ppgtt_addr)->subtables[L1_index(ppgtt_addr)];
+}
+
static void
@@ -524,26 +495,33 @@ gen10_write_header(void)
dwords = 5 + app_name_len / sizeof(uint32_t);
dword_out(CMD_MEM_TRACE_VERSION | (dwords - 1));
dword_out(AUB_MEM_TRACE_VERSION_FILE_VERSION);
- dword_out(AUB_MEM_TRACE_VERSION_DEVICE_CNL |
- AUB_MEM_TRACE_VERSION_METHOD_PHY);
+ dword_out(AUB_MEM_TRACE_VERSION_DEVICE_CNL);
dword_out(0); /* version */
dword_out(0); /* version */
data_out(app_name, app_name_len);
+ /* GGTT PT */
+ uint32_t ggtt_ptes = STATIC_GGTT_MAP_SIZE >> 12;
+
+ mem_trace_memory_write_header_out(STATIC_GGTT_MAP_START >> 12,
+ ggtt_ptes * GEN8_PTE_SIZE,
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT_ENTRY);
+ for (uint32_t i = 0; i < ggtt_ptes; i++) {
+ dword_out(3 + 0x1000 * i + STATIC_GGTT_MAP_START);
+ dword_out(0);
+ }
+
/* RENDER_RING */
- gen8_map_base_size(RENDER_RING_ADDR, RING_SIZE);
mem_trace_memory_write_header_out(RENDER_RING_ADDR, RING_SIZE,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
for (uint32_t i = 0; i < RING_SIZE; i += sizeof(uint32_t))
dword_out(0);
/* RENDER_PPHWSP */
- gen8_map_base_size(RENDER_CONTEXT_ADDR,
- PPHWSP_SIZE + sizeof(render_context_init));
mem_trace_memory_write_header_out(RENDER_CONTEXT_ADDR,
PPHWSP_SIZE +
sizeof(render_context_init),
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
for (uint32_t i = 0; i < PPHWSP_SIZE; i += sizeof(uint32_t))
dword_out(0);
@@ -551,19 +529,16 @@ gen10_write_header(void)
data_out(render_context_init, sizeof(render_context_init));
/* BLITTER_RING */
- gen8_map_base_size(BLITTER_RING_ADDR, RING_SIZE);
mem_trace_memory_write_header_out(BLITTER_RING_ADDR, RING_SIZE,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
for (uint32_t i = 0; i < RING_SIZE; i += sizeof(uint32_t))
dword_out(0);
/* BLITTER_PPHWSP */
- gen8_map_base_size(BLITTER_CONTEXT_ADDR,
- PPHWSP_SIZE + sizeof(blitter_context_init));
mem_trace_memory_write_header_out(BLITTER_CONTEXT_ADDR,
PPHWSP_SIZE +
sizeof(blitter_context_init),
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
for (uint32_t i = 0; i < PPHWSP_SIZE; i += sizeof(uint32_t))
dword_out(0);
@@ -571,19 +546,16 @@ gen10_write_header(void)
data_out(blitter_context_init, sizeof(blitter_context_init));
/* VIDEO_RING */
- gen8_map_base_size(VIDEO_RING_ADDR, RING_SIZE);
mem_trace_memory_write_header_out(VIDEO_RING_ADDR, RING_SIZE,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
for (uint32_t i = 0; i < RING_SIZE; i += sizeof(uint32_t))
dword_out(0);
/* VIDEO_PPHWSP */
- gen8_map_base_size(VIDEO_CONTEXT_ADDR,
- PPHWSP_SIZE + sizeof(video_context_init));
mem_trace_memory_write_header_out(VIDEO_CONTEXT_ADDR,
PPHWSP_SIZE +
sizeof(video_context_init),
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
for (uint32_t i = 0; i < PPHWSP_SIZE; i += sizeof(uint32_t))
dword_out(0);
@@ -654,15 +626,13 @@ aub_write_trace_block(uint32_t type, void *virtual, uint32_t size, uint64_t gtt_
static const char null_block[8 * 4096];
for (uint32_t offset = 0; offset < size; offset += block_size) {
- block_size = size - offset;
-
- if (block_size > 8 * 4096)
- block_size = 8 * 4096;
+ block_size = min(8 * 4096, size - offset);
if (gen >= 10) {
- mem_trace_memory_write_header_out(gtt_offset + offset,
+ block_size = min(4096, block_size);
+ mem_trace_memory_write_header_out(ppgtt_lookup(gtt_offset + offset),
block_size,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_PHYSICAL);
} else {
dword_out(CMD_AUB_TRACE_HEADER_BLOCK |
((addr_bits > 32 ? 6 : 5) - 2));
@@ -750,17 +720,17 @@ aub_dump_execlist(uint64_t batch_offset, int ring_flag)
}
mem_trace_memory_write_header_out(ring_addr, 16,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
- dword_out(AUB_MI_BATCH_BUFFER_START | (3 - 2));
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
+ dword_out(AUB_MI_BATCH_BUFFER_START | /* ppgtt */ 0x100 | (3 - 2));
dword_out(batch_offset & 0xFFFFFFFF);
dword_out(batch_offset >> 32);
dword_out(0 /* MI_NOOP */);
mem_trace_memory_write_header_out(ring_addr + 8192 + 20, 4,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
dword_out(0); /* RING_BUFFER_HEAD */
mem_trace_memory_write_header_out(ring_addr + 8192 + 28, 4,
- AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_LOCAL);
+ AUB_MEM_TRACE_MEMORY_ADDRESS_SPACE_GGTT);
dword_out(16); /* RING_BUFFER_TAIL */
if (gen >= 11) {
@@ -936,7 +906,7 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
}
if (gen >= 10)
- offset = STATIC_GGTT_MAP_END;
+ offset = 0x1000;
else
offset = gtt_size();
@@ -976,7 +946,7 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
fail_if(bo->map == MAP_FAILED, "intel_aubdump: bo mmap failed\n");
if (gen >= 10)
- gen8_map_ggtt_range(bo->offset, bo->offset + bo->size);
+ map_ppgtt(bo->offset, bo->size);
}
batch_index = (execbuffer2->flags & I915_EXEC_BATCH_FIRST) ? 0 :
--
2.14.3
More information about the igt-dev
mailing list