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@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13784>
This commit is contained in:
Alyssa Rosenzweig 2021-11-13 14:24:01 -05:00 committed by Marge Bot
parent 6637fbb211
commit d55a1a77bd
3 changed files with 13 additions and 37 deletions

View file

@ -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);
}
}

View file

@ -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

View file

@ -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,
};
}