1f453ba04SDave Airlie /* 2f453ba04SDave Airlie * Copyright (c) 2006-2008 Intel Corporation 3f453ba04SDave Airlie * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 4f453ba04SDave Airlie * Copyright (c) 2008 Red Hat Inc. 5f453ba04SDave Airlie * 6f453ba04SDave Airlie * DRM core CRTC related functions 7f453ba04SDave Airlie * 8f453ba04SDave Airlie * Permission to use, copy, modify, distribute, and sell this software and its 9f453ba04SDave Airlie * documentation for any purpose is hereby granted without fee, provided that 10f453ba04SDave Airlie * the above copyright notice appear in all copies and that both that copyright 11f453ba04SDave Airlie * notice and this permission notice appear in supporting documentation, and 12f453ba04SDave Airlie * that the name of the copyright holders not be used in advertising or 13f453ba04SDave Airlie * publicity pertaining to distribution of the software without specific, 14f453ba04SDave Airlie * written prior permission. The copyright holders make no representations 15f453ba04SDave Airlie * about the suitability of this software for any purpose. It is provided "as 16f453ba04SDave Airlie * is" without express or implied warranty. 17f453ba04SDave Airlie * 18f453ba04SDave Airlie * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 19f453ba04SDave Airlie * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 20f453ba04SDave Airlie * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 21f453ba04SDave Airlie * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 22f453ba04SDave Airlie * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 23f453ba04SDave Airlie * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 24f453ba04SDave Airlie * OF THIS SOFTWARE. 25f453ba04SDave Airlie * 26f453ba04SDave Airlie * Authors: 27f453ba04SDave Airlie * Keith Packard 28f453ba04SDave Airlie * Eric Anholt <eric@anholt.net> 29f453ba04SDave Airlie * Dave Airlie <airlied@linux.ie> 30f453ba04SDave Airlie * Jesse Barnes <jesse.barnes@intel.com> 31f453ba04SDave Airlie */ 326ba6d03eSVille Syrjälä #include <linux/ctype.h> 33f453ba04SDave Airlie #include <linux/list.h> 345a0e3ad6STejun Heo #include <linux/slab.h> 352d1a8a48SPaul Gortmaker #include <linux/export.h> 366d6003c4SGustavo Padovan #include <linux/dma-fence.h> 37760285e7SDavid Howells #include <drm/drmP.h> 38760285e7SDavid Howells #include <drm/drm_crtc.h> 39760285e7SDavid Howells #include <drm/drm_edid.h> 40760285e7SDavid Howells #include <drm/drm_fourcc.h> 4151fd371bSRob Clark #include <drm/drm_modeset_lock.h> 4288a48e29SRob Clark #include <drm/drm_atomic.h> 433b96a0b1SDaniel Vetter #include <drm/drm_auth.h> 449edbf1faSTomeu Vizoso #include <drm/drm_debugfs_crc.h> 45f453ba04SDave Airlie 468bd441b2SDaniel Vetter #include "drm_crtc_internal.h" 4767d0ec4eSDaniel Vetter #include "drm_internal.h" 488bd441b2SDaniel Vetter 496a0d9528SLukas Wunner /** 50d5d487ebSDaniel Vetter * DOC: overview 51d5d487ebSDaniel Vetter * 52d5d487ebSDaniel Vetter * A CRTC represents the overall display pipeline. It receives pixel data from 53d5d487ebSDaniel Vetter * &drm_plane and blends them together. The &drm_display_mode is also attached 54d5d487ebSDaniel Vetter * to the CRTC, specifying display timings. On the output side the data is fed 55d5d487ebSDaniel Vetter * to one or more &drm_encoder, which are then each connected to one 56d5d487ebSDaniel Vetter * &drm_connector. 57d5d487ebSDaniel Vetter * 58d5d487ebSDaniel Vetter * To create a CRTC, a KMS drivers allocates and zeroes an instances of 59d5d487ebSDaniel Vetter * &struct drm_crtc (possibly as part of a larger structure) and registers it 60d5d487ebSDaniel Vetter * with a call to drm_crtc_init_with_planes(). 61d5d487ebSDaniel Vetter * 62d5d487ebSDaniel Vetter * The CRTC is also the entry point for legacy modeset operations, see 63d5d487ebSDaniel Vetter * &drm_crtc_funcs.set_config, legacy plane operations, see 64d5d487ebSDaniel Vetter * &drm_crtc_funcs.page_flip and &drm_crtc_funcs.cursor_set2, and other legacy 65d5d487ebSDaniel Vetter * operations like &drm_crtc_funcs.gamma_set. For atomic drivers all these 66d5d487ebSDaniel Vetter * features are controlled through &drm_property and 67d5d487ebSDaniel Vetter * &drm_mode_config_funcs.atomic_check and &drm_mode_config_funcs.atomic_check. 68d5d487ebSDaniel Vetter */ 69d5d487ebSDaniel Vetter 70d5d487ebSDaniel Vetter /** 716d1b81d8SShawn Guo * drm_crtc_from_index - find the registered CRTC at an index 726d1b81d8SShawn Guo * @dev: DRM device 736d1b81d8SShawn Guo * @idx: index of registered CRTC to find for 746d1b81d8SShawn Guo * 756d1b81d8SShawn Guo * Given a CRTC index, return the registered CRTC from DRM device's 76931c670dSShawn Guo * list of CRTCs with matching index. This is the inverse of drm_crtc_index(). 77931c670dSShawn Guo * It's useful in the vblank callbacks (like &drm_driver.enable_vblank or 78931c670dSShawn Guo * &drm_driver.disable_vblank), since that still deals with indices instead 79931c670dSShawn Guo * of pointers to &struct drm_crtc." 806d1b81d8SShawn Guo */ 816d1b81d8SShawn Guo struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx) 826d1b81d8SShawn Guo { 836d1b81d8SShawn Guo struct drm_crtc *crtc; 846d1b81d8SShawn Guo 856d1b81d8SShawn Guo drm_for_each_crtc(crtc, dev) 866d1b81d8SShawn Guo if (idx == crtc->index) 876d1b81d8SShawn Guo return crtc; 886d1b81d8SShawn Guo 896d1b81d8SShawn Guo return NULL; 906d1b81d8SShawn Guo } 916d1b81d8SShawn Guo EXPORT_SYMBOL(drm_crtc_from_index); 926d1b81d8SShawn Guo 936d1b81d8SShawn Guo /** 946a0d9528SLukas Wunner * drm_crtc_force_disable - Forcibly turn off a CRTC 956a0d9528SLukas Wunner * @crtc: CRTC to turn off 966a0d9528SLukas Wunner * 9718dddadcSDaniel Vetter * Note: This should only be used by non-atomic legacy drivers. 9818dddadcSDaniel Vetter * 996a0d9528SLukas Wunner * Returns: 1006a0d9528SLukas Wunner * Zero on success, error code on failure. 1016a0d9528SLukas Wunner */ 1026a0d9528SLukas Wunner int drm_crtc_force_disable(struct drm_crtc *crtc) 1036a0d9528SLukas Wunner { 1046a0d9528SLukas Wunner struct drm_mode_set set = { 1056a0d9528SLukas Wunner .crtc = crtc, 1066a0d9528SLukas Wunner }; 1076a0d9528SLukas Wunner 10818dddadcSDaniel Vetter WARN_ON(drm_drv_uses_atomic_modeset(crtc->dev)); 10918dddadcSDaniel Vetter 1106a0d9528SLukas Wunner return drm_mode_set_config_internal(&set); 1116a0d9528SLukas Wunner } 1126a0d9528SLukas Wunner EXPORT_SYMBOL(drm_crtc_force_disable); 1136a0d9528SLukas Wunner 1146a0d9528SLukas Wunner /** 1156a0d9528SLukas Wunner * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs 1166a0d9528SLukas Wunner * @dev: DRM device whose CRTCs to turn off 1176a0d9528SLukas Wunner * 1186a0d9528SLukas Wunner * Drivers may want to call this on unload to ensure that all displays are 1196a0d9528SLukas Wunner * unlit and the GPU is in a consistent, low power state. Takes modeset locks. 1206a0d9528SLukas Wunner * 12118dddadcSDaniel Vetter * Note: This should only be used by non-atomic legacy drivers. For an atomic 12218dddadcSDaniel Vetter * version look at drm_atomic_helper_shutdown(). 12318dddadcSDaniel Vetter * 1246a0d9528SLukas Wunner * Returns: 1256a0d9528SLukas Wunner * Zero on success, error code on failure. 1266a0d9528SLukas Wunner */ 1276a0d9528SLukas Wunner int drm_crtc_force_disable_all(struct drm_device *dev) 1286a0d9528SLukas Wunner { 1296a0d9528SLukas Wunner struct drm_crtc *crtc; 1306a0d9528SLukas Wunner int ret = 0; 1316a0d9528SLukas Wunner 1326a0d9528SLukas Wunner drm_modeset_lock_all(dev); 1336a0d9528SLukas Wunner drm_for_each_crtc(crtc, dev) 1346a0d9528SLukas Wunner if (crtc->enabled) { 1356a0d9528SLukas Wunner ret = drm_crtc_force_disable(crtc); 1366a0d9528SLukas Wunner if (ret) 1376a0d9528SLukas Wunner goto out; 1386a0d9528SLukas Wunner } 1396a0d9528SLukas Wunner out: 1406a0d9528SLukas Wunner drm_modeset_unlock_all(dev); 1416a0d9528SLukas Wunner return ret; 1426a0d9528SLukas Wunner } 1436a0d9528SLukas Wunner EXPORT_SYMBOL(drm_crtc_force_disable_all); 1446a0d9528SLukas Wunner 145fa3ab4c2SVille Syrjälä static unsigned int drm_num_crtcs(struct drm_device *dev) 146fa3ab4c2SVille Syrjälä { 147fa3ab4c2SVille Syrjälä unsigned int num = 0; 148fa3ab4c2SVille Syrjälä struct drm_crtc *tmp; 149fa3ab4c2SVille Syrjälä 150fa3ab4c2SVille Syrjälä drm_for_each_crtc(tmp, dev) { 151fa3ab4c2SVille Syrjälä num++; 152fa3ab4c2SVille Syrjälä } 153fa3ab4c2SVille Syrjälä 154fa3ab4c2SVille Syrjälä return num; 155fa3ab4c2SVille Syrjälä } 156fa3ab4c2SVille Syrjälä 15728575f16SDaniel Vetter int drm_crtc_register_all(struct drm_device *dev) 15879190ea2SBenjamin Gaignard { 15979190ea2SBenjamin Gaignard struct drm_crtc *crtc; 16079190ea2SBenjamin Gaignard int ret = 0; 16179190ea2SBenjamin Gaignard 16279190ea2SBenjamin Gaignard drm_for_each_crtc(crtc, dev) { 1639edbf1faSTomeu Vizoso if (drm_debugfs_crtc_add(crtc)) 1649edbf1faSTomeu Vizoso DRM_ERROR("Failed to initialize debugfs entry for CRTC '%s'.\n", 1659edbf1faSTomeu Vizoso crtc->name); 1669edbf1faSTomeu Vizoso 16779190ea2SBenjamin Gaignard if (crtc->funcs->late_register) 16879190ea2SBenjamin Gaignard ret = crtc->funcs->late_register(crtc); 16979190ea2SBenjamin Gaignard if (ret) 17079190ea2SBenjamin Gaignard return ret; 17179190ea2SBenjamin Gaignard } 17279190ea2SBenjamin Gaignard 17379190ea2SBenjamin Gaignard return 0; 17479190ea2SBenjamin Gaignard } 17579190ea2SBenjamin Gaignard 17628575f16SDaniel Vetter void drm_crtc_unregister_all(struct drm_device *dev) 17779190ea2SBenjamin Gaignard { 17879190ea2SBenjamin Gaignard struct drm_crtc *crtc; 17979190ea2SBenjamin Gaignard 18079190ea2SBenjamin Gaignard drm_for_each_crtc(crtc, dev) { 18179190ea2SBenjamin Gaignard if (crtc->funcs->early_unregister) 18279190ea2SBenjamin Gaignard crtc->funcs->early_unregister(crtc); 1839edbf1faSTomeu Vizoso drm_debugfs_crtc_remove(crtc); 18479190ea2SBenjamin Gaignard } 18579190ea2SBenjamin Gaignard } 18679190ea2SBenjamin Gaignard 1879edbf1faSTomeu Vizoso static int drm_crtc_crc_init(struct drm_crtc *crtc) 1889edbf1faSTomeu Vizoso { 1899edbf1faSTomeu Vizoso #ifdef CONFIG_DEBUG_FS 1909edbf1faSTomeu Vizoso spin_lock_init(&crtc->crc.lock); 1919edbf1faSTomeu Vizoso init_waitqueue_head(&crtc->crc.wq); 1929edbf1faSTomeu Vizoso crtc->crc.source = kstrdup("auto", GFP_KERNEL); 1939edbf1faSTomeu Vizoso if (!crtc->crc.source) 1949edbf1faSTomeu Vizoso return -ENOMEM; 1959edbf1faSTomeu Vizoso #endif 1969edbf1faSTomeu Vizoso return 0; 1979edbf1faSTomeu Vizoso } 1989edbf1faSTomeu Vizoso 1999edbf1faSTomeu Vizoso static void drm_crtc_crc_fini(struct drm_crtc *crtc) 2009edbf1faSTomeu Vizoso { 2019edbf1faSTomeu Vizoso #ifdef CONFIG_DEBUG_FS 2029edbf1faSTomeu Vizoso kfree(crtc->crc.source); 2039edbf1faSTomeu Vizoso #endif 2049edbf1faSTomeu Vizoso } 2059edbf1faSTomeu Vizoso 20635f8cc3bSGustavo Padovan static const struct dma_fence_ops drm_crtc_fence_ops; 20735f8cc3bSGustavo Padovan 2086d6003c4SGustavo Padovan static struct drm_crtc *fence_to_crtc(struct dma_fence *fence) 2096d6003c4SGustavo Padovan { 2106d6003c4SGustavo Padovan BUG_ON(fence->ops != &drm_crtc_fence_ops); 2116d6003c4SGustavo Padovan return container_of(fence->lock, struct drm_crtc, fence_lock); 2126d6003c4SGustavo Padovan } 2136d6003c4SGustavo Padovan 2146d6003c4SGustavo Padovan static const char *drm_crtc_fence_get_driver_name(struct dma_fence *fence) 2156d6003c4SGustavo Padovan { 2166d6003c4SGustavo Padovan struct drm_crtc *crtc = fence_to_crtc(fence); 2176d6003c4SGustavo Padovan 2186d6003c4SGustavo Padovan return crtc->dev->driver->name; 2196d6003c4SGustavo Padovan } 2206d6003c4SGustavo Padovan 2216d6003c4SGustavo Padovan static const char *drm_crtc_fence_get_timeline_name(struct dma_fence *fence) 2226d6003c4SGustavo Padovan { 2236d6003c4SGustavo Padovan struct drm_crtc *crtc = fence_to_crtc(fence); 2246d6003c4SGustavo Padovan 2256d6003c4SGustavo Padovan return crtc->timeline_name; 2266d6003c4SGustavo Padovan } 2276d6003c4SGustavo Padovan 2286d6003c4SGustavo Padovan static bool drm_crtc_fence_enable_signaling(struct dma_fence *fence) 2296d6003c4SGustavo Padovan { 2306d6003c4SGustavo Padovan return true; 2316d6003c4SGustavo Padovan } 2326d6003c4SGustavo Padovan 23335f8cc3bSGustavo Padovan static const struct dma_fence_ops drm_crtc_fence_ops = { 2346d6003c4SGustavo Padovan .get_driver_name = drm_crtc_fence_get_driver_name, 2356d6003c4SGustavo Padovan .get_timeline_name = drm_crtc_fence_get_timeline_name, 2366d6003c4SGustavo Padovan .enable_signaling = drm_crtc_fence_enable_signaling, 2376d6003c4SGustavo Padovan .wait = dma_fence_default_wait, 2386d6003c4SGustavo Padovan }; 2396d6003c4SGustavo Padovan 24035f8cc3bSGustavo Padovan struct dma_fence *drm_crtc_create_fence(struct drm_crtc *crtc) 24135f8cc3bSGustavo Padovan { 24235f8cc3bSGustavo Padovan struct dma_fence *fence; 24335f8cc3bSGustavo Padovan 24435f8cc3bSGustavo Padovan fence = kzalloc(sizeof(*fence), GFP_KERNEL); 24535f8cc3bSGustavo Padovan if (!fence) 24635f8cc3bSGustavo Padovan return NULL; 24735f8cc3bSGustavo Padovan 24835f8cc3bSGustavo Padovan dma_fence_init(fence, &drm_crtc_fence_ops, &crtc->fence_lock, 24935f8cc3bSGustavo Padovan crtc->fence_context, ++crtc->fence_seqno); 25035f8cc3bSGustavo Padovan 25135f8cc3bSGustavo Padovan return fence; 25235f8cc3bSGustavo Padovan } 25335f8cc3bSGustavo Padovan 254f453ba04SDave Airlie /** 255e13161afSMatt Roper * drm_crtc_init_with_planes - Initialise a new CRTC object with 256e13161afSMatt Roper * specified primary and cursor planes. 257f453ba04SDave Airlie * @dev: DRM device 258f453ba04SDave Airlie * @crtc: CRTC object to init 259e13161afSMatt Roper * @primary: Primary plane for CRTC 260e13161afSMatt Roper * @cursor: Cursor plane for CRTC 261f453ba04SDave Airlie * @funcs: callbacks for the new CRTC 262f9882876SVille Syrjälä * @name: printf style format string for the CRTC name, or NULL for default name 263f453ba04SDave Airlie * 264532b3671SDaniel Vetter * Inits a new object created as base part of a driver crtc object. Drivers 265532b3671SDaniel Vetter * should use this function instead of drm_crtc_init(), which is only provided 266532b3671SDaniel Vetter * for backwards compatibility with drivers which do not yet support universal 267532b3671SDaniel Vetter * planes). For really simple hardware which has only 1 plane look at 268532b3671SDaniel Vetter * drm_simple_display_pipe_init() instead. 2696bfc56aaSVille Syrjälä * 270c8e32cc1SDaniel Vetter * Returns: 2716bfc56aaSVille Syrjälä * Zero on success, error code on failure. 272f453ba04SDave Airlie */ 273e13161afSMatt Roper int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, 274e13161afSMatt Roper struct drm_plane *primary, 275fc1d3e44SMatt Roper struct drm_plane *cursor, 276f9882876SVille Syrjälä const struct drm_crtc_funcs *funcs, 277f9882876SVille Syrjälä const char *name, ...) 278f453ba04SDave Airlie { 27951fd371bSRob Clark struct drm_mode_config *config = &dev->mode_config; 2806bfc56aaSVille Syrjälä int ret; 2816bfc56aaSVille Syrjälä 282522cf91fSBenjamin Gaignard WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY); 283522cf91fSBenjamin Gaignard WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR); 284522cf91fSBenjamin Gaignard 2852a8d3eacSVille Syrjälä /* crtc index is used with 32bit bitmasks */ 2862a8d3eacSVille Syrjälä if (WARN_ON(config->num_crtc >= 32)) 2872a8d3eacSVille Syrjälä return -EINVAL; 2882a8d3eacSVille Syrjälä 289f453ba04SDave Airlie crtc->dev = dev; 290f453ba04SDave Airlie crtc->funcs = funcs; 291f453ba04SDave Airlie 2923b24f7d6SDaniel Vetter INIT_LIST_HEAD(&crtc->commit_list); 2933b24f7d6SDaniel Vetter spin_lock_init(&crtc->commit_lock); 2943b24f7d6SDaniel Vetter 29551fd371bSRob Clark drm_modeset_lock_init(&crtc->mutex); 2962135ea7aSThierry Reding ret = drm_mode_object_add(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); 2976bfc56aaSVille Syrjälä if (ret) 298baf698b0SDaniel Vetter return ret; 299f453ba04SDave Airlie 300fa3ab4c2SVille Syrjälä if (name) { 301fa3ab4c2SVille Syrjälä va_list ap; 302fa3ab4c2SVille Syrjälä 303fa3ab4c2SVille Syrjälä va_start(ap, name); 304fa3ab4c2SVille Syrjälä crtc->name = kvasprintf(GFP_KERNEL, name, ap); 305fa3ab4c2SVille Syrjälä va_end(ap); 306fa3ab4c2SVille Syrjälä } else { 307fa3ab4c2SVille Syrjälä crtc->name = kasprintf(GFP_KERNEL, "crtc-%d", 308fa3ab4c2SVille Syrjälä drm_num_crtcs(dev)); 309fa3ab4c2SVille Syrjälä } 310fa3ab4c2SVille Syrjälä if (!crtc->name) { 3117c8f6d25SDave Airlie drm_mode_object_unregister(dev, &crtc->base); 312fa3ab4c2SVille Syrjälä return -ENOMEM; 313fa3ab4c2SVille Syrjälä } 314fa3ab4c2SVille Syrjälä 3156d6003c4SGustavo Padovan crtc->fence_context = dma_fence_context_alloc(1); 3166d6003c4SGustavo Padovan spin_lock_init(&crtc->fence_lock); 3176d6003c4SGustavo Padovan snprintf(crtc->timeline_name, sizeof(crtc->timeline_name), 3186d6003c4SGustavo Padovan "CRTC:%d-%s", crtc->base.id, crtc->name); 3196d6003c4SGustavo Padovan 320bffd9de0SPaulo Zanoni crtc->base.properties = &crtc->properties; 321bffd9de0SPaulo Zanoni 32251fd371bSRob Clark list_add_tail(&crtc->head, &config->crtc_list); 323490d3d1bSChris Wilson crtc->index = config->num_crtc++; 3246bfc56aaSVille Syrjälä 325e13161afSMatt Roper crtc->primary = primary; 326fc1d3e44SMatt Roper crtc->cursor = cursor; 3277abc7d47SRob Clark if (primary && !primary->possible_crtcs) 328e13161afSMatt Roper primary->possible_crtcs = 1 << drm_crtc_index(crtc); 3297abc7d47SRob Clark if (cursor && !cursor->possible_crtcs) 330fc1d3e44SMatt Roper cursor->possible_crtcs = 1 << drm_crtc_index(crtc); 331e13161afSMatt Roper 3329edbf1faSTomeu Vizoso ret = drm_crtc_crc_init(crtc); 3339edbf1faSTomeu Vizoso if (ret) { 3349edbf1faSTomeu Vizoso drm_mode_object_unregister(dev, &crtc->base); 3359edbf1faSTomeu Vizoso return ret; 3369edbf1faSTomeu Vizoso } 3379edbf1faSTomeu Vizoso 338eab3bbefSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 339eab3bbefSDaniel Vetter drm_object_attach_property(&crtc->base, config->prop_active, 0); 340955f3c33SDaniel Stone drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); 341beaf5af4SGustavo Padovan drm_object_attach_property(&crtc->base, 342beaf5af4SGustavo Padovan config->prop_out_fence_ptr, 0); 343eab3bbefSDaniel Vetter } 344eab3bbefSDaniel Vetter 345baf698b0SDaniel Vetter return 0; 346f453ba04SDave Airlie } 347e13161afSMatt Roper EXPORT_SYMBOL(drm_crtc_init_with_planes); 348f453ba04SDave Airlie 349f453ba04SDave Airlie /** 350ad6f5c34SVille Syrjälä * drm_crtc_cleanup - Clean up the core crtc usage 351f453ba04SDave Airlie * @crtc: CRTC to cleanup 352f453ba04SDave Airlie * 353ad6f5c34SVille Syrjälä * This function cleans up @crtc and removes it from the DRM mode setting 354ad6f5c34SVille Syrjälä * core. Note that the function does *not* free the crtc structure itself, 355ad6f5c34SVille Syrjälä * this is the responsibility of the caller. 356f453ba04SDave Airlie */ 357f453ba04SDave Airlie void drm_crtc_cleanup(struct drm_crtc *crtc) 358f453ba04SDave Airlie { 359f453ba04SDave Airlie struct drm_device *dev = crtc->dev; 360f453ba04SDave Airlie 361490d3d1bSChris Wilson /* Note that the crtc_list is considered to be static; should we 362490d3d1bSChris Wilson * remove the drm_crtc at runtime we would have to decrement all 363490d3d1bSChris Wilson * the indices on the drm_crtc after us in the crtc_list. 364490d3d1bSChris Wilson */ 365490d3d1bSChris Wilson 3669edbf1faSTomeu Vizoso drm_crtc_crc_fini(crtc); 3679edbf1faSTomeu Vizoso 368f453ba04SDave Airlie kfree(crtc->gamma_store); 369f453ba04SDave Airlie crtc->gamma_store = NULL; 370f453ba04SDave Airlie 37151fd371bSRob Clark drm_modeset_lock_fini(&crtc->mutex); 37251fd371bSRob Clark 3737c8f6d25SDave Airlie drm_mode_object_unregister(dev, &crtc->base); 374f453ba04SDave Airlie list_del(&crtc->head); 375f453ba04SDave Airlie dev->mode_config.num_crtc--; 3763009c037SThierry Reding 3773009c037SThierry Reding WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state); 3783009c037SThierry Reding if (crtc->state && crtc->funcs->atomic_destroy_state) 3793009c037SThierry Reding crtc->funcs->atomic_destroy_state(crtc, crtc->state); 380a18c0af1SThierry Reding 381fa3ab4c2SVille Syrjälä kfree(crtc->name); 382fa3ab4c2SVille Syrjälä 383a18c0af1SThierry Reding memset(crtc, 0, sizeof(*crtc)); 384f453ba04SDave Airlie } 385f453ba04SDave Airlie EXPORT_SYMBOL(drm_crtc_cleanup); 386f453ba04SDave Airlie 387f453ba04SDave Airlie /** 388f453ba04SDave Airlie * drm_mode_getcrtc - get CRTC configuration 389065a50edSDaniel Vetter * @dev: drm device for the ioctl 390065a50edSDaniel Vetter * @data: data pointer for the ioctl 391065a50edSDaniel Vetter * @file_priv: drm file for the ioctl call 392f453ba04SDave Airlie * 393f453ba04SDave Airlie * Construct a CRTC configuration structure to return to the user. 394f453ba04SDave Airlie * 395f453ba04SDave Airlie * Called by the user via ioctl. 396f453ba04SDave Airlie * 397c8e32cc1SDaniel Vetter * Returns: 3981a498633SDaniel Vetter * Zero on success, negative errno on failure. 399f453ba04SDave Airlie */ 400f453ba04SDave Airlie int drm_mode_getcrtc(struct drm_device *dev, 401f453ba04SDave Airlie void *data, struct drm_file *file_priv) 402f453ba04SDave Airlie { 403f453ba04SDave Airlie struct drm_mode_crtc *crtc_resp = data; 404f453ba04SDave Airlie struct drm_crtc *crtc; 40564c32b49SVille Syrjälä struct drm_plane *plane; 406f453ba04SDave Airlie 407fb3b06c8SDave Airlie if (!drm_core_check_feature(dev, DRIVER_MODESET)) 408fb3b06c8SDave Airlie return -EINVAL; 409fb3b06c8SDave Airlie 410418da172SKeith Packard crtc = drm_crtc_find(dev, file_priv, crtc_resp->crtc_id); 411fcf93f69SDaniel Vetter if (!crtc) 412fcf93f69SDaniel Vetter return -ENOENT; 413f453ba04SDave Airlie 41464c32b49SVille Syrjälä plane = crtc->primary; 41564c32b49SVille Syrjälä 416f453ba04SDave Airlie crtc_resp->gamma_size = crtc->gamma_size; 417de7b6be7SDaniel Stone 41864c32b49SVille Syrjälä drm_modeset_lock(&plane->mutex, NULL); 41964c32b49SVille Syrjälä if (plane->state && plane->state->fb) 42064c32b49SVille Syrjälä crtc_resp->fb_id = plane->state->fb->base.id; 42164c32b49SVille Syrjälä else if (!plane->state && plane->fb) 42264c32b49SVille Syrjälä crtc_resp->fb_id = plane->fb->base.id; 423f453ba04SDave Airlie else 424f453ba04SDave Airlie crtc_resp->fb_id = 0; 425f453ba04SDave Airlie 42664c32b49SVille Syrjälä if (plane->state) { 42764c32b49SVille Syrjälä crtc_resp->x = plane->state->src_x >> 16; 42864c32b49SVille Syrjälä crtc_resp->y = plane->state->src_y >> 16; 4292c77bb29SDaniel Vetter } 43064c32b49SVille Syrjälä drm_modeset_unlock(&plane->mutex); 4312c77bb29SDaniel Vetter 4322c77bb29SDaniel Vetter drm_modeset_lock(&crtc->mutex, NULL); 4332c77bb29SDaniel Vetter if (crtc->state) { 43431c946e8SDaniel Vetter if (crtc->state->enable) { 435934a8a89SDaniel Stone drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); 43631c946e8SDaniel Vetter crtc_resp->mode_valid = 1; 43731c946e8SDaniel Vetter } else { 43831c946e8SDaniel Vetter crtc_resp->mode_valid = 0; 43931c946e8SDaniel Vetter } 44031c946e8SDaniel Vetter } else { 44131c946e8SDaniel Vetter crtc_resp->x = crtc->x; 44231c946e8SDaniel Vetter crtc_resp->y = crtc->y; 443bf2d5eb9SVille Syrjälä 44431c946e8SDaniel Vetter if (crtc->enabled) { 445934a8a89SDaniel Stone drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); 446f453ba04SDave Airlie crtc_resp->mode_valid = 1; 447f453ba04SDave Airlie 448f453ba04SDave Airlie } else { 449f453ba04SDave Airlie crtc_resp->mode_valid = 0; 450f453ba04SDave Airlie } 45131c946e8SDaniel Vetter } 4522c77bb29SDaniel Vetter drm_modeset_unlock(&crtc->mutex); 453f453ba04SDave Airlie 454baf698b0SDaniel Vetter return 0; 455f453ba04SDave Airlie } 456f453ba04SDave Airlie 4572ceb585aSDaniel Vetter static int __drm_mode_set_config_internal(struct drm_mode_set *set, 4582ceb585aSDaniel Vetter struct drm_modeset_acquire_ctx *ctx) 4592d13b679SDaniel Vetter { 4602d13b679SDaniel Vetter struct drm_crtc *crtc = set->crtc; 4615cef29aaSDaniel Vetter struct drm_framebuffer *fb; 4625cef29aaSDaniel Vetter struct drm_crtc *tmp; 463b0d12325SDaniel Vetter int ret; 4642d13b679SDaniel Vetter 4655cef29aaSDaniel Vetter /* 4665cef29aaSDaniel Vetter * NOTE: ->set_config can also disable other crtcs (if we steal all 4675cef29aaSDaniel Vetter * connectors from it), hence we need to refcount the fbs across all 4685cef29aaSDaniel Vetter * crtcs. Atomic modeset will have saner semantics ... 4695cef29aaSDaniel Vetter */ 470e4f62546SDaniel Vetter drm_for_each_crtc(tmp, crtc->dev) 4713d30a59bSDaniel Vetter tmp->primary->old_fb = tmp->primary->fb; 4725cef29aaSDaniel Vetter 473b0d12325SDaniel Vetter fb = set->fb; 474b0d12325SDaniel Vetter 475a4eff9aaSDaniel Vetter ret = crtc->funcs->set_config(set, ctx); 476b0d12325SDaniel Vetter if (ret == 0) { 4777e7de761SVille Syrjälä crtc->primary->crtc = fb ? crtc : NULL; 4780fe27f06SDaniel Vetter crtc->primary->fb = fb; 4795cef29aaSDaniel Vetter } 480cc85e121SDaniel Vetter 481e4f62546SDaniel Vetter drm_for_each_crtc(tmp, crtc->dev) { 482f4510a27SMatt Roper if (tmp->primary->fb) 483a4a69da0SThierry Reding drm_framebuffer_get(tmp->primary->fb); 4843d30a59bSDaniel Vetter if (tmp->primary->old_fb) 485a4a69da0SThierry Reding drm_framebuffer_put(tmp->primary->old_fb); 4863d30a59bSDaniel Vetter tmp->primary->old_fb = NULL; 487b0d12325SDaniel Vetter } 488b0d12325SDaniel Vetter 489b0d12325SDaniel Vetter return ret; 4902d13b679SDaniel Vetter } 491d49473a5SDaniel Vetter /** 492d49473a5SDaniel Vetter * drm_mode_set_config_internal - helper to call &drm_mode_config_funcs.set_config 493d49473a5SDaniel Vetter * @set: modeset config to set 494d49473a5SDaniel Vetter * 495d49473a5SDaniel Vetter * This is a little helper to wrap internal calls to the 496d49473a5SDaniel Vetter * &drm_mode_config_funcs.set_config driver interface. The only thing it adds is 497d49473a5SDaniel Vetter * correct refcounting dance. 498d49473a5SDaniel Vetter * 499d49473a5SDaniel Vetter * This should only be used by non-atomic legacy drivers. 500d49473a5SDaniel Vetter * 501d49473a5SDaniel Vetter * Returns: 502d49473a5SDaniel Vetter * Zero on success, negative errno on failure. 503d49473a5SDaniel Vetter */ 504d49473a5SDaniel Vetter int drm_mode_set_config_internal(struct drm_mode_set *set) 505d49473a5SDaniel Vetter { 506d49473a5SDaniel Vetter WARN_ON(drm_drv_uses_atomic_modeset(set->crtc->dev)); 507d49473a5SDaniel Vetter 5082ceb585aSDaniel Vetter return __drm_mode_set_config_internal(set, NULL); 509d49473a5SDaniel Vetter } 5102d13b679SDaniel Vetter EXPORT_SYMBOL(drm_mode_set_config_internal); 5112d13b679SDaniel Vetter 512af93629dSMatt Roper /** 513af93629dSMatt Roper * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the 514af93629dSMatt Roper * CRTC viewport 515af93629dSMatt Roper * @crtc: CRTC that framebuffer will be displayed on 516af93629dSMatt Roper * @x: x panning 517af93629dSMatt Roper * @y: y panning 518af93629dSMatt Roper * @mode: mode that framebuffer will be displayed under 519af93629dSMatt Roper * @fb: framebuffer to check size of 520c11e9283SDamien Lespiau */ 521af93629dSMatt Roper int drm_crtc_check_viewport(const struct drm_crtc *crtc, 522c11e9283SDamien Lespiau int x, int y, 523c11e9283SDamien Lespiau const struct drm_display_mode *mode, 524c11e9283SDamien Lespiau const struct drm_framebuffer *fb) 525c11e9283SDamien Lespiau 526c11e9283SDamien Lespiau { 527c11e9283SDamien Lespiau int hdisplay, vdisplay; 528c11e9283SDamien Lespiau 529196cd5d3SDaniel Vetter drm_mode_get_hv_timing(mode, &hdisplay, &vdisplay); 530a0c1bbb0SDamien Lespiau 53133e0be63SVille Syrjälä if (crtc->state && 532bd2ef25dSVille Syrjälä drm_rotation_90_or_270(crtc->primary->state->rotation)) 533c11e9283SDamien Lespiau swap(hdisplay, vdisplay); 534c11e9283SDamien Lespiau 53543968d7bSDaniel Vetter return drm_framebuffer_check_src_coords(x << 16, y << 16, 53643968d7bSDaniel Vetter hdisplay << 16, vdisplay << 16, 53743968d7bSDaniel Vetter fb); 538c11e9283SDamien Lespiau } 539af93629dSMatt Roper EXPORT_SYMBOL(drm_crtc_check_viewport); 540c11e9283SDamien Lespiau 5412d13b679SDaniel Vetter /** 542f453ba04SDave Airlie * drm_mode_setcrtc - set CRTC configuration 543065a50edSDaniel Vetter * @dev: drm device for the ioctl 544065a50edSDaniel Vetter * @data: data pointer for the ioctl 545065a50edSDaniel Vetter * @file_priv: drm file for the ioctl call 546f453ba04SDave Airlie * 547f453ba04SDave Airlie * Build a new CRTC configuration based on user request. 548f453ba04SDave Airlie * 549f453ba04SDave Airlie * Called by the user via ioctl. 550f453ba04SDave Airlie * 551c8e32cc1SDaniel Vetter * Returns: 5521a498633SDaniel Vetter * Zero on success, negative errno on failure. 553f453ba04SDave Airlie */ 554f453ba04SDave Airlie int drm_mode_setcrtc(struct drm_device *dev, void *data, 555f453ba04SDave Airlie struct drm_file *file_priv) 556f453ba04SDave Airlie { 557f453ba04SDave Airlie struct drm_mode_config *config = &dev->mode_config; 558f453ba04SDave Airlie struct drm_mode_crtc *crtc_req = data; 5596653cc8dSVille Syrjälä struct drm_crtc *crtc; 56064c32b49SVille Syrjälä struct drm_plane *plane; 561f453ba04SDave Airlie struct drm_connector **connector_set = NULL, *connector; 562f453ba04SDave Airlie struct drm_framebuffer *fb = NULL; 563f453ba04SDave Airlie struct drm_display_mode *mode = NULL; 564f453ba04SDave Airlie struct drm_mode_set set; 565f453ba04SDave Airlie uint32_t __user *set_connectors_ptr; 5662ceb585aSDaniel Vetter struct drm_modeset_acquire_ctx ctx; 5674a1b0714SLaurent Pinchart int ret; 568f453ba04SDave Airlie int i; 569f453ba04SDave Airlie 570fb3b06c8SDave Airlie if (!drm_core_check_feature(dev, DRIVER_MODESET)) 571fb3b06c8SDave Airlie return -EINVAL; 572fb3b06c8SDave Airlie 57301447e9fSZhao Junwang /* 57401447e9fSZhao Junwang * Universal plane src offsets are only 16.16, prevent havoc for 57501447e9fSZhao Junwang * drivers using universal plane code internally. 57601447e9fSZhao Junwang */ 57701447e9fSZhao Junwang if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) 5781d97e915SVille Syrjälä return -ERANGE; 5791d97e915SVille Syrjälä 580418da172SKeith Packard crtc = drm_crtc_find(dev, file_priv, crtc_req->crtc_id); 581a2b34e22SRob Clark if (!crtc) { 58258367ed6SZhao Yakui DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); 5832ceb585aSDaniel Vetter return -ENOENT; 584f453ba04SDave Airlie } 585fa3ab4c2SVille Syrjälä DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); 586f453ba04SDave Airlie 58764c32b49SVille Syrjälä plane = crtc->primary; 58864c32b49SVille Syrjälä 58953552d5dSDaniel Vetter mutex_lock(&crtc->dev->mode_config.mutex); 5903fa6a073SMaarten Lankhorst drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE); 5912ceb585aSDaniel Vetter retry: 5922ceb585aSDaniel Vetter ret = drm_modeset_lock_all_ctx(crtc->dev, &ctx); 5932ceb585aSDaniel Vetter if (ret) 5942ceb585aSDaniel Vetter goto out; 595bf2d5eb9SVille Syrjälä 596f453ba04SDave Airlie if (crtc_req->mode_valid) { 597f453ba04SDave Airlie /* If we have a mode we need a framebuffer. */ 598f453ba04SDave Airlie /* If we pass -1, set the mode with the currently bound fb */ 599f453ba04SDave Airlie if (crtc_req->fb_id == -1) { 600a36c027dSVille Syrjälä struct drm_framebuffer *old_fb; 601a36c027dSVille Syrjälä 602a36c027dSVille Syrjälä if (plane->state) 603a36c027dSVille Syrjälä old_fb = plane->state->fb; 604a36c027dSVille Syrjälä else 605a36c027dSVille Syrjälä old_fb = plane->fb; 606a36c027dSVille Syrjälä 607a36c027dSVille Syrjälä if (!old_fb) { 6086653cc8dSVille Syrjälä DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); 6096653cc8dSVille Syrjälä ret = -EINVAL; 6106653cc8dSVille Syrjälä goto out; 6116653cc8dSVille Syrjälä } 612bf2d5eb9SVille Syrjälä 613a36c027dSVille Syrjälä fb = old_fb; 614b0d12325SDaniel Vetter /* Make refcounting symmetric with the lookup path. */ 615a4a69da0SThierry Reding drm_framebuffer_get(fb); 616f453ba04SDave Airlie } else { 617418da172SKeith Packard fb = drm_framebuffer_lookup(dev, file_priv, crtc_req->fb_id); 618786b99edSDaniel Vetter if (!fb) { 61958367ed6SZhao Yakui DRM_DEBUG_KMS("Unknown FB ID%d\n", 62058367ed6SZhao Yakui crtc_req->fb_id); 62137c4e705SVille Syrjälä ret = -ENOENT; 622f453ba04SDave Airlie goto out; 623f453ba04SDave Airlie } 624f453ba04SDave Airlie } 625f453ba04SDave Airlie 626f453ba04SDave Airlie mode = drm_mode_create(dev); 627ee34ab5bSVille Syrjälä if (!mode) { 628ee34ab5bSVille Syrjälä ret = -ENOMEM; 629ee34ab5bSVille Syrjälä goto out; 630ee34ab5bSVille Syrjälä } 631ee34ab5bSVille Syrjälä 63275a655e0SVille Syrjälä ret = drm_mode_convert_umode(dev, mode, &crtc_req->mode); 63390367bf6SVille Syrjälä if (ret) { 63490367bf6SVille Syrjälä DRM_DEBUG_KMS("Invalid mode\n"); 63590367bf6SVille Syrjälä goto out; 63690367bf6SVille Syrjälä } 63790367bf6SVille Syrjälä 6387eb5f302SLaurent Pinchart /* 6397eb5f302SLaurent Pinchart * Check whether the primary plane supports the fb pixel format. 6407eb5f302SLaurent Pinchart * Drivers not implementing the universal planes API use a 6417eb5f302SLaurent Pinchart * default formats list provided by the DRM core which doesn't 6427eb5f302SLaurent Pinchart * match real hardware capabilities. Skip the check in that 6437eb5f302SLaurent Pinchart * case. 6447eb5f302SLaurent Pinchart */ 64564c32b49SVille Syrjälä if (!plane->format_default) { 64664c32b49SVille Syrjälä ret = drm_plane_check_pixel_format(plane, 64723163a7dSVille Syrjälä fb->format->format, 64823163a7dSVille Syrjälä fb->modifier); 6497eb5f302SLaurent Pinchart if (ret) { 650b3c11ac2SEric Engestrom struct drm_format_name_buf format_name; 65123163a7dSVille Syrjälä DRM_DEBUG_KMS("Invalid pixel format %s, modifier 0x%llx\n", 652438b74a5SVille Syrjälä drm_get_format_name(fb->format->format, 65323163a7dSVille Syrjälä &format_name), 65423163a7dSVille Syrjälä fb->modifier); 6557eb5f302SLaurent Pinchart goto out; 6567eb5f302SLaurent Pinchart } 6577eb5f302SLaurent Pinchart } 6587eb5f302SLaurent Pinchart 659c11e9283SDamien Lespiau ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, 660c11e9283SDamien Lespiau mode, fb); 661c11e9283SDamien Lespiau if (ret) 6625f61bb42SVille Syrjälä goto out; 663c11e9283SDamien Lespiau 664f453ba04SDave Airlie } 665f453ba04SDave Airlie 666f453ba04SDave Airlie if (crtc_req->count_connectors == 0 && mode) { 66758367ed6SZhao Yakui DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); 668f453ba04SDave Airlie ret = -EINVAL; 669f453ba04SDave Airlie goto out; 670f453ba04SDave Airlie } 671f453ba04SDave Airlie 6727781de74SJakob Bornecrantz if (crtc_req->count_connectors > 0 && (!mode || !fb)) { 67358367ed6SZhao Yakui DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n", 674f453ba04SDave Airlie crtc_req->count_connectors); 675f453ba04SDave Airlie ret = -EINVAL; 676f453ba04SDave Airlie goto out; 677f453ba04SDave Airlie } 678f453ba04SDave Airlie 679f453ba04SDave Airlie if (crtc_req->count_connectors > 0) { 680f453ba04SDave Airlie u32 out_id; 681f453ba04SDave Airlie 682f453ba04SDave Airlie /* Avoid unbounded kernel memory allocation */ 683f453ba04SDave Airlie if (crtc_req->count_connectors > config->num_connector) { 684f453ba04SDave Airlie ret = -EINVAL; 685f453ba04SDave Airlie goto out; 686f453ba04SDave Airlie } 687f453ba04SDave Airlie 6882f6c5389SThierry Reding connector_set = kmalloc_array(crtc_req->count_connectors, 689f453ba04SDave Airlie sizeof(struct drm_connector *), 690f453ba04SDave Airlie GFP_KERNEL); 691f453ba04SDave Airlie if (!connector_set) { 692f453ba04SDave Airlie ret = -ENOMEM; 693f453ba04SDave Airlie goto out; 694f453ba04SDave Airlie } 695f453ba04SDave Airlie 696f453ba04SDave Airlie for (i = 0; i < crtc_req->count_connectors; i++) { 697b164d31fSDave Airlie connector_set[i] = NULL; 69881f6c7f8SVille Syrjälä set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; 699f453ba04SDave Airlie if (get_user(out_id, &set_connectors_ptr[i])) { 700f453ba04SDave Airlie ret = -EFAULT; 701f453ba04SDave Airlie goto out; 702f453ba04SDave Airlie } 703f453ba04SDave Airlie 704418da172SKeith Packard connector = drm_connector_lookup(dev, file_priv, out_id); 705a2b34e22SRob Clark if (!connector) { 70658367ed6SZhao Yakui DRM_DEBUG_KMS("Connector id %d unknown\n", 70758367ed6SZhao Yakui out_id); 708f27657f2SVille Syrjälä ret = -ENOENT; 709f453ba04SDave Airlie goto out; 710f453ba04SDave Airlie } 7119440106bSJerome Glisse DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", 7129440106bSJerome Glisse connector->base.id, 71325933820SJani Nikula connector->name); 714f453ba04SDave Airlie 715f453ba04SDave Airlie connector_set[i] = connector; 716f453ba04SDave Airlie } 717f453ba04SDave Airlie } 718f453ba04SDave Airlie 719f453ba04SDave Airlie set.crtc = crtc; 720f453ba04SDave Airlie set.x = crtc_req->x; 721f453ba04SDave Airlie set.y = crtc_req->y; 722f453ba04SDave Airlie set.mode = mode; 723f453ba04SDave Airlie set.connectors = connector_set; 724f453ba04SDave Airlie set.num_connectors = crtc_req->count_connectors; 725f453ba04SDave Airlie set.fb = fb; 7262ceb585aSDaniel Vetter ret = __drm_mode_set_config_internal(&set, &ctx); 727f453ba04SDave Airlie 728f453ba04SDave Airlie out: 729b0d12325SDaniel Vetter if (fb) 730a4a69da0SThierry Reding drm_framebuffer_put(fb); 731b0d12325SDaniel Vetter 732b164d31fSDave Airlie if (connector_set) { 733b164d31fSDave Airlie for (i = 0; i < crtc_req->count_connectors; i++) { 734b164d31fSDave Airlie if (connector_set[i]) 735ad093607SThierry Reding drm_connector_put(connector_set[i]); 736b164d31fSDave Airlie } 737b164d31fSDave Airlie } 738f453ba04SDave Airlie kfree(connector_set); 739ee34ab5bSVille Syrjälä drm_mode_destroy(dev, mode); 7402ceb585aSDaniel Vetter if (ret == -EDEADLK) { 7413fa6a073SMaarten Lankhorst ret = drm_modeset_backoff(&ctx); 7423fa6a073SMaarten Lankhorst if (!ret) 7432ceb585aSDaniel Vetter goto retry; 7442ceb585aSDaniel Vetter } 7452ceb585aSDaniel Vetter drm_modeset_drop_locks(&ctx); 7462ceb585aSDaniel Vetter drm_modeset_acquire_fini(&ctx); 74753552d5dSDaniel Vetter mutex_unlock(&crtc->dev->mode_config.mutex); 7482ceb585aSDaniel Vetter 749f453ba04SDave Airlie return ret; 750f453ba04SDave Airlie } 751f453ba04SDave Airlie 752949619f3SDaniel Vetter int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, 753bffd9de0SPaulo Zanoni struct drm_property *property, 754bffd9de0SPaulo Zanoni uint64_t value) 755bffd9de0SPaulo Zanoni { 756bffd9de0SPaulo Zanoni int ret = -EINVAL; 757bffd9de0SPaulo Zanoni struct drm_crtc *crtc = obj_to_crtc(obj); 758bffd9de0SPaulo Zanoni 759bffd9de0SPaulo Zanoni if (crtc->funcs->set_property) 760bffd9de0SPaulo Zanoni ret = crtc->funcs->set_property(crtc, property, value); 761144a7999SDaniel Vetter if (!ret) 762bffd9de0SPaulo Zanoni drm_object_property_set_value(obj, property, value); 763bffd9de0SPaulo Zanoni 764bffd9de0SPaulo Zanoni return ret; 765bffd9de0SPaulo Zanoni } 766