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