1use std::{ffi::c_uint, io, os::unix::io::BorrowedFd};
2
3use drm_sys::*;
4use rustix::ioctl::{
5 ioctl, Getter, NoArg, NoneOpcode, ReadOpcode, ReadWriteOpcode, Setter, Updater, WriteOpcode,
6};
7
8macro_rules! ioctl_readwrite {
9 ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
10 pub unsafe fn $name(fd: BorrowedFd, data: &mut $ty) -> io::Result<()> {
11 type Opcode = ReadWriteOpcode<$ioty, $nr, $ty>;
12 Ok(ioctl(fd, Updater::<Opcode, $ty>::new(data))?)
13 }
14 };
15}
16
17macro_rules! ioctl_read {
18 ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
19 pub unsafe fn $name(fd: BorrowedFd) -> io::Result<$ty> {
20 type Opcode = ReadOpcode<$ioty, $nr, $ty>;
21 Ok(ioctl(fd, Getter::<Opcode, $ty>::new())?)
22 }
23 };
24}
25
26macro_rules! ioctl_write_ptr {
27 ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
28 pub unsafe fn $name(fd: BorrowedFd, data: &$ty) -> io::Result<()> {
29 type Opcode = WriteOpcode<$ioty, $nr, $ty>;
30 Ok(ioctl(fd, Setter::<Opcode, $ty>::new(*data))?)
31 }
32 };
33}
34
35macro_rules! ioctl_none {
36 ($name:ident, $ioty:expr, $nr:expr) => {
37 pub unsafe fn $name(fd: BorrowedFd) -> io::Result<()> {
38 type Opcode = NoneOpcode<$ioty, $nr, ()>;
39 Ok(ioctl(fd, NoArg::<Opcode>::new())?)
40 }
41 };
42}
43
44ioctl_readwrite!(get_bus_id, DRM_IOCTL_BASE, 0x01, drm_unique);
50
51ioctl_readwrite!(get_client, DRM_IOCTL_BASE, 0x05, drm_client);
57
58ioctl_readwrite!(get_cap, DRM_IOCTL_BASE, 0x0c, drm_get_cap);
64
65ioctl_write_ptr!(set_cap, DRM_IOCTL_BASE, 0x0d, drm_set_client_cap);
71
72ioctl_readwrite!(set_version, DRM_IOCTL_BASE, 0x07, drm_set_version);
78
79ioctl_readwrite!(get_version, DRM_IOCTL_BASE, 0x00, drm_version);
85
86ioctl_read!(get_token, DRM_IOCTL_BASE, 0x02, drm_auth);
92
93ioctl_write_ptr!(auth_token, DRM_IOCTL_BASE, 0x11, drm_auth);
99
100ioctl_none!(acquire_master, DRM_IOCTL_BASE, 0x1e);
106
107ioctl_none!(release_master, DRM_IOCTL_BASE, 0x1f);
113
114ioctl_readwrite!(get_irq_from_bus_id, DRM_IOCTL_BASE, 0x03, drm_irq_busid);
120
121ioctl_readwrite!(wait_vblank, DRM_IOCTL_BASE, 0x3a, drm_wait_vblank);
127
128pub(crate) mod mode {
129 use super::*;
130
131 ioctl_readwrite!(get_resources, DRM_IOCTL_BASE, 0xA0, drm_mode_card_res);
133
134 ioctl_readwrite!(
135 get_plane_resources,
136 DRM_IOCTL_BASE,
137 0xB5,
138 drm_mode_get_plane_res
139 );
140
141 ioctl_readwrite!(get_connector, DRM_IOCTL_BASE, 0xA7, drm_mode_get_connector);
143
144 ioctl_readwrite!(get_encoder, DRM_IOCTL_BASE, 0xA6, drm_mode_get_encoder);
146
147 ioctl_readwrite!(get_crtc, DRM_IOCTL_BASE, 0xA1, drm_mode_crtc);
149 ioctl_readwrite!(set_crtc, DRM_IOCTL_BASE, 0xA2, drm_mode_crtc);
150
151 ioctl_readwrite!(get_gamma, DRM_IOCTL_BASE, 0xA4, drm_mode_crtc_lut);
153 ioctl_readwrite!(set_gamma, DRM_IOCTL_BASE, 0xA5, drm_mode_crtc_lut);
154
155 ioctl_readwrite!(get_fb, DRM_IOCTL_BASE, 0xAD, drm_mode_fb_cmd);
159 ioctl_readwrite!(get_fb2, DRM_IOCTL_BASE, 0xCE, drm_mode_fb_cmd2);
160 ioctl_readwrite!(add_fb, DRM_IOCTL_BASE, 0xAE, drm_mode_fb_cmd);
161 ioctl_readwrite!(add_fb2, DRM_IOCTL_BASE, 0xB8, drm_mode_fb_cmd2);
162 ioctl_readwrite!(rm_fb, DRM_IOCTL_BASE, 0xAF, c_uint);
163
164 ioctl_readwrite!(get_plane, DRM_IOCTL_BASE, 0xB6, drm_mode_get_plane);
166
167 ioctl_readwrite!(set_plane, DRM_IOCTL_BASE, 0xB7, drm_mode_set_plane);
168
169 ioctl_readwrite!(create_dumb, DRM_IOCTL_BASE, 0xB2, drm_mode_create_dumb);
171
172 ioctl_readwrite!(map_dumb, DRM_IOCTL_BASE, 0xB3, drm_mode_map_dumb);
173
174 ioctl_readwrite!(destroy_dumb, DRM_IOCTL_BASE, 0xB4, drm_mode_destroy_dumb);
175
176 ioctl_readwrite!(cursor, DRM_IOCTL_BASE, 0xA3, drm_mode_cursor);
178 ioctl_readwrite!(cursor2, DRM_IOCTL_BASE, 0xBB, drm_mode_cursor2);
179
180 ioctl_readwrite!(get_property, DRM_IOCTL_BASE, 0xAA, drm_mode_get_property);
182
183 ioctl_readwrite!(
184 connector_set_property,
185 DRM_IOCTL_BASE,
186 0xAB,
187 drm_mode_connector_set_property
188 );
189
190 ioctl_readwrite!(
191 obj_get_properties,
192 DRM_IOCTL_BASE,
193 0xB9,
194 drm_mode_obj_get_properties
195 );
196
197 ioctl_readwrite!(
198 obj_set_property,
199 DRM_IOCTL_BASE,
200 0xBA,
201 drm_mode_obj_set_property
202 );
203
204 ioctl_readwrite!(get_blob, DRM_IOCTL_BASE, 0xAC, drm_mode_get_blob);
206
207 ioctl_readwrite!(create_blob, DRM_IOCTL_BASE, 0xBD, drm_mode_create_blob);
210
211 ioctl_readwrite!(destroy_blob, DRM_IOCTL_BASE, 0xBE, drm_mode_destroy_blob);
212
213 ioctl_readwrite!(
215 crtc_page_flip,
216 DRM_IOCTL_BASE,
217 0xB0,
218 drm_mode_crtc_page_flip
219 );
220
221 ioctl_readwrite!(dirty_fb, DRM_IOCTL_BASE, 0xB1, drm_mode_fb_dirty_cmd);
222
223 ioctl_readwrite!(atomic, DRM_IOCTL_BASE, 0xBC, drm_mode_atomic);
224
225 ioctl_readwrite!(create_lease, DRM_IOCTL_BASE, 0xC6, drm_mode_create_lease);
226 ioctl_readwrite!(list_lessees, DRM_IOCTL_BASE, 0xC7, drm_mode_list_lessees);
227 ioctl_readwrite!(get_lease, DRM_IOCTL_BASE, 0xC8, drm_mode_get_lease);
228 ioctl_readwrite!(revoke_lease, DRM_IOCTL_BASE, 0xC9, drm_mode_revoke_lease);
229}
230
231pub(crate) mod gem {
232 use super::*;
233
234 ioctl_readwrite!(open, DRM_IOCTL_BASE, 0x0b, drm_gem_open);
236 ioctl_write_ptr!(close, DRM_IOCTL_BASE, 0x09, drm_gem_close);
237
238 ioctl_readwrite!(prime_handle_to_fd, DRM_IOCTL_BASE, 0x2d, drm_prime_handle);
240
241 ioctl_readwrite!(prime_fd_to_handle, DRM_IOCTL_BASE, 0x2e, drm_prime_handle);
243}
244
245pub(crate) mod syncobj {
246 use super::*;
247
248 ioctl_readwrite!(create, DRM_IOCTL_BASE, 0xBF, drm_syncobj_create);
250 ioctl_readwrite!(destroy, DRM_IOCTL_BASE, 0xC0, drm_syncobj_destroy);
252 ioctl_readwrite!(handle_to_fd, DRM_IOCTL_BASE, 0xC1, drm_syncobj_handle);
254 ioctl_readwrite!(fd_to_handle, DRM_IOCTL_BASE, 0xC2, drm_syncobj_handle);
256 ioctl_readwrite!(wait, DRM_IOCTL_BASE, 0xC3, drm_syncobj_wait);
258 ioctl_readwrite!(reset, DRM_IOCTL_BASE, 0xC4, drm_syncobj_array);
260 ioctl_readwrite!(signal, DRM_IOCTL_BASE, 0xC5, drm_syncobj_array);
262
263 ioctl_readwrite!(
265 timeline_wait,
266 DRM_IOCTL_BASE,
267 0xCA,
268 drm_syncobj_timeline_wait
269 );
270 ioctl_readwrite!(query, DRM_IOCTL_BASE, 0xCB, drm_syncobj_timeline_array);
272 ioctl_readwrite!(transfer, DRM_IOCTL_BASE, 0xCC, drm_syncobj_transfer);
274 ioctl_readwrite!(
276 timeline_signal,
277 DRM_IOCTL_BASE,
278 0xCD,
279 drm_syncobj_timeline_array
280 );
281}