]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdrm.git/blob - xf86drmMode.c
Merge branch 'pageflip' of git://people.freedesktop.org/~jbarnes/drm
[glsdk/libdrm.git] / xf86drmMode.c
1 /*
2  * \file xf86drmMode.c
3  * Header for DRM modesetting interface.
4  *
5  * \author Jakob Bornecrantz <wallbraker@gmail.com>
6  *
7  * \par Acknowledgements:
8  * Feb 2007, Dave Airlie <airlied@linux.ie>
9  */
11 /*
12  * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
13  * Copyright (c) 2007-2008 Dave Airlie <airlied@linux.ie>
14  * Copyright (c) 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files (the "Software"),
18  * to deal in the Software without restriction, including without limitation
19  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20  * and/or sell copies of the Software, and to permit persons to whom the
21  * Software is furnished to do so, subject to the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be included in
24  * all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32  * IN THE SOFTWARE.
33  *
34  */
36 /*
37  * TODO the types we are after are defined in diffrent headers on diffrent
38  * platforms find which headers to include to get uint32_t
39  */
40 #include <stdint.h>
41 #include <sys/ioctl.h>
42 #include <stdio.h>
44 #include "xf86drmMode.h"
45 #include "xf86drm.h"
46 #include <drm.h>
47 #include <string.h>
48 #include <dirent.h>
49 #include <unistd.h>
50 #include <errno.h>
52 #define U642VOID(x) ((void *)(unsigned long)(x))
53 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
55 /*
56  * Util functions
57  */
59 void* drmAllocCpy(void *array, int count, int entry_size)
60 {
61         char *r;
62         int i;
64         if (!count || !array || !entry_size)
65                 return 0;
67         if (!(r = drmMalloc(count*entry_size)))
68                 return 0;
70         for (i = 0; i < count; i++)
71                 memcpy(r+(entry_size*i), array+(entry_size*i), entry_size);
73         return r;
74 }
76 /*
77  * A couple of free functions.
78  */
80 void drmModeFreeModeInfo(drmModeModeInfoPtr ptr)
81 {
82         if (!ptr)
83                 return;
85         drmFree(ptr);
86 }
88 void drmModeFreeResources(drmModeResPtr ptr)
89 {
90         if (!ptr)
91                 return;
93         drmFree(ptr);
95 }
97 void drmModeFreeFB(drmModeFBPtr ptr)
98 {
99         if (!ptr)
100                 return;
102         /* we might add more frees later. */
103         drmFree(ptr);
106 void drmModeFreeCrtc(drmModeCrtcPtr ptr)
108         if (!ptr)
109                 return;
111         drmFree(ptr);
115 void drmModeFreeConnector(drmModeConnectorPtr ptr)
117         if (!ptr)
118                 return;
120         drmFree(ptr->encoders);
121         drmFree(ptr->prop_values);
122         drmFree(ptr->props);
123         drmFree(ptr->modes);
124         drmFree(ptr);
128 void drmModeFreeEncoder(drmModeEncoderPtr ptr)
130         drmFree(ptr);
133 /*
134  * ModeSetting functions.
135  */
137 drmModeResPtr drmModeGetResources(int fd)
139         struct drm_mode_card_res res;
140         drmModeResPtr r = 0;
142         memset(&res, 0, sizeof(struct drm_mode_card_res));
144         if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
145                 return 0;
147         if (res.count_fbs)
148                 res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t)));
149         if (res.count_crtcs)
150                 res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t)));
151         if (res.count_connectors)
152                 res.connector_id_ptr = VOID2U64(drmMalloc(res.count_connectors*sizeof(uint32_t)));
153         if (res.count_encoders)
154                 res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t)));
156         if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) {
157                 r = NULL;
158                 goto err_allocs;
159         }
161         /*
162          * return
163          */
166         if (!(r = drmMalloc(sizeof(*r))))
167                 return 0;
169         r->min_width     = res.min_width;
170         r->max_width     = res.max_width;
171         r->min_height    = res.min_height;
172         r->max_height    = res.max_height;
173         r->count_fbs     = res.count_fbs;
174         r->count_crtcs   = res.count_crtcs;
175         r->count_connectors = res.count_connectors;
176         r->count_encoders = res.count_encoders;
177         /* TODO we realy should test if these allocs fails. */
178         r->fbs           = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
179         r->crtcs         = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
180         r->connectors       = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t));
181         r->encoders      = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t));
183 err_allocs:
184         drmFree(U642VOID(res.fb_id_ptr));
185         drmFree(U642VOID(res.crtc_id_ptr));
186         drmFree(U642VOID(res.connector_id_ptr));
187         drmFree(U642VOID(res.encoder_id_ptr));
189         return r;
192 int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
193                  uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
194                  uint32_t *buf_id)
196         struct drm_mode_fb_cmd f;
197         int ret;
199         f.width  = width;
200         f.height = height;
201         f.pitch  = pitch;
202         f.bpp    = bpp;
203         f.depth  = depth;
204         f.handle = bo_handle;
206         if ((ret = drmIoctl(fd, DRM_IOCTL_MODE_ADDFB, &f)))
207                 return ret;
209         *buf_id = f.fb_id;
210         return 0;
213 int drmModeRmFB(int fd, uint32_t bufferId)
215         return drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
220 drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
222         struct drm_mode_fb_cmd info;
223         drmModeFBPtr r;
225         info.fb_id = buf;
227         if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))
228                 return NULL;
230         if (!(r = drmMalloc(sizeof(*r))))
231                 return NULL;
233         r->fb_id = info.fb_id;
234         r->width = info.width;
235         r->height = info.height;
236         r->pitch = info.pitch;
237         r->bpp = info.bpp;
238         r->handle = info.handle;
239         r->depth = info.depth;
241         return r;
245 /*
246  * Crtc functions
247  */
249 drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
251         struct drm_mode_crtc crtc;
252         drmModeCrtcPtr r;
254         crtc.crtc_id = crtcId;
256         if (drmIoctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc))
257                 return 0;
259         /*
260          * return
261          */
263         if (!(r = drmMalloc(sizeof(*r))))
264                 return 0;
266         r->crtc_id         = crtc.crtc_id;
267         r->x               = crtc.x;
268         r->y               = crtc.y;
269         r->mode_valid      = crtc.mode_valid;
270         if (r->mode_valid)
271                 memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo));
272         r->buffer_id       = crtc.fb_id;
273         r->gamma_size      = crtc.gamma_size;
274         return r;
278 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
279                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
280                    drmModeModeInfoPtr mode)
282         struct drm_mode_crtc crtc;
284         crtc.x             = x;
285         crtc.y             = y;
286         crtc.crtc_id       = crtcId;
287         crtc.fb_id         = bufferId;
288         crtc.set_connectors_ptr = VOID2U64(connectors);
289         crtc.count_connectors = count;
290         if (mode) {
291           memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
292           crtc.mode_valid = 1;
293         } else
294           crtc.mode_valid = 0;
296         return drmIoctl(fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
299 /*
300  * Cursor manipulation
301  */
303 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height)
305         struct drm_mode_cursor arg;
307         arg.flags = DRM_MODE_CURSOR_BO;
308         arg.crtc_id = crtcId;
309         arg.width = width;
310         arg.height = height;
311         arg.handle = bo_handle;
313         return drmIoctl(fd, DRM_IOCTL_MODE_CURSOR, &arg);
316 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y)
318         struct drm_mode_cursor arg;
320         arg.flags = DRM_MODE_CURSOR_MOVE;
321         arg.crtc_id = crtcId;
322         arg.x = x;
323         arg.y = y;
325         return drmIoctl(fd, DRM_IOCTL_MODE_CURSOR, &arg);
328 /*
329  * Encoder get
330  */
331 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id)
333         struct drm_mode_get_encoder enc;
334         drmModeEncoderPtr r = NULL;
336         enc.encoder_id = encoder_id;
337         enc.encoder_type = 0;
338         enc.possible_crtcs = 0;
339         enc.possible_clones = 0;
341         if (drmIoctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc))
342                 return 0;
344         if (!(r = drmMalloc(sizeof(*r))))
345                 return 0;
347         r->encoder_id = enc.encoder_id;
348         r->crtc_id = enc.crtc_id;
349         r->encoder_type = enc.encoder_type;
350         r->possible_crtcs = enc.possible_crtcs;
351         r->possible_clones = enc.possible_clones;
353         return r;
356 /*
357  * Connector manipulation
358  */
360 drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id)
362         struct drm_mode_get_connector conn;
363         drmModeConnectorPtr r = NULL;
365         conn.connector_id = connector_id;
366         conn.connector_type_id = 0;
367         conn.connector_type  = 0;
368         conn.count_modes  = 0;
369         conn.modes_ptr    = 0;
370         conn.count_props  = 0;
371         conn.props_ptr    = 0;
372         conn.prop_values_ptr = 0;
373         conn.count_encoders  = 0;
374         conn.encoders_ptr = 0;
376         if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
377                 return 0;
379         if (conn.count_props) {
380                 conn.props_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint32_t)));
381                 conn.prop_values_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint64_t)));
382         }
384         if (conn.count_modes)
385                 conn.modes_ptr = VOID2U64(drmMalloc(conn.count_modes*sizeof(struct drm_mode_modeinfo)));
387         if (conn.count_encoders)
388                 conn.encoders_ptr = VOID2U64(drmMalloc(conn.count_encoders*sizeof(uint32_t)));
390         if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
391                 goto err_allocs;
393         if(!(r = drmMalloc(sizeof(*r)))) {
394                 goto err_allocs;
395         }
397         r->connector_id = conn.connector_id;
398         r->encoder_id = conn.encoder_id;
399         r->connection   = conn.connection;
400         r->mmWidth      = conn.mm_width;
401         r->mmHeight     = conn.mm_height;
402         /* convert subpixel from kernel to userspace */
403         r->subpixel     = conn.subpixel + 1;
404         r->count_modes  = conn.count_modes;
405         /* TODO we should test if these alloc & cpy fails. */
406         r->count_props  = conn.count_props;
407         r->props        = drmAllocCpy(U642VOID(conn.props_ptr), conn.count_props, sizeof(uint32_t));
408         r->prop_values  = drmAllocCpy(U642VOID(conn.prop_values_ptr), conn.count_props, sizeof(uint64_t));
409         r->modes        = drmAllocCpy(U642VOID(conn.modes_ptr), conn.count_modes, sizeof(struct drm_mode_modeinfo));
410         r->count_encoders = conn.count_encoders;
411         r->encoders     = drmAllocCpy(U642VOID(conn.encoders_ptr), conn.count_encoders, sizeof(uint32_t));
412         r->connector_type  = conn.connector_type;
413         r->connector_type_id = conn.connector_type_id;
415         if (!r->props || !r->prop_values || !r->modes || !r->encoders)
416                 goto err_allocs;
418 err_allocs:
419         drmFree(U642VOID(conn.prop_values_ptr));
420         drmFree(U642VOID(conn.props_ptr));
421         drmFree(U642VOID(conn.modes_ptr));
422         drmFree(U642VOID(conn.encoders_ptr));
424         return r;
427 int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
429         struct drm_mode_mode_cmd res;
431         memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
432         res.connector_id = connector_id;
434         return drmIoctl(fd, DRM_IOCTL_MODE_ATTACHMODE, &res);
437 int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
439         struct drm_mode_mode_cmd res;
441         memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
442         res.connector_id = connector_id;
444         return drmIoctl(fd, DRM_IOCTL_MODE_DETACHMODE, &res);
448 drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
450         struct drm_mode_get_property prop;
451         drmModePropertyPtr r;
453         prop.prop_id = property_id;
454         prop.count_enum_blobs = 0;
455         prop.count_values = 0;
456         prop.flags = 0;
457         prop.enum_blob_ptr = 0;
458         prop.values_ptr = 0;
460         if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
461                 return 0;
463         if (prop.count_values)
464                 prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t)));
466         if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_ENUM))
467                 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum)));
469         if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_BLOB)) {
470                 prop.values_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
471                 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
472         }
474         if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) {
475                 r = NULL;
476                 goto err_allocs;
477         }
479         if (!(r = drmMalloc(sizeof(*r))))
480                 return NULL;
482         r->prop_id = prop.prop_id;
483         r->count_values = prop.count_values;
485         r->flags = prop.flags;
486         if (prop.count_values)
487                 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t));
488         if (prop.flags & DRM_MODE_PROP_ENUM) {
489                 r->count_enums = prop.count_enum_blobs;
490                 r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum));
491         } else if (prop.flags & DRM_MODE_PROP_BLOB) {
492                 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_enum_blobs, sizeof(uint32_t));
493                 r->blob_ids = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(uint32_t));
494                 r->count_blobs = prop.count_enum_blobs;
495         }
496         strncpy(r->name, prop.name, DRM_PROP_NAME_LEN);
497         r->name[DRM_PROP_NAME_LEN-1] = 0;
499 err_allocs:
500         drmFree(U642VOID(prop.values_ptr));
501         drmFree(U642VOID(prop.enum_blob_ptr));
503         return r;
506 void drmModeFreeProperty(drmModePropertyPtr ptr)
508         if (!ptr)
509                 return;
511         drmFree(ptr->values);
512         drmFree(ptr->enums);
513         drmFree(ptr);
516 drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id)
518         struct drm_mode_get_blob blob;
519         drmModePropertyBlobPtr r;
521         blob.length = 0;
522         blob.data = 0;
523         blob.blob_id = blob_id;
525         if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob))
526                 return NULL;
528         if (blob.length)
529                 blob.data = VOID2U64(drmMalloc(blob.length));
531         if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) {
532                 r = NULL;
533                 goto err_allocs;
534         }
536         if (!(r = drmMalloc(sizeof(*r))))
537                 return NULL;
539         r->id = blob.blob_id;
540         r->length = blob.length;
541         r->data = drmAllocCpy(U642VOID(blob.data), 1, blob.length);
543 err_allocs:
544         drmFree(U642VOID(blob.data));
545         return r;
548 void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr)
550         if (!ptr)
551                 return;
553         drmFree(ptr->data);
554         drmFree(ptr);
557 int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
558                              uint64_t value)
560         struct drm_mode_connector_set_property osp;
561         int ret;
563         osp.connector_id = connector_id;
564         osp.prop_id = property_id;
565         osp.value = value;
567         if ((ret = drmIoctl(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp)))
568                 return ret;
570         return 0;
573 /*
574  * checks if a modesetting capable driver has attached to the pci id
575  * returns 0 if modesetting supported.
576  *  -EINVAL or invalid bus id
577  *  -ENOSYS if no modesetting support
578 */
579 int drmCheckModesettingSupported(const char *busid)
581 #ifdef __linux__
582         char pci_dev_dir[1024];
583         int domain, bus, dev, func;
584         DIR *sysdir;
585         struct dirent *dent;
586         int found = 0, ret;
588         ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
589         if (ret != 4)
590                 return -EINVAL;
592         sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/drm",
593                 domain, bus, dev, func);
595         sysdir = opendir(pci_dev_dir);
596         if (sysdir) {
597                 dent = readdir(sysdir);
598                 while (dent) {
599                         if (!strncmp(dent->d_name, "controlD", 8)) {
600                                 found = 1;
601                                 break;
602                         }
604                         dent = readdir(sysdir);
605                 }
606                 closedir(sysdir);
607                 if (found)
608                         return 0;
609         }
611         sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/",
612                 domain, bus, dev, func);
614         sysdir = opendir(pci_dev_dir);
615         if (!sysdir)
616                 return -EINVAL;
618         dent = readdir(sysdir);
619         while (dent) {
620                 if (!strncmp(dent->d_name, "drm:controlD", 12)) {
621                         found = 1;
622                         break;
623                 }
625                 dent = readdir(sysdir);
626         }
628         closedir(sysdir);
629         if (found)
630                 return 0;
631 #endif
632         return -ENOSYS;
636 int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
637                         uint16_t *red, uint16_t *green, uint16_t *blue)
639         int ret;
640         struct drm_mode_crtc_lut l;
642         l.crtc_id = crtc_id;
643         l.gamma_size = size;
644         l.red = VOID2U64(red);
645         l.green = VOID2U64(green);
646         l.blue = VOID2U64(blue);
648         if ((ret = drmIoctl(fd, DRM_IOCTL_MODE_GETGAMMA, &l)))
649                 return ret;
651         return 0;
654 int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
655                         uint16_t *red, uint16_t *green, uint16_t *blue)
657         int ret;
658         struct drm_mode_crtc_lut l;
660         l.crtc_id = crtc_id;
661         l.gamma_size = size;
662         l.red = VOID2U64(red);
663         l.green = VOID2U64(green);
664         l.blue = VOID2U64(blue);
666         if ((ret = drmIoctl(fd, DRM_IOCTL_MODE_SETGAMMA, &l)))
667                 return ret;
669         return 0;
672 int drmHandleEvent(int fd, drmEventContextPtr evctx)
674         char buffer[1024];
675         int len, i;
676         struct drm_event *e;
677         struct drm_event_vblank *vblank;
678         
679         /* The DRM read semantics guarantees that we always get only
680          * complete events. */
682         len = read(fd, buffer, sizeof buffer);
683         if (len == 0)
684                 return 0;
685         if (len < sizeof *e)
686                 return -1;
688         i = 0;
689         while (i < len) {
690                 e = (struct drm_event *) &buffer[i];
691                 switch (e->type) {
692                 case DRM_EVENT_VBLANK:
693                         if (evctx->version < 1 ||
694                             evctx->vblank_handler == NULL)
695                                 break;
696                         vblank = (struct drm_event_vblank *) e;
697                         evctx->vblank_handler(fd,
698                                               vblank->sequence, 
699                                               vblank->tv_sec,
700                                               vblank->tv_usec,
701                                               U642VOID (vblank->user_data));
702                         break;
703                 case DRM_EVENT_FLIP_COMPLETE:
704                         if (evctx->version < 1 ||
705                             evctx->page_flip_handler == NULL)
706                                 break;
707                         vblank = (struct drm_event_vblank *) e;
708                         evctx->page_flip_handler(fd,
709                                                  vblank->sequence,
710                                                  vblank->tv_sec,
711                                                  vblank->tv_usec,
712                                                  U642VOID (vblank->user_data));
713                         break;
714                 default:
715                         break;
716                 }
717                 i += e->length;
718         }
720         return 0;
723 int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
724                     uint32_t flags, void *user_data)
726         struct drm_mode_crtc_page_flip flip;
728         flip.fb_id = fb_id;
729         flip.crtc_id = crtc_id;
730         flip.user_data = VOID2U64(user_data);
731         flip.flags = flags;
732         flip.reserved = 0;
734         return drmIoctl(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);