Lines Matching +full:int +full:- +full:property
2 * Copyright (c) 2006-2008 Intel Corporation
43 char *fnname(int val) \
45 int i; \
84 * Non-global properties, but "required" for certain connectors.
88 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
89 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
90 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
97 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
98 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
99 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
107 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
108 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
109 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
110 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
111 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
118 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
119 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
120 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
121 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
122 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
138 int type;
140 int count;
149 { DRM_MODE_CONNECTOR_DVII, "DVI-I", 0 },
150 { DRM_MODE_CONNECTOR_DVID, "DVI-D", 0 },
151 { DRM_MODE_CONNECTOR_DVIA, "DVI-A", 0 },
158 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A", 0 },
159 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 },
178 snprintf(buf, 32, "%s-%d",
179 drm_encoder_enum_list[encoder->encoder_type].name,
180 encoder->base.id);
189 snprintf(buf, 32, "%s-%d",
190 drm_connector_enum_list[connector->connector_type].name,
191 connector->connector_type_id);
207 * drm_mode_object_get - allocate a new identifier
221 static int drm_mode_object_get(struct drm_device *dev,
224 int new_id = 0;
225 int ret;
227 ret = drm_gem_name_create(&dev->mode_config.crtc_names, obj, &new_id);
231 obj->id = new_id;
232 obj->type = obj_type;
237 * drm_mode_object_put - free an identifer
250 drm_gem_names_remove(&dev->mode_config.crtc_names, object->id);
258 obj = drm_gem_name_ref(&dev->mode_config.crtc_names, id, NULL);
259 if (!obj || (obj->type != type) || (obj->id != id))
267 * drm_framebuffer_init - initialize a framebuffer
279 int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
282 int ret;
284 refcount_init(&fb->refcount, 1);
286 ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB);
290 fb->dev = dev;
291 fb->funcs = funcs;
292 dev->mode_config.num_fb++;
293 list_add(&fb->head, &dev->mode_config.fb_list);
301 fb->funcs->destroy(fb);
305 * drm_framebuffer_unreference - unref a framebuffer
312 struct drm_device *dev = fb->dev;
313 DRM_DEBUG("FB ID: %d\n", fb->base.id);
314 if (!sx_xlocked(&dev->mode_config.mutex))
315 DRM_WARNING("%s: dev->mode_config.mutex not locked\n", __func__);
316 if (refcount_release(&fb->refcount))
322 * drm_framebuffer_reference - incr the fb refcnt
326 DRM_DEBUG("FB ID: %d\n", fb->base.id);
327 refcount_acquire(&fb->refcount);
332 * drm_framebuffer_cleanup - remove a framebuffer object
343 struct drm_device *dev = fb->dev;
351 drm_mode_object_put(dev, &fb->base);
352 list_del(&fb->head);
353 dev->mode_config.num_fb--;
358 * drm_framebuffer_remove - remove and unreference a framebuffer object
369 struct drm_device *dev = fb->dev;
373 int ret;
376 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
377 if (crtc->fb == fb) {
382 ret = crtc->funcs->set_config(&set);
388 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
389 if (plane->fb == fb) {
391 ret = plane->funcs->disable_plane(plane);
395 plane->fb = NULL;
396 plane->crtc = NULL;
400 list_del(&fb->filp_head);
407 * drm_crtc_init - Initialise a new CRTC object
420 int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
423 int ret;
425 crtc->dev = dev;
426 crtc->funcs = funcs;
427 crtc->invert_dimensions = false;
429 sx_xlock(&dev->mode_config.mutex);
431 ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
435 crtc->base.properties = &crtc->properties;
437 list_add_tail(&crtc->head, &dev->mode_config.crtc_list);
438 dev->mode_config.num_crtc++;
441 sx_xunlock(&dev->mode_config.mutex);
448 * drm_crtc_cleanup - Cleans up the core crtc usage.
459 struct drm_device *dev = crtc->dev;
461 free(crtc->gamma_store, DRM_MEM_KMS);
462 crtc->gamma_store = NULL;
464 drm_mode_object_put(dev, &crtc->base);
465 list_del(&crtc->head);
466 dev->mode_config.num_crtc--;
471 * drm_mode_probed_add - add a mode to a connector's probed mode list
483 list_add(&mode->head, &connector->probed_modes);
488 * drm_mode_remove - remove and free a mode
500 list_del(&mode->head);
501 drm_mode_destroy(connector->dev, mode);
506 * drm_connector_init - Init a preallocated connector
521 int drm_connector_init(struct drm_device *dev,
524 int connector_type)
526 int ret;
528 sx_xlock(&dev->mode_config.mutex);
530 ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR);
534 connector->base.properties = &connector->properties;
535 connector->dev = dev;
536 connector->funcs = funcs;
537 connector->connector_type = connector_type;
538 connector->connector_type_id =
540 INIT_LIST_HEAD(&connector->user_modes);
541 INIT_LIST_HEAD(&connector->probed_modes);
542 INIT_LIST_HEAD(&connector->modes);
543 connector->edid_blob_ptr = NULL;
544 connector->status = connector_status_unknown;
546 list_add_tail(&connector->head, &dev->mode_config.connector_list);
547 dev->mode_config.num_connector++;
550 drm_object_attach_property(&connector->base,
551 dev->mode_config.edid_property,
554 drm_object_attach_property(&connector->base,
555 dev->mode_config.dpms_property, 0);
558 sx_xunlock(&dev->mode_config.mutex);
565 * drm_connector_cleanup - cleans up an initialised connector
575 struct drm_device *dev = connector->dev;
578 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
581 list_for_each_entry_safe(mode, t, &connector->modes, head)
584 list_for_each_entry_safe(mode, t, &connector->user_modes, head)
587 sx_xlock(&dev->mode_config.mutex);
588 drm_mode_object_put(dev, &connector->base);
589 list_del(&connector->head);
590 dev->mode_config.num_connector--;
591 sx_xunlock(&dev->mode_config.mutex);
601 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
608 int drm_encoder_init(struct drm_device *dev,
611 int encoder_type)
613 int ret;
615 sx_xlock(&dev->mode_config.mutex);
617 ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
621 encoder->dev = dev;
622 encoder->encoder_type = encoder_type;
623 encoder->funcs = funcs;
625 list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
626 dev->mode_config.num_encoder++;
629 sx_xunlock(&dev->mode_config.mutex);
637 struct drm_device *dev = encoder->dev;
638 sx_xlock(&dev->mode_config.mutex);
639 drm_mode_object_put(dev, &encoder->base);
640 list_del(&encoder->head);
641 dev->mode_config.num_encoder--;
642 sx_xunlock(&dev->mode_config.mutex);
646 int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
652 int ret;
654 sx_xlock(&dev->mode_config.mutex);
656 ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
660 plane->base.properties = &plane->properties;
661 plane->dev = dev;
662 plane->funcs = funcs;
663 plane->format_types = malloc(sizeof(uint32_t) * format_count,
665 memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
666 plane->format_count = format_count;
667 plane->possible_crtcs = possible_crtcs;
674 list_add_tail(&plane->head, &dev->mode_config.plane_list);
675 dev->mode_config.num_plane++;
677 INIT_LIST_HEAD(&plane->head);
681 sx_xunlock(&dev->mode_config.mutex);
689 struct drm_device *dev = plane->dev;
691 sx_xlock(&dev->mode_config.mutex);
692 free(plane->format_types, DRM_MEM_KMS);
693 drm_mode_object_put(dev, &plane->base);
695 if (!list_empty(&plane->head)) {
696 list_del(&plane->head);
697 dev->mode_config.num_plane--;
699 sx_xunlock(&dev->mode_config.mutex);
704 * drm_mode_create - create a new display mode
722 if (drm_mode_object_get(dev, &nmode->base, DRM_MODE_OBJECT_MODE)) {
732 * drm_mode_destroy - remove a mode
746 drm_mode_object_put(dev, &mode->base);
752 static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
763 dev->mode_config.edid_property = edid;
768 dev->mode_config.dpms_property = dpms;
774 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
777 * Called by a driver the first time a DVI-I connector is made.
779 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
784 if (dev->mode_config.dvi_i_select_subconnector_property)
792 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
798 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
805 * drm_create_tv_properties - create TV specific connector properties
815 int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
820 int i;
822 if (dev->mode_config.tv_select_subconnector_property)
832 dev->mode_config.tv_select_subconnector_property = tv_selector;
839 dev->mode_config.tv_subconnector_property = tv_subconnector;
844 dev->mode_config.tv_left_margin_property =
847 dev->mode_config.tv_right_margin_property =
850 dev->mode_config.tv_top_margin_property =
853 dev->mode_config.tv_bottom_margin_property =
856 dev->mode_config.tv_mode_property =
860 drm_property_add_enum(dev->mode_config.tv_mode_property, i,
863 dev->mode_config.tv_brightness_property =
866 dev->mode_config.tv_contrast_property =
869 dev->mode_config.tv_flicker_reduction_property =
872 dev->mode_config.tv_overscan_property =
875 dev->mode_config.tv_saturation_property =
878 dev->mode_config.tv_hue_property =
886 * drm_mode_create_scaling_mode_property - create scaling mode property
892 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
896 if (dev->mode_config.scaling_mode_property)
904 dev->mode_config.scaling_mode_property = scaling_mode;
911 * drm_mode_create_dithering_property - create dithering property
917 int drm_mode_create_dithering_property(struct drm_device *dev)
921 if (dev->mode_config.dithering_mode_property)
928 dev->mode_config.dithering_mode_property = dithering_mode;
935 * drm_mode_create_dirty_property - create dirty property
941 int drm_mode_create_dirty_info_property(struct drm_device *dev)
945 if (dev->mode_config.dirty_info_property)
953 dev->mode_config.dirty_info_property = dirty_info;
960 * drm_mode_config_init - initialize DRM mode_configuration structure
971 sx_init(&dev->mode_config.mutex, "kmslk");
972 INIT_LIST_HEAD(&dev->mode_config.fb_list);
973 INIT_LIST_HEAD(&dev->mode_config.crtc_list);
974 INIT_LIST_HEAD(&dev->mode_config.connector_list);
975 INIT_LIST_HEAD(&dev->mode_config.encoder_list);
976 INIT_LIST_HEAD(&dev->mode_config.property_list);
977 INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
978 INIT_LIST_HEAD(&dev->mode_config.plane_list);
979 drm_gem_names_init(&dev->mode_config.crtc_names);
981 sx_xlock(&dev->mode_config.mutex);
983 sx_xunlock(&dev->mode_config.mutex);
986 dev->mode_config.num_fb = 0;
987 dev->mode_config.num_connector = 0;
988 dev->mode_config.num_crtc = 0;
989 dev->mode_config.num_encoder = 0;
993 int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
997 total_objects += dev->mode_config.num_crtc;
998 total_objects += dev->mode_config.num_connector;
999 total_objects += dev->mode_config.num_encoder;
1001 group->id_list = malloc(total_objects * sizeof(uint32_t),
1003 group->num_crtcs = 0;
1004 group->num_connectors = 0;
1005 group->num_encoders = 0;
1011 free(group->id_list, DRM_MEM_KMS);
1012 group->id_list = NULL;
1015 int drm_mode_group_init_legacy_group(struct drm_device *dev,
1021 int ret;
1026 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
1027 group->id_list[group->num_crtcs++] = crtc->base.id;
1029 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
1030 group->id_list[group->num_crtcs + group->num_encoders++] =
1031 encoder->base.id;
1033 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
1034 group->id_list[group->num_crtcs + group->num_encoders +
1035 group->num_connectors++] = connector->base.id;
1042 * drm_mode_config_cleanup - free up DRM mode_config info
1059 struct drm_property *property, *pt;
1063 list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list,
1065 encoder->funcs->destroy(encoder);
1069 &dev->mode_config.connector_list, head) {
1070 connector->funcs->destroy(connector);
1073 list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
1075 drm_property_destroy(dev, property);
1078 list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
1083 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
1087 list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
1089 plane->funcs->destroy(plane);
1092 list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
1093 crtc->funcs->destroy(crtc);
1096 drm_gem_names_fini(&dev->mode_config.crtc_names);
1101 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1114 if (in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX ||
1115 in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX ||
1116 in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX ||
1117 in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX ||
1118 in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX)
1121 out->clock = in->clock;
1122 out->hdisplay = in->hdisplay;
1123 out->hsync_start = in->hsync_start;
1124 out->hsync_end = in->hsync_end;
1125 out->htotal = in->htotal;
1126 out->hskew = in->hskew;
1127 out->vdisplay = in->vdisplay;
1128 out->vsync_start = in->vsync_start;
1129 out->vsync_end = in->vsync_end;
1130 out->vtotal = in->vtotal;
1131 out->vscan = in->vscan;
1132 out->vrefresh = in->vrefresh;
1133 out->flags = in->flags;
1134 out->type = in->type;
1135 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1136 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1140 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1153 static int drm_crtc_convert_umode(struct drm_display_mode *out,
1156 if (in->clock > INT_MAX || in->vrefresh > INT_MAX)
1157 return -ERANGE;
1159 out->clock = in->clock;
1160 out->hdisplay = in->hdisplay;
1161 out->hsync_start = in->hsync_start;
1162 out->hsync_end = in->hsync_end;
1163 out->htotal = in->htotal;
1164 out->hskew = in->hskew;
1165 out->vdisplay = in->vdisplay;
1166 out->vsync_start = in->vsync_start;
1167 out->vsync_end = in->vsync_end;
1168 out->vtotal = in->vtotal;
1169 out->vscan = in->vscan;
1170 out->vrefresh = in->vrefresh;
1171 out->flags = in->flags;
1172 out->type = in->type;
1173 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1174 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1180 * drm_mode_getresources - get graphics configuration
1197 int drm_mode_getresources(struct drm_device *dev, void *data,
1206 int ret = 0;
1207 int connector_count = 0;
1208 int crtc_count = 0;
1209 int fb_count = 0;
1210 int encoder_count = 0;
1211 int copied = 0, i;
1219 return -EINVAL;
1221 sx_xlock(&dev->mode_config.mutex);
1224 * For the non-control nodes we need to limit the list of resources
1227 list_for_each(lh, &file_priv->fbs)
1230 mode_group = &file_priv->master->minor->mode_group;
1231 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1233 list_for_each(lh, &dev->mode_config.crtc_list)
1236 list_for_each(lh, &dev->mode_config.connector_list)
1239 list_for_each(lh, &dev->mode_config.encoder_list)
1243 crtc_count = mode_group->num_crtcs;
1244 connector_count = mode_group->num_connectors;
1245 encoder_count = mode_group->num_encoders;
1248 card_res->max_height = dev->mode_config.max_height;
1249 card_res->min_height = dev->mode_config.min_height;
1250 card_res->max_width = dev->mode_config.max_width;
1251 card_res->min_width = dev->mode_config.min_width;
1255 if (card_res->count_fbs >= fb_count) {
1257 fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
1258 list_for_each_entry(fb, &file_priv->fbs, filp_head) {
1259 if (put_user(fb->base.id, fb_id + copied)) {
1260 ret = -EFAULT;
1266 card_res->count_fbs = fb_count;
1269 if (card_res->count_crtcs >= crtc_count) {
1271 crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
1272 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1273 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
1275 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1276 if (put_user(crtc->base.id, crtc_id + copied)) {
1277 ret = -EFAULT;
1283 for (i = 0; i < mode_group->num_crtcs; i++) {
1284 if (put_user(mode_group->id_list[i],
1286 ret = -EFAULT;
1293 card_res->count_crtcs = crtc_count;
1296 if (card_res->count_encoders >= encoder_count) {
1298 encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
1299 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1301 &dev->mode_config.encoder_list,
1303 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
1305 if (put_user(encoder->base.id, encoder_id +
1307 ret = -EFAULT;
1313 for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
1314 if (put_user(mode_group->id_list[i],
1316 ret = -EFAULT;
1324 card_res->count_encoders = encoder_count;
1327 if (card_res->count_connectors >= connector_count) {
1329 connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
1330 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1332 &dev->mode_config.connector_list,
1335 connector->base.id,
1337 if (put_user(connector->base.id,
1339 ret = -EFAULT;
1345 int start = mode_group->num_crtcs +
1346 mode_group->num_encoders;
1347 for (i = start; i < start + mode_group->num_connectors; i++) {
1348 if (put_user(mode_group->id_list[i],
1350 ret = -EFAULT;
1357 card_res->count_connectors = connector_count;
1359 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
1360 card_res->count_connectors, card_res->count_encoders);
1363 sx_xunlock(&dev->mode_config.mutex);
1368 * drm_mode_getcrtc - get CRTC configuration
1384 int drm_mode_getcrtc(struct drm_device *dev,
1390 int ret = 0;
1393 return -EINVAL;
1395 sx_xlock(&dev->mode_config.mutex);
1397 obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
1400 ret = -EINVAL;
1405 crtc_resp->x = crtc->x;
1406 crtc_resp->y = crtc->y;
1407 crtc_resp->gamma_size = crtc->gamma_size;
1408 if (crtc->fb)
1409 crtc_resp->fb_id = crtc->fb->base.id;
1411 crtc_resp->fb_id = 0;
1413 if (crtc->enabled) {
1415 drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
1416 crtc_resp->mode_valid = 1;
1419 crtc_resp->mode_valid = 0;
1423 sx_xunlock(&dev->mode_config.mutex);
1428 * drm_mode_getconnector - get connector configuration
1444 int drm_mode_getconnector(struct drm_device *dev, void *data,
1451 int mode_count = 0;
1452 int props_count = 0;
1453 int encoders_count = 0;
1454 int ret = 0;
1455 int copied = 0;
1456 int i;
1464 return -EINVAL;
1468 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
1470 sx_xlock(&dev->mode_config.mutex);
1472 obj = drm_mode_object_find(dev, out_resp->connector_id,
1475 ret = -EINVAL;
1480 props_count = connector->properties.count;
1483 if (connector->encoder_ids[i] != 0) {
1488 if (out_resp->count_modes == 0) {
1489 connector->funcs->fill_modes(connector,
1490 dev->mode_config.max_width,
1491 dev->mode_config.max_height);
1494 /* delayed so we get modes regardless of pre-fill_modes state */
1495 list_for_each_entry(mode, &connector->modes, head)
1498 out_resp->connector_id = connector->base.id;
1499 out_resp->connector_type = connector->connector_type;
1500 out_resp->connector_type_id = connector->connector_type_id;
1501 out_resp->mm_width = connector->display_info.width_mm;
1502 out_resp->mm_height = connector->display_info.height_mm;
1503 out_resp->subpixel = connector->display_info.subpixel_order;
1504 out_resp->connection = connector->status;
1505 if (connector->encoder)
1506 out_resp->encoder_id = connector->encoder->base.id;
1508 out_resp->encoder_id = 0;
1514 if ((out_resp->count_modes >= mode_count) && mode_count) {
1516 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
1517 list_for_each_entry(mode, &connector->modes, head) {
1521 ret = -EFAULT;
1527 out_resp->count_modes = mode_count;
1529 if ((out_resp->count_props >= props_count) && props_count) {
1531 prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
1532 prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
1533 for (i = 0; i < connector->properties.count; i++) {
1534 if (put_user(connector->properties.ids[i],
1536 ret = -EFAULT;
1540 if (put_user(connector->properties.values[i],
1542 ret = -EFAULT;
1548 out_resp->count_props = props_count;
1550 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1552 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
1554 if (connector->encoder_ids[i] != 0) {
1555 if (put_user(connector->encoder_ids[i],
1557 ret = -EFAULT;
1564 out_resp->count_encoders = encoders_count;
1567 sx_xunlock(&dev->mode_config.mutex);
1571 int drm_mode_getencoder(struct drm_device *dev, void *data,
1577 int ret = 0;
1580 return -EINVAL;
1582 sx_xlock(&dev->mode_config.mutex);
1583 obj = drm_mode_object_find(dev, enc_resp->encoder_id,
1586 ret = -EINVAL;
1591 if (encoder->crtc)
1592 enc_resp->crtc_id = encoder->crtc->base.id;
1594 enc_resp->crtc_id = 0;
1595 enc_resp->encoder_type = encoder->encoder_type;
1596 enc_resp->encoder_id = encoder->base.id;
1597 enc_resp->possible_crtcs = encoder->possible_crtcs;
1598 enc_resp->possible_clones = encoder->possible_clones;
1601 sx_xunlock(&dev->mode_config.mutex);
1606 * drm_mode_getplane_res - get plane info
1616 int drm_mode_getplane_res(struct drm_device *dev, void *data,
1623 int copied = 0, ret = 0;
1626 return -EINVAL;
1628 sx_xlock(&dev->mode_config.mutex);
1629 config = &dev->mode_config;
1635 if (config->num_plane &&
1636 (plane_resp->count_planes >= config->num_plane)) {
1637 plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr;
1639 list_for_each_entry(plane, &config->plane_list, head) {
1640 if (put_user(plane->base.id, plane_ptr + copied)) {
1641 ret = -EFAULT;
1647 plane_resp->count_planes = config->num_plane;
1650 sx_xunlock(&dev->mode_config.mutex);
1655 * drm_mode_getplane - get plane info
1666 int drm_mode_getplane(struct drm_device *dev, void *data,
1673 int ret = 0;
1676 return -EINVAL;
1678 sx_xlock(&dev->mode_config.mutex);
1679 obj = drm_mode_object_find(dev, plane_resp->plane_id,
1682 ret = -ENOENT;
1687 if (plane->crtc)
1688 plane_resp->crtc_id = plane->crtc->base.id;
1690 plane_resp->crtc_id = 0;
1692 if (plane->fb)
1693 plane_resp->fb_id = plane->fb->base.id;
1695 plane_resp->fb_id = 0;
1697 plane_resp->plane_id = plane->base.id;
1698 plane_resp->possible_crtcs = plane->possible_crtcs;
1699 plane_resp->gamma_size = plane->gamma_size;
1705 if (plane->format_count &&
1706 (plane_resp->count_format_types >= plane->format_count)) {
1707 format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr;
1709 plane->format_types,
1710 sizeof(uint32_t) * plane->format_count)) {
1711 ret = -EFAULT;
1715 plane_resp->count_format_types = plane->format_count;
1718 sx_xunlock(&dev->mode_config.mutex);
1723 * drm_mode_setplane - set up or tear down an plane
1734 int drm_mode_setplane(struct drm_device *dev, void *data,
1742 int ret = 0;
1743 unsigned int fb_width, fb_height;
1744 int i;
1747 return -EINVAL;
1749 sx_xlock(&dev->mode_config.mutex);
1755 obj = drm_mode_object_find(dev, plane_req->plane_id,
1759 plane_req->plane_id);
1760 ret = -ENOENT;
1766 if (!plane_req->fb_id) {
1767 plane->funcs->disable_plane(plane);
1768 plane->crtc = NULL;
1769 plane->fb = NULL;
1773 obj = drm_mode_object_find(dev, plane_req->crtc_id,
1777 plane_req->crtc_id);
1778 ret = -ENOENT;
1783 obj = drm_mode_object_find(dev, plane_req->fb_id,
1787 plane_req->fb_id);
1788 ret = -ENOENT;
1794 for (i = 0; i < plane->format_count; i++)
1795 if (fb->pixel_format == plane->format_types[i])
1797 if (i == plane->format_count) {
1798 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb->pixel_format);
1799 ret = -EINVAL;
1803 fb_width = fb->width << 16;
1804 fb_height = fb->height << 16;
1807 if (plane_req->src_w > fb_width ||
1808 plane_req->src_x > fb_width - plane_req->src_w ||
1809 plane_req->src_h > fb_height ||
1810 plane_req->src_y > fb_height - plane_req->src_h) {
1813 plane_req->src_w >> 16,
1814 ((plane_req->src_w & 0xffff) * 15625) >> 10,
1815 plane_req->src_h >> 16,
1816 ((plane_req->src_h & 0xffff) * 15625) >> 10,
1817 plane_req->src_x >> 16,
1818 ((plane_req->src_x & 0xffff) * 15625) >> 10,
1819 plane_req->src_y >> 16,
1820 ((plane_req->src_y & 0xffff) * 15625) >> 10);
1821 ret = -ENOSPC;
1826 if (plane_req->crtc_w > INT_MAX ||
1827 plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w ||
1828 plane_req->crtc_h > INT_MAX ||
1829 plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) {
1831 plane_req->crtc_w, plane_req->crtc_h,
1832 plane_req->crtc_x, plane_req->crtc_y);
1833 ret = -ERANGE;
1837 ret = plane->funcs->update_plane(plane, crtc, fb,
1838 plane_req->crtc_x, plane_req->crtc_y,
1839 plane_req->crtc_w, plane_req->crtc_h,
1840 plane_req->src_x, plane_req->src_y,
1841 plane_req->src_w, plane_req->src_h);
1843 plane->crtc = crtc;
1844 plane->fb = fb;
1848 sx_xunlock(&dev->mode_config.mutex);
1854 * drm_mode_setcrtc - set CRTC configuration
1870 int drm_mode_setcrtc(struct drm_device *dev, void *data,
1873 struct drm_mode_config *config = &dev->mode_config;
1882 int ret;
1883 int i;
1886 return -EINVAL;
1889 if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX)
1890 return -ERANGE;
1892 sx_xlock(&dev->mode_config.mutex);
1893 obj = drm_mode_object_find(dev, crtc_req->crtc_id,
1896 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
1897 ret = -EINVAL;
1901 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1903 if (crtc_req->mode_valid) {
1904 int hdisplay, vdisplay;
1906 /* If we pass -1, set the mode with the currently bound fb */
1907 if (crtc_req->fb_id == -1) {
1908 if (!crtc->fb) {
1910 ret = -EINVAL;
1913 fb = crtc->fb;
1915 obj = drm_mode_object_find(dev, crtc_req->fb_id,
1919 crtc_req->fb_id);
1920 ret = -EINVAL;
1928 ret = -ENOMEM;
1932 ret = drm_crtc_convert_umode(mode, &crtc_req->mode);
1940 hdisplay = mode->hdisplay;
1941 vdisplay = mode->vdisplay;
1943 if (crtc->invert_dimensions) {
1944 int tmp;
1950 if (hdisplay > fb->width ||
1951 vdisplay > fb->height ||
1952 crtc_req->x > fb->width - hdisplay ||
1953 crtc_req->y > fb->height - vdisplay) {
1955 fb->width, fb->height,
1956 hdisplay, vdisplay, crtc_req->x, crtc_req->y,
1957 crtc->invert_dimensions ? " (inverted)" : "");
1958 ret = -ENOSPC;
1963 if (crtc_req->count_connectors == 0 && mode) {
1965 ret = -EINVAL;
1969 if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
1971 crtc_req->count_connectors);
1972 ret = -EINVAL;
1976 if (crtc_req->count_connectors > 0) {
1980 if (crtc_req->count_connectors > config->num_connector) {
1981 ret = -EINVAL;
1985 connector_set = malloc(crtc_req->count_connectors *
1989 for (i = 0; i < crtc_req->count_connectors; i++) {
1990 set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
1992 ret = -EFAULT;
2001 ret = -EINVAL;
2006 connector->base.id,
2014 set.x = crtc_req->x;
2015 set.y = crtc_req->y;
2018 set.num_connectors = crtc_req->count_connectors;
2020 ret = crtc->funcs->set_config(&set);
2025 sx_xunlock(&dev->mode_config.mutex);
2029 int drm_mode_cursor_ioctl(struct drm_device *dev,
2035 int ret = 0;
2038 return -EINVAL;
2040 if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
2041 return -EINVAL;
2043 sx_xlock(&dev->mode_config.mutex);
2044 obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC);
2046 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
2047 ret = -EINVAL;
2052 if (req->flags & DRM_MODE_CURSOR_BO) {
2053 if (!crtc->funcs->cursor_set) {
2054 ret = -ENXIO;
2058 ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
2059 req->width, req->height);
2062 if (req->flags & DRM_MODE_CURSOR_MOVE) {
2063 if (crtc->funcs->cursor_move) {
2064 ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
2066 ret = -EFAULT;
2071 sx_xunlock(&dev->mode_config.mutex);
2112 * drm_mode_addfb - add an FB to the graphics configuration
2128 int drm_mode_addfb(struct drm_device *dev,
2133 struct drm_mode_config *config = &dev->mode_config;
2135 int ret = 0;
2138 r.fb_id = or->fb_id;
2139 r.width = or->width;
2140 r.height = or->height;
2141 r.pitches[0] = or->pitch;
2142 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
2143 r.handles[0] = or->handle;
2146 return -EINVAL;
2148 if ((config->min_width > r.width) || (r.width > config->max_width))
2149 return -EINVAL;
2151 if ((config->min_height > r.height) || (r.height > config->max_height))
2152 return -EINVAL;
2154 sx_xlock(&dev->mode_config.mutex);
2159 ret = dev->mode_config.funcs->fb_create(dev, file_priv, &r, &fb);
2165 or->fb_id = fb->base.id;
2166 list_add(&fb->filp_head, &file_priv->fbs);
2167 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
2170 sx_xunlock(&dev->mode_config.mutex);
2174 static int format_check(const struct drm_mode_fb_cmd2 *r)
2176 uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
2241 return -EINVAL;
2245 static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
2247 int ret, hsub, vsub, num_planes, i;
2251 DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r->pixel_format);
2255 hsub = drm_format_horz_chroma_subsampling(r->pixel_format);
2256 vsub = drm_format_vert_chroma_subsampling(r->pixel_format);
2257 num_planes = drm_format_num_planes(r->pixel_format);
2259 if (r->width == 0 || r->width % hsub) {
2260 DRM_DEBUG_KMS("bad framebuffer width %u\n", r->height);
2261 return -EINVAL;
2264 if (r->height == 0 || r->height % vsub) {
2265 DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
2266 return -EINVAL;
2270 unsigned int width = r->width / (i != 0 ? hsub : 1);
2271 unsigned int height = r->height / (i != 0 ? vsub : 1);
2272 unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
2274 if (!r->handles[i]) {
2276 return -EINVAL;
2280 return -ERANGE;
2282 if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
2283 return -ERANGE;
2285 if (r->pitches[i] < width * cpp) {
2286 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
2287 return -EINVAL;
2295 * drm_mode_addfb2 - add an FB to the graphics configuration
2311 int drm_mode_addfb2(struct drm_device *dev,
2315 struct drm_mode_config *config = &dev->mode_config;
2317 int ret;
2320 return -EINVAL;
2322 if (r->flags & ~DRM_MODE_FB_INTERLACED) {
2323 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
2324 return -EINVAL;
2327 if ((config->min_width > r->width) || (r->width > config->max_width)) {
2329 r->width, config->min_width, config->max_width);
2330 return -EINVAL;
2332 if ((config->min_height > r->height) || (r->height > config->max_height)) {
2334 r->height, config->min_height, config->max_height);
2335 return -EINVAL;
2342 sx_xlock(&dev->mode_config.mutex);
2344 ret = dev->mode_config.funcs->fb_create(dev, file_priv, r, &fb);
2350 r->fb_id = fb->base.id;
2351 list_add(&fb->filp_head, &file_priv->fbs);
2352 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
2355 sx_xunlock(&dev->mode_config.mutex);
2360 * drm_mode_rmfb - remove an FB from the configuration
2376 int drm_mode_rmfb(struct drm_device *dev,
2383 int ret = 0;
2384 int found = 0;
2387 return -EINVAL;
2389 sx_xlock(&dev->mode_config.mutex);
2393 ret = -EINVAL;
2398 list_for_each_entry(fbl, &file_priv->fbs, filp_head)
2403 ret = -EINVAL;
2410 sx_xunlock(&dev->mode_config.mutex);
2415 * drm_mode_getfb - get FB info
2431 int drm_mode_getfb(struct drm_device *dev,
2437 int ret = 0;
2440 return -EINVAL;
2442 sx_xlock(&dev->mode_config.mutex);
2443 obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
2445 ret = -EINVAL;
2450 r->height = fb->height;
2451 r->width = fb->width;
2452 r->depth = fb->depth;
2453 r->bpp = fb->bits_per_pixel;
2454 r->pitch = fb->pitches[0];
2455 r->handle = 0;
2456 fb->funcs->create_handle(fb, file_priv, &r->handle);
2459 sx_xunlock(&dev->mode_config.mutex);
2463 int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2472 int num_clips;
2473 int ret;
2476 return -EINVAL;
2478 sx_xlock(&dev->mode_config.mutex);
2479 obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
2481 ret = -EINVAL;
2486 num_clips = r->num_clips;
2487 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
2490 ret = -EINVAL;
2494 flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
2498 ret = -EINVAL;
2504 ret = -EINVAL;
2512 ret = -EFAULT;
2517 if (fb->funcs->dirty) {
2518 ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
2521 ret = -ENOSYS;
2528 sx_xunlock(&dev->mode_config.mutex);
2534 * drm_fb_release - remove and free the FBs on this file
2549 struct drm_device *dev = priv->minor->dev;
2552 sx_xlock(&dev->mode_config.mutex);
2553 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
2556 sx_xunlock(&dev->mode_config.mutex);
2560 * drm_mode_attachmode - add a mode to the user mode list
2571 list_add_tail(&mode->head, &connector->user_modes);
2574 int drm_mode_attachmode_crtc(struct drm_device *dev, struct drm_crtc *crtc,
2578 int ret = 0;
2582 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2583 if (!connector->encoder)
2585 if (connector->encoder->crtc == crtc) {
2588 ret = -ENOMEM;
2591 list_add_tail(&dup_mode->head, &list);
2595 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2596 if (!connector->encoder)
2598 if (connector->encoder->crtc == crtc)
2599 list_move_tail(list.next, &connector->user_modes);
2612 static int drm_mode_detachmode(struct drm_device *dev,
2616 int found = 0;
2617 int ret = 0;
2620 list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) {
2622 list_del(&match_mode->head);
2630 ret = -EINVAL;
2635 int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode)
2639 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2647 * drm_fb_attachmode - Attach a user mode to an connector
2659 int drm_mode_attachmode_ioctl(struct drm_device *dev,
2666 struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2667 int ret;
2670 return -EINVAL;
2672 sx_xlock(&dev->mode_config.mutex);
2674 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2676 ret = -EINVAL;
2683 ret = -ENOMEM;
2696 sx_xunlock(&dev->mode_config.mutex);
2702 * drm_fb_detachmode - Detach a user specified mode from an connector
2713 int drm_mode_detachmode_ioctl(struct drm_device *dev,
2720 struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2721 int ret;
2724 return -EINVAL;
2726 sx_xlock(&dev->mode_config.mutex);
2728 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2730 ret = -EINVAL;
2743 sx_xunlock(&dev->mode_config.mutex);
2747 struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2748 const char *name, int num_values)
2750 struct drm_property *property = NULL;
2751 int ret;
2753 property = malloc(sizeof(struct drm_property), DRM_MEM_KMS,
2757 property->values = malloc(sizeof(uint64_t)*num_values, DRM_MEM_KMS,
2760 ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
2764 property->flags = flags;
2765 property->num_values = num_values;
2766 INIT_LIST_HEAD(&property->enum_blob_list);
2769 strncpy(property->name, name, DRM_PROP_NAME_LEN);
2770 property->name[DRM_PROP_NAME_LEN-1] = '\0';
2773 list_add_tail(&property->head, &dev->mode_config.property_list);
2774 return property;
2776 free(property->values, DRM_MEM_KMS);
2777 free(property, DRM_MEM_KMS);
2782 struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2785 int num_values)
2787 struct drm_property *property;
2788 int i, ret;
2792 property = drm_property_create(dev, flags, name, num_values);
2793 if (!property)
2797 ret = drm_property_add_enum(property, i,
2801 drm_property_destroy(dev, property);
2806 return property;
2811 int flags, const char *name,
2813 int num_values)
2815 struct drm_property *property;
2816 int i, ret;
2820 property = drm_property_create(dev, flags, name, num_values);
2821 if (!property)
2825 ret = drm_property_add_enum(property, i,
2829 drm_property_destroy(dev, property);
2834 return property;
2838 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2842 struct drm_property *property;
2846 property = drm_property_create(dev, flags, name, 2);
2847 if (!property)
2850 property->values[0] = min;
2851 property->values[1] = max;
2853 return property;
2857 int drm_property_add_enum(struct drm_property *property, int index,
2862 if (!(property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)))
2863 return -EINVAL;
2869 if ((property->flags & DRM_MODE_PROP_BITMASK) && (value > 63))
2870 return -EINVAL;
2872 if (!list_empty(&property->enum_blob_list)) {
2873 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2874 if (prop_enum->value == value) {
2875 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2876 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2884 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2885 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2886 prop_enum->value = value;
2888 property->values[index] = value;
2889 list_add_tail(&prop_enum->head, &property->enum_blob_list);
2894 void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
2898 list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) {
2899 list_del(&prop_enum->head);
2903 if (property->num_values)
2904 free(property->values, DRM_MEM_KMS);
2905 drm_mode_object_put(dev, &property->base);
2906 list_del(&property->head);
2907 free(property, DRM_MEM_KMS);
2912 struct drm_property *property,
2915 int count = obj->properties->count;
2918 DRM_WARNING("Failed to attach object property (type: 0x%x). Please "
2921 obj->type);
2925 obj->properties->ids[count] = property->base.id;
2926 obj->properties->values[count] = init_val;
2927 obj->properties->count++;
2931 int drm_object_property_set_value(struct drm_mode_object *obj,
2932 struct drm_property *property, uint64_t val)
2934 int i;
2936 for (i = 0; i < obj->properties->count; i++) {
2937 if (obj->properties->ids[i] == property->base.id) {
2938 obj->properties->values[i] = val;
2943 return -EINVAL;
2947 int drm_object_property_get_value(struct drm_mode_object *obj,
2948 struct drm_property *property, uint64_t *val)
2950 int i;
2952 for (i = 0; i < obj->properties->count; i++) {
2953 if (obj->properties->ids[i] == property->base.id) {
2954 *val = obj->properties->values[i];
2959 return -EINVAL;
2963 int drm_mode_getproperty_ioctl(struct drm_device *dev,
2968 struct drm_property *property;
2969 int enum_count = 0;
2970 int blob_count = 0;
2971 int value_count = 0;
2972 int ret = 0, i;
2973 int copied;
2982 return -EINVAL;
2984 sx_xlock(&dev->mode_config.mutex);
2985 obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2987 ret = -EINVAL;
2990 property = obj_to_property(obj);
2992 if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
2993 list_for_each_entry(prop_enum, &property->enum_blob_list, head)
2995 } else if (property->flags & DRM_MODE_PROP_BLOB) {
2996 list_for_each_entry(prop_blob, &property->enum_blob_list, head)
3000 value_count = property->num_values;
3002 strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
3003 out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
3004 out_resp->flags = property->flags;
3006 if ((out_resp->count_values >= value_count) && value_count) {
3007 values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
3009 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
3010 ret = -EFAULT;
3015 out_resp->count_values = value_count;
3017 if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
3018 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
3020 enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
3021 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
3023 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
3024 ret = -EFAULT;
3029 &prop_enum->name, DRM_PROP_NAME_LEN)) {
3030 ret = -EFAULT;
3036 out_resp->count_enum_blobs = enum_count;
3039 if (property->flags & DRM_MODE_PROP_BLOB) {
3040 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
3042 blob_id_ptr = (uint32_t __user *)(unsigned long)out_resp->enum_blob_ptr;
3043 blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
3045 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
3046 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
3047 ret = -EFAULT;
3051 if (put_user(prop_blob->length, blob_length_ptr + copied)) {
3052 ret = -EFAULT;
3059 out_resp->count_enum_blobs = blob_count;
3062 sx_xunlock(&dev->mode_config.mutex);
3066 static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
3070 int ret;
3077 ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
3083 blob->length = length;
3085 memcpy(blob->data, data, length);
3087 list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
3094 drm_mode_object_put(dev, &blob->base);
3095 list_del(&blob->head);
3099 int drm_mode_getblob_ioctl(struct drm_device *dev,
3105 int ret = 0;
3109 return -EINVAL;
3111 sx_xlock(&dev->mode_config.mutex);
3112 obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
3114 ret = -EINVAL;
3119 if (out_resp->length == blob->length) {
3120 blob_ptr = (void __user *)(unsigned long)out_resp->data;
3121 if (copy_to_user(blob_ptr, blob->data, blob->length)){
3122 ret = -EFAULT;
3126 out_resp->length = blob->length;
3129 sx_xunlock(&dev->mode_config.mutex);
3133 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
3136 struct drm_device *dev = connector->dev;
3137 int ret, size;
3139 if (connector->edid_blob_ptr)
3140 drm_property_destroy_blob(dev, connector->edid_blob_ptr);
3144 connector->edid_blob_ptr = NULL;
3145 ret = drm_object_property_set_value(&connector->base, dev->mode_config.edid_property, 0);
3149 size = EDID_LENGTH * (1 + edid->extensions);
3150 connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
3152 if (!connector->edid_blob_ptr)
3153 return -EINVAL;
3155 ret = drm_object_property_set_value(&connector->base,
3156 dev->mode_config.edid_property,
3157 connector->edid_blob_ptr->base.id);
3163 static bool drm_property_change_is_valid(struct drm_property *property,
3166 if (property->flags & DRM_MODE_PROP_IMMUTABLE)
3168 if (property->flags & DRM_MODE_PROP_RANGE) {
3169 if (value < property->values[0] || value > property->values[1])
3172 } else if (property->flags & DRM_MODE_PROP_BITMASK) {
3173 int i;
3175 for (i = 0; i < property->num_values; i++)
3176 valid_mask |= (1ULL << property->values[i]);
3178 } else if (property->flags & DRM_MODE_PROP_BLOB) {
3182 int i;
3183 for (i = 0; i < property->num_values; i++)
3184 if (property->values[i] == value)
3190 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
3195 .value = conn_set_prop->value,
3196 .prop_id = conn_set_prop->prop_id,
3197 .obj_id = conn_set_prop->connector_id,
3205 static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
3206 struct drm_property *property,
3209 int ret = -EINVAL;
3213 if (property == connector->dev->mode_config.dpms_property) {
3214 if (connector->funcs->dpms)
3215 (*connector->funcs->dpms)(connector, (int)value);
3217 } else if (connector->funcs->set_property)
3218 ret = connector->funcs->set_property(connector, property, value);
3220 /* store the property value if successful */
3222 drm_object_property_set_value(&connector->base, property, value);
3226 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
3227 struct drm_property *property,
3230 int ret = -EINVAL;
3233 if (crtc->funcs->set_property)
3234 ret = crtc->funcs->set_property(crtc, property, value);
3236 drm_object_property_set_value(obj, property, value);
3241 static int drm_mode_plane_set_obj_prop(struct drm_mode_object *obj,
3242 struct drm_property *property,
3245 int ret = -EINVAL;
3248 if (plane->funcs->set_property)
3249 ret = plane->funcs->set_property(plane, property, value);
3251 drm_object_property_set_value(obj, property, value);
3256 int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
3261 int ret = 0;
3262 int i;
3263 int copied = 0;
3264 int props_count = 0;
3269 return -EINVAL;
3271 sx_xlock(&dev->mode_config.mutex);
3273 obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type);
3275 ret = -EINVAL;
3278 if (!obj->properties) {
3279 ret = -EINVAL;
3283 props_count = obj->properties->count;
3287 if ((arg->count_props >= props_count) && props_count) {
3289 props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr);
3291 (arg->prop_values_ptr);
3293 if (put_user(obj->properties->ids[i],
3295 ret = -EFAULT;
3298 if (put_user(obj->properties->values[i],
3300 ret = -EFAULT;
3306 arg->count_props = props_count;
3308 sx_xunlock(&dev->mode_config.mutex);
3312 int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
3318 struct drm_property *property;
3319 int ret = -EINVAL;
3320 int i;
3323 return -EINVAL;
3325 sx_xlock(&dev->mode_config.mutex);
3327 arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type);
3330 if (!arg_obj->properties)
3333 for (i = 0; i < arg_obj->properties->count; i++)
3334 if (arg_obj->properties->ids[i] == arg->prop_id)
3337 if (i == arg_obj->properties->count)
3340 prop_obj = drm_mode_object_find(dev, arg->prop_id,
3344 property = obj_to_property(prop_obj);
3346 if (!drm_property_change_is_valid(property, arg->value))
3349 switch (arg_obj->type) {
3351 ret = drm_mode_connector_set_obj_prop(arg_obj, property,
3352 arg->value);
3355 ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value);
3358 ret = drm_mode_plane_set_obj_prop(arg_obj, property, arg->value);
3363 sx_xunlock(&dev->mode_config.mutex);
3367 int drm_mode_connector_attach_encoder(struct drm_connector *connector,
3370 int i;
3373 if (connector->encoder_ids[i] == 0) {
3374 connector->encoder_ids[i] = encoder->base.id;
3378 return -ENOMEM;
3385 int i;
3387 if (connector->encoder_ids[i] == encoder->base.id) {
3388 connector->encoder_ids[i] = 0;
3389 if (connector->encoder == encoder)
3390 connector->encoder = NULL;
3397 int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
3398 int gamma_size)
3400 crtc->gamma_size = gamma_size;
3402 crtc->gamma_store = malloc(gamma_size * sizeof(uint16_t) * 3,
3409 int drm_mode_gamma_set_ioctl(struct drm_device *dev,
3416 int size;
3417 int ret = 0;
3420 return -EINVAL;
3422 sx_xlock(&dev->mode_config.mutex);
3423 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
3425 ret = -EINVAL;
3430 if (crtc->funcs->gamma_set == NULL) {
3431 ret = -ENOSYS;
3436 if (crtc_lut->gamma_size != crtc->gamma_size) {
3437 ret = -EINVAL;
3441 size = crtc_lut->gamma_size * (sizeof(uint16_t));
3442 r_base = crtc->gamma_store;
3443 if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
3444 ret = -EFAULT;
3449 if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
3450 ret = -EFAULT;
3455 if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
3456 ret = -EFAULT;
3460 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
3463 sx_xunlock(&dev->mode_config.mutex);
3468 int drm_mode_gamma_get_ioctl(struct drm_device *dev,
3475 int size;
3476 int ret = 0;
3479 return -EINVAL;
3481 sx_xlock(&dev->mode_config.mutex);
3482 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
3484 ret = -EINVAL;
3490 if (crtc_lut->gamma_size != crtc->gamma_size) {
3491 ret = -EINVAL;
3495 size = crtc_lut->gamma_size * (sizeof(uint16_t));
3496 r_base = crtc->gamma_store;
3497 if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
3498 ret = -EFAULT;
3503 if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
3504 ret = -EFAULT;
3509 if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
3510 ret = -EFAULT;
3514 sx_xunlock(&dev->mode_config.mutex);
3525 int drm_mode_page_flip_ioctl(struct drm_device *dev,
3536 int hdisplay, vdisplay;
3537 int ret = -EINVAL;
3539 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
3540 page_flip->reserved != 0)
3541 return -EINVAL;
3543 sx_xlock(&dev->mode_config.mutex);
3544 obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC);
3549 if (crtc->fb == NULL) {
3554 ret = -EBUSY;
3558 if (crtc->funcs->page_flip == NULL)
3561 obj = drm_mode_object_find(dev, page_flip->fb_id, DRM_MODE_OBJECT_FB);
3566 hdisplay = crtc->mode.hdisplay;
3567 vdisplay = crtc->mode.vdisplay;
3569 if (crtc->invert_dimensions) {
3570 int tmp;
3576 if (hdisplay > fb->width ||
3577 vdisplay > fb->height ||
3578 crtc->x > fb->width - hdisplay ||
3579 crtc->y > fb->height - vdisplay) {
3581 fb->width, fb->height, hdisplay, vdisplay, crtc->x, crtc->y,
3582 crtc->invert_dimensions ? " (inverted)" : "");
3583 ret = -ENOSPC;
3587 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
3588 ret = -ENOMEM;
3589 mtx_lock(&dev->event_lock);
3590 if (file_priv->event_space < sizeof e->event) {
3591 mtx_unlock(&dev->event_lock);
3594 file_priv->event_space -= sizeof e->event;
3595 mtx_unlock(&dev->event_lock);
3598 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
3599 e->event.base.length = sizeof e->event;
3600 e->event.user_data = page_flip->user_data;
3601 e->base.event = &e->event.base;
3602 e->base.file_priv = file_priv;
3603 e->base.destroy =
3607 ret = crtc->funcs->page_flip(crtc, fb, e);
3609 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
3610 mtx_lock(&dev->event_lock);
3611 file_priv->event_space += sizeof e->event;
3612 mtx_unlock(&dev->event_lock);
3618 sx_xunlock(&dev->mode_config.mutex);
3628 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
3629 if (crtc->funcs->reset)
3630 crtc->funcs->reset(crtc);
3632 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
3633 if (encoder->funcs->reset)
3634 encoder->funcs->reset(encoder);
3636 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3637 connector->status = connector_status_unknown;
3639 if (connector->funcs->reset)
3640 connector->funcs->reset(connector);
3645 int drm_mode_create_dumb_ioctl(struct drm_device *dev,
3650 if (!dev->driver->dumb_create)
3651 return -ENOSYS;
3652 return dev->driver->dumb_create(file_priv, dev, args);
3655 int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
3661 if (!dev->driver->dumb_map_offset)
3662 return -ENOSYS;
3664 return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
3667 int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
3672 if (!dev->driver->dumb_destroy)
3673 return -ENOSYS;
3675 return dev->driver->dumb_destroy(file_priv, dev, args->handle);
3682 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
3683 int *bpp)
3748 * drm_format_num_planes - get the number of planes for format
3754 int drm_format_num_planes(uint32_t format)
3782 * drm_format_plane_cpp - determine the bytes per pixel value
3789 int drm_format_plane_cpp(uint32_t format, int plane)
3791 unsigned int depth;
3792 int bpp;
3829 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3836 int drm_format_horz_chroma_subsampling(uint32_t format)
3864 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3871 int drm_format_vert_chroma_subsampling(uint32_t format)