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>
40 #include <drm/drm_modeset_lock.h>
41 #include <drm/drm_atomic.h>
42 #include <drm/drm_auth.h>
44 #include "drm_crtc_internal.h"
45 #include "drm_internal.h"
47 static struct drm_framebuffer *
48 internal_framebuffer_create(struct drm_device *dev,
49 const struct drm_mode_fb_cmd2 *r,
50 struct drm_file *file_priv);
52 /* Avoid boilerplate. I'm tired of typing. */
53 #define DRM_ENUM_NAME_FN(fnname, list) \
54 const char *fnname(int val) \
57 for (i = 0; i < ARRAY_SIZE(list); i++) { \
58 if (list[i].type == val) \
59 return list[i].name; \
67 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
68 { DRM_MODE_DPMS_ON, "On" },
69 { DRM_MODE_DPMS_STANDBY, "Standby" },
70 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
71 { DRM_MODE_DPMS_OFF, "Off" }
74 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
76 static const struct drm_prop_enum_list drm_plane_type_enum_list[] = {
77 { DRM_PLANE_TYPE_OVERLAY, "Overlay" },
78 { DRM_PLANE_TYPE_PRIMARY, "Primary" },
79 { DRM_PLANE_TYPE_CURSOR, "Cursor" },
85 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
86 { DRM_MODE_SCALE_NONE, "None" },
87 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
88 { DRM_MODE_SCALE_CENTER, "Center" },
89 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
92 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
93 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
94 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
95 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
99 * Non-global properties, but "required" for certain connectors.
101 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
102 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
103 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
104 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
107 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
109 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
110 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
111 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
112 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
115 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
116 drm_dvi_i_subconnector_enum_list)
118 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
119 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
120 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
121 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
122 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
123 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
126 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
128 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
129 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
130 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
131 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
132 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
133 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
136 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
137 drm_tv_subconnector_enum_list)
139 static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = {
140 { DRM_MODE_DIRTY_OFF, "Off" },
141 { DRM_MODE_DIRTY_ON, "On" },
142 { DRM_MODE_DIRTY_ANNOTATE, "Annotate" },
145 struct drm_conn_prop_enum_list {
152 * Connector and encoder types.
154 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
155 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
156 { DRM_MODE_CONNECTOR_VGA, "VGA" },
157 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
158 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
159 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
160 { DRM_MODE_CONNECTOR_Composite, "Composite" },
161 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
162 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
163 { DRM_MODE_CONNECTOR_Component, "Component" },
164 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
165 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
166 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
167 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
168 { DRM_MODE_CONNECTOR_TV, "TV" },
169 { DRM_MODE_CONNECTOR_eDP, "eDP" },
170 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
171 { DRM_MODE_CONNECTOR_DSI, "DSI" },
172 { DRM_MODE_CONNECTOR_DPI, "DPI" },
175 static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
176 { DRM_MODE_ENCODER_NONE, "None" },
177 { DRM_MODE_ENCODER_DAC, "DAC" },
178 { DRM_MODE_ENCODER_TMDS, "TMDS" },
179 { DRM_MODE_ENCODER_LVDS, "LVDS" },
180 { DRM_MODE_ENCODER_TVDAC, "TV" },
181 { DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
182 { DRM_MODE_ENCODER_DSI, "DSI" },
183 { DRM_MODE_ENCODER_DPMST, "DP MST" },
184 { DRM_MODE_ENCODER_DPI, "DPI" },
187 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
188 { SubPixelUnknown, "Unknown" },
189 { SubPixelHorizontalRGB, "Horizontal RGB" },
190 { SubPixelHorizontalBGR, "Horizontal BGR" },
191 { SubPixelVerticalRGB, "Vertical RGB" },
192 { SubPixelVerticalBGR, "Vertical BGR" },
193 { SubPixelNone, "None" },
196 void drm_connector_ida_init(void)
200 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
201 ida_init(&drm_connector_enum_list[i].ida);
204 void drm_connector_ida_destroy(void)
208 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
209 ida_destroy(&drm_connector_enum_list[i].ida);
213 * drm_get_connector_status_name - return a string for connector status
214 * @status: connector status to compute name of
216 * In contrast to the other drm_get_*_name functions this one here returns a
217 * const pointer and hence is threadsafe.
219 const char *drm_get_connector_status_name(enum drm_connector_status status)
221 if (status == connector_status_connected)
223 else if (status == connector_status_disconnected)
224 return "disconnected";
228 EXPORT_SYMBOL(drm_get_connector_status_name);
231 * drm_get_subpixel_order_name - return a string for a given subpixel enum
232 * @order: enum of subpixel_order
234 * Note you could abuse this and return something out of bounds, but that
235 * would be a caller error. No unscrubbed user data should make it here.
237 const char *drm_get_subpixel_order_name(enum subpixel_order order)
239 return drm_subpixel_enum_list[order].name;
241 EXPORT_SYMBOL(drm_get_subpixel_order_name);
244 * Internal function to assign a slot in the object idr and optionally
245 * register the object into the idr.
247 static int drm_mode_object_get_reg(struct drm_device *dev,
248 struct drm_mode_object *obj,
251 void (*obj_free_cb)(struct kref *kref))
255 mutex_lock(&dev->mode_config.idr_mutex);
256 ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_KERNEL);
259 * Set up the object linking under the protection of the idr
260 * lock so that other users can't see inconsistent state.
263 obj->type = obj_type;
265 obj->free_cb = obj_free_cb;
266 kref_init(&obj->refcount);
269 mutex_unlock(&dev->mode_config.idr_mutex);
271 return ret < 0 ? ret : 0;
275 * drm_mode_object_get - allocate a new modeset identifier
277 * @obj: object pointer, used to generate unique ID
278 * @obj_type: object type
280 * Create a unique identifier based on @ptr in @dev's identifier space. Used
281 * for tracking modes, CRTCs and connectors. Note that despite the _get postfix
282 * modeset identifiers are _not_ reference counted. Hence don't use this for
283 * reference counted modeset objects like framebuffers.
286 * Zero on success, error code on failure.
288 int drm_mode_object_get(struct drm_device *dev,
289 struct drm_mode_object *obj, uint32_t obj_type)
291 return drm_mode_object_get_reg(dev, obj, obj_type, true, NULL);
294 static void drm_mode_object_register(struct drm_device *dev,
295 struct drm_mode_object *obj)
297 mutex_lock(&dev->mode_config.idr_mutex);
298 idr_replace(&dev->mode_config.crtc_idr, obj, obj->id);
299 mutex_unlock(&dev->mode_config.idr_mutex);
303 * drm_mode_object_unregister - free a modeset identifer
305 * @object: object to free
307 * Free @id from @dev's unique identifier pool.
308 * This function can be called multiple times, and guards against
310 * These modeset identifiers are _not_ reference counted. Hence don't use this
311 * for reference counted modeset objects like framebuffers.
313 void drm_mode_object_unregister(struct drm_device *dev,
314 struct drm_mode_object *object)
316 mutex_lock(&dev->mode_config.idr_mutex);
318 idr_remove(&dev->mode_config.crtc_idr, object->id);
321 mutex_unlock(&dev->mode_config.idr_mutex);
324 static struct drm_mode_object *_object_find(struct drm_device *dev,
325 uint32_t id, uint32_t type)
327 struct drm_mode_object *obj = NULL;
329 mutex_lock(&dev->mode_config.idr_mutex);
330 obj = idr_find(&dev->mode_config.crtc_idr, id);
331 if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type)
333 if (obj && obj->id != id)
336 if (obj && obj->free_cb) {
337 if (!kref_get_unless_zero(&obj->refcount))
340 mutex_unlock(&dev->mode_config.idr_mutex);
346 * drm_mode_object_find - look up a drm object with static lifetime
348 * @id: id of the mode object
349 * @type: type of the mode object
351 * This function is used to look up a modeset object. It will acquire a
352 * reference for reference counted objects. This reference must be dropped again
353 * by callind drm_mode_object_unreference().
355 struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
356 uint32_t id, uint32_t type)
358 struct drm_mode_object *obj = NULL;
360 obj = _object_find(dev, id, type);
363 EXPORT_SYMBOL(drm_mode_object_find);
366 * drm_mode_object_unreference - decr the object refcnt
369 * This functions decrements the object's refcount if it is a refcounted modeset
370 * object. It is a no-op on any other object. This is used to drop references
371 * acquired with drm_mode_object_reference().
373 void drm_mode_object_unreference(struct drm_mode_object *obj)
376 DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
377 kref_put(&obj->refcount, obj->free_cb);
380 EXPORT_SYMBOL(drm_mode_object_unreference);
383 * drm_mode_object_reference - incr the object refcnt
386 * This functions increments the object's refcount if it is a refcounted modeset
387 * object. It is a no-op on any other object. References should be dropped again
388 * by calling drm_mode_object_unreference().
390 void drm_mode_object_reference(struct drm_mode_object *obj)
393 DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
394 kref_get(&obj->refcount);
397 EXPORT_SYMBOL(drm_mode_object_reference);
400 * drm_crtc_force_disable - Forcibly turn off a CRTC
401 * @crtc: CRTC to turn off
404 * Zero on success, error code on failure.
406 int drm_crtc_force_disable(struct drm_crtc *crtc)
408 struct drm_mode_set set = {
412 return drm_mode_set_config_internal(&set);
414 EXPORT_SYMBOL(drm_crtc_force_disable);
417 * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs
418 * @dev: DRM device whose CRTCs to turn off
420 * Drivers may want to call this on unload to ensure that all displays are
421 * unlit and the GPU is in a consistent, low power state. Takes modeset locks.
424 * Zero on success, error code on failure.
426 int drm_crtc_force_disable_all(struct drm_device *dev)
428 struct drm_crtc *crtc;
431 drm_modeset_lock_all(dev);
432 drm_for_each_crtc(crtc, dev)
434 ret = drm_crtc_force_disable(crtc);
439 drm_modeset_unlock_all(dev);
442 EXPORT_SYMBOL(drm_crtc_force_disable_all);
444 static void drm_framebuffer_free(struct kref *kref)
446 struct drm_framebuffer *fb =
447 container_of(kref, struct drm_framebuffer, base.refcount);
448 struct drm_device *dev = fb->dev;
451 * The lookup idr holds a weak reference, which has not necessarily been
452 * removed at this point. Check for that.
454 drm_mode_object_unregister(dev, &fb->base);
456 fb->funcs->destroy(fb);
460 * drm_framebuffer_init - initialize a framebuffer
462 * @fb: framebuffer to be initialized
463 * @funcs: ... with these functions
465 * Allocates an ID for the framebuffer's parent mode object, sets its mode
466 * functions & device file and adds it to the master fd list.
469 * This functions publishes the fb and makes it available for concurrent access
470 * by other users. Which means by this point the fb _must_ be fully set up -
471 * since all the fb attributes are invariant over its lifetime, no further
472 * locking but only correct reference counting is required.
475 * Zero on success, error code on failure.
477 int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
478 const struct drm_framebuffer_funcs *funcs)
482 INIT_LIST_HEAD(&fb->filp_head);
486 ret = drm_mode_object_get_reg(dev, &fb->base, DRM_MODE_OBJECT_FB,
487 false, drm_framebuffer_free);
491 mutex_lock(&dev->mode_config.fb_lock);
492 dev->mode_config.num_fb++;
493 list_add(&fb->head, &dev->mode_config.fb_list);
494 mutex_unlock(&dev->mode_config.fb_lock);
496 drm_mode_object_register(dev, &fb->base);
500 EXPORT_SYMBOL(drm_framebuffer_init);
503 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
505 * @id: id of the fb object
507 * If successful, this grabs an additional reference to the framebuffer -
508 * callers need to make sure to eventually unreference the returned framebuffer
509 * again, using @drm_framebuffer_unreference.
511 struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
514 struct drm_mode_object *obj;
515 struct drm_framebuffer *fb = NULL;
517 obj = _object_find(dev, id, DRM_MODE_OBJECT_FB);
522 EXPORT_SYMBOL(drm_framebuffer_lookup);
525 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
526 * @fb: fb to unregister
528 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
529 * those used for fbdev. Note that the caller must hold a reference of it's own,
530 * i.e. the object may not be destroyed through this call (since it'll lead to a
531 * locking inversion).
533 void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
535 struct drm_device *dev;
542 /* Mark fb as reaped and drop idr ref. */
543 drm_mode_object_unregister(dev, &fb->base);
545 EXPORT_SYMBOL(drm_framebuffer_unregister_private);
548 * drm_framebuffer_cleanup - remove a framebuffer object
549 * @fb: framebuffer to remove
551 * Cleanup framebuffer. This function is intended to be used from the drivers
552 * ->destroy callback. It can also be used to clean up driver private
553 * framebuffers embedded into a larger structure.
555 * Note that this function does not remove the fb from active usuage - if it is
556 * still used anywhere, hilarity can ensue since userspace could call getfb on
557 * the id and get back -EINVAL. Obviously no concern at driver unload time.
559 * Also, the framebuffer will not be removed from the lookup idr - for
560 * user-created framebuffers this will happen in in the rmfb ioctl. For
561 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
562 * drm_framebuffer_unregister_private.
564 void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
566 struct drm_device *dev = fb->dev;
568 mutex_lock(&dev->mode_config.fb_lock);
570 dev->mode_config.num_fb--;
571 mutex_unlock(&dev->mode_config.fb_lock);
573 EXPORT_SYMBOL(drm_framebuffer_cleanup);
576 * drm_framebuffer_remove - remove and unreference a framebuffer object
577 * @fb: framebuffer to remove
579 * Scans all the CRTCs and planes in @dev's mode_config. If they're
580 * using @fb, removes it, setting it to NULL. Then drops the reference to the
581 * passed-in framebuffer. Might take the modeset locks.
583 * Note that this function optimizes the cleanup away if the caller holds the
584 * last reference to the framebuffer. It is also guaranteed to not take the
585 * modeset locks in this case.
587 void drm_framebuffer_remove(struct drm_framebuffer *fb)
589 struct drm_device *dev;
590 struct drm_crtc *crtc;
591 struct drm_plane *plane;
598 WARN_ON(!list_empty(&fb->filp_head));
601 * drm ABI mandates that we remove any deleted framebuffers from active
602 * useage. But since most sane clients only remove framebuffers they no
603 * longer need, try to optimize this away.
605 * Since we're holding a reference ourselves, observing a refcount of 1
606 * means that we're the last holder and can skip it. Also, the refcount
607 * can never increase from 1 again, so we don't need any barriers or
610 * Note that userspace could try to race with use and instate a new
611 * usage _after_ we've cleared all current ones. End result will be an
612 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
615 if (drm_framebuffer_read_refcount(fb) > 1) {
616 if (dev->mode_config.funcs->atomic_commit) {
617 drm_atomic_remove_fb(fb);
621 drm_modeset_lock_all(dev);
622 /* remove from any CRTC */
623 drm_for_each_crtc(crtc, dev) {
624 if (crtc->primary->fb == fb) {
625 /* should turn off the crtc */
626 if (drm_crtc_force_disable(crtc))
627 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
631 drm_for_each_plane(plane, dev) {
633 drm_plane_force_disable(plane);
635 drm_modeset_unlock_all(dev);
639 drm_framebuffer_unreference(fb);
641 EXPORT_SYMBOL(drm_framebuffer_remove);
643 DEFINE_WW_CLASS(crtc_ww_class);
645 static unsigned int drm_num_crtcs(struct drm_device *dev)
647 unsigned int num = 0;
648 struct drm_crtc *tmp;
650 drm_for_each_crtc(tmp, dev) {
657 static int drm_crtc_register_all(struct drm_device *dev)
659 struct drm_crtc *crtc;
662 drm_for_each_crtc(crtc, dev) {
663 if (crtc->funcs->late_register)
664 ret = crtc->funcs->late_register(crtc);
672 static void drm_crtc_unregister_all(struct drm_device *dev)
674 struct drm_crtc *crtc;
676 drm_for_each_crtc(crtc, dev) {
677 if (crtc->funcs->early_unregister)
678 crtc->funcs->early_unregister(crtc);
683 * drm_crtc_init_with_planes - Initialise a new CRTC object with
684 * specified primary and cursor planes.
686 * @crtc: CRTC object to init
687 * @primary: Primary plane for CRTC
688 * @cursor: Cursor plane for CRTC
689 * @funcs: callbacks for the new CRTC
690 * @name: printf style format string for the CRTC name, or NULL for default name
692 * Inits a new object created as base part of a driver crtc object.
695 * Zero on success, error code on failure.
697 int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
698 struct drm_plane *primary,
699 struct drm_plane *cursor,
700 const struct drm_crtc_funcs *funcs,
701 const char *name, ...)
703 struct drm_mode_config *config = &dev->mode_config;
706 WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY);
707 WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR);
712 INIT_LIST_HEAD(&crtc->commit_list);
713 spin_lock_init(&crtc->commit_lock);
715 drm_modeset_lock_init(&crtc->mutex);
716 ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
724 crtc->name = kvasprintf(GFP_KERNEL, name, ap);
727 crtc->name = kasprintf(GFP_KERNEL, "crtc-%d",
731 drm_mode_object_unregister(dev, &crtc->base);
735 crtc->base.properties = &crtc->properties;
737 list_add_tail(&crtc->head, &config->crtc_list);
738 crtc->index = config->num_crtc++;
740 crtc->primary = primary;
741 crtc->cursor = cursor;
743 primary->possible_crtcs = 1 << drm_crtc_index(crtc);
745 cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
747 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
748 drm_object_attach_property(&crtc->base, config->prop_active, 0);
749 drm_object_attach_property(&crtc->base, config->prop_mode_id, 0);
754 EXPORT_SYMBOL(drm_crtc_init_with_planes);
757 * drm_crtc_cleanup - Clean up the core crtc usage
758 * @crtc: CRTC to cleanup
760 * This function cleans up @crtc and removes it from the DRM mode setting
761 * core. Note that the function does *not* free the crtc structure itself,
762 * this is the responsibility of the caller.
764 void drm_crtc_cleanup(struct drm_crtc *crtc)
766 struct drm_device *dev = crtc->dev;
768 /* Note that the crtc_list is considered to be static; should we
769 * remove the drm_crtc at runtime we would have to decrement all
770 * the indices on the drm_crtc after us in the crtc_list.
773 kfree(crtc->gamma_store);
774 crtc->gamma_store = NULL;
776 drm_modeset_lock_fini(&crtc->mutex);
778 drm_mode_object_unregister(dev, &crtc->base);
779 list_del(&crtc->head);
780 dev->mode_config.num_crtc--;
782 WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state);
783 if (crtc->state && crtc->funcs->atomic_destroy_state)
784 crtc->funcs->atomic_destroy_state(crtc, crtc->state);
788 memset(crtc, 0, sizeof(*crtc));
790 EXPORT_SYMBOL(drm_crtc_cleanup);
793 * drm_mode_remove - remove and free a mode
794 * @connector: connector list to modify
795 * @mode: mode to remove
797 * Remove @mode from @connector's mode list, then free it.
799 static void drm_mode_remove(struct drm_connector *connector,
800 struct drm_display_mode *mode)
802 list_del(&mode->head);
803 drm_mode_destroy(connector->dev, mode);
807 * drm_display_info_set_bus_formats - set the supported bus formats
808 * @info: display info to store bus formats in
809 * @formats: array containing the supported bus formats
810 * @num_formats: the number of entries in the fmts array
812 * Store the supported bus formats in display info structure.
813 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
814 * a full list of available formats.
816 int drm_display_info_set_bus_formats(struct drm_display_info *info,
818 unsigned int num_formats)
822 if (!formats && num_formats)
825 if (formats && num_formats) {
826 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
832 kfree(info->bus_formats);
833 info->bus_formats = fmts;
834 info->num_bus_formats = num_formats;
838 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
841 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
842 * @connector: connector to quwery
844 * The kernel supports per-connector configration of its consoles through
845 * use of the video= parameter. This function parses that option and
846 * extracts the user's specified mode (or enable/disable status) for a
847 * particular connector. This is typically only used during the early fbdev
850 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
852 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
855 if (fb_get_options(connector->name, &option))
858 if (!drm_mode_parse_command_line_for_connector(option,
866 switch (mode->force) {
870 case DRM_FORCE_ON_DIGITAL:
879 DRM_INFO("forcing %s connector %s\n", connector->name, s);
880 connector->force = mode->force;
883 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
885 mode->xres, mode->yres,
886 mode->refresh_specified ? mode->refresh : 60,
887 mode->rb ? " reduced blanking" : "",
888 mode->margins ? " with margins" : "",
889 mode->interlace ? " interlaced" : "");
892 static void drm_connector_free(struct kref *kref)
894 struct drm_connector *connector =
895 container_of(kref, struct drm_connector, base.refcount);
896 struct drm_device *dev = connector->dev;
898 drm_mode_object_unregister(dev, &connector->base);
899 connector->funcs->destroy(connector);
903 * drm_connector_init - Init a preallocated connector
905 * @connector: the connector to init
906 * @funcs: callbacks for this connector
907 * @connector_type: user visible type of the connector
909 * Initialises a preallocated connector. Connectors should be
910 * subclassed as part of driver connector objects.
913 * Zero on success, error code on failure.
915 int drm_connector_init(struct drm_device *dev,
916 struct drm_connector *connector,
917 const struct drm_connector_funcs *funcs,
920 struct drm_mode_config *config = &dev->mode_config;
922 struct ida *connector_ida =
923 &drm_connector_enum_list[connector_type].ida;
925 drm_modeset_lock_all(dev);
927 ret = drm_mode_object_get_reg(dev, &connector->base,
928 DRM_MODE_OBJECT_CONNECTOR,
929 false, drm_connector_free);
933 connector->base.properties = &connector->properties;
934 connector->dev = dev;
935 connector->funcs = funcs;
937 connector->connector_id = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL);
938 if (connector->connector_id < 0) {
939 ret = connector->connector_id;
943 connector->connector_type = connector_type;
944 connector->connector_type_id =
945 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
946 if (connector->connector_type_id < 0) {
947 ret = connector->connector_type_id;
951 kasprintf(GFP_KERNEL, "%s-%d",
952 drm_connector_enum_list[connector_type].name,
953 connector->connector_type_id);
954 if (!connector->name) {
956 goto out_put_type_id;
959 INIT_LIST_HEAD(&connector->probed_modes);
960 INIT_LIST_HEAD(&connector->modes);
961 connector->edid_blob_ptr = NULL;
962 connector->status = connector_status_unknown;
964 drm_connector_get_cmdline_mode(connector);
966 /* We should add connectors at the end to avoid upsetting the connector
968 list_add_tail(&connector->head, &config->connector_list);
969 config->num_connector++;
971 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
972 drm_object_attach_property(&connector->base,
973 config->edid_property,
976 drm_object_attach_property(&connector->base,
977 config->dpms_property, 0);
979 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
980 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
983 connector->debugfs_entry = NULL;
986 ida_remove(connector_ida, connector->connector_type_id);
989 ida_remove(&config->connector_ida, connector->connector_id);
992 drm_mode_object_unregister(dev, &connector->base);
995 drm_modeset_unlock_all(dev);
999 EXPORT_SYMBOL(drm_connector_init);
1002 * drm_connector_cleanup - cleans up an initialised connector
1003 * @connector: connector to cleanup
1005 * Cleans up the connector but doesn't free the object.
1007 void drm_connector_cleanup(struct drm_connector *connector)
1009 struct drm_device *dev = connector->dev;
1010 struct drm_display_mode *mode, *t;
1012 /* The connector should have been removed from userspace long before
1013 * it is finally destroyed.
1015 if (WARN_ON(connector->registered))
1016 drm_connector_unregister(connector);
1018 if (connector->tile_group) {
1019 drm_mode_put_tile_group(dev, connector->tile_group);
1020 connector->tile_group = NULL;
1023 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
1024 drm_mode_remove(connector, mode);
1026 list_for_each_entry_safe(mode, t, &connector->modes, head)
1027 drm_mode_remove(connector, mode);
1029 ida_remove(&drm_connector_enum_list[connector->connector_type].ida,
1030 connector->connector_type_id);
1032 ida_remove(&dev->mode_config.connector_ida,
1033 connector->connector_id);
1035 kfree(connector->display_info.bus_formats);
1036 drm_mode_object_unregister(dev, &connector->base);
1037 kfree(connector->name);
1038 connector->name = NULL;
1039 list_del(&connector->head);
1040 dev->mode_config.num_connector--;
1042 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
1043 if (connector->state && connector->funcs->atomic_destroy_state)
1044 connector->funcs->atomic_destroy_state(connector,
1047 memset(connector, 0, sizeof(*connector));
1049 EXPORT_SYMBOL(drm_connector_cleanup);
1052 * drm_connector_register - register a connector
1053 * @connector: the connector to register
1055 * Register userspace interfaces for a connector
1058 * Zero on success, error code on failure.
1060 int drm_connector_register(struct drm_connector *connector)
1064 if (connector->registered)
1067 ret = drm_sysfs_connector_add(connector);
1071 ret = drm_debugfs_connector_add(connector);
1076 if (connector->funcs->late_register) {
1077 ret = connector->funcs->late_register(connector);
1082 drm_mode_object_register(connector->dev, &connector->base);
1084 connector->registered = true;
1088 drm_debugfs_connector_remove(connector);
1090 drm_sysfs_connector_remove(connector);
1093 EXPORT_SYMBOL(drm_connector_register);
1096 * drm_connector_unregister - unregister a connector
1097 * @connector: the connector to unregister
1099 * Unregister userspace interfaces for a connector
1101 void drm_connector_unregister(struct drm_connector *connector)
1103 if (!connector->registered)
1106 if (connector->funcs->early_unregister)
1107 connector->funcs->early_unregister(connector);
1109 drm_sysfs_connector_remove(connector);
1110 drm_debugfs_connector_remove(connector);
1112 connector->registered = false;
1114 EXPORT_SYMBOL(drm_connector_unregister);
1116 static int drm_connector_register_all(struct drm_device *dev)
1118 struct drm_connector *connector;
1121 mutex_lock(&dev->mode_config.mutex);
1123 drm_for_each_connector(connector, dev) {
1124 ret = drm_connector_register(connector);
1129 mutex_unlock(&dev->mode_config.mutex);
1134 mutex_unlock(&dev->mode_config.mutex);
1135 drm_connector_unregister_all(dev);
1140 * drm_connector_unregister_all - unregister connector userspace interfaces
1143 * This functions unregisters all connectors from sysfs and other places so
1144 * that userspace can no longer access them. Drivers should call this as the
1145 * first step tearing down the device instace, or when the underlying
1146 * physical device disappeared (e.g. USB unplug), right before calling
1147 * drm_dev_unregister().
1149 void drm_connector_unregister_all(struct drm_device *dev)
1151 struct drm_connector *connector;
1153 /* FIXME: taking the mode config mutex ends up in a clash with sysfs */
1154 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
1155 drm_connector_unregister(connector);
1157 EXPORT_SYMBOL(drm_connector_unregister_all);
1159 static int drm_encoder_register_all(struct drm_device *dev)
1161 struct drm_encoder *encoder;
1164 drm_for_each_encoder(encoder, dev) {
1165 if (encoder->funcs->late_register)
1166 ret = encoder->funcs->late_register(encoder);
1174 static void drm_encoder_unregister_all(struct drm_device *dev)
1176 struct drm_encoder *encoder;
1178 drm_for_each_encoder(encoder, dev) {
1179 if (encoder->funcs->early_unregister)
1180 encoder->funcs->early_unregister(encoder);
1185 * drm_encoder_init - Init a preallocated encoder
1187 * @encoder: the encoder to init
1188 * @funcs: callbacks for this encoder
1189 * @encoder_type: user visible type of the encoder
1190 * @name: printf style format string for the encoder name, or NULL for default name
1192 * Initialises a preallocated encoder. Encoder should be
1193 * subclassed as part of driver encoder objects.
1196 * Zero on success, error code on failure.
1198 int drm_encoder_init(struct drm_device *dev,
1199 struct drm_encoder *encoder,
1200 const struct drm_encoder_funcs *funcs,
1201 int encoder_type, const char *name, ...)
1205 drm_modeset_lock_all(dev);
1207 ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
1212 encoder->encoder_type = encoder_type;
1213 encoder->funcs = funcs;
1218 encoder->name = kvasprintf(GFP_KERNEL, name, ap);
1221 encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
1222 drm_encoder_enum_list[encoder_type].name,
1225 if (!encoder->name) {
1230 list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
1231 encoder->index = dev->mode_config.num_encoder++;
1235 drm_mode_object_unregister(dev, &encoder->base);
1238 drm_modeset_unlock_all(dev);
1242 EXPORT_SYMBOL(drm_encoder_init);
1245 * drm_encoder_cleanup - cleans up an initialised encoder
1246 * @encoder: encoder to cleanup
1248 * Cleans up the encoder but doesn't free the object.
1250 void drm_encoder_cleanup(struct drm_encoder *encoder)
1252 struct drm_device *dev = encoder->dev;
1254 /* Note that the encoder_list is considered to be static; should we
1255 * remove the drm_encoder at runtime we would have to decrement all
1256 * the indices on the drm_encoder after us in the encoder_list.
1259 drm_modeset_lock_all(dev);
1260 drm_mode_object_unregister(dev, &encoder->base);
1261 kfree(encoder->name);
1262 list_del(&encoder->head);
1263 dev->mode_config.num_encoder--;
1264 drm_modeset_unlock_all(dev);
1266 memset(encoder, 0, sizeof(*encoder));
1268 EXPORT_SYMBOL(drm_encoder_cleanup);
1270 static unsigned int drm_num_planes(struct drm_device *dev)
1272 unsigned int num = 0;
1273 struct drm_plane *tmp;
1275 drm_for_each_plane(tmp, dev) {
1283 * drm_universal_plane_init - Initialize a new universal plane object
1285 * @plane: plane object to init
1286 * @possible_crtcs: bitmask of possible CRTCs
1287 * @funcs: callbacks for the new plane
1288 * @formats: array of supported formats (%DRM_FORMAT_*)
1289 * @format_count: number of elements in @formats
1290 * @type: type of plane (overlay, primary, cursor)
1291 * @name: printf style format string for the plane name, or NULL for default name
1293 * Initializes a plane object of type @type.
1296 * Zero on success, error code on failure.
1298 int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
1299 unsigned long possible_crtcs,
1300 const struct drm_plane_funcs *funcs,
1301 const uint32_t *formats, unsigned int format_count,
1302 enum drm_plane_type type,
1303 const char *name, ...)
1305 struct drm_mode_config *config = &dev->mode_config;
1308 ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
1312 drm_modeset_lock_init(&plane->mutex);
1314 plane->base.properties = &plane->properties;
1316 plane->funcs = funcs;
1317 plane->format_types = kmalloc_array(format_count, sizeof(uint32_t),
1319 if (!plane->format_types) {
1320 DRM_DEBUG_KMS("out of memory when allocating plane\n");
1321 drm_mode_object_unregister(dev, &plane->base);
1329 plane->name = kvasprintf(GFP_KERNEL, name, ap);
1332 plane->name = kasprintf(GFP_KERNEL, "plane-%d",
1333 drm_num_planes(dev));
1336 kfree(plane->format_types);
1337 drm_mode_object_unregister(dev, &plane->base);
1341 memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
1342 plane->format_count = format_count;
1343 plane->possible_crtcs = possible_crtcs;
1346 list_add_tail(&plane->head, &config->plane_list);
1347 plane->index = config->num_total_plane++;
1348 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1349 config->num_overlay_plane++;
1351 drm_object_attach_property(&plane->base,
1352 config->plane_type_property,
1355 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
1356 drm_object_attach_property(&plane->base, config->prop_fb_id, 0);
1357 drm_object_attach_property(&plane->base, config->prop_crtc_id, 0);
1358 drm_object_attach_property(&plane->base, config->prop_crtc_x, 0);
1359 drm_object_attach_property(&plane->base, config->prop_crtc_y, 0);
1360 drm_object_attach_property(&plane->base, config->prop_crtc_w, 0);
1361 drm_object_attach_property(&plane->base, config->prop_crtc_h, 0);
1362 drm_object_attach_property(&plane->base, config->prop_src_x, 0);
1363 drm_object_attach_property(&plane->base, config->prop_src_y, 0);
1364 drm_object_attach_property(&plane->base, config->prop_src_w, 0);
1365 drm_object_attach_property(&plane->base, config->prop_src_h, 0);
1370 EXPORT_SYMBOL(drm_universal_plane_init);
1372 static int drm_plane_register_all(struct drm_device *dev)
1374 struct drm_plane *plane;
1377 drm_for_each_plane(plane, dev) {
1378 if (plane->funcs->late_register)
1379 ret = plane->funcs->late_register(plane);
1387 static void drm_plane_unregister_all(struct drm_device *dev)
1389 struct drm_plane *plane;
1391 drm_for_each_plane(plane, dev) {
1392 if (plane->funcs->early_unregister)
1393 plane->funcs->early_unregister(plane);
1398 * drm_plane_init - Initialize a legacy plane
1400 * @plane: plane object to init
1401 * @possible_crtcs: bitmask of possible CRTCs
1402 * @funcs: callbacks for the new plane
1403 * @formats: array of supported formats (%DRM_FORMAT_*)
1404 * @format_count: number of elements in @formats
1405 * @is_primary: plane type (primary vs overlay)
1407 * Legacy API to initialize a DRM plane.
1409 * New drivers should call drm_universal_plane_init() instead.
1412 * Zero on success, error code on failure.
1414 int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
1415 unsigned long possible_crtcs,
1416 const struct drm_plane_funcs *funcs,
1417 const uint32_t *formats, unsigned int format_count,
1420 enum drm_plane_type type;
1422 type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY;
1423 return drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
1424 formats, format_count, type, NULL);
1426 EXPORT_SYMBOL(drm_plane_init);
1429 * drm_plane_cleanup - Clean up the core plane usage
1430 * @plane: plane to cleanup
1432 * This function cleans up @plane and removes it from the DRM mode setting
1433 * core. Note that the function does *not* free the plane structure itself,
1434 * this is the responsibility of the caller.
1436 void drm_plane_cleanup(struct drm_plane *plane)
1438 struct drm_device *dev = plane->dev;
1440 drm_modeset_lock_all(dev);
1441 kfree(plane->format_types);
1442 drm_mode_object_unregister(dev, &plane->base);
1444 BUG_ON(list_empty(&plane->head));
1446 /* Note that the plane_list is considered to be static; should we
1447 * remove the drm_plane at runtime we would have to decrement all
1448 * the indices on the drm_plane after us in the plane_list.
1451 list_del(&plane->head);
1452 dev->mode_config.num_total_plane--;
1453 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1454 dev->mode_config.num_overlay_plane--;
1455 drm_modeset_unlock_all(dev);
1457 WARN_ON(plane->state && !plane->funcs->atomic_destroy_state);
1458 if (plane->state && plane->funcs->atomic_destroy_state)
1459 plane->funcs->atomic_destroy_state(plane, plane->state);
1463 memset(plane, 0, sizeof(*plane));
1465 EXPORT_SYMBOL(drm_plane_cleanup);
1468 * drm_plane_from_index - find the registered plane at an index
1470 * @idx: index of registered plane to find for
1472 * Given a plane index, return the registered plane from DRM device's
1473 * list of planes with matching index.
1476 drm_plane_from_index(struct drm_device *dev, int idx)
1478 struct drm_plane *plane;
1480 drm_for_each_plane(plane, dev)
1481 if (idx == plane->index)
1486 EXPORT_SYMBOL(drm_plane_from_index);
1489 * drm_plane_force_disable - Forcibly disable a plane
1490 * @plane: plane to disable
1492 * Forces the plane to be disabled.
1494 * Used when the plane's current framebuffer is destroyed,
1495 * and when restoring fbdev mode.
1497 void drm_plane_force_disable(struct drm_plane *plane)
1504 plane->old_fb = plane->fb;
1505 ret = plane->funcs->disable_plane(plane);
1507 DRM_ERROR("failed to disable plane with busy fb\n");
1508 plane->old_fb = NULL;
1511 /* disconnect the plane from the fb and crtc: */
1512 drm_framebuffer_unreference(plane->old_fb);
1513 plane->old_fb = NULL;
1517 EXPORT_SYMBOL(drm_plane_force_disable);
1519 int drm_modeset_register_all(struct drm_device *dev)
1523 ret = drm_plane_register_all(dev);
1527 ret = drm_crtc_register_all(dev);
1531 ret = drm_encoder_register_all(dev);
1535 ret = drm_connector_register_all(dev);
1542 drm_encoder_unregister_all(dev);
1544 drm_crtc_unregister_all(dev);
1546 drm_plane_unregister_all(dev);
1551 void drm_modeset_unregister_all(struct drm_device *dev)
1553 drm_connector_unregister_all(dev);
1554 drm_encoder_unregister_all(dev);
1555 drm_crtc_unregister_all(dev);
1556 drm_plane_unregister_all(dev);
1559 static int drm_mode_create_standard_properties(struct drm_device *dev)
1561 struct drm_property *prop;
1564 * Standard properties (apply to all connectors)
1566 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1567 DRM_MODE_PROP_IMMUTABLE,
1571 dev->mode_config.edid_property = prop;
1573 prop = drm_property_create_enum(dev, 0,
1574 "DPMS", drm_dpms_enum_list,
1575 ARRAY_SIZE(drm_dpms_enum_list));
1578 dev->mode_config.dpms_property = prop;
1580 prop = drm_property_create(dev,
1581 DRM_MODE_PROP_BLOB |
1582 DRM_MODE_PROP_IMMUTABLE,
1586 dev->mode_config.path_property = prop;
1588 prop = drm_property_create(dev,
1589 DRM_MODE_PROP_BLOB |
1590 DRM_MODE_PROP_IMMUTABLE,
1594 dev->mode_config.tile_property = prop;
1596 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1597 "type", drm_plane_type_enum_list,
1598 ARRAY_SIZE(drm_plane_type_enum_list));
1601 dev->mode_config.plane_type_property = prop;
1603 prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
1604 "SRC_X", 0, UINT_MAX);
1607 dev->mode_config.prop_src_x = prop;
1609 prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
1610 "SRC_Y", 0, UINT_MAX);
1613 dev->mode_config.prop_src_y = prop;
1615 prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
1616 "SRC_W", 0, UINT_MAX);
1619 dev->mode_config.prop_src_w = prop;
1621 prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
1622 "SRC_H", 0, UINT_MAX);
1625 dev->mode_config.prop_src_h = prop;
1627 prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC,
1628 "CRTC_X", INT_MIN, INT_MAX);
1631 dev->mode_config.prop_crtc_x = prop;
1633 prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC,
1634 "CRTC_Y", INT_MIN, INT_MAX);
1637 dev->mode_config.prop_crtc_y = prop;
1639 prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
1640 "CRTC_W", 0, INT_MAX);
1643 dev->mode_config.prop_crtc_w = prop;
1645 prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC,
1646 "CRTC_H", 0, INT_MAX);
1649 dev->mode_config.prop_crtc_h = prop;
1651 prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC,
1652 "FB_ID", DRM_MODE_OBJECT_FB);
1655 dev->mode_config.prop_fb_id = prop;
1657 prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC,
1658 "CRTC_ID", DRM_MODE_OBJECT_CRTC);
1661 dev->mode_config.prop_crtc_id = prop;
1663 prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC,
1667 dev->mode_config.prop_active = prop;
1669 prop = drm_property_create(dev,
1670 DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB,
1674 dev->mode_config.prop_mode_id = prop;
1676 prop = drm_property_create(dev,
1681 dev->mode_config.degamma_lut_property = prop;
1683 prop = drm_property_create_range(dev,
1684 DRM_MODE_PROP_IMMUTABLE,
1685 "DEGAMMA_LUT_SIZE", 0, UINT_MAX);
1688 dev->mode_config.degamma_lut_size_property = prop;
1690 prop = drm_property_create(dev,
1695 dev->mode_config.ctm_property = prop;
1697 prop = drm_property_create(dev,
1702 dev->mode_config.gamma_lut_property = prop;
1704 prop = drm_property_create_range(dev,
1705 DRM_MODE_PROP_IMMUTABLE,
1706 "GAMMA_LUT_SIZE", 0, UINT_MAX);
1709 dev->mode_config.gamma_lut_size_property = prop;
1715 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1718 * Called by a driver the first time a DVI-I connector is made.
1720 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1722 struct drm_property *dvi_i_selector;
1723 struct drm_property *dvi_i_subconnector;
1725 if (dev->mode_config.dvi_i_select_subconnector_property)
1729 drm_property_create_enum(dev, 0,
1730 "select subconnector",
1731 drm_dvi_i_select_enum_list,
1732 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1733 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1735 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1737 drm_dvi_i_subconnector_enum_list,
1738 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1739 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1743 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1746 * drm_create_tv_properties - create TV specific connector properties
1748 * @num_modes: number of different TV formats (modes) supported
1749 * @modes: array of pointers to strings containing name of each format
1751 * Called by a driver's TV initialization routine, this function creates
1752 * the TV specific connector properties for a given device. Caller is
1753 * responsible for allocating a list of format names and passing them to
1756 int drm_mode_create_tv_properties(struct drm_device *dev,
1757 unsigned int num_modes,
1758 const char * const modes[])
1760 struct drm_property *tv_selector;
1761 struct drm_property *tv_subconnector;
1764 if (dev->mode_config.tv_select_subconnector_property)
1768 * Basic connector properties
1770 tv_selector = drm_property_create_enum(dev, 0,
1771 "select subconnector",
1772 drm_tv_select_enum_list,
1773 ARRAY_SIZE(drm_tv_select_enum_list));
1777 dev->mode_config.tv_select_subconnector_property = tv_selector;
1780 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1782 drm_tv_subconnector_enum_list,
1783 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1784 if (!tv_subconnector)
1786 dev->mode_config.tv_subconnector_property = tv_subconnector;
1789 * Other, TV specific properties: margins & TV modes.
1791 dev->mode_config.tv_left_margin_property =
1792 drm_property_create_range(dev, 0, "left margin", 0, 100);
1793 if (!dev->mode_config.tv_left_margin_property)
1796 dev->mode_config.tv_right_margin_property =
1797 drm_property_create_range(dev, 0, "right margin", 0, 100);
1798 if (!dev->mode_config.tv_right_margin_property)
1801 dev->mode_config.tv_top_margin_property =
1802 drm_property_create_range(dev, 0, "top margin", 0, 100);
1803 if (!dev->mode_config.tv_top_margin_property)
1806 dev->mode_config.tv_bottom_margin_property =
1807 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1808 if (!dev->mode_config.tv_bottom_margin_property)
1811 dev->mode_config.tv_mode_property =
1812 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1814 if (!dev->mode_config.tv_mode_property)
1817 for (i = 0; i < num_modes; i++)
1818 drm_property_add_enum(dev->mode_config.tv_mode_property, i,
1821 dev->mode_config.tv_brightness_property =
1822 drm_property_create_range(dev, 0, "brightness", 0, 100);
1823 if (!dev->mode_config.tv_brightness_property)
1826 dev->mode_config.tv_contrast_property =
1827 drm_property_create_range(dev, 0, "contrast", 0, 100);
1828 if (!dev->mode_config.tv_contrast_property)
1831 dev->mode_config.tv_flicker_reduction_property =
1832 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1833 if (!dev->mode_config.tv_flicker_reduction_property)
1836 dev->mode_config.tv_overscan_property =
1837 drm_property_create_range(dev, 0, "overscan", 0, 100);
1838 if (!dev->mode_config.tv_overscan_property)
1841 dev->mode_config.tv_saturation_property =
1842 drm_property_create_range(dev, 0, "saturation", 0, 100);
1843 if (!dev->mode_config.tv_saturation_property)
1846 dev->mode_config.tv_hue_property =
1847 drm_property_create_range(dev, 0, "hue", 0, 100);
1848 if (!dev->mode_config.tv_hue_property)
1855 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1858 * drm_mode_create_scaling_mode_property - create scaling mode property
1861 * Called by a driver the first time it's needed, must be attached to desired
1864 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1866 struct drm_property *scaling_mode;
1868 if (dev->mode_config.scaling_mode_property)
1872 drm_property_create_enum(dev, 0, "scaling mode",
1873 drm_scaling_mode_enum_list,
1874 ARRAY_SIZE(drm_scaling_mode_enum_list));
1876 dev->mode_config.scaling_mode_property = scaling_mode;
1880 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1883 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1886 * Called by a driver the first time it's needed, must be attached to desired
1890 * Zero on success, negative errno on failure.
1892 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1894 if (dev->mode_config.aspect_ratio_property)
1897 dev->mode_config.aspect_ratio_property =
1898 drm_property_create_enum(dev, 0, "aspect ratio",
1899 drm_aspect_ratio_enum_list,
1900 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1902 if (dev->mode_config.aspect_ratio_property == NULL)
1907 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1910 * drm_mode_create_dirty_property - create dirty property
1913 * Called by a driver the first time it's needed, must be attached to desired
1916 int drm_mode_create_dirty_info_property(struct drm_device *dev)
1918 struct drm_property *dirty_info;
1920 if (dev->mode_config.dirty_info_property)
1924 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1926 drm_dirty_info_enum_list,
1927 ARRAY_SIZE(drm_dirty_info_enum_list));
1928 dev->mode_config.dirty_info_property = dirty_info;
1932 EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
1935 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1938 * Create the the suggested x/y offset property for connectors.
1940 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1942 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1945 dev->mode_config.suggested_x_property =
1946 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1948 dev->mode_config.suggested_y_property =
1949 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
1951 if (dev->mode_config.suggested_x_property == NULL ||
1952 dev->mode_config.suggested_y_property == NULL)
1956 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
1959 * drm_mode_getresources - get graphics configuration
1960 * @dev: drm device for the ioctl
1961 * @data: data pointer for the ioctl
1962 * @file_priv: drm file for the ioctl call
1964 * Construct a set of configuration description structures and return
1965 * them to the user, including CRTC, connector and framebuffer configuration.
1967 * Called by the user via ioctl.
1970 * Zero on success, negative errno on failure.
1972 int drm_mode_getresources(struct drm_device *dev, void *data,
1973 struct drm_file *file_priv)
1975 struct drm_mode_card_res *card_res = data;
1976 struct list_head *lh;
1977 struct drm_framebuffer *fb;
1978 struct drm_connector *connector;
1979 struct drm_crtc *crtc;
1980 struct drm_encoder *encoder;
1982 int connector_count = 0;
1985 int encoder_count = 0;
1987 uint32_t __user *fb_id;
1988 uint32_t __user *crtc_id;
1989 uint32_t __user *connector_id;
1990 uint32_t __user *encoder_id;
1992 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1996 mutex_lock(&file_priv->fbs_lock);
1998 * For the non-control nodes we need to limit the list of resources
1999 * by IDs in the group list for this node
2001 list_for_each(lh, &file_priv->fbs)
2004 /* handle this in 4 parts */
2006 if (card_res->count_fbs >= fb_count) {
2008 fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
2009 list_for_each_entry(fb, &file_priv->fbs, filp_head) {
2010 if (put_user(fb->base.id, fb_id + copied)) {
2011 mutex_unlock(&file_priv->fbs_lock);
2017 card_res->count_fbs = fb_count;
2018 mutex_unlock(&file_priv->fbs_lock);
2020 /* mode_config.mutex protects the connector list against e.g. DP MST
2021 * connector hot-adding. CRTC/Plane lists are invariant. */
2022 mutex_lock(&dev->mode_config.mutex);
2023 drm_for_each_crtc(crtc, dev)
2026 drm_for_each_connector(connector, dev)
2029 drm_for_each_encoder(encoder, dev)
2032 card_res->max_height = dev->mode_config.max_height;
2033 card_res->min_height = dev->mode_config.min_height;
2034 card_res->max_width = dev->mode_config.max_width;
2035 card_res->min_width = dev->mode_config.min_width;
2038 if (card_res->count_crtcs >= crtc_count) {
2040 crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
2041 drm_for_each_crtc(crtc, dev) {
2042 if (put_user(crtc->base.id, crtc_id + copied)) {
2049 card_res->count_crtcs = crtc_count;
2052 if (card_res->count_encoders >= encoder_count) {
2054 encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
2055 drm_for_each_encoder(encoder, dev) {
2056 if (put_user(encoder->base.id, encoder_id +
2064 card_res->count_encoders = encoder_count;
2067 if (card_res->count_connectors >= connector_count) {
2069 connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
2070 drm_for_each_connector(connector, dev) {
2071 if (put_user(connector->base.id,
2072 connector_id + copied)) {
2079 card_res->count_connectors = connector_count;
2082 mutex_unlock(&dev->mode_config.mutex);
2087 * drm_mode_getcrtc - get CRTC configuration
2088 * @dev: drm device for the ioctl
2089 * @data: data pointer for the ioctl
2090 * @file_priv: drm file for the ioctl call
2092 * Construct a CRTC configuration structure to return to the user.
2094 * Called by the user via ioctl.
2097 * Zero on success, negative errno on failure.
2099 int drm_mode_getcrtc(struct drm_device *dev,
2100 void *data, struct drm_file *file_priv)
2102 struct drm_mode_crtc *crtc_resp = data;
2103 struct drm_crtc *crtc;
2105 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2108 crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
2112 drm_modeset_lock_crtc(crtc, crtc->primary);
2113 crtc_resp->gamma_size = crtc->gamma_size;
2114 if (crtc->primary->fb)
2115 crtc_resp->fb_id = crtc->primary->fb->base.id;
2117 crtc_resp->fb_id = 0;
2120 crtc_resp->x = crtc->primary->state->src_x >> 16;
2121 crtc_resp->y = crtc->primary->state->src_y >> 16;
2122 if (crtc->state->enable) {
2123 drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
2124 crtc_resp->mode_valid = 1;
2127 crtc_resp->mode_valid = 0;
2130 crtc_resp->x = crtc->x;
2131 crtc_resp->y = crtc->y;
2132 if (crtc->enabled) {
2133 drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
2134 crtc_resp->mode_valid = 1;
2137 crtc_resp->mode_valid = 0;
2140 drm_modeset_unlock_crtc(crtc);
2145 static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
2146 const struct drm_file *file_priv)
2149 * If user-space hasn't configured the driver to expose the stereo 3D
2150 * modes, don't expose them.
2152 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
2158 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
2160 /* For atomic drivers only state objects are synchronously updated and
2161 * protected by modeset locks, so check those first. */
2162 if (connector->state)
2163 return connector->state->best_encoder;
2164 return connector->encoder;
2167 /* helper for getconnector and getproperties ioctls */
2168 static int get_properties(struct drm_mode_object *obj, bool atomic,
2169 uint32_t __user *prop_ptr, uint64_t __user *prop_values,
2170 uint32_t *arg_count_props)
2175 props_count = obj->properties->count;
2177 props_count -= obj->properties->atomic_count;
2179 if ((*arg_count_props >= props_count) && props_count) {
2180 for (i = 0, copied = 0; copied < props_count; i++) {
2181 struct drm_property *prop = obj->properties->properties[i];
2184 if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic)
2187 ret = drm_object_property_get_value(obj, prop, &val);
2191 if (put_user(prop->base.id, prop_ptr + copied))
2194 if (put_user(val, prop_values + copied))
2200 *arg_count_props = props_count;
2206 * drm_mode_getconnector - get connector configuration
2207 * @dev: drm device for the ioctl
2208 * @data: data pointer for the ioctl
2209 * @file_priv: drm file for the ioctl call
2211 * Construct a connector configuration structure to return to the user.
2213 * Called by the user via ioctl.
2216 * Zero on success, negative errno on failure.
2218 int drm_mode_getconnector(struct drm_device *dev, void *data,
2219 struct drm_file *file_priv)
2221 struct drm_mode_get_connector *out_resp = data;
2222 struct drm_connector *connector;
2223 struct drm_encoder *encoder;
2224 struct drm_display_mode *mode;
2226 int encoders_count = 0;
2230 struct drm_mode_modeinfo u_mode;
2231 struct drm_mode_modeinfo __user *mode_ptr;
2232 uint32_t __user *encoder_ptr;
2234 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2237 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
2239 mutex_lock(&dev->mode_config.mutex);
2241 connector = drm_connector_lookup(dev, out_resp->connector_id);
2247 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++)
2248 if (connector->encoder_ids[i] != 0)
2251 if (out_resp->count_modes == 0) {
2252 connector->funcs->fill_modes(connector,
2253 dev->mode_config.max_width,
2254 dev->mode_config.max_height);
2257 /* delayed so we get modes regardless of pre-fill_modes state */
2258 list_for_each_entry(mode, &connector->modes, head)
2259 if (drm_mode_expose_to_userspace(mode, file_priv))
2262 out_resp->connector_id = connector->base.id;
2263 out_resp->connector_type = connector->connector_type;
2264 out_resp->connector_type_id = connector->connector_type_id;
2265 out_resp->mm_width = connector->display_info.width_mm;
2266 out_resp->mm_height = connector->display_info.height_mm;
2267 out_resp->subpixel = connector->display_info.subpixel_order;
2268 out_resp->connection = connector->status;
2270 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2271 encoder = drm_connector_get_encoder(connector);
2273 out_resp->encoder_id = encoder->base.id;
2275 out_resp->encoder_id = 0;
2278 * This ioctl is called twice, once to determine how much space is
2279 * needed, and the 2nd time to fill it.
2281 if ((out_resp->count_modes >= mode_count) && mode_count) {
2283 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2284 list_for_each_entry(mode, &connector->modes, head) {
2285 if (!drm_mode_expose_to_userspace(mode, file_priv))
2288 drm_mode_convert_to_umode(&u_mode, mode);
2289 if (copy_to_user(mode_ptr + copied,
2290 &u_mode, sizeof(u_mode))) {
2297 out_resp->count_modes = mode_count;
2299 ret = get_properties(&connector->base, file_priv->atomic,
2300 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2301 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2302 &out_resp->count_props);
2306 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2308 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
2309 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2310 if (connector->encoder_ids[i] != 0) {
2311 if (put_user(connector->encoder_ids[i],
2312 encoder_ptr + copied)) {
2320 out_resp->count_encoders = encoders_count;
2323 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2325 drm_connector_unreference(connector);
2327 mutex_unlock(&dev->mode_config.mutex);
2332 static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder)
2334 struct drm_connector *connector;
2335 struct drm_device *dev = encoder->dev;
2336 bool uses_atomic = false;
2338 /* For atomic drivers only state objects are synchronously updated and
2339 * protected by modeset locks, so check those first. */
2340 drm_for_each_connector(connector, dev) {
2341 if (!connector->state)
2346 if (connector->state->best_encoder != encoder)
2349 return connector->state->crtc;
2352 /* Don't return stale data (e.g. pending async disable). */
2356 return encoder->crtc;
2360 * drm_mode_getencoder - get encoder configuration
2361 * @dev: drm device for the ioctl
2362 * @data: data pointer for the ioctl
2363 * @file_priv: drm file for the ioctl call
2365 * Construct a encoder configuration structure to return to the user.
2367 * Called by the user via ioctl.
2370 * Zero on success, negative errno on failure.
2372 int drm_mode_getencoder(struct drm_device *dev, void *data,
2373 struct drm_file *file_priv)
2375 struct drm_mode_get_encoder *enc_resp = data;
2376 struct drm_encoder *encoder;
2377 struct drm_crtc *crtc;
2379 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2382 encoder = drm_encoder_find(dev, enc_resp->encoder_id);
2386 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2387 crtc = drm_encoder_get_crtc(encoder);
2389 enc_resp->crtc_id = crtc->base.id;
2391 enc_resp->crtc_id = 0;
2392 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2394 enc_resp->encoder_type = encoder->encoder_type;
2395 enc_resp->encoder_id = encoder->base.id;
2396 enc_resp->possible_crtcs = encoder->possible_crtcs;
2397 enc_resp->possible_clones = encoder->possible_clones;
2403 * drm_mode_getplane_res - enumerate all plane resources
2406 * @file_priv: DRM file info
2408 * Construct a list of plane ids to return to the user.
2410 * Called by the user via ioctl.
2413 * Zero on success, negative errno on failure.
2415 int drm_mode_getplane_res(struct drm_device *dev, void *data,
2416 struct drm_file *file_priv)
2418 struct drm_mode_get_plane_res *plane_resp = data;
2419 struct drm_mode_config *config;
2420 struct drm_plane *plane;
2421 uint32_t __user *plane_ptr;
2423 unsigned num_planes;
2425 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2428 config = &dev->mode_config;
2430 if (file_priv->universal_planes)
2431 num_planes = config->num_total_plane;
2433 num_planes = config->num_overlay_plane;
2436 * This ioctl is called twice, once to determine how much space is
2437 * needed, and the 2nd time to fill it.
2440 (plane_resp->count_planes >= num_planes)) {
2441 plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr;
2443 /* Plane lists are invariant, no locking needed. */
2444 drm_for_each_plane(plane, dev) {
2446 * Unless userspace set the 'universal planes'
2447 * capability bit, only advertise overlays.
2449 if (plane->type != DRM_PLANE_TYPE_OVERLAY &&
2450 !file_priv->universal_planes)
2453 if (put_user(plane->base.id, plane_ptr + copied))
2458 plane_resp->count_planes = num_planes;
2464 * drm_mode_getplane - get plane configuration
2467 * @file_priv: DRM file info
2469 * Construct a plane configuration structure to return to the user.
2471 * Called by the user via ioctl.
2474 * Zero on success, negative errno on failure.
2476 int drm_mode_getplane(struct drm_device *dev, void *data,
2477 struct drm_file *file_priv)
2479 struct drm_mode_get_plane *plane_resp = data;
2480 struct drm_plane *plane;
2481 uint32_t __user *format_ptr;
2483 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2486 plane = drm_plane_find(dev, plane_resp->plane_id);
2490 drm_modeset_lock(&plane->mutex, NULL);
2492 plane_resp->crtc_id = plane->crtc->base.id;
2494 plane_resp->crtc_id = 0;
2497 plane_resp->fb_id = plane->fb->base.id;
2499 plane_resp->fb_id = 0;
2500 drm_modeset_unlock(&plane->mutex);
2502 plane_resp->plane_id = plane->base.id;
2503 plane_resp->possible_crtcs = plane->possible_crtcs;
2504 plane_resp->gamma_size = 0;
2507 * This ioctl is called twice, once to determine how much space is
2508 * needed, and the 2nd time to fill it.
2510 if (plane->format_count &&
2511 (plane_resp->count_format_types >= plane->format_count)) {
2512 format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr;
2513 if (copy_to_user(format_ptr,
2514 plane->format_types,
2515 sizeof(uint32_t) * plane->format_count)) {
2519 plane_resp->count_format_types = plane->format_count;
2525 * drm_plane_check_pixel_format - Check if the plane supports the pixel format
2526 * @plane: plane to check for format support
2527 * @format: the pixel format
2530 * Zero of @plane has @format in its list of supported pixel formats, -EINVAL
2533 int drm_plane_check_pixel_format(const struct drm_plane *plane, u32 format)
2537 for (i = 0; i < plane->format_count; i++) {
2538 if (format == plane->format_types[i])
2545 static int check_src_coords(uint32_t src_x, uint32_t src_y,
2546 uint32_t src_w, uint32_t src_h,
2547 const struct drm_framebuffer *fb)
2549 unsigned int fb_width, fb_height;
2551 fb_width = fb->width << 16;
2552 fb_height = fb->height << 16;
2554 /* Make sure source coordinates are inside the fb. */
2555 if (src_w > fb_width ||
2556 src_x > fb_width - src_w ||
2557 src_h > fb_height ||
2558 src_y > fb_height - src_h) {
2559 DRM_DEBUG_KMS("Invalid source coordinates "
2560 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
2561 src_w >> 16, ((src_w & 0xffff) * 15625) >> 10,
2562 src_h >> 16, ((src_h & 0xffff) * 15625) >> 10,
2563 src_x >> 16, ((src_x & 0xffff) * 15625) >> 10,
2564 src_y >> 16, ((src_y & 0xffff) * 15625) >> 10);
2572 * setplane_internal - setplane handler for internal callers
2574 * Note that we assume an extra reference has already been taken on fb. If the
2575 * update fails, this reference will be dropped before return; if it succeeds,
2576 * the previous framebuffer (if any) will be unreferenced instead.
2578 * src_{x,y,w,h} are provided in 16.16 fixed point format
2580 static int __setplane_internal(struct drm_plane *plane,
2581 struct drm_crtc *crtc,
2582 struct drm_framebuffer *fb,
2583 int32_t crtc_x, int32_t crtc_y,
2584 uint32_t crtc_w, uint32_t crtc_h,
2585 /* src_{x,y,w,h} values are 16.16 fixed point */
2586 uint32_t src_x, uint32_t src_y,
2587 uint32_t src_w, uint32_t src_h)
2591 /* No fb means shut it down */
2593 plane->old_fb = plane->fb;
2594 ret = plane->funcs->disable_plane(plane);
2599 plane->old_fb = NULL;
2604 /* Check whether this plane is usable on this CRTC */
2605 if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
2606 DRM_DEBUG_KMS("Invalid crtc for plane\n");
2611 /* Check whether this plane supports the fb pixel format. */
2612 ret = drm_plane_check_pixel_format(plane, fb->pixel_format);
2614 DRM_DEBUG_KMS("Invalid pixel format %s\n",
2615 drm_get_format_name(fb->pixel_format));
2619 /* Give drivers some help against integer overflows */
2620 if (crtc_w > INT_MAX ||
2621 crtc_x > INT_MAX - (int32_t) crtc_w ||
2623 crtc_y > INT_MAX - (int32_t) crtc_h) {
2624 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
2625 crtc_w, crtc_h, crtc_x, crtc_y);
2630 ret = check_src_coords(src_x, src_y, src_w, src_h, fb);
2634 plane->old_fb = plane->fb;
2635 ret = plane->funcs->update_plane(plane, crtc, fb,
2636 crtc_x, crtc_y, crtc_w, crtc_h,
2637 src_x, src_y, src_w, src_h);
2643 plane->old_fb = NULL;
2648 drm_framebuffer_unreference(fb);
2650 drm_framebuffer_unreference(plane->old_fb);
2651 plane->old_fb = NULL;
2656 static int setplane_internal(struct drm_plane *plane,
2657 struct drm_crtc *crtc,
2658 struct drm_framebuffer *fb,
2659 int32_t crtc_x, int32_t crtc_y,
2660 uint32_t crtc_w, uint32_t crtc_h,
2661 /* src_{x,y,w,h} values are 16.16 fixed point */
2662 uint32_t src_x, uint32_t src_y,
2663 uint32_t src_w, uint32_t src_h)
2667 drm_modeset_lock_all(plane->dev);
2668 ret = __setplane_internal(plane, crtc, fb,
2669 crtc_x, crtc_y, crtc_w, crtc_h,
2670 src_x, src_y, src_w, src_h);
2671 drm_modeset_unlock_all(plane->dev);
2677 * drm_mode_setplane - configure a plane's configuration
2679 * @data: ioctl data*
2680 * @file_priv: DRM file info
2682 * Set plane configuration, including placement, fb, scaling, and other factors.
2683 * Or pass a NULL fb to disable (planes may be disabled without providing a
2687 * Zero on success, negative errno on failure.
2689 int drm_mode_setplane(struct drm_device *dev, void *data,
2690 struct drm_file *file_priv)
2692 struct drm_mode_set_plane *plane_req = data;
2693 struct drm_plane *plane;
2694 struct drm_crtc *crtc = NULL;
2695 struct drm_framebuffer *fb = NULL;
2697 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2701 * First, find the plane, crtc, and fb objects. If not available,
2702 * we don't bother to call the driver.
2704 plane = drm_plane_find(dev, plane_req->plane_id);
2706 DRM_DEBUG_KMS("Unknown plane ID %d\n",
2707 plane_req->plane_id);
2711 if (plane_req->fb_id) {
2712 fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
2714 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
2719 crtc = drm_crtc_find(dev, plane_req->crtc_id);
2721 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
2722 plane_req->crtc_id);
2728 * setplane_internal will take care of deref'ing either the old or new
2729 * framebuffer depending on success.
2731 return setplane_internal(plane, crtc, fb,
2732 plane_req->crtc_x, plane_req->crtc_y,
2733 plane_req->crtc_w, plane_req->crtc_h,
2734 plane_req->src_x, plane_req->src_y,
2735 plane_req->src_w, plane_req->src_h);
2739 * drm_mode_set_config_internal - helper to call ->set_config
2740 * @set: modeset config to set
2742 * This is a little helper to wrap internal calls to the ->set_config driver
2743 * interface. The only thing it adds is correct refcounting dance.
2746 * Zero on success, negative errno on failure.
2748 int drm_mode_set_config_internal(struct drm_mode_set *set)
2750 struct drm_crtc *crtc = set->crtc;
2751 struct drm_framebuffer *fb;
2752 struct drm_crtc *tmp;
2756 * NOTE: ->set_config can also disable other crtcs (if we steal all
2757 * connectors from it), hence we need to refcount the fbs across all
2758 * crtcs. Atomic modeset will have saner semantics ...
2760 drm_for_each_crtc(tmp, crtc->dev)
2761 tmp->primary->old_fb = tmp->primary->fb;
2765 ret = crtc->funcs->set_config(set);
2767 crtc->primary->crtc = crtc;
2768 crtc->primary->fb = fb;
2771 drm_for_each_crtc(tmp, crtc->dev) {
2772 if (tmp->primary->fb)
2773 drm_framebuffer_reference(tmp->primary->fb);
2774 if (tmp->primary->old_fb)
2775 drm_framebuffer_unreference(tmp->primary->old_fb);
2776 tmp->primary->old_fb = NULL;
2781 EXPORT_SYMBOL(drm_mode_set_config_internal);
2784 * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode
2785 * @mode: mode to query
2786 * @hdisplay: hdisplay value to fill in
2787 * @vdisplay: vdisplay value to fill in
2789 * The vdisplay value will be doubled if the specified mode is a stereo mode of
2790 * the appropriate layout.
2792 void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2793 int *hdisplay, int *vdisplay)
2795 struct drm_display_mode adjusted;
2797 drm_mode_copy(&adjusted, mode);
2798 drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY);
2799 *hdisplay = adjusted.crtc_hdisplay;
2800 *vdisplay = adjusted.crtc_vdisplay;
2802 EXPORT_SYMBOL(drm_crtc_get_hv_timing);
2805 * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
2807 * @crtc: CRTC that framebuffer will be displayed on
2810 * @mode: mode that framebuffer will be displayed under
2811 * @fb: framebuffer to check size of
2813 int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2815 const struct drm_display_mode *mode,
2816 const struct drm_framebuffer *fb)
2819 int hdisplay, vdisplay;
2821 drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
2824 crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) |
2825 BIT(DRM_ROTATE_270)))
2826 swap(hdisplay, vdisplay);
2828 return check_src_coords(x << 16, y << 16,
2829 hdisplay << 16, vdisplay << 16, fb);
2831 EXPORT_SYMBOL(drm_crtc_check_viewport);
2834 * drm_mode_setcrtc - set CRTC configuration
2835 * @dev: drm device for the ioctl
2836 * @data: data pointer for the ioctl
2837 * @file_priv: drm file for the ioctl call
2839 * Build a new CRTC configuration based on user request.
2841 * Called by the user via ioctl.
2844 * Zero on success, negative errno on failure.
2846 int drm_mode_setcrtc(struct drm_device *dev, void *data,
2847 struct drm_file *file_priv)
2849 struct drm_mode_config *config = &dev->mode_config;
2850 struct drm_mode_crtc *crtc_req = data;
2851 struct drm_crtc *crtc;
2852 struct drm_connector **connector_set = NULL, *connector;
2853 struct drm_framebuffer *fb = NULL;
2854 struct drm_display_mode *mode = NULL;
2855 struct drm_mode_set set;
2856 uint32_t __user *set_connectors_ptr;
2860 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2864 * Universal plane src offsets are only 16.16, prevent havoc for
2865 * drivers using universal plane code internally.
2867 if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000)
2870 drm_modeset_lock_all(dev);
2871 crtc = drm_crtc_find(dev, crtc_req->crtc_id);
2873 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
2877 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
2879 if (crtc_req->mode_valid) {
2880 /* If we have a mode we need a framebuffer. */
2881 /* If we pass -1, set the mode with the currently bound fb */
2882 if (crtc_req->fb_id == -1) {
2883 if (!crtc->primary->fb) {
2884 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
2888 fb = crtc->primary->fb;
2889 /* Make refcounting symmetric with the lookup path. */
2890 drm_framebuffer_reference(fb);
2892 fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
2894 DRM_DEBUG_KMS("Unknown FB ID%d\n",
2901 mode = drm_mode_create(dev);
2907 ret = drm_mode_convert_umode(mode, &crtc_req->mode);
2909 DRM_DEBUG_KMS("Invalid mode\n");
2914 * Check whether the primary plane supports the fb pixel format.
2915 * Drivers not implementing the universal planes API use a
2916 * default formats list provided by the DRM core which doesn't
2917 * match real hardware capabilities. Skip the check in that
2920 if (!crtc->primary->format_default) {
2921 ret = drm_plane_check_pixel_format(crtc->primary,
2924 DRM_DEBUG_KMS("Invalid pixel format %s\n",
2925 drm_get_format_name(fb->pixel_format));
2930 ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y,
2937 if (crtc_req->count_connectors == 0 && mode) {
2938 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
2943 if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
2944 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
2945 crtc_req->count_connectors);
2950 if (crtc_req->count_connectors > 0) {
2953 /* Avoid unbounded kernel memory allocation */
2954 if (crtc_req->count_connectors > config->num_connector) {
2959 connector_set = kmalloc_array(crtc_req->count_connectors,
2960 sizeof(struct drm_connector *),
2962 if (!connector_set) {
2967 for (i = 0; i < crtc_req->count_connectors; i++) {
2968 connector_set[i] = NULL;
2969 set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
2970 if (get_user(out_id, &set_connectors_ptr[i])) {
2975 connector = drm_connector_lookup(dev, out_id);
2977 DRM_DEBUG_KMS("Connector id %d unknown\n",
2982 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
2986 connector_set[i] = connector;
2991 set.x = crtc_req->x;
2992 set.y = crtc_req->y;
2994 set.connectors = connector_set;
2995 set.num_connectors = crtc_req->count_connectors;
2997 ret = drm_mode_set_config_internal(&set);
3001 drm_framebuffer_unreference(fb);
3003 if (connector_set) {
3004 for (i = 0; i < crtc_req->count_connectors; i++) {
3005 if (connector_set[i])
3006 drm_connector_unreference(connector_set[i]);
3009 kfree(connector_set);
3010 drm_mode_destroy(dev, mode);
3011 drm_modeset_unlock_all(dev);
3016 * drm_mode_cursor_universal - translate legacy cursor ioctl call into a
3017 * universal plane handler call
3018 * @crtc: crtc to update cursor for
3019 * @req: data pointer for the ioctl
3020 * @file_priv: drm file for the ioctl call
3022 * Legacy cursor ioctl's work directly with driver buffer handles. To
3023 * translate legacy ioctl calls into universal plane handler calls, we need to
3024 * wrap the native buffer handle in a drm_framebuffer.
3026 * Note that we assume any handle passed to the legacy ioctls was a 32-bit ARGB
3027 * buffer with a pitch of 4*width; the universal plane interface should be used
3028 * directly in cases where the hardware can support other buffer settings and
3029 * userspace wants to make use of these capabilities.
3032 * Zero on success, negative errno on failure.
3034 static int drm_mode_cursor_universal(struct drm_crtc *crtc,
3035 struct drm_mode_cursor2 *req,
3036 struct drm_file *file_priv)
3038 struct drm_device *dev = crtc->dev;
3039 struct drm_framebuffer *fb = NULL;
3040 struct drm_mode_fb_cmd2 fbreq = {
3041 .width = req->width,
3042 .height = req->height,
3043 .pixel_format = DRM_FORMAT_ARGB8888,
3044 .pitches = { req->width * 4 },
3045 .handles = { req->handle },
3047 int32_t crtc_x, crtc_y;
3048 uint32_t crtc_w = 0, crtc_h = 0;
3049 uint32_t src_w = 0, src_h = 0;
3052 BUG_ON(!crtc->cursor);
3053 WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL);
3056 * Obtain fb we'll be using (either new or existing) and take an extra
3057 * reference to it if fb != null. setplane will take care of dropping
3058 * the reference if the plane update fails.
3060 if (req->flags & DRM_MODE_CURSOR_BO) {
3062 fb = internal_framebuffer_create(dev, &fbreq, file_priv);
3064 DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n");
3067 fb->hot_x = req->hot_x;
3068 fb->hot_y = req->hot_y;
3073 fb = crtc->cursor->fb;
3075 drm_framebuffer_reference(fb);
3078 if (req->flags & DRM_MODE_CURSOR_MOVE) {
3082 crtc_x = crtc->cursor_x;
3083 crtc_y = crtc->cursor_y;
3088 crtc_h = fb->height;
3089 src_w = fb->width << 16;
3090 src_h = fb->height << 16;
3094 * setplane_internal will take care of deref'ing either the old or new
3095 * framebuffer depending on success.
3097 ret = __setplane_internal(crtc->cursor, crtc, fb,
3098 crtc_x, crtc_y, crtc_w, crtc_h,
3099 0, 0, src_w, src_h);
3101 /* Update successful; save new cursor position, if necessary */
3102 if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) {
3103 crtc->cursor_x = req->x;
3104 crtc->cursor_y = req->y;
3110 static int drm_mode_cursor_common(struct drm_device *dev,
3111 struct drm_mode_cursor2 *req,
3112 struct drm_file *file_priv)
3114 struct drm_crtc *crtc;
3117 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3120 if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
3123 crtc = drm_crtc_find(dev, req->crtc_id);
3125 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
3130 * If this crtc has a universal cursor plane, call that plane's update
3131 * handler rather than using legacy cursor handlers.
3133 drm_modeset_lock_crtc(crtc, crtc->cursor);
3135 ret = drm_mode_cursor_universal(crtc, req, file_priv);
3139 if (req->flags & DRM_MODE_CURSOR_BO) {
3140 if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
3144 /* Turns off the cursor if handle is 0 */
3145 if (crtc->funcs->cursor_set2)
3146 ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle,
3147 req->width, req->height, req->hot_x, req->hot_y);
3149 ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
3150 req->width, req->height);
3153 if (req->flags & DRM_MODE_CURSOR_MOVE) {
3154 if (crtc->funcs->cursor_move) {
3155 ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
3162 drm_modeset_unlock_crtc(crtc);
3170 * drm_mode_cursor_ioctl - set CRTC's cursor configuration
3171 * @dev: drm device for the ioctl
3172 * @data: data pointer for the ioctl
3173 * @file_priv: drm file for the ioctl call
3175 * Set the cursor configuration based on user request.
3177 * Called by the user via ioctl.
3180 * Zero on success, negative errno on failure.
3182 int drm_mode_cursor_ioctl(struct drm_device *dev,
3183 void *data, struct drm_file *file_priv)
3185 struct drm_mode_cursor *req = data;
3186 struct drm_mode_cursor2 new_req;
3188 memcpy(&new_req, req, sizeof(struct drm_mode_cursor));
3189 new_req.hot_x = new_req.hot_y = 0;
3191 return drm_mode_cursor_common(dev, &new_req, file_priv);
3195 * drm_mode_cursor2_ioctl - set CRTC's cursor configuration
3196 * @dev: drm device for the ioctl
3197 * @data: data pointer for the ioctl
3198 * @file_priv: drm file for the ioctl call
3200 * Set the cursor configuration based on user request. This implements the 2nd
3201 * version of the cursor ioctl, which allows userspace to additionally specify
3202 * the hotspot of the pointer.
3204 * Called by the user via ioctl.
3207 * Zero on success, negative errno on failure.
3209 int drm_mode_cursor2_ioctl(struct drm_device *dev,
3210 void *data, struct drm_file *file_priv)
3212 struct drm_mode_cursor2 *req = data;
3214 return drm_mode_cursor_common(dev, req, file_priv);
3218 * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description
3219 * @bpp: bits per pixels
3220 * @depth: bit depth per pixel
3222 * Computes a drm fourcc pixel format code for the given @bpp/@depth values.
3223 * Useful in fbdev emulation code, since that deals in those values.
3225 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
3231 fmt = DRM_FORMAT_C8;
3235 fmt = DRM_FORMAT_XRGB1555;
3237 fmt = DRM_FORMAT_RGB565;
3240 fmt = DRM_FORMAT_RGB888;
3244 fmt = DRM_FORMAT_XRGB8888;
3245 else if (depth == 30)
3246 fmt = DRM_FORMAT_XRGB2101010;
3248 fmt = DRM_FORMAT_ARGB8888;
3251 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
3252 fmt = DRM_FORMAT_XRGB8888;
3258 EXPORT_SYMBOL(drm_mode_legacy_fb_format);
3261 * drm_mode_addfb - add an FB to the graphics configuration
3262 * @dev: drm device for the ioctl
3263 * @data: data pointer for the ioctl
3264 * @file_priv: drm file for the ioctl call
3266 * Add a new FB to the specified CRTC, given a user request. This is the
3267 * original addfb ioctl which only supported RGB formats.
3269 * Called by the user via ioctl.
3272 * Zero on success, negative errno on failure.
3274 int drm_mode_addfb(struct drm_device *dev,
3275 void *data, struct drm_file *file_priv)
3277 struct drm_mode_fb_cmd *or = data;
3278 struct drm_mode_fb_cmd2 r = {};
3281 /* convert to new format and call new ioctl */
3282 r.fb_id = or->fb_id;
3283 r.width = or->width;
3284 r.height = or->height;
3285 r.pitches[0] = or->pitch;
3286 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
3287 r.handles[0] = or->handle;
3289 ret = drm_mode_addfb2(dev, &r, file_priv);
3293 or->fb_id = r.fb_id;
3298 static int format_check(const struct drm_mode_fb_cmd2 *r)
3300 uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
3304 case DRM_FORMAT_RGB332:
3305 case DRM_FORMAT_BGR233:
3306 case DRM_FORMAT_XRGB4444:
3307 case DRM_FORMAT_XBGR4444:
3308 case DRM_FORMAT_RGBX4444:
3309 case DRM_FORMAT_BGRX4444:
3310 case DRM_FORMAT_ARGB4444:
3311 case DRM_FORMAT_ABGR4444:
3312 case DRM_FORMAT_RGBA4444:
3313 case DRM_FORMAT_BGRA4444:
3314 case DRM_FORMAT_XRGB1555:
3315 case DRM_FORMAT_XBGR1555:
3316 case DRM_FORMAT_RGBX5551:
3317 case DRM_FORMAT_BGRX5551:
3318 case DRM_FORMAT_ARGB1555:
3319 case DRM_FORMAT_ABGR1555:
3320 case DRM_FORMAT_RGBA5551:
3321 case DRM_FORMAT_BGRA5551:
3322 case DRM_FORMAT_RGB565:
3323 case DRM_FORMAT_BGR565:
3324 case DRM_FORMAT_RGB888:
3325 case DRM_FORMAT_BGR888:
3326 case DRM_FORMAT_XRGB8888:
3327 case DRM_FORMAT_XBGR8888:
3328 case DRM_FORMAT_RGBX8888:
3329 case DRM_FORMAT_BGRX8888:
3330 case DRM_FORMAT_ARGB8888:
3331 case DRM_FORMAT_ABGR8888:
3332 case DRM_FORMAT_RGBA8888:
3333 case DRM_FORMAT_BGRA8888:
3334 case DRM_FORMAT_XRGB2101010:
3335 case DRM_FORMAT_XBGR2101010:
3336 case DRM_FORMAT_RGBX1010102:
3337 case DRM_FORMAT_BGRX1010102:
3338 case DRM_FORMAT_ARGB2101010:
3339 case DRM_FORMAT_ABGR2101010:
3340 case DRM_FORMAT_RGBA1010102:
3341 case DRM_FORMAT_BGRA1010102:
3342 case DRM_FORMAT_YUYV:
3343 case DRM_FORMAT_YVYU:
3344 case DRM_FORMAT_UYVY:
3345 case DRM_FORMAT_VYUY:
3346 case DRM_FORMAT_AYUV:
3347 case DRM_FORMAT_NV12:
3348 case DRM_FORMAT_NV21:
3349 case DRM_FORMAT_NV16:
3350 case DRM_FORMAT_NV61:
3351 case DRM_FORMAT_NV24:
3352 case DRM_FORMAT_NV42:
3353 case DRM_FORMAT_YUV410:
3354 case DRM_FORMAT_YVU410:
3355 case DRM_FORMAT_YUV411:
3356 case DRM_FORMAT_YVU411:
3357 case DRM_FORMAT_YUV420:
3358 case DRM_FORMAT_YVU420:
3359 case DRM_FORMAT_YUV422:
3360 case DRM_FORMAT_YVU422:
3361 case DRM_FORMAT_YUV444:
3362 case DRM_FORMAT_YVU444:
3365 DRM_DEBUG_KMS("invalid pixel format %s\n",
3366 drm_get_format_name(r->pixel_format));
3371 static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
3373 int ret, hsub, vsub, num_planes, i;
3375 ret = format_check(r);
3377 DRM_DEBUG_KMS("bad framebuffer format %s\n",
3378 drm_get_format_name(r->pixel_format));
3382 hsub = drm_format_horz_chroma_subsampling(r->pixel_format);
3383 vsub = drm_format_vert_chroma_subsampling(r->pixel_format);
3384 num_planes = drm_format_num_planes(r->pixel_format);
3386 if (r->width == 0 || r->width % hsub) {
3387 DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
3391 if (r->height == 0 || r->height % vsub) {
3392 DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
3396 for (i = 0; i < num_planes; i++) {
3397 unsigned int width = r->width / (i != 0 ? hsub : 1);
3398 unsigned int height = r->height / (i != 0 ? vsub : 1);
3399 unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
3401 if (!r->handles[i]) {
3402 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
3406 if ((uint64_t) width * cpp > UINT_MAX)
3409 if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
3412 if (r->pitches[i] < width * cpp) {
3413 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
3417 if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {
3418 DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
3423 /* modifier specific checks: */
3424 switch (r->modifier[i]) {
3425 case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE:
3426 /* NOTE: the pitch restriction may be lifted later if it turns
3427 * out that no hw has this restriction:
3429 if (r->pixel_format != DRM_FORMAT_NV12 ||
3430 width % 128 || height % 32 ||
3431 r->pitches[i] % 128) {
3432 DRM_DEBUG_KMS("bad modifier data for plane %d\n", i);
3442 for (i = num_planes; i < 4; i++) {
3443 if (r->modifier[i]) {
3444 DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i);
3448 /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */
3449 if (!(r->flags & DRM_MODE_FB_MODIFIERS))
3452 if (r->handles[i]) {
3453 DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i);
3457 if (r->pitches[i]) {
3458 DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i);
3462 if (r->offsets[i]) {
3463 DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i);
3471 static struct drm_framebuffer *
3472 internal_framebuffer_create(struct drm_device *dev,
3473 const struct drm_mode_fb_cmd2 *r,
3474 struct drm_file *file_priv)
3476 struct drm_mode_config *config = &dev->mode_config;
3477 struct drm_framebuffer *fb;
3480 if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) {
3481 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
3482 return ERR_PTR(-EINVAL);
3485 if ((config->min_width > r->width) || (r->width > config->max_width)) {
3486 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
3487 r->width, config->min_width, config->max_width);
3488 return ERR_PTR(-EINVAL);
3490 if ((config->min_height > r->height) || (r->height > config->max_height)) {
3491 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
3492 r->height, config->min_height, config->max_height);
3493 return ERR_PTR(-EINVAL);
3496 if (r->flags & DRM_MODE_FB_MODIFIERS &&
3497 !dev->mode_config.allow_fb_modifiers) {
3498 DRM_DEBUG_KMS("driver does not support fb modifiers\n");
3499 return ERR_PTR(-EINVAL);
3502 ret = framebuffer_check(r);
3504 return ERR_PTR(ret);
3506 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
3508 DRM_DEBUG_KMS("could not create framebuffer\n");
3516 * drm_mode_addfb2 - add an FB to the graphics configuration
3517 * @dev: drm device for the ioctl
3518 * @data: data pointer for the ioctl
3519 * @file_priv: drm file for the ioctl call
3521 * Add a new FB to the specified CRTC, given a user request with format. This is
3522 * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
3523 * and uses fourcc codes as pixel format specifiers.
3525 * Called by the user via ioctl.
3528 * Zero on success, negative errno on failure.
3530 int drm_mode_addfb2(struct drm_device *dev,
3531 void *data, struct drm_file *file_priv)
3533 struct drm_mode_fb_cmd2 *r = data;
3534 struct drm_framebuffer *fb;
3536 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3539 fb = internal_framebuffer_create(dev, r, file_priv);
3543 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
3544 r->fb_id = fb->base.id;
3546 /* Transfer ownership to the filp for reaping on close */
3547 mutex_lock(&file_priv->fbs_lock);
3548 list_add(&fb->filp_head, &file_priv->fbs);
3549 mutex_unlock(&file_priv->fbs_lock);
3554 struct drm_mode_rmfb_work {
3555 struct work_struct work;
3556 struct list_head fbs;
3559 static void drm_mode_rmfb_work_fn(struct work_struct *w)
3561 struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work);
3563 while (!list_empty(&arg->fbs)) {
3564 struct drm_framebuffer *fb =
3565 list_first_entry(&arg->fbs, typeof(*fb), filp_head);
3567 list_del_init(&fb->filp_head);
3568 drm_framebuffer_remove(fb);
3573 * drm_mode_rmfb - remove an FB from the configuration
3574 * @dev: drm device for the ioctl
3575 * @data: data pointer for the ioctl
3576 * @file_priv: drm file for the ioctl call
3578 * Remove the FB specified by the user.
3580 * Called by the user via ioctl.
3583 * Zero on success, negative errno on failure.
3585 int drm_mode_rmfb(struct drm_device *dev,
3586 void *data, struct drm_file *file_priv)
3588 struct drm_framebuffer *fb = NULL;
3589 struct drm_framebuffer *fbl = NULL;
3590 uint32_t *id = data;
3593 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3596 fb = drm_framebuffer_lookup(dev, *id);
3600 mutex_lock(&file_priv->fbs_lock);
3601 list_for_each_entry(fbl, &file_priv->fbs, filp_head)
3605 mutex_unlock(&file_priv->fbs_lock);
3609 list_del_init(&fb->filp_head);
3610 mutex_unlock(&file_priv->fbs_lock);
3612 /* drop the reference we picked up in framebuffer lookup */
3613 drm_framebuffer_unreference(fb);
3616 * we now own the reference that was stored in the fbs list
3618 * drm_framebuffer_remove may fail with -EINTR on pending signals,
3619 * so run this in a separate stack as there's no way to correctly
3620 * handle this after the fb is already removed from the lookup table.
3622 if (drm_framebuffer_read_refcount(fb) > 1) {
3623 struct drm_mode_rmfb_work arg;
3625 INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
3626 INIT_LIST_HEAD(&arg.fbs);
3627 list_add_tail(&fb->filp_head, &arg.fbs);
3629 schedule_work(&arg.work);
3630 flush_work(&arg.work);
3631 destroy_work_on_stack(&arg.work);
3633 drm_framebuffer_unreference(fb);
3638 drm_framebuffer_unreference(fb);
3643 * drm_mode_getfb - get FB info
3644 * @dev: drm device for the ioctl
3645 * @data: data pointer for the ioctl
3646 * @file_priv: drm file for the ioctl call
3648 * Lookup the FB given its ID and return info about it.
3650 * Called by the user via ioctl.
3653 * Zero on success, negative errno on failure.
3655 int drm_mode_getfb(struct drm_device *dev,
3656 void *data, struct drm_file *file_priv)
3658 struct drm_mode_fb_cmd *r = data;
3659 struct drm_framebuffer *fb;
3662 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3665 fb = drm_framebuffer_lookup(dev, r->fb_id);
3669 r->height = fb->height;
3670 r->width = fb->width;
3671 r->depth = fb->depth;
3672 r->bpp = fb->bits_per_pixel;
3673 r->pitch = fb->pitches[0];
3674 if (fb->funcs->create_handle) {
3675 if (drm_is_current_master(file_priv) || capable(CAP_SYS_ADMIN) ||
3676 drm_is_control_client(file_priv)) {
3677 ret = fb->funcs->create_handle(fb, file_priv,
3680 /* GET_FB() is an unprivileged ioctl so we must not
3681 * return a buffer-handle to non-master processes! For
3682 * backwards-compatibility reasons, we cannot make
3683 * GET_FB() privileged, so just return an invalid handle
3684 * for non-masters. */
3692 drm_framebuffer_unreference(fb);
3698 * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB
3699 * @dev: drm device for the ioctl
3700 * @data: data pointer for the ioctl
3701 * @file_priv: drm file for the ioctl call
3703 * Lookup the FB and flush out the damaged area supplied by userspace as a clip
3704 * rectangle list. Generic userspace which does frontbuffer rendering must call
3705 * this ioctl to flush out the changes on manual-update display outputs, e.g.
3706 * usb display-link, mipi manual update panels or edp panel self refresh modes.
3708 * Modesetting drivers which always update the frontbuffer do not need to
3709 * implement the corresponding ->dirty framebuffer callback.
3711 * Called by the user via ioctl.
3714 * Zero on success, negative errno on failure.
3716 int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
3717 void *data, struct drm_file *file_priv)
3719 struct drm_clip_rect __user *clips_ptr;
3720 struct drm_clip_rect *clips = NULL;
3721 struct drm_mode_fb_dirty_cmd *r = data;
3722 struct drm_framebuffer *fb;
3727 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3730 fb = drm_framebuffer_lookup(dev, r->fb_id);
3734 num_clips = r->num_clips;
3735 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
3737 if (!num_clips != !clips_ptr) {
3742 flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
3744 /* If userspace annotates copy, clips must come in pairs */
3745 if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
3750 if (num_clips && clips_ptr) {
3751 if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
3755 clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL);
3761 ret = copy_from_user(clips, clips_ptr,
3762 num_clips * sizeof(*clips));
3769 if (fb->funcs->dirty) {
3770 ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
3779 drm_framebuffer_unreference(fb);
3785 * drm_fb_release - remove and free the FBs on this file
3786 * @priv: drm file for the ioctl
3788 * Destroy all the FBs associated with @filp.
3790 * Called by the user via ioctl.
3793 * Zero on success, negative errno on failure.
3795 void drm_fb_release(struct drm_file *priv)
3797 struct drm_framebuffer *fb, *tfb;
3798 struct drm_mode_rmfb_work arg;
3800 INIT_LIST_HEAD(&arg.fbs);
3803 * When the file gets released that means no one else can access the fb
3804 * list any more, so no need to grab fpriv->fbs_lock. And we need to
3805 * avoid upsetting lockdep since the universal cursor code adds a
3806 * framebuffer while holding mutex locks.
3808 * Note that a real deadlock between fpriv->fbs_lock and the modeset
3809 * locks is impossible here since no one else but this function can get
3812 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
3813 if (drm_framebuffer_read_refcount(fb) > 1) {
3814 list_move_tail(&fb->filp_head, &arg.fbs);
3816 list_del_init(&fb->filp_head);
3818 /* This drops the fpriv->fbs reference. */
3819 drm_framebuffer_unreference(fb);
3823 if (!list_empty(&arg.fbs)) {
3824 INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
3826 schedule_work(&arg.work);
3827 flush_work(&arg.work);
3828 destroy_work_on_stack(&arg.work);
3832 static bool drm_property_type_valid(struct drm_property *property)
3834 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
3835 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
3836 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
3840 * drm_property_create - create a new property type
3842 * @flags: flags specifying the property type
3843 * @name: name of the property
3844 * @num_values: number of pre-defined values
3846 * This creates a new generic drm property which can then be attached to a drm
3847 * object with drm_object_attach_property. The returned property object must be
3848 * freed with drm_property_destroy.
3850 * Note that the DRM core keeps a per-device list of properties and that, if
3851 * drm_mode_config_cleanup() is called, it will destroy all properties created
3855 * A pointer to the newly created property on success, NULL on failure.
3857 struct drm_property *drm_property_create(struct drm_device *dev, int flags,
3858 const char *name, int num_values)
3860 struct drm_property *property = NULL;
3863 property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
3867 property->dev = dev;
3870 property->values = kcalloc(num_values, sizeof(uint64_t),
3872 if (!property->values)
3876 ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
3880 property->flags = flags;
3881 property->num_values = num_values;
3882 INIT_LIST_HEAD(&property->enum_list);
3885 strncpy(property->name, name, DRM_PROP_NAME_LEN);
3886 property->name[DRM_PROP_NAME_LEN-1] = '\0';
3889 list_add_tail(&property->head, &dev->mode_config.property_list);
3891 WARN_ON(!drm_property_type_valid(property));
3895 kfree(property->values);
3899 EXPORT_SYMBOL(drm_property_create);
3902 * drm_property_create_enum - create a new enumeration property type
3904 * @flags: flags specifying the property type
3905 * @name: name of the property
3906 * @props: enumeration lists with property values
3907 * @num_values: number of pre-defined values
3909 * This creates a new generic drm property which can then be attached to a drm
3910 * object with drm_object_attach_property. The returned property object must be
3911 * freed with drm_property_destroy.
3913 * Userspace is only allowed to set one of the predefined values for enumeration
3917 * A pointer to the newly created property on success, NULL on failure.
3919 struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
3921 const struct drm_prop_enum_list *props,
3924 struct drm_property *property;
3927 flags |= DRM_MODE_PROP_ENUM;
3929 property = drm_property_create(dev, flags, name, num_values);
3933 for (i = 0; i < num_values; i++) {
3934 ret = drm_property_add_enum(property, i,
3938 drm_property_destroy(dev, property);
3945 EXPORT_SYMBOL(drm_property_create_enum);
3948 * drm_property_create_bitmask - create a new bitmask property type
3950 * @flags: flags specifying the property type
3951 * @name: name of the property
3952 * @props: enumeration lists with property bitflags
3953 * @num_props: size of the @props array
3954 * @supported_bits: bitmask of all supported enumeration values
3956 * This creates a new bitmask drm property which can then be attached to a drm
3957 * object with drm_object_attach_property. The returned property object must be
3958 * freed with drm_property_destroy.
3960 * Compared to plain enumeration properties userspace is allowed to set any
3961 * or'ed together combination of the predefined property bitflag values
3964 * A pointer to the newly created property on success, NULL on failure.
3966 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
3967 int flags, const char *name,
3968 const struct drm_prop_enum_list *props,
3970 uint64_t supported_bits)
3972 struct drm_property *property;
3973 int i, ret, index = 0;
3974 int num_values = hweight64(supported_bits);
3976 flags |= DRM_MODE_PROP_BITMASK;
3978 property = drm_property_create(dev, flags, name, num_values);
3981 for (i = 0; i < num_props; i++) {
3982 if (!(supported_bits & (1ULL << props[i].type)))
3985 if (WARN_ON(index >= num_values)) {
3986 drm_property_destroy(dev, property);
3990 ret = drm_property_add_enum(property, index++,
3994 drm_property_destroy(dev, property);
4001 EXPORT_SYMBOL(drm_property_create_bitmask);
4003 static struct drm_property *property_create_range(struct drm_device *dev,
4004 int flags, const char *name,
4005 uint64_t min, uint64_t max)
4007 struct drm_property *property;
4009 property = drm_property_create(dev, flags, name, 2);
4013 property->values[0] = min;
4014 property->values[1] = max;
4020 * drm_property_create_range - create a new unsigned ranged property type
4022 * @flags: flags specifying the property type
4023 * @name: name of the property
4024 * @min: minimum value of the property
4025 * @max: maximum value of the property
4027 * This creates a new generic drm property which can then be attached to a drm
4028 * object with drm_object_attach_property. The returned property object must be
4029 * freed with drm_property_destroy.
4031 * Userspace is allowed to set any unsigned integer value in the (min, max)
4035 * A pointer to the newly created property on success, NULL on failure.
4037 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
4039 uint64_t min, uint64_t max)
4041 return property_create_range(dev, DRM_MODE_PROP_RANGE | flags,
4044 EXPORT_SYMBOL(drm_property_create_range);
4047 * drm_property_create_signed_range - create a new signed ranged property type
4049 * @flags: flags specifying the property type
4050 * @name: name of the property
4051 * @min: minimum value of the property
4052 * @max: maximum value of the property
4054 * This creates a new generic drm property which can then be attached to a drm
4055 * object with drm_object_attach_property. The returned property object must be
4056 * freed with drm_property_destroy.
4058 * Userspace is allowed to set any signed integer value in the (min, max)
4062 * A pointer to the newly created property on success, NULL on failure.
4064 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
4065 int flags, const char *name,
4066 int64_t min, int64_t max)
4068 return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags,
4069 name, I642U64(min), I642U64(max));
4071 EXPORT_SYMBOL(drm_property_create_signed_range);
4074 * drm_property_create_object - create a new object property type
4076 * @flags: flags specifying the property type
4077 * @name: name of the property
4078 * @type: object type from DRM_MODE_OBJECT_* defines
4080 * This creates a new generic drm property which can then be attached to a drm
4081 * object with drm_object_attach_property. The returned property object must be
4082 * freed with drm_property_destroy.
4084 * Userspace is only allowed to set this to any property value of the given
4085 * @type. Only useful for atomic properties, which is enforced.
4088 * A pointer to the newly created property on success, NULL on failure.
4090 struct drm_property *drm_property_create_object(struct drm_device *dev,
4091 int flags, const char *name, uint32_t type)
4093 struct drm_property *property;
4095 flags |= DRM_MODE_PROP_OBJECT;
4097 if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC)))
4100 property = drm_property_create(dev, flags, name, 1);
4104 property->values[0] = type;
4108 EXPORT_SYMBOL(drm_property_create_object);
4111 * drm_property_create_bool - create a new boolean property type
4113 * @flags: flags specifying the property type
4114 * @name: name of the property
4116 * This creates a new generic drm property which can then be attached to a drm
4117 * object with drm_object_attach_property. The returned property object must be
4118 * freed with drm_property_destroy.
4120 * This is implemented as a ranged property with only {0, 1} as valid values.
4123 * A pointer to the newly created property on success, NULL on failure.
4125 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
4128 return drm_property_create_range(dev, flags, name, 0, 1);
4130 EXPORT_SYMBOL(drm_property_create_bool);
4133 * drm_property_add_enum - add a possible value to an enumeration property
4134 * @property: enumeration property to change
4135 * @index: index of the new enumeration
4136 * @value: value of the new enumeration
4137 * @name: symbolic name of the new enumeration
4139 * This functions adds enumerations to a property.
4141 * It's use is deprecated, drivers should use one of the more specific helpers
4142 * to directly create the property with all enumerations already attached.
4145 * Zero on success, error code on failure.
4147 int drm_property_add_enum(struct drm_property *property, int index,
4148 uint64_t value, const char *name)
4150 struct drm_property_enum *prop_enum;
4152 if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
4153 drm_property_type_is(property, DRM_MODE_PROP_BITMASK)))
4157 * Bitmask enum properties have the additional constraint of values
4160 if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) &&
4164 if (!list_empty(&property->enum_list)) {
4165 list_for_each_entry(prop_enum, &property->enum_list, head) {
4166 if (prop_enum->value == value) {
4167 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
4168 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
4174 prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
4178 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
4179 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
4180 prop_enum->value = value;
4182 property->values[index] = value;
4183 list_add_tail(&prop_enum->head, &property->enum_list);
4186 EXPORT_SYMBOL(drm_property_add_enum);
4189 * drm_property_destroy - destroy a drm property
4191 * @property: property to destry
4193 * This function frees a property including any attached resources like
4194 * enumeration values.
4196 void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
4198 struct drm_property_enum *prop_enum, *pt;
4200 list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) {
4201 list_del(&prop_enum->head);
4205 if (property->num_values)
4206 kfree(property->values);
4207 drm_mode_object_unregister(dev, &property->base);
4208 list_del(&property->head);
4211 EXPORT_SYMBOL(drm_property_destroy);
4214 * drm_object_attach_property - attach a property to a modeset object
4215 * @obj: drm modeset object
4216 * @property: property to attach
4217 * @init_val: initial value of the property
4219 * This attaches the given property to the modeset object with the given initial
4220 * value. Currently this function cannot fail since the properties are stored in
4221 * a statically sized array.
4223 void drm_object_attach_property(struct drm_mode_object *obj,
4224 struct drm_property *property,
4227 int count = obj->properties->count;
4229 if (count == DRM_OBJECT_MAX_PROPERTY) {
4230 WARN(1, "Failed to attach object property (type: 0x%x). Please "
4231 "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time "
4232 "you see this message on the same object type.\n",
4237 obj->properties->properties[count] = property;
4238 obj->properties->values[count] = init_val;
4239 obj->properties->count++;
4240 if (property->flags & DRM_MODE_PROP_ATOMIC)
4241 obj->properties->atomic_count++;
4243 EXPORT_SYMBOL(drm_object_attach_property);
4246 * drm_object_property_set_value - set the value of a property
4247 * @obj: drm mode object to set property value for
4248 * @property: property to set
4249 * @val: value the property should be set to
4251 * This functions sets a given property on a given object. This function only
4252 * changes the software state of the property, it does not call into the
4253 * driver's ->set_property callback.
4256 * Zero on success, error code on failure.
4258 int drm_object_property_set_value(struct drm_mode_object *obj,
4259 struct drm_property *property, uint64_t val)
4263 for (i = 0; i < obj->properties->count; i++) {
4264 if (obj->properties->properties[i] == property) {
4265 obj->properties->values[i] = val;
4272 EXPORT_SYMBOL(drm_object_property_set_value);
4275 * drm_object_property_get_value - retrieve the value of a property
4276 * @obj: drm mode object to get property value from
4277 * @property: property to retrieve
4278 * @val: storage for the property value
4280 * This function retrieves the softare state of the given property for the given
4281 * property. Since there is no driver callback to retrieve the current property
4282 * value this might be out of sync with the hardware, depending upon the driver
4286 * Zero on success, error code on failure.
4288 int drm_object_property_get_value(struct drm_mode_object *obj,
4289 struct drm_property *property, uint64_t *val)
4293 /* read-only properties bypass atomic mechanism and still store
4294 * their value in obj->properties->values[].. mostly to avoid
4295 * having to deal w/ EDID and similar props in atomic paths:
4297 if (drm_core_check_feature(property->dev, DRIVER_ATOMIC) &&
4298 !(property->flags & DRM_MODE_PROP_IMMUTABLE))
4299 return drm_atomic_get_property(obj, property, val);
4301 for (i = 0; i < obj->properties->count; i++) {
4302 if (obj->properties->properties[i] == property) {
4303 *val = obj->properties->values[i];
4310 EXPORT_SYMBOL(drm_object_property_get_value);
4313 * drm_mode_getproperty_ioctl - get the property metadata
4316 * @file_priv: DRM file info
4318 * This function retrieves the metadata for a given property, like the different
4319 * possible values for an enum property or the limits for a range property.
4321 * Blob properties are special
4323 * Called by the user via ioctl.
4326 * Zero on success, negative errno on failure.
4328 int drm_mode_getproperty_ioctl(struct drm_device *dev,
4329 void *data, struct drm_file *file_priv)
4331 struct drm_mode_get_property *out_resp = data;
4332 struct drm_property *property;
4334 int value_count = 0;
4337 struct drm_property_enum *prop_enum;
4338 struct drm_mode_property_enum __user *enum_ptr;
4339 uint64_t __user *values_ptr;
4341 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4344 drm_modeset_lock_all(dev);
4345 property = drm_property_find(dev, out_resp->prop_id);
4351 if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
4352 drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
4353 list_for_each_entry(prop_enum, &property->enum_list, head)
4357 value_count = property->num_values;
4359 strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
4360 out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
4361 out_resp->flags = property->flags;
4363 if ((out_resp->count_values >= value_count) && value_count) {
4364 values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
4365 for (i = 0; i < value_count; i++) {
4366 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
4372 out_resp->count_values = value_count;
4374 if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
4375 drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
4376 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
4378 enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
4379 list_for_each_entry(prop_enum, &property->enum_list, head) {
4381 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
4386 if (copy_to_user(&enum_ptr[copied].name,
4387 &prop_enum->name, DRM_PROP_NAME_LEN)) {
4394 out_resp->count_enum_blobs = enum_count;
4398 * NOTE: The idea seems to have been to use this to read all the blob
4399 * property values. But nothing ever added them to the corresponding
4400 * list, userspace always used the special-purpose get_blob ioctl to
4401 * read the value for a blob property. It also doesn't make a lot of
4402 * sense to return values here when everything else is just metadata for
4403 * the property itself.
4405 if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
4406 out_resp->count_enum_blobs = 0;
4408 drm_modeset_unlock_all(dev);
4412 static void drm_property_free_blob(struct kref *kref)
4414 struct drm_property_blob *blob =
4415 container_of(kref, struct drm_property_blob, base.refcount);
4417 mutex_lock(&blob->dev->mode_config.blob_lock);
4418 list_del(&blob->head_global);
4419 mutex_unlock(&blob->dev->mode_config.blob_lock);
4421 drm_mode_object_unregister(blob->dev, &blob->base);
4427 * drm_property_create_blob - Create new blob property
4429 * Creates a new blob property for a specified DRM device, optionally
4432 * @dev: DRM device to create property for
4433 * @length: Length to allocate for blob data
4434 * @data: If specified, copies data into blob
4437 * New blob property with a single reference on success, or an ERR_PTR
4440 struct drm_property_blob *
4441 drm_property_create_blob(struct drm_device *dev, size_t length,
4444 struct drm_property_blob *blob;
4447 if (!length || length > ULONG_MAX - sizeof(struct drm_property_blob))
4448 return ERR_PTR(-EINVAL);
4450 blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
4452 return ERR_PTR(-ENOMEM);
4454 /* This must be explicitly initialised, so we can safely call list_del
4455 * on it in the removal handler, even if it isn't in a file list. */
4456 INIT_LIST_HEAD(&blob->head_file);
4457 blob->length = length;
4461 memcpy(blob->data, data, length);
4463 ret = drm_mode_object_get_reg(dev, &blob->base, DRM_MODE_OBJECT_BLOB,
4464 true, drm_property_free_blob);
4467 return ERR_PTR(-EINVAL);
4470 mutex_lock(&dev->mode_config.blob_lock);
4471 list_add_tail(&blob->head_global,
4472 &dev->mode_config.property_blob_list);
4473 mutex_unlock(&dev->mode_config.blob_lock);
4477 EXPORT_SYMBOL(drm_property_create_blob);
4480 * drm_property_unreference_blob - Unreference a blob property
4482 * Drop a reference on a blob property. May free the object.
4484 * @blob: Pointer to blob property
4486 void drm_property_unreference_blob(struct drm_property_blob *blob)
4491 drm_mode_object_unreference(&blob->base);
4493 EXPORT_SYMBOL(drm_property_unreference_blob);
4496 * drm_property_destroy_user_blobs - destroy all blobs created by this client
4498 * @file_priv: destroy all blobs owned by this file handle
4500 void drm_property_destroy_user_blobs(struct drm_device *dev,
4501 struct drm_file *file_priv)
4503 struct drm_property_blob *blob, *bt;
4506 * When the file gets released that means no one else can access the
4507 * blob list any more, so no need to grab dev->blob_lock.
4509 list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) {
4510 list_del_init(&blob->head_file);
4511 drm_property_unreference_blob(blob);
4516 * drm_property_reference_blob - Take a reference on an existing property
4518 * Take a new reference on an existing blob property.
4520 * @blob: Pointer to blob property
4522 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob)
4524 drm_mode_object_reference(&blob->base);
4527 EXPORT_SYMBOL(drm_property_reference_blob);
4530 * drm_property_lookup_blob - look up a blob property and take a reference
4532 * @id: id of the blob property
4534 * If successful, this takes an additional reference to the blob property.
4535 * callers need to make sure to eventually unreference the returned property
4536 * again, using @drm_property_unreference_blob.
4538 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
4541 struct drm_mode_object *obj;
4542 struct drm_property_blob *blob = NULL;
4544 obj = _object_find(dev, id, DRM_MODE_OBJECT_BLOB);
4546 blob = obj_to_blob(obj);
4549 EXPORT_SYMBOL(drm_property_lookup_blob);
4552 * drm_property_replace_global_blob - atomically replace existing blob property
4554 * @replace: location of blob property pointer to be replaced
4555 * @length: length of data for new blob, or 0 for no data
4556 * @data: content for new blob, or NULL for no data
4557 * @obj_holds_id: optional object for property holding blob ID
4558 * @prop_holds_id: optional property holding blob ID
4559 * @return 0 on success or error on failure
4561 * This function will atomically replace a global property in the blob list,
4562 * optionally updating a property which holds the ID of that property. It is
4563 * guaranteed to be atomic: no caller will be allowed to see intermediate
4564 * results, and either the entire operation will succeed and clean up the
4565 * previous property, or it will fail and the state will be unchanged.
4567 * If length is 0 or data is NULL, no new blob will be created, and the holding
4568 * property, if specified, will be set to 0.
4570 * Access to the replace pointer is assumed to be protected by the caller, e.g.
4571 * by holding the relevant modesetting object lock for its parent.
4573 * For example, a drm_connector has a 'PATH' property, which contains the ID
4574 * of a blob property with the value of the MST path information. Calling this
4575 * function with replace pointing to the connector's path_blob_ptr, length and
4576 * data set for the new path information, obj_holds_id set to the connector's
4577 * base object, and prop_holds_id set to the path property name, will perform
4578 * a completely atomic update. The access to path_blob_ptr is protected by the
4579 * caller holding a lock on the connector.
4581 static int drm_property_replace_global_blob(struct drm_device *dev,
4582 struct drm_property_blob **replace,
4585 struct drm_mode_object *obj_holds_id,
4586 struct drm_property *prop_holds_id)
4588 struct drm_property_blob *new_blob = NULL;
4589 struct drm_property_blob *old_blob = NULL;
4592 WARN_ON(replace == NULL);
4594 old_blob = *replace;
4596 if (length && data) {
4597 new_blob = drm_property_create_blob(dev, length, data);
4598 if (IS_ERR(new_blob))
4599 return PTR_ERR(new_blob);
4602 /* This does not need to be synchronised with blob_lock, as the
4603 * get_properties ioctl locks all modesetting objects, and
4604 * obj_holds_id must be locked before calling here, so we cannot
4605 * have its value out of sync with the list membership modified
4606 * below under blob_lock. */
4608 ret = drm_object_property_set_value(obj_holds_id,
4611 new_blob->base.id : 0);
4616 drm_property_unreference_blob(old_blob);
4617 *replace = new_blob;
4622 drm_property_unreference_blob(new_blob);
4627 * drm_mode_getblob_ioctl - get the contents of a blob property value
4630 * @file_priv: DRM file info
4632 * This function retrieves the contents of a blob property. The value stored in
4633 * an object's blob property is just a normal modeset object id.
4635 * Called by the user via ioctl.
4638 * Zero on success, negative errno on failure.
4640 int drm_mode_getblob_ioctl(struct drm_device *dev,
4641 void *data, struct drm_file *file_priv)
4643 struct drm_mode_get_blob *out_resp = data;
4644 struct drm_property_blob *blob;
4646 void __user *blob_ptr;
4648 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4651 blob = drm_property_lookup_blob(dev, out_resp->blob_id);
4655 if (out_resp->length == blob->length) {
4656 blob_ptr = (void __user *)(unsigned long)out_resp->data;
4657 if (copy_to_user(blob_ptr, blob->data, blob->length)) {
4662 out_resp->length = blob->length;
4664 drm_property_unreference_blob(blob);
4670 * drm_mode_createblob_ioctl - create a new blob property
4673 * @file_priv: DRM file info
4675 * This function creates a new blob property with user-defined values. In order
4676 * to give us sensible validation and checking when creating, rather than at
4677 * every potential use, we also require a type to be provided upfront.
4679 * Called by the user via ioctl.
4682 * Zero on success, negative errno on failure.
4684 int drm_mode_createblob_ioctl(struct drm_device *dev,
4685 void *data, struct drm_file *file_priv)
4687 struct drm_mode_create_blob *out_resp = data;
4688 struct drm_property_blob *blob;
4689 void __user *blob_ptr;
4692 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4695 blob = drm_property_create_blob(dev, out_resp->length, NULL);
4697 return PTR_ERR(blob);
4699 blob_ptr = (void __user *)(unsigned long)out_resp->data;
4700 if (copy_from_user(blob->data, blob_ptr, out_resp->length)) {
4705 /* Dropping the lock between create_blob and our access here is safe
4706 * as only the same file_priv can remove the blob; at this point, it is
4707 * not associated with any file_priv. */
4708 mutex_lock(&dev->mode_config.blob_lock);
4709 out_resp->blob_id = blob->base.id;
4710 list_add_tail(&blob->head_file, &file_priv->blobs);
4711 mutex_unlock(&dev->mode_config.blob_lock);
4716 drm_property_unreference_blob(blob);
4721 * drm_mode_destroyblob_ioctl - destroy a user blob property
4724 * @file_priv: DRM file info
4726 * Destroy an existing user-defined blob property.
4728 * Called by the user via ioctl.
4731 * Zero on success, negative errno on failure.
4733 int drm_mode_destroyblob_ioctl(struct drm_device *dev,
4734 void *data, struct drm_file *file_priv)
4736 struct drm_mode_destroy_blob *out_resp = data;
4737 struct drm_property_blob *blob = NULL, *bt;
4741 if (!drm_core_check_feature(dev, DRIVER_MODESET))
4744 blob = drm_property_lookup_blob(dev, out_resp->blob_id);
4748 mutex_lock(&dev->mode_config.blob_lock);
4749 /* Ensure the property was actually created by this user. */
4750 list_for_each_entry(bt, &file_priv->blobs, head_file) {
4762 /* We must drop head_file here, because we may not be the last
4763 * reference on the blob. */
4764 list_del_init(&blob->head_file);
4765 mutex_unlock(&dev->mode_config.blob_lock);
4767 /* One reference from lookup, and one from the filp. */
4768 drm_property_unreference_blob(blob);
4769 drm_property_unreference_blob(blob);
4774 mutex_unlock(&dev->mode_config.blob_lock);
4775 drm_property_unreference_blob(blob);
4781 * drm_mode_connector_set_path_property - set tile property on connector
4782 * @connector: connector to set property on.
4783 * @path: path to use for property; must not be NULL.
4785 * This creates a property to expose to userspace to specify a
4786 * connector path. This is mainly used for DisplayPort MST where
4787 * connectors have a topology and we want to allow userspace to give
4788 * them more meaningful names.
4791 * Zero on success, negative errno on failure.
4793 int drm_mode_connector_set_path_property(struct drm_connector *connector,
4796 struct drm_device *dev = connector->dev;
4799 ret = drm_property_replace_global_blob(dev,
4800 &connector->path_blob_ptr,
4804 dev->mode_config.path_property);
4807 EXPORT_SYMBOL(drm_mode_connector_set_path_property);
4810 * drm_mode_connector_set_tile_property - set tile property on connector
4811 * @connector: connector to set property on.
4813 * This looks up the tile information for a connector, and creates a
4814 * property for userspace to parse if it exists. The property is of
4815 * the form of 8 integers using ':' as a separator.
4818 * Zero on success, errno on failure.
4820 int drm_mode_connector_set_tile_property(struct drm_connector *connector)
4822 struct drm_device *dev = connector->dev;
4826 if (!connector->has_tile) {
4827 ret = drm_property_replace_global_blob(dev,
4828 &connector->tile_blob_ptr,
4832 dev->mode_config.tile_property);
4836 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
4837 connector->tile_group->id, connector->tile_is_single_monitor,
4838 connector->num_h_tile, connector->num_v_tile,
4839 connector->tile_h_loc, connector->tile_v_loc,
4840 connector->tile_h_size, connector->tile_v_size);
4842 ret = drm_property_replace_global_blob(dev,
4843 &connector->tile_blob_ptr,
4847 dev->mode_config.tile_property);
4850 EXPORT_SYMBOL(drm_mode_connector_set_tile_property);
4853 * drm_mode_connector_update_edid_property - update the edid property of a connector
4854 * @connector: drm connector
4855 * @edid: new value of the edid property
4857 * This function creates a new blob modeset object and assigns its id to the
4858 * connector's edid property.
4861 * Zero on success, negative errno on failure.
4863 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
4864 const struct edid *edid)
4866 struct drm_device *dev = connector->dev;
4870 /* ignore requests to set edid when overridden */
4871 if (connector->override_edid)
4875 size = EDID_LENGTH * (1 + edid->extensions);
4877 ret = drm_property_replace_global_blob(dev,
4878 &connector->edid_blob_ptr,
4882 dev->mode_config.edid_property);
4885 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
4887 /* Some properties could refer to dynamic refcnt'd objects, or things that
4888 * need special locking to handle lifetime issues (ie. to ensure the prop
4889 * value doesn't become invalid part way through the property update due to
4890 * race). The value returned by reference via 'obj' should be passed back
4891 * to drm_property_change_valid_put() after the property is set (and the
4892 * object to which the property is attached has a chance to take it's own
4895 bool drm_property_change_valid_get(struct drm_property *property,
4896 uint64_t value, struct drm_mode_object **ref)
4900 if (property->flags & DRM_MODE_PROP_IMMUTABLE)
4905 if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) {
4906 if (value < property->values[0] || value > property->values[1])
4909 } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) {
4910 int64_t svalue = U642I64(value);
4912 if (svalue < U642I64(property->values[0]) ||
4913 svalue > U642I64(property->values[1]))
4916 } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
4917 uint64_t valid_mask = 0;
4919 for (i = 0; i < property->num_values; i++)
4920 valid_mask |= (1ULL << property->values[i]);
4921 return !(value & ~valid_mask);
4922 } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) {
4923 struct drm_property_blob *blob;
4928 blob = drm_property_lookup_blob(property->dev, value);
4935 } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
4936 /* a zero value for an object property translates to null: */
4940 *ref = _object_find(property->dev, value, property->values[0]);
4941 return *ref != NULL;
4944 for (i = 0; i < property->num_values; i++)
4945 if (property->values[i] == value)
4950 void drm_property_change_valid_put(struct drm_property *property,
4951 struct drm_mode_object *ref)
4956 if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
4957 drm_mode_object_unreference(ref);
4958 } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
4959 drm_property_unreference_blob(obj_to_blob(ref));
4963 * drm_mode_connector_property_set_ioctl - set the current value of a connector property
4966 * @file_priv: DRM file info
4968 * This function sets the current value for a connectors's property. It also
4969 * calls into a driver's ->set_property callback to update the hardware state
4971 * Called by the user via ioctl.
4974 * Zero on success, negative errno on failure.
4976 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
4977 void *data, struct drm_file *file_priv)
4979 struct drm_mode_connector_set_property *conn_set_prop = data;
4980 struct drm_mode_obj_set_property obj_set_prop = {
4981 .value = conn_set_prop->value,
4982 .prop_id = conn_set_prop->prop_id,
4983 .obj_id = conn_set_prop->connector_id,
4984 .obj_type = DRM_MODE_OBJECT_CONNECTOR
4987 /* It does all the locking and checking we need */
4988 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
4991 static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
4992 struct drm_property *property,
4996 struct drm_connector *connector = obj_to_connector(obj);
4998 /* Do DPMS ourselves */
4999 if (property == connector->dev->mode_config.dpms_property) {
5000 ret = (*connector->funcs->dpms)(connector, (int)value);
5001 } else if (connector->funcs->set_property)
5002 ret = connector->funcs->set_property(connector, property, value);
5004 /* store the property value if successful */
5006 drm_object_property_set_value(&connector->base, property, value);
5010 static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
5011 struct drm_property *property,
5015 struct drm_crtc *crtc = obj_to_crtc(obj);
5017 if (crtc->funcs->set_property)
5018 ret = crtc->funcs->set_property(crtc, property, value);
5020 drm_object_property_set_value(obj, property, value);
5026 * drm_mode_plane_set_obj_prop - set the value of a property
5027 * @plane: drm plane object to set property value for
5028 * @property: property to set
5029 * @value: value the property should be set to
5031 * This functions sets a given property on a given plane object. This function
5032 * calls the driver's ->set_property callback and changes the software state of
5033 * the property if the callback succeeds.
5036 * Zero on success, error code on failure.
5038 int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
5039 struct drm_property *property,
5043 struct drm_mode_object *obj = &plane->base;
5045 if (plane->funcs->set_property)
5046 ret = plane->funcs->set_property(plane, property, value);
5048 drm_object_property_set_value(obj, property, value);
5052 EXPORT_SYMBOL(drm_mode_plane_set_obj_prop);
5055 * drm_mode_obj_get_properties_ioctl - get the current value of a object's property
5058 * @file_priv: DRM file info
5060 * This function retrieves the current value for an object's property. Compared
5061 * to the connector specific ioctl this one is extended to also work on crtc and
5064 * Called by the user via ioctl.
5067 * Zero on success, negative errno on failure.
5069 int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
5070 struct drm_file *file_priv)
5072 struct drm_mode_obj_get_properties *arg = data;
5073 struct drm_mode_object *obj;
5076 if (!drm_core_check_feature(dev, DRIVER_MODESET))
5079 drm_modeset_lock_all(dev);
5081 obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type);
5086 if (!obj->properties) {
5091 ret = get_properties(obj, file_priv->atomic,
5092 (uint32_t __user *)(unsigned long)(arg->props_ptr),
5093 (uint64_t __user *)(unsigned long)(arg->prop_values_ptr),
5097 drm_mode_object_unreference(obj);
5099 drm_modeset_unlock_all(dev);
5104 * drm_mode_obj_set_property_ioctl - set the current value of an object's property
5107 * @file_priv: DRM file info
5109 * This function sets the current value for an object's property. It also calls
5110 * into a driver's ->set_property callback to update the hardware state.
5111 * Compared to the connector specific ioctl this one is extended to also work on
5112 * crtc and plane objects.
5114 * Called by the user via ioctl.
5117 * Zero on success, negative errno on failure.
5119 int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
5120 struct drm_file *file_priv)
5122 struct drm_mode_obj_set_property *arg = data;
5123 struct drm_mode_object *arg_obj;
5124 struct drm_mode_object *prop_obj;
5125 struct drm_property *property;
5126 int i, ret = -EINVAL;
5127 struct drm_mode_object *ref;
5129 if (!drm_core_check_feature(dev, DRIVER_MODESET))
5132 drm_modeset_lock_all(dev);
5134 arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type);
5139 if (!arg_obj->properties)
5142 for (i = 0; i < arg_obj->properties->count; i++)
5143 if (arg_obj->properties->properties[i]->base.id == arg->prop_id)
5146 if (i == arg_obj->properties->count)
5149 prop_obj = drm_mode_object_find(dev, arg->prop_id,
5150 DRM_MODE_OBJECT_PROPERTY);
5155 property = obj_to_property(prop_obj);
5157 if (!drm_property_change_valid_get(property, arg->value, &ref))
5160 switch (arg_obj->type) {
5161 case DRM_MODE_OBJECT_CONNECTOR:
5162 ret = drm_mode_connector_set_obj_prop(arg_obj, property,
5165 case DRM_MODE_OBJECT_CRTC:
5166 ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value);
5168 case DRM_MODE_OBJECT_PLANE:
5169 ret = drm_mode_plane_set_obj_prop(obj_to_plane(arg_obj),
5170 property, arg->value);
5174 drm_property_change_valid_put(property, ref);
5177 drm_mode_object_unreference(arg_obj);
5179 drm_modeset_unlock_all(dev);
5184 * drm_mode_connector_attach_encoder - attach a connector to an encoder
5185 * @connector: connector to attach
5186 * @encoder: encoder to attach @connector to
5188 * This function links up a connector to an encoder. Note that the routing
5189 * restrictions between encoders and crtcs are exposed to userspace through the
5190 * possible_clones and possible_crtcs bitmasks.
5193 * Zero on success, negative errno on failure.
5195 int drm_mode_connector_attach_encoder(struct drm_connector *connector,
5196 struct drm_encoder *encoder)
5201 * In the past, drivers have attempted to model the static association
5202 * of connector to encoder in simple connector/encoder devices using a
5203 * direct assignment of connector->encoder = encoder. This connection
5204 * is a logical one and the responsibility of the core, so drivers are
5205 * expected not to mess with this.
5207 * Note that the error return should've been enough here, but a large
5208 * majority of drivers ignores the return value, so add in a big WARN
5209 * to get people's attention.
5211 if (WARN_ON(connector->encoder))
5214 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
5215 if (connector->encoder_ids[i] == 0) {
5216 connector->encoder_ids[i] = encoder->base.id;
5222 EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
5225 * drm_mode_crtc_set_gamma_size - set the gamma table size
5226 * @crtc: CRTC to set the gamma table size for
5227 * @gamma_size: size of the gamma table
5229 * Drivers which support gamma tables should set this to the supported gamma
5230 * table size when initializing the CRTC. Currently the drm core only supports a
5231 * fixed gamma table size.
5234 * Zero on success, negative errno on failure.
5236 int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
5239 uint16_t *r_base, *g_base, *b_base;
5242 crtc->gamma_size = gamma_size;
5244 crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3,
5246 if (!crtc->gamma_store) {
5247 crtc->gamma_size = 0;
5251 r_base = crtc->gamma_store;
5252 g_base = r_base + gamma_size;
5253 b_base = g_base + gamma_size;
5254 for (i = 0; i < gamma_size; i++) {
5263 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
5266 * drm_mode_gamma_set_ioctl - set the gamma table
5269 * @file_priv: DRM file info
5271 * Set the gamma table of a CRTC to the one passed in by the user. Userspace can
5272 * inquire the required gamma table size through drm_mode_gamma_get_ioctl.
5274 * Called by the user via ioctl.
5277 * Zero on success, negative errno on failure.
5279 int drm_mode_gamma_set_ioctl(struct drm_device *dev,
5280 void *data, struct drm_file *file_priv)
5282 struct drm_mode_crtc_lut *crtc_lut = data;
5283 struct drm_crtc *crtc;
5284 void *r_base, *g_base, *b_base;
5288 if (!drm_core_check_feature(dev, DRIVER_MODESET))
5291 drm_modeset_lock_all(dev);
5292 crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
5298 if (crtc->funcs->gamma_set == NULL) {
5303 /* memcpy into gamma store */
5304 if (crtc_lut->gamma_size != crtc->gamma_size) {
5309 size = crtc_lut->gamma_size * (sizeof(uint16_t));
5310 r_base = crtc->gamma_store;
5311 if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
5316 g_base = r_base + size;
5317 if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
5322 b_base = g_base + size;
5323 if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
5328 ret = crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size);
5331 drm_modeset_unlock_all(dev);
5337 * drm_mode_gamma_get_ioctl - get the gamma table
5340 * @file_priv: DRM file info
5342 * Copy the current gamma table into the storage provided. This also provides
5343 * the gamma table size the driver expects, which can be used to size the
5344 * allocated storage.
5346 * Called by the user via ioctl.
5349 * Zero on success, negative errno on failure.
5351 int drm_mode_gamma_get_ioctl(struct drm_device *dev,
5352 void *data, struct drm_file *file_priv)
5354 struct drm_mode_crtc_lut *crtc_lut = data;
5355 struct drm_crtc *crtc;
5356 void *r_base, *g_base, *b_base;
5360 if (!drm_core_check_feature(dev, DRIVER_MODESET))
5363 drm_modeset_lock_all(dev);
5364 crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
5370 /* memcpy into gamma store */
5371 if (crtc_lut->gamma_size != crtc->gamma_size) {
5376 size = crtc_lut->gamma_size * (sizeof(uint16_t));
5377 r_base = crtc->gamma_store;
5378 if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
5383 g_base = r_base + size;
5384 if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
5389 b_base = g_base + size;
5390 if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
5395 drm_modeset_unlock_all(dev);
5400 * drm_mode_page_flip_ioctl - schedule an asynchronous fb update
5403 * @file_priv: DRM file info
5405 * This schedules an asynchronous update on a given CRTC, called page flip.
5406 * Optionally a drm event is generated to signal the completion of the event.
5407 * Generic drivers cannot assume that a pageflip with changed framebuffer
5408 * properties (including driver specific metadata like tiling layout) will work,
5409 * but some drivers support e.g. pixel format changes through the pageflip
5412 * Called by the user via ioctl.
5415 * Zero on success, negative errno on failure.
5417 int drm_mode_page_flip_ioctl(struct drm_device *dev,
5418 void *data, struct drm_file *file_priv)
5420 struct drm_mode_crtc_page_flip *page_flip = data;
5421 struct drm_crtc *crtc;
5422 struct drm_framebuffer *fb = NULL;
5423 struct drm_pending_vblank_event *e = NULL;
5426 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
5427 page_flip->reserved != 0)
5430 if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
5433 crtc = drm_crtc_find(dev, page_flip->crtc_id);
5437 drm_modeset_lock_crtc(crtc, crtc->primary);
5438 if (crtc->primary->fb == NULL) {
5439 /* The framebuffer is currently unbound, presumably
5440 * due to a hotplug event, that userspace has not
5447 if (crtc->funcs->page_flip == NULL)
5450 fb = drm_framebuffer_lookup(dev, page_flip->fb_id);
5457 const struct drm_plane_state *state = crtc->primary->state;
5459 ret = check_src_coords(state->src_x, state->src_y,
5460 state->src_w, state->src_h, fb);
5462 ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, &crtc->mode, fb);
5467 if (crtc->primary->fb->pixel_format != fb->pixel_format) {
5468 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
5473 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
5474 e = kzalloc(sizeof *e, GFP_KERNEL);
5479 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
5480 e->event.base.length = sizeof(e->event);
5481 e->event.user_data = page_flip->user_data;
5482 ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base);
5489 crtc->primary->old_fb = crtc->primary->fb;
5490 ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags);
5492 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT)
5493 drm_event_cancel_free(dev, &e->base);
5494 /* Keep the old fb, don't unref it. */
5495 crtc->primary->old_fb = NULL;
5497 crtc->primary->fb = fb;
5498 /* Unref only the old framebuffer. */
5504 drm_framebuffer_unreference(fb);
5505 if (crtc->primary->old_fb)
5506 drm_framebuffer_unreference(crtc->primary->old_fb);
5507 crtc->primary->old_fb = NULL;
5508 drm_modeset_unlock_crtc(crtc);
5514 * drm_mode_config_reset - call ->reset callbacks
5517 * This functions calls all the crtc's, encoder's and connector's ->reset
5518 * callback. Drivers can use this in e.g. their driver load or resume code to
5519 * reset hardware and software state.
5521 void drm_mode_config_reset(struct drm_device *dev)
5523 struct drm_crtc *crtc;
5524 struct drm_plane *plane;
5525 struct drm_encoder *encoder;
5526 struct drm_connector *connector;
5528 drm_for_each_plane(plane, dev)
5529 if (plane->funcs->reset)
5530 plane->funcs->reset(plane);
5532 drm_for_each_crtc(crtc, dev)
5533 if (crtc->funcs->reset)
5534 crtc->funcs->reset(crtc);
5536 drm_for_each_encoder(encoder, dev)
5537 if (encoder->funcs->reset)
5538 encoder->funcs->reset(encoder);
5540 mutex_lock(&dev->mode_config.mutex);
5541 drm_for_each_connector(connector, dev)
5542 if (connector->funcs->reset)
5543 connector->funcs->reset(connector);
5544 mutex_unlock(&dev->mode_config.mutex);
5546 EXPORT_SYMBOL(drm_mode_config_reset);
5549 * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer
5552 * @file_priv: DRM file info
5554 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
5555 * TTM or something else entirely) and returns the resulting buffer handle. This
5556 * handle can then be wrapped up into a framebuffer modeset object.
5558 * Note that userspace is not allowed to use such objects for render
5559 * acceleration - drivers must create their own private ioctls for such a use
5562 * Called by the user via ioctl.
5565 * Zero on success, negative errno on failure.
5567 int drm_mode_create_dumb_ioctl(struct drm_device *dev,
5568 void *data, struct drm_file *file_priv)
5570 struct drm_mode_create_dumb *args = data;
5571 u32 cpp, stride, size;
5573 if (!dev->driver->dumb_create)
5575 if (!args->width || !args->height || !args->bpp)
5578 /* overflow checks for 32bit size calculations */
5579 /* NOTE: DIV_ROUND_UP() can overflow */
5580 cpp = DIV_ROUND_UP(args->bpp, 8);
5581 if (!cpp || cpp > 0xffffffffU / args->width)
5583 stride = cpp * args->width;
5584 if (args->height > 0xffffffffU / stride)
5587 /* test for wrap-around */
5588 size = args->height * stride;
5589 if (PAGE_ALIGN(size) == 0)
5593 * handle, pitch and size are output parameters. Zero them out to
5594 * prevent drivers from accidentally using uninitialized data. Since
5595 * not all existing userspace is clearing these fields properly we
5596 * cannot reject IOCTL with garbage in them.
5602 return dev->driver->dumb_create(file_priv, dev, args);
5606 * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer
5609 * @file_priv: DRM file info
5611 * Allocate an offset in the drm device node's address space to be able to
5612 * memory map a dumb buffer.
5614 * Called by the user via ioctl.
5617 * Zero on success, negative errno on failure.
5619 int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
5620 void *data, struct drm_file *file_priv)
5622 struct drm_mode_map_dumb *args = data;
5624 /* call driver ioctl to get mmap offset */
5625 if (!dev->driver->dumb_map_offset)
5628 return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
5632 * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer
5635 * @file_priv: DRM file info
5637 * This destroys the userspace handle for the given dumb backing storage buffer.
5638 * Since buffer objects must be reference counted in the kernel a buffer object
5639 * won't be immediately freed if a framebuffer modeset object still uses it.
5641 * Called by the user via ioctl.
5644 * Zero on success, negative errno on failure.
5646 int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
5647 void *data, struct drm_file *file_priv)
5649 struct drm_mode_destroy_dumb *args = data;
5651 if (!dev->driver->dumb_destroy)
5654 return dev->driver->dumb_destroy(file_priv, dev, args->handle);
5658 * drm_rotation_simplify() - Try to simplify the rotation
5659 * @rotation: Rotation to be simplified
5660 * @supported_rotations: Supported rotations
5662 * Attempt to simplify the rotation to a form that is supported.
5663 * Eg. if the hardware supports everything except DRM_REFLECT_X
5664 * one could call this function like this:
5666 * drm_rotation_simplify(rotation, BIT(DRM_ROTATE_0) |
5667 * BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_180) |
5668 * BIT(DRM_ROTATE_270) | BIT(DRM_REFLECT_Y));
5670 * to eliminate the DRM_ROTATE_X flag. Depending on what kind of
5671 * transforms the hardware supports, this function may not
5672 * be able to produce a supported transform, so the caller should
5673 * check the result afterwards.
5675 unsigned int drm_rotation_simplify(unsigned int rotation,
5676 unsigned int supported_rotations)
5678 if (rotation & ~supported_rotations) {
5679 rotation ^= BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y);
5680 rotation = (rotation & DRM_REFLECT_MASK) |
5681 BIT((ffs(rotation & DRM_ROTATE_MASK) + 1) % 4);
5686 EXPORT_SYMBOL(drm_rotation_simplify);
5689 * drm_mode_config_init - initialize DRM mode_configuration structure
5692 * Initialize @dev's mode_config structure, used for tracking the graphics
5693 * configuration of @dev.
5695 * Since this initializes the modeset locks, no locking is possible. Which is no
5696 * problem, since this should happen single threaded at init time. It is the
5697 * driver's problem to ensure this guarantee.
5700 void drm_mode_config_init(struct drm_device *dev)
5702 mutex_init(&dev->mode_config.mutex);
5703 drm_modeset_lock_init(&dev->mode_config.connection_mutex);
5704 mutex_init(&dev->mode_config.idr_mutex);
5705 mutex_init(&dev->mode_config.fb_lock);
5706 mutex_init(&dev->mode_config.blob_lock);
5707 INIT_LIST_HEAD(&dev->mode_config.fb_list);
5708 INIT_LIST_HEAD(&dev->mode_config.crtc_list);
5709 INIT_LIST_HEAD(&dev->mode_config.connector_list);
5710 INIT_LIST_HEAD(&dev->mode_config.encoder_list);
5711 INIT_LIST_HEAD(&dev->mode_config.property_list);
5712 INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
5713 INIT_LIST_HEAD(&dev->mode_config.plane_list);
5714 idr_init(&dev->mode_config.crtc_idr);
5715 idr_init(&dev->mode_config.tile_idr);
5716 ida_init(&dev->mode_config.connector_ida);
5718 drm_modeset_lock_all(dev);
5719 drm_mode_create_standard_properties(dev);
5720 drm_modeset_unlock_all(dev);
5722 /* Just to be sure */
5723 dev->mode_config.num_fb = 0;
5724 dev->mode_config.num_connector = 0;
5725 dev->mode_config.num_crtc = 0;
5726 dev->mode_config.num_encoder = 0;
5727 dev->mode_config.num_overlay_plane = 0;
5728 dev->mode_config.num_total_plane = 0;
5730 EXPORT_SYMBOL(drm_mode_config_init);
5733 * drm_mode_config_cleanup - free up DRM mode_config info
5736 * Free up all the connectors and CRTCs associated with this DRM device, then
5737 * free up the framebuffers and associated buffer objects.
5739 * Note that since this /should/ happen single-threaded at driver/device
5740 * teardown time, no locking is required. It's the driver's job to ensure that
5741 * this guarantee actually holds true.
5743 * FIXME: cleanup any dangling user buffer objects too
5745 void drm_mode_config_cleanup(struct drm_device *dev)
5747 struct drm_connector *connector, *ot;
5748 struct drm_crtc *crtc, *ct;
5749 struct drm_encoder *encoder, *enct;
5750 struct drm_framebuffer *fb, *fbt;
5751 struct drm_property *property, *pt;
5752 struct drm_property_blob *blob, *bt;
5753 struct drm_plane *plane, *plt;
5755 list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list,
5757 encoder->funcs->destroy(encoder);
5760 list_for_each_entry_safe(connector, ot,
5761 &dev->mode_config.connector_list, head) {
5762 connector->funcs->destroy(connector);
5765 list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
5767 drm_property_destroy(dev, property);
5770 list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
5772 plane->funcs->destroy(plane);
5775 list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
5776 crtc->funcs->destroy(crtc);
5779 list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
5781 drm_property_unreference_blob(blob);
5785 * Single-threaded teardown context, so it's not required to grab the
5786 * fb_lock to protect against concurrent fb_list access. Contrary, it
5787 * would actually deadlock with the drm_framebuffer_cleanup function.
5789 * Also, if there are any framebuffers left, that's a driver leak now,
5790 * so politely WARN about this.
5792 WARN_ON(!list_empty(&dev->mode_config.fb_list));
5793 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
5794 drm_framebuffer_free(&fb->base.refcount);
5797 ida_destroy(&dev->mode_config.connector_ida);
5798 idr_destroy(&dev->mode_config.tile_idr);
5799 idr_destroy(&dev->mode_config.crtc_idr);
5800 drm_modeset_lock_fini(&dev->mode_config.connection_mutex);
5802 EXPORT_SYMBOL(drm_mode_config_cleanup);
5804 struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
5805 unsigned int supported_rotations)
5807 static const struct drm_prop_enum_list props[] = {
5808 { DRM_ROTATE_0, "rotate-0" },
5809 { DRM_ROTATE_90, "rotate-90" },
5810 { DRM_ROTATE_180, "rotate-180" },
5811 { DRM_ROTATE_270, "rotate-270" },
5812 { DRM_REFLECT_X, "reflect-x" },
5813 { DRM_REFLECT_Y, "reflect-y" },
5816 return drm_property_create_bitmask(dev, 0, "rotation",
5817 props, ARRAY_SIZE(props),
5818 supported_rotations);
5820 EXPORT_SYMBOL(drm_mode_create_rotation_property);
5825 * Tile groups are used to represent tiled monitors with a unique
5826 * integer identifier. Tiled monitors using DisplayID v1.3 have
5827 * a unique 8-byte handle, we store this in a tile group, so we
5828 * have a common identifier for all tiles in a monitor group.
5830 static void drm_tile_group_free(struct kref *kref)
5832 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
5833 struct drm_device *dev = tg->dev;
5834 mutex_lock(&dev->mode_config.idr_mutex);
5835 idr_remove(&dev->mode_config.tile_idr, tg->id);
5836 mutex_unlock(&dev->mode_config.idr_mutex);
5841 * drm_mode_put_tile_group - drop a reference to a tile group.
5843 * @tg: tile group to drop reference to.
5845 * drop reference to tile group and free if 0.
5847 void drm_mode_put_tile_group(struct drm_device *dev,
5848 struct drm_tile_group *tg)
5850 kref_put(&tg->refcount, drm_tile_group_free);
5854 * drm_mode_get_tile_group - get a reference to an existing tile group
5856 * @topology: 8-bytes unique per monitor.
5858 * Use the unique bytes to get a reference to an existing tile group.
5861 * tile group or NULL if not found.
5863 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
5866 struct drm_tile_group *tg;
5868 mutex_lock(&dev->mode_config.idr_mutex);
5869 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
5870 if (!memcmp(tg->group_data, topology, 8)) {
5871 if (!kref_get_unless_zero(&tg->refcount))
5873 mutex_unlock(&dev->mode_config.idr_mutex);
5877 mutex_unlock(&dev->mode_config.idr_mutex);
5880 EXPORT_SYMBOL(drm_mode_get_tile_group);
5883 * drm_mode_create_tile_group - create a tile group from a displayid description
5885 * @topology: 8-bytes unique per monitor.
5887 * Create a tile group for the unique monitor, and get a unique
5888 * identifier for the tile group.
5891 * new tile group or error.
5893 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
5896 struct drm_tile_group *tg;
5899 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
5901 return ERR_PTR(-ENOMEM);
5903 kref_init(&tg->refcount);
5904 memcpy(tg->group_data, topology, 8);
5907 mutex_lock(&dev->mode_config.idr_mutex);
5908 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
5916 mutex_unlock(&dev->mode_config.idr_mutex);
5919 EXPORT_SYMBOL(drm_mode_create_tile_group);
5922 * drm_crtc_enable_color_mgmt - enable color management properties
5924 * @degamma_lut_size: the size of the degamma lut (before CSC)
5925 * @has_ctm: whether to attach ctm_property for CSC matrix
5926 * @gamma_lut_size: the size of the gamma lut (after CSC)
5928 * This function lets the driver enable the color correction
5929 * properties on a CRTC. This includes 3 degamma, csc and gamma
5930 * properties that userspace can set and 2 size properties to inform
5931 * the userspace of the lut sizes. Each of the properties are
5932 * optional. The gamma and degamma properties are only attached if
5933 * their size is not 0 and ctm_property is only attached if has_ctm is
5936 void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
5937 uint degamma_lut_size,
5939 uint gamma_lut_size)
5941 struct drm_device *dev = crtc->dev;
5942 struct drm_mode_config *config = &dev->mode_config;
5944 if (degamma_lut_size) {
5945 drm_object_attach_property(&crtc->base,
5946 config->degamma_lut_property, 0);
5947 drm_object_attach_property(&crtc->base,
5948 config->degamma_lut_size_property,
5953 drm_object_attach_property(&crtc->base,
5954 config->ctm_property, 0);
5956 if (gamma_lut_size) {
5957 drm_object_attach_property(&crtc->base,
5958 config->gamma_lut_property, 0);
5959 drm_object_attach_property(&crtc->base,
5960 config->gamma_lut_size_property,
5964 EXPORT_SYMBOL(drm_crtc_enable_color_mgmt);