Mesa (main): asahi: Fix agx_map_* structures
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Nov 18 23:46:49 UTC 2021
Module: Mesa
Branch: main
Commit: d55a1a77bd11c3ae1547e8e46beb67b36baaf618
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d55a1a77bd11c3ae1547e8e46beb67b36baaf618
Author: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Date: Sat Nov 13 14:24:01 2021 -0500
asahi: Fix agx_map_* structures
Dougall Johnson observed these structures make more sense with indices[]
first in the entries and indices[] absent from the header. Then the
sentinel entry disappears, nr_entries makes more sense, and a few magic
numbers pop out. Many thanks to Dougall's astute eyes.
Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13784>
---
src/asahi/lib/decode.c | 24 +++++-------------------
src/asahi/lib/io.h | 3 +--
src/gallium/drivers/asahi/magic.c | 23 +++++++----------------
3 files changed, 13 insertions(+), 37 deletions(-)
diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c
index 9132fff3f43..29b57025b23 100644
--- a/src/asahi/lib/decode.c
+++ b/src/asahi/lib/decode.c
@@ -130,20 +130,12 @@ agxdecode_validate_map(void *map)
return;
}
- 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; ++i) {
+ struct agx_map_entry *entries = ((void *) hdr) + sizeof(*hdr);
+ for (unsigned i = 0; i < hdr->nr_entries; ++i) {
struct agx_map_entry entry = entries[i];
- for (unsigned j = 0; j < 6; ++j) {
+ for (unsigned j = 0; j < ARRAY_SIZE(entry.indices); ++j) {
unsigned handle = entry.indices[j];
if (handle) {
agxdecode_mark_mapped(handle);
@@ -152,16 +144,10 @@ agxdecode_validate_map(void *map)
}
}
- /* Check the sentinel */
- 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);
+ fprintf(stderr, "ERROR - wrong handle count, got %u, expected %u (%u entries)\n",
+ nr_handles, hdr->nr_handles, hdr->nr_entries);
}
}
diff --git a/src/asahi/lib/io.h b/src/asahi/lib/io.h
index bfac6fc42fc..40b9f2ddb7b 100644
--- a/src/asahi/lib/io.h
+++ b/src/asahi/lib/io.h
@@ -194,10 +194,10 @@ struct agx_map_header {
uint32_t cmdbuf_size;
uint32_t nr_handles;
uint32_t nr_entries;
- uint32_t indices[6];
} __attribute__((packed));
struct agx_map_entry {
+ uint32_t indices[6];
uint32_t unkAAA; // 20 00 00 00
uint32_t unk2; // 00 00 00 00
uint32_t unk3; // 00 00 00 00
@@ -208,7 +208,6 @@ 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 indices[6];
} __attribute__((packed));
uint64_t
diff --git a/src/gallium/drivers/asahi/magic.c b/src/gallium/drivers/asahi/magic.c
index 05ec6a5c8df..feef9b3eaad 100644
--- a/src/gallium/drivers/asahi/magic.c
+++ b/src/gallium/drivers/asahi/magic.c
@@ -176,9 +176,8 @@ 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 = count + 1,
- .nr_handles = count + 1,
- .indices = {0x0b},
+ .nr_entries = count,
+ .nr_handles = count,
};
}
@@ -187,28 +186,20 @@ demo_mem_map(void *map, size_t size, unsigned *handles, unsigned count,
uint64_t cmdbuf_id, uint64_t encoder_id, unsigned cmdbuf_size)
{
struct agx_map_header *header = map;
- struct agx_map_entry *entries = (struct agx_map_entry *) (((uint8_t *) map) + 0x40);
+ struct agx_map_entry *entries = (struct agx_map_entry *) (((uint8_t *) map) + sizeof(*header));
struct agx_map_entry *end = (struct agx_map_entry *) (((uint8_t *) map) + size);
/* Header precedes the entry */
- *header = demo_map_header(cmdbuf_id, encoder_id, cmdbuf_size, count);
+ *header = demo_map_header(cmdbuf_id, encoder_id, cmdbuf_size, count + 1);
/* Add an entry for each BO mapped */
- for (unsigned i = 0; i < count; ++i) {
+ for (unsigned i = 0; i < count + 1; ++i) {
assert((entries + i) < end);
entries[i] = (struct agx_map_entry) {
- .unkAAA = 0x20,
+ .indices = {(i == 0) ? 0x0b : handles[i - 1]},
+ .unkAAA = i == count ? 0x40 : 0x20,
.unkBBB = 0x1,
.unka = 0x1ffff,
- .indices = {handles[i]}
};
}
-
- /* Final entry is a sentinel */
- assert((entries + count) < end);
- entries[count] = (struct agx_map_entry) {
- .unkAAA = 0x40,
- .unkBBB = 0x1,
- .unka = 0x1ffff,
- };
}
More information about the mesa-commit
mailing list