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>
43 #include <drm/drm_framebuffer.h>
45 #include "drm_crtc_internal.h"
46 #include "drm_internal.h"
51 static const struct drm_prop_enum_list drm_plane_type_enum_list
[] = {
52 { DRM_PLANE_TYPE_OVERLAY
, "Overlay" },
53 { DRM_PLANE_TYPE_PRIMARY
, "Primary" },
54 { DRM_PLANE_TYPE_CURSOR
, "Cursor" },
61 * drm_crtc_force_disable - Forcibly turn off a CRTC
62 * @crtc: CRTC to turn off
65 * Zero on success, error code on failure.
67 int drm_crtc_force_disable(struct drm_crtc
*crtc
)
69 struct drm_mode_set set
= {
73 return drm_mode_set_config_internal(&set
);
75 EXPORT_SYMBOL(drm_crtc_force_disable
);
78 * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs
79 * @dev: DRM device whose CRTCs to turn off
81 * Drivers may want to call this on unload to ensure that all displays are
82 * unlit and the GPU is in a consistent, low power state. Takes modeset locks.
85 * Zero on success, error code on failure.
87 int drm_crtc_force_disable_all(struct drm_device
*dev
)
89 struct drm_crtc
*crtc
;
92 drm_modeset_lock_all(dev
);
93 drm_for_each_crtc(crtc
, dev
)
95 ret
= drm_crtc_force_disable(crtc
);
100 drm_modeset_unlock_all(dev
);
103 EXPORT_SYMBOL(drm_crtc_force_disable_all
);
105 DEFINE_WW_CLASS(crtc_ww_class
);
107 static unsigned int drm_num_crtcs(struct drm_device
*dev
)
109 unsigned int num
= 0;
110 struct drm_crtc
*tmp
;
112 drm_for_each_crtc(tmp
, dev
) {
119 static int drm_crtc_register_all(struct drm_device
*dev
)
121 struct drm_crtc
*crtc
;
124 drm_for_each_crtc(crtc
, dev
) {
125 if (crtc
->funcs
->late_register
)
126 ret
= crtc
->funcs
->late_register(crtc
);
134 static void drm_crtc_unregister_all(struct drm_device
*dev
)
136 struct drm_crtc
*crtc
;
138 drm_for_each_crtc(crtc
, dev
) {
139 if (crtc
->funcs
->early_unregister
)
140 crtc
->funcs
->early_unregister(crtc
);
145 * drm_crtc_init_with_planes - Initialise a new CRTC object with
146 * specified primary and cursor planes.
148 * @crtc: CRTC object to init
149 * @primary: Primary plane for CRTC
150 * @cursor: Cursor plane for CRTC
151 * @funcs: callbacks for the new CRTC
152 * @name: printf style format string for the CRTC name, or NULL for default name
154 * Inits a new object created as base part of a driver crtc object.
157 * Zero on success, error code on failure.
159 int drm_crtc_init_with_planes(struct drm_device
*dev
, struct drm_crtc
*crtc
,
160 struct drm_plane
*primary
,
161 struct drm_plane
*cursor
,
162 const struct drm_crtc_funcs
*funcs
,
163 const char *name
, ...)
165 struct drm_mode_config
*config
= &dev
->mode_config
;
168 WARN_ON(primary
&& primary
->type
!= DRM_PLANE_TYPE_PRIMARY
);
169 WARN_ON(cursor
&& cursor
->type
!= DRM_PLANE_TYPE_CURSOR
);
174 INIT_LIST_HEAD(&crtc
->commit_list
);
175 spin_lock_init(&crtc
->commit_lock
);
177 drm_modeset_lock_init(&crtc
->mutex
);
178 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
186 crtc
->name
= kvasprintf(GFP_KERNEL
, name
, ap
);
189 crtc
->name
= kasprintf(GFP_KERNEL
, "crtc-%d",
193 drm_mode_object_unregister(dev
, &crtc
->base
);
197 crtc
->base
.properties
= &crtc
->properties
;
199 list_add_tail(&crtc
->head
, &config
->crtc_list
);
200 crtc
->index
= config
->num_crtc
++;
202 crtc
->primary
= primary
;
203 crtc
->cursor
= cursor
;
205 primary
->possible_crtcs
= 1 << drm_crtc_index(crtc
);
207 cursor
->possible_crtcs
= 1 << drm_crtc_index(crtc
);
209 if (drm_core_check_feature(dev
, DRIVER_ATOMIC
)) {
210 drm_object_attach_property(&crtc
->base
, config
->prop_active
, 0);
211 drm_object_attach_property(&crtc
->base
, config
->prop_mode_id
, 0);
216 EXPORT_SYMBOL(drm_crtc_init_with_planes
);
219 * drm_crtc_cleanup - Clean up the core crtc usage
220 * @crtc: CRTC to cleanup
222 * This function cleans up @crtc and removes it from the DRM mode setting
223 * core. Note that the function does *not* free the crtc structure itself,
224 * this is the responsibility of the caller.
226 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
228 struct drm_device
*dev
= crtc
->dev
;
230 /* Note that the crtc_list is considered to be static; should we
231 * remove the drm_crtc at runtime we would have to decrement all
232 * the indices on the drm_crtc after us in the crtc_list.
235 kfree(crtc
->gamma_store
);
236 crtc
->gamma_store
= NULL
;
238 drm_modeset_lock_fini(&crtc
->mutex
);
240 drm_mode_object_unregister(dev
, &crtc
->base
);
241 list_del(&crtc
->head
);
242 dev
->mode_config
.num_crtc
--;
244 WARN_ON(crtc
->state
&& !crtc
->funcs
->atomic_destroy_state
);
245 if (crtc
->state
&& crtc
->funcs
->atomic_destroy_state
)
246 crtc
->funcs
->atomic_destroy_state(crtc
, crtc
->state
);
250 memset(crtc
, 0, sizeof(*crtc
));
252 EXPORT_SYMBOL(drm_crtc_cleanup
);
254 static unsigned int drm_num_planes(struct drm_device
*dev
)
256 unsigned int num
= 0;
257 struct drm_plane
*tmp
;
259 drm_for_each_plane(tmp
, dev
) {
267 * drm_universal_plane_init - Initialize a new universal plane object
269 * @plane: plane object to init
270 * @possible_crtcs: bitmask of possible CRTCs
271 * @funcs: callbacks for the new plane
272 * @formats: array of supported formats (DRM_FORMAT\_\*)
273 * @format_count: number of elements in @formats
274 * @type: type of plane (overlay, primary, cursor)
275 * @name: printf style format string for the plane name, or NULL for default name
277 * Initializes a plane object of type @type.
280 * Zero on success, error code on failure.
282 int drm_universal_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
283 unsigned long possible_crtcs
,
284 const struct drm_plane_funcs
*funcs
,
285 const uint32_t *formats
, unsigned int format_count
,
286 enum drm_plane_type type
,
287 const char *name
, ...)
289 struct drm_mode_config
*config
= &dev
->mode_config
;
292 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
296 drm_modeset_lock_init(&plane
->mutex
);
298 plane
->base
.properties
= &plane
->properties
;
300 plane
->funcs
= funcs
;
301 plane
->format_types
= kmalloc_array(format_count
, sizeof(uint32_t),
303 if (!plane
->format_types
) {
304 DRM_DEBUG_KMS("out of memory when allocating plane\n");
305 drm_mode_object_unregister(dev
, &plane
->base
);
313 plane
->name
= kvasprintf(GFP_KERNEL
, name
, ap
);
316 plane
->name
= kasprintf(GFP_KERNEL
, "plane-%d",
317 drm_num_planes(dev
));
320 kfree(plane
->format_types
);
321 drm_mode_object_unregister(dev
, &plane
->base
);
325 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
326 plane
->format_count
= format_count
;
327 plane
->possible_crtcs
= possible_crtcs
;
330 list_add_tail(&plane
->head
, &config
->plane_list
);
331 plane
->index
= config
->num_total_plane
++;
332 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
)
333 config
->num_overlay_plane
++;
335 drm_object_attach_property(&plane
->base
,
336 config
->plane_type_property
,
339 if (drm_core_check_feature(dev
, DRIVER_ATOMIC
)) {
340 drm_object_attach_property(&plane
->base
, config
->prop_fb_id
, 0);
341 drm_object_attach_property(&plane
->base
, config
->prop_crtc_id
, 0);
342 drm_object_attach_property(&plane
->base
, config
->prop_crtc_x
, 0);
343 drm_object_attach_property(&plane
->base
, config
->prop_crtc_y
, 0);
344 drm_object_attach_property(&plane
->base
, config
->prop_crtc_w
, 0);
345 drm_object_attach_property(&plane
->base
, config
->prop_crtc_h
, 0);
346 drm_object_attach_property(&plane
->base
, config
->prop_src_x
, 0);
347 drm_object_attach_property(&plane
->base
, config
->prop_src_y
, 0);
348 drm_object_attach_property(&plane
->base
, config
->prop_src_w
, 0);
349 drm_object_attach_property(&plane
->base
, config
->prop_src_h
, 0);
354 EXPORT_SYMBOL(drm_universal_plane_init
);
356 static int drm_plane_register_all(struct drm_device
*dev
)
358 struct drm_plane
*plane
;
361 drm_for_each_plane(plane
, dev
) {
362 if (plane
->funcs
->late_register
)
363 ret
= plane
->funcs
->late_register(plane
);
371 static void drm_plane_unregister_all(struct drm_device
*dev
)
373 struct drm_plane
*plane
;
375 drm_for_each_plane(plane
, dev
) {
376 if (plane
->funcs
->early_unregister
)
377 plane
->funcs
->early_unregister(plane
);
382 * drm_plane_init - Initialize a legacy plane
384 * @plane: plane object to init
385 * @possible_crtcs: bitmask of possible CRTCs
386 * @funcs: callbacks for the new plane
387 * @formats: array of supported formats (DRM_FORMAT\_\*)
388 * @format_count: number of elements in @formats
389 * @is_primary: plane type (primary vs overlay)
391 * Legacy API to initialize a DRM plane.
393 * New drivers should call drm_universal_plane_init() instead.
396 * Zero on success, error code on failure.
398 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
399 unsigned long possible_crtcs
,
400 const struct drm_plane_funcs
*funcs
,
401 const uint32_t *formats
, unsigned int format_count
,
404 enum drm_plane_type type
;
406 type
= is_primary
? DRM_PLANE_TYPE_PRIMARY
: DRM_PLANE_TYPE_OVERLAY
;
407 return drm_universal_plane_init(dev
, plane
, possible_crtcs
, funcs
,
408 formats
, format_count
, type
, NULL
);
410 EXPORT_SYMBOL(drm_plane_init
);
413 * drm_plane_cleanup - Clean up the core plane usage
414 * @plane: plane to cleanup
416 * This function cleans up @plane and removes it from the DRM mode setting
417 * core. Note that the function does *not* free the plane structure itself,
418 * this is the responsibility of the caller.
420 void drm_plane_cleanup(struct drm_plane
*plane
)
422 struct drm_device
*dev
= plane
->dev
;
424 drm_modeset_lock_all(dev
);
425 kfree(plane
->format_types
);
426 drm_mode_object_unregister(dev
, &plane
->base
);
428 BUG_ON(list_empty(&plane
->head
));
430 /* Note that the plane_list is considered to be static; should we
431 * remove the drm_plane at runtime we would have to decrement all
432 * the indices on the drm_plane after us in the plane_list.
435 list_del(&plane
->head
);
436 dev
->mode_config
.num_total_plane
--;
437 if (plane
->type
== DRM_PLANE_TYPE_OVERLAY
)
438 dev
->mode_config
.num_overlay_plane
--;
439 drm_modeset_unlock_all(dev
);
441 WARN_ON(plane
->state
&& !plane
->funcs
->atomic_destroy_state
);
442 if (plane
->state
&& plane
->funcs
->atomic_destroy_state
)
443 plane
->funcs
->atomic_destroy_state(plane
, plane
->state
);
447 memset(plane
, 0, sizeof(*plane
));
449 EXPORT_SYMBOL(drm_plane_cleanup
);
452 * drm_plane_from_index - find the registered plane at an index
454 * @idx: index of registered plane to find for
456 * Given a plane index, return the registered plane from DRM device's
457 * list of planes with matching index.
460 drm_plane_from_index(struct drm_device
*dev
, int idx
)
462 struct drm_plane
*plane
;
464 drm_for_each_plane(plane
, dev
)
465 if (idx
== plane
->index
)
470 EXPORT_SYMBOL(drm_plane_from_index
);
473 * drm_plane_force_disable - Forcibly disable a plane
474 * @plane: plane to disable
476 * Forces the plane to be disabled.
478 * Used when the plane's current framebuffer is destroyed,
479 * and when restoring fbdev mode.
481 void drm_plane_force_disable(struct drm_plane
*plane
)
488 plane
->old_fb
= plane
->fb
;
489 ret
= plane
->funcs
->disable_plane(plane
);
491 DRM_ERROR("failed to disable plane with busy fb\n");
492 plane
->old_fb
= NULL
;
495 /* disconnect the plane from the fb and crtc: */
496 drm_framebuffer_unreference(plane
->old_fb
);
497 plane
->old_fb
= NULL
;
501 EXPORT_SYMBOL(drm_plane_force_disable
);
503 int drm_modeset_register_all(struct drm_device
*dev
)
507 ret
= drm_plane_register_all(dev
);
511 ret
= drm_crtc_register_all(dev
);
515 ret
= drm_encoder_register_all(dev
);
519 ret
= drm_connector_register_all(dev
);
526 drm_encoder_unregister_all(dev
);
528 drm_crtc_unregister_all(dev
);
530 drm_plane_unregister_all(dev
);
535 void drm_modeset_unregister_all(struct drm_device
*dev
)
537 drm_connector_unregister_all(dev
);
538 drm_encoder_unregister_all(dev
);
539 drm_crtc_unregister_all(dev
);
540 drm_plane_unregister_all(dev
);
543 static int drm_mode_create_standard_properties(struct drm_device
*dev
)
545 struct drm_property
*prop
;
548 ret
= drm_connector_create_standard_properties(dev
);
552 prop
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
553 "type", drm_plane_type_enum_list
,
554 ARRAY_SIZE(drm_plane_type_enum_list
));
557 dev
->mode_config
.plane_type_property
= prop
;
559 prop
= drm_property_create_range(dev
, DRM_MODE_PROP_ATOMIC
,
560 "SRC_X", 0, UINT_MAX
);
563 dev
->mode_config
.prop_src_x
= prop
;
565 prop
= drm_property_create_range(dev
, DRM_MODE_PROP_ATOMIC
,
566 "SRC_Y", 0, UINT_MAX
);
569 dev
->mode_config
.prop_src_y
= prop
;
571 prop
= drm_property_create_range(dev
, DRM_MODE_PROP_ATOMIC
,
572 "SRC_W", 0, UINT_MAX
);
575 dev
->mode_config
.prop_src_w
= prop
;
577 prop
= drm_property_create_range(dev
, DRM_MODE_PROP_ATOMIC
,
578 "SRC_H", 0, UINT_MAX
);
581 dev
->mode_config
.prop_src_h
= prop
;
583 prop
= drm_property_create_signed_range(dev
, DRM_MODE_PROP_ATOMIC
,
584 "CRTC_X", INT_MIN
, INT_MAX
);
587 dev
->mode_config
.prop_crtc_x
= prop
;
589 prop
= drm_property_create_signed_range(dev
, DRM_MODE_PROP_ATOMIC
,
590 "CRTC_Y", INT_MIN
, INT_MAX
);
593 dev
->mode_config
.prop_crtc_y
= prop
;
595 prop
= drm_property_create_range(dev
, DRM_MODE_PROP_ATOMIC
,
596 "CRTC_W", 0, INT_MAX
);
599 dev
->mode_config
.prop_crtc_w
= prop
;
601 prop
= drm_property_create_range(dev
, DRM_MODE_PROP_ATOMIC
,
602 "CRTC_H", 0, INT_MAX
);
605 dev
->mode_config
.prop_crtc_h
= prop
;
607 prop
= drm_property_create_object(dev
, DRM_MODE_PROP_ATOMIC
,
608 "FB_ID", DRM_MODE_OBJECT_FB
);
611 dev
->mode_config
.prop_fb_id
= prop
;
613 prop
= drm_property_create_object(dev
, DRM_MODE_PROP_ATOMIC
,
614 "CRTC_ID", DRM_MODE_OBJECT_CRTC
);
617 dev
->mode_config
.prop_crtc_id
= prop
;
619 prop
= drm_property_create_bool(dev
, DRM_MODE_PROP_ATOMIC
,
623 dev
->mode_config
.prop_active
= prop
;
625 prop
= drm_property_create(dev
,
626 DRM_MODE_PROP_ATOMIC
| DRM_MODE_PROP_BLOB
,
630 dev
->mode_config
.prop_mode_id
= prop
;
632 prop
= drm_property_create(dev
,
637 dev
->mode_config
.degamma_lut_property
= prop
;
639 prop
= drm_property_create_range(dev
,
640 DRM_MODE_PROP_IMMUTABLE
,
641 "DEGAMMA_LUT_SIZE", 0, UINT_MAX
);
644 dev
->mode_config
.degamma_lut_size_property
= prop
;
646 prop
= drm_property_create(dev
,
651 dev
->mode_config
.ctm_property
= prop
;
653 prop
= drm_property_create(dev
,
658 dev
->mode_config
.gamma_lut_property
= prop
;
660 prop
= drm_property_create_range(dev
,
661 DRM_MODE_PROP_IMMUTABLE
,
662 "GAMMA_LUT_SIZE", 0, UINT_MAX
);
665 dev
->mode_config
.gamma_lut_size_property
= prop
;
671 * drm_mode_getresources - get graphics configuration
672 * @dev: drm device for the ioctl
673 * @data: data pointer for the ioctl
674 * @file_priv: drm file for the ioctl call
676 * Construct a set of configuration description structures and return
677 * them to the user, including CRTC, connector and framebuffer configuration.
679 * Called by the user via ioctl.
682 * Zero on success, negative errno on failure.
684 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
685 struct drm_file
*file_priv
)
687 struct drm_mode_card_res
*card_res
= data
;
688 struct list_head
*lh
;
689 struct drm_framebuffer
*fb
;
690 struct drm_connector
*connector
;
691 struct drm_crtc
*crtc
;
692 struct drm_encoder
*encoder
;
694 int connector_count
= 0;
697 int encoder_count
= 0;
699 uint32_t __user
*fb_id
;
700 uint32_t __user
*crtc_id
;
701 uint32_t __user
*connector_id
;
702 uint32_t __user
*encoder_id
;
704 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
708 mutex_lock(&file_priv
->fbs_lock
);
710 * For the non-control nodes we need to limit the list of resources
711 * by IDs in the group list for this node
713 list_for_each(lh
, &file_priv
->fbs
)
716 /* handle this in 4 parts */
718 if (card_res
->count_fbs
>= fb_count
) {
720 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
721 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
722 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
723 mutex_unlock(&file_priv
->fbs_lock
);
729 card_res
->count_fbs
= fb_count
;
730 mutex_unlock(&file_priv
->fbs_lock
);
732 /* mode_config.mutex protects the connector list against e.g. DP MST
733 * connector hot-adding. CRTC/Plane lists are invariant. */
734 mutex_lock(&dev
->mode_config
.mutex
);
735 drm_for_each_crtc(crtc
, dev
)
738 drm_for_each_connector(connector
, dev
)
741 drm_for_each_encoder(encoder
, dev
)
744 card_res
->max_height
= dev
->mode_config
.max_height
;
745 card_res
->min_height
= dev
->mode_config
.min_height
;
746 card_res
->max_width
= dev
->mode_config
.max_width
;
747 card_res
->min_width
= dev
->mode_config
.min_width
;
750 if (card_res
->count_crtcs
>= crtc_count
) {
752 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
753 drm_for_each_crtc(crtc
, dev
) {
754 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
761 card_res
->count_crtcs
= crtc_count
;
764 if (card_res
->count_encoders
>= encoder_count
) {
766 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
767 drm_for_each_encoder(encoder
, dev
) {
768 if (put_user(encoder
->base
.id
, encoder_id
+
776 card_res
->count_encoders
= encoder_count
;
779 if (card_res
->count_connectors
>= connector_count
) {
781 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
782 drm_for_each_connector(connector
, dev
) {
783 if (put_user(connector
->base
.id
,
784 connector_id
+ copied
)) {
791 card_res
->count_connectors
= connector_count
;
794 mutex_unlock(&dev
->mode_config
.mutex
);
799 * drm_mode_getcrtc - get CRTC configuration
800 * @dev: drm device for the ioctl
801 * @data: data pointer for the ioctl
802 * @file_priv: drm file for the ioctl call
804 * Construct a CRTC configuration structure to return to the user.
806 * Called by the user via ioctl.
809 * Zero on success, negative errno on failure.
811 int drm_mode_getcrtc(struct drm_device
*dev
,
812 void *data
, struct drm_file
*file_priv
)
814 struct drm_mode_crtc
*crtc_resp
= data
;
815 struct drm_crtc
*crtc
;
817 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
820 crtc
= drm_crtc_find(dev
, crtc_resp
->crtc_id
);
824 drm_modeset_lock_crtc(crtc
, crtc
->primary
);
825 crtc_resp
->gamma_size
= crtc
->gamma_size
;
826 if (crtc
->primary
->fb
)
827 crtc_resp
->fb_id
= crtc
->primary
->fb
->base
.id
;
829 crtc_resp
->fb_id
= 0;
832 crtc_resp
->x
= crtc
->primary
->state
->src_x
>> 16;
833 crtc_resp
->y
= crtc
->primary
->state
->src_y
>> 16;
834 if (crtc
->state
->enable
) {
835 drm_mode_convert_to_umode(&crtc_resp
->mode
, &crtc
->state
->mode
);
836 crtc_resp
->mode_valid
= 1;
839 crtc_resp
->mode_valid
= 0;
842 crtc_resp
->x
= crtc
->x
;
843 crtc_resp
->y
= crtc
->y
;
845 drm_mode_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
846 crtc_resp
->mode_valid
= 1;
849 crtc_resp
->mode_valid
= 0;
852 drm_modeset_unlock_crtc(crtc
);
858 * drm_mode_getplane_res - enumerate all plane resources
861 * @file_priv: DRM file info
863 * Construct a list of plane ids to return to the user.
865 * Called by the user via ioctl.
868 * Zero on success, negative errno on failure.
870 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
871 struct drm_file
*file_priv
)
873 struct drm_mode_get_plane_res
*plane_resp
= data
;
874 struct drm_mode_config
*config
;
875 struct drm_plane
*plane
;
876 uint32_t __user
*plane_ptr
;
880 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
883 config
= &dev
->mode_config
;
885 if (file_priv
->universal_planes
)
886 num_planes
= config
->num_total_plane
;
888 num_planes
= config
->num_overlay_plane
;
891 * This ioctl is called twice, once to determine how much space is
892 * needed, and the 2nd time to fill it.
895 (plane_resp
->count_planes
>= num_planes
)) {
896 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
898 /* Plane lists are invariant, no locking needed. */
899 drm_for_each_plane(plane
, dev
) {
901 * Unless userspace set the 'universal planes'
902 * capability bit, only advertise overlays.
904 if (plane
->type
!= DRM_PLANE_TYPE_OVERLAY
&&
905 !file_priv
->universal_planes
)
908 if (put_user(plane
->base
.id
, plane_ptr
+ copied
))
913 plane_resp
->count_planes
= num_planes
;
919 * drm_mode_getplane - get plane configuration
922 * @file_priv: DRM file info
924 * Construct a plane configuration structure to return to the user.
926 * Called by the user via ioctl.
929 * Zero on success, negative errno on failure.
931 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
932 struct drm_file
*file_priv
)
934 struct drm_mode_get_plane
*plane_resp
= data
;
935 struct drm_plane
*plane
;
936 uint32_t __user
*format_ptr
;
938 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
941 plane
= drm_plane_find(dev
, plane_resp
->plane_id
);
945 drm_modeset_lock(&plane
->mutex
, NULL
);
947 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
949 plane_resp
->crtc_id
= 0;
952 plane_resp
->fb_id
= plane
->fb
->base
.id
;
954 plane_resp
->fb_id
= 0;
955 drm_modeset_unlock(&plane
->mutex
);
957 plane_resp
->plane_id
= plane
->base
.id
;
958 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
959 plane_resp
->gamma_size
= 0;
962 * This ioctl is called twice, once to determine how much space is
963 * needed, and the 2nd time to fill it.
965 if (plane
->format_count
&&
966 (plane_resp
->count_format_types
>= plane
->format_count
)) {
967 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
968 if (copy_to_user(format_ptr
,
970 sizeof(uint32_t) * plane
->format_count
)) {
974 plane_resp
->count_format_types
= plane
->format_count
;
980 * drm_plane_check_pixel_format - Check if the plane supports the pixel format
981 * @plane: plane to check for format support
982 * @format: the pixel format
985 * Zero of @plane has @format in its list of supported pixel formats, -EINVAL
988 int drm_plane_check_pixel_format(const struct drm_plane
*plane
, u32 format
)
992 for (i
= 0; i
< plane
->format_count
; i
++) {
993 if (format
== plane
->format_types
[i
])
1000 static int check_src_coords(uint32_t src_x
, uint32_t src_y
,
1001 uint32_t src_w
, uint32_t src_h
,
1002 const struct drm_framebuffer
*fb
)
1004 unsigned int fb_width
, fb_height
;
1006 fb_width
= fb
->width
<< 16;
1007 fb_height
= fb
->height
<< 16;
1009 /* Make sure source coordinates are inside the fb. */
1010 if (src_w
> fb_width
||
1011 src_x
> fb_width
- src_w
||
1012 src_h
> fb_height
||
1013 src_y
> fb_height
- src_h
) {
1014 DRM_DEBUG_KMS("Invalid source coordinates "
1015 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1016 src_w
>> 16, ((src_w
& 0xffff) * 15625) >> 10,
1017 src_h
>> 16, ((src_h
& 0xffff) * 15625) >> 10,
1018 src_x
>> 16, ((src_x
& 0xffff) * 15625) >> 10,
1019 src_y
>> 16, ((src_y
& 0xffff) * 15625) >> 10);
1027 * setplane_internal - setplane handler for internal callers
1029 * Note that we assume an extra reference has already been taken on fb. If the
1030 * update fails, this reference will be dropped before return; if it succeeds,
1031 * the previous framebuffer (if any) will be unreferenced instead.
1033 * src_{x,y,w,h} are provided in 16.16 fixed point format
1035 static int __setplane_internal(struct drm_plane
*plane
,
1036 struct drm_crtc
*crtc
,
1037 struct drm_framebuffer
*fb
,
1038 int32_t crtc_x
, int32_t crtc_y
,
1039 uint32_t crtc_w
, uint32_t crtc_h
,
1040 /* src_{x,y,w,h} values are 16.16 fixed point */
1041 uint32_t src_x
, uint32_t src_y
,
1042 uint32_t src_w
, uint32_t src_h
)
1046 /* No fb means shut it down */
1048 plane
->old_fb
= plane
->fb
;
1049 ret
= plane
->funcs
->disable_plane(plane
);
1054 plane
->old_fb
= NULL
;
1059 /* Check whether this plane is usable on this CRTC */
1060 if (!(plane
->possible_crtcs
& drm_crtc_mask(crtc
))) {
1061 DRM_DEBUG_KMS("Invalid crtc for plane\n");
1066 /* Check whether this plane supports the fb pixel format. */
1067 ret
= drm_plane_check_pixel_format(plane
, fb
->pixel_format
);
1069 char *format_name
= drm_get_format_name(fb
->pixel_format
);
1070 DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name
);
1075 /* Give drivers some help against integer overflows */
1076 if (crtc_w
> INT_MAX
||
1077 crtc_x
> INT_MAX
- (int32_t) crtc_w
||
1079 crtc_y
> INT_MAX
- (int32_t) crtc_h
) {
1080 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1081 crtc_w
, crtc_h
, crtc_x
, crtc_y
);
1086 ret
= check_src_coords(src_x
, src_y
, src_w
, src_h
, fb
);
1090 plane
->old_fb
= plane
->fb
;
1091 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1092 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
1093 src_x
, src_y
, src_w
, src_h
);
1099 plane
->old_fb
= NULL
;
1104 drm_framebuffer_unreference(fb
);
1106 drm_framebuffer_unreference(plane
->old_fb
);
1107 plane
->old_fb
= NULL
;
1112 static int setplane_internal(struct drm_plane
*plane
,
1113 struct drm_crtc
*crtc
,
1114 struct drm_framebuffer
*fb
,
1115 int32_t crtc_x
, int32_t crtc_y
,
1116 uint32_t crtc_w
, uint32_t crtc_h
,
1117 /* src_{x,y,w,h} values are 16.16 fixed point */
1118 uint32_t src_x
, uint32_t src_y
,
1119 uint32_t src_w
, uint32_t src_h
)
1123 drm_modeset_lock_all(plane
->dev
);
1124 ret
= __setplane_internal(plane
, crtc
, fb
,
1125 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
1126 src_x
, src_y
, src_w
, src_h
);
1127 drm_modeset_unlock_all(plane
->dev
);
1133 * drm_mode_setplane - configure a plane's configuration
1135 * @data: ioctl data*
1136 * @file_priv: DRM file info
1138 * Set plane configuration, including placement, fb, scaling, and other factors.
1139 * Or pass a NULL fb to disable (planes may be disabled without providing a
1143 * Zero on success, negative errno on failure.
1145 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1146 struct drm_file
*file_priv
)
1148 struct drm_mode_set_plane
*plane_req
= data
;
1149 struct drm_plane
*plane
;
1150 struct drm_crtc
*crtc
= NULL
;
1151 struct drm_framebuffer
*fb
= NULL
;
1153 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1157 * First, find the plane, crtc, and fb objects. If not available,
1158 * we don't bother to call the driver.
1160 plane
= drm_plane_find(dev
, plane_req
->plane_id
);
1162 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1163 plane_req
->plane_id
);
1167 if (plane_req
->fb_id
) {
1168 fb
= drm_framebuffer_lookup(dev
, plane_req
->fb_id
);
1170 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1175 crtc
= drm_crtc_find(dev
, plane_req
->crtc_id
);
1177 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1178 plane_req
->crtc_id
);
1184 * setplane_internal will take care of deref'ing either the old or new
1185 * framebuffer depending on success.
1187 return setplane_internal(plane
, crtc
, fb
,
1188 plane_req
->crtc_x
, plane_req
->crtc_y
,
1189 plane_req
->crtc_w
, plane_req
->crtc_h
,
1190 plane_req
->src_x
, plane_req
->src_y
,
1191 plane_req
->src_w
, plane_req
->src_h
);
1195 * drm_mode_set_config_internal - helper to call ->set_config
1196 * @set: modeset config to set
1198 * This is a little helper to wrap internal calls to the ->set_config driver
1199 * interface. The only thing it adds is correct refcounting dance.
1202 * Zero on success, negative errno on failure.
1204 int drm_mode_set_config_internal(struct drm_mode_set
*set
)
1206 struct drm_crtc
*crtc
= set
->crtc
;
1207 struct drm_framebuffer
*fb
;
1208 struct drm_crtc
*tmp
;
1212 * NOTE: ->set_config can also disable other crtcs (if we steal all
1213 * connectors from it), hence we need to refcount the fbs across all
1214 * crtcs. Atomic modeset will have saner semantics ...
1216 drm_for_each_crtc(tmp
, crtc
->dev
)
1217 tmp
->primary
->old_fb
= tmp
->primary
->fb
;
1221 ret
= crtc
->funcs
->set_config(set
);
1223 crtc
->primary
->crtc
= crtc
;
1224 crtc
->primary
->fb
= fb
;
1227 drm_for_each_crtc(tmp
, crtc
->dev
) {
1228 if (tmp
->primary
->fb
)
1229 drm_framebuffer_reference(tmp
->primary
->fb
);
1230 if (tmp
->primary
->old_fb
)
1231 drm_framebuffer_unreference(tmp
->primary
->old_fb
);
1232 tmp
->primary
->old_fb
= NULL
;
1237 EXPORT_SYMBOL(drm_mode_set_config_internal
);
1240 * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode
1241 * @mode: mode to query
1242 * @hdisplay: hdisplay value to fill in
1243 * @vdisplay: vdisplay value to fill in
1245 * The vdisplay value will be doubled if the specified mode is a stereo mode of
1246 * the appropriate layout.
1248 void drm_crtc_get_hv_timing(const struct drm_display_mode
*mode
,
1249 int *hdisplay
, int *vdisplay
)
1251 struct drm_display_mode adjusted
;
1253 drm_mode_copy(&adjusted
, mode
);
1254 drm_mode_set_crtcinfo(&adjusted
, CRTC_STEREO_DOUBLE_ONLY
);
1255 *hdisplay
= adjusted
.crtc_hdisplay
;
1256 *vdisplay
= adjusted
.crtc_vdisplay
;
1258 EXPORT_SYMBOL(drm_crtc_get_hv_timing
);
1261 * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the
1263 * @crtc: CRTC that framebuffer will be displayed on
1266 * @mode: mode that framebuffer will be displayed under
1267 * @fb: framebuffer to check size of
1269 int drm_crtc_check_viewport(const struct drm_crtc
*crtc
,
1271 const struct drm_display_mode
*mode
,
1272 const struct drm_framebuffer
*fb
)
1275 int hdisplay
, vdisplay
;
1277 drm_crtc_get_hv_timing(mode
, &hdisplay
, &vdisplay
);
1280 crtc
->primary
->state
->rotation
& (DRM_ROTATE_90
|
1282 swap(hdisplay
, vdisplay
);
1284 return check_src_coords(x
<< 16, y
<< 16,
1285 hdisplay
<< 16, vdisplay
<< 16, fb
);
1287 EXPORT_SYMBOL(drm_crtc_check_viewport
);
1290 * drm_mode_setcrtc - set CRTC configuration
1291 * @dev: drm device for the ioctl
1292 * @data: data pointer for the ioctl
1293 * @file_priv: drm file for the ioctl call
1295 * Build a new CRTC configuration based on user request.
1297 * Called by the user via ioctl.
1300 * Zero on success, negative errno on failure.
1302 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1303 struct drm_file
*file_priv
)
1305 struct drm_mode_config
*config
= &dev
->mode_config
;
1306 struct drm_mode_crtc
*crtc_req
= data
;
1307 struct drm_crtc
*crtc
;
1308 struct drm_connector
**connector_set
= NULL
, *connector
;
1309 struct drm_framebuffer
*fb
= NULL
;
1310 struct drm_display_mode
*mode
= NULL
;
1311 struct drm_mode_set set
;
1312 uint32_t __user
*set_connectors_ptr
;
1316 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1320 * Universal plane src offsets are only 16.16, prevent havoc for
1321 * drivers using universal plane code internally.
1323 if (crtc_req
->x
& 0xffff0000 || crtc_req
->y
& 0xffff0000)
1326 drm_modeset_lock_all(dev
);
1327 crtc
= drm_crtc_find(dev
, crtc_req
->crtc_id
);
1329 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1333 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc
->base
.id
, crtc
->name
);
1335 if (crtc_req
->mode_valid
) {
1336 /* If we have a mode we need a framebuffer. */
1337 /* If we pass -1, set the mode with the currently bound fb */
1338 if (crtc_req
->fb_id
== -1) {
1339 if (!crtc
->primary
->fb
) {
1340 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
1344 fb
= crtc
->primary
->fb
;
1345 /* Make refcounting symmetric with the lookup path. */
1346 drm_framebuffer_reference(fb
);
1348 fb
= drm_framebuffer_lookup(dev
, crtc_req
->fb_id
);
1350 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1357 mode
= drm_mode_create(dev
);
1363 ret
= drm_mode_convert_umode(mode
, &crtc_req
->mode
);
1365 DRM_DEBUG_KMS("Invalid mode\n");
1370 * Check whether the primary plane supports the fb pixel format.
1371 * Drivers not implementing the universal planes API use a
1372 * default formats list provided by the DRM core which doesn't
1373 * match real hardware capabilities. Skip the check in that
1376 if (!crtc
->primary
->format_default
) {
1377 ret
= drm_plane_check_pixel_format(crtc
->primary
,
1380 char *format_name
= drm_get_format_name(fb
->pixel_format
);
1381 DRM_DEBUG_KMS("Invalid pixel format %s\n", format_name
);
1387 ret
= drm_crtc_check_viewport(crtc
, crtc_req
->x
, crtc_req
->y
,
1394 if (crtc_req
->count_connectors
== 0 && mode
) {
1395 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1400 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1401 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1402 crtc_req
->count_connectors
);
1407 if (crtc_req
->count_connectors
> 0) {
1410 /* Avoid unbounded kernel memory allocation */
1411 if (crtc_req
->count_connectors
> config
->num_connector
) {
1416 connector_set
= kmalloc_array(crtc_req
->count_connectors
,
1417 sizeof(struct drm_connector
*),
1419 if (!connector_set
) {
1424 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1425 connector_set
[i
] = NULL
;
1426 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
1427 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1432 connector
= drm_connector_lookup(dev
, out_id
);
1434 DRM_DEBUG_KMS("Connector id %d unknown\n",
1439 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1443 connector_set
[i
] = connector
;
1448 set
.x
= crtc_req
->x
;
1449 set
.y
= crtc_req
->y
;
1451 set
.connectors
= connector_set
;
1452 set
.num_connectors
= crtc_req
->count_connectors
;
1454 ret
= drm_mode_set_config_internal(&set
);
1458 drm_framebuffer_unreference(fb
);
1460 if (connector_set
) {
1461 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1462 if (connector_set
[i
])
1463 drm_connector_unreference(connector_set
[i
]);
1466 kfree(connector_set
);
1467 drm_mode_destroy(dev
, mode
);
1468 drm_modeset_unlock_all(dev
);
1473 * drm_mode_cursor_universal - translate legacy cursor ioctl call into a
1474 * universal plane handler call
1475 * @crtc: crtc to update cursor for
1476 * @req: data pointer for the ioctl
1477 * @file_priv: drm file for the ioctl call
1479 * Legacy cursor ioctl's work directly with driver buffer handles. To
1480 * translate legacy ioctl calls into universal plane handler calls, we need to
1481 * wrap the native buffer handle in a drm_framebuffer.
1483 * Note that we assume any handle passed to the legacy ioctls was a 32-bit ARGB
1484 * buffer with a pitch of 4*width; the universal plane interface should be used
1485 * directly in cases where the hardware can support other buffer settings and
1486 * userspace wants to make use of these capabilities.
1489 * Zero on success, negative errno on failure.
1491 static int drm_mode_cursor_universal(struct drm_crtc
*crtc
,
1492 struct drm_mode_cursor2
*req
,
1493 struct drm_file
*file_priv
)
1495 struct drm_device
*dev
= crtc
->dev
;
1496 struct drm_framebuffer
*fb
= NULL
;
1497 struct drm_mode_fb_cmd2 fbreq
= {
1498 .width
= req
->width
,
1499 .height
= req
->height
,
1500 .pixel_format
= DRM_FORMAT_ARGB8888
,
1501 .pitches
= { req
->width
* 4 },
1502 .handles
= { req
->handle
},
1504 int32_t crtc_x
, crtc_y
;
1505 uint32_t crtc_w
= 0, crtc_h
= 0;
1506 uint32_t src_w
= 0, src_h
= 0;
1509 BUG_ON(!crtc
->cursor
);
1510 WARN_ON(crtc
->cursor
->crtc
!= crtc
&& crtc
->cursor
->crtc
!= NULL
);
1513 * Obtain fb we'll be using (either new or existing) and take an extra
1514 * reference to it if fb != null. setplane will take care of dropping
1515 * the reference if the plane update fails.
1517 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1519 fb
= drm_internal_framebuffer_create(dev
, &fbreq
, file_priv
);
1521 DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n");
1524 fb
->hot_x
= req
->hot_x
;
1525 fb
->hot_y
= req
->hot_y
;
1530 fb
= crtc
->cursor
->fb
;
1532 drm_framebuffer_reference(fb
);
1535 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1539 crtc_x
= crtc
->cursor_x
;
1540 crtc_y
= crtc
->cursor_y
;
1545 crtc_h
= fb
->height
;
1546 src_w
= fb
->width
<< 16;
1547 src_h
= fb
->height
<< 16;
1551 * setplane_internal will take care of deref'ing either the old or new
1552 * framebuffer depending on success.
1554 ret
= __setplane_internal(crtc
->cursor
, crtc
, fb
,
1555 crtc_x
, crtc_y
, crtc_w
, crtc_h
,
1556 0, 0, src_w
, src_h
);
1558 /* Update successful; save new cursor position, if necessary */
1559 if (ret
== 0 && req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1560 crtc
->cursor_x
= req
->x
;
1561 crtc
->cursor_y
= req
->y
;
1567 static int drm_mode_cursor_common(struct drm_device
*dev
,
1568 struct drm_mode_cursor2
*req
,
1569 struct drm_file
*file_priv
)
1571 struct drm_crtc
*crtc
;
1574 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1577 if (!req
->flags
|| (~DRM_MODE_CURSOR_FLAGS
& req
->flags
))
1580 crtc
= drm_crtc_find(dev
, req
->crtc_id
);
1582 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1587 * If this crtc has a universal cursor plane, call that plane's update
1588 * handler rather than using legacy cursor handlers.
1590 drm_modeset_lock_crtc(crtc
, crtc
->cursor
);
1592 ret
= drm_mode_cursor_universal(crtc
, req
, file_priv
);
1596 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1597 if (!crtc
->funcs
->cursor_set
&& !crtc
->funcs
->cursor_set2
) {
1601 /* Turns off the cursor if handle is 0 */
1602 if (crtc
->funcs
->cursor_set2
)
1603 ret
= crtc
->funcs
->cursor_set2(crtc
, file_priv
, req
->handle
,
1604 req
->width
, req
->height
, req
->hot_x
, req
->hot_y
);
1606 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1607 req
->width
, req
->height
);
1610 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1611 if (crtc
->funcs
->cursor_move
) {
1612 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1619 drm_modeset_unlock_crtc(crtc
);
1627 * drm_mode_cursor_ioctl - set CRTC's cursor configuration
1628 * @dev: drm device for the ioctl
1629 * @data: data pointer for the ioctl
1630 * @file_priv: drm file for the ioctl call
1632 * Set the cursor configuration based on user request.
1634 * Called by the user via ioctl.
1637 * Zero on success, negative errno on failure.
1639 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1640 void *data
, struct drm_file
*file_priv
)
1642 struct drm_mode_cursor
*req
= data
;
1643 struct drm_mode_cursor2 new_req
;
1645 memcpy(&new_req
, req
, sizeof(struct drm_mode_cursor
));
1646 new_req
.hot_x
= new_req
.hot_y
= 0;
1648 return drm_mode_cursor_common(dev
, &new_req
, file_priv
);
1652 * drm_mode_cursor2_ioctl - set CRTC's cursor configuration
1653 * @dev: drm device for the ioctl
1654 * @data: data pointer for the ioctl
1655 * @file_priv: drm file for the ioctl call
1657 * Set the cursor configuration based on user request. This implements the 2nd
1658 * version of the cursor ioctl, which allows userspace to additionally specify
1659 * the hotspot of the pointer.
1661 * Called by the user via ioctl.
1664 * Zero on success, negative errno on failure.
1666 int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
1667 void *data
, struct drm_file
*file_priv
)
1669 struct drm_mode_cursor2
*req
= data
;
1671 return drm_mode_cursor_common(dev
, req
, file_priv
);
1674 int drm_mode_crtc_set_obj_prop(struct drm_mode_object
*obj
,
1675 struct drm_property
*property
,
1679 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
1681 if (crtc
->funcs
->set_property
)
1682 ret
= crtc
->funcs
->set_property(crtc
, property
, value
);
1684 drm_object_property_set_value(obj
, property
, value
);
1690 * drm_mode_plane_set_obj_prop - set the value of a property
1691 * @plane: drm plane object to set property value for
1692 * @property: property to set
1693 * @value: value the property should be set to
1695 * This functions sets a given property on a given plane object. This function
1696 * calls the driver's ->set_property callback and changes the software state of
1697 * the property if the callback succeeds.
1700 * Zero on success, error code on failure.
1702 int drm_mode_plane_set_obj_prop(struct drm_plane
*plane
,
1703 struct drm_property
*property
,
1707 struct drm_mode_object
*obj
= &plane
->base
;
1709 if (plane
->funcs
->set_property
)
1710 ret
= plane
->funcs
->set_property(plane
, property
, value
);
1712 drm_object_property_set_value(obj
, property
, value
);
1716 EXPORT_SYMBOL(drm_mode_plane_set_obj_prop
);
1719 * drm_mode_crtc_set_gamma_size - set the gamma table size
1720 * @crtc: CRTC to set the gamma table size for
1721 * @gamma_size: size of the gamma table
1723 * Drivers which support gamma tables should set this to the supported gamma
1724 * table size when initializing the CRTC. Currently the drm core only supports a
1725 * fixed gamma table size.
1728 * Zero on success, negative errno on failure.
1730 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
1733 uint16_t *r_base
, *g_base
, *b_base
;
1736 crtc
->gamma_size
= gamma_size
;
1738 crtc
->gamma_store
= kcalloc(gamma_size
, sizeof(uint16_t) * 3,
1740 if (!crtc
->gamma_store
) {
1741 crtc
->gamma_size
= 0;
1745 r_base
= crtc
->gamma_store
;
1746 g_base
= r_base
+ gamma_size
;
1747 b_base
= g_base
+ gamma_size
;
1748 for (i
= 0; i
< gamma_size
; i
++) {
1757 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
1760 * drm_mode_gamma_set_ioctl - set the gamma table
1763 * @file_priv: DRM file info
1765 * Set the gamma table of a CRTC to the one passed in by the user. Userspace can
1766 * inquire the required gamma table size through drm_mode_gamma_get_ioctl.
1768 * Called by the user via ioctl.
1771 * Zero on success, negative errno on failure.
1773 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
1774 void *data
, struct drm_file
*file_priv
)
1776 struct drm_mode_crtc_lut
*crtc_lut
= data
;
1777 struct drm_crtc
*crtc
;
1778 void *r_base
, *g_base
, *b_base
;
1782 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1785 drm_modeset_lock_all(dev
);
1786 crtc
= drm_crtc_find(dev
, crtc_lut
->crtc_id
);
1792 if (crtc
->funcs
->gamma_set
== NULL
) {
1797 /* memcpy into gamma store */
1798 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
1803 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
1804 r_base
= crtc
->gamma_store
;
1805 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
1810 g_base
= r_base
+ size
;
1811 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
1816 b_base
= g_base
+ size
;
1817 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
1822 ret
= crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, crtc
->gamma_size
);
1825 drm_modeset_unlock_all(dev
);
1831 * drm_mode_gamma_get_ioctl - get the gamma table
1834 * @file_priv: DRM file info
1836 * Copy the current gamma table into the storage provided. This also provides
1837 * the gamma table size the driver expects, which can be used to size the
1838 * allocated storage.
1840 * Called by the user via ioctl.
1843 * Zero on success, negative errno on failure.
1845 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
1846 void *data
, struct drm_file
*file_priv
)
1848 struct drm_mode_crtc_lut
*crtc_lut
= data
;
1849 struct drm_crtc
*crtc
;
1850 void *r_base
, *g_base
, *b_base
;
1854 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1857 drm_modeset_lock_all(dev
);
1858 crtc
= drm_crtc_find(dev
, crtc_lut
->crtc_id
);
1864 /* memcpy into gamma store */
1865 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
1870 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
1871 r_base
= crtc
->gamma_store
;
1872 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
1877 g_base
= r_base
+ size
;
1878 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
1883 b_base
= g_base
+ size
;
1884 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
1889 drm_modeset_unlock_all(dev
);
1894 * drm_mode_page_flip_ioctl - schedule an asynchronous fb update
1897 * @file_priv: DRM file info
1899 * This schedules an asynchronous update on a given CRTC, called page flip.
1900 * Optionally a drm event is generated to signal the completion of the event.
1901 * Generic drivers cannot assume that a pageflip with changed framebuffer
1902 * properties (including driver specific metadata like tiling layout) will work,
1903 * but some drivers support e.g. pixel format changes through the pageflip
1906 * Called by the user via ioctl.
1909 * Zero on success, negative errno on failure.
1911 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
1912 void *data
, struct drm_file
*file_priv
)
1914 struct drm_mode_crtc_page_flip_target
*page_flip
= data
;
1915 struct drm_crtc
*crtc
;
1916 struct drm_framebuffer
*fb
= NULL
;
1917 struct drm_pending_vblank_event
*e
= NULL
;
1918 u32 target_vblank
= page_flip
->sequence
;
1921 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1924 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
)
1927 if (page_flip
->sequence
!= 0 && !(page_flip
->flags
& DRM_MODE_PAGE_FLIP_TARGET
))
1930 /* Only one of the DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE/RELATIVE flags
1933 if ((page_flip
->flags
& DRM_MODE_PAGE_FLIP_TARGET
) == DRM_MODE_PAGE_FLIP_TARGET
)
1936 if ((page_flip
->flags
& DRM_MODE_PAGE_FLIP_ASYNC
) && !dev
->mode_config
.async_page_flip
)
1939 crtc
= drm_crtc_find(dev
, page_flip
->crtc_id
);
1943 if (crtc
->funcs
->page_flip_target
) {
1947 r
= drm_crtc_vblank_get(crtc
);
1951 current_vblank
= drm_crtc_vblank_count(crtc
);
1953 switch (page_flip
->flags
& DRM_MODE_PAGE_FLIP_TARGET
) {
1954 case DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE
:
1955 if ((int)(target_vblank
- current_vblank
) > 1) {
1956 DRM_DEBUG("Invalid absolute flip target %u, "
1957 "must be <= %u\n", target_vblank
,
1958 current_vblank
+ 1);
1959 drm_crtc_vblank_put(crtc
);
1963 case DRM_MODE_PAGE_FLIP_TARGET_RELATIVE
:
1964 if (target_vblank
!= 0 && target_vblank
!= 1) {
1965 DRM_DEBUG("Invalid relative flip target %u, "
1966 "must be 0 or 1\n", target_vblank
);
1967 drm_crtc_vblank_put(crtc
);
1970 target_vblank
+= current_vblank
;
1973 target_vblank
= current_vblank
+
1974 !(page_flip
->flags
& DRM_MODE_PAGE_FLIP_ASYNC
);
1977 } else if (crtc
->funcs
->page_flip
== NULL
||
1978 (page_flip
->flags
& DRM_MODE_PAGE_FLIP_TARGET
)) {
1982 drm_modeset_lock_crtc(crtc
, crtc
->primary
);
1983 if (crtc
->primary
->fb
== NULL
) {
1984 /* The framebuffer is currently unbound, presumably
1985 * due to a hotplug event, that userspace has not
1992 fb
= drm_framebuffer_lookup(dev
, page_flip
->fb_id
);
1999 const struct drm_plane_state
*state
= crtc
->primary
->state
;
2001 ret
= check_src_coords(state
->src_x
, state
->src_y
,
2002 state
->src_w
, state
->src_h
, fb
);
2004 ret
= drm_crtc_check_viewport(crtc
, crtc
->x
, crtc
->y
, &crtc
->mode
, fb
);
2009 if (crtc
->primary
->fb
->pixel_format
!= fb
->pixel_format
) {
2010 DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
2015 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
2016 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
2021 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
2022 e
->event
.base
.length
= sizeof(e
->event
);
2023 e
->event
.user_data
= page_flip
->user_data
;
2024 ret
= drm_event_reserve_init(dev
, file_priv
, &e
->base
, &e
->event
.base
);
2031 crtc
->primary
->old_fb
= crtc
->primary
->fb
;
2032 if (crtc
->funcs
->page_flip_target
)
2033 ret
= crtc
->funcs
->page_flip_target(crtc
, fb
, e
,
2037 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
, page_flip
->flags
);
2039 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
)
2040 drm_event_cancel_free(dev
, &e
->base
);
2041 /* Keep the old fb, don't unref it. */
2042 crtc
->primary
->old_fb
= NULL
;
2044 crtc
->primary
->fb
= fb
;
2045 /* Unref only the old framebuffer. */
2050 if (ret
&& crtc
->funcs
->page_flip_target
)
2051 drm_crtc_vblank_put(crtc
);
2053 drm_framebuffer_unreference(fb
);
2054 if (crtc
->primary
->old_fb
)
2055 drm_framebuffer_unreference(crtc
->primary
->old_fb
);
2056 crtc
->primary
->old_fb
= NULL
;
2057 drm_modeset_unlock_crtc(crtc
);
2063 * drm_mode_config_reset - call ->reset callbacks
2066 * This functions calls all the crtc's, encoder's and connector's ->reset
2067 * callback. Drivers can use this in e.g. their driver load or resume code to
2068 * reset hardware and software state.
2070 void drm_mode_config_reset(struct drm_device
*dev
)
2072 struct drm_crtc
*crtc
;
2073 struct drm_plane
*plane
;
2074 struct drm_encoder
*encoder
;
2075 struct drm_connector
*connector
;
2077 drm_for_each_plane(plane
, dev
)
2078 if (plane
->funcs
->reset
)
2079 plane
->funcs
->reset(plane
);
2081 drm_for_each_crtc(crtc
, dev
)
2082 if (crtc
->funcs
->reset
)
2083 crtc
->funcs
->reset(crtc
);
2085 drm_for_each_encoder(encoder
, dev
)
2086 if (encoder
->funcs
->reset
)
2087 encoder
->funcs
->reset(encoder
);
2089 mutex_lock(&dev
->mode_config
.mutex
);
2090 drm_for_each_connector(connector
, dev
)
2091 if (connector
->funcs
->reset
)
2092 connector
->funcs
->reset(connector
);
2093 mutex_unlock(&dev
->mode_config
.mutex
);
2095 EXPORT_SYMBOL(drm_mode_config_reset
);
2098 * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer
2101 * @file_priv: DRM file info
2103 * This creates a new dumb buffer in the driver's backing storage manager (GEM,
2104 * TTM or something else entirely) and returns the resulting buffer handle. This
2105 * handle can then be wrapped up into a framebuffer modeset object.
2107 * Note that userspace is not allowed to use such objects for render
2108 * acceleration - drivers must create their own private ioctls for such a use
2111 * Called by the user via ioctl.
2114 * Zero on success, negative errno on failure.
2116 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
2117 void *data
, struct drm_file
*file_priv
)
2119 struct drm_mode_create_dumb
*args
= data
;
2120 u32 cpp
, stride
, size
;
2122 if (!dev
->driver
->dumb_create
)
2124 if (!args
->width
|| !args
->height
|| !args
->bpp
)
2127 /* overflow checks for 32bit size calculations */
2128 /* NOTE: DIV_ROUND_UP() can overflow */
2129 cpp
= DIV_ROUND_UP(args
->bpp
, 8);
2130 if (!cpp
|| cpp
> 0xffffffffU
/ args
->width
)
2132 stride
= cpp
* args
->width
;
2133 if (args
->height
> 0xffffffffU
/ stride
)
2136 /* test for wrap-around */
2137 size
= args
->height
* stride
;
2138 if (PAGE_ALIGN(size
) == 0)
2142 * handle, pitch and size are output parameters. Zero them out to
2143 * prevent drivers from accidentally using uninitialized data. Since
2144 * not all existing userspace is clearing these fields properly we
2145 * cannot reject IOCTL with garbage in them.
2151 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
2155 * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer
2158 * @file_priv: DRM file info
2160 * Allocate an offset in the drm device node's address space to be able to
2161 * memory map a dumb buffer.
2163 * Called by the user via ioctl.
2166 * Zero on success, negative errno on failure.
2168 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
2169 void *data
, struct drm_file
*file_priv
)
2171 struct drm_mode_map_dumb
*args
= data
;
2173 /* call driver ioctl to get mmap offset */
2174 if (!dev
->driver
->dumb_map_offset
)
2177 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
2181 * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer
2184 * @file_priv: DRM file info
2186 * This destroys the userspace handle for the given dumb backing storage buffer.
2187 * Since buffer objects must be reference counted in the kernel a buffer object
2188 * won't be immediately freed if a framebuffer modeset object still uses it.
2190 * Called by the user via ioctl.
2193 * Zero on success, negative errno on failure.
2195 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
2196 void *data
, struct drm_file
*file_priv
)
2198 struct drm_mode_destroy_dumb
*args
= data
;
2200 if (!dev
->driver
->dumb_destroy
)
2203 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
2207 * drm_rotation_simplify() - Try to simplify the rotation
2208 * @rotation: Rotation to be simplified
2209 * @supported_rotations: Supported rotations
2211 * Attempt to simplify the rotation to a form that is supported.
2212 * Eg. if the hardware supports everything except DRM_REFLECT_X
2213 * one could call this function like this:
2215 * drm_rotation_simplify(rotation, DRM_ROTATE_0 |
2216 * DRM_ROTATE_90 | DRM_ROTATE_180 |
2217 * DRM_ROTATE_270 | DRM_REFLECT_Y);
2219 * to eliminate the DRM_ROTATE_X flag. Depending on what kind of
2220 * transforms the hardware supports, this function may not
2221 * be able to produce a supported transform, so the caller should
2222 * check the result afterwards.
2224 unsigned int drm_rotation_simplify(unsigned int rotation
,
2225 unsigned int supported_rotations
)
2227 if (rotation
& ~supported_rotations
) {
2228 rotation
^= DRM_REFLECT_X
| DRM_REFLECT_Y
;
2229 rotation
= (rotation
& DRM_REFLECT_MASK
) |
2230 BIT((ffs(rotation
& DRM_ROTATE_MASK
) + 1) % 4);
2235 EXPORT_SYMBOL(drm_rotation_simplify
);
2238 * drm_mode_config_init - initialize DRM mode_configuration structure
2241 * Initialize @dev's mode_config structure, used for tracking the graphics
2242 * configuration of @dev.
2244 * Since this initializes the modeset locks, no locking is possible. Which is no
2245 * problem, since this should happen single threaded at init time. It is the
2246 * driver's problem to ensure this guarantee.
2249 void drm_mode_config_init(struct drm_device
*dev
)
2251 mutex_init(&dev
->mode_config
.mutex
);
2252 drm_modeset_lock_init(&dev
->mode_config
.connection_mutex
);
2253 mutex_init(&dev
->mode_config
.idr_mutex
);
2254 mutex_init(&dev
->mode_config
.fb_lock
);
2255 mutex_init(&dev
->mode_config
.blob_lock
);
2256 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
2257 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
2258 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
2259 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
2260 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
2261 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
2262 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
2263 idr_init(&dev
->mode_config
.crtc_idr
);
2264 idr_init(&dev
->mode_config
.tile_idr
);
2265 ida_init(&dev
->mode_config
.connector_ida
);
2267 drm_modeset_lock_all(dev
);
2268 drm_mode_create_standard_properties(dev
);
2269 drm_modeset_unlock_all(dev
);
2271 /* Just to be sure */
2272 dev
->mode_config
.num_fb
= 0;
2273 dev
->mode_config
.num_connector
= 0;
2274 dev
->mode_config
.num_crtc
= 0;
2275 dev
->mode_config
.num_encoder
= 0;
2276 dev
->mode_config
.num_overlay_plane
= 0;
2277 dev
->mode_config
.num_total_plane
= 0;
2279 EXPORT_SYMBOL(drm_mode_config_init
);
2282 * drm_mode_config_cleanup - free up DRM mode_config info
2285 * Free up all the connectors and CRTCs associated with this DRM device, then
2286 * free up the framebuffers and associated buffer objects.
2288 * Note that since this /should/ happen single-threaded at driver/device
2289 * teardown time, no locking is required. It's the driver's job to ensure that
2290 * this guarantee actually holds true.
2292 * FIXME: cleanup any dangling user buffer objects too
2294 void drm_mode_config_cleanup(struct drm_device
*dev
)
2296 struct drm_connector
*connector
, *ot
;
2297 struct drm_crtc
*crtc
, *ct
;
2298 struct drm_encoder
*encoder
, *enct
;
2299 struct drm_framebuffer
*fb
, *fbt
;
2300 struct drm_property
*property
, *pt
;
2301 struct drm_property_blob
*blob
, *bt
;
2302 struct drm_plane
*plane
, *plt
;
2304 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
2306 encoder
->funcs
->destroy(encoder
);
2309 list_for_each_entry_safe(connector
, ot
,
2310 &dev
->mode_config
.connector_list
, head
) {
2311 connector
->funcs
->destroy(connector
);
2314 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
2316 drm_property_destroy(dev
, property
);
2319 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
2321 plane
->funcs
->destroy(plane
);
2324 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
2325 crtc
->funcs
->destroy(crtc
);
2328 list_for_each_entry_safe(blob
, bt
, &dev
->mode_config
.property_blob_list
,
2330 drm_property_unreference_blob(blob
);
2334 * Single-threaded teardown context, so it's not required to grab the
2335 * fb_lock to protect against concurrent fb_list access. Contrary, it
2336 * would actually deadlock with the drm_framebuffer_cleanup function.
2338 * Also, if there are any framebuffers left, that's a driver leak now,
2339 * so politely WARN about this.
2341 WARN_ON(!list_empty(&dev
->mode_config
.fb_list
));
2342 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
2343 drm_framebuffer_free(&fb
->base
.refcount
);
2346 ida_destroy(&dev
->mode_config
.connector_ida
);
2347 idr_destroy(&dev
->mode_config
.tile_idr
);
2348 idr_destroy(&dev
->mode_config
.crtc_idr
);
2349 drm_modeset_lock_fini(&dev
->mode_config
.connection_mutex
);
2351 EXPORT_SYMBOL(drm_mode_config_cleanup
);
2353 struct drm_property
*drm_mode_create_rotation_property(struct drm_device
*dev
,
2354 unsigned int supported_rotations
)
2356 static const struct drm_prop_enum_list props
[] = {
2357 { __builtin_ffs(DRM_ROTATE_0
) - 1, "rotate-0" },
2358 { __builtin_ffs(DRM_ROTATE_90
) - 1, "rotate-90" },
2359 { __builtin_ffs(DRM_ROTATE_180
) - 1, "rotate-180" },
2360 { __builtin_ffs(DRM_ROTATE_270
) - 1, "rotate-270" },
2361 { __builtin_ffs(DRM_REFLECT_X
) - 1, "reflect-x" },
2362 { __builtin_ffs(DRM_REFLECT_Y
) - 1, "reflect-y" },
2365 return drm_property_create_bitmask(dev
, 0, "rotation",
2366 props
, ARRAY_SIZE(props
),
2367 supported_rotations
);
2369 EXPORT_SYMBOL(drm_mode_create_rotation_property
);
2374 * Tile groups are used to represent tiled monitors with a unique
2375 * integer identifier. Tiled monitors using DisplayID v1.3 have
2376 * a unique 8-byte handle, we store this in a tile group, so we
2377 * have a common identifier for all tiles in a monitor group.
2379 static void drm_tile_group_free(struct kref
*kref
)
2381 struct drm_tile_group
*tg
= container_of(kref
, struct drm_tile_group
, refcount
);
2382 struct drm_device
*dev
= tg
->dev
;
2383 mutex_lock(&dev
->mode_config
.idr_mutex
);
2384 idr_remove(&dev
->mode_config
.tile_idr
, tg
->id
);
2385 mutex_unlock(&dev
->mode_config
.idr_mutex
);
2390 * drm_mode_put_tile_group - drop a reference to a tile group.
2392 * @tg: tile group to drop reference to.
2394 * drop reference to tile group and free if 0.
2396 void drm_mode_put_tile_group(struct drm_device
*dev
,
2397 struct drm_tile_group
*tg
)
2399 kref_put(&tg
->refcount
, drm_tile_group_free
);
2403 * drm_mode_get_tile_group - get a reference to an existing tile group
2405 * @topology: 8-bytes unique per monitor.
2407 * Use the unique bytes to get a reference to an existing tile group.
2410 * tile group or NULL if not found.
2412 struct drm_tile_group
*drm_mode_get_tile_group(struct drm_device
*dev
,
2415 struct drm_tile_group
*tg
;
2417 mutex_lock(&dev
->mode_config
.idr_mutex
);
2418 idr_for_each_entry(&dev
->mode_config
.tile_idr
, tg
, id
) {
2419 if (!memcmp(tg
->group_data
, topology
, 8)) {
2420 if (!kref_get_unless_zero(&tg
->refcount
))
2422 mutex_unlock(&dev
->mode_config
.idr_mutex
);
2426 mutex_unlock(&dev
->mode_config
.idr_mutex
);
2429 EXPORT_SYMBOL(drm_mode_get_tile_group
);
2432 * drm_mode_create_tile_group - create a tile group from a displayid description
2434 * @topology: 8-bytes unique per monitor.
2436 * Create a tile group for the unique monitor, and get a unique
2437 * identifier for the tile group.
2440 * new tile group or error.
2442 struct drm_tile_group
*drm_mode_create_tile_group(struct drm_device
*dev
,
2445 struct drm_tile_group
*tg
;
2448 tg
= kzalloc(sizeof(*tg
), GFP_KERNEL
);
2450 return ERR_PTR(-ENOMEM
);
2452 kref_init(&tg
->refcount
);
2453 memcpy(tg
->group_data
, topology
, 8);
2456 mutex_lock(&dev
->mode_config
.idr_mutex
);
2457 ret
= idr_alloc(&dev
->mode_config
.tile_idr
, tg
, 1, 0, GFP_KERNEL
);
2465 mutex_unlock(&dev
->mode_config
.idr_mutex
);
2468 EXPORT_SYMBOL(drm_mode_create_tile_group
);
2471 * drm_crtc_enable_color_mgmt - enable color management properties
2473 * @degamma_lut_size: the size of the degamma lut (before CSC)
2474 * @has_ctm: whether to attach ctm_property for CSC matrix
2475 * @gamma_lut_size: the size of the gamma lut (after CSC)
2477 * This function lets the driver enable the color correction
2478 * properties on a CRTC. This includes 3 degamma, csc and gamma
2479 * properties that userspace can set and 2 size properties to inform
2480 * the userspace of the lut sizes. Each of the properties are
2481 * optional. The gamma and degamma properties are only attached if
2482 * their size is not 0 and ctm_property is only attached if has_ctm is
2485 void drm_crtc_enable_color_mgmt(struct drm_crtc
*crtc
,
2486 uint degamma_lut_size
,
2488 uint gamma_lut_size
)
2490 struct drm_device
*dev
= crtc
->dev
;
2491 struct drm_mode_config
*config
= &dev
->mode_config
;
2493 if (degamma_lut_size
) {
2494 drm_object_attach_property(&crtc
->base
,
2495 config
->degamma_lut_property
, 0);
2496 drm_object_attach_property(&crtc
->base
,
2497 config
->degamma_lut_size_property
,
2502 drm_object_attach_property(&crtc
->base
,
2503 config
->ctm_property
, 0);
2505 if (gamma_lut_size
) {
2506 drm_object_attach_property(&crtc
->base
,
2507 config
->gamma_lut_property
, 0);
2508 drm_object_attach_property(&crtc
->base
,
2509 config
->gamma_lut_size_property
,
2513 EXPORT_SYMBOL(drm_crtc_enable_color_mgmt
);