1 /* 2 * Copyright 2024 Sergio Lopez 3 * Copyright 2022 Google LLC 4 * SPDX-License-Identifier: MIT 5 */ 6 7 #ifndef ASAHI_PROTO_H_ 8 #define ASAHI_PROTO_H_ 9 10 /** 11 * Defines the layout of shmem buffer used for host->guest communication. 12 */ 13 struct asahi_shmem { 14 struct vdrm_shmem base; 15 16 /** 17 * Counter that is incremented on asynchronous errors, like SUBMIT 18 * or GEM_NEW failures. The guest should treat errors as context- 19 * lost. 20 */ 21 uint32_t async_error; 22 23 /** 24 * Counter that is incremented on global fault (see MSM_PARAM_FAULTS) 25 */ 26 uint32_t global_faults; 27 }; 28 DEFINE_CAST(vdrm_shmem, asahi_shmem) 29 30 /* 31 * Possible cmd types for "command stream", ie. payload of EXECBUF ioctl: 32 */ 33 enum asahi_ccmd { 34 ASAHI_CCMD_NOP = 1, /* No payload, can be used to sync with host */ 35 ASAHI_CCMD_IOCTL_SIMPLE, 36 ASAHI_CCMD_GET_PARAMS, 37 ASAHI_CCMD_GEM_NEW, 38 ASAHI_CCMD_GEM_BIND, 39 ASAHI_CCMD_SUBMIT, 40 }; 41 42 #define ASAHI_CCMD(_cmd, _len) \ 43 (struct vdrm_ccmd_req) \ 44 { \ 45 .cmd = ASAHI_CCMD_##_cmd, .len = (_len), \ 46 } 47 48 /* 49 * ASAHI_CCMD_NOP 50 */ 51 struct asahi_ccmd_nop_req { 52 struct vdrm_ccmd_req hdr; 53 }; 54 55 /* 56 * ASAHI_CCMD_IOCTL_SIMPLE 57 * 58 * Forward simple/flat IOC_RW or IOC_W ioctls. Limited ioctls are supported. 59 */ 60 struct asahi_ccmd_ioctl_simple_req { 61 struct vdrm_ccmd_req hdr; 62 63 uint32_t cmd; 64 uint8_t payload[]; 65 }; 66 DEFINE_CAST(vdrm_ccmd_req, asahi_ccmd_ioctl_simple_req) 67 68 struct asahi_ccmd_ioctl_simple_rsp { 69 struct vdrm_ccmd_rsp hdr; 70 71 /* ioctl return value, interrupted syscalls are handled on the host without 72 * returning to the guest. 73 */ 74 int32_t ret; 75 76 /* The output payload for IOC_RW ioctls, the payload is the same size as 77 * asahi_context_cmd_ioctl_simple_req. 78 * 79 * For IOC_W ioctls (userspace writes, kernel reads) this is zero length. 80 */ 81 uint8_t payload[]; 82 }; 83 84 struct asahi_ccmd_get_params_req { 85 struct vdrm_ccmd_req hdr; 86 struct drm_asahi_get_params params; 87 }; 88 DEFINE_CAST(vdrm_ccmd_req, asahi_ccmd_get_params_req) 89 90 struct asahi_ccmd_get_params_rsp { 91 struct vdrm_ccmd_rsp hdr; 92 int32_t ret; 93 struct drm_asahi_params_global params; 94 }; 95 96 struct asahi_ccmd_gem_new_req { 97 struct vdrm_ccmd_req hdr; 98 uint32_t flags; 99 uint32_t bind_flags; 100 uint32_t vm_id; 101 uint32_t blob_id; 102 uint64_t size; 103 uint64_t addr; 104 }; 105 DEFINE_CAST(vdrm_ccmd_req, asahi_ccmd_gem_new_req) 106 107 struct asahi_ccmd_gem_bind_req { 108 struct vdrm_ccmd_req hdr; 109 uint32_t op; 110 uint32_t flags; 111 uint32_t vm_id; 112 uint32_t res_id; 113 uint64_t size; 114 uint64_t addr; 115 }; 116 DEFINE_CAST(vdrm_ccmd_req, asahi_ccmd_gem_bind_req) 117 118 struct asahi_ccmd_gem_bind_rsp { 119 struct vdrm_ccmd_rsp hdr; 120 int32_t ret; 121 }; 122 123 struct asahi_ccmd_submit_req { 124 struct vdrm_ccmd_req hdr; 125 uint32_t queue_id; 126 uint32_t result_res_id; 127 uint32_t command_count; 128 129 uint8_t payload[]; 130 }; 131 DEFINE_CAST(vdrm_ccmd_req, asahi_ccmd_submit_req) 132 133 #endif // ASAHI_PROTO_H_ 134