drm/ffi/
drm.rs

1/*
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26use libc::*;
27use byteorder::{ByteOrder, NativeEndian};
28
29use ffi::util::*;
30
31pub const DRM_NAME: &'static str = "drm";	        /**< Name in kernel, /dev, and /proc */
32pub const DRM_MIN_ORDER: c_int = 5;        /**< At least 2^5 bytes = 32 bytes */
33pub const DRM_MAX_ORDER: u8	= 22;	    /**< Up to 2^22 bytes = 4MB */
34pub const DRM_RAM_PERCENT: c_int = 10;	    /**< How much system ram can we lock? */
35
36pub type drm_context_t = c_uint;
37pub type drm_drawable_t = c_uint;
38pub type drm_magic_t = c_uint;
39
40/**
41 * Cliprect.
42 *
43 * \warning: If you change this structure, make sure you change
44 * XF86DRIClipRectRec in the server as well
45 *
46 * \note KW: Actually it's illegal to change either for
47 * backwards-compatibility reasons.
48 */
49 #[repr(C)]
50pub struct drm_clip_rect {
51	x1: c_ushort,
52	y1: c_ushort,
53	x2: c_ushort,
54	y2: c_ushort
55}
56impl ::std::default::Default for drm_clip_rect {
57    fn default() -> drm_clip_rect { unsafe { ::std::mem::zeroed() } }
58}
59
60
61/**
62 * Drawable information.
63 */
64 #[repr(C)]
65pub struct drm_drawable_info {
66	num_rects: c_uint,
67	rects: *mut drm_clip_rect
68}
69impl ::std::default::Default for drm_drawable_info {
70    fn default() -> drm_drawable_info { unsafe { ::std::mem::zeroed() } }
71}
72
73
74/**
75 * Texture region,
76 */
77#[repr(C)]
78pub struct drm_tex_region {
79	next: c_uchar,
80	prev: c_uchar,
81	in_use: c_uchar,
82	padding: c_uchar,
83	age: c_uint
84}
85impl ::std::default::Default for drm_tex_region {
86    fn default() -> drm_tex_region { unsafe { ::std::mem::zeroed() } }
87}
88
89
90/**
91 * Hardware lock.
92 *
93 * The lock structure is a simple cache-line aligned integer.  To avoid
94 * processor bus contention on a multiprocessor system, there should not be any
95 * other data stored in the same cache line.
96 */
97#[repr(C)]
98pub struct drm_hw_lock {
99	lock: VolatileCell<c_uint>,		/**< lock variable */
100	padding: [c_char; 60]
101}
102impl ::std::default::Default for drm_hw_lock {
103    fn default() -> drm_hw_lock { unsafe { ::std::mem::zeroed() } }
104}
105
106
107/**
108 * DRM_IOCTL_VERSION ioctl argument type.
109 *
110 * \sa drmGetVersion().
111 */
112#[repr(C)]
113pub struct drm_version {
114	version_major: c_int,	  /**< Major version */
115	version_minor: c_int,	  /**< Minor version */
116	version_patchlevel: c_int,	  /**< Patch level */
117	name_len: KernelSizeT,	  /**< Length of name buffer */
118	name: *mut c_char,	  /**< Name of driver */
119	date_len: KernelSizeT,	  /**< Length of date buffer */
120	date: *mut c_char,	  /**< User-space buffer to hold date */
121	desc_len: KernelSizeT,	  /**< Length of desc buffer */
122	desc: *mut c_char
123}
124impl ::std::default::Default for drm_version {
125    fn default() -> drm_version { unsafe { ::std::mem::zeroed() } }
126}
127
128
129/**
130 * DRM_IOCTL_GET_UNIQUE ioctl argument type.
131 *
132 * \sa drmGetBusid() and drmSetBusId().
133 */
134#[repr(C)]
135pub struct drm_unique {
136	unique_len: KernelSizeT,	  /**< Length of unique */
137	unique: *mut c_char
138}
139impl ::std::default::Default for drm_unique {
140    fn default() -> drm_unique { unsafe { ::std::mem::zeroed() } }
141}
142
143
144#[repr(C)]
145pub struct drm_list {
146	count: c_int,		  /**< Length of user-space structures */
147	version: *mut drm_version
148}
149impl ::std::default::Default for drm_list {
150    fn default() -> drm_list { unsafe { ::std::mem::zeroed() } }
151}
152
153
154#[repr(C)]
155pub struct drm_block {
156	unused: c_int
157}
158impl ::std::default::Default for drm_block {
159    fn default() -> drm_block { unsafe { ::std::mem::zeroed() } }
160}
161
162
163#[repr(C)]
164pub enum drm_control_func {
165    DRM_ADD_COMMAND,
166    DRM_RM_COMMAND,
167    DRM_INST_HANDLER,
168    DRM_UNINST_HANDLER
169}
170
171/**
172 * DRM_IOCTL_CONTROL ioctl argument type.
173 *
174 * \sa drmCtlInstHandler() and drmCtlUninstHandler().
175 */
176#[repr(C)]
177pub struct drm_control {
178	func: drm_control_func,
179	irq: c_int
180}
181impl ::std::default::Default for drm_control {
182    fn default() -> drm_control { unsafe { ::std::mem::zeroed() } }
183}
184
185
186/**
187 * Type of memory to map.
188 */
189 #[repr(C)]
190pub enum drm_map_type {
191	_DRM_FRAME_BUFFER = 0,	  /**< WC (no caching), no core dump */
192	_DRM_REGISTERS = 1,	  /**< no caching, no core dump */
193	_DRM_SHM = 2,		  /**< shared, cached */
194	_DRM_AGP = 3,		  /**< AGP/GART */
195	_DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
196	_DRM_CONSISTENT = 5
197}
198
199/**
200 * Memory mapping flags.
201 */
202 #[repr(C)]
203pub enum drm_map_flags {
204	_DRM_RESTRICTED = 0x01,	     /**< Cannot be mapped to user-virtual */
205	_DRM_READ_ONLY = 0x02,
206	_DRM_LOCKED = 0x04,	     /**< shared, cached, locked */
207	_DRM_KERNEL = 0x08,	     /**< kernel requires access */
208	_DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
209	_DRM_CONTAINS_LOCK = 0x20,   /**< SHM page that contains lock */
210	_DRM_REMOVABLE = 0x40,	     /**< Removable mapping */
211	_DRM_DRIVER = 0x80
212}
213
214#[repr(C)]
215pub struct drm_ctx_priv_map {
216	ctx_id: c_uint,	 /**< Context requesting private mapping */
217	handle: *mut c_void
218}
219impl ::std::default::Default for drm_ctx_priv_map {
220    fn default() -> drm_ctx_priv_map { unsafe { ::std::mem::zeroed() } }
221}
222
223
224/**
225 * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
226 * argument type.
227 *
228 * \sa drmAddMap().
229 */
230#[repr(C)]
231pub struct drm_map {
232	offset: c_ulong,	 /**< Requested physical address (0 for SAREA)*/
233	size: c_ulong,	 /**< Requested physical size (bytes) */
234	map_type: drm_map_type,	 /**< Type of memory to map */
235	flags: drm_map_flags,	 /**< Flags */
236	handle: *mut c_void,		 /**< User-space: "Handle" to pass to mmap() */
237				 /**< Kernel-space: kernel-virtual address */
238	mtrr: c_int
239}
240impl ::std::default::Default for drm_map {
241    fn default() -> drm_map { unsafe { ::std::mem::zeroed() } }
242}
243
244
245/**
246 * DRM_IOCTL_GET_CLIENT ioctl argument type.
247 */
248#[repr(C)]
249pub struct drm_client {
250	idx: c_int,		/**< Which client desired? */
251	auth: c_int,		/**< Is client authenticated? */
252	pid: c_ulong,	/**< Process ID */
253	uid: c_ulong,	/**< User ID */
254	magic: c_ulong,	/**< Magic */
255	iocs: c_ulong
256}
257impl ::std::default::Default for drm_client {
258    fn default() -> drm_client { unsafe { ::std::mem::zeroed() } }
259}
260
261
262#[repr(C)]
263pub enum drm_stat_type {
264	_DRM_STAT_LOCK,
265	_DRM_STAT_OPENS,
266	_DRM_STAT_CLOSES,
267	_DRM_STAT_IOCTLS,
268	_DRM_STAT_LOCKS,
269	_DRM_STAT_UNLOCKS,
270	_DRM_STAT_VALUE,	/**< Generic value */
271	_DRM_STAT_BYTE,		/**< Generic byte counter (1024bytes/K) */
272	_DRM_STAT_COUNT,	/**< Generic non-byte counter (1000/k) */
273
274	_DRM_STAT_IRQ,		/**< IRQ */
275	_DRM_STAT_PRIMARY,	/**< Primary DMA bytes */
276	_DRM_STAT_SECONDARY,	/**< Secondary DMA bytes */
277	_DRM_STAT_DMA,		/**< DMA */
278	_DRM_STAT_SPECIAL,	/**< Special DMA (e.g., priority or polled) */
279	_DRM_STAT_MISSED
280}
281
282#[repr(C)]
283pub struct drm_stats_data {
284    value: c_ulong,
285    stat_type: drm_stat_type
286}
287impl ::std::default::Default for drm_stats_data {
288    fn default() -> drm_stats_data { unsafe { ::std::mem::zeroed() } }
289}
290
291
292/**
293 * DRM_IOCTL_GET_STATS ioctl argument type.
294 */
295#[repr(C)]
296pub struct drm_stats {
297	count: c_ulong,
298	data: [drm_stats_data; 15]
299}
300impl ::std::default::Default for drm_stats {
301    fn default() -> drm_stats { unsafe { ::std::mem::zeroed() } }
302}
303
304
305/**
306 * Hardware locking flags.
307 */
308#[repr(C)]
309pub enum drm_lock_flags {
310	_DRM_LOCK_READY = 0x01,	     /**< Wait until hardware is ready for DMA */
311	_DRM_LOCK_QUIESCENT = 0x02,  /**< Wait until hardware quiescent */
312	_DRM_LOCK_FLUSH = 0x04,	     /**< Flush this context's DMA queue first */
313	_DRM_LOCK_FLUSH_ALL = 0x08,  /**< Flush all DMA queues first */
314	/* These *HALT* flags aren't supported yet
315	   -- they will be used to support the
316	   full-screen DGA-like mode. */
317	_DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
318	_DRM_HALT_CUR_QUEUES = 0x20
319}
320
321/**
322 * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
323 *
324 * \sa drmGetLock() and drmUnlock().
325 */
326#[repr(C)]
327pub struct drm_lock {
328	context: c_int,
329	flags: drm_lock_flags
330}
331impl ::std::default::Default for drm_lock {
332    fn default() -> drm_lock { unsafe { ::std::mem::zeroed() } }
333}
334
335
336/**
337 * DMA flags
338 *
339 * \warning
340 * These values \e must match xf86drm.h.
341 *
342 * \sa drm_dma.
343 */
344#[repr(C)]
345pub enum drm_dma_flags {
346	/* Flags for DMA buffer dispatch */
347	_DRM_DMA_BLOCK = 0x01,	      /**<
348				       * Block until buffer dispatched.
349				       *
350				       * \note The buffer may not yet have
351				       * been processed by the hardware --
352				       * getting a hardware lock with the
353				       * hardware quiescent will ensure
354				       * that the buffer has been
355				       * processed.
356				       */
357	_DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
358	_DRM_DMA_PRIORITY = 0x04,     /**< High priority dispatch */
359
360	/* Flags for DMA buffer request */
361	_DRM_DMA_WAIT = 0x10,	      /**< Wait for free buffers */
362	_DRM_DMA_SMALLER_OK = 0x20,   /**< Smaller-than-requested buffers OK */
363	_DRM_DMA_LARGER_OK = 0x40
364}
365
366#[repr(C)]
367pub enum drm_buf_desc_flags {
368    _DRM_PAGE_ALIGN = 0x01,	/**< Align on page boundaries for DMA */
369    _DRM_AGP_BUFFER = 0x02,	/**< Buffer is in AGP space */
370    _DRM_SG_BUFFER = 0x04,	/**< Scatter/gather memory buffer */
371    _DRM_FB_BUFFER = 0x08,	/**< Buffer is in frame buffer */
372    _DRM_PCI_BUFFER_RO = 0x10
373}
374
375/**
376 * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
377 *
378 * \sa drmAddBufs().
379 */
380#[repr(C)]
381pub struct drm_buf_desc {
382	count: c_int,		 /**< Number of buffers of this size */
383	size: c_int,		 /**< Size in bytes */
384	low_mark: c_int,		 /**< Low water mark */
385	high_mark: c_int,		 /**< High water mark */
386	flags: drm_buf_desc_flags,
387	agp_start: c_ulong
388}
389impl ::std::default::Default for drm_buf_desc {
390    fn default() -> drm_buf_desc { unsafe { ::std::mem::zeroed() } }
391}
392
393
394/**
395 * DRM_IOCTL_INFO_BUFS ioctl argument type.
396 */
397#[repr(C)]
398pub struct drm_buf_info {
399	count: c_int,		/**< Entries in list */
400	list: *mut drm_buf_desc
401}
402impl ::std::default::Default for drm_buf_info {
403    fn default() -> drm_buf_info { unsafe { ::std::mem::zeroed() } }
404}
405
406
407/**
408 * DRM_IOCTL_FREE_BUFS ioctl argument type.
409 */
410#[repr(C)]
411pub struct drm_buf_free {
412	count: c_int,
413	list: *mut c_int
414}
415impl ::std::default::Default for drm_buf_free {
416    fn default() -> drm_buf_free { unsafe { ::std::mem::zeroed() } }
417}
418
419
420/**
421 * Buffer information
422 *
423 * \sa drm_buf_map.
424 */
425#[repr(C)]
426pub struct drm_buf_pub {
427	idx: c_int,		       /**< Index into the master buffer list */
428	total: c_int,		       /**< Buffer size */
429	used: c_int,		       /**< Amount of buffer in use (for DMA) */
430	address: *mut c_void
431}
432impl ::std::default::Default for drm_buf_pub {
433    fn default() -> drm_buf_pub { unsafe { ::std::mem::zeroed() } }
434}
435
436
437/**
438 * DRM_IOCTL_MAP_BUFS ioctl argument type.
439 */
440#[repr(C)]
441pub struct drm_buf_map {
442	count: c_int,		/**< Length of the buffer list */
443	virtual_address: *mut c_void,		/**< Mmap'd area in user-virtual */
444	list: *mut drm_buf_pub
445}
446impl ::std::default::Default for drm_buf_map {
447    fn default() -> drm_buf_map { unsafe { ::std::mem::zeroed() } }
448}
449
450
451/**
452 * DRM_IOCTL_DMA ioctl argument type.
453 *
454 * Indices here refer to the offset into the buffer list in drm_buf_get.
455 *
456 * \sa drmDMA().
457 */
458#[repr(C)]
459pub struct drm_dma {
460	context: c_int,			  /**< Context handle */
461	send_count: c_int,			  /**< Number of buffers to send */
462	send_indices: *mut c_int,	  /**< List of handles to buffers */
463	send_sizes: *mut c_int,		  /**< Lengths of data to send */
464	flags: drm_dma_flags,	  /**< Flags */
465	request_count: c_int,		  /**< Number of buffers requested */
466	request_size: c_int,		  /**< Desired size for buffers */
467	request_indices: *mut c_int,	  /**< Buffer information */
468	request_sizes: *mut c_int,
469	granted_count: c_int
470}
471impl ::std::default::Default for drm_dma {
472    fn default() -> drm_dma { unsafe { ::std::mem::zeroed() } }
473}
474
475
476#[repr(C)]
477pub enum drm_ctx_flags {
478	_DRM_CONTEXT_PRESERVED = 0x01,
479	_DRM_CONTEXT_2DONLY = 0x02
480}
481
482/**
483 * DRM_IOCTL_ADD_CTX ioctl argument type.
484 *
485 * \sa drmCreateContext() and drmDestroyContext().
486 */
487#[repr(C)]
488pub struct drm_ctx {
489	handle: drm_context_t,
490	flags: drm_ctx_flags
491}
492impl ::std::default::Default for drm_ctx {
493    fn default() -> drm_ctx { unsafe { ::std::mem::zeroed() } }
494}
495
496
497/**
498 * DRM_IOCTL_RES_CTX ioctl argument type.
499 */
500#[repr(C)]
501pub struct drm_ctx_res {
502	count: c_int,
503	contexts: *mut drm_ctx
504}
505impl ::std::default::Default for drm_ctx_res {
506    fn default() -> drm_ctx_res { unsafe { ::std::mem::zeroed() } }
507}
508
509
510/**
511 * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
512 */
513struct drm_draw {
514	handle: drm_drawable_t
515}
516
517/**
518 * DRM_IOCTL_UPDATE_DRAW ioctl argument type.
519 */
520#[repr(C)]
521pub enum drm_drawable_info_type_t {
522	DRM_DRAWABLE_CLIPRECTS
523}
524
525#[repr(C)]
526pub struct drm_update_draw {
527	handle: drm_drawable_t,
528	update_type: c_uint,
529	num: c_uint,
530	data: c_ulonglong
531}
532impl ::std::default::Default for drm_update_draw {
533    fn default() -> drm_update_draw { unsafe { ::std::mem::zeroed() } }
534}
535
536
537/**
538 * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
539 */
540#[repr(C)]
541pub struct drm_auth {
542	magic: drm_magic_t
543}
544impl ::std::default::Default for drm_auth {
545    fn default() -> drm_auth { unsafe { ::std::mem::zeroed() } }
546}
547
548
549/**
550 * DRM_IOCTL_IRQ_BUSID ioctl argument type.
551 *
552 * \sa drmGetInterruptFromBusID().
553 */
554#[repr(C)]
555pub struct drm_irq_busid {
556	irq: c_int,	/**< IRQ number */
557	busnum: c_int,	/**< bus number */
558	devnum: c_int,	/**< device number */
559	funcnum: c_int
560}
561impl ::std::default::Default for drm_irq_busid {
562    fn default() -> drm_irq_busid { unsafe { ::std::mem::zeroed() } }
563}
564
565
566#[repr(C)]
567pub enum drm_vblank_seq_type {
568	_DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
569	_DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
570	/* bits 1-6 are reserved for high crtcs */
571	_DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e,
572	_DRM_VBLANK_EVENT = 0x4000000,   /**< Send event instead of blocking */
573	_DRM_VBLANK_FLIP = 0x8000000,   /**< Scheduled buffer swap should flip */
574	_DRM_VBLANK_NEXTONMISS = 0x10000000,	/**< If missed, wait for next vblank */
575	_DRM_VBLANK_SECONDARY = 0x20000000,	/**< Secondary display controller */
576	_DRM_VBLANK_SIGNAL = 0x40000000
577}
578impl drm_vblank_seq_type {
579    fn from_u32(n: u32) -> drm_vblank_seq_type {
580        match n {
581            0x0         => drm_vblank_seq_type::_DRM_VBLANK_ABSOLUTE,
582            0x1         => drm_vblank_seq_type::_DRM_VBLANK_RELATIVE,
583            0x0000003e  => drm_vblank_seq_type::_DRM_VBLANK_HIGH_CRTC_MASK,
584            0x04000000  => drm_vblank_seq_type::_DRM_VBLANK_EVENT,
585            0x08000000  => drm_vblank_seq_type::_DRM_VBLANK_FLIP,
586            0x10000000  => drm_vblank_seq_type::_DRM_VBLANK_NEXTONMISS,
587            0x20000000  => drm_vblank_seq_type::_DRM_VBLANK_SECONDARY,
588            0x40000000  => drm_vblank_seq_type::_DRM_VBLANK_SIGNAL,
589            _           => drm_vblank_seq_type::_DRM_VBLANK_ABSOLUTE
590        }
591    }
592}
593pub const _DRM_VBLANK_HIGH_CRTC_SHIFT: c_int = 1;
594
595#[repr(C)]
596pub struct drm_wait_vblank_request {
597	request_type: drm_vblank_seq_type,
598	sequence: c_uint,
599	signal: c_ulong,
600}
601impl ::std::default::Default for drm_wait_vblank_request {
602    fn default() -> drm_wait_vblank_request { unsafe { ::std::mem::zeroed() } }
603}
604
605
606#[repr(C)]
607pub struct drm_wait_vblank_reply {
608	reply_type: drm_vblank_seq_type,
609	sequence: c_uint,
610	tval_sec: c_long,
611	tval_usec: c_long
612}
613impl ::std::default::Default for drm_wait_vblank_reply {
614    fn default() -> drm_wait_vblank_reply { unsafe { ::std::mem::zeroed() } }
615}
616
617
618/**
619 * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
620 *
621 * \sa drmWaitVBlank().
622 */
623#[repr(C)]
624pub struct drm_wait_vblank {
625	data: [u8; 24]
626}
627impl ::std::default::Default for drm_wait_vblank {
628    fn default() -> drm_wait_vblank { unsafe { ::std::mem::zeroed() } }
629}
630
631
632impl drm_wait_vblank {
633    #[cfg(target_pointer_width = "32")]
634    fn request (&self) -> drm_wait_vblank_request {
635        let req = drm_wait_vblank_request {
636            request_type: drm_vblank_seq_type::from_u32(NativeEndian::read_u32(&self.data[0..4])),
637            sequence: NativeEndian::read_u32(&self.data[5..8]),
638            signal: NativeEndian::read_u32(&self.data[9..16])
639        };
640
641        req
642    }
643
644    #[cfg(target_pointer_width = "32")]
645    fn reply (&self) -> drm_wait_vblank_reply {
646        let reply = drm_wait_vblank_reply {
647            reply_type: drm_vblank_seq_type::from_u32(NativeEndian::read_u32(&self.data[0..4])),
648            sequence: NativeEndian::read_u32(&self.data[5..8]),
649            tval_sec: NativeEndian::read_i32(&self.data[9..16]),
650            tval_usec: NativeEndian::read_i32(&self.data[17..24])
651        };
652
653        reply
654    }
655
656    #[cfg(target_pointer_width = "64")]
657    fn request (&self) -> drm_wait_vblank_request {
658        let req = drm_wait_vblank_request {
659            request_type: drm_vblank_seq_type::from_u32(NativeEndian::read_u32(&self.data[0..4])),
660            sequence: NativeEndian::read_u32(&self.data[5..8]),
661            signal: NativeEndian::read_u64(&self.data[9..16])
662        };
663
664        req
665    }
666
667    #[cfg(target_pointer_width = "64")]
668    fn reply (&self) -> drm_wait_vblank_reply {
669        let reply = drm_wait_vblank_reply {
670            reply_type: drm_vblank_seq_type::from_u32(NativeEndian::read_u32(&self.data[0..4])),
671            sequence: NativeEndian::read_u32(&self.data[5..8]),
672            tval_sec: NativeEndian::read_i64(&self.data[9..16]),
673            tval_usec: NativeEndian::read_i64(&self.data[17..24])
674        };
675
676        reply
677    }
678}
679
680pub const _DRM_PRE_MODESET: c_int = 1;
681pub const _DRM_POST_MODESET: c_int = 2;
682
683/**
684 * DRM_IOCTL_MODESET_CTL ioctl argument type
685 *
686 * \sa drmModesetCtl().
687 */
688#[repr(C)]
689pub struct drm_modeset_ctl {
690    crtc: u32,
691	cmd: u32
692}
693impl ::std::default::Default for drm_modeset_ctl {
694    fn default() -> drm_modeset_ctl { unsafe { ::std::mem::zeroed() } }
695}
696
697
698/**
699 * DRM_IOCTL_AGP_ENABLE ioctl argument type.
700 *
701 * \sa drmAgpEnable().
702 */
703#[repr(C)]
704pub struct drm_agp_mode {
705	mode: c_ulong
706}
707impl ::std::default::Default for drm_agp_mode {
708    fn default() -> drm_agp_mode { unsafe { ::std::mem::zeroed() } }
709}
710
711
712/**
713 * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
714 *
715 * \sa drmAgpAlloc() and drmAgpFree().
716 */
717#[repr(C)]
718pub struct drm_agp_buffer {
719	size: c_ulong,	/**< In bytes -- will round to page boundary */
720	handle: c_ulong,	/**< Used for binding / unbinding */
721	buffer_type: c_ulong,	/**< Type of memory to allocate */
722	physical: c_ulong
723}
724impl ::std::default::Default for drm_agp_buffer {
725    fn default() -> drm_agp_buffer { unsafe { ::std::mem::zeroed() } }
726}
727
728
729/**
730 * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
731 *
732 * \sa drmAgpBind() and drmAgpUnbind().
733 */
734#[repr(C)]
735pub struct drm_agp_binding {
736	handle: c_ulong,	/**< From drm_agp_buffer */
737	offset: c_ulong
738}
739impl ::std::default::Default for drm_agp_binding {
740    fn default() -> drm_agp_binding { unsafe { ::std::mem::zeroed() } }
741}
742
743
744/**
745 * DRM_IOCTL_AGP_INFO ioctl argument type.
746 *
747 * \sa drmAgpVersionMajor(), drmAgpVersionMinor(), drmAgpGetMode(),
748 * drmAgpBase(), drmAgpSize(), drmAgpMemoryUsed(), drmAgpMemoryAvail(),
749 * drmAgpVendorId() and drmAgpDeviceId().
750 */
751#[repr(C)]
752pub struct drm_agp_info {
753	agp_version_major: c_int,
754	agp_version_minor: c_int,
755	mode: c_ulong,
756	aperture_base: c_ulong,	/* physical address */
757	aperture_size: c_ulong,	/* bytes */
758	memory_allowed: c_ulong,	/* bytes */
759	memory_used: c_ulong,
760
761	/* PCI information */
762	id_vendor: c_ushort,
763	id_device: c_ushort
764}
765impl ::std::default::Default for drm_agp_info {
766    fn default() -> drm_agp_info { unsafe { ::std::mem::zeroed() } }
767}
768
769
770/**
771 * DRM_IOCTL_SG_ALLOC ioctl argument type.
772 */
773#[repr(C)]
774pub struct drm_scatter_gather {
775	size: c_ulong,	/**< In bytes -- will round to page boundary */
776	handle: c_ulong
777}
778impl ::std::default::Default for drm_scatter_gather {
779    fn default() -> drm_scatter_gather { unsafe { ::std::mem::zeroed() } }
780}
781
782
783/**
784 * DRM_IOCTL_SET_VERSION ioctl argument type.
785 */
786#[repr(C)]
787pub struct drm_set_version {
788	drm_di_major: c_int,
789	drm_di_minor: c_int,
790	drm_dd_major: c_int,
791	drm_dd_minor: c_int
792}
793impl ::std::default::Default for drm_set_version {
794    fn default() -> drm_set_version { unsafe { ::std::mem::zeroed() } }
795}
796
797
798/** DRM_IOCTL_GEM_CLOSE ioctl argument type */
799struct drm_gem_close {
800	/** Handle of the object to be closed. */
801	handle: u32,
802	pad: u32
803}
804
805/** DRM_IOCTL_GEM_FLINK ioctl argument type */
806#[repr(C)]
807pub struct drm_gem_flink {
808	/** Handle for the object being named */
809	handle: u32,
810
811	/** Returned global name */
812	name: u32
813}
814impl ::std::default::Default for drm_gem_flink {
815    fn default() -> drm_gem_flink { unsafe { ::std::mem::zeroed() } }
816}
817
818
819/** DRM_IOCTL_GEM_OPEN ioctl argument type */
820#[repr(C)]
821pub struct drm_gem_open {
822	/** Name of object being opened */
823	name: u32,
824
825	/** Returned handle for the object */
826	handle: u32,
827
828	/** Returned size of the object */
829	size: u64
830}
831impl ::std::default::Default for drm_gem_open {
832    fn default() -> drm_gem_open { unsafe { ::std::mem::zeroed() } }
833}
834
835
836pub const DRM_CAP_DUMB_BUFFER: uint64_t = 0x1;
837pub const DRM_CAP_VBLANK_HIGH_CRTC: uint64_t = 0x2;
838pub const DRM_CAP_DUMB_PREFERRED_DEPTH: uint64_t = 0x3;
839pub const DRM_CAP_DUMB_PREFER_SHADOW: uint64_t = 0x4;
840pub const DRM_CAP_PRIME: uint64_t = 0x5;
841pub const  DRM_PRIME_CAP_IMPORT: uint64_t = 0x1;
842pub const  DRM_PRIME_CAP_EXPORT: uint64_t = 0x2;
843pub const DRM_CAP_TIMESTAMP_MONOTONIC: uint64_t = 0x6;
844pub const DRM_CAP_ASYNC_PAGE_FLIP: uint64_t = 0x7;
845/*
846 * The CURSOR_WIDTH and CURSOR_HEIGHT capabilities return a valid widthxheight
847 * combination for the hardware cursor. The intention is that a hardware
848 * agnostic userspace can query a cursor plane size to use.
849 *
850 * Note that the cross-driver contract is to merely return a valid size;
851 * drivers are free to attach another meaning on top, eg. i915 returns the
852 * maximum plane size.
853 */
854pub const DRM_CAP_CURSOR_WIDTH: uint64_t = 0x8;
855pub const DRM_CAP_CURSOR_HEIGHT: uint64_t = 0x9;
856pub const DRM_CAP_ADDFB2_MODIFIERS: uint64_t = 0x10;
857
858/** DRM_IOCTL_GET_CAP ioctl argument type */
859#[repr(C)]
860pub struct drm_get_cap {
861	capability: u64,
862	value: u64
863}
864impl ::std::default::Default for drm_get_cap {
865    fn default() -> drm_get_cap { unsafe { ::std::mem::zeroed() } }
866}
867
868
869/**
870 * DRM_CLIENT_CAP_STEREO_3D
871 *
872 * if set to 1, the DRM core will expose the stereo 3D capabilities of the
873 * monitor by advertising the supported 3D layouts in the flags of struct
874 * drm_mode_modeinfo.
875 */
876pub const DRM_CLIENT_CAP_STEREO_3D: c_int = 1;
877
878/**
879 * DRM_CLIENT_CAP_UNIVERSAL_PLANES
880 *
881 * If set to 1, the DRM core will expose all planes (overlay, primary, and
882 * cursor) to userspace.
883 */
884pub const DRM_CLIENT_CAP_UNIVERSAL_PLANES: c_int = 2;
885
886/**
887 * DRM_CLIENT_CAP_ATOMIC
888 *
889 * If set to 1, the DRM core will expose atomic properties to userspace
890 */
891pub const DRM_CLIENT_CAP_ATOMIC: c_int = 3;
892
893/** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
894#[repr(C)]
895pub struct drm_set_client_cap {
896	capability: u64,
897	value: u64
898}
899impl ::std::default::Default for drm_set_client_cap {
900    fn default() -> drm_set_client_cap { unsafe { ::std::mem::zeroed() } }
901}
902
903
904pub const DRM_RDWR: c_int = O_RDWR;
905// const DRM_CLOEXEC: c_int = O_CLOEXEC;
906#[repr(C)]
907pub struct drm_prime_handle {
908	handle: u32,
909
910	/** Flags.. only applicable for handle->fd */
911	flags: u32,
912
913	/** Returned dmabuf file descriptor */
914	fd: i32
915}
916impl ::std::default::Default for drm_prime_handle {
917    fn default() -> drm_prime_handle { unsafe { ::std::mem::zeroed() } }
918}
919
920
921// #include "drm_mode.h"
922
923/**
924 * Device specific ioctls should only be in their respective headers
925 * The device specific ioctl range is from 0x40 to 0x9f.
926 * Generic IOCTLS restart at 0xA0.
927 *
928 * \sa drmCommandNone(), drmCommandRead(), drmCommandWrite(), and
929 * drmCommandReadWrite().
930 */
931pub const DRM_COMMAND_BASE: c_int = 0x40;
932pub const DRM_COMMAND_END: c_int = 0xA0;
933
934/**
935 * Header for events written back to userspace on the drm fd.  The
936 * type defines the type of event, the length specifies the total
937 * length of the event (including the header), and user_data is
938 * typically a 64 bit value passed with the ioctl that triggered the
939 * event.  A read on the drm fd will always only return complete
940 * events, that is, if for example the read buffer is 100 bytes, and
941 * there are two 64 byte events pending, only one will be returned.
942 *
943 * Event types 0 - 0x7fffffff are generic drm events, 0x80000000 and
944 * up are chipset specific.
945 */
946#[repr(C)]
947pub struct drm_event {
948	event_type: u32,
949	length: u32
950}
951impl ::std::default::Default for drm_event {
952    fn default() -> drm_event { unsafe { ::std::mem::zeroed() } }
953}
954
955
956pub const DRM_EVENT_VBLANK: c_int = 0x01;
957pub const DRM_EVENT_FLIP_COMPLETE: c_int = 0x02;
958
959#[repr(C)]
960pub struct drm_event_vblank {
961	base: drm_event,
962	user_data: u64,
963	tv_sec: u32,
964	tv_usec: u32,
965	sequence: u32,
966	reserved: u32
967}
968impl ::std::default::Default for drm_event_vblank {
969    fn default() -> drm_event_vblank { unsafe { ::std::mem::zeroed() } }
970}
971
972
973/* typedef area */
974type drm_clip_rect_t = drm_clip_rect;
975type drm_drawable_info_t = drm_drawable_info;
976type drm_tex_region_t = drm_tex_region;
977type drm_hw_lock_t = drm_hw_lock;
978type drm_version_t = drm_version;
979type drm_unique_t = drm_unique;
980type drm_list_t = drm_list;
981type drm_block_t = drm_block;
982type drm_control_t = drm_control;
983type drm_map_type_t = drm_map_type;
984type drm_map_flags_t = drm_map_flags;
985type drm_ctx_priv_map_t = drm_ctx_priv_map;
986type drm_map_t = drm_map;
987type drm_client_t = drm_client;
988type drm_stat_type_t = drm_stat_type;
989type drm_stats_t = drm_stats;
990type drm_lock_flags_t = drm_lock_flags;
991type drm_lock_t = drm_lock;
992type drm_dma_flags_t = drm_dma_flags;
993type drm_buf_desc_t = drm_buf_desc;
994type drm_buf_info_t = drm_buf_info;
995type drm_buf_free_t = drm_buf_free;
996type drm_buf_pub_t = drm_buf_pub;
997type drm_buf_map_t = drm_buf_map;
998type drm_dma_t = drm_dma;
999type drm_wait_vblank_t = drm_wait_vblank;
1000type drm_agp_mode_t = drm_agp_mode;
1001type drm_ctx_flags_t = drm_ctx_flags;
1002type drm_ctx_t = drm_ctx;
1003type drm_ctx_res_t = drm_ctx_res;
1004type drm_draw_t = drm_draw;
1005type drm_update_draw_t = drm_update_draw;
1006type drm_auth_t = drm_auth;
1007type drm_irq_busid_t = drm_irq_busid;
1008type drm_vblank_seq_type_t = drm_vblank_seq_type;
1009
1010type drm_agp_buffer_t = drm_agp_buffer;
1011type drm_agp_binding_t = drm_agp_binding;
1012type drm_agp_info_t = drm_agp_info;
1013type drm_scatter_gather_t = drm_scatter_gather;
1014type drm_set_version_t = drm_set_version;