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/list.h>
33 #include <linux/slab.h>
34 #include <linux/export.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_edid.h>
38 #include <drm/drm_fourcc.h>
41 * drm_modeset_lock_all - take all modeset locks
44 * This function takes all modeset locks, suitable where a more fine-grained
45 * scheme isn't (yet) implemented.
47 void drm_modeset_lock_all(struct drm_device
*dev
)
49 struct drm_crtc
*crtc
;
51 mutex_lock(&dev
->mode_config
.mutex
);
53 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
54 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
56 EXPORT_SYMBOL(drm_modeset_lock_all
);
59 * drm_modeset_unlock_all - drop all modeset locks
62 void drm_modeset_unlock_all(struct drm_device
*dev
)
64 struct drm_crtc
*crtc
;
66 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
67 mutex_unlock(&crtc
->mutex
);
69 mutex_unlock(&dev
->mode_config
.mutex
);
71 EXPORT_SYMBOL(drm_modeset_unlock_all
);
74 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
77 void drm_warn_on_modeset_not_all_locked(struct drm_device
*dev
)
79 struct drm_crtc
*crtc
;
81 /* Locking is currently fubar in the panic handler. */
85 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
86 WARN_ON(!mutex_is_locked(&crtc
->mutex
));
88 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
90 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked
);
92 /* Avoid boilerplate. I'm tired of typing. */
93 #define DRM_ENUM_NAME_FN(fnname, list) \
94 char *fnname(int val) \
97 for (i = 0; i < ARRAY_SIZE(list); i++) { \
98 if (list[i].type == val) \
99 return list[i].name; \
101 return "(unknown)"; \
107 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
108 { { DRM_MODE_DPMS_ON
, "On" },
109 { DRM_MODE_DPMS_STANDBY
, "Standby" },
110 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
111 { DRM_MODE_DPMS_OFF
, "Off" }
114 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
117 * Optional properties
119 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
121 { DRM_MODE_SCALE_NONE
, "None" },
122 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
123 { DRM_MODE_SCALE_CENTER
, "Center" },
124 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
127 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
129 { DRM_MODE_DITHERING_OFF
, "Off" },
130 { DRM_MODE_DITHERING_ON
, "On" },
131 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
135 * Non-global properties, but "required" for certain connectors.
137 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
139 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
140 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
141 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
144 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
146 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
148 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
149 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
150 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
153 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
154 drm_dvi_i_subconnector_enum_list
)
156 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
158 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
159 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
160 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
161 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
162 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
165 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
167 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
169 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
170 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
171 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
172 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
173 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
176 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
177 drm_tv_subconnector_enum_list
)
179 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
180 { DRM_MODE_DIRTY_OFF
, "Off" },
181 { DRM_MODE_DIRTY_ON
, "On" },
182 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
185 struct drm_conn_prop_enum_list
{
192 * Connector and encoder types.
194 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
195 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
196 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
197 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
198 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
199 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
200 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
201 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
202 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
203 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
204 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
205 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
206 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
207 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
208 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
209 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
210 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
213 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
214 { { DRM_MODE_ENCODER_NONE
, "None" },
215 { DRM_MODE_ENCODER_DAC
, "DAC" },
216 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
217 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
218 { DRM_MODE_ENCODER_TVDAC
, "TV" },
219 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
222 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
226 snprintf(buf
, 32, "%s-%d",
227 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
231 EXPORT_SYMBOL(drm_get_encoder_name
);
233 char *drm_get_connector_name(struct drm_connector
*connector
)
237 snprintf(buf
, 32, "%s-%d",
238 drm_connector_enum_list
[connector
->connector_type
].name
,
239 connector
->connector_type_id
);
242 EXPORT_SYMBOL(drm_get_connector_name
);
244 char *drm_get_connector_status_name(enum drm_connector_status status
)
246 if (status
== connector_status_connected
)
248 else if (status
== connector_status_disconnected
)
249 return "disconnected";
253 EXPORT_SYMBOL(drm_get_connector_status_name
);
256 * drm_mode_object_get - allocate a new modeset identifier
258 * @obj: object pointer, used to generate unique ID
259 * @obj_type: object type
261 * Create a unique identifier based on @ptr in @dev's identifier space. Used
262 * for tracking modes, CRTCs and connectors.
265 * New unique (relative to other objects in @dev) integer identifier for the
268 static int drm_mode_object_get(struct drm_device
*dev
,
269 struct drm_mode_object
*obj
, uint32_t obj_type
)
273 mutex_lock(&dev
->mode_config
.idr_mutex
);
274 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
277 * Set up the object linking under the protection of the idr
278 * lock so that other users can't see inconsistent state.
281 obj
->type
= obj_type
;
283 mutex_unlock(&dev
->mode_config
.idr_mutex
);
285 return ret
< 0 ? ret
: 0;
289 * drm_mode_object_put - free a modeset identifer
291 * @object: object to free
293 * Free @id from @dev's unique identifier pool.
295 static void drm_mode_object_put(struct drm_device
*dev
,
296 struct drm_mode_object
*object
)
298 mutex_lock(&dev
->mode_config
.idr_mutex
);
299 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
300 mutex_unlock(&dev
->mode_config
.idr_mutex
);
304 * drm_mode_object_find - look up a drm object with static lifetime
306 * @id: id of the mode object
307 * @type: type of the mode object
309 * Note that framebuffers cannot be looked up with this functions - since those
310 * are reference counted, they need special treatment.
312 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
313 uint32_t id
, uint32_t type
)
315 struct drm_mode_object
*obj
= NULL
;
317 /* Framebuffers are reference counted and need their own lookup
319 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
321 mutex_lock(&dev
->mode_config
.idr_mutex
);
322 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
323 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
325 mutex_unlock(&dev
->mode_config
.idr_mutex
);
329 EXPORT_SYMBOL(drm_mode_object_find
);
332 * drm_framebuffer_init - initialize a framebuffer
334 * @fb: framebuffer to be initialized
335 * @funcs: ... with these functions
337 * Allocates an ID for the framebuffer's parent mode object, sets its mode
338 * functions & device file and adds it to the master fd list.
341 * This functions publishes the fb and makes it available for concurrent access
342 * by other users. Which means by this point the fb _must_ be fully set up -
343 * since all the fb attributes are invariant over its lifetime, no further
344 * locking but only correct reference counting is required.
347 * Zero on success, error code on failure.
349 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
350 const struct drm_framebuffer_funcs
*funcs
)
354 mutex_lock(&dev
->mode_config
.fb_lock
);
355 kref_init(&fb
->refcount
);
356 INIT_LIST_HEAD(&fb
->filp_head
);
360 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
364 /* Grab the idr reference. */
365 drm_framebuffer_reference(fb
);
367 dev
->mode_config
.num_fb
++;
368 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
370 mutex_unlock(&dev
->mode_config
.fb_lock
);
374 EXPORT_SYMBOL(drm_framebuffer_init
);
376 static void drm_framebuffer_free(struct kref
*kref
)
378 struct drm_framebuffer
*fb
=
379 container_of(kref
, struct drm_framebuffer
, refcount
);
380 fb
->funcs
->destroy(fb
);
383 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
386 struct drm_mode_object
*obj
= NULL
;
387 struct drm_framebuffer
*fb
;
389 mutex_lock(&dev
->mode_config
.idr_mutex
);
390 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
391 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
395 mutex_unlock(&dev
->mode_config
.idr_mutex
);
401 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
403 * @id: id of the fb object
405 * If successful, this grabs an additional reference to the framebuffer -
406 * callers need to make sure to eventually unreference the returned framebuffer
409 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
412 struct drm_framebuffer
*fb
;
414 mutex_lock(&dev
->mode_config
.fb_lock
);
415 fb
= __drm_framebuffer_lookup(dev
, id
);
417 drm_framebuffer_reference(fb
);
418 mutex_unlock(&dev
->mode_config
.fb_lock
);
422 EXPORT_SYMBOL(drm_framebuffer_lookup
);
425 * drm_framebuffer_unreference - unref a framebuffer
426 * @fb: framebuffer to unref
428 * This functions decrements the fb's refcount and frees it if it drops to zero.
430 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
432 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
433 kref_put(&fb
->refcount
, drm_framebuffer_free
);
435 EXPORT_SYMBOL(drm_framebuffer_unreference
);
438 * drm_framebuffer_reference - incr the fb refcnt
441 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
443 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
444 kref_get(&fb
->refcount
);
446 EXPORT_SYMBOL(drm_framebuffer_reference
);
448 static void drm_framebuffer_free_bug(struct kref
*kref
)
453 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
455 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
456 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
459 /* dev->mode_config.fb_lock must be held! */
460 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
461 struct drm_framebuffer
*fb
)
463 mutex_lock(&dev
->mode_config
.idr_mutex
);
464 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
465 mutex_unlock(&dev
->mode_config
.idr_mutex
);
469 __drm_framebuffer_unreference(fb
);
473 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
474 * @fb: fb to unregister
476 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
477 * those used for fbdev. Note that the caller must hold a reference of it's own,
478 * i.e. the object may not be destroyed through this call (since it'll lead to a
479 * locking inversion).
481 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
483 struct drm_device
*dev
= fb
->dev
;
485 mutex_lock(&dev
->mode_config
.fb_lock
);
486 /* Mark fb as reaped and drop idr ref. */
487 __drm_framebuffer_unregister(dev
, fb
);
488 mutex_unlock(&dev
->mode_config
.fb_lock
);
490 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
493 * drm_framebuffer_cleanup - remove a framebuffer object
494 * @fb: framebuffer to remove
496 * Cleanup references to a user-created framebuffer. This function is intended
497 * to be used from the drivers ->destroy callback.
499 * Note that this function does not remove the fb from active usuage - if it is
500 * still used anywhere, hilarity can ensue since userspace could call getfb on
501 * the id and get back -EINVAL. Obviously no concern at driver unload time.
503 * Also, the framebuffer will not be removed from the lookup idr - for
504 * user-created framebuffers this will happen in in the rmfb ioctl. For
505 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
506 * drm_framebuffer_unregister_private.
508 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
510 struct drm_device
*dev
= fb
->dev
;
512 mutex_lock(&dev
->mode_config
.fb_lock
);
514 dev
->mode_config
.num_fb
--;
515 mutex_unlock(&dev
->mode_config
.fb_lock
);
517 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
520 * drm_framebuffer_remove - remove and unreference a framebuffer object
521 * @fb: framebuffer to remove
523 * Scans all the CRTCs and planes in @dev's mode_config. If they're
524 * using @fb, removes it, setting it to NULL. Then drops the reference to the
525 * passed-in framebuffer. Might take the modeset locks.
527 * Note that this function optimizes the cleanup away if the caller holds the
528 * last reference to the framebuffer. It is also guaranteed to not take the
529 * modeset locks in this case.
531 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
533 struct drm_device
*dev
= fb
->dev
;
534 struct drm_crtc
*crtc
;
535 struct drm_plane
*plane
;
536 struct drm_mode_set set
;
539 WARN_ON(!list_empty(&fb
->filp_head
));
542 * drm ABI mandates that we remove any deleted framebuffers from active
543 * useage. But since most sane clients only remove framebuffers they no
544 * longer need, try to optimize this away.
546 * Since we're holding a reference ourselves, observing a refcount of 1
547 * means that we're the last holder and can skip it. Also, the refcount
548 * can never increase from 1 again, so we don't need any barriers or
551 * Note that userspace could try to race with use and instate a new
552 * usage _after_ we've cleared all current ones. End result will be an
553 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
556 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
557 drm_modeset_lock_all(dev
);
558 /* remove from any CRTC */
559 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
560 if (crtc
->fb
== fb
) {
561 /* should turn off the crtc */
562 memset(&set
, 0, sizeof(struct drm_mode_set
));
565 ret
= drm_mode_set_config_internal(&set
);
567 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
571 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
572 if (plane
->fb
== fb
) {
573 /* should turn off the crtc */
574 ret
= plane
->funcs
->disable_plane(plane
);
576 DRM_ERROR("failed to disable plane with busy fb\n");
577 /* disconnect the plane from the fb and crtc: */
578 __drm_framebuffer_unreference(plane
->fb
);
583 drm_modeset_unlock_all(dev
);
586 drm_framebuffer_unreference(fb
);
588 EXPORT_SYMBOL(drm_framebuffer_remove
);
591 * drm_crtc_init - Initialise a new CRTC object
593 * @crtc: CRTC object to init
594 * @funcs: callbacks for the new CRTC
596 * Inits a new object created as base part of an driver crtc object.
599 * Zero on success, error code on failure.
601 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
602 const struct drm_crtc_funcs
*funcs
)
608 crtc
->invert_dimensions
= false;
610 drm_modeset_lock_all(dev
);
611 mutex_init(&crtc
->mutex
);
612 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
614 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
618 crtc
->base
.properties
= &crtc
->properties
;
620 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
621 dev
->mode_config
.num_crtc
++;
624 drm_modeset_unlock_all(dev
);
628 EXPORT_SYMBOL(drm_crtc_init
);
631 * drm_crtc_cleanup - Cleans up the core crtc usage.
632 * @crtc: CRTC to cleanup
634 * Cleanup @crtc. Removes from drm modesetting space
635 * does NOT free object, caller does that.
637 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
639 struct drm_device
*dev
= crtc
->dev
;
641 kfree(crtc
->gamma_store
);
642 crtc
->gamma_store
= NULL
;
644 drm_mode_object_put(dev
, &crtc
->base
);
645 list_del(&crtc
->head
);
646 dev
->mode_config
.num_crtc
--;
648 EXPORT_SYMBOL(drm_crtc_cleanup
);
651 * drm_mode_probed_add - add a mode to a connector's probed mode list
652 * @connector: connector the new mode
655 * Add @mode to @connector's mode list for later use.
657 void drm_mode_probed_add(struct drm_connector
*connector
,
658 struct drm_display_mode
*mode
)
660 list_add(&mode
->head
, &connector
->probed_modes
);
662 EXPORT_SYMBOL(drm_mode_probed_add
);
665 * drm_mode_remove - remove and free a mode
666 * @connector: connector list to modify
667 * @mode: mode to remove
669 * Remove @mode from @connector's mode list, then free it.
671 void drm_mode_remove(struct drm_connector
*connector
,
672 struct drm_display_mode
*mode
)
674 list_del(&mode
->head
);
675 drm_mode_destroy(connector
->dev
, mode
);
677 EXPORT_SYMBOL(drm_mode_remove
);
680 * drm_connector_init - Init a preallocated connector
682 * @connector: the connector to init
683 * @funcs: callbacks for this connector
684 * @connector_type: user visible type of the connector
686 * Initialises a preallocated connector. Connectors should be
687 * subclassed as part of driver connector objects.
690 * Zero on success, error code on failure.
692 int drm_connector_init(struct drm_device
*dev
,
693 struct drm_connector
*connector
,
694 const struct drm_connector_funcs
*funcs
,
699 drm_modeset_lock_all(dev
);
701 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
705 connector
->base
.properties
= &connector
->properties
;
706 connector
->dev
= dev
;
707 connector
->funcs
= funcs
;
708 connector
->connector_type
= connector_type
;
709 connector
->connector_type_id
=
710 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
711 INIT_LIST_HEAD(&connector
->probed_modes
);
712 INIT_LIST_HEAD(&connector
->modes
);
713 connector
->edid_blob_ptr
= NULL
;
714 connector
->status
= connector_status_unknown
;
716 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
717 dev
->mode_config
.num_connector
++;
719 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
720 drm_object_attach_property(&connector
->base
,
721 dev
->mode_config
.edid_property
,
724 drm_object_attach_property(&connector
->base
,
725 dev
->mode_config
.dpms_property
, 0);
728 drm_modeset_unlock_all(dev
);
732 EXPORT_SYMBOL(drm_connector_init
);
735 * drm_connector_cleanup - cleans up an initialised connector
736 * @connector: connector to cleanup
738 * Cleans up the connector but doesn't free the object.
740 void drm_connector_cleanup(struct drm_connector
*connector
)
742 struct drm_device
*dev
= connector
->dev
;
743 struct drm_display_mode
*mode
, *t
;
745 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
746 drm_mode_remove(connector
, mode
);
748 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
749 drm_mode_remove(connector
, mode
);
751 drm_mode_object_put(dev
, &connector
->base
);
752 list_del(&connector
->head
);
753 dev
->mode_config
.num_connector
--;
755 EXPORT_SYMBOL(drm_connector_cleanup
);
757 void drm_connector_unplug_all(struct drm_device
*dev
)
759 struct drm_connector
*connector
;
761 /* taking the mode config mutex ends up in a clash with sysfs */
762 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
763 drm_sysfs_connector_remove(connector
);
766 EXPORT_SYMBOL(drm_connector_unplug_all
);
768 int drm_encoder_init(struct drm_device
*dev
,
769 struct drm_encoder
*encoder
,
770 const struct drm_encoder_funcs
*funcs
,
775 drm_modeset_lock_all(dev
);
777 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
782 encoder
->encoder_type
= encoder_type
;
783 encoder
->funcs
= funcs
;
785 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
786 dev
->mode_config
.num_encoder
++;
789 drm_modeset_unlock_all(dev
);
793 EXPORT_SYMBOL(drm_encoder_init
);
795 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
797 struct drm_device
*dev
= encoder
->dev
;
798 drm_modeset_lock_all(dev
);
799 drm_mode_object_put(dev
, &encoder
->base
);
800 list_del(&encoder
->head
);
801 dev
->mode_config
.num_encoder
--;
802 drm_modeset_unlock_all(dev
);
804 EXPORT_SYMBOL(drm_encoder_cleanup
);
806 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
807 unsigned long possible_crtcs
,
808 const struct drm_plane_funcs
*funcs
,
809 const uint32_t *formats
, uint32_t format_count
,
814 drm_modeset_lock_all(dev
);
816 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
820 plane
->base
.properties
= &plane
->properties
;
822 plane
->funcs
= funcs
;
823 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
825 if (!plane
->format_types
) {
826 DRM_DEBUG_KMS("out of memory when allocating plane\n");
827 drm_mode_object_put(dev
, &plane
->base
);
832 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
833 plane
->format_count
= format_count
;
834 plane
->possible_crtcs
= possible_crtcs
;
836 /* private planes are not exposed to userspace, but depending on
837 * display hardware, might be convenient to allow sharing programming
838 * for the scanout engine with the crtc implementation.
841 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
842 dev
->mode_config
.num_plane
++;
844 INIT_LIST_HEAD(&plane
->head
);
848 drm_modeset_unlock_all(dev
);
852 EXPORT_SYMBOL(drm_plane_init
);
854 void drm_plane_cleanup(struct drm_plane
*plane
)
856 struct drm_device
*dev
= plane
->dev
;
858 drm_modeset_lock_all(dev
);
859 kfree(plane
->format_types
);
860 drm_mode_object_put(dev
, &plane
->base
);
861 /* if not added to a list, it must be a private plane */
862 if (!list_empty(&plane
->head
)) {
863 list_del(&plane
->head
);
864 dev
->mode_config
.num_plane
--;
866 drm_modeset_unlock_all(dev
);
868 EXPORT_SYMBOL(drm_plane_cleanup
);
871 * drm_mode_create - create a new display mode
874 * Create a new drm_display_mode, give it an ID, and return it.
877 * Pointer to new mode on success, NULL on error.
879 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
881 struct drm_display_mode
*nmode
;
883 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
887 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
894 EXPORT_SYMBOL(drm_mode_create
);
897 * drm_mode_destroy - remove a mode
899 * @mode: mode to remove
901 * Free @mode's unique identifier, then free it.
903 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
908 drm_mode_object_put(dev
, &mode
->base
);
912 EXPORT_SYMBOL(drm_mode_destroy
);
914 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
916 struct drm_property
*edid
;
917 struct drm_property
*dpms
;
920 * Standard properties (apply to all connectors)
922 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
923 DRM_MODE_PROP_IMMUTABLE
,
925 dev
->mode_config
.edid_property
= edid
;
927 dpms
= drm_property_create_enum(dev
, 0,
928 "DPMS", drm_dpms_enum_list
,
929 ARRAY_SIZE(drm_dpms_enum_list
));
930 dev
->mode_config
.dpms_property
= dpms
;
936 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
939 * Called by a driver the first time a DVI-I connector is made.
941 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
943 struct drm_property
*dvi_i_selector
;
944 struct drm_property
*dvi_i_subconnector
;
946 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
950 drm_property_create_enum(dev
, 0,
951 "select subconnector",
952 drm_dvi_i_select_enum_list
,
953 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
954 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
956 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
958 drm_dvi_i_subconnector_enum_list
,
959 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
960 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
964 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
967 * drm_create_tv_properties - create TV specific connector properties
969 * @num_modes: number of different TV formats (modes) supported
970 * @modes: array of pointers to strings containing name of each format
972 * Called by a driver's TV initialization routine, this function creates
973 * the TV specific connector properties for a given device. Caller is
974 * responsible for allocating a list of format names and passing them to
977 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
980 struct drm_property
*tv_selector
;
981 struct drm_property
*tv_subconnector
;
984 if (dev
->mode_config
.tv_select_subconnector_property
)
988 * Basic connector properties
990 tv_selector
= drm_property_create_enum(dev
, 0,
991 "select subconnector",
992 drm_tv_select_enum_list
,
993 ARRAY_SIZE(drm_tv_select_enum_list
));
994 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
997 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
999 drm_tv_subconnector_enum_list
,
1000 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1001 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1004 * Other, TV specific properties: margins & TV modes.
1006 dev
->mode_config
.tv_left_margin_property
=
1007 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1009 dev
->mode_config
.tv_right_margin_property
=
1010 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1012 dev
->mode_config
.tv_top_margin_property
=
1013 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1015 dev
->mode_config
.tv_bottom_margin_property
=
1016 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1018 dev
->mode_config
.tv_mode_property
=
1019 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1021 for (i
= 0; i
< num_modes
; i
++)
1022 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1025 dev
->mode_config
.tv_brightness_property
=
1026 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1028 dev
->mode_config
.tv_contrast_property
=
1029 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1031 dev
->mode_config
.tv_flicker_reduction_property
=
1032 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1034 dev
->mode_config
.tv_overscan_property
=
1035 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1037 dev
->mode_config
.tv_saturation_property
=
1038 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1040 dev
->mode_config
.tv_hue_property
=
1041 drm_property_create_range(dev
, 0, "hue", 0, 100);
1045 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1048 * drm_mode_create_scaling_mode_property - create scaling mode property
1051 * Called by a driver the first time it's needed, must be attached to desired
1054 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1056 struct drm_property
*scaling_mode
;
1058 if (dev
->mode_config
.scaling_mode_property
)
1062 drm_property_create_enum(dev
, 0, "scaling mode",
1063 drm_scaling_mode_enum_list
,
1064 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1066 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1070 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1073 * drm_mode_create_dithering_property - create dithering property
1076 * Called by a driver the first time it's needed, must be attached to desired
1079 int drm_mode_create_dithering_property(struct drm_device
*dev
)
1081 struct drm_property
*dithering_mode
;
1083 if (dev
->mode_config
.dithering_mode_property
)
1087 drm_property_create_enum(dev
, 0, "dithering",
1088 drm_dithering_mode_enum_list
,
1089 ARRAY_SIZE(drm_dithering_mode_enum_list
));
1090 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
1094 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
1097 * drm_mode_create_dirty_property - create dirty property
1100 * Called by a driver the first time it's needed, must be attached to desired
1103 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1105 struct drm_property
*dirty_info
;
1107 if (dev
->mode_config
.dirty_info_property
)
1111 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1113 drm_dirty_info_enum_list
,
1114 ARRAY_SIZE(drm_dirty_info_enum_list
));
1115 dev
->mode_config
.dirty_info_property
= dirty_info
;
1119 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1121 static int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1123 uint32_t total_objects
= 0;
1125 total_objects
+= dev
->mode_config
.num_crtc
;
1126 total_objects
+= dev
->mode_config
.num_connector
;
1127 total_objects
+= dev
->mode_config
.num_encoder
;
1129 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1130 if (!group
->id_list
)
1133 group
->num_crtcs
= 0;
1134 group
->num_connectors
= 0;
1135 group
->num_encoders
= 0;
1139 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1140 struct drm_mode_group
*group
)
1142 struct drm_crtc
*crtc
;
1143 struct drm_encoder
*encoder
;
1144 struct drm_connector
*connector
;
1147 if ((ret
= drm_mode_group_init(dev
, group
)))
1150 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1151 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1153 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1154 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1157 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1158 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1159 group
->num_connectors
++] = connector
->base
.id
;
1163 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1166 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1167 * @out: drm_mode_modeinfo struct to return to the user
1168 * @in: drm_display_mode to use
1170 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1173 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1174 const struct drm_display_mode
*in
)
1176 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1177 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1178 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1179 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1180 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1181 "timing values too large for mode info\n");
1183 out
->clock
= in
->clock
;
1184 out
->hdisplay
= in
->hdisplay
;
1185 out
->hsync_start
= in
->hsync_start
;
1186 out
->hsync_end
= in
->hsync_end
;
1187 out
->htotal
= in
->htotal
;
1188 out
->hskew
= in
->hskew
;
1189 out
->vdisplay
= in
->vdisplay
;
1190 out
->vsync_start
= in
->vsync_start
;
1191 out
->vsync_end
= in
->vsync_end
;
1192 out
->vtotal
= in
->vtotal
;
1193 out
->vscan
= in
->vscan
;
1194 out
->vrefresh
= in
->vrefresh
;
1195 out
->flags
= in
->flags
;
1196 out
->type
= in
->type
;
1197 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1198 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1202 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1203 * @out: drm_display_mode to return to the user
1204 * @in: drm_mode_modeinfo to use
1206 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1210 * Zero on success, errno on failure.
1212 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1213 const struct drm_mode_modeinfo
*in
)
1215 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1218 out
->clock
= in
->clock
;
1219 out
->hdisplay
= in
->hdisplay
;
1220 out
->hsync_start
= in
->hsync_start
;
1221 out
->hsync_end
= in
->hsync_end
;
1222 out
->htotal
= in
->htotal
;
1223 out
->hskew
= in
->hskew
;
1224 out
->vdisplay
= in
->vdisplay
;
1225 out
->vsync_start
= in
->vsync_start
;
1226 out
->vsync_end
= in
->vsync_end
;
1227 out
->vtotal
= in
->vtotal
;
1228 out
->vscan
= in
->vscan
;
1229 out
->vrefresh
= in
->vrefresh
;
1230 out
->flags
= in
->flags
;
1231 out
->type
= in
->type
;
1232 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1233 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1239 * drm_mode_getresources - get graphics configuration
1240 * @dev: drm device for the ioctl
1241 * @data: data pointer for the ioctl
1242 * @file_priv: drm file for the ioctl call
1244 * Construct a set of configuration description structures and return
1245 * them to the user, including CRTC, connector and framebuffer configuration.
1247 * Called by the user via ioctl.
1250 * Zero on success, errno on failure.
1252 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1253 struct drm_file
*file_priv
)
1255 struct drm_mode_card_res
*card_res
= data
;
1256 struct list_head
*lh
;
1257 struct drm_framebuffer
*fb
;
1258 struct drm_connector
*connector
;
1259 struct drm_crtc
*crtc
;
1260 struct drm_encoder
*encoder
;
1262 int connector_count
= 0;
1265 int encoder_count
= 0;
1267 uint32_t __user
*fb_id
;
1268 uint32_t __user
*crtc_id
;
1269 uint32_t __user
*connector_id
;
1270 uint32_t __user
*encoder_id
;
1271 struct drm_mode_group
*mode_group
;
1273 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1277 mutex_lock(&file_priv
->fbs_lock
);
1279 * For the non-control nodes we need to limit the list of resources
1280 * by IDs in the group list for this node
1282 list_for_each(lh
, &file_priv
->fbs
)
1285 /* handle this in 4 parts */
1287 if (card_res
->count_fbs
>= fb_count
) {
1289 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1290 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1291 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1292 mutex_unlock(&file_priv
->fbs_lock
);
1298 card_res
->count_fbs
= fb_count
;
1299 mutex_unlock(&file_priv
->fbs_lock
);
1301 drm_modeset_lock_all(dev
);
1302 mode_group
= &file_priv
->master
->minor
->mode_group
;
1303 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1305 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1308 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1311 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1315 crtc_count
= mode_group
->num_crtcs
;
1316 connector_count
= mode_group
->num_connectors
;
1317 encoder_count
= mode_group
->num_encoders
;
1320 card_res
->max_height
= dev
->mode_config
.max_height
;
1321 card_res
->min_height
= dev
->mode_config
.min_height
;
1322 card_res
->max_width
= dev
->mode_config
.max_width
;
1323 card_res
->min_width
= dev
->mode_config
.min_width
;
1326 if (card_res
->count_crtcs
>= crtc_count
) {
1328 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1329 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1330 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1332 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1333 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1340 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1341 if (put_user(mode_group
->id_list
[i
],
1342 crtc_id
+ copied
)) {
1350 card_res
->count_crtcs
= crtc_count
;
1353 if (card_res
->count_encoders
>= encoder_count
) {
1355 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1356 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1357 list_for_each_entry(encoder
,
1358 &dev
->mode_config
.encoder_list
,
1360 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1361 drm_get_encoder_name(encoder
));
1362 if (put_user(encoder
->base
.id
, encoder_id
+
1370 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1371 if (put_user(mode_group
->id_list
[i
],
1372 encoder_id
+ copied
)) {
1381 card_res
->count_encoders
= encoder_count
;
1384 if (card_res
->count_connectors
>= connector_count
) {
1386 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1387 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1388 list_for_each_entry(connector
,
1389 &dev
->mode_config
.connector_list
,
1391 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1393 drm_get_connector_name(connector
));
1394 if (put_user(connector
->base
.id
,
1395 connector_id
+ copied
)) {
1402 int start
= mode_group
->num_crtcs
+
1403 mode_group
->num_encoders
;
1404 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1405 if (put_user(mode_group
->id_list
[i
],
1406 connector_id
+ copied
)) {
1414 card_res
->count_connectors
= connector_count
;
1416 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1417 card_res
->count_connectors
, card_res
->count_encoders
);
1420 drm_modeset_unlock_all(dev
);
1425 * drm_mode_getcrtc - get CRTC configuration
1426 * @dev: drm device for the ioctl
1427 * @data: data pointer for the ioctl
1428 * @file_priv: drm file for the ioctl call
1430 * Construct a CRTC configuration structure to return to the user.
1432 * Called by the user via ioctl.
1435 * Zero on success, errno on failure.
1437 int drm_mode_getcrtc(struct drm_device
*dev
,
1438 void *data
, struct drm_file
*file_priv
)
1440 struct drm_mode_crtc
*crtc_resp
= data
;
1441 struct drm_crtc
*crtc
;
1442 struct drm_mode_object
*obj
;
1445 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1448 drm_modeset_lock_all(dev
);
1450 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1451 DRM_MODE_OBJECT_CRTC
);
1456 crtc
= obj_to_crtc(obj
);
1458 crtc_resp
->x
= crtc
->x
;
1459 crtc_resp
->y
= crtc
->y
;
1460 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1462 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1464 crtc_resp
->fb_id
= 0;
1466 if (crtc
->enabled
) {
1468 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1469 crtc_resp
->mode_valid
= 1;
1472 crtc_resp
->mode_valid
= 0;
1476 drm_modeset_unlock_all(dev
);
1481 * drm_mode_getconnector - get connector configuration
1482 * @dev: drm device for the ioctl
1483 * @data: data pointer for the ioctl
1484 * @file_priv: drm file for the ioctl call
1486 * Construct a connector configuration structure to return to the user.
1488 * Called by the user via ioctl.
1491 * Zero on success, errno on failure.
1493 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1494 struct drm_file
*file_priv
)
1496 struct drm_mode_get_connector
*out_resp
= data
;
1497 struct drm_mode_object
*obj
;
1498 struct drm_connector
*connector
;
1499 struct drm_display_mode
*mode
;
1501 int props_count
= 0;
1502 int encoders_count
= 0;
1506 struct drm_mode_modeinfo u_mode
;
1507 struct drm_mode_modeinfo __user
*mode_ptr
;
1508 uint32_t __user
*prop_ptr
;
1509 uint64_t __user
*prop_values
;
1510 uint32_t __user
*encoder_ptr
;
1512 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1515 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1517 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1519 mutex_lock(&dev
->mode_config
.mutex
);
1521 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1522 DRM_MODE_OBJECT_CONNECTOR
);
1527 connector
= obj_to_connector(obj
);
1529 props_count
= connector
->properties
.count
;
1531 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1532 if (connector
->encoder_ids
[i
] != 0) {
1537 if (out_resp
->count_modes
== 0) {
1538 connector
->funcs
->fill_modes(connector
,
1539 dev
->mode_config
.max_width
,
1540 dev
->mode_config
.max_height
);
1543 /* delayed so we get modes regardless of pre-fill_modes state */
1544 list_for_each_entry(mode
, &connector
->modes
, head
)
1547 out_resp
->connector_id
= connector
->base
.id
;
1548 out_resp
->connector_type
= connector
->connector_type
;
1549 out_resp
->connector_type_id
= connector
->connector_type_id
;
1550 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1551 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1552 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1553 out_resp
->connection
= connector
->status
;
1554 if (connector
->encoder
)
1555 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1557 out_resp
->encoder_id
= 0;
1560 * This ioctl is called twice, once to determine how much space is
1561 * needed, and the 2nd time to fill it.
1563 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1565 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1566 list_for_each_entry(mode
, &connector
->modes
, head
) {
1567 drm_crtc_convert_to_umode(&u_mode
, mode
);
1568 if (copy_to_user(mode_ptr
+ copied
,
1569 &u_mode
, sizeof(u_mode
))) {
1576 out_resp
->count_modes
= mode_count
;
1578 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1580 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1581 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1582 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1583 if (put_user(connector
->properties
.ids
[i
],
1584 prop_ptr
+ copied
)) {
1589 if (put_user(connector
->properties
.values
[i
],
1590 prop_values
+ copied
)) {
1597 out_resp
->count_props
= props_count
;
1599 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1601 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1602 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1603 if (connector
->encoder_ids
[i
] != 0) {
1604 if (put_user(connector
->encoder_ids
[i
],
1605 encoder_ptr
+ copied
)) {
1613 out_resp
->count_encoders
= encoders_count
;
1616 mutex_unlock(&dev
->mode_config
.mutex
);
1621 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1622 struct drm_file
*file_priv
)
1624 struct drm_mode_get_encoder
*enc_resp
= data
;
1625 struct drm_mode_object
*obj
;
1626 struct drm_encoder
*encoder
;
1629 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1632 drm_modeset_lock_all(dev
);
1633 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1634 DRM_MODE_OBJECT_ENCODER
);
1639 encoder
= obj_to_encoder(obj
);
1642 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1644 enc_resp
->crtc_id
= 0;
1645 enc_resp
->encoder_type
= encoder
->encoder_type
;
1646 enc_resp
->encoder_id
= encoder
->base
.id
;
1647 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1648 enc_resp
->possible_clones
= encoder
->possible_clones
;
1651 drm_modeset_unlock_all(dev
);
1656 * drm_mode_getplane_res - get plane info
1659 * @file_priv: DRM file info
1661 * Return an plane count and set of IDs.
1663 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1664 struct drm_file
*file_priv
)
1666 struct drm_mode_get_plane_res
*plane_resp
= data
;
1667 struct drm_mode_config
*config
;
1668 struct drm_plane
*plane
;
1669 uint32_t __user
*plane_ptr
;
1670 int copied
= 0, ret
= 0;
1672 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1675 drm_modeset_lock_all(dev
);
1676 config
= &dev
->mode_config
;
1679 * This ioctl is called twice, once to determine how much space is
1680 * needed, and the 2nd time to fill it.
1682 if (config
->num_plane
&&
1683 (plane_resp
->count_planes
>= config
->num_plane
)) {
1684 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1686 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1687 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1694 plane_resp
->count_planes
= config
->num_plane
;
1697 drm_modeset_unlock_all(dev
);
1702 * drm_mode_getplane - get plane info
1705 * @file_priv: DRM file info
1707 * Return plane info, including formats supported, gamma size, any
1710 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1711 struct drm_file
*file_priv
)
1713 struct drm_mode_get_plane
*plane_resp
= data
;
1714 struct drm_mode_object
*obj
;
1715 struct drm_plane
*plane
;
1716 uint32_t __user
*format_ptr
;
1719 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1722 drm_modeset_lock_all(dev
);
1723 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1724 DRM_MODE_OBJECT_PLANE
);
1729 plane
= obj_to_plane(obj
);
1732 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1734 plane_resp
->crtc_id
= 0;
1737 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1739 plane_resp
->fb_id
= 0;
1741 plane_resp
->plane_id
= plane
->base
.id
;
1742 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1743 plane_resp
->gamma_size
= plane
->gamma_size
;
1746 * This ioctl is called twice, once to determine how much space is
1747 * needed, and the 2nd time to fill it.
1749 if (plane
->format_count
&&
1750 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1751 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1752 if (copy_to_user(format_ptr
,
1753 plane
->format_types
,
1754 sizeof(uint32_t) * plane
->format_count
)) {
1759 plane_resp
->count_format_types
= plane
->format_count
;
1762 drm_modeset_unlock_all(dev
);
1767 * drm_mode_setplane - set up or tear down an plane
1769 * @data: ioctl data*
1770 * @file_priv: DRM file info
1772 * Set plane info, including placement, fb, scaling, and other factors.
1773 * Or pass a NULL fb to disable.
1775 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1776 struct drm_file
*file_priv
)
1778 struct drm_mode_set_plane
*plane_req
= data
;
1779 struct drm_mode_object
*obj
;
1780 struct drm_plane
*plane
;
1781 struct drm_crtc
*crtc
;
1782 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
1784 unsigned int fb_width
, fb_height
;
1787 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1791 * First, find the plane, crtc, and fb objects. If not available,
1792 * we don't bother to call the driver.
1794 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1795 DRM_MODE_OBJECT_PLANE
);
1797 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1798 plane_req
->plane_id
);
1801 plane
= obj_to_plane(obj
);
1803 /* No fb means shut it down */
1804 if (!plane_req
->fb_id
) {
1805 drm_modeset_lock_all(dev
);
1807 plane
->funcs
->disable_plane(plane
);
1810 drm_modeset_unlock_all(dev
);
1814 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1815 DRM_MODE_OBJECT_CRTC
);
1817 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1818 plane_req
->crtc_id
);
1822 crtc
= obj_to_crtc(obj
);
1824 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1826 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1832 /* Check whether this plane supports the fb pixel format. */
1833 for (i
= 0; i
< plane
->format_count
; i
++)
1834 if (fb
->pixel_format
== plane
->format_types
[i
])
1836 if (i
== plane
->format_count
) {
1837 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1842 fb_width
= fb
->width
<< 16;
1843 fb_height
= fb
->height
<< 16;
1845 /* Make sure source coordinates are inside the fb. */
1846 if (plane_req
->src_w
> fb_width
||
1847 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1848 plane_req
->src_h
> fb_height
||
1849 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1850 DRM_DEBUG_KMS("Invalid source coordinates "
1851 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1852 plane_req
->src_w
>> 16,
1853 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1854 plane_req
->src_h
>> 16,
1855 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1856 plane_req
->src_x
>> 16,
1857 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1858 plane_req
->src_y
>> 16,
1859 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1864 /* Give drivers some help against integer overflows */
1865 if (plane_req
->crtc_w
> INT_MAX
||
1866 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1867 plane_req
->crtc_h
> INT_MAX
||
1868 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1869 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1870 plane_req
->crtc_w
, plane_req
->crtc_h
,
1871 plane_req
->crtc_x
, plane_req
->crtc_y
);
1876 drm_modeset_lock_all(dev
);
1877 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1878 plane_req
->crtc_x
, plane_req
->crtc_y
,
1879 plane_req
->crtc_w
, plane_req
->crtc_h
,
1880 plane_req
->src_x
, plane_req
->src_y
,
1881 plane_req
->src_w
, plane_req
->src_h
);
1888 drm_modeset_unlock_all(dev
);
1892 drm_framebuffer_unreference(fb
);
1894 drm_framebuffer_unreference(old_fb
);
1900 * drm_mode_set_config_internal - helper to call ->set_config
1901 * @set: modeset config to set
1903 * This is a little helper to wrap internal calls to the ->set_config driver
1904 * interface. The only thing it adds is correct refcounting dance.
1906 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
1908 struct drm_crtc
*crtc
= set
->crtc
;
1909 struct drm_framebuffer
*fb
, *old_fb
;
1915 ret
= crtc
->funcs
->set_config(set
);
1918 drm_framebuffer_unreference(old_fb
);
1920 drm_framebuffer_reference(fb
);
1925 EXPORT_SYMBOL(drm_mode_set_config_internal
);
1928 * drm_mode_setcrtc - set CRTC configuration
1929 * @dev: drm device for the ioctl
1930 * @data: data pointer for the ioctl
1931 * @file_priv: drm file for the ioctl call
1933 * Build a new CRTC configuration based on user request.
1935 * Called by the user via ioctl.
1938 * Zero on success, errno on failure.
1940 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1941 struct drm_file
*file_priv
)
1943 struct drm_mode_config
*config
= &dev
->mode_config
;
1944 struct drm_mode_crtc
*crtc_req
= data
;
1945 struct drm_mode_object
*obj
;
1946 struct drm_crtc
*crtc
;
1947 struct drm_connector
**connector_set
= NULL
, *connector
;
1948 struct drm_framebuffer
*fb
= NULL
;
1949 struct drm_display_mode
*mode
= NULL
;
1950 struct drm_mode_set set
;
1951 uint32_t __user
*set_connectors_ptr
;
1955 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1958 /* For some reason crtc x/y offsets are signed internally. */
1959 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
1962 drm_modeset_lock_all(dev
);
1963 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1964 DRM_MODE_OBJECT_CRTC
);
1966 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1970 crtc
= obj_to_crtc(obj
);
1971 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1973 if (crtc_req
->mode_valid
) {
1974 int hdisplay
, vdisplay
;
1975 /* If we have a mode we need a framebuffer. */
1976 /* If we pass -1, set the mode with the currently bound fb */
1977 if (crtc_req
->fb_id
== -1) {
1979 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
1984 /* Make refcounting symmetric with the lookup path. */
1985 drm_framebuffer_reference(fb
);
1987 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
1989 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1996 mode
= drm_mode_create(dev
);
2002 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2004 DRM_DEBUG_KMS("Invalid mode\n");
2008 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2010 hdisplay
= mode
->hdisplay
;
2011 vdisplay
= mode
->vdisplay
;
2013 if (crtc
->invert_dimensions
)
2014 swap(hdisplay
, vdisplay
);
2016 if (hdisplay
> fb
->width
||
2017 vdisplay
> fb
->height
||
2018 crtc_req
->x
> fb
->width
- hdisplay
||
2019 crtc_req
->y
> fb
->height
- vdisplay
) {
2020 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2021 fb
->width
, fb
->height
,
2022 hdisplay
, vdisplay
, crtc_req
->x
, crtc_req
->y
,
2023 crtc
->invert_dimensions
? " (inverted)" : "");
2029 if (crtc_req
->count_connectors
== 0 && mode
) {
2030 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2035 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2036 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2037 crtc_req
->count_connectors
);
2042 if (crtc_req
->count_connectors
> 0) {
2045 /* Avoid unbounded kernel memory allocation */
2046 if (crtc_req
->count_connectors
> config
->num_connector
) {
2051 connector_set
= kmalloc(crtc_req
->count_connectors
*
2052 sizeof(struct drm_connector
*),
2054 if (!connector_set
) {
2059 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2060 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2061 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2066 obj
= drm_mode_object_find(dev
, out_id
,
2067 DRM_MODE_OBJECT_CONNECTOR
);
2069 DRM_DEBUG_KMS("Connector id %d unknown\n",
2074 connector
= obj_to_connector(obj
);
2075 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2077 drm_get_connector_name(connector
));
2079 connector_set
[i
] = connector
;
2084 set
.x
= crtc_req
->x
;
2085 set
.y
= crtc_req
->y
;
2087 set
.connectors
= connector_set
;
2088 set
.num_connectors
= crtc_req
->count_connectors
;
2090 ret
= drm_mode_set_config_internal(&set
);
2094 drm_framebuffer_unreference(fb
);
2096 kfree(connector_set
);
2097 drm_mode_destroy(dev
, mode
);
2098 drm_modeset_unlock_all(dev
);
2102 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2103 void *data
, struct drm_file
*file_priv
)
2105 struct drm_mode_cursor
*req
= data
;
2106 struct drm_mode_object
*obj
;
2107 struct drm_crtc
*crtc
;
2110 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2113 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2116 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2118 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2121 crtc
= obj_to_crtc(obj
);
2123 mutex_lock(&crtc
->mutex
);
2124 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2125 if (!crtc
->funcs
->cursor_set
) {
2129 /* Turns off the cursor if handle is 0 */
2130 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2131 req
->width
, req
->height
);
2134 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2135 if (crtc
->funcs
->cursor_move
) {
2136 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2143 mutex_unlock(&crtc
->mutex
);
2148 /* Original addfb only supported RGB formats, so figure out which one */
2149 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2155 fmt
= DRM_FORMAT_C8
;
2159 fmt
= DRM_FORMAT_XRGB1555
;
2161 fmt
= DRM_FORMAT_RGB565
;
2164 fmt
= DRM_FORMAT_RGB888
;
2168 fmt
= DRM_FORMAT_XRGB8888
;
2169 else if (depth
== 30)
2170 fmt
= DRM_FORMAT_XRGB2101010
;
2172 fmt
= DRM_FORMAT_ARGB8888
;
2175 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2176 fmt
= DRM_FORMAT_XRGB8888
;
2182 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2185 * drm_mode_addfb - add an FB to the graphics configuration
2186 * @dev: drm device for the ioctl
2187 * @data: data pointer for the ioctl
2188 * @file_priv: drm file for the ioctl call
2190 * Add a new FB to the specified CRTC, given a user request.
2192 * Called by the user via ioctl.
2195 * Zero on success, errno on failure.
2197 int drm_mode_addfb(struct drm_device
*dev
,
2198 void *data
, struct drm_file
*file_priv
)
2200 struct drm_mode_fb_cmd
*or = data
;
2201 struct drm_mode_fb_cmd2 r
= {};
2202 struct drm_mode_config
*config
= &dev
->mode_config
;
2203 struct drm_framebuffer
*fb
;
2206 /* Use new struct with format internally */
2207 r
.fb_id
= or->fb_id
;
2208 r
.width
= or->width
;
2209 r
.height
= or->height
;
2210 r
.pitches
[0] = or->pitch
;
2211 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2212 r
.handles
[0] = or->handle
;
2214 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2217 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2220 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2223 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2225 DRM_DEBUG_KMS("could not create framebuffer\n");
2229 mutex_lock(&file_priv
->fbs_lock
);
2230 or->fb_id
= fb
->base
.id
;
2231 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2232 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2233 mutex_unlock(&file_priv
->fbs_lock
);
2238 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2240 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2244 case DRM_FORMAT_RGB332
:
2245 case DRM_FORMAT_BGR233
:
2246 case DRM_FORMAT_XRGB4444
:
2247 case DRM_FORMAT_XBGR4444
:
2248 case DRM_FORMAT_RGBX4444
:
2249 case DRM_FORMAT_BGRX4444
:
2250 case DRM_FORMAT_ARGB4444
:
2251 case DRM_FORMAT_ABGR4444
:
2252 case DRM_FORMAT_RGBA4444
:
2253 case DRM_FORMAT_BGRA4444
:
2254 case DRM_FORMAT_XRGB1555
:
2255 case DRM_FORMAT_XBGR1555
:
2256 case DRM_FORMAT_RGBX5551
:
2257 case DRM_FORMAT_BGRX5551
:
2258 case DRM_FORMAT_ARGB1555
:
2259 case DRM_FORMAT_ABGR1555
:
2260 case DRM_FORMAT_RGBA5551
:
2261 case DRM_FORMAT_BGRA5551
:
2262 case DRM_FORMAT_RGB565
:
2263 case DRM_FORMAT_BGR565
:
2264 case DRM_FORMAT_RGB888
:
2265 case DRM_FORMAT_BGR888
:
2266 case DRM_FORMAT_XRGB8888
:
2267 case DRM_FORMAT_XBGR8888
:
2268 case DRM_FORMAT_RGBX8888
:
2269 case DRM_FORMAT_BGRX8888
:
2270 case DRM_FORMAT_ARGB8888
:
2271 case DRM_FORMAT_ABGR8888
:
2272 case DRM_FORMAT_RGBA8888
:
2273 case DRM_FORMAT_BGRA8888
:
2274 case DRM_FORMAT_XRGB2101010
:
2275 case DRM_FORMAT_XBGR2101010
:
2276 case DRM_FORMAT_RGBX1010102
:
2277 case DRM_FORMAT_BGRX1010102
:
2278 case DRM_FORMAT_ARGB2101010
:
2279 case DRM_FORMAT_ABGR2101010
:
2280 case DRM_FORMAT_RGBA1010102
:
2281 case DRM_FORMAT_BGRA1010102
:
2282 case DRM_FORMAT_YUYV
:
2283 case DRM_FORMAT_YVYU
:
2284 case DRM_FORMAT_UYVY
:
2285 case DRM_FORMAT_VYUY
:
2286 case DRM_FORMAT_AYUV
:
2287 case DRM_FORMAT_NV12
:
2288 case DRM_FORMAT_NV21
:
2289 case DRM_FORMAT_NV16
:
2290 case DRM_FORMAT_NV61
:
2291 case DRM_FORMAT_NV24
:
2292 case DRM_FORMAT_NV42
:
2293 case DRM_FORMAT_YUV410
:
2294 case DRM_FORMAT_YVU410
:
2295 case DRM_FORMAT_YUV411
:
2296 case DRM_FORMAT_YVU411
:
2297 case DRM_FORMAT_YUV420
:
2298 case DRM_FORMAT_YVU420
:
2299 case DRM_FORMAT_YUV422
:
2300 case DRM_FORMAT_YVU422
:
2301 case DRM_FORMAT_YUV444
:
2302 case DRM_FORMAT_YVU444
:
2309 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2311 int ret
, hsub
, vsub
, num_planes
, i
;
2313 ret
= format_check(r
);
2315 DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2319 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2320 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2321 num_planes
= drm_format_num_planes(r
->pixel_format
);
2323 if (r
->width
== 0 || r
->width
% hsub
) {
2324 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2328 if (r
->height
== 0 || r
->height
% vsub
) {
2329 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2333 for (i
= 0; i
< num_planes
; i
++) {
2334 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2335 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2336 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2338 if (!r
->handles
[i
]) {
2339 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2343 if ((uint64_t) width
* cpp
> UINT_MAX
)
2346 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2349 if (r
->pitches
[i
] < width
* cpp
) {
2350 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2359 * drm_mode_addfb2 - add an FB to the graphics configuration
2360 * @dev: drm device for the ioctl
2361 * @data: data pointer for the ioctl
2362 * @file_priv: drm file for the ioctl call
2364 * Add a new FB to the specified CRTC, given a user request with format.
2366 * Called by the user via ioctl.
2369 * Zero on success, errno on failure.
2371 int drm_mode_addfb2(struct drm_device
*dev
,
2372 void *data
, struct drm_file
*file_priv
)
2374 struct drm_mode_fb_cmd2
*r
= data
;
2375 struct drm_mode_config
*config
= &dev
->mode_config
;
2376 struct drm_framebuffer
*fb
;
2379 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2382 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2383 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2387 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2388 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2389 r
->width
, config
->min_width
, config
->max_width
);
2392 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2393 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2394 r
->height
, config
->min_height
, config
->max_height
);
2398 ret
= framebuffer_check(r
);
2402 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2404 DRM_DEBUG_KMS("could not create framebuffer\n");
2408 mutex_lock(&file_priv
->fbs_lock
);
2409 r
->fb_id
= fb
->base
.id
;
2410 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2411 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2412 mutex_unlock(&file_priv
->fbs_lock
);
2419 * drm_mode_rmfb - remove an FB from the configuration
2420 * @dev: drm device for the ioctl
2421 * @data: data pointer for the ioctl
2422 * @file_priv: drm file for the ioctl call
2424 * Remove the FB specified by the user.
2426 * Called by the user via ioctl.
2429 * Zero on success, errno on failure.
2431 int drm_mode_rmfb(struct drm_device
*dev
,
2432 void *data
, struct drm_file
*file_priv
)
2434 struct drm_framebuffer
*fb
= NULL
;
2435 struct drm_framebuffer
*fbl
= NULL
;
2436 uint32_t *id
= data
;
2439 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2442 mutex_lock(&file_priv
->fbs_lock
);
2443 mutex_lock(&dev
->mode_config
.fb_lock
);
2444 fb
= __drm_framebuffer_lookup(dev
, *id
);
2448 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2454 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2455 __drm_framebuffer_unregister(dev
, fb
);
2457 list_del_init(&fb
->filp_head
);
2458 mutex_unlock(&dev
->mode_config
.fb_lock
);
2459 mutex_unlock(&file_priv
->fbs_lock
);
2461 drm_framebuffer_remove(fb
);
2466 mutex_unlock(&dev
->mode_config
.fb_lock
);
2467 mutex_unlock(&file_priv
->fbs_lock
);
2473 * drm_mode_getfb - get FB info
2474 * @dev: drm device for the ioctl
2475 * @data: data pointer for the ioctl
2476 * @file_priv: drm file for the ioctl call
2478 * Lookup the FB given its ID and return info about it.
2480 * Called by the user via ioctl.
2483 * Zero on success, errno on failure.
2485 int drm_mode_getfb(struct drm_device
*dev
,
2486 void *data
, struct drm_file
*file_priv
)
2488 struct drm_mode_fb_cmd
*r
= data
;
2489 struct drm_framebuffer
*fb
;
2492 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2495 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2499 r
->height
= fb
->height
;
2500 r
->width
= fb
->width
;
2501 r
->depth
= fb
->depth
;
2502 r
->bpp
= fb
->bits_per_pixel
;
2503 r
->pitch
= fb
->pitches
[0];
2504 if (fb
->funcs
->create_handle
)
2505 ret
= fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2509 drm_framebuffer_unreference(fb
);
2514 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2515 void *data
, struct drm_file
*file_priv
)
2517 struct drm_clip_rect __user
*clips_ptr
;
2518 struct drm_clip_rect
*clips
= NULL
;
2519 struct drm_mode_fb_dirty_cmd
*r
= data
;
2520 struct drm_framebuffer
*fb
;
2525 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2528 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2532 num_clips
= r
->num_clips
;
2533 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2535 if (!num_clips
!= !clips_ptr
) {
2540 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2542 /* If userspace annotates copy, clips must come in pairs */
2543 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2548 if (num_clips
&& clips_ptr
) {
2549 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2553 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2559 ret
= copy_from_user(clips
, clips_ptr
,
2560 num_clips
* sizeof(*clips
));
2567 if (fb
->funcs
->dirty
) {
2568 drm_modeset_lock_all(dev
);
2569 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2571 drm_modeset_unlock_all(dev
);
2579 drm_framebuffer_unreference(fb
);
2586 * drm_fb_release - remove and free the FBs on this file
2587 * @priv: drm file for the ioctl
2589 * Destroy all the FBs associated with @filp.
2591 * Called by the user via ioctl.
2594 * Zero on success, errno on failure.
2596 void drm_fb_release(struct drm_file
*priv
)
2598 struct drm_device
*dev
= priv
->minor
->dev
;
2599 struct drm_framebuffer
*fb
, *tfb
;
2601 mutex_lock(&priv
->fbs_lock
);
2602 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2604 mutex_lock(&dev
->mode_config
.fb_lock
);
2605 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2606 __drm_framebuffer_unregister(dev
, fb
);
2607 mutex_unlock(&dev
->mode_config
.fb_lock
);
2609 list_del_init(&fb
->filp_head
);
2611 /* This will also drop the fpriv->fbs reference. */
2612 drm_framebuffer_remove(fb
);
2614 mutex_unlock(&priv
->fbs_lock
);
2617 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2618 const char *name
, int num_values
)
2620 struct drm_property
*property
= NULL
;
2623 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2628 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2629 if (!property
->values
)
2633 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2637 property
->flags
= flags
;
2638 property
->num_values
= num_values
;
2639 INIT_LIST_HEAD(&property
->enum_blob_list
);
2642 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2643 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2646 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2649 kfree(property
->values
);
2653 EXPORT_SYMBOL(drm_property_create
);
2655 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2657 const struct drm_prop_enum_list
*props
,
2660 struct drm_property
*property
;
2663 flags
|= DRM_MODE_PROP_ENUM
;
2665 property
= drm_property_create(dev
, flags
, name
, num_values
);
2669 for (i
= 0; i
< num_values
; i
++) {
2670 ret
= drm_property_add_enum(property
, i
,
2674 drm_property_destroy(dev
, property
);
2681 EXPORT_SYMBOL(drm_property_create_enum
);
2683 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2684 int flags
, const char *name
,
2685 const struct drm_prop_enum_list
*props
,
2688 struct drm_property
*property
;
2691 flags
|= DRM_MODE_PROP_BITMASK
;
2693 property
= drm_property_create(dev
, flags
, name
, num_values
);
2697 for (i
= 0; i
< num_values
; i
++) {
2698 ret
= drm_property_add_enum(property
, i
,
2702 drm_property_destroy(dev
, property
);
2709 EXPORT_SYMBOL(drm_property_create_bitmask
);
2711 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2713 uint64_t min
, uint64_t max
)
2715 struct drm_property
*property
;
2717 flags
|= DRM_MODE_PROP_RANGE
;
2719 property
= drm_property_create(dev
, flags
, name
, 2);
2723 property
->values
[0] = min
;
2724 property
->values
[1] = max
;
2728 EXPORT_SYMBOL(drm_property_create_range
);
2730 int drm_property_add_enum(struct drm_property
*property
, int index
,
2731 uint64_t value
, const char *name
)
2733 struct drm_property_enum
*prop_enum
;
2735 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
2739 * Bitmask enum properties have the additional constraint of values
2742 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
2745 if (!list_empty(&property
->enum_blob_list
)) {
2746 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2747 if (prop_enum
->value
== value
) {
2748 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2749 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2755 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2759 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2760 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2761 prop_enum
->value
= value
;
2763 property
->values
[index
] = value
;
2764 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2767 EXPORT_SYMBOL(drm_property_add_enum
);
2769 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2771 struct drm_property_enum
*prop_enum
, *pt
;
2773 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2774 list_del(&prop_enum
->head
);
2778 if (property
->num_values
)
2779 kfree(property
->values
);
2780 drm_mode_object_put(dev
, &property
->base
);
2781 list_del(&property
->head
);
2784 EXPORT_SYMBOL(drm_property_destroy
);
2786 void drm_object_attach_property(struct drm_mode_object
*obj
,
2787 struct drm_property
*property
,
2790 int count
= obj
->properties
->count
;
2792 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
2793 WARN(1, "Failed to attach object property (type: 0x%x). Please "
2794 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
2795 "you see this message on the same object type.\n",
2800 obj
->properties
->ids
[count
] = property
->base
.id
;
2801 obj
->properties
->values
[count
] = init_val
;
2802 obj
->properties
->count
++;
2804 EXPORT_SYMBOL(drm_object_attach_property
);
2806 int drm_object_property_set_value(struct drm_mode_object
*obj
,
2807 struct drm_property
*property
, uint64_t val
)
2811 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2812 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2813 obj
->properties
->values
[i
] = val
;
2820 EXPORT_SYMBOL(drm_object_property_set_value
);
2822 int drm_object_property_get_value(struct drm_mode_object
*obj
,
2823 struct drm_property
*property
, uint64_t *val
)
2827 for (i
= 0; i
< obj
->properties
->count
; i
++) {
2828 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
2829 *val
= obj
->properties
->values
[i
];
2836 EXPORT_SYMBOL(drm_object_property_get_value
);
2838 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2839 void *data
, struct drm_file
*file_priv
)
2841 struct drm_mode_object
*obj
;
2842 struct drm_mode_get_property
*out_resp
= data
;
2843 struct drm_property
*property
;
2846 int value_count
= 0;
2849 struct drm_property_enum
*prop_enum
;
2850 struct drm_mode_property_enum __user
*enum_ptr
;
2851 struct drm_property_blob
*prop_blob
;
2852 uint32_t __user
*blob_id_ptr
;
2853 uint64_t __user
*values_ptr
;
2854 uint32_t __user
*blob_length_ptr
;
2856 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2859 drm_modeset_lock_all(dev
);
2860 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2865 property
= obj_to_property(obj
);
2867 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
2868 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2870 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2871 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2875 value_count
= property
->num_values
;
2877 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2878 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2879 out_resp
->flags
= property
->flags
;
2881 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2882 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
2883 for (i
= 0; i
< value_count
; i
++) {
2884 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2890 out_resp
->count_values
= value_count
;
2892 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
2893 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2895 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2896 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2898 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2903 if (copy_to_user(&enum_ptr
[copied
].name
,
2904 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2911 out_resp
->count_enum_blobs
= enum_count
;
2914 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2915 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2917 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2918 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
2920 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2921 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2926 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2934 out_resp
->count_enum_blobs
= blob_count
;
2937 drm_modeset_unlock_all(dev
);
2941 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2944 struct drm_property_blob
*blob
;
2947 if (!length
|| !data
)
2950 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2954 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2960 blob
->length
= length
;
2962 memcpy(blob
->data
, data
, length
);
2964 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2968 static void drm_property_destroy_blob(struct drm_device
*dev
,
2969 struct drm_property_blob
*blob
)
2971 drm_mode_object_put(dev
, &blob
->base
);
2972 list_del(&blob
->head
);
2976 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2977 void *data
, struct drm_file
*file_priv
)
2979 struct drm_mode_object
*obj
;
2980 struct drm_mode_get_blob
*out_resp
= data
;
2981 struct drm_property_blob
*blob
;
2983 void __user
*blob_ptr
;
2985 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2988 drm_modeset_lock_all(dev
);
2989 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2994 blob
= obj_to_blob(obj
);
2996 if (out_resp
->length
== blob
->length
) {
2997 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
2998 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3003 out_resp
->length
= blob
->length
;
3006 drm_modeset_unlock_all(dev
);
3010 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3013 struct drm_device
*dev
= connector
->dev
;
3016 if (connector
->edid_blob_ptr
)
3017 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3019 /* Delete edid, when there is none. */
3021 connector
->edid_blob_ptr
= NULL
;
3022 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3026 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3027 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3029 if (!connector
->edid_blob_ptr
)
3032 ret
= drm_object_property_set_value(&connector
->base
,
3033 dev
->mode_config
.edid_property
,
3034 connector
->edid_blob_ptr
->base
.id
);
3038 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3040 static bool drm_property_change_is_valid(struct drm_property
*property
,
3043 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3045 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3046 if (value
< property
->values
[0] || value
> property
->values
[1])
3049 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3051 uint64_t valid_mask
= 0;
3052 for (i
= 0; i
< property
->num_values
; i
++)
3053 valid_mask
|= (1ULL << property
->values
[i
]);
3054 return !(value
& ~valid_mask
);
3055 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3056 /* Only the driver knows */
3060 for (i
= 0; i
< property
->num_values
; i
++)
3061 if (property
->values
[i
] == value
)
3067 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3068 void *data
, struct drm_file
*file_priv
)
3070 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3071 struct drm_mode_obj_set_property obj_set_prop
= {
3072 .value
= conn_set_prop
->value
,
3073 .prop_id
= conn_set_prop
->prop_id
,
3074 .obj_id
= conn_set_prop
->connector_id
,
3075 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3078 /* It does all the locking and checking we need */
3079 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3082 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3083 struct drm_property
*property
,
3087 struct drm_connector
*connector
= obj_to_connector(obj
);
3089 /* Do DPMS ourselves */
3090 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3091 if (connector
->funcs
->dpms
)
3092 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3094 } else if (connector
->funcs
->set_property
)
3095 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3097 /* store the property value if successful */
3099 drm_object_property_set_value(&connector
->base
, property
, value
);
3103 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3104 struct drm_property
*property
,
3108 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3110 if (crtc
->funcs
->set_property
)
3111 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3113 drm_object_property_set_value(obj
, property
, value
);
3118 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3119 struct drm_property
*property
,
3123 struct drm_plane
*plane
= obj_to_plane(obj
);
3125 if (plane
->funcs
->set_property
)
3126 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3128 drm_object_property_set_value(obj
, property
, value
);
3133 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3134 struct drm_file
*file_priv
)
3136 struct drm_mode_obj_get_properties
*arg
= data
;
3137 struct drm_mode_object
*obj
;
3141 int props_count
= 0;
3142 uint32_t __user
*props_ptr
;
3143 uint64_t __user
*prop_values_ptr
;
3145 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3148 drm_modeset_lock_all(dev
);
3150 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3155 if (!obj
->properties
) {
3160 props_count
= obj
->properties
->count
;
3162 /* This ioctl is called twice, once to determine how much space is
3163 * needed, and the 2nd time to fill it. */
3164 if ((arg
->count_props
>= props_count
) && props_count
) {
3166 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3167 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3168 (arg
->prop_values_ptr
);
3169 for (i
= 0; i
< props_count
; i
++) {
3170 if (put_user(obj
->properties
->ids
[i
],
3171 props_ptr
+ copied
)) {
3175 if (put_user(obj
->properties
->values
[i
],
3176 prop_values_ptr
+ copied
)) {
3183 arg
->count_props
= props_count
;
3185 drm_modeset_unlock_all(dev
);
3189 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3190 struct drm_file
*file_priv
)
3192 struct drm_mode_obj_set_property
*arg
= data
;
3193 struct drm_mode_object
*arg_obj
;
3194 struct drm_mode_object
*prop_obj
;
3195 struct drm_property
*property
;
3199 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3202 drm_modeset_lock_all(dev
);
3204 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3207 if (!arg_obj
->properties
)
3210 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3211 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3214 if (i
== arg_obj
->properties
->count
)
3217 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3218 DRM_MODE_OBJECT_PROPERTY
);
3221 property
= obj_to_property(prop_obj
);
3223 if (!drm_property_change_is_valid(property
, arg
->value
))
3226 switch (arg_obj
->type
) {
3227 case DRM_MODE_OBJECT_CONNECTOR
:
3228 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3231 case DRM_MODE_OBJECT_CRTC
:
3232 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3234 case DRM_MODE_OBJECT_PLANE
:
3235 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3240 drm_modeset_unlock_all(dev
);
3244 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3245 struct drm_encoder
*encoder
)
3249 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3250 if (connector
->encoder_ids
[i
] == 0) {
3251 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3257 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3259 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3260 struct drm_encoder
*encoder
)
3263 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3264 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3265 connector
->encoder_ids
[i
] = 0;
3266 if (connector
->encoder
== encoder
)
3267 connector
->encoder
= NULL
;
3272 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3274 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3277 crtc
->gamma_size
= gamma_size
;
3279 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3280 if (!crtc
->gamma_store
) {
3281 crtc
->gamma_size
= 0;
3287 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3289 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3290 void *data
, struct drm_file
*file_priv
)
3292 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3293 struct drm_mode_object
*obj
;
3294 struct drm_crtc
*crtc
;
3295 void *r_base
, *g_base
, *b_base
;
3299 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3302 drm_modeset_lock_all(dev
);
3303 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3308 crtc
= obj_to_crtc(obj
);
3310 if (crtc
->funcs
->gamma_set
== NULL
) {
3315 /* memcpy into gamma store */
3316 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3321 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3322 r_base
= crtc
->gamma_store
;
3323 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3328 g_base
= r_base
+ size
;
3329 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3334 b_base
= g_base
+ size
;
3335 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3340 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3343 drm_modeset_unlock_all(dev
);
3348 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3349 void *data
, struct drm_file
*file_priv
)
3351 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3352 struct drm_mode_object
*obj
;
3353 struct drm_crtc
*crtc
;
3354 void *r_base
, *g_base
, *b_base
;
3358 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3361 drm_modeset_lock_all(dev
);
3362 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3367 crtc
= obj_to_crtc(obj
);
3369 /* memcpy into gamma store */
3370 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3375 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3376 r_base
= crtc
->gamma_store
;
3377 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3382 g_base
= r_base
+ size
;
3383 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3388 b_base
= g_base
+ size
;
3389 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3394 drm_modeset_unlock_all(dev
);
3398 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3399 void *data
, struct drm_file
*file_priv
)
3401 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3402 struct drm_mode_object
*obj
;
3403 struct drm_crtc
*crtc
;
3404 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
3405 struct drm_pending_vblank_event
*e
= NULL
;
3406 unsigned long flags
;
3407 int hdisplay
, vdisplay
;
3410 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3411 page_flip
->reserved
!= 0)
3414 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3417 crtc
= obj_to_crtc(obj
);
3419 mutex_lock(&crtc
->mutex
);
3420 if (crtc
->fb
== NULL
) {
3421 /* The framebuffer is currently unbound, presumably
3422 * due to a hotplug event, that userspace has not
3429 if (crtc
->funcs
->page_flip
== NULL
)
3432 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
3436 hdisplay
= crtc
->mode
.hdisplay
;
3437 vdisplay
= crtc
->mode
.vdisplay
;
3439 if (crtc
->invert_dimensions
)
3440 swap(hdisplay
, vdisplay
);
3442 if (hdisplay
> fb
->width
||
3443 vdisplay
> fb
->height
||
3444 crtc
->x
> fb
->width
- hdisplay
||
3445 crtc
->y
> fb
->height
- vdisplay
) {
3446 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
3447 fb
->width
, fb
->height
, hdisplay
, vdisplay
, crtc
->x
, crtc
->y
,
3448 crtc
->invert_dimensions
? " (inverted)" : "");
3453 if (crtc
->fb
->pixel_format
!= fb
->pixel_format
) {
3454 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
3459 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3461 spin_lock_irqsave(&dev
->event_lock
, flags
);
3462 if (file_priv
->event_space
< sizeof e
->event
) {
3463 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3466 file_priv
->event_space
-= sizeof e
->event
;
3467 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3469 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3471 spin_lock_irqsave(&dev
->event_lock
, flags
);
3472 file_priv
->event_space
+= sizeof e
->event
;
3473 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3477 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3478 e
->event
.base
.length
= sizeof e
->event
;
3479 e
->event
.user_data
= page_flip
->user_data
;
3480 e
->base
.event
= &e
->event
.base
;
3481 e
->base
.file_priv
= file_priv
;
3483 (void (*) (struct drm_pending_event
*)) kfree
;
3487 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3489 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3490 spin_lock_irqsave(&dev
->event_lock
, flags
);
3491 file_priv
->event_space
+= sizeof e
->event
;
3492 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3495 /* Keep the old fb, don't unref it. */
3499 * Warn if the driver hasn't properly updated the crtc->fb
3500 * field to reflect that the new framebuffer is now used.
3501 * Failing to do so will screw with the reference counting
3504 WARN_ON(crtc
->fb
!= fb
);
3505 /* Unref only the old framebuffer. */
3511 drm_framebuffer_unreference(fb
);
3513 drm_framebuffer_unreference(old_fb
);
3514 mutex_unlock(&crtc
->mutex
);
3519 void drm_mode_config_reset(struct drm_device
*dev
)
3521 struct drm_crtc
*crtc
;
3522 struct drm_encoder
*encoder
;
3523 struct drm_connector
*connector
;
3525 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3526 if (crtc
->funcs
->reset
)
3527 crtc
->funcs
->reset(crtc
);
3529 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3530 if (encoder
->funcs
->reset
)
3531 encoder
->funcs
->reset(encoder
);
3533 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3534 connector
->status
= connector_status_unknown
;
3536 if (connector
->funcs
->reset
)
3537 connector
->funcs
->reset(connector
);
3540 EXPORT_SYMBOL(drm_mode_config_reset
);
3542 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3543 void *data
, struct drm_file
*file_priv
)
3545 struct drm_mode_create_dumb
*args
= data
;
3547 if (!dev
->driver
->dumb_create
)
3549 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3552 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3553 void *data
, struct drm_file
*file_priv
)
3555 struct drm_mode_map_dumb
*args
= data
;
3557 /* call driver ioctl to get mmap offset */
3558 if (!dev
->driver
->dumb_map_offset
)
3561 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3564 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3565 void *data
, struct drm_file
*file_priv
)
3567 struct drm_mode_destroy_dumb
*args
= data
;
3569 if (!dev
->driver
->dumb_destroy
)
3572 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3576 * Just need to support RGB formats here for compat with code that doesn't
3577 * use pixel formats directly yet.
3579 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3584 case DRM_FORMAT_RGB332
:
3585 case DRM_FORMAT_BGR233
:
3589 case DRM_FORMAT_XRGB1555
:
3590 case DRM_FORMAT_XBGR1555
:
3591 case DRM_FORMAT_RGBX5551
:
3592 case DRM_FORMAT_BGRX5551
:
3593 case DRM_FORMAT_ARGB1555
:
3594 case DRM_FORMAT_ABGR1555
:
3595 case DRM_FORMAT_RGBA5551
:
3596 case DRM_FORMAT_BGRA5551
:
3600 case DRM_FORMAT_RGB565
:
3601 case DRM_FORMAT_BGR565
:
3605 case DRM_FORMAT_RGB888
:
3606 case DRM_FORMAT_BGR888
:
3610 case DRM_FORMAT_XRGB8888
:
3611 case DRM_FORMAT_XBGR8888
:
3612 case DRM_FORMAT_RGBX8888
:
3613 case DRM_FORMAT_BGRX8888
:
3617 case DRM_FORMAT_XRGB2101010
:
3618 case DRM_FORMAT_XBGR2101010
:
3619 case DRM_FORMAT_RGBX1010102
:
3620 case DRM_FORMAT_BGRX1010102
:
3621 case DRM_FORMAT_ARGB2101010
:
3622 case DRM_FORMAT_ABGR2101010
:
3623 case DRM_FORMAT_RGBA1010102
:
3624 case DRM_FORMAT_BGRA1010102
:
3628 case DRM_FORMAT_ARGB8888
:
3629 case DRM_FORMAT_ABGR8888
:
3630 case DRM_FORMAT_RGBA8888
:
3631 case DRM_FORMAT_BGRA8888
:
3636 DRM_DEBUG_KMS("unsupported pixel format\n");
3642 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
3645 * drm_format_num_planes - get the number of planes for format
3646 * @format: pixel format (DRM_FORMAT_*)
3649 * The number of planes used by the specified pixel format.
3651 int drm_format_num_planes(uint32_t format
)
3654 case DRM_FORMAT_YUV410
:
3655 case DRM_FORMAT_YVU410
:
3656 case DRM_FORMAT_YUV411
:
3657 case DRM_FORMAT_YVU411
:
3658 case DRM_FORMAT_YUV420
:
3659 case DRM_FORMAT_YVU420
:
3660 case DRM_FORMAT_YUV422
:
3661 case DRM_FORMAT_YVU422
:
3662 case DRM_FORMAT_YUV444
:
3663 case DRM_FORMAT_YVU444
:
3665 case DRM_FORMAT_NV12
:
3666 case DRM_FORMAT_NV21
:
3667 case DRM_FORMAT_NV16
:
3668 case DRM_FORMAT_NV61
:
3669 case DRM_FORMAT_NV24
:
3670 case DRM_FORMAT_NV42
:
3676 EXPORT_SYMBOL(drm_format_num_planes
);
3679 * drm_format_plane_cpp - determine the bytes per pixel value
3680 * @format: pixel format (DRM_FORMAT_*)
3681 * @plane: plane index
3684 * The bytes per pixel value for the specified plane.
3686 int drm_format_plane_cpp(uint32_t format
, int plane
)
3691 if (plane
>= drm_format_num_planes(format
))
3695 case DRM_FORMAT_YUYV
:
3696 case DRM_FORMAT_YVYU
:
3697 case DRM_FORMAT_UYVY
:
3698 case DRM_FORMAT_VYUY
:
3700 case DRM_FORMAT_NV12
:
3701 case DRM_FORMAT_NV21
:
3702 case DRM_FORMAT_NV16
:
3703 case DRM_FORMAT_NV61
:
3704 case DRM_FORMAT_NV24
:
3705 case DRM_FORMAT_NV42
:
3706 return plane
? 2 : 1;
3707 case DRM_FORMAT_YUV410
:
3708 case DRM_FORMAT_YVU410
:
3709 case DRM_FORMAT_YUV411
:
3710 case DRM_FORMAT_YVU411
:
3711 case DRM_FORMAT_YUV420
:
3712 case DRM_FORMAT_YVU420
:
3713 case DRM_FORMAT_YUV422
:
3714 case DRM_FORMAT_YVU422
:
3715 case DRM_FORMAT_YUV444
:
3716 case DRM_FORMAT_YVU444
:
3719 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
3723 EXPORT_SYMBOL(drm_format_plane_cpp
);
3726 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
3727 * @format: pixel format (DRM_FORMAT_*)
3730 * The horizontal chroma subsampling factor for the
3731 * specified pixel format.
3733 int drm_format_horz_chroma_subsampling(uint32_t format
)
3736 case DRM_FORMAT_YUV411
:
3737 case DRM_FORMAT_YVU411
:
3738 case DRM_FORMAT_YUV410
:
3739 case DRM_FORMAT_YVU410
:
3741 case DRM_FORMAT_YUYV
:
3742 case DRM_FORMAT_YVYU
:
3743 case DRM_FORMAT_UYVY
:
3744 case DRM_FORMAT_VYUY
:
3745 case DRM_FORMAT_NV12
:
3746 case DRM_FORMAT_NV21
:
3747 case DRM_FORMAT_NV16
:
3748 case DRM_FORMAT_NV61
:
3749 case DRM_FORMAT_YUV422
:
3750 case DRM_FORMAT_YVU422
:
3751 case DRM_FORMAT_YUV420
:
3752 case DRM_FORMAT_YVU420
:
3758 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
3761 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
3762 * @format: pixel format (DRM_FORMAT_*)
3765 * The vertical chroma subsampling factor for the
3766 * specified pixel format.
3768 int drm_format_vert_chroma_subsampling(uint32_t format
)
3771 case DRM_FORMAT_YUV410
:
3772 case DRM_FORMAT_YVU410
:
3774 case DRM_FORMAT_YUV420
:
3775 case DRM_FORMAT_YVU420
:
3776 case DRM_FORMAT_NV12
:
3777 case DRM_FORMAT_NV21
:
3783 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);
3786 * drm_mode_config_init - initialize DRM mode_configuration structure
3789 * Initialize @dev's mode_config structure, used for tracking the graphics
3790 * configuration of @dev.
3792 * Since this initializes the modeset locks, no locking is possible. Which is no
3793 * problem, since this should happen single threaded at init time. It is the
3794 * driver's problem to ensure this guarantee.
3797 void drm_mode_config_init(struct drm_device
*dev
)
3799 mutex_init(&dev
->mode_config
.mutex
);
3800 mutex_init(&dev
->mode_config
.idr_mutex
);
3801 mutex_init(&dev
->mode_config
.fb_lock
);
3802 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
3803 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
3804 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
3805 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
3806 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
3807 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
3808 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
3809 idr_init(&dev
->mode_config
.crtc_idr
);
3811 drm_modeset_lock_all(dev
);
3812 drm_mode_create_standard_connector_properties(dev
);
3813 drm_modeset_unlock_all(dev
);
3815 /* Just to be sure */
3816 dev
->mode_config
.num_fb
= 0;
3817 dev
->mode_config
.num_connector
= 0;
3818 dev
->mode_config
.num_crtc
= 0;
3819 dev
->mode_config
.num_encoder
= 0;
3821 EXPORT_SYMBOL(drm_mode_config_init
);
3824 * drm_mode_config_cleanup - free up DRM mode_config info
3827 * Free up all the connectors and CRTCs associated with this DRM device, then
3828 * free up the framebuffers and associated buffer objects.
3830 * Note that since this /should/ happen single-threaded at driver/device
3831 * teardown time, no locking is required. It's the driver's job to ensure that
3832 * this guarantee actually holds true.
3834 * FIXME: cleanup any dangling user buffer objects too
3836 void drm_mode_config_cleanup(struct drm_device
*dev
)
3838 struct drm_connector
*connector
, *ot
;
3839 struct drm_crtc
*crtc
, *ct
;
3840 struct drm_encoder
*encoder
, *enct
;
3841 struct drm_framebuffer
*fb
, *fbt
;
3842 struct drm_property
*property
, *pt
;
3843 struct drm_property_blob
*blob
, *bt
;
3844 struct drm_plane
*plane
, *plt
;
3846 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
3848 encoder
->funcs
->destroy(encoder
);
3851 list_for_each_entry_safe(connector
, ot
,
3852 &dev
->mode_config
.connector_list
, head
) {
3853 connector
->funcs
->destroy(connector
);
3856 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
3858 drm_property_destroy(dev
, property
);
3861 list_for_each_entry_safe(blob
, bt
, &dev
->mode_config
.property_blob_list
,
3863 drm_property_destroy_blob(dev
, blob
);
3867 * Single-threaded teardown context, so it's not required to grab the
3868 * fb_lock to protect against concurrent fb_list access. Contrary, it
3869 * would actually deadlock with the drm_framebuffer_cleanup function.
3871 * Also, if there are any framebuffers left, that's a driver leak now,
3872 * so politely WARN about this.
3874 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
3875 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
3876 drm_framebuffer_remove(fb
);
3879 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
3881 plane
->funcs
->destroy(plane
);
3884 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
3885 crtc
->funcs
->destroy(crtc
);
3888 idr_destroy(&dev
->mode_config
.crtc_idr
);
3890 EXPORT_SYMBOL(drm_mode_config_cleanup
);