diff options
author | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2021-07-10 12:05:34 -0400 |
---|---|---|
committer | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2021-07-10 12:05:34 -0400 |
commit | d5580ee805a8790cf1f2e44898d188b6ff9d3402 (patch) | |
tree | bf6651ac10d6d3e9133de179531e658713cd16af /src/asahi | |
parent | 0eb4a4dd7950c98e1d6fa102c366a48e042ed427 (diff) |
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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11815>
Diffstat (limited to 'src/asahi')
-rw-r--r-- | src/asahi/lib/decode.c | 53 | ||||
-rw-r--r-- | src/asahi/lib/io.h | 10 |
2 files changed, 43 insertions, 20 deletions
diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index e2f1ad9488f..a9fabdf74f8 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 f9b8832cf41..a5086b158c4 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 |