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