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