aboutsummaryrefslogtreecommitdiffstats
path: root/sys/linux/dev_dri.txt
blob: 6e30f9e97ee52737e82e72e942d6d9ced89685d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# Copyright 2015 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

include <uapi/asm/ioctl.h>
include <uapi/linux/fcntl.h>
include <uapi/drm/drm.h>
include <uapi/drm/drm_mode.h>
include <uapi/drm/drm_fourcc.h>
include <linux/agp_backend.h>

resource fd_dri[fd]
resource drmctx[int32]
resource drm_agp_handle[intptr]
resource drm_gem_handle[int32]
resource drm_gem_name[int32]

# TODO: these seems to be pretty important things, where does one get these?
type drm_crtc_id int32
type drm_fb_id int32

syz_open_dev$dri(dev ptr[in, string["/dev/dri/card#"]], id intptr, flags flags[open_flags]) fd_dri
syz_open_dev$dricontrol(dev ptr[in, string["/dev/dri/controlD#"]], id intptr, flags flags[open_flags]) fd_dri
syz_open_dev$drirender(dev ptr[in, string["/dev/dri/renderD#"]], id intptr, flags flags[open_flags]) fd_dri
openat$drirender128(fd const[AT_FDCWD], file ptr[in, string["/dev/dri/renderD128"]], flags flags[open_flags], mode const[0]) fd_dri

ioctl$DRM_IOCTL_VERSION(fd fd_dri, cmd const[DRM_IOCTL_VERSION], arg ptr[in, drm_version])
ioctl$DRM_IOCTL_GET_UNIQUE(fd fd_dri, cmd const[DRM_IOCTL_GET_UNIQUE], arg ptr[in, drm_unique_out])
ioctl$DRM_IOCTL_GET_MAGIC(fd fd_dri, cmd const[DRM_IOCTL_GET_MAGIC], arg ptr[in, int32])
ioctl$DRM_IOCTL_IRQ_BUSID(fd fd_dri, cmd const[DRM_IOCTL_IRQ_BUSID], arg ptr[in, drm_irq_busid])
ioctl$DRM_IOCTL_GET_MAP(fd fd_dri, cmd const[DRM_IOCTL_GET_MAP], arg ptr[inout, drm_map$DRM_IOCTL_GET_MAP])
ioctl$DRM_IOCTL_GET_CLIENT(fd fd_dri, cmd const[DRM_IOCTL_GET_CLIENT], arg ptr[inout, drm_client])
ioctl$DRM_IOCTL_GET_STATS(fd fd_dri, cmd const[DRM_IOCTL_GET_STATS], arg buffer[out])
ioctl$DRM_IOCTL_GET_CAP(fd fd_dri, cmd const[DRM_IOCTL_GET_CAP], arg ptr[in, drm_get_cap])
ioctl$DRM_IOCTL_SET_CLIENT_CAP(fd fd_dri, cmd const[DRM_IOCTL_SET_CLIENT_CAP], arg ptr[in, drm_get_cap])
ioctl$DRM_IOCTL_SET_VERSION(fd fd_dri, cmd const[DRM_IOCTL_SET_VERSION], arg ptr[in, drm_set_version])
ioctl$DRM_IOCTL_SET_UNIQUE(fd fd_dri, cmd const[DRM_IOCTL_SET_UNIQUE], arg ptr[in, drm_unique_in])
ioctl$DRM_IOCTL_AUTH_MAGIC(fd fd_dri, cmd const[DRM_IOCTL_AUTH_MAGIC], arg ptr[in, int32])
ioctl$DRM_IOCTL_ADD_MAP(fd fd_dri, cmd const[DRM_IOCTL_ADD_MAP], arg ptr[inout, drm_map$DRM_IOCTL_ADD_MAP])
ioctl$DRM_IOCTL_RM_MAP(fd fd_dri, cmd const[DRM_IOCTL_RM_MAP], arg ptr[in, drm_map$DRM_IOCTL_RM_MAP])
ioctl$DRM_IOCTL_SET_SAREA_CTX(fd fd_dri, cmd const[DRM_IOCTL_SET_SAREA_CTX], arg ptr[in, drm_ctx_priv_map])
ioctl$DRM_IOCTL_GET_SAREA_CTX(fd fd_dri, cmd const[DRM_IOCTL_GET_SAREA_CTX], arg ptr[in, drm_ctx_priv_map])
ioctl$DRM_IOCTL_SET_MASTER(fd fd_dri, cmd const[DRM_IOCTL_SET_MASTER])
ioctl$DRM_IOCTL_DROP_MASTER(fd fd_dri, cmd const[DRM_IOCTL_DROP_MASTER])
ioctl$DRM_IOCTL_ADD_CTX(fd fd_dri, cmd const[DRM_IOCTL_ADD_CTX], arg ptr[out, drm_ctx])
ioctl$DRM_IOCTL_RM_CTX(fd fd_dri, cmd const[DRM_IOCTL_RM_CTX], arg ptr[in, drm_ctx])
ioctl$DRM_IOCTL_GET_CTX(fd fd_dri, cmd const[DRM_IOCTL_GET_CTX], arg ptr[in, drm_ctx])
ioctl$DRM_IOCTL_SWITCH_CTX(fd fd_dri, cmd const[DRM_IOCTL_SWITCH_CTX], arg ptr[in, drm_ctx])
ioctl$DRM_IOCTL_NEW_CTX(fd fd_dri, cmd const[DRM_IOCTL_NEW_CTX], arg ptr[in, drm_ctx])
ioctl$DRM_IOCTL_RES_CTX(fd fd_dri, cmd const[DRM_IOCTL_RES_CTX], arg ptr[in, drm_ctx_res])
ioctl$DRM_IOCTL_LOCK(fd fd_dri, cmd const[DRM_IOCTL_LOCK], arg ptr[in, drm_lock])
ioctl$DRM_IOCTL_UNLOCK(fd fd_dri, cmd const[DRM_IOCTL_UNLOCK], arg ptr[in, drm_lock])
ioctl$DRM_IOCTL_ADD_BUFS(fd fd_dri, cmd const[DRM_IOCTL_ADD_BUFS], arg ptr[in, drm_buf_desc])
ioctl$DRM_IOCTL_MARK_BUFS(fd fd_dri, cmd const[DRM_IOCTL_MARK_BUFS], arg ptr[in, drm_buf_desc])
ioctl$DRM_IOCTL_INFO_BUFS(fd fd_dri, cmd const[DRM_IOCTL_INFO_BUFS], arg ptr[in, drm_buf_desc])
ioctl$DRM_IOCTL_MAP_BUFS(fd fd_dri, cmd const[DRM_IOCTL_MAP_BUFS], arg ptr[in, drm_buf_map])
ioctl$DRM_IOCTL_FREE_BUFS(fd fd_dri, cmd const[DRM_IOCTL_FREE_BUFS], arg ptr[in, drm_buf_free])
ioctl$DRM_IOCTL_DMA(fd fd_dri, cmd const[DRM_IOCTL_DMA], arg ptr[in, drm_dma])
ioctl$DRM_IOCTL_CONTROL(fd fd_dri, cmd const[DRM_IOCTL_CONTROL], arg ptr[in, drm_control])
ioctl$DRM_IOCTL_AGP_ACQUIRE(fd fd_dri, cmd const[DRM_IOCTL_AGP_ACQUIRE])
ioctl$DRM_IOCTL_AGP_RELEASE(fd fd_dri, cmd const[DRM_IOCTL_AGP_RELEASE])
ioctl$DRM_IOCTL_AGP_ENABLE(fd fd_dri, cmd const[DRM_IOCTL_AGP_ENABLE], arg ptr[in, int32])
ioctl$DRM_IOCTL_AGP_INFO(fd fd_dri, cmd const[DRM_IOCTL_AGP_INFO], arg buffer[out])
ioctl$DRM_IOCTL_AGP_ALLOC(fd fd_dri, cmd const[DRM_IOCTL_AGP_ALLOC], arg ptr[inout, drm_agp_buffer$DRM_IOCTL_AGP_ALLOC])
ioctl$DRM_IOCTL_AGP_FREE(fd fd_dri, cmd const[DRM_IOCTL_AGP_FREE], arg ptr[in, drm_agp_buffer$DRM_IOCTL_AGP_FREE])
ioctl$DRM_IOCTL_AGP_BIND(fd fd_dri, cmd const[DRM_IOCTL_AGP_BIND], arg ptr[in, drm_agp_binding])
ioctl$DRM_IOCTL_AGP_UNBIND(fd fd_dri, cmd const[DRM_IOCTL_AGP_UNBIND], arg ptr[in, drm_agp_binding])
ioctl$DRM_IOCTL_SG_ALLOC(fd fd_dri, cmd const[DRM_IOCTL_SG_ALLOC], arg ptr[in, drm_scatter_gather])
ioctl$DRM_IOCTL_SG_FREE(fd fd_dri, cmd const[DRM_IOCTL_SG_FREE], arg ptr[in, drm_scatter_gather])
ioctl$DRM_IOCTL_WAIT_VBLANK(fd fd_dri, cmd const[DRM_IOCTL_WAIT_VBLANK], arg ptr[in, drm_wait_vblank])
ioctl$DRM_IOCTL_MODESET_CTL(fd fd_dri, cmd const[DRM_IOCTL_MODESET_CTL], arg ptr[in, drm_modeset_ctl])
ioctl$DRM_IOCTL_GEM_OPEN(fd fd_dri, cmd const[DRM_IOCTL_GEM_OPEN], arg ptr[inout, drm_gem_open])
ioctl$DRM_IOCTL_GEM_CLOSE(fd fd_dri, cmd const[DRM_IOCTL_GEM_CLOSE], arg ptr[in, drm_gem_close])
ioctl$DRM_IOCTL_GEM_FLINK(fd fd_dri, cmd const[DRM_IOCTL_GEM_FLINK], arg ptr[inout, drm_gem_flink])
ioctl$DRM_IOCTL_MODE_GETRESOURCES(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETRESOURCES], arg ptr[in, drm_mode_card_res])
ioctl$DRM_IOCTL_PRIME_HANDLE_TO_FD(fd fd_dri, cmd const[DRM_IOCTL_PRIME_HANDLE_TO_FD], arg ptr[inout, drm_prime_handle$DRM_IOCTL_PRIME_HANDLE_TO_FD])
ioctl$DRM_IOCTL_PRIME_FD_TO_HANDLE(fd fd_dri, cmd const[DRM_IOCTL_PRIME_FD_TO_HANDLE], arg ptr[inout, drm_prime_handle$DRM_IOCTL_PRIME_FD_TO_HANDLE])
ioctl$DRM_IOCTL_MODE_GETPLANERESOURCES(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETPLANERESOURCES], arg ptr[in, drm_mode_get_plane_res])
ioctl$DRM_IOCTL_MODE_GETCRTC(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETCRTC], arg ptr[in, drm_mode_crtc])
ioctl$DRM_IOCTL_MODE_SETCRTC(fd fd_dri, cmd const[DRM_IOCTL_MODE_SETCRTC], arg ptr[in, drm_mode_crtc])

ioctl$DRM_IOCTL_MODE_GETPLANE(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETPLANE], arg ptr[in, drm_mode_get_plane])
ioctl$DRM_IOCTL_MODE_SETPLANE(fd fd_dri, cmd const[DRM_IOCTL_MODE_SETPLANE], arg ptr[in, drm_mode_set_plane])

resource drm_plane_id[int32]

drm_mode_get_plane_res {
	ids	ptr64[out, array[drm_plane_id]]
	cnt	len[ids, int32]
}

drm_mode_get_plane {
	plane_id		drm_plane_id
# These are outputs:
	crtc_id			const[0, int32]
	fb_id			const[0, int32]
	possible_crtcs		const[0, int32]
	gamma_size		const[0, int32]
	count_format_types	len[format_type_ptr, int32]
	format_type_ptr		ptr64[out, array[int32]]
}

drm_mode_set_plane {
	plane_id	drm_plane_id
	crtc_id		drm_crtc_id
	fb_id		drm_fb_id
	flags		int32
	crtc_x		int32
	crtc_y		int32
	crtc_w		int32
	crtc_h		int32
	src_x		int32
	src_y		int32
	src_h		int32
	src_w		int32
}

ioctl$DRM_IOCTL_MODE_CURSOR(fd fd_dri, cmd const[DRM_IOCTL_MODE_CURSOR], arg ptr[in, drm_mode_cursor])
ioctl$DRM_IOCTL_MODE_CURSOR2(fd fd_dri, cmd const[DRM_IOCTL_MODE_CURSOR2], arg ptr[in, drm_mode_cursor2])

drm_mode_cursor {
	flags	flags[drm_mode_cursor_flags, int32]
	crtc_id	drm_crtc_id
	x	int32
	y	int32
	width	int32
	height	int32
	handle	int32
}

drm_mode_cursor2 {
	flags	flags[drm_mode_cursor_flags, int32]
	crtc_id	drm_crtc_id
	x	int32
	y	int32
	width	int32
	height	int32
	handle	int32
	hot_x	int32
	hot_y	int32
}

drm_mode_cursor_flags = DRM_MODE_CURSOR_BO, DRM_MODE_CURSOR_MOVE

ioctl$DRM_IOCTL_MODE_GETGAMMA(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETGAMMA], arg ptr[in, drm_mode_crtc_lut])
ioctl$DRM_IOCTL_MODE_SETGAMMA(fd fd_dri, cmd const[DRM_IOCTL_MODE_SETGAMMA], arg ptr[in, drm_mode_crtc_lut])

drm_mode_crtc_lut {
	crtc_id		drm_crtc_id
# gamma_size needs to be equal to gamma_size passed to DRM_IOCTL_MODE_SETCRTC.
	gamma_size	len[red, int32]
	red		ptr64[in, array[int16]]
# NEED: these should be of the same size as red.
	green		ptr64[in, array[int16]]
	blue		ptr64[in, array[int16]]
}

ioctl$DRM_IOCTL_MODE_GETENCODER(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETENCODER], arg ptr[in, drm_mode_get_encoder])

drm_mode_get_encoder {
# TODO: where does one get these?
	encoder_id	int32
# Outputs:
	encoder_type	const[0, int32]
	crtc_id		const[0, int32]
	possible_crtcs	const[0, int32]
	possible_clones	const[0, int32]
}

ioctl$DRM_IOCTL_MODE_GETCONNECTOR(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETCONNECTOR], arg ptr[in, drm_mode_get_connector])

drm_mode_get_connector {
# Everything except for connector_id are outputs.
	encoders_ptr		ptr64[out, array[int32]]
	modes_ptr		ptr64[out, array[int32]]
	props_ptr		ptr64[out, array[int32]]
	prop_values_ptr		ptr64[out, array[int32]]
	count_modes		len[modes_ptr, int32]
	count_props		len[props_ptr, int32]
	count_encoders		len[count_modes, int32]
	encoder_id		const[0, int32]
# TODO: where does one get these?
	connector_id		int32
	connector_type		const[0, int32]
	connector_type_id	const[0, int32]
	connection		const[0, int32]
	mm_width		const[0, int32]
	mm_height		const[0, int32]
	subpixel		const[0, int32]
	pad			const[0, int32]
}

ioctl$DRM_IOCTL_MODE_GETPROPERTY(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETPROPERTY], arg ptr[in, drm_mode_get_property])
ioctl$DRM_IOCTL_MODE_SETPROPERTY(fd fd_dri, cmd const[DRM_IOCTL_MODE_SETPROPERTY], arg ptr[in, drm_mode_connector_set_property])
ioctl$DRM_IOCTL_MODE_GETPROPBLOB(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETPROPBLOB], arg ptr[in, drm_mode_get_blob])
ioctl$DRM_IOCTL_MODE_OBJ_GETPROPERTIES(fd fd_dri, cmd const[DRM_IOCTL_MODE_OBJ_GETPROPERTIES], arg ptr[in, drm_mode_obj_get_properties])
ioctl$DRM_IOCTL_MODE_OBJ_SETPROPERTY(fd fd_dri, cmd const[DRM_IOCTL_MODE_OBJ_SETPROPERTY], arg ptr[in, drm_mode_obj_set_property])
ioctl$DRM_IOCTL_MODE_CREATEPROPBLOB(fd fd_dri, cmd const[DRM_IOCTL_MODE_CREATEPROPBLOB], arg ptr[inout, drm_mode_create_blob])
ioctl$DRM_IOCTL_MODE_DESTROYPROPBLOB(fd fd_dri, cmd const[DRM_IOCTL_MODE_DESTROYPROPBLOB], arg ptr[in, drm_mode_destroy_blob])

drm_mode_get_property {
	values_ptr		ptr64[out, array[int64]]
	enum_blob_ptr		ptr64[out, array[drm_mode_property_enum]]
# TODO: where does one get these?
	prop_id			int32
	flags			const[0, int32]
	name			array[const[0, int8], DRM_PROP_NAME_LEN]
	count_values		len[values_ptr, int32]
	count_enum_blobs	len[enum_blob_ptr, int32]
}

drm_mode_property_enum {
	value	int64
	name	array[const[0, int8], DRM_PROP_NAME_LEN]
}

drm_mode_connector_set_property {
	value		int64
	prop_id		int32
	connector_id	int32
}

drm_mode_obj_set_property {
	value		int64
	prop_id		int32
	obj_id		int32
	obj_type	flags[drm_obj_type, int32]
}

drm_obj_type = DRM_MODE_OBJECT_CRTC, DRM_MODE_OBJECT_CONNECTOR, DRM_MODE_OBJECT_ENCODER, DRM_MODE_OBJECT_MODE, DRM_MODE_OBJECT_PROPERTY, DRM_MODE_OBJECT_FB, DRM_MODE_OBJECT_BLOB, DRM_MODE_OBJECT_PLANE, DRM_MODE_OBJECT_ANY

drm_mode_obj_get_properties {
	props_ptr	ptr64[in, array[int32]]
# NEED: this should be the same size as props_ptr.
	prop_values_ptr	ptr64[out, array[int64]]
	count_props	len[props_ptr, int32]
	obj_id		int32
	obj_type	flags[drm_obj_type, int32]
}

# TODO: are there pre-existing blobs? what ids do they have?
resource drm_blob_id[int32]: 0, 1, 2

drm_mode_get_blob {
	blob_id	drm_blob_id
	length	len[data, int32]
	data	ptr64[out, array[int8]]
}

drm_mode_create_blob {
	data	ptr64[in, array[int8]]
	length	len[data, int32]
	blob_id	drm_blob_id	(out)
}

drm_mode_destroy_blob {
	blob_id	drm_blob_id
}

ioctl$DRM_IOCTL_MODE_GETFB(fd fd_dri, cmd const[DRM_IOCTL_MODE_GETFB], arg ptr[in, drm_mode_fb_cmd])
ioctl$DRM_IOCTL_MODE_ADDFB(fd fd_dri, cmd const[DRM_IOCTL_MODE_ADDFB], arg ptr[in, drm_mode_fb_cmd])
ioctl$DRM_IOCTL_MODE_ADDFB2(fd fd_dri, cmd const[DRM_IOCTL_MODE_ADDFB2], arg ptr[in, drm_mode_fb_cmd2])

drm_mode_fb_cmd {
	fb_id	drm_fb_id
	width	int32
	height	int32
	pitch	int32
	bpp	int32
	depth	int32
	handle	int32
}

drm_mode_fb_cmd2 {
	fb_id		drm_fb_id
	width		int32
	height		int32
	pixel_format	int32
	flags		flags[drm_mode_fb_flags, int32]
	handles		array[int32, 4]
	pitches		array[int32, 4]
	offsets		array[int32, 4]
	modifier	array[int64, 4]
}

drm_mode_fb_flags = DRM_MODE_FB_INTERLACED, DRM_MODE_FB_MODIFIERS

ioctl$DRM_IOCTL_MODE_RMFB(fd fd_dri, cmd const[DRM_IOCTL_MODE_RMFB], arg ptr[in, drm_fb_id])
ioctl$DRM_IOCTL_MODE_PAGE_FLIP(fd fd_dri, cmd const[DRM_IOCTL_MODE_PAGE_FLIP], arg ptr[in, drm_mode_crtc_page_flip_target])

drm_mode_crtc_page_flip_target {
	crtc_id		drm_crtc_id
	fb_id		drm_fb_id
	flags		flags[drm_page_flip_flags, int32]
	sequence	int32
	user_data	int64
}

drm_page_flip_flags = DRM_MODE_PAGE_FLIP_EVENT, DRM_MODE_PAGE_FLIP_ASYNC, DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE, DRM_MODE_PAGE_FLIP_TARGET_RELATIVE

ioctl$DRM_IOCTL_MODE_DIRTYFB(fd fd_dri, cmd const[DRM_IOCTL_MODE_DIRTYFB], arg ptr[in, drm_mode_fb_dirty_cmd])

drm_mode_fb_dirty_cmd {
	fb_id		drm_fb_id
	flags		flags[drm_mode_fb_dirty_flags, int32]
	color		int32
	num_clips	len[clips_ptr, int32]
	clips_ptr	ptr64[in, array[drm_clip_rect]]
}

drm_clip_rect {
	x1	int16
	y1	int16
	x2	int16
	y2	int16
}

drm_mode_fb_dirty_flags = DRM_MODE_FB_DIRTY_ANNOTATE_COPY, DRM_MODE_FB_DIRTY_ANNOTATE_FILL

ioctl$DRM_IOCTL_MODE_CREATE_DUMB(fd fd_dri, cmd const[DRM_IOCTL_MODE_CREATE_DUMB], arg ptr[inout, drm_mode_create_dumb])
ioctl$DRM_IOCTL_MODE_MAP_DUMB(fd fd_dri, cmd const[DRM_IOCTL_MODE_MAP_DUMB], arg ptr[inout, drm_mode_map_dumb])
ioctl$DRM_IOCTL_MODE_DESTROY_DUMB(fd fd_dri, cmd const[DRM_IOCTL_MODE_DESTROY_DUMB], arg ptr[in, drm_mode_destroy_dumb])

resource drm_dumb_handle[int32]

drm_mode_create_dumb {
	height	int32	(in)
	width	int32	(in)
	bpp	int32	(in)
# flags does not seem to be used by any driver.
	flags	const[0, int32]
	handle	drm_dumb_handle	(out)
	pitch	int32	(out)
	size	int64	(out)
}

drm_mode_map_dumb {
	handle	drm_dumb_handle	(in)
	pad	const[0, int32]
	offset	int64	(out)
}

drm_mode_destroy_dumb {
	handle	drm_dumb_handle
}

ioctl$DRM_IOCTL_MODE_ATOMIC(fd fd_dri, cmd const[DRM_IOCTL_MODE_ATOMIC], arg ptr[in, drm_mode_atomic])

drm_mode_atomic {
	flags		flags[drm_mode_atomic_flags, int32]
	count_objs	len[objs_ptr, int32]
	objs_ptr	ptr64[in, array[int32]]
# NEED: this array is probably parallel to objs_ptr.
	count_props_ptr	ptr64[in, array[int32]]
	props_ptr	ptr64[in, array[int32]]
	prop_values_ptr	ptr64[in, array[int32]]
	reserved	const[0, int64]
	user_data	int64
}

drm_mode_atomic_flags = DRM_MODE_PAGE_FLIP_EVENT, DRM_MODE_ATOMIC_TEST_ONLY, DRM_MODE_ATOMIC_NONBLOCK, DRM_MODE_ATOMIC_ALLOW_MODESET

# TODO: describe SYNCOBJ ioctls (but we don't have any DRIVER_SYNCOBJ hardware).
#resource drm_syncobj[int32]

#ioctl$DRM_IOCTL_SYNCOBJ_CREATE(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_CREATE], arg ptr[in, drm_syncobj_create])
#ioctl$DRM_IOCTL_SYNCOBJ_DESTROY(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_DESTROY], arg ptr[in, drm_syncobj_destroy])
#ioctl$DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_TRANSFER(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_TRANSFER], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_WAIT(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_WAIT], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_RESET(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_RESET], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_SIGNAL(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_SIGNAL], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_SYNCOBJ_QUERY(fd fd_dri, cmd const[DRM_IOCTL_SYNCOBJ_QUERY], arg ptr[in, XXXXX])

#drm_syncobj_create {
#	handle drm_syncobj[opt]
#	flags	bool32
#}

#drm_syncobj_destroy {
#	handle drm_syncobj
#	pad const[0, int32]
#}

# TODO: describe SEQUENCE ioctls (but we don't have DRIVER_MODESET hardware).
#ioctl$DRM_IOCTL_CRTC_GET_SEQUENCE(fd fd_dri, cmd const[DRM_IOCTL_CRTC_GET_SEQUENCE], arg ptr[in, XXXXX])
#ioctl$DRM_IOCTL_CRTC_QUEUE_SEQUENCE(fd fd_dri, cmd const[DRM_IOCTL_CRTC_QUEUE_SEQUENCE], arg ptr[in, XXXXX])

ioctl$DRM_IOCTL_MODE_CREATE_LEASE(fd fd_dri, cmd const[DRM_IOCTL_MODE_CREATE_LEASE], arg ptr[inout, drm_mode_create_lease])
ioctl$DRM_IOCTL_MODE_LIST_LESSEES(fd fd_dri, cmd const[DRM_IOCTL_MODE_LIST_LESSEES], arg ptr[in, drm_mode_list_lessees])
ioctl$DRM_IOCTL_MODE_GET_LEASE(fd fd_dri, cmd const[DRM_IOCTL_MODE_GET_LEASE], arg ptr[in, drm_mode_get_lease])
ioctl$DRM_IOCTL_MODE_REVOKE_LEASE(fd fd_dri, cmd const[DRM_IOCTL_MODE_REVOKE_LEASE], arg ptr[in, drm_mode_revoke_lease])

resource drm_lessee_id[int32]

drm_mode_create_lease {
# TODO: what are these "object ids"? where does one get these?
	object_ids	ptr64[in, array[int32]]	(in)
	object_count	len[object_ids, int32]	(in)
	flags		flags[drm_mode_create_lease_flag, int32]	(in)
	lessee_id	drm_lessee_id	(out)
	fd		fd	(out)
}

drm_mode_create_lease_flag = O_CLOEXEC, O_NONBLOCK

drm_mode_list_lessees {
	count_lessees	len[lessees_ptr, int32]
	pad		const[0, int32]
	lessees_ptr	ptr64[out, array[drm_lessee_id]]
}

drm_mode_get_lease {
	count_objects	len[objects_ptr, int32]
	pad		const[0, int32]
	objects_ptr	ptr64[out, array[int32]]
}

drm_mode_revoke_lease {
	lessee_id	drm_lessee_id
}

drm_version {
	maj	int32
	min	int32
	patch	int32
	namelen	len[name, intptr]
	name	buffer[out]
	datelen	len[date, intptr]
	date	buffer[out]
	desclen	len[desc, intptr]
	desc	buffer[out]
}

drm_unique_in {
	len	len[uni, intptr]
	uni	buffer[in]
}

drm_unique_out {
	len	len[uni, intptr]
	uni	buffer[out]
}

drm_irq_busid {
	irq	int32
	bus	int32
	dev	int32
	func	int32
}

drm_map$DRM_IOCTL_GET_MAP {
	off	vma	(inout)
	size	intptr	(out)
	type	int32	(out)
	flags	int32	(out)
	handle	vma	(out)
	mtrr	int32	(out)
}

drm_map$DRM_IOCTL_ADD_MAP {
	off	vma	(in)
	size	intptr	(in)
	type	flags[drm_map_type, int32]	(in)
	flags	flags[drm_map_flags, int32]	(in)
	handle	vma	(out)
	mtrr	int32	(out)
}

drm_map$DRM_IOCTL_RM_MAP {
# Only handle is used.
	off	const[0, intptr]
	size	const[0, intptr]
	type	const[0, int32]
	flags	const[0, int32]
	handle	vma
	mtrr	const[0, int32]
}

drm_client {
	idx	int32
	auth	int32
	pid	alignptr[pid]
	uid	alignptr[uid]
	magic	intptr
	iocs	intptr
}

drm_get_cap {
	cap	flags[drm_cap, int64]
	val	const[0, int64]
}

drm_cap = DRM_CAP_DUMB_BUFFER, DRM_CAP_VBLANK_HIGH_CRTC, DRM_CAP_DUMB_PREFERRED_DEPTH, DRM_CAP_DUMB_PREFER_SHADOW, DRM_CAP_PRIME, DRM_PRIME_CAP_IMPORT, DRM_PRIME_CAP_EXPORT, DRM_CAP_TIMESTAMP_MONOTONIC, DRM_CAP_ASYNC_PAGE_FLIP, DRM_CAP_CURSOR_WIDTH, DRM_CAP_CURSOR_HEIGHT, DRM_CAP_ADDFB2_MODIFIERS, DRM_CAP_PAGE_FLIP_TARGET, DRM_CAP_CRTC_IN_VBLANK_EVENT, DRM_CAP_SYNCOBJ, DRM_CAP_SYNCOBJ_TIMELINE

drm_set_version {
	di_maj	int32
	di_min	int32
	dd_maj	int32
	dd_min	int32
}

drm_ctx_priv_map {
	ctxid	drmctx
	handle	buffer[out]
}

drm_ctx {
	handle	drmctx
	flags	flags[drm_ctx_flags, int32]
}

drm_ctx_res {
	count	len[context, int32]
	context	ptr[out, array[drm_ctx]]
}

drm_lock {
	context	drmctx
	flags	flags[drm_lock_flags, int32]
}

drm_buf_desc {
	count	int32
	size	int32
	lomark	int32
	himark	int32
	flags	flags[drm_buf_flags, int32]
# TODO: what is agp addresses? should it be a special type?
	agpaddr	intptr
}

drm_buf_map {
	count	len[list, int32]
	virtual	buffer[out]
	list	ptr[in, array[drm_buf_pub]]
}

drm_buf_pub {
	idx	int32
	total	len[addr, int32]
	used	int32
	addr	buffer[out]
}

drm_buf_free {
	count	len[list, int32]
	list	ptr[in, array[int32]]
}

drm_dma {
	context	drmctx
	sendcnt	len[sendind, int32]
	sendind	ptr[in, array[int32]]
	sendsiz	ptr[in, array[int32]]
	flags	flags[drm_dma_flags, int32]
	reqcnd	len[reqind, int32]
	reqsiz0	int32
	reqind	ptr[in, array[int32]]
	reqsiz	ptr[in, array[int32]]
	granted	const[0, int32]
}

drm_control {
	func	flags[drm_control_type, int32]
	irq	int32
}

drm_agp_buffer$DRM_IOCTL_AGP_ALLOC {
	size	intptr	(in)
	handle	drm_agp_handle	(out)
	type	flags[drm_agp_mem_type, intptr]	(in)
	physic	intptr	(out)
}

drm_agp_buffer$DRM_IOCTL_AGP_FREE {
# Only handle is used.
	size	const[0, intptr]
	handle	drm_agp_handle
	type	const[0, intptr]
	physic	const[0, intptr]
}

drm_agp_binding {
	handle	drm_agp_handle
	offset	intptr
}

drm_scatter_gather {
	size	intptr
	handle	drm_agp_handle
}

drm_wait_vblank {
	type	flags[drm_vblank_seq_type, int32]
	seq	int32
	signal	signalno
}

drm_modeset_ctl {
	crtc	int32
	cmd	int32
}

drm_gem_open {
	name	drm_gem_name	(in)
	handle	drm_gem_handle	(out)
	size	int64	(out)
}

drm_gem_close {
	handle	drm_gem_handle
	pad	const[0, int32]
}

drm_gem_flink {
	handle	drm_gem_handle	(in)
	name	drm_gem_name	(out)
}

drm_mode_card_res {
	fbid	ptr64[out, array[int32]]
	crtcid	ptr64[out, array[int32]]
	connid	ptr64[out, array[int32]]
	encid	ptr64[out, array[int32]]
	nfbid	len[fbid, int32]
	ncrtcid	len[crtcid, int32]
	nconnid	len[connid, int32]
	nencid	len[encid, int32]
	maxw	const[0, int32]
	maxh	const[0, int32]
	minw	const[0, int32]
	minh	const[0, int32]
}

drm_prime_handle$DRM_IOCTL_PRIME_HANDLE_TO_FD {
	handle	drm_gem_handle	(in)
	flags	flags[dup_flags, int32]	(in)
	fd	fd_dri	(out)
}

drm_prime_handle$DRM_IOCTL_PRIME_FD_TO_HANDLE {
	handle	drm_gem_handle	(out)
	flags	const[0, int32]
	fd	fd_dri	(in)
}

drm_mode_crtc {
	set_connectors_ptr	ptr64[in, array[int32]]
	count_connectors	len[set_connectors_ptr, int32]
	crtc_id			drm_crtc_id
	fb_id			drm_fb_id
	x			int32
	y			int32
	gamma_size		int32
	mode_valid		int32
	mode			drm_mode_modeinfo
}

drm_mode_modeinfo {
	clock	int32
	hdisp	int16
	hsyncs	int16
	hsynce	int16
	htotal	int16
	hskew	int16
	vdisp	int16
	vsyncs	int16
	vsynce	int16
	vtotal	int16
	vscan	int16
	vrefr	int16
	flag	int32
	type	int32
	name	array[int8, DRM_DISPLAY_MODE_LEN]
}

drm_agp_mem_type = 0, 1, 2, AGP_USER_MEMORY, AGP_USER_CACHED_MEMORY
drm_map_type = _DRM_FRAME_BUFFER, _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, _DRM_SCATTER_GATHER, _DRM_CONSISTENT
drm_map_flags = _DRM_RESTRICTED, _DRM_READ_ONLY, _DRM_LOCKED, _DRM_KERNEL, _DRM_WRITE_COMBINING, _DRM_CONTAINS_LOCK, _DRM_REMOVABLE, _DRM_DRIVER
drm_ctx_flags = _DRM_CONTEXT_PRESERVED, _DRM_CONTEXT_2DONLY
drm_lock_flags = _DRM_LOCK_READY, _DRM_LOCK_QUIESCENT, _DRM_LOCK_FLUSH, _DRM_LOCK_FLUSH_ALL, _DRM_HALT_ALL_QUEUES, _DRM_HALT_CUR_QUEUES
drm_buf_flags = _DRM_PAGE_ALIGN, _DRM_AGP_BUFFER, _DRM_SG_BUFFER, _DRM_FB_BUFFER, _DRM_PCI_BUFFER_RO
drm_dma_flags = _DRM_DMA_BLOCK, _DRM_DMA_WHILE_LOCKED, _DRM_DMA_PRIORITY, _DRM_DMA_WAIT, _DRM_DMA_SMALLER_OK, _DRM_DMA_LARGER_OK
drm_control_type = DRM_ADD_COMMAND, DRM_RM_COMMAND, DRM_INST_HANDLER, DRM_UNINST_HANDLER
drm_vblank_seq_type = _DRM_VBLANK_ABSOLUTE, _DRM_VBLANK_RELATIVE, _DRM_VBLANK_HIGH_CRTC_MASK, _DRM_VBLANK_EVENT, _DRM_VBLANK_FLIP, _DRM_VBLANK_NEXTONMISS, _DRM_VBLANK_SECONDARY, _DRM_VBLANK_SIGNAL