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