2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/ctype.h>
33 #include <linux/list.h>
34 #include <linux/export.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_edid.h>
38 #include <uapi_drm/drm_fourcc.h>
39 #include <linux/slab.h>
40 #include <drm/drm_modeset_lock.h>
42 #include "drm_crtc_internal.h"
44 static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev,
45 struct drm_mode_fb_cmd2 *r,
46 struct drm_file *file_priv);
49 * drm_modeset_lock_all - take all modeset locks
52 * This function takes all modeset locks, suitable where a more fine-grained
53 * scheme isn't (yet) implemented. Locks must be dropped with
54 * drm_modeset_unlock_all.
56 void drm_modeset_lock_all(struct drm_device *dev)
58 struct drm_mode_config *config = &dev->mode_config;
59 struct drm_modeset_acquire_ctx *ctx;
62 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
66 mutex_lock(&config->mutex);
68 drm_modeset_acquire_init(ctx, 0);
71 ret = drm_modeset_lock(&config->connection_mutex, ctx);
74 ret = drm_modeset_lock_all_crtcs(dev, ctx);
78 WARN_ON(config->acquire_ctx);
80 /* now we hold the locks, so now that it is safe, stash the
81 * ctx for drm_modeset_unlock_all():
83 config->acquire_ctx = ctx;
85 drm_warn_on_modeset_not_all_locked(dev);
90 if (ret == -EDEADLK) {
91 drm_modeset_backoff(ctx);
95 EXPORT_SYMBOL(drm_modeset_lock_all);
98 * drm_modeset_unlock_all - drop all modeset locks
101 * This function drop all modeset locks taken by drm_modeset_lock_all.
103 void drm_modeset_unlock_all(struct drm_device *dev)
105 struct drm_mode_config *config = &dev->mode_config;
106 struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx;
111 config->acquire_ctx = NULL;
112 drm_modeset_drop_locks(ctx);
113 drm_modeset_acquire_fini(ctx);
117 mutex_unlock(&dev->mode_config.mutex);
119 EXPORT_SYMBOL(drm_modeset_unlock_all);
122 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
125 * Useful as a debug assert.
127 void drm_warn_on_modeset_not_all_locked(struct drm_device *dev)
129 struct drm_crtc *crtc;
131 /* Locking is currently fubar in the panic handler. */
133 if (oops_in_progress)
137 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
138 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
140 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
141 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
143 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked);
145 /* Avoid boilerplate. I'm tired of typing. */
146 #define DRM_ENUM_NAME_FN(fnname, list) \
147 const char *fnname(int val) \
150 for (i = 0; i < ARRAY_SIZE(list); i++) { \
151 if (list[i].type == val) \
152 return list[i].name; \
154 return "(unknown)"; \
160 static const struct drm_prop_enum_list drm_dpms_enum_list[] =
161 { { DRM_MODE_DPMS_ON, "On" },
162 { DRM_MODE_DPMS_STANDBY, "Standby" },
163 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
164 { DRM_MODE_DPMS_OFF, "Off" }
167 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
169 static const struct drm_prop_enum_list drm_plane_type_enum_list[] =
171 { DRM_PLANE_TYPE_OVERLAY, "Overlay" },
172 { DRM_PLANE_TYPE_PRIMARY, "Primary" },
173 { DRM_PLANE_TYPE_CURSOR, "Cursor" },
177 * Optional properties
179 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] =
181 { DRM_MODE_SCALE_NONE, "None" },
182 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
183 { DRM_MODE_SCALE_CENTER, "Center" },
184 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
187 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
188 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
189 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
190 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
194 * Non-global properties, but "required" for certain connectors.
196 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] =
198 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
199 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
200 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
203 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
205 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] =
207 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
208 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
209 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
212 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
213 drm_dvi_i_subconnector_enum_list)
215 static const struct drm_prop_enum_list drm_tv_select_enum_list[] =
217 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
218 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
219 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
220 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
221 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
224 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
226 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] =
228 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
229 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
230 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
231 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
232 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
235 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
236 drm_tv_subconnector_enum_list)
238 static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = {
239 { DRM_MODE_DIRTY_OFF, "Off" },
240 { DRM_MODE_DIRTY_ON, "On" },
241 { DRM_MODE_DIRTY_ANNOTATE, "Annotate" },
244 struct drm_conn_prop_enum_list {
251 * Connector and encoder types.
253 static struct drm_conn_prop_enum_list drm_connector_enum_list[] =
254 { { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
255 { DRM_MODE_CONNECTOR_VGA, "VGA" },
256 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
257 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
258 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
259 { DRM_MODE_CONNECTOR_Composite, "Composite" },
260 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
261 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
262 { DRM_MODE_CONNECTOR_Component, "Component" },
263 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
264 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
265 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
266 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
267 { DRM_MODE_CONNECTOR_TV, "TV" },
268 { DRM_MODE_CONNECTOR_eDP, "eDP" },
269 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
270 { DRM_MODE_CONNECTOR_DSI, "DSI" },
273 static const struct drm_prop_enum_list drm_encoder_enum_list[] =
274 { { DRM_MODE_ENCODER_NONE, "None" },
275 { DRM_MODE_ENCODER_DAC, "DAC" },
276 { DRM_MODE_ENCODER_TMDS, "TMDS" },
277 { DRM_MODE_ENCODER_LVDS, "LVDS" },
278 { DRM_MODE_ENCODER_TVDAC, "TV" },
279 { DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
280 { DRM_MODE_ENCODER_DSI, "DSI" },
281 { DRM_MODE_ENCODER_DPMST, "DP MST" },
284 static const struct drm_prop_enum_list drm_subpixel_enum_list[] =
286 { SubPixelUnknown, "Unknown" },
287 { SubPixelHorizontalRGB, "Horizontal RGB" },
288 { SubPixelHorizontalBGR, "Horizontal BGR" },
289 { SubPixelVerticalRGB, "Vertical RGB" },
290 { SubPixelVerticalBGR, "Vertical BGR" },
291 { SubPixelNone, "None" },
294 void drm_connector_ida_init(void)
299 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
300 ida_init(&drm_connector_enum_list[i].ida);
304 void drm_connector_ida_destroy(void)
309 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
310 ida_destroy(&drm_connector_enum_list[i].ida);
315 * drm_get_connector_status_name - return a string for connector status
316 * @status: connector status to compute name of
318 * In contrast to the other drm_get_*_name functions this one here returns a
319 * const pointer and hence is threadsafe.
321 const char *drm_get_connector_status_name(enum drm_connector_status status)
323 if (status == connector_status_connected)
325 else if (status == connector_status_disconnected)
326 return "disconnected";
330 EXPORT_SYMBOL(drm_get_connector_status_name);
333 * drm_get_subpixel_order_name - return a string for a given subpixel enum
334 * @order: enum of subpixel_order
336 * Note you could abuse this and return something out of bounds, but that
337 * would be a caller error. No unscrubbed user data should make it here.
339 const char *drm_get_subpixel_order_name(enum subpixel_order order)
341 return drm_subpixel_enum_list[order].name;
343 EXPORT_SYMBOL(drm_get_subpixel_order_name);
345 static char printable_char(int c)
347 return isascii(c) && isprint(c) ? c : '?';
351 * drm_get_format_name - return a string for drm fourcc format
352 * @format: format to compute name of
354 * Note that the buffer used by this function is globally shared and owned by
355 * the function itself.
357 * FIXME: This isn't really multithreading safe.
359 const char *drm_get_format_name(uint32_t format)
363 ksnprintf(buf, sizeof(buf),
364 "%c%c%c%c %s-endian (0x%08x)",
365 printable_char(format & 0xff),
366 printable_char((format >> 8) & 0xff),
367 printable_char((format >> 16) & 0xff),
368 printable_char((format >> 24) & 0x7f),
369 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
374 EXPORT_SYMBOL(drm_get_format_name);
377 * drm_mode_object_get - allocate a new modeset identifier
379 * @obj: object pointer, used to generate unique ID
380 * @obj_type: object type
382 * Create a unique identifier based on @ptr in @dev's identifier space. Used
383 * for tracking modes, CRTCs and connectors. Note that despite the _get postfix
384 * modeset identifiers are _not_ reference counted. Hence don't use this for
385 * reference counted modeset objects like framebuffers.
388 * New unique (relative to other objects in @dev) integer identifier for the
391 int drm_mode_object_get(struct drm_device *dev,
392 struct drm_mode_object *obj, uint32_t obj_type)
396 mutex_lock(&dev->mode_config.idr_mutex);
397 ret = idr_alloc(&dev->mode_config.crtc_idr, obj, 1, 0, GFP_KERNEL);
400 * Set up the object linking under the protection of the idr
401 * lock so that other users can't see inconsistent state.
404 obj->type = obj_type;
406 mutex_unlock(&dev->mode_config.idr_mutex);
408 return ret < 0 ? ret : 0;
412 * drm_mode_object_put - free a modeset identifer
414 * @object: object to free
416 * Free @id from @dev's unique identifier pool. Note that despite the _get
417 * postfix modeset identifiers are _not_ reference counted. Hence don't use this
418 * for reference counted modeset objects like framebuffers.
420 void drm_mode_object_put(struct drm_device *dev,
421 struct drm_mode_object *object)
423 mutex_lock(&dev->mode_config.idr_mutex);
424 idr_remove(&dev->mode_config.crtc_idr, object->id);
425 mutex_unlock(&dev->mode_config.idr_mutex);
428 static struct drm_mode_object *_object_find(struct drm_device *dev,
429 uint32_t id, uint32_t type)
431 struct drm_mode_object *obj = NULL;
433 mutex_lock(&dev->mode_config.idr_mutex);
434 obj = idr_find(&dev->mode_config.crtc_idr, id);
435 if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type)
437 if (obj && obj->id != id)
439 /* don't leak out unref'd fb's */
440 if (obj && (obj->type == DRM_MODE_OBJECT_FB))
442 mutex_unlock(&dev->mode_config.idr_mutex);
448 * drm_mode_object_find - look up a drm object with static lifetime
450 * @id: id of the mode object
451 * @type: type of the mode object
453 * Note that framebuffers cannot be looked up with this functions - since those
454 * are reference counted, they need special treatment. Even with
455 * DRM_MODE_OBJECT_ANY (although that will simply return NULL
456 * rather than WARN_ON()).
458 struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
459 uint32_t id, uint32_t type)
461 struct drm_mode_object *obj = NULL;
463 /* Framebuffers are reference counted and need their own lookup
465 WARN_ON(type == DRM_MODE_OBJECT_FB);
466 obj = _object_find(dev, id, type);
469 EXPORT_SYMBOL(drm_mode_object_find);
472 * drm_framebuffer_init - initialize a framebuffer
474 * @fb: framebuffer to be initialized
475 * @funcs: ... with these functions
477 * Allocates an ID for the framebuffer's parent mode object, sets its mode
478 * functions & device file and adds it to the master fd list.
481 * This functions publishes the fb and makes it available for concurrent access
482 * by other users. Which means by this point the fb _must_ be fully set up -
483 * since all the fb attributes are invariant over its lifetime, no further
484 * locking but only correct reference counting is required.
487 * Zero on success, error code on failure.
489 int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
490 const struct drm_framebuffer_funcs *funcs)
494 mutex_lock(&dev->mode_config.fb_lock);
495 kref_init(&fb->refcount);
496 INIT_LIST_HEAD(&fb->filp_head);
500 ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB);
504 /* Grab the idr reference. */
505 drm_framebuffer_reference(fb);
507 dev->mode_config.num_fb++;
508 list_add(&fb->head, &dev->mode_config.fb_list);
510 mutex_unlock(&dev->mode_config.fb_lock);
514 EXPORT_SYMBOL(drm_framebuffer_init);
516 static void drm_framebuffer_free(struct kref *kref)
518 struct drm_framebuffer *fb =
519 container_of(kref, struct drm_framebuffer, refcount);
520 fb->funcs->destroy(fb);
523 static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev,
526 struct drm_mode_object *obj = NULL;
527 struct drm_framebuffer *fb;
529 mutex_lock(&dev->mode_config.idr_mutex);
530 obj = idr_find(&dev->mode_config.crtc_idr, id);
531 if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id))
535 mutex_unlock(&dev->mode_config.idr_mutex);
541 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
543 * @id: id of the fb object
545 * If successful, this grabs an additional reference to the framebuffer -
546 * callers need to make sure to eventually unreference the returned framebuffer
547 * again, using @drm_framebuffer_unreference.
549 struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
552 struct drm_framebuffer *fb;
554 mutex_lock(&dev->mode_config.fb_lock);
555 fb = __drm_framebuffer_lookup(dev, id);
557 drm_framebuffer_reference(fb);
558 mutex_unlock(&dev->mode_config.fb_lock);
562 EXPORT_SYMBOL(drm_framebuffer_lookup);
565 * drm_framebuffer_unreference - unref a framebuffer
566 * @fb: framebuffer to unref
568 * This functions decrements the fb's refcount and frees it if it drops to zero.
570 void drm_framebuffer_unreference(struct drm_framebuffer *fb)
572 DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount));
573 kref_put(&fb->refcount, drm_framebuffer_free);
575 EXPORT_SYMBOL(drm_framebuffer_unreference);
578 * drm_framebuffer_reference - incr the fb refcnt
581 * This functions increments the fb's refcount.
583 void drm_framebuffer_reference(struct drm_framebuffer *fb)
585 DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount));
586 kref_get(&fb->refcount);
588 EXPORT_SYMBOL(drm_framebuffer_reference);
590 static void drm_framebuffer_free_bug(struct kref *kref)
595 static void __drm_framebuffer_unreference(struct drm_framebuffer *fb)
597 DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount));
598 kref_put(&fb->refcount, drm_framebuffer_free_bug);
601 /* dev->mode_config.fb_lock must be held! */
602 static void __drm_framebuffer_unregister(struct drm_device *dev,
603 struct drm_framebuffer *fb)
605 mutex_lock(&dev->mode_config.idr_mutex);
606 idr_remove(&dev->mode_config.crtc_idr, fb->base.id);
607 mutex_unlock(&dev->mode_config.idr_mutex);
611 __drm_framebuffer_unreference(fb);
615 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
616 * @fb: fb to unregister
618 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
619 * those used for fbdev. Note that the caller must hold a reference of it's own,
620 * i.e. the object may not be destroyed through this call (since it'll lead to a
621 * locking inversion).
623 void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
625 struct drm_device *dev = fb->dev;
627 mutex_lock(&dev->mode_config.fb_lock);
628 /* Mark fb as reaped and drop idr ref. */
629 __drm_framebuffer_unregister(dev, fb);
630 mutex_unlock(&dev->mode_config.fb_lock);
632 EXPORT_SYMBOL(drm_framebuffer_unregister_private);
635 * drm_framebuffer_cleanup - remove a framebuffer object
636 * @fb: framebuffer to remove
638 * Cleanup framebuffer. This function is intended to be used from the drivers
639 * ->destroy callback. It can also be used to clean up driver private
640 * framebuffers embedded into a larger structure.
642 * Note that this function does not remove the fb from active usuage - if it is
643 * still used anywhere, hilarity can ensue since userspace could call getfb on
644 * the id and get back -EINVAL. Obviously no concern at driver unload time.
646 * Also, the framebuffer will not be removed from the lookup idr - for
647 * user-created framebuffers this will happen in in the rmfb ioctl. For
648 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
649 * drm_framebuffer_unregister_private.
651 void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
653 struct drm_device *dev = fb->dev;
655 mutex_lock(&dev->mode_config.fb_lock);
657 dev->mode_config.num_fb--;
658 mutex_unlock(&dev->mode_config.fb_lock);
660 EXPORT_SYMBOL(drm_framebuffer_cleanup);
663 * drm_framebuffer_remove - remove and unreference a framebuffer object
664 * @fb: framebuffer to remove
666 * Scans all the CRTCs and planes in @dev's mode_config. If they're
667 * using @fb, removes it, setting it to NULL. Then drops the reference to the
668 * passed-in framebuffer. Might take the modeset locks.
670 * Note that this function optimizes the cleanup away if the caller holds the
671 * last reference to the framebuffer. It is also guaranteed to not take the
672 * modeset locks in this case.
674 void drm_framebuffer_remove(struct drm_framebuffer *fb)
676 struct drm_device *dev = fb->dev;
677 struct drm_crtc *crtc;
678 struct drm_plane *plane;
679 struct drm_mode_set set;
682 WARN_ON(!list_empty(&fb->filp_head));
685 * drm ABI mandates that we remove any deleted framebuffers from active
686 * useage. But since most sane clients only remove framebuffers they no
687 * longer need, try to optimize this away.
689 * Since we're holding a reference ourselves, observing a refcount of 1
690 * means that we're the last holder and can skip it. Also, the refcount
691 * can never increase from 1 again, so we don't need any barriers or
694 * Note that userspace could try to race with use and instate a new
695 * usage _after_ we've cleared all current ones. End result will be an
696 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
699 if (atomic_read(&fb->refcount.refcount) > 1) {
700 drm_modeset_lock_all(dev);
701 /* remove from any CRTC */
702 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
703 if (crtc->primary->fb == fb) {
704 /* should turn off the crtc */
705 memset(&set, 0, sizeof(struct drm_mode_set));
708 ret = drm_mode_set_config_internal(&set);
710 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
714 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
716 drm_plane_force_disable(plane);
718 drm_modeset_unlock_all(dev);
721 drm_framebuffer_unreference(fb);
723 EXPORT_SYMBOL(drm_framebuffer_remove);
725 DEFINE_WW_CLASS(crtc_ww_class);
728 * drm_crtc_init_with_planes - Initialise a new CRTC object with
729 * specified primary and cursor planes.
731 * @crtc: CRTC object to init
732 * @primary: Primary plane for CRTC
733 * @cursor: Cursor plane for CRTC
734 * @funcs: callbacks for the new CRTC
736 * Inits a new object created as base part of a driver crtc object.
739 * Zero on success, error code on failure.
741 int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
742 struct drm_plane *primary,
743 struct drm_plane *cursor,
744 const struct drm_crtc_funcs *funcs)
746 struct drm_mode_config *config = &dev->mode_config;
751 crtc->invert_dimensions = false;
753 drm_modeset_lock_all(dev);
754 drm_modeset_lock_init(&crtc->mutex);
755 /* dropped by _unlock_all(): */
756 drm_modeset_lock(&crtc->mutex, config->acquire_ctx);
758 ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
762 crtc->base.properties = &crtc->properties;
764 list_add_tail(&crtc->head, &config->crtc_list);
767 crtc->primary = primary;
768 crtc->cursor = cursor;
770 primary->possible_crtcs = 1 << drm_crtc_index(crtc);
772 cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
775 drm_modeset_unlock_all(dev);
779 EXPORT_SYMBOL(drm_crtc_init_with_planes);
782 * drm_crtc_cleanup - Clean up the core crtc usage
783 * @crtc: CRTC to cleanup
785 * This function cleans up @crtc and removes it from the DRM mode setting
786 * core. Note that the function does *not* free the crtc structure itself,
787 * this is the responsibility of the caller.
789 void drm_crtc_cleanup(struct drm_crtc *crtc)
791 struct drm_device *dev = crtc->dev;
793 kfree(crtc->gamma_store);
794 crtc->gamma_store = NULL;
796 drm_modeset_lock_fini(&crtc->mutex);
798 drm_mode_object_put(dev, &crtc->base);
799 list_del(&crtc->head);
800 dev->mode_config.num_crtc--;
802 EXPORT_SYMBOL(drm_crtc_cleanup);
805 * drm_crtc_index - find the index of a registered CRTC
806 * @crtc: CRTC to find index for
808 * Given a registered CRTC, return the index of that CRTC within a DRM
809 * device's list of CRTCs.
811 unsigned int drm_crtc_index(struct drm_crtc *crtc)
813 unsigned int index = 0;
814 struct drm_crtc *tmp;
816 list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) {
825 EXPORT_SYMBOL(drm_crtc_index);
828 * drm_mode_remove - remove and free a mode
829 * @connector: connector list to modify
830 * @mode: mode to remove
832 * Remove @mode from @connector's mode list, then free it.
834 static void drm_mode_remove(struct drm_connector *connector,
835 struct drm_display_mode *mode)
837 list_del(&mode->head);
838 drm_mode_destroy(connector->dev, mode);
842 * drm_connector_init - Init a preallocated connector
844 * @connector: the connector to init
845 * @funcs: callbacks for this connector
846 * @connector_type: user visible type of the connector
848 * Initialises a preallocated connector. Connectors should be
849 * subclassed as part of driver connector objects.
852 * Zero on success, error code on failure.
854 int drm_connector_init(struct drm_device *dev,
855 struct drm_connector *connector,
856 const struct drm_connector_funcs *funcs,
861 drm_modeset_lock_all(dev);
863 ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR);
867 connector->base.properties = &connector->properties;
868 connector->dev = dev;
869 connector->funcs = funcs;
870 connector->connector_type = connector_type;
871 connector->connector_type_id =
872 ++drm_connector_enum_list[connector_type].count; /* TODO */
873 if (connector->connector_type_id < 0) {
874 ret = connector->connector_type_id;
878 drm_asprintf(GFP_KERNEL, "%s-%d",
879 drm_connector_enum_list[connector_type].name,
880 connector->connector_type_id);
881 if (!connector->name) {
886 INIT_LIST_HEAD(&connector->probed_modes);
887 INIT_LIST_HEAD(&connector->modes);
888 connector->edid_blob_ptr = NULL;
889 connector->status = connector_status_unknown;
891 list_add_tail(&connector->head, &dev->mode_config.connector_list);
892 dev->mode_config.num_connector++;
894 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
895 drm_object_attach_property(&connector->base,
896 dev->mode_config.edid_property,
899 drm_object_attach_property(&connector->base,
900 dev->mode_config.dpms_property, 0);
902 connector->debugfs_entry = NULL;
906 drm_mode_object_put(dev, &connector->base);
909 drm_modeset_unlock_all(dev);
913 EXPORT_SYMBOL(drm_connector_init);
916 * drm_connector_cleanup - cleans up an initialised connector
917 * @connector: connector to cleanup
919 * Cleans up the connector but doesn't free the object.
921 void drm_connector_cleanup(struct drm_connector *connector)
923 struct drm_device *dev = connector->dev;
924 struct drm_display_mode *mode, *t;
926 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
927 drm_mode_remove(connector, mode);
929 list_for_each_entry_safe(mode, t, &connector->modes, head)
930 drm_mode_remove(connector, mode);
932 drm_mode_object_put(dev, &connector->base);
933 kfree(connector->name);
934 connector->name = NULL;
935 list_del(&connector->head);
936 dev->mode_config.num_connector--;
938 EXPORT_SYMBOL(drm_connector_cleanup);
941 * drm_connector_register - register a connector
942 * @connector: the connector to register
944 * Register userspace interfaces for a connector
947 * Zero on success, error code on failure.
949 int drm_connector_register(struct drm_connector *connector)
953 ret = drm_sysfs_connector_add(connector);
958 ret = drm_debugfs_connector_add(connector);
961 drm_sysfs_connector_remove(connector);
967 EXPORT_SYMBOL(drm_connector_register);
970 * drm_connector_unregister - unregister a connector
971 * @connector: the connector to unregister
973 * Unregister userspace interfaces for a connector
975 void drm_connector_unregister(struct drm_connector *connector)
977 drm_sysfs_connector_remove(connector);
979 drm_debugfs_connector_remove(connector);
982 EXPORT_SYMBOL(drm_connector_unregister);
986 * drm_connector_unplug_all - unregister connector userspace interfaces
989 * This function unregisters all connector userspace interfaces in sysfs. Should
990 * be call when the device is disconnected, e.g. from an usb driver's
991 * ->disconnect callback.
993 void drm_connector_unplug_all(struct drm_device *dev)
995 struct drm_connector *connector;
997 /* taking the mode config mutex ends up in a clash with sysfs */
998 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
999 drm_connector_unregister(connector);
1002 EXPORT_SYMBOL(drm_connector_unplug_all);
1005 * drm_bridge_init - initialize a drm transcoder/bridge
1007 * @bridge: transcoder/bridge to set up
1008 * @funcs: bridge function table
1010 * Initialises a preallocated bridge. Bridges should be
1011 * subclassed as part of driver connector objects.
1014 * Zero on success, error code on failure.
1016 int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
1017 const struct drm_bridge_funcs *funcs)
1021 drm_modeset_lock_all(dev);
1023 ret = drm_mode_object_get(dev, &bridge->base, DRM_MODE_OBJECT_BRIDGE);
1028 bridge->funcs = funcs;
1030 list_add_tail(&bridge->head, &dev->mode_config.bridge_list);
1031 dev->mode_config.num_bridge++;
1034 drm_modeset_unlock_all(dev);
1037 EXPORT_SYMBOL(drm_bridge_init);
1040 * drm_bridge_cleanup - cleans up an initialised bridge
1041 * @bridge: bridge to cleanup
1043 * Cleans up the bridge but doesn't free the object.
1045 void drm_bridge_cleanup(struct drm_bridge *bridge)
1047 struct drm_device *dev = bridge->dev;
1049 drm_modeset_lock_all(dev);
1050 drm_mode_object_put(dev, &bridge->base);
1051 list_del(&bridge->head);
1052 dev->mode_config.num_bridge--;
1053 drm_modeset_unlock_all(dev);
1055 EXPORT_SYMBOL(drm_bridge_cleanup);
1058 * drm_encoder_init - Init a preallocated encoder
1060 * @encoder: the encoder to init
1061 * @funcs: callbacks for this encoder
1062 * @encoder_type: user visible type of the encoder
1064 * Initialises a preallocated encoder. Encoder should be
1065 * subclassed as part of driver encoder objects.
1068 * Zero on success, error code on failure.
1070 int drm_encoder_init(struct drm_device *dev,
1071 struct drm_encoder *encoder,
1072 const struct drm_encoder_funcs *funcs,
1077 drm_modeset_lock_all(dev);
1079 ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
1084 encoder->encoder_type = encoder_type;
1085 encoder->funcs = funcs;
1086 encoder->name = drm_asprintf(GFP_KERNEL, "%s-%d",
1087 drm_encoder_enum_list[encoder_type].name,
1089 if (!encoder->name) {
1094 list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
1095 dev->mode_config.num_encoder++;
1099 drm_mode_object_put(dev, &encoder->base);
1102 drm_modeset_unlock_all(dev);
1106 EXPORT_SYMBOL(drm_encoder_init);
1109 * drm_encoder_cleanup - cleans up an initialised encoder
1110 * @encoder: encoder to cleanup
1112 * Cleans up the encoder but doesn't free the object.
1114 void drm_encoder_cleanup(struct drm_encoder *encoder)
1116 struct drm_device *dev = encoder->dev;
1117 drm_modeset_lock_all(dev);
1118 drm_mode_object_put(dev, &encoder->base);
1119 kfree(encoder->name);
1120 encoder->name = NULL;
1121 list_del(&encoder->head);
1122 dev->mode_config.num_encoder--;
1123 drm_modeset_unlock_all(dev);
1125 EXPORT_SYMBOL(drm_encoder_cleanup);
1128 * drm_universal_plane_init - Initialize a new universal plane object
1130 * @plane: plane object to init
1131 * @possible_crtcs: bitmask of possible CRTCs
1132 * @funcs: callbacks for the new plane
1133 * @formats: array of supported formats (%DRM_FORMAT_*)
1134 * @format_count: number of elements in @formats
1135 * @type: type of plane (overlay, primary, cursor)
1137 * Initializes a plane object of type @type.
1140 * Zero on success, error code on failure.
1142 int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
1143 unsigned long possible_crtcs,
1144 const struct drm_plane_funcs *funcs,
1145 const uint32_t *formats, uint32_t format_count,
1146 enum drm_plane_type type)
1150 drm_modeset_lock_all(dev);
1152 ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
1156 plane->base.properties = &plane->properties;
1158 plane->funcs = funcs;
1159 plane->format_types = kmalloc(sizeof(uint32_t) * format_count,
1161 if (!plane->format_types) {
1162 DRM_DEBUG_KMS("out of memory when allocating plane\n");
1163 drm_mode_object_put(dev, &plane->base);
1168 memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
1169 plane->format_count = format_count;
1170 plane->possible_crtcs = possible_crtcs;
1173 list_add_tail(&plane->head, &dev->mode_config.plane_list);
1174 dev->mode_config.num_total_plane++;
1175 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1176 dev->mode_config.num_overlay_plane++;
1178 drm_object_attach_property(&plane->base,
1179 dev->mode_config.plane_type_property,
1183 drm_modeset_unlock_all(dev);
1187 EXPORT_SYMBOL(drm_universal_plane_init);
1190 * drm_plane_init - Initialize a legacy plane
1192 * @plane: plane object to init
1193 * @possible_crtcs: bitmask of possible CRTCs
1194 * @funcs: callbacks for the new plane
1195 * @formats: array of supported formats (%DRM_FORMAT_*)
1196 * @format_count: number of elements in @formats
1197 * @is_primary: plane type (primary vs overlay)
1199 * Legacy API to initialize a DRM plane.
1201 * New drivers should call drm_universal_plane_init() instead.
1204 * Zero on success, error code on failure.
1206 int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
1207 unsigned long possible_crtcs,
1208 const struct drm_plane_funcs *funcs,
1209 const uint32_t *formats, uint32_t format_count,
1212 enum drm_plane_type type;
1214 type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY;
1215 return drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
1216 formats, format_count, type);
1218 EXPORT_SYMBOL(drm_plane_init);
1221 * drm_plane_cleanup - Clean up the core plane usage
1222 * @plane: plane to cleanup
1224 * This function cleans up @plane and removes it from the DRM mode setting
1225 * core. Note that the function does *not* free the plane structure itself,
1226 * this is the responsibility of the caller.
1228 void drm_plane_cleanup(struct drm_plane *plane)
1230 struct drm_device *dev = plane->dev;
1232 drm_modeset_lock_all(dev);
1233 kfree(plane->format_types);
1234 drm_mode_object_put(dev, &plane->base);
1236 BUG_ON(list_empty(&plane->head));
1238 list_del(&plane->head);
1239 dev->mode_config.num_total_plane--;
1240 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1241 dev->mode_config.num_overlay_plane--;
1242 drm_modeset_unlock_all(dev);
1244 EXPORT_SYMBOL(drm_plane_cleanup);
1247 * drm_plane_force_disable - Forcibly disable a plane
1248 * @plane: plane to disable
1250 * Forces the plane to be disabled.
1252 * Used when the plane's current framebuffer is destroyed,
1253 * and when restoring fbdev mode.
1255 void drm_plane_force_disable(struct drm_plane *plane)
1257 struct drm_framebuffer *old_fb = plane->fb;
1263 ret = plane->funcs->disable_plane(plane);
1265 DRM_ERROR("failed to disable plane with busy fb\n");
1268 /* disconnect the plane from the fb and crtc: */
1269 __drm_framebuffer_unreference(old_fb);
1273 EXPORT_SYMBOL(drm_plane_force_disable);
1275 static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
1277 struct drm_property *edid;
1278 struct drm_property *dpms;
1279 struct drm_property *dev_path;
1282 * Standard properties (apply to all connectors)
1284 edid = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1285 DRM_MODE_PROP_IMMUTABLE,
1287 dev->mode_config.edid_property = edid;
1289 dpms = drm_property_create_enum(dev, 0,
1290 "DPMS", drm_dpms_enum_list,
1291 ARRAY_SIZE(drm_dpms_enum_list));
1292 dev->mode_config.dpms_property = dpms;
1294 dev_path = drm_property_create(dev,
1295 DRM_MODE_PROP_BLOB |
1296 DRM_MODE_PROP_IMMUTABLE,
1298 dev->mode_config.path_property = dev_path;
1303 static int drm_mode_create_standard_plane_properties(struct drm_device *dev)
1305 struct drm_property *type;
1308 * Standard properties (apply to all planes)
1310 type = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1311 "type", drm_plane_type_enum_list,
1312 ARRAY_SIZE(drm_plane_type_enum_list));
1313 dev->mode_config.plane_type_property = type;
1319 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1322 * Called by a driver the first time a DVI-I connector is made.
1324 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1326 struct drm_property *dvi_i_selector;
1327 struct drm_property *dvi_i_subconnector;
1329 if (dev->mode_config.dvi_i_select_subconnector_property)
1333 drm_property_create_enum(dev, 0,
1334 "select subconnector",
1335 drm_dvi_i_select_enum_list,
1336 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1337 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1339 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1341 drm_dvi_i_subconnector_enum_list,
1342 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1343 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1347 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1350 * drm_create_tv_properties - create TV specific connector properties
1352 * @num_modes: number of different TV formats (modes) supported
1353 * @modes: array of pointers to strings containing name of each format
1355 * Called by a driver's TV initialization routine, this function creates
1356 * the TV specific connector properties for a given device. Caller is
1357 * responsible for allocating a list of format names and passing them to
1360 int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
1363 struct drm_property *tv_selector;
1364 struct drm_property *tv_subconnector;
1367 if (dev->mode_config.tv_select_subconnector_property)
1371 * Basic connector properties
1373 tv_selector = drm_property_create_enum(dev, 0,
1374 "select subconnector",
1375 drm_tv_select_enum_list,
1376 ARRAY_SIZE(drm_tv_select_enum_list));
1377 dev->mode_config.tv_select_subconnector_property = tv_selector;
1380 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1382 drm_tv_subconnector_enum_list,
1383 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1384 dev->mode_config.tv_subconnector_property = tv_subconnector;
1387 * Other, TV specific properties: margins & TV modes.
1389 dev->mode_config.tv_left_margin_property =
1390 drm_property_create_range(dev, 0, "left margin", 0, 100);
1392 dev->mode_config.tv_right_margin_property =
1393 drm_property_create_range(dev, 0, "right margin", 0, 100);
1395 dev->mode_config.tv_top_margin_property =
1396 drm_property_create_range(dev, 0, "top margin", 0, 100);
1398 dev->mode_config.tv_bottom_margin_property =
1399 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1401 dev->mode_config.tv_mode_property =
1402 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1404 for (i = 0; i < num_modes; i++)
1405 drm_property_add_enum(dev->mode_config.tv_mode_property, i,
1408 dev->mode_config.tv_brightness_property =
1409 drm_property_create_range(dev, 0, "brightness", 0, 100);
1411 dev->mode_config.tv_contrast_property =
1412 drm_property_create_range(dev, 0, "contrast", 0, 100);
1414 dev->mode_config.tv_flicker_reduction_property =
1415 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1417 dev->mode_config.tv_overscan_property =
1418 drm_property_create_range(dev, 0, "overscan", 0, 100);
1420 dev->mode_config.tv_saturation_property =
1421 drm_property_create_range(dev, 0, "saturation", 0, 100);
1423 dev->mode_config.tv_hue_property =
1424 drm_property_create_range(dev, 0, "hue", 0, 100);
1428 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1431 * drm_mode_create_scaling_mode_property - create scaling mode property
1434 * Called by a driver the first time it's needed, must be attached to desired
1437 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1439 struct drm_property *scaling_mode;
1441 if (dev->mode_config.scaling_mode_property)
1445 drm_property_create_enum(dev, 0, "scaling mode",
1446 drm_scaling_mode_enum_list,
1447 ARRAY_SIZE(drm_scaling_mode_enum_list));
1449 dev->mode_config.scaling_mode_property = scaling_mode;
1453 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1456 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1459 * Called by a driver the first time it's needed, must be attached to desired
1463 * Zero on success, errno on failure.
1465 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1467 if (dev->mode_config.aspect_ratio_property)
1470 dev->mode_config.aspect_ratio_property =
1471 drm_property_create_enum(dev, 0, "aspect ratio",
1472 drm_aspect_ratio_enum_list,
1473 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1475 if (dev->mode_config.aspect_ratio_property == NULL)
1480 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1483 * drm_mode_create_dirty_property - create dirty property
1486 * Called by a driver the first time it's needed, must be attached to desired
1489 int drm_mode_create_dirty_info_property(struct drm_device *dev)
1491 struct drm_property *dirty_info;
1493 if (dev->mode_config.dirty_info_property)
1497 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1499 drm_dirty_info_enum_list,
1500 ARRAY_SIZE(drm_dirty_info_enum_list));
1501 dev->mode_config.dirty_info_property = dirty_info;
1505 EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
1507 static int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
1509 uint32_t total_objects = 0;
1511 total_objects += dev->mode_config.num_crtc;
1512 total_objects += dev->mode_config.num_connector;
1513 total_objects += dev->mode_config.num_encoder;
1514 total_objects += dev->mode_config.num_bridge;
1516 group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL);
1517 if (!group->id_list)
1520 group->num_crtcs = 0;
1521 group->num_connectors = 0;
1522 group->num_encoders = 0;
1523 group->num_bridges = 0;
1527 void drm_mode_group_destroy(struct drm_mode_group *group)
1529 kfree(group->id_list);
1530 group->id_list = NULL;
1534 * NOTE: Driver's shouldn't ever call drm_mode_group_init_legacy_group - it is
1535 * the drm core's responsibility to set up mode control groups.
1537 int drm_mode_group_init_legacy_group(struct drm_device *dev,
1538 struct drm_mode_group *group)
1540 struct drm_crtc *crtc;
1541 struct drm_encoder *encoder;
1542 struct drm_connector *connector;
1543 struct drm_bridge *bridge;
1546 if ((ret = drm_mode_group_init(dev, group)))
1549 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
1550 group->id_list[group->num_crtcs++] = crtc->base.id;
1552 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
1553 group->id_list[group->num_crtcs + group->num_encoders++] =
1556 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
1557 group->id_list[group->num_crtcs + group->num_encoders +
1558 group->num_connectors++] = connector->base.id;
1560 list_for_each_entry(bridge, &dev->mode_config.bridge_list, head)
1561 group->id_list[group->num_crtcs + group->num_encoders +
1562 group->num_connectors + group->num_bridges++] =
1567 EXPORT_SYMBOL(drm_mode_group_init_legacy_group);
1569 void drm_reinit_primary_mode_group(struct drm_device *dev)
1571 drm_modeset_lock_all(dev);
1572 drm_mode_group_destroy(&dev->primary->mode_group);
1573 drm_mode_group_init_legacy_group(dev, &dev->primary->mode_group);
1574 drm_modeset_unlock_all(dev);
1576 EXPORT_SYMBOL(drm_reinit_primary_mode_group);
1579 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1580 * @out: drm_mode_modeinfo struct to return to the user
1581 * @in: drm_display_mode to use
1583 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1586 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out,
1587 const struct drm_display_mode *in)
1589 WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX ||
1590 in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX ||
1591 in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX ||
1592 in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX ||
1593 in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX,
1594 "timing values too large for mode info\n");
1596 out->clock = in->clock;
1597 out->hdisplay = in->hdisplay;
1598 out->hsync_start = in->hsync_start;
1599 out->hsync_end = in->hsync_end;
1600 out->htotal = in->htotal;
1601 out->hskew = in->hskew;
1602 out->vdisplay = in->vdisplay;
1603 out->vsync_start = in->vsync_start;
1604 out->vsync_end = in->vsync_end;
1605 out->vtotal = in->vtotal;
1606 out->vscan = in->vscan;
1607 out->vrefresh = in->vrefresh;
1608 out->flags = in->flags;
1609 out->type = in->type;
1610 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1611 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1615 * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
1616 * @out: drm_display_mode to return to the user
1617 * @in: drm_mode_modeinfo to use
1619 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1623 * Zero on success, errno on failure.
1625 static int drm_crtc_convert_umode(struct drm_display_mode *out,
1626 const struct drm_mode_modeinfo *in)
1628 if (in->clock > INT_MAX || in->vrefresh > INT_MAX)
1631 if ((in->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX)
1634 out->clock = in->clock;
1635 out->hdisplay = in->hdisplay;
1636 out->hsync_start = in->hsync_start;
1637 out->hsync_end = in->hsync_end;
1638 out->htotal = in->htotal;
1639 out->hskew = in->hskew;
1640 out->vdisplay = in->vdisplay;
1641 out->vsync_start = in->vsync_start;
1642 out->vsync_end = in->vsync_end;
1643 out->vtotal = in->vtotal;
1644 out->vscan = in->vscan;
1645 out->vrefresh = in->vrefresh;
1646 out->flags = in->flags;
1647 out->type = in->type;
1648 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1649 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1655 * drm_mode_getresources - get graphics configuration
1656 * @dev: drm device for the ioctl
1657 * @data: data pointer for the ioctl
1658 * @file_priv: drm file for the ioctl call
1660 * Construct a set of configuration description structures and return
1661 * them to the user, including CRTC, connector and framebuffer configuration.
1663 * Called by the user via ioctl.
1666 * Zero on success, errno on failure.
1668 int drm_mode_getresources(struct drm_device *dev, void *data,
1669 struct drm_file *file_priv)
1671 struct drm_mode_card_res *card_res = data;
1672 struct list_head *lh;
1673 struct drm_framebuffer *fb;
1674 struct drm_connector *connector;
1675 struct drm_crtc *crtc;
1676 struct drm_encoder *encoder;
1678 int connector_count = 0;
1681 int encoder_count = 0;
1683 uint32_t __user *fb_id;
1684 uint32_t __user *crtc_id;
1685 uint32_t __user *connector_id;
1686 uint32_t __user *encoder_id;
1687 struct drm_mode_group *mode_group;
1689 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1693 mutex_lock(&file_priv->fbs_lock);
1695 * For the non-control nodes we need to limit the list of resources
1696 * by IDs in the group list for this node
1698 list_for_each(lh, &file_priv->fbs)
1701 /* handle this in 4 parts */
1703 if (card_res->count_fbs >= fb_count) {
1705 fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
1706 list_for_each_entry(fb, &file_priv->fbs, filp_head) {
1707 if (put_user(fb->base.id, fb_id + copied)) {
1708 mutex_unlock(&file_priv->fbs_lock);
1714 card_res->count_fbs = fb_count;
1715 mutex_unlock(&file_priv->fbs_lock);
1717 drm_modeset_lock_all(dev);
1718 if (!drm_is_primary_client(file_priv)) {
1721 list_for_each(lh, &dev->mode_config.crtc_list)
1724 list_for_each(lh, &dev->mode_config.connector_list)
1727 list_for_each(lh, &dev->mode_config.encoder_list)
1731 crtc_count = mode_group->num_crtcs;
1732 connector_count = mode_group->num_connectors;
1733 encoder_count = mode_group->num_encoders;
1736 card_res->max_height = dev->mode_config.max_height;
1737 card_res->min_height = dev->mode_config.min_height;
1738 card_res->max_width = dev->mode_config.max_width;
1739 card_res->min_width = dev->mode_config.min_width;
1742 if (card_res->count_crtcs >= crtc_count) {
1744 crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
1746 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
1748 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1749 if (put_user(crtc->base.id, crtc_id + copied)) {
1756 for (i = 0; i < mode_group->num_crtcs; i++) {
1757 if (put_user(mode_group->id_list[i],
1758 crtc_id + copied)) {
1766 card_res->count_crtcs = crtc_count;
1769 if (card_res->count_encoders >= encoder_count) {
1771 encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
1773 list_for_each_entry(encoder,
1774 &dev->mode_config.encoder_list,
1776 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
1778 if (put_user(encoder->base.id, encoder_id +
1786 for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
1787 if (put_user(mode_group->id_list[i],
1788 encoder_id + copied)) {
1797 card_res->count_encoders = encoder_count;
1800 if (card_res->count_connectors >= connector_count) {
1802 connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
1804 list_for_each_entry(connector,
1805 &dev->mode_config.connector_list,
1807 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1810 if (put_user(connector->base.id,
1811 connector_id + copied)) {
1818 int start = mode_group->num_crtcs +
1819 mode_group->num_encoders;
1820 for (i = start; i < start + mode_group->num_connectors; i++) {
1821 if (put_user(mode_group->id_list[i],
1822 connector_id + copied)) {
1830 card_res->count_connectors = connector_count;
1832 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
1833 card_res->count_connectors, card_res->count_encoders);
1836 drm_modeset_unlock_all(dev);
1841 * drm_mode_getcrtc - get CRTC configuration
1842 * @dev: drm device for the ioctl
1843 * @data: data pointer for the ioctl
1844 * @file_priv: drm file for the ioctl call
1846 * Construct a CRTC configuration structure to return to the user.
1848 * Called by the user via ioctl.
1851 * Zero on success, errno on failure.
1853 int drm_mode_getcrtc(struct drm_device *dev,
1854 void *data, struct drm_file *file_priv)
1856 struct drm_mode_crtc *crtc_resp = data;
1857 struct drm_crtc *crtc;
1860 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1863 drm_modeset_lock_all(dev);
1865 crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
1871 crtc_resp->x = crtc->x;
1872 crtc_resp->y = crtc->y;
1873 crtc_resp->gamma_size = crtc->gamma_size;
1874 if (crtc->primary->fb)
1875 crtc_resp->fb_id = crtc->primary->fb->base.id;
1877 crtc_resp->fb_id = 0;
1879 if (crtc->enabled) {
1881 drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
1882 crtc_resp->mode_valid = 1;
1885 crtc_resp->mode_valid = 0;
1889 drm_modeset_unlock_all(dev);
1893 static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1894 const struct drm_file *file_priv)
1897 * If user-space hasn't configured the driver to expose the stereo 3D
1898 * modes, don't expose them.
1900 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
1907 * drm_mode_getconnector - get connector configuration
1908 * @dev: drm device for the ioctl
1909 * @data: data pointer for the ioctl
1910 * @file_priv: drm file for the ioctl call
1912 * Construct a connector configuration structure to return to the user.
1914 * Called by the user via ioctl.
1917 * Zero on success, errno on failure.
1919 int drm_mode_getconnector(struct drm_device *dev, void *data,
1920 struct drm_file *file_priv)
1922 struct drm_mode_get_connector *out_resp = data;
1923 struct drm_connector *connector;
1924 struct drm_display_mode *mode;
1926 int props_count = 0;
1927 int encoders_count = 0;
1931 struct drm_mode_modeinfo u_mode;
1932 struct drm_mode_modeinfo __user *mode_ptr;
1933 uint32_t __user *prop_ptr;
1934 uint64_t __user *prop_values;
1935 uint32_t __user *encoder_ptr;
1937 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1940 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1942 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
1944 mutex_lock(&dev->mode_config.mutex);
1945 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1947 connector = drm_connector_find(dev, out_resp->connector_id);
1953 props_count = connector->properties.count;
1955 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1956 if (connector->encoder_ids[i] != 0) {
1961 if (out_resp->count_modes == 0) {
1962 connector->funcs->fill_modes(connector,
1963 dev->mode_config.max_width,
1964 dev->mode_config.max_height);
1967 /* delayed so we get modes regardless of pre-fill_modes state */
1968 list_for_each_entry(mode, &connector->modes, head)
1969 if (drm_mode_expose_to_userspace(mode, file_priv))
1972 out_resp->connector_id = connector->base.id;
1973 out_resp->connector_type = connector->connector_type;
1974 out_resp->connector_type_id = connector->connector_type_id;
1975 out_resp->mm_width = connector->display_info.width_mm;
1976 out_resp->mm_height = connector->display_info.height_mm;
1977 out_resp->subpixel = connector->display_info.subpixel_order;
1978 out_resp->connection = connector->status;
1979 if (connector->encoder)
1980 out_resp->encoder_id = connector->encoder->base.id;
1982 out_resp->encoder_id = 0;
1985 * This ioctl is called twice, once to determine how much space is
1986 * needed, and the 2nd time to fill it.
1988 if ((out_resp->count_modes >= mode_count) && mode_count) {
1990 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
1991 list_for_each_entry(mode, &connector->modes, head) {
1992 if (!drm_mode_expose_to_userspace(mode, file_priv))
1995 drm_crtc_convert_to_umode(&u_mode, mode);
1996 if (copy_to_user(mode_ptr + copied,
1997 &u_mode, sizeof(u_mode))) {
2004 out_resp->count_modes = mode_count;
2006 if ((out_resp->count_props >= props_count) && props_count) {
2008 prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
2009 prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
2010 for (i = 0; i < connector->properties.count; i++) {
2011 if (put_user(connector->properties.ids[i],
2012 prop_ptr + copied)) {
2017 if (put_user(connector->properties.values[i],
2018 prop_values + copied)) {
2025 out_resp->count_props = props_count;
2027 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2029 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
2030 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2031 if (connector->encoder_ids[i] != 0) {
2032 if (put_user(connector->encoder_ids[i],
2033 encoder_ptr + copied)) {
2041 out_resp->count_encoders = encoders_count;
2044 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2045 mutex_unlock(&dev->mode_config.mutex);
2051 * drm_mode_getencoder - get encoder configuration
2052 * @dev: drm device for the ioctl
2053 * @data: data pointer for the ioctl
2054 * @file_priv: drm file for the ioctl call
2056 * Construct a encoder configuration structure to return to the user.
2058 * Called by the user via ioctl.
2061 * Zero on success, errno on failure.
2063 int drm_mode_getencoder(struct drm_device *dev, void *data,
2064 struct drm_file *file_priv)
2066 struct drm_mode_get_encoder *enc_resp = data;
2067 struct drm_encoder *encoder;
2070 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2073 drm_modeset_lock_all(dev);
2074 encoder = drm_encoder_find(dev, enc_resp->encoder_id);
2081 enc_resp->crtc_id = encoder->crtc->base.id;
2083 enc_resp->crtc_id = 0;
2084 enc_resp->encoder_type = encoder->encoder_type;
2085 enc_resp->encoder_id = encoder->base.id;
2086 enc_resp->possible_crtcs = encoder->possible_crtcs;
2087 enc_resp->possible_clones = encoder->possible_clones;
2090 drm_modeset_unlock_all(dev);
2095 * drm_mode_getplane_res - enumerate all plane resources
2098 * @file_priv: DRM file info
2100 * Construct a list of plane ids to return to the user.
2102 * Called by the user via ioctl.
2105 * Zero on success, errno on failure.
2107 int drm_mode_getplane_res(struct drm_device *dev, void *data,
2108 struct drm_file *file_priv)
2110 struct drm_mode_get_plane_res *plane_resp = data;
2111 struct drm_mode_config *config;
2112 struct drm_plane *plane;
2113 uint32_t __user *plane_ptr;
2114 int copied = 0, ret = 0;
2115 unsigned num_planes;
2117 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2120 drm_modeset_lock_all(dev);
2121 config = &dev->mode_config;
2123 if (file_priv->universal_planes)
2124 num_planes = config->num_total_plane;
2126 num_planes = config->num_overlay_plane;
2129 * This ioctl is called twice, once to determine how much space is
2130 * needed, and the 2nd time to fill it.
2133 (plane_resp->count_planes >= num_planes)) {
2134 plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr;
2136 list_for_each_entry(plane, &config->plane_list, head) {
2138 * Unless userspace set the 'universal planes'
2139 * capability bit, only advertise overlays.
2141 if (plane->type != DRM_PLANE_TYPE_OVERLAY &&
2142 !file_priv->universal_planes)
2145 if (put_user(plane->base.id, plane_ptr + copied)) {
2152 plane_resp->count_planes = num_planes;
2155 drm_modeset_unlock_all(dev);
2160 * drm_mode_getplane - get plane configuration
2163 * @file_priv: DRM file info
2165 * Construct a plane configuration structure to return to the user.
2167 * Called by the user via ioctl.
2170 * Zero on success, errno on failure.
2172 int drm_mode_getplane(struct drm_device *dev, void *data,
2173 struct drm_file *file_priv)
2175 struct drm_mode_get_plane *plane_resp = data;
2176 struct drm_plane *plane;
2177 uint32_t __user *format_ptr;
2180 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2183 drm_modeset_lock_all(dev);
2184 plane = drm_plane_find(dev, plane_resp->plane_id);
2191 plane_resp->crtc_id = plane->crtc->base.id;
2193 plane_resp->crtc_id = 0;
2196 plane_resp->fb_id = plane->fb->base.id;
2198 plane_resp->fb_id = 0;
2200 plane_resp->plane_id = plane->base.id;
2201 plane_resp->possible_crtcs = plane->possible_crtcs;
2202 plane_resp->gamma_size = 0;
2205 * This ioctl is called twice, once to determine how much space is
2206 * needed, and the 2nd time to fill it.
2208 if (plane->format_count &&
2209 (plane_resp->count_format_types >= plane->format_count)) {
2210 format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr;
2211 if (copy_to_user(format_ptr,
2212 plane->format_types,
2213 sizeof(uint32_t) * plane->format_count)) {
2218 plane_resp->count_format_types = plane->format_count;
2221 drm_modeset_unlock_all(dev);
2226 * setplane_internal - setplane handler for internal callers
2228 * Note that we assume an extra reference has already been taken on fb. If the
2229 * update fails, this reference will be dropped before return; if it succeeds,
2230 * the previous framebuffer (if any) will be unreferenced instead.
2232 * src_{x,y,w,h} are provided in 16.16 fixed point format
2234 static int setplane_internal(struct drm_plane *plane,
2235 struct drm_crtc *crtc,
2236 struct drm_framebuffer *fb,
2237 int32_t crtc_x, int32_t crtc_y,
2238 uint32_t crtc_w, uint32_t crtc_h,
2239 /* src_{x,y,w,h} values are 16.16 fixed point */
2240 uint32_t src_x, uint32_t src_y,
2241 uint32_t src_w, uint32_t src_h)
2243 struct drm_device *dev = plane->dev;
2244 struct drm_framebuffer *old_fb = NULL;
2246 unsigned int fb_width, fb_height;
2249 /* No fb means shut it down */
2251 drm_modeset_lock_all(dev);
2253 ret = plane->funcs->disable_plane(plane);
2260 drm_modeset_unlock_all(dev);
2264 /* Check whether this plane is usable on this CRTC */
2265 if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
2266 DRM_DEBUG_KMS("Invalid crtc for plane\n");
2271 /* Check whether this plane supports the fb pixel format. */
2272 for (i = 0; i < plane->format_count; i++)
2273 if (fb->pixel_format == plane->format_types[i])
2275 if (i == plane->format_count) {
2276 DRM_DEBUG_KMS("Invalid pixel format %s\n",
2277 drm_get_format_name(fb->pixel_format));
2282 fb_width = fb->width << 16;
2283 fb_height = fb->height << 16;
2285 /* Make sure source coordinates are inside the fb. */
2286 if (src_w > fb_width ||
2287 src_x > fb_width - src_w ||
2288 src_h > fb_height ||
2289 src_y > fb_height - src_h) {
2290 DRM_DEBUG_KMS("Invalid source coordinates "
2291 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
2292 src_w >> 16, ((src_w & 0xffff) * 15625) >> 10,
2293 src_h >> 16, ((src_h & 0xffff) * 15625) >> 10,
2294 src_x >> 16, ((src_x & 0xffff) * 15625) >> 10,
2295 src_y >> 16, ((src_y & 0xffff) * 15625) >> 10);
2300 drm_modeset_lock_all(dev);
2302 ret = plane->funcs->update_plane(plane, crtc, fb,
2303 crtc_x, crtc_y, crtc_w, crtc_h,
2304 src_x, src_y, src_w, src_h);
2312 drm_modeset_unlock_all(dev);
2316 drm_framebuffer_unreference(fb);
2318 drm_framebuffer_unreference(old_fb);
2325 * drm_mode_setplane - configure a plane's configuration
2327 * @data: ioctl data*
2328 * @file_priv: DRM file info
2330 * Set plane configuration, including placement, fb, scaling, and other factors.
2331 * Or pass a NULL fb to disable (planes may be disabled without providing a
2335 * Zero on success, errno on failure.
2337 int drm_mode_setplane(struct drm_device *dev, void *data,
2338 struct drm_file *file_priv)
2340 struct drm_mode_set_plane *plane_req = data;
2341 struct drm_mode_object *obj;
2342 struct drm_plane *plane;
2343 struct drm_crtc *crtc = NULL;
2344 struct drm_framebuffer *fb = NULL;
2346 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2349 /* Give drivers some help against integer overflows */
2350 if (plane_req->crtc_w > INT_MAX ||
2351 plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w ||
2352 plane_req->crtc_h > INT_MAX ||
2353 plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) {
2354 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
2355 plane_req->crtc_w, plane_req->crtc_h,
2356 plane_req->crtc_x, plane_req->crtc_y);
2361 * First, find the plane, crtc, and fb objects. If not available,
2362 * we don't bother to call the driver.
2364 obj = drm_mode_object_find(dev, plane_req->plane_id,
2365 DRM_MODE_OBJECT_PLANE);
2367 DRM_DEBUG_KMS("Unknown plane ID %d\n",
2368 plane_req->plane_id);
2371 plane = obj_to_plane(obj);
2373 if (plane_req->fb_id) {
2374 fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
2376 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
2381 obj = drm_mode_object_find(dev, plane_req->crtc_id,
2382 DRM_MODE_OBJECT_CRTC);
2384 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
2385 plane_req->crtc_id);
2388 crtc = obj_to_crtc(obj);
2392 * setplane_internal will take care of deref'ing either the old or new
2393 * framebuffer depending on success.
2395 return setplane_internal(plane, crtc, fb,
2396 plane_req->crtc_x, plane_req->crtc_y,
2397 plane_req->crtc_w, plane_req->crtc_h,
2398 plane_req->src_x, plane_req->src_y,
2399 plane_req->src_w, plane_req->src_h);
2403 * drm_mode_set_config_internal - helper to call ->set_config
2404 * @set: modeset config to set
2406 * This is a little helper to wrap internal calls to the ->set_config driver
2407 * interface. The only thing it adds is correct refcounting dance.
2410 * Zero on success, errno on failure.
2412 int drm_mode_set_config_internal(struct drm_mode_set *set)
2414 struct drm_crtc *crtc = set->crtc;
2415 struct drm_framebuffer *fb;
2416 struct drm_crtc *tmp;
2420 * NOTE: ->set_config can also disable other crtcs (if we steal all
2421 * connectors from it), hence we need to refcount the fbs across all
2422 * crtcs. Atomic modeset will have saner semantics ...
2424 list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head)
2425 tmp->old_fb = tmp->primary->fb;
2429 ret = crtc->funcs->set_config(set);
2431 crtc->primary->crtc = crtc;
2432 crtc->primary->fb = fb;
2435 list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) {
2436 if (tmp->primary->fb)
2437 drm_framebuffer_reference(tmp->primary->fb);
2439 drm_framebuffer_unreference(tmp->old_fb);
2444 EXPORT_SYMBOL(drm_mode_set_config_internal);
2447 * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
2449 * @crtc: CRTC that framebuffer will be displayed on
2452 * @mode: mode that framebuffer will be displayed under
2453 * @fb: framebuffer to check size of
2455 int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2457 const struct drm_display_mode *mode,
2458 const struct drm_framebuffer *fb)
2461 int hdisplay, vdisplay;
2463 hdisplay = mode->hdisplay;
2464 vdisplay = mode->vdisplay;
2466 if (drm_mode_is_stereo(mode)) {
2467 struct drm_display_mode adjusted = *mode;
2469 drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE);
2470 hdisplay = adjusted.crtc_hdisplay;
2471 vdisplay = adjusted.crtc_vdisplay;
2474 if (crtc->invert_dimensions)
2475 swap(hdisplay, vdisplay);
2477 if (hdisplay > fb->width ||
2478 vdisplay > fb->height ||
2479 x > fb->width - hdisplay ||
2480 y > fb->height - vdisplay) {
2481 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2482 fb->width, fb->height, hdisplay, vdisplay, x, y,
2483 crtc->invert_dimensions ? " (inverted)" : "");
2489 EXPORT_SYMBOL(drm_crtc_check_viewport);
2492 * drm_mode_setcrtc - set CRTC configuration
2493 * @dev: drm device for the ioctl
2494 * @data: data pointer for the ioctl
2495 * @file_priv: drm file for the ioctl call
2497 * Build a new CRTC configuration based on user request.
2499 * Called by the user via ioctl.
2502 * Zero on success, errno on failure.
2504 int drm_mode_setcrtc(struct drm_device *dev, void *data,
2505 struct drm_file *file_priv)
2507 struct drm_mode_config *config = &dev->mode_config;
2508 struct drm_mode_crtc *crtc_req = data;
2509 struct drm_crtc *crtc;
2510 struct drm_connector **connector_set = NULL, *connector;
2511 struct drm_framebuffer *fb = NULL;
2512 struct drm_display_mode *mode = NULL;
2513 struct drm_mode_set set;
2514 uint32_t __user *set_connectors_ptr;
2518 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2521 /* For some reason crtc x/y offsets are signed internally. */
2522 if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX)
2525 drm_modeset_lock_all(dev);
2526 crtc = drm_crtc_find(dev, crtc_req->crtc_id);
2528 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
2532 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
2534 if (crtc_req->mode_valid) {
2535 /* If we have a mode we need a framebuffer. */
2536 /* If we pass -1, set the mode with the currently bound fb */
2537 if (crtc_req->fb_id == -1) {
2538 if (!crtc->primary->fb) {
2539 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2543 fb = crtc->primary->fb;
2544 /* Make refcounting symmetric with the lookup path. */
2545 drm_framebuffer_reference(fb);
2547 fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
2549 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2556 mode = drm_mode_create(dev);
2562 ret = drm_crtc_convert_umode(mode, &crtc_req->mode);
2564 DRM_DEBUG_KMS("Invalid mode\n");
2568 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
2570 ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y,
2577 if (crtc_req->count_connectors == 0 && mode) {
2578 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2583 if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
2584 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2585 crtc_req->count_connectors);
2590 if (crtc_req->count_connectors > 0) {
2593 /* Avoid unbounded kernel memory allocation */
2594 if (crtc_req->count_connectors > config->num_connector) {
2599 connector_set = kmalloc(crtc_req->count_connectors *
2600 sizeof(struct drm_connector *),
2602 if (!connector_set) {
2607 for (i = 0; i < crtc_req->count_connectors; i++) {
2608 set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
2609 if (get_user(out_id, &set_connectors_ptr[i])) {
2614 connector = drm_connector_find(dev, out_id);
2616 DRM_DEBUG_KMS("Connector id %d unknown\n",
2621 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2625 connector_set[i] = connector;
2630 set.x = crtc_req->x;
2631 set.y = crtc_req->y;
2633 set.connectors = connector_set;
2634 set.num_connectors = crtc_req->count_connectors;
2636 ret = drm_mode_set_config_internal(&set);
2640 drm_framebuffer_unreference(fb);
2642 kfree(connector_set);
2643 drm_mode_destroy(dev, mode);
2644 drm_modeset_unlock_all(dev);
2649 * drm_mode_cursor_universal - translate legacy cursor ioctl call into a
2650 * universal plane handler call
2651 * @crtc: crtc to update cursor for
2652 * @req: data pointer for the ioctl
2653 * @file_priv: drm file for the ioctl call
2655 * Legacy cursor ioctl's work directly with driver buffer handles. To
2656 * translate legacy ioctl calls into universal plane handler calls, we need to
2657 * wrap the native buffer handle in a drm_framebuffer.
2659 * Note that we assume any handle passed to the legacy ioctls was a 32-bit ARGB
2660 * buffer with a pitch of 4*width; the universal plane interface should be used
2661 * directly in cases where the hardware can support other buffer settings and
2662 * userspace wants to make use of these capabilities.
2665 * Zero on success, errno on failure.
2667 static int drm_mode_cursor_universal(struct drm_crtc *crtc,
2668 struct drm_mode_cursor2 *req,
2669 struct drm_file *file_priv)
2671 struct drm_device *dev = crtc->dev;
2672 struct drm_framebuffer *fb = NULL;
2673 struct drm_mode_fb_cmd2 fbreq = {
2674 .width = req->width,
2675 .height = req->height,
2676 .pixel_format = DRM_FORMAT_ARGB8888,
2677 .pitches = { req->width * 4 },
2678 .handles = { req->handle },
2680 int32_t crtc_x, crtc_y;
2681 uint32_t crtc_w = 0, crtc_h = 0;
2682 uint32_t src_w = 0, src_h = 0;
2685 BUG_ON(!crtc->cursor);
2688 * Obtain fb we'll be using (either new or existing) and take an extra
2689 * reference to it if fb != null. setplane will take care of dropping
2690 * the reference if the plane update fails.
2692 if (req->flags & DRM_MODE_CURSOR_BO) {
2694 fb = add_framebuffer_internal(dev, &fbreq, file_priv);
2696 DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n");
2700 drm_framebuffer_reference(fb);
2705 mutex_lock(&dev->mode_config.mutex);
2706 fb = crtc->cursor->fb;
2708 drm_framebuffer_reference(fb);
2709 mutex_unlock(&dev->mode_config.mutex);
2712 if (req->flags & DRM_MODE_CURSOR_MOVE) {
2716 crtc_x = crtc->cursor_x;
2717 crtc_y = crtc->cursor_y;
2722 crtc_h = fb->height;
2723 src_w = fb->width << 16;
2724 src_h = fb->height << 16;
2728 * setplane_internal will take care of deref'ing either the old or new
2729 * framebuffer depending on success.
2731 ret = setplane_internal(crtc->cursor, crtc, fb,
2732 crtc_x, crtc_y, crtc_w, crtc_h,
2733 0, 0, src_w, src_h);
2735 /* Update successful; save new cursor position, if necessary */
2736 if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) {
2737 crtc->cursor_x = req->x;
2738 crtc->cursor_y = req->y;
2744 static int drm_mode_cursor_common(struct drm_device *dev,
2745 struct drm_mode_cursor2 *req,
2746 struct drm_file *file_priv)
2748 struct drm_crtc *crtc;
2751 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2754 if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
2757 crtc = drm_crtc_find(dev, req->crtc_id);
2759 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
2764 * If this crtc has a universal cursor plane, call that plane's update
2765 * handler rather than using legacy cursor handlers.
2768 return drm_mode_cursor_universal(crtc, req, file_priv);
2770 drm_modeset_lock(&crtc->mutex, NULL);
2771 if (req->flags & DRM_MODE_CURSOR_BO) {
2772 if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
2776 /* Turns off the cursor if handle is 0 */
2777 if (crtc->funcs->cursor_set2)
2778 ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle,
2779 req->width, req->height, req->hot_x, req->hot_y);
2781 ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
2782 req->width, req->height);
2785 if (req->flags & DRM_MODE_CURSOR_MOVE) {
2786 if (crtc->funcs->cursor_move) {
2787 ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
2794 drm_modeset_unlock(&crtc->mutex);
2802 * drm_mode_cursor_ioctl - set CRTC's cursor configuration
2803 * @dev: drm device for the ioctl
2804 * @data: data pointer for the ioctl
2805 * @file_priv: drm file for the ioctl call
2807 * Set the cursor configuration based on user request.
2809 * Called by the user via ioctl.
2812 * Zero on success, errno on failure.
2814 int drm_mode_cursor_ioctl(struct drm_device *dev,
2815 void *data, struct drm_file *file_priv)
2817 struct drm_mode_cursor *req = data;
2818 struct drm_mode_cursor2 new_req;
2820 memcpy(&new_req, req, sizeof(struct drm_mode_cursor));
2821 new_req.hot_x = new_req.hot_y = 0;
2823 return drm_mode_cursor_common(dev, &new_req, file_priv);
2827 * drm_mode_cursor2_ioctl - set CRTC's cursor configuration
2828 * @dev: drm device for the ioctl
2829 * @data: data pointer for the ioctl
2830 * @file_priv: drm file for the ioctl call
2832 * Set the cursor configuration based on user request. This implements the 2nd
2833 * version of the cursor ioctl, which allows userspace to additionally specify
2834 * the hotspot of the pointer.
2836 * Called by the user via ioctl.
2839 * Zero on success, errno on failure.
2841 int drm_mode_cursor2_ioctl(struct drm_device *dev,
2842 void *data, struct drm_file *file_priv)
2844 struct drm_mode_cursor2 *req = data;
2845 return drm_mode_cursor_common(dev, req, file_priv);
2849 * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description
2850 * @bpp: bits per pixels
2851 * @depth: bit depth per pixel
2853 * Computes a drm fourcc pixel format code for the given @bpp/@depth values.
2854 * Useful in fbdev emulation code, since that deals in those values.
2856 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
2862 fmt = DRM_FORMAT_C8;
2866 fmt = DRM_FORMAT_XRGB1555;
2868 fmt = DRM_FORMAT_RGB565;
2871 fmt = DRM_FORMAT_RGB888;
2875 fmt = DRM_FORMAT_XRGB8888;
2876 else if (depth == 30)
2877 fmt = DRM_FORMAT_XRGB2101010;
2879 fmt = DRM_FORMAT_ARGB8888;
2882 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2883 fmt = DRM_FORMAT_XRGB8888;
2889 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
2892 * drm_mode_addfb - add an FB to the graphics configuration
2893 * @dev: drm device for the ioctl
2894 * @data: data pointer for the ioctl
2895 * @file_priv: drm file for the ioctl call
2897 * Add a new FB to the specified CRTC, given a user request. This is the
2898 * original addfb ioclt which only supported RGB formats.
2900 * Called by the user via ioctl.
2903 * Zero on success, errno on failure.
2905 int drm_mode_addfb(struct drm_device *dev,
2906 void *data, struct drm_file *file_priv)
2908 struct drm_mode_fb_cmd *or = data;
2909 struct drm_mode_fb_cmd2 r = {};
2910 struct drm_mode_config *config = &dev->mode_config;
2911 struct drm_framebuffer *fb;
2914 /* Use new struct with format internally */
2915 r.fb_id = or->fb_id;
2916 r.width = or->width;
2917 r.height = or->height;
2918 r.pitches[0] = or->pitch;
2919 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
2920 r.handles[0] = or->handle;
2922 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2925 if ((config->min_width > r.width) || (r.width > config->max_width))
2928 if ((config->min_height > r.height) || (r.height > config->max_height))
2931 fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r);
2933 DRM_DEBUG_KMS("could not create framebuffer\n");
2937 mutex_lock(&file_priv->fbs_lock);
2938 or->fb_id = fb->base.id;
2939 list_add(&fb->filp_head, &file_priv->fbs);
2940 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
2941 mutex_unlock(&file_priv->fbs_lock);
2946 static int format_check(const struct drm_mode_fb_cmd2 *r)
2948 uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
2952 case DRM_FORMAT_RGB332:
2953 case DRM_FORMAT_BGR233:
2954 case DRM_FORMAT_XRGB4444:
2955 case DRM_FORMAT_XBGR4444:
2956 case DRM_FORMAT_RGBX4444:
2957 case DRM_FORMAT_BGRX4444:
2958 case DRM_FORMAT_ARGB4444:
2959 case DRM_FORMAT_ABGR4444:
2960 case DRM_FORMAT_RGBA4444:
2961 case DRM_FORMAT_BGRA4444:
2962 case DRM_FORMAT_XRGB1555:
2963 case DRM_FORMAT_XBGR1555:
2964 case DRM_FORMAT_RGBX5551:
2965 case DRM_FORMAT_BGRX5551:
2966 case DRM_FORMAT_ARGB1555:
2967 case DRM_FORMAT_ABGR1555:
2968 case DRM_FORMAT_RGBA5551:
2969 case DRM_FORMAT_BGRA5551:
2970 case DRM_FORMAT_RGB565:
2971 case DRM_FORMAT_BGR565:
2972 case DRM_FORMAT_RGB888:
2973 case DRM_FORMAT_BGR888:
2974 case DRM_FORMAT_XRGB8888:
2975 case DRM_FORMAT_XBGR8888:
2976 case DRM_FORMAT_RGBX8888:
2977 case DRM_FORMAT_BGRX8888:
2978 case DRM_FORMAT_ARGB8888:
2979 case DRM_FORMAT_ABGR8888:
2980 case DRM_FORMAT_RGBA8888:
2981 case DRM_FORMAT_BGRA8888:
2982 case DRM_FORMAT_XRGB2101010:
2983 case DRM_FORMAT_XBGR2101010:
2984 case DRM_FORMAT_RGBX1010102:
2985 case DRM_FORMAT_BGRX1010102:
2986 case DRM_FORMAT_ARGB2101010:
2987 case DRM_FORMAT_ABGR2101010:
2988 case DRM_FORMAT_RGBA1010102:
2989 case DRM_FORMAT_BGRA1010102:
2990 case DRM_FORMAT_YUYV:
2991 case DRM_FORMAT_YVYU:
2992 case DRM_FORMAT_UYVY:
2993 case DRM_FORMAT_VYUY:
2994 case DRM_FORMAT_AYUV:
2995 case DRM_FORMAT_NV12:
2996 case DRM_FORMAT_NV21:
2997 case DRM_FORMAT_NV16:
2998 case DRM_FORMAT_NV61:
2999 case DRM_FORMAT_NV24:
3000 case DRM_FORMAT_NV42:
3001 case DRM_FORMAT_YUV410:
3002 case DRM_FORMAT_YVU410:
3003 case DRM_FORMAT_YUV411:
3004 case DRM_FORMAT_YVU411:
3005 case DRM_FORMAT_YUV420:
3006 case DRM_FORMAT_YVU420:
3007 case DRM_FORMAT_YUV422:
3008 case DRM_FORMAT_YVU422:
3009 case DRM_FORMAT_YUV444:
3010 case DRM_FORMAT_YVU444:
3013 DRM_DEBUG_KMS("invalid pixel format %s\n",
3014 drm_get_format_name(r->pixel_format));
3019 static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
3021 int ret, hsub, vsub, num_planes, i;
3023 ret = format_check(r);
3025 DRM_DEBUG_KMS("bad framebuffer format %s\n",
3026 drm_get_format_name(r->pixel_format));
3030 hsub = drm_format_horz_chroma_subsampling(r->pixel_format);
3031 vsub = drm_format_vert_chroma_subsampling(r->pixel_format);
3032 num_planes = drm_format_num_planes(r->pixel_format);
3034 if (r->width == 0 || r->width % hsub) {
3035 DRM_DEBUG_KMS("bad framebuffer width %u\n", r->height);
3039 if (r->height == 0 || r->height % vsub) {
3040 DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
3044 for (i = 0; i < num_planes; i++) {
3045 unsigned int width = r->width / (i != 0 ? hsub : 1);
3046 unsigned int height = r->height / (i != 0 ? vsub : 1);
3047 unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
3049 if (!r->handles[i]) {
3050 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
3054 if ((uint64_t) width * cpp > UINT_MAX)
3057 if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
3060 if (r->pitches[i] < width * cpp) {
3061 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
3069 static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev,
3070 struct drm_mode_fb_cmd2 *r,
3071 struct drm_file *file_priv)
3073 struct drm_mode_config *config = &dev->mode_config;
3074 struct drm_framebuffer *fb;
3077 if (r->flags & ~DRM_MODE_FB_INTERLACED) {
3078 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
3079 return ERR_PTR(-EINVAL);
3082 if ((config->min_width > r->width) || (r->width > config->max_width)) {
3083 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
3084 r->width, config->min_width, config->max_width);
3085 return ERR_PTR(-EINVAL);
3087 if ((config->min_height > r->height) || (r->height > config->max_height)) {
3088 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
3089 r->height, config->min_height, config->max_height);
3090 return ERR_PTR(-EINVAL);
3093 ret = framebuffer_check(r);
3095 return ERR_PTR(ret);
3097 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
3099 DRM_DEBUG_KMS("could not create framebuffer\n");
3103 mutex_lock(&file_priv->fbs_lock);
3104 r->fb_id = fb->base.id;
3105 list_add(&fb->filp_head, &file_priv->fbs);
3106 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
3107 mutex_unlock(&file_priv->fbs_lock);
3113 * drm_mode_addfb2 - add an FB to the graphics configuration
3114 * @dev: drm device for the ioctl
3115 * @data: data pointer for the ioctl
3116 * @file_priv: drm file for the ioctl call
3118 * Add a new FB to the specified CRTC, given a user request with format. This is
3119 * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
3120 * and uses fourcc codes as pixel format specifiers.
3122 * Called by the user via ioctl.
3125 * Zero on success, errno on failure.
3127 int drm_mode_addfb2(struct drm_device *dev,
3128 void *data, struct drm_file *file_priv)
3130 struct drm_framebuffer *fb;
3132 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3135 fb = add_framebuffer_internal(dev, data, file_priv);
3143 * drm_mode_rmfb - remove an FB from the configuration
3144 * @dev: drm device for the ioctl
3145 * @data: data pointer for the ioctl
3146 * @file_priv: drm file for the ioctl call
3148 * Remove the FB specified by the user.
3150 * Called by the user via ioctl.
3153 * Zero on success, errno on failure.
3155 int drm_mode_rmfb(struct drm_device *dev,
3156 void *data, struct drm_file *file_priv)
3158 struct drm_framebuffer *fb = NULL;
3159 struct drm_framebuffer *fbl = NULL;
3160 uint32_t *id = data;
3163 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3166 mutex_lock(&file_priv->fbs_lock);
3167 mutex_lock(&dev->mode_config.fb_lock);
3168 fb = __drm_framebuffer_lookup(dev, *id);
3172 list_for_each_entry(fbl, &file_priv->fbs, filp_head)
3178 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
3179 __drm_framebuffer_unregister(dev, fb);
3181 list_del_init(&fb->filp_head);
3182 mutex_unlock(&dev->mode_config.fb_lock);
3183 mutex_unlock(&file_priv->fbs_lock);
3185 drm_framebuffer_remove(fb);
3190 mutex_unlock(&dev->mode_config.fb_lock);
3191 mutex_unlock(&file_priv->fbs_lock);
3197 * drm_mode_getfb - get FB info
3198 * @dev: drm device for the ioctl
3199 * @data: data pointer for the ioctl
3200 * @file_priv: drm file for the ioctl call
3202 * Lookup the FB given its ID and return info about it.
3204 * Called by the user via ioctl.
3207 * Zero on success, errno on failure.
3209 int drm_mode_getfb(struct drm_device *dev,
3210 void *data, struct drm_file *file_priv)
3212 struct drm_mode_fb_cmd *r = data;
3213 struct drm_framebuffer *fb;
3216 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3219 fb = drm_framebuffer_lookup(dev, r->fb_id);
3223 r->height = fb->height;
3224 r->width = fb->width;
3225 r->depth = fb->depth;
3226 r->bpp = fb->bits_per_pixel;
3227 r->pitch = fb->pitches[0];
3228 if (fb->funcs->create_handle) {
3229 ret = fb->funcs->create_handle(fb, file_priv, &r->handle);
3234 drm_framebuffer_unreference(fb);
3240 * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB
3241 * @dev: drm device for the ioctl
3242 * @data: data pointer for the ioctl
3243 * @file_priv: drm file for the ioctl call
3245 * Lookup the FB and flush out the damaged area supplied by userspace as a clip
3246 * rectangle list. Generic userspace which does frontbuffer rendering must call
3247 * this ioctl to flush out the changes on manual-update display outputs, e.g.
3248 * usb display-link, mipi manual update panels or edp panel self refresh modes.
3250 * Modesetting drivers which always update the frontbuffer do not need to
3251 * implement the corresponding ->dirty framebuffer callback.
3253 * Called by the user via ioctl.
3256 * Zero on success, errno on failure.
3258 int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
3259 void *data, struct drm_file *file_priv)
3261 struct drm_clip_rect __user *clips_ptr;
3262 struct drm_clip_rect *clips = NULL;
3263 struct drm_mode_fb_dirty_cmd *r = data;
3264 struct drm_framebuffer *fb;
3269 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3272 fb = drm_framebuffer_lookup(dev, r->fb_id);
3276 num_clips = r->num_clips;
3277 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
3279 if (!num_clips != !clips_ptr) {
3284 flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
3286 /* If userspace annotates copy, clips must come in pairs */
3287 if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
3292 if (num_clips && clips_ptr) {
3293 if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
3297 clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
3303 ret = copy_from_user(clips, clips_ptr,
3304 num_clips * sizeof(*clips));
3311 if (fb->funcs->dirty) {
3312 ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
3321 drm_framebuffer_unreference(fb);
3328 * drm_fb_release - remove and free the FBs on this file
3329 * @priv: drm file for the ioctl
3331 * Destroy all the FBs associated with @filp.
3333 * Called by the user via ioctl.
3336 * Zero on success, errno on failure.
3338 void drm_fb_release(struct drm_file *priv)
3340 struct drm_device *dev = priv->dev;
3341 struct drm_framebuffer *fb, *tfb;
3343 mutex_lock(&priv->fbs_lock);
3344 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
3346 mutex_lock(&dev->mode_config.fb_lock);
3347 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
3348 __drm_framebuffer_unregister(dev, fb);
3349 mutex_unlock(&dev->mode_config.fb_lock);
3351 list_del_init(&fb->filp_head);
3353 /* This will also drop the fpriv->fbs reference. */
3354 drm_framebuffer_remove(fb);
3356 mutex_unlock(&priv->fbs_lock);
3360 * drm_property_create - create a new property type
3362 * @flags: flags specifying the property type
3363 * @name: name of the property
3364 * @num_values: number of pre-defined values
3366 * This creates a new generic drm property which can then be attached to a drm
3367 * object with drm_object_attach_property. The returned property object must be
3368 * freed with drm_property_destroy.
3371 * A pointer to the newly created property on success, NULL on failure.
3373 struct drm_property *drm_property_create(struct drm_device *dev, int flags,
3374 const char *name, int num_values)
3376 struct drm_property *property = NULL;
3379 property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
3383 property->dev = dev;
3386 property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
3387 if (!property->values)
3391 ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
3395 property->flags = flags;
3396 property->num_values = num_values;
3397 INIT_LIST_HEAD(&property->enum_blob_list);
3400 strncpy(property->name, name, DRM_PROP_NAME_LEN);
3401 property->name[DRM_PROP_NAME_LEN-1] = '\0';
3404 list_add_tail(&property->head, &dev->mode_config.property_list);
3406 WARN_ON(!drm_property_type_valid(property));
3410 kfree(property->values);
3414 EXPORT_SYMBOL(drm_property_create);
3417 * drm_property_create_enum - create a new enumeration property type
3419 * @flags: flags specifying the property type
3420 * @name: name of the property
3421 * @props: enumeration lists with property values
3422 * @num_values: number of pre-defined values
3424 * This creates a new generic drm property which can then be attached to a drm
3425 * object with drm_object_attach_property. The returned property object must be
3426 * freed with drm_property_destroy.
3428 * Userspace is only allowed to set one of the predefined values for enumeration
3432 * A pointer to the newly created property on success, NULL on failure.
3434 struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
3436 const struct drm_prop_enum_list *props,
3439 struct drm_property *property;
3442 flags |= DRM_MODE_PROP_ENUM;
3444 property = drm_property_create(dev, flags, name, num_values);
3448 for (i = 0; i < num_values; i++) {
3449 ret = drm_property_add_enum(property, i,
3453 drm_property_destroy(dev, property);
3460 EXPORT_SYMBOL(drm_property_create_enum);
3463 * drm_property_create_bitmask - create a new bitmask property type
3465 * @flags: flags specifying the property type
3466 * @name: name of the property
3467 * @props: enumeration lists with property bitflags
3468 * @num_values: number of pre-defined values
3470 * This creates a new generic drm property which can then be attached to a drm
3471 * object with drm_object_attach_property. The returned property object must be
3472 * freed with drm_property_destroy.
3474 * Compared to plain enumeration properties userspace is allowed to set any
3475 * or'ed together combination of the predefined property bitflag values
3478 * A pointer to the newly created property on success, NULL on failure.
3480 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
3481 int flags, const char *name,
3482 const struct drm_prop_enum_list *props,
3485 struct drm_property *property;
3488 flags |= DRM_MODE_PROP_BITMASK;
3490 property = drm_property_create(dev, flags, name, num_values);
3494 for (i = 0; i < num_values; i++) {
3495 ret = drm_property_add_enum(property, i,
3499 drm_property_destroy(dev, property);
3506 EXPORT_SYMBOL(drm_property_create_bitmask);
3508 static struct drm_property *property_create_range(struct drm_device *dev,
3509 int flags, const char *name,
3510 uint64_t min, uint64_t max)
3512 struct drm_property *property;
3514 property = drm_property_create(dev, flags, name, 2);
3518 property->values[0] = min;
3519 property->values[1] = max;
3525 * drm_property_create_range - create a new ranged property type
3527 * @flags: flags specifying the property type
3528 * @name: name of the property
3529 * @min: minimum value of the property
3530 * @max: maximum value of the property
3532 * This creates a new generic drm property which can then be attached to a drm
3533 * object with drm_object_attach_property. The returned property object must be
3534 * freed with drm_property_destroy.
3536 * Userspace is allowed to set any interger value in the (min, max) range
3540 * A pointer to the newly created property on success, NULL on failure.
3542 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
3544 uint64_t min, uint64_t max)
3546 return property_create_range(dev, DRM_MODE_PROP_RANGE | flags,
3549 EXPORT_SYMBOL(drm_property_create_range);
3551 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
3552 int flags, const char *name,
3553 int64_t min, int64_t max)
3555 return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags,
3556 name, I642U64(min), I642U64(max));
3558 EXPORT_SYMBOL(drm_property_create_signed_range);
3560 struct drm_property *drm_property_create_object(struct drm_device *dev,
3561 int flags, const char *name, uint32_t type)
3563 struct drm_property *property;
3565 flags |= DRM_MODE_PROP_OBJECT;
3567 property = drm_property_create(dev, flags, name, 1);
3571 property->values[0] = type;
3575 EXPORT_SYMBOL(drm_property_create_object);
3578 * drm_property_add_enum - add a possible value to an enumeration property
3579 * @property: enumeration property to change
3580 * @index: index of the new enumeration
3581 * @value: value of the new enumeration
3582 * @name: symbolic name of the new enumeration
3584 * This functions adds enumerations to a property.
3586 * It's use is deprecated, drivers should use one of the more specific helpers
3587 * to directly create the property with all enumerations already attached.
3590 * Zero on success, error code on failure.
3592 int drm_property_add_enum(struct drm_property *property, int index,
3593 uint64_t value, const char *name)
3595 struct drm_property_enum *prop_enum;
3597 if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
3598 drm_property_type_is(property, DRM_MODE_PROP_BITMASK)))
3602 * Bitmask enum properties have the additional constraint of values
3605 if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) &&
3609 if (!list_empty(&property->enum_blob_list)) {
3610 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
3611 if (prop_enum->value == value) {
3612 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
3613 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
3619 prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
3623 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
3624 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
3625 prop_enum->value = value;
3627 property->values[index] = value;
3628 list_add_tail(&prop_enum->head, &property->enum_blob_list);
3631 EXPORT_SYMBOL(drm_property_add_enum);
3634 * drm_property_destroy - destroy a drm property
3636 * @property: property to destry
3638 * This function frees a property including any attached resources like
3639 * enumeration values.
3641 void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
3643 struct drm_property_enum *prop_enum, *pt;
3645 list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) {
3646 list_del(&prop_enum->head);
3650 if (property->num_values)
3651 kfree(property->values);
3652 drm_mode_object_put(dev, &property->base);
3653 list_del(&property->head);
3656 EXPORT_SYMBOL(drm_property_destroy);
3659 * drm_object_attach_property - attach a property to a modeset object
3660 * @obj: drm modeset object
3661 * @property: property to attach
3662 * @init_val: initial value of the property
3664 * This attaches the given property to the modeset object with the given initial
3665 * value. Currently this function cannot fail since the properties are stored in
3666 * a statically sized array.
3668 void drm_object_attach_property(struct drm_mode_object *obj,
3669 struct drm_property *property,
3672 int count = obj->properties->count;
3674 if (count == DRM_OBJECT_MAX_PROPERTY) {
3675 WARN(1, "Failed to attach object property (type: 0x%x). Please "
3676 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
3677 "you see this message on the same object type.\n",
3682 obj->properties->ids[count] = property->base.id;
3683 obj->properties->values[count] = init_val;
3684 obj->properties->count++;
3686 EXPORT_SYMBOL(drm_object_attach_property);
3689 * drm_object_property_set_value - set the value of a property
3690 * @obj: drm mode object to set property value for
3691 * @property: property to set
3692 * @val: value the property should be set to
3694 * This functions sets a given property on a given object. This function only
3695 * changes the software state of the property, it does not call into the
3696 * driver's ->set_property callback.
3699 * Zero on success, error code on failure.
3701 int drm_object_property_set_value(struct drm_mode_object *obj,
3702 struct drm_property *property, uint64_t val)
3706 for (i = 0; i < obj->properties->count; i++) {
3707 if (obj->properties->ids[i] == property->base.id) {
3708 obj->properties->values[i] = val;
3715 EXPORT_SYMBOL(drm_object_property_set_value);
3718 * drm_object_property_get_value - retrieve the value of a property
3719 * @obj: drm mode object to get property value from
3720 * @property: property to retrieve
3721 * @val: storage for the property value
3723 * This function retrieves the softare state of the given property for the given
3724 * property. Since there is no driver callback to retrieve the current property
3725 * value this might be out of sync with the hardware, depending upon the driver
3729 * Zero on success, error code on failure.
3731 int drm_object_property_get_value(struct drm_mode_object *obj,
3732 struct drm_property *property, uint64_t *val)
3736 for (i = 0; i < obj->properties->count; i++) {
3737 if (obj->properties->ids[i] == property->base.id) {
3738 *val = obj->properties->values[i];
3745 EXPORT_SYMBOL(drm_object_property_get_value);
3748 * drm_mode_getproperty_ioctl - get the current value of a connector's property
3751 * @file_priv: DRM file info
3753 * This function retrieves the current value for an connectors's property.
3755 * Called by the user via ioctl.
3758 * Zero on success, errno on failure.
3760 int drm_mode_getproperty_ioctl(struct drm_device *dev,
3761 void *data, struct drm_file *file_priv)
3763 struct drm_mode_get_property *out_resp = data;
3764 struct drm_property *property;
3767 int value_count = 0;
3770 struct drm_property_enum *prop_enum;
3771 struct drm_mode_property_enum __user *enum_ptr;
3772 struct drm_property_blob *prop_blob;
3773 uint32_t __user *blob_id_ptr;
3774 uint64_t __user *values_ptr;
3775 uint32_t __user *blob_length_ptr;
3777 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3780 drm_modeset_lock_all(dev);
3781 property = drm_property_find(dev, out_resp->prop_id);
3787 if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
3788 drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
3789 list_for_each_entry(prop_enum, &property->enum_blob_list, head)
3791 } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) {
3792 list_for_each_entry(prop_blob, &property->enum_blob_list, head)
3796 value_count = property->num_values;
3798 strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
3799 out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
3800 out_resp->flags = property->flags;
3802 if ((out_resp->count_values >= value_count) && value_count) {
3803 values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
3804 for (i = 0; i < value_count; i++) {
3805 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
3811 out_resp->count_values = value_count;
3813 if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
3814 drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
3815 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
3817 enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
3818 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
3820 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
3825 if (copy_to_user(&enum_ptr[copied].name,
3826 &prop_enum->name, DRM_PROP_NAME_LEN)) {
3833 out_resp->count_enum_blobs = enum_count;
3836 if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) {
3837 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
3839 blob_id_ptr = (uint32_t __user *)(unsigned long)out_resp->enum_blob_ptr;
3840 blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
3842 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
3843 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
3848 if (put_user(prop_blob->length, blob_length_ptr + copied)) {
3856 out_resp->count_enum_blobs = blob_count;
3859 drm_modeset_unlock_all(dev);
3863 static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
3866 struct drm_property_blob *blob;
3869 if (!length || !data)
3872 blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
3876 ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
3882 blob->length = length;
3884 memcpy(blob->data, data, length);
3886 list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
3890 static void drm_property_destroy_blob(struct drm_device *dev,
3891 struct drm_property_blob *blob)
3893 drm_mode_object_put(dev, &blob->base);
3894 list_del(&blob->head);
3899 * drm_mode_getblob_ioctl - get the contents of a blob property value
3902 * @file_priv: DRM file info
3904 * This function retrieves the contents of a blob property. The value stored in
3905 * an object's blob property is just a normal modeset object id.
3907 * Called by the user via ioctl.
3910 * Zero on success, errno on failure.
3912 int drm_mode_getblob_ioctl(struct drm_device *dev,
3913 void *data, struct drm_file *file_priv)
3915 struct drm_mode_get_blob *out_resp = data;
3916 struct drm_property_blob *blob;
3918 void __user *blob_ptr;
3920 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3923 drm_modeset_lock_all(dev);
3924 blob = drm_property_blob_find(dev, out_resp->blob_id);
3930 if (out_resp->length == blob->length) {
3931 blob_ptr = (void __user *)(unsigned long)out_resp->data;
3932 if (copy_to_user(blob_ptr, blob->data, blob->length)){
3937 out_resp->length = blob->length;
3940 drm_modeset_unlock_all(dev);
3944 int drm_mode_connector_set_path_property(struct drm_connector *connector,
3947 struct drm_device *dev = connector->dev;
3949 size = strlen(path) + 1;
3951 connector->path_blob_ptr = drm_property_create_blob(connector->dev,
3953 if (!connector->path_blob_ptr)
3956 ret = drm_object_property_set_value(&connector->base,
3957 dev->mode_config.path_property,
3958 connector->path_blob_ptr->base.id);
3961 EXPORT_SYMBOL(drm_mode_connector_set_path_property);
3964 * drm_mode_connector_update_edid_property - update the edid property of a connector
3965 * @connector: drm connector
3966 * @edid: new value of the edid property
3968 * This function creates a new blob modeset object and assigns its id to the
3969 * connector's edid property.
3972 * Zero on success, errno on failure.
3974 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
3977 struct drm_device *dev = connector->dev;
3980 /* ignore requests to set edid when overridden */
3981 if (connector->override_edid)
3984 if (connector->edid_blob_ptr)
3985 drm_property_destroy_blob(dev, connector->edid_blob_ptr);
3987 /* Delete edid, when there is none. */
3989 connector->edid_blob_ptr = NULL;
3990 ret = drm_object_property_set_value(&connector->base, dev->mode_config.edid_property, 0);
3994 size = EDID_LENGTH * (1 + edid->extensions);
3995 connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
3997 if (!connector->edid_blob_ptr)
4000 ret = drm_object_property_set_value(&connector->base,
4001 dev->mode_config.edid_property,
4002 connector->edid_blob_ptr->base.id);
4006 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
4008 static bool drm_property_change_is_valid(struct drm_property *property,
4011 if (property->flags & DRM_MODE_PROP_IMMUTABLE)
4014 if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) {
4015 if (value < property->values[0] || value > property->values[1])
4018 } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) {
4019 int64_t svalue = U642I64(value);
4020 if (svalue < U642I64(property->values[0]) ||
4021 svalue > U642I64(property->values[1]))
4024 } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
4026 uint64_t valid_mask = 0;
4027 for (i = 0; i < property->num_values; i++)
4028 valid_mask |= (1ULL << property->values[i]);
4029 return !(value & ~valid_mask);
4030 } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) {
4031 /* Only the driver knows */
4033 } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
4034 struct drm_mode_object *obj;
4035 /* a zero value for an object property translates to null: */
4039 * NOTE: use _object_find() directly to bypass restriction on
4040 * looking up refcnt'd objects (ie. fb's). For a refcnt'd
4041 * object this could race against object finalization, so it
4042 * simply tells us that the object *was* valid. Which is good
4045 obj = _object_find(property->dev, value, property->values[0]);
4049 for (i = 0; i < property->num_values; i++)
4050 if (property->values[i] == value)
4057 * drm_mode_connector_property_set_ioctl - set the current value of a connector property
4060 * @file_priv: DRM file info
4062 * This function sets the current value for a connectors's property. It also
4063 * calls into a driver's ->set_property callback to update the hardware state
4065 * Called by the user via ioctl.
4068 * Zero on success, errno on failure.
4070 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
4071 void *data, struct drm_file *file_priv)
4073 struct drm_mode_connector_set_property *conn_set_prop = data;
4074 struct drm_mode_obj_set_property obj_set_prop = {
4075 .value = conn_set_prop->value,
4076 .prop_id = conn_set_prop->prop_id,
4077 .obj_id = conn_set_prop->connector_id,
4078 .obj_type = DRM_MODE_OBJECT_CONNECTOR
4081 /* It does all the locking and checking we need */
4082 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
4085 static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
4086 struct drm_property *property,
4090 struct drm_connector *connector = obj_to_connector(obj);
4092 /* Do DPMS ourselves */
4093 if (property == connector->dev->mode_config.dpms_property) {
4094 if (connector->funcs->dpms)
4095 (*connector->funcs->dpms)(connector, (int)value);
4097 } else if (connector->funcs->set_property)
4098 ret = connector->funcs->set_property(connector, property, value);
4100 /* store the property value if successful */
4102 drm_object_property_set_value(&connector->base, property, value);
4106 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
4107 struct drm_property *property,
4111 struct drm_crtc *crtc = obj_to_crtc(obj);
4113 if (crtc->funcs->set_property)
4114 ret = crtc->funcs->set_property(crtc, property, value);
4116 drm_object_property_set_value(obj, property, value);
4121 static int drm_mode_plane_set_obj_prop(struct drm_mode_object *obj,
4122 struct drm_property *property,
4126 struct drm_plane *plane = obj_to_plane(obj);
4128 if (plane->funcs->set_property)
4129 ret = plane->funcs->set_property(plane, property, value);
4131 drm_object_property_set_value(obj, property, value);
4137 * drm_mode_getproperty_ioctl - get the current value of a object's property
4140 * @file_priv: DRM file info
4142 * This function retrieves the current value for an object's property. Compared
4143 * to the connector specific ioctl this one is extended to also work on crtc and
4146 * Called by the user via ioctl.
4149 * Zero on success, errno on failure.
4151 int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
4152 struct drm_file *file_priv)
4154 struct drm_mode_obj_get_properties *arg = data;
4155 struct drm_mode_object *obj;
4159 int props_count = 0;
4160 uint32_t __user *props_ptr;
4161 uint64_t __user *prop_values_ptr;
4163 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4166 drm_modeset_lock_all(dev);
4168 obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type);
4173 if (!obj->properties) {
4178 props_count = obj->properties->count;
4180 /* This ioctl is called twice, once to determine how much space is
4181 * needed, and the 2nd time to fill it. */
4182 if ((arg->count_props >= props_count) && props_count) {
4184 props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr);
4185 prop_values_ptr = (uint64_t __user *)(unsigned long)
4186 (arg->prop_values_ptr);
4187 for (i = 0; i < props_count; i++) {
4188 if (put_user(obj->properties->ids[i],
4189 props_ptr + copied)) {
4193 if (put_user(obj->properties->values[i],
4194 prop_values_ptr + copied)) {
4201 arg->count_props = props_count;
4203 drm_modeset_unlock_all(dev);
4208 * drm_mode_obj_set_property_ioctl - set the current value of an object's property
4211 * @file_priv: DRM file info
4213 * This function sets the current value for an object's property. It also calls
4214 * into a driver's ->set_property callback to update the hardware state.
4215 * Compared to the connector specific ioctl this one is extended to also work on
4216 * crtc and plane objects.
4218 * Called by the user via ioctl.
4221 * Zero on success, errno on failure.
4223 int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
4224 struct drm_file *file_priv)
4226 struct drm_mode_obj_set_property *arg = data;
4227 struct drm_mode_object *arg_obj;
4228 struct drm_mode_object *prop_obj;
4229 struct drm_property *property;
4233 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4236 drm_modeset_lock_all(dev);
4238 arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type);
4243 if (!arg_obj->properties)
4246 for (i = 0; i < arg_obj->properties->count; i++)
4247 if (arg_obj->properties->ids[i] == arg->prop_id)
4250 if (i == arg_obj->properties->count)
4253 prop_obj = drm_mode_object_find(dev, arg->prop_id,
4254 DRM_MODE_OBJECT_PROPERTY);
4259 property = obj_to_property(prop_obj);
4261 if (!drm_property_change_is_valid(property, arg->value))
4264 switch (arg_obj->type) {
4265 case DRM_MODE_OBJECT_CONNECTOR:
4266 ret = drm_mode_connector_set_obj_prop(arg_obj, property,
4269 case DRM_MODE_OBJECT_CRTC:
4270 ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value);
4272 case DRM_MODE_OBJECT_PLANE:
4273 ret = drm_mode_plane_set_obj_prop(arg_obj, property, arg->value);
4278 drm_modeset_unlock_all(dev);
4283 * drm_mode_connector_attach_encoder - attach a connector to an encoder
4284 * @connector: connector to attach
4285 * @encoder: encoder to attach @connector to
4287 * This function links up a connector to an encoder. Note that the routing
4288 * restrictions between encoders and crtcs are exposed to userspace through the
4289 * possible_clones and possible_crtcs bitmasks.
4292 * Zero on success, errno on failure.
4294 int drm_mode_connector_attach_encoder(struct drm_connector *connector,
4295 struct drm_encoder *encoder)
4299 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
4300 if (connector->encoder_ids[i] == 0) {
4301 connector->encoder_ids[i] = encoder->base.id;
4307 EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
4310 * drm_mode_crtc_set_gamma_size - set the gamma table size
4311 * @crtc: CRTC to set the gamma table size for
4312 * @gamma_size: size of the gamma table
4314 * Drivers which support gamma tables should set this to the supported gamma
4315 * table size when initializing the CRTC. Currently the drm core only supports a
4316 * fixed gamma table size.
4319 * Zero on success, errno on failure.
4321 int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
4324 crtc->gamma_size = gamma_size;
4326 crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL);
4327 if (!crtc->gamma_store) {
4328 crtc->gamma_size = 0;
4334 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
4337 * drm_mode_gamma_set_ioctl - set the gamma table
4340 * @file_priv: DRM file info
4342 * Set the gamma table of a CRTC to the one passed in by the user. Userspace can
4343 * inquire the required gamma table size through drm_mode_gamma_get_ioctl.
4345 * Called by the user via ioctl.
4348 * Zero on success, errno on failure.
4350 int drm_mode_gamma_set_ioctl(struct drm_device *dev,
4351 void *data, struct drm_file *file_priv)
4353 struct drm_mode_crtc_lut *crtc_lut = data;
4354 struct drm_crtc *crtc;
4355 void *r_base, *g_base, *b_base;
4359 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4362 drm_modeset_lock_all(dev);
4363 crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
4369 if (crtc->funcs->gamma_set == NULL) {
4374 /* memcpy into gamma store */
4375 if (crtc_lut->gamma_size != crtc->gamma_size) {
4380 size = crtc_lut->gamma_size * (sizeof(uint16_t));
4381 r_base = crtc->gamma_store;
4382 if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
4387 g_base = (char *)r_base + size;
4388 if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
4393 b_base = (char *)g_base + size;
4394 if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
4399 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
4402 drm_modeset_unlock_all(dev);
4408 * drm_mode_gamma_get_ioctl - get the gamma table
4411 * @file_priv: DRM file info
4413 * Copy the current gamma table into the storage provided. This also provides
4414 * the gamma table size the driver expects, which can be used to size the
4415 * allocated storage.
4417 * Called by the user via ioctl.
4420 * Zero on success, errno on failure.
4422 int drm_mode_gamma_get_ioctl(struct drm_device *dev,
4423 void *data, struct drm_file *file_priv)
4425 struct drm_mode_crtc_lut *crtc_lut = data;
4426 struct drm_crtc *crtc;
4427 void *r_base, *g_base, *b_base;
4431 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4434 drm_modeset_lock_all(dev);
4435 crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
4441 /* memcpy into gamma store */
4442 if (crtc_lut->gamma_size != crtc->gamma_size) {
4447 size = crtc_lut->gamma_size * (sizeof(uint16_t));
4448 r_base = crtc->gamma_store;
4449 if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
4454 g_base = (char *)r_base + size;
4455 if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
4460 b_base = (char *)g_base + size;
4461 if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
4466 drm_modeset_unlock_all(dev);
4471 * The Linux version of kfree() is a macro and can't be called
4472 * directly via a function pointer
4474 static void drm_kms_free(void *arg)
4480 * drm_mode_page_flip_ioctl - schedule an asynchronous fb update
4483 * @file_priv: DRM file info
4485 * This schedules an asynchronous update on a given CRTC, called page flip.
4486 * Optionally a drm event is generated to signal the completion of the event.
4487 * Generic drivers cannot assume that a pageflip with changed framebuffer
4488 * properties (including driver specific metadata like tiling layout) will work,
4489 * but some drivers support e.g. pixel format changes through the pageflip
4492 * Called by the user via ioctl.
4495 * Zero on success, errno on failure.
4497 int drm_mode_page_flip_ioctl(struct drm_device *dev,
4498 void *data, struct drm_file *file_priv)
4500 struct drm_mode_crtc_page_flip *page_flip = data;
4501 struct drm_crtc *crtc;
4502 struct drm_framebuffer *fb = NULL, *old_fb = NULL;
4503 struct drm_pending_vblank_event *e = NULL;
4506 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
4507 page_flip->reserved != 0)
4510 if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
4513 crtc = drm_crtc_find(dev, page_flip->crtc_id);
4517 drm_modeset_lock(&crtc->mutex, NULL);
4518 if (crtc->primary->fb == NULL) {
4519 /* The framebuffer is currently unbound, presumably
4520 * due to a hotplug event, that userspace has not
4527 if (crtc->funcs->page_flip == NULL)
4530 fb = drm_framebuffer_lookup(dev, page_flip->fb_id);
4536 ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, &crtc->mode, fb);
4540 if (crtc->primary->fb->pixel_format != fb->pixel_format) {
4541 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
4546 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
4548 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
4549 if (file_priv->event_space < sizeof e->event) {
4550 lockmgr(&dev->event_lock, LK_RELEASE);
4553 file_priv->event_space -= sizeof e->event;
4554 lockmgr(&dev->event_lock, LK_RELEASE);
4556 e = kzalloc(sizeof *e, GFP_KERNEL);
4558 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
4559 file_priv->event_space += sizeof e->event;
4560 lockmgr(&dev->event_lock, LK_RELEASE);
4564 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
4565 e->event.base.length = sizeof e->event;
4566 e->event.user_data = page_flip->user_data;
4567 e->base.event = &e->event.base;
4568 e->base.file_priv = file_priv;
4569 #ifdef __DragonFly__
4571 (void (*) (struct drm_pending_event *)) drm_kms_free;
4574 (void (*) (struct drm_pending_event *)) kfree;
4578 old_fb = crtc->primary->fb;
4579 ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags);
4581 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
4582 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
4583 file_priv->event_space += sizeof e->event;
4584 lockmgr(&dev->event_lock, LK_RELEASE);
4587 /* Keep the old fb, don't unref it. */
4591 * Warn if the driver hasn't properly updated the crtc->fb
4592 * field to reflect that the new framebuffer is now used.
4593 * Failing to do so will screw with the reference counting
4596 WARN_ON(crtc->primary->fb != fb);
4597 /* Unref only the old framebuffer. */
4603 drm_framebuffer_unreference(fb);
4605 drm_framebuffer_unreference(old_fb);
4606 drm_modeset_unlock(&crtc->mutex);
4612 * drm_mode_config_reset - call ->reset callbacks
4615 * This functions calls all the crtc's, encoder's and connector's ->reset
4616 * callback. Drivers can use this in e.g. their driver load or resume code to
4617 * reset hardware and software state.
4619 void drm_mode_config_reset(struct drm_device *dev)
4621 struct drm_crtc *crtc;
4622 struct drm_encoder *encoder;
4623 struct drm_connector *connector;
4625 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
4626 if (crtc->funcs->reset)
4627 crtc->funcs->reset(crtc);
4629 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
4630 if (encoder->funcs->reset)
4631 encoder->funcs->reset(encoder);
4633 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
4634 connector->status = connector_status_unknown;
4636 if (connector->funcs->reset)
4637 connector->funcs->reset(connector);
4640 EXPORT_SYMBOL(drm_mode_config_reset);
4643 * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer
4646 * @file_priv: DRM file info
4648 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
4649 * TTM or something else entirely) and returns the resulting buffer handle. This
4650 * handle can then be wrapped up into a framebuffer modeset object.
4652 * Note that userspace is not allowed to use such objects for render
4653 * acceleration - drivers must create their own private ioctls for such a use
4656 * Called by the user via ioctl.
4659 * Zero on success, errno on failure.
4661 int drm_mode_create_dumb_ioctl(struct drm_device *dev,
4662 void *data, struct drm_file *file_priv)
4664 struct drm_mode_create_dumb *args = data;
4665 u32 cpp, stride, size;
4667 if (!dev->driver->dumb_create)
4669 if (!args->width || !args->height || !args->bpp)
4672 /* overflow checks for 32bit size calculations */
4673 /* NOTE: DIV_ROUND_UP() can overflow */
4674 cpp = DIV_ROUND_UP(args->bpp, 8);
4675 if (!cpp || cpp > 0xffffffffU / args->width)
4677 stride = cpp * args->width;
4678 if (args->height > 0xffffffffU / stride)
4681 /* test for wrap-around */
4682 size = args->height * stride;
4683 if (PAGE_ALIGN(size) == 0)
4686 return dev->driver->dumb_create(file_priv, dev, args);
4690 * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer
4693 * @file_priv: DRM file info
4695 * Allocate an offset in the drm device node's address space to be able to
4696 * memory map a dumb buffer.
4698 * Called by the user via ioctl.
4701 * Zero on success, errno on failure.
4703 int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
4704 void *data, struct drm_file *file_priv)
4706 struct drm_mode_map_dumb *args = data;
4708 /* call driver ioctl to get mmap offset */
4709 if (!dev->driver->dumb_map_offset)
4712 return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
4716 * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer
4719 * @file_priv: DRM file info
4721 * This destroys the userspace handle for the given dumb backing storage buffer.
4722 * Since buffer objects must be reference counted in the kernel a buffer object
4723 * won't be immediately freed if a framebuffer modeset object still uses it.
4725 * Called by the user via ioctl.
4728 * Zero on success, errno on failure.
4730 int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
4731 void *data, struct drm_file *file_priv)
4733 struct drm_mode_destroy_dumb *args = data;
4735 if (!dev->driver->dumb_destroy)
4738 return dev->driver->dumb_destroy(file_priv, dev, args->handle);
4742 * drm_fb_get_bpp_depth - get the bpp/depth values for format
4743 * @format: pixel format (DRM_FORMAT_*)
4744 * @depth: storage for the depth value
4745 * @bpp: storage for the bpp value
4747 * This only supports RGB formats here for compat with code that doesn't use
4748 * pixel formats directly yet.
4750 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
4755 case DRM_FORMAT_RGB332:
4756 case DRM_FORMAT_BGR233:
4760 case DRM_FORMAT_XRGB1555:
4761 case DRM_FORMAT_XBGR1555:
4762 case DRM_FORMAT_RGBX5551:
4763 case DRM_FORMAT_BGRX5551:
4764 case DRM_FORMAT_ARGB1555:
4765 case DRM_FORMAT_ABGR1555:
4766 case DRM_FORMAT_RGBA5551:
4767 case DRM_FORMAT_BGRA5551:
4771 case DRM_FORMAT_RGB565:
4772 case DRM_FORMAT_BGR565:
4776 case DRM_FORMAT_RGB888:
4777 case DRM_FORMAT_BGR888:
4781 case DRM_FORMAT_XRGB8888:
4782 case DRM_FORMAT_XBGR8888:
4783 case DRM_FORMAT_RGBX8888:
4784 case DRM_FORMAT_BGRX8888:
4788 case DRM_FORMAT_XRGB2101010:
4789 case DRM_FORMAT_XBGR2101010:
4790 case DRM_FORMAT_RGBX1010102:
4791 case DRM_FORMAT_BGRX1010102:
4792 case DRM_FORMAT_ARGB2101010:
4793 case DRM_FORMAT_ABGR2101010:
4794 case DRM_FORMAT_RGBA1010102:
4795 case DRM_FORMAT_BGRA1010102:
4799 case DRM_FORMAT_ARGB8888:
4800 case DRM_FORMAT_ABGR8888:
4801 case DRM_FORMAT_RGBA8888:
4802 case DRM_FORMAT_BGRA8888:
4807 DRM_DEBUG_KMS("unsupported pixel format %s\n",
4808 drm_get_format_name(format));
4814 EXPORT_SYMBOL(drm_fb_get_bpp_depth);
4817 * drm_format_num_planes - get the number of planes for format
4818 * @format: pixel format (DRM_FORMAT_*)
4821 * The number of planes used by the specified pixel format.
4823 int drm_format_num_planes(uint32_t format)
4826 case DRM_FORMAT_YUV410:
4827 case DRM_FORMAT_YVU410:
4828 case DRM_FORMAT_YUV411:
4829 case DRM_FORMAT_YVU411:
4830 case DRM_FORMAT_YUV420:
4831 case DRM_FORMAT_YVU420:
4832 case DRM_FORMAT_YUV422:
4833 case DRM_FORMAT_YVU422:
4834 case DRM_FORMAT_YUV444:
4835 case DRM_FORMAT_YVU444:
4837 case DRM_FORMAT_NV12:
4838 case DRM_FORMAT_NV21:
4839 case DRM_FORMAT_NV16:
4840 case DRM_FORMAT_NV61:
4841 case DRM_FORMAT_NV24:
4842 case DRM_FORMAT_NV42:
4848 EXPORT_SYMBOL(drm_format_num_planes);
4851 * drm_format_plane_cpp - determine the bytes per pixel value
4852 * @format: pixel format (DRM_FORMAT_*)
4853 * @plane: plane index
4856 * The bytes per pixel value for the specified plane.
4858 int drm_format_plane_cpp(uint32_t format, int plane)
4863 if (plane >= drm_format_num_planes(format))
4867 case DRM_FORMAT_YUYV:
4868 case DRM_FORMAT_YVYU:
4869 case DRM_FORMAT_UYVY:
4870 case DRM_FORMAT_VYUY:
4872 case DRM_FORMAT_NV12:
4873 case DRM_FORMAT_NV21:
4874 case DRM_FORMAT_NV16:
4875 case DRM_FORMAT_NV61:
4876 case DRM_FORMAT_NV24:
4877 case DRM_FORMAT_NV42:
4878 return plane ? 2 : 1;
4879 case DRM_FORMAT_YUV410:
4880 case DRM_FORMAT_YVU410:
4881 case DRM_FORMAT_YUV411:
4882 case DRM_FORMAT_YVU411:
4883 case DRM_FORMAT_YUV420:
4884 case DRM_FORMAT_YVU420:
4885 case DRM_FORMAT_YUV422:
4886 case DRM_FORMAT_YVU422:
4887 case DRM_FORMAT_YUV444:
4888 case DRM_FORMAT_YVU444:
4891 drm_fb_get_bpp_depth(format, &depth, &bpp);
4895 EXPORT_SYMBOL(drm_format_plane_cpp);
4898 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
4899 * @format: pixel format (DRM_FORMAT_*)
4902 * The horizontal chroma subsampling factor for the
4903 * specified pixel format.
4905 int drm_format_horz_chroma_subsampling(uint32_t format)
4908 case DRM_FORMAT_YUV411:
4909 case DRM_FORMAT_YVU411:
4910 case DRM_FORMAT_YUV410:
4911 case DRM_FORMAT_YVU410:
4913 case DRM_FORMAT_YUYV:
4914 case DRM_FORMAT_YVYU:
4915 case DRM_FORMAT_UYVY:
4916 case DRM_FORMAT_VYUY:
4917 case DRM_FORMAT_NV12:
4918 case DRM_FORMAT_NV21:
4919 case DRM_FORMAT_NV16:
4920 case DRM_FORMAT_NV61:
4921 case DRM_FORMAT_YUV422:
4922 case DRM_FORMAT_YVU422:
4923 case DRM_FORMAT_YUV420:
4924 case DRM_FORMAT_YVU420:
4930 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
4933 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
4934 * @format: pixel format (DRM_FORMAT_*)
4937 * The vertical chroma subsampling factor for the
4938 * specified pixel format.
4940 int drm_format_vert_chroma_subsampling(uint32_t format)
4943 case DRM_FORMAT_YUV410:
4944 case DRM_FORMAT_YVU410:
4946 case DRM_FORMAT_YUV420:
4947 case DRM_FORMAT_YVU420:
4948 case DRM_FORMAT_NV12:
4949 case DRM_FORMAT_NV21:
4955 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
4958 * drm_mode_config_init - initialize DRM mode_configuration structure
4961 * Initialize @dev's mode_config structure, used for tracking the graphics
4962 * configuration of @dev.
4964 * Since this initializes the modeset locks, no locking is possible. Which is no
4965 * problem, since this should happen single threaded at init time. It is the
4966 * driver's problem to ensure this guarantee.
4969 void drm_mode_config_init(struct drm_device *dev)
4971 lockinit(&dev->mode_config.mutex, "drmmcm", 0, LK_CANRECURSE);
4972 drm_modeset_lock_init(&dev->mode_config.connection_mutex);
4973 lockinit(&dev->mode_config.idr_mutex, "mcfgidr", 0, LK_CANRECURSE);
4974 lockinit(&dev->mode_config.fb_lock, "drmfbl", 0, LK_CANRECURSE);
4975 INIT_LIST_HEAD(&dev->mode_config.fb_list);
4976 INIT_LIST_HEAD(&dev->mode_config.crtc_list);
4977 INIT_LIST_HEAD(&dev->mode_config.connector_list);
4978 INIT_LIST_HEAD(&dev->mode_config.bridge_list);
4979 INIT_LIST_HEAD(&dev->mode_config.encoder_list);
4980 INIT_LIST_HEAD(&dev->mode_config.property_list);
4981 INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
4982 INIT_LIST_HEAD(&dev->mode_config.plane_list);
4983 idr_init(&dev->mode_config.crtc_idr);
4985 drm_modeset_lock_all(dev);
4986 drm_mode_create_standard_connector_properties(dev);
4987 drm_mode_create_standard_plane_properties(dev);
4988 drm_modeset_unlock_all(dev);
4990 /* Just to be sure */
4991 dev->mode_config.num_fb = 0;
4992 dev->mode_config.num_connector = 0;
4993 dev->mode_config.num_crtc = 0;
4994 dev->mode_config.num_encoder = 0;
4995 dev->mode_config.num_overlay_plane = 0;
4996 dev->mode_config.num_total_plane = 0;
4998 EXPORT_SYMBOL(drm_mode_config_init);
5001 * drm_mode_config_cleanup - free up DRM mode_config info
5004 * Free up all the connectors and CRTCs associated with this DRM device, then
5005 * free up the framebuffers and associated buffer objects.
5007 * Note that since this /should/ happen single-threaded at driver/device
5008 * teardown time, no locking is required. It's the driver's job to ensure that
5009 * this guarantee actually holds true.
5011 * FIXME: cleanup any dangling user buffer objects too
5013 void drm_mode_config_cleanup(struct drm_device *dev)
5015 struct drm_connector *connector, *ot;
5016 struct drm_crtc *crtc, *ct;
5017 struct drm_encoder *encoder, *enct;
5018 struct drm_bridge *bridge, *brt;
5019 struct drm_framebuffer *fb, *fbt;
5020 struct drm_property *property, *pt;
5021 struct drm_property_blob *blob, *bt;
5022 struct drm_plane *plane, *plt;
5024 list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list,
5026 encoder->funcs->destroy(encoder);
5029 list_for_each_entry_safe(bridge, brt,
5030 &dev->mode_config.bridge_list, head) {
5031 bridge->funcs->destroy(bridge);
5034 list_for_each_entry_safe(connector, ot,
5035 &dev->mode_config.connector_list, head) {
5036 connector->funcs->destroy(connector);
5039 list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
5041 drm_property_destroy(dev, property);
5044 list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
5046 drm_property_destroy_blob(dev, blob);
5050 * Single-threaded teardown context, so it's not required to grab the
5051 * fb_lock to protect against concurrent fb_list access. Contrary, it
5052 * would actually deadlock with the drm_framebuffer_cleanup function.
5054 * Also, if there are any framebuffers left, that's a driver leak now,
5055 * so politely WARN about this.
5057 WARN_ON(!list_empty(&dev->mode_config.fb_list));
5058 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
5059 drm_framebuffer_remove(fb);
5062 list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
5064 plane->funcs->destroy(plane);
5067 list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
5068 crtc->funcs->destroy(crtc);
5071 idr_destroy(&dev->mode_config.crtc_idr);
5072 drm_modeset_lock_fini(&dev->mode_config.connection_mutex);
5074 EXPORT_SYMBOL(drm_mode_config_cleanup);