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