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)
101 drmFree(ptr->connectors);
102 drmFree(ptr->encoders);
107 void drmModeFreeFB(drmModeFBPtr ptr)
112 /* we might add more frees later. */
116 void drmModeFreeCrtc(drmModeCrtcPtr ptr)
125 void drmModeFreeConnector(drmModeConnectorPtr ptr)
130 drmFree(ptr->encoders);
131 drmFree(ptr->prop_values);
138 void drmModeFreeEncoder(drmModeEncoderPtr ptr)
144 * ModeSetting functions.
147 drmModeResPtr drmModeGetResources(int fd)
149 struct drm_mode_card_res res, counts;
153 memset(&res, 0, sizeof(struct drm_mode_card_res));
154 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
160 res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t)));
164 if (res.count_crtcs) {
165 res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t)));
166 if (!res.crtc_id_ptr)
169 if (res.count_connectors) {
170 res.connector_id_ptr = VOID2U64(drmMalloc(res.count_connectors*sizeof(uint32_t)));
171 if (!res.connector_id_ptr)
174 if (res.count_encoders) {
175 res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t)));
176 if (!res.encoder_id_ptr)
180 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
183 /* The number of available connectors and etc may have changed with a
184 * hotplug event in between the ioctls, in which case the field is
185 * silently ignored by the kernel.
187 if (counts.count_fbs < res.count_fbs ||
188 counts.count_crtcs < res.count_crtcs ||
189 counts.count_connectors < res.count_connectors ||
190 counts.count_encoders < res.count_encoders)
192 drmFree(U642VOID(res.fb_id_ptr));
193 drmFree(U642VOID(res.crtc_id_ptr));
194 drmFree(U642VOID(res.connector_id_ptr));
195 drmFree(U642VOID(res.encoder_id_ptr));
203 if (!(r = drmMalloc(sizeof(*r))))
206 r->min_width = res.min_width;
207 r->max_width = res.max_width;
208 r->min_height = res.min_height;
209 r->max_height = res.max_height;
210 r->count_fbs = res.count_fbs;
211 r->count_crtcs = res.count_crtcs;
212 r->count_connectors = res.count_connectors;
213 r->count_encoders = res.count_encoders;
215 r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
216 r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
217 r->connectors = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t));
218 r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t));
219 if ((res.count_fbs && !r->fbs) ||
220 (res.count_crtcs && !r->crtcs) ||
221 (res.count_connectors && !r->connectors) ||
222 (res.count_encoders && !r->encoders))
226 drmFree(r->connectors);
227 drmFree(r->encoders);
233 drmFree(U642VOID(res.fb_id_ptr));
234 drmFree(U642VOID(res.crtc_id_ptr));
235 drmFree(U642VOID(res.connector_id_ptr));
236 drmFree(U642VOID(res.encoder_id_ptr));
241 int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
242 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
245 struct drm_mode_fb_cmd f;
253 f.handle = bo_handle;
255 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB, &f)))
262 int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
263 uint32_t pixel_format, uint32_t bo_handles[4],
264 uint32_t pitches[4], uint32_t offsets[4],
265 uint32_t *buf_id, uint32_t flags)
267 struct drm_mode_fb_cmd2 f;
272 f.pixel_format = pixel_format;
274 memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0]));
275 memcpy(f.pitches, pitches, 4 * sizeof(pitches[0]));
276 memcpy(f.offsets, offsets, 4 * sizeof(offsets[0]));
278 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
285 int drmModeRmFB(int fd, uint32_t bufferId)
287 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
292 drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
294 struct drm_mode_fb_cmd info;
299 if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))
302 if (!(r = drmMalloc(sizeof(*r))))
305 r->fb_id = info.fb_id;
306 r->width = info.width;
307 r->height = info.height;
308 r->pitch = info.pitch;
310 r->handle = info.handle;
311 r->depth = info.depth;
316 int drmModeDirtyFB(int fd, uint32_t bufferId,
317 drmModeClipPtr clips, uint32_t num_clips)
319 struct drm_mode_fb_dirty_cmd dirty = { 0 };
321 dirty.fb_id = bufferId;
322 dirty.clips_ptr = VOID2U64(clips);
323 dirty.num_clips = num_clips;
325 return DRM_IOCTL(fd, DRM_IOCTL_MODE_DIRTYFB, &dirty);
333 drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
335 struct drm_mode_crtc crtc;
338 crtc.crtc_id = crtcId;
340 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc))
347 if (!(r = drmMalloc(sizeof(*r))))
350 r->crtc_id = crtc.crtc_id;
353 r->mode_valid = crtc.mode_valid;
355 memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo));
356 r->width = crtc.mode.hdisplay;
357 r->height = crtc.mode.vdisplay;
359 r->buffer_id = crtc.fb_id;
360 r->gamma_size = crtc.gamma_size;
365 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
366 uint32_t x, uint32_t y, uint32_t *connectors, int count,
367 drmModeModeInfoPtr mode)
369 struct drm_mode_crtc crtc;
373 crtc.crtc_id = crtcId;
374 crtc.fb_id = bufferId;
375 crtc.set_connectors_ptr = VOID2U64(connectors);
376 crtc.count_connectors = count;
378 memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
383 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
387 * Cursor manipulation
390 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height)
392 struct drm_mode_cursor arg;
394 arg.flags = DRM_MODE_CURSOR_BO;
395 arg.crtc_id = crtcId;
398 arg.handle = bo_handle;
400 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR, &arg);
403 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y)
405 struct drm_mode_cursor arg;
407 arg.flags = DRM_MODE_CURSOR_MOVE;
408 arg.crtc_id = crtcId;
412 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR, &arg);
418 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id)
420 struct drm_mode_get_encoder enc;
421 drmModeEncoderPtr r = NULL;
423 enc.encoder_id = encoder_id;
424 enc.encoder_type = 0;
425 enc.possible_crtcs = 0;
426 enc.possible_clones = 0;
428 if (drmIoctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc))
431 if (!(r = drmMalloc(sizeof(*r))))
434 r->encoder_id = enc.encoder_id;
435 r->crtc_id = enc.crtc_id;
436 r->encoder_type = enc.encoder_type;
437 r->possible_crtcs = enc.possible_crtcs;
438 r->possible_clones = enc.possible_clones;
444 * Connector manipulation
447 drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id)
449 struct drm_mode_get_connector conn, counts;
450 drmModeConnectorPtr r = NULL;
453 memset(&conn, 0, sizeof(struct drm_mode_get_connector));
454 conn.connector_id = connector_id;
456 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
461 if (conn.count_props) {
462 conn.props_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint32_t)));
465 conn.prop_values_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint64_t)));
466 if (!conn.prop_values_ptr)
470 if (conn.count_modes) {
471 conn.modes_ptr = VOID2U64(drmMalloc(conn.count_modes*sizeof(struct drm_mode_modeinfo)));
476 if (conn.count_encoders) {
477 conn.encoders_ptr = VOID2U64(drmMalloc(conn.count_encoders*sizeof(uint32_t)));
478 if (!conn.encoders_ptr)
482 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
485 /* The number of available connectors and etc may have changed with a
486 * hotplug event in between the ioctls, in which case the field is
487 * silently ignored by the kernel.
489 if (counts.count_props < conn.count_props ||
490 counts.count_modes < conn.count_modes ||
491 counts.count_encoders < conn.count_encoders) {
492 drmFree(U642VOID(conn.props_ptr));
493 drmFree(U642VOID(conn.prop_values_ptr));
494 drmFree(U642VOID(conn.modes_ptr));
495 drmFree(U642VOID(conn.encoders_ptr));
500 if(!(r = drmMalloc(sizeof(*r)))) {
504 r->connector_id = conn.connector_id;
505 r->encoder_id = conn.encoder_id;
506 r->connection = conn.connection;
507 r->mmWidth = conn.mm_width;
508 r->mmHeight = conn.mm_height;
509 /* convert subpixel from kernel to userspace */
510 r->subpixel = conn.subpixel + 1;
511 r->count_modes = conn.count_modes;
512 r->count_props = conn.count_props;
513 r->props = drmAllocCpy(U642VOID(conn.props_ptr), conn.count_props, sizeof(uint32_t));
514 r->prop_values = drmAllocCpy(U642VOID(conn.prop_values_ptr), conn.count_props, sizeof(uint64_t));
515 r->modes = drmAllocCpy(U642VOID(conn.modes_ptr), conn.count_modes, sizeof(struct drm_mode_modeinfo));
516 r->count_encoders = conn.count_encoders;
517 r->encoders = drmAllocCpy(U642VOID(conn.encoders_ptr), conn.count_encoders, sizeof(uint32_t));
518 r->connector_type = conn.connector_type;
519 r->connector_type_id = conn.connector_type_id;
521 if ((r->count_props && !r->props) ||
522 (r->count_props && !r->prop_values) ||
523 (r->count_modes && !r->modes) ||
524 (r->count_encoders && !r->encoders)) {
526 drmFree(r->prop_values);
528 drmFree(r->encoders);
534 drmFree(U642VOID(conn.prop_values_ptr));
535 drmFree(U642VOID(conn.props_ptr));
536 drmFree(U642VOID(conn.modes_ptr));
537 drmFree(U642VOID(conn.encoders_ptr));
542 int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
544 struct drm_mode_mode_cmd res;
546 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
547 res.connector_id = connector_id;
549 return DRM_IOCTL(fd, DRM_IOCTL_MODE_ATTACHMODE, &res);
552 int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
554 struct drm_mode_mode_cmd res;
556 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
557 res.connector_id = connector_id;
559 return DRM_IOCTL(fd, DRM_IOCTL_MODE_DETACHMODE, &res);
563 drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
565 struct drm_mode_get_property prop;
566 drmModePropertyPtr r;
568 prop.prop_id = property_id;
569 prop.count_enum_blobs = 0;
570 prop.count_values = 0;
572 prop.enum_blob_ptr = 0;
575 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
578 if (prop.count_values)
579 prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t)));
581 if (prop.count_enum_blobs && (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)))
582 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum)));
584 if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_BLOB)) {
585 prop.values_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
586 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
589 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) {
594 if (!(r = drmMalloc(sizeof(*r))))
597 r->prop_id = prop.prop_id;
598 r->count_values = prop.count_values;
600 r->flags = prop.flags;
601 if (prop.count_values)
602 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t));
603 if (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
604 r->count_enums = prop.count_enum_blobs;
605 r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum));
606 } else if (prop.flags & DRM_MODE_PROP_BLOB) {
607 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_enum_blobs, sizeof(uint32_t));
608 r->blob_ids = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(uint32_t));
609 r->count_blobs = prop.count_enum_blobs;
611 strncpy(r->name, prop.name, DRM_PROP_NAME_LEN);
612 r->name[DRM_PROP_NAME_LEN-1] = 0;
615 drmFree(U642VOID(prop.values_ptr));
616 drmFree(U642VOID(prop.enum_blob_ptr));
621 void drmModeFreeProperty(drmModePropertyPtr ptr)
626 drmFree(ptr->values);
631 drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id)
633 struct drm_mode_get_blob blob;
634 drmModePropertyBlobPtr r;
638 blob.blob_id = blob_id;
640 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob))
644 blob.data = VOID2U64(drmMalloc(blob.length));
646 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) {
651 if (!(r = drmMalloc(sizeof(*r))))
654 r->id = blob.blob_id;
655 r->length = blob.length;
656 r->data = drmAllocCpy(U642VOID(blob.data), 1, blob.length);
659 drmFree(U642VOID(blob.data));
663 void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr)
672 int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
675 struct drm_mode_connector_set_property osp;
677 osp.connector_id = connector_id;
678 osp.prop_id = property_id;
681 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp);
685 * checks if a modesetting capable driver has attached to the pci id
686 * returns 0 if modesetting supported.
687 * -EINVAL or invalid bus id
688 * -ENOSYS if no modesetting support
690 int drmCheckModesettingSupported(const char *busid)
693 char pci_dev_dir[1024];
694 int domain, bus, dev, func;
699 ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
703 sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/drm",
704 domain, bus, dev, func);
706 sysdir = opendir(pci_dev_dir);
708 dent = readdir(sysdir);
710 if (!strncmp(dent->d_name, "controlD", 8)) {
715 dent = readdir(sysdir);
722 sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/",
723 domain, bus, dev, func);
725 sysdir = opendir(pci_dev_dir);
729 dent = readdir(sysdir);
731 if (!strncmp(dent->d_name, "drm:controlD", 12)) {
736 dent = readdir(sysdir);
747 int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
748 uint16_t *red, uint16_t *green, uint16_t *blue)
750 struct drm_mode_crtc_lut l;
754 l.red = VOID2U64(red);
755 l.green = VOID2U64(green);
756 l.blue = VOID2U64(blue);
758 return DRM_IOCTL(fd, DRM_IOCTL_MODE_GETGAMMA, &l);
761 int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
762 uint16_t *red, uint16_t *green, uint16_t *blue)
764 struct drm_mode_crtc_lut l;
768 l.red = VOID2U64(red);
769 l.green = VOID2U64(green);
770 l.blue = VOID2U64(blue);
772 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETGAMMA, &l);
775 int drmHandleEvent(int fd, drmEventContextPtr evctx)
780 struct drm_event_vblank *vblank;
782 /* The DRM read semantics guarantees that we always get only
783 * complete events. */
785 len = read(fd, buffer, sizeof buffer);
793 e = (struct drm_event *) &buffer[i];
795 case DRM_EVENT_VBLANK:
796 if (evctx->version < 1 ||
797 evctx->vblank_handler == NULL)
799 vblank = (struct drm_event_vblank *) e;
800 evctx->vblank_handler(fd,
804 U642VOID (vblank->user_data));
806 case DRM_EVENT_FLIP_COMPLETE:
807 if (evctx->version < 2 ||
808 evctx->page_flip_handler == NULL)
810 vblank = (struct drm_event_vblank *) e;
811 evctx->page_flip_handler(fd,
815 U642VOID (vblank->user_data));
826 int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
827 uint32_t flags, void *user_data)
829 struct drm_mode_crtc_page_flip flip;
832 flip.crtc_id = crtc_id;
833 flip.user_data = VOID2U64(user_data);
837 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);
840 int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
841 uint32_t fb_id, uint32_t flags,
842 uint32_t crtc_x, uint32_t crtc_y,
843 uint32_t crtc_w, uint32_t crtc_h,
844 uint32_t src_x, uint32_t src_y,
845 uint32_t src_w, uint32_t src_h)
848 struct drm_mode_set_plane s;
850 s.plane_id = plane_id;
863 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
867 drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
869 struct drm_mode_get_plane ovr, counts;
870 drmModePlanePtr r = 0;
873 memset(&ovr, 0, sizeof(struct drm_mode_get_plane));
874 ovr.plane_id = plane_id;
875 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
880 if (ovr.count_format_types) {
881 ovr.format_type_ptr = VOID2U64(drmMalloc(ovr.count_format_types *
883 if (!ovr.format_type_ptr)
887 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
890 if (counts.count_format_types < ovr.count_format_types) {
891 drmFree(U642VOID(ovr.format_type_ptr));
895 if (!(r = drmMalloc(sizeof(*r))))
898 r->count_formats = ovr.count_format_types;
899 r->plane_id = ovr.plane_id;
900 r->crtc_id = ovr.crtc_id;
901 r->fb_id = ovr.fb_id;
902 r->possible_crtcs = ovr.possible_crtcs;
903 r->gamma_size = ovr.gamma_size;
904 r->formats = drmAllocCpy(U642VOID(ovr.format_type_ptr),
905 ovr.count_format_types, sizeof(uint32_t));
906 if (ovr.count_format_types && !r->formats) {
913 drmFree(U642VOID(ovr.format_type_ptr));
918 void drmModeFreePlane(drmModePlanePtr ptr)
923 drmFree(ptr->formats);
927 drmModePlaneResPtr drmModeGetPlaneResources(int fd)
929 struct drm_mode_get_plane_res res, counts;
930 drmModePlaneResPtr r = 0;
933 memset(&res, 0, sizeof(struct drm_mode_get_plane_res));
934 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
939 if (res.count_planes) {
940 res.plane_id_ptr = VOID2U64(drmMalloc(res.count_planes *
942 if (!res.plane_id_ptr)
946 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
949 if (counts.count_planes < res.count_planes) {
950 drmFree(U642VOID(res.plane_id_ptr));
954 if (!(r = drmMalloc(sizeof(*r))))
957 r->count_planes = res.count_planes;
958 r->planes = drmAllocCpy(U642VOID(res.plane_id_ptr),
959 res.count_planes, sizeof(uint32_t));
960 if (res.count_planes && !r->planes) {
967 drmFree(U642VOID(res.plane_id_ptr));
972 void drmModeFreePlaneResources(drmModePlaneResPtr ptr)
977 drmFree(ptr->planes);
981 drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
983 uint32_t object_type)
985 struct drm_mode_obj_get_properties properties;
986 drmModeObjectPropertiesPtr ret = NULL;
990 memset(&properties, 0, sizeof(struct drm_mode_obj_get_properties));
991 properties.obj_id = object_id;
992 properties.obj_type = object_type;
994 if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
997 count = properties.count_props;
1000 properties.props_ptr = VOID2U64(drmMalloc(count *
1002 if (!properties.props_ptr)
1004 properties.prop_values_ptr = VOID2U64(drmMalloc(count *
1006 if (!properties.prop_values_ptr)
1010 if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
1013 if (count < properties.count_props) {
1014 drmFree(U642VOID(properties.props_ptr));
1015 drmFree(U642VOID(properties.prop_values_ptr));
1018 count = properties.count_props;
1020 ret = drmMalloc(sizeof(*ret));
1024 ret->count_props = count;
1025 ret->props = drmAllocCpy(U642VOID(properties.props_ptr),
1026 count, sizeof(uint32_t));
1027 ret->prop_values = drmAllocCpy(U642VOID(properties.prop_values_ptr),
1028 count, sizeof(uint64_t));
1029 if (ret->count_props && (!ret->props || !ret->prop_values)) {
1030 drmFree(ret->props);
1031 drmFree(ret->prop_values);
1037 drmFree(U642VOID(properties.props_ptr));
1038 drmFree(U642VOID(properties.prop_values_ptr));
1042 void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr)
1046 drmFree(ptr->props);
1047 drmFree(ptr->prop_values);
1051 int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type,
1052 uint32_t property_id, uint64_t value)
1054 struct drm_mode_obj_set_property prop;
1057 prop.prop_id = property_id;
1058 prop.obj_id = object_id;
1059 prop.obj_type = object_type;
1061 return DRM_IOCTL(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY, &prop);