Mesa (main): asahi: Identify more unknown fields in the memmap

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jul 11 18:58:29 UTC 2021


Module: Mesa
Branch: main
Commit: d5580ee805a8790cf1f2e44898d188b6ff9d3402
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d5580ee805a8790cf1f2e44898d188b6ff9d3402

Author: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Date:   Sat Jul 10 12:05:34 2021 -0400

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 at rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11815>

---

 src/asahi/lib/decode.c            | 53 ++++++++++++++++++++++++++++-----------
 src/asahi/lib/io.h                | 10 +++-----
 src/gallium/drivers/asahi/magic.c |  9 +++----
 3 files changed, 47 insertions(+), 25 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
@@ -100,44 +100,69 @@ agxdecode_find_handle(unsigned handle, unsigned type)
    return NULL;
 }
 
+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
diff --git a/src/gallium/drivers/asahi/magic.c b/src/gallium/drivers/asahi/magic.c
index af8dd6e5416..6d4b75f7bf8 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
    };
 }



More information about the mesa-commit mailing list