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; 405f453ba04SDave Airlie 406fb3b06c8SDave Airlie if (!drm_core_check_feature(dev, DRIVER_MODESET)) 407fb3b06c8SDave Airlie return -EINVAL; 408fb3b06c8SDave Airlie 409418da172SKeith Packard crtc = drm_crtc_find(dev, file_priv, crtc_resp->crtc_id); 410fcf93f69SDaniel Vetter if (!crtc) 411fcf93f69SDaniel Vetter return -ENOENT; 412f453ba04SDave Airlie 413f453ba04SDave Airlie crtc_resp->gamma_size = crtc->gamma_size; 414de7b6be7SDaniel Stone 4152c77bb29SDaniel Vetter drm_modeset_lock(&crtc->primary->mutex, NULL); 416de7b6be7SDaniel Stone if (crtc->primary->state && crtc->primary->state->fb) 417de7b6be7SDaniel Stone crtc_resp->fb_id = crtc->primary->state->fb->base.id; 418de7b6be7SDaniel Stone else if (!crtc->primary->state && crtc->primary->fb) 419f4510a27SMatt Roper crtc_resp->fb_id = crtc->primary->fb->base.id; 420f453ba04SDave Airlie else 421f453ba04SDave Airlie crtc_resp->fb_id = 0; 422f453ba04SDave Airlie 4232c77bb29SDaniel Vetter if (crtc->primary->state) { 42431c946e8SDaniel Vetter crtc_resp->x = crtc->primary->state->src_x >> 16; 42531c946e8SDaniel Vetter crtc_resp->y = crtc->primary->state->src_y >> 16; 4262c77bb29SDaniel Vetter } 4272c77bb29SDaniel Vetter drm_modeset_unlock(&crtc->primary->mutex); 4282c77bb29SDaniel Vetter 4292c77bb29SDaniel Vetter drm_modeset_lock(&crtc->mutex, NULL); 4302c77bb29SDaniel Vetter if (crtc->state) { 43131c946e8SDaniel Vetter if (crtc->state->enable) { 432934a8a89SDaniel Stone drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); 43331c946e8SDaniel Vetter crtc_resp->mode_valid = 1; 434f453ba04SDave Airlie 43531c946e8SDaniel Vetter } else { 43631c946e8SDaniel Vetter crtc_resp->mode_valid = 0; 43731c946e8SDaniel Vetter } 43831c946e8SDaniel Vetter } else { 43931c946e8SDaniel Vetter crtc_resp->x = crtc->x; 44031c946e8SDaniel Vetter crtc_resp->y = crtc->y; 44131c946e8SDaniel Vetter if (crtc->enabled) { 442934a8a89SDaniel Stone drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); 443f453ba04SDave Airlie crtc_resp->mode_valid = 1; 444f453ba04SDave Airlie 445f453ba04SDave Airlie } else { 446f453ba04SDave Airlie crtc_resp->mode_valid = 0; 447f453ba04SDave Airlie } 44831c946e8SDaniel Vetter } 4492c77bb29SDaniel Vetter drm_modeset_unlock(&crtc->mutex); 450f453ba04SDave Airlie 451baf698b0SDaniel Vetter return 0; 452f453ba04SDave Airlie } 453f453ba04SDave Airlie 4542ceb585aSDaniel Vetter static int __drm_mode_set_config_internal(struct drm_mode_set *set, 4552ceb585aSDaniel Vetter struct drm_modeset_acquire_ctx *ctx) 4562d13b679SDaniel Vetter { 4572d13b679SDaniel Vetter struct drm_crtc *crtc = set->crtc; 4585cef29aaSDaniel Vetter struct drm_framebuffer *fb; 4595cef29aaSDaniel Vetter struct drm_crtc *tmp; 460b0d12325SDaniel Vetter int ret; 4612d13b679SDaniel Vetter 4625cef29aaSDaniel Vetter /* 4635cef29aaSDaniel Vetter * NOTE: ->set_config can also disable other crtcs (if we steal all 4645cef29aaSDaniel Vetter * connectors from it), hence we need to refcount the fbs across all 4655cef29aaSDaniel Vetter * crtcs. Atomic modeset will have saner semantics ... 4665cef29aaSDaniel Vetter */ 467e4f62546SDaniel Vetter drm_for_each_crtc(tmp, crtc->dev) 4683d30a59bSDaniel Vetter tmp->primary->old_fb = tmp->primary->fb; 4695cef29aaSDaniel Vetter 470b0d12325SDaniel Vetter fb = set->fb; 471b0d12325SDaniel Vetter 472a4eff9aaSDaniel Vetter ret = crtc->funcs->set_config(set, ctx); 473b0d12325SDaniel Vetter if (ret == 0) { 4747e7de761SVille Syrjälä crtc->primary->crtc = fb ? crtc : NULL; 4750fe27f06SDaniel Vetter crtc->primary->fb = fb; 4765cef29aaSDaniel Vetter } 477cc85e121SDaniel Vetter 478e4f62546SDaniel Vetter drm_for_each_crtc(tmp, crtc->dev) { 479f4510a27SMatt Roper if (tmp->primary->fb) 480a4a69da0SThierry Reding drm_framebuffer_get(tmp->primary->fb); 4813d30a59bSDaniel Vetter if (tmp->primary->old_fb) 482a4a69da0SThierry Reding drm_framebuffer_put(tmp->primary->old_fb); 4833d30a59bSDaniel Vetter tmp->primary->old_fb = NULL; 484b0d12325SDaniel Vetter } 485b0d12325SDaniel Vetter 486b0d12325SDaniel Vetter return ret; 4872d13b679SDaniel Vetter } 488d49473a5SDaniel Vetter /** 489d49473a5SDaniel Vetter * drm_mode_set_config_internal - helper to call &drm_mode_config_funcs.set_config 490d49473a5SDaniel Vetter * @set: modeset config to set 491d49473a5SDaniel Vetter * 492d49473a5SDaniel Vetter * This is a little helper to wrap internal calls to the 493d49473a5SDaniel Vetter * &drm_mode_config_funcs.set_config driver interface. The only thing it adds is 494d49473a5SDaniel Vetter * correct refcounting dance. 495d49473a5SDaniel Vetter * 496d49473a5SDaniel Vetter * This should only be used by non-atomic legacy drivers. 497d49473a5SDaniel Vetter * 498d49473a5SDaniel Vetter * Returns: 499d49473a5SDaniel Vetter * Zero on success, negative errno on failure. 500d49473a5SDaniel Vetter */ 501d49473a5SDaniel Vetter int drm_mode_set_config_internal(struct drm_mode_set *set) 502d49473a5SDaniel Vetter { 503d49473a5SDaniel Vetter WARN_ON(drm_drv_uses_atomic_modeset(set->crtc->dev)); 504d49473a5SDaniel Vetter 5052ceb585aSDaniel Vetter return __drm_mode_set_config_internal(set, NULL); 506d49473a5SDaniel Vetter } 5072d13b679SDaniel Vetter EXPORT_SYMBOL(drm_mode_set_config_internal); 5082d13b679SDaniel Vetter 509af93629dSMatt Roper /** 510af93629dSMatt Roper * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the 511af93629dSMatt Roper * CRTC viewport 512af93629dSMatt Roper * @crtc: CRTC that framebuffer will be displayed on 513af93629dSMatt Roper * @x: x panning 514af93629dSMatt Roper * @y: y panning 515af93629dSMatt Roper * @mode: mode that framebuffer will be displayed under 516af93629dSMatt Roper * @fb: framebuffer to check size of 517c11e9283SDamien Lespiau */ 518af93629dSMatt Roper int drm_crtc_check_viewport(const struct drm_crtc *crtc, 519c11e9283SDamien Lespiau int x, int y, 520c11e9283SDamien Lespiau const struct drm_display_mode *mode, 521c11e9283SDamien Lespiau const struct drm_framebuffer *fb) 522c11e9283SDamien Lespiau 523c11e9283SDamien Lespiau { 524c11e9283SDamien Lespiau int hdisplay, vdisplay; 525c11e9283SDamien Lespiau 526196cd5d3SDaniel Vetter drm_mode_get_hv_timing(mode, &hdisplay, &vdisplay); 527a0c1bbb0SDamien Lespiau 52833e0be63SVille Syrjälä if (crtc->state && 529bd2ef25dSVille Syrjälä drm_rotation_90_or_270(crtc->primary->state->rotation)) 530c11e9283SDamien Lespiau swap(hdisplay, vdisplay); 531c11e9283SDamien Lespiau 53243968d7bSDaniel Vetter return drm_framebuffer_check_src_coords(x << 16, y << 16, 53343968d7bSDaniel Vetter hdisplay << 16, vdisplay << 16, 53443968d7bSDaniel Vetter fb); 535c11e9283SDamien Lespiau } 536af93629dSMatt Roper EXPORT_SYMBOL(drm_crtc_check_viewport); 537c11e9283SDamien Lespiau 5382d13b679SDaniel Vetter /** 539f453ba04SDave Airlie * drm_mode_setcrtc - set CRTC configuration 540065a50edSDaniel Vetter * @dev: drm device for the ioctl 541065a50edSDaniel Vetter * @data: data pointer for the ioctl 542065a50edSDaniel Vetter * @file_priv: drm file for the ioctl call 543f453ba04SDave Airlie * 544f453ba04SDave Airlie * Build a new CRTC configuration based on user request. 545f453ba04SDave Airlie * 546f453ba04SDave Airlie * Called by the user via ioctl. 547f453ba04SDave Airlie * 548c8e32cc1SDaniel Vetter * Returns: 5491a498633SDaniel Vetter * Zero on success, negative errno on failure. 550f453ba04SDave Airlie */ 551f453ba04SDave Airlie int drm_mode_setcrtc(struct drm_device *dev, void *data, 552f453ba04SDave Airlie struct drm_file *file_priv) 553f453ba04SDave Airlie { 554f453ba04SDave Airlie struct drm_mode_config *config = &dev->mode_config; 555f453ba04SDave Airlie struct drm_mode_crtc *crtc_req = data; 5566653cc8dSVille Syrjälä struct drm_crtc *crtc; 557f453ba04SDave Airlie struct drm_connector **connector_set = NULL, *connector; 558f453ba04SDave Airlie struct drm_framebuffer *fb = NULL; 559f453ba04SDave Airlie struct drm_display_mode *mode = NULL; 560f453ba04SDave Airlie struct drm_mode_set set; 561f453ba04SDave Airlie uint32_t __user *set_connectors_ptr; 5622ceb585aSDaniel Vetter struct drm_modeset_acquire_ctx ctx; 5634a1b0714SLaurent Pinchart int ret; 564f453ba04SDave Airlie int i; 565f453ba04SDave Airlie 566fb3b06c8SDave Airlie if (!drm_core_check_feature(dev, DRIVER_MODESET)) 567fb3b06c8SDave Airlie return -EINVAL; 568fb3b06c8SDave Airlie 56901447e9fSZhao Junwang /* 57001447e9fSZhao Junwang * Universal plane src offsets are only 16.16, prevent havoc for 57101447e9fSZhao Junwang * drivers using universal plane code internally. 57201447e9fSZhao Junwang */ 57301447e9fSZhao Junwang if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) 5741d97e915SVille Syrjälä return -ERANGE; 5751d97e915SVille Syrjälä 576418da172SKeith Packard crtc = drm_crtc_find(dev, file_priv, crtc_req->crtc_id); 577a2b34e22SRob Clark if (!crtc) { 57858367ed6SZhao Yakui DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); 5792ceb585aSDaniel Vetter return -ENOENT; 580f453ba04SDave Airlie } 581fa3ab4c2SVille Syrjälä DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); 582f453ba04SDave Airlie 58353552d5dSDaniel Vetter mutex_lock(&crtc->dev->mode_config.mutex); 5843fa6a073SMaarten Lankhorst drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE); 5852ceb585aSDaniel Vetter retry: 5862ceb585aSDaniel Vetter ret = drm_modeset_lock_all_ctx(crtc->dev, &ctx); 5872ceb585aSDaniel Vetter if (ret) 5882ceb585aSDaniel Vetter goto out; 589f453ba04SDave Airlie if (crtc_req->mode_valid) { 590f453ba04SDave Airlie /* If we have a mode we need a framebuffer. */ 591f453ba04SDave Airlie /* If we pass -1, set the mode with the currently bound fb */ 592f453ba04SDave Airlie if (crtc_req->fb_id == -1) { 593f4510a27SMatt Roper if (!crtc->primary->fb) { 5946653cc8dSVille Syrjälä DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); 5956653cc8dSVille Syrjälä ret = -EINVAL; 5966653cc8dSVille Syrjälä goto out; 5976653cc8dSVille Syrjälä } 598f4510a27SMatt Roper fb = crtc->primary->fb; 599b0d12325SDaniel Vetter /* Make refcounting symmetric with the lookup path. */ 600a4a69da0SThierry Reding drm_framebuffer_get(fb); 601f453ba04SDave Airlie } else { 602418da172SKeith Packard fb = drm_framebuffer_lookup(dev, file_priv, crtc_req->fb_id); 603786b99edSDaniel Vetter if (!fb) { 60458367ed6SZhao Yakui DRM_DEBUG_KMS("Unknown FB ID%d\n", 60558367ed6SZhao Yakui crtc_req->fb_id); 60637c4e705SVille Syrjälä ret = -ENOENT; 607f453ba04SDave Airlie goto out; 608f453ba04SDave Airlie } 609f453ba04SDave Airlie } 610f453ba04SDave Airlie 611f453ba04SDave Airlie mode = drm_mode_create(dev); 612ee34ab5bSVille Syrjälä if (!mode) { 613ee34ab5bSVille Syrjälä ret = -ENOMEM; 614ee34ab5bSVille Syrjälä goto out; 615ee34ab5bSVille Syrjälä } 616ee34ab5bSVille Syrjälä 61775a655e0SVille Syrjälä ret = drm_mode_convert_umode(dev, mode, &crtc_req->mode); 61890367bf6SVille Syrjälä if (ret) { 61990367bf6SVille Syrjälä DRM_DEBUG_KMS("Invalid mode\n"); 62090367bf6SVille Syrjälä goto out; 62190367bf6SVille Syrjälä } 62290367bf6SVille Syrjälä 6237eb5f302SLaurent Pinchart /* 6247eb5f302SLaurent Pinchart * Check whether the primary plane supports the fb pixel format. 6257eb5f302SLaurent Pinchart * Drivers not implementing the universal planes API use a 6267eb5f302SLaurent Pinchart * default formats list provided by the DRM core which doesn't 6277eb5f302SLaurent Pinchart * match real hardware capabilities. Skip the check in that 6287eb5f302SLaurent Pinchart * case. 6297eb5f302SLaurent Pinchart */ 6307eb5f302SLaurent Pinchart if (!crtc->primary->format_default) { 6317eb5f302SLaurent Pinchart ret = drm_plane_check_pixel_format(crtc->primary, 63223163a7dSVille Syrjälä fb->format->format, 63323163a7dSVille Syrjälä fb->modifier); 6347eb5f302SLaurent Pinchart if (ret) { 635b3c11ac2SEric Engestrom struct drm_format_name_buf format_name; 63623163a7dSVille Syrjälä DRM_DEBUG_KMS("Invalid pixel format %s, modifier 0x%llx\n", 637438b74a5SVille Syrjälä drm_get_format_name(fb->format->format, 63823163a7dSVille Syrjälä &format_name), 63923163a7dSVille Syrjälä fb->modifier); 6407eb5f302SLaurent Pinchart goto out; 6417eb5f302SLaurent Pinchart } 6427eb5f302SLaurent Pinchart } 6437eb5f302SLaurent Pinchart 644c11e9283SDamien Lespiau ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, 645c11e9283SDamien Lespiau mode, fb); 646c11e9283SDamien Lespiau if (ret) 6475f61bb42SVille Syrjälä goto out; 648c11e9283SDamien Lespiau 649f453ba04SDave Airlie } 650f453ba04SDave Airlie 651f453ba04SDave Airlie if (crtc_req->count_connectors == 0 && mode) { 65258367ed6SZhao Yakui DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); 653f453ba04SDave Airlie ret = -EINVAL; 654f453ba04SDave Airlie goto out; 655f453ba04SDave Airlie } 656f453ba04SDave Airlie 6577781de74SJakob Bornecrantz if (crtc_req->count_connectors > 0 && (!mode || !fb)) { 65858367ed6SZhao Yakui DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n", 659f453ba04SDave Airlie crtc_req->count_connectors); 660f453ba04SDave Airlie ret = -EINVAL; 661f453ba04SDave Airlie goto out; 662f453ba04SDave Airlie } 663f453ba04SDave Airlie 664f453ba04SDave Airlie if (crtc_req->count_connectors > 0) { 665f453ba04SDave Airlie u32 out_id; 666f453ba04SDave Airlie 667f453ba04SDave Airlie /* Avoid unbounded kernel memory allocation */ 668f453ba04SDave Airlie if (crtc_req->count_connectors > config->num_connector) { 669f453ba04SDave Airlie ret = -EINVAL; 670f453ba04SDave Airlie goto out; 671f453ba04SDave Airlie } 672f453ba04SDave Airlie 6732f6c5389SThierry Reding connector_set = kmalloc_array(crtc_req->count_connectors, 674f453ba04SDave Airlie sizeof(struct drm_connector *), 675f453ba04SDave Airlie GFP_KERNEL); 676f453ba04SDave Airlie if (!connector_set) { 677f453ba04SDave Airlie ret = -ENOMEM; 678f453ba04SDave Airlie goto out; 679f453ba04SDave Airlie } 680f453ba04SDave Airlie 681f453ba04SDave Airlie for (i = 0; i < crtc_req->count_connectors; i++) { 682b164d31fSDave Airlie connector_set[i] = NULL; 68381f6c7f8SVille Syrjälä set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; 684f453ba04SDave Airlie if (get_user(out_id, &set_connectors_ptr[i])) { 685f453ba04SDave Airlie ret = -EFAULT; 686f453ba04SDave Airlie goto out; 687f453ba04SDave Airlie } 688f453ba04SDave Airlie 689418da172SKeith Packard connector = drm_connector_lookup(dev, file_priv, out_id); 690a2b34e22SRob Clark if (!connector) { 69158367ed6SZhao Yakui DRM_DEBUG_KMS("Connector id %d unknown\n", 69258367ed6SZhao Yakui out_id); 693f27657f2SVille Syrjälä ret = -ENOENT; 694f453ba04SDave Airlie goto out; 695f453ba04SDave Airlie } 6969440106bSJerome Glisse DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", 6979440106bSJerome Glisse connector->base.id, 69825933820SJani Nikula connector->name); 699f453ba04SDave Airlie 700f453ba04SDave Airlie connector_set[i] = connector; 701f453ba04SDave Airlie } 702f453ba04SDave Airlie } 703f453ba04SDave Airlie 704f453ba04SDave Airlie set.crtc = crtc; 705f453ba04SDave Airlie set.x = crtc_req->x; 706f453ba04SDave Airlie set.y = crtc_req->y; 707f453ba04SDave Airlie set.mode = mode; 708f453ba04SDave Airlie set.connectors = connector_set; 709f453ba04SDave Airlie set.num_connectors = crtc_req->count_connectors; 710f453ba04SDave Airlie set.fb = fb; 7112ceb585aSDaniel Vetter ret = __drm_mode_set_config_internal(&set, &ctx); 712f453ba04SDave Airlie 713f453ba04SDave Airlie out: 714b0d12325SDaniel Vetter if (fb) 715a4a69da0SThierry Reding drm_framebuffer_put(fb); 716b0d12325SDaniel Vetter 717b164d31fSDave Airlie if (connector_set) { 718b164d31fSDave Airlie for (i = 0; i < crtc_req->count_connectors; i++) { 719b164d31fSDave Airlie if (connector_set[i]) 720ad093607SThierry Reding drm_connector_put(connector_set[i]); 721b164d31fSDave Airlie } 722b164d31fSDave Airlie } 723f453ba04SDave Airlie kfree(connector_set); 724ee34ab5bSVille Syrjälä drm_mode_destroy(dev, mode); 7252ceb585aSDaniel Vetter if (ret == -EDEADLK) { 7263fa6a073SMaarten Lankhorst ret = drm_modeset_backoff(&ctx); 7273fa6a073SMaarten Lankhorst if (!ret) 7282ceb585aSDaniel Vetter goto retry; 7292ceb585aSDaniel Vetter } 7302ceb585aSDaniel Vetter drm_modeset_drop_locks(&ctx); 7312ceb585aSDaniel Vetter drm_modeset_acquire_fini(&ctx); 73253552d5dSDaniel Vetter mutex_unlock(&crtc->dev->mode_config.mutex); 7332ceb585aSDaniel Vetter 734f453ba04SDave Airlie return ret; 735f453ba04SDave Airlie } 736f453ba04SDave Airlie 737949619f3SDaniel Vetter int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, 738bffd9de0SPaulo Zanoni struct drm_property *property, 739bffd9de0SPaulo Zanoni uint64_t value) 740bffd9de0SPaulo Zanoni { 741bffd9de0SPaulo Zanoni int ret = -EINVAL; 742bffd9de0SPaulo Zanoni struct drm_crtc *crtc = obj_to_crtc(obj); 743bffd9de0SPaulo Zanoni 744bffd9de0SPaulo Zanoni if (crtc->funcs->set_property) 745bffd9de0SPaulo Zanoni ret = crtc->funcs->set_property(crtc, property, value); 746144a7999SDaniel Vetter if (!ret) 747bffd9de0SPaulo Zanoni drm_object_property_set_value(obj, property, value); 748bffd9de0SPaulo Zanoni 749bffd9de0SPaulo Zanoni return ret; 750bffd9de0SPaulo Zanoni } 751