2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/ctype.h>
33 #include <linux/list.h>
34 #include <linux/slab.h>
35 #include <linux/export.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_edid.h>
39 #include <drm/drm_fourcc.h>
41 #include "drm_crtc_internal.h"
44 * drm_modeset_lock_all - take all modeset locks
47 * This function takes all modeset locks, suitable where a more fine-grained
48 * scheme isn't (yet) implemented. Locks must be dropped with
49 * drm_modeset_unlock_all.
51 void drm_modeset_lock_all(struct drm_device
*dev
)
53 struct drm_crtc
*crtc
;
55 mutex_lock(&dev
->mode_config
.mutex
);
57 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
58 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
60 EXPORT_SYMBOL(drm_modeset_lock_all
);
63 * drm_modeset_unlock_all - drop all modeset locks
66 * This function drop all modeset locks taken by drm_modeset_lock_all.
68 void drm_modeset_unlock_all(struct drm_device
*dev
)
70 struct drm_crtc
*crtc
;
72 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
73 mutex_unlock(&crtc
->mutex
);
75 mutex_unlock(&dev
->mode_config
.mutex
);
77 EXPORT_SYMBOL(drm_modeset_unlock_all
);
80 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
83 * Useful as a debug assert.
85 void drm_warn_on_modeset_not_all_locked(struct drm_device
*dev
)
87 struct drm_crtc
*crtc
;
89 /* Locking is currently fubar in the panic handler. */
93 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
94 WARN_ON(!mutex_is_locked(&crtc
->mutex
));
96 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
98 EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked
);
100 /* Avoid boilerplate. I'm tired of typing. */
101 #define DRM_ENUM_NAME_FN(fnname, list) \
102 const char *fnname(int val) \
105 for (i = 0; i < ARRAY_SIZE(list); i++) { \
106 if (list[i].type == val) \
107 return list[i].name; \
109 return "(unknown)"; \
115 static const struct drm_prop_enum_list drm_dpms_enum_list
[] =
116 { { DRM_MODE_DPMS_ON
, "On" },
117 { DRM_MODE_DPMS_STANDBY
, "Standby" },
118 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
119 { DRM_MODE_DPMS_OFF
, "Off" }
122 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
124 static const struct drm_prop_enum_list drm_plane_type_enum_list
[] =
126 { DRM_PLANE_TYPE_OVERLAY
, "Overlay" },
127 { DRM_PLANE_TYPE_PRIMARY
, "Primary" },
128 { DRM_PLANE_TYPE_CURSOR
, "Cursor" },
132 * Optional properties
134 static const struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
136 { DRM_MODE_SCALE_NONE
, "None" },
137 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
138 { DRM_MODE_SCALE_CENTER
, "Center" },
139 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
143 * Non-global properties, but "required" for certain connectors.
145 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
147 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
148 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
149 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
152 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
154 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
156 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
157 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
158 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
161 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
162 drm_dvi_i_subconnector_enum_list
)
164 static const struct drm_prop_enum_list drm_tv_select_enum_list
[] =
166 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
167 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
168 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
169 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
170 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
173 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
175 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
177 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
178 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
179 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
180 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
181 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
184 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
185 drm_tv_subconnector_enum_list
)
187 static const struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
188 { DRM_MODE_DIRTY_OFF
, "Off" },
189 { DRM_MODE_DIRTY_ON
, "On" },
190 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
193 struct drm_conn_prop_enum_list
{
200 * Connector and encoder types.
202 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
203 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown" },
204 { DRM_MODE_CONNECTOR_VGA
, "VGA" },
205 { DRM_MODE_CONNECTOR_DVII
, "DVI-I" },
206 { DRM_MODE_CONNECTOR_DVID
, "DVI-D" },
207 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A" },
208 { DRM_MODE_CONNECTOR_Composite
, "Composite" },
209 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO" },
210 { DRM_MODE_CONNECTOR_LVDS
, "LVDS" },
211 { DRM_MODE_CONNECTOR_Component
, "Component" },
212 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN" },
213 { DRM_MODE_CONNECTOR_DisplayPort
, "DP" },
214 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A" },
215 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B" },
216 { DRM_MODE_CONNECTOR_TV
, "TV" },
217 { DRM_MODE_CONNECTOR_eDP
, "eDP" },
218 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual" },
219 { DRM_MODE_CONNECTOR_DSI
, "DSI" },
222 static const struct drm_prop_enum_list drm_encoder_enum_list
[] =
223 { { DRM_MODE_ENCODER_NONE
, "None" },
224 { DRM_MODE_ENCODER_DAC
, "DAC" },
225 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
226 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
227 { DRM_MODE_ENCODER_TVDAC
, "TV" },
228 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
229 { DRM_MODE_ENCODER_DSI
, "DSI" },
230 { DRM_MODE_ENCODER_DPMST
, "DP MST" },
233 static const struct drm_prop_enum_list drm_subpixel_enum_list
[] =
235 { SubPixelUnknown
, "Unknown" },
236 { SubPixelHorizontalRGB
, "Horizontal RGB" },
237 { SubPixelHorizontalBGR
, "Horizontal BGR" },
238 { SubPixelVerticalRGB
, "Vertical RGB" },
239 { SubPixelVerticalBGR
, "Vertical BGR" },
240 { SubPixelNone
, "None" },
243 void drm_connector_ida_init(void)
247 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
248 ida_init(&drm_connector_enum_list
[i
].ida
);
251 void drm_connector_ida_destroy(void)
255 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
256 ida_destroy(&drm_connector_enum_list
[i
].ida
);
260 * drm_get_encoder_name - return a string for encoder
261 * @encoder: the encoder to get name for
263 const char *drm_get_encoder_name(const struct drm_encoder
*encoder
)
265 return encoder
->name
;
267 EXPORT_SYMBOL(drm_get_encoder_name
);
270 * drm_get_connector_name - return a string for connector
271 * @connector: the connector to get name for
273 const char *drm_get_connector_name(const struct drm_connector
*connector
)
275 return connector
->name
;
277 EXPORT_SYMBOL(drm_get_connector_name
);
280 * drm_get_connector_status_name - return a string for connector status
281 * @status: connector status to compute name of
283 * In contrast to the other drm_get_*_name functions this one here returns a
284 * const pointer and hence is threadsafe.
286 const char *drm_get_connector_status_name(enum drm_connector_status status
)
288 if (status
== connector_status_connected
)
290 else if (status
== connector_status_disconnected
)
291 return "disconnected";
295 EXPORT_SYMBOL(drm_get_connector_status_name
);
298 * drm_get_subpixel_order_name - return a string for a given subpixel enum
299 * @order: enum of subpixel_order
301 * Note you could abuse this and return something out of bounds, but that
302 * would be a caller error. No unscrubbed user data should make it here.
304 const char *drm_get_subpixel_order_name(enum subpixel_order order
)
306 return drm_subpixel_enum_list
[order
].name
;
308 EXPORT_SYMBOL(drm_get_subpixel_order_name
);
310 static char printable_char(int c
)
312 return isascii(c
) && isprint(c
) ? c
: '?';
316 * drm_get_format_name - return a string for drm fourcc format
317 * @format: format to compute name of
319 * Note that the buffer used by this function is globally shared and owned by
320 * the function itself.
322 * FIXME: This isn't really multithreading safe.
324 const char *drm_get_format_name(uint32_t format
)
328 snprintf(buf
, sizeof(buf
),
329 "%c%c%c%c %s-endian (0x%08x)",
330 printable_char(format
& 0xff),
331 printable_char((format
>> 8) & 0xff),
332 printable_char((format
>> 16) & 0xff),
333 printable_char((format
>> 24) & 0x7f),
334 format
& DRM_FORMAT_BIG_ENDIAN
? "big" : "little",
339 EXPORT_SYMBOL(drm_get_format_name
);
342 * drm_mode_object_get - allocate a new modeset identifier
344 * @obj: object pointer, used to generate unique ID
345 * @obj_type: object type
347 * Create a unique identifier based on @ptr in @dev's identifier space. Used
348 * for tracking modes, CRTCs and connectors. Note that despite the _get postfix
349 * modeset identifiers are _not_ reference counted. Hence don't use this for
350 * reference counted modeset objects like framebuffers.
353 * New unique (relative to other objects in @dev) integer identifier for the
356 int drm_mode_object_get(struct drm_device
*dev
,
357 struct drm_mode_object
*obj
, uint32_t obj_type
)
361 mutex_lock(&dev
->mode_config
.idr_mutex
);
362 ret
= idr_alloc(&dev
->mode_config
.crtc_idr
, obj
, 1, 0, GFP_KERNEL
);
365 * Set up the object linking under the protection of the idr
366 * lock so that other users can't see inconsistent state.
369 obj
->type
= obj_type
;
371 mutex_unlock(&dev
->mode_config
.idr_mutex
);
373 return ret
< 0 ? ret
: 0;
377 * drm_mode_object_put - free a modeset identifer
379 * @object: object to free
381 * Free @id from @dev's unique identifier pool. Note that despite the _get
382 * postfix modeset identifiers are _not_ reference counted. Hence don't use this
383 * for reference counted modeset objects like framebuffers.
385 void drm_mode_object_put(struct drm_device
*dev
,
386 struct drm_mode_object
*object
)
388 mutex_lock(&dev
->mode_config
.idr_mutex
);
389 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
390 mutex_unlock(&dev
->mode_config
.idr_mutex
);
394 * drm_mode_object_find - look up a drm object with static lifetime
396 * @id: id of the mode object
397 * @type: type of the mode object
399 * Note that framebuffers cannot be looked up with this functions - since those
400 * are reference counted, they need special treatment.
402 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
403 uint32_t id
, uint32_t type
)
405 struct drm_mode_object
*obj
= NULL
;
407 /* Framebuffers are reference counted and need their own lookup
409 WARN_ON(type
== DRM_MODE_OBJECT_FB
);
411 mutex_lock(&dev
->mode_config
.idr_mutex
);
412 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
413 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
415 mutex_unlock(&dev
->mode_config
.idr_mutex
);
419 EXPORT_SYMBOL(drm_mode_object_find
);
422 * drm_framebuffer_init - initialize a framebuffer
424 * @fb: framebuffer to be initialized
425 * @funcs: ... with these functions
427 * Allocates an ID for the framebuffer's parent mode object, sets its mode
428 * functions & device file and adds it to the master fd list.
431 * This functions publishes the fb and makes it available for concurrent access
432 * by other users. Which means by this point the fb _must_ be fully set up -
433 * since all the fb attributes are invariant over its lifetime, no further
434 * locking but only correct reference counting is required.
437 * Zero on success, error code on failure.
439 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
440 const struct drm_framebuffer_funcs
*funcs
)
444 mutex_lock(&dev
->mode_config
.fb_lock
);
445 kref_init(&fb
->refcount
);
446 INIT_LIST_HEAD(&fb
->filp_head
);
450 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
454 /* Grab the idr reference. */
455 drm_framebuffer_reference(fb
);
457 dev
->mode_config
.num_fb
++;
458 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
460 mutex_unlock(&dev
->mode_config
.fb_lock
);
464 EXPORT_SYMBOL(drm_framebuffer_init
);
466 static void drm_framebuffer_free(struct kref
*kref
)
468 struct drm_framebuffer
*fb
=
469 container_of(kref
, struct drm_framebuffer
, refcount
);
470 fb
->funcs
->destroy(fb
);
473 static struct drm_framebuffer
*__drm_framebuffer_lookup(struct drm_device
*dev
,
476 struct drm_mode_object
*obj
= NULL
;
477 struct drm_framebuffer
*fb
;
479 mutex_lock(&dev
->mode_config
.idr_mutex
);
480 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
481 if (!obj
|| (obj
->type
!= DRM_MODE_OBJECT_FB
) || (obj
->id
!= id
))
485 mutex_unlock(&dev
->mode_config
.idr_mutex
);
491 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
493 * @id: id of the fb object
495 * If successful, this grabs an additional reference to the framebuffer -
496 * callers need to make sure to eventually unreference the returned framebuffer
497 * again, using @drm_framebuffer_unreference.
499 struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
502 struct drm_framebuffer
*fb
;
504 mutex_lock(&dev
->mode_config
.fb_lock
);
505 fb
= __drm_framebuffer_lookup(dev
, id
);
507 drm_framebuffer_reference(fb
);
508 mutex_unlock(&dev
->mode_config
.fb_lock
);
512 EXPORT_SYMBOL(drm_framebuffer_lookup
);
515 * drm_framebuffer_unreference - unref a framebuffer
516 * @fb: framebuffer to unref
518 * This functions decrements the fb's refcount and frees it if it drops to zero.
520 void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
522 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
523 kref_put(&fb
->refcount
, drm_framebuffer_free
);
525 EXPORT_SYMBOL(drm_framebuffer_unreference
);
528 * drm_framebuffer_reference - incr the fb refcnt
531 * This functions increments the fb's refcount.
533 void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
535 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
536 kref_get(&fb
->refcount
);
538 EXPORT_SYMBOL(drm_framebuffer_reference
);
540 static void drm_framebuffer_free_bug(struct kref
*kref
)
545 static void __drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
547 DRM_DEBUG("FB ID: %d\n", fb
->base
.id
);
548 kref_put(&fb
->refcount
, drm_framebuffer_free_bug
);
551 /* dev->mode_config.fb_lock must be held! */
552 static void __drm_framebuffer_unregister(struct drm_device
*dev
,
553 struct drm_framebuffer
*fb
)
555 mutex_lock(&dev
->mode_config
.idr_mutex
);
556 idr_remove(&dev
->mode_config
.crtc_idr
, fb
->base
.id
);
557 mutex_unlock(&dev
->mode_config
.idr_mutex
);
561 __drm_framebuffer_unreference(fb
);
565 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
566 * @fb: fb to unregister
568 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
569 * those used for fbdev. Note that the caller must hold a reference of it's own,
570 * i.e. the object may not be destroyed through this call (since it'll lead to a
571 * locking inversion).
573 void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
)
575 struct drm_device
*dev
= fb
->dev
;
577 mutex_lock(&dev
->mode_config
.fb_lock
);
578 /* Mark fb as reaped and drop idr ref. */
579 __drm_framebuffer_unregister(dev
, fb
);
580 mutex_unlock(&dev
->mode_config
.fb_lock
);
582 EXPORT_SYMBOL(drm_framebuffer_unregister_private
);
585 * drm_framebuffer_cleanup - remove a framebuffer object
586 * @fb: framebuffer to remove
588 * Cleanup framebuffer. This function is intended to be used from the drivers
589 * ->destroy callback. It can also be used to clean up driver private
590 * framebuffers embedded into a larger structure.
592 * Note that this function does not remove the fb from active usuage - if it is
593 * still used anywhere, hilarity can ensue since userspace could call getfb on
594 * the id and get back -EINVAL. Obviously no concern at driver unload time.
596 * Also, the framebuffer will not be removed from the lookup idr - for
597 * user-created framebuffers this will happen in in the rmfb ioctl. For
598 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
599 * drm_framebuffer_unregister_private.
601 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
603 struct drm_device
*dev
= fb
->dev
;
605 mutex_lock(&dev
->mode_config
.fb_lock
);
607 dev
->mode_config
.num_fb
--;
608 mutex_unlock(&dev
->mode_config
.fb_lock
);
610 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
613 * drm_framebuffer_remove - remove and unreference a framebuffer object
614 * @fb: framebuffer to remove
616 * Scans all the CRTCs and planes in @dev's mode_config. If they're
617 * using @fb, removes it, setting it to NULL. Then drops the reference to the
618 * passed-in framebuffer. Might take the modeset locks.
620 * Note that this function optimizes the cleanup away if the caller holds the
621 * last reference to the framebuffer. It is also guaranteed to not take the
622 * modeset locks in this case.
624 void drm_framebuffer_remove(struct drm_framebuffer
*fb
)
626 struct drm_device
*dev
= fb
->dev
;
627 struct drm_crtc
*crtc
;
628 struct drm_plane
*plane
;
629 struct drm_mode_set set
;
632 WARN_ON(!list_empty(&fb
->filp_head
));
635 * drm ABI mandates that we remove any deleted framebuffers from active
636 * useage. But since most sane clients only remove framebuffers they no
637 * longer need, try to optimize this away.
639 * Since we're holding a reference ourselves, observing a refcount of 1
640 * means that we're the last holder and can skip it. Also, the refcount
641 * can never increase from 1 again, so we don't need any barriers or
644 * Note that userspace could try to race with use and instate a new
645 * usage _after_ we've cleared all current ones. End result will be an
646 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
649 if (atomic_read(&fb
->refcount
.refcount
) > 1) {
650 drm_modeset_lock_all(dev
);
651 /* remove from any CRTC */
652 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
653 if (crtc
->primary
->fb
== fb
) {
654 /* should turn off the crtc */
655 memset(&set
, 0, sizeof(struct drm_mode_set
));
658 ret
= drm_mode_set_config_internal(&set
);
660 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
664 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
666 drm_plane_force_disable(plane
);
668 drm_modeset_unlock_all(dev
);
671 drm_framebuffer_unreference(fb
);
673 EXPORT_SYMBOL(drm_framebuffer_remove
);
676 * drm_crtc_init_with_planes - Initialise a new CRTC object with
677 * specified primary and cursor planes.
679 * @crtc: CRTC object to init
680 * @primary: Primary plane for CRTC
681 * @cursor: Cursor plane for CRTC
682 * @funcs: callbacks for the new CRTC
684 * Inits a new object created as base part of a driver crtc object.
687 * Zero on success, error code on failure.
689 int drm_crtc_init_with_planes(struct drm_device
*dev
, struct drm_crtc
*crtc
,
690 struct drm_plane
*primary
,
692 const struct drm_crtc_funcs
*funcs
)
698 crtc
->invert_dimensions
= false;
700 drm_modeset_lock_all(dev
);
701 mutex_init(&crtc
->mutex
);
702 mutex_lock_nest_lock(&crtc
->mutex
, &dev
->mode_config
.mutex
);
704 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
708 crtc
->base
.properties
= &crtc
->properties
;
710 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
711 dev
->mode_config
.num_crtc
++;
713 crtc
->primary
= primary
;
715 primary
->possible_crtcs
= 1 << drm_crtc_index(crtc
);
718 drm_modeset_unlock_all(dev
);
722 EXPORT_SYMBOL(drm_crtc_init_with_planes
);
725 * drm_crtc_cleanup - Clean up the core crtc usage
726 * @crtc: CRTC to cleanup
728 * This function cleans up @crtc and removes it from the DRM mode setting
729 * core. Note that the function does *not* free the crtc structure itself,
730 * this is the responsibility of the caller.
732 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
734 struct drm_device
*dev
= crtc
->dev
;
736 kfree(crtc
->gamma_store
);
737 crtc
->gamma_store
= NULL
;
739 drm_mode_object_put(dev
, &crtc
->base
);
740 list_del(&crtc
->head
);
741 dev
->mode_config
.num_crtc
--;
743 EXPORT_SYMBOL(drm_crtc_cleanup
);
746 * drm_crtc_index - find the index of a registered CRTC
747 * @crtc: CRTC to find index for
749 * Given a registered CRTC, return the index of that CRTC within a DRM
750 * device's list of CRTCs.
752 unsigned int drm_crtc_index(struct drm_crtc
*crtc
)
754 unsigned int index
= 0;
755 struct drm_crtc
*tmp
;
757 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
) {
766 EXPORT_SYMBOL(drm_crtc_index
);
769 * drm_mode_remove - remove and free a mode
770 * @connector: connector list to modify
771 * @mode: mode to remove
773 * Remove @mode from @connector's mode list, then free it.
775 static void drm_mode_remove(struct drm_connector
*connector
,
776 struct drm_display_mode
*mode
)
778 list_del(&mode
->head
);
779 drm_mode_destroy(connector
->dev
, mode
);
783 * drm_connector_init - Init a preallocated connector
785 * @connector: the connector to init
786 * @funcs: callbacks for this connector
787 * @connector_type: user visible type of the connector
789 * Initialises a preallocated connector. Connectors should be
790 * subclassed as part of driver connector objects.
793 * Zero on success, error code on failure.
795 int drm_connector_init(struct drm_device
*dev
,
796 struct drm_connector
*connector
,
797 const struct drm_connector_funcs
*funcs
,
801 struct ida
*connector_ida
=
802 &drm_connector_enum_list
[connector_type
].ida
;
804 drm_modeset_lock_all(dev
);
806 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
810 connector
->base
.properties
= &connector
->properties
;
811 connector
->dev
= dev
;
812 connector
->funcs
= funcs
;
813 connector
->connector_type
= connector_type
;
814 connector
->connector_type_id
=
815 ida_simple_get(connector_ida
, 1, 0, GFP_KERNEL
);
816 if (connector
->connector_type_id
< 0) {
817 ret
= connector
->connector_type_id
;
821 kasprintf(GFP_KERNEL
, "%s-%d",
822 drm_connector_enum_list
[connector_type
].name
,
823 connector
->connector_type_id
);
824 if (!connector
->name
) {
829 INIT_LIST_HEAD(&connector
->probed_modes
);
830 INIT_LIST_HEAD(&connector
->modes
);
831 connector
->edid_blob_ptr
= NULL
;
832 connector
->status
= connector_status_unknown
;
834 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
835 dev
->mode_config
.num_connector
++;
837 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
838 drm_object_attach_property(&connector
->base
,
839 dev
->mode_config
.edid_property
,
842 drm_object_attach_property(&connector
->base
,
843 dev
->mode_config
.dpms_property
, 0);
847 drm_mode_object_put(dev
, &connector
->base
);
850 drm_modeset_unlock_all(dev
);
854 EXPORT_SYMBOL(drm_connector_init
);
857 * drm_connector_cleanup - cleans up an initialised connector
858 * @connector: connector to cleanup
860 * Cleans up the connector but doesn't free the object.
862 void drm_connector_cleanup(struct drm_connector
*connector
)
864 struct drm_device
*dev
= connector
->dev
;
865 struct drm_display_mode
*mode
, *t
;
867 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
868 drm_mode_remove(connector
, mode
);
870 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
871 drm_mode_remove(connector
, mode
);
873 ida_remove(&drm_connector_enum_list
[connector
->connector_type
].ida
,
874 connector
->connector_type_id
);
876 drm_mode_object_put(dev
, &connector
->base
);
877 kfree(connector
->name
);
878 connector
->name
= NULL
;
879 list_del(&connector
->head
);
880 dev
->mode_config
.num_connector
--;
882 EXPORT_SYMBOL(drm_connector_cleanup
);
885 * drm_connector_unplug_all - unregister connector userspace interfaces
888 * This function unregisters all connector userspace interfaces in sysfs. Should
889 * be call when the device is disconnected, e.g. from an usb driver's
890 * ->disconnect callback.
892 void drm_connector_unplug_all(struct drm_device
*dev
)
894 struct drm_connector
*connector
;
896 /* taking the mode config mutex ends up in a clash with sysfs */
897 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
898 drm_sysfs_connector_remove(connector
);
901 EXPORT_SYMBOL(drm_connector_unplug_all
);
904 * drm_bridge_init - initialize a drm transcoder/bridge
906 * @bridge: transcoder/bridge to set up
907 * @funcs: bridge function table
909 * Initialises a preallocated bridge. Bridges should be
910 * subclassed as part of driver connector objects.
913 * Zero on success, error code on failure.
915 int drm_bridge_init(struct drm_device
*dev
, struct drm_bridge
*bridge
,
916 const struct drm_bridge_funcs
*funcs
)
920 drm_modeset_lock_all(dev
);
922 ret
= drm_mode_object_get(dev
, &bridge
->base
, DRM_MODE_OBJECT_BRIDGE
);
927 bridge
->funcs
= funcs
;
929 list_add_tail(&bridge
->head
, &dev
->mode_config
.bridge_list
);
930 dev
->mode_config
.num_bridge
++;
933 drm_modeset_unlock_all(dev
);
936 EXPORT_SYMBOL(drm_bridge_init
);
939 * drm_bridge_cleanup - cleans up an initialised bridge
940 * @bridge: bridge to cleanup
942 * Cleans up the bridge but doesn't free the object.
944 void drm_bridge_cleanup(struct drm_bridge
*bridge
)
946 struct drm_device
*dev
= bridge
->dev
;
948 drm_modeset_lock_all(dev
);
949 drm_mode_object_put(dev
, &bridge
->base
);
950 list_del(&bridge
->head
);
951 dev
->mode_config
.num_bridge
--;
952 drm_modeset_unlock_all(dev
);
954 EXPORT_SYMBOL(drm_bridge_cleanup
);
957 * drm_encoder_init - Init a preallocated encoder
959 * @encoder: the encoder to init
960 * @funcs: callbacks for this encoder
961 * @encoder_type: user visible type of the encoder
963 * Initialises a preallocated encoder. Encoder should be
964 * subclassed as part of driver encoder objects.
967 * Zero on success, error code on failure.
969 int drm_encoder_init(struct drm_device
*dev
,
970 struct drm_encoder
*encoder
,
971 const struct drm_encoder_funcs
*funcs
,
976 drm_modeset_lock_all(dev
);
978 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
983 encoder
->encoder_type
= encoder_type
;
984 encoder
->funcs
= funcs
;
985 encoder
->name
= kasprintf(GFP_KERNEL
, "%s-%d",
986 drm_encoder_enum_list
[encoder_type
].name
,
988 if (!encoder
->name
) {
993 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
994 dev
->mode_config
.num_encoder
++;
998 drm_mode_object_put(dev
, &encoder
->base
);
1001 drm_modeset_unlock_all(dev
);
1005 EXPORT_SYMBOL(drm_encoder_init
);
1008 * drm_encoder_cleanup - cleans up an initialised encoder
1009 * @encoder: encoder to cleanup
1011 * Cleans up the encoder but doesn't free the object.
1013 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
1015 struct drm_device
*dev
= encoder
->dev
;
1016 drm_modeset_lock_all(dev
);
1017 drm_mode_object_put(dev
, &encoder
->base
);
1018 kfree(encoder
->name
);
1019 encoder
->name
= NULL
;
1020 list_del(&encoder
->head
);
1021 dev
->mode_config
.num_encoder
--;
1022 drm_modeset_unlock_all(dev
);
1024 EXPORT_SYMBOL(drm_encoder_cleanup
);
1027 * drm_universal_plane_init - Initialize a new universal plane object
1029 * @plane: plane object to init
1030 * @possible_crtcs: bitmask of possible CRTCs
1031 * @funcs: callbacks for the new plane
1032 * @formats: array of supported formats (%DRM_FORMAT_*)
1033 * @format_count: number of elements in @formats
1034 * @type: type of plane (overlay, primary, cursor)
1036 * Initializes a plane object of type @type.
1039 * Zero on success, error code on failure.
1041 int drm_universal_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
1042 unsigned long possible_crtcs
,
1043 const struct drm_plane_funcs
*funcs
,
1044 const uint32_t *formats
, uint32_t format_count
,
1045 enum drm_plane_type type
)
1049 drm_modeset_lock_all(dev
);
1051 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
1055 plane
->base
.properties
= &plane
->properties
;
1057 plane
->funcs
= funcs
;
1058 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
1060 if (!plane
->format_types
) {
1061 DRM_DEBUG_KMS("out of memory when allocating plane\n");
1062 drm_mode_object_put(dev
, &plane
->base
);
1067 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
1068 plane
->format_count
= format_count
;
1069 plane
->possible_crtcs
= possible_crtcs
;
1072 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
1073 dev
->mode_config
.num_total_plane
++;
1074 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
)
1075 dev
->mode_config
.num_overlay_plane
++;
1077 drm_object_attach_property(&plane
->base
,
1078 dev
->mode_config
.plane_type_property
,
1082 drm_modeset_unlock_all(dev
);
1086 EXPORT_SYMBOL(drm_universal_plane_init
);
1089 * drm_plane_init - Initialize a legacy plane
1091 * @plane: plane object to init
1092 * @possible_crtcs: bitmask of possible CRTCs
1093 * @funcs: callbacks for the new plane
1094 * @formats: array of supported formats (%DRM_FORMAT_*)
1095 * @format_count: number of elements in @formats
1096 * @is_primary: plane type (primary vs overlay)
1098 * Legacy API to initialize a DRM plane.
1100 * New drivers should call drm_universal_plane_init() instead.
1103 * Zero on success, error code on failure.
1105 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
1106 unsigned long possible_crtcs
,
1107 const struct drm_plane_funcs
*funcs
,
1108 const uint32_t *formats
, uint32_t format_count
,
1111 enum drm_plane_type type
;
1113 type
= is_primary
? DRM_PLANE_TYPE_PRIMARY
: DRM_PLANE_TYPE_OVERLAY
;
1114 return drm_universal_plane_init(dev
, plane
, possible_crtcs
, funcs
,
1115 formats
, format_count
, type
);
1117 EXPORT_SYMBOL(drm_plane_init
);
1120 * drm_plane_cleanup - Clean up the core plane usage
1121 * @plane: plane to cleanup
1123 * This function cleans up @plane and removes it from the DRM mode setting
1124 * core. Note that the function does *not* free the plane structure itself,
1125 * this is the responsibility of the caller.
1127 void drm_plane_cleanup(struct drm_plane
*plane
)
1129 struct drm_device
*dev
= plane
->dev
;
1131 drm_modeset_lock_all(dev
);
1132 kfree(plane
->format_types
);
1133 drm_mode_object_put(dev
, &plane
->base
);
1135 BUG_ON(list_empty(&plane
->head
));
1137 list_del(&plane
->head
);
1138 dev
->mode_config
.num_total_plane
--;
1139 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
)
1140 dev
->mode_config
.num_overlay_plane
--;
1141 drm_modeset_unlock_all(dev
);
1143 EXPORT_SYMBOL(drm_plane_cleanup
);
1146 * drm_plane_force_disable - Forcibly disable a plane
1147 * @plane: plane to disable
1149 * Forces the plane to be disabled.
1151 * Used when the plane's current framebuffer is destroyed,
1152 * and when restoring fbdev mode.
1154 void drm_plane_force_disable(struct drm_plane
*plane
)
1156 struct drm_framebuffer
*old_fb
= plane
->fb
;
1162 ret
= plane
->funcs
->disable_plane(plane
);
1164 DRM_ERROR("failed to disable plane with busy fb\n");
1167 /* disconnect the plane from the fb and crtc: */
1168 __drm_framebuffer_unreference(old_fb
);
1172 EXPORT_SYMBOL(drm_plane_force_disable
);
1174 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
1176 struct drm_property
*edid
;
1177 struct drm_property
*dpms
;
1180 * Standard properties (apply to all connectors)
1182 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
1183 DRM_MODE_PROP_IMMUTABLE
,
1185 dev
->mode_config
.edid_property
= edid
;
1187 dpms
= drm_property_create_enum(dev
, 0,
1188 "DPMS", drm_dpms_enum_list
,
1189 ARRAY_SIZE(drm_dpms_enum_list
));
1190 dev
->mode_config
.dpms_property
= dpms
;
1195 static int drm_mode_create_standard_plane_properties(struct drm_device
*dev
)
1197 struct drm_property
*type
;
1200 * Standard properties (apply to all planes)
1202 type
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1203 "type", drm_plane_type_enum_list
,
1204 ARRAY_SIZE(drm_plane_type_enum_list
));
1205 dev
->mode_config
.plane_type_property
= type
;
1211 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1214 * Called by a driver the first time a DVI-I connector is made.
1216 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
1218 struct drm_property
*dvi_i_selector
;
1219 struct drm_property
*dvi_i_subconnector
;
1221 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
1225 drm_property_create_enum(dev
, 0,
1226 "select subconnector",
1227 drm_dvi_i_select_enum_list
,
1228 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
1229 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
1231 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1233 drm_dvi_i_subconnector_enum_list
,
1234 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
1235 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
1239 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
1242 * drm_create_tv_properties - create TV specific connector properties
1244 * @num_modes: number of different TV formats (modes) supported
1245 * @modes: array of pointers to strings containing name of each format
1247 * Called by a driver's TV initialization routine, this function creates
1248 * the TV specific connector properties for a given device. Caller is
1249 * responsible for allocating a list of format names and passing them to
1252 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
1255 struct drm_property
*tv_selector
;
1256 struct drm_property
*tv_subconnector
;
1259 if (dev
->mode_config
.tv_select_subconnector_property
)
1263 * Basic connector properties
1265 tv_selector
= drm_property_create_enum(dev
, 0,
1266 "select subconnector",
1267 drm_tv_select_enum_list
,
1268 ARRAY_SIZE(drm_tv_select_enum_list
));
1269 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
1272 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1274 drm_tv_subconnector_enum_list
,
1275 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
1276 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
1279 * Other, TV specific properties: margins & TV modes.
1281 dev
->mode_config
.tv_left_margin_property
=
1282 drm_property_create_range(dev
, 0, "left margin", 0, 100);
1284 dev
->mode_config
.tv_right_margin_property
=
1285 drm_property_create_range(dev
, 0, "right margin", 0, 100);
1287 dev
->mode_config
.tv_top_margin_property
=
1288 drm_property_create_range(dev
, 0, "top margin", 0, 100);
1290 dev
->mode_config
.tv_bottom_margin_property
=
1291 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
1293 dev
->mode_config
.tv_mode_property
=
1294 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
1296 for (i
= 0; i
< num_modes
; i
++)
1297 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1300 dev
->mode_config
.tv_brightness_property
=
1301 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1303 dev
->mode_config
.tv_contrast_property
=
1304 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1306 dev
->mode_config
.tv_flicker_reduction_property
=
1307 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1309 dev
->mode_config
.tv_overscan_property
=
1310 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1312 dev
->mode_config
.tv_saturation_property
=
1313 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1315 dev
->mode_config
.tv_hue_property
=
1316 drm_property_create_range(dev
, 0, "hue", 0, 100);
1320 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1323 * drm_mode_create_scaling_mode_property - create scaling mode property
1326 * Called by a driver the first time it's needed, must be attached to desired
1329 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1331 struct drm_property
*scaling_mode
;
1333 if (dev
->mode_config
.scaling_mode_property
)
1337 drm_property_create_enum(dev
, 0, "scaling mode",
1338 drm_scaling_mode_enum_list
,
1339 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1341 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1345 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1348 * drm_mode_create_dirty_property - create dirty property
1351 * Called by a driver the first time it's needed, must be attached to desired
1354 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
1356 struct drm_property
*dirty_info
;
1358 if (dev
->mode_config
.dirty_info_property
)
1362 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1364 drm_dirty_info_enum_list
,
1365 ARRAY_SIZE(drm_dirty_info_enum_list
));
1366 dev
->mode_config
.dirty_info_property
= dirty_info
;
1370 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
1372 static int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
1374 uint32_t total_objects
= 0;
1376 total_objects
+= dev
->mode_config
.num_crtc
;
1377 total_objects
+= dev
->mode_config
.num_connector
;
1378 total_objects
+= dev
->mode_config
.num_encoder
;
1379 total_objects
+= dev
->mode_config
.num_bridge
;
1381 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
1382 if (!group
->id_list
)
1385 group
->num_crtcs
= 0;
1386 group
->num_connectors
= 0;
1387 group
->num_encoders
= 0;
1388 group
->num_bridges
= 0;
1392 void drm_mode_group_destroy(struct drm_mode_group
*group
)
1394 kfree(group
->id_list
);
1395 group
->id_list
= NULL
;
1399 * NOTE: Driver's shouldn't ever call drm_mode_group_init_legacy_group - it is
1400 * the drm core's responsibility to set up mode control groups.
1402 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
1403 struct drm_mode_group
*group
)
1405 struct drm_crtc
*crtc
;
1406 struct drm_encoder
*encoder
;
1407 struct drm_connector
*connector
;
1408 struct drm_bridge
*bridge
;
1411 if ((ret
= drm_mode_group_init(dev
, group
)))
1414 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
1415 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
1417 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
1418 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
1421 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
1422 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1423 group
->num_connectors
++] = connector
->base
.id
;
1425 list_for_each_entry(bridge
, &dev
->mode_config
.bridge_list
, head
)
1426 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
1427 group
->num_connectors
+ group
->num_bridges
++] =
1432 EXPORT_SYMBOL(drm_mode_group_init_legacy_group
);
1435 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1436 * @out: drm_mode_modeinfo struct to return to the user
1437 * @in: drm_display_mode to use
1439 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1442 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1443 const struct drm_display_mode
*in
)
1445 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1446 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1447 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1448 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1449 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1450 "timing values too large for mode info\n");
1452 out
->clock
= in
->clock
;
1453 out
->hdisplay
= in
->hdisplay
;
1454 out
->hsync_start
= in
->hsync_start
;
1455 out
->hsync_end
= in
->hsync_end
;
1456 out
->htotal
= in
->htotal
;
1457 out
->hskew
= in
->hskew
;
1458 out
->vdisplay
= in
->vdisplay
;
1459 out
->vsync_start
= in
->vsync_start
;
1460 out
->vsync_end
= in
->vsync_end
;
1461 out
->vtotal
= in
->vtotal
;
1462 out
->vscan
= in
->vscan
;
1463 out
->vrefresh
= in
->vrefresh
;
1464 out
->flags
= in
->flags
;
1465 out
->type
= in
->type
;
1466 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1467 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1471 * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
1472 * @out: drm_display_mode to return to the user
1473 * @in: drm_mode_modeinfo to use
1475 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1479 * Zero on success, errno on failure.
1481 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1482 const struct drm_mode_modeinfo
*in
)
1484 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
1487 if ((in
->flags
& DRM_MODE_FLAG_3D_MASK
) > DRM_MODE_FLAG_3D_MAX
)
1490 out
->clock
= in
->clock
;
1491 out
->hdisplay
= in
->hdisplay
;
1492 out
->hsync_start
= in
->hsync_start
;
1493 out
->hsync_end
= in
->hsync_end
;
1494 out
->htotal
= in
->htotal
;
1495 out
->hskew
= in
->hskew
;
1496 out
->vdisplay
= in
->vdisplay
;
1497 out
->vsync_start
= in
->vsync_start
;
1498 out
->vsync_end
= in
->vsync_end
;
1499 out
->vtotal
= in
->vtotal
;
1500 out
->vscan
= in
->vscan
;
1501 out
->vrefresh
= in
->vrefresh
;
1502 out
->flags
= in
->flags
;
1503 out
->type
= in
->type
;
1504 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1505 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1511 * drm_mode_getresources - get graphics configuration
1512 * @dev: drm device for the ioctl
1513 * @data: data pointer for the ioctl
1514 * @file_priv: drm file for the ioctl call
1516 * Construct a set of configuration description structures and return
1517 * them to the user, including CRTC, connector and framebuffer configuration.
1519 * Called by the user via ioctl.
1522 * Zero on success, errno on failure.
1524 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1525 struct drm_file
*file_priv
)
1527 struct drm_mode_card_res
*card_res
= data
;
1528 struct list_head
*lh
;
1529 struct drm_framebuffer
*fb
;
1530 struct drm_connector
*connector
;
1531 struct drm_crtc
*crtc
;
1532 struct drm_encoder
*encoder
;
1534 int connector_count
= 0;
1537 int encoder_count
= 0;
1539 uint32_t __user
*fb_id
;
1540 uint32_t __user
*crtc_id
;
1541 uint32_t __user
*connector_id
;
1542 uint32_t __user
*encoder_id
;
1543 struct drm_mode_group
*mode_group
;
1545 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1549 mutex_lock(&file_priv
->fbs_lock
);
1551 * For the non-control nodes we need to limit the list of resources
1552 * by IDs in the group list for this node
1554 list_for_each(lh
, &file_priv
->fbs
)
1557 /* handle this in 4 parts */
1559 if (card_res
->count_fbs
>= fb_count
) {
1561 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1562 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1563 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1564 mutex_unlock(&file_priv
->fbs_lock
);
1570 card_res
->count_fbs
= fb_count
;
1571 mutex_unlock(&file_priv
->fbs_lock
);
1573 drm_modeset_lock_all(dev
);
1574 if (!drm_is_primary_client(file_priv
)) {
1577 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1580 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1583 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1587 mode_group
= &file_priv
->master
->minor
->mode_group
;
1588 crtc_count
= mode_group
->num_crtcs
;
1589 connector_count
= mode_group
->num_connectors
;
1590 encoder_count
= mode_group
->num_encoders
;
1593 card_res
->max_height
= dev
->mode_config
.max_height
;
1594 card_res
->min_height
= dev
->mode_config
.min_height
;
1595 card_res
->max_width
= dev
->mode_config
.max_width
;
1596 card_res
->min_width
= dev
->mode_config
.min_width
;
1599 if (card_res
->count_crtcs
>= crtc_count
) {
1601 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1603 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1605 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1606 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1613 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1614 if (put_user(mode_group
->id_list
[i
],
1615 crtc_id
+ copied
)) {
1623 card_res
->count_crtcs
= crtc_count
;
1626 if (card_res
->count_encoders
>= encoder_count
) {
1628 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1630 list_for_each_entry(encoder
,
1631 &dev
->mode_config
.encoder_list
,
1633 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1634 drm_get_encoder_name(encoder
));
1635 if (put_user(encoder
->base
.id
, encoder_id
+
1643 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1644 if (put_user(mode_group
->id_list
[i
],
1645 encoder_id
+ copied
)) {
1654 card_res
->count_encoders
= encoder_count
;
1657 if (card_res
->count_connectors
>= connector_count
) {
1659 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1661 list_for_each_entry(connector
,
1662 &dev
->mode_config
.connector_list
,
1664 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1667 if (put_user(connector
->base
.id
,
1668 connector_id
+ copied
)) {
1675 int start
= mode_group
->num_crtcs
+
1676 mode_group
->num_encoders
;
1677 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1678 if (put_user(mode_group
->id_list
[i
],
1679 connector_id
+ copied
)) {
1687 card_res
->count_connectors
= connector_count
;
1689 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1690 card_res
->count_connectors
, card_res
->count_encoders
);
1693 drm_modeset_unlock_all(dev
);
1698 * drm_mode_getcrtc - get CRTC configuration
1699 * @dev: drm device for the ioctl
1700 * @data: data pointer for the ioctl
1701 * @file_priv: drm file for the ioctl call
1703 * Construct a CRTC configuration structure to return to the user.
1705 * Called by the user via ioctl.
1708 * Zero on success, errno on failure.
1710 int drm_mode_getcrtc(struct drm_device
*dev
,
1711 void *data
, struct drm_file
*file_priv
)
1713 struct drm_mode_crtc
*crtc_resp
= data
;
1714 struct drm_crtc
*crtc
;
1715 struct drm_mode_object
*obj
;
1718 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1721 drm_modeset_lock_all(dev
);
1723 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1724 DRM_MODE_OBJECT_CRTC
);
1729 crtc
= obj_to_crtc(obj
);
1731 crtc_resp
->x
= crtc
->x
;
1732 crtc_resp
->y
= crtc
->y
;
1733 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1734 if (crtc
->primary
->fb
)
1735 crtc_resp
->fb_id
= crtc
->primary
->fb
->base
.id
;
1737 crtc_resp
->fb_id
= 0;
1739 if (crtc
->enabled
) {
1741 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1742 crtc_resp
->mode_valid
= 1;
1745 crtc_resp
->mode_valid
= 0;
1749 drm_modeset_unlock_all(dev
);
1753 static bool drm_mode_expose_to_userspace(const struct drm_display_mode
*mode
,
1754 const struct drm_file
*file_priv
)
1757 * If user-space hasn't configured the driver to expose the stereo 3D
1758 * modes, don't expose them.
1760 if (!file_priv
->stereo_allowed
&& drm_mode_is_stereo(mode
))
1767 * drm_mode_getconnector - get connector configuration
1768 * @dev: drm device for the ioctl
1769 * @data: data pointer for the ioctl
1770 * @file_priv: drm file for the ioctl call
1772 * Construct a connector configuration structure to return to the user.
1774 * Called by the user via ioctl.
1777 * Zero on success, errno on failure.
1779 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1780 struct drm_file
*file_priv
)
1782 struct drm_mode_get_connector
*out_resp
= data
;
1783 struct drm_mode_object
*obj
;
1784 struct drm_connector
*connector
;
1785 struct drm_display_mode
*mode
;
1787 int props_count
= 0;
1788 int encoders_count
= 0;
1792 struct drm_mode_modeinfo u_mode
;
1793 struct drm_mode_modeinfo __user
*mode_ptr
;
1794 uint32_t __user
*prop_ptr
;
1795 uint64_t __user
*prop_values
;
1796 uint32_t __user
*encoder_ptr
;
1798 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1801 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1803 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1805 mutex_lock(&dev
->mode_config
.mutex
);
1807 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1808 DRM_MODE_OBJECT_CONNECTOR
);
1813 connector
= obj_to_connector(obj
);
1815 props_count
= connector
->properties
.count
;
1817 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1818 if (connector
->encoder_ids
[i
] != 0) {
1823 if (out_resp
->count_modes
== 0) {
1824 connector
->funcs
->fill_modes(connector
,
1825 dev
->mode_config
.max_width
,
1826 dev
->mode_config
.max_height
);
1829 /* delayed so we get modes regardless of pre-fill_modes state */
1830 list_for_each_entry(mode
, &connector
->modes
, head
)
1831 if (drm_mode_expose_to_userspace(mode
, file_priv
))
1834 out_resp
->connector_id
= connector
->base
.id
;
1835 out_resp
->connector_type
= connector
->connector_type
;
1836 out_resp
->connector_type_id
= connector
->connector_type_id
;
1837 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1838 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1839 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1840 out_resp
->connection
= connector
->status
;
1841 if (connector
->encoder
)
1842 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1844 out_resp
->encoder_id
= 0;
1847 * This ioctl is called twice, once to determine how much space is
1848 * needed, and the 2nd time to fill it.
1850 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1852 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1853 list_for_each_entry(mode
, &connector
->modes
, head
) {
1854 if (!drm_mode_expose_to_userspace(mode
, file_priv
))
1857 drm_crtc_convert_to_umode(&u_mode
, mode
);
1858 if (copy_to_user(mode_ptr
+ copied
,
1859 &u_mode
, sizeof(u_mode
))) {
1866 out_resp
->count_modes
= mode_count
;
1868 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1870 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1871 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1872 for (i
= 0; i
< connector
->properties
.count
; i
++) {
1873 if (put_user(connector
->properties
.ids
[i
],
1874 prop_ptr
+ copied
)) {
1879 if (put_user(connector
->properties
.values
[i
],
1880 prop_values
+ copied
)) {
1887 out_resp
->count_props
= props_count
;
1889 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1891 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1892 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1893 if (connector
->encoder_ids
[i
] != 0) {
1894 if (put_user(connector
->encoder_ids
[i
],
1895 encoder_ptr
+ copied
)) {
1903 out_resp
->count_encoders
= encoders_count
;
1906 mutex_unlock(&dev
->mode_config
.mutex
);
1912 * drm_mode_getencoder - get encoder configuration
1913 * @dev: drm device for the ioctl
1914 * @data: data pointer for the ioctl
1915 * @file_priv: drm file for the ioctl call
1917 * Construct a encoder configuration structure to return to the user.
1919 * Called by the user via ioctl.
1922 * Zero on success, errno on failure.
1924 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1925 struct drm_file
*file_priv
)
1927 struct drm_mode_get_encoder
*enc_resp
= data
;
1928 struct drm_mode_object
*obj
;
1929 struct drm_encoder
*encoder
;
1932 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1935 drm_modeset_lock_all(dev
);
1936 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1937 DRM_MODE_OBJECT_ENCODER
);
1942 encoder
= obj_to_encoder(obj
);
1945 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1947 enc_resp
->crtc_id
= 0;
1948 enc_resp
->encoder_type
= encoder
->encoder_type
;
1949 enc_resp
->encoder_id
= encoder
->base
.id
;
1950 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1951 enc_resp
->possible_clones
= encoder
->possible_clones
;
1954 drm_modeset_unlock_all(dev
);
1959 * drm_mode_getplane_res - enumerate all plane resources
1962 * @file_priv: DRM file info
1964 * Construct a list of plane ids to return to the user.
1966 * Called by the user via ioctl.
1969 * Zero on success, errno on failure.
1971 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1972 struct drm_file
*file_priv
)
1974 struct drm_mode_get_plane_res
*plane_resp
= data
;
1975 struct drm_mode_config
*config
;
1976 struct drm_plane
*plane
;
1977 uint32_t __user
*plane_ptr
;
1978 int copied
= 0, ret
= 0;
1979 unsigned num_planes
;
1981 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1984 drm_modeset_lock_all(dev
);
1985 config
= &dev
->mode_config
;
1987 if (file_priv
->universal_planes
)
1988 num_planes
= config
->num_total_plane
;
1990 num_planes
= config
->num_overlay_plane
;
1993 * This ioctl is called twice, once to determine how much space is
1994 * needed, and the 2nd time to fill it.
1997 (plane_resp
->count_planes
>= num_planes
)) {
1998 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
2000 list_for_each_entry(plane
, &config
->plane_list
, head
) {
2002 * Unless userspace set the 'universal planes'
2003 * capability bit, only advertise overlays.
2005 if (plane
->type
!= DRM_PLANE_TYPE_OVERLAY
&&
2006 !file_priv
->universal_planes
)
2009 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
2016 plane_resp
->count_planes
= num_planes
;
2019 drm_modeset_unlock_all(dev
);
2024 * drm_mode_getplane - get plane configuration
2027 * @file_priv: DRM file info
2029 * Construct a plane configuration structure to return to the user.
2031 * Called by the user via ioctl.
2034 * Zero on success, errno on failure.
2036 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
2037 struct drm_file
*file_priv
)
2039 struct drm_mode_get_plane
*plane_resp
= data
;
2040 struct drm_mode_object
*obj
;
2041 struct drm_plane
*plane
;
2042 uint32_t __user
*format_ptr
;
2045 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2048 drm_modeset_lock_all(dev
);
2049 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
2050 DRM_MODE_OBJECT_PLANE
);
2055 plane
= obj_to_plane(obj
);
2058 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
2060 plane_resp
->crtc_id
= 0;
2063 plane_resp
->fb_id
= plane
->fb
->base
.id
;
2065 plane_resp
->fb_id
= 0;
2067 plane_resp
->plane_id
= plane
->base
.id
;
2068 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
2069 plane_resp
->gamma_size
= 0;
2072 * This ioctl is called twice, once to determine how much space is
2073 * needed, and the 2nd time to fill it.
2075 if (plane
->format_count
&&
2076 (plane_resp
->count_format_types
>= plane
->format_count
)) {
2077 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
2078 if (copy_to_user(format_ptr
,
2079 plane
->format_types
,
2080 sizeof(uint32_t) * plane
->format_count
)) {
2085 plane_resp
->count_format_types
= plane
->format_count
;
2088 drm_modeset_unlock_all(dev
);
2093 * drm_mode_setplane - configure a plane's configuration
2095 * @data: ioctl data*
2096 * @file_priv: DRM file info
2098 * Set plane configuration, including placement, fb, scaling, and other factors.
2099 * Or pass a NULL fb to disable.
2102 * Zero on success, errno on failure.
2104 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
2105 struct drm_file
*file_priv
)
2107 struct drm_mode_set_plane
*plane_req
= data
;
2108 struct drm_mode_object
*obj
;
2109 struct drm_plane
*plane
;
2110 struct drm_crtc
*crtc
;
2111 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
2113 unsigned int fb_width
, fb_height
;
2116 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2120 * First, find the plane, crtc, and fb objects. If not available,
2121 * we don't bother to call the driver.
2123 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
2124 DRM_MODE_OBJECT_PLANE
);
2126 DRM_DEBUG_KMS("Unknown plane ID %d\n",
2127 plane_req
->plane_id
);
2130 plane
= obj_to_plane(obj
);
2132 /* No fb means shut it down */
2133 if (!plane_req
->fb_id
) {
2134 drm_modeset_lock_all(dev
);
2136 ret
= plane
->funcs
->disable_plane(plane
);
2143 drm_modeset_unlock_all(dev
);
2147 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
2148 DRM_MODE_OBJECT_CRTC
);
2150 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
2151 plane_req
->crtc_id
);
2155 crtc
= obj_to_crtc(obj
);
2157 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
2159 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
2165 /* Check whether this plane supports the fb pixel format. */
2166 for (i
= 0; i
< plane
->format_count
; i
++)
2167 if (fb
->pixel_format
== plane
->format_types
[i
])
2169 if (i
== plane
->format_count
) {
2170 DRM_DEBUG_KMS("Invalid pixel format %s\n",
2171 drm_get_format_name(fb
->pixel_format
));
2176 fb_width
= fb
->width
<< 16;
2177 fb_height
= fb
->height
<< 16;
2179 /* Make sure source coordinates are inside the fb. */
2180 if (plane_req
->src_w
> fb_width
||
2181 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
2182 plane_req
->src_h
> fb_height
||
2183 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
2184 DRM_DEBUG_KMS("Invalid source coordinates "
2185 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
2186 plane_req
->src_w
>> 16,
2187 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
2188 plane_req
->src_h
>> 16,
2189 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
2190 plane_req
->src_x
>> 16,
2191 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
2192 plane_req
->src_y
>> 16,
2193 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
2198 /* Give drivers some help against integer overflows */
2199 if (plane_req
->crtc_w
> INT_MAX
||
2200 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
2201 plane_req
->crtc_h
> INT_MAX
||
2202 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
2203 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
2204 plane_req
->crtc_w
, plane_req
->crtc_h
,
2205 plane_req
->crtc_x
, plane_req
->crtc_y
);
2210 drm_modeset_lock_all(dev
);
2212 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
2213 plane_req
->crtc_x
, plane_req
->crtc_y
,
2214 plane_req
->crtc_w
, plane_req
->crtc_h
,
2215 plane_req
->src_x
, plane_req
->src_y
,
2216 plane_req
->src_w
, plane_req
->src_h
);
2224 drm_modeset_unlock_all(dev
);
2228 drm_framebuffer_unreference(fb
);
2230 drm_framebuffer_unreference(old_fb
);
2236 * drm_mode_set_config_internal - helper to call ->set_config
2237 * @set: modeset config to set
2239 * This is a little helper to wrap internal calls to the ->set_config driver
2240 * interface. The only thing it adds is correct refcounting dance.
2243 * Zero on success, errno on failure.
2245 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
2247 struct drm_crtc
*crtc
= set
->crtc
;
2248 struct drm_framebuffer
*fb
;
2249 struct drm_crtc
*tmp
;
2253 * NOTE: ->set_config can also disable other crtcs (if we steal all
2254 * connectors from it), hence we need to refcount the fbs across all
2255 * crtcs. Atomic modeset will have saner semantics ...
2257 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
)
2258 tmp
->old_fb
= tmp
->primary
->fb
;
2262 ret
= crtc
->funcs
->set_config(set
);
2264 crtc
->primary
->crtc
= crtc
;
2265 crtc
->primary
->fb
= fb
;
2268 list_for_each_entry(tmp
, &crtc
->dev
->mode_config
.crtc_list
, head
) {
2269 if (tmp
->primary
->fb
)
2270 drm_framebuffer_reference(tmp
->primary
->fb
);
2272 drm_framebuffer_unreference(tmp
->old_fb
);
2277 EXPORT_SYMBOL(drm_mode_set_config_internal
);
2280 * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
2282 * @crtc: CRTC that framebuffer will be displayed on
2285 * @mode: mode that framebuffer will be displayed under
2286 * @fb: framebuffer to check size of
2288 int drm_crtc_check_viewport(const struct drm_crtc
*crtc
,
2290 const struct drm_display_mode
*mode
,
2291 const struct drm_framebuffer
*fb
)
2294 int hdisplay
, vdisplay
;
2296 hdisplay
= mode
->hdisplay
;
2297 vdisplay
= mode
->vdisplay
;
2299 if (drm_mode_is_stereo(mode
)) {
2300 struct drm_display_mode adjusted
= *mode
;
2302 drm_mode_set_crtcinfo(&adjusted
, CRTC_STEREO_DOUBLE
);
2303 hdisplay
= adjusted
.crtc_hdisplay
;
2304 vdisplay
= adjusted
.crtc_vdisplay
;
2307 if (crtc
->invert_dimensions
)
2308 swap(hdisplay
, vdisplay
);
2310 if (hdisplay
> fb
->width
||
2311 vdisplay
> fb
->height
||
2312 x
> fb
->width
- hdisplay
||
2313 y
> fb
->height
- vdisplay
) {
2314 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n",
2315 fb
->width
, fb
->height
, hdisplay
, vdisplay
, x
, y
,
2316 crtc
->invert_dimensions
? " (inverted)" : "");
2322 EXPORT_SYMBOL(drm_crtc_check_viewport
);
2325 * drm_mode_setcrtc - set CRTC configuration
2326 * @dev: drm device for the ioctl
2327 * @data: data pointer for the ioctl
2328 * @file_priv: drm file for the ioctl call
2330 * Build a new CRTC configuration based on user request.
2332 * Called by the user via ioctl.
2335 * Zero on success, errno on failure.
2337 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
2338 struct drm_file
*file_priv
)
2340 struct drm_mode_config
*config
= &dev
->mode_config
;
2341 struct drm_mode_crtc
*crtc_req
= data
;
2342 struct drm_mode_object
*obj
;
2343 struct drm_crtc
*crtc
;
2344 struct drm_connector
**connector_set
= NULL
, *connector
;
2345 struct drm_framebuffer
*fb
= NULL
;
2346 struct drm_display_mode
*mode
= NULL
;
2347 struct drm_mode_set set
;
2348 uint32_t __user
*set_connectors_ptr
;
2352 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2355 /* For some reason crtc x/y offsets are signed internally. */
2356 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
2359 drm_modeset_lock_all(dev
);
2360 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
2361 DRM_MODE_OBJECT_CRTC
);
2363 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
2367 crtc
= obj_to_crtc(obj
);
2368 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
2370 if (crtc_req
->mode_valid
) {
2371 /* If we have a mode we need a framebuffer. */
2372 /* If we pass -1, set the mode with the currently bound fb */
2373 if (crtc_req
->fb_id
== -1) {
2374 if (!crtc
->primary
->fb
) {
2375 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2379 fb
= crtc
->primary
->fb
;
2380 /* Make refcounting symmetric with the lookup path. */
2381 drm_framebuffer_reference(fb
);
2383 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
2385 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2392 mode
= drm_mode_create(dev
);
2398 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
2400 DRM_DEBUG_KMS("Invalid mode\n");
2404 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
2406 ret
= drm_crtc_check_viewport(crtc
, crtc_req
->x
, crtc_req
->y
,
2413 if (crtc_req
->count_connectors
== 0 && mode
) {
2414 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2419 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
2420 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2421 crtc_req
->count_connectors
);
2426 if (crtc_req
->count_connectors
> 0) {
2429 /* Avoid unbounded kernel memory allocation */
2430 if (crtc_req
->count_connectors
> config
->num_connector
) {
2435 connector_set
= kmalloc(crtc_req
->count_connectors
*
2436 sizeof(struct drm_connector
*),
2438 if (!connector_set
) {
2443 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
2444 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
2445 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
2450 obj
= drm_mode_object_find(dev
, out_id
,
2451 DRM_MODE_OBJECT_CONNECTOR
);
2453 DRM_DEBUG_KMS("Connector id %d unknown\n",
2458 connector
= obj_to_connector(obj
);
2459 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2463 connector_set
[i
] = connector
;
2468 set
.x
= crtc_req
->x
;
2469 set
.y
= crtc_req
->y
;
2471 set
.connectors
= connector_set
;
2472 set
.num_connectors
= crtc_req
->count_connectors
;
2474 ret
= drm_mode_set_config_internal(&set
);
2478 drm_framebuffer_unreference(fb
);
2480 kfree(connector_set
);
2481 drm_mode_destroy(dev
, mode
);
2482 drm_modeset_unlock_all(dev
);
2486 static int drm_mode_cursor_common(struct drm_device
*dev
,
2487 struct drm_mode_cursor2
*req
,
2488 struct drm_file
*file_priv
)
2490 struct drm_mode_object
*obj
;
2491 struct drm_crtc
*crtc
;
2494 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2497 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
2500 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2502 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
2505 crtc
= obj_to_crtc(obj
);
2507 mutex_lock(&crtc
->mutex
);
2508 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
2509 if (!crtc
->funcs
->cursor_set
&& !crtc
->funcs
->cursor_set2
) {
2513 /* Turns off the cursor if handle is 0 */
2514 if (crtc
->funcs
->cursor_set2
)
2515 ret
= crtc
->funcs
->cursor_set2(crtc
, file_priv
, req
->handle
,
2516 req
->width
, req
->height
, req
->hot_x
, req
->hot_y
);
2518 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2519 req
->width
, req
->height
);
2522 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2523 if (crtc
->funcs
->cursor_move
) {
2524 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2531 mutex_unlock(&crtc
->mutex
);
2539 * drm_mode_cursor_ioctl - set CRTC's cursor configuration
2540 * @dev: drm device for the ioctl
2541 * @data: data pointer for the ioctl
2542 * @file_priv: drm file for the ioctl call
2544 * Set the cursor configuration based on user request.
2546 * Called by the user via ioctl.
2549 * Zero on success, errno on failure.
2551 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2552 void *data
, struct drm_file
*file_priv
)
2554 struct drm_mode_cursor
*req
= data
;
2555 struct drm_mode_cursor2 new_req
;
2557 memcpy(&new_req
, req
, sizeof(struct drm_mode_cursor
));
2558 new_req
.hot_x
= new_req
.hot_y
= 0;
2560 return drm_mode_cursor_common(dev
, &new_req
, file_priv
);
2564 * drm_mode_cursor2_ioctl - set CRTC's cursor configuration
2565 * @dev: drm device for the ioctl
2566 * @data: data pointer for the ioctl
2567 * @file_priv: drm file for the ioctl call
2569 * Set the cursor configuration based on user request. This implements the 2nd
2570 * version of the cursor ioctl, which allows userspace to additionally specify
2571 * the hotspot of the pointer.
2573 * Called by the user via ioctl.
2576 * Zero on success, errno on failure.
2578 int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
2579 void *data
, struct drm_file
*file_priv
)
2581 struct drm_mode_cursor2
*req
= data
;
2582 return drm_mode_cursor_common(dev
, req
, file_priv
);
2586 * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description
2587 * @bpp: bits per pixels
2588 * @depth: bit depth per pixel
2590 * Computes a drm fourcc pixel format code for the given @bpp/@depth values.
2591 * Useful in fbdev emulation code, since that deals in those values.
2593 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2599 fmt
= DRM_FORMAT_C8
;
2603 fmt
= DRM_FORMAT_XRGB1555
;
2605 fmt
= DRM_FORMAT_RGB565
;
2608 fmt
= DRM_FORMAT_RGB888
;
2612 fmt
= DRM_FORMAT_XRGB8888
;
2613 else if (depth
== 30)
2614 fmt
= DRM_FORMAT_XRGB2101010
;
2616 fmt
= DRM_FORMAT_ARGB8888
;
2619 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2620 fmt
= DRM_FORMAT_XRGB8888
;
2626 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2629 * drm_mode_addfb - add an FB to the graphics configuration
2630 * @dev: drm device for the ioctl
2631 * @data: data pointer for the ioctl
2632 * @file_priv: drm file for the ioctl call
2634 * Add a new FB to the specified CRTC, given a user request. This is the
2635 * original addfb ioclt which only supported RGB formats.
2637 * Called by the user via ioctl.
2640 * Zero on success, errno on failure.
2642 int drm_mode_addfb(struct drm_device
*dev
,
2643 void *data
, struct drm_file
*file_priv
)
2645 struct drm_mode_fb_cmd
*or = data
;
2646 struct drm_mode_fb_cmd2 r
= {};
2647 struct drm_mode_config
*config
= &dev
->mode_config
;
2648 struct drm_framebuffer
*fb
;
2651 /* Use new struct with format internally */
2652 r
.fb_id
= or->fb_id
;
2653 r
.width
= or->width
;
2654 r
.height
= or->height
;
2655 r
.pitches
[0] = or->pitch
;
2656 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2657 r
.handles
[0] = or->handle
;
2659 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2662 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2665 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2668 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2670 DRM_DEBUG_KMS("could not create framebuffer\n");
2674 mutex_lock(&file_priv
->fbs_lock
);
2675 or->fb_id
= fb
->base
.id
;
2676 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2677 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2678 mutex_unlock(&file_priv
->fbs_lock
);
2683 static int format_check(const struct drm_mode_fb_cmd2
*r
)
2685 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2689 case DRM_FORMAT_RGB332
:
2690 case DRM_FORMAT_BGR233
:
2691 case DRM_FORMAT_XRGB4444
:
2692 case DRM_FORMAT_XBGR4444
:
2693 case DRM_FORMAT_RGBX4444
:
2694 case DRM_FORMAT_BGRX4444
:
2695 case DRM_FORMAT_ARGB4444
:
2696 case DRM_FORMAT_ABGR4444
:
2697 case DRM_FORMAT_RGBA4444
:
2698 case DRM_FORMAT_BGRA4444
:
2699 case DRM_FORMAT_XRGB1555
:
2700 case DRM_FORMAT_XBGR1555
:
2701 case DRM_FORMAT_RGBX5551
:
2702 case DRM_FORMAT_BGRX5551
:
2703 case DRM_FORMAT_ARGB1555
:
2704 case DRM_FORMAT_ABGR1555
:
2705 case DRM_FORMAT_RGBA5551
:
2706 case DRM_FORMAT_BGRA5551
:
2707 case DRM_FORMAT_RGB565
:
2708 case DRM_FORMAT_BGR565
:
2709 case DRM_FORMAT_RGB888
:
2710 case DRM_FORMAT_BGR888
:
2711 case DRM_FORMAT_XRGB8888
:
2712 case DRM_FORMAT_XBGR8888
:
2713 case DRM_FORMAT_RGBX8888
:
2714 case DRM_FORMAT_BGRX8888
:
2715 case DRM_FORMAT_ARGB8888
:
2716 case DRM_FORMAT_ABGR8888
:
2717 case DRM_FORMAT_RGBA8888
:
2718 case DRM_FORMAT_BGRA8888
:
2719 case DRM_FORMAT_XRGB2101010
:
2720 case DRM_FORMAT_XBGR2101010
:
2721 case DRM_FORMAT_RGBX1010102
:
2722 case DRM_FORMAT_BGRX1010102
:
2723 case DRM_FORMAT_ARGB2101010
:
2724 case DRM_FORMAT_ABGR2101010
:
2725 case DRM_FORMAT_RGBA1010102
:
2726 case DRM_FORMAT_BGRA1010102
:
2727 case DRM_FORMAT_YUYV
:
2728 case DRM_FORMAT_YVYU
:
2729 case DRM_FORMAT_UYVY
:
2730 case DRM_FORMAT_VYUY
:
2731 case DRM_FORMAT_AYUV
:
2732 case DRM_FORMAT_NV12
:
2733 case DRM_FORMAT_NV21
:
2734 case DRM_FORMAT_NV16
:
2735 case DRM_FORMAT_NV61
:
2736 case DRM_FORMAT_NV24
:
2737 case DRM_FORMAT_NV42
:
2738 case DRM_FORMAT_YUV410
:
2739 case DRM_FORMAT_YVU410
:
2740 case DRM_FORMAT_YUV411
:
2741 case DRM_FORMAT_YVU411
:
2742 case DRM_FORMAT_YUV420
:
2743 case DRM_FORMAT_YVU420
:
2744 case DRM_FORMAT_YUV422
:
2745 case DRM_FORMAT_YVU422
:
2746 case DRM_FORMAT_YUV444
:
2747 case DRM_FORMAT_YVU444
:
2750 DRM_DEBUG_KMS("invalid pixel format %s\n",
2751 drm_get_format_name(r
->pixel_format
));
2756 static int framebuffer_check(const struct drm_mode_fb_cmd2
*r
)
2758 int ret
, hsub
, vsub
, num_planes
, i
;
2760 ret
= format_check(r
);
2762 DRM_DEBUG_KMS("bad framebuffer format %s\n",
2763 drm_get_format_name(r
->pixel_format
));
2767 hsub
= drm_format_horz_chroma_subsampling(r
->pixel_format
);
2768 vsub
= drm_format_vert_chroma_subsampling(r
->pixel_format
);
2769 num_planes
= drm_format_num_planes(r
->pixel_format
);
2771 if (r
->width
== 0 || r
->width
% hsub
) {
2772 DRM_DEBUG_KMS("bad framebuffer width %u\n", r
->height
);
2776 if (r
->height
== 0 || r
->height
% vsub
) {
2777 DRM_DEBUG_KMS("bad framebuffer height %u\n", r
->height
);
2781 for (i
= 0; i
< num_planes
; i
++) {
2782 unsigned int width
= r
->width
/ (i
!= 0 ? hsub
: 1);
2783 unsigned int height
= r
->height
/ (i
!= 0 ? vsub
: 1);
2784 unsigned int cpp
= drm_format_plane_cpp(r
->pixel_format
, i
);
2786 if (!r
->handles
[i
]) {
2787 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i
);
2791 if ((uint64_t) width
* cpp
> UINT_MAX
)
2794 if ((uint64_t) height
* r
->pitches
[i
] + r
->offsets
[i
] > UINT_MAX
)
2797 if (r
->pitches
[i
] < width
* cpp
) {
2798 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r
->pitches
[i
], i
);
2807 * drm_mode_addfb2 - add an FB to the graphics configuration
2808 * @dev: drm device for the ioctl
2809 * @data: data pointer for the ioctl
2810 * @file_priv: drm file for the ioctl call
2812 * Add a new FB to the specified CRTC, given a user request with format. This is
2813 * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
2814 * and uses fourcc codes as pixel format specifiers.
2816 * Called by the user via ioctl.
2819 * Zero on success, errno on failure.
2821 int drm_mode_addfb2(struct drm_device
*dev
,
2822 void *data
, struct drm_file
*file_priv
)
2824 struct drm_mode_fb_cmd2
*r
= data
;
2825 struct drm_mode_config
*config
= &dev
->mode_config
;
2826 struct drm_framebuffer
*fb
;
2829 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2832 if (r
->flags
& ~DRM_MODE_FB_INTERLACED
) {
2833 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r
->flags
);
2837 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2838 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
2839 r
->width
, config
->min_width
, config
->max_width
);
2842 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2843 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
2844 r
->height
, config
->min_height
, config
->max_height
);
2848 ret
= framebuffer_check(r
);
2852 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2854 DRM_DEBUG_KMS("could not create framebuffer\n");
2858 mutex_lock(&file_priv
->fbs_lock
);
2859 r
->fb_id
= fb
->base
.id
;
2860 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2861 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2862 mutex_unlock(&file_priv
->fbs_lock
);
2869 * drm_mode_rmfb - remove an FB from the configuration
2870 * @dev: drm device for the ioctl
2871 * @data: data pointer for the ioctl
2872 * @file_priv: drm file for the ioctl call
2874 * Remove the FB specified by the user.
2876 * Called by the user via ioctl.
2879 * Zero on success, errno on failure.
2881 int drm_mode_rmfb(struct drm_device
*dev
,
2882 void *data
, struct drm_file
*file_priv
)
2884 struct drm_framebuffer
*fb
= NULL
;
2885 struct drm_framebuffer
*fbl
= NULL
;
2886 uint32_t *id
= data
;
2889 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2892 mutex_lock(&file_priv
->fbs_lock
);
2893 mutex_lock(&dev
->mode_config
.fb_lock
);
2894 fb
= __drm_framebuffer_lookup(dev
, *id
);
2898 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2904 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
2905 __drm_framebuffer_unregister(dev
, fb
);
2907 list_del_init(&fb
->filp_head
);
2908 mutex_unlock(&dev
->mode_config
.fb_lock
);
2909 mutex_unlock(&file_priv
->fbs_lock
);
2911 drm_framebuffer_remove(fb
);
2916 mutex_unlock(&dev
->mode_config
.fb_lock
);
2917 mutex_unlock(&file_priv
->fbs_lock
);
2923 * drm_mode_getfb - get FB info
2924 * @dev: drm device for the ioctl
2925 * @data: data pointer for the ioctl
2926 * @file_priv: drm file for the ioctl call
2928 * Lookup the FB given its ID and return info about it.
2930 * Called by the user via ioctl.
2933 * Zero on success, errno on failure.
2935 int drm_mode_getfb(struct drm_device
*dev
,
2936 void *data
, struct drm_file
*file_priv
)
2938 struct drm_mode_fb_cmd
*r
= data
;
2939 struct drm_framebuffer
*fb
;
2942 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2945 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
2949 r
->height
= fb
->height
;
2950 r
->width
= fb
->width
;
2951 r
->depth
= fb
->depth
;
2952 r
->bpp
= fb
->bits_per_pixel
;
2953 r
->pitch
= fb
->pitches
[0];
2954 if (fb
->funcs
->create_handle
) {
2955 if (file_priv
->is_master
|| capable(CAP_SYS_ADMIN
) ||
2956 drm_is_control_client(file_priv
)) {
2957 ret
= fb
->funcs
->create_handle(fb
, file_priv
,
2960 /* GET_FB() is an unprivileged ioctl so we must not
2961 * return a buffer-handle to non-master processes! For
2962 * backwards-compatibility reasons, we cannot make
2963 * GET_FB() privileged, so just return an invalid handle
2964 * for non-masters. */
2972 drm_framebuffer_unreference(fb
);
2978 * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB
2979 * @dev: drm device for the ioctl
2980 * @data: data pointer for the ioctl
2981 * @file_priv: drm file for the ioctl call
2983 * Lookup the FB and flush out the damaged area supplied by userspace as a clip
2984 * rectangle list. Generic userspace which does frontbuffer rendering must call
2985 * this ioctl to flush out the changes on manual-update display outputs, e.g.
2986 * usb display-link, mipi manual update panels or edp panel self refresh modes.
2988 * Modesetting drivers which always update the frontbuffer do not need to
2989 * implement the corresponding ->dirty framebuffer callback.
2991 * Called by the user via ioctl.
2994 * Zero on success, errno on failure.
2996 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2997 void *data
, struct drm_file
*file_priv
)
2999 struct drm_clip_rect __user
*clips_ptr
;
3000 struct drm_clip_rect
*clips
= NULL
;
3001 struct drm_mode_fb_dirty_cmd
*r
= data
;
3002 struct drm_framebuffer
*fb
;
3007 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3010 fb
= drm_framebuffer_lookup(dev
, r
->fb_id
);
3014 num_clips
= r
->num_clips
;
3015 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
3017 if (!num_clips
!= !clips_ptr
) {
3022 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
3024 /* If userspace annotates copy, clips must come in pairs */
3025 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
3030 if (num_clips
&& clips_ptr
) {
3031 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
3035 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
3041 ret
= copy_from_user(clips
, clips_ptr
,
3042 num_clips
* sizeof(*clips
));
3049 if (fb
->funcs
->dirty
) {
3050 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
3059 drm_framebuffer_unreference(fb
);
3066 * drm_fb_release - remove and free the FBs on this file
3067 * @priv: drm file for the ioctl
3069 * Destroy all the FBs associated with @filp.
3071 * Called by the user via ioctl.
3074 * Zero on success, errno on failure.
3076 void drm_fb_release(struct drm_file
*priv
)
3078 struct drm_device
*dev
= priv
->minor
->dev
;
3079 struct drm_framebuffer
*fb
, *tfb
;
3081 mutex_lock(&priv
->fbs_lock
);
3082 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
3084 mutex_lock(&dev
->mode_config
.fb_lock
);
3085 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */
3086 __drm_framebuffer_unregister(dev
, fb
);
3087 mutex_unlock(&dev
->mode_config
.fb_lock
);
3089 list_del_init(&fb
->filp_head
);
3091 /* This will also drop the fpriv->fbs reference. */
3092 drm_framebuffer_remove(fb
);
3094 mutex_unlock(&priv
->fbs_lock
);
3098 * drm_property_create - create a new property type
3100 * @flags: flags specifying the property type
3101 * @name: name of the property
3102 * @num_values: number of pre-defined values
3104 * This creates a new generic drm property which can then be attached to a drm
3105 * object with drm_object_attach_property. The returned property object must be
3106 * freed with drm_property_destroy.
3109 * A pointer to the newly created property on success, NULL on failure.
3111 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
3112 const char *name
, int num_values
)
3114 struct drm_property
*property
= NULL
;
3117 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
3122 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
3123 if (!property
->values
)
3127 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
3131 property
->flags
= flags
;
3132 property
->num_values
= num_values
;
3133 INIT_LIST_HEAD(&property
->enum_blob_list
);
3136 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
3137 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3140 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
3143 kfree(property
->values
);
3147 EXPORT_SYMBOL(drm_property_create
);
3150 * drm_property_create - create a new enumeration property type
3152 * @flags: flags specifying the property type
3153 * @name: name of the property
3154 * @props: enumeration lists with property values
3155 * @num_values: number of pre-defined values
3157 * This creates a new generic drm property which can then be attached to a drm
3158 * object with drm_object_attach_property. The returned property object must be
3159 * freed with drm_property_destroy.
3161 * Userspace is only allowed to set one of the predefined values for enumeration
3165 * A pointer to the newly created property on success, NULL on failure.
3167 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
3169 const struct drm_prop_enum_list
*props
,
3172 struct drm_property
*property
;
3175 flags
|= DRM_MODE_PROP_ENUM
;
3177 property
= drm_property_create(dev
, flags
, name
, num_values
);
3181 for (i
= 0; i
< num_values
; i
++) {
3182 ret
= drm_property_add_enum(property
, i
,
3186 drm_property_destroy(dev
, property
);
3193 EXPORT_SYMBOL(drm_property_create_enum
);
3196 * drm_property_create - create a new bitmask property type
3198 * @flags: flags specifying the property type
3199 * @name: name of the property
3200 * @props: enumeration lists with property bitflags
3201 * @num_values: number of pre-defined values
3203 * This creates a new generic drm property which can then be attached to a drm
3204 * object with drm_object_attach_property. The returned property object must be
3205 * freed with drm_property_destroy.
3207 * Compared to plain enumeration properties userspace is allowed to set any
3208 * or'ed together combination of the predefined property bitflag values
3211 * A pointer to the newly created property on success, NULL on failure.
3213 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
3214 int flags
, const char *name
,
3215 const struct drm_prop_enum_list
*props
,
3218 struct drm_property
*property
;
3221 flags
|= DRM_MODE_PROP_BITMASK
;
3223 property
= drm_property_create(dev
, flags
, name
, num_values
);
3227 for (i
= 0; i
< num_values
; i
++) {
3228 ret
= drm_property_add_enum(property
, i
,
3232 drm_property_destroy(dev
, property
);
3239 EXPORT_SYMBOL(drm_property_create_bitmask
);
3242 * drm_property_create - create a new ranged property type
3244 * @flags: flags specifying the property type
3245 * @name: name of the property
3246 * @min: minimum value of the property
3247 * @max: maximum value of the property
3249 * This creates a new generic drm property which can then be attached to a drm
3250 * object with drm_object_attach_property. The returned property object must be
3251 * freed with drm_property_destroy.
3253 * Userspace is allowed to set any interger value in the (min, max) range
3257 * A pointer to the newly created property on success, NULL on failure.
3259 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
3261 uint64_t min
, uint64_t max
)
3263 struct drm_property
*property
;
3265 flags
|= DRM_MODE_PROP_RANGE
;
3267 property
= drm_property_create(dev
, flags
, name
, 2);
3271 property
->values
[0] = min
;
3272 property
->values
[1] = max
;
3276 EXPORT_SYMBOL(drm_property_create_range
);
3279 * drm_property_add_enum - add a possible value to an enumeration property
3280 * @property: enumeration property to change
3281 * @index: index of the new enumeration
3282 * @value: value of the new enumeration
3283 * @name: symbolic name of the new enumeration
3285 * This functions adds enumerations to a property.
3287 * It's use is deprecated, drivers should use one of the more specific helpers
3288 * to directly create the property with all enumerations already attached.
3291 * Zero on success, error code on failure.
3293 int drm_property_add_enum(struct drm_property
*property
, int index
,
3294 uint64_t value
, const char *name
)
3296 struct drm_property_enum
*prop_enum
;
3298 if (!(property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)))
3302 * Bitmask enum properties have the additional constraint of values
3305 if ((property
->flags
& DRM_MODE_PROP_BITMASK
) && (value
> 63))
3308 if (!list_empty(&property
->enum_blob_list
)) {
3309 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3310 if (prop_enum
->value
== value
) {
3311 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
3312 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3318 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
3322 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
3323 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
3324 prop_enum
->value
= value
;
3326 property
->values
[index
] = value
;
3327 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
3330 EXPORT_SYMBOL(drm_property_add_enum
);
3333 * drm_property_destroy - destroy a drm property
3335 * @property: property to destry
3337 * This function frees a property including any attached resources like
3338 * enumeration values.
3340 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
3342 struct drm_property_enum
*prop_enum
, *pt
;
3344 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
3345 list_del(&prop_enum
->head
);
3349 if (property
->num_values
)
3350 kfree(property
->values
);
3351 drm_mode_object_put(dev
, &property
->base
);
3352 list_del(&property
->head
);
3355 EXPORT_SYMBOL(drm_property_destroy
);
3358 * drm_object_attach_property - attach a property to a modeset object
3359 * @obj: drm modeset object
3360 * @property: property to attach
3361 * @init_val: initial value of the property
3363 * This attaches the given property to the modeset object with the given initial
3364 * value. Currently this function cannot fail since the properties are stored in
3365 * a statically sized array.
3367 void drm_object_attach_property(struct drm_mode_object
*obj
,
3368 struct drm_property
*property
,
3371 int count
= obj
->properties
->count
;
3373 if (count
== DRM_OBJECT_MAX_PROPERTY
) {
3374 WARN(1, "Failed to attach object property (type: 0x%x). Please "
3375 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
3376 "you see this message on the same object type.\n",
3381 obj
->properties
->ids
[count
] = property
->base
.id
;
3382 obj
->properties
->values
[count
] = init_val
;
3383 obj
->properties
->count
++;
3385 EXPORT_SYMBOL(drm_object_attach_property
);
3388 * drm_object_property_set_value - set the value of a property
3389 * @obj: drm mode object to set property value for
3390 * @property: property to set
3391 * @val: value the property should be set to
3393 * This functions sets a given property on a given object. This function only
3394 * changes the software state of the property, it does not call into the
3395 * driver's ->set_property callback.
3398 * Zero on success, error code on failure.
3400 int drm_object_property_set_value(struct drm_mode_object
*obj
,
3401 struct drm_property
*property
, uint64_t val
)
3405 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3406 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3407 obj
->properties
->values
[i
] = val
;
3414 EXPORT_SYMBOL(drm_object_property_set_value
);
3417 * drm_object_property_get_value - retrieve the value of a property
3418 * @obj: drm mode object to get property value from
3419 * @property: property to retrieve
3420 * @val: storage for the property value
3422 * This function retrieves the softare state of the given property for the given
3423 * property. Since there is no driver callback to retrieve the current property
3424 * value this might be out of sync with the hardware, depending upon the driver
3428 * Zero on success, error code on failure.
3430 int drm_object_property_get_value(struct drm_mode_object
*obj
,
3431 struct drm_property
*property
, uint64_t *val
)
3435 for (i
= 0; i
< obj
->properties
->count
; i
++) {
3436 if (obj
->properties
->ids
[i
] == property
->base
.id
) {
3437 *val
= obj
->properties
->values
[i
];
3444 EXPORT_SYMBOL(drm_object_property_get_value
);
3447 * drm_mode_getproperty_ioctl - get the current value of a connector's property
3450 * @file_priv: DRM file info
3452 * This function retrieves the current value for an connectors's property.
3454 * Called by the user via ioctl.
3457 * Zero on success, errno on failure.
3459 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
3460 void *data
, struct drm_file
*file_priv
)
3462 struct drm_mode_object
*obj
;
3463 struct drm_mode_get_property
*out_resp
= data
;
3464 struct drm_property
*property
;
3467 int value_count
= 0;
3470 struct drm_property_enum
*prop_enum
;
3471 struct drm_mode_property_enum __user
*enum_ptr
;
3472 struct drm_property_blob
*prop_blob
;
3473 uint32_t __user
*blob_id_ptr
;
3474 uint64_t __user
*values_ptr
;
3475 uint32_t __user
*blob_length_ptr
;
3477 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3480 drm_modeset_lock_all(dev
);
3481 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3486 property
= obj_to_property(obj
);
3488 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3489 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
3491 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3492 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
3496 value_count
= property
->num_values
;
3498 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
3499 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
3500 out_resp
->flags
= property
->flags
;
3502 if ((out_resp
->count_values
>= value_count
) && value_count
) {
3503 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
3504 for (i
= 0; i
< value_count
; i
++) {
3505 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
3511 out_resp
->count_values
= value_count
;
3513 if (property
->flags
& (DRM_MODE_PROP_ENUM
| DRM_MODE_PROP_BITMASK
)) {
3514 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
3516 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3517 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
3519 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
3524 if (copy_to_user(&enum_ptr
[copied
].name
,
3525 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
3532 out_resp
->count_enum_blobs
= enum_count
;
3535 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3536 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
3538 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
3539 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
3541 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
3542 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
3547 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
3555 out_resp
->count_enum_blobs
= blob_count
;
3558 drm_modeset_unlock_all(dev
);
3562 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
3565 struct drm_property_blob
*blob
;
3568 if (!length
|| !data
)
3571 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
3575 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
3581 blob
->length
= length
;
3583 memcpy(blob
->data
, data
, length
);
3585 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
3589 static void drm_property_destroy_blob(struct drm_device
*dev
,
3590 struct drm_property_blob
*blob
)
3592 drm_mode_object_put(dev
, &blob
->base
);
3593 list_del(&blob
->head
);
3598 * drm_mode_getblob_ioctl - get the contents of a blob property value
3601 * @file_priv: DRM file info
3603 * This function retrieves the contents of a blob property. The value stored in
3604 * an object's blob property is just a normal modeset object id.
3606 * Called by the user via ioctl.
3609 * Zero on success, errno on failure.
3611 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
3612 void *data
, struct drm_file
*file_priv
)
3614 struct drm_mode_object
*obj
;
3615 struct drm_mode_get_blob
*out_resp
= data
;
3616 struct drm_property_blob
*blob
;
3618 void __user
*blob_ptr
;
3620 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3623 drm_modeset_lock_all(dev
);
3624 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
3629 blob
= obj_to_blob(obj
);
3631 if (out_resp
->length
== blob
->length
) {
3632 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
3633 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3638 out_resp
->length
= blob
->length
;
3641 drm_modeset_unlock_all(dev
);
3646 * drm_mode_connector_update_edid_property - update the edid property of a connector
3647 * @connector: drm connector
3648 * @edid: new value of the edid property
3650 * This function creates a new blob modeset object and assigns its id to the
3651 * connector's edid property.
3654 * Zero on success, errno on failure.
3656 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3659 struct drm_device
*dev
= connector
->dev
;
3662 if (connector
->edid_blob_ptr
)
3663 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3665 /* Delete edid, when there is none. */
3667 connector
->edid_blob_ptr
= NULL
;
3668 ret
= drm_object_property_set_value(&connector
->base
, dev
->mode_config
.edid_property
, 0);
3672 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3673 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3675 if (!connector
->edid_blob_ptr
)
3678 ret
= drm_object_property_set_value(&connector
->base
,
3679 dev
->mode_config
.edid_property
,
3680 connector
->edid_blob_ptr
->base
.id
);
3684 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3686 static bool drm_property_change_is_valid(struct drm_property
*property
,
3689 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3691 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3692 if (value
< property
->values
[0] || value
> property
->values
[1])
3695 } else if (property
->flags
& DRM_MODE_PROP_BITMASK
) {
3697 uint64_t valid_mask
= 0;
3698 for (i
= 0; i
< property
->num_values
; i
++)
3699 valid_mask
|= (1ULL << property
->values
[i
]);
3700 return !(value
& ~valid_mask
);
3701 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
3702 /* Only the driver knows */
3706 for (i
= 0; i
< property
->num_values
; i
++)
3707 if (property
->values
[i
] == value
)
3714 * drm_mode_connector_property_set_ioctl - set the current value of a connector property
3717 * @file_priv: DRM file info
3719 * This function sets the current value for a connectors's property. It also
3720 * calls into a driver's ->set_property callback to update the hardware state
3722 * Called by the user via ioctl.
3725 * Zero on success, errno on failure.
3727 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3728 void *data
, struct drm_file
*file_priv
)
3730 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
3731 struct drm_mode_obj_set_property obj_set_prop
= {
3732 .value
= conn_set_prop
->value
,
3733 .prop_id
= conn_set_prop
->prop_id
,
3734 .obj_id
= conn_set_prop
->connector_id
,
3735 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
3738 /* It does all the locking and checking we need */
3739 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
3742 static int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
3743 struct drm_property
*property
,
3747 struct drm_connector
*connector
= obj_to_connector(obj
);
3749 /* Do DPMS ourselves */
3750 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3751 if (connector
->funcs
->dpms
)
3752 (*connector
->funcs
->dpms
)(connector
, (int)value
);
3754 } else if (connector
->funcs
->set_property
)
3755 ret
= connector
->funcs
->set_property(connector
, property
, value
);
3757 /* store the property value if successful */
3759 drm_object_property_set_value(&connector
->base
, property
, value
);
3763 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
3764 struct drm_property
*property
,
3768 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
3770 if (crtc
->funcs
->set_property
)
3771 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
3773 drm_object_property_set_value(obj
, property
, value
);
3778 static int drm_mode_plane_set_obj_prop(struct drm_mode_object
*obj
,
3779 struct drm_property
*property
,
3783 struct drm_plane
*plane
= obj_to_plane(obj
);
3785 if (plane
->funcs
->set_property
)
3786 ret
= plane
->funcs
->set_property(plane
, property
, value
);
3788 drm_object_property_set_value(obj
, property
, value
);
3794 * drm_mode_getproperty_ioctl - get the current value of a object's property
3797 * @file_priv: DRM file info
3799 * This function retrieves the current value for an object's property. Compared
3800 * to the connector specific ioctl this one is extended to also work on crtc and
3803 * Called by the user via ioctl.
3806 * Zero on success, errno on failure.
3808 int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
3809 struct drm_file
*file_priv
)
3811 struct drm_mode_obj_get_properties
*arg
= data
;
3812 struct drm_mode_object
*obj
;
3816 int props_count
= 0;
3817 uint32_t __user
*props_ptr
;
3818 uint64_t __user
*prop_values_ptr
;
3820 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3823 drm_modeset_lock_all(dev
);
3825 obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3830 if (!obj
->properties
) {
3835 props_count
= obj
->properties
->count
;
3837 /* This ioctl is called twice, once to determine how much space is
3838 * needed, and the 2nd time to fill it. */
3839 if ((arg
->count_props
>= props_count
) && props_count
) {
3841 props_ptr
= (uint32_t __user
*)(unsigned long)(arg
->props_ptr
);
3842 prop_values_ptr
= (uint64_t __user
*)(unsigned long)
3843 (arg
->prop_values_ptr
);
3844 for (i
= 0; i
< props_count
; i
++) {
3845 if (put_user(obj
->properties
->ids
[i
],
3846 props_ptr
+ copied
)) {
3850 if (put_user(obj
->properties
->values
[i
],
3851 prop_values_ptr
+ copied
)) {
3858 arg
->count_props
= props_count
;
3860 drm_modeset_unlock_all(dev
);
3865 * drm_mode_obj_set_property_ioctl - set the current value of an object's property
3868 * @file_priv: DRM file info
3870 * This function sets the current value for an object's property. It also calls
3871 * into a driver's ->set_property callback to update the hardware state.
3872 * Compared to the connector specific ioctl this one is extended to also work on
3873 * crtc and plane objects.
3875 * Called by the user via ioctl.
3878 * Zero on success, errno on failure.
3880 int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
3881 struct drm_file
*file_priv
)
3883 struct drm_mode_obj_set_property
*arg
= data
;
3884 struct drm_mode_object
*arg_obj
;
3885 struct drm_mode_object
*prop_obj
;
3886 struct drm_property
*property
;
3890 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3893 drm_modeset_lock_all(dev
);
3895 arg_obj
= drm_mode_object_find(dev
, arg
->obj_id
, arg
->obj_type
);
3900 if (!arg_obj
->properties
)
3903 for (i
= 0; i
< arg_obj
->properties
->count
; i
++)
3904 if (arg_obj
->properties
->ids
[i
] == arg
->prop_id
)
3907 if (i
== arg_obj
->properties
->count
)
3910 prop_obj
= drm_mode_object_find(dev
, arg
->prop_id
,
3911 DRM_MODE_OBJECT_PROPERTY
);
3916 property
= obj_to_property(prop_obj
);
3918 if (!drm_property_change_is_valid(property
, arg
->value
))
3921 switch (arg_obj
->type
) {
3922 case DRM_MODE_OBJECT_CONNECTOR
:
3923 ret
= drm_mode_connector_set_obj_prop(arg_obj
, property
,
3926 case DRM_MODE_OBJECT_CRTC
:
3927 ret
= drm_mode_crtc_set_obj_prop(arg_obj
, property
, arg
->value
);
3929 case DRM_MODE_OBJECT_PLANE
:
3930 ret
= drm_mode_plane_set_obj_prop(arg_obj
, property
, arg
->value
);
3935 drm_modeset_unlock_all(dev
);
3940 * drm_mode_connector_attach_encoder - attach a connector to an encoder
3941 * @connector: connector to attach
3942 * @encoder: encoder to attach @connector to
3944 * This function links up a connector to an encoder. Note that the routing
3945 * restrictions between encoders and crtcs are exposed to userspace through the
3946 * possible_clones and possible_crtcs bitmasks.
3949 * Zero on success, errno on failure.
3951 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3952 struct drm_encoder
*encoder
)
3956 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3957 if (connector
->encoder_ids
[i
] == 0) {
3958 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3964 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3967 * drm_mode_crtc_set_gamma_size - set the gamma table size
3968 * @crtc: CRTC to set the gamma table size for
3969 * @gamma_size: size of the gamma table
3971 * Drivers which support gamma tables should set this to the supported gamma
3972 * table size when initializing the CRTC. Currently the drm core only supports a
3973 * fixed gamma table size.
3976 * Zero on success, errno on failure.
3978 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3981 crtc
->gamma_size
= gamma_size
;
3983 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3984 if (!crtc
->gamma_store
) {
3985 crtc
->gamma_size
= 0;
3991 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3994 * drm_mode_gamma_set_ioctl - set the gamma table
3997 * @file_priv: DRM file info
3999 * Set the gamma table of a CRTC to the one passed in by the user. Userspace can
4000 * inquire the required gamma table size through drm_mode_gamma_get_ioctl.
4002 * Called by the user via ioctl.
4005 * Zero on success, errno on failure.
4007 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
4008 void *data
, struct drm_file
*file_priv
)
4010 struct drm_mode_crtc_lut
*crtc_lut
= data
;
4011 struct drm_mode_object
*obj
;
4012 struct drm_crtc
*crtc
;
4013 void *r_base
, *g_base
, *b_base
;
4017 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
4020 drm_modeset_lock_all(dev
);
4021 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
4026 crtc
= obj_to_crtc(obj
);
4028 if (crtc
->funcs
->gamma_set
== NULL
) {
4033 /* memcpy into gamma store */
4034 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
4039 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
4040 r_base
= crtc
->gamma_store
;
4041 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
4046 g_base
= r_base
+ size
;
4047 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
4052 b_base
= g_base
+ size
;
4053 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
4058 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
4061 drm_modeset_unlock_all(dev
);
4067 * drm_mode_gamma_get_ioctl - get the gamma table
4070 * @file_priv: DRM file info
4072 * Copy the current gamma table into the storage provided. This also provides
4073 * the gamma table size the driver expects, which can be used to size the
4074 * allocated storage.
4076 * Called by the user via ioctl.
4079 * Zero on success, errno on failure.
4081 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
4082 void *data
, struct drm_file
*file_priv
)
4084 struct drm_mode_crtc_lut
*crtc_lut
= data
;
4085 struct drm_mode_object
*obj
;
4086 struct drm_crtc
*crtc
;
4087 void *r_base
, *g_base
, *b_base
;
4091 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
4094 drm_modeset_lock_all(dev
);
4095 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
4100 crtc
= obj_to_crtc(obj
);
4102 /* memcpy into gamma store */
4103 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
4108 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
4109 r_base
= crtc
->gamma_store
;
4110 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
4115 g_base
= r_base
+ size
;
4116 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
4121 b_base
= g_base
+ size
;
4122 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
4127 drm_modeset_unlock_all(dev
);
4132 * drm_mode_page_flip_ioctl - schedule an asynchronous fb update
4135 * @file_priv: DRM file info
4137 * This schedules an asynchronous update on a given CRTC, called page flip.
4138 * Optionally a drm event is generated to signal the completion of the event.
4139 * Generic drivers cannot assume that a pageflip with changed framebuffer
4140 * properties (including driver specific metadata like tiling layout) will work,
4141 * but some drivers support e.g. pixel format changes through the pageflip
4144 * Called by the user via ioctl.
4147 * Zero on success, errno on failure.
4149 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
4150 void *data
, struct drm_file
*file_priv
)
4152 struct drm_mode_crtc_page_flip
*page_flip
= data
;
4153 struct drm_mode_object
*obj
;
4154 struct drm_crtc
*crtc
;
4155 struct drm_framebuffer
*fb
= NULL
, *old_fb
= NULL
;
4156 struct drm_pending_vblank_event
*e
= NULL
;
4157 unsigned long flags
;
4160 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
4161 page_flip
->reserved
!= 0)
4164 if ((page_flip
->flags
& DRM_MODE_PAGE_FLIP_ASYNC
) && !dev
->mode_config
.async_page_flip
)
4167 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
4170 crtc
= obj_to_crtc(obj
);
4172 mutex_lock(&crtc
->mutex
);
4173 if (crtc
->primary
->fb
== NULL
) {
4174 /* The framebuffer is currently unbound, presumably
4175 * due to a hotplug event, that userspace has not
4182 if (crtc
->funcs
->page_flip
== NULL
)
4185 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
4191 ret
= drm_crtc_check_viewport(crtc
, crtc
->x
, crtc
->y
, &crtc
->mode
, fb
);
4195 if (crtc
->primary
->fb
->pixel_format
!= fb
->pixel_format
) {
4196 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
4201 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
4203 spin_lock_irqsave(&dev
->event_lock
, flags
);
4204 if (file_priv
->event_space
< sizeof e
->event
) {
4205 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
4208 file_priv
->event_space
-= sizeof e
->event
;
4209 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
4211 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
4213 spin_lock_irqsave(&dev
->event_lock
, flags
);
4214 file_priv
->event_space
+= sizeof e
->event
;
4215 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
4219 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
4220 e
->event
.base
.length
= sizeof e
->event
;
4221 e
->event
.user_data
= page_flip
->user_data
;
4222 e
->base
.event
= &e
->event
.base
;
4223 e
->base
.file_priv
= file_priv
;
4225 (void (*) (struct drm_pending_event
*)) kfree
;
4228 old_fb
= crtc
->primary
->fb
;
4229 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
, page_flip
->flags
);
4231 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
4232 spin_lock_irqsave(&dev
->event_lock
, flags
);
4233 file_priv
->event_space
+= sizeof e
->event
;
4234 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
4237 /* Keep the old fb, don't unref it. */
4241 * Warn if the driver hasn't properly updated the crtc->fb
4242 * field to reflect that the new framebuffer is now used.
4243 * Failing to do so will screw with the reference counting
4246 WARN_ON(crtc
->primary
->fb
!= fb
);
4247 /* Unref only the old framebuffer. */
4253 drm_framebuffer_unreference(fb
);
4255 drm_framebuffer_unreference(old_fb
);
4256 mutex_unlock(&crtc
->mutex
);
4262 * drm_mode_config_reset - call ->reset callbacks
4265 * This functions calls all the crtc's, encoder's and connector's ->reset
4266 * callback. Drivers can use this in e.g. their driver load or resume code to
4267 * reset hardware and software state.
4269 void drm_mode_config_reset(struct drm_device
*dev
)
4271 struct drm_crtc
*crtc
;
4272 struct drm_encoder
*encoder
;
4273 struct drm_connector
*connector
;
4275 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
4276 if (crtc
->funcs
->reset
)
4277 crtc
->funcs
->reset(crtc
);
4279 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
4280 if (encoder
->funcs
->reset
)
4281 encoder
->funcs
->reset(encoder
);
4283 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
4284 connector
->status
= connector_status_unknown
;
4286 if (connector
->funcs
->reset
)
4287 connector
->funcs
->reset(connector
);
4290 EXPORT_SYMBOL(drm_mode_config_reset
);
4293 * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer
4296 * @file_priv: DRM file info
4298 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
4299 * TTM or something else entirely) and returns the resulting buffer handle. This
4300 * handle can then be wrapped up into a framebuffer modeset object.
4302 * Note that userspace is not allowed to use such objects for render
4303 * acceleration - drivers must create their own private ioctls for such a use
4306 * Called by the user via ioctl.
4309 * Zero on success, errno on failure.
4311 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
4312 void *data
, struct drm_file
*file_priv
)
4314 struct drm_mode_create_dumb
*args
= data
;
4315 u32 cpp
, stride
, size
;
4317 if (!dev
->driver
->dumb_create
)
4319 if (!args
->width
|| !args
->height
|| !args
->bpp
)
4322 /* overflow checks for 32bit size calculations */
4323 cpp
= DIV_ROUND_UP(args
->bpp
, 8);
4324 if (cpp
> 0xffffffffU
/ args
->width
)
4326 stride
= cpp
* args
->width
;
4327 if (args
->height
> 0xffffffffU
/ stride
)
4330 /* test for wrap-around */
4331 size
= args
->height
* stride
;
4332 if (PAGE_ALIGN(size
) == 0)
4335 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
4339 * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer
4342 * @file_priv: DRM file info
4344 * Allocate an offset in the drm device node's address space to be able to
4345 * memory map a dumb buffer.
4347 * Called by the user via ioctl.
4350 * Zero on success, errno on failure.
4352 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
4353 void *data
, struct drm_file
*file_priv
)
4355 struct drm_mode_map_dumb
*args
= data
;
4357 /* call driver ioctl to get mmap offset */
4358 if (!dev
->driver
->dumb_map_offset
)
4361 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
4365 * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer
4368 * @file_priv: DRM file info
4370 * This destroys the userspace handle for the given dumb backing storage buffer.
4371 * Since buffer objects must be reference counted in the kernel a buffer object
4372 * won't be immediately freed if a framebuffer modeset object still uses it.
4374 * Called by the user via ioctl.
4377 * Zero on success, errno on failure.
4379 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
4380 void *data
, struct drm_file
*file_priv
)
4382 struct drm_mode_destroy_dumb
*args
= data
;
4384 if (!dev
->driver
->dumb_destroy
)
4387 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
4391 * drm_fb_get_bpp_depth - get the bpp/depth values for format
4392 * @format: pixel format (DRM_FORMAT_*)
4393 * @depth: storage for the depth value
4394 * @bpp: storage for the bpp value
4396 * This only supports RGB formats here for compat with code that doesn't use
4397 * pixel formats directly yet.
4399 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
4404 case DRM_FORMAT_RGB332
:
4405 case DRM_FORMAT_BGR233
:
4409 case DRM_FORMAT_XRGB1555
:
4410 case DRM_FORMAT_XBGR1555
:
4411 case DRM_FORMAT_RGBX5551
:
4412 case DRM_FORMAT_BGRX5551
:
4413 case DRM_FORMAT_ARGB1555
:
4414 case DRM_FORMAT_ABGR1555
:
4415 case DRM_FORMAT_RGBA5551
:
4416 case DRM_FORMAT_BGRA5551
:
4420 case DRM_FORMAT_RGB565
:
4421 case DRM_FORMAT_BGR565
:
4425 case DRM_FORMAT_RGB888
:
4426 case DRM_FORMAT_BGR888
:
4430 case DRM_FORMAT_XRGB8888
:
4431 case DRM_FORMAT_XBGR8888
:
4432 case DRM_FORMAT_RGBX8888
:
4433 case DRM_FORMAT_BGRX8888
:
4437 case DRM_FORMAT_XRGB2101010
:
4438 case DRM_FORMAT_XBGR2101010
:
4439 case DRM_FORMAT_RGBX1010102
:
4440 case DRM_FORMAT_BGRX1010102
:
4441 case DRM_FORMAT_ARGB2101010
:
4442 case DRM_FORMAT_ABGR2101010
:
4443 case DRM_FORMAT_RGBA1010102
:
4444 case DRM_FORMAT_BGRA1010102
:
4448 case DRM_FORMAT_ARGB8888
:
4449 case DRM_FORMAT_ABGR8888
:
4450 case DRM_FORMAT_RGBA8888
:
4451 case DRM_FORMAT_BGRA8888
:
4456 DRM_DEBUG_KMS("unsupported pixel format %s\n",
4457 drm_get_format_name(format
));
4463 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);
4466 * drm_format_num_planes - get the number of planes for format
4467 * @format: pixel format (DRM_FORMAT_*)
4470 * The number of planes used by the specified pixel format.
4472 int drm_format_num_planes(uint32_t format
)
4475 case DRM_FORMAT_YUV410
:
4476 case DRM_FORMAT_YVU410
:
4477 case DRM_FORMAT_YUV411
:
4478 case DRM_FORMAT_YVU411
:
4479 case DRM_FORMAT_YUV420
:
4480 case DRM_FORMAT_YVU420
:
4481 case DRM_FORMAT_YUV422
:
4482 case DRM_FORMAT_YVU422
:
4483 case DRM_FORMAT_YUV444
:
4484 case DRM_FORMAT_YVU444
:
4486 case DRM_FORMAT_NV12
:
4487 case DRM_FORMAT_NV21
:
4488 case DRM_FORMAT_NV16
:
4489 case DRM_FORMAT_NV61
:
4490 case DRM_FORMAT_NV24
:
4491 case DRM_FORMAT_NV42
:
4497 EXPORT_SYMBOL(drm_format_num_planes
);
4500 * drm_format_plane_cpp - determine the bytes per pixel value
4501 * @format: pixel format (DRM_FORMAT_*)
4502 * @plane: plane index
4505 * The bytes per pixel value for the specified plane.
4507 int drm_format_plane_cpp(uint32_t format
, int plane
)
4512 if (plane
>= drm_format_num_planes(format
))
4516 case DRM_FORMAT_YUYV
:
4517 case DRM_FORMAT_YVYU
:
4518 case DRM_FORMAT_UYVY
:
4519 case DRM_FORMAT_VYUY
:
4521 case DRM_FORMAT_NV12
:
4522 case DRM_FORMAT_NV21
:
4523 case DRM_FORMAT_NV16
:
4524 case DRM_FORMAT_NV61
:
4525 case DRM_FORMAT_NV24
:
4526 case DRM_FORMAT_NV42
:
4527 return plane
? 2 : 1;
4528 case DRM_FORMAT_YUV410
:
4529 case DRM_FORMAT_YVU410
:
4530 case DRM_FORMAT_YUV411
:
4531 case DRM_FORMAT_YVU411
:
4532 case DRM_FORMAT_YUV420
:
4533 case DRM_FORMAT_YVU420
:
4534 case DRM_FORMAT_YUV422
:
4535 case DRM_FORMAT_YVU422
:
4536 case DRM_FORMAT_YUV444
:
4537 case DRM_FORMAT_YVU444
:
4540 drm_fb_get_bpp_depth(format
, &depth
, &bpp
);
4544 EXPORT_SYMBOL(drm_format_plane_cpp
);
4547 * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
4548 * @format: pixel format (DRM_FORMAT_*)
4551 * The horizontal chroma subsampling factor for the
4552 * specified pixel format.
4554 int drm_format_horz_chroma_subsampling(uint32_t format
)
4557 case DRM_FORMAT_YUV411
:
4558 case DRM_FORMAT_YVU411
:
4559 case DRM_FORMAT_YUV410
:
4560 case DRM_FORMAT_YVU410
:
4562 case DRM_FORMAT_YUYV
:
4563 case DRM_FORMAT_YVYU
:
4564 case DRM_FORMAT_UYVY
:
4565 case DRM_FORMAT_VYUY
:
4566 case DRM_FORMAT_NV12
:
4567 case DRM_FORMAT_NV21
:
4568 case DRM_FORMAT_NV16
:
4569 case DRM_FORMAT_NV61
:
4570 case DRM_FORMAT_YUV422
:
4571 case DRM_FORMAT_YVU422
:
4572 case DRM_FORMAT_YUV420
:
4573 case DRM_FORMAT_YVU420
:
4579 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling
);
4582 * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
4583 * @format: pixel format (DRM_FORMAT_*)
4586 * The vertical chroma subsampling factor for the
4587 * specified pixel format.
4589 int drm_format_vert_chroma_subsampling(uint32_t format
)
4592 case DRM_FORMAT_YUV410
:
4593 case DRM_FORMAT_YVU410
:
4595 case DRM_FORMAT_YUV420
:
4596 case DRM_FORMAT_YVU420
:
4597 case DRM_FORMAT_NV12
:
4598 case DRM_FORMAT_NV21
:
4604 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling
);
4607 * drm_mode_config_init - initialize DRM mode_configuration structure
4610 * Initialize @dev's mode_config structure, used for tracking the graphics
4611 * configuration of @dev.
4613 * Since this initializes the modeset locks, no locking is possible. Which is no
4614 * problem, since this should happen single threaded at init time. It is the
4615 * driver's problem to ensure this guarantee.
4618 void drm_mode_config_init(struct drm_device
*dev
)
4620 mutex_init(&dev
->mode_config
.mutex
);
4621 mutex_init(&dev
->mode_config
.idr_mutex
);
4622 mutex_init(&dev
->mode_config
.fb_lock
);
4623 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
4624 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
4625 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
4626 INIT_LIST_HEAD(&dev
->mode_config
.bridge_list
);
4627 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
4628 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
4629 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
4630 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
4631 idr_init(&dev
->mode_config
.crtc_idr
);
4633 drm_modeset_lock_all(dev
);
4634 drm_mode_create_standard_connector_properties(dev
);
4635 drm_mode_create_standard_plane_properties(dev
);
4636 drm_modeset_unlock_all(dev
);
4638 /* Just to be sure */
4639 dev
->mode_config
.num_fb
= 0;
4640 dev
->mode_config
.num_connector
= 0;
4641 dev
->mode_config
.num_crtc
= 0;
4642 dev
->mode_config
.num_encoder
= 0;
4643 dev
->mode_config
.num_overlay_plane
= 0;
4644 dev
->mode_config
.num_total_plane
= 0;
4646 EXPORT_SYMBOL(drm_mode_config_init
);
4649 * drm_mode_config_cleanup - free up DRM mode_config info
4652 * Free up all the connectors and CRTCs associated with this DRM device, then
4653 * free up the framebuffers and associated buffer objects.
4655 * Note that since this /should/ happen single-threaded at driver/device
4656 * teardown time, no locking is required. It's the driver's job to ensure that
4657 * this guarantee actually holds true.
4659 * FIXME: cleanup any dangling user buffer objects too
4661 void drm_mode_config_cleanup(struct drm_device
*dev
)
4663 struct drm_connector
*connector
, *ot
;
4664 struct drm_crtc
*crtc
, *ct
;
4665 struct drm_encoder
*encoder
, *enct
;
4666 struct drm_bridge
*bridge
, *brt
;
4667 struct drm_framebuffer
*fb
, *fbt
;
4668 struct drm_property
*property
, *pt
;
4669 struct drm_property_blob
*blob
, *bt
;
4670 struct drm_plane
*plane
, *plt
;
4672 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
4674 encoder
->funcs
->destroy(encoder
);
4677 list_for_each_entry_safe(bridge
, brt
,
4678 &dev
->mode_config
.bridge_list
, head
) {
4679 bridge
->funcs
->destroy(bridge
);
4682 list_for_each_entry_safe(connector
, ot
,
4683 &dev
->mode_config
.connector_list
, head
) {
4684 connector
->funcs
->destroy(connector
);
4687 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
4689 drm_property_destroy(dev
, property
);
4692 list_for_each_entry_safe(blob
, bt
, &dev
->mode_config
.property_blob_list
,
4694 drm_property_destroy_blob(dev
, blob
);
4698 * Single-threaded teardown context, so it's not required to grab the
4699 * fb_lock to protect against concurrent fb_list access. Contrary, it
4700 * would actually deadlock with the drm_framebuffer_cleanup function.
4702 * Also, if there are any framebuffers left, that's a driver leak now,
4703 * so politely WARN about this.
4705 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
4706 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
4707 drm_framebuffer_remove(fb
);
4710 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
4712 plane
->funcs
->destroy(plane
);
4715 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
4716 crtc
->funcs
->destroy(crtc
);
4719 idr_destroy(&dev
->mode_config
.crtc_idr
);
4721 EXPORT_SYMBOL(drm_mode_config_cleanup
);