asahi: Sync some names with Project Zero

This should clarify a few things I didn't get independently
investigating the interface. Of coruse, I got other pieces... the sum of
the parts is better :-)

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16512>
This commit is contained in:
Alyssa Rosenzweig 2022-04-02 21:55:25 -04:00
parent 6e59474ced
commit db32b4a064
4 changed files with 67 additions and 55 deletions

View File

@ -446,11 +446,11 @@ agx_submit_cmdbuf(struct agx_device *dev, unsigned cmdbuf, unsigned mappings, ui
#if __APPLE__
struct agx_submit_cmdbuf_req req = {
.unk0 = 0x10,
.unk1 = 0x1,
.cmdbuf = cmdbuf,
.mappings = mappings,
.user_0 = (void *) ((uintptr_t) 0xABCD), // Passed in the notif queue
.user_1 = (void *) ((uintptr_t) 0x1234), // Maybe pick better
.count = 1,
.command_buffer_shmem_id = cmdbuf,
.segment_list_shmem_id = mappings,
.notify_1 = 0xABCD,
.notify_2 = 0x1234,
.unk2 = 0x0,
.unk3 = 0x1,
};

View File

@ -125,18 +125,18 @@ agxdecode_validate_map(void *map)
/* Check the header */
struct agx_map_header *hdr = map;
if (hdr->nr_entries == 0) {
if (hdr->resource_group_count == 0) {
fprintf(stderr, "ERROR - empty map\n");
return;
}
/* Check the entries */
struct agx_map_entry *entries = ((void *) hdr) + sizeof(*hdr);
for (unsigned i = 0; i < hdr->nr_entries; ++i) {
for (unsigned i = 0; i < hdr->resource_group_count; ++i) {
struct agx_map_entry entry = entries[i];
for (unsigned j = 0; j < ARRAY_SIZE(entry.indices); ++j) {
unsigned handle = entry.indices[j];
for (unsigned j = 0; j < ARRAY_SIZE(entry.resource_id); ++j) {
unsigned handle = entry.resource_id[j];
if (handle) {
agxdecode_mark_mapped(handle);
nr_handles++;
@ -145,9 +145,9 @@ agxdecode_validate_map(void *map)
}
/* Check the handle count */
if (nr_handles != hdr->nr_handles) {
if (nr_handles != hdr->total_resources) {
fprintf(stderr, "ERROR - wrong handle count, got %u, expected %u (%u entries)\n",
nr_handles, hdr->nr_handles, hdr->nr_entries);
nr_handles, hdr->total_resources, hdr->resource_group_count);
}
}

View File

@ -32,6 +32,19 @@
#include <IOKit/IODataQueueClient.h>
#endif
/*
* This file contains necessary defines for the macOS (IOKit) interface to the
* AGX accelerator, required to build a userspace graphics driver on macOS.
*
* They are not used under Linux.
*
* Information is this file was originally determined independently. More
* recently, names have been augmented via the oob_timestamp code sample from
* Project Zero [1]
*
* [1] https://bugs.chromium.org/p/project-zero/issues/detail?id=1986
*/
#define AGX_SERVICE_TYPE 0x100005
enum agx_selector {
@ -116,9 +129,10 @@ struct agx_create_command_queue_resp {
} __attribute__((packed));
struct agx_create_shmem_resp {
void *map;
uint32_t size;
uint32_t id;
/* IOAccelDeviceShmemData */
void *map;
uint32_t size;
uint32_t id;
} __attribute__((packed));
struct agx_create_notification_queue_resp {
@ -132,15 +146,18 @@ struct agx_create_notification_queue_resp {
} __attribute__((packed));
struct agx_submit_cmdbuf_req {
uint32_t unk0;
uint32_t unk1;
uint32_t cmdbuf;
uint32_t mappings;
/* IOAccelCommandQueueSubmitArgs_Header */
uint32_t unk0;
uint32_t count;
/* IOAccelCommandQueueSubmitArgs_Command */
uint32_t command_buffer_shmem_id;
uint32_t segment_list_shmem_id;
uint64_t unk1B; // 0, new in 12.x
void *user_0;
void *user_1;
uint32_t unk2;
uint32_t unk3;
uint64_t notify_1;
uint64_t notify_2;
uint32_t unk2;
uint32_t unk3;
} __attribute__((packed));
/* Memory allocation isn't really understood yet. By comparing SHADER/CMDBUF_32
@ -186,32 +203,28 @@ struct agx_command_queue {
struct agx_notification_queue notif;
};
/* Not sure if this is hardware or software defined */
struct agx_map_header {
uint64_t cmdbuf_id; // GUID
uint32_t unk2; // 01 00 00 00
uint32_t unk3; // 28 05 00 80, 12.x: 30 01 00 80
uint64_t encoder_id; // GUID
uint32_t unk6; // 00 00 00 00
uint32_t cmdbuf_size;
/* IOAccelSegmentListHeader */
uint64_t cmdbuf_id; // GUID
uint32_t segment_count;
uint32_t length;
uint64_t encoder_id; // GUID
/* IOAccelSegmentResourceListHeader */
uint32_t kernel_commands_start_offset;
uint32_t kernel_commands_end_offset;
uint32_t padding[2];
uint32_t nr_handles;
uint32_t nr_entries;
uint32_t total_resources;
uint32_t resource_group_count;
} __attribute__((packed));
/* IOAccelSegmentResourceList_ResourceGroup */
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
uint32_t unk4; // 00 00 00 00
uint32_t unk5; // 00 00 00 00
uint32_t unk6; // 00 00 00 00
uint32_t unkBBB; // 01 00 00 00
uint32_t unk8; // 00 00 00 00
uint32_t unk9; // 00 00 00 00
uint32_t unka; // ff ff 01 00
uint32_t resource_id[6];
uint32_t resource_unk[6];
uint16_t resource_flags[6];
uint16_t unka; // ff ff
uint16_t resource_count;
} __attribute__((packed));
uint64_t

View File

@ -279,15 +279,13 @@ demo_map_header(uint64_t cmdbuf_id, uint64_t encoder_id, unsigned cmdbuf_size, u
{
return (struct agx_map_header) {
.cmdbuf_id = cmdbuf_id,
.unk2 = 0x1,
.unk3 = 0x528, // 1320
.segment_count = 1,
.length = 0x130,
.encoder_id = encoder_id,
.unk6 = 0x0,
.cmdbuf_size = cmdbuf_size,
/* +1 for the sentinel ending */
.nr_entries = count,
.nr_handles = count,
.kernel_commands_start_offset = 0,
.kernel_commands_end_offset = cmdbuf_size,
.total_resources = count,
.resource_group_count = count,
};
}
@ -306,10 +304,11 @@ demo_mem_map(void *map, size_t size, unsigned *handles, unsigned count,
for (unsigned i = 0; i < count; ++i) {
assert((entries + i) < end);
entries[i] = (struct agx_map_entry) {
.indices = {handles[i]},
.unkAAA = 0x20,
.unkBBB = 0x1,
.unka = 0x1ffff,
.resource_id = { handles[i] },
.resource_unk = { 0x20 },
.resource_flags = { 0x1 },
.resource_count = 1,
.unka = 0xffff,
};
}
}