Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006-2008 Intel Corporation |
| 3 | * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> |
| 4 | * Copyright (c) 2008 Red Hat Inc. |
| 5 | * |
| 6 | * DRM core CRTC related functions |
| 7 | * |
| 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. |
| 17 | * |
| 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 |
| 24 | * OF THIS SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Keith Packard |
| 28 | * Eric Anholt <eric@anholt.net> |
| 29 | * Dave Airlie <airlied@linux.ie> |
| 30 | * Jesse Barnes <jesse.barnes@intel.com> |
| 31 | */ |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 32 | #include <linux/ctype.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 33 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 35 | #include <linux/export.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 36 | #include <drm/drmP.h> |
| 37 | #include <drm/drm_crtc.h> |
| 38 | #include <drm/drm_edid.h> |
| 39 | #include <drm/drm_fourcc.h> |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 40 | #include <drm/drm_modeset_lock.h> |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 41 | #include <drm/drm_atomic.h> |
Daniel Vetter | 3b96a0b | 2016-06-21 10:54:22 +0200 | [diff] [blame] | 42 | #include <drm/drm_auth.h> |
Tomeu Vizoso | 9edbf1f | 2016-10-06 17:21:06 +0200 | [diff] [blame] | 43 | #include <drm/drm_debugfs_crc.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 44 | |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 45 | #include "drm_crtc_internal.h" |
Daniel Vetter | 67d0ec4 | 2014-09-10 12:43:53 +0200 | [diff] [blame] | 46 | #include "drm_internal.h" |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 47 | |
Lukas Wunner | 6a0d952 | 2016-06-08 18:47:27 +0200 | [diff] [blame] | 48 | /** |
| 49 | * drm_crtc_force_disable - Forcibly turn off a CRTC |
| 50 | * @crtc: CRTC to turn off |
| 51 | * |
| 52 | * Returns: |
| 53 | * Zero on success, error code on failure. |
| 54 | */ |
| 55 | int drm_crtc_force_disable(struct drm_crtc *crtc) |
| 56 | { |
| 57 | struct drm_mode_set set = { |
| 58 | .crtc = crtc, |
| 59 | }; |
| 60 | |
| 61 | return drm_mode_set_config_internal(&set); |
| 62 | } |
| 63 | EXPORT_SYMBOL(drm_crtc_force_disable); |
| 64 | |
| 65 | /** |
| 66 | * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs |
| 67 | * @dev: DRM device whose CRTCs to turn off |
| 68 | * |
| 69 | * Drivers may want to call this on unload to ensure that all displays are |
| 70 | * unlit and the GPU is in a consistent, low power state. Takes modeset locks. |
| 71 | * |
| 72 | * Returns: |
| 73 | * Zero on success, error code on failure. |
| 74 | */ |
| 75 | int drm_crtc_force_disable_all(struct drm_device *dev) |
| 76 | { |
| 77 | struct drm_crtc *crtc; |
| 78 | int ret = 0; |
| 79 | |
| 80 | drm_modeset_lock_all(dev); |
| 81 | drm_for_each_crtc(crtc, dev) |
| 82 | if (crtc->enabled) { |
| 83 | ret = drm_crtc_force_disable(crtc); |
| 84 | if (ret) |
| 85 | goto out; |
| 86 | } |
| 87 | out: |
| 88 | drm_modeset_unlock_all(dev); |
| 89 | return ret; |
| 90 | } |
| 91 | EXPORT_SYMBOL(drm_crtc_force_disable_all); |
| 92 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 93 | static unsigned int drm_num_crtcs(struct drm_device *dev) |
| 94 | { |
| 95 | unsigned int num = 0; |
| 96 | struct drm_crtc *tmp; |
| 97 | |
| 98 | drm_for_each_crtc(tmp, dev) { |
| 99 | num++; |
| 100 | } |
| 101 | |
| 102 | return num; |
| 103 | } |
| 104 | |
Daniel Vetter | 28575f1 | 2016-11-14 12:58:23 +0100 | [diff] [blame^] | 105 | int drm_crtc_register_all(struct drm_device *dev) |
Benjamin Gaignard | 79190ea | 2016-06-21 16:37:09 +0200 | [diff] [blame] | 106 | { |
| 107 | struct drm_crtc *crtc; |
| 108 | int ret = 0; |
| 109 | |
| 110 | drm_for_each_crtc(crtc, dev) { |
Tomeu Vizoso | 9edbf1f | 2016-10-06 17:21:06 +0200 | [diff] [blame] | 111 | if (drm_debugfs_crtc_add(crtc)) |
| 112 | DRM_ERROR("Failed to initialize debugfs entry for CRTC '%s'.\n", |
| 113 | crtc->name); |
| 114 | |
Benjamin Gaignard | 79190ea | 2016-06-21 16:37:09 +0200 | [diff] [blame] | 115 | if (crtc->funcs->late_register) |
| 116 | ret = crtc->funcs->late_register(crtc); |
| 117 | if (ret) |
| 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Daniel Vetter | 28575f1 | 2016-11-14 12:58:23 +0100 | [diff] [blame^] | 124 | void drm_crtc_unregister_all(struct drm_device *dev) |
Benjamin Gaignard | 79190ea | 2016-06-21 16:37:09 +0200 | [diff] [blame] | 125 | { |
| 126 | struct drm_crtc *crtc; |
| 127 | |
| 128 | drm_for_each_crtc(crtc, dev) { |
| 129 | if (crtc->funcs->early_unregister) |
| 130 | crtc->funcs->early_unregister(crtc); |
Tomeu Vizoso | 9edbf1f | 2016-10-06 17:21:06 +0200 | [diff] [blame] | 131 | drm_debugfs_crtc_remove(crtc); |
Benjamin Gaignard | 79190ea | 2016-06-21 16:37:09 +0200 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Tomeu Vizoso | 9edbf1f | 2016-10-06 17:21:06 +0200 | [diff] [blame] | 135 | static int drm_crtc_crc_init(struct drm_crtc *crtc) |
| 136 | { |
| 137 | #ifdef CONFIG_DEBUG_FS |
| 138 | spin_lock_init(&crtc->crc.lock); |
| 139 | init_waitqueue_head(&crtc->crc.wq); |
| 140 | crtc->crc.source = kstrdup("auto", GFP_KERNEL); |
| 141 | if (!crtc->crc.source) |
| 142 | return -ENOMEM; |
| 143 | #endif |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static void drm_crtc_crc_fini(struct drm_crtc *crtc) |
| 148 | { |
| 149 | #ifdef CONFIG_DEBUG_FS |
| 150 | kfree(crtc->crc.source); |
| 151 | #endif |
| 152 | } |
| 153 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 154 | /** |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 155 | * drm_crtc_init_with_planes - Initialise a new CRTC object with |
| 156 | * specified primary and cursor planes. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 157 | * @dev: DRM device |
| 158 | * @crtc: CRTC object to init |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 159 | * @primary: Primary plane for CRTC |
| 160 | * @cursor: Cursor plane for CRTC |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 161 | * @funcs: callbacks for the new CRTC |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 162 | * @name: printf style format string for the CRTC name, or NULL for default name |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 163 | * |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 164 | * Inits a new object created as base part of a driver crtc object. Drivers |
| 165 | * should use this function instead of drm_crtc_init(), which is only provided |
| 166 | * for backwards compatibility with drivers which do not yet support universal |
| 167 | * planes). For really simple hardware which has only 1 plane look at |
| 168 | * drm_simple_display_pipe_init() instead. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 169 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 170 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 171 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 172 | */ |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 173 | int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, |
| 174 | struct drm_plane *primary, |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 175 | struct drm_plane *cursor, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 176 | const struct drm_crtc_funcs *funcs, |
| 177 | const char *name, ...) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 178 | { |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 179 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 180 | int ret; |
| 181 | |
Benjamin Gaignard | 522cf91 | 2015-03-17 12:05:29 +0100 | [diff] [blame] | 182 | WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY); |
| 183 | WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR); |
| 184 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 185 | crtc->dev = dev; |
| 186 | crtc->funcs = funcs; |
| 187 | |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame] | 188 | INIT_LIST_HEAD(&crtc->commit_list); |
| 189 | spin_lock_init(&crtc->commit_lock); |
| 190 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 191 | drm_modeset_lock_init(&crtc->mutex); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 192 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
| 193 | if (ret) |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 194 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 195 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 196 | if (name) { |
| 197 | va_list ap; |
| 198 | |
| 199 | va_start(ap, name); |
| 200 | crtc->name = kvasprintf(GFP_KERNEL, name, ap); |
| 201 | va_end(ap); |
| 202 | } else { |
| 203 | crtc->name = kasprintf(GFP_KERNEL, "crtc-%d", |
| 204 | drm_num_crtcs(dev)); |
| 205 | } |
| 206 | if (!crtc->name) { |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 207 | drm_mode_object_unregister(dev, &crtc->base); |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 208 | return -ENOMEM; |
| 209 | } |
| 210 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 211 | crtc->base.properties = &crtc->properties; |
| 212 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 213 | list_add_tail(&crtc->head, &config->crtc_list); |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 214 | crtc->index = config->num_crtc++; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 215 | |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 216 | crtc->primary = primary; |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 217 | crtc->cursor = cursor; |
Rob Clark | 7abc7d4 | 2016-11-05 10:52:01 -0400 | [diff] [blame] | 218 | if (primary && !primary->possible_crtcs) |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 219 | primary->possible_crtcs = 1 << drm_crtc_index(crtc); |
Rob Clark | 7abc7d4 | 2016-11-05 10:52:01 -0400 | [diff] [blame] | 220 | if (cursor && !cursor->possible_crtcs) |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 221 | cursor->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 222 | |
Tomeu Vizoso | 9edbf1f | 2016-10-06 17:21:06 +0200 | [diff] [blame] | 223 | ret = drm_crtc_crc_init(crtc); |
| 224 | if (ret) { |
| 225 | drm_mode_object_unregister(dev, &crtc->base); |
| 226 | return ret; |
| 227 | } |
| 228 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 229 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 230 | drm_object_attach_property(&crtc->base, config->prop_active, 0); |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 231 | drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 234 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 235 | } |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 236 | EXPORT_SYMBOL(drm_crtc_init_with_planes); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 237 | |
| 238 | /** |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 239 | * drm_crtc_cleanup - Clean up the core crtc usage |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 240 | * @crtc: CRTC to cleanup |
| 241 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 242 | * This function cleans up @crtc and removes it from the DRM mode setting |
| 243 | * core. Note that the function does *not* free the crtc structure itself, |
| 244 | * this is the responsibility of the caller. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 245 | */ |
| 246 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
| 247 | { |
| 248 | struct drm_device *dev = crtc->dev; |
| 249 | |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 250 | /* Note that the crtc_list is considered to be static; should we |
| 251 | * remove the drm_crtc at runtime we would have to decrement all |
| 252 | * the indices on the drm_crtc after us in the crtc_list. |
| 253 | */ |
| 254 | |
Tomeu Vizoso | 9edbf1f | 2016-10-06 17:21:06 +0200 | [diff] [blame] | 255 | drm_crtc_crc_fini(crtc); |
| 256 | |
Sachin Kamat | 9e1c156 | 2012-11-19 09:44:56 +0000 | [diff] [blame] | 257 | kfree(crtc->gamma_store); |
| 258 | crtc->gamma_store = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 259 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 260 | drm_modeset_lock_fini(&crtc->mutex); |
| 261 | |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 262 | drm_mode_object_unregister(dev, &crtc->base); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 263 | list_del(&crtc->head); |
| 264 | dev->mode_config.num_crtc--; |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 265 | |
| 266 | WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state); |
| 267 | if (crtc->state && crtc->funcs->atomic_destroy_state) |
| 268 | crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 269 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 270 | kfree(crtc->name); |
| 271 | |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 272 | memset(crtc, 0, sizeof(*crtc)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 273 | } |
| 274 | EXPORT_SYMBOL(drm_crtc_cleanup); |
| 275 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 276 | /** |
| 277 | * drm_mode_getcrtc - get CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 278 | * @dev: drm device for the ioctl |
| 279 | * @data: data pointer for the ioctl |
| 280 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 281 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 282 | * Construct a CRTC configuration structure to return to the user. |
| 283 | * |
| 284 | * Called by the user via ioctl. |
| 285 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 286 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 287 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 288 | */ |
| 289 | int drm_mode_getcrtc(struct drm_device *dev, |
| 290 | void *data, struct drm_file *file_priv) |
| 291 | { |
| 292 | struct drm_mode_crtc *crtc_resp = data; |
| 293 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 294 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 295 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 296 | return -EINVAL; |
| 297 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 298 | crtc = drm_crtc_find(dev, crtc_resp->crtc_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 299 | if (!crtc) |
| 300 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 301 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 302 | drm_modeset_lock_crtc(crtc, crtc->primary); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 303 | crtc_resp->gamma_size = crtc->gamma_size; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 304 | if (crtc->primary->fb) |
| 305 | crtc_resp->fb_id = crtc->primary->fb->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 306 | else |
| 307 | crtc_resp->fb_id = 0; |
| 308 | |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 309 | if (crtc->state) { |
| 310 | crtc_resp->x = crtc->primary->state->src_x >> 16; |
| 311 | crtc_resp->y = crtc->primary->state->src_y >> 16; |
| 312 | if (crtc->state->enable) { |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 313 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 314 | crtc_resp->mode_valid = 1; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 315 | |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 316 | } else { |
| 317 | crtc_resp->mode_valid = 0; |
| 318 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 319 | } else { |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 320 | crtc_resp->x = crtc->x; |
| 321 | crtc_resp->y = crtc->y; |
| 322 | if (crtc->enabled) { |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 323 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 324 | crtc_resp->mode_valid = 1; |
| 325 | |
| 326 | } else { |
| 327 | crtc_resp->mode_valid = 0; |
| 328 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 329 | } |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 330 | drm_modeset_unlock_crtc(crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 331 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 332 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 335 | /** |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 336 | * drm_mode_set_config_internal - helper to call ->set_config |
| 337 | * @set: modeset config to set |
| 338 | * |
| 339 | * This is a little helper to wrap internal calls to the ->set_config driver |
| 340 | * interface. The only thing it adds is correct refcounting dance. |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 341 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 342 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 343 | * Zero on success, negative errno on failure. |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 344 | */ |
| 345 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
| 346 | { |
| 347 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 348 | struct drm_framebuffer *fb; |
| 349 | struct drm_crtc *tmp; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 350 | int ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 351 | |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 352 | /* |
| 353 | * NOTE: ->set_config can also disable other crtcs (if we steal all |
| 354 | * connectors from it), hence we need to refcount the fbs across all |
| 355 | * crtcs. Atomic modeset will have saner semantics ... |
| 356 | */ |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 357 | drm_for_each_crtc(tmp, crtc->dev) |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 358 | tmp->primary->old_fb = tmp->primary->fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 359 | |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 360 | fb = set->fb; |
| 361 | |
| 362 | ret = crtc->funcs->set_config(set); |
| 363 | if (ret == 0) { |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 364 | crtc->primary->crtc = crtc; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 365 | crtc->primary->fb = fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 366 | } |
Daniel Vetter | cc85e12 | 2013-06-15 00:13:15 +0200 | [diff] [blame] | 367 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 368 | drm_for_each_crtc(tmp, crtc->dev) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 369 | if (tmp->primary->fb) |
| 370 | drm_framebuffer_reference(tmp->primary->fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 371 | if (tmp->primary->old_fb) |
| 372 | drm_framebuffer_unreference(tmp->primary->old_fb); |
| 373 | tmp->primary->old_fb = NULL; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | return ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 377 | } |
| 378 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
| 379 | |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 380 | /** |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 381 | * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode |
| 382 | * @mode: mode to query |
| 383 | * @hdisplay: hdisplay value to fill in |
| 384 | * @vdisplay: vdisplay value to fill in |
| 385 | * |
| 386 | * The vdisplay value will be doubled if the specified mode is a stereo mode of |
| 387 | * the appropriate layout. |
| 388 | */ |
| 389 | void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
| 390 | int *hdisplay, int *vdisplay) |
| 391 | { |
| 392 | struct drm_display_mode adjusted; |
| 393 | |
| 394 | drm_mode_copy(&adjusted, mode); |
| 395 | drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY); |
| 396 | *hdisplay = adjusted.crtc_hdisplay; |
| 397 | *vdisplay = adjusted.crtc_vdisplay; |
| 398 | } |
| 399 | EXPORT_SYMBOL(drm_crtc_get_hv_timing); |
| 400 | |
| 401 | /** |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 402 | * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the |
| 403 | * CRTC viewport |
| 404 | * @crtc: CRTC that framebuffer will be displayed on |
| 405 | * @x: x panning |
| 406 | * @y: y panning |
| 407 | * @mode: mode that framebuffer will be displayed under |
| 408 | * @fb: framebuffer to check size of |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 409 | */ |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 410 | int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
| 411 | int x, int y, |
| 412 | const struct drm_display_mode *mode, |
| 413 | const struct drm_framebuffer *fb) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 414 | |
| 415 | { |
| 416 | int hdisplay, vdisplay; |
| 417 | |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 418 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
Damien Lespiau | a0c1bbb | 2013-09-25 16:45:31 +0100 | [diff] [blame] | 419 | |
Ville Syrjälä | 33e0be6 | 2015-10-16 18:38:39 +0300 | [diff] [blame] | 420 | if (crtc->state && |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 421 | drm_rotation_90_or_270(crtc->primary->state->rotation)) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 422 | swap(hdisplay, vdisplay); |
| 423 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 424 | return drm_framebuffer_check_src_coords(x << 16, y << 16, |
| 425 | hdisplay << 16, vdisplay << 16, |
| 426 | fb); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 427 | } |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 428 | EXPORT_SYMBOL(drm_crtc_check_viewport); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 429 | |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 430 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 431 | * drm_mode_setcrtc - set CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 432 | * @dev: drm device for the ioctl |
| 433 | * @data: data pointer for the ioctl |
| 434 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 435 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 436 | * Build a new CRTC configuration based on user request. |
| 437 | * |
| 438 | * Called by the user via ioctl. |
| 439 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 440 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 441 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 442 | */ |
| 443 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
| 444 | struct drm_file *file_priv) |
| 445 | { |
| 446 | struct drm_mode_config *config = &dev->mode_config; |
| 447 | struct drm_mode_crtc *crtc_req = data; |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 448 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 449 | struct drm_connector **connector_set = NULL, *connector; |
| 450 | struct drm_framebuffer *fb = NULL; |
| 451 | struct drm_display_mode *mode = NULL; |
| 452 | struct drm_mode_set set; |
| 453 | uint32_t __user *set_connectors_ptr; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 454 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 455 | int i; |
| 456 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 457 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 458 | return -EINVAL; |
| 459 | |
Zhao Junwang | 01447e9 | 2015-07-07 17:08:35 +0800 | [diff] [blame] | 460 | /* |
| 461 | * Universal plane src offsets are only 16.16, prevent havoc for |
| 462 | * drivers using universal plane code internally. |
| 463 | */ |
| 464 | if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) |
Ville Syrjälä | 1d97e91 | 2012-03-13 12:35:41 +0200 | [diff] [blame] | 465 | return -ERANGE; |
| 466 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 467 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 468 | crtc = drm_crtc_find(dev, crtc_req->crtc_id); |
| 469 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 470 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 471 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 472 | goto out; |
| 473 | } |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 474 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 475 | |
| 476 | if (crtc_req->mode_valid) { |
| 477 | /* If we have a mode we need a framebuffer. */ |
| 478 | /* If we pass -1, set the mode with the currently bound fb */ |
| 479 | if (crtc_req->fb_id == -1) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 480 | if (!crtc->primary->fb) { |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 481 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
| 482 | ret = -EINVAL; |
| 483 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 484 | } |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 485 | fb = crtc->primary->fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 486 | /* Make refcounting symmetric with the lookup path. */ |
| 487 | drm_framebuffer_reference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 488 | } else { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 489 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
| 490 | if (!fb) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 491 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
| 492 | crtc_req->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 493 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 494 | goto out; |
| 495 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | mode = drm_mode_create(dev); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 499 | if (!mode) { |
| 500 | ret = -ENOMEM; |
| 501 | goto out; |
| 502 | } |
| 503 | |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 504 | ret = drm_mode_convert_umode(mode, &crtc_req->mode); |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 505 | if (ret) { |
| 506 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 507 | goto out; |
| 508 | } |
| 509 | |
Laurent Pinchart | 7eb5f30 | 2015-03-09 10:41:07 +0200 | [diff] [blame] | 510 | /* |
| 511 | * Check whether the primary plane supports the fb pixel format. |
| 512 | * Drivers not implementing the universal planes API use a |
| 513 | * default formats list provided by the DRM core which doesn't |
| 514 | * match real hardware capabilities. Skip the check in that |
| 515 | * case. |
| 516 | */ |
| 517 | if (!crtc->primary->format_default) { |
| 518 | ret = drm_plane_check_pixel_format(crtc->primary, |
| 519 | fb->pixel_format); |
| 520 | if (ret) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 521 | struct drm_format_name_buf format_name; |
| 522 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
| 523 | drm_get_format_name(fb->pixel_format, |
| 524 | &format_name)); |
Laurent Pinchart | 7eb5f30 | 2015-03-09 10:41:07 +0200 | [diff] [blame] | 525 | goto out; |
| 526 | } |
| 527 | } |
| 528 | |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 529 | ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, |
| 530 | mode, fb); |
| 531 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 532 | goto out; |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 533 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | if (crtc_req->count_connectors == 0 && mode) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 537 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 538 | ret = -EINVAL; |
| 539 | goto out; |
| 540 | } |
| 541 | |
Jakob Bornecrantz | 7781de7 | 2009-08-03 13:43:58 +0100 | [diff] [blame] | 542 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 543 | DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n", |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 544 | crtc_req->count_connectors); |
| 545 | ret = -EINVAL; |
| 546 | goto out; |
| 547 | } |
| 548 | |
| 549 | if (crtc_req->count_connectors > 0) { |
| 550 | u32 out_id; |
| 551 | |
| 552 | /* Avoid unbounded kernel memory allocation */ |
| 553 | if (crtc_req->count_connectors > config->num_connector) { |
| 554 | ret = -EINVAL; |
| 555 | goto out; |
| 556 | } |
| 557 | |
Thierry Reding | 2f6c538 | 2014-12-10 13:03:36 +0100 | [diff] [blame] | 558 | connector_set = kmalloc_array(crtc_req->count_connectors, |
| 559 | sizeof(struct drm_connector *), |
| 560 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 561 | if (!connector_set) { |
| 562 | ret = -ENOMEM; |
| 563 | goto out; |
| 564 | } |
| 565 | |
| 566 | for (i = 0; i < crtc_req->count_connectors; i++) { |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 567 | connector_set[i] = NULL; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 568 | set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 569 | if (get_user(out_id, &set_connectors_ptr[i])) { |
| 570 | ret = -EFAULT; |
| 571 | goto out; |
| 572 | } |
| 573 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 574 | connector = drm_connector_lookup(dev, out_id); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 575 | if (!connector) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 576 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
| 577 | out_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 578 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 579 | goto out; |
| 580 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 581 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 582 | connector->base.id, |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 583 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 584 | |
| 585 | connector_set[i] = connector; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | set.crtc = crtc; |
| 590 | set.x = crtc_req->x; |
| 591 | set.y = crtc_req->y; |
| 592 | set.mode = mode; |
| 593 | set.connectors = connector_set; |
| 594 | set.num_connectors = crtc_req->count_connectors; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 595 | set.fb = fb; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 596 | ret = drm_mode_set_config_internal(&set); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 597 | |
| 598 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 599 | if (fb) |
| 600 | drm_framebuffer_unreference(fb); |
| 601 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 602 | if (connector_set) { |
| 603 | for (i = 0; i < crtc_req->count_connectors; i++) { |
| 604 | if (connector_set[i]) |
| 605 | drm_connector_unreference(connector_set[i]); |
| 606 | } |
| 607 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 608 | kfree(connector_set); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 609 | drm_mode_destroy(dev, mode); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 610 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 611 | return ret; |
| 612 | } |
| 613 | |
Daniel Vetter | 949619f | 2016-08-29 10:27:51 +0200 | [diff] [blame] | 614 | int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
| 615 | struct drm_property *property, |
| 616 | uint64_t value) |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 617 | { |
| 618 | int ret = -EINVAL; |
| 619 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 620 | |
| 621 | if (crtc->funcs->set_property) |
| 622 | ret = crtc->funcs->set_property(crtc, property, value); |
| 623 | if (!ret) |
| 624 | drm_object_property_set_value(obj, property, value); |
| 625 | |
| 626 | return ret; |
| 627 | } |
| 628 | |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 629 | /** |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 630 | * DOC: Tile group |
| 631 | * |
| 632 | * Tile groups are used to represent tiled monitors with a unique |
| 633 | * integer identifier. Tiled monitors using DisplayID v1.3 have |
| 634 | * a unique 8-byte handle, we store this in a tile group, so we |
| 635 | * have a common identifier for all tiles in a monitor group. |
| 636 | */ |
| 637 | static void drm_tile_group_free(struct kref *kref) |
| 638 | { |
| 639 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
| 640 | struct drm_device *dev = tg->dev; |
| 641 | mutex_lock(&dev->mode_config.idr_mutex); |
| 642 | idr_remove(&dev->mode_config.tile_idr, tg->id); |
| 643 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 644 | kfree(tg); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * drm_mode_put_tile_group - drop a reference to a tile group. |
| 649 | * @dev: DRM device |
| 650 | * @tg: tile group to drop reference to. |
| 651 | * |
| 652 | * drop reference to tile group and free if 0. |
| 653 | */ |
| 654 | void drm_mode_put_tile_group(struct drm_device *dev, |
| 655 | struct drm_tile_group *tg) |
| 656 | { |
| 657 | kref_put(&tg->refcount, drm_tile_group_free); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * drm_mode_get_tile_group - get a reference to an existing tile group |
| 662 | * @dev: DRM device |
| 663 | * @topology: 8-bytes unique per monitor. |
| 664 | * |
| 665 | * Use the unique bytes to get a reference to an existing tile group. |
| 666 | * |
| 667 | * RETURNS: |
| 668 | * tile group or NULL if not found. |
| 669 | */ |
| 670 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
| 671 | char topology[8]) |
| 672 | { |
| 673 | struct drm_tile_group *tg; |
| 674 | int id; |
| 675 | mutex_lock(&dev->mode_config.idr_mutex); |
| 676 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
| 677 | if (!memcmp(tg->group_data, topology, 8)) { |
| 678 | if (!kref_get_unless_zero(&tg->refcount)) |
| 679 | tg = NULL; |
| 680 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 681 | return tg; |
| 682 | } |
| 683 | } |
| 684 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 685 | return NULL; |
| 686 | } |
Rob Clark | 81ddd1b | 2015-03-27 13:01:52 -0400 | [diff] [blame] | 687 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 688 | |
| 689 | /** |
| 690 | * drm_mode_create_tile_group - create a tile group from a displayid description |
| 691 | * @dev: DRM device |
| 692 | * @topology: 8-bytes unique per monitor. |
| 693 | * |
| 694 | * Create a tile group for the unique monitor, and get a unique |
| 695 | * identifier for the tile group. |
| 696 | * |
| 697 | * RETURNS: |
| 698 | * new tile group or error. |
| 699 | */ |
| 700 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
| 701 | char topology[8]) |
| 702 | { |
| 703 | struct drm_tile_group *tg; |
| 704 | int ret; |
| 705 | |
| 706 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
| 707 | if (!tg) |
| 708 | return ERR_PTR(-ENOMEM); |
| 709 | |
| 710 | kref_init(&tg->refcount); |
| 711 | memcpy(tg->group_data, topology, 8); |
| 712 | tg->dev = dev; |
| 713 | |
| 714 | mutex_lock(&dev->mode_config.idr_mutex); |
| 715 | ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); |
| 716 | if (ret >= 0) { |
| 717 | tg->id = ret; |
| 718 | } else { |
| 719 | kfree(tg); |
| 720 | tg = ERR_PTR(ret); |
| 721 | } |
| 722 | |
| 723 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 724 | return tg; |
| 725 | } |
Rob Clark | 81ddd1b | 2015-03-27 13:01:52 -0400 | [diff] [blame] | 726 | EXPORT_SYMBOL(drm_mode_create_tile_group); |