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