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> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 41 | |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 42 | #include "drm_crtc_internal.h" |
| 43 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 44 | static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev, |
| 45 | struct drm_mode_fb_cmd2 *r, |
| 46 | struct drm_file *file_priv); |
| 47 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 48 | /** |
| 49 | * drm_modeset_lock_all - take all modeset locks |
| 50 | * @dev: drm device |
| 51 | * |
| 52 | * This function takes all modeset locks, suitable where a more fine-grained |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 53 | * scheme isn't (yet) implemented. Locks must be dropped with |
| 54 | * drm_modeset_unlock_all. |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 55 | */ |
| 56 | void drm_modeset_lock_all(struct drm_device *dev) |
| 57 | { |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 58 | struct drm_mode_config *config = &dev->mode_config; |
| 59 | struct drm_modeset_acquire_ctx *ctx; |
| 60 | int ret; |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 61 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 62 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 63 | if (WARN_ON(!ctx)) |
| 64 | return; |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 65 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 66 | mutex_lock(&config->mutex); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 67 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 68 | drm_modeset_acquire_init(ctx, 0); |
| 69 | |
| 70 | retry: |
| 71 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 72 | if (ret) |
| 73 | goto fail; |
| 74 | ret = drm_modeset_lock_all_crtcs(dev, ctx); |
| 75 | if (ret) |
| 76 | goto fail; |
| 77 | |
| 78 | WARN_ON(config->acquire_ctx); |
| 79 | |
| 80 | /* now we hold the locks, so now that it is safe, stash the |
| 81 | * ctx for drm_modeset_unlock_all(): |
| 82 | */ |
| 83 | config->acquire_ctx = ctx; |
| 84 | |
| 85 | drm_warn_on_modeset_not_all_locked(dev); |
| 86 | |
| 87 | return; |
| 88 | |
| 89 | fail: |
| 90 | if (ret == -EDEADLK) { |
| 91 | drm_modeset_backoff(ctx); |
| 92 | goto retry; |
| 93 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 94 | } |
| 95 | EXPORT_SYMBOL(drm_modeset_lock_all); |
| 96 | |
| 97 | /** |
| 98 | * drm_modeset_unlock_all - drop all modeset locks |
| 99 | * @dev: device |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 100 | * |
| 101 | * This function drop all modeset locks taken by drm_modeset_lock_all. |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 102 | */ |
| 103 | void drm_modeset_unlock_all(struct drm_device *dev) |
| 104 | { |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 105 | struct drm_mode_config *config = &dev->mode_config; |
| 106 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 107 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 108 | if (WARN_ON(!ctx)) |
| 109 | return; |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 110 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 111 | config->acquire_ctx = NULL; |
| 112 | drm_modeset_drop_locks(ctx); |
| 113 | drm_modeset_acquire_fini(ctx); |
| 114 | |
| 115 | kfree(ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 116 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 117 | mutex_unlock(&dev->mode_config.mutex); |
| 118 | } |
| 119 | EXPORT_SYMBOL(drm_modeset_unlock_all); |
| 120 | |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 121 | /** |
| 122 | * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked |
| 123 | * @dev: device |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 124 | * |
| 125 | * Useful as a debug assert. |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 126 | */ |
| 127 | void drm_warn_on_modeset_not_all_locked(struct drm_device *dev) |
| 128 | { |
| 129 | struct drm_crtc *crtc; |
| 130 | |
Daniel Vetter | a9b054e | 2013-05-02 09:43:05 +0200 | [diff] [blame] | 131 | /* Locking is currently fubar in the panic handler. */ |
| 132 | if (oops_in_progress) |
| 133 | return; |
| 134 | |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 135 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 136 | WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 137 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 138 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 139 | WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); |
| 140 | } |
| 141 | EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked); |
| 142 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 143 | /* Avoid boilerplate. I'm tired of typing. */ |
| 144 | #define DRM_ENUM_NAME_FN(fnname, list) \ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 145 | const char *fnname(int val) \ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 146 | { \ |
| 147 | int i; \ |
| 148 | for (i = 0; i < ARRAY_SIZE(list); i++) { \ |
| 149 | if (list[i].type == val) \ |
| 150 | return list[i].name; \ |
| 151 | } \ |
| 152 | return "(unknown)"; \ |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * Global properties |
| 157 | */ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 158 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 159 | { { DRM_MODE_DPMS_ON, "On" }, |
| 160 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
| 161 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
| 162 | { DRM_MODE_DPMS_OFF, "Off" } |
| 163 | }; |
| 164 | |
| 165 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
| 166 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 167 | static const struct drm_prop_enum_list drm_plane_type_enum_list[] = |
| 168 | { |
| 169 | { DRM_PLANE_TYPE_OVERLAY, "Overlay" }, |
| 170 | { DRM_PLANE_TYPE_PRIMARY, "Primary" }, |
| 171 | { DRM_PLANE_TYPE_CURSOR, "Cursor" }, |
| 172 | }; |
| 173 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 174 | /* |
| 175 | * Optional properties |
| 176 | */ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 177 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 178 | { |
Jesse Barnes | 53bd838 | 2009-07-01 10:04:40 -0700 | [diff] [blame] | 179 | { DRM_MODE_SCALE_NONE, "None" }, |
| 180 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
| 181 | { DRM_MODE_SCALE_CENTER, "Center" }, |
| 182 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 183 | }; |
| 184 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 185 | /* |
| 186 | * Non-global properties, but "required" for certain connectors. |
| 187 | */ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 188 | static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 189 | { |
| 190 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 191 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 192 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 193 | }; |
| 194 | |
| 195 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
| 196 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 197 | static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 198 | { |
| 199 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 200 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 201 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 202 | }; |
| 203 | |
| 204 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
| 205 | drm_dvi_i_subconnector_enum_list) |
| 206 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 207 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 208 | { |
| 209 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 210 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 211 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 212 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 213 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
| 217 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 218 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 219 | { |
| 220 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 221 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 222 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 223 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 224 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
| 228 | drm_tv_subconnector_enum_list) |
| 229 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 230 | static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = { |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 231 | { DRM_MODE_DIRTY_OFF, "Off" }, |
| 232 | { DRM_MODE_DIRTY_ON, "On" }, |
| 233 | { DRM_MODE_DIRTY_ANNOTATE, "Annotate" }, |
| 234 | }; |
| 235 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 236 | struct drm_conn_prop_enum_list { |
| 237 | int type; |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 238 | const char *name; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 239 | struct ida ida; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | /* |
| 243 | * Connector and encoder types. |
| 244 | */ |
| 245 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 246 | { { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
| 247 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
| 248 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
| 249 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
| 250 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
| 251 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
| 252 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
| 253 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
| 254 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
| 255 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
| 256 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
| 257 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
| 258 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
| 259 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
| 260 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
| 261 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
Shobhit Kumar | b892327 | 2013-08-27 15:12:13 +0300 | [diff] [blame] | 262 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 263 | }; |
| 264 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 265 | static const struct drm_prop_enum_list drm_encoder_enum_list[] = |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 266 | { { DRM_MODE_ENCODER_NONE, "None" }, |
| 267 | { DRM_MODE_ENCODER_DAC, "DAC" }, |
| 268 | { DRM_MODE_ENCODER_TMDS, "TMDS" }, |
| 269 | { DRM_MODE_ENCODER_LVDS, "LVDS" }, |
| 270 | { DRM_MODE_ENCODER_TVDAC, "TV" }, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 271 | { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, |
Shobhit Kumar | b892327 | 2013-08-27 15:12:13 +0300 | [diff] [blame] | 272 | { DRM_MODE_ENCODER_DSI, "DSI" }, |
Dave Airlie | 182407a | 2014-05-02 11:09:54 +1000 | [diff] [blame] | 273 | { DRM_MODE_ENCODER_DPMST, "DP MST" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 274 | }; |
| 275 | |
Jesse Barnes | ac1bb36 | 2014-02-10 15:32:44 -0800 | [diff] [blame] | 276 | static const struct drm_prop_enum_list drm_subpixel_enum_list[] = |
| 277 | { |
| 278 | { SubPixelUnknown, "Unknown" }, |
| 279 | { SubPixelHorizontalRGB, "Horizontal RGB" }, |
| 280 | { SubPixelHorizontalBGR, "Horizontal BGR" }, |
| 281 | { SubPixelVerticalRGB, "Vertical RGB" }, |
| 282 | { SubPixelVerticalBGR, "Vertical BGR" }, |
| 283 | { SubPixelNone, "None" }, |
| 284 | }; |
| 285 | |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 286 | void drm_connector_ida_init(void) |
| 287 | { |
| 288 | int i; |
| 289 | |
| 290 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 291 | ida_init(&drm_connector_enum_list[i].ida); |
| 292 | } |
| 293 | |
| 294 | void drm_connector_ida_destroy(void) |
| 295 | { |
| 296 | int i; |
| 297 | |
| 298 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 299 | ida_destroy(&drm_connector_enum_list[i].ida); |
| 300 | } |
| 301 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 302 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 303 | * drm_get_connector_status_name - return a string for connector status |
| 304 | * @status: connector status to compute name of |
| 305 | * |
| 306 | * In contrast to the other drm_get_*_name functions this one here returns a |
| 307 | * const pointer and hence is threadsafe. |
| 308 | */ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 309 | const char *drm_get_connector_status_name(enum drm_connector_status status) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 310 | { |
| 311 | if (status == connector_status_connected) |
| 312 | return "connected"; |
| 313 | else if (status == connector_status_disconnected) |
| 314 | return "disconnected"; |
| 315 | else |
| 316 | return "unknown"; |
| 317 | } |
Lespiau, Damien | ed7951d | 2013-05-10 12:36:42 +0000 | [diff] [blame] | 318 | EXPORT_SYMBOL(drm_get_connector_status_name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 319 | |
Jesse Barnes | ac1bb36 | 2014-02-10 15:32:44 -0800 | [diff] [blame] | 320 | /** |
| 321 | * drm_get_subpixel_order_name - return a string for a given subpixel enum |
| 322 | * @order: enum of subpixel_order |
| 323 | * |
| 324 | * Note you could abuse this and return something out of bounds, but that |
| 325 | * would be a caller error. No unscrubbed user data should make it here. |
| 326 | */ |
| 327 | const char *drm_get_subpixel_order_name(enum subpixel_order order) |
| 328 | { |
| 329 | return drm_subpixel_enum_list[order].name; |
| 330 | } |
| 331 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
| 332 | |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 333 | static char printable_char(int c) |
| 334 | { |
| 335 | return isascii(c) && isprint(c) ? c : '?'; |
| 336 | } |
| 337 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 338 | /** |
| 339 | * drm_get_format_name - return a string for drm fourcc format |
| 340 | * @format: format to compute name of |
| 341 | * |
| 342 | * Note that the buffer used by this function is globally shared and owned by |
| 343 | * the function itself. |
| 344 | * |
| 345 | * FIXME: This isn't really multithreading safe. |
| 346 | */ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 347 | const char *drm_get_format_name(uint32_t format) |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 348 | { |
| 349 | static char buf[32]; |
| 350 | |
| 351 | snprintf(buf, sizeof(buf), |
| 352 | "%c%c%c%c %s-endian (0x%08x)", |
| 353 | printable_char(format & 0xff), |
| 354 | printable_char((format >> 8) & 0xff), |
| 355 | printable_char((format >> 16) & 0xff), |
| 356 | printable_char((format >> 24) & 0x7f), |
| 357 | format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", |
| 358 | format); |
| 359 | |
| 360 | return buf; |
| 361 | } |
| 362 | EXPORT_SYMBOL(drm_get_format_name); |
| 363 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 364 | /** |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 365 | * drm_mode_object_get - allocate a new modeset identifier |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 366 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 367 | * @obj: object pointer, used to generate unique ID |
| 368 | * @obj_type: object type |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 369 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 370 | * Create a unique identifier based on @ptr in @dev's identifier space. Used |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 371 | * for tracking modes, CRTCs and connectors. Note that despite the _get postfix |
| 372 | * modeset identifiers are _not_ reference counted. Hence don't use this for |
| 373 | * reference counted modeset objects like framebuffers. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 374 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 375 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 376 | * New unique (relative to other objects in @dev) integer identifier for the |
| 377 | * object. |
| 378 | */ |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 379 | int drm_mode_object_get(struct drm_device *dev, |
| 380 | struct drm_mode_object *obj, uint32_t obj_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 381 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 382 | int ret; |
| 383 | |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 384 | mutex_lock(&dev->mode_config.idr_mutex); |
Tejun Heo | 2e92881 | 2013-02-27 17:04:08 -0800 | [diff] [blame] | 385 | ret = idr_alloc(&dev->mode_config.crtc_idr, obj, 1, 0, GFP_KERNEL); |
| 386 | if (ret >= 0) { |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 387 | /* |
| 388 | * Set up the object linking under the protection of the idr |
| 389 | * lock so that other users can't see inconsistent state. |
| 390 | */ |
Tejun Heo | 2e92881 | 2013-02-27 17:04:08 -0800 | [diff] [blame] | 391 | obj->id = ret; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 392 | obj->type = obj_type; |
| 393 | } |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 394 | mutex_unlock(&dev->mode_config.idr_mutex); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 395 | |
Tejun Heo | 2e92881 | 2013-02-27 17:04:08 -0800 | [diff] [blame] | 396 | return ret < 0 ? ret : 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /** |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 400 | * drm_mode_object_put - free a modeset identifer |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 401 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 402 | * @object: object to free |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 403 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 404 | * Free @id from @dev's unique identifier pool. Note that despite the _get |
| 405 | * postfix modeset identifiers are _not_ reference counted. Hence don't use this |
| 406 | * for reference counted modeset objects like framebuffers. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 407 | */ |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 408 | void drm_mode_object_put(struct drm_device *dev, |
| 409 | struct drm_mode_object *object) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 410 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 411 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 412 | idr_remove(&dev->mode_config.crtc_idr, object->id); |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 413 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 416 | static struct drm_mode_object *_object_find(struct drm_device *dev, |
| 417 | uint32_t id, uint32_t type) |
| 418 | { |
| 419 | struct drm_mode_object *obj = NULL; |
| 420 | |
| 421 | mutex_lock(&dev->mode_config.idr_mutex); |
| 422 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
| 423 | if (!obj || (type != DRM_MODE_OBJECT_ANY && obj->type != type) || |
| 424 | (obj->id != id)) |
| 425 | obj = NULL; |
| 426 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 427 | |
| 428 | return obj; |
| 429 | } |
| 430 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 431 | /** |
| 432 | * drm_mode_object_find - look up a drm object with static lifetime |
| 433 | * @dev: drm device |
| 434 | * @id: id of the mode object |
| 435 | * @type: type of the mode object |
| 436 | * |
| 437 | * Note that framebuffers cannot be looked up with this functions - since those |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 438 | * are reference counted, they need special treatment. Even with |
| 439 | * DRM_MODE_OBJECT_ANY (although that will simply return NULL |
| 440 | * rather than WARN_ON()). |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 441 | */ |
Daniel Vetter | 7a9c906 | 2009-09-15 22:57:31 +0200 | [diff] [blame] | 442 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
| 443 | uint32_t id, uint32_t type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 444 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 445 | struct drm_mode_object *obj = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 446 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 447 | /* Framebuffers are reference counted and need their own lookup |
| 448 | * function.*/ |
| 449 | WARN_ON(type == DRM_MODE_OBJECT_FB); |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 450 | obj = _object_find(dev, id, type); |
| 451 | /* don't leak out unref'd fb's */ |
| 452 | if (obj && (obj->type == DRM_MODE_OBJECT_FB)) |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 453 | obj = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 454 | return obj; |
| 455 | } |
| 456 | EXPORT_SYMBOL(drm_mode_object_find); |
| 457 | |
| 458 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 459 | * drm_framebuffer_init - initialize a framebuffer |
| 460 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 461 | * @fb: framebuffer to be initialized |
| 462 | * @funcs: ... with these functions |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 463 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 464 | * Allocates an ID for the framebuffer's parent mode object, sets its mode |
| 465 | * functions & device file and adds it to the master fd list. |
| 466 | * |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 467 | * IMPORTANT: |
| 468 | * This functions publishes the fb and makes it available for concurrent access |
| 469 | * by other users. Which means by this point the fb _must_ be fully set up - |
| 470 | * since all the fb attributes are invariant over its lifetime, no further |
| 471 | * locking but only correct reference counting is required. |
| 472 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 473 | * Returns: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 474 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 475 | */ |
| 476 | int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, |
| 477 | const struct drm_framebuffer_funcs *funcs) |
| 478 | { |
| 479 | int ret; |
| 480 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 481 | mutex_lock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 482 | kref_init(&fb->refcount); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 483 | INIT_LIST_HEAD(&fb->filp_head); |
| 484 | fb->dev = dev; |
| 485 | fb->funcs = funcs; |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 486 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 487 | ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 488 | if (ret) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 489 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 490 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 491 | /* Grab the idr reference. */ |
| 492 | drm_framebuffer_reference(fb); |
| 493 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 494 | dev->mode_config.num_fb++; |
| 495 | list_add(&fb->head, &dev->mode_config.fb_list); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 496 | out: |
| 497 | mutex_unlock(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | EXPORT_SYMBOL(drm_framebuffer_init); |
| 502 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 503 | static void drm_framebuffer_free(struct kref *kref) |
| 504 | { |
| 505 | struct drm_framebuffer *fb = |
| 506 | container_of(kref, struct drm_framebuffer, refcount); |
| 507 | fb->funcs->destroy(fb); |
| 508 | } |
| 509 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 510 | static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev, |
| 511 | uint32_t id) |
| 512 | { |
| 513 | struct drm_mode_object *obj = NULL; |
| 514 | struct drm_framebuffer *fb; |
| 515 | |
| 516 | mutex_lock(&dev->mode_config.idr_mutex); |
| 517 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
| 518 | if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id)) |
| 519 | fb = NULL; |
| 520 | else |
| 521 | fb = obj_to_fb(obj); |
| 522 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 523 | |
| 524 | return fb; |
| 525 | } |
| 526 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 527 | /** |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 528 | * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference |
| 529 | * @dev: drm device |
| 530 | * @id: id of the fb object |
| 531 | * |
| 532 | * If successful, this grabs an additional reference to the framebuffer - |
| 533 | * callers need to make sure to eventually unreference the returned framebuffer |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 534 | * again, using @drm_framebuffer_unreference. |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 535 | */ |
| 536 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
| 537 | uint32_t id) |
| 538 | { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 539 | struct drm_framebuffer *fb; |
| 540 | |
| 541 | mutex_lock(&dev->mode_config.fb_lock); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 542 | fb = __drm_framebuffer_lookup(dev, id); |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 543 | if (fb) |
archit taneja | 9131d3d | 2013-04-10 08:59:39 +0000 | [diff] [blame] | 544 | drm_framebuffer_reference(fb); |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 545 | mutex_unlock(&dev->mode_config.fb_lock); |
| 546 | |
| 547 | return fb; |
| 548 | } |
| 549 | EXPORT_SYMBOL(drm_framebuffer_lookup); |
| 550 | |
| 551 | /** |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 552 | * drm_framebuffer_unreference - unref a framebuffer |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 553 | * @fb: framebuffer to unref |
| 554 | * |
| 555 | * This functions decrements the fb's refcount and frees it if it drops to zero. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 556 | */ |
| 557 | void drm_framebuffer_unreference(struct drm_framebuffer *fb) |
| 558 | { |
Rob Clark | 8291272 | 2014-03-18 10:07:08 -0400 | [diff] [blame] | 559 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 560 | kref_put(&fb->refcount, drm_framebuffer_free); |
| 561 | } |
| 562 | EXPORT_SYMBOL(drm_framebuffer_unreference); |
| 563 | |
| 564 | /** |
| 565 | * drm_framebuffer_reference - incr the fb refcnt |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 566 | * @fb: framebuffer |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 567 | * |
| 568 | * This functions increments the fb's refcount. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 569 | */ |
| 570 | void drm_framebuffer_reference(struct drm_framebuffer *fb) |
| 571 | { |
Rob Clark | 8291272 | 2014-03-18 10:07:08 -0400 | [diff] [blame] | 572 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 573 | kref_get(&fb->refcount); |
| 574 | } |
| 575 | EXPORT_SYMBOL(drm_framebuffer_reference); |
| 576 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 577 | static void drm_framebuffer_free_bug(struct kref *kref) |
| 578 | { |
| 579 | BUG(); |
| 580 | } |
| 581 | |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 582 | static void __drm_framebuffer_unreference(struct drm_framebuffer *fb) |
| 583 | { |
Rob Clark | 8291272 | 2014-03-18 10:07:08 -0400 | [diff] [blame] | 584 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 585 | kref_put(&fb->refcount, drm_framebuffer_free_bug); |
| 586 | } |
| 587 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 588 | /* dev->mode_config.fb_lock must be held! */ |
| 589 | static void __drm_framebuffer_unregister(struct drm_device *dev, |
| 590 | struct drm_framebuffer *fb) |
| 591 | { |
| 592 | mutex_lock(&dev->mode_config.idr_mutex); |
| 593 | idr_remove(&dev->mode_config.crtc_idr, fb->base.id); |
| 594 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 595 | |
| 596 | fb->base.id = 0; |
| 597 | |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 598 | __drm_framebuffer_unreference(fb); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 599 | } |
| 600 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 601 | /** |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 602 | * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr |
| 603 | * @fb: fb to unregister |
| 604 | * |
| 605 | * Drivers need to call this when cleaning up driver-private framebuffers, e.g. |
| 606 | * those used for fbdev. Note that the caller must hold a reference of it's own, |
| 607 | * i.e. the object may not be destroyed through this call (since it'll lead to a |
| 608 | * locking inversion). |
| 609 | */ |
| 610 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) |
| 611 | { |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 612 | struct drm_device *dev = fb->dev; |
| 613 | |
| 614 | mutex_lock(&dev->mode_config.fb_lock); |
| 615 | /* Mark fb as reaped and drop idr ref. */ |
| 616 | __drm_framebuffer_unregister(dev, fb); |
| 617 | mutex_unlock(&dev->mode_config.fb_lock); |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 618 | } |
| 619 | EXPORT_SYMBOL(drm_framebuffer_unregister_private); |
| 620 | |
| 621 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 622 | * drm_framebuffer_cleanup - remove a framebuffer object |
| 623 | * @fb: framebuffer to remove |
| 624 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 625 | * Cleanup framebuffer. This function is intended to be used from the drivers |
| 626 | * ->destroy callback. It can also be used to clean up driver private |
| 627 | * framebuffers embedded into a larger structure. |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 628 | * |
| 629 | * Note that this function does not remove the fb from active usuage - if it is |
| 630 | * still used anywhere, hilarity can ensue since userspace could call getfb on |
| 631 | * the id and get back -EINVAL. Obviously no concern at driver unload time. |
| 632 | * |
| 633 | * Also, the framebuffer will not be removed from the lookup idr - for |
| 634 | * user-created framebuffers this will happen in in the rmfb ioctl. For |
| 635 | * driver-private objects (e.g. for fbdev) drivers need to explicitly call |
| 636 | * drm_framebuffer_unregister_private. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 637 | */ |
| 638 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb) |
| 639 | { |
| 640 | struct drm_device *dev = fb->dev; |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 641 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 642 | mutex_lock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 643 | list_del(&fb->head); |
| 644 | dev->mode_config.num_fb--; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 645 | mutex_unlock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 646 | } |
| 647 | EXPORT_SYMBOL(drm_framebuffer_cleanup); |
| 648 | |
| 649 | /** |
| 650 | * drm_framebuffer_remove - remove and unreference a framebuffer object |
| 651 | * @fb: framebuffer to remove |
| 652 | * |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 653 | * Scans all the CRTCs and planes in @dev's mode_config. If they're |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 654 | * using @fb, removes it, setting it to NULL. Then drops the reference to the |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 655 | * passed-in framebuffer. Might take the modeset locks. |
| 656 | * |
| 657 | * Note that this function optimizes the cleanup away if the caller holds the |
| 658 | * last reference to the framebuffer. It is also guaranteed to not take the |
| 659 | * modeset locks in this case. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 660 | */ |
| 661 | void drm_framebuffer_remove(struct drm_framebuffer *fb) |
| 662 | { |
| 663 | struct drm_device *dev = fb->dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 664 | struct drm_crtc *crtc; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 665 | struct drm_plane *plane; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 666 | struct drm_mode_set set; |
| 667 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 668 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 669 | WARN_ON(!list_empty(&fb->filp_head)); |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 670 | |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 671 | /* |
| 672 | * drm ABI mandates that we remove any deleted framebuffers from active |
| 673 | * useage. But since most sane clients only remove framebuffers they no |
| 674 | * longer need, try to optimize this away. |
| 675 | * |
| 676 | * Since we're holding a reference ourselves, observing a refcount of 1 |
| 677 | * means that we're the last holder and can skip it. Also, the refcount |
| 678 | * can never increase from 1 again, so we don't need any barriers or |
| 679 | * locks. |
| 680 | * |
| 681 | * Note that userspace could try to race with use and instate a new |
| 682 | * usage _after_ we've cleared all current ones. End result will be an |
| 683 | * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot |
| 684 | * in this manner. |
| 685 | */ |
| 686 | if (atomic_read(&fb->refcount.refcount) > 1) { |
| 687 | drm_modeset_lock_all(dev); |
| 688 | /* remove from any CRTC */ |
| 689 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 690 | if (crtc->primary->fb == fb) { |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 691 | /* should turn off the crtc */ |
| 692 | memset(&set, 0, sizeof(struct drm_mode_set)); |
| 693 | set.crtc = crtc; |
| 694 | set.fb = NULL; |
| 695 | ret = drm_mode_set_config_internal(&set); |
| 696 | if (ret) |
| 697 | DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); |
| 698 | } |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 699 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 700 | |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 701 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 702 | if (plane->fb == fb) |
| 703 | drm_plane_force_disable(plane); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 704 | } |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 705 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 706 | } |
| 707 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 708 | drm_framebuffer_unreference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 709 | } |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 710 | EXPORT_SYMBOL(drm_framebuffer_remove); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 711 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 712 | DEFINE_WW_CLASS(crtc_ww_class); |
| 713 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 714 | /** |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 715 | * drm_crtc_init_with_planes - Initialise a new CRTC object with |
| 716 | * specified primary and cursor planes. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 717 | * @dev: DRM device |
| 718 | * @crtc: CRTC object to init |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 719 | * @primary: Primary plane for CRTC |
| 720 | * @cursor: Cursor plane for CRTC |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 721 | * @funcs: callbacks for the new CRTC |
| 722 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 723 | * Inits a new object created as base part of a driver crtc object. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 724 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 725 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 726 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 727 | */ |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 728 | int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, |
| 729 | struct drm_plane *primary, |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame^] | 730 | struct drm_plane *cursor, |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 731 | const struct drm_crtc_funcs *funcs) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 732 | { |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 733 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 734 | int ret; |
| 735 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 736 | crtc->dev = dev; |
| 737 | crtc->funcs = funcs; |
Rob Clark | 7c80e12 | 2012-09-04 16:35:56 +0000 | [diff] [blame] | 738 | crtc->invert_dimensions = false; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 739 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 740 | drm_modeset_lock_all(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 741 | drm_modeset_lock_init(&crtc->mutex); |
| 742 | /* dropped by _unlock_all(): */ |
| 743 | drm_modeset_lock(&crtc->mutex, config->acquire_ctx); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 744 | |
| 745 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
| 746 | if (ret) |
| 747 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 748 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 749 | crtc->base.properties = &crtc->properties; |
| 750 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 751 | list_add_tail(&crtc->head, &config->crtc_list); |
| 752 | config->num_crtc++; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 753 | |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 754 | crtc->primary = primary; |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame^] | 755 | crtc->cursor = cursor; |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 756 | if (primary) |
| 757 | primary->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame^] | 758 | if (cursor) |
| 759 | cursor->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 760 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 761 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 762 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 763 | |
| 764 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 765 | } |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 766 | EXPORT_SYMBOL(drm_crtc_init_with_planes); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 767 | |
| 768 | /** |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 769 | * drm_crtc_cleanup - Clean up the core crtc usage |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 770 | * @crtc: CRTC to cleanup |
| 771 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 772 | * This function cleans up @crtc and removes it from the DRM mode setting |
| 773 | * core. Note that the function does *not* free the crtc structure itself, |
| 774 | * this is the responsibility of the caller. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 775 | */ |
| 776 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
| 777 | { |
| 778 | struct drm_device *dev = crtc->dev; |
| 779 | |
Sachin Kamat | 9e1c156 | 2012-11-19 09:44:56 +0000 | [diff] [blame] | 780 | kfree(crtc->gamma_store); |
| 781 | crtc->gamma_store = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 782 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 783 | drm_modeset_lock_fini(&crtc->mutex); |
| 784 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 785 | drm_mode_object_put(dev, &crtc->base); |
| 786 | list_del(&crtc->head); |
| 787 | dev->mode_config.num_crtc--; |
| 788 | } |
| 789 | EXPORT_SYMBOL(drm_crtc_cleanup); |
| 790 | |
| 791 | /** |
Russell King | db5f7a6 | 2014-01-02 21:27:33 +0000 | [diff] [blame] | 792 | * drm_crtc_index - find the index of a registered CRTC |
| 793 | * @crtc: CRTC to find index for |
| 794 | * |
| 795 | * Given a registered CRTC, return the index of that CRTC within a DRM |
| 796 | * device's list of CRTCs. |
| 797 | */ |
| 798 | unsigned int drm_crtc_index(struct drm_crtc *crtc) |
| 799 | { |
| 800 | unsigned int index = 0; |
| 801 | struct drm_crtc *tmp; |
| 802 | |
| 803 | list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) { |
| 804 | if (tmp == crtc) |
| 805 | return index; |
| 806 | |
| 807 | index++; |
| 808 | } |
| 809 | |
| 810 | BUG(); |
| 811 | } |
| 812 | EXPORT_SYMBOL(drm_crtc_index); |
| 813 | |
Lespiau, Damien | 86f422d | 2013-08-20 00:53:06 +0100 | [diff] [blame] | 814 | /* |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 815 | * drm_mode_remove - remove and free a mode |
| 816 | * @connector: connector list to modify |
| 817 | * @mode: mode to remove |
| 818 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 819 | * Remove @mode from @connector's mode list, then free it. |
| 820 | */ |
Lespiau, Damien | 86f422d | 2013-08-20 00:53:06 +0100 | [diff] [blame] | 821 | static void drm_mode_remove(struct drm_connector *connector, |
| 822 | struct drm_display_mode *mode) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 823 | { |
| 824 | list_del(&mode->head); |
Sascha Hauer | 554f1d7 | 2012-02-01 11:38:19 +0100 | [diff] [blame] | 825 | drm_mode_destroy(connector->dev, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 826 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 827 | |
| 828 | /** |
| 829 | * drm_connector_init - Init a preallocated connector |
| 830 | * @dev: DRM device |
| 831 | * @connector: the connector to init |
| 832 | * @funcs: callbacks for this connector |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 833 | * @connector_type: user visible type of the connector |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 834 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 835 | * Initialises a preallocated connector. Connectors should be |
| 836 | * subclassed as part of driver connector objects. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 837 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 838 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 839 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 840 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 841 | int drm_connector_init(struct drm_device *dev, |
| 842 | struct drm_connector *connector, |
| 843 | const struct drm_connector_funcs *funcs, |
| 844 | int connector_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 845 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 846 | int ret; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 847 | struct ida *connector_ida = |
| 848 | &drm_connector_enum_list[connector_type].ida; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 849 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 850 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 851 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 852 | ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR); |
| 853 | if (ret) |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 854 | goto out_unlock; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 855 | |
Paulo Zanoni | 7e3bdf4 | 2012-05-15 18:09:01 -0300 | [diff] [blame] | 856 | connector->base.properties = &connector->properties; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 857 | connector->dev = dev; |
| 858 | connector->funcs = funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 859 | connector->connector_type = connector_type; |
| 860 | connector->connector_type_id = |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 861 | ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); |
| 862 | if (connector->connector_type_id < 0) { |
| 863 | ret = connector->connector_type_id; |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 864 | goto out_put; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 865 | } |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 866 | connector->name = |
| 867 | kasprintf(GFP_KERNEL, "%s-%d", |
| 868 | drm_connector_enum_list[connector_type].name, |
| 869 | connector->connector_type_id); |
| 870 | if (!connector->name) { |
| 871 | ret = -ENOMEM; |
| 872 | goto out_put; |
| 873 | } |
| 874 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 875 | INIT_LIST_HEAD(&connector->probed_modes); |
| 876 | INIT_LIST_HEAD(&connector->modes); |
| 877 | connector->edid_blob_ptr = NULL; |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 878 | connector->status = connector_status_unknown; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 879 | |
| 880 | list_add_tail(&connector->head, &dev->mode_config.connector_list); |
| 881 | dev->mode_config.num_connector++; |
| 882 | |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 883 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 884 | drm_object_attach_property(&connector->base, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 885 | dev->mode_config.edid_property, |
| 886 | 0); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 887 | |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 888 | drm_object_attach_property(&connector->base, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 889 | dev->mode_config.dpms_property, 0); |
| 890 | |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 891 | out_put: |
| 892 | if (ret) |
| 893 | drm_mode_object_put(dev, &connector->base); |
| 894 | |
| 895 | out_unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 896 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 897 | |
| 898 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 899 | } |
| 900 | EXPORT_SYMBOL(drm_connector_init); |
| 901 | |
| 902 | /** |
| 903 | * drm_connector_cleanup - cleans up an initialised connector |
| 904 | * @connector: connector to cleanup |
| 905 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 906 | * Cleans up the connector but doesn't free the object. |
| 907 | */ |
| 908 | void drm_connector_cleanup(struct drm_connector *connector) |
| 909 | { |
| 910 | struct drm_device *dev = connector->dev; |
| 911 | struct drm_display_mode *mode, *t; |
| 912 | |
| 913 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
| 914 | drm_mode_remove(connector, mode); |
| 915 | |
| 916 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 917 | drm_mode_remove(connector, mode); |
| 918 | |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 919 | ida_remove(&drm_connector_enum_list[connector->connector_type].ida, |
| 920 | connector->connector_type_id); |
| 921 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 922 | drm_mode_object_put(dev, &connector->base); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 923 | kfree(connector->name); |
| 924 | connector->name = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 925 | list_del(&connector->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 926 | dev->mode_config.num_connector--; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 927 | } |
| 928 | EXPORT_SYMBOL(drm_connector_cleanup); |
| 929 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 930 | /** |
| 931 | * drm_connector_unplug_all - unregister connector userspace interfaces |
| 932 | * @dev: drm device |
| 933 | * |
| 934 | * This function unregisters all connector userspace interfaces in sysfs. Should |
| 935 | * be call when the device is disconnected, e.g. from an usb driver's |
| 936 | * ->disconnect callback. |
| 937 | */ |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 938 | void drm_connector_unplug_all(struct drm_device *dev) |
| 939 | { |
| 940 | struct drm_connector *connector; |
| 941 | |
| 942 | /* taking the mode config mutex ends up in a clash with sysfs */ |
| 943 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 944 | drm_sysfs_connector_remove(connector); |
| 945 | |
| 946 | } |
| 947 | EXPORT_SYMBOL(drm_connector_unplug_all); |
| 948 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 949 | /** |
| 950 | * drm_bridge_init - initialize a drm transcoder/bridge |
| 951 | * @dev: drm device |
| 952 | * @bridge: transcoder/bridge to set up |
| 953 | * @funcs: bridge function table |
| 954 | * |
| 955 | * Initialises a preallocated bridge. Bridges should be |
| 956 | * subclassed as part of driver connector objects. |
| 957 | * |
| 958 | * Returns: |
| 959 | * Zero on success, error code on failure. |
| 960 | */ |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 961 | int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge, |
| 962 | const struct drm_bridge_funcs *funcs) |
| 963 | { |
| 964 | int ret; |
| 965 | |
| 966 | drm_modeset_lock_all(dev); |
| 967 | |
| 968 | ret = drm_mode_object_get(dev, &bridge->base, DRM_MODE_OBJECT_BRIDGE); |
| 969 | if (ret) |
| 970 | goto out; |
| 971 | |
| 972 | bridge->dev = dev; |
| 973 | bridge->funcs = funcs; |
| 974 | |
| 975 | list_add_tail(&bridge->head, &dev->mode_config.bridge_list); |
| 976 | dev->mode_config.num_bridge++; |
| 977 | |
| 978 | out: |
| 979 | drm_modeset_unlock_all(dev); |
| 980 | return ret; |
| 981 | } |
| 982 | EXPORT_SYMBOL(drm_bridge_init); |
| 983 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 984 | /** |
| 985 | * drm_bridge_cleanup - cleans up an initialised bridge |
| 986 | * @bridge: bridge to cleanup |
| 987 | * |
| 988 | * Cleans up the bridge but doesn't free the object. |
| 989 | */ |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 990 | void drm_bridge_cleanup(struct drm_bridge *bridge) |
| 991 | { |
| 992 | struct drm_device *dev = bridge->dev; |
| 993 | |
| 994 | drm_modeset_lock_all(dev); |
| 995 | drm_mode_object_put(dev, &bridge->base); |
| 996 | list_del(&bridge->head); |
| 997 | dev->mode_config.num_bridge--; |
| 998 | drm_modeset_unlock_all(dev); |
| 999 | } |
| 1000 | EXPORT_SYMBOL(drm_bridge_cleanup); |
| 1001 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1002 | /** |
| 1003 | * drm_encoder_init - Init a preallocated encoder |
| 1004 | * @dev: drm device |
| 1005 | * @encoder: the encoder to init |
| 1006 | * @funcs: callbacks for this encoder |
| 1007 | * @encoder_type: user visible type of the encoder |
| 1008 | * |
| 1009 | * Initialises a preallocated encoder. Encoder should be |
| 1010 | * subclassed as part of driver encoder objects. |
| 1011 | * |
| 1012 | * Returns: |
| 1013 | * Zero on success, error code on failure. |
| 1014 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1015 | int drm_encoder_init(struct drm_device *dev, |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1016 | struct drm_encoder *encoder, |
| 1017 | const struct drm_encoder_funcs *funcs, |
| 1018 | int encoder_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1019 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1020 | int ret; |
| 1021 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1022 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1023 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1024 | ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); |
| 1025 | if (ret) |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1026 | goto out_unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1027 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1028 | encoder->dev = dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1029 | encoder->encoder_type = encoder_type; |
| 1030 | encoder->funcs = funcs; |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1031 | encoder->name = kasprintf(GFP_KERNEL, "%s-%d", |
| 1032 | drm_encoder_enum_list[encoder_type].name, |
| 1033 | encoder->base.id); |
| 1034 | if (!encoder->name) { |
| 1035 | ret = -ENOMEM; |
| 1036 | goto out_put; |
| 1037 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1038 | |
| 1039 | list_add_tail(&encoder->head, &dev->mode_config.encoder_list); |
| 1040 | dev->mode_config.num_encoder++; |
| 1041 | |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1042 | out_put: |
| 1043 | if (ret) |
| 1044 | drm_mode_object_put(dev, &encoder->base); |
| 1045 | |
| 1046 | out_unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1047 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1048 | |
| 1049 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1050 | } |
| 1051 | EXPORT_SYMBOL(drm_encoder_init); |
| 1052 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1053 | /** |
| 1054 | * drm_encoder_cleanup - cleans up an initialised encoder |
| 1055 | * @encoder: encoder to cleanup |
| 1056 | * |
| 1057 | * Cleans up the encoder but doesn't free the object. |
| 1058 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1059 | void drm_encoder_cleanup(struct drm_encoder *encoder) |
| 1060 | { |
| 1061 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1062 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1063 | drm_mode_object_put(dev, &encoder->base); |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1064 | kfree(encoder->name); |
| 1065 | encoder->name = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1066 | list_del(&encoder->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 1067 | dev->mode_config.num_encoder--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1068 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1069 | } |
| 1070 | EXPORT_SYMBOL(drm_encoder_cleanup); |
| 1071 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1072 | /** |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1073 | * drm_universal_plane_init - Initialize a new universal plane object |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1074 | * @dev: DRM device |
| 1075 | * @plane: plane object to init |
| 1076 | * @possible_crtcs: bitmask of possible CRTCs |
| 1077 | * @funcs: callbacks for the new plane |
| 1078 | * @formats: array of supported formats (%DRM_FORMAT_*) |
| 1079 | * @format_count: number of elements in @formats |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1080 | * @type: type of plane (overlay, primary, cursor) |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1081 | * |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1082 | * Initializes a plane object of type @type. |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1083 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1084 | * Returns: |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1085 | * Zero on success, error code on failure. |
| 1086 | */ |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1087 | int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 1088 | unsigned long possible_crtcs, |
| 1089 | const struct drm_plane_funcs *funcs, |
| 1090 | const uint32_t *formats, uint32_t format_count, |
| 1091 | enum drm_plane_type type) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1092 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1093 | int ret; |
| 1094 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1095 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1096 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1097 | ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); |
| 1098 | if (ret) |
| 1099 | goto out; |
| 1100 | |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 1101 | plane->base.properties = &plane->properties; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1102 | plane->dev = dev; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1103 | plane->funcs = funcs; |
| 1104 | plane->format_types = kmalloc(sizeof(uint32_t) * format_count, |
| 1105 | GFP_KERNEL); |
| 1106 | if (!plane->format_types) { |
| 1107 | DRM_DEBUG_KMS("out of memory when allocating plane\n"); |
| 1108 | drm_mode_object_put(dev, &plane->base); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1109 | ret = -ENOMEM; |
| 1110 | goto out; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1113 | memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1114 | plane->format_count = format_count; |
| 1115 | plane->possible_crtcs = possible_crtcs; |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1116 | plane->type = type; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1117 | |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1118 | list_add_tail(&plane->head, &dev->mode_config.plane_list); |
| 1119 | dev->mode_config.num_total_plane++; |
| 1120 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
| 1121 | dev->mode_config.num_overlay_plane++; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1122 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1123 | drm_object_attach_property(&plane->base, |
| 1124 | dev->mode_config.plane_type_property, |
| 1125 | plane->type); |
| 1126 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1127 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1128 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1129 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1130 | return ret; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1131 | } |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1132 | EXPORT_SYMBOL(drm_universal_plane_init); |
| 1133 | |
| 1134 | /** |
| 1135 | * drm_plane_init - Initialize a legacy plane |
| 1136 | * @dev: DRM device |
| 1137 | * @plane: plane object to init |
| 1138 | * @possible_crtcs: bitmask of possible CRTCs |
| 1139 | * @funcs: callbacks for the new plane |
| 1140 | * @formats: array of supported formats (%DRM_FORMAT_*) |
| 1141 | * @format_count: number of elements in @formats |
| 1142 | * @is_primary: plane type (primary vs overlay) |
| 1143 | * |
| 1144 | * Legacy API to initialize a DRM plane. |
| 1145 | * |
| 1146 | * New drivers should call drm_universal_plane_init() instead. |
| 1147 | * |
| 1148 | * Returns: |
| 1149 | * Zero on success, error code on failure. |
| 1150 | */ |
| 1151 | int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 1152 | unsigned long possible_crtcs, |
| 1153 | const struct drm_plane_funcs *funcs, |
| 1154 | const uint32_t *formats, uint32_t format_count, |
| 1155 | bool is_primary) |
| 1156 | { |
| 1157 | enum drm_plane_type type; |
| 1158 | |
| 1159 | type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY; |
| 1160 | return drm_universal_plane_init(dev, plane, possible_crtcs, funcs, |
| 1161 | formats, format_count, type); |
| 1162 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1163 | EXPORT_SYMBOL(drm_plane_init); |
| 1164 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1165 | /** |
| 1166 | * drm_plane_cleanup - Clean up the core plane usage |
| 1167 | * @plane: plane to cleanup |
| 1168 | * |
| 1169 | * This function cleans up @plane and removes it from the DRM mode setting |
| 1170 | * core. Note that the function does *not* free the plane structure itself, |
| 1171 | * this is the responsibility of the caller. |
| 1172 | */ |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1173 | void drm_plane_cleanup(struct drm_plane *plane) |
| 1174 | { |
| 1175 | struct drm_device *dev = plane->dev; |
| 1176 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1177 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1178 | kfree(plane->format_types); |
| 1179 | drm_mode_object_put(dev, &plane->base); |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1180 | |
| 1181 | BUG_ON(list_empty(&plane->head)); |
| 1182 | |
| 1183 | list_del(&plane->head); |
| 1184 | dev->mode_config.num_total_plane--; |
| 1185 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
| 1186 | dev->mode_config.num_overlay_plane--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1187 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1188 | } |
| 1189 | EXPORT_SYMBOL(drm_plane_cleanup); |
| 1190 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1191 | /** |
| 1192 | * drm_plane_force_disable - Forcibly disable a plane |
| 1193 | * @plane: plane to disable |
| 1194 | * |
| 1195 | * Forces the plane to be disabled. |
| 1196 | * |
| 1197 | * Used when the plane's current framebuffer is destroyed, |
| 1198 | * and when restoring fbdev mode. |
| 1199 | */ |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1200 | void drm_plane_force_disable(struct drm_plane *plane) |
| 1201 | { |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 1202 | struct drm_framebuffer *old_fb = plane->fb; |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1203 | int ret; |
| 1204 | |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 1205 | if (!old_fb) |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1206 | return; |
| 1207 | |
| 1208 | ret = plane->funcs->disable_plane(plane); |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 1209 | if (ret) { |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1210 | DRM_ERROR("failed to disable plane with busy fb\n"); |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 1211 | return; |
| 1212 | } |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1213 | /* disconnect the plane from the fb and crtc: */ |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 1214 | __drm_framebuffer_unreference(old_fb); |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1215 | plane->fb = NULL; |
| 1216 | plane->crtc = NULL; |
| 1217 | } |
| 1218 | EXPORT_SYMBOL(drm_plane_force_disable); |
| 1219 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1220 | static int drm_mode_create_standard_connector_properties(struct drm_device *dev) |
| 1221 | { |
| 1222 | struct drm_property *edid; |
| 1223 | struct drm_property *dpms; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1224 | |
| 1225 | /* |
| 1226 | * Standard properties (apply to all connectors) |
| 1227 | */ |
| 1228 | edid = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
| 1229 | DRM_MODE_PROP_IMMUTABLE, |
| 1230 | "EDID", 0); |
| 1231 | dev->mode_config.edid_property = edid; |
| 1232 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1233 | dpms = drm_property_create_enum(dev, 0, |
| 1234 | "DPMS", drm_dpms_enum_list, |
| 1235 | ARRAY_SIZE(drm_dpms_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1236 | dev->mode_config.dpms_property = dpms; |
| 1237 | |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1241 | static int drm_mode_create_standard_plane_properties(struct drm_device *dev) |
| 1242 | { |
| 1243 | struct drm_property *type; |
| 1244 | |
| 1245 | /* |
| 1246 | * Standard properties (apply to all planes) |
| 1247 | */ |
| 1248 | type = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 1249 | "type", drm_plane_type_enum_list, |
| 1250 | ARRAY_SIZE(drm_plane_type_enum_list)); |
| 1251 | dev->mode_config.plane_type_property = type; |
| 1252 | |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1256 | /** |
| 1257 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
| 1258 | * @dev: DRM device |
| 1259 | * |
| 1260 | * Called by a driver the first time a DVI-I connector is made. |
| 1261 | */ |
| 1262 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
| 1263 | { |
| 1264 | struct drm_property *dvi_i_selector; |
| 1265 | struct drm_property *dvi_i_subconnector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1266 | |
| 1267 | if (dev->mode_config.dvi_i_select_subconnector_property) |
| 1268 | return 0; |
| 1269 | |
| 1270 | dvi_i_selector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1271 | drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1272 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1273 | drm_dvi_i_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1274 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1275 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
| 1276 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1277 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1278 | "subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1279 | drm_dvi_i_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1280 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1281 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
| 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
| 1286 | |
| 1287 | /** |
| 1288 | * drm_create_tv_properties - create TV specific connector properties |
| 1289 | * @dev: DRM device |
| 1290 | * @num_modes: number of different TV formats (modes) supported |
| 1291 | * @modes: array of pointers to strings containing name of each format |
| 1292 | * |
| 1293 | * Called by a driver's TV initialization routine, this function creates |
| 1294 | * the TV specific connector properties for a given device. Caller is |
| 1295 | * responsible for allocating a list of format names and passing them to |
| 1296 | * this routine. |
| 1297 | */ |
| 1298 | int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes, |
| 1299 | char *modes[]) |
| 1300 | { |
| 1301 | struct drm_property *tv_selector; |
| 1302 | struct drm_property *tv_subconnector; |
| 1303 | int i; |
| 1304 | |
| 1305 | if (dev->mode_config.tv_select_subconnector_property) |
| 1306 | return 0; |
| 1307 | |
| 1308 | /* |
| 1309 | * Basic connector properties |
| 1310 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1311 | tv_selector = drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1312 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1313 | drm_tv_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1314 | ARRAY_SIZE(drm_tv_select_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1315 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
| 1316 | |
| 1317 | tv_subconnector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1318 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 1319 | "subconnector", |
| 1320 | drm_tv_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1321 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1322 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
| 1323 | |
| 1324 | /* |
| 1325 | * Other, TV specific properties: margins & TV modes. |
| 1326 | */ |
| 1327 | dev->mode_config.tv_left_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1328 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1329 | |
| 1330 | dev->mode_config.tv_right_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1331 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1332 | |
| 1333 | dev->mode_config.tv_top_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1334 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1335 | |
| 1336 | dev->mode_config.tv_bottom_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1337 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1338 | |
| 1339 | dev->mode_config.tv_mode_property = |
| 1340 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
| 1341 | "mode", num_modes); |
| 1342 | for (i = 0; i < num_modes; i++) |
| 1343 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
| 1344 | i, modes[i]); |
| 1345 | |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1346 | dev->mode_config.tv_brightness_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1347 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1348 | |
| 1349 | dev->mode_config.tv_contrast_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1350 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1351 | |
| 1352 | dev->mode_config.tv_flicker_reduction_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1353 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1354 | |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1355 | dev->mode_config.tv_overscan_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1356 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1357 | |
| 1358 | dev->mode_config.tv_saturation_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1359 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1360 | |
| 1361 | dev->mode_config.tv_hue_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1362 | drm_property_create_range(dev, 0, "hue", 0, 100); |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1363 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1364 | return 0; |
| 1365 | } |
| 1366 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
| 1367 | |
| 1368 | /** |
| 1369 | * drm_mode_create_scaling_mode_property - create scaling mode property |
| 1370 | * @dev: DRM device |
| 1371 | * |
| 1372 | * Called by a driver the first time it's needed, must be attached to desired |
| 1373 | * connectors. |
| 1374 | */ |
| 1375 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
| 1376 | { |
| 1377 | struct drm_property *scaling_mode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1378 | |
| 1379 | if (dev->mode_config.scaling_mode_property) |
| 1380 | return 0; |
| 1381 | |
| 1382 | scaling_mode = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1383 | drm_property_create_enum(dev, 0, "scaling mode", |
| 1384 | drm_scaling_mode_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1385 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1386 | |
| 1387 | dev->mode_config.scaling_mode_property = scaling_mode; |
| 1388 | |
| 1389 | return 0; |
| 1390 | } |
| 1391 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
| 1392 | |
| 1393 | /** |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1394 | * drm_mode_create_dirty_property - create dirty property |
| 1395 | * @dev: DRM device |
| 1396 | * |
| 1397 | * Called by a driver the first time it's needed, must be attached to desired |
| 1398 | * connectors. |
| 1399 | */ |
| 1400 | int drm_mode_create_dirty_info_property(struct drm_device *dev) |
| 1401 | { |
| 1402 | struct drm_property *dirty_info; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1403 | |
| 1404 | if (dev->mode_config.dirty_info_property) |
| 1405 | return 0; |
| 1406 | |
| 1407 | dirty_info = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1408 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1409 | "dirty", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1410 | drm_dirty_info_enum_list, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1411 | ARRAY_SIZE(drm_dirty_info_enum_list)); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1412 | dev->mode_config.dirty_info_property = dirty_info; |
| 1413 | |
| 1414 | return 0; |
| 1415 | } |
| 1416 | EXPORT_SYMBOL(drm_mode_create_dirty_info_property); |
| 1417 | |
Ville Syrjälä | ea9cbb0 | 2013-04-25 20:09:20 +0300 | [diff] [blame] | 1418 | static int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1419 | { |
| 1420 | uint32_t total_objects = 0; |
| 1421 | |
| 1422 | total_objects += dev->mode_config.num_crtc; |
| 1423 | total_objects += dev->mode_config.num_connector; |
| 1424 | total_objects += dev->mode_config.num_encoder; |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 1425 | total_objects += dev->mode_config.num_bridge; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1426 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1427 | group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL); |
| 1428 | if (!group->id_list) |
| 1429 | return -ENOMEM; |
| 1430 | |
| 1431 | group->num_crtcs = 0; |
| 1432 | group->num_connectors = 0; |
| 1433 | group->num_encoders = 0; |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 1434 | group->num_bridges = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1435 | return 0; |
| 1436 | } |
| 1437 | |
Dave Airlie | ad22279 | 2014-05-02 13:22:19 +1000 | [diff] [blame] | 1438 | void drm_mode_group_destroy(struct drm_mode_group *group) |
| 1439 | { |
| 1440 | kfree(group->id_list); |
| 1441 | group->id_list = NULL; |
| 1442 | } |
| 1443 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1444 | /* |
| 1445 | * NOTE: Driver's shouldn't ever call drm_mode_group_init_legacy_group - it is |
| 1446 | * the drm core's responsibility to set up mode control groups. |
| 1447 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1448 | int drm_mode_group_init_legacy_group(struct drm_device *dev, |
| 1449 | struct drm_mode_group *group) |
| 1450 | { |
| 1451 | struct drm_crtc *crtc; |
| 1452 | struct drm_encoder *encoder; |
| 1453 | struct drm_connector *connector; |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 1454 | struct drm_bridge *bridge; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1455 | int ret; |
| 1456 | |
| 1457 | if ((ret = drm_mode_group_init(dev, group))) |
| 1458 | return ret; |
| 1459 | |
| 1460 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 1461 | group->id_list[group->num_crtcs++] = crtc->base.id; |
| 1462 | |
| 1463 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 1464 | group->id_list[group->num_crtcs + group->num_encoders++] = |
| 1465 | encoder->base.id; |
| 1466 | |
| 1467 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 1468 | group->id_list[group->num_crtcs + group->num_encoders + |
| 1469 | group->num_connectors++] = connector->base.id; |
| 1470 | |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 1471 | list_for_each_entry(bridge, &dev->mode_config.bridge_list, head) |
| 1472 | group->id_list[group->num_crtcs + group->num_encoders + |
| 1473 | group->num_connectors + group->num_bridges++] = |
| 1474 | bridge->base.id; |
| 1475 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1476 | return 0; |
| 1477 | } |
Dave Airlie | 9c1dfc5 | 2012-03-20 06:59:29 +0000 | [diff] [blame] | 1478 | EXPORT_SYMBOL(drm_mode_group_init_legacy_group); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1479 | |
| 1480 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1481 | * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo |
| 1482 | * @out: drm_mode_modeinfo struct to return to the user |
| 1483 | * @in: drm_display_mode to use |
| 1484 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1485 | * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to |
| 1486 | * the user. |
| 1487 | */ |
Ville Syrjälä | 93bbf6d | 2012-03-13 12:35:47 +0200 | [diff] [blame] | 1488 | static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, |
| 1489 | const struct drm_display_mode *in) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1490 | { |
Ville Syrjälä | e36fae3 | 2012-03-13 12:35:40 +0200 | [diff] [blame] | 1491 | WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX || |
| 1492 | in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX || |
| 1493 | in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX || |
| 1494 | in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX || |
| 1495 | in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX, |
| 1496 | "timing values too large for mode info\n"); |
| 1497 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1498 | out->clock = in->clock; |
| 1499 | out->hdisplay = in->hdisplay; |
| 1500 | out->hsync_start = in->hsync_start; |
| 1501 | out->hsync_end = in->hsync_end; |
| 1502 | out->htotal = in->htotal; |
| 1503 | out->hskew = in->hskew; |
| 1504 | out->vdisplay = in->vdisplay; |
| 1505 | out->vsync_start = in->vsync_start; |
| 1506 | out->vsync_end = in->vsync_end; |
| 1507 | out->vtotal = in->vtotal; |
| 1508 | out->vscan = in->vscan; |
| 1509 | out->vrefresh = in->vrefresh; |
| 1510 | out->flags = in->flags; |
| 1511 | out->type = in->type; |
| 1512 | strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); |
| 1513 | out->name[DRM_DISPLAY_MODE_LEN-1] = 0; |
| 1514 | } |
| 1515 | |
| 1516 | /** |
Marc-André Lureau | 74afee7 | 2013-10-18 16:11:27 +0200 | [diff] [blame] | 1517 | * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1518 | * @out: drm_display_mode to return to the user |
| 1519 | * @in: drm_mode_modeinfo to use |
| 1520 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1521 | * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to |
| 1522 | * the caller. |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1523 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1524 | * Returns: |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1525 | * Zero on success, errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1526 | */ |
Ville Syrjälä | 93bbf6d | 2012-03-13 12:35:47 +0200 | [diff] [blame] | 1527 | static int drm_crtc_convert_umode(struct drm_display_mode *out, |
| 1528 | const struct drm_mode_modeinfo *in) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1529 | { |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1530 | if (in->clock > INT_MAX || in->vrefresh > INT_MAX) |
| 1531 | return -ERANGE; |
| 1532 | |
Damien Lespiau | 5848ad4 | 2013-09-27 12:11:50 +0100 | [diff] [blame] | 1533 | if ((in->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX) |
| 1534 | return -EINVAL; |
| 1535 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1536 | out->clock = in->clock; |
| 1537 | out->hdisplay = in->hdisplay; |
| 1538 | out->hsync_start = in->hsync_start; |
| 1539 | out->hsync_end = in->hsync_end; |
| 1540 | out->htotal = in->htotal; |
| 1541 | out->hskew = in->hskew; |
| 1542 | out->vdisplay = in->vdisplay; |
| 1543 | out->vsync_start = in->vsync_start; |
| 1544 | out->vsync_end = in->vsync_end; |
| 1545 | out->vtotal = in->vtotal; |
| 1546 | out->vscan = in->vscan; |
| 1547 | out->vrefresh = in->vrefresh; |
| 1548 | out->flags = in->flags; |
| 1549 | out->type = in->type; |
| 1550 | strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); |
| 1551 | out->name[DRM_DISPLAY_MODE_LEN-1] = 0; |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1552 | |
| 1553 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
| 1557 | * drm_mode_getresources - get graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1558 | * @dev: drm device for the ioctl |
| 1559 | * @data: data pointer for the ioctl |
| 1560 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1561 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1562 | * Construct a set of configuration description structures and return |
| 1563 | * them to the user, including CRTC, connector and framebuffer configuration. |
| 1564 | * |
| 1565 | * Called by the user via ioctl. |
| 1566 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1567 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1568 | * Zero on success, errno on failure. |
| 1569 | */ |
| 1570 | int drm_mode_getresources(struct drm_device *dev, void *data, |
| 1571 | struct drm_file *file_priv) |
| 1572 | { |
| 1573 | struct drm_mode_card_res *card_res = data; |
| 1574 | struct list_head *lh; |
| 1575 | struct drm_framebuffer *fb; |
| 1576 | struct drm_connector *connector; |
| 1577 | struct drm_crtc *crtc; |
| 1578 | struct drm_encoder *encoder; |
| 1579 | int ret = 0; |
| 1580 | int connector_count = 0; |
| 1581 | int crtc_count = 0; |
| 1582 | int fb_count = 0; |
| 1583 | int encoder_count = 0; |
| 1584 | int copied = 0, i; |
| 1585 | uint32_t __user *fb_id; |
| 1586 | uint32_t __user *crtc_id; |
| 1587 | uint32_t __user *connector_id; |
| 1588 | uint32_t __user *encoder_id; |
| 1589 | struct drm_mode_group *mode_group; |
| 1590 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1591 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1592 | return -EINVAL; |
| 1593 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1594 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1595 | mutex_lock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1596 | /* |
| 1597 | * For the non-control nodes we need to limit the list of resources |
| 1598 | * by IDs in the group list for this node |
| 1599 | */ |
| 1600 | list_for_each(lh, &file_priv->fbs) |
| 1601 | fb_count++; |
| 1602 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1603 | /* handle this in 4 parts */ |
| 1604 | /* FBs */ |
| 1605 | if (card_res->count_fbs >= fb_count) { |
| 1606 | copied = 0; |
| 1607 | fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; |
| 1608 | list_for_each_entry(fb, &file_priv->fbs, filp_head) { |
| 1609 | if (put_user(fb->base.id, fb_id + copied)) { |
| 1610 | mutex_unlock(&file_priv->fbs_lock); |
| 1611 | return -EFAULT; |
| 1612 | } |
| 1613 | copied++; |
| 1614 | } |
| 1615 | } |
| 1616 | card_res->count_fbs = fb_count; |
| 1617 | mutex_unlock(&file_priv->fbs_lock); |
| 1618 | |
| 1619 | drm_modeset_lock_all(dev); |
Thomas Hellstrom | 4368305 | 2014-03-13 11:07:44 +0100 | [diff] [blame] | 1620 | if (!drm_is_primary_client(file_priv)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1621 | |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 1622 | mode_group = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1623 | list_for_each(lh, &dev->mode_config.crtc_list) |
| 1624 | crtc_count++; |
| 1625 | |
| 1626 | list_for_each(lh, &dev->mode_config.connector_list) |
| 1627 | connector_count++; |
| 1628 | |
| 1629 | list_for_each(lh, &dev->mode_config.encoder_list) |
| 1630 | encoder_count++; |
| 1631 | } else { |
| 1632 | |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 1633 | mode_group = &file_priv->master->minor->mode_group; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1634 | crtc_count = mode_group->num_crtcs; |
| 1635 | connector_count = mode_group->num_connectors; |
| 1636 | encoder_count = mode_group->num_encoders; |
| 1637 | } |
| 1638 | |
| 1639 | card_res->max_height = dev->mode_config.max_height; |
| 1640 | card_res->min_height = dev->mode_config.min_height; |
| 1641 | card_res->max_width = dev->mode_config.max_width; |
| 1642 | card_res->min_width = dev->mode_config.min_width; |
| 1643 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1644 | /* CRTCs */ |
| 1645 | if (card_res->count_crtcs >= crtc_count) { |
| 1646 | copied = 0; |
| 1647 | crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 1648 | if (!mode_group) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1649 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 1650 | head) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1651 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1652 | if (put_user(crtc->base.id, crtc_id + copied)) { |
| 1653 | ret = -EFAULT; |
| 1654 | goto out; |
| 1655 | } |
| 1656 | copied++; |
| 1657 | } |
| 1658 | } else { |
| 1659 | for (i = 0; i < mode_group->num_crtcs; i++) { |
| 1660 | if (put_user(mode_group->id_list[i], |
| 1661 | crtc_id + copied)) { |
| 1662 | ret = -EFAULT; |
| 1663 | goto out; |
| 1664 | } |
| 1665 | copied++; |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | card_res->count_crtcs = crtc_count; |
| 1670 | |
| 1671 | /* Encoders */ |
| 1672 | if (card_res->count_encoders >= encoder_count) { |
| 1673 | copied = 0; |
| 1674 | encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 1675 | if (!mode_group) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1676 | list_for_each_entry(encoder, |
| 1677 | &dev->mode_config.encoder_list, |
| 1678 | head) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1679 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id, |
Jani Nikula | 83a8cfd | 2014-06-03 14:56:22 +0300 | [diff] [blame] | 1680 | encoder->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1681 | if (put_user(encoder->base.id, encoder_id + |
| 1682 | copied)) { |
| 1683 | ret = -EFAULT; |
| 1684 | goto out; |
| 1685 | } |
| 1686 | copied++; |
| 1687 | } |
| 1688 | } else { |
| 1689 | for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) { |
| 1690 | if (put_user(mode_group->id_list[i], |
| 1691 | encoder_id + copied)) { |
| 1692 | ret = -EFAULT; |
| 1693 | goto out; |
| 1694 | } |
| 1695 | copied++; |
| 1696 | } |
| 1697 | |
| 1698 | } |
| 1699 | } |
| 1700 | card_res->count_encoders = encoder_count; |
| 1701 | |
| 1702 | /* Connectors */ |
| 1703 | if (card_res->count_connectors >= connector_count) { |
| 1704 | copied = 0; |
| 1705 | connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 1706 | if (!mode_group) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1707 | list_for_each_entry(connector, |
| 1708 | &dev->mode_config.connector_list, |
| 1709 | head) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1710 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 1711 | connector->base.id, |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 1712 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1713 | if (put_user(connector->base.id, |
| 1714 | connector_id + copied)) { |
| 1715 | ret = -EFAULT; |
| 1716 | goto out; |
| 1717 | } |
| 1718 | copied++; |
| 1719 | } |
| 1720 | } else { |
| 1721 | int start = mode_group->num_crtcs + |
| 1722 | mode_group->num_encoders; |
| 1723 | for (i = start; i < start + mode_group->num_connectors; i++) { |
| 1724 | if (put_user(mode_group->id_list[i], |
| 1725 | connector_id + copied)) { |
| 1726 | ret = -EFAULT; |
| 1727 | goto out; |
| 1728 | } |
| 1729 | copied++; |
| 1730 | } |
| 1731 | } |
| 1732 | } |
| 1733 | card_res->count_connectors = connector_count; |
| 1734 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1735 | DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1736 | card_res->count_connectors, card_res->count_encoders); |
| 1737 | |
| 1738 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1739 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1740 | return ret; |
| 1741 | } |
| 1742 | |
| 1743 | /** |
| 1744 | * drm_mode_getcrtc - get CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1745 | * @dev: drm device for the ioctl |
| 1746 | * @data: data pointer for the ioctl |
| 1747 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1748 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1749 | * Construct a CRTC configuration structure to return to the user. |
| 1750 | * |
| 1751 | * Called by the user via ioctl. |
| 1752 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1753 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1754 | * Zero on success, errno on failure. |
| 1755 | */ |
| 1756 | int drm_mode_getcrtc(struct drm_device *dev, |
| 1757 | void *data, struct drm_file *file_priv) |
| 1758 | { |
| 1759 | struct drm_mode_crtc *crtc_resp = data; |
| 1760 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1761 | int ret = 0; |
| 1762 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1763 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1764 | return -EINVAL; |
| 1765 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1766 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1767 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 1768 | crtc = drm_crtc_find(dev, crtc_resp->crtc_id); |
| 1769 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 1770 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1771 | goto out; |
| 1772 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1773 | |
| 1774 | crtc_resp->x = crtc->x; |
| 1775 | crtc_resp->y = crtc->y; |
| 1776 | crtc_resp->gamma_size = crtc->gamma_size; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1777 | if (crtc->primary->fb) |
| 1778 | crtc_resp->fb_id = crtc->primary->fb->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1779 | else |
| 1780 | crtc_resp->fb_id = 0; |
| 1781 | |
| 1782 | if (crtc->enabled) { |
| 1783 | |
| 1784 | drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
| 1785 | crtc_resp->mode_valid = 1; |
| 1786 | |
| 1787 | } else { |
| 1788 | crtc_resp->mode_valid = 0; |
| 1789 | } |
| 1790 | |
| 1791 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1792 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1793 | return ret; |
| 1794 | } |
| 1795 | |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 1796 | static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
| 1797 | const struct drm_file *file_priv) |
| 1798 | { |
| 1799 | /* |
| 1800 | * If user-space hasn't configured the driver to expose the stereo 3D |
| 1801 | * modes, don't expose them. |
| 1802 | */ |
| 1803 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
| 1804 | return false; |
| 1805 | |
| 1806 | return true; |
| 1807 | } |
| 1808 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1809 | /** |
| 1810 | * drm_mode_getconnector - get connector configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1811 | * @dev: drm device for the ioctl |
| 1812 | * @data: data pointer for the ioctl |
| 1813 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1814 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1815 | * Construct a connector configuration structure to return to the user. |
| 1816 | * |
| 1817 | * Called by the user via ioctl. |
| 1818 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1819 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1820 | * Zero on success, errno on failure. |
| 1821 | */ |
| 1822 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
| 1823 | struct drm_file *file_priv) |
| 1824 | { |
| 1825 | struct drm_mode_get_connector *out_resp = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1826 | struct drm_connector *connector; |
| 1827 | struct drm_display_mode *mode; |
| 1828 | int mode_count = 0; |
| 1829 | int props_count = 0; |
| 1830 | int encoders_count = 0; |
| 1831 | int ret = 0; |
| 1832 | int copied = 0; |
| 1833 | int i; |
| 1834 | struct drm_mode_modeinfo u_mode; |
| 1835 | struct drm_mode_modeinfo __user *mode_ptr; |
| 1836 | uint32_t __user *prop_ptr; |
| 1837 | uint64_t __user *prop_values; |
| 1838 | uint32_t __user *encoder_ptr; |
| 1839 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1840 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1841 | return -EINVAL; |
| 1842 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1843 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
| 1844 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1845 | DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1846 | |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 1847 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1848 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 1849 | connector = drm_connector_find(dev, out_resp->connector_id); |
| 1850 | if (!connector) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 1851 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1852 | goto out; |
| 1853 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1854 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 1855 | props_count = connector->properties.count; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1856 | |
| 1857 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 1858 | if (connector->encoder_ids[i] != 0) { |
| 1859 | encoders_count++; |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | if (out_resp->count_modes == 0) { |
| 1864 | connector->funcs->fill_modes(connector, |
| 1865 | dev->mode_config.max_width, |
| 1866 | dev->mode_config.max_height); |
| 1867 | } |
| 1868 | |
| 1869 | /* delayed so we get modes regardless of pre-fill_modes state */ |
| 1870 | list_for_each_entry(mode, &connector->modes, head) |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 1871 | if (drm_mode_expose_to_userspace(mode, file_priv)) |
| 1872 | mode_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1873 | |
| 1874 | out_resp->connector_id = connector->base.id; |
| 1875 | out_resp->connector_type = connector->connector_type; |
| 1876 | out_resp->connector_type_id = connector->connector_type_id; |
| 1877 | out_resp->mm_width = connector->display_info.width_mm; |
| 1878 | out_resp->mm_height = connector->display_info.height_mm; |
| 1879 | out_resp->subpixel = connector->display_info.subpixel_order; |
| 1880 | out_resp->connection = connector->status; |
Daniel Vetter | 832fd39 | 2014-06-05 11:07:20 +0200 | [diff] [blame] | 1881 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1882 | if (connector->encoder) |
| 1883 | out_resp->encoder_id = connector->encoder->base.id; |
| 1884 | else |
| 1885 | out_resp->encoder_id = 0; |
Daniel Vetter | 832fd39 | 2014-06-05 11:07:20 +0200 | [diff] [blame] | 1886 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1887 | |
| 1888 | /* |
| 1889 | * This ioctl is called twice, once to determine how much space is |
| 1890 | * needed, and the 2nd time to fill it. |
| 1891 | */ |
| 1892 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
| 1893 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1894 | mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1895 | list_for_each_entry(mode, &connector->modes, head) { |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 1896 | if (!drm_mode_expose_to_userspace(mode, file_priv)) |
| 1897 | continue; |
| 1898 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1899 | drm_crtc_convert_to_umode(&u_mode, mode); |
| 1900 | if (copy_to_user(mode_ptr + copied, |
| 1901 | &u_mode, sizeof(u_mode))) { |
| 1902 | ret = -EFAULT; |
| 1903 | goto out; |
| 1904 | } |
| 1905 | copied++; |
| 1906 | } |
| 1907 | } |
| 1908 | out_resp->count_modes = mode_count; |
| 1909 | |
| 1910 | if ((out_resp->count_props >= props_count) && props_count) { |
| 1911 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1912 | prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr); |
| 1913 | prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr); |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 1914 | for (i = 0; i < connector->properties.count; i++) { |
| 1915 | if (put_user(connector->properties.ids[i], |
| 1916 | prop_ptr + copied)) { |
| 1917 | ret = -EFAULT; |
| 1918 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1919 | } |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 1920 | |
| 1921 | if (put_user(connector->properties.values[i], |
| 1922 | prop_values + copied)) { |
| 1923 | ret = -EFAULT; |
| 1924 | goto out; |
| 1925 | } |
| 1926 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | out_resp->count_props = props_count; |
| 1930 | |
| 1931 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
| 1932 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1933 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1934 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 1935 | if (connector->encoder_ids[i] != 0) { |
| 1936 | if (put_user(connector->encoder_ids[i], |
| 1937 | encoder_ptr + copied)) { |
| 1938 | ret = -EFAULT; |
| 1939 | goto out; |
| 1940 | } |
| 1941 | copied++; |
| 1942 | } |
| 1943 | } |
| 1944 | } |
| 1945 | out_resp->count_encoders = encoders_count; |
| 1946 | |
| 1947 | out: |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 1948 | mutex_unlock(&dev->mode_config.mutex); |
| 1949 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1950 | return ret; |
| 1951 | } |
| 1952 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1953 | /** |
| 1954 | * drm_mode_getencoder - get encoder configuration |
| 1955 | * @dev: drm device for the ioctl |
| 1956 | * @data: data pointer for the ioctl |
| 1957 | * @file_priv: drm file for the ioctl call |
| 1958 | * |
| 1959 | * Construct a encoder configuration structure to return to the user. |
| 1960 | * |
| 1961 | * Called by the user via ioctl. |
| 1962 | * |
| 1963 | * Returns: |
| 1964 | * Zero on success, errno on failure. |
| 1965 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1966 | int drm_mode_getencoder(struct drm_device *dev, void *data, |
| 1967 | struct drm_file *file_priv) |
| 1968 | { |
| 1969 | struct drm_mode_get_encoder *enc_resp = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1970 | struct drm_encoder *encoder; |
| 1971 | int ret = 0; |
| 1972 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1973 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1974 | return -EINVAL; |
| 1975 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1976 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 1977 | encoder = drm_encoder_find(dev, enc_resp->encoder_id); |
| 1978 | if (!encoder) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 1979 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1980 | goto out; |
| 1981 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1982 | |
| 1983 | if (encoder->crtc) |
| 1984 | enc_resp->crtc_id = encoder->crtc->base.id; |
| 1985 | else |
| 1986 | enc_resp->crtc_id = 0; |
| 1987 | enc_resp->encoder_type = encoder->encoder_type; |
| 1988 | enc_resp->encoder_id = encoder->base.id; |
| 1989 | enc_resp->possible_crtcs = encoder->possible_crtcs; |
| 1990 | enc_resp->possible_clones = encoder->possible_clones; |
| 1991 | |
| 1992 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1993 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1994 | return ret; |
| 1995 | } |
| 1996 | |
| 1997 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1998 | * drm_mode_getplane_res - enumerate all plane resources |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1999 | * @dev: DRM device |
| 2000 | * @data: ioctl data |
| 2001 | * @file_priv: DRM file info |
| 2002 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2003 | * Construct a list of plane ids to return to the user. |
| 2004 | * |
| 2005 | * Called by the user via ioctl. |
| 2006 | * |
| 2007 | * Returns: |
| 2008 | * Zero on success, errno on failure. |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2009 | */ |
| 2010 | int drm_mode_getplane_res(struct drm_device *dev, void *data, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2011 | struct drm_file *file_priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2012 | { |
| 2013 | struct drm_mode_get_plane_res *plane_resp = data; |
| 2014 | struct drm_mode_config *config; |
| 2015 | struct drm_plane *plane; |
| 2016 | uint32_t __user *plane_ptr; |
| 2017 | int copied = 0, ret = 0; |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2018 | unsigned num_planes; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2019 | |
| 2020 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2021 | return -EINVAL; |
| 2022 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2023 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2024 | config = &dev->mode_config; |
| 2025 | |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2026 | if (file_priv->universal_planes) |
| 2027 | num_planes = config->num_total_plane; |
| 2028 | else |
| 2029 | num_planes = config->num_overlay_plane; |
| 2030 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2031 | /* |
| 2032 | * This ioctl is called twice, once to determine how much space is |
| 2033 | * needed, and the 2nd time to fill it. |
| 2034 | */ |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2035 | if (num_planes && |
| 2036 | (plane_resp->count_planes >= num_planes)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2037 | plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2038 | |
| 2039 | list_for_each_entry(plane, &config->plane_list, head) { |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2040 | /* |
| 2041 | * Unless userspace set the 'universal planes' |
| 2042 | * capability bit, only advertise overlays. |
| 2043 | */ |
| 2044 | if (plane->type != DRM_PLANE_TYPE_OVERLAY && |
| 2045 | !file_priv->universal_planes) |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 2046 | continue; |
| 2047 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2048 | if (put_user(plane->base.id, plane_ptr + copied)) { |
| 2049 | ret = -EFAULT; |
| 2050 | goto out; |
| 2051 | } |
| 2052 | copied++; |
| 2053 | } |
| 2054 | } |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2055 | plane_resp->count_planes = num_planes; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2056 | |
| 2057 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2058 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2059 | return ret; |
| 2060 | } |
| 2061 | |
| 2062 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2063 | * drm_mode_getplane - get plane configuration |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2064 | * @dev: DRM device |
| 2065 | * @data: ioctl data |
| 2066 | * @file_priv: DRM file info |
| 2067 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2068 | * Construct a plane configuration structure to return to the user. |
| 2069 | * |
| 2070 | * Called by the user via ioctl. |
| 2071 | * |
| 2072 | * Returns: |
| 2073 | * Zero on success, errno on failure. |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2074 | */ |
| 2075 | int drm_mode_getplane(struct drm_device *dev, void *data, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2076 | struct drm_file *file_priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2077 | { |
| 2078 | struct drm_mode_get_plane *plane_resp = data; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2079 | struct drm_plane *plane; |
| 2080 | uint32_t __user *format_ptr; |
| 2081 | int ret = 0; |
| 2082 | |
| 2083 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2084 | return -EINVAL; |
| 2085 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2086 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2087 | plane = drm_plane_find(dev, plane_resp->plane_id); |
| 2088 | if (!plane) { |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2089 | ret = -ENOENT; |
| 2090 | goto out; |
| 2091 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2092 | |
| 2093 | if (plane->crtc) |
| 2094 | plane_resp->crtc_id = plane->crtc->base.id; |
| 2095 | else |
| 2096 | plane_resp->crtc_id = 0; |
| 2097 | |
| 2098 | if (plane->fb) |
| 2099 | plane_resp->fb_id = plane->fb->base.id; |
| 2100 | else |
| 2101 | plane_resp->fb_id = 0; |
| 2102 | |
| 2103 | plane_resp->plane_id = plane->base.id; |
| 2104 | plane_resp->possible_crtcs = plane->possible_crtcs; |
Ville Syrjälä | 778ad90 | 2013-06-03 16:11:42 +0300 | [diff] [blame] | 2105 | plane_resp->gamma_size = 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2106 | |
| 2107 | /* |
| 2108 | * This ioctl is called twice, once to determine how much space is |
| 2109 | * needed, and the 2nd time to fill it. |
| 2110 | */ |
| 2111 | if (plane->format_count && |
| 2112 | (plane_resp->count_format_types >= plane->format_count)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2113 | format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2114 | if (copy_to_user(format_ptr, |
| 2115 | plane->format_types, |
| 2116 | sizeof(uint32_t) * plane->format_count)) { |
| 2117 | ret = -EFAULT; |
| 2118 | goto out; |
| 2119 | } |
| 2120 | } |
| 2121 | plane_resp->count_format_types = plane->format_count; |
| 2122 | |
| 2123 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2124 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2125 | return ret; |
| 2126 | } |
| 2127 | |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2128 | /* |
| 2129 | * setplane_internal - setplane handler for internal callers |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2130 | * |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2131 | * Note that we assume an extra reference has already been taken on fb. If the |
| 2132 | * update fails, this reference will be dropped before return; if it succeeds, |
| 2133 | * the previous framebuffer (if any) will be unreferenced instead. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2134 | * |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2135 | * src_{x,y,w,h} are provided in 16.16 fixed point format |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2136 | */ |
Chris Wilson | 17cfd91 | 2014-06-13 15:22:28 +0100 | [diff] [blame] | 2137 | static int setplane_internal(struct drm_plane *plane, |
| 2138 | struct drm_crtc *crtc, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2139 | struct drm_framebuffer *fb, |
| 2140 | int32_t crtc_x, int32_t crtc_y, |
| 2141 | uint32_t crtc_w, uint32_t crtc_h, |
| 2142 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
| 2143 | uint32_t src_x, uint32_t src_y, |
| 2144 | uint32_t src_w, uint32_t src_h) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2145 | { |
Chris Wilson | 17cfd91 | 2014-06-13 15:22:28 +0100 | [diff] [blame] | 2146 | struct drm_device *dev = plane->dev; |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2147 | struct drm_framebuffer *old_fb = NULL; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2148 | int ret = 0; |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 2149 | unsigned int fb_width, fb_height; |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2150 | int i; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2151 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2152 | /* No fb means shut it down */ |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2153 | if (!fb) { |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2154 | drm_modeset_lock_all(dev); |
| 2155 | old_fb = plane->fb; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 2156 | ret = plane->funcs->disable_plane(plane); |
| 2157 | if (!ret) { |
| 2158 | plane->crtc = NULL; |
| 2159 | plane->fb = NULL; |
| 2160 | } else { |
| 2161 | old_fb = NULL; |
| 2162 | } |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2163 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2164 | goto out; |
| 2165 | } |
| 2166 | |
Matt Roper | 7f994f3 | 2014-05-29 08:06:51 -0700 | [diff] [blame] | 2167 | /* Check whether this plane is usable on this CRTC */ |
| 2168 | if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) { |
| 2169 | DRM_DEBUG_KMS("Invalid crtc for plane\n"); |
| 2170 | ret = -EINVAL; |
| 2171 | goto out; |
| 2172 | } |
| 2173 | |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2174 | /* Check whether this plane supports the fb pixel format. */ |
| 2175 | for (i = 0; i < plane->format_count; i++) |
| 2176 | if (fb->pixel_format == plane->format_types[i]) |
| 2177 | break; |
| 2178 | if (i == plane->format_count) { |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 2179 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
| 2180 | drm_get_format_name(fb->pixel_format)); |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2181 | ret = -EINVAL; |
| 2182 | goto out; |
| 2183 | } |
| 2184 | |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 2185 | fb_width = fb->width << 16; |
| 2186 | fb_height = fb->height << 16; |
| 2187 | |
| 2188 | /* Make sure source coordinates are inside the fb. */ |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2189 | if (src_w > fb_width || |
| 2190 | src_x > fb_width - src_w || |
| 2191 | src_h > fb_height || |
| 2192 | src_y > fb_height - src_h) { |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 2193 | DRM_DEBUG_KMS("Invalid source coordinates " |
| 2194 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2195 | src_w >> 16, ((src_w & 0xffff) * 15625) >> 10, |
| 2196 | src_h >> 16, ((src_h & 0xffff) * 15625) >> 10, |
| 2197 | src_x >> 16, ((src_x & 0xffff) * 15625) >> 10, |
| 2198 | src_y >> 16, ((src_y & 0xffff) * 15625) >> 10); |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 2199 | ret = -ENOSPC; |
| 2200 | goto out; |
| 2201 | } |
| 2202 | |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2203 | drm_modeset_lock_all(dev); |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2204 | old_fb = plane->fb; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2205 | ret = plane->funcs->update_plane(plane, crtc, fb, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2206 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2207 | src_x, src_y, src_w, src_h); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2208 | if (!ret) { |
| 2209 | plane->crtc = crtc; |
| 2210 | plane->fb = fb; |
Daniel Vetter | 35f8bad | 2013-02-15 21:21:37 +0100 | [diff] [blame] | 2211 | fb = NULL; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2212 | } else { |
| 2213 | old_fb = NULL; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2214 | } |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2215 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2216 | |
| 2217 | out: |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2218 | if (fb) |
| 2219 | drm_framebuffer_unreference(fb); |
| 2220 | if (old_fb) |
| 2221 | drm_framebuffer_unreference(old_fb); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2222 | |
| 2223 | return ret; |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2224 | |
| 2225 | } |
| 2226 | |
| 2227 | /** |
| 2228 | * drm_mode_setplane - configure a plane's configuration |
| 2229 | * @dev: DRM device |
| 2230 | * @data: ioctl data* |
| 2231 | * @file_priv: DRM file info |
| 2232 | * |
| 2233 | * Set plane configuration, including placement, fb, scaling, and other factors. |
| 2234 | * Or pass a NULL fb to disable (planes may be disabled without providing a |
| 2235 | * valid crtc). |
| 2236 | * |
| 2237 | * Returns: |
| 2238 | * Zero on success, errno on failure. |
| 2239 | */ |
| 2240 | int drm_mode_setplane(struct drm_device *dev, void *data, |
| 2241 | struct drm_file *file_priv) |
| 2242 | { |
| 2243 | struct drm_mode_set_plane *plane_req = data; |
| 2244 | struct drm_mode_object *obj; |
| 2245 | struct drm_plane *plane; |
| 2246 | struct drm_crtc *crtc = NULL; |
| 2247 | struct drm_framebuffer *fb = NULL; |
| 2248 | |
| 2249 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2250 | return -EINVAL; |
| 2251 | |
| 2252 | /* Give drivers some help against integer overflows */ |
| 2253 | if (plane_req->crtc_w > INT_MAX || |
| 2254 | plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w || |
| 2255 | plane_req->crtc_h > INT_MAX || |
| 2256 | plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) { |
| 2257 | DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", |
| 2258 | plane_req->crtc_w, plane_req->crtc_h, |
| 2259 | plane_req->crtc_x, plane_req->crtc_y); |
| 2260 | return -ERANGE; |
| 2261 | } |
| 2262 | |
| 2263 | /* |
| 2264 | * First, find the plane, crtc, and fb objects. If not available, |
| 2265 | * we don't bother to call the driver. |
| 2266 | */ |
| 2267 | obj = drm_mode_object_find(dev, plane_req->plane_id, |
| 2268 | DRM_MODE_OBJECT_PLANE); |
| 2269 | if (!obj) { |
| 2270 | DRM_DEBUG_KMS("Unknown plane ID %d\n", |
| 2271 | plane_req->plane_id); |
| 2272 | return -ENOENT; |
| 2273 | } |
| 2274 | plane = obj_to_plane(obj); |
| 2275 | |
| 2276 | if (plane_req->fb_id) { |
| 2277 | fb = drm_framebuffer_lookup(dev, plane_req->fb_id); |
| 2278 | if (!fb) { |
| 2279 | DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", |
| 2280 | plane_req->fb_id); |
| 2281 | return -ENOENT; |
| 2282 | } |
| 2283 | |
| 2284 | obj = drm_mode_object_find(dev, plane_req->crtc_id, |
| 2285 | DRM_MODE_OBJECT_CRTC); |
| 2286 | if (!obj) { |
| 2287 | DRM_DEBUG_KMS("Unknown crtc ID %d\n", |
| 2288 | plane_req->crtc_id); |
| 2289 | return -ENOENT; |
| 2290 | } |
| 2291 | crtc = obj_to_crtc(obj); |
| 2292 | } |
| 2293 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2294 | /* |
| 2295 | * setplane_internal will take care of deref'ing either the old or new |
| 2296 | * framebuffer depending on success. |
| 2297 | */ |
Chris Wilson | 17cfd91 | 2014-06-13 15:22:28 +0100 | [diff] [blame] | 2298 | return setplane_internal(plane, crtc, fb, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2299 | plane_req->crtc_x, plane_req->crtc_y, |
| 2300 | plane_req->crtc_w, plane_req->crtc_h, |
| 2301 | plane_req->src_x, plane_req->src_y, |
| 2302 | plane_req->src_w, plane_req->src_h); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | /** |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2306 | * drm_mode_set_config_internal - helper to call ->set_config |
| 2307 | * @set: modeset config to set |
| 2308 | * |
| 2309 | * This is a little helper to wrap internal calls to the ->set_config driver |
| 2310 | * interface. The only thing it adds is correct refcounting dance. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2311 | * |
| 2312 | * Returns: |
| 2313 | * Zero on success, errno on failure. |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2314 | */ |
| 2315 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
| 2316 | { |
| 2317 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2318 | struct drm_framebuffer *fb; |
| 2319 | struct drm_crtc *tmp; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2320 | int ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2321 | |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2322 | /* |
| 2323 | * NOTE: ->set_config can also disable other crtcs (if we steal all |
| 2324 | * connectors from it), hence we need to refcount the fbs across all |
| 2325 | * crtcs. Atomic modeset will have saner semantics ... |
| 2326 | */ |
| 2327 | list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2328 | tmp->old_fb = tmp->primary->fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2329 | |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2330 | fb = set->fb; |
| 2331 | |
| 2332 | ret = crtc->funcs->set_config(set); |
| 2333 | if (ret == 0) { |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 2334 | crtc->primary->crtc = crtc; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2335 | crtc->primary->fb = fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2336 | } |
Daniel Vetter | cc85e12 | 2013-06-15 00:13:15 +0200 | [diff] [blame] | 2337 | |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2338 | list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2339 | if (tmp->primary->fb) |
| 2340 | drm_framebuffer_reference(tmp->primary->fb); |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2341 | if (tmp->old_fb) |
| 2342 | drm_framebuffer_unreference(tmp->old_fb); |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | return ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2346 | } |
| 2347 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
| 2348 | |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2349 | /** |
| 2350 | * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the |
| 2351 | * CRTC viewport |
| 2352 | * @crtc: CRTC that framebuffer will be displayed on |
| 2353 | * @x: x panning |
| 2354 | * @y: y panning |
| 2355 | * @mode: mode that framebuffer will be displayed under |
| 2356 | * @fb: framebuffer to check size of |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2357 | */ |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2358 | int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
| 2359 | int x, int y, |
| 2360 | const struct drm_display_mode *mode, |
| 2361 | const struct drm_framebuffer *fb) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2362 | |
| 2363 | { |
| 2364 | int hdisplay, vdisplay; |
| 2365 | |
| 2366 | hdisplay = mode->hdisplay; |
| 2367 | vdisplay = mode->vdisplay; |
| 2368 | |
Damien Lespiau | a0c1bbb | 2013-09-25 16:45:31 +0100 | [diff] [blame] | 2369 | if (drm_mode_is_stereo(mode)) { |
| 2370 | struct drm_display_mode adjusted = *mode; |
| 2371 | |
| 2372 | drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE); |
| 2373 | hdisplay = adjusted.crtc_hdisplay; |
| 2374 | vdisplay = adjusted.crtc_vdisplay; |
| 2375 | } |
| 2376 | |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2377 | if (crtc->invert_dimensions) |
| 2378 | swap(hdisplay, vdisplay); |
| 2379 | |
| 2380 | if (hdisplay > fb->width || |
| 2381 | vdisplay > fb->height || |
| 2382 | x > fb->width - hdisplay || |
| 2383 | y > fb->height - vdisplay) { |
| 2384 | DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n", |
| 2385 | fb->width, fb->height, hdisplay, vdisplay, x, y, |
| 2386 | crtc->invert_dimensions ? " (inverted)" : ""); |
| 2387 | return -ENOSPC; |
| 2388 | } |
| 2389 | |
| 2390 | return 0; |
| 2391 | } |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2392 | EXPORT_SYMBOL(drm_crtc_check_viewport); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2393 | |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2394 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2395 | * drm_mode_setcrtc - set CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2396 | * @dev: drm device for the ioctl |
| 2397 | * @data: data pointer for the ioctl |
| 2398 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2399 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2400 | * Build a new CRTC configuration based on user request. |
| 2401 | * |
| 2402 | * Called by the user via ioctl. |
| 2403 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2404 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2405 | * Zero on success, errno on failure. |
| 2406 | */ |
| 2407 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
| 2408 | struct drm_file *file_priv) |
| 2409 | { |
| 2410 | struct drm_mode_config *config = &dev->mode_config; |
| 2411 | struct drm_mode_crtc *crtc_req = data; |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2412 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2413 | struct drm_connector **connector_set = NULL, *connector; |
| 2414 | struct drm_framebuffer *fb = NULL; |
| 2415 | struct drm_display_mode *mode = NULL; |
| 2416 | struct drm_mode_set set; |
| 2417 | uint32_t __user *set_connectors_ptr; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2418 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2419 | int i; |
| 2420 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2421 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2422 | return -EINVAL; |
| 2423 | |
Ville Syrjälä | 1d97e91 | 2012-03-13 12:35:41 +0200 | [diff] [blame] | 2424 | /* For some reason crtc x/y offsets are signed internally. */ |
| 2425 | if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX) |
| 2426 | return -ERANGE; |
| 2427 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2428 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2429 | crtc = drm_crtc_find(dev, crtc_req->crtc_id); |
| 2430 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2431 | 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] | 2432 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2433 | goto out; |
| 2434 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2435 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2436 | |
| 2437 | if (crtc_req->mode_valid) { |
| 2438 | /* If we have a mode we need a framebuffer. */ |
| 2439 | /* If we pass -1, set the mode with the currently bound fb */ |
| 2440 | if (crtc_req->fb_id == -1) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2441 | if (!crtc->primary->fb) { |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2442 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
| 2443 | ret = -EINVAL; |
| 2444 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2445 | } |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2446 | fb = crtc->primary->fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2447 | /* Make refcounting symmetric with the lookup path. */ |
| 2448 | drm_framebuffer_reference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2449 | } else { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 2450 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
| 2451 | if (!fb) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2452 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
| 2453 | crtc_req->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 2454 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2455 | goto out; |
| 2456 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | mode = drm_mode_create(dev); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2460 | if (!mode) { |
| 2461 | ret = -ENOMEM; |
| 2462 | goto out; |
| 2463 | } |
| 2464 | |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 2465 | ret = drm_crtc_convert_umode(mode, &crtc_req->mode); |
| 2466 | if (ret) { |
| 2467 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 2468 | goto out; |
| 2469 | } |
| 2470 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2471 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2472 | |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2473 | ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, |
| 2474 | mode, fb); |
| 2475 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2476 | goto out; |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2477 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | if (crtc_req->count_connectors == 0 && mode) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2481 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2482 | ret = -EINVAL; |
| 2483 | goto out; |
| 2484 | } |
| 2485 | |
Jakob Bornecrantz | 7781de7 | 2009-08-03 13:43:58 +0100 | [diff] [blame] | 2486 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2487 | 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] | 2488 | crtc_req->count_connectors); |
| 2489 | ret = -EINVAL; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | |
| 2493 | if (crtc_req->count_connectors > 0) { |
| 2494 | u32 out_id; |
| 2495 | |
| 2496 | /* Avoid unbounded kernel memory allocation */ |
| 2497 | if (crtc_req->count_connectors > config->num_connector) { |
| 2498 | ret = -EINVAL; |
| 2499 | goto out; |
| 2500 | } |
| 2501 | |
| 2502 | connector_set = kmalloc(crtc_req->count_connectors * |
| 2503 | sizeof(struct drm_connector *), |
| 2504 | GFP_KERNEL); |
| 2505 | if (!connector_set) { |
| 2506 | ret = -ENOMEM; |
| 2507 | goto out; |
| 2508 | } |
| 2509 | |
| 2510 | for (i = 0; i < crtc_req->count_connectors; i++) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2511 | 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] | 2512 | if (get_user(out_id, &set_connectors_ptr[i])) { |
| 2513 | ret = -EFAULT; |
| 2514 | goto out; |
| 2515 | } |
| 2516 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2517 | connector = drm_connector_find(dev, out_id); |
| 2518 | if (!connector) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2519 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
| 2520 | out_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2521 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2522 | goto out; |
| 2523 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2524 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 2525 | connector->base.id, |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 2526 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2527 | |
| 2528 | connector_set[i] = connector; |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | set.crtc = crtc; |
| 2533 | set.x = crtc_req->x; |
| 2534 | set.y = crtc_req->y; |
| 2535 | set.mode = mode; |
| 2536 | set.connectors = connector_set; |
| 2537 | set.num_connectors = crtc_req->count_connectors; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 2538 | set.fb = fb; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2539 | ret = drm_mode_set_config_internal(&set); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2540 | |
| 2541 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2542 | if (fb) |
| 2543 | drm_framebuffer_unreference(fb); |
| 2544 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2545 | kfree(connector_set); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2546 | drm_mode_destroy(dev, mode); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2547 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2548 | return ret; |
| 2549 | } |
| 2550 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2551 | /** |
| 2552 | * drm_mode_cursor_universal - translate legacy cursor ioctl call into a |
| 2553 | * universal plane handler call |
| 2554 | * @crtc: crtc to update cursor for |
| 2555 | * @req: data pointer for the ioctl |
| 2556 | * @file_priv: drm file for the ioctl call |
| 2557 | * |
| 2558 | * Legacy cursor ioctl's work directly with driver buffer handles. To |
| 2559 | * translate legacy ioctl calls into universal plane handler calls, we need to |
| 2560 | * wrap the native buffer handle in a drm_framebuffer. |
| 2561 | * |
| 2562 | * Note that we assume any handle passed to the legacy ioctls was a 32-bit ARGB |
| 2563 | * buffer with a pitch of 4*width; the universal plane interface should be used |
| 2564 | * directly in cases where the hardware can support other buffer settings and |
| 2565 | * userspace wants to make use of these capabilities. |
| 2566 | * |
| 2567 | * Returns: |
| 2568 | * Zero on success, errno on failure. |
| 2569 | */ |
| 2570 | static int drm_mode_cursor_universal(struct drm_crtc *crtc, |
| 2571 | struct drm_mode_cursor2 *req, |
| 2572 | struct drm_file *file_priv) |
| 2573 | { |
| 2574 | struct drm_device *dev = crtc->dev; |
| 2575 | struct drm_framebuffer *fb = NULL; |
| 2576 | struct drm_mode_fb_cmd2 fbreq = { |
| 2577 | .width = req->width, |
| 2578 | .height = req->height, |
| 2579 | .pixel_format = DRM_FORMAT_ARGB8888, |
| 2580 | .pitches = { req->width * 4 }, |
| 2581 | .handles = { req->handle }, |
| 2582 | }; |
| 2583 | int32_t crtc_x, crtc_y; |
| 2584 | uint32_t crtc_w = 0, crtc_h = 0; |
| 2585 | uint32_t src_w = 0, src_h = 0; |
| 2586 | int ret = 0; |
| 2587 | |
| 2588 | BUG_ON(!crtc->cursor); |
| 2589 | |
| 2590 | /* |
| 2591 | * Obtain fb we'll be using (either new or existing) and take an extra |
| 2592 | * reference to it if fb != null. setplane will take care of dropping |
| 2593 | * the reference if the plane update fails. |
| 2594 | */ |
| 2595 | if (req->flags & DRM_MODE_CURSOR_BO) { |
| 2596 | if (req->handle) { |
| 2597 | fb = add_framebuffer_internal(dev, &fbreq, file_priv); |
| 2598 | if (IS_ERR(fb)) { |
| 2599 | DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n"); |
| 2600 | return PTR_ERR(fb); |
| 2601 | } |
| 2602 | |
| 2603 | drm_framebuffer_reference(fb); |
| 2604 | } else { |
| 2605 | fb = NULL; |
| 2606 | } |
| 2607 | } else { |
| 2608 | mutex_lock(&dev->mode_config.mutex); |
| 2609 | fb = crtc->cursor->fb; |
| 2610 | if (fb) |
| 2611 | drm_framebuffer_reference(fb); |
| 2612 | mutex_unlock(&dev->mode_config.mutex); |
| 2613 | } |
| 2614 | |
| 2615 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2616 | crtc_x = req->x; |
| 2617 | crtc_y = req->y; |
| 2618 | } else { |
| 2619 | crtc_x = crtc->cursor_x; |
| 2620 | crtc_y = crtc->cursor_y; |
| 2621 | } |
| 2622 | |
| 2623 | if (fb) { |
| 2624 | crtc_w = fb->width; |
| 2625 | crtc_h = fb->height; |
| 2626 | src_w = fb->width << 16; |
| 2627 | src_h = fb->height << 16; |
| 2628 | } |
| 2629 | |
| 2630 | /* |
| 2631 | * setplane_internal will take care of deref'ing either the old or new |
| 2632 | * framebuffer depending on success. |
| 2633 | */ |
Chris Wilson | 17cfd91 | 2014-06-13 15:22:28 +0100 | [diff] [blame] | 2634 | ret = setplane_internal(crtc->cursor, crtc, fb, |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2635 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2636 | 0, 0, src_w, src_h); |
| 2637 | |
| 2638 | /* Update successful; save new cursor position, if necessary */ |
| 2639 | if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2640 | crtc->cursor_x = req->x; |
| 2641 | crtc->cursor_y = req->y; |
| 2642 | } |
| 2643 | |
| 2644 | return ret; |
| 2645 | } |
| 2646 | |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2647 | static int drm_mode_cursor_common(struct drm_device *dev, |
| 2648 | struct drm_mode_cursor2 *req, |
| 2649 | struct drm_file *file_priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2650 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2651 | struct drm_crtc *crtc; |
| 2652 | int ret = 0; |
| 2653 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2654 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2655 | return -EINVAL; |
| 2656 | |
Jakob Bornecrantz | 7c4eaca | 2012-08-16 08:29:03 +0000 | [diff] [blame] | 2657 | if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2658 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2659 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2660 | crtc = drm_crtc_find(dev, req->crtc_id); |
| 2661 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2662 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2663 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2664 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2665 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2666 | /* |
| 2667 | * If this crtc has a universal cursor plane, call that plane's update |
| 2668 | * handler rather than using legacy cursor handlers. |
| 2669 | */ |
| 2670 | if (crtc->cursor) |
| 2671 | return drm_mode_cursor_universal(crtc, req, file_priv); |
| 2672 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 2673 | drm_modeset_lock(&crtc->mutex, NULL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2674 | if (req->flags & DRM_MODE_CURSOR_BO) { |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2675 | if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2676 | ret = -ENXIO; |
| 2677 | goto out; |
| 2678 | } |
| 2679 | /* Turns off the cursor if handle is 0 */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2680 | if (crtc->funcs->cursor_set2) |
| 2681 | ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle, |
| 2682 | req->width, req->height, req->hot_x, req->hot_y); |
| 2683 | else |
| 2684 | ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, |
| 2685 | req->width, req->height); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2689 | if (crtc->funcs->cursor_move) { |
| 2690 | ret = crtc->funcs->cursor_move(crtc, req->x, req->y); |
| 2691 | } else { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2692 | ret = -EFAULT; |
| 2693 | goto out; |
| 2694 | } |
| 2695 | } |
| 2696 | out: |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 2697 | drm_modeset_unlock(&crtc->mutex); |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 2698 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2699 | return ret; |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2700 | |
| 2701 | } |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2702 | |
| 2703 | |
| 2704 | /** |
| 2705 | * drm_mode_cursor_ioctl - set CRTC's cursor configuration |
| 2706 | * @dev: drm device for the ioctl |
| 2707 | * @data: data pointer for the ioctl |
| 2708 | * @file_priv: drm file for the ioctl call |
| 2709 | * |
| 2710 | * Set the cursor configuration based on user request. |
| 2711 | * |
| 2712 | * Called by the user via ioctl. |
| 2713 | * |
| 2714 | * Returns: |
| 2715 | * Zero on success, errno on failure. |
| 2716 | */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2717 | int drm_mode_cursor_ioctl(struct drm_device *dev, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2718 | void *data, struct drm_file *file_priv) |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2719 | { |
| 2720 | struct drm_mode_cursor *req = data; |
| 2721 | struct drm_mode_cursor2 new_req; |
| 2722 | |
| 2723 | memcpy(&new_req, req, sizeof(struct drm_mode_cursor)); |
| 2724 | new_req.hot_x = new_req.hot_y = 0; |
| 2725 | |
| 2726 | return drm_mode_cursor_common(dev, &new_req, file_priv); |
| 2727 | } |
| 2728 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2729 | /** |
| 2730 | * drm_mode_cursor2_ioctl - set CRTC's cursor configuration |
| 2731 | * @dev: drm device for the ioctl |
| 2732 | * @data: data pointer for the ioctl |
| 2733 | * @file_priv: drm file for the ioctl call |
| 2734 | * |
| 2735 | * Set the cursor configuration based on user request. This implements the 2nd |
| 2736 | * version of the cursor ioctl, which allows userspace to additionally specify |
| 2737 | * the hotspot of the pointer. |
| 2738 | * |
| 2739 | * Called by the user via ioctl. |
| 2740 | * |
| 2741 | * Returns: |
| 2742 | * Zero on success, errno on failure. |
| 2743 | */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2744 | int drm_mode_cursor2_ioctl(struct drm_device *dev, |
| 2745 | void *data, struct drm_file *file_priv) |
| 2746 | { |
| 2747 | struct drm_mode_cursor2 *req = data; |
| 2748 | return drm_mode_cursor_common(dev, req, file_priv); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2749 | } |
| 2750 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2751 | /** |
| 2752 | * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description |
| 2753 | * @bpp: bits per pixels |
| 2754 | * @depth: bit depth per pixel |
| 2755 | * |
| 2756 | * Computes a drm fourcc pixel format code for the given @bpp/@depth values. |
| 2757 | * Useful in fbdev emulation code, since that deals in those values. |
| 2758 | */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2759 | uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) |
| 2760 | { |
| 2761 | uint32_t fmt; |
| 2762 | |
| 2763 | switch (bpp) { |
| 2764 | case 8: |
Ville Syrjälä | d84f031 | 2013-01-31 19:43:38 +0200 | [diff] [blame] | 2765 | fmt = DRM_FORMAT_C8; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2766 | break; |
| 2767 | case 16: |
| 2768 | if (depth == 15) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2769 | fmt = DRM_FORMAT_XRGB1555; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2770 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2771 | fmt = DRM_FORMAT_RGB565; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2772 | break; |
| 2773 | case 24: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2774 | fmt = DRM_FORMAT_RGB888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2775 | break; |
| 2776 | case 32: |
| 2777 | if (depth == 24) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2778 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2779 | else if (depth == 30) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2780 | fmt = DRM_FORMAT_XRGB2101010; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2781 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2782 | fmt = DRM_FORMAT_ARGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2783 | break; |
| 2784 | default: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2785 | DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n"); |
| 2786 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2787 | break; |
| 2788 | } |
| 2789 | |
| 2790 | return fmt; |
| 2791 | } |
| 2792 | EXPORT_SYMBOL(drm_mode_legacy_fb_format); |
| 2793 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2794 | /** |
| 2795 | * drm_mode_addfb - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2796 | * @dev: drm device for the ioctl |
| 2797 | * @data: data pointer for the ioctl |
| 2798 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2799 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2800 | * Add a new FB to the specified CRTC, given a user request. This is the |
| 2801 | * original addfb ioclt which only supported RGB formats. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2802 | * |
| 2803 | * Called by the user via ioctl. |
| 2804 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2805 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2806 | * Zero on success, errno on failure. |
| 2807 | */ |
| 2808 | int drm_mode_addfb(struct drm_device *dev, |
| 2809 | void *data, struct drm_file *file_priv) |
| 2810 | { |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2811 | struct drm_mode_fb_cmd *or = data; |
| 2812 | struct drm_mode_fb_cmd2 r = {}; |
| 2813 | struct drm_mode_config *config = &dev->mode_config; |
| 2814 | struct drm_framebuffer *fb; |
| 2815 | int ret = 0; |
| 2816 | |
| 2817 | /* Use new struct with format internally */ |
| 2818 | r.fb_id = or->fb_id; |
| 2819 | r.width = or->width; |
| 2820 | r.height = or->height; |
| 2821 | r.pitches[0] = or->pitch; |
| 2822 | r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); |
| 2823 | r.handles[0] = or->handle; |
| 2824 | |
| 2825 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2826 | return -EINVAL; |
| 2827 | |
Jesse Barnes | acb4b99 | 2011-11-07 12:03:23 -0800 | [diff] [blame] | 2828 | if ((config->min_width > r.width) || (r.width > config->max_width)) |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2829 | return -EINVAL; |
Jesse Barnes | acb4b99 | 2011-11-07 12:03:23 -0800 | [diff] [blame] | 2830 | |
| 2831 | if ((config->min_height > r.height) || (r.height > config->max_height)) |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2832 | return -EINVAL; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2833 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2834 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r); |
| 2835 | if (IS_ERR(fb)) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2836 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2837 | return PTR_ERR(fb); |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2838 | } |
| 2839 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2840 | mutex_lock(&file_priv->fbs_lock); |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2841 | or->fb_id = fb->base.id; |
| 2842 | list_add(&fb->filp_head, &file_priv->fbs); |
| 2843 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2844 | mutex_unlock(&file_priv->fbs_lock); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2845 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2846 | return ret; |
| 2847 | } |
| 2848 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 2849 | static int format_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2850 | { |
| 2851 | uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; |
| 2852 | |
| 2853 | switch (format) { |
| 2854 | case DRM_FORMAT_C8: |
| 2855 | case DRM_FORMAT_RGB332: |
| 2856 | case DRM_FORMAT_BGR233: |
| 2857 | case DRM_FORMAT_XRGB4444: |
| 2858 | case DRM_FORMAT_XBGR4444: |
| 2859 | case DRM_FORMAT_RGBX4444: |
| 2860 | case DRM_FORMAT_BGRX4444: |
| 2861 | case DRM_FORMAT_ARGB4444: |
| 2862 | case DRM_FORMAT_ABGR4444: |
| 2863 | case DRM_FORMAT_RGBA4444: |
| 2864 | case DRM_FORMAT_BGRA4444: |
| 2865 | case DRM_FORMAT_XRGB1555: |
| 2866 | case DRM_FORMAT_XBGR1555: |
| 2867 | case DRM_FORMAT_RGBX5551: |
| 2868 | case DRM_FORMAT_BGRX5551: |
| 2869 | case DRM_FORMAT_ARGB1555: |
| 2870 | case DRM_FORMAT_ABGR1555: |
| 2871 | case DRM_FORMAT_RGBA5551: |
| 2872 | case DRM_FORMAT_BGRA5551: |
| 2873 | case DRM_FORMAT_RGB565: |
| 2874 | case DRM_FORMAT_BGR565: |
| 2875 | case DRM_FORMAT_RGB888: |
| 2876 | case DRM_FORMAT_BGR888: |
| 2877 | case DRM_FORMAT_XRGB8888: |
| 2878 | case DRM_FORMAT_XBGR8888: |
| 2879 | case DRM_FORMAT_RGBX8888: |
| 2880 | case DRM_FORMAT_BGRX8888: |
| 2881 | case DRM_FORMAT_ARGB8888: |
| 2882 | case DRM_FORMAT_ABGR8888: |
| 2883 | case DRM_FORMAT_RGBA8888: |
| 2884 | case DRM_FORMAT_BGRA8888: |
| 2885 | case DRM_FORMAT_XRGB2101010: |
| 2886 | case DRM_FORMAT_XBGR2101010: |
| 2887 | case DRM_FORMAT_RGBX1010102: |
| 2888 | case DRM_FORMAT_BGRX1010102: |
| 2889 | case DRM_FORMAT_ARGB2101010: |
| 2890 | case DRM_FORMAT_ABGR2101010: |
| 2891 | case DRM_FORMAT_RGBA1010102: |
| 2892 | case DRM_FORMAT_BGRA1010102: |
| 2893 | case DRM_FORMAT_YUYV: |
| 2894 | case DRM_FORMAT_YVYU: |
| 2895 | case DRM_FORMAT_UYVY: |
| 2896 | case DRM_FORMAT_VYUY: |
| 2897 | case DRM_FORMAT_AYUV: |
| 2898 | case DRM_FORMAT_NV12: |
| 2899 | case DRM_FORMAT_NV21: |
| 2900 | case DRM_FORMAT_NV16: |
| 2901 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 2902 | case DRM_FORMAT_NV24: |
| 2903 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2904 | case DRM_FORMAT_YUV410: |
| 2905 | case DRM_FORMAT_YVU410: |
| 2906 | case DRM_FORMAT_YUV411: |
| 2907 | case DRM_FORMAT_YVU411: |
| 2908 | case DRM_FORMAT_YUV420: |
| 2909 | case DRM_FORMAT_YVU420: |
| 2910 | case DRM_FORMAT_YUV422: |
| 2911 | case DRM_FORMAT_YVU422: |
| 2912 | case DRM_FORMAT_YUV444: |
| 2913 | case DRM_FORMAT_YVU444: |
| 2914 | return 0; |
| 2915 | default: |
Ville Syrjälä | 23c453a | 2013-10-15 21:06:51 +0300 | [diff] [blame] | 2916 | DRM_DEBUG_KMS("invalid pixel format %s\n", |
| 2917 | drm_get_format_name(r->pixel_format)); |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2918 | return -EINVAL; |
| 2919 | } |
| 2920 | } |
| 2921 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 2922 | static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2923 | { |
| 2924 | int ret, hsub, vsub, num_planes, i; |
| 2925 | |
| 2926 | ret = format_check(r); |
| 2927 | if (ret) { |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 2928 | DRM_DEBUG_KMS("bad framebuffer format %s\n", |
| 2929 | drm_get_format_name(r->pixel_format)); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2930 | return ret; |
| 2931 | } |
| 2932 | |
| 2933 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); |
| 2934 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); |
| 2935 | num_planes = drm_format_num_planes(r->pixel_format); |
| 2936 | |
| 2937 | if (r->width == 0 || r->width % hsub) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2938 | DRM_DEBUG_KMS("bad framebuffer width %u\n", r->height); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2939 | return -EINVAL; |
| 2940 | } |
| 2941 | |
| 2942 | if (r->height == 0 || r->height % vsub) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2943 | DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2944 | return -EINVAL; |
| 2945 | } |
| 2946 | |
| 2947 | for (i = 0; i < num_planes; i++) { |
| 2948 | unsigned int width = r->width / (i != 0 ? hsub : 1); |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 2949 | unsigned int height = r->height / (i != 0 ? vsub : 1); |
| 2950 | unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2951 | |
| 2952 | if (!r->handles[i]) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2953 | DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2954 | return -EINVAL; |
| 2955 | } |
| 2956 | |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 2957 | if ((uint64_t) width * cpp > UINT_MAX) |
| 2958 | return -ERANGE; |
| 2959 | |
| 2960 | if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) |
| 2961 | return -ERANGE; |
| 2962 | |
| 2963 | if (r->pitches[i] < width * cpp) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2964 | DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2965 | return -EINVAL; |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 2972 | static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev, |
| 2973 | struct drm_mode_fb_cmd2 *r, |
| 2974 | struct drm_file *file_priv) |
| 2975 | { |
| 2976 | struct drm_mode_config *config = &dev->mode_config; |
| 2977 | struct drm_framebuffer *fb; |
| 2978 | int ret; |
| 2979 | |
| 2980 | if (r->flags & ~DRM_MODE_FB_INTERLACED) { |
| 2981 | DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags); |
| 2982 | return ERR_PTR(-EINVAL); |
| 2983 | } |
| 2984 | |
| 2985 | if ((config->min_width > r->width) || (r->width > config->max_width)) { |
| 2986 | DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n", |
| 2987 | r->width, config->min_width, config->max_width); |
| 2988 | return ERR_PTR(-EINVAL); |
| 2989 | } |
| 2990 | if ((config->min_height > r->height) || (r->height > config->max_height)) { |
| 2991 | DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n", |
| 2992 | r->height, config->min_height, config->max_height); |
| 2993 | return ERR_PTR(-EINVAL); |
| 2994 | } |
| 2995 | |
| 2996 | ret = framebuffer_check(r); |
| 2997 | if (ret) |
| 2998 | return ERR_PTR(ret); |
| 2999 | |
| 3000 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); |
| 3001 | if (IS_ERR(fb)) { |
| 3002 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
| 3003 | return fb; |
| 3004 | } |
| 3005 | |
| 3006 | mutex_lock(&file_priv->fbs_lock); |
| 3007 | r->fb_id = fb->base.id; |
| 3008 | list_add(&fb->filp_head, &file_priv->fbs); |
| 3009 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
| 3010 | mutex_unlock(&file_priv->fbs_lock); |
| 3011 | |
| 3012 | return fb; |
| 3013 | } |
| 3014 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3015 | /** |
| 3016 | * drm_mode_addfb2 - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3017 | * @dev: drm device for the ioctl |
| 3018 | * @data: data pointer for the ioctl |
| 3019 | * @file_priv: drm file for the ioctl call |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3020 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3021 | * Add a new FB to the specified CRTC, given a user request with format. This is |
| 3022 | * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers |
| 3023 | * and uses fourcc codes as pixel format specifiers. |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3024 | * |
| 3025 | * Called by the user via ioctl. |
| 3026 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3027 | * Returns: |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3028 | * Zero on success, errno on failure. |
| 3029 | */ |
| 3030 | int drm_mode_addfb2(struct drm_device *dev, |
| 3031 | void *data, struct drm_file *file_priv) |
| 3032 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3033 | struct drm_framebuffer *fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3034 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3035 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3036 | return -EINVAL; |
| 3037 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3038 | fb = add_framebuffer_internal(dev, data, file_priv); |
| 3039 | if (IS_ERR(fb)) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3040 | return PTR_ERR(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3041 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3042 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | /** |
| 3046 | * drm_mode_rmfb - remove an FB from the configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3047 | * @dev: drm device for the ioctl |
| 3048 | * @data: data pointer for the ioctl |
| 3049 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3050 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3051 | * Remove the FB specified by the user. |
| 3052 | * |
| 3053 | * Called by the user via ioctl. |
| 3054 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3055 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3056 | * Zero on success, errno on failure. |
| 3057 | */ |
| 3058 | int drm_mode_rmfb(struct drm_device *dev, |
| 3059 | void *data, struct drm_file *file_priv) |
| 3060 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3061 | struct drm_framebuffer *fb = NULL; |
| 3062 | struct drm_framebuffer *fbl = NULL; |
| 3063 | uint32_t *id = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3064 | int found = 0; |
| 3065 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3066 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3067 | return -EINVAL; |
| 3068 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3069 | mutex_lock(&file_priv->fbs_lock); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3070 | mutex_lock(&dev->mode_config.fb_lock); |
| 3071 | fb = __drm_framebuffer_lookup(dev, *id); |
| 3072 | if (!fb) |
| 3073 | goto fail_lookup; |
| 3074 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3075 | list_for_each_entry(fbl, &file_priv->fbs, filp_head) |
| 3076 | if (fb == fbl) |
| 3077 | found = 1; |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3078 | if (!found) |
| 3079 | goto fail_lookup; |
| 3080 | |
| 3081 | /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ |
| 3082 | __drm_framebuffer_unregister(dev, fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3083 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3084 | list_del_init(&fb->filp_head); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3085 | mutex_unlock(&dev->mode_config.fb_lock); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3086 | mutex_unlock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3087 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3088 | drm_framebuffer_remove(fb); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3089 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3090 | return 0; |
| 3091 | |
| 3092 | fail_lookup: |
| 3093 | mutex_unlock(&dev->mode_config.fb_lock); |
| 3094 | mutex_unlock(&file_priv->fbs_lock); |
| 3095 | |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3096 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | /** |
| 3100 | * drm_mode_getfb - get FB info |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3101 | * @dev: drm device for the ioctl |
| 3102 | * @data: data pointer for the ioctl |
| 3103 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3104 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3105 | * Lookup the FB given its ID and return info about it. |
| 3106 | * |
| 3107 | * Called by the user via ioctl. |
| 3108 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3109 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3110 | * Zero on success, errno on failure. |
| 3111 | */ |
| 3112 | int drm_mode_getfb(struct drm_device *dev, |
| 3113 | void *data, struct drm_file *file_priv) |
| 3114 | { |
| 3115 | struct drm_mode_fb_cmd *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3116 | struct drm_framebuffer *fb; |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3117 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3118 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3119 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3120 | return -EINVAL; |
| 3121 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3122 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3123 | if (!fb) |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3124 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3125 | |
| 3126 | r->height = fb->height; |
| 3127 | r->width = fb->width; |
| 3128 | r->depth = fb->depth; |
| 3129 | r->bpp = fb->bits_per_pixel; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 3130 | r->pitch = fb->pitches[0]; |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3131 | if (fb->funcs->create_handle) { |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 3132 | if (file_priv->is_master || capable(CAP_SYS_ADMIN) || |
Thomas Hellstrom | 4368305 | 2014-03-13 11:07:44 +0100 | [diff] [blame] | 3133 | drm_is_control_client(file_priv)) { |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3134 | ret = fb->funcs->create_handle(fb, file_priv, |
| 3135 | &r->handle); |
| 3136 | } else { |
| 3137 | /* GET_FB() is an unprivileged ioctl so we must not |
| 3138 | * return a buffer-handle to non-master processes! For |
| 3139 | * backwards-compatibility reasons, we cannot make |
| 3140 | * GET_FB() privileged, so just return an invalid handle |
| 3141 | * for non-masters. */ |
| 3142 | r->handle = 0; |
| 3143 | ret = 0; |
| 3144 | } |
| 3145 | } else { |
Daniel Vetter | af26ef3 | 2012-12-13 23:07:50 +0100 | [diff] [blame] | 3146 | ret = -ENODEV; |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3147 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3148 | |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3149 | drm_framebuffer_unreference(fb); |
| 3150 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3151 | return ret; |
| 3152 | } |
| 3153 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3154 | /** |
| 3155 | * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB |
| 3156 | * @dev: drm device for the ioctl |
| 3157 | * @data: data pointer for the ioctl |
| 3158 | * @file_priv: drm file for the ioctl call |
| 3159 | * |
| 3160 | * Lookup the FB and flush out the damaged area supplied by userspace as a clip |
| 3161 | * rectangle list. Generic userspace which does frontbuffer rendering must call |
| 3162 | * this ioctl to flush out the changes on manual-update display outputs, e.g. |
| 3163 | * usb display-link, mipi manual update panels or edp panel self refresh modes. |
| 3164 | * |
| 3165 | * Modesetting drivers which always update the frontbuffer do not need to |
| 3166 | * implement the corresponding ->dirty framebuffer callback. |
| 3167 | * |
| 3168 | * Called by the user via ioctl. |
| 3169 | * |
| 3170 | * Returns: |
| 3171 | * Zero on success, errno on failure. |
| 3172 | */ |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3173 | int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
| 3174 | void *data, struct drm_file *file_priv) |
| 3175 | { |
| 3176 | struct drm_clip_rect __user *clips_ptr; |
| 3177 | struct drm_clip_rect *clips = NULL; |
| 3178 | struct drm_mode_fb_dirty_cmd *r = data; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3179 | struct drm_framebuffer *fb; |
| 3180 | unsigned flags; |
| 3181 | int num_clips; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 3182 | int ret; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3183 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3184 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3185 | return -EINVAL; |
| 3186 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3187 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 3188 | if (!fb) |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3189 | return -ENOENT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3190 | |
| 3191 | num_clips = r->num_clips; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3192 | clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3193 | |
| 3194 | if (!num_clips != !clips_ptr) { |
| 3195 | ret = -EINVAL; |
| 3196 | goto out_err1; |
| 3197 | } |
| 3198 | |
| 3199 | flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags; |
| 3200 | |
| 3201 | /* If userspace annotates copy, clips must come in pairs */ |
| 3202 | if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) { |
| 3203 | ret = -EINVAL; |
| 3204 | goto out_err1; |
| 3205 | } |
| 3206 | |
| 3207 | if (num_clips && clips_ptr) { |
Xi Wang | a5cd335 | 2011-11-23 01:12:01 -0500 | [diff] [blame] | 3208 | if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) { |
| 3209 | ret = -EINVAL; |
| 3210 | goto out_err1; |
| 3211 | } |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3212 | clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL); |
| 3213 | if (!clips) { |
| 3214 | ret = -ENOMEM; |
| 3215 | goto out_err1; |
| 3216 | } |
| 3217 | |
| 3218 | ret = copy_from_user(clips, clips_ptr, |
| 3219 | num_clips * sizeof(*clips)); |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 3220 | if (ret) { |
| 3221 | ret = -EFAULT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3222 | goto out_err2; |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 3223 | } |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | if (fb->funcs->dirty) { |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 3227 | ret = fb->funcs->dirty(fb, file_priv, flags, r->color, |
| 3228 | clips, num_clips); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3229 | } else { |
| 3230 | ret = -ENOSYS; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | out_err2: |
| 3234 | kfree(clips); |
| 3235 | out_err1: |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 3236 | drm_framebuffer_unreference(fb); |
| 3237 | |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3238 | return ret; |
| 3239 | } |
| 3240 | |
| 3241 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3242 | /** |
| 3243 | * drm_fb_release - remove and free the FBs on this file |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3244 | * @priv: drm file for the ioctl |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3245 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3246 | * Destroy all the FBs associated with @filp. |
| 3247 | * |
| 3248 | * Called by the user via ioctl. |
| 3249 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3250 | * Returns: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3251 | * Zero on success, errno on failure. |
| 3252 | */ |
Kristian Høgsberg | ea39f83 | 2009-02-12 14:37:56 -0500 | [diff] [blame] | 3253 | void drm_fb_release(struct drm_file *priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3254 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3255 | struct drm_device *dev = priv->minor->dev; |
| 3256 | struct drm_framebuffer *fb, *tfb; |
| 3257 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3258 | mutex_lock(&priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3259 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3260 | |
| 3261 | mutex_lock(&dev->mode_config.fb_lock); |
| 3262 | /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ |
| 3263 | __drm_framebuffer_unregister(dev, fb); |
| 3264 | mutex_unlock(&dev->mode_config.fb_lock); |
| 3265 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3266 | list_del_init(&fb->filp_head); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3267 | |
| 3268 | /* This will also drop the fpriv->fbs reference. */ |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 3269 | drm_framebuffer_remove(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3270 | } |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3271 | mutex_unlock(&priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3272 | } |
| 3273 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3274 | /** |
| 3275 | * drm_property_create - create a new property type |
| 3276 | * @dev: drm device |
| 3277 | * @flags: flags specifying the property type |
| 3278 | * @name: name of the property |
| 3279 | * @num_values: number of pre-defined values |
| 3280 | * |
| 3281 | * This creates a new generic drm property which can then be attached to a drm |
| 3282 | * object with drm_object_attach_property. The returned property object must be |
| 3283 | * freed with drm_property_destroy. |
| 3284 | * |
| 3285 | * Returns: |
| 3286 | * A pointer to the newly created property on success, NULL on failure. |
| 3287 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3288 | struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
| 3289 | const char *name, int num_values) |
| 3290 | { |
| 3291 | struct drm_property *property = NULL; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3292 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3293 | |
| 3294 | property = kzalloc(sizeof(struct drm_property), GFP_KERNEL); |
| 3295 | if (!property) |
| 3296 | return NULL; |
| 3297 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3298 | property->dev = dev; |
| 3299 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3300 | if (num_values) { |
| 3301 | property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL); |
| 3302 | if (!property->values) |
| 3303 | goto fail; |
| 3304 | } |
| 3305 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3306 | ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); |
| 3307 | if (ret) |
| 3308 | goto fail; |
| 3309 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3310 | property->flags = flags; |
| 3311 | property->num_values = num_values; |
| 3312 | INIT_LIST_HEAD(&property->enum_blob_list); |
| 3313 | |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 3314 | if (name) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3315 | strncpy(property->name, name, DRM_PROP_NAME_LEN); |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 3316 | property->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3317 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3318 | |
| 3319 | list_add_tail(&property->head, &dev->mode_config.property_list); |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3320 | |
| 3321 | WARN_ON(!drm_property_type_valid(property)); |
| 3322 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3323 | return property; |
| 3324 | fail: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3325 | kfree(property->values); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3326 | kfree(property); |
| 3327 | return NULL; |
| 3328 | } |
| 3329 | EXPORT_SYMBOL(drm_property_create); |
| 3330 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3331 | /** |
| 3332 | * drm_property_create - create a new enumeration property type |
| 3333 | * @dev: drm device |
| 3334 | * @flags: flags specifying the property type |
| 3335 | * @name: name of the property |
| 3336 | * @props: enumeration lists with property values |
| 3337 | * @num_values: number of pre-defined values |
| 3338 | * |
| 3339 | * This creates a new generic drm property which can then be attached to a drm |
| 3340 | * object with drm_object_attach_property. The returned property object must be |
| 3341 | * freed with drm_property_destroy. |
| 3342 | * |
| 3343 | * Userspace is only allowed to set one of the predefined values for enumeration |
| 3344 | * properties. |
| 3345 | * |
| 3346 | * Returns: |
| 3347 | * A pointer to the newly created property on success, NULL on failure. |
| 3348 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 3349 | struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
| 3350 | const char *name, |
| 3351 | const struct drm_prop_enum_list *props, |
| 3352 | int num_values) |
| 3353 | { |
| 3354 | struct drm_property *property; |
| 3355 | int i, ret; |
| 3356 | |
| 3357 | flags |= DRM_MODE_PROP_ENUM; |
| 3358 | |
| 3359 | property = drm_property_create(dev, flags, name, num_values); |
| 3360 | if (!property) |
| 3361 | return NULL; |
| 3362 | |
| 3363 | for (i = 0; i < num_values; i++) { |
| 3364 | ret = drm_property_add_enum(property, i, |
| 3365 | props[i].type, |
| 3366 | props[i].name); |
| 3367 | if (ret) { |
| 3368 | drm_property_destroy(dev, property); |
| 3369 | return NULL; |
| 3370 | } |
| 3371 | } |
| 3372 | |
| 3373 | return property; |
| 3374 | } |
| 3375 | EXPORT_SYMBOL(drm_property_create_enum); |
| 3376 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3377 | /** |
| 3378 | * drm_property_create - create a new bitmask property type |
| 3379 | * @dev: drm device |
| 3380 | * @flags: flags specifying the property type |
| 3381 | * @name: name of the property |
| 3382 | * @props: enumeration lists with property bitflags |
| 3383 | * @num_values: number of pre-defined values |
| 3384 | * |
| 3385 | * This creates a new generic drm property which can then be attached to a drm |
| 3386 | * object with drm_object_attach_property. The returned property object must be |
| 3387 | * freed with drm_property_destroy. |
| 3388 | * |
| 3389 | * Compared to plain enumeration properties userspace is allowed to set any |
| 3390 | * or'ed together combination of the predefined property bitflag values |
| 3391 | * |
| 3392 | * Returns: |
| 3393 | * A pointer to the newly created property on success, NULL on failure. |
| 3394 | */ |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3395 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
| 3396 | int flags, const char *name, |
| 3397 | const struct drm_prop_enum_list *props, |
| 3398 | int num_values) |
| 3399 | { |
| 3400 | struct drm_property *property; |
| 3401 | int i, ret; |
| 3402 | |
| 3403 | flags |= DRM_MODE_PROP_BITMASK; |
| 3404 | |
| 3405 | property = drm_property_create(dev, flags, name, num_values); |
| 3406 | if (!property) |
| 3407 | return NULL; |
| 3408 | |
| 3409 | for (i = 0; i < num_values; i++) { |
| 3410 | ret = drm_property_add_enum(property, i, |
| 3411 | props[i].type, |
| 3412 | props[i].name); |
| 3413 | if (ret) { |
| 3414 | drm_property_destroy(dev, property); |
| 3415 | return NULL; |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | return property; |
| 3420 | } |
| 3421 | EXPORT_SYMBOL(drm_property_create_bitmask); |
| 3422 | |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3423 | static struct drm_property *property_create_range(struct drm_device *dev, |
| 3424 | int flags, const char *name, |
| 3425 | uint64_t min, uint64_t max) |
| 3426 | { |
| 3427 | struct drm_property *property; |
| 3428 | |
| 3429 | property = drm_property_create(dev, flags, name, 2); |
| 3430 | if (!property) |
| 3431 | return NULL; |
| 3432 | |
| 3433 | property->values[0] = min; |
| 3434 | property->values[1] = max; |
| 3435 | |
| 3436 | return property; |
| 3437 | } |
| 3438 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3439 | /** |
| 3440 | * drm_property_create - create a new ranged property type |
| 3441 | * @dev: drm device |
| 3442 | * @flags: flags specifying the property type |
| 3443 | * @name: name of the property |
| 3444 | * @min: minimum value of the property |
| 3445 | * @max: maximum value of the property |
| 3446 | * |
| 3447 | * This creates a new generic drm property which can then be attached to a drm |
| 3448 | * object with drm_object_attach_property. The returned property object must be |
| 3449 | * freed with drm_property_destroy. |
| 3450 | * |
| 3451 | * Userspace is allowed to set any interger value in the (min, max) range |
| 3452 | * inclusive. |
| 3453 | * |
| 3454 | * Returns: |
| 3455 | * A pointer to the newly created property on success, NULL on failure. |
| 3456 | */ |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3457 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
| 3458 | const char *name, |
| 3459 | uint64_t min, uint64_t max) |
| 3460 | { |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3461 | return property_create_range(dev, DRM_MODE_PROP_RANGE | flags, |
| 3462 | name, min, max); |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3463 | } |
| 3464 | EXPORT_SYMBOL(drm_property_create_range); |
| 3465 | |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3466 | struct drm_property *drm_property_create_signed_range(struct drm_device *dev, |
| 3467 | int flags, const char *name, |
| 3468 | int64_t min, int64_t max) |
| 3469 | { |
| 3470 | return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags, |
| 3471 | name, I642U64(min), I642U64(max)); |
| 3472 | } |
| 3473 | EXPORT_SYMBOL(drm_property_create_signed_range); |
| 3474 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3475 | struct drm_property *drm_property_create_object(struct drm_device *dev, |
| 3476 | int flags, const char *name, uint32_t type) |
| 3477 | { |
| 3478 | struct drm_property *property; |
| 3479 | |
| 3480 | flags |= DRM_MODE_PROP_OBJECT; |
| 3481 | |
| 3482 | property = drm_property_create(dev, flags, name, 1); |
| 3483 | if (!property) |
| 3484 | return NULL; |
| 3485 | |
| 3486 | property->values[0] = type; |
| 3487 | |
| 3488 | return property; |
| 3489 | } |
| 3490 | EXPORT_SYMBOL(drm_property_create_object); |
| 3491 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3492 | /** |
| 3493 | * drm_property_add_enum - add a possible value to an enumeration property |
| 3494 | * @property: enumeration property to change |
| 3495 | * @index: index of the new enumeration |
| 3496 | * @value: value of the new enumeration |
| 3497 | * @name: symbolic name of the new enumeration |
| 3498 | * |
| 3499 | * This functions adds enumerations to a property. |
| 3500 | * |
| 3501 | * It's use is deprecated, drivers should use one of the more specific helpers |
| 3502 | * to directly create the property with all enumerations already attached. |
| 3503 | * |
| 3504 | * Returns: |
| 3505 | * Zero on success, error code on failure. |
| 3506 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3507 | int drm_property_add_enum(struct drm_property *property, int index, |
| 3508 | uint64_t value, const char *name) |
| 3509 | { |
| 3510 | struct drm_property_enum *prop_enum; |
| 3511 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3512 | if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 3513 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK))) |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3514 | return -EINVAL; |
| 3515 | |
| 3516 | /* |
| 3517 | * Bitmask enum properties have the additional constraint of values |
| 3518 | * from 0 to 63 |
| 3519 | */ |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3520 | if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) && |
| 3521 | (value > 63)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3522 | return -EINVAL; |
| 3523 | |
| 3524 | if (!list_empty(&property->enum_blob_list)) { |
| 3525 | list_for_each_entry(prop_enum, &property->enum_blob_list, head) { |
| 3526 | if (prop_enum->value == value) { |
| 3527 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 3528 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3529 | return 0; |
| 3530 | } |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL); |
| 3535 | if (!prop_enum) |
| 3536 | return -ENOMEM; |
| 3537 | |
| 3538 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 3539 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3540 | prop_enum->value = value; |
| 3541 | |
| 3542 | property->values[index] = value; |
| 3543 | list_add_tail(&prop_enum->head, &property->enum_blob_list); |
| 3544 | return 0; |
| 3545 | } |
| 3546 | EXPORT_SYMBOL(drm_property_add_enum); |
| 3547 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3548 | /** |
| 3549 | * drm_property_destroy - destroy a drm property |
| 3550 | * @dev: drm device |
| 3551 | * @property: property to destry |
| 3552 | * |
| 3553 | * This function frees a property including any attached resources like |
| 3554 | * enumeration values. |
| 3555 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3556 | void drm_property_destroy(struct drm_device *dev, struct drm_property *property) |
| 3557 | { |
| 3558 | struct drm_property_enum *prop_enum, *pt; |
| 3559 | |
| 3560 | list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) { |
| 3561 | list_del(&prop_enum->head); |
| 3562 | kfree(prop_enum); |
| 3563 | } |
| 3564 | |
| 3565 | if (property->num_values) |
| 3566 | kfree(property->values); |
| 3567 | drm_mode_object_put(dev, &property->base); |
| 3568 | list_del(&property->head); |
| 3569 | kfree(property); |
| 3570 | } |
| 3571 | EXPORT_SYMBOL(drm_property_destroy); |
| 3572 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3573 | /** |
| 3574 | * drm_object_attach_property - attach a property to a modeset object |
| 3575 | * @obj: drm modeset object |
| 3576 | * @property: property to attach |
| 3577 | * @init_val: initial value of the property |
| 3578 | * |
| 3579 | * This attaches the given property to the modeset object with the given initial |
| 3580 | * value. Currently this function cannot fail since the properties are stored in |
| 3581 | * a statically sized array. |
| 3582 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3583 | void drm_object_attach_property(struct drm_mode_object *obj, |
| 3584 | struct drm_property *property, |
| 3585 | uint64_t init_val) |
| 3586 | { |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3587 | int count = obj->properties->count; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3588 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3589 | if (count == DRM_OBJECT_MAX_PROPERTY) { |
| 3590 | WARN(1, "Failed to attach object property (type: 0x%x). Please " |
| 3591 | "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " |
| 3592 | "you see this message on the same object type.\n", |
| 3593 | obj->type); |
| 3594 | return; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3595 | } |
| 3596 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3597 | obj->properties->ids[count] = property->base.id; |
| 3598 | obj->properties->values[count] = init_val; |
| 3599 | obj->properties->count++; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3600 | } |
| 3601 | EXPORT_SYMBOL(drm_object_attach_property); |
| 3602 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3603 | /** |
| 3604 | * drm_object_property_set_value - set the value of a property |
| 3605 | * @obj: drm mode object to set property value for |
| 3606 | * @property: property to set |
| 3607 | * @val: value the property should be set to |
| 3608 | * |
| 3609 | * This functions sets a given property on a given object. This function only |
| 3610 | * changes the software state of the property, it does not call into the |
| 3611 | * driver's ->set_property callback. |
| 3612 | * |
| 3613 | * Returns: |
| 3614 | * Zero on success, error code on failure. |
| 3615 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3616 | int drm_object_property_set_value(struct drm_mode_object *obj, |
| 3617 | struct drm_property *property, uint64_t val) |
| 3618 | { |
| 3619 | int i; |
| 3620 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3621 | for (i = 0; i < obj->properties->count; i++) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3622 | if (obj->properties->ids[i] == property->base.id) { |
| 3623 | obj->properties->values[i] = val; |
| 3624 | return 0; |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | return -EINVAL; |
| 3629 | } |
| 3630 | EXPORT_SYMBOL(drm_object_property_set_value); |
| 3631 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3632 | /** |
| 3633 | * drm_object_property_get_value - retrieve the value of a property |
| 3634 | * @obj: drm mode object to get property value from |
| 3635 | * @property: property to retrieve |
| 3636 | * @val: storage for the property value |
| 3637 | * |
| 3638 | * This function retrieves the softare state of the given property for the given |
| 3639 | * property. Since there is no driver callback to retrieve the current property |
| 3640 | * value this might be out of sync with the hardware, depending upon the driver |
| 3641 | * and property. |
| 3642 | * |
| 3643 | * Returns: |
| 3644 | * Zero on success, error code on failure. |
| 3645 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3646 | int drm_object_property_get_value(struct drm_mode_object *obj, |
| 3647 | struct drm_property *property, uint64_t *val) |
| 3648 | { |
| 3649 | int i; |
| 3650 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3651 | for (i = 0; i < obj->properties->count; i++) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3652 | if (obj->properties->ids[i] == property->base.id) { |
| 3653 | *val = obj->properties->values[i]; |
| 3654 | return 0; |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | return -EINVAL; |
| 3659 | } |
| 3660 | EXPORT_SYMBOL(drm_object_property_get_value); |
| 3661 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3662 | /** |
| 3663 | * drm_mode_getproperty_ioctl - get the current value of a connector's property |
| 3664 | * @dev: DRM device |
| 3665 | * @data: ioctl data |
| 3666 | * @file_priv: DRM file info |
| 3667 | * |
| 3668 | * This function retrieves the current value for an connectors's property. |
| 3669 | * |
| 3670 | * Called by the user via ioctl. |
| 3671 | * |
| 3672 | * Returns: |
| 3673 | * Zero on success, errno on failure. |
| 3674 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3675 | int drm_mode_getproperty_ioctl(struct drm_device *dev, |
| 3676 | void *data, struct drm_file *file_priv) |
| 3677 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3678 | struct drm_mode_get_property *out_resp = data; |
| 3679 | struct drm_property *property; |
| 3680 | int enum_count = 0; |
| 3681 | int blob_count = 0; |
| 3682 | int value_count = 0; |
| 3683 | int ret = 0, i; |
| 3684 | int copied; |
| 3685 | struct drm_property_enum *prop_enum; |
| 3686 | struct drm_mode_property_enum __user *enum_ptr; |
| 3687 | struct drm_property_blob *prop_blob; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3688 | uint32_t __user *blob_id_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3689 | uint64_t __user *values_ptr; |
| 3690 | uint32_t __user *blob_length_ptr; |
| 3691 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3692 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3693 | return -EINVAL; |
| 3694 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3695 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 3696 | property = drm_property_find(dev, out_resp->prop_id); |
| 3697 | if (!property) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 3698 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3699 | goto done; |
| 3700 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3701 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3702 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 3703 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3704 | list_for_each_entry(prop_enum, &property->enum_blob_list, head) |
| 3705 | enum_count++; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3706 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3707 | list_for_each_entry(prop_blob, &property->enum_blob_list, head) |
| 3708 | blob_count++; |
| 3709 | } |
| 3710 | |
| 3711 | value_count = property->num_values; |
| 3712 | |
| 3713 | strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN); |
| 3714 | out_resp->name[DRM_PROP_NAME_LEN-1] = 0; |
| 3715 | out_resp->flags = property->flags; |
| 3716 | |
| 3717 | if ((out_resp->count_values >= value_count) && value_count) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3718 | values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3719 | for (i = 0; i < value_count; i++) { |
| 3720 | if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { |
| 3721 | ret = -EFAULT; |
| 3722 | goto done; |
| 3723 | } |
| 3724 | } |
| 3725 | } |
| 3726 | out_resp->count_values = value_count; |
| 3727 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3728 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 3729 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3730 | if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { |
| 3731 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3732 | enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3733 | list_for_each_entry(prop_enum, &property->enum_blob_list, head) { |
| 3734 | |
| 3735 | if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { |
| 3736 | ret = -EFAULT; |
| 3737 | goto done; |
| 3738 | } |
| 3739 | |
| 3740 | if (copy_to_user(&enum_ptr[copied].name, |
| 3741 | &prop_enum->name, DRM_PROP_NAME_LEN)) { |
| 3742 | ret = -EFAULT; |
| 3743 | goto done; |
| 3744 | } |
| 3745 | copied++; |
| 3746 | } |
| 3747 | } |
| 3748 | out_resp->count_enum_blobs = enum_count; |
| 3749 | } |
| 3750 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3751 | if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3752 | if ((out_resp->count_enum_blobs >= blob_count) && blob_count) { |
| 3753 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3754 | blob_id_ptr = (uint32_t __user *)(unsigned long)out_resp->enum_blob_ptr; |
| 3755 | blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3756 | |
| 3757 | list_for_each_entry(prop_blob, &property->enum_blob_list, head) { |
| 3758 | if (put_user(prop_blob->base.id, blob_id_ptr + copied)) { |
| 3759 | ret = -EFAULT; |
| 3760 | goto done; |
| 3761 | } |
| 3762 | |
| 3763 | if (put_user(prop_blob->length, blob_length_ptr + copied)) { |
| 3764 | ret = -EFAULT; |
| 3765 | goto done; |
| 3766 | } |
| 3767 | |
| 3768 | copied++; |
| 3769 | } |
| 3770 | } |
| 3771 | out_resp->count_enum_blobs = blob_count; |
| 3772 | } |
| 3773 | done: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3774 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3775 | return ret; |
| 3776 | } |
| 3777 | |
| 3778 | static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length, |
| 3779 | void *data) |
| 3780 | { |
| 3781 | struct drm_property_blob *blob; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3782 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3783 | |
| 3784 | if (!length || !data) |
| 3785 | return NULL; |
| 3786 | |
| 3787 | blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); |
| 3788 | if (!blob) |
| 3789 | return NULL; |
| 3790 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3791 | ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB); |
| 3792 | if (ret) { |
| 3793 | kfree(blob); |
| 3794 | return NULL; |
| 3795 | } |
| 3796 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3797 | blob->length = length; |
| 3798 | |
| 3799 | memcpy(blob->data, data, length); |
| 3800 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3801 | list_add_tail(&blob->head, &dev->mode_config.property_blob_list); |
| 3802 | return blob; |
| 3803 | } |
| 3804 | |
| 3805 | static void drm_property_destroy_blob(struct drm_device *dev, |
| 3806 | struct drm_property_blob *blob) |
| 3807 | { |
| 3808 | drm_mode_object_put(dev, &blob->base); |
| 3809 | list_del(&blob->head); |
| 3810 | kfree(blob); |
| 3811 | } |
| 3812 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3813 | /** |
| 3814 | * drm_mode_getblob_ioctl - get the contents of a blob property value |
| 3815 | * @dev: DRM device |
| 3816 | * @data: ioctl data |
| 3817 | * @file_priv: DRM file info |
| 3818 | * |
| 3819 | * This function retrieves the contents of a blob property. The value stored in |
| 3820 | * an object's blob property is just a normal modeset object id. |
| 3821 | * |
| 3822 | * Called by the user via ioctl. |
| 3823 | * |
| 3824 | * Returns: |
| 3825 | * Zero on success, errno on failure. |
| 3826 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3827 | int drm_mode_getblob_ioctl(struct drm_device *dev, |
| 3828 | void *data, struct drm_file *file_priv) |
| 3829 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3830 | struct drm_mode_get_blob *out_resp = data; |
| 3831 | struct drm_property_blob *blob; |
| 3832 | int ret = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3833 | void __user *blob_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3834 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3835 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3836 | return -EINVAL; |
| 3837 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3838 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 3839 | blob = drm_property_blob_find(dev, out_resp->blob_id); |
| 3840 | if (!blob) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 3841 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3842 | goto done; |
| 3843 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3844 | |
| 3845 | if (out_resp->length == blob->length) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3846 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3847 | if (copy_to_user(blob_ptr, blob->data, blob->length)){ |
| 3848 | ret = -EFAULT; |
| 3849 | goto done; |
| 3850 | } |
| 3851 | } |
| 3852 | out_resp->length = blob->length; |
| 3853 | |
| 3854 | done: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3855 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3856 | return ret; |
| 3857 | } |
| 3858 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3859 | /** |
| 3860 | * drm_mode_connector_update_edid_property - update the edid property of a connector |
| 3861 | * @connector: drm connector |
| 3862 | * @edid: new value of the edid property |
| 3863 | * |
| 3864 | * This function creates a new blob modeset object and assigns its id to the |
| 3865 | * connector's edid property. |
| 3866 | * |
| 3867 | * Returns: |
| 3868 | * Zero on success, errno on failure. |
| 3869 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3870 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
| 3871 | struct edid *edid) |
| 3872 | { |
| 3873 | struct drm_device *dev = connector->dev; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 3874 | int ret, size; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3875 | |
| 3876 | if (connector->edid_blob_ptr) |
| 3877 | drm_property_destroy_blob(dev, connector->edid_blob_ptr); |
| 3878 | |
| 3879 | /* Delete edid, when there is none. */ |
| 3880 | if (!edid) { |
| 3881 | connector->edid_blob_ptr = NULL; |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 3882 | ret = drm_object_property_set_value(&connector->base, dev->mode_config.edid_property, 0); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3883 | return ret; |
| 3884 | } |
| 3885 | |
Adam Jackson | 7466f4c | 2010-03-29 21:43:23 +0000 | [diff] [blame] | 3886 | size = EDID_LENGTH * (1 + edid->extensions); |
| 3887 | connector->edid_blob_ptr = drm_property_create_blob(connector->dev, |
| 3888 | size, edid); |
Sachin Kamat | e655d12 | 2012-11-19 09:44:57 +0000 | [diff] [blame] | 3889 | if (!connector->edid_blob_ptr) |
| 3890 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3891 | |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 3892 | ret = drm_object_property_set_value(&connector->base, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3893 | dev->mode_config.edid_property, |
| 3894 | connector->edid_blob_ptr->base.id); |
| 3895 | |
| 3896 | return ret; |
| 3897 | } |
| 3898 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
| 3899 | |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3900 | static bool drm_property_change_is_valid(struct drm_property *property, |
Ville Syrjälä | 592c20e | 2012-05-24 20:53:58 +0300 | [diff] [blame] | 3901 | uint64_t value) |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3902 | { |
| 3903 | if (property->flags & DRM_MODE_PROP_IMMUTABLE) |
| 3904 | return false; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3905 | |
| 3906 | if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) { |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3907 | if (value < property->values[0] || value > property->values[1]) |
| 3908 | return false; |
| 3909 | return true; |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3910 | } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) { |
| 3911 | int64_t svalue = U642I64(value); |
| 3912 | if (svalue < U642I64(property->values[0]) || |
| 3913 | svalue > U642I64(property->values[1])) |
| 3914 | return false; |
| 3915 | return true; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3916 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3917 | int i; |
Ville Syrjälä | 592c20e | 2012-05-24 20:53:58 +0300 | [diff] [blame] | 3918 | uint64_t valid_mask = 0; |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3919 | for (i = 0; i < property->num_values; i++) |
| 3920 | valid_mask |= (1ULL << property->values[i]); |
| 3921 | return !(value & ~valid_mask); |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3922 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
Ville Syrjälä | c4a5675 | 2012-10-25 18:05:06 +0000 | [diff] [blame] | 3923 | /* Only the driver knows */ |
| 3924 | return true; |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3925 | } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
| 3926 | struct drm_mode_object *obj; |
| 3927 | /* a zero value for an object property translates to null: */ |
| 3928 | if (value == 0) |
| 3929 | return true; |
| 3930 | /* |
| 3931 | * NOTE: use _object_find() directly to bypass restriction on |
| 3932 | * looking up refcnt'd objects (ie. fb's). For a refcnt'd |
| 3933 | * object this could race against object finalization, so it |
| 3934 | * simply tells us that the object *was* valid. Which is good |
| 3935 | * enough. |
| 3936 | */ |
| 3937 | obj = _object_find(property->dev, value, property->values[0]); |
| 3938 | return obj != NULL; |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3939 | } else { |
| 3940 | int i; |
| 3941 | for (i = 0; i < property->num_values; i++) |
| 3942 | if (property->values[i] == value) |
| 3943 | return true; |
| 3944 | return false; |
| 3945 | } |
| 3946 | } |
| 3947 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3948 | /** |
| 3949 | * drm_mode_connector_property_set_ioctl - set the current value of a connector property |
| 3950 | * @dev: DRM device |
| 3951 | * @data: ioctl data |
| 3952 | * @file_priv: DRM file info |
| 3953 | * |
| 3954 | * This function sets the current value for a connectors's property. It also |
| 3955 | * calls into a driver's ->set_property callback to update the hardware state |
| 3956 | * |
| 3957 | * Called by the user via ioctl. |
| 3958 | * |
| 3959 | * Returns: |
| 3960 | * Zero on success, errno on failure. |
| 3961 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3962 | int drm_mode_connector_property_set_ioctl(struct drm_device *dev, |
| 3963 | void *data, struct drm_file *file_priv) |
| 3964 | { |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 3965 | struct drm_mode_connector_set_property *conn_set_prop = data; |
| 3966 | struct drm_mode_obj_set_property obj_set_prop = { |
| 3967 | .value = conn_set_prop->value, |
| 3968 | .prop_id = conn_set_prop->prop_id, |
| 3969 | .obj_id = conn_set_prop->connector_id, |
| 3970 | .obj_type = DRM_MODE_OBJECT_CONNECTOR |
| 3971 | }; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3972 | |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 3973 | /* It does all the locking and checking we need */ |
| 3974 | return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3975 | } |
| 3976 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3977 | static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
| 3978 | struct drm_property *property, |
| 3979 | uint64_t value) |
| 3980 | { |
| 3981 | int ret = -EINVAL; |
| 3982 | struct drm_connector *connector = obj_to_connector(obj); |
| 3983 | |
| 3984 | /* Do DPMS ourselves */ |
| 3985 | if (property == connector->dev->mode_config.dpms_property) { |
| 3986 | if (connector->funcs->dpms) |
| 3987 | (*connector->funcs->dpms)(connector, (int)value); |
| 3988 | ret = 0; |
| 3989 | } else if (connector->funcs->set_property) |
| 3990 | ret = connector->funcs->set_property(connector, property, value); |
| 3991 | |
| 3992 | /* store the property value if successful */ |
| 3993 | if (!ret) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 3994 | drm_object_property_set_value(&connector->base, property, value); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3995 | return ret; |
| 3996 | } |
| 3997 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 3998 | static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
| 3999 | struct drm_property *property, |
| 4000 | uint64_t value) |
| 4001 | { |
| 4002 | int ret = -EINVAL; |
| 4003 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 4004 | |
| 4005 | if (crtc->funcs->set_property) |
| 4006 | ret = crtc->funcs->set_property(crtc, property, value); |
| 4007 | if (!ret) |
| 4008 | drm_object_property_set_value(obj, property, value); |
| 4009 | |
| 4010 | return ret; |
| 4011 | } |
| 4012 | |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4013 | static int drm_mode_plane_set_obj_prop(struct drm_mode_object *obj, |
| 4014 | struct drm_property *property, |
| 4015 | uint64_t value) |
| 4016 | { |
| 4017 | int ret = -EINVAL; |
| 4018 | struct drm_plane *plane = obj_to_plane(obj); |
| 4019 | |
| 4020 | if (plane->funcs->set_property) |
| 4021 | ret = plane->funcs->set_property(plane, property, value); |
| 4022 | if (!ret) |
| 4023 | drm_object_property_set_value(obj, property, value); |
| 4024 | |
| 4025 | return ret; |
| 4026 | } |
| 4027 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4028 | /** |
| 4029 | * drm_mode_getproperty_ioctl - get the current value of a object's property |
| 4030 | * @dev: DRM device |
| 4031 | * @data: ioctl data |
| 4032 | * @file_priv: DRM file info |
| 4033 | * |
| 4034 | * This function retrieves the current value for an object's property. Compared |
| 4035 | * to the connector specific ioctl this one is extended to also work on crtc and |
| 4036 | * plane objects. |
| 4037 | * |
| 4038 | * Called by the user via ioctl. |
| 4039 | * |
| 4040 | * Returns: |
| 4041 | * Zero on success, errno on failure. |
| 4042 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4043 | int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
| 4044 | struct drm_file *file_priv) |
| 4045 | { |
| 4046 | struct drm_mode_obj_get_properties *arg = data; |
| 4047 | struct drm_mode_object *obj; |
| 4048 | int ret = 0; |
| 4049 | int i; |
| 4050 | int copied = 0; |
| 4051 | int props_count = 0; |
| 4052 | uint32_t __user *props_ptr; |
| 4053 | uint64_t __user *prop_values_ptr; |
| 4054 | |
| 4055 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4056 | return -EINVAL; |
| 4057 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4058 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4059 | |
| 4060 | obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
| 4061 | if (!obj) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4062 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4063 | goto out; |
| 4064 | } |
| 4065 | if (!obj->properties) { |
| 4066 | ret = -EINVAL; |
| 4067 | goto out; |
| 4068 | } |
| 4069 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4070 | props_count = obj->properties->count; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4071 | |
| 4072 | /* This ioctl is called twice, once to determine how much space is |
| 4073 | * needed, and the 2nd time to fill it. */ |
| 4074 | if ((arg->count_props >= props_count) && props_count) { |
| 4075 | copied = 0; |
| 4076 | props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr); |
| 4077 | prop_values_ptr = (uint64_t __user *)(unsigned long) |
| 4078 | (arg->prop_values_ptr); |
| 4079 | for (i = 0; i < props_count; i++) { |
| 4080 | if (put_user(obj->properties->ids[i], |
| 4081 | props_ptr + copied)) { |
| 4082 | ret = -EFAULT; |
| 4083 | goto out; |
| 4084 | } |
| 4085 | if (put_user(obj->properties->values[i], |
| 4086 | prop_values_ptr + copied)) { |
| 4087 | ret = -EFAULT; |
| 4088 | goto out; |
| 4089 | } |
| 4090 | copied++; |
| 4091 | } |
| 4092 | } |
| 4093 | arg->count_props = props_count; |
| 4094 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4095 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4096 | return ret; |
| 4097 | } |
| 4098 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4099 | /** |
| 4100 | * drm_mode_obj_set_property_ioctl - set the current value of an object's property |
| 4101 | * @dev: DRM device |
| 4102 | * @data: ioctl data |
| 4103 | * @file_priv: DRM file info |
| 4104 | * |
| 4105 | * This function sets the current value for an object's property. It also calls |
| 4106 | * into a driver's ->set_property callback to update the hardware state. |
| 4107 | * Compared to the connector specific ioctl this one is extended to also work on |
| 4108 | * crtc and plane objects. |
| 4109 | * |
| 4110 | * Called by the user via ioctl. |
| 4111 | * |
| 4112 | * Returns: |
| 4113 | * Zero on success, errno on failure. |
| 4114 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4115 | int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, |
| 4116 | struct drm_file *file_priv) |
| 4117 | { |
| 4118 | struct drm_mode_obj_set_property *arg = data; |
| 4119 | struct drm_mode_object *arg_obj; |
| 4120 | struct drm_mode_object *prop_obj; |
| 4121 | struct drm_property *property; |
| 4122 | int ret = -EINVAL; |
| 4123 | int i; |
| 4124 | |
| 4125 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4126 | return -EINVAL; |
| 4127 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4128 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4129 | |
| 4130 | arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4131 | if (!arg_obj) { |
| 4132 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4133 | goto out; |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4134 | } |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4135 | if (!arg_obj->properties) |
| 4136 | goto out; |
| 4137 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4138 | for (i = 0; i < arg_obj->properties->count; i++) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4139 | if (arg_obj->properties->ids[i] == arg->prop_id) |
| 4140 | break; |
| 4141 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4142 | if (i == arg_obj->properties->count) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4143 | goto out; |
| 4144 | |
| 4145 | prop_obj = drm_mode_object_find(dev, arg->prop_id, |
| 4146 | DRM_MODE_OBJECT_PROPERTY); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4147 | if (!prop_obj) { |
| 4148 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4149 | goto out; |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4150 | } |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4151 | property = obj_to_property(prop_obj); |
| 4152 | |
| 4153 | if (!drm_property_change_is_valid(property, arg->value)) |
| 4154 | goto out; |
| 4155 | |
| 4156 | switch (arg_obj->type) { |
| 4157 | case DRM_MODE_OBJECT_CONNECTOR: |
| 4158 | ret = drm_mode_connector_set_obj_prop(arg_obj, property, |
| 4159 | arg->value); |
| 4160 | break; |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 4161 | case DRM_MODE_OBJECT_CRTC: |
| 4162 | ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); |
| 4163 | break; |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4164 | case DRM_MODE_OBJECT_PLANE: |
| 4165 | ret = drm_mode_plane_set_obj_prop(arg_obj, property, arg->value); |
| 4166 | break; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4170 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4171 | return ret; |
| 4172 | } |
| 4173 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4174 | /** |
| 4175 | * drm_mode_connector_attach_encoder - attach a connector to an encoder |
| 4176 | * @connector: connector to attach |
| 4177 | * @encoder: encoder to attach @connector to |
| 4178 | * |
| 4179 | * This function links up a connector to an encoder. Note that the routing |
| 4180 | * restrictions between encoders and crtcs are exposed to userspace through the |
| 4181 | * possible_clones and possible_crtcs bitmasks. |
| 4182 | * |
| 4183 | * Returns: |
| 4184 | * Zero on success, errno on failure. |
| 4185 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4186 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
| 4187 | struct drm_encoder *encoder) |
| 4188 | { |
| 4189 | int i; |
| 4190 | |
| 4191 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 4192 | if (connector->encoder_ids[i] == 0) { |
| 4193 | connector->encoder_ids[i] = encoder->base.id; |
| 4194 | return 0; |
| 4195 | } |
| 4196 | } |
| 4197 | return -ENOMEM; |
| 4198 | } |
| 4199 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
| 4200 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4201 | /** |
| 4202 | * drm_mode_crtc_set_gamma_size - set the gamma table size |
| 4203 | * @crtc: CRTC to set the gamma table size for |
| 4204 | * @gamma_size: size of the gamma table |
| 4205 | * |
| 4206 | * Drivers which support gamma tables should set this to the supported gamma |
| 4207 | * table size when initializing the CRTC. Currently the drm core only supports a |
| 4208 | * fixed gamma table size. |
| 4209 | * |
| 4210 | * Returns: |
| 4211 | * Zero on success, errno on failure. |
| 4212 | */ |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 4213 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4214 | int gamma_size) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4215 | { |
| 4216 | crtc->gamma_size = gamma_size; |
| 4217 | |
| 4218 | crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL); |
| 4219 | if (!crtc->gamma_store) { |
| 4220 | crtc->gamma_size = 0; |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 4221 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4222 | } |
| 4223 | |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 4224 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4225 | } |
| 4226 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); |
| 4227 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4228 | /** |
| 4229 | * drm_mode_gamma_set_ioctl - set the gamma table |
| 4230 | * @dev: DRM device |
| 4231 | * @data: ioctl data |
| 4232 | * @file_priv: DRM file info |
| 4233 | * |
| 4234 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can |
| 4235 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. |
| 4236 | * |
| 4237 | * Called by the user via ioctl. |
| 4238 | * |
| 4239 | * Returns: |
| 4240 | * Zero on success, errno on failure. |
| 4241 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4242 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
| 4243 | void *data, struct drm_file *file_priv) |
| 4244 | { |
| 4245 | struct drm_mode_crtc_lut *crtc_lut = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4246 | struct drm_crtc *crtc; |
| 4247 | void *r_base, *g_base, *b_base; |
| 4248 | int size; |
| 4249 | int ret = 0; |
| 4250 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 4251 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4252 | return -EINVAL; |
| 4253 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4254 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 4255 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
| 4256 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4257 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4258 | goto out; |
| 4259 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4260 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 4261 | if (crtc->funcs->gamma_set == NULL) { |
| 4262 | ret = -ENOSYS; |
| 4263 | goto out; |
| 4264 | } |
| 4265 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4266 | /* memcpy into gamma store */ |
| 4267 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 4268 | ret = -EINVAL; |
| 4269 | goto out; |
| 4270 | } |
| 4271 | |
| 4272 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 4273 | r_base = crtc->gamma_store; |
| 4274 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { |
| 4275 | ret = -EFAULT; |
| 4276 | goto out; |
| 4277 | } |
| 4278 | |
| 4279 | g_base = r_base + size; |
| 4280 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { |
| 4281 | ret = -EFAULT; |
| 4282 | goto out; |
| 4283 | } |
| 4284 | |
| 4285 | b_base = g_base + size; |
| 4286 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { |
| 4287 | ret = -EFAULT; |
| 4288 | goto out; |
| 4289 | } |
| 4290 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 4291 | crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4292 | |
| 4293 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4294 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4295 | return ret; |
| 4296 | |
| 4297 | } |
| 4298 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4299 | /** |
| 4300 | * drm_mode_gamma_get_ioctl - get the gamma table |
| 4301 | * @dev: DRM device |
| 4302 | * @data: ioctl data |
| 4303 | * @file_priv: DRM file info |
| 4304 | * |
| 4305 | * Copy the current gamma table into the storage provided. This also provides |
| 4306 | * the gamma table size the driver expects, which can be used to size the |
| 4307 | * allocated storage. |
| 4308 | * |
| 4309 | * Called by the user via ioctl. |
| 4310 | * |
| 4311 | * Returns: |
| 4312 | * Zero on success, errno on failure. |
| 4313 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4314 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
| 4315 | void *data, struct drm_file *file_priv) |
| 4316 | { |
| 4317 | struct drm_mode_crtc_lut *crtc_lut = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4318 | struct drm_crtc *crtc; |
| 4319 | void *r_base, *g_base, *b_base; |
| 4320 | int size; |
| 4321 | int ret = 0; |
| 4322 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 4323 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4324 | return -EINVAL; |
| 4325 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4326 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 4327 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
| 4328 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4329 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4330 | goto out; |
| 4331 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4332 | |
| 4333 | /* memcpy into gamma store */ |
| 4334 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 4335 | ret = -EINVAL; |
| 4336 | goto out; |
| 4337 | } |
| 4338 | |
| 4339 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 4340 | r_base = crtc->gamma_store; |
| 4341 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { |
| 4342 | ret = -EFAULT; |
| 4343 | goto out; |
| 4344 | } |
| 4345 | |
| 4346 | g_base = r_base + size; |
| 4347 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { |
| 4348 | ret = -EFAULT; |
| 4349 | goto out; |
| 4350 | } |
| 4351 | |
| 4352 | b_base = g_base + size; |
| 4353 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { |
| 4354 | ret = -EFAULT; |
| 4355 | goto out; |
| 4356 | } |
| 4357 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4358 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4359 | return ret; |
| 4360 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4361 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4362 | /** |
| 4363 | * drm_mode_page_flip_ioctl - schedule an asynchronous fb update |
| 4364 | * @dev: DRM device |
| 4365 | * @data: ioctl data |
| 4366 | * @file_priv: DRM file info |
| 4367 | * |
| 4368 | * This schedules an asynchronous update on a given CRTC, called page flip. |
| 4369 | * Optionally a drm event is generated to signal the completion of the event. |
| 4370 | * Generic drivers cannot assume that a pageflip with changed framebuffer |
| 4371 | * properties (including driver specific metadata like tiling layout) will work, |
| 4372 | * but some drivers support e.g. pixel format changes through the pageflip |
| 4373 | * ioctl. |
| 4374 | * |
| 4375 | * Called by the user via ioctl. |
| 4376 | * |
| 4377 | * Returns: |
| 4378 | * Zero on success, errno on failure. |
| 4379 | */ |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4380 | int drm_mode_page_flip_ioctl(struct drm_device *dev, |
| 4381 | void *data, struct drm_file *file_priv) |
| 4382 | { |
| 4383 | struct drm_mode_crtc_page_flip *page_flip = data; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4384 | struct drm_crtc *crtc; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 4385 | struct drm_framebuffer *fb = NULL, *old_fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4386 | struct drm_pending_vblank_event *e = NULL; |
| 4387 | unsigned long flags; |
| 4388 | int ret = -EINVAL; |
| 4389 | |
| 4390 | if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || |
| 4391 | page_flip->reserved != 0) |
| 4392 | return -EINVAL; |
| 4393 | |
Keith Packard | 62f2104 | 2013-07-22 18:50:00 -0700 | [diff] [blame] | 4394 | if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip) |
| 4395 | return -EINVAL; |
| 4396 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 4397 | crtc = drm_crtc_find(dev, page_flip->crtc_id); |
| 4398 | if (!crtc) |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4399 | return -ENOENT; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4400 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 4401 | drm_modeset_lock(&crtc->mutex, NULL); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 4402 | if (crtc->primary->fb == NULL) { |
Chris Wilson | 90c1efd | 2010-07-17 20:23:26 +0100 | [diff] [blame] | 4403 | /* The framebuffer is currently unbound, presumably |
| 4404 | * due to a hotplug event, that userspace has not |
| 4405 | * yet discovered. |
| 4406 | */ |
| 4407 | ret = -EBUSY; |
| 4408 | goto out; |
| 4409 | } |
| 4410 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4411 | if (crtc->funcs->page_flip == NULL) |
| 4412 | goto out; |
| 4413 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 4414 | fb = drm_framebuffer_lookup(dev, page_flip->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 4415 | if (!fb) { |
| 4416 | ret = -ENOENT; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4417 | goto out; |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 4418 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4419 | |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 4420 | ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, &crtc->mode, fb); |
| 4421 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 4422 | goto out; |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 4423 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 4424 | if (crtc->primary->fb->pixel_format != fb->pixel_format) { |
Laurent Pinchart | 909d9cd | 2013-04-22 01:38:46 +0200 | [diff] [blame] | 4425 | DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); |
| 4426 | ret = -EINVAL; |
| 4427 | goto out; |
| 4428 | } |
| 4429 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4430 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
| 4431 | ret = -ENOMEM; |
| 4432 | spin_lock_irqsave(&dev->event_lock, flags); |
| 4433 | if (file_priv->event_space < sizeof e->event) { |
| 4434 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4435 | goto out; |
| 4436 | } |
| 4437 | file_priv->event_space -= sizeof e->event; |
| 4438 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4439 | |
| 4440 | e = kzalloc(sizeof *e, GFP_KERNEL); |
| 4441 | if (e == NULL) { |
| 4442 | spin_lock_irqsave(&dev->event_lock, flags); |
| 4443 | file_priv->event_space += sizeof e->event; |
| 4444 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4445 | goto out; |
| 4446 | } |
| 4447 | |
Jesse Barnes | 7bd4d7b | 2009-11-19 10:50:22 -0800 | [diff] [blame] | 4448 | e->event.base.type = DRM_EVENT_FLIP_COMPLETE; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4449 | e->event.base.length = sizeof e->event; |
| 4450 | e->event.user_data = page_flip->user_data; |
| 4451 | e->base.event = &e->event.base; |
| 4452 | e->base.file_priv = file_priv; |
| 4453 | e->base.destroy = |
| 4454 | (void (*) (struct drm_pending_event *)) kfree; |
| 4455 | } |
| 4456 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 4457 | old_fb = crtc->primary->fb; |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 4458 | ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags); |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4459 | if (ret) { |
Joonyoung Shim | aef6a7e | 2012-04-18 13:47:02 +0900 | [diff] [blame] | 4460 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
| 4461 | spin_lock_irqsave(&dev->event_lock, flags); |
| 4462 | file_priv->event_space += sizeof e->event; |
| 4463 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 4464 | kfree(e); |
| 4465 | } |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 4466 | /* Keep the old fb, don't unref it. */ |
| 4467 | old_fb = NULL; |
| 4468 | } else { |
Thierry Reding | 8cf1e98 | 2013-02-13 16:08:33 +0100 | [diff] [blame] | 4469 | /* |
| 4470 | * Warn if the driver hasn't properly updated the crtc->fb |
| 4471 | * field to reflect that the new framebuffer is now used. |
| 4472 | * Failing to do so will screw with the reference counting |
| 4473 | * on framebuffers. |
| 4474 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 4475 | WARN_ON(crtc->primary->fb != fb); |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 4476 | /* Unref only the old framebuffer. */ |
| 4477 | fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4478 | } |
| 4479 | |
| 4480 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 4481 | if (fb) |
| 4482 | drm_framebuffer_unreference(fb); |
| 4483 | if (old_fb) |
| 4484 | drm_framebuffer_unreference(old_fb); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 4485 | drm_modeset_unlock(&crtc->mutex); |
Daniel Vetter | b4d5e7d | 2012-12-11 16:59:31 +0100 | [diff] [blame] | 4486 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 4487 | return ret; |
| 4488 | } |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 4489 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4490 | /** |
| 4491 | * drm_mode_config_reset - call ->reset callbacks |
| 4492 | * @dev: drm device |
| 4493 | * |
| 4494 | * This functions calls all the crtc's, encoder's and connector's ->reset |
| 4495 | * callback. Drivers can use this in e.g. their driver load or resume code to |
| 4496 | * reset hardware and software state. |
| 4497 | */ |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 4498 | void drm_mode_config_reset(struct drm_device *dev) |
| 4499 | { |
| 4500 | struct drm_crtc *crtc; |
| 4501 | struct drm_encoder *encoder; |
| 4502 | struct drm_connector *connector; |
| 4503 | |
| 4504 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 4505 | if (crtc->funcs->reset) |
| 4506 | crtc->funcs->reset(crtc); |
| 4507 | |
| 4508 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 4509 | if (encoder->funcs->reset) |
| 4510 | encoder->funcs->reset(encoder); |
| 4511 | |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 4512 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 4513 | connector->status = connector_status_unknown; |
| 4514 | |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 4515 | if (connector->funcs->reset) |
| 4516 | connector->funcs->reset(connector); |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 4517 | } |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 4518 | } |
| 4519 | EXPORT_SYMBOL(drm_mode_config_reset); |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 4520 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4521 | /** |
| 4522 | * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer |
| 4523 | * @dev: DRM device |
| 4524 | * @data: ioctl data |
| 4525 | * @file_priv: DRM file info |
| 4526 | * |
| 4527 | * This creates a new dumb buffer in the driver's backing storage manager (GEM, |
| 4528 | * TTM or something else entirely) and returns the resulting buffer handle. This |
| 4529 | * handle can then be wrapped up into a framebuffer modeset object. |
| 4530 | * |
| 4531 | * Note that userspace is not allowed to use such objects for render |
| 4532 | * acceleration - drivers must create their own private ioctls for such a use |
| 4533 | * case. |
| 4534 | * |
| 4535 | * Called by the user via ioctl. |
| 4536 | * |
| 4537 | * Returns: |
| 4538 | * Zero on success, errno on failure. |
| 4539 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 4540 | int drm_mode_create_dumb_ioctl(struct drm_device *dev, |
| 4541 | void *data, struct drm_file *file_priv) |
| 4542 | { |
| 4543 | struct drm_mode_create_dumb *args = data; |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 4544 | u32 cpp, stride, size; |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 4545 | |
| 4546 | if (!dev->driver->dumb_create) |
| 4547 | return -ENOSYS; |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 4548 | if (!args->width || !args->height || !args->bpp) |
| 4549 | return -EINVAL; |
| 4550 | |
| 4551 | /* overflow checks for 32bit size calculations */ |
| 4552 | cpp = DIV_ROUND_UP(args->bpp, 8); |
| 4553 | if (cpp > 0xffffffffU / args->width) |
| 4554 | return -EINVAL; |
| 4555 | stride = cpp * args->width; |
| 4556 | if (args->height > 0xffffffffU / stride) |
| 4557 | return -EINVAL; |
| 4558 | |
| 4559 | /* test for wrap-around */ |
| 4560 | size = args->height * stride; |
| 4561 | if (PAGE_ALIGN(size) == 0) |
| 4562 | return -EINVAL; |
| 4563 | |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 4564 | return dev->driver->dumb_create(file_priv, dev, args); |
| 4565 | } |
| 4566 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4567 | /** |
| 4568 | * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer |
| 4569 | * @dev: DRM device |
| 4570 | * @data: ioctl data |
| 4571 | * @file_priv: DRM file info |
| 4572 | * |
| 4573 | * Allocate an offset in the drm device node's address space to be able to |
| 4574 | * memory map a dumb buffer. |
| 4575 | * |
| 4576 | * Called by the user via ioctl. |
| 4577 | * |
| 4578 | * Returns: |
| 4579 | * Zero on success, errno on failure. |
| 4580 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 4581 | int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, |
| 4582 | void *data, struct drm_file *file_priv) |
| 4583 | { |
| 4584 | struct drm_mode_map_dumb *args = data; |
| 4585 | |
| 4586 | /* call driver ioctl to get mmap offset */ |
| 4587 | if (!dev->driver->dumb_map_offset) |
| 4588 | return -ENOSYS; |
| 4589 | |
| 4590 | return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset); |
| 4591 | } |
| 4592 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4593 | /** |
| 4594 | * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer |
| 4595 | * @dev: DRM device |
| 4596 | * @data: ioctl data |
| 4597 | * @file_priv: DRM file info |
| 4598 | * |
| 4599 | * This destroys the userspace handle for the given dumb backing storage buffer. |
| 4600 | * Since buffer objects must be reference counted in the kernel a buffer object |
| 4601 | * won't be immediately freed if a framebuffer modeset object still uses it. |
| 4602 | * |
| 4603 | * Called by the user via ioctl. |
| 4604 | * |
| 4605 | * Returns: |
| 4606 | * Zero on success, errno on failure. |
| 4607 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 4608 | int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, |
| 4609 | void *data, struct drm_file *file_priv) |
| 4610 | { |
| 4611 | struct drm_mode_destroy_dumb *args = data; |
| 4612 | |
| 4613 | if (!dev->driver->dumb_destroy) |
| 4614 | return -ENOSYS; |
| 4615 | |
| 4616 | return dev->driver->dumb_destroy(file_priv, dev, args->handle); |
| 4617 | } |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4618 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4619 | /** |
| 4620 | * drm_fb_get_bpp_depth - get the bpp/depth values for format |
| 4621 | * @format: pixel format (DRM_FORMAT_*) |
| 4622 | * @depth: storage for the depth value |
| 4623 | * @bpp: storage for the bpp value |
| 4624 | * |
| 4625 | * This only supports RGB formats here for compat with code that doesn't use |
| 4626 | * pixel formats directly yet. |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4627 | */ |
| 4628 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, |
| 4629 | int *bpp) |
| 4630 | { |
| 4631 | switch (format) { |
Ville Syrjälä | c51a6bc | 2013-01-31 19:43:37 +0200 | [diff] [blame] | 4632 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 4633 | case DRM_FORMAT_RGB332: |
| 4634 | case DRM_FORMAT_BGR233: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4635 | *depth = 8; |
| 4636 | *bpp = 8; |
| 4637 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 4638 | case DRM_FORMAT_XRGB1555: |
| 4639 | case DRM_FORMAT_XBGR1555: |
| 4640 | case DRM_FORMAT_RGBX5551: |
| 4641 | case DRM_FORMAT_BGRX5551: |
| 4642 | case DRM_FORMAT_ARGB1555: |
| 4643 | case DRM_FORMAT_ABGR1555: |
| 4644 | case DRM_FORMAT_RGBA5551: |
| 4645 | case DRM_FORMAT_BGRA5551: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4646 | *depth = 15; |
| 4647 | *bpp = 16; |
| 4648 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 4649 | case DRM_FORMAT_RGB565: |
| 4650 | case DRM_FORMAT_BGR565: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4651 | *depth = 16; |
| 4652 | *bpp = 16; |
| 4653 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 4654 | case DRM_FORMAT_RGB888: |
| 4655 | case DRM_FORMAT_BGR888: |
| 4656 | *depth = 24; |
| 4657 | *bpp = 24; |
| 4658 | break; |
| 4659 | case DRM_FORMAT_XRGB8888: |
| 4660 | case DRM_FORMAT_XBGR8888: |
| 4661 | case DRM_FORMAT_RGBX8888: |
| 4662 | case DRM_FORMAT_BGRX8888: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4663 | *depth = 24; |
| 4664 | *bpp = 32; |
| 4665 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 4666 | case DRM_FORMAT_XRGB2101010: |
| 4667 | case DRM_FORMAT_XBGR2101010: |
| 4668 | case DRM_FORMAT_RGBX1010102: |
| 4669 | case DRM_FORMAT_BGRX1010102: |
| 4670 | case DRM_FORMAT_ARGB2101010: |
| 4671 | case DRM_FORMAT_ABGR2101010: |
| 4672 | case DRM_FORMAT_RGBA1010102: |
| 4673 | case DRM_FORMAT_BGRA1010102: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4674 | *depth = 30; |
| 4675 | *bpp = 32; |
| 4676 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 4677 | case DRM_FORMAT_ARGB8888: |
| 4678 | case DRM_FORMAT_ABGR8888: |
| 4679 | case DRM_FORMAT_RGBA8888: |
| 4680 | case DRM_FORMAT_BGRA8888: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4681 | *depth = 32; |
| 4682 | *bpp = 32; |
| 4683 | break; |
| 4684 | default: |
Ville Syrjälä | 23c453a | 2013-10-15 21:06:51 +0300 | [diff] [blame] | 4685 | DRM_DEBUG_KMS("unsupported pixel format %s\n", |
| 4686 | drm_get_format_name(format)); |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 4687 | *depth = 0; |
| 4688 | *bpp = 0; |
| 4689 | break; |
| 4690 | } |
| 4691 | } |
| 4692 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 4693 | |
| 4694 | /** |
| 4695 | * drm_format_num_planes - get the number of planes for format |
| 4696 | * @format: pixel format (DRM_FORMAT_*) |
| 4697 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4698 | * Returns: |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 4699 | * The number of planes used by the specified pixel format. |
| 4700 | */ |
| 4701 | int drm_format_num_planes(uint32_t format) |
| 4702 | { |
| 4703 | switch (format) { |
| 4704 | case DRM_FORMAT_YUV410: |
| 4705 | case DRM_FORMAT_YVU410: |
| 4706 | case DRM_FORMAT_YUV411: |
| 4707 | case DRM_FORMAT_YVU411: |
| 4708 | case DRM_FORMAT_YUV420: |
| 4709 | case DRM_FORMAT_YVU420: |
| 4710 | case DRM_FORMAT_YUV422: |
| 4711 | case DRM_FORMAT_YVU422: |
| 4712 | case DRM_FORMAT_YUV444: |
| 4713 | case DRM_FORMAT_YVU444: |
| 4714 | return 3; |
| 4715 | case DRM_FORMAT_NV12: |
| 4716 | case DRM_FORMAT_NV21: |
| 4717 | case DRM_FORMAT_NV16: |
| 4718 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 4719 | case DRM_FORMAT_NV24: |
| 4720 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 4721 | return 2; |
| 4722 | default: |
| 4723 | return 1; |
| 4724 | } |
| 4725 | } |
| 4726 | EXPORT_SYMBOL(drm_format_num_planes); |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 4727 | |
| 4728 | /** |
| 4729 | * drm_format_plane_cpp - determine the bytes per pixel value |
| 4730 | * @format: pixel format (DRM_FORMAT_*) |
| 4731 | * @plane: plane index |
| 4732 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4733 | * Returns: |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 4734 | * The bytes per pixel value for the specified plane. |
| 4735 | */ |
| 4736 | int drm_format_plane_cpp(uint32_t format, int plane) |
| 4737 | { |
| 4738 | unsigned int depth; |
| 4739 | int bpp; |
| 4740 | |
| 4741 | if (plane >= drm_format_num_planes(format)) |
| 4742 | return 0; |
| 4743 | |
| 4744 | switch (format) { |
| 4745 | case DRM_FORMAT_YUYV: |
| 4746 | case DRM_FORMAT_YVYU: |
| 4747 | case DRM_FORMAT_UYVY: |
| 4748 | case DRM_FORMAT_VYUY: |
| 4749 | return 2; |
| 4750 | case DRM_FORMAT_NV12: |
| 4751 | case DRM_FORMAT_NV21: |
| 4752 | case DRM_FORMAT_NV16: |
| 4753 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 4754 | case DRM_FORMAT_NV24: |
| 4755 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 4756 | return plane ? 2 : 1; |
| 4757 | case DRM_FORMAT_YUV410: |
| 4758 | case DRM_FORMAT_YVU410: |
| 4759 | case DRM_FORMAT_YUV411: |
| 4760 | case DRM_FORMAT_YVU411: |
| 4761 | case DRM_FORMAT_YUV420: |
| 4762 | case DRM_FORMAT_YVU420: |
| 4763 | case DRM_FORMAT_YUV422: |
| 4764 | case DRM_FORMAT_YVU422: |
| 4765 | case DRM_FORMAT_YUV444: |
| 4766 | case DRM_FORMAT_YVU444: |
| 4767 | return 1; |
| 4768 | default: |
| 4769 | drm_fb_get_bpp_depth(format, &depth, &bpp); |
| 4770 | return bpp >> 3; |
| 4771 | } |
| 4772 | } |
| 4773 | EXPORT_SYMBOL(drm_format_plane_cpp); |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 4774 | |
| 4775 | /** |
| 4776 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor |
| 4777 | * @format: pixel format (DRM_FORMAT_*) |
| 4778 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4779 | * Returns: |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 4780 | * The horizontal chroma subsampling factor for the |
| 4781 | * specified pixel format. |
| 4782 | */ |
| 4783 | int drm_format_horz_chroma_subsampling(uint32_t format) |
| 4784 | { |
| 4785 | switch (format) { |
| 4786 | case DRM_FORMAT_YUV411: |
| 4787 | case DRM_FORMAT_YVU411: |
| 4788 | case DRM_FORMAT_YUV410: |
| 4789 | case DRM_FORMAT_YVU410: |
| 4790 | return 4; |
| 4791 | case DRM_FORMAT_YUYV: |
| 4792 | case DRM_FORMAT_YVYU: |
| 4793 | case DRM_FORMAT_UYVY: |
| 4794 | case DRM_FORMAT_VYUY: |
| 4795 | case DRM_FORMAT_NV12: |
| 4796 | case DRM_FORMAT_NV21: |
| 4797 | case DRM_FORMAT_NV16: |
| 4798 | case DRM_FORMAT_NV61: |
| 4799 | case DRM_FORMAT_YUV422: |
| 4800 | case DRM_FORMAT_YVU422: |
| 4801 | case DRM_FORMAT_YUV420: |
| 4802 | case DRM_FORMAT_YVU420: |
| 4803 | return 2; |
| 4804 | default: |
| 4805 | return 1; |
| 4806 | } |
| 4807 | } |
| 4808 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); |
| 4809 | |
| 4810 | /** |
| 4811 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor |
| 4812 | * @format: pixel format (DRM_FORMAT_*) |
| 4813 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4814 | * Returns: |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 4815 | * The vertical chroma subsampling factor for the |
| 4816 | * specified pixel format. |
| 4817 | */ |
| 4818 | int drm_format_vert_chroma_subsampling(uint32_t format) |
| 4819 | { |
| 4820 | switch (format) { |
| 4821 | case DRM_FORMAT_YUV410: |
| 4822 | case DRM_FORMAT_YVU410: |
| 4823 | return 4; |
| 4824 | case DRM_FORMAT_YUV420: |
| 4825 | case DRM_FORMAT_YVU420: |
| 4826 | case DRM_FORMAT_NV12: |
| 4827 | case DRM_FORMAT_NV21: |
| 4828 | return 2; |
| 4829 | default: |
| 4830 | return 1; |
| 4831 | } |
| 4832 | } |
| 4833 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4834 | |
| 4835 | /** |
| 4836 | * drm_mode_config_init - initialize DRM mode_configuration structure |
| 4837 | * @dev: DRM device |
| 4838 | * |
| 4839 | * Initialize @dev's mode_config structure, used for tracking the graphics |
| 4840 | * configuration of @dev. |
| 4841 | * |
| 4842 | * Since this initializes the modeset locks, no locking is possible. Which is no |
| 4843 | * problem, since this should happen single threaded at init time. It is the |
| 4844 | * driver's problem to ensure this guarantee. |
| 4845 | * |
| 4846 | */ |
| 4847 | void drm_mode_config_init(struct drm_device *dev) |
| 4848 | { |
| 4849 | mutex_init(&dev->mode_config.mutex); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 4850 | drm_modeset_lock_init(&dev->mode_config.connection_mutex); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4851 | mutex_init(&dev->mode_config.idr_mutex); |
| 4852 | mutex_init(&dev->mode_config.fb_lock); |
| 4853 | INIT_LIST_HEAD(&dev->mode_config.fb_list); |
| 4854 | INIT_LIST_HEAD(&dev->mode_config.crtc_list); |
| 4855 | INIT_LIST_HEAD(&dev->mode_config.connector_list); |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 4856 | INIT_LIST_HEAD(&dev->mode_config.bridge_list); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4857 | INIT_LIST_HEAD(&dev->mode_config.encoder_list); |
| 4858 | INIT_LIST_HEAD(&dev->mode_config.property_list); |
| 4859 | INIT_LIST_HEAD(&dev->mode_config.property_blob_list); |
| 4860 | INIT_LIST_HEAD(&dev->mode_config.plane_list); |
| 4861 | idr_init(&dev->mode_config.crtc_idr); |
| 4862 | |
| 4863 | drm_modeset_lock_all(dev); |
| 4864 | drm_mode_create_standard_connector_properties(dev); |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 4865 | drm_mode_create_standard_plane_properties(dev); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4866 | drm_modeset_unlock_all(dev); |
| 4867 | |
| 4868 | /* Just to be sure */ |
| 4869 | dev->mode_config.num_fb = 0; |
| 4870 | dev->mode_config.num_connector = 0; |
| 4871 | dev->mode_config.num_crtc = 0; |
| 4872 | dev->mode_config.num_encoder = 0; |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 4873 | dev->mode_config.num_overlay_plane = 0; |
| 4874 | dev->mode_config.num_total_plane = 0; |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4875 | } |
| 4876 | EXPORT_SYMBOL(drm_mode_config_init); |
| 4877 | |
| 4878 | /** |
| 4879 | * drm_mode_config_cleanup - free up DRM mode_config info |
| 4880 | * @dev: DRM device |
| 4881 | * |
| 4882 | * Free up all the connectors and CRTCs associated with this DRM device, then |
| 4883 | * free up the framebuffers and associated buffer objects. |
| 4884 | * |
| 4885 | * Note that since this /should/ happen single-threaded at driver/device |
| 4886 | * teardown time, no locking is required. It's the driver's job to ensure that |
| 4887 | * this guarantee actually holds true. |
| 4888 | * |
| 4889 | * FIXME: cleanup any dangling user buffer objects too |
| 4890 | */ |
| 4891 | void drm_mode_config_cleanup(struct drm_device *dev) |
| 4892 | { |
| 4893 | struct drm_connector *connector, *ot; |
| 4894 | struct drm_crtc *crtc, *ct; |
| 4895 | struct drm_encoder *encoder, *enct; |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 4896 | struct drm_bridge *bridge, *brt; |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4897 | struct drm_framebuffer *fb, *fbt; |
| 4898 | struct drm_property *property, *pt; |
| 4899 | struct drm_property_blob *blob, *bt; |
| 4900 | struct drm_plane *plane, *plt; |
| 4901 | |
| 4902 | list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list, |
| 4903 | head) { |
| 4904 | encoder->funcs->destroy(encoder); |
| 4905 | } |
| 4906 | |
Sean Paul | 3b336ec | 2013-08-14 16:47:37 -0400 | [diff] [blame] | 4907 | list_for_each_entry_safe(bridge, brt, |
| 4908 | &dev->mode_config.bridge_list, head) { |
| 4909 | bridge->funcs->destroy(bridge); |
| 4910 | } |
| 4911 | |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4912 | list_for_each_entry_safe(connector, ot, |
| 4913 | &dev->mode_config.connector_list, head) { |
| 4914 | connector->funcs->destroy(connector); |
| 4915 | } |
| 4916 | |
| 4917 | list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, |
| 4918 | head) { |
| 4919 | drm_property_destroy(dev, property); |
| 4920 | } |
| 4921 | |
| 4922 | list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, |
| 4923 | head) { |
| 4924 | drm_property_destroy_blob(dev, blob); |
| 4925 | } |
| 4926 | |
| 4927 | /* |
| 4928 | * Single-threaded teardown context, so it's not required to grab the |
| 4929 | * fb_lock to protect against concurrent fb_list access. Contrary, it |
| 4930 | * would actually deadlock with the drm_framebuffer_cleanup function. |
| 4931 | * |
| 4932 | * Also, if there are any framebuffers left, that's a driver leak now, |
| 4933 | * so politely WARN about this. |
| 4934 | */ |
| 4935 | WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
| 4936 | list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { |
| 4937 | drm_framebuffer_remove(fb); |
| 4938 | } |
| 4939 | |
| 4940 | list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, |
| 4941 | head) { |
| 4942 | plane->funcs->destroy(plane); |
| 4943 | } |
| 4944 | |
| 4945 | list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { |
| 4946 | crtc->funcs->destroy(crtc); |
| 4947 | } |
| 4948 | |
| 4949 | idr_destroy(&dev->mode_config.crtc_idr); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 4950 | drm_modeset_lock_fini(&dev->mode_config.connection_mutex); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 4951 | } |
| 4952 | EXPORT_SYMBOL(drm_mode_config_cleanup); |