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>
48 #include "xf86drmMode.h"
64 #define VG_CLEAR(s) VG(memset(&s, 0, sizeof(s)))
66 #define U642VOID(x) ((void *)(unsigned long)(x))
67 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
69 static inline int DRM_IOCTL(int fd, unsigned long cmd, void *arg)
71 int ret = drmIoctl(fd, cmd, arg);
72 return ret < 0 ? -errno : ret;
79 void* drmAllocCpy(void *array, int count, int entry_size)
84 if (!count || !array || !entry_size)
87 if (!(r = drmMalloc(count*entry_size)))
90 for (i = 0; i < count; i++)
91 memcpy(r+(entry_size*i), array+(entry_size*i), entry_size);
97 * A couple of free functions.
100 void drmModeFreeModeInfo(drmModeModeInfoPtr ptr)
108 void drmModeFreeResources(drmModeResPtr ptr)
115 drmFree(ptr->connectors);
116 drmFree(ptr->encoders);
121 void drmModeFreeFB(drmModeFBPtr ptr)
126 /* we might add more frees later. */
130 void drmModeFreeCrtc(drmModeCrtcPtr ptr)
139 void drmModeFreeConnector(drmModeConnectorPtr ptr)
144 drmFree(ptr->encoders);
145 drmFree(ptr->prop_values);
152 void drmModeFreeEncoder(drmModeEncoderPtr ptr)
158 * ModeSetting functions.
161 drmModeResPtr drmModeGetResources(int fd)
163 struct drm_mode_card_res res, counts;
167 memset(&res, 0, sizeof(struct drm_mode_card_res));
168 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
174 res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t)));
178 if (res.count_crtcs) {
179 res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t)));
180 if (!res.crtc_id_ptr)
183 if (res.count_connectors) {
184 res.connector_id_ptr = VOID2U64(drmMalloc(res.count_connectors*sizeof(uint32_t)));
185 if (!res.connector_id_ptr)
188 if (res.count_encoders) {
189 res.encoder_id_ptr = VOID2U64(drmMalloc(res.count_encoders*sizeof(uint32_t)));
190 if (!res.encoder_id_ptr)
194 if (drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res))
197 /* The number of available connectors and etc may have changed with a
198 * hotplug event in between the ioctls, in which case the field is
199 * silently ignored by the kernel.
201 if (counts.count_fbs < res.count_fbs ||
202 counts.count_crtcs < res.count_crtcs ||
203 counts.count_connectors < res.count_connectors ||
204 counts.count_encoders < res.count_encoders)
206 drmFree(U642VOID(res.fb_id_ptr));
207 drmFree(U642VOID(res.crtc_id_ptr));
208 drmFree(U642VOID(res.connector_id_ptr));
209 drmFree(U642VOID(res.encoder_id_ptr));
217 if (!(r = drmMalloc(sizeof(*r))))
220 r->min_width = res.min_width;
221 r->max_width = res.max_width;
222 r->min_height = res.min_height;
223 r->max_height = res.max_height;
224 r->count_fbs = res.count_fbs;
225 r->count_crtcs = res.count_crtcs;
226 r->count_connectors = res.count_connectors;
227 r->count_encoders = res.count_encoders;
229 r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
230 r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
231 r->connectors = drmAllocCpy(U642VOID(res.connector_id_ptr), res.count_connectors, sizeof(uint32_t));
232 r->encoders = drmAllocCpy(U642VOID(res.encoder_id_ptr), res.count_encoders, sizeof(uint32_t));
233 if ((res.count_fbs && !r->fbs) ||
234 (res.count_crtcs && !r->crtcs) ||
235 (res.count_connectors && !r->connectors) ||
236 (res.count_encoders && !r->encoders))
240 drmFree(r->connectors);
241 drmFree(r->encoders);
247 drmFree(U642VOID(res.fb_id_ptr));
248 drmFree(U642VOID(res.crtc_id_ptr));
249 drmFree(U642VOID(res.connector_id_ptr));
250 drmFree(U642VOID(res.encoder_id_ptr));
255 int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
256 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
259 struct drm_mode_fb_cmd f;
268 f.handle = bo_handle;
270 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB, &f)))
277 int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
278 uint32_t pixel_format, uint32_t bo_handles[4],
279 uint32_t pitches[4], uint32_t offsets[4],
280 uint32_t *buf_id, uint32_t flags)
282 struct drm_mode_fb_cmd2 f;
287 f.pixel_format = pixel_format;
289 memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0]));
290 memcpy(f.pitches, pitches, 4 * sizeof(pitches[0]));
291 memcpy(f.offsets, offsets, 4 * sizeof(offsets[0]));
293 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
300 int drmModeRmFB(int fd, uint32_t bufferId)
302 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
307 drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
309 struct drm_mode_fb_cmd info;
314 if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))
317 if (!(r = drmMalloc(sizeof(*r))))
320 r->fb_id = info.fb_id;
321 r->width = info.width;
322 r->height = info.height;
323 r->pitch = info.pitch;
325 r->handle = info.handle;
326 r->depth = info.depth;
331 int drmModeDirtyFB(int fd, uint32_t bufferId,
332 drmModeClipPtr clips, uint32_t num_clips)
334 struct drm_mode_fb_dirty_cmd dirty = { 0 };
336 dirty.fb_id = bufferId;
337 dirty.clips_ptr = VOID2U64(clips);
338 dirty.num_clips = num_clips;
340 return DRM_IOCTL(fd, DRM_IOCTL_MODE_DIRTYFB, &dirty);
348 drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
350 struct drm_mode_crtc crtc;
354 crtc.crtc_id = crtcId;
356 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCRTC, &crtc))
363 if (!(r = drmMalloc(sizeof(*r))))
366 r->crtc_id = crtc.crtc_id;
369 r->mode_valid = crtc.mode_valid;
371 memcpy(&r->mode, &crtc.mode, sizeof(struct drm_mode_modeinfo));
372 r->width = crtc.mode.hdisplay;
373 r->height = crtc.mode.vdisplay;
375 r->buffer_id = crtc.fb_id;
376 r->gamma_size = crtc.gamma_size;
381 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
382 uint32_t x, uint32_t y, uint32_t *connectors, int count,
383 drmModeModeInfoPtr mode)
385 struct drm_mode_crtc crtc;
390 crtc.crtc_id = crtcId;
391 crtc.fb_id = bufferId;
392 crtc.set_connectors_ptr = VOID2U64(connectors);
393 crtc.count_connectors = count;
395 memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
400 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
404 * Cursor manipulation
407 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height)
409 struct drm_mode_cursor arg;
411 arg.flags = DRM_MODE_CURSOR_BO;
412 arg.crtc_id = crtcId;
415 arg.handle = bo_handle;
417 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR, &arg);
420 int drmModeSetCursor2(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height, int32_t hot_x, int32_t hot_y)
422 struct drm_mode_cursor2 arg;
424 arg.flags = DRM_MODE_CURSOR_BO;
425 arg.crtc_id = crtcId;
428 arg.handle = bo_handle;
432 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR2, &arg);
435 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y)
437 struct drm_mode_cursor arg;
439 arg.flags = DRM_MODE_CURSOR_MOVE;
440 arg.crtc_id = crtcId;
444 return DRM_IOCTL(fd, DRM_IOCTL_MODE_CURSOR, &arg);
450 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id)
452 struct drm_mode_get_encoder enc;
453 drmModeEncoderPtr r = NULL;
455 enc.encoder_id = encoder_id;
457 enc.encoder_type = 0;
458 enc.possible_crtcs = 0;
459 enc.possible_clones = 0;
461 if (drmIoctl(fd, DRM_IOCTL_MODE_GETENCODER, &enc))
464 if (!(r = drmMalloc(sizeof(*r))))
467 r->encoder_id = enc.encoder_id;
468 r->crtc_id = enc.crtc_id;
469 r->encoder_type = enc.encoder_type;
470 r->possible_crtcs = enc.possible_crtcs;
471 r->possible_clones = enc.possible_clones;
477 * Connector manipulation
480 drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id)
482 struct drm_mode_get_connector conn, counts;
483 drmModeConnectorPtr r = NULL;
486 memset(&conn, 0, sizeof(struct drm_mode_get_connector));
487 conn.connector_id = connector_id;
489 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
494 if (conn.count_props) {
495 conn.props_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint32_t)));
498 conn.prop_values_ptr = VOID2U64(drmMalloc(conn.count_props*sizeof(uint64_t)));
499 if (!conn.prop_values_ptr)
503 if (conn.count_modes) {
504 conn.modes_ptr = VOID2U64(drmMalloc(conn.count_modes*sizeof(struct drm_mode_modeinfo)));
509 if (conn.count_encoders) {
510 conn.encoders_ptr = VOID2U64(drmMalloc(conn.count_encoders*sizeof(uint32_t)));
511 if (!conn.encoders_ptr)
515 if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
518 /* The number of available connectors and etc may have changed with a
519 * hotplug event in between the ioctls, in which case the field is
520 * silently ignored by the kernel.
522 if (counts.count_props < conn.count_props ||
523 counts.count_modes < conn.count_modes ||
524 counts.count_encoders < conn.count_encoders) {
525 drmFree(U642VOID(conn.props_ptr));
526 drmFree(U642VOID(conn.prop_values_ptr));
527 drmFree(U642VOID(conn.modes_ptr));
528 drmFree(U642VOID(conn.encoders_ptr));
533 if(!(r = drmMalloc(sizeof(*r)))) {
537 r->connector_id = conn.connector_id;
538 r->encoder_id = conn.encoder_id;
539 r->connection = conn.connection;
540 r->mmWidth = conn.mm_width;
541 r->mmHeight = conn.mm_height;
542 /* convert subpixel from kernel to userspace */
543 r->subpixel = conn.subpixel + 1;
544 r->count_modes = conn.count_modes;
545 r->count_props = conn.count_props;
546 r->props = drmAllocCpy(U642VOID(conn.props_ptr), conn.count_props, sizeof(uint32_t));
547 r->prop_values = drmAllocCpy(U642VOID(conn.prop_values_ptr), conn.count_props, sizeof(uint64_t));
548 r->modes = drmAllocCpy(U642VOID(conn.modes_ptr), conn.count_modes, sizeof(struct drm_mode_modeinfo));
549 r->count_encoders = conn.count_encoders;
550 r->encoders = drmAllocCpy(U642VOID(conn.encoders_ptr), conn.count_encoders, sizeof(uint32_t));
551 r->connector_type = conn.connector_type;
552 r->connector_type_id = conn.connector_type_id;
554 if ((r->count_props && !r->props) ||
555 (r->count_props && !r->prop_values) ||
556 (r->count_modes && !r->modes) ||
557 (r->count_encoders && !r->encoders)) {
559 drmFree(r->prop_values);
561 drmFree(r->encoders);
567 drmFree(U642VOID(conn.prop_values_ptr));
568 drmFree(U642VOID(conn.props_ptr));
569 drmFree(U642VOID(conn.modes_ptr));
570 drmFree(U642VOID(conn.encoders_ptr));
575 int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
577 struct drm_mode_mode_cmd res;
579 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
580 res.connector_id = connector_id;
582 return DRM_IOCTL(fd, DRM_IOCTL_MODE_ATTACHMODE, &res);
585 int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
587 struct drm_mode_mode_cmd res;
589 memcpy(&res.mode, mode_info, sizeof(struct drm_mode_modeinfo));
590 res.connector_id = connector_id;
592 return DRM_IOCTL(fd, DRM_IOCTL_MODE_DETACHMODE, &res);
596 drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
598 struct drm_mode_get_property prop;
599 drmModePropertyPtr r;
602 prop.prop_id = property_id;
603 prop.count_enum_blobs = 0;
604 prop.count_values = 0;
606 prop.enum_blob_ptr = 0;
609 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
612 if (prop.count_values)
613 prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t)));
615 if (prop.count_enum_blobs && (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)))
616 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum)));
618 if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_BLOB)) {
619 prop.values_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
620 prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(uint32_t)));
623 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) {
628 if (!(r = drmMalloc(sizeof(*r))))
631 r->prop_id = prop.prop_id;
632 r->count_values = prop.count_values;
634 r->flags = prop.flags;
635 if (prop.count_values)
636 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t));
637 if (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
638 r->count_enums = prop.count_enum_blobs;
639 r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum));
640 } else if (prop.flags & DRM_MODE_PROP_BLOB) {
641 r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_enum_blobs, sizeof(uint32_t));
642 r->blob_ids = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(uint32_t));
643 r->count_blobs = prop.count_enum_blobs;
645 strncpy(r->name, prop.name, DRM_PROP_NAME_LEN);
646 r->name[DRM_PROP_NAME_LEN-1] = 0;
649 drmFree(U642VOID(prop.values_ptr));
650 drmFree(U642VOID(prop.enum_blob_ptr));
655 void drmModeFreeProperty(drmModePropertyPtr ptr)
660 drmFree(ptr->values);
665 drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id)
667 struct drm_mode_get_blob blob;
668 drmModePropertyBlobPtr r;
672 blob.blob_id = blob_id;
674 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob))
678 blob.data = VOID2U64(drmMalloc(blob.length));
680 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) {
685 if (!(r = drmMalloc(sizeof(*r))))
688 r->id = blob.blob_id;
689 r->length = blob.length;
690 r->data = drmAllocCpy(U642VOID(blob.data), 1, blob.length);
693 drmFree(U642VOID(blob.data));
697 void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr)
706 int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
709 struct drm_mode_connector_set_property osp;
711 osp.connector_id = connector_id;
712 osp.prop_id = property_id;
715 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPROPERTY, &osp);
719 * checks if a modesetting capable driver has attached to the pci id
720 * returns 0 if modesetting supported.
721 * -EINVAL or invalid bus id
722 * -ENOSYS if no modesetting support
724 int drmCheckModesettingSupported(const char *busid)
726 #if defined (__linux__)
727 char pci_dev_dir[1024];
728 int domain, bus, dev, func;
733 ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
737 sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/drm",
738 domain, bus, dev, func);
740 sysdir = opendir(pci_dev_dir);
742 dent = readdir(sysdir);
744 if (!strncmp(dent->d_name, "controlD", 8)) {
749 dent = readdir(sysdir);
756 sprintf(pci_dev_dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/",
757 domain, bus, dev, func);
759 sysdir = opendir(pci_dev_dir);
763 dent = readdir(sysdir);
765 if (!strncmp(dent->d_name, "drm:controlD", 12)) {
770 dent = readdir(sysdir);
776 #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
777 char kbusid[1024], sbusid[1024];
779 int domain, bus, dev, func;
780 int i, modesetting, ret;
783 ret = sscanf(busid, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev,
787 snprintf(kbusid, sizeof(kbusid), "pci:%04x:%02x:%02x.%d", domain, bus,
790 /* How many GPUs do we expect in the machine ? */
791 for (i = 0; i < 16; i++) {
792 snprintf(oid, sizeof(oid), "hw.dri.%d.busid", i);
793 len = sizeof(sbusid);
794 ret = sysctlbyname(oid, sbusid, &len, NULL, 0);
800 if (strcmp(sbusid, kbusid) != 0)
802 snprintf(oid, sizeof(oid), "hw.dri.%d.modesetting", i);
803 len = sizeof(modesetting);
804 ret = sysctlbyname(oid, &modesetting, &len, NULL, 0);
805 if (ret == -1 || len != sizeof(modesetting))
807 return (modesetting ? 0 : -ENOSYS);
814 int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
815 uint16_t *red, uint16_t *green, uint16_t *blue)
817 struct drm_mode_crtc_lut l;
821 l.red = VOID2U64(red);
822 l.green = VOID2U64(green);
823 l.blue = VOID2U64(blue);
825 return DRM_IOCTL(fd, DRM_IOCTL_MODE_GETGAMMA, &l);
828 int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
829 uint16_t *red, uint16_t *green, uint16_t *blue)
831 struct drm_mode_crtc_lut l;
835 l.red = VOID2U64(red);
836 l.green = VOID2U64(green);
837 l.blue = VOID2U64(blue);
839 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETGAMMA, &l);
842 int drmHandleEvent(int fd, drmEventContextPtr evctx)
847 struct drm_event_vblank *vblank;
849 /* The DRM read semantics guarantees that we always get only
850 * complete events. */
852 len = read(fd, buffer, sizeof buffer);
860 e = (struct drm_event *) &buffer[i];
862 case DRM_EVENT_VBLANK:
863 if (evctx->version < 1 ||
864 evctx->vblank_handler == NULL)
866 vblank = (struct drm_event_vblank *) e;
867 evctx->vblank_handler(fd,
871 U642VOID (vblank->user_data));
873 case DRM_EVENT_FLIP_COMPLETE:
874 if (evctx->version < 2 ||
875 evctx->page_flip_handler == NULL)
877 vblank = (struct drm_event_vblank *) e;
878 evctx->page_flip_handler(fd,
882 U642VOID (vblank->user_data));
893 int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
894 uint32_t flags, void *user_data)
896 struct drm_mode_crtc_page_flip flip;
899 flip.crtc_id = crtc_id;
900 flip.user_data = VOID2U64(user_data);
904 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);
907 int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
908 uint32_t fb_id, uint32_t flags,
909 uint32_t crtc_x, uint32_t crtc_y,
910 uint32_t crtc_w, uint32_t crtc_h,
911 uint32_t src_x, uint32_t src_y,
912 uint32_t src_w, uint32_t src_h)
915 struct drm_mode_set_plane s;
917 s.plane_id = plane_id;
930 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
934 drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
936 struct drm_mode_get_plane ovr, counts;
937 drmModePlanePtr r = 0;
940 memset(&ovr, 0, sizeof(struct drm_mode_get_plane));
941 ovr.plane_id = plane_id;
942 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
947 if (ovr.count_format_types) {
948 ovr.format_type_ptr = VOID2U64(drmMalloc(ovr.count_format_types *
950 if (!ovr.format_type_ptr)
954 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
957 if (counts.count_format_types < ovr.count_format_types) {
958 drmFree(U642VOID(ovr.format_type_ptr));
962 if (!(r = drmMalloc(sizeof(*r))))
965 r->count_formats = ovr.count_format_types;
966 r->plane_id = ovr.plane_id;
967 r->crtc_id = ovr.crtc_id;
968 r->fb_id = ovr.fb_id;
969 r->possible_crtcs = ovr.possible_crtcs;
970 r->gamma_size = ovr.gamma_size;
971 r->formats = drmAllocCpy(U642VOID(ovr.format_type_ptr),
972 ovr.count_format_types, sizeof(uint32_t));
973 if (ovr.count_format_types && !r->formats) {
980 drmFree(U642VOID(ovr.format_type_ptr));
985 void drmModeFreePlane(drmModePlanePtr ptr)
990 drmFree(ptr->formats);
994 drmModePlaneResPtr drmModeGetPlaneResources(int fd)
996 struct drm_mode_get_plane_res res, counts;
997 drmModePlaneResPtr r = 0;
1000 memset(&res, 0, sizeof(struct drm_mode_get_plane_res));
1001 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
1006 if (res.count_planes) {
1007 res.plane_id_ptr = VOID2U64(drmMalloc(res.count_planes *
1009 if (!res.plane_id_ptr)
1013 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
1016 if (counts.count_planes < res.count_planes) {
1017 drmFree(U642VOID(res.plane_id_ptr));
1021 if (!(r = drmMalloc(sizeof(*r))))
1024 r->count_planes = res.count_planes;
1025 r->planes = drmAllocCpy(U642VOID(res.plane_id_ptr),
1026 res.count_planes, sizeof(uint32_t));
1027 if (res.count_planes && !r->planes) {
1034 drmFree(U642VOID(res.plane_id_ptr));
1039 void drmModeFreePlaneResources(drmModePlaneResPtr ptr)
1044 drmFree(ptr->planes);
1048 drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
1050 uint32_t object_type)
1052 struct drm_mode_obj_get_properties properties;
1053 drmModeObjectPropertiesPtr ret = NULL;
1057 memset(&properties, 0, sizeof(struct drm_mode_obj_get_properties));
1058 properties.obj_id = object_id;
1059 properties.obj_type = object_type;
1061 if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
1064 count = properties.count_props;
1067 properties.props_ptr = VOID2U64(drmMalloc(count *
1069 if (!properties.props_ptr)
1071 properties.prop_values_ptr = VOID2U64(drmMalloc(count *
1073 if (!properties.prop_values_ptr)
1077 if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
1080 if (count < properties.count_props) {
1081 drmFree(U642VOID(properties.props_ptr));
1082 drmFree(U642VOID(properties.prop_values_ptr));
1085 count = properties.count_props;
1087 ret = drmMalloc(sizeof(*ret));
1091 ret->count_props = count;
1092 ret->props = drmAllocCpy(U642VOID(properties.props_ptr),
1093 count, sizeof(uint32_t));
1094 ret->prop_values = drmAllocCpy(U642VOID(properties.prop_values_ptr),
1095 count, sizeof(uint64_t));
1096 if (ret->count_props && (!ret->props || !ret->prop_values)) {
1097 drmFree(ret->props);
1098 drmFree(ret->prop_values);
1104 drmFree(U642VOID(properties.props_ptr));
1105 drmFree(U642VOID(properties.prop_values_ptr));
1109 void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr)
1113 drmFree(ptr->props);
1114 drmFree(ptr->prop_values);
1118 int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type,
1119 uint32_t property_id, uint64_t value)
1121 struct drm_mode_obj_set_property prop;
1124 prop.prop_id = property_id;
1125 prop.obj_id = object_id;
1126 prop.obj_type = object_type;
1128 return DRM_IOCTL(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY, &prop);