From: Alyssa Rosenzweig Date: Sat, 10 Jul 2021 16:05:34 +0000 (-0400) Subject: asahi: Identify more unknown fields in the memmap X-Git-Tag: upstream/21.2.3~609 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5580ee805a8790cf1f2e44898d188b6ff9d3402;p=platform%2Fupstream%2Fmesa.git asahi: Identify more unknown fields in the memmap From validating the memory map of a Metal sample and seeing what goes wrong. Signed-off-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index e2f1ad9..a9fabdf 100644 --- a/src/asahi/lib/decode.c +++ b/src/asahi/lib/decode.c @@ -101,43 +101,68 @@ agxdecode_find_handle(unsigned handle, unsigned type) } static void +agxdecode_mark_mapped(unsigned handle) +{ + struct agx_bo *bo = agxdecode_find_handle(handle, AGX_ALLOC_REGULAR); + + if (!bo) { + fprintf(stderr, "ERROR - unknown BO mapped with handle %u\n", handle); + return; + } + + /* Mark mapped for future consumption */ + bo->mapped = true; +} + +static void agxdecode_validate_map(void *map) { + unsigned nr_handles = 0; + /* First, mark everything unmapped */ for (unsigned i = 0; i < mmap_count; ++i) mmap_array[i].mapped = false; /* Check the header */ struct agx_map_header *hdr = map; - if (hdr->nr_entries_1 == 0) { + if (hdr->nr_entries == 0) { fprintf(stderr, "ERROR - empty map\n"); return; } - if (hdr->nr_entries_1 != hdr->nr_entries_2) { - fprintf(stderr, "WARN - mismatched map %u vs %u\n", hdr->nr_entries_1, hdr->nr_entries_2); + for (unsigned i = 0; i < 6; ++i) { + unsigned handle = hdr->indices[i]; + if (handle) { + agxdecode_mark_mapped(handle); + nr_handles++; + } } /* Check the entries */ struct agx_map_entry *entries = (struct agx_map_entry *) (&hdr[1]); - for (unsigned i = 0; i < hdr->nr_entries_1 - 1; ++i) { + for (unsigned i = 0; i < hdr->nr_entries - 1; ++i) { struct agx_map_entry entry = entries[i]; - struct agx_bo *bo = agxdecode_find_handle(entry.index, AGX_ALLOC_REGULAR); - - if (!bo) { - fprintf(stderr, "ERROR - unknown BO mapped with handle %u\n", entry.index); - continue; + + for (unsigned j = 0; j < 6; ++j) { + unsigned handle = entry.indices[j]; + if (handle) { + agxdecode_mark_mapped(handle); + nr_handles++; + } } - - /* Mark mapped for future consumption */ - bo->mapped = true; } /* Check the sentinel */ - if (entries[hdr->nr_entries_1 - 1].index) { - fprintf(stderr, "ERROR - last entry nonzero %u\n", entries[hdr->nr_entries_1 - 1].index); + if (entries[hdr->nr_entries - 1].indices[0]) { + fprintf(stderr, "ERROR - last entry nonzero %u\n", entries[hdr->nr_entries - 1].indices[0]); return; } + + /* Check the handle count */ + if (nr_handles != hdr->nr_handles) { + fprintf(stderr, "ERROR - wrong handle count, got %u, expected %u\n", + nr_handles, hdr->nr_handles); + } } static inline void * diff --git a/src/asahi/lib/io.h b/src/asahi/lib/io.h index f9b8832..a5086b1 100644 --- a/src/asahi/lib/io.h +++ b/src/asahi/lib/io.h @@ -192,10 +192,9 @@ struct agx_map_header { uint64_t encoder_id; // GUID uint32_t unk6; // 00 00 00 00 uint32_t cmdbuf_size; - uint32_t nr_entries_1; - uint32_t nr_entries_2; - uint32_t unka; // 0b 00 00 00 - uint32_t padding[5]; + uint32_t nr_handles; + uint32_t nr_entries; + uint32_t indices[6]; } __attribute__((packed)); struct agx_map_entry { @@ -209,8 +208,7 @@ struct agx_map_entry { uint32_t unk8; // 00 00 00 00 uint32_t unk9; // 00 00 00 00 uint32_t unka; // ff ff 01 00 - uint32_t index; - uint32_t padding[5]; + uint32_t indices[6]; } __attribute__((packed)); #endif diff --git a/src/gallium/drivers/asahi/magic.c b/src/gallium/drivers/asahi/magic.c index af8dd6e..6d4b75f 100644 --- a/src/gallium/drivers/asahi/magic.c +++ b/src/gallium/drivers/asahi/magic.c @@ -269,9 +269,9 @@ demo_map_header(uint64_t cmdbuf_id, uint64_t encoder_id, unsigned cmdbuf_size, u .cmdbuf_size = cmdbuf_size, /* +1 for the sentinel ending */ - .nr_entries_1 = count + 1, - .nr_entries_2 = count + 1, - .unka = 0x0b, + .nr_entries = count + 1, + .nr_handles = count + 1, + .indices = {0x0b}, }; } @@ -293,7 +293,7 @@ demo_mem_map(void *map, size_t size, unsigned *handles, unsigned count, .unkAAA = 0x20, .unkBBB = 0x1, .unka = 0x1ffff, - .index = handles[i] + .indices = {handles[i]} }; } @@ -303,6 +303,5 @@ demo_mem_map(void *map, size_t size, unsigned *handles, unsigned count, .unkAAA = 0x40, .unkBBB = 0x1, .unka = 0x1ffff, - .index = 0 }; }