3 * Header for DRM modesetting interface.
5 * \author Jakob Bornecrantz <wallbraker@gmail.com>
7 * \par Acknowledgements:
8 * Feb 2007, Dave Airlie <airlied@linux.ie>
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>
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:
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
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
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
41 #include <sys/ioctl.h>
44 #include "xf86drmMode.h"
52 #define U642VOID(x) ((void *)(unsigned long)(x))
53 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
55 static inline int DRM_IOCTL(int fd, unsigned long cmd, void *arg)
57 int ret = drmIoctl(fd, cmd, arg);
58 return ret < 0 ? -errno : ret;
65 void* drmAllocCpy(void *array, int count, int entry_size)
70 if (!count || !array || !entry_size)
73 if (!(r = drmMalloc(count*entry_size)))
76 for (i = 0; i < count; i++)
77 memcpy(r+(entry_size*i), array+(entry_size*i), entry_size);
83 * A couple of free functions.
86 void drmModeFreeModeInfo(drmModeModeInfoPtr ptr)
94 void drmModeFreeResources(drmModeResPtr ptr)
103 void drmModeFreeFB(drmModeFBPtr ptr)
108 /* we might add more frees later. */
112 void drmModeFreeCrtc(drmModeCrtcPtr ptr)
121 void drmModeFreeConnector(drmModeConnectorPtr ptr)
126 drmFree(ptr->encoders);
127 drmFree(ptr->prop_values);
134 void drmModeFreeEncoder(drmModeEncoderPtr ptr)
140 * ModeSetting functions.
143 drmModeResPtr drmModeGetResources(int fd)
145 struct drm_mode_card_res res, counts;
149 memset(&res, 0, sizeof(struct drm_mode_card_res));
150 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
156 res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t)));
160 if (res.count_crtcs) {
161 res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t)));
162 if (!res.crtc_id_ptr)
165 if (res.count_connectors) {
166 res.connector_id_ptr = VOID2U64(drmMalloc(res.count_connectors*sizeof(uint32_t)));
167 if (!res.connector_id_ptr)
170 if (res.count_encoders) {
171 res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t)));
172 if (!res.encoder_id_ptr)
176 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
179 /* The number of available connectors and etc may have changed with a
180 * hotplug event in between the ioctls, in which case the field is
181 * silently ignored by the kernel.
183 if (counts.count_fbs < res.count_fbs ||
184 counts.count_crtcs < res.count_crtcs ||
185 counts.count_connectors < res.count_connectors ||
186 counts.count_encoders < res.count_encoders)
188 drmFree(U642VOID(res.fb_id_ptr));
189 drmFree(U642VOID(res.crtc_id_ptr));
190 drmFree(U642VOID(res.connector_id_ptr));
191 drmFree(U642VOID(res.encoder_id_ptr));
199 if (!(r = drmMalloc(sizeof(*r))))
202 r->min_width = res.min_width;
203 r->max_width = res.max_width;
204 r->min_height = res.min_height;
205 r->max_height = res.max_height;
206 r->count_fbs = res.count_fbs;
207 r->count_crtcs = res.count_crtcs;
208 r->count_connectors = res.count_connectors;
209 r->count_encoders = res.count_encoders;
211 r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
212 r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
213 r->connectors = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t));
214 r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t));
215 if ((res.count_fbs && !r->fbs) ||
216 (res.count_crtcs && !r->crtcs) ||
217 (res.count_connectors && !r->connectors) ||
218 (res.count_encoders && !r->encoders))
222 drmFree(r->connectors);
223 drmFree(r->encoders);
229 drmFree(U642VOID(res.fb_id_ptr));
230 drmFree(U642VOID(res.crtc_id_ptr));
231 drmFree(U642VOID(res.connector_id_ptr));
232 drmFree(U642VOID(res.encoder_id_ptr));
237 int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
238 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
241 struct drm_mode_fb_cmd f;
249 f.handle = bo_handle;
251 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB, &f)))
258 int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
259 uint32_t pixel_format, uint32_t bo_handles[4],
260 uint32_t pitches[4], uint32_t offsets[4],
261 uint32_t *buf_id, uint32_t flags)
263 struct drm_mode_fb_cmd2 f;
268 f.pixel_format = pixel_format;
270 memcpy(f.handles, bo_handles, sizeof(bo_handles));
271 memcpy(f.pitches, pitches, sizeof(pitches));
272 memcpy(f.offsets, offsets, sizeof(offsets));
274 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
281 int drmModeRmFB(int fd, uint32_t bufferId)
283 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
288 drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
290 struct drm_mode_fb_cmd info;
295 if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))
298 if (!(r = drmMalloc(sizeof(*r))))
301 r->fb_id = info.fb_id;
302 r->width = info.width;
303 r->height = info.height;
304 r->pitch = info.pitch;
306 r->handle = info.handle;
307 r->depth = info.depth;
312 int drmModeDirtyFB(int fd, uint32_t bufferId,
313 drmModeClipPtr clips, uint32_t num_clips)
315 struct drm_mode_fb_dirty_cmd dirty = { 0 };
317 dirty.fb_id = bufferId;
318 dirty.clips_ptr = VOID2U64(clips);
319 dirty.num_clips = num_clips;
321 return DRM_IOCTL(fd, DRM_IOCTL_MODE_DIRTYFB, &dirty);
329 drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
331 struct drm_mode_crtc crtc;
334 crtc.crtc_id = crtcId;
336 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc))
343 if (!(r = drmMalloc(sizeof(*r))))
346 r->crtc_id = crtc.crtc_id;
349 r->mode_valid = crtc.mode_valid;
351 memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo));
352 r->buffer_id = crtc.fb_id;
353 r->gamma_size = crtc.gamma_size;
358 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
359 uint32_t x, uint32_t y, uint32_t *connectors, int count,
360 drmModeModeInfoPtr mode)
362 struct drm_mode_crtc crtc;
366 crtc.crtc_id = crtcId;
367 crtc.fb_id = bufferId;
368 crtc.set_connectors_ptr = VOID2U64(connectors);
369 crtc.count_connectors = count;
371 memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
376 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
380 * Cursor manipulation
383 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height)
385 struct drm_mode_cursor arg;
387 arg.flags = DRM_MODE_CURSOR_BO;
388 arg.crtc_id = crtcId;
391 arg.handle = bo_handle;
393 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR, &arg);
396 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y)
398 struct drm_mode_cursor arg;
400 arg.flags = DRM_MODE_CURSOR_MOVE;
401 arg.crtc_id = crtcId;
405 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR, &arg);
411 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id)
413 struct drm_mode_get_encoder enc;
414 drmModeEncoderPtr r = NULL;
416 enc.encoder_id = encoder_id;
417 enc.encoder_type = 0;
418 enc.possible_crtcs = 0;
419 enc.possible_clones = 0;
421 if (drmIoctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc))
424 if (!(r = drmMalloc(sizeof(*r))))
427 r->encoder_id = enc.encoder_id;
428 r->crtc_id = enc.crtc_id;
429 r->encoder_type = enc.encoder_type;
430 r->possible_crtcs = enc.possible_crtcs;
431 r->possible_clones = enc.possible_clones;
437 * Connector manipulation
440 drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id)
442 struct drm_mode_get_connector conn, counts;
443 drmModeConnectorPtr r = NULL;
446 memset(&conn, 0, sizeof(struct drm_mode_get_connector));
447 conn.connector_id = connector_id;
449 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
454 if (conn.count_props) {
455 conn.props_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint32_t)));
458 conn.prop_values_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint64_t)));
459 if (!conn.prop_values_ptr)
463 if (conn.count_modes) {
464 conn.modes_ptr = VOID2U64(drmMalloc(conn.count_modes*sizeof(struct drm_mode_modeinfo)));
469 if (conn.count_encoders) {
470 conn.encoders_ptr = VOID2U64(drmMalloc(conn.count_encoders*sizeof(uint32_t)));
471 if (!conn.encoders_ptr)
475 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
478 /* The number of available connectors and etc may have changed with a
479 * hotplug event in between the ioctls, in which case the field is
480 * silently ignored by the kernel.
482 if (counts.count_props < conn.count_props ||
483 counts.count_modes < conn.count_modes ||
484 counts.count_encoders < conn.count_encoders) {
485 drmFree(U642VOID(conn.props_ptr));
486 drmFree(U642VOID(conn.prop_values_ptr));
487 drmFree(U642VOID(conn.modes_ptr));
488 drmFree(U642VOID(conn.encoders_ptr));
493 if(!(r = drmMalloc(sizeof(*r)))) {
497 r->connector_id = conn.connector_id;
498 r->encoder_id = conn.encoder_id;
499 r->connection = conn.connection;
500 r->mmWidth = conn.mm_width;
501 r->mmHeight = conn.mm_height;
502 /* convert subpixel from kernel to userspace */
503 r->subpixel = conn.subpixel + 1;
504 r->count_modes = conn.count_modes;
505 r->count_props = conn.count_props;
506 r->props = drmAllocCpy(U642VOID(conn.props_ptr), conn.count_props, sizeof(uint32_t));
507 r->prop_values = drmAllocCpy(U642VOID(conn.prop_values_ptr), conn.count_props, sizeof(uint64_t));
508 r->modes = drmAllocCpy(U642VOID(conn.modes_ptr), conn.count_modes, sizeof(struct drm_mode_modeinfo));
509 r->count_encoders = conn.count_encoders;
510 r->encoders = drmAllocCpy(U642VOID(conn.encoders_ptr), conn.count_encoders, sizeof(uint32_t));
511 r->connector_type = conn.connector_type;
512 r->connector_type_id = conn.connector_type_id;
514 if ((r->count_props && !r->props) ||
515 (r->count_props && !r->prop_values) ||
516 (r->count_modes && !r->modes) ||
517 (r->count_encoders && !r->encoders)) {
519 drmFree(r->prop_values);
521 drmFree(r->encoders);
527 drmFree(U642VOID(conn.prop_values_ptr));
528 drmFree(U642VOID(conn.props_ptr));
529 drmFree(U642VOID(conn.modes_ptr));
530 drmFree(U642VOID(conn.encoders_ptr));
535 int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
537 struct drm_mode_mode_cmd res;
539 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
540 res.connector_id = connector_id;
542 return DRM_IOCTL(fd, DRM_IOCTL_MODE_ATTACHMODE, &res);
545 int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
547 struct drm_mode_mode_cmd res;
549 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
550 res.connector_id = connector_id;
552 return DRM_IOCTL(fd, DRM_IOCTL_MODE_DETACHMODE, &res);
556 drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
558 struct drm_mode_get_property prop;
559 drmModePropertyPtr r;
561 prop.prop_id = property_id;
562 prop.count_enum_blobs = 0;
563 prop.count_values = 0;
565 prop.enum_blob_ptr = 0;
568 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
571 if (prop.count_values)
572 prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t)));
574 if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_ENUM))
575 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum)));
577 if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_BLOB)) {
578 prop.values_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
579 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
582 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) {
587 if (!(r = drmMalloc(sizeof(*r))))
590 r->prop_id = prop.prop_id;
591 r->count_values = prop.count_values;
593 r->flags = prop.flags;
594 if (prop.count_values)
595 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t));
596 if (prop.flags & DRM_MODE_PROP_ENUM) {
597 r->count_enums = prop.count_enum_blobs;
598 r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum));
599 } else if (prop.flags & DRM_MODE_PROP_BLOB) {
600 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_enum_blobs, sizeof(uint32_t));
601 r->blob_ids = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(uint32_t));
602 r->count_blobs = prop.count_enum_blobs;
604 strncpy(r->name, prop.name, DRM_PROP_NAME_LEN);
605 r->name[DRM_PROP_NAME_LEN-1] = 0;
608 drmFree(U642VOID(prop.values_ptr));
609 drmFree(U642VOID(prop.enum_blob_ptr));
614 void drmModeFreeProperty(drmModePropertyPtr ptr)
619 drmFree(ptr->values);
624 drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id)
626 struct drm_mode_get_blob blob;
627 drmModePropertyBlobPtr r;
631 blob.blob_id = blob_id;
633 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob))
637 blob.data = VOID2U64(drmMalloc(blob.length));
639 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) {
644 if (!(r = drmMalloc(sizeof(*r))))
647 r->id = blob.blob_id;
648 r->length = blob.length;
649 r->data = drmAllocCpy(U642VOID(blob.data), 1, blob.length);
652 drmFree(U642VOID(blob.data));
656 void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr)
665 int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
668 struct drm_mode_connector_set_property osp;
670 osp.connector_id = connector_id;
671 osp.prop_id = property_id;
674 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp);
678 * checks if a modesetting capable driver has attached to the pci id
679 * returns 0 if modesetting supported.
680 * -EINVAL or invalid bus id
681 * -ENOSYS if no modesetting support
683 int drmCheckModesettingSupported(const char *busid)
686 char pci_dev_dir[1024];
687 int domain, bus, dev, func;
692 ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
696 sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/drm",
697 domain, bus, dev, func);
699 sysdir = opendir(pci_dev_dir);
701 dent = readdir(sysdir);
703 if (!strncmp(dent->d_name, "controlD", 8)) {
708 dent = readdir(sysdir);
715 sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/",
716 domain, bus, dev, func);
718 sysdir = opendir(pci_dev_dir);
722 dent = readdir(sysdir);
724 if (!strncmp(dent->d_name, "drm:controlD", 12)) {
729 dent = readdir(sysdir);
740 int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
741 uint16_t *red, uint16_t *green, uint16_t *blue)
743 struct drm_mode_crtc_lut l;
747 l.red = VOID2U64(red);
748 l.green = VOID2U64(green);
749 l.blue = VOID2U64(blue);
751 return DRM_IOCTL(fd, DRM_IOCTL_MODE_GETGAMMA, &l);
754 int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
755 uint16_t *red, uint16_t *green, uint16_t *blue)
757 struct drm_mode_crtc_lut l;
761 l.red = VOID2U64(red);
762 l.green = VOID2U64(green);
763 l.blue = VOID2U64(blue);
765 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETGAMMA, &l);
768 int drmHandleEvent(int fd, drmEventContextPtr evctx)
773 struct drm_event_vblank *vblank;
775 /* The DRM read semantics guarantees that we always get only
776 * complete events. */
778 len = read(fd, buffer, sizeof buffer);
786 e = (struct drm_event *) &buffer[i];
788 case DRM_EVENT_VBLANK:
789 if (evctx->version < 1 ||
790 evctx->vblank_handler == NULL)
792 vblank = (struct drm_event_vblank *) e;
793 evctx->vblank_handler(fd,
797 U642VOID (vblank->user_data));
799 case DRM_EVENT_FLIP_COMPLETE:
800 if (evctx->version < 2 ||
801 evctx->page_flip_handler == NULL)
803 vblank = (struct drm_event_vblank *) e;
804 evctx->page_flip_handler(fd,
808 U642VOID (vblank->user_data));
819 int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
820 uint32_t flags, void *user_data)
822 struct drm_mode_crtc_page_flip flip;
825 flip.crtc_id = crtc_id;
826 flip.user_data = VOID2U64(user_data);
830 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);
833 int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
834 uint32_t fb_id, uint32_t flags,
835 uint32_t crtc_x, uint32_t crtc_y,
836 uint32_t crtc_w, uint32_t crtc_h,
837 uint32_t src_x, uint32_t src_y,
838 uint32_t src_w, uint32_t src_h)
841 struct drm_mode_set_plane s;
843 s.plane_id = plane_id;
856 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
860 drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
862 struct drm_mode_get_plane ovr, counts;
863 drmModePlanePtr r = 0;
866 memset(&ovr, 0, sizeof(struct drm_mode_get_plane));
867 ovr.plane_id = plane_id;
868 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
873 if (ovr.count_format_types) {
874 ovr.format_type_ptr = VOID2U64(drmMalloc(ovr.count_format_types *
876 if (!ovr.format_type_ptr)
880 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
883 if (counts.count_format_types < ovr.count_format_types) {
884 drmFree(U642VOID(ovr.format_type_ptr));
888 if (!(r = drmMalloc(sizeof(*r))))
891 r->count_formats = ovr.count_format_types;
892 r->plane_id = ovr.plane_id;
893 r->crtc_id = ovr.crtc_id;
894 r->fb_id = ovr.fb_id;
895 r->possible_crtcs = ovr.possible_crtcs;
896 r->gamma_size = ovr.gamma_size;
897 r->formats = drmAllocCpy(U642VOID(ovr.format_type_ptr),
898 ovr.count_format_types, sizeof(uint32_t));
899 if (ovr.count_format_types && !r->formats) {
905 drmFree(U642VOID(ovr.format_type_ptr));
910 void drmModeFreePlane(drmModePlanePtr ptr)
915 drmFree(ptr->formats);
919 drmModePlaneResPtr drmModeGetPlaneResources(int fd)
921 struct drm_mode_get_plane_res res, counts;
922 drmModePlaneResPtr r = 0;
925 memset(&res, 0, sizeof(struct drm_mode_get_plane_res));
926 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
931 if (res.count_planes) {
932 res.plane_id_ptr = VOID2U64(drmMalloc(res.count_planes *
934 if (!res.plane_id_ptr)
938 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
941 if (counts.count_planes < res.count_planes) {
942 drmFree(U642VOID(res.plane_id_ptr));
946 if (!(r = drmMalloc(sizeof(*r))))
949 r->count_planes = res.count_planes;
950 r->planes = drmAllocCpy(U642VOID(res.plane_id_ptr),
951 res.count_planes, sizeof(uint32_t));
952 if (res.count_planes && !r->planes) {
958 drmFree(U642VOID(res.plane_id_ptr));