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