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__ #if __APPLE__
struct agx_submit_cmdbuf_req req = { struct agx_submit_cmdbuf_req req = {
.unk0 = 0x10, .unk0 = 0x10,
.unk1 = 0x1, .count = 1,
.cmdbuf = cmdbuf, .command_buffer_shmem_id = cmdbuf,
.mappings = mappings, .segment_list_shmem_id = mappings,
.user_0 = (void *) ((uintptr_t) 0xABCD), // Passed in the notif queue .notify_1 = 0xABCD,
.user_1 = (void *) ((uintptr_t) 0x1234), // Maybe pick better .notify_2 = 0x1234,
.unk2 = 0x0, .unk2 = 0x0,
.unk3 = 0x1, .unk3 = 0x1,
}; };

View file

@ -125,18 +125,18 @@ agxdecode_validate_map(void *map)
/* Check the header */ /* Check the header */
struct agx_map_header *hdr = map; struct agx_map_header *hdr = map;
if (hdr->nr_entries == 0) { if (hdr->resource_group_count == 0) {
fprintf(stderr, "ERROR - empty map\n"); fprintf(stderr, "ERROR - empty map\n");
return; return;
} }
/* Check the entries */ /* Check the entries */
struct agx_map_entry *entries = ((void *) hdr) + sizeof(*hdr); 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]; struct agx_map_entry entry = entries[i];
for (unsigned j = 0; j < ARRAY_SIZE(entry.indices); ++j) { for (unsigned j = 0; j < ARRAY_SIZE(entry.resource_id); ++j) {
unsigned handle = entry.indices[j]; unsigned handle = entry.resource_id[j];
if (handle) { if (handle) {
agxdecode_mark_mapped(handle); agxdecode_mark_mapped(handle);
nr_handles++; nr_handles++;
@ -145,9 +145,9 @@ agxdecode_validate_map(void *map)
} }
/* Check the handle count */ /* 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", 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> #include <IOKit/IODataQueueClient.h>
#endif #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 #define AGX_SERVICE_TYPE 0x100005
enum agx_selector { enum agx_selector {
@ -116,6 +129,7 @@ struct agx_create_command_queue_resp {
} __attribute__((packed)); } __attribute__((packed));
struct agx_create_shmem_resp { struct agx_create_shmem_resp {
/* IOAccelDeviceShmemData */
void *map; void *map;
uint32_t size; uint32_t size;
uint32_t id; uint32_t id;
@ -132,13 +146,16 @@ struct agx_create_notification_queue_resp {
} __attribute__((packed)); } __attribute__((packed));
struct agx_submit_cmdbuf_req { struct agx_submit_cmdbuf_req {
/* IOAccelCommandQueueSubmitArgs_Header */
uint32_t unk0; uint32_t unk0;
uint32_t unk1; uint32_t count;
uint32_t cmdbuf;
uint32_t mappings; /* IOAccelCommandQueueSubmitArgs_Command */
uint32_t command_buffer_shmem_id;
uint32_t segment_list_shmem_id;
uint64_t unk1B; // 0, new in 12.x uint64_t unk1B; // 0, new in 12.x
void *user_0; uint64_t notify_1;
void *user_1; uint64_t notify_2;
uint32_t unk2; uint32_t unk2;
uint32_t unk3; uint32_t unk3;
} __attribute__((packed)); } __attribute__((packed));
@ -186,32 +203,28 @@ struct agx_command_queue {
struct agx_notification_queue notif; struct agx_notification_queue notif;
}; };
/* Not sure if this is hardware or software defined */
struct agx_map_header { struct agx_map_header {
/* IOAccelSegmentListHeader */
uint64_t cmdbuf_id; // GUID uint64_t cmdbuf_id; // GUID
uint32_t unk2; // 01 00 00 00 uint32_t segment_count;
uint32_t unk3; // 28 05 00 80, 12.x: 30 01 00 80 uint32_t length;
uint64_t encoder_id; // GUID uint64_t encoder_id; // GUID
uint32_t unk6; // 00 00 00 00
uint32_t cmdbuf_size; /* IOAccelSegmentResourceListHeader */
uint32_t kernel_commands_start_offset;
uint32_t kernel_commands_end_offset;
uint32_t padding[2]; uint32_t padding[2];
uint32_t nr_handles; uint32_t total_resources;
uint32_t nr_entries; uint32_t resource_group_count;
} __attribute__((packed)); } __attribute__((packed));
/* IOAccelSegmentResourceList_ResourceGroup */
struct agx_map_entry { struct agx_map_entry {
uint32_t indices[6]; uint32_t resource_id[6];
uint32_t unkAAA; // 20 00 00 00 uint32_t resource_unk[6];
uint32_t unk2; // 00 00 00 00 uint16_t resource_flags[6];
uint32_t unk3; // 00 00 00 00 uint16_t unka; // ff ff
uint32_t unk4; // 00 00 00 00 uint16_t resource_count;
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
} __attribute__((packed)); } __attribute__((packed));
uint64_t 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) { return (struct agx_map_header) {
.cmdbuf_id = cmdbuf_id, .cmdbuf_id = cmdbuf_id,
.unk2 = 0x1, .segment_count = 1,
.unk3 = 0x528, // 1320 .length = 0x130,
.encoder_id = encoder_id, .encoder_id = encoder_id,
.unk6 = 0x0, .kernel_commands_start_offset = 0,
.cmdbuf_size = cmdbuf_size, .kernel_commands_end_offset = cmdbuf_size,
.total_resources = count,
/* +1 for the sentinel ending */ .resource_group_count = count,
.nr_entries = count,
.nr_handles = count,
}; };
} }
@ -306,10 +304,11 @@ demo_mem_map(void *map, size_t size, unsigned *handles, unsigned count,
for (unsigned i = 0; i < count; ++i) { for (unsigned i = 0; i < count; ++i) {
assert((entries + i) < end); assert((entries + i) < end);
entries[i] = (struct agx_map_entry) { entries[i] = (struct agx_map_entry) {
.indices = {handles[i]}, .resource_id = { handles[i] },
.unkAAA = 0x20, .resource_unk = { 0x20 },
.unkBBB = 0x1, .resource_flags = { 0x1 },
.unka = 0x1ffff, .resource_count = 1,
.unka = 0xffff,
}; };
} }
} }