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